Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- src/conf/capabilities.c | 3 +-- src/conf/cpu_conf.c | 3 +-- src/conf/domain_conf.c | 26 +++++++++++--------------- src/util/virbuffer.h | 9 +++++++++ 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 69af3911a0..ba554535ae 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -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); diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index cdb8583647..c21d11d244 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -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)); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 478feb92d8..b8867fd1ea 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -22004,7 +22004,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, @@ -23287,7 +23287,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, @@ -23396,7 +23396,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, @@ -23432,7 +23432,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, @@ -23446,7 +23445,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); @@ -23508,7 +23507,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, @@ -23545,7 +23544,6 @@ static int virDomainPanicDefFormat(virBufferPtr buf, virDomainPanicDefPtr def) { virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; - int indent = virBufferGetIndent(buf, false); virBufferAddLit(buf, "<panic"); @@ -23553,7 +23551,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) @@ -23888,7 +23886,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; @@ -24538,7 +24536,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, @@ -24751,7 +24749,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", @@ -24933,7 +24931,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 || @@ -24987,7 +24985,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 | @@ -25065,8 +25062,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); diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index f34217968b..6ad9c3ec54 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -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); -- 2.13.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list