1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

lv_manip: add lv_uniq_rename_update

Add function to rename LV to either passed name or if
the name is already in use, generate new lvol% name.
This commit is contained in:
Zdenek Kabelac 2019-10-21 09:16:45 +02:00
parent 5714c8c9cc
commit 2266a1863f
2 changed files with 26 additions and 0 deletions

View File

@ -4625,6 +4625,30 @@ int lv_rename_update(struct cmd_context *cmd, struct logical_volume *lv,
return 1;
}
/*
* Rename LV to new name, if name is occupies, lvol% is generated.
* VG must be locked by caller.
*/
int lv_uniq_rename_update(struct cmd_context *cmd, struct logical_volume *lv,
const char *new_name, int update_mda)
{
char uniq_name[NAME_LEN];
/* If the name is in use, generate new lvol%d */
if (lv_name_is_used_in_vg(lv->vg, new_name, NULL)) {
if (!generate_lv_name(lv->vg, "lvol%d", uniq_name, sizeof(uniq_name))) {
log_error("Failed to generate unique name for unused logical volume.");
return 0;
}
new_name = uniq_name;
}
if (!lv_rename_update(cmd, lv, new_name, 0))
return_0;
return 1;
}
/*
* Core of LV renaming routine.
* VG must be locked by caller.

View File

@ -845,6 +845,8 @@ int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,
const char *new_name);
int lv_rename_update(struct cmd_context *cmd, struct logical_volume *lv,
const char *new_name, int update_mda);
int lv_uniq_rename_update(struct cmd_context *cmd, struct logical_volume *lv,
const char *new_name, int update_mda);
/* Updates and reloads metadata for given lv */
int lv_update_and_reload(struct logical_volume *lv);