conf: eliminate hardcoded indent from domain xml

Many of the domain xml format functions (including all of the device
format functions) had hard-coded spaces, which made for incorrect
indentation when those functions were called in a different context
(for example, commit 2122cf39 added <interface> XML into the document
provided to a network hook script, and in this case it should have
been indented by 2 spaces, but was instead indented by 6 spaces).

To make it possible to insert a properly indented device anywhere into
an XML document, this patch removes hardcoded spaces from the
formatting functions, and calls virBufferAdjustIndent() at appropriate
places instead. (a regex search of domain_conf.c was done to assure
that all occurrences of hardcoded spaces were removed).

virDomainDiskSourceDefFormatInternal() is also called from
snapshot_conf.c, so two virBufferAdjustIndent() calls were temporarily
added around that call - those functions will have hardcoded spaces
removed in a separate patch.

This could cause some conflicts when backporting future changes to the
formatting functions to older branches, but fortunately the changes
are almost all trivial, so conflict resolution will be obvious.
This commit is contained in:
Laine Stump 2014-03-05 11:50:42 +02:00
parent a81756f1ff
commit ca6dc7b585
4 changed files with 366 additions and 288 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
/*
* snapshot_conf.c: domain snapshot XML processing
*
* Copyright (C) 2006-2013 Red Hat, Inc.
* Copyright (C) 2006-2014 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@ -630,6 +630,7 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
if (disk->format > 0)
virBufferEscapeString(buf, " <driver type='%s'/>\n",
virStorageFileFormatTypeToString(disk->format));
virBufferAdjustIndent(buf, 6);
virDomainDiskSourceDefFormatInternal(buf,
type,
disk->file,
@ -639,6 +640,7 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
disk->hosts,
0, NULL, NULL, 0);
virBufferAdjustIndent(buf, -6);
virBufferAddLit(buf, " </disk>\n");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2013 Red Hat, Inc.
* Copyright (C) 2010-2014 Red Hat, Inc.
* Copyright IBM Corp. 2008
*
* lxc_domain.h: LXC domain helpers
@ -53,7 +53,7 @@ static int virLXCDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
{
virLXCDomainObjPrivatePtr priv = data;
virBufferAsprintf(buf, " <init pid='%llu'/>\n",
virBufferAsprintf(buf, "<init pid='%llu'/>\n",
(unsigned long long)priv->initpid);
return 0;

View File

@ -1,7 +1,7 @@
/*
* qemu_domain.c: QEMU domain private state
*
* Copyright (C) 2006-2013 Red Hat, Inc.
* Copyright (C) 2006-2014 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@ -287,7 +287,7 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
break;
}
virBufferEscapeString(buf, " <monitor path='%s'", monitorpath);
virBufferEscapeString(buf, "<monitor path='%s'", monitorpath);
if (priv->monJSON)
virBufferAddLit(buf, " json='1'");
virBufferAsprintf(buf, " type='%s'/>\n",
@ -297,34 +297,38 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
if (priv->nvcpupids) {
size_t i;
virBufferAddLit(buf, " <vcpus>\n");
virBufferAddLit(buf, "<vcpus>\n");
virBufferAdjustIndent(buf, 2);
for (i = 0; i < priv->nvcpupids; i++) {
virBufferAsprintf(buf, " <vcpu pid='%d'/>\n", priv->vcpupids[i]);
virBufferAsprintf(buf, "<vcpu pid='%d'/>\n", priv->vcpupids[i]);
}
virBufferAddLit(buf, " </vcpus>\n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</vcpus>\n");
}
if (priv->qemuCaps) {
size_t i;
virBufferAddLit(buf, " <qemuCaps>\n");
virBufferAddLit(buf, "<qemuCaps>\n");
virBufferAdjustIndent(buf, 2);
for (i = 0; i < QEMU_CAPS_LAST; i++) {
if (virQEMUCapsGet(priv->qemuCaps, i)) {
virBufferAsprintf(buf, " <flag name='%s'/>\n",
virBufferAsprintf(buf, "<flag name='%s'/>\n",
virQEMUCapsTypeToString(i));
}
}
virBufferAddLit(buf, " </qemuCaps>\n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</qemuCaps>\n");
}
if (priv->lockState)
virBufferAsprintf(buf, " <lockstate>%s</lockstate>\n", priv->lockState);
virBufferAsprintf(buf, "<lockstate>%s</lockstate>\n", priv->lockState);
job = priv->job.active;
if (!qemuDomainTrackJob(job))
priv->job.active = QEMU_JOB_NONE;
if (priv->job.active || priv->job.asyncJob) {
virBufferAsprintf(buf, " <job type='%s' async='%s'",
virBufferAsprintf(buf, "<job type='%s' async='%s'",
qemuDomainJobTypeToString(priv->job.active),
qemuDomainAsyncJobTypeToString(priv->job.asyncJob));
if (priv->job.phase) {
@ -337,16 +341,18 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
priv->job.active = job;
if (priv->fakeReboot)
virBufferAddLit(buf, " <fakereboot/>\n");
virBufferAddLit(buf, "<fakereboot/>\n");
if (priv->qemuDevices && *priv->qemuDevices) {
char **tmp = priv->qemuDevices;
virBufferAddLit(buf, " <devices>\n");
virBufferAddLit(buf, "<devices>\n");
virBufferAdjustIndent(buf, 2);
while (*tmp) {
virBufferAsprintf(buf, " <device alias='%s'/>\n", *tmp);
virBufferAsprintf(buf, "<device alias='%s'/>\n", *tmp);
tmp++;
}
virBufferAddLit(buf, " </devices>\n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</devices>\n");
}
return 0;
@ -651,18 +657,21 @@ qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
if (!cmd->num_args && !cmd->num_env)
return 0;
virBufferAddLit(buf, " <qemu:commandline>\n");
virBufferAddLit(buf, "<qemu:commandline>\n");
virBufferAdjustIndent(buf, 2);
for (i = 0; i < cmd->num_args; i++)
virBufferEscapeString(buf, " <qemu:arg value='%s'/>\n",
virBufferEscapeString(buf, "<qemu:arg value='%s'/>\n",
cmd->args[i]);
for (i = 0; i < cmd->num_env; i++) {
virBufferAsprintf(buf, " <qemu:env name='%s'", cmd->env_name[i]);
virBufferAsprintf(buf, "<qemu:env name='%s'", cmd->env_name[i]);
if (cmd->env_value[i])
virBufferEscapeString(buf, " value='%s'", cmd->env_value[i]);
virBufferAddLit(buf, "/>\n");
}
virBufferAddLit(buf, " </qemu:commandline>\n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</qemu:commandline>\n");
return 0;
}