Bug 796602

Summary: "lvconvert --splitmirrors" can create not valid Logical Volume names
Product: Red Hat Enterprise Linux 6 Reporter: Pierguido Lambri <plambri>
Component: lvm2Assignee: Alasdair Kergon <agk>
Status: CLOSED ERRATA QA Contact: Cluster QE <mspqa-list>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.3CC: agk, cmarthal, dwysocha, mbroz, prajnoha, thornber, zkabelac
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: lvm2-2.02.95-3.el6 Doc Type: Bug Fix
Doc Text:
If a Volume Group name is supplied with the Logical Volume name, 'lvconvert --splitmirrors' fails to strip it off. This leads to an attempt to use a Logical Volume name that is invalid. This release detects and validates any supplied Volume Group name correctly.
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-06-20 15:01:44 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Pierguido Lambri 2012-02-23 10:00:22 UTC
Description of problem:
I was able to create LV names with the "/" using the lvconvert command:

# lvconvert --splitmirrors 1 --name test/testlv1 test/testlv

The command returns errors:

 Name "test-test/testlv1" invalid. It contains "/".
  Failed to rename test-testlv_mimage_1 (253:3) to test-test/testlv1
  Failed to rename newly split LV in the kernel
  libdevmapper exiting with 1 device(s) still suspended.

But the LVM metadata are modified, so now we have a LV named "test/testlv1":

# lvs
  LV              VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv_root         VolGroup -wi-ao   8.54g                                      
  lv_swap         VolGroup -wi-ao 992.00m                                      
  test/testlv1    test     -wa-s-  12.00m                                      
  testlv          test     -wa-a-  12.00m                                      
  testlv_mimage_0 test     vwa-a-  12.00m             

This LV is impossible to remove using lvremove.

Version-Release number of selected component (if applicable):
Reproduced on the latest LVM2 package on RHEL6 (lvm2-2.02.87-6.el6.x86_64)

How reproducible:
ALways


Steps to Reproduce:
1. Create a mirrored LV
2. Split the logical volume using as name "xxxx/yyyyy"
3. The command will give an error but the LV is present in the lvs output
  
Actual results:
The metadata are modified and the not valid name is used.


Expected results:
The lvconvert should raise an error and not insert the lv metadata.


Additional info:

These are the tests I've done:

# lvcreate -m1 --alloc anywhere --mirrorlog core -L10MB -n testlv test

# lvconvert --splitmirrors 1 --name test/testlv1 test/testlv
  Name "test-test/testlv1" invalid. It contains "/".
  Failed to rename test-testlv_mimage_1 (253:3) to test-test/testlv1
  Failed to rename newly split LV in the kernel
  libdevmapper exiting with 1 device(s) still suspended.

# lvs
  LV              VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv_root         VolGroup -wi-ao   8.54g                                      
  lv_swap         VolGroup -wi-ao 992.00m                                      
  test/testlv1    test     -wa-s-  12.00m                                      
  testlv          test     -wa-a-  12.00m                                      
  testlv_mimage_0 test     vwa-a-  12.00m                                     


# dmsetup info -c
Name                 Maj Min Stat Open Targ Event  UUID                                                                
VolGroup-lv_swap     253   1 L--w    1    1      0 LVM-nVuLBqbbvI8SrGo7i3vzetJbfMaOikyCzoNWkcsukJjWY4xPFetOBefvy2M9fUfd
VolGroup-lv_root     253   0 L--w    1    1      0 LVM-nVuLBqbbvI8SrGo7i3vzetJbfMaOikyCCa3zIo1ufjkjluvqDUe2cJInd0jnn2NC
test-testlv          253   4 L--w    0    1      1 LVM-8o1OhBGDPPZFMV0qGlguT9hgL4j2j0EFp0xLyMunDX61SJ4lhVwJ38lCVkuEZPPT
test-testlv_mimage_1 253   3 L-sw    0    1      0 LVM-8o1OhBGDPPZFMV0qGlguT9hgL4j2j0EFq0Js0lfTsjp0GbxpnqdiCyYd9Gu4s0b6
test-testlv_mimage_0 253   2 L--w    0    1      0 LVM-8o1OhBGDPPZFMV0qGlguT9hgL4j2j0EFEu3US3n1wEgf3ooIQ1XaLsmUjZDowb5p

