[PATCH 3/6] conf: tighten <domainsnapshot> schema

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

One way to test this patch: s/qed/raw/ in the file
tests/domainsnapshotxml2xmlin/disk_snapshot.xml, then run
make -C tests check TESTS=domainsnapshotschematest.  Pre-patch,
the file will pass the schema, even though attempts to use that
description with virDomainSnapshotCreateXML will fail because
raw files cannot have a backing store.  Post-patch, the file
will fail virt-xml-validate.

* docs/schemas/domainsnapshot.rng (domain): Use nested grammar
to avoid restricting <domain>.
(storageFormat): Override for tighter usage.
* docs/schemas/storagecommon.rng (startupPolicy): Create a no-op
default.
* docs/schemas/domaincommon.rng (storageFormat): Cross-reference.
(startupPolicy): Move the non-trivial define...
* docs/schemas/domain.rng (startupPolicy): ...here.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 docs/schemas/domain.rng         | 15 ++++++++++++++-
 docs/schemas/domaincommon.rng   | 12 ++----------
 docs/schemas/domainsnapshot.rng | 21 +++++++++++++++++++--
 docs/schemas/storagecommon.rng  |  5 +++++
 4 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index cf0be68..41bd95b 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -1,9 +1,22 @@
 <?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="startupPolicy" combine='choice'>
+    <!-- overrides the no-op version in storagecommon.rng -->
+    <attribute name="startupPolicy">
+      <choice>
+        <value>mandatory</value>
+        <value>requisite</value>
+        <value>optional</value>
+      </choice>
+    </attribute>
+  </define>
+
 </grammar>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 7fc0cff..6c92848 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1140,16 +1140,6 @@
     </element>
   </define>

-  <define name="startupPolicy">
-    <attribute name="startupPolicy">
-      <choice>
-        <value>mandatory</value>
-        <value>requisite</value>
-        <value>optional</value>
-      </choice>
-    </attribute>
-  </define>
-
   <!--
       A disk description can be either of type file or block
       The name of the attribute on the source element depends on the type
@@ -1501,6 +1491,8 @@
     </optional>
   </define>
   <define name='storageFormat'>
+    <!-- See also domainsnapshot.rng which overrides this for a
+         smaller set of choices in snapshots -->
     <choice>
       <value>raw</value>
       <value>dir</value>
diff --git a/docs/schemas/domainsnapshot.rng b/docs/schemas/domainsnapshot.rng
index 824a186..b0ac854 100644
--- a/docs/schemas/domainsnapshot.rng
+++ b/docs/schemas/domainsnapshot.rng
@@ -5,7 +5,19 @@
     <ref name='domainsnapshot'/>
   </start>

-  <include href='domaincommon.rng'/>
+  <include href='domaincommon.rng'>
+    <!-- override storageFormat to limit to just those formats known
+         to have backing file -->
+    <define name='storageFormat'>
+      <choice>
+        <value>cow</value>
+        <value>qcow</value>
+        <value>qcow2</value>
+        <value>qed</value>
+        <value>vmdk</value>
+      </choice>
+    </define>
+  </include>

   <define name='domainsnapshot'>
     <element name='domainsnapshot'>
@@ -75,7 +87,12 @@
                 <ref name="UUID"/>
               </element>
             </element>
-            <ref name='domain'/>
+            <!-- Nested grammar ensures that any of our overrides of
+                 domaincommon defines do not impact the domain.rng
+                 usage of domaincommon.  -->
+            <grammar>
+              <include href='domain.rng'/>
+            </grammar>
           </choice>
         </optional>
         <optional>
diff --git a/docs/schemas/storagecommon.rng b/docs/schemas/storagecommon.rng
index 54cf6b4..0fa90b8 100644
--- a/docs/schemas/storagecommon.rng
+++ b/docs/schemas/storagecommon.rng
@@ -52,4 +52,9 @@
     </element>
   </define>

+  <!-- overridden in domain.rng to allow non-empty use -->
+  <define name='startupPolicy'>
+    <notAllowed/>
+  </define>
+
 </grammar>
-- 
1.9.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]