virDomainObjGetOneDef will help to retrieve the correct definition pointer from @vm in cases where VIR_DOMAIN_AFFECT_LIVE and VIR_DOMAIN_AFFECT_CONFIG are mutually exclusive. The function simply returns the correct pointer. This similarly to virDomainObjGetDefs will greatly simplify the code. --- src/conf/domain_conf.c | 36 ++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 1 + src/libvirt_private.syms | 1 + 3 files changed, 38 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3cc182b..35e1cb4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2948,6 +2948,42 @@ virDomainObjGetDefs(virDomainObjPtr vm, } +/** + * virDomainObjGetOneDef: + * + * @vm: Domain object + * @flags: for virDomainModificationImpact + * + * Helper function to resolve @flags and return the correct domain pointer + * object. This function returns one of @vm->def or @vm->persistentDef + * according to @flags. This helper should be used only in APIs that guarantee + * that @flags contains exactly one of VIR_DOMAIN_AFFECT_LIVE, + * VIR_DOMAIN_AFFECT_CONFIG. + * + * Returns the correct definition pointer or NULL on error. + */ +virDomainDefPtr +virDomainObjGetOneDef(virDomainObjPtr vm, + unsigned int flags) +{ + if (flags & VIR_DOMAIN_AFFECT_LIVE && flags & VIR_DOMAIN_AFFECT_CONFIG) { + virReportInvalidArg(ctl, "%s", + _("Flags 'VIR_DOMAIN_AFFECT_LIVE' and " + "'VIR_DOMAIN_AFFECT_CONFIG' are mutually " + "exclusive")); + return NULL; + } + + if (virDomainObjUpdateModificationImpact(vm, &flags) < 0) + return NULL; + + if (virDomainObjIsActive(vm) && flags & VIR_DOMAIN_AFFECT_CONFIG) + return vm->newDef; + else + return vm->def; +} + + /* * The caller must hold a lock on the driver owning 'doms', * and must also have locked 'dom', to ensure no one else diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ba17a8d..db49d46 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2553,6 +2553,7 @@ int virDomainObjGetDefs(virDomainObjPtr vm, unsigned int flags, virDomainDefPtr *liveDef, virDomainDefPtr *persDef); +virDomainDefPtr virDomainObjGetOneDef(virDomainObjPtr vm, unsigned int flags); int virDomainLiveConfigHelperMethod(virCapsPtr caps, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index dc8a52d..858c00f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -385,6 +385,7 @@ virDomainObjEndAPI; virDomainObjFormat; virDomainObjGetDefs; virDomainObjGetMetadata; +virDomainObjGetOneDef; virDomainObjGetPersistentDef; virDomainObjGetState; virDomainObjListAdd; -- 2.4.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list