9119d9
From db9b89f699644c68e0f41f90947b69a3d47b6f38 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <db9b89f699644c68e0f41f90947b69a3d47b6f38@dist-git>
9119d9
From: Peter Krempa <pkrempa@redhat.com>
9119d9
Date: Fri, 21 Nov 2014 15:04:12 +0100
9119d9
Subject: [PATCH] storage: rbd: Implement support for passing config file
9119d9
 option
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1164528
9119d9
9119d9
To be able to express some use cases of the RBD backing with libvirt, we
9119d9
need to be able to specify a config file for the RBD client to qemu as
9119d9
that is one of the commonly used options.
9119d9
9119d9
(cherry picked from commit b7d1bee2b9a8d7ed76456447b090702223da39f5)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 docs/formatdomain.html.in                              |  9 +++++++++
9119d9
 docs/schemas/domaincommon.rng                          |  8 ++++++++
9119d9
 src/conf/domain_conf.c                                 | 18 ++++++++++++++++--
9119d9
 src/qemu/qemu_command.c                                |  3 +++
9119d9
 src/util/virstoragefile.c                              |  5 +++++
9119d9
 src/util/virstoragefile.h                              |  2 ++
9119d9
 .../qemuxml2argv-disk-drive-network-rbd.args           |  2 ++
9119d9
 .../qemuxml2argv-disk-drive-network-rbd.xml            |  8 ++++++++
9119d9
 8 files changed, 53 insertions(+), 2 deletions(-)
9119d9
9119d9
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
9119d9
index 789f6ee..e044eab 100644
9119d9
--- a/docs/formatdomain.html.in
9119d9
+++ b/docs/formatdomain.html.in
9119d9
@@ -1662,6 +1662,7 @@
9119d9
       <source protocol="rbd" name="image_name2">
9119d9
         <host name="hostname" port="7000"/>
9119d9
         <snapshot name="snapname"/>
9119d9
+        <config file="/path/to/file"/>
9119d9
       </source>
9119d9
       <target dev="hdc" bus="ide"/>
9119d9
       <auth username='myuser'>
9119d9
@@ -2005,6 +2006,14 @@
9119d9
             source for storage protocols.
9119d9
             Supported for 'rbd' since 1.2.11 (QEMU only).
9119d9
           
9119d9
+          
config
9119d9
+          
9119d9
+            The file attribute for the config element
9119d9
+            provides a fully qualified path to a configuration file to be
9119d9
+            provided as a parameter to the client of a networked storage
9119d9
+            protocol. Supported for 'rbd' since 1.2.11
9119d9
+            (QEMU only).
9119d9
+          
9119d9
         
9119d9
 
9119d9
         

9119d9
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
9119d9
index fa17494..7cb37c7 100644
9119d9
--- a/docs/schemas/domaincommon.rng
9119d9
+++ b/docs/schemas/domaincommon.rng
9119d9
@@ -1455,6 +1455,14 @@
9119d9
             <empty/>
9119d9
           </element>
9119d9
         </optional>
9119d9
+        <optional>
9119d9
+          <element name="config">
9119d9
+            <attribute name="file">
9119d9
+              <ref name="absFilePath"/>
9119d9
+            </attribute>
9119d9
+            <empty/>
9119d9
+          </element>
9119d9
+        </optional>
9119d9
         <empty/>
9119d9
       </element>
9119d9
     </interleave>
9119d9
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
9119d9
index 82d321a..baf16dc 100644
9119d9
--- a/src/conf/domain_conf.c
9119d9
+++ b/src/conf/domain_conf.c
9119d9
@@ -3161,7 +3161,8 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
9119d9
     if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
9119d9
         virDomainDiskDefPtr disk = dev->data.disk;
9119d9
 
9119d9
-        /* internal snapshots are currently supported only with rbd: */
9119d9
+        /* internal snapshots and config files are currently supported
9119d9
+         * only with rbd: */
9119d9
         if (virStorageSourceGetActualType(disk->src) != VIR_STORAGE_TYPE_NETWORK &&
9119d9
             disk->src->protocol != VIR_STORAGE_NET_PROTOCOL_RBD) {
9119d9
             if (disk->src->snapshot) {
9119d9
@@ -3170,6 +3171,13 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
9119d9
                                  "only with 'rbd' disks"));
9119d9
                 return -1;
9119d9
             }
9119d9
+
9119d9
+            if (disk->src->configFile) {
9119d9
+                virReportError(VIR_ERR_XML_ERROR, "%s",
9119d9
+                               _("<config> element is currently supported "
9119d9
+                                 "only with 'rbd' disks"));
9119d9
+                return -1;
9119d9
+            }
9119d9
         }
9119d9
     }
9119d9
 
9119d9
@@ -5380,6 +5388,9 @@ virDomainDiskSourceParse(xmlNodePtr node,
9119d9
         /* snapshot currently works only for remote disks */
9119d9
         src->snapshot = virXPathString("string(./snapshot/@name)", ctxt);
9119d9
 
9119d9
+        /* config file currently only works with remote disks */
9119d9
+        src->configFile = virXPathString("string(./config/@file)", ctxt);
9119d9
+
9119d9
         if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0)
9119d9
             goto cleanup;
9119d9
         break;
