]> sourceware.org Git - lvm2.git/commitdiff
Avoid generating duplicate lv names
authorAlasdair Kergon <agk@redhat.com>
Wed, 14 Nov 2001 14:12:01 +0000 (14:12 +0000)
committerAlasdair Kergon <agk@redhat.com>
Wed, 14 Nov 2001 14:12:01 +0000 (14:12 +0000)
lib/metadata/lv_manip.c
tools/lvcreate.c

index 02ba761d38de23bbcfa793d12da3f9b1b4265e2f..0c296769a7ab25ad16df8032bba275df41832949 100644 (file)
@@ -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;
index f16fc03686ddabd8dcb1ca32360ee67ea262f6e1..f5c461010a764383544b8409927d2788a3aa8ae3 100644 (file)
@@ -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;
 }
This page took 0.037774 seconds and 5 git commands to generate.