Skip to contentSkip to conversation

Bug: LVM2 create long name device failed but we can see it by run lvs

linux-lvm xufeng zhang 2 participants 3 messages Nov 12, 2010 – Nov 13, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

I found a potential bug in LVM2.2.02.25, but it is also exist in LVM2.2.02.76 after I checked.

This is the bug description:
When we create a logic volume with long names(such as 125), LVM2 will return "Name too long" error and create volume failed. However, you will see it exist in volume group if you run lvs command. The reason is that when LVM2 create a empty device in lv_create_empty() function, it didn't check the length of device names, but the empty device activate failed afterward because of too long name(vgname+lvname>128).

I made a patch for LVM2.2.02.25 by adding name length check.

lib/misc/lvm-string.h 2010-11-12 14:57:02.000000000 +0800 renamed from lib/misc/lvm-string.h 2010-11-12 15:05:52.000000000 +0800 +2 -0
@@ -34,4 +34,6 @@
                 char c);
 unsigned count_chars_len(const char *str, size_t size, char c);
 
+unsigned count_lvname_add_vgname_len(const char *vgname,
+               const char *lvname);
 #endif
lib/misc/lvm-string.c 2010-11-12 14:57:02.000000000 +0800 renamed from lib/misc/lvm-string.c 2010-11-12 15:05:52.000000000 +0800 +13 -0
@@ -83,6 +83,19 @@
        }
 }
 
+unsigned count_lvname_add_vgname_len(const char *vgname, const char *lvname)
+{
+        unsigned sum_len = 1;
+        int sum_hyphens = 0;
+
+        count_chars(vgname, &sum_len, &sum_hyphens, '-');
+        count_chars(lvname, &sum_len, &sum_hyphens, '-');
+
+        sum_len += sum_hyphens;
+
+        return sum_len;
+}
+
 /*
  * <vg>-<lv>-<layer> or if !layer just <vg>-<lv>.
  */
lib/metadata/lv_manip.c 2010-11-12 14:57:02.000000000 +0800 renamed from lib/metadata/lv_manip.c 2010-11-12 15:05:52.000000000 +0800 +8 -0
@@ -1494,6 +1494,7 @@
        struct lv_list *ll = NULL;
        struct logical_volume *lv;
        char dname[NAME_LEN];
+       unsigned sum_len;
 
        if (vg->max_lv && (vg->max_lv == vg->lv_count)) {
                log_error("Maximum number of logical volumes (%u) reached "
@@ -1501,6 +1502,15 @@
                return NULL;
        }
 
+       /* we must ensure the sum length of vgname and lvname don't
+          exceed DM_NAME_LEN before we create an empty logic device */
+       if ((sum_len = count_lvname_add_vgname_len(vg->name, name)) >= NAME_LEN) {
+               log_error("Group Name \"%s\" plus Device Name \"%s\" is too long\n",
+                       vg->name, name);
+               log_error("Logical volume \"%s\" created failed.\n", name);
+               return NULL;
                                                                                                                                                                                             9,1           61%
  if (strstr(name, "%d") &&
            !(name = generate_lv_name(vg, name, dname, sizeof(dname)))) {

log_error("Failed to generate unique name for the new "

Thanks,
Xufeng Zhang

#1 lore raw
Quoted 9 lines · xufeng zhang

This is the bug description:
When we create a logic volume with long names(such as 125), LVM2 will return "Name too long" error
and create volume failed. However, you will see it exist in volume group if you run lvs command.
The reason is that when LVM2 create a empty device in lv_create_empty() function, it didn't check the
length of device names, but the empty device activate failed afterward because of too long name(vgname+lvname>128).

Thanks for reporting that.

Presumably 'vgrename' needs a similar restriction.

Alasdair

#2 lore raw
Quoted 12 lines · Alasdair G Kergon
Quoted 10 lines · xufeng zhang

This is the bug description:
When we create a logic volume with long names(such as 125), LVM2 will return "Name too long" error
and create volume failed. However, you will see it exist in volume group if you run lvs command.
The reason is that when LVM2 create a empty device in lv_create_empty() function, it didn't check the
length of device names, but the empty device activate failed afterward because of too long name(vgname+lvname>128).

Quoted 4 lines

Thanks for reporting that.

Presumably 'vgrename' needs a similar restriction.

Maybe I have made a mistake, I can't reproduce this bug in LVM2.2.02.76 now.

Thanks,
Xufeng Zhang

Quoted 4 lines

Alasdair