Skip to contentSkip to conversation

Bug in LVM2 tools

linux-lvm Xuân Baldauf 2 participants 3 messages Oct 4, 2006

lore
Share & tools
lore
#0 lore raw

Hello,

I observed an obscure bug in the current LVM2 tools. Observe this:

# dd if=/dev/zero of=testfile bs=1024k count=1
1+0 records in
1+0 records out
1048576 bytes (1,0 MB) copied, 0,009037 seconds, 116 MB/s
# losetup /dev/loop4 testfile
# pvcreate /dev/loop4
  Physical volume "/dev/loop4" successfully created
# vgcreate --physicalextentsize=1k test.vg /dev/loop4
  Volume group "test.vg" successfully created
# lvcreate --name=test.lv --size=832k test.vg
  Insufficient free extents (640) in volume group test.vg: 832 required
# vgremove test.vg
  Volume group "test.vg" successfully removed
# vgcreate --physicalextentsize=1k test.vg /dev/loop4
  Volume group "test.vg" successfully created
# lvcreate --name=test.lv --size=832k test.vg
  Logical volume "test.lv" created
#

I create a file "testfile" of 1024KiB size and view it as /dev/loop4. Then I create a physical volume on /dev/loop4 and a volume group "test.vg" covering that physical volume. The metadata needs the first 192KiB. However, I cannot use the remaining 832KiB for a logical volume. This is the bug.

However, if I remove the volume group "test.vg" and once more create it again, now the remaining 832KiB are fully usable. This behaviour is inconsistent.

Analyzing the metadata after the first "vgcreate", one can see that the pe_count of the physical volume is too small. It seems that there is space reserved for a second metadata copy at the end of /dev/loop4, however, no second metadata copy is requrested at the invocation of "pvcreate".

For me, it is in particuliar important that the first "vgcreate" does not use any extra space at the end of the block device the physical volume lives on, as, in my case, the physical volume contains already data (which is to be made available as a logical volume).

ciao,
Xu�n.

#2 lore raw
In reply to Xuân Baldauf
Quoted 3 lines · Xu�n Baldauf

I observed an obscure bug in the current LVM2 tools. Observe this:

# vgcreate --physicalextentsize=1k test.vg /dev/loop4

When you have larger PEs, this bug gets lost in the rounding that gets done for alignment.

Quoted 2 lines

It seems that there is
space reserved for a second metadata copy at the end of /dev/loop4,

It's not actually related to that - it's simply a mistake in the logic that means it adjusts for the metadata areas both in pvcreate and then a second time in vgcreate. When you run vgremove it now reinstates the full disk size (a bug fix that was applied) so the subsequent vgcreate only makes a single (correct) adjustment. In short, there's confusion of responsibility between pvcreate and vgcreate for calculating the usable data area size that holds the PEs.

Alasdair

Signature · 1 line
[email protected]