mirror of
https://github.com/libvirt/libvirt.git
synced 2026-09-03 20:53:04 -05:00
qemu_domainjob: remove dependency on qemuDomainDiskPrivatePtr
Both parsing and formatting of NBD migration jobs is QEMU specific and since we're trying to create a hypervisor-agnostic module out of qemu_domainjob.c, move the NBD XML handling bits to the qemu_domain module instead. Additionally, move the respective NBD XML calls to the 'parseJob'/'formatJob' callbacks of the qemuDomainObjPrivateJobCallbacks structure. Signed-off-by: Prathamesh Chavan <pc44800@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
committed by
Erik Skultety
parent
1ca15137da
commit
b3204e820f
+148
-2
@@ -108,12 +108,70 @@ qemuJobResetPrivate(void *opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
static int
|
||||||
qemuDomainFormatJobPrivate(virBufferPtr buf,
|
qemuDomainFormatJobPrivate(virBufferPtr buf,
|
||||||
qemuDomainJobObjPtr job)
|
qemuDomainJobObjPtr job,
|
||||||
|
virDomainObjPtr vm)
|
||||||
{
|
{
|
||||||
qemuDomainJobPrivatePtr priv = job->privateData;
|
qemuDomainJobPrivatePtr priv = job->privateData;
|
||||||
|
|
||||||
|
if (job->asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT &&
|
||||||
|
qemuDomainObjPrivateXMLFormatNBDMigration(buf, vm) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (priv->migParams)
|
if (priv->migParams)
|
||||||
qemuMigrationParamsFormat(buf, priv->migParams);
|
qemuMigrationParamsFormat(buf, priv->migParams);
|
||||||
|
|
||||||
@@ -121,12 +179,100 @@ qemuDomainFormatJobPrivate(virBufferPtr buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
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
|
static int
|
||||||
qemuDomainParseJobPrivate(xmlXPathContextPtr ctxt,
|
qemuDomainParseJobPrivate(xmlXPathContextPtr ctxt,
|
||||||
qemuDomainJobObjPtr job)
|
qemuDomainJobObjPtr job,
|
||||||
|
virDomainObjPtr vm)
|
||||||
{
|
{
|
||||||
qemuDomainJobPrivatePtr priv = job->privateData;
|
qemuDomainJobPrivatePtr priv = job->privateData;
|
||||||
|
|
||||||
|
if (qemuDomainObjPrivateXMLParseJobNBD(vm, ctxt) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (qemuMigrationParamsParse(ctxt, &priv->migParams) < 0)
|
if (qemuMigrationParamsParse(ctxt, &priv->migParams) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|||||||
+2
-148
@@ -1195,66 +1195,11 @@ qemuDomainObjAbortAsyncJob(virDomainObjPtr obj)
|
|||||||
virDomainObjBroadcast(obj);
|
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
|
int
|
||||||
qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
|
qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
|
||||||
virDomainObjPtr vm)
|
virDomainObjPtr vm)
|
||||||
{
|
{
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
qemuDomainJobObjPtr jobObj = &priv->job;
|
|
||||||
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
||||||
qemuDomainJob job = priv->job.active;
|
qemuDomainJob job = priv->job.active;
|
||||||
@@ -1279,11 +1224,7 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
|
|||||||
if (priv->job.asyncJob != QEMU_ASYNC_JOB_NONE)
|
if (priv->job.asyncJob != QEMU_ASYNC_JOB_NONE)
|
||||||
virBufferAsprintf(&attrBuf, " flags='0x%lx'", priv->job.apiFlags);
|
virBufferAsprintf(&attrBuf, " flags='0x%lx'", priv->job.apiFlags);
|
||||||
|
|
||||||
if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT &&
|
if (priv->job.cb->formatJob(&childBuf, &priv->job, vm) < 0)
|
||||||
qemuDomainObjPrivateXMLFormatNBDMigration(&childBuf, vm) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (jobObj->cb->formatJob(&childBuf, jobObj) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virXMLFormatElement(buf, "job", &attrBuf, &childBuf);
|
virXMLFormatElement(buf, "job", &attrBuf, &childBuf);
|
||||||
@@ -1292,90 +1233,6 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
|
qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
|
||||||
xmlXPathContextPtr ctxt)
|
xmlXPathContextPtr ctxt)
|
||||||
@@ -1427,10 +1284,7 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuDomainObjPrivateXMLParseJobNBD(vm, ctxt) < 0)
|
if (priv->job.cb->parseJob(ctxt, job, vm) < 0)
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (job->cb->parseJob(ctxt, job) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -161,9 +161,11 @@ typedef void *(*qemuDomainObjPrivateJobAlloc)(void);
|
|||||||
typedef void (*qemuDomainObjPrivateJobFree)(void *);
|
typedef void (*qemuDomainObjPrivateJobFree)(void *);
|
||||||
typedef void (*qemuDomainObjPrivateJobReset)(void *);
|
typedef void (*qemuDomainObjPrivateJobReset)(void *);
|
||||||
typedef int (*qemuDomainObjPrivateJobFormat)(virBufferPtr,
|
typedef int (*qemuDomainObjPrivateJobFormat)(virBufferPtr,
|
||||||
qemuDomainJobObjPtr);
|
qemuDomainJobObjPtr,
|
||||||
|
virDomainObjPtr);
|
||||||
typedef int (*qemuDomainObjPrivateJobParse)(xmlXPathContextPtr,
|
typedef int (*qemuDomainObjPrivateJobParse)(xmlXPathContextPtr,
|
||||||
qemuDomainJobObjPtr);
|
qemuDomainJobObjPtr,
|
||||||
|
virDomainObjPtr);
|
||||||
|
|
||||||
typedef struct _qemuDomainObjPrivateJobCallbacks qemuDomainObjPrivateJobCallbacks;
|
typedef struct _qemuDomainObjPrivateJobCallbacks qemuDomainObjPrivateJobCallbacks;
|
||||||
typedef qemuDomainObjPrivateJobCallbacks *qemuDomainObjPrivateJobCallbacksPtr;
|
typedef qemuDomainObjPrivateJobCallbacks *qemuDomainObjPrivateJobCallbacksPtr;
|
||||||
|
|||||||
Reference in New Issue
Block a user