Red Hat Bugzilla – Bug 619826
[RFE] Need a way to determine if a particular block device is a logical volume
Last modified: 2010-11-10 16:03:14 EST
+++ This bug was initially created as a clone of Bug #619793 +++
Description of problem:
I need a robust, reliable way to determine if a particular block device is a logical volume when inspecting a guest. This rules out methods based on path name inspection, as these paths can be changed by configuration and vary between distributions.
My chosen solution to this problem is to stat every device returned by lvs(), and to stat the target device, and test if the major and minor numbers of the target appear in the list returned by lvs(). This avoid any issues relating to path names. However, it is complicated because stat() doesn't chroot, and therefore you can't stat a device node. I'm doing sh("stat...") to work round this, which is ugly.
I don't know what the best approach to this is. It could be a new is_lvm_device(dev), a change to the existing stat() api to work on device nodes, a new api to stat device nodes(), or something else.
However, I'm slightly concerned that this use case is quite esoteric. I can't think of any previous occasion using libguestfs or otherwise when I have been concerned to know whether or not a block device is a logical volume. The high-level api may be extremely under-used, meaning an implementation in virt-v2v is more appropriate.
Version-Release number of selected component (if applicable):
--- Additional comment from firstname.lastname@example.org on 2010-07-30 11:40:48 EDT ---
Patch posted upstream:
--- Additional comment from email@example.com on 2010-07-30 12:03:17 EDT ---
Matt, you'd better clone this bug for RHEL 6.
Created attachment 435600 [details]
Backport new API is_lv from upstream development branch.
This is the backported patch, with generated code.
Woudln't it be simpler to pull this from the udev database? It should know this in some way (and if it doesn't, *it* should be changed).
Bill, did you mean udev or blkid? I can't see anything in udev about
this. blkid doesn't currently contain this information either. Could be
added though, although probably not for RHEL 6.0 ...
*** Bug 620861 has been marked as a duplicate of this bug. ***
It should be simple to test this feature in guestfish. In a guest which has a logical volume called /dev/VolGroup00/LogVol00 (for example, rhel4u8-64b-pv-raw-intel), do:
guestfish -i /path/to/guest.img
><fs> is-lv /dev/VolGroup00/LogVol00
><fs> is-lv /dev/sda1
Patch is ready to go as soon as we get ACKs. If it's ACKed now,
I can do a build this evening.
We won't make Snapshot 10, so this will have to be Snapshot 11.
><fs> sparse test.img 100M
><fs> part-disk /dev/sda mbr
><fs> is-lv /dev/sda
><fs> is-lv /dev/sda1
><fs> pvcreate /dev/sda1
><fs> vgcreate vg1 /dev/sda1
><fs> lvcreate lv1 vg1 10
><fs> is-lv /dev/vg1/lv1
working as expected.
Red Hat Enterprise Linux 6.0 is now available and should resolve
the problem described in this bug report. This report is therefore being closed
with a resolution of CURRENTRELEASE. You may reopen this bug report if the
solution does not work for you.