In some cases, caller of libxlDomainObjListAdd() tries to acquire MODIFY job after the call. Let's adjust libxlDomainObjListAdd() so that it will keep the job set upon return (if requested by caller). Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/libxl/libxl_domain.c | 17 ++++++++++++++--- src/libxl/libxl_domain.h | 1 + src/libxl/libxl_driver.c | 24 +++++++----------------- src/libxl/libxl_migration.c | 18 ++---------------- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index f2e1af52e5..8e45ac512a 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -72,6 +72,7 @@ VIR_ONCE_GLOBAL_INIT(libxlDomainObjPrivate); * @def: domain definition * @oldDef: previous domain definition * @live: whether @def is live definition + * @keepJob: whether to leave MODIFY job set on returned object * @flags: an bitwise-OR of virDomainObjListAdd flags * * Add a domain onto the list of domain object and sets its @@ -81,6 +82,10 @@ VIR_ONCE_GLOBAL_INIT(libxlDomainObjPrivate); * In addition to that, if definition of an existing domain is * changed a MODIFY job is acquired prior to that. * + * If @keepJob is true, then the MODIFY job is not ended upon + * successful return from this function. This might be handy if + * caller would try to acquire the job anyway. + * * Returns: domain object pointer on success, * NULL otherwise. */ @@ -89,9 +94,11 @@ libxlDomainObjListAdd(libxlDriverPrivatePtr driver, virDomainDefPtr def, virDomainDefPtr *oldDef, bool live, + bool keepJob, unsigned int flags) { virDomainObjPtr vm = NULL; + bool defSet = false; if (!(vm = virDomainObjListAdd(driver->domains, def, driver->xmlopt, flags))) return NULL; @@ -102,7 +109,9 @@ libxlDomainObjListAdd(libxlDriverPrivatePtr driver, * just set the definition without acquiring job. */ if (!vm->def) { virDomainObjAssignDef(vm, def, live, oldDef); - VIR_RETURN_PTR(vm); + defSet = true; + if (!keepJob) + VIR_RETURN_PTR(vm); } /* Bad luck. Domain was pre-existing and this call is trying @@ -114,9 +123,11 @@ libxlDomainObjListAdd(libxlDriverPrivatePtr driver, return NULL; } - virDomainObjAssignDef(vm, def, live, oldDef); + if (!defSet) + virDomainObjAssignDef(vm, def, live, oldDef); - libxlDomainObjEndJob(driver, vm); + if (!keepJob) + libxlDomainObjEndJob(driver, vm); return vm; } diff --git a/src/libxl/libxl_domain.h b/src/libxl/libxl_domain.h index b5d5127e91..b04bbb6c51 100644 --- a/src/libxl/libxl_domain.h +++ b/src/libxl/libxl_domain.h @@ -88,6 +88,7 @@ libxlDomainObjListAdd(libxlDriverPrivatePtr driver, virDomainDefPtr def, virDomainDefPtr *oldDef, bool live, + bool keepJob, unsigned int flags); int diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 9c9a30bb90..8a9a8baf79 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -601,7 +601,7 @@ libxlAddDom0(libxlDriverPrivatePtr driver) if (virUUIDParse("00000000-0000-0000-0000-000000000000", def->uuid) < 0) goto cleanup; - if (!(vm = libxlDomainObjListAdd(driver, def, &oldDef, false, 0))) + if (!(vm = libxlDomainObjListAdd(driver, def, &oldDef, false, false, 0))) goto cleanup; def = NULL; @@ -1026,17 +1026,11 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml, if (virDomainCreateXMLEnsureACL(conn, def) < 0) goto cleanup; - if (!(vm = libxlDomainObjListAdd(driver, def, NULL, true, + if (!(vm = libxlDomainObjListAdd(driver, def, NULL, true, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; def = NULL; - if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { - if (!vm->persistent) - virDomainObjListRemove(driver->domains, vm); - goto cleanup; - } - if (libxlDomainStartNew(driver, vm, (flags & VIR_DOMAIN_START_PAUSED) != 0) < 0) { if (!vm->persistent) @@ -1943,17 +1937,11 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from, if (virDomainRestoreFlagsEnsureACL(conn, def) < 0) goto cleanup; - if (!(vm = libxlDomainObjListAdd(driver, def, NULL, true, + if (!(vm = libxlDomainObjListAdd(driver, def, NULL, true, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; def = NULL; - if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { - if (!vm->persistent) - virDomainObjListRemove(driver->domains, vm); - goto cleanup; - } - ret = libxlDomainStartRestore(driver, vm, (flags & VIR_DOMAIN_SAVE_PAUSED) != 0, fd, hdr.version); @@ -2840,7 +2828,7 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; - if (!(vm = libxlDomainObjListAdd(driver, def, &oldDef, false, 0))) + if (!(vm = libxlDomainObjListAdd(driver, def, &oldDef, false, true, 0))) goto cleanup; def = NULL; @@ -2850,7 +2838,7 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag cfg->caps, vm->newDef ? vm->newDef : vm->def) < 0) { virDomainObjListRemove(driver->domains, vm); - goto cleanup; + goto endjob; } dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); @@ -2859,6 +2847,8 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag !oldDef ? VIR_DOMAIN_EVENT_DEFINED_ADDED : VIR_DOMAIN_EVENT_DEFINED_UPDATED); + endjob: + libxlDomainObjEndJob(driver, vm); cleanup: virDomainDefFree(def); diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index d0b0142900..e498846371 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -566,18 +566,11 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn, &mig, &xmlout, &taint_hook) < 0) goto error; - if (!(vm = libxlDomainObjListAdd(driver, *def, NULL, true, + if (!(vm = libxlDomainObjListAdd(driver, *def, NULL, true, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto error; *def = NULL; - /* - * Unless an error is encountered in this function, the job will - * be terminated in the finish phase. - */ - if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) - goto error; - priv = vm->privateData; if (taint_hook) { @@ -672,18 +665,11 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn, &mig, &xmlout, &taint_hook) < 0) goto error; - if (!(vm = libxlDomainObjListAdd(driver, *def, NULL, true, + if (!(vm = libxlDomainObjListAdd(driver, *def, NULL, true, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto error; *def = NULL; - /* - * Unless an error is encountered in this function, the job will - * be terminated in the finish phase. - */ - if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) - goto error; - priv = vm->privateData; if (taint_hook) { -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list