[libvirt] [PATCH 2/7] Add support for storage format in FS <driver>

Daniel P. Berrange berrange at redhat.com
Fri Mar 15 16:32:39 UTC 2013


From: "Daniel P. Berrange" <berrange at redhat.com>

Extend the <driver> element in filesystem devices to
allow a storage format to be set. The new attribute
uses 'format' to reflect the storage format. This is
different from the <driver> element in disk devices
which use 'type' to reflect the storage format. THis
is because the 'type' attribute on filesystem devices
is already used for the driver backend, for which the
disk devices use the 'name' attribte. Arggggh.

Anyway for disks we have

   <driver name="qemu" type="raw"/>

And for filesystems this change means we now have

   <driver type="loop" format="raw"/>

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 docs/formatdomain.html.in     | 24 ++++++++++++++
 docs/schemas/domaincommon.rng | 73 ++++++++++++++++++++++++++++++-------------
 src/conf/domain_conf.c        | 25 ++++++++++++---
 src/conf/domain_conf.h        |  6 ++--
 src/qemu/qemu_command.c       |  3 +-
 5 files changed, 102 insertions(+), 29 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 1ef80b0..c0a65a5 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1811,6 +1811,13 @@
       <target dir='/import/from/host'/>
       <readonly/>
     </filesystem>
+    <filesystem type='file' accessmode='passthrough'>
+      <driver name='loop' type='raw'/>
+      <driver type='path' wrpolicy='immediate'/>
+      <source file='/export/to/guest.img'/>
+      <target dir='/import/from/host'/>
+      <readonly/>
+    </filesystem>
     ...
   </devices>
   ...</pre>
@@ -1902,6 +1909,23 @@
 
       </dd>
 
+      <dt><code>driver</code></dt>
+      <dd>
+        The optional driver element allows specifying further details
+        related to the hypervisor driver used to provide the filesystem.
+        <span class="since">Since 1.0.4</span>
+        <ul>
+          <li>
+            If the hypervisor supports multiple backend drivers, then
+            the <code>type</code> attribute selects the primary
+            backend driver name, while the <code>format</code>
+            attribute provides the format type. For example, LXC
+            supports a type of "loop", with a format of "raw". QEMU
+            supports a type of "path" or "handle", but no formats.
+          </li>
+        </ul>
+      </dd>
+
       <dt><code>source</code></dt>
       <dd>
         The resource on the host that is being accessed in the guest. The
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 9792065..a75c515 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -853,7 +853,7 @@
   <define name="diskspec">
     <interleave>
       <optional>
-        <ref name="driver"/>
+        <ref name="diskDriver"/>
       </optional>
       <optional>
         <ref name='diskMirror'/>
@@ -1205,7 +1205,7 @@
   <!--
       Disk may use a special driver for access.
     -->
-  <define name="driver">
+  <define name="diskDriver">
     <element name="driver">
       <choice>
         <group>
@@ -1249,13 +1249,13 @@
     <optional>
       <attribute name='type'>
         <choice>
-          <ref name='diskFormat'/>
+          <ref name='storageFormat'/>
           <value>aio</value> <!-- back-compat for 'raw' -->
         </choice>
       </attribute>
     </optional>
   </define>
-  <define name='diskFormat'>
+  <define name='storageFormat'>
     <choice>
       <value>raw</value>
       <value>dir</value>
@@ -1414,6 +1414,9 @@
           <attribute name="type">
             <value>file</value>
           </attribute>
+          <optional>
+            <ref name="diskDriver"/>
+          </optional>
           <interleave>
             <element name="source">
               <attribute name="file">
@@ -1427,6 +1430,9 @@
           <attribute name="type">
             <value>block</value>
           </attribute>
+          <optional>
+            <ref name="diskDriver"/>
+          </optional>
           <interleave>
             <element name="source">
               <attribute name="dev">
@@ -1443,6 +1449,9 @@
               <value>mount</value>
             </attribute>
           </optional>
+          <optional>
+            <ref name="diskDriver"/>
+          </optional>
           <interleave>
             <element name="source">
               <attribute name="dir">
@@ -1450,22 +1459,6 @@
               </attribute>
               <empty/>
             </element>
-            <optional>
-              <element name="driver">
-                <attribute name="type">
-                  <choice>
-                    <value>path</value>
-                    <value>handle</value>
-                  </choice>
-                </attribute>
-                <optional>
-                  <attribute name="wrpolicy">
-                    <value>immediate</value>
-                  </attribute>
-                </optional>
-                <empty/>
-              </element>
-            </optional>
           </interleave>
         </group>
         <group>
@@ -1474,6 +1467,9 @@
               <value>bind</value>
             </attribute>
           </optional>
+          <optional>
+            <ref name="diskDriver"/>
+          </optional>
           <interleave>
             <element name="source">
               <attribute name="dir">
@@ -1487,6 +1483,9 @@
           <attribute name="type">
             <value>template</value>
           </attribute>
+          <optional>
+            <ref name="diskDriver"/>
+          </optional>
           <interleave>
             <element name="source">
               <attribute name="name">
