Bug 2095758

Summary: Regression in 'startupPolicy' behaviour for disks backed by a block device
Product: Red Hat Enterprise Linux 8 Reporter: Juan Orti <jortialc>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Han Han <hhan>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.6CC: akretzsc, chwen, coli, dzheng, hhan, jdenemar, jsuchane, lmen, pkrempa, qinwang, virt-maint, xuzhang, ymankad
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-8.0.0-8.module+el8.7.0+15648+3854f89a Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2109571 (view as bug list) Environment:
Last Closed: 2022-11-08 09:20:10 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: 8.5.0
Embargoed:
Bug Depends On:    
Bug Blocks: 2109571    

Description Juan Orti 2022-06-10 13:26:50 UTC
Description of problem:
In RHEL 7, using the option startupPolicy='optional' in hard disks backed by a block device worked as expected. However, after upgrading to RHEL 8, this option is rejected.

Version-Release number of selected component (if applicable):
libvirt-8.0.0-5.module+el8.6.0+14480+c0a3aa0f.x86_64

How reproducible:
Always

Steps to Reproduce:
1. Have a RHEL 8.6 hypervisor, libvirt-8.0.0-5.module+el8.6.0+14480+c0a3aa0f.x86_64
2. Start up a VM
3. Try to attach an existing block device like /dev/sdb with startupPolicy='optional':

    # cat /tmp/disk.xml
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none'/>
      <source dev='/dev/sdb' startupPolicy='optional'/>
      <target dev='vdb' bus='virtio'/>
    </disk>

Actual results:
The attachment fails:

    # virsh attach-device guest /tmp/disk.xml --live
    error: Failed to attach device from /tmp/disk.xml
    error: XML error: 'startupPolicy' is only valid for 'file' type volume

Expected results:
- Device attachment not rejected as in RHEL 7.
- Be able to start up the VM if startupPolicy='optional' and the block device /dev/sdb doesn't exist.

Additional info:

Comment 1 Peter Krempa 2022-06-14 15:01:13 UTC
Fixed upstream by:

commit ed8984306e1cd44c424fda3ed412a4177dd7b84d
Author: Peter Krempa <pkrempa>
Date:   Tue Jun 14 14:21:33 2022 +0200

    virDomainDiskTranslateSourcePool: Fix check of 'startupPolicy' definition
    
    The check was historically done only for _TYPE_VOLUME disks, but
    refactors to allow _TYPE_VOLUME disks in the backing chain caused a
    regression where we'd reject startupPolicy also for _TYPE_BLOCK disks
    which historically worked well.
    
    Fix it by using the 'virDomainDiskDefValidateStartupPolicy' helper and
    use it only when the top level image is a _TYPE_VOLUME as in other cases
    it was already validated. This also allows _TYPE_BLOCK volumes to use
    startup policy.
    
    Fixes: 37f01262eed9f37dd5eb7de8b83edd2fea741054
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2095758
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Ján Tomko <jtomko>

commit b90d0f0a1e4ee52c828fb683c14c14e241e6fcbb
Author: Peter Krempa <pkrempa>
Date:   Tue Jun 14 14:07:47 2022 +0200

    virDomainDiskDefValidateStartupPolicy: Validate disk type better
    
    Our startup policy checkers work only for local paths, so disk sources
    such as NVMe, or vhost-user can't be used with startup policy.
    
    Unfortunately the validation did not catch these cases. Fix it.
    
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Ján Tomko <jtomko>

commit 3603a18bcec18842cedecbd8329723062b87795c
Author: Peter Krempa <pkrempa>
Date:   Tue Jun 14 13:23:29 2022 +0200

    domain_validate: Split out validation of disk startup policy
    
    Move the code into 'virDomainDiskDefValidateStartupPolicy' which will be
    later reused in the qemu driver.
    
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Ján Tomko <jtomko>

commit 9a480737c8adf92c332aa850c5269191ceb04eb9
Author: Peter Krempa <pkrempa>
Date:   Tue Jun 14 13:13:48 2022 +0200

    virDomainDiskDefValidate: Improve error messages for 'startupPolicy' checks
    
    Remove linebreak and mention the attribute name. Also prepare the error
    messages for future by substituting the type of offending access.
    
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Ján Tomko <jtomko>

