We move functions `qemuDomainObjPrivateXMLParseJob` and
`qemuDomainObjPrivateXMLFormatJob` to `qemu_domainjob`.
To make this happen, corresponding changes in their
parameters were made, as well as they were exposed
to be used in `qemu_domain` file.
Signed-off-by: Prathamesh Chavan <pc44800(a)gmail.com>
---
src/qemu/qemu_domain.c | 245 +-------------------------------------
src/qemu/qemu_domainjob.c | 244 +++++++++++++++++++++++++++++++++++++
src/qemu/qemu_domainjob.h | 8 ++
3 files changed, 254 insertions(+), 243 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2d9d8226d6..10d2033db1 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2168,102 +2168,6 @@ qemuDomainObjPrivateXMLFormatPR(virBufferPtr buf,
}
-static int
-qemuDomainObjPrivateXMLFormatNBDMigrationSource(virBufferPtr buf,
- virStorageSourcePtr src,
- virDomainXMLOptionPtr xmlopt)
-{
- g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
- g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
-
- virBufferAsprintf(&attrBuf, " type='%s' format='%s'",
- virStorageTypeToString(src->type),
- virStorageFileFormatTypeToString(src->format));
-
- if (virDomainDiskSourceFormat(&childBuf, src, "source", 0, false,
- VIR_DOMAIN_DEF_FORMAT_STATUS,
- false, false, xmlopt) < 0)
- return -1;
-
- virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf);
-
- return 0;
-}
-
-
-static int
-qemuDomainObjPrivateXMLFormatNBDMigration(virBufferPtr buf,
- virDomainObjPtr vm)
-{
- qemuDomainObjPrivatePtr priv = vm->privateData;
- size_t i;
- virDomainDiskDefPtr disk;
- qemuDomainDiskPrivatePtr diskPriv;
-
- for (i = 0; i < vm->def->ndisks; i++) {
- g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
- g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
- disk = vm->def->disks[i];
- diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
-
- virBufferAsprintf(&attrBuf, " dev='%s'
migrating='%s'",
- disk->dst, diskPriv->migrating ? "yes" :
"no");
-
- if (diskPriv->migrSource &&
- qemuDomainObjPrivateXMLFormatNBDMigrationSource(&childBuf,
- diskPriv->migrSource,
- priv->driver->xmlopt)
< 0)
- return -1;
-
- virXMLFormatElement(buf, "disk", &attrBuf, &childBuf);
- }
-
- return 0;
-}
-
-
-static int
-qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
- virDomainObjPtr vm,
- qemuDomainObjPrivatePtr priv)
-{
- g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
- g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
- qemuDomainJob job = priv->job.active;
-
- if (!qemuDomainTrackJob(job))
- job = QEMU_JOB_NONE;
-
- if (job == QEMU_JOB_NONE &&
- priv->job.asyncJob == QEMU_ASYNC_JOB_NONE)
- return 0;
-
- virBufferAsprintf(&attrBuf, " type='%s' async='%s'",
- qemuDomainJobTypeToString(job),
- qemuDomainAsyncJobTypeToString(priv->job.asyncJob));
-
- if (priv->job.phase) {
- virBufferAsprintf(&attrBuf, " phase='%s'",
- qemuDomainAsyncJobPhaseToString(priv->job.asyncJob,
- priv->job.phase));
- }
-
- if (priv->job.asyncJob != QEMU_ASYNC_JOB_NONE)
- virBufferAsprintf(&attrBuf, " flags='0x%lx'",
priv->job.apiFlags);
-
- if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT &&
- qemuDomainObjPrivateXMLFormatNBDMigration(&childBuf, vm) < 0)
- return -1;
-
- if (priv->job.migParams)
- qemuMigrationParamsFormat(&childBuf, priv->job.migParams);
-
- virXMLFormatElement(buf, "job", &attrBuf, &childBuf);
-
- return 0;
-}
-
-
static bool
qemuDomainHasSlirp(virDomainObjPtr vm)
{
@@ -2399,7 +2303,7 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf,
if (priv->lockState)
virBufferAsprintf(buf, "<lockstate>%s</lockstate>\n",
priv->lockState);
- if (qemuDomainObjPrivateXMLFormatJob(buf, vm, priv) < 0)
+ if (qemuDomainObjPrivateXMLFormatJob(buf, vm) < 0)
return -1;
if (priv->fakeReboot)
@@ -2899,151 +2803,6 @@ qemuDomainObjPrivateXMLParsePR(xmlXPathContextPtr ctxt,
}
-static int
-qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node,
- xmlXPathContextPtr ctxt,
- virDomainDiskDefPtr disk,
- virDomainXMLOptionPtr xmlopt)
-{
- VIR_XPATH_NODE_AUTORESTORE(ctxt);
- qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
- g_autofree char *format = NULL;
- g_autofree char *type = NULL;
- g_autoptr(virStorageSource) migrSource = NULL;
- xmlNodePtr sourceNode;
-
- ctxt->node = node;
-
- if (!(ctxt->node = virXPathNode("./migrationSource", ctxt)))
- return 0;
-
- if (!(type = virXMLPropString(ctxt->node, "type"))) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("missing storage source type"));
- return -1;
- }
-
- if (!(format = virXMLPropString(ctxt->node, "format"))) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("missing storage source format"));
- return -1;
- }
-
- if (!(migrSource = virDomainStorageSourceParseBase(type, format, NULL)))
- return -1;
-
- /* newer libvirt uses the <source> subelement instead of formatting the
- * source directly into <migrationSource> */
- if ((sourceNode = virXPathNode("./source", ctxt)))
- ctxt->node = sourceNode;
-
- if (virDomainStorageSourceParse(ctxt->node, ctxt, migrSource,
- VIR_DOMAIN_DEF_PARSE_STATUS, xmlopt) < 0)
- return -1;
-
- diskPriv->migrSource = g_steal_pointer(&migrSource);
- return 0;
-}
-
-
-static int
-qemuDomainObjPrivateXMLParseJobNBD(virDomainObjPtr vm,
- qemuDomainObjPrivatePtr priv,
- xmlXPathContextPtr ctxt)
-{
- g_autofree xmlNodePtr *nodes = NULL;
- size_t i;
- int n;
-
- if ((n = virXPathNodeSet("./disk[@migrating='yes']", ctxt,
&nodes)) < 0)
- return -1;
-
- if (n > 0) {
- if (priv->job.asyncJob != QEMU_ASYNC_JOB_MIGRATION_OUT) {
- VIR_WARN("Found disks marked for migration but we were not "
- "migrating");
- n = 0;
- }
- for (i = 0; i < n; i++) {
- virDomainDiskDefPtr disk;
- g_autofree char *dst = NULL;
-
- if ((dst = virXMLPropString(nodes[i], "dev")) &&
- (disk = virDomainDiskByTarget(vm->def, dst))) {
- QEMU_DOMAIN_DISK_PRIVATE(disk)->migrating = true;
-
- if (qemuDomainObjPrivateXMLParseJobNBDSource(nodes[i], ctxt,
- disk,
- priv->driver->xmlopt)
< 0)
- return -1;
- }
- }
- }
-
- return 0;
-}
-
-
-static int
-qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
- qemuDomainObjPrivatePtr priv,
- xmlXPathContextPtr ctxt)
-{
- VIR_XPATH_NODE_AUTORESTORE(ctxt);
- g_autofree char *tmp = NULL;
-
- if (!(ctxt->node = virXPathNode("./job[1]", ctxt)))
- return 0;
-
- if ((tmp = virXPathString("string(@type)", ctxt))) {
- int type;
-
- if ((type = qemuDomainJobTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unknown job type %s"), tmp);
- return -1;
- }
- VIR_FREE(tmp);
- priv->job.active = type;
- }
-
- if ((tmp = virXPathString("string(@async)", ctxt))) {
- int async;
-
- if ((async = qemuDomainAsyncJobTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unknown async job type %s"), tmp);
- return -1;
- }
- VIR_FREE(tmp);
- priv->job.asyncJob = async;
-
- if ((tmp = virXPathString("string(@phase)", ctxt))) {
- priv->job.phase = qemuDomainAsyncJobPhaseFromString(async, tmp);
- if (priv->job.phase < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unknown job phase %s"), tmp);
- return -1;
- }
- VIR_FREE(tmp);
- }
- }
-
- if (virXPathULongHex("string(@flags)", ctxt, &priv->job.apiFlags) ==
-2) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid job
flags"));
- return -1;
- }
-
- if (qemuDomainObjPrivateXMLParseJobNBD(vm, priv, ctxt) < 0)
- return -1;
-
- if (qemuMigrationParamsParse(ctxt, &priv->job.migParams) < 0)
- return -1;
-
- return 0;
-}
-
-
static int
qemuDomainObjPrivateXMLParseSlirpFeatures(xmlNodePtr featuresNode,
xmlXPathContextPtr ctxt,
@@ -3203,7 +2962,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
priv->lockState = virXPathString("string(./lockstate)", ctxt);
- if (qemuDomainObjPrivateXMLParseJob(vm, priv, ctxt) < 0)
+ if (qemuDomainObjPrivateXMLParseJob(vm, ctxt) < 0)
goto error;
priv->fakeReboot = virXPathBoolean("boolean(./fakereboot)", ctxt) == 1;
diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c
index 654f1c4f90..454a5a2c23 100644
--- a/src/qemu/qemu_domainjob.c
+++ b/src/qemu/qemu_domainjob.c
@@ -1184,3 +1184,247 @@ qemuDomainObjAbortAsyncJob(virDomainObjPtr obj)
priv->job.abortJob = true;
virDomainObjBroadcast(obj);
}
+
+
+static int
+qemuDomainObjPrivateXMLFormatNBDMigrationSource(virBufferPtr buf,
+ virStorageSourcePtr src,
+ virDomainXMLOptionPtr xmlopt)
+{
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+
+ virBufferAsprintf(&attrBuf, " type='%s' format='%s'",
+ virStorageTypeToString(src->type),
+ virStorageFileFormatTypeToString(src->format));
+
+ if (virDomainDiskSourceFormat(&childBuf, src, "source", 0, false,
+ VIR_DOMAIN_DEF_FORMAT_STATUS,
+ false, false, xmlopt) < 0)
+ return -1;
+
+ virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf);
+
+ return 0;
+}
+
+
+static int
+qemuDomainObjPrivateXMLFormatNBDMigration(virBufferPtr buf,
+ virDomainObjPtr vm)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ size_t i;
+ virDomainDiskDefPtr disk;
+ qemuDomainDiskPrivatePtr diskPriv;
+
+ for (i = 0; i < vm->def->ndisks; i++) {
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+ disk = vm->def->disks[i];
+ diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+
+ virBufferAsprintf(&attrBuf, " dev='%s'
migrating='%s'",
+ disk->dst, diskPriv->migrating ? "yes" :
"no");
+
+ if (diskPriv->migrSource &&
+ qemuDomainObjPrivateXMLFormatNBDMigrationSource(&childBuf,
+ diskPriv->migrSource,
+ priv->driver->xmlopt)
< 0)
+ return -1;
+
+ virXMLFormatElement(buf, "disk", &attrBuf, &childBuf);
+ }
+
+ return 0;
+}
+
+
+int
+qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
+ virDomainObjPtr vm)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ qemuDomainJobObjPtr jobObj = &priv->job;
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+ qemuDomainJob job = jobObj->active;
+
+ if (!qemuDomainTrackJob(job))
+ job = QEMU_JOB_NONE;
+
+ if (job == QEMU_JOB_NONE &&
+ jobObj->asyncJob == QEMU_ASYNC_JOB_NONE)
+ return 0;
+
+ virBufferAsprintf(&attrBuf, " type='%s' async='%s'",
+ qemuDomainJobTypeToString(job),
+ qemuDomainAsyncJobTypeToString(jobObj->asyncJob));
+
+ if (jobObj->phase) {
+ virBufferAsprintf(&attrBuf, " phase='%s'",
+ qemuDomainAsyncJobPhaseToString(jobObj->asyncJob,
+ jobObj->phase));
+ }
+
+ if (jobObj->asyncJob != QEMU_ASYNC_JOB_NONE)
+ virBufferAsprintf(&attrBuf, " flags='0x%lx'",
jobObj->apiFlags);
+
+ if (jobObj->asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT &&
+ qemuDomainObjPrivateXMLFormatNBDMigration(&childBuf, vm) < 0)
+ return -1;
+
+ if (jobObj->migParams)
+ qemuMigrationParamsFormat(&childBuf, jobObj->migParams);
+
+ virXMLFormatElement(buf, "job", &attrBuf, &childBuf);
+
+ return 0;
+}
+
+
+static int
+qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
+ virDomainDiskDefPtr disk,
+ virDomainXMLOptionPtr xmlopt)
+{
+ VIR_XPATH_NODE_AUTORESTORE(ctxt);
+ qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+ g_autofree char *format = NULL;
+ g_autofree char *type = NULL;
+ g_autoptr(virStorageSource) migrSource = NULL;
+ xmlNodePtr sourceNode;
+
+ ctxt->node = node;
+
+ if (!(ctxt->node = virXPathNode("./migrationSource", ctxt)))
+ return 0;
+
+ if (!(type = virXMLPropString(ctxt->node, "type"))) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("missing storage source type"));
+ return -1;
+ }
+
+ if (!(format = virXMLPropString(ctxt->node, "format"))) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("missing storage source format"));
+ return -1;
+ }
+
+ if (!(migrSource = virDomainStorageSourceParseBase(type, format, NULL)))
+ return -1;
+
+ /* newer libvirt uses the <source> subelement instead of formatting the
+ * source directly into <migrationSource> */
+ if ((sourceNode = virXPathNode("./source", ctxt)))
+ ctxt->node = sourceNode;
+
+ if (virDomainStorageSourceParse(ctxt->node, ctxt, migrSource,
+ VIR_DOMAIN_DEF_PARSE_STATUS, xmlopt) < 0)
+ return -1;
+
+ diskPriv->migrSource = g_steal_pointer(&migrSource);
+ return 0;
+}
+
+
+static int
+qemuDomainObjPrivateXMLParseJobNBD(virDomainObjPtr vm,
+ xmlXPathContextPtr ctxt)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ qemuDomainJobObjPtr job = &priv->job;
+ virDomainXMLOptionPtr xmlopt = priv->driver->xmlopt;
+ g_autofree xmlNodePtr *nodes = NULL;
+ size_t i;
+ int n;
+
+ if ((n = virXPathNodeSet("./disk[@migrating='yes']", ctxt,
&nodes)) < 0)
+ return -1;
+
+ if (n > 0) {
+ if (job->asyncJob != QEMU_ASYNC_JOB_MIGRATION_OUT) {
+ VIR_WARN("Found disks marked for migration but we were not "
+ "migrating");
+ n = 0;
+ }
+ for (i = 0; i < n; i++) {
+ virDomainDiskDefPtr disk;
+ g_autofree char *dst = NULL;
+
+ if ((dst = virXMLPropString(nodes[i], "dev")) &&
+ (disk = virDomainDiskByTarget(vm->def, dst))) {
+ QEMU_DOMAIN_DISK_PRIVATE(disk)->migrating = true;
+
+ if (qemuDomainObjPrivateXMLParseJobNBDSource(nodes[i], ctxt,
+ disk,
+ xmlopt) < 0)
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+int
+qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
+ xmlXPathContextPtr ctxt)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ qemuDomainJobObjPtr job = &priv->job;
+ VIR_XPATH_NODE_AUTORESTORE(ctxt);
+ g_autofree char *tmp = NULL;
+
+ if (!(ctxt->node = virXPathNode("./job[1]", ctxt)))
+ return 0;
+
+ if ((tmp = virXPathString("string(@type)", ctxt))) {
+ int type;
+
+ if ((type = qemuDomainJobTypeFromString(tmp)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unknown job type %s"), tmp);
+ return -1;
+ }
+ VIR_FREE(tmp);
+ job->active = type;
+ }
+
+ if ((tmp = virXPathString("string(@async)", ctxt))) {
+ int async;
+
+ if ((async = qemuDomainAsyncJobTypeFromString(tmp)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unknown async job type %s"), tmp);
+ return -1;
+ }
+ VIR_FREE(tmp);
+ job->asyncJob = async;
+
+ if ((tmp = virXPathString("string(@phase)", ctxt))) {
+ job->phase = qemuDomainAsyncJobPhaseFromString(async, tmp);
+ if (job->phase < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unknown job phase %s"), tmp);
+ return -1;
+ }
+ VIR_FREE(tmp);
+ }
+ }
+
+ if (virXPathULongHex("string(@flags)", ctxt, &job->apiFlags) == -2)
{
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid job
flags"));
+ return -1;
+ }
+
+ if (qemuDomainObjPrivateXMLParseJobNBD(vm, ctxt) < 0)
+ return -1;
+
+ if (qemuMigrationParamsParse(ctxt, &job->migParams) < 0)
+ return -1;
+
+ return 0;
+}
diff --git a/src/qemu/qemu_domainjob.h b/src/qemu/qemu_domainjob.h
index 124664354d..9d2ee14584 100644
--- a/src/qemu/qemu_domainjob.h
+++ b/src/qemu/qemu_domainjob.h
@@ -267,3 +267,11 @@ void qemuDomainObjFreeJob(qemuDomainJobObjPtr job);
int qemuDomainObjInitJob(qemuDomainJobObjPtr job);
bool qemuDomainJobAllowed(qemuDomainJobObjPtr jobs, qemuDomainJob newJob);
+
+int
+qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
+ virDomainObjPtr vm);
+
+int
+qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
+ xmlXPathContextPtr ctxt);
--
2.17.1