]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: set up for per-grammar overrides in schemas
authorEric Blake <eblake@redhat.com>
Mon, 14 Apr 2014 22:54:15 +0000 (16:54 -0600)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 15 Apr 2014 19:07:59 +0000 (21:07 +0200)
This patch is my first experience playing with nested grammars,
as documented in http://relaxng.org/tutorial-20011203.html#IDA3PZR.
I plan on doing more overrides in order to make the RelaxNG
grammar mirror the C code refactoring into a common
virStorageSource, but where different clients of that source do
not support the same subset of functionality.  By starting with
something fairly easy to validate, I can make sure my later
patches will be possible.

This patch adds a use of the no-op <ref
name='sourceStartupPolicy'/> to the disksnapshot definition, so
that the snapshot version of a type='file' <source> more closely
resembles the version in domaincommon.  A future patch will merge
the two files into using a common define, but this patch is
sufficient for testing that adding <source
startupPolicy='optional'/> in any of the
tests/domainsnapshotxml2xmlin/*.xml files still gets rejected
unless it occurs within the <domain> subelement, because the
definition of startupPolicy is empty outside of domain.rng.

* docs/schemas/storagecommon.rng (storageStartupPolicy)
(storageSourceExtra): Create no-op defaults.
* docs/schemas/domainsnapshot.rng (domain): Use nested grammar
to avoid restricting <domain>.
(storageSourceExtra): Create new override.
(disksnapshot): Access overrides through common names.
* docs/schemas/domaincommon.rng (disk): Access overrides through
common names.
* docs/schemas/domain.rng (storageStartupPolicy)
(storageSourceExtra): Create new overrides.

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
docs/schemas/domain.rng
docs/schemas/domaincommon.rng
docs/schemas/domainsnapshot.rng
docs/schemas/storagecommon.rng
tests/domainsnapshotxml2xmlin/disk-invalid.xml [new file with mode: 0644]

index cf0be68c27c3d39f900f3140fb628e1843f3a3fa..114b87e261f48cd222a6375a6174e0007e892476 100644 (file)
@@ -1,9 +1,21 @@
 <?xml version="1.0"?>
 <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
-  <!-- We handle only document defining a domain -->
+  <!-- Grammar for accepting a domain element, both as top level, and
+       also suitable for inclusion in domainsnapshot.rng -->
   <start>
     <ref name="domain"/>
   </start>
 
   <include href='domaincommon.rng'/>
+
+  <define name='storageStartupPolicy' combine='choice'>
+    <!-- overrides the no-op version in storagecommon.rng -->
+    <ref name='startupPolicy'/>
+  </define>
+
+  <define name='storageSourceExtra' combine='choice'>
+    <!-- overrides the no-op version in storagecommon.rng -->
+    <ref name='diskspec'/>
+  </define>
+
 </grammar>
index 59f3fdd525fef52edae66f0bfb23a52c0a84814b..df2c839e340abaf14f7e3de0e6838dfba65e337d 100644 (file)
                     </attribute>
                   </optional>
                   <optional>
-                    <ref name="startupPolicy"/>
+                    <ref name="storageStartupPolicy"/>
                   </optional>
                   <optional>
                     <ref name='devSeclabel'/>
                     </attribute>
                   </optional>
                   <optional>
-                    <ref name="startupPolicy"/>
+                    <ref name="storageStartupPolicy"/>
                   </optional>
                   <optional>
                     <ref name='devSeclabel'/>
                     <ref name="absFilePath"/>
                   </attribute>
                   <optional>
-                    <ref name="startupPolicy"/>
+                    <ref name="storageStartupPolicy"/>
                   </optional>
                   <empty/>
                 </element>
                     </attribute>
                   </optional>
                   <optional>
-                    <ref name="startupPolicy"/>
+                    <ref name="storageStartupPolicy"/>
                   </optional>
                   <optional>
                     <ref name='devSeclabel'/>
             </interleave>
           </group>
         </choice>
-        <ref name="diskspec"/>
+        <ref name="storageSourceExtra"/>
       </interleave>
     </element>
   </define>
+
   <define name="diskSourceNetwork">
     <attribute name="protocol">
       <choice>
index 644da90f9c33a2c66be2d95c1b645cd2234c35c6..bec12dbe24a14178d1a814f08e5a7147bca1e5fe 100644 (file)
                 <ref name="UUID"/>
               </element>
             </element>
-            <ref name='domain'/>
+            <!-- Nested grammar ensures that any of our overrides of
+                 storagecommon/domaincommon defines do not conflict
+                 with any domain.rng overrides.  -->
+            <grammar>
+              <include href='domain.rng'/>
+            </grammar>
           </choice>
         </optional>
         <optional>
     </choice>
   </define>
 
+  <define name='storageSourceExtra' combine='choice'>
+    <!-- overrides the no-op version in storagecommon.rng -->
+    <ref name='disksnapshotdriver'/>
+  </define>
+
   <define name='disksnapshot'>
     <element name='disk'>
       <attribute name='name'>
                         <ref name='absFilePath'/>
                       </attribute>
                     </optional>
+                    <optional>
+                      <ref name='storageStartupPolicy'/>
+                    </optional>
                     <empty/>
                   </element>
                 </optional>
-                <ref name='disksnapshotdriver'/>
+                <ref name='storageSourceExtra'/>
               </interleave>
             </group>
             <group>
                     <empty/>
                   </element>
                 </optional>
-                <ref name='disksnapshotdriver'/>
+                <ref name='storageSourceExtra'/>
               </interleave>
             </group>
             <group>
                     <ref name='diskSourceNetwork'/>
                   </element>
                 </optional>
-                <ref name='disksnapshotdriver'/>
+                <ref name='storageSourceExtra'/>
               </interleave>
             </group>
           </choice>
index 1015e8d33427b098751c5c0920e0f5b0ac98bec0..06b2f81fde59d97f410d830689c426c5b297442c 100644 (file)
     </choice>
   </define>
 
+  <define name='storageStartupPolicy'>
+    <!-- Use a combine='choice' override in client files that want to
+         add additional attributes to a <source> sub-element
+         associated with a storage source -->
+    <notAllowed/>
+  </define>
+
+  <define name='storageSourceExtra'>
+    <!-- Use a combine='choice' override in client files that want to
+         add additional elements as siblings of a <source> sub-element
+         associated with a storage source -->
+    <notAllowed/>
+  </define>
+
 </grammar>
diff --git a/tests/domainsnapshotxml2xmlin/disk-invalid.xml b/tests/domainsnapshotxml2xmlin/disk-invalid.xml
new file mode 100644 (file)
index 0000000..6d2bea4
--- /dev/null
@@ -0,0 +1,10 @@
+<domainsnapshot>
+  <name>asdf</name>
+  <description>adsf</description>
+  <disks>
+    <disk name='vda' snapshot='external'>
+      <source file='/tmp/foo' startupPolicy='optional'/>
+      <driver/>
+    </disk>
+  </disks>
+</domainsnapshot>