mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
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:
parent
3a4649b532
commit
d8be0f4bc3
@ -2057,11 +2057,13 @@ qemuDomainObjPrivateXMLFormatAllowReboot(virBufferPtr buf,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
static int
|
||||
qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
|
||||
virDomainObjPtr vm,
|
||||
qemuDomainObjPrivatePtr priv)
|
||||
{
|
||||
virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
|
||||
virBuffer childBuf = VIR_BUFFER_INITIALIZER;
|
||||
qemuDomainJob job = priv->job.active;
|
||||
|
||||
if (!qemuDomainTrackJob(job))
|
||||
@ -2069,37 +2071,34 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
|
||||
|
||||
if (job == QEMU_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),
|
||||
qemuDomainAsyncJobTypeToString(priv->job.asyncJob));
|
||||
|
||||
if (priv->job.phase) {
|
||||
virBufferAsprintf(buf, " phase='%s'",
|
||||
virBufferAsprintf(&attrBuf, " phase='%s'",
|
||||
qemuDomainAsyncJobPhaseToString(priv->job.asyncJob,
|
||||
priv->job.phase));
|
||||
}
|
||||
if (priv->job.asyncJob != QEMU_ASYNC_JOB_MIGRATION_OUT) {
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
} else {
|
||||
|
||||
if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT) {
|
||||
size_t i;
|
||||
virDomainDiskDefPtr disk;
|
||||
qemuDomainDiskPrivatePtr diskPriv;
|
||||
|
||||
virBufferAddLit(buf, ">\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
for (i = 0; i < vm->def->ndisks; i++) {
|
||||
disk = vm->def->disks[i];
|
||||
diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
||||
virBufferAsprintf(buf, "<disk dev='%s' migrating='%s'/>\n",
|
||||
disk->dst,
|
||||
diskPriv->migrating ? "yes" : "no");
|
||||
virBufferAsprintf(&childBuf, "<disk dev='%s' migrating='%s'/>\n",
|
||||
disk->dst, 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)
|
||||
virBufferAsprintf(buf, "<lockstate>%s</lockstate>\n", priv->lockState);
|
||||
|
||||
qemuDomainObjPrivateXMLFormatJob(buf, vm, priv);
|
||||
if (qemuDomainObjPrivateXMLFormatJob(buf, vm, priv) < 0)
|
||||
return -1;
|
||||
|
||||
if (priv->fakeReboot)
|
||||
virBufferAddLit(buf, "<fakereboot/>\n");
|
||||
|
Loading…
Reference in New Issue
Block a user