Bug 820116

Summary: vgcfgrestore fails with division by zero if PV with zero length present in VG
Product: Red Hat Enterprise Linux 6 Reporter: Jiri Lunacek <jiri.lunacek>
Component: lvm2Assignee: Peter Rajnoha <prajnoha>
Status: CLOSED ERRATA QA Contact: Cluster QE <mspqa-list>
Severity: high Docs Contact:
Priority: high    
Version: 6.2CC: agk, coughlan, dwysocha, glux, heinzm, jbrassow, mbroz, msnitzer, nperic, prajnoha, prockai, thornber, zkabelac
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: lvm2-2.02.97-2.el6 Doc Type: Bug Fix
Doc Text:
In a situation where there was a PV in a VG with zero PEs (physical extents) so the PV was used to store metadata only, the vgcfgrestore failed with a "Floating point exception" error that was caused by division by zero. A proper check for this condition has been added to prevent the error.
Story Points: ---
Clone Of:
: 820237 (view as bug list) Environment:
Last Closed: 2013-02-21 08:09:46 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 820237    

Description Jiri Lunacek 2012-05-09 08:24:57 UTC
Description of problem:
If there is PV with zero PE count in the VG, vgcfgrestore on the VG fails saying "Floating point exception", which is caused by division by zero.

Background:
We are using LVM heavily for storage of block device backups. Because the PVs are usually very busy and metadata manipulation requires direct access to the metadata sector (may take considerable time to complete), we have created a metadata-only PV on a separate drive. 

Version-Release number of selected component (if applicable):
  LVM version:     2.02.87(2)-RHEL6 (2011-10-12)
  Library version: 1.02.66-RHEL6 (2011-10-12)
  Driver version:  4.22.6

How reproducible:
Always

Steps to Reproduce:
create /dev/<metadata_device> with size 200M
create /dev/<data_device> of any size
pvcreate --metadatasize 128m /dev/<metadata_device>
pvcreate --metadatasize 128m /dev/<data_device>
vgcreate -s 128m myVG /dev/<metadata_device> /dev/<data_device>
vgcfgbackup myVG
vgcfgrestore myVG
  
Actual results:
Last command fails with "Floating point exception" error. 

Expected results:
vgcfgrestore should successfully write VG metadata

Additional info:
This issue may be worked around by omitting the zero-length PV from the backup file. See file contents below.
We have solved this for our case using the above workaround and making the metadata PV bigger and setting allocable to N afterwards.

Backup file contents:
# Generated by LVM2 version 2.02.87(2)-RHEL6 (2011-10-12): Wed May  9 10:13:28 2012

contents = "Text Format Volume Group"
version = 1

description = "vgcfgbackup -f myvg.vg myvg"

creation_host = "localhost.localdomain"	# Linux localhost.localdomain 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64
creation_time = 1336551208	# Wed May  9 10:13:28 2012

myvg {
	id = "ouGQeP-8bPl-udT8-lm8a-Nd3A-WprB-pOGXfj"
	seqno = 1
	status = ["RESIZEABLE", "READ", "WRITE"]
	flags = []
	extent_size = 262144		# 128 Megabytes
	max_lv = 0
	max_pv = 0
	metadata_copies = 0

	physical_volumes {

		pv0 {
			id = "hbMvQA-zTeD-CKPc-WE8o-umlm-Z6GJ-iyALRr"
			device = "/dev/vg_test/pv1"	# Hint only

			status = ["ALLOCATABLE"]
			flags = []
			dev_size = 20971520	# 10 Gigabytes
			pe_start = 264192
			pe_count = 78	# 9.75 Gigabytes
		}

		pv1 {
			id = "K1BwfU-2LuG-8aeW-IXHR-RLf7-d36V-DMERDr"
			device = "/dev/vg_test/pv_metadata"	# Hint only

			status = ["ALLOCATABLE"]
			flags = []
			dev_size = 409600	# 200 Megabytes
			pe_start = 264192
			pe_count = 0	# 0 Kilobytes
		}
	}

}


Backup file for workaround:
# Generated by LVM2 version 2.02.87(2)-RHEL6 (2011-10-12): Wed May  9 10:13:28 2012

contents = "Text Format Volume Group"
version = 1

