Description of problem: When setting a block threshold (virsh domblkthreshold) for an image in the backing chain and then triggering it, libvirt will report wrong Version-Release number of selected component (if applicable): How reproducible: Steps to Reproduce: 1. In an extra terminal run: 'virsh event --all --loop' 2. Create a VM with disk having at least 2 images in a backing chain and the 'index' of the bottom not being '1'. (e.g. by adding an extra disk prior to it): <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/tmp/copysrc.1594817277' index='6'/> <backingStore type='file' index='2'> <format type='raw'/> <source file='/tmp/copysrc'/> <backingStore/> </backingStore> <target dev='vda' bus='virtio'/> <alias name='virtio-disk0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/> </disk> (backing image of vda has index '2') 3. register a threshold: virsh domblkthreshold --domain upstream vda[2] 1 4. run a block job which will write to the backing image triggering the threshold: virsh blockcommit upstream vda --active Actual results: event 'block-threshold' for domain upstream-bj: dev: vda[1](/tmp/copysrc) 1 524287 Expected results: event 'block-threshold' for domain upstream-bj: dev: vda[2](/tmp/copysrc) 1 983039 Additional info: Happens when -blockdev is used.
Fixed upstream by: commit fd2369d02654c20c4a262407c563b0f5c7c31d68 Author: Peter Krempa <pkrempa> Date: Wed Jul 15 12:33:34 2020 +0200 virStorageSourceFindByNodeName: Remove unused 'idx' argument None of the callers actually use it. Signed-off-by: Peter Krempa <pkrempa> Reviewed-by: Eric Blake <eblake> commit db712b0673db2afd39ab11d660657b6a1240b2db Author: Peter Krempa <pkrempa> Date: Wed Jul 15 12:29:34 2020 +0200 qemuDomainDiskLookupByNodename: Remove unused 'idx' All callers pass NULL as the value. Remove the argument. Signed-off-by: Peter Krempa <pkrempa> Reviewed-by: Eric Blake <eblake> commit 877d705ccf9e515a7506a2d326227251c4e272c7 Author: Peter Krempa <pkrempa> Date: Wed Jul 15 13:06:44 2020 +0200 virDomainSetBlockThreshold: Clarify values of @dev the event is fired for Top level image may get two events, one with the disk target (vda) and one with disk target with index (vda[3]) if the top level image has an index. Signed-off-by: Peter Krempa <pkrempa> Reviewed-by: Eric Blake <eblake> commit c414ab00e288535596010d7cc4174d6e40328408 Author: Peter Krempa <pkrempa> Date: Wed Jul 15 11:51:17 2020 +0200 qemuProcessHandleBlockThreshold: Report correct indexes The index returned by qemuDomainDiskLookupByNodename is the position in the backing chain rather than the index we report in the XML. Since with -blockdev they differ now and additionally the disk source also has an index we need to fix the 'threshold' events we report: 1) If it's the top level image we must always trigger the event without any suffix as we did until now 2) We must report the correct index 3) We must report the correct index also for the top level image, when blockdev is used. This means that we need to potentially emit 2 events, one for the device without the index and then when blockdev is used and the top level image has an index we must do it also with the index. This will fix it for blockdev cases, while also not removing previous semantics. https://bugzilla.redhat.com/show_bug.cgi?id=1857204 Signed-off-by: Peter Krempa <pkrempa> Reviewed-by: Eric Blake <eblake> commit 48b7c33cc7fb46af398b7e0aa3d50f05d2f1321b Author: Peter Krempa <pkrempa> Date: Wed Jul 15 12:01:39 2020 +0200 qemuDomainDiskBackingStoreGetName: Eliminate temp variable We can return the formatted string directly. Signed-off-by: Peter Krempa <pkrempa> Reviewed-by: Eric Blake <eblake> commit 4a19b7b83251f2f6e02561ad58374617ac2e7e3e Author: Peter Krempa <pkrempa> Date: Wed Jul 15 12:19:35 2020 +0200 qemuDomainDiskBackingStoreGetName: Remove unused argument Signed-off-by: Peter Krempa <pkrempa> Reviewed-by: Eric Blake <eblake> commit 794d7d97d8d98179b2e90baca9cf56b232f65e99 Author: Peter Krempa <pkrempa> Date: Wed Jul 15 13:02:24 2020 +0200 virDomainSetBlockThreshold: Document values of '@dev' better Mention where to obtain the index and how it's treated. Signed-off-by: Peter Krempa <pkrempa> Reviewed-by: Eric Blake <eblake>
Test with libvirt-6.6.0-2.module+el8.3.0+7567+dc41c0a9.x86_64 Result is: PASS Steps: 1. create a disk only snapshot for vm1, which having 2 disks = [vda, vdb] [root@dell-per730-67 /]# virsh snapshot-create-as vm1 snap1 --disk-only Domain snapshot snap1 created [root@dell-per730-67 /]# virsh dumpxml vm1 | awk '/<disk/,/<\/disk/' <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/var/lib/libvirt/images/jeos-27-x86_64.snap1' index='3'/> <backingStore type='file' index='2'> <format type='qcow2'/> <source file='/var/lib/libvirt/images/jeos-27-x86_64.qcow2'/> <backingStore/> </backingStore> <target dev='vda' bus='virtio'/> <alias name='virtio-disk0'/> <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/var/lib/libvirt/images/vdb.snap1' index='4'/> <backingStore type='file' index='1'> <format type='qcow2'/> <source file='/var/lib/libvirt/images/vdb.qcow2'/> <backingStore/> </backingStore> <target dev='vdb' bus='virtio'/> <alias name='virtio-disk1'/> <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/> </disk> 2. set a block threshold for vda[2] [root@dell-per730-67 /]# virsh domblkthreshold --domain vm1 vda[2] 1 3. create some data in vda active layer image: [root@localhost ~]# dd if=/dev/urandom of=/tmp/file bs=1 count=100; sync 100+0 records in 100+0 records out 100 bytes copied, 0.0010502 s, 95.2 kB/s 4. in another terminal, monitor virsh events: [root@dell-per730-67 ~]# virsh event vm1 --all --loop 5. back to original terminal, start a blockcommit job for vda [root@dell-per730-67 /]# virsh blockcommit vm1 vda --active Active Block Commit started 6. go to the monitor terminal, the block-threshold event contains correct vda index=2 [root@dell-per730-67 ~]# virsh event vm1 --all --loop setlocale: No such file or directory event 'block-threshold' for domain vm1: dev: vda[2](/var/lib/libvirt/images/jeos-27-x86_64.qcow2) 1 65535
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 (virt:8.3 bug fix and enhancement update), 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://access.redhat.com/errata/RHBA-2020:5137