# dmsetup ls --tree
VolGroup-lv_swap (253:1)
 └─ (252:2)
VolGroup-lv_root (253:0)
 └─ (252:2)
test-testlv (253:4)
 └─ (252:16)
test-testlv_mimage_1 (253:3)
 └─ (252:16)
test-testlv_mimage_0 (253:2)


The LV is removable by restoring a modified backup:

# diff -u test_00036-1793593470.vg /etc/lvm/archive/test_00036-1793593470.vg 
--- test_00036-1793593470.vg	2012-02-23 07:45:31.716806707 +0000
+++ /etc/lvm/archive/test_00036-1793593470.vg	2012-02-22 17:01:04.283832033 +0000
@@ -69,7 +69,7 @@
 			}
 		}
 
-		test_testlv1 {
+		test/testlv1 {
 			id = "q0Js0l-fTsj-p0Gb-xpnq-diCy-Yd9G-u4s0b6"
 			status = ["READ", "WRITE", "VISIBLE"]
 			flags = []


# vgcfgrestore -f test_00036-1793593470.vg test
  Restored volume group test


# lvs
  LV              VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv_root         VolGroup -wi-ao   8.54g                                      
  lv_swap         VolGroup -wi-ao 992.00m                                      
  test_testlv1    test     -wa---  12.00m                                      
  testlv          test     -wa-a-  12.00m                                      
  testlv_mimage_0 test     vwa-a-  12.00m                                      


# lvremove test/test_testlv1
  Logical volume "test_testlv1" successfully removed

# lvs
  LV              VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv_root         VolGroup -wi-ao   8.54g                                      
  lv_swap         VolGroup -wi-ao 992.00m                                      
  testlv          test     -wa-a-  12.00m                                      
  testlv_mimage_0 test     vwa-a-  12.00m                                      

# lvremove testlv
  Volume group "testlv" not found
  Skipping volume group testlv

# lvremove test/testlv
Do you really want to remove active logical volume testlv? [y/n]: y
  Logical volume "testlv" successfully removed

# lvremove test/testlv_mimage_0
Do you really want to remove active logical volume testlv_mimage_0? [y/n]: y
  Logical volume "testlv_mimage_0" successfully removed

# lvs
  LV      VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv_root VolGroup -wi-ao   8.54g                                      
  lv_swap VolGroup -wi-ao 992.00m

Comment 2 Alasdair Kergon 2012-02-23 12:00:25 UTC
I've updated vg_validate (which validates the metadata independently before writing it to disk) to catch bugs like this.

Comment 3 Alasdair Kergon 2012-02-23 12:05:19 UTC
Like other tools, this should validate the VG name, if present, and strip it to obtain the LV name.

The cmdline rules are:
  VG name needs to appear at least once on cmdline.
  If more than one VG name on cmdline, they must all match.

Comment 4 Peter Rajnoha 2012-02-24 14:37:58 UTC
(In reply to comment #2)
> I've updated vg_validate (which validates the metadata independently before
> writing it to disk) to catch bugs like this.

In lvm2 v2.02.93, moving bug to POST:

[0] devel/~ # lvs
  LV    VG   Attr     LSize Pool Origin Data%  Move Log        Copy%  Convert
  lvol0 vg   mwi-a-m- 4.00m                         lvol0_mlog 100.00        

[0] devel/~ # lvconvert --splitmirrors 1 --name vg/abc vg/lvol0
  Internal error: LV name vg/pokus has invalid form.
  Intermediate VG metadata write failed.

[0] devel/~ # lvs
  LV    VG   Attr     LSize Pool Origin Data%  Move Log        Copy%  Convert
  lvol0 vg   mwi-a-m- 4.00m                         lvol0_mlog 100.00        

[0] devel/~ # dmsetup info -c -o name
Name             
vg-lvol0         
vg-lvol0_mimage_1
vg-lvol0_mimage_0
vg-lvol0_mlog

Comment 5 Peter Rajnoha 2012-02-24 14:53:41 UTC
[0] devel/~ # vgs              
  VG   #PV #LV #SN Attr   VSize VFree
  vg     9   0   0 wz--n- 1.09g 1.09g

[0] devel/~ # lvcreate -l1 -n vg/a vg
  Logical volume "a" created

[0] devel/~ # lvcreate -l1 -n xyz/b vg
  Inconsistent volume group names given: "xyz" and "vg"
  Run `lvcreate --help' for more information.


...well, sorry, moving back from POST, this still needs one small patch for the processing to be consistent for all LVM comamnds (like described in comment #3).

(though the original problem is resolved already)

Comment 6 Peter Rajnoha 2012-03-30 10:22:40 UTC
I've added the additional patch so now we have (taking into account comment #3):

  devel/~ # lvconvert --splitmirrors 1 -n vg/splitted_one vg/mirrored_one
  Logical volume mirrored_one converted.
    
  devel/~ # lvconvert --splitmirrors 1 -n abc/splitted_one vg/mirrored_one
  Please use a single volume group name ("vg" or "abc")
  Run `lvconvert --help' for more information.

Comment 9 Alasdair Kergon 2012-04-23 14:06:25 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
If a Volume Group name is supplied with the Logical Volume name, 'lvconvert --splitmirrors' fails to strip it off.  This leads to an attempt to use a Logical Volume name that is invalid.

This release detects and validates any supplied Volume Group name correctly.

Comment 10 Corey Marthaler 2012-05-04 20:52:10 UTC
Fix verified in the latest rpms.

2.6.32-269.el6.x86_64
lvm2-2.02.95-7.el6    BUILT: Wed May  2 05:14:03 CDT 2012
lvm2-libs-2.02.95-7.el6    BUILT: Wed May  2 05:14:03 CDT 2012
lvm2-cluster-2.02.95-7.el6    BUILT: Wed May  2 05:14:03 CDT 2012
udev-147-2.40.el6    BUILT: Fri Sep 23 07:51:13 CDT 2011
device-mapper-1.02.74-7.el6    BUILT: Wed May  2 05:14:03 CDT 2012
device-mapper-libs-1.02.74-7.el6    BUILT: Wed May  2 05:14:03 CDT 2012
device-mapper-event-1.02.74-7.el6    BUILT: Wed May  2 05:14:03 CDT 2012
device-mapper-event-libs-1.02.74-7.el6    BUILT: Wed May  2 05:14:03 CDT 2012
cmirror-2.02.95-7.el6    BUILT: Wed May  2 05:14:03 CDT 2012

[root@hayes-01 ~]# lvs -a -o +devices
  LV                VG     Attr     LSize  Log         Copy%  Devices
  mirror            hayes  mwi-a-m- 12.00m mirror_mlog 100.00 mirror_mimage_0(0),mirror_mimage_1(0),mirror_mimage_2(0)
  [mirror_mimage_0] hayes  iwi-aom- 12.00m                    /dev/etherd/e1.1p1(0)
  [mirror_mimage_1] hayes  iwi-aom- 12.00m                    /dev/etherd/e1.1p2(0)
  [mirror_mimage_2] hayes  iwi-aom- 12.00m                    /dev/etherd/e1.1p3(0)
  [mirror_mlog]     hayes  lwi-aom-  4.00m                    /dev/etherd/e1.1p9(0)

[root@hayes-01 ~]# lvconvert --splitmirrors 1 --name hayes/mirror1 hayes/mirror
  Logical volume mirror converted.
[root@hayes-01 ~]# lvs -a -o +devices
  LV                VG     Attr     LSize  Log         Copy%  Devices
  mirror            hayes  mwi-a-m- 12.00m mirror_mlog 100.00 mirror_mimage_0(0),mirror_mimage_1(0)
  mirror1           hayes  -wi-a--- 12.00m                    /dev/etherd/e1.1p3(0)
  [mirror_mimage_0] hayes  iwi-aom- 12.00m                    /dev/etherd/e1.1p1(0)
  [mirror_mimage_1] hayes  iwi-aom- 12.00m                    /dev/etherd/e1.1p2(0)
  [mirror_mlog]     hayes  lwi-aom-  4.00m                    /dev/etherd/e1.1p9(0)

[root@hayes-01 ~]# lvconvert --splitmirrors 1 --name foo/bar hayes/mirror
  Please use a single volume group name ("hayes" or "foo")
  Run `lvconvert --help' for more information.

Comment 12 errata-xmlrpc 2012-06-20 15:01:44 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2012-0962.html