linux-lvm.redhat.com archive mirror
 help / color / mirror / Atom feed
* [linux-lvm] Bug: LVM2 create long name device failed but we can see it by run lvs
@ 2010-11-12  9:38 xufeng zhang
  2010-11-12 10:06 ` Alasdair G Kergon
  0 siblings, 1 reply; 3+ messages in thread
From: xufeng zhang @ 2010-11-12  9:38 UTC (permalink / raw)
  To: linux-lvm

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [linux-lvm] Bug: LVM2 create long name device failed but we can see it by run lvs
  2010-11-12  9:38 [linux-lvm] Bug: LVM2 create long name device failed but we can see it by run lvs xufeng zhang
@ 2010-11-12 10:06 ` Alasdair G Kergon
  2010-11-13  7:34   ` xufeng zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Alasdair G Kergon @ 2010-11-12 10:06 UTC (permalink / raw)
  To: xufeng zhang; +Cc: linux-lvm

On Fri, Nov 12, 2010 at 05:38:32PM +0800, xufeng zhang wrote:
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [linux-lvm] Bug: LVM2 create long name device failed but we can see it by run lvs
  2010-11-12 10:06 ` Alasdair G Kergon
@ 2010-11-13  7:34   ` xufeng zhang
  0 siblings, 0 replies; 3+ messages in thread
From: xufeng zhang @ 2010-11-13  7:34 UTC (permalink / raw)
  To: linux-lvm

On 11/12/2010 06:06 PM, Alasdair G Kergon wrote:
> On Fri, Nov 12, 2010 at 05:38:32PM +0800, xufeng zhang wrote:
>    
>> 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.
>    
Maybe I have made a mistake, I can't reproduce this bug in LVM2.2.02.76 now.

Thanks,
Xufeng Zhang
> Alasdair
>
>
>    

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-11-13  7:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-12  9:38 [linux-lvm] Bug: LVM2 create long name device failed but we can see it by run lvs xufeng zhang
2010-11-12 10:06 ` Alasdair G Kergon
2010-11-13  7:34   ` xufeng zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).