mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
util: introduce virBufferSetChildIndent macro
Reviewed-by: John Ferlan <jferlan@redhat.com> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
30fca06a11
commit
ef3ea17f62
@ -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);
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user