description = "vgcfgbackup -f myvg.vg myvg"

creation_host = "localhost.localdomain"	# Linux localhost.localdomain 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64
creation_time = 1336551208	# Wed May  9 10:13:28 2012

myvg {
	id = "ouGQeP-8bPl-udT8-lm8a-Nd3A-WprB-pOGXfj"
	seqno = 1
	status = ["RESIZEABLE", "READ", "WRITE"]
	flags = []
	extent_size = 262144		# 128 Megabytes
	max_lv = 0
	max_pv = 0
	metadata_copies = 0

	physical_volumes {

		pv0 {
			id = "hbMvQA-zTeD-CKPc-WE8o-umlm-Z6GJ-iyALRr"
			device = "/dev/vg_test/pv1"	# Hint only

			status = ["ALLOCATABLE"]
			flags = []
			dev_size = 20971520	# 10 Gigabytes
			pe_start = 264192
			pe_count = 78	# 9.75 Gigabytes
		}
	}

}

Comment 2 Alasdair Kergon 2012-05-09 12:51:02 UTC
Thanks for reporting this!

Peter has committed a fix for the next upstream release (2.02.96) and this will be picked up by RHEL6.4:

http://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=501a2c04a4cb009a4c6497cd601801b2fe32fb4e

Comment 5 Nenad Peric 2012-09-12 14:13:36 UTC
Tested with old and new versioni of lvm2.

With older version the core dumps as expected (reported by BZ):

Syncing disks.
(09:15:44) [root@r6-node02:~]$ pvcreate --metadatasize 128m /dev/sde1 
  Writing physical volume data to disk "/dev/sde1"
  Physical volume "/dev/sde1" successfully created
(09:15:55) [root@r6-node02:~]$ pvcreate --metadatasize 128m /dev/sdf1 
  Writing physical volume data to disk "/dev/sdf1"
  Physical volume "/dev/sdf1" successfully created
(09:15:58) [root@r6-node02:~]$ vgcreate -s 128m myvg2 /dev/sde1 /dev/sdf1
  Volume group "myvg2" successfully created
(09:16:12) [root@r6-node02:~]$ pvs
  PV         VG       Fmt  Attr PSize   PFree  
  /dev/sdb1  myvg     lvm2 a--    9.75g   9.75g
  /dev/sdc1  myvg     lvm2 a--  200.98m 200.98m
  /dev/sde1  myvg2    lvm2 a--  199.98m 199.98m
  /dev/sdf1  myvg2    lvm2 a--    9.75g   9.75g
  /dev/vda2  VolGroup lvm2 a--    8.51g      0 
(09:16:14) [root@r6-node02:~]$ vgcfgbackup myvg2
  Volume group "myvg2" successfully backed up.
(09:16:48) [root@r6-node02:~]$ vgcfgrestore myvg2
Floating point exception (core dumped)
----------------------------------------------------------------------------



With the new version of lvm it works normally:

(09:12:13) [root@r6-node01:/etc/yum.repos.d]$ pvcreate --metadatasize 128m /dev/sdb
sdb   sdb1  
(09:12:13) [root@r6-node01:/etc/yum.repos.d]$ pvcreate --metadatasize 128m /dev/sdb
sdb   sdb1  
(09:12:13) [root@r6-node01:/etc/yum.repos.d]$ pvcreate --metadatasize 128m /dev/sdb1 
  Physical volume "/dev/sdb1" successfully created
(09:12:48) [root@r6-node01:/etc/yum.repos.d]$ vgcreate -s 128m myvg /dev/sda1 /dev/sdb1
  Volume group "myvg" (09:13:17) [root@r6-node01:/etc/yum.repos.d]$ vgcfgbackup myvg
  Volume group "myvg" successfully backed up.
successfully created
(09:13:59) [root@r6-node01:/etc/lvm/backup]$ vgcfgrestore myvg
  Restored volume group myvg
(09:14:09) [root@r6-node01:/etc/lvm/backup]$


Packages installed:

lvm2-2.02.95-10.el6.x86_64
device-mapper-1.02.74-10.el6.x86_64
kernel-2.6.32-279.el6.x86_64

Comment 6 errata-xmlrpc 2013-02-21 08:09:46 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-2013-0501.html