1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

cachevol: generate a unique name when creating

When a cachevol is automatically created, if the default name
conflicts with an existing name, generate a new unique name.
This commit is contained in:
David Teigland 2020-07-23 13:07:32 -05:00
parent 3c9177fdc0
commit 085760992d
2 changed files with 24 additions and 0 deletions

View File

@ -208,5 +208,15 @@ lvchange -ay $vg/$lv1
lvchange -an $vg/$lv1 lvchange -an $vg/$lv1
lvremove $vg/$lv1 lvremove $vg/$lv1
# if the cache name is used generate a new name
lvcreate -n $lv1 -l8 -an $vg @slow
lvcreate -n ${lv1}_cache -l1 -an $vg @slow
lvconvert -y --type writecache --cachedevice @fast --cachesize 8M $vg/$lv1
check lv_field $vg/$lv1 segtype writecache
check lv_field $vg/${lv1}_cache0_cvol lv_size "8.00m"
lvchange -ay $vg/$lv1
lvchange -an $vg/$lv1
lvremove $vg/$lv1
vgremove -ff $vg vgremove -ff $vg

View File

@ -4267,6 +4267,7 @@ static int _lv_create_cachevol(struct cmd_context *cmd,
struct logical_volume **cachevol_lv) struct logical_volume **cachevol_lv)
{ {
char cvname[NAME_LEN]; char cvname[NAME_LEN];
char format[NAME_LEN];
struct dm_list *use_pvh; struct dm_list *use_pvh;
struct pv_list *pvl; struct pv_list *pvl;
char *dev_name; char *dev_name;
@ -4373,6 +4374,19 @@ static int _lv_create_cachevol(struct cmd_context *cmd,
return 0; return 0;
} }
if (find_lv(vg, cvname)) {
memset(format, 0, sizeof(cvname));
memset(cvname, 0, sizeof(cvname));
if (dm_snprintf(format, sizeof(format), "%s_cache%%d", lv->name) < 0) {
log_error("Failed to generate cachevol LV format.");
return 0;
}
if (!generate_lv_name(vg, format, cvname, sizeof(cvname))) {
log_error("Failed to generate cachevol LV name.");
return 0;
}
}
lp.lv_name = cvname; lp.lv_name = cvname;
lp.pvh = use_pvh; lp.pvh = use_pvh;
lp.extents = cache_size_sectors / vg->extent_size; lp.extents = cache_size_sectors / vg->extent_size;