mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Avoid generating duplicate lv names
This commit is contained in:
parent
5238b63f1a
commit
6e74833c6c
@ -174,12 +174,12 @@ static int _allocate(struct volume_group *vg, struct logical_volume *lv,
|
||||
return r;
|
||||
}
|
||||
|
||||
static char *_make_up_lv_name(struct volume_group *vg,
|
||||
static char *_generate_lv_name(struct volume_group *vg,
|
||||
char *buffer, size_t len)
|
||||
{
|
||||
struct list *lvh;
|
||||
struct logical_volume *lv;
|
||||
int high = 1, i, s;
|
||||
int high = -1, i, s;
|
||||
|
||||
list_iterate(lvh, &vg->lvs) {
|
||||
lv = &(list_item(lvh, struct lv_list)->lv);
|
||||
@ -188,10 +188,10 @@ static char *_make_up_lv_name(struct volume_group *vg,
|
||||
continue;
|
||||
|
||||
if (i > high)
|
||||
high = i + 1;
|
||||
high = i;
|
||||
}
|
||||
|
||||
if ((s = snprintf(buffer, len, "lvol%d", high)) < 0 || s >= len)
|
||||
if ((s = snprintf(buffer, len, "lvol%d", high + 1)) < 0 || s >= len)
|
||||
return NULL;
|
||||
|
||||
return buffer;
|
||||
@ -230,7 +230,7 @@ struct logical_volume *lv_create(const char *name,
|
||||
}
|
||||
|
||||
if (!name &&
|
||||
!(name = _make_up_lv_name(vg, dname, sizeof(dname)))) {
|
||||
!(name = _generate_lv_name(vg, dname, sizeof(dname)))) {
|
||||
log_error("Failed to generate unique name for the new "
|
||||
"logical volume");
|
||||
return NULL;
|
||||
|
@ -233,6 +233,8 @@ int lvcreate(int argc, char **argv)
|
||||
if (!fid->ops->vg_write(fid, vg))
|
||||
return ECMD_FAILED;
|
||||
|
||||
log_print("Logical volume %s created", lv->name);
|
||||
|
||||
if (!lv_activate(lv))
|
||||
return ECMD_FAILED;
|
||||
|
||||
@ -263,7 +265,5 @@ int lvcreate(int argc, char **argv)
|
||||
return ret;
|
||||
***********/
|
||||
|
||||
log_print("Logical volume %s created", lv->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user