@@ -1500,6 +1499,9 @@
           <attribute name="type">
             <value>ram</value>
           </attribute>
+          <optional>
+            <ref name="diskDriver"/>
+          </optional>
           <interleave>
             <element name="source">
               <attribute name="usage">
@@ -1557,6 +1559,35 @@
       </interleave>
     </element>
   </define>
+  <define name="fsDriver">
+    <element name="driver">
+      <!-- Annoying inconsistency. 'disk' uses 'name'
+           for this kind of info, and 'type' for the
+           storage format. We need the latter too, so
+           had to invent a new attribute name -->
+      <optional>
+        <attribute name="type">
+          <choice>
+            <value>path</value>
+            <value>handle</value>
+            <value>loop</value>
+          </choice>
+        </attribute>
+      </optional>
+      <optional>
+        <attribute name="format">
+          <ref name="storageFormat"/>
+        </attribute>
+      </optional>
+      <optional>
+        <attribute name="wrpolicy">
+          <value>immediate</value>
+        </attribute>
+      </optional>
+      <empty/>
+    </element>
+  </define>
+
   <!--
       An interface description can either be of type bridge in which case
       it will use a bridging source, or of type ethernet which uses a device
@@ -3609,7 +3640,7 @@
       </attribute>
       <optional>
         <attribute name='format'>
-          <ref name='diskFormat'/>
+          <ref name='storageFormat'/>
         </attribute>
       </optional>
       <optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3278e9c..c344fca 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -329,7 +329,8 @@ VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST,
 VIR_ENUM_IMPL(virDomainFSDriverType, VIR_DOMAIN_FS_DRIVER_TYPE_LAST,
               "default",
               "path",
-              "handle")
+              "handle",
+              "loop")
 
 VIR_ENUM_IMPL(virDomainFSAccessMode, VIR_DOMAIN_FS_ACCESSMODE_LAST,
               "passthrough",
@@ -5015,6 +5016,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
     char *fsdriver = NULL;
     char *source = NULL;
     char *target = NULL;
+    char *format = NULL;
     char *accessmode = NULL;
     char *wrpolicy = NULL;
     char *usage = NULL;
@@ -5083,9 +5085,13 @@ virDomainFSDefParseXML(xmlNodePtr node,
                 target = virXMLPropString(cur, "dir");
             } else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
                 def->readonly = 1;
-            } else if (!fsdriver && xmlStrEqual(cur->name, BAD_CAST "driver")) {
-                fsdriver = virXMLPropString(cur, "type");
-                wrpolicy = virXMLPropString(cur, "wrpolicy");
+            } else if (xmlStrEqual(cur->name, BAD_CAST "driver")) {
+                if (!fsdriver)
+                    fsdriver = virXMLPropString(cur, "type");
+                if (!wrpolicy)
+                    wrpolicy = virXMLPropString(cur, "wrpolicy");
+                if (!format)
+                    format = virXMLPropString(cur, "format");
             }
         }
         cur = cur->next;
@@ -5093,12 +5099,20 @@ virDomainFSDefParseXML(xmlNodePtr node,
 
     if (fsdriver) {
         if ((def->fsdriver = virDomainFSDriverTypeTypeFromString(fsdriver)) <= 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown fs driver type '%s'"), fsdriver);
             goto error;
         }
     }
 
+    if (format) {
+        if ((def->format = virStorageFileFormatTypeFromString(format)) <= 0) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("unknown driver format value '%s'"), format);
+            goto error;
+        }
+    }
+
     if (wrpolicy) {
         if ((def->wrpolicy = virDomainFSWrpolicyTypeFromString(wrpolicy)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -5158,6 +5172,7 @@ cleanup:
     VIR_FREE(wrpolicy);
     VIR_FREE(usage);
     VIR_FREE(unit);
+    VIR_FREE(format);
 
     return def;
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 96f11ba..e4bc42b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -749,6 +749,7 @@ enum virDomainFSDriverType {
     VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT = 0,
     VIR_DOMAIN_FS_DRIVER_TYPE_PATH,
     VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE,
+    VIR_DOMAIN_FS_DRIVER_TYPE_LOOP,
 
     VIR_DOMAIN_FS_DRIVER_TYPE_LAST
 };
@@ -775,9 +776,10 @@ enum virDomainFSWrpolicy {
 
 struct _virDomainFSDef {
     int type;
-    int fsdriver;
-    int accessmode;
+    int fsdriver; /* enum virDomainFSDriverType */
+    int accessmode; /* enum virDomainFSAccessMode */
     int wrpolicy; /* enum virDomainFSWrpolicy */
+    int format; /* enum virStorageFileFormat */
     unsigned long long usage;
     char *src;
     char *dst;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 03f068c..37ddfb3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -129,7 +129,8 @@ VIR_ENUM_DECL(qemuDomainFSDriver)
 VIR_ENUM_IMPL(qemuDomainFSDriver, VIR_DOMAIN_FS_DRIVER_TYPE_LAST,
               "local",
               "local",
-              "handle");
+              "handle",
+              NULL);
 
 
 /**
-- 
1.7.11.7




More information about the libvir-list mailing list