From 4cc65b4967b80339110a3e82cc2e7a4451410619 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 14 Sep 2016 07:22:40 +0200 Subject: [PATCH] conf: Introduce virDomainObjGetOneDefState Return whether the live or persistent definition was returned. Sometimes it's necessary to base the decisions on this. --- src/conf/domain_conf.c | 62 ++++++++++++++++++++++++++++++---------- src/conf/domain_conf.h | 3 ++ src/libvirt_private.syms | 1 + 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a70be31989..ea246b0e6d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3117,6 +3117,52 @@ virDomainObjGetDefs(virDomainObjPtr vm, } +/** + * virDomainObjGetOneDefState: + * + * @vm: Domain object + * @flags: for virDomainModificationImpact + * @live: set to true if live config was returned (may be omitted) + * + * 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. @live is set to true if the live vm config will be + * returned. This helper should be used only in APIs that guarantee + * that @flags contains exactly one of VIR_DOMAIN_AFFECT_LIVE or + * VIR_DOMAIN_AFFECT_CONFIG and not both. + * + * Returns the correct definition pointer or NULL on error. + */ +virDomainDefPtr +virDomainObjGetOneDefState(virDomainObjPtr vm, + unsigned int flags, + bool *live) +{ + 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 (live) { + if (flags & VIR_DOMAIN_AFFECT_LIVE) + *live = true; + else + *live = false; + } + + if (virDomainObjIsActive(vm) && flags & VIR_DOMAIN_AFFECT_CONFIG) + return vm->newDef; + else + return vm->def; +} + + /** * virDomainObjGetOneDef: * @@ -3135,21 +3181,7 @@ 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; + return virDomainObjGetOneDefState(vm, flags, NULL); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f43fcc8900..d4a84c3718 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2592,6 +2592,9 @@ int virDomainObjGetDefs(virDomainObjPtr vm, unsigned int flags, virDomainDefPtr *liveDef, virDomainDefPtr *persDef); +virDomainDefPtr virDomainObjGetOneDefState(virDomainObjPtr vm, + unsigned int flags, + bool *state); virDomainDefPtr virDomainObjGetOneDef(virDomainObjPtr vm, unsigned int flags); virDomainDefPtr virDomainDefCopy(virDomainDefPtr src, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 562a3d9777..03b0865ff8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -417,6 +417,7 @@ virDomainObjFormat; virDomainObjGetDefs; virDomainObjGetMetadata; virDomainObjGetOneDef; +virDomainObjGetOneDefState; virDomainObjGetPersistentDef; virDomainObjGetShortName; virDomainObjGetState;