Comment 5 Han Han 2022-06-16 09:35:46 UTC
Tested on libvirt-8.0.0-8.module+el8.7.0+15648+3854f89a.x86_64 qemu-kvm-6.2.0-14.module+el8.7.0+15289+26b4351e.x86_64:
1. Create a domain from the XML with: file,block,volume type; startupPolicy="optional"; non-exist disks
➜  ~ xmllint --format rh85.xml|xmllint --xpath //disk -
<disk type="file" device="disk">
      <driver name="qemu" type="qcow2"/>
      <source file="/var/lib/libvirt/images/RHEL-8.5-x86_64-latest.qcow2" startupPolicy="optional"/>
      <target dev="vda" bus="virtio"/>
    </disk><disk type="block" device="disk">
      <driver name="qemu" type="raw"/>
      <source dev="/dev/sda" startupPolicy="optional"/>
      <target dev="vdb" bus="virtio"/>
    </disk><disk type="volume" device="disk">
      <driver name="qemu" type="raw"/>
      <source pool="images" volume="test" startupPolicy="optional"/>
      <target dev="vdc" bus="virtio"/>
    </disk><disk type="file" device="disk">
      <driver name="qemu" type="qcow2"/>
      <source file="/var/lib/libvirt/images/NODISK" startupPolicy="optional"/>
      <target dev="vdd" bus="virtio"/>
    </disk><disk type="block" device="disk">
      <driver name="qemu" type="raw"/>
      <source dev="/dev/NODISK" startupPolicy="optional"/>
      <target dev="vde" bus="virtio"/>
    </disk><disk type="volume" device="disk">
      <driver name="qemu" type="raw"/>
      <source pool="images" volume="NODISK" startupPolicy="optional"/>
      <target dev="vdg" bus="virtio"/>
    </disk>

➜  ~ virsh create rh85.xml
Domain 'rh85' created from rh85.xml

2. Check the live domain XML:
➜  ~ virsh dumpxml rh85|xmllint --xpath //disk -       
<disk type="file" device="disk">
      <driver name="qemu" type="qcow2"/>
      <source file="/var/lib/libvirt/images/RHEL-8.5-x86_64-latest.qcow2" startupPolicy="optional" index="5"/>
      <backingStore/>
      <target dev="vda" bus="virtio"/>
      <alias name="virtio-disk0"/>
      <address type="pci" domain="0x0000" bus="0x04" slot="0x00" function="0x0"/>
    </disk><disk type="block" device="disk">
      <driver name="qemu" type="raw"/>
      <source dev="/dev/sda" startupPolicy="optional" index="4"/>
      <backingStore/>
      <target dev="vdb" bus="virtio"/>
      <alias name="virtio-disk1"/>
      <address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
    </disk><disk type="volume" device="disk">
      <driver name="qemu" type="raw"/>
      <source pool="images" volume="test" startupPolicy="optional" index="3"/>
      <backingStore/>
      <target dev="vdc" bus="virtio"/>
      <alias name="virtio-disk2"/>
      <address type="pci" domain="0x0000" bus="0x08" slot="0x00" function="0x0"/>
    </disk>

VM started and the domain XML is expected.

Comment 11 Han Han 2022-06-30 08:41:23 UTC
Verified on libvirt-8.0.0-8.module+el8.7.0+15648+3854f89a.x86_64 qemu-kvm-6.2.0-16.module+el8.7.0+15743+c774064d.x86_64

Start VM with startupPolicy attribute for file/block/volume type disks.
<disk type="file" device="disk">
      <driver name="qemu" type="qcow2"/>
      <source file="/var/lib/libvirt/images/RHEL-8.5-x86_64-latest.qcow2" startupPolicy="optional"/>
      <target dev="vda" bus="virtio"/>
      <address type="pci" domain="0x0000" bus="0x04" slot="0x00" function="0x0"/>
    </disk><disk type="volume" device="disk">
      <driver name="qemu" type="raw"/>
      <source pool="netfs-gluster" volume="vol1" startupPolicy="optional"/>
      <target dev="vdb" bus="virtio"/>
      <address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
    </disk><disk type="block" device="disk">
      <driver name="qemu" type="raw"/>
      <source dev="/dev/sda" startupPolicy="optional"/>
      <target dev="vdc" bus="virtio"/>
      <address type="pci" domain="0x0000" bus="0x08" slot="0x00" function="0x0"/>
    </disk><disk type="volume" device="disk">
      <driver name="qemu" type="raw"/>
      <source pool="mapth" volume="dm-0" startupPolicy="optional"/>
      <target dev="vdd" bus="virtio"/>
      <address type="pci" domain="0x0000" bus="0x09" slot="0x00" function="0x0"/>
    </disk><disk type="volume" device="disk">
      <driver name="qemu" type="raw"/>
      <source pool="iscsi" volume="unit:0:0:0" startupPolicy="optional"/>
      <target dev="vde" bus="virtio"/>
      <address type="pci" domain="0x0000" bus="0x0a" slot="0x00" function="0x0"/>
    </disk>

VM started
PASS

Comment 17 errata-xmlrpc 2022-11-08 09:20:10 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 (Low: virt:rhel and virt-devel:rhel security, 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/RHSA-2022:7472