]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: rbd: Implement support for passing config file option
authorPeter Krempa <pkrempa@redhat.com>
Tue, 11 Nov 2014 16:31:24 +0000 (17:31 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 21 Nov 2014 13:37:03 +0000 (14:37 +0100)
To be able to express some use cases of the RBD backing with libvirt, we
need to be able to specify a config file for the RBD client to qemu as
that is one of the commonly used options.

docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/qemu/qemu_command.c
src/util/virstoragefile.c
src/util/virstoragefile.h
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd.args
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd.xml

index 4ad444413f079d36a5bfc2a221c13b84c9d9a653..48b1a7f5347bd29fba55c42fdf9f5d0ee8672112 100644 (file)
       &lt;source protocol="rbd" name="image_name2"&gt;
         &lt;host name="hostname" port="7000"/&gt;
         &lt;snapshot name="snapname"/&gt;
+        &lt;config file="/path/to/file"/&gt;
       &lt;/source&gt;
       &lt;target dev="hdc" bus="ide"/&gt;
       &lt;auth username='myuser'&gt;
             source for storage protocols.
             Supported for 'rbd' <span class="since">since 1.2.11 (QEMU only).</span>
           </dd>
+          <dt><code>config</code></dt>
+          <dd>
+            The <code>file</code> attribute for the <code>config</code> element
+            provides a fully qualified path to a configuration file to be
+            provided as a parameter to the client of a networked storage
+            protocol. Supported for 'rbd' <span class="since">since 1.2.11
+            (QEMU only).</span>
+          </dd>
         </dl>
 
         <p>
index 539602e768de643b8915e59d20086415e6f426de..ae5c253a63457153bdefaf6a945ce07c1fe2c00b 100644 (file)
             <empty/>
           </element>
         </optional>
+        <optional>
+          <element name="config">
+            <attribute name="file">
+              <ref name="absFilePath"/>
+            </attribute>
+            <empty/>
+          </element>
+        </optional>
         <empty/>
       </element>
     </interleave>
index e225296faadb99bd2d8021f3c0775bcc3deb888f..f1c2f5fec2aa0942d62ee5810495b328e9fcd3d0 100644 (file)
@@ -3169,7 +3169,8 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
     if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
         virDomainDiskDefPtr disk = dev->data.disk;
 
-        /* internal snapshots are currently supported only with rbd: */
+        /* internal snapshots and config files are currently supported
+         * only with rbd: */
         if (virStorageSourceGetActualType(disk->src) != VIR_STORAGE_TYPE_NETWORK &&
             disk->src->protocol != VIR_STORAGE_NET_PROTOCOL_RBD) {
             if (disk->src->snapshot) {
@@ -3178,6 +3179,13 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
                                  "only with 'rbd' disks"));
                 return -1;
             }
+
+            if (disk->src->configFile) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("<config> element is currently supported "
+                                 "only with 'rbd' disks"));
+                return -1;
+            }
         }
     }
 
@@ -5395,6 +5403,9 @@ virDomainDiskSourceParse(xmlNodePtr node,
         /* snapshot currently works only for remote disks */
         src->snapshot = virXPathString("string(./snapshot/@name)", ctxt);
 
+        /* config file currently only works with remote disks */
+        src->configFile = virXPathString("string(./config/@file)", ctxt);
+
         if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0)
             goto cleanup;
         break;
@@ -16167,7 +16178,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
 
             VIR_FREE(path);
 
-            if (src->nhosts == 0 && !src->snapshot) {
+            if (src->nhosts == 0 && !src->snapshot && !src->configFile) {
                 virBufferAddLit(buf, "/>\n");
             } else {
                 virBufferAddLit(buf, ">\n");
@@ -16193,6 +16204,9 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
                 virBufferEscapeString(buf, "<snapshot name='%s'/>\n",
                                       src->snapshot);
 
+                virBufferEscapeString(buf, "<config file='%s'/>\n",
+                                      src->configFile);
+
                 virBufferAdjustIndent(buf, -2);
                 virBufferAddLit(buf, "</source>\n");
             }
index 555f4da0a74b3dac28d033fdffc82baf8a1abf01..cbdef9c36e7ed22368ba3ef64a7f62a3f57a07de 100644 (file)
@@ -3013,6 +3013,9 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src,
                 }
             }
 
+            if (src->configFile)
+                virBufferEscape(&buf, '\\', ":", ":conf=%s", src->configFile);
+
             if (virBufferCheckError(&buf) < 0)
                 goto cleanup;
 
index b0baf9561a4ac41882f121a84bb19242ed987c87..c4242516ec88e59377de9f5d5b5bd22564d45e5a 100644 (file)
@@ -1849,6 +1849,7 @@ virStorageSourceCopy(const virStorageSource *src,
         VIR_STRDUP(ret->relPath, src->relPath) < 0 ||
         VIR_STRDUP(ret->backingStoreRaw, src->backingStoreRaw) < 0 ||
         VIR_STRDUP(ret->snapshot, src->snapshot) < 0 ||
+        VIR_STRDUP(ret->configFile, src->configFile) < 0 ||
         VIR_STRDUP(ret->compat, src->compat) < 0)
         goto error;
 
@@ -2349,6 +2350,10 @@ virStorageSourceParseRBDColonString(const char *rbdstr,
             }
         }
 
+        if (STRPREFIX(p, "conf=") &&
+            VIR_STRDUP(src->configFile, p + strlen("conf=")) < 0)
+            goto error;
+
         p = next;
     }
     VIR_FREE(options);
index e0ccd446403bb114a157669e8094b81c7a5239d2..e05b8438b45004d0ff1e9ac6620fc4fe778f8bb3 100644 (file)
@@ -239,6 +239,8 @@ struct _virStorageSource {
     int protocol; /* virStorageNetProtocol */
     char *volume; /* volume name for remote storage */
     char *snapshot; /* for storage systems supporting internal snapshots */
+    char *configFile; /* some storage systems use config file as part of
+                         the source definition */
     size_t nhosts;
     virStorageNetHostDefPtr hosts;
     virStorageSourcePoolDefPtr srcpool;
index e4f138990dd85bed5d680579f86b61660bfa7b99..f634e8d45155420ec56c463c73aec5e97786f55b 100644 (file)
@@ -9,4 +9,6 @@ mon3.example.org\:6322,if=virtio,format=raw' \
 -drive 'file=rbd:pool/image@foo:auth_supported=none:\
 mon_host=mon1.example.org\:6321\;mon2.example.org\:6322\;\
 mon3.example.org\:6322,if=virtio,format=raw' \
+-drive file=rbd:pool/image@foo:auth_supported=none:\
+conf=/blah/test.conf,if=virtio,format=raw \
 -net none -serial none -parallel none
index f6accd83d724ce3d28a65a458d46ba24cee21a9c..9ffe633ce265cbd25da539a73ecf4d17224dbac4 100644 (file)
       </source>
       <target dev='vdc' bus='virtio'/>
     </disk>
+    <disk type='network' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source protocol='rbd' name='pool/image'>
+        <snapshot name='foo'/>
+        <config file='/blah/test.conf'/>
+      </source>
+      <target dev='vdd' bus='virtio'/>
+    </disk>
     <controller type='usb' index='0'/>
     <controller type='ide' index='0'/>
     <controller type='pci' index='0' model='pci-root'/>