Blame SOURCES/libvirt-conf-Support-disk-source-formatting-without-needing-a-virDomainDiskDefPtr.patch

c401cc
From 969efd354611526e1c718c1cba9f188aa96f24ce Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <969efd354611526e1c718c1cba9f188aa96f24ce@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:54:43 +0100
c401cc
Subject: [PATCH] conf: Support disk source formatting without needing a
c401cc
 virDomainDiskDefPtr
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
The <source> element formatting function was expecting a
c401cc
virDomainDiskDefPtr to store the data. As snapshots are not using this
c401cc
data structure to hold the data, we need to add an internal function
c401cc
which splits out individual fields separately.
c401cc
c401cc
(cherry picked from commit d6b4c2cca9886720c7ada718acdde1254ae1e25a)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/conf/domain_conf.c | 129 ++++++++++++++++++++++++++++++-------------------
c401cc
 1 file changed, 78 insertions(+), 51 deletions(-)
c401cc
c401cc
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
c401cc
index 409fcda..7032b2b 100644
c401cc
--- a/src/conf/domain_conf.c
c401cc
+++ b/src/conf/domain_conf.c
c401cc
@@ -14463,28 +14463,38 @@ virDomainDiskBlockIoDefFormat(virBufferPtr buf,
c401cc
 }
c401cc
 
c401cc
 static int
