]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: disk: Separate virStorageSource formatting
authorPeter Krempa <pkrempa@redhat.com>
Mon, 5 Mar 2018 14:13:41 +0000 (15:13 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 14 Mar 2018 11:19:44 +0000 (12:19 +0100)
Move out formatting of 'startuPolicy' which is a property of the disk
out of the <source> element. Extracting the code formating the content
and attributes will also allow reuse in other parts of the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms

index b77cc8ed9f677627f9d068c403cf01cfcf936371..1c79d2b49bea952aadb0d76e2856d9bfa2db749a 100644 (file)
@@ -22798,45 +22798,39 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr buf,
 }
 
 
-static int
-virDomainDiskSourceFormatInternal(virBufferPtr buf,
-                                  virStorageSourcePtr src,
-                                  int policy,
-                                  unsigned int flags,
-                                  bool skipSeclabels,
-                                  virDomainXMLOptionPtr xmlopt)
+int
+virDomainStorageSourceFormat(virBufferPtr attrBuf,
+                             virBufferPtr childBuf,
+                             virStorageSourcePtr src,
+                             unsigned int flags,
+                             bool skipSeclabels)
 {
-    virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
-    virBuffer childBuf = VIR_BUFFER_INITIALIZER;
-
-    virBufferSetChildIndent(&childBuf, buf);
-
     switch ((virStorageType)src->type) {
     case VIR_STORAGE_TYPE_FILE:
-        virBufferEscapeString(&attrBuf, " file='%s'", src->path);
+        virBufferEscapeString(attrBuf, " file='%s'", src->path);
         break;
 
     case VIR_STORAGE_TYPE_BLOCK:
-        virBufferEscapeString(&attrBuf, " dev='%s'", src->path);
+        virBufferEscapeString(attrBuf, " dev='%s'", src->path);
         break;
 
     case VIR_STORAGE_TYPE_DIR:
-        virBufferEscapeString(&attrBuf, " dir='%s'", src->path);
+        virBufferEscapeString(attrBuf, " dir='%s'", src->path);
         break;
 
     case VIR_STORAGE_TYPE_NETWORK:
-        if (virDomainDiskSourceFormatNetwork(&attrBuf, &childBuf,
+        if (virDomainDiskSourceFormatNetwork(attrBuf, childBuf,
                                              src, flags) < 0)
-            goto error;
+            return -1;
         break;
 
     case VIR_STORAGE_TYPE_VOLUME:
         if (src->srcpool) {
-            virBufferEscapeString(&attrBuf, " pool='%s'", src->srcpool->pool);
-            virBufferEscapeString(&attrBuf, " volume='%s'",
+            virBufferEscapeString(attrBuf, " pool='%s'", src->srcpool->pool);
+            virBufferEscapeString(attrBuf, " volume='%s'",
                                   src->srcpool->volume);
             if (src->srcpool->mode)
-                virBufferAsprintf(&attrBuf, " mode='%s'",
+                virBufferAsprintf(attrBuf, " mode='%s'",
                                   virStorageSourcePoolModeTypeToString(src->srcpool->mode));
         }
 
@@ -22846,18 +22840,12 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
     case VIR_STORAGE_TYPE_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected disk type %d"), src->type);
-        goto error;
+        return -1;
     }
 
-    if (src->type != VIR_STORAGE_TYPE_NETWORK) {
-        if (policy)
-            virBufferEscapeString(&attrBuf, " startupPolicy='%s'",
-                                  virDomainStartupPolicyTypeToString(policy));
-
-        if (!skipSeclabels)
-            virDomainSourceDefFormatSeclabel(&childBuf, src->nseclabels,
-                                             src->seclabels, flags);
-    }
+    if (!skipSeclabels && src->type != VIR_STORAGE_TYPE_NETWORK)
+        virDomainSourceDefFormatSeclabel(childBuf, src->nseclabels,
+                                         src->seclabels, flags);
 
     /* Storage Source formatting will not carry through the blunder
      * that disk source formatting had at one time to format the
@@ -22866,26 +22854,52 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
      * So avoid formatting it for volumes. */
     if (src->auth && src->authInherited &&
         src->type != VIR_STORAGE_TYPE_VOLUME)
-        virStorageAuthDefFormat(&childBuf, src->auth);
+        virStorageAuthDefFormat(childBuf, src->auth);
 
     /* If we found encryption as a child of <source>, then format it
      * as we found it. */
     if (src->encryption && src->encryptionInherited &&
-        virStorageEncryptionFormat(&childBuf, src->encryption) < 0)
-        goto error;
+        virStorageEncryptionFormat(childBuf, src->encryption) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+static int
+virDomainDiskSourceFormatInternal(virBufferPtr buf,
+                                  virStorageSourcePtr src,
+                                  int policy,
+                                  unsigned int flags,
+                                  bool skipSeclabels,
+                                  virDomainXMLOptionPtr xmlopt)
+{
+    virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
+    virBuffer childBuf = VIR_BUFFER_INITIALIZER;
+    int ret = -1;
+
+    virBufferSetChildIndent(&childBuf, buf);
+
+    if (virDomainStorageSourceFormat(&attrBuf, &childBuf, src, flags,
+                                     skipSeclabels) < 0)
+        goto cleanup;
+
+    if (policy && src->type != VIR_STORAGE_TYPE_NETWORK)
+        virBufferEscapeString(&attrBuf, " startupPolicy='%s'",
+                              virDomainStartupPolicyTypeToString(policy));
 
     if (virDomainDiskSourceFormatPrivateData(&childBuf, src, flags, xmlopt) < 0)
-        goto error;
+        goto cleanup;
 
     if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0)
-        goto error;
+        goto cleanup;
 
-    return 0;
+    ret = 0;
 
error:
cleanup:
     virBufferFreeAndReset(&attrBuf);
     virBufferFreeAndReset(&childBuf);
-    return -1;
+    return ret;
 }
 
 
index 337ce79425a76043d3856b7f74bb414232b081b4..61379e50fed5e2c65b23e49b3b4f6d7ac08fed86 100644 (file)
@@ -3427,6 +3427,13 @@ int virDomainDiskDefCheckDuplicateInfo(const virDomainDiskDef *a,
                                        const virDomainDiskDef *b)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
+int virDomainStorageSourceFormat(virBufferPtr attrBuf,
+                                 virBufferPtr childBuf,
+                                 virStorageSourcePtr src,
+                                 unsigned int flags,
+                                 bool skipSeclabels)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+
 int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
                                      int maplen,
                                      int ncpumaps,
index 3766e20d3b301528f0ed6a5f7594b2351f070b73..c67bce73890c009b82476adc924ec67639c7b76f 100644 (file)
@@ -542,6 +542,7 @@ virDomainStateReasonFromString;
 virDomainStateReasonToString;
 virDomainStateTypeFromString;
 virDomainStateTypeToString;
+virDomainStorageSourceFormat;
 virDomainTaintTypeFromString;
 virDomainTaintTypeToString;
 virDomainTimerModeTypeFromString;