[libvirt] [RFC] domain xml validation for source elements

Daniel P. Berrange berrange at redhat.com
Wed Jul 22 11:48:17 UTC 2015

On Wed, Jul 22, 2015 at 01:43:12PM +0200, Boris Fiuczynski wrote:
> I ran into a problem that was caused by a missing leading slash (/) in the
> value of the file attribute of a disks source element.
> Defining the domain worked without a problem.

That's because 'virsh define' does not turn on schema validation by

> Editing the domain and trying to save it resulted in a very generic error
> message:

...but 'virsh edit' does do schema validation.

> error: XML document failed to validate against schema: Unable to validate
> doc against /usr/share/libvirt/schemas/domain.rng
> Extra element devices in interleave
> Element domain failed to validate content
> Failed. Try again? [y,n,i,f,?]:
> It took me some time to find out that the schema defines in absFilePath a
> leading slash as required for a fully qualified file path but the C code
> parsing does not require/validate it.
>   <define name="diskSourceFile">
>     ...
>     <interleave>
>       <optional>
>         <element name="source">
>           <optional>
>             <attribute name="file">
>               <ref name="absFilePath"/>
>             </attribute>
>           </optional>
>           ...
>         </element>
>       </optional>
>     </interleave>
>   </define>
>   <define name="absFilePath">
>     <data type="string">
>       <param
> name="pattern">/[a-zA-Z0-9_\.\+\-\\&"'<>/%,:]+</param>
>     </data>
>   </define>
> I tried to fix the behavior by implementing additional validation code in
> method virDomainDiskSourceParse checking for the leading slash on the
> absolute file path.
> This resulted in breaking the VMware tests (xml2vmxtest), e.g.
> 8) VMware XML-2-VMX cdrom-scsi-file -> cdrom-scsi-file
> When looking at the related test data I found:
>     <disk type='file' device='cdrom'>
>       <source file='[testing] isos/cdrom.iso'/>
>       <target dev='sda' bus='scsi'/>
>     </disk>
> Besides the fact that the file path string also contains the characters
> space, opening and closing square brackets which are not specified as valid
> characters the file path string does not have a leading slash but instead
> some kind of 'datastore' specific name.
> What is the way to approach this since I am not a VMware user?
> 1) Change the schema to include the missing characters and removing the
> requirement for the leading slash and include additional schema aligned
> validation in the parsing code (method virDomainDiskSourceParse) or
> 2) fix the VMware tests to use absolute paths only and include additional
> schema aligned validation in the parsing code (method
> virDomainDiskSourceParse).

I guess the key question is whether it is valid for VMWare to have a
source path that does not begin with a '/'. If so, then we should
change our RNG schema to not require a leading '/', avoiding the
problem you saw.

|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

More information about the libvir-list mailing list