]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: introduce virBufferSetChildIndent macro
authorPavel Hrdina <phrdina@redhat.com>
Thu, 24 Aug 2017 12:54:56 +0000 (14:54 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 28 Aug 2017 12:02:34 +0000 (14:02 +0200)
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/conf/capabilities.c
src/conf/cpu_conf.c
src/conf/domain_conf.c
src/util/virbuffer.h

index 69af3911a0837f5da190d3731eea695f331c7b0e..ba554535ae5dca746fa83802ffcbdfb6a5783723 100644 (file)
@@ -872,7 +872,6 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
 {
     size_t i = 0;
     size_t j = 0;
-    int indent = virBufferGetIndent(buf, false);
     virBuffer controlBuf = VIR_BUFFER_INITIALIZER;
 
     if (!ncaches)
@@ -903,7 +902,7 @@ virCapabilitiesFormatCaches(virBufferPtr buf,
                           cpus_str);
         VIR_FREE(cpus_str);
 
-        virBufferAdjustIndent(&controlBuf, indent + 4);
+        virBufferSetChildIndent(&controlBuf, buf);
         for (j = 0; j < bank->ncontrols; j++) {
             bool min_kilos = !(bank->controls[j]->granularity % 1024);
 
index cdb85836479e46f52efd16069863fc286ad9fdd0..c21d11d2445fb18dd4ac44f4a32bab6a72473d72 100644 (file)
@@ -599,7 +599,6 @@ virCPUDefFormatBufFull(virBufferPtr buf,
     int ret = -1;
     virBuffer attributeBuf = VIR_BUFFER_INITIALIZER;
     virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
-    int indent = virBufferGetIndent(buf, false);
 
     if (!def)
         return 0;
@@ -636,7 +635,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
     }
 
     /* Format children */
-    virBufferAdjustIndent(&childrenBuf, indent + 2);
+    virBufferSetChildIndent(&childrenBuf, buf);
     if (def->type == VIR_CPU_TYPE_HOST && def->arch)
         virBufferAsprintf(&childrenBuf, "<arch>%s</arch>\n",
                           virArchToString(def->arch));
index 646b60a83da542bbb914e62ee47073531fb7bbb4..51a7d003dce57c73beb8916b8b3e503a75a5a893 100644 (file)
@@ -22015,7 +22015,7 @@ virDomainControllerDefFormat(virBufferPtr buf,
     const char *modelName = NULL;
     virBuffer childBuf = VIR_BUFFER_INITIALIZER;
 
-    virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
+    virBufferSetChildIndent(&childBuf, buf);
 
     if (!type) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -23298,7 +23298,7 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
     virBuffer childBuf = VIR_BUFFER_INITIALIZER;
     size_t i;
 
-    virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
+    virBufferSetChildIndent(&childBuf, buf);
 
     if (!mode) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -23407,7 +23407,7 @@ virDomainSoundDefFormat(virBufferPtr buf,
     virBuffer childBuf = VIR_BUFFER_INITIALIZER;
     size_t i;
 
-    virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
+    virBufferSetChildIndent(&childBuf, buf);
 
     if (!model) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -23443,7 +23443,6 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
 {
     const char *model = virDomainMemballoonModelTypeToString(def->model);
     virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
-    int indent = virBufferGetIndent(buf, false);
 
     if (!model) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -23457,7 +23456,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
         virBufferAsprintf(buf, " autodeflate='%s'",
                           virTristateSwitchTypeToString(def->autodeflate));
 
-    virBufferAdjustIndent(&childrenBuf, indent + 2);
+    virBufferSetChildIndent(&childrenBuf, buf);
 
     if (def->period)
         virBufferAsprintf(&childrenBuf, "<stats period='%i'/>\n", def->period);
@@ -23519,7 +23518,7 @@ virDomainWatchdogDefFormat(virBufferPtr buf,
     const char *action = virDomainWatchdogActionTypeToString(def->action);
     virBuffer childBuf = VIR_BUFFER_INITIALIZER;
 
-    virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
+    virBufferSetChildIndent(&childBuf, buf);
 
     if (!model) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -23556,7 +23555,6 @@ static int virDomainPanicDefFormat(virBufferPtr buf,
                                    virDomainPanicDefPtr def)
 {
     virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
-    int indent = virBufferGetIndent(buf, false);
 
     virBufferAddLit(buf, "<panic");
 
@@ -23564,7 +23562,7 @@ static int virDomainPanicDefFormat(virBufferPtr buf,
         virBufferAsprintf(buf, " model='%s'",
                           virDomainPanicModelTypeToString(def->model));
 
-    virBufferAdjustIndent(&childrenBuf, indent + 2);
+    virBufferSetChildIndent(&childrenBuf, buf);
     virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0);
 
     if (virBufferCheckError(&childrenBuf) < 0)
@@ -23899,7 +23897,7 @@ virDomainInputDefFormat(virBufferPtr buf,
     virBufferAsprintf(buf, "<input type='%s' bus='%s'",
                       type, bus);
 
-    virBufferAdjustIndent(&childbuf, virBufferGetIndent(buf, false) + 2);
+    virBufferSetChildIndent(&childbuf, buf);
     virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
     if (virBufferCheckError(&driverBuf) < 0)
         return -1;
@@ -24549,7 +24547,7 @@ virDomainHubDefFormat(virBufferPtr buf,
     const char *type = virDomainHubTypeToString(def->type);
     virBuffer childBuf = VIR_BUFFER_INITIALIZER;
 
-    virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
+    virBufferSetChildIndent(&childBuf, buf);
 
     if (!type) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -24762,7 +24760,7 @@ virDomainCputuneDefFormat(virBufferPtr buf,
     virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
     int ret = -1;
 
-    virBufferAdjustIndent(&childrenBuf, virBufferGetIndent(buf, false) + 2);
+    virBufferSetChildIndent(&childrenBuf, buf);
 
     if (def->cputune.sharesSpecified)
         virBufferAsprintf(&childrenBuf, "<shares>%llu</shares>\n",
@@ -24944,7 +24942,7 @@ virDomainIOMMUDefFormat(virBufferPtr buf,
 {
     virBuffer childBuf = VIR_BUFFER_INITIALIZER;
 
-    virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
+    virBufferSetChildIndent(&childBuf, buf);
 
     if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT ||
         iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT ||
@@ -24998,7 +24996,6 @@ virDomainDefFormatInternal(virDomainDefPtr def,
     int n;
     size_t i;
     virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
-    int indent;
     char *netprefix = NULL;
 
     virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS |
@@ -25076,8 +25073,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                       def->mem.cur_balloon);
 
     /* start format blkiotune */
-    indent = virBufferGetIndent(buf, false);
-    virBufferAdjustIndent(&childrenBuf, indent + 2);
+    virBufferSetChildIndent(&childrenBuf, buf);
     if (def->blkio.weight)
         virBufferAsprintf(&childrenBuf, "<weight>%u</weight>\n",
                           def->blkio.weight);
index f34217968b83ccb4c4826b97636a88844de6e749..6ad9c3ec54627243a95e496d78908b56ad7244ce 100644 (file)
@@ -102,6 +102,15 @@ void virBufferURIEncodeString(virBufferPtr buf, const char *str);
 void virBufferAdjustIndent(virBufferPtr buf, int indent);
 void virBufferSetIndent(virBufferPtr, int indent);
 
+/**
+ * virBufferSetChildIndent
+ *
+ * Gets the parent indentation, increments it by 2 and sets it to
+ * child buffer.
+ */
+# define virBufferSetChildIndent(childBuf_, parentBuf_) \
+    virBufferAdjustIndent(childBuf_, virBufferGetIndent(parentBuf_, false) + 2)
+
 int virBufferGetIndent(const virBuffer *buf, bool dynamic);
 
 void virBufferTrim(virBufferPtr buf, const char *trim, int len);