Blob Blame History Raw
From 33fb1d6dc316343067768c9e7d0720c4ebf5733b Mon Sep 17 00:00:00 2001
Message-Id: <33fb1d6dc316343067768c9e7d0720c4ebf5733b@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 26 Feb 2014 14:54:45 +0100
Subject: [PATCH] conf: Split out seclabel formating code for disk source

https://bugzilla.redhat.com/show_bug.cgi?id=1032370

The code is common for all the various disk types. Split it out to a
common function.

(cherry picked from commit 30f7ca67d96d448411c1a92749bbe9f9bf4c167f)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c | 62 ++++++++++++++++++++++++--------------------------
 1 file changed, 30 insertions(+), 32 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bba6201..e4e3f6b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14462,6 +14462,32 @@ virDomainDiskBlockIoDefFormat(virBufferPtr buf,
     }
 }
 
+
+/* virDomainDiskSourceDefFormatSeclabel:
+ *
+ * This function automaticaly closes the <source> element and formats any
+ * possible seclabels.
+ */
+static void
+virDomainDiskSourceDefFormatSeclabel(virBufferPtr buf,
+                                     size_t nseclabels,
+                                     virSecurityDeviceLabelDefPtr *seclabels,
+                                     unsigned int flags)
+{
+    size_t n;
+
+    if (nseclabels) {
+        virBufferAddLit(buf, ">\n");
+        virBufferAdjustIndent(buf, 8);
+        for (n = 0; n < nseclabels; n++)
+            virSecurityDeviceLabelDefFormat(buf, seclabels[n], flags);
+        virBufferAdjustIndent(buf, -8);
+        virBufferAddLit(buf, "      </source>\n");
+    } else {
+        virBufferAddLit(buf, "/>\n");
+    }
+}
+
 static int
 virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
                                      int type,
@@ -14488,33 +14514,15 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
             virBufferEscapeString(buf, " file='%s'", src);
             virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
 
-            if (nseclabels) {
-                virBufferAddLit(buf, ">\n");
-                virBufferAdjustIndent(buf, 8);
-                for (n = 0; n < nseclabels; n++)
-                    virSecurityDeviceLabelDefFormat(buf, seclabels[n], flags);
-                virBufferAdjustIndent(buf, -8);
-                virBufferAddLit(buf, "      </source>\n");
-            } else {
-                virBufferAddLit(buf, "/>\n");
-            }
-            break;
+            virDomainDiskSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags);
+           break;
 
         case VIR_DOMAIN_DISK_TYPE_BLOCK:
             virBufferAddLit(buf, "      <source");
             virBufferEscapeString(buf, " dev='%s'", src);
             virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
 
-            if (nseclabels) {
-                virBufferAddLit(buf, ">\n");
-                virBufferAdjustIndent(buf, 8);
-                for (n = 0; n < nseclabels; n++)
-                    virSecurityDeviceLabelDefFormat(buf, seclabels[n], flags);
-                virBufferAdjustIndent(buf, -8);
-                virBufferAddLit(buf, "      </source>\n");
-            } else {
-                virBufferAddLit(buf, "/>\n");
-            }
+            virDomainDiskSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags);
             break;
 
         case VIR_DOMAIN_DISK_TYPE_DIR:
@@ -14562,17 +14570,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
             }
             virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
 
-            if (nseclabels) {
-                virBufferAddLit(buf, ">\n");
-                virBufferAdjustIndent(buf, 8);
-                for (n = 0; n < nseclabels; n++)
-                    virSecurityDeviceLabelDefFormat(buf, seclabels[n],
-                                                    flags);
-                virBufferAdjustIndent(buf, -8);
-                virBufferAddLit(buf, "      </source>\n");
-            } else {
-                virBufferAddLit(buf, "/>\n");
-            }
+            virDomainDiskSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags);
             break;
 
         default:
-- 
1.9.0