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, "%s\n",
virArchToString(def->arch));
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 646b60a83d..51a7d003dc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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, "\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, "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, "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, "%llu\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, "%u\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);