]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Introduce helper to help getting correct def for getter functions
authorPeter Krempa <pkrempa@redhat.com>
Mon, 15 Jun 2015 17:04:41 +0000 (19:04 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 18 Jun 2015 13:13:44 +0000 (15:13 +0200)
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
src/conf/domain_conf.h
src/libvirt_private.syms

index e771d346c5dd2dbcfc04b32fe9a27c57122795ff..9d19893f31476968899985d36a3a0bb0cb45e5a5 100644 (file)
@@ -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 or
+ * VIR_DOMAIN_AFFECT_CONFIG and not both.
+ *
+ * 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
index ba17a8d732d3a73489732bb50e55f04fcef71ba6..db49d467521de2cb56d9af064e49e2473767235c 100644 (file)
@@ -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,
index cd347ac6adcd264eab0b87bc67565f32d2292dfc..2d4ab2171de3fbf6f59fd5e06f8382c6b8b157c4 100644 (file)
@@ -385,6 +385,7 @@ virDomainObjEndAPI;
 virDomainObjFormat;
 virDomainObjGetDefs;
 virDomainObjGetMetadata;
+virDomainObjGetOneDef;
 virDomainObjGetPersistentDef;
 virDomainObjGetState;
 virDomainObjListAdd;