[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 09/14] snapshot: indent domain xml when nesting, round 9



This round fixes shared network formatting to use int rather
than char * for specifying the indent.

* src/util/network.h (virVirtualPortProfileFormat)
(virBandwidthDefFormat): Alter signature.
* src/util/network.c (virVirtualPortProfileFormat)
(virBandwidthDefFormat): Alter indentation.
(virBandwidthChildDefFormat): Add parameter.
* src/conf/domain_conf.c (virDomainActualNetDefFormat)
(virDomainNetDefFormat): Adjust callers.
* src/conf/network_conf.c (virPortGroupDefFormat)
(virNetworkDefFormat): Likewise.
---
 src/conf/domain_conf.c  |   13 ++++-------
 src/conf/network_conf.c |    8 +++---
 src/util/network.c      |   49 +++++++++++++++++++---------------------------
 src/util/network.h      |    9 ++++---
 4 files changed, 34 insertions(+), 45 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4d2e6c3..be32598 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9398,14 +9398,13 @@ virDomainActualNetDefFormat(virBufferPtr buf,
             return ret;
         }
         virBufferAsprintf(buf, " mode='%s'/>\n", mode);
-        virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile,
-                                    "        ");
+        virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile, 8);
         break;
     default:
         break;
     }

-    if (virBandwidthDefFormat(buf, def->bandwidth, "      ") < 0)
+    if (virBandwidthDefFormat(buf, def->bandwidth, 6) < 0)
         goto error;

     virBufferAddLit(buf, "      </actual>\n");
@@ -9445,8 +9444,7 @@ virDomainNetDefFormat(virBufferPtr buf,
                                  def->data.network.portgroup);
         }
         virBufferAddLit(buf, "/>\n");
-        virVirtualPortProfileFormat(buf, def->data.network.virtPortProfile,
-                                    "      ");
+        virVirtualPortProfileFormat(buf, def->data.network.virtPortProfile, 6);
         if ((flags & VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET) &&
             (virDomainActualNetDefFormat(buf, def->data.network.actual) < 0))
             return -1;
@@ -9497,8 +9495,7 @@ virDomainNetDefFormat(virBufferPtr buf,
         virBufferAsprintf(buf, " mode='%s'",
                    virMacvtapModeTypeToString(def->data.direct.mode));
         virBufferAddLit(buf, "/>\n");
-        virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile,
-                                    "      ");
+        virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile, 6);
         break;

     case VIR_DOMAIN_NET_TYPE_USER:
@@ -9563,7 +9560,7 @@ virDomainNetDefFormat(virBufferPtr buf,
         virBufferAsprintf(buf, "      <link state='%s'/>\n",
                           virDomainNetInterfaceLinkStateTypeToString(def->linkstate));

-    if (virBandwidthDefFormat(buf, def->bandwidth, "      ") < 0)
+    if (virBandwidthDefFormat(buf, def->bandwidth, 6) < 0)
         return -1;

     if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index b98ffad..f5f712f 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1267,8 +1267,8 @@ virPortGroupDefFormat(virBufferPtr buf,
         virBufferAddLit(buf, " default='yes'");
     }
     virBufferAddLit(buf, ">\n");
-    virVirtualPortProfileFormat(buf, def->virtPortProfile, "    ");
-    virBandwidthDefFormat(buf, def->bandwidth, "    ");
+    virVirtualPortProfileFormat(buf, def->virtPortProfile, 4);
+    virBandwidthDefFormat(buf, def->bandwidth, 4);
     virBufferAddLit(buf, "  </portgroup>\n");
 }

@@ -1341,7 +1341,7 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
     if (virNetworkDNSDefFormat(&buf, def->dns) < 0)
         goto error;

-    if (virBandwidthDefFormat(&buf, def->bandwidth, "  ") < 0)
+    if (virBandwidthDefFormat(&buf, def->bandwidth, 2) < 0)
         goto error;

     for (ii = 0; ii < def->nips; ii++) {
@@ -1349,7 +1349,7 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
             goto error;
     }

-    virVirtualPortProfileFormat(&buf, def->virtPortProfile, "  ");
+    virVirtualPortProfileFormat(&buf, def->virtPortProfile, 2);

     for (ii = 0; ii < def->nPortGroups; ii++)
         virPortGroupDefFormat(&buf, &def->portGroups[ii]);
