Bug 1341415

Summary: 'virsh event' can not capture disk-change events
Product: Red Hat Enterprise Linux 7 Reporter: Yanqiu Zhang <yanqzhan>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.3CC: dyuan, fjin, mzhan, pkrempa, rbalakri, yafu, yanqzhan, zpeng
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-2.0.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-03 18:46:09 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:

Description Yanqiu Zhang 2016-06-01 03:11:20 UTC
Description of problem:
'virsh event' can not capture disk-change events

Version-Release number of selected component (if applicable):
libvirt-1.3.4-1.el7.x86_64
qemu-kvm-rhev-2.6.0-4.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Edit the guest  xml with optional startupPolicy,(rhel7.1.qcow2-non is a non-exist disk).
   ...
<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/rhel7.1.qcow2-non' startupPolicy='optional'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
.....
2.Open the second terminal, run the 'event-test.py' python script to catch the event
# python /usr/share/doc/libvirt-python-1.3.4/examples/event-test.py qemu:///system
Using uri:qemu:///system    
3.Open third terminal, run the 'virsh event' command to catch the events
#virsh event --all --loop     
4.Start the guest :
#virsh start testvm
5. Check log about disk-change in the libvirtd.log:
#cat /var/log/libvirt/libvirtd.log | grep -i change
2016-05-31 09:41:32.247+0000: 513: debug : udevEventHandleCallback:1548 : udev action: 'change'
2016-05-31 09:41:36.691+0000: 518: info : virObjectNew:202 : OBJECT_NEW: obj=0x7fdc30001010 classname=virDomainEventDiskChange
2016-05-31 09:41:36.691+0000: 518: debug : virDomainEventDiskChangeDispose:474 : obj=0x7fdc30001010
2016-05-31 09:41:36.970+0000: 513: debug : udevEventHandleCallback:1548 : udev action: 'change'

Actual results:
No disk-change events show in the 2nd terminal & 3rd terminal.

Expected results:
'virsh event' should be able to capture disk-change events:
(2nd terminal) # python /usr/share/doc/libvirt-python-1.2.15/examples/event-test.py qemu:///system
Using uri:qemu:///system
myDomainEventDiskChangeCallback: Domain testvm(4) disk change oldSrcPath: /var/lib/libvirt/images/rhel7.1.qcow2-non newSrcPath: None devAlias: virtio-disk0 reason: 1
(3rd terminal):# virsh events --all --loop
event 'disk-change' for domain testvm disk virtio-disk0: /var/lib/libvirt/images/rhel7.1.qcow2-non -> <null>: dropped

Additional info:
1.It works well with libvirt-1.2.17-13.el7.x86_64.

Comment 2 Peter Krempa 2016-06-08 06:23:39 UTC
Fixed upstream:

commit 9cda91d6f6b887c6f06868f4d2fb16c288ae20d5
Author: Peter Krempa <pkrempa>
Date:   Thu Jun 2 15:32:00 2016 +0200

    qemu: process: Call disk startup policy check after cloning domain def
    
    In commit 1e38ef72 the disk startup policy check was moved prior to the
    call to virDomainObjSetDefTransient which dropped the disk from the
    config rather than the def to be started which is a bug.
    
    Additionally we'd not report the disk change event for this since the
    disk aliases were not set at that point.
    
    Finally 'volume' based disks would not work with startup policy too.
    
    Fix it by moving it back after the definition is copied, aliases are
    assigned and disk sources are translated.

Comment 4 yafu 2016-07-06 06:08:30 UTC
Reproduced with libvirt-1.3.4-1.el7.x86_64.
steps are as comment 0.

Verify pass with libvirt-2.0.0-1.el7.x86_64.

Test steps:
1.Edit the guest xml with optional startupPolicy,(no-disk.qcow2 is a non-exist disk).
   ...
<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/no-disk.qcow2' startupPolicy='optional'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
.....


2.Open the second terminal, run the 'event-test.py' python script to catch the events
# python /usr/share/doc/libvirt-python-2.0.0/examples/event-test.py qemu:///system
Using uri:qemu:///system  
 
3.Open third terminal, run the 'virsh event' command to catch the events
#virsh event --all --loop 
    
4.Start the guest :
#virsh start rhel7.3

5.Check the output in the second terminal, can see the disk-chanage event:
 myDomainEventDiskChangeCallback: Domain rhel7.3(123) disk change oldSrcPath: /var/lib/libvirt/images/no-disk.qcow2 newSrcPath: None devAlias: virtio-disk1 reason: 1

6.Check the output in the third terminal,also can see the disk-change event:
event 'disk-change' for domain rhel7.3 disk virtio-disk1: /var/lib/libvirt/images/no-disk.qcow2 -> <null>: dropped

7.Also test cdrom/floppy with 'file' type, also can see the disk-change event.

Comment 6 errata-xmlrpc 2016-11-03 18:46:09 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.

https://rhn.redhat.com/errata/RHSA-2016-2577.html