<div dir="ltr">On Fri, May 31, 2013 at 4:17 PM, Richard W.M. Jones <span dir="ltr"><<a href="mailto:rjones@redhat.com" target="_blank">rjones@redhat.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On Fri, May 31, 2013 at 04:03:32PM +0800, Qiu Yu wrote:<br>


> Actually I'm looking into an issue with OpenStack / Libvirt manipulating<br>
> LVM as an image backend. When the logical volume is created, udev rules<br>
> will set the ownership to root:disk. After libvirt actually starting an<br>
> instance, device node ownership will change to qemu:qemu by libvirt. Then,<br>
> if you stop an instance, the device node ownership will change back to<br>
> root:root. Seems there's some inconsistency here.<br>
<br>
</div>This is actually a well-known bug in libvirt.<br>
<br>
<a href="https://bugzilla.redhat.com/show_bug.cgi?id=796072" target="_blank">https://bugzilla.redhat.com/show_bug.cgi?id=796072</a><br>
(marked as a duplicate of a private bug 547546 for some reason --<br>
I will try to get this made non-private)<br>
<br>
You can turn off libvirt's ownership management (set dynamic_ownership<br>
= 0 in /etc/libvirt/qemu.conf) however this will cause other problems.<br>
I don't think there is a proper solution to this yet.<br>
<div class=""><div class="h5"><br>
Rich.<br><br></div></div></blockquote><div><br></div><div style>Richard,</div><div style><br></div><div style>Really thanks for the advice. But seems I'm hitting another permission issue regarding libguestfs and LVM image.</div>

<div style><br></div><div style>Following code snippet is stripped from OpenStack data injection logic. Running as non-root user (stack) will report "guestfs_launch failed" error, and the debug message shows it failed to open the LVM device node.</div>

<div style><br></div><div style>I've already set up the group permission ('disk' and 'fuse') for the 'stack' user. Could you shed some lights of what else should I look into? Thanks!</div><div style>

<br></div><div><div>$ cat test.py </div><div>import guestfs</div><div>g = guestfs.GuestFS()</div><div>g.add_drive_opts("/dev/xenvg/123", format="qcow2")</div><div>g.launch()</div></div><div><br></div>
<div>
<div>$ id</div><div>uid=501(stack) gid=504(stack) groups=504(stack),6(disk),498(fuse)</div></div><div><br></div><div><div>$ ll /dev/mapper/xenvg-123 </div><div>lrwxrwxrwx 1 root root 7 May 31 17:16 /dev/mapper/xenvg-123 -> ../dm-2</div>

<div>$ ll /dev/dm-2             </div><div>brw-rw---- 1 root disk 253, 2 May 31 18:06 /dev/dm-2</div></div><div><br></div><div style>$ python test.py <br></div><div style><div>libguestfs: trace: add_drive_opts "/dev/xenvg/123" "format:qcow2"</div>

<div>libguestfs: trace: add_drive_opts = 0</div><div>libguestfs: trace: launch</div><div>libguestfs: trace: launch = -1 (error)</div><div>Traceback (most recent call last):</div><div>  File "test.py", line 4, in <module></div>

<div>    g.launch()</div><div>  File "/usr/lib/python2.6/site-packages/guestfs.py", line 244, in launch</div><div>    return libguestfsmod.launch (self._o)</div><div>RuntimeError: guestfs_launch failed, see earlier error messages</div>

<div>libguestfs: trace: close</div></div><div><br></div><div>$ export LIBGUESTFS_DEBUG=1<br></div><div><div>$ python test.py           </div><div>libguestfs: new guestfs handle 0x26a8250</div><div>libguestfs: trace: add_drive_opts "/dev/xenvg/123" "format:qcow2"</div>

<div>libguestfs: trace: add_drive_opts = 0</div><div>libguestfs: trace: launch</div><div>libguestfs: [00000ms] febootstrap-supermin-helper --verbose -f checksum '/usr/lib64/guestfs/supermin.d' x86_64</div><div>supermin helper [00000ms] whitelist = (not specified), host_cpu = x86_64, kernel = (null), initrd = (null), appliance = (null)</div>

<div>supermin helper [00000ms] inputs[0] = /usr/lib64/guestfs/supermin.d</div><div>checking modpath /lib/modules/2.6.32-358.6.2.ns8.el6.x86_64 is a directory</div><div>picked vmlinuz-2.6.32-358.6.2.ns8.el6.x86_64 because modpath /lib/modules/2.6.32-358.6.2.ns8.el6.x86_64 exists</div>

<div>supermin helper [00000ms] finished creating kernel</div><div>supermin helper [00000ms] visiting /usr/lib64/guestfs/supermin.d</div><div>supermin helper [00000ms] visiting /usr/lib64/guestfs/supermin.d/base.img</div>
<div>
supermin helper [00000ms] visiting /usr/lib64/guestfs/supermin.d/daemon.img</div><div>supermin helper [00000ms] visiting /usr/lib64/guestfs/supermin.d/hostfiles</div><div>supermin helper [00015ms] visiting /usr/lib64/guestfs/supermin.d/init.img</div>

<div>supermin helper [00015ms] adding kernel modules</div><div>supermin helper [00080ms] finished creating appliance</div><div>libguestfs: [00083ms] begin testing qemu features</div><div>libguestfs: [00097ms] finished testing qemu features</div>

<div>libguestfs: accept_from_daemon: 0x26a8250 g->state = 1</div><div>[00098ms] /usr/libexec/qemu-kvm \</div><div>    -global virtio-blk-pci.scsi=off \</div><div>    -drive file=/dev/xenvg/123,cache=off,format=qcow2,if=virtio \</div>

<div>    -nodefconfig \</div><div>    -enable-kvm \</div><div>    -nodefaults \</div><div>    -nographic \</div><div>    -m 500 \</div><div>    -no-reboot \</div><div>    -device virtio-serial \</div><div>    -serial stdio \</div>

<div>    -chardev socket,path=/tmp/libguestfssaaw6T/guestfsd.sock,id=channel0 \</div><div>    -device virtserialport,chardev=channel0,name=org.libguestfs.channel.0 \</div><div>    -kernel /var/tmp/.guestfs-501/kernel.30285 \</div>

<div>    -initrd /var/tmp/.guestfs-501/initrd.30285 \</div><div>    -append 'panic=1 console=ttyS0 udevtimeout=300 no_timer_check acpi=off printk.time=1 cgroup_disable=memory selinux=0 guestfs_verbose=1 TERM=screen-bce ' \</div>

<div>    -drive file=/var/tmp/.guestfs-501/root.30285,snapshot=on,if=virtio,cache=unsafeqemu-kvm: -drive file=/dev/xenvg/123,cache=off,format=qcow2,if=virtio: could not open disk image /dev/xenvg/123: Invalid argument</div>

<div>libguestfs: child_cleanup: 0x26a8250: child process died</div><div>libguestfs: trace: launch = -1 (error)</div><div>Traceback (most recent call last):</div><div>  File "test.py", line 4, in <module></div>

<div>    g.launch()</div><div>  File "/usr/lib/python2.6/site-packages/guestfs.py", line 244, in launch</div><div>    return libguestfsmod.launch (self._o)</div><div>RuntimeError: guestfs_launch failed, see earlier error messages</div>

<div>libguestfs: trace: close</div><div>libguestfs: closing guestfs handle 0x26a8250 (state 0)</div></div><div><br></div><div>--</div><div style>Qiu Yu </div></div><br></div></div>