diff --git a/src/util/network.c b/src/util/network.c
index ee69557..9969e80 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -882,15 +882,15 @@ virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, virVirtualPortProfi
 void
 virVirtualPortProfileFormat(virBufferPtr buf,
                             virVirtualPortProfileParamsPtr virtPort,
-                            const char *indent)
+                            int indent)
 {
     char uuidstr[VIR_UUID_STRING_BUFLEN];

     if (!virtPort || virtPort->virtPortType == VIR_VIRTUALPORT_NONE)
         return;

-    virBufferAsprintf(buf, "%s<virtualport type='%s'>\n",
-                      indent,
+    virBufferAsprintf(buf, "%*s<virtualport type='%s'>\n",
+                      indent, "",
                       virVirtualPortTypeToString(virtPort->virtPortType));

     switch (virtPort->virtPortType) {
@@ -902,9 +902,9 @@ virVirtualPortProfileFormat(virBufferPtr buf,
         virUUIDFormat(virtPort->u.virtPort8021Qbg.instanceID,
                       uuidstr);
         virBufferAsprintf(buf,
-                          "%s  <parameters managerid='%d' typeid='%d' "
+                          "%*s<parameters managerid='%d' typeid='%d' "
                           "typeidversion='%d' instanceid='%s'/>\n",
-                          indent,
+                          indent + 2, "",
                           virtPort->u.virtPort8021Qbg.managerID,
                           virtPort->u.virtPort8021Qbg.typeID,
                           virtPort->u.virtPort8021Qbg.typeIDVersion,
@@ -913,13 +913,13 @@ virVirtualPortProfileFormat(virBufferPtr buf,

     case VIR_VIRTUALPORT_8021QBH:
         virBufferAsprintf(buf,
-                          "%s  <parameters profileid='%s'/>\n",
-                          indent,
+                          "%*s<parameters profileid='%s'/>\n",
+                          indent + 2, "",
                           virtPort->u.virtPort8021Qbh.profileID);
         break;
     }

-    virBufferAsprintf(buf, "%s</virtualport>\n", indent);
+    virBufferIndentAddLit(buf, indent, "</virtualport>\n");
 }

 static int
@@ -1072,13 +1072,15 @@ virBandwidthDefFree(virBandwidthPtr def)
 static int
 virBandwidthChildDefFormat(virBufferPtr buf,
                            virRatePtr def,
-                           const char *elem_name)
+                           const char *elem_name,
+                           int indent)
 {
     if (!buf || !def || !elem_name)
         return -1;

     if (def->average) {
-        virBufferAsprintf(buf, "<%s average='%llu'", elem_name, def->average);
+        virBufferAsprintf(buf, "%*s<%s average='%llu'", indent, "",
+                          elem_name, def->average);

         if (def->peak)
             virBufferAsprintf(buf, " peak='%llu'", def->peak);
@@ -1095,17 +1097,16 @@ virBandwidthChildDefFormat(virBufferPtr buf,
  * virBandwidthDefFormat:
  * @buf: Buffer to print to
  * @def: Data source
- * @indent: prepend all lines printed with this
+ * @indent: prepend all lines printed with this many spaces
  *
  * Formats bandwidth and prepend each line with @indent.
- * Passing NULL to @indent is equivalent passing "".
  *
  * Returns 0 on success, else -1.
  */
 int
 virBandwidthDefFormat(virBufferPtr buf,
                       virBandwidthPtr def,
-                      const char *indent)
+                      int indent)
 {
     int ret = -1;

@@ -1117,23 +1118,13 @@ virBandwidthDefFormat(virBufferPtr buf,
         goto cleanup;
     }

-    if (!indent)
-        indent = "";
-
-    virBufferAsprintf(buf, "%s<bandwidth>\n", indent);
-    if (def->in) {
-        virBufferAsprintf(buf, "%s  ", indent);
-        if (virBandwidthChildDefFormat(buf, def->in, "inbound") < 0)
-            goto cleanup;
-    }
-
-    if (def->out) {
-        virBufferAsprintf(buf, "%s  ", indent);
-        if (virBandwidthChildDefFormat(buf, def->out, "outbound") < 0)
-            goto cleanup;
-    }
+    virBufferIndentAddLit(buf, indent, "<bandwidth>\n");
+    if (virBandwidthChildDefFormat(buf, def->in, "inbound", indent + 2) < 0)
+        goto cleanup;
+    if (virBandwidthChildDefFormat(buf, def->out, "outbound", indent + 2) < 0)
+        goto cleanup;

-    virBufferAsprintf(buf, "%s</bandwidth>\n", indent);
+    virBufferIndentAddLit(buf, indent, "</bandwidth>\n");

     ret = 0;

diff --git a/src/util/network.h b/src/util/network.h
index 4d195af..9fb9a19 100644
--- a/src/util/network.h
+++ b/src/util/network.h
@@ -1,7 +1,7 @@
 /*
  * network.h: network helper APIs for libvirt
  *
- * Copyright (C) 2009-2009 Red Hat, Inc.
+ * Copyright (C) 2009-2009, 2011 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -148,15 +148,16 @@ virVirtualPortProfileParseXML(xmlNodePtr node,
 void
 virVirtualPortProfileFormat(virBufferPtr buf,
                             virVirtualPortProfileParamsPtr virtPort,
-                            const char *indent);
+                            int indent);

-bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, virVirtualPortProfileParamsPtr b);
+bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a,
+                                virVirtualPortProfileParamsPtr b);

 virBandwidthPtr virBandwidthDefParseNode(xmlNodePtr node);
 void virBandwidthDefFree(virBandwidthPtr def);
 int virBandwidthDefFormat(virBufferPtr buf,
                           virBandwidthPtr def,
-                          const char *indent);
+                          int indent);

 int virBandwidthEnable(virBandwidthPtr bandwidth, const char *iface);
 int virBandwidthDisable(const char *iface, bool may_fail);
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]