9119d9
@@ -15923,7 +15934,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
9119d9
 
9119d9
             VIR_FREE(path);
9119d9
 
9119d9
-            if (src->nhosts == 0 && !src->snapshot) {
9119d9
+            if (src->nhosts == 0 && !src->snapshot && !src->configFile) {
9119d9
                 virBufferAddLit(buf, "/>\n");
9119d9
             } else {
9119d9
                 virBufferAddLit(buf, ">\n");
9119d9
@@ -15949,6 +15960,9 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
9119d9
                 virBufferEscapeString(buf, "<snapshot name='%s'/>\n",
9119d9
                                       src->snapshot);
9119d9
 
9119d9
+                virBufferEscapeString(buf, "<config file='%s'/>\n",
9119d9
+                                      src->configFile);
9119d9
+
9119d9
                 virBufferAdjustIndent(buf, -2);
9119d9
                 virBufferAddLit(buf, "</source>\n");
9119d9
             }
9119d9
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
9119d9
index 5d34ba3..09a22dc 100644
9119d9
--- a/src/qemu/qemu_command.c
9119d9
+++ b/src/qemu/qemu_command.c
9119d9
@@ -3016,6 +3016,9 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src,
9119d9
                 }
9119d9
             }
9119d9
 
9119d9
+            if (src->configFile)
9119d9
+                virBufferEscape(&buf, '\\', ":", ":conf=%s", src->configFile);
9119d9
+
9119d9
             if (virBufferCheckError(&buf) < 0)
9119d9
                 goto cleanup;
9119d9
 
9119d9
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
9119d9
index 6cdc5be..580ad20 100644
9119d9
--- a/src/util/virstoragefile.c
9119d9
+++ b/src/util/virstoragefile.c
9119d9
@@ -1843,6 +1843,7 @@ virStorageSourceCopy(const virStorageSource *src,
9119d9
         VIR_STRDUP(ret->relPath, src->relPath) < 0 ||
9119d9
         VIR_STRDUP(ret->backingStoreRaw, src->backingStoreRaw) < 0 ||
9119d9
         VIR_STRDUP(ret->snapshot, src->snapshot) < 0 ||
9119d9
+        VIR_STRDUP(ret->configFile, src->configFile) < 0 ||
9119d9
         VIR_STRDUP(ret->compat, src->compat) < 0)
9119d9
         goto error;
9119d9
 
9119d9
@@ -2328,6 +2329,10 @@ virStorageSourceParseRBDColonString(const char *rbdstr,
9119d9
             }
9119d9
         }
9119d9
 
9119d9
+        if (STRPREFIX(p, "conf=") &&
9119d9
+            VIR_STRDUP(src->configFile, p + strlen("conf=")) < 0)
9119d9
+            goto error;
9119d9
+
9119d9
         p = next;
9119d9
     }
9119d9
     VIR_FREE(options);
9119d9
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
9119d9
index 74aa1a3..3a585a4 100644
9119d9
--- a/src/util/virstoragefile.h
9119d9
+++ b/src/util/virstoragefile.h
9119d9
@@ -237,6 +237,8 @@ struct _virStorageSource {
9119d9
     int protocol; /* virStorageNetProtocol */
9119d9
     char *volume; /* volume name for remote storage */
9119d9
     char *snapshot; /* for storage systems supporting internal snapshots */
9119d9
+    char *configFile; /* some storage systems use config file as part of
9119d9
+                         the source definition */
9119d9
     size_t nhosts;
9119d9
     virStorageNetHostDefPtr hosts;
9119d9
     virStorageSourcePoolDefPtr srcpool;
9119d9
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd.args
9119d9
index e4f1389..f634e8d 100644
9119d9
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd.args
9119d9
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd.args
9119d9
@@ -9,4 +9,6 @@ mon3.example.org\:6322,if=virtio,format=raw' \
9119d9
 -drive 'file=rbd:pool/image@foo:auth_supported=none:\
9119d9
 mon_host=mon1.example.org\:6321\;mon2.example.org\:6322\;\
9119d9
 mon3.example.org\:6322,if=virtio,format=raw' \
9119d9
+-drive file=rbd:pool/image@foo:auth_supported=none:\
9119d9
+conf=/blah/test.conf,if=virtio,format=raw \
9119d9
 -net none -serial none -parallel none
9119d9
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd.xml
9119d9
index f6accd8..9ffe633 100644
9119d9
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd.xml
9119d9
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd.xml
9119d9
@@ -46,6 +46,14 @@
9119d9
       </source>
9119d9
       <target dev='vdc' bus='virtio'/>
9119d9
     </disk>
9119d9
+    <disk type='network' device='disk'>
9119d9
+      <driver name='qemu' type='raw'/>
9119d9
+      <source protocol='rbd' name='pool/image'>
9119d9
+        <snapshot name='foo'/>
9119d9
+        <config file='/blah/test.conf'/>
9119d9
+      </source>
9119d9
+      <target dev='vdd' bus='virtio'/>
9119d9
+    </disk>
9119d9
     <controller type='usb' index='0'/>
9119d9
     <controller type='ide' index='0'/>
9119d9
     <controller type='pci' index='0' model='pci-root'/>
9119d9
-- 
9119d9
2.1.3
9119d9