[linux-lvm] Bug: LVM2 create long name device failed but we can see it by run lvs

xufeng zhang xufeng.zhang at windriver.com
Fri Nov 12 09:38:32 UTC 2010


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.
--- LVM2.2.01.05.orig/lib/misc/lvm-string.h       2010-11-12 
15:05:52.000000000 +0800
+++ LVM2.2.01.05/lib/misc/lvm-string.h            2010-11-12 
14:57:02.000000000 +0800
@@ -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
--- LVM2.2.01.05.orig/lib/misc/lvm-string.c       2010-11-12 
15:05:52.000000000 +0800
+++ LVM2.2.01.05/lib/misc/lvm-string.c            2010-11-12 
14:57:02.000000000 +0800
@@ -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>.
   */
--- LVM2.2.01.05.orig/lib/metadata/lv_manip.c       2010-11-12 
15:05:52.000000000 +0800
+++ LVM2.2.01.05/lib/metadata/lv_manip.c            2010-11-12 
14:57:02.000000000 +0800
@@ -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




More information about the linux-lvm mailing list