c401cc
-virDomainDiskSourceDefFormat(virBufferPtr buf,
c401cc
-                             virDomainDiskDefPtr def,
c401cc
-                             unsigned int flags)
c401cc
+virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
c401cc
+                                     int type,
c401cc
+                                     const char *src,
c401cc
+                                     int policy,
c401cc
+                                     int protocol,
c401cc
+                                     size_t nhosts,
c401cc
+                                     virDomainDiskHostDefPtr hosts,
c401cc
+                                     size_t nseclabels,
c401cc
+                                     virSecurityDeviceLabelDefPtr *seclabels,
c401cc
+                                     virDomainDiskSourcePoolDefPtr srcpool,
c401cc
+                                     unsigned int flags)
c401cc
 {
c401cc
-    int n;
c401cc
-    const char *startupPolicy = virDomainStartupPolicyTypeToString(def->startupPolicy);
c401cc
+    size_t n;
c401cc
+    const char *startupPolicy = NULL;
c401cc
 
c401cc
-    if (def->src || def->nhosts > 0 || def->srcpool ||
c401cc
-        def->startupPolicy) {
c401cc
-        switch (def->type) {
c401cc
+    if (policy)
c401cc
+        startupPolicy = virDomainStartupPolicyTypeToString(policy);
c401cc
+
c401cc
+    if (src || nhosts > 0 || srcpool || startupPolicy) {
c401cc
+        switch (type) {
c401cc
         case VIR_DOMAIN_DISK_TYPE_FILE:
c401cc
             virBufferAddLit(buf, "      
c401cc
-            if (def->src)
c401cc
-                virBufferEscapeString(buf, " file='%s'", def->src);
c401cc
-            if (def->startupPolicy)
c401cc
+            if (src)
c401cc
+                virBufferEscapeString(buf, " file='%s'", src);
c401cc
+            if (startupPolicy)
c401cc
                 virBufferEscapeString(buf, " startupPolicy='%s'",
c401cc
                                       startupPolicy);
c401cc
-            if (def->nseclabels) {
c401cc
+            if (nseclabels) {
c401cc
                 virBufferAddLit(buf, ">\n");
c401cc
                 virBufferAdjustIndent(buf, 8);
c401cc
-                for (n = 0; n < def->nseclabels; n++)
c401cc
-                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n],
c401cc
+                for (n = 0; n < nseclabels; n++)
c401cc
+                    virSecurityDeviceLabelDefFormat(buf, seclabels[n],
c401cc
                                                     flags);
c401cc
                 virBufferAdjustIndent(buf, -8);
c401cc
                 virBufferAddLit(buf, "      </source>\n");
c401cc
@@ -14494,15 +14504,15 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
c401cc
             break;
c401cc
         case VIR_DOMAIN_DISK_TYPE_BLOCK:
c401cc
             virBufferAddLit(buf, "      
c401cc
-            virBufferEscapeString(buf, " dev='%s'", def->src);
c401cc
-            if (def->startupPolicy)
c401cc
+            virBufferEscapeString(buf, " dev='%s'", src);
c401cc
+            if (startupPolicy)
c401cc
                 virBufferEscapeString(buf, " startupPolicy='%s'",
c401cc
                                       startupPolicy);
c401cc
-            if (def->nseclabels) {
c401cc
+            if (nseclabels) {
c401cc
                 virBufferAddLit(buf, ">\n");
c401cc
                 virBufferAdjustIndent(buf, 8);
c401cc
-                for (n = 0; n < def->nseclabels; n++)
c401cc
-                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n],
c401cc
+                for (n = 0; n < nseclabels; n++)
c401cc
+                    virSecurityDeviceLabelDefFormat(buf, seclabels[n],
c401cc
                                                     flags);
c401cc
                 virBufferAdjustIndent(buf, -8);
c401cc
                 virBufferAddLit(buf, "      </source>\n");
c401cc
@@ -14511,41 +14521,38 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
c401cc
             }
c401cc
             break;
c401cc
         case VIR_DOMAIN_DISK_TYPE_DIR:
c401cc
-            virBufferEscapeString(buf, "      
c401cc
-                                  def->src);
c401cc
-            if (def->startupPolicy)
c401cc
+            virBufferEscapeString(buf, "      
c401cc
+            if (startupPolicy)
c401cc
                 virBufferEscapeString(buf, " startupPolicy='%s'",
c401cc
                                       startupPolicy);
c401cc
             virBufferAddLit(buf, "/>\n");
c401cc
             break;
c401cc
         case VIR_DOMAIN_DISK_TYPE_NETWORK:
c401cc
             virBufferAsprintf(buf, "      
c401cc
-                              virDomainDiskProtocolTypeToString(def->protocol));
c401cc
-            if (def->src) {
c401cc
-                virBufferEscapeString(buf, " name='%s'", def->src);
c401cc
-            }
c401cc
-            if (def->nhosts == 0) {
c401cc
+                              virDomainDiskProtocolTypeToString(protocol));
c401cc
+            if (src)
c401cc
+                virBufferEscapeString(buf, " name='%s'", src);
c401cc
+
c401cc
+            if (nhosts == 0) {
c401cc
                 virBufferAddLit(buf, "/>\n");
c401cc
             } else {
c401cc
-                size_t i;
c401cc
-
c401cc
                 virBufferAddLit(buf, ">\n");
c401cc
-                for (i = 0; i < def->nhosts; i++) {
c401cc
+                for (n = 0; n < nhosts; n++) {
c401cc
                     virBufferAddLit(buf, "        
c401cc
-                    if (def->hosts[i].name) {
c401cc
-                        virBufferEscapeString(buf, " name='%s'", def->hosts[i].name);
c401cc
-                    }
c401cc
-                    if (def->hosts[i].port) {
c401cc
+                    if (hosts[n].name)
c401cc
+                        virBufferEscapeString(buf, " name='%s'", hosts[n].name);
c401cc
+
c401cc
+                    if (hosts[n].port)
c401cc
                         virBufferEscapeString(buf, " port='%s'",
c401cc
-                                              def->hosts[i].port);
c401cc
-                    }
c401cc
-                    if (def->hosts[i].transport) {
c401cc
+                                              hosts[n].port);
c401cc
+
c401cc
+                    if (hosts[n].transport)
c401cc
                         virBufferAsprintf(buf, " transport='%s'",
c401cc
-                                          virDomainDiskProtocolTransportTypeToString(def->hosts[i].transport));
c401cc
-                    }
c401cc
-                    if (def->hosts[i].socket) {
c401cc
-                        virBufferEscapeString(buf, " socket='%s'", def->hosts[i].socket);
c401cc
-                    }
c401cc
+                                          virDomainDiskProtocolTransportTypeToString(hosts[n].transport));
c401cc
+
c401cc
+                    if (hosts[n].socket)
c401cc
+                        virBufferEscapeString(buf, " socket='%s'", hosts[n].socket);
c401cc
+
c401cc
                     virBufferAddLit(buf, "/>\n");
c401cc
                 }
c401cc
                 virBufferAddLit(buf, "      </source>\n");
c401cc
@@ -14554,21 +14561,21 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
c401cc
         case VIR_DOMAIN_DISK_TYPE_VOLUME:
c401cc
             virBufferAddLit(buf, "      
c401cc
 
c401cc
-            if (def->srcpool) {
c401cc
+            if (srcpool) {
c401cc
                 virBufferAsprintf(buf, " pool='%s' volume='%s'",
c401cc
-                                  def->srcpool->pool, def->srcpool->volume);
c401cc
-                if (def->srcpool->mode)
c401cc
+                                  srcpool->pool, srcpool->volume);
c401cc
+                if (srcpool->mode)
c401cc
                     virBufferAsprintf(buf, " mode='%s'",
c401cc
-                                      virDomainDiskSourcePoolModeTypeToString(def->srcpool->mode));
c401cc
+                                      virDomainDiskSourcePoolModeTypeToString(srcpool->mode));
c401cc
             }
c401cc
-            if (def->startupPolicy)
c401cc
+            if (startupPolicy)
c401cc
                 virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
c401cc
 
c401cc
-            if (def->nseclabels) {
c401cc
+            if (nseclabels) {
c401cc
                 virBufferAddLit(buf, ">\n");
c401cc
                 virBufferAdjustIndent(buf, 8);
c401cc
-                for (n = 0; n < def->nseclabels; n++)
c401cc
-                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n],
c401cc
+                for (n = 0; n < nseclabels; n++)
c401cc
+                    virSecurityDeviceLabelDefFormat(buf, seclabels[n],
c401cc
                                                     flags);
c401cc
                 virBufferAdjustIndent(buf, -8);
c401cc
                 virBufferAddLit(buf, "      </source>\n");
c401cc
@@ -14579,7 +14586,7 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
c401cc
         default:
c401cc
             virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
                            _("unexpected disk type %s"),
c401cc
-                           virDomainDiskTypeToString(def->type));
c401cc
+                           virDomainDiskTypeToString(type));
c401cc
             return -1;
c401cc
         }
c401cc
     }
c401cc
@@ -14587,6 +14594,26 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
c401cc
     return 0;
c401cc
 }
c401cc
 
c401cc
+
c401cc
+static int
c401cc
+virDomainDiskSourceDefFormat(virBufferPtr buf,
c401cc
+                             virDomainDiskDefPtr def,
c401cc
+                             unsigned int flags)
c401cc
+{
c401cc
+    return virDomainDiskSourceDefFormatInternal(buf,
c401cc
+                                                def->type,
c401cc
+                                                def->src,
c401cc
+                                                def->startupPolicy,
c401cc
+                                                def->protocol,
c401cc
+                                                def->nhosts,
c401cc
+                                                def->hosts,
c401cc
+                                                def->nseclabels,
c401cc
+                                                def->seclabels,
c401cc
+                                                def->srcpool,
c401cc
+                                                flags);
c401cc
+}
c401cc
+
c401cc
+
c401cc
 static int
c401cc
 virDomainDiskDefFormat(virBufferPtr buf,
c401cc
                        virDomainDiskDefPtr def,
c401cc
-- 
c401cc
1.9.0
c401cc