qemu: domain: Use virXMLFormatElement in qemuDomainObjPrivateXMLFormatJob

Modernize the code by using the clever formatter rather than checking
manually when to format the end of the element.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Peter Krempa 2018-03-01 18:16:38 +01:00
parent 3a4649b532
commit d8be0f4bc3

View File

@ -2057,11 +2057,13 @@ qemuDomainObjPrivateXMLFormatAllowReboot(virBufferPtr buf,
} }
static void static int
qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf, qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
virDomainObjPtr vm, virDomainObjPtr vm,
qemuDomainObjPrivatePtr priv) qemuDomainObjPrivatePtr priv)
{ {
virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
virBuffer childBuf = VIR_BUFFER_INITIALIZER;
qemuDomainJob job = priv->job.active; qemuDomainJob job = priv->job.active;
if (!qemuDomainTrackJob(job)) if (!qemuDomainTrackJob(job))
@ -2069,37 +2071,34 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
if (job == QEMU_JOB_NONE && if (job == QEMU_JOB_NONE &&
priv->job.asyncJob == QEMU_ASYNC_JOB_NONE) priv->job.asyncJob == QEMU_ASYNC_JOB_NONE)
return; return 0;
virBufferAsprintf(buf, "<job type='%s' async='%s'", virBufferSetChildIndent(&childBuf, buf);
virBufferAsprintf(&attrBuf, " type='%s' async='%s'",
qemuDomainJobTypeToString(job), qemuDomainJobTypeToString(job),
qemuDomainAsyncJobTypeToString(priv->job.asyncJob)); qemuDomainAsyncJobTypeToString(priv->job.asyncJob));
if (priv->job.phase) { if (priv->job.phase) {
virBufferAsprintf(buf, " phase='%s'", virBufferAsprintf(&attrBuf, " phase='%s'",
qemuDomainAsyncJobPhaseToString(priv->job.asyncJob, qemuDomainAsyncJobPhaseToString(priv->job.asyncJob,
priv->job.phase)); priv->job.phase));
} }
if (priv->job.asyncJob != QEMU_ASYNC_JOB_MIGRATION_OUT) {
virBufferAddLit(buf, "/>\n"); if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT) {
} else {
size_t i; size_t i;
virDomainDiskDefPtr disk; virDomainDiskDefPtr disk;
qemuDomainDiskPrivatePtr diskPriv; qemuDomainDiskPrivatePtr diskPriv;
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
for (i = 0; i < vm->def->ndisks; i++) { for (i = 0; i < vm->def->ndisks; i++) {
disk = vm->def->disks[i]; disk = vm->def->disks[i];
diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
virBufferAsprintf(buf, "<disk dev='%s' migrating='%s'/>\n", virBufferAsprintf(&childBuf, "<disk dev='%s' migrating='%s'/>\n",
disk->dst, disk->dst, diskPriv->migrating ? "yes" : "no");
diskPriv->migrating ? "yes" : "no");
} }
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</job>\n");
} }
return virXMLFormatElement(buf, "job", &attrBuf, &childBuf);
} }
@ -2159,7 +2158,8 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf,
if (priv->lockState) if (priv->lockState)
virBufferAsprintf(buf, "<lockstate>%s</lockstate>\n", priv->lockState); virBufferAsprintf(buf, "<lockstate>%s</lockstate>\n", priv->lockState);
qemuDomainObjPrivateXMLFormatJob(buf, vm, priv); if (qemuDomainObjPrivateXMLFormatJob(buf, vm, priv) < 0)
return -1;
if (priv->fakeReboot) if (priv->fakeReboot)
virBufferAddLit(buf, "<fakereboot/>\n"); virBufferAddLit(buf, "<fakereboot/>\n");