Daniel P. Berrange schreef:
and a volume can be either a file
or a physical device, so fixing it to be 'phy:' is not correct.
How can we know if the volume is a file or a device?

virStorageVolGetInfo() will tell you via the 'info' field of the struct
it fills

As attached. I updated the 'typ' option.

We also need to apply the reverse mapping when generating the XML. eg
do a virStorageVolLookupByPath() to discover the volume/pool.
Mmm... that sounds not trivial... (I mean duplicate wise).

This is true - until we merge all the XML processing for drivers together
there will be a non-trivial bit of duplication

Not done yet... and I prefer the last thing to be a different patch.


Stefan
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 02ca509..8e2a7b6 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -344,7 +344,7 @@
     <dl>
       <dt><code>disk</code></dt>
       <dd>The <code>disk</code> element is the main container for describing
-       disks. The <code>type</code> attribute is either "file" or "block"
+       disks. The <code>type</code> attribute is either "file", "block" or 
"pool"
        and refers to the underlying source for the disk. The optional
        <code>device</code> attribute indicates how the disk is to be exposed
        to the guest OS. Possible values for this attribute are "floppy", "disk"
@@ -354,7 +354,11 @@
       <dd>If the disk <code>type</code> is "file", then the <code>file</code> 
attribute
        specifies the fully-qualified path to the file holding the disk. If the 
disk
        <code>type</code> is "block", then the <code>dev</code> attribute 
specifies
-       the path to the host device to serve as the disk. <span 
class="since">Since 0.0.3</span></dd>
+       the path to the host device to serve as the disk. If the disk 
<code>type</code>
+    is "pool", then the <code>pool</code> and <code>volume</code> specify the
+    virtual location of the disk, the path is automatically resolved if the 
pool
+    and the volume exist.
+    <span class="since">Since 0.0.3</span></dd>
       <dt><code>target</code></dt>
       <dd>The <code>target</code> element controls the bus / device under 
which the
        disk is exposed to the guest OS. The <code>dev</code> attribute 
indicates
diff --git a/src/xml.c b/src/xml.c
index 22dc211..598bfb3 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -1300,6 +1300,8 @@ virDomainParseXMLDiskDesc(virConnectPtr conn, xmlNodePtr 
node,
             typ = 0;
         else if (xmlStrEqual(type, BAD_CAST "block"))
             typ = 1;
+        else if (xmlStrEqual(type, BAD_CAST "pool"))
+            typ = 2;
         xmlFree(type);
     }
     device = xmlGetProp(node, BAD_CAST "device");
@@ -1309,11 +1311,32 @@ virDomainParseXMLDiskDesc(virConnectPtr conn, 
xmlNodePtr node,
         if (cur->type == XML_ELEMENT_NODE) {
             if ((source == NULL) &&
                 (xmlStrEqual(cur->name, BAD_CAST "source"))) {
-
                 if (typ == 0)
                     source = xmlGetProp(cur, BAD_CAST "file");
-                else
+                else if (typ == 1)
                     source = xmlGetProp(cur, BAD_CAST "dev");
+                else if (typ == 2) {
+                    xmlChar *pool   = xmlGetProp(cur, BAD_CAST "pool");
+                    xmlChar *volume = xmlGetProp(cur, BAD_CAST "volume");
+                    if (pool != NULL && volume != NULL) {
+                        virStoragePoolPtr virPool;
+                        virPool = virStoragePoolLookupByName(conn, (const char 
*) pool);
+                        if (virPool != NULL) {
+                            virStorageVolPtr virVol;
+                            virVol = virStorageVolLookupByName(virPool, (const 
char *) volume);
+                            if (virVol != NULL) {
+                                virStorageVolInfo info;
+                                if (virStorageVolGetInfo(virVol, &info) == 0) {
+                                    source = BAD_CAST 
virStorageVolGetPath(virVol);
+                                    /* We set the type to the 'native' type */
+                                    typ = info.type;
+                                }
+                            }
+                        }
+                    }
+                    xmlFree(pool);
+                    xmlFree(volume);
+                }
             } else if ((target == NULL) &&
                        (xmlStrEqual(cur->name, BAD_CAST "target"))) {
                 target = xmlGetProp(cur, BAD_CAST "dev");
@@ -1411,7 +1434,7 @@ virDomainParseXMLDiskDesc(virConnectPtr conn, xmlNodePtr 
node,
                 virBufferVSprintf(buf, "(uname 'phy:%s')", source);
             else
                 virBufferVSprintf(buf, "(uname 'phy:/dev/%s')", source);
-        }
+        } 
     }
     if (ro == 1)
         virBufferAddLit(buf, "(mode 'r')");
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to