Bug 1960993

Summary: disk with storage slice with 0 offset doesn't conform to XML schema
Product: Red Hat Enterprise Linux 9 Reporter: zhentang <zhetang>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED CURRENTRELEASE QA Contact: zhentang <zhetang>
Severity: low Docs Contact:
Priority: unspecified    
Version: 9.0CC: hhan, jdenemar, meili, pkrempa, virt-maint, xuzhang
Target Milestone: betaKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-7.4.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-12-07 21:57:54 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: 7.4.0
Embargoed:

Description zhentang 2021-05-17 01:33:56 UTC
Description of problem:


Version-Release number of selected component (if applicable):
libvirt 7.0.0

How reproducible:
100%

Steps to Reproduce:
1.prepare guest xml with
...
<disk type="file" device="disk">
  <driver name="qemu" type="raw" copy_on_read="off" cache="none" discard="ignore" detect_zeroes="on" io="native"/>
  <source file="/tmp/disk-raw">
    <slices>
      <slice type="storage" offset="0" size="104857600"/>
    </slices>
  </source>
  <backingStore/>
  <target dev="sdb" bus="scsi"/>
  <alias name="ua-slices"/>
  <iotune>
    <total_bytes_sec>10000000</total_bytes_sec>
    <group_name>slice</group_name>
  </iotune>
</disk>
...
2. virt-xml-validate tztest.xml
Relax-NG validity error : Extra element devices in interleave
tztest.xml:57: element devices: Relax-NG validity error : Element domain failed to validate content
tztest.xml fails to validate

3. remove slices part and then pass the validate



Actual results:
failed to validate with slices

Expected results:
should successfully pass the validate with slices

Additional info:

Comment 1 Peter Krempa 2021-05-17 07:19:57 UTC
The actual XML problem is that 'offset' is 0:

 error: value of attribute "offset" is invalid; must be an integer greater than or equal to 1

I need to check whether the rest of the code properly supports offset 0 though before fixing the schema.

Comment 2 Peter Krempa 2021-06-01 08:05:03 UTC
Fixed upstream:

commit fac773fab93dc526513d7ced40e1d685e193705c
Author: Peter Krempa <pkrempa>
Date:   Fri May 21 14:53:43 2021 +0200

    schema: Allow '0' offset for a <slice> of <disk>
    
    Using slice to cut off the end of the image is a perfectly vaid
    configuration. Use 'unsignedInt' instead of 'positiveInteger' for the
    'offset' attribute in the XML schema and modify one test case to cover
    this use case.
    
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1960993
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Pavel Hrdina <phrdina>

v7.3.0-264-gfac773fab9

Comment 6 zhentang 2021-06-23 03:34:49 UTC
libvirtd 7.4.0-1.el9
qemu-kvm 6.0.0-2.el9
=========================================
verified

bug-check.xml
...
<disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='none' io='native' copy_on_read='off' discard='ignore' detect_zeroes='on'/>
      <source file='/tmp/disk-raw'>
        <slices>
          <slice type='storage' offset='0' size='104857600'/>
        </slices>
      </source>
      <backingStore/>
      <target dev='sdb' bus='scsi'/>
      <iotune>
        <total_bytes_sec>10000000</total_bytes_sec>
        <group_name>slice</group_name>
      </iotune>
      <alias name='ua-slices'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
...

#virt-xml-validate ~/bug_check.xml
/root/bug_check.xml validates
# virsh define ~/bug_check.xml
Domain 'tztest_ins_me' defined from /root/bug_check.xml