render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From a1871d142620750d21fed3c06053fad60ca3f7c5 Mon Sep 17 00:00:00 2001
Message-Id: <a1871d142620750d21fed3c06053fad60ca3f7c5@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 22 Jan 2015 15:53:41 +0100
Subject: [PATCH] conf: Factor out setting of metadata to simplify code

https://bugzilla.redhat.com/show_bug.cgi?id=1184929

The code to set the metadata in a domain definition is common to live
and inactive domains. Factor it out into a common func.

(cherry picked from commit e9cb66f14e19935db16938ebdf1e407103b4de1e)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c | 115 +++++++++++++++++++++++--------------------------
 1 file changed, 54 insertions(+), 61 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7bfb602..6817e0e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19032,87 +19032,80 @@ cleanup:
     return ret;
 }
 
-int
-virDomainObjSetMetadata(virDomainObjPtr vm,
+
+static int
+virDomainDefSetMetadata(virDomainDefPtr def,
                         int type,
                         const char *metadata,
                         const char *key ATTRIBUTE_UNUSED,
-                        const char *uri ATTRIBUTE_UNUSED,
+                        const char *uri ATTRIBUTE_UNUSED)
+{
+    int ret = -1;
+
+    switch ((virDomainMetadataType) type) {
+    case VIR_DOMAIN_METADATA_DESCRIPTION:
+        VIR_FREE(def->description);
+        if (VIR_STRDUP(def->description, metadata) < 0)
+            goto cleanup;
+        break;
+
+    case VIR_DOMAIN_METADATA_TITLE:
+        VIR_FREE(def->title);
+        if (VIR_STRDUP(def->title, metadata) < 0)
+            goto cleanup;
+        break;
+
+    case VIR_DOMAIN_METADATA_ELEMENT:
+        virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+                       _("<metadata> element is not supported"));
+        goto cleanup;
+        break;
+
+    default:
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("unknown metadata type"));
+        goto cleanup;
+        break;
+    }
+
+    ret = 0;
+
+cleanup:
+    return ret;
+}
+
+
+int
+virDomainObjSetMetadata(virDomainObjPtr vm,
+                        int type,
+                        const char *metadata,
+                        const char *key,
+                        const char *uri,
                         virCapsPtr caps,
                         virDomainXMLOptionPtr xmlopt,
                         const char *configDir,
                         unsigned int flags)
 {
     virDomainDefPtr persistentDef;
-    int ret = -1;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
 
     if (virDomainLiveConfigHelperMethod(caps, xmlopt, vm, &flags,
                                         &persistentDef) < 0)
-        goto cleanup;
+        return -1;
 
-    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
-        switch ((virDomainMetadataType) type) {
-        case VIR_DOMAIN_METADATA_DESCRIPTION:
-            VIR_FREE(vm->def->description);
-            if (VIR_STRDUP(vm->def->description, metadata) < 0)
-                goto cleanup;
-            break;
-
-        case VIR_DOMAIN_METADATA_TITLE:
-            VIR_FREE(vm->def->title);
-            if (VIR_STRDUP(vm->def->title, metadata) < 0)
-                goto cleanup;
-            break;
-
-        case VIR_DOMAIN_METADATA_ELEMENT:
-            virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-                           _("<metadata> element is not supported"));
-            goto cleanup;
-            break;
-
-        default:
-            virReportError(VIR_ERR_INVALID_ARG, "%s",
-                           _("unknown metadata type"));
-            goto cleanup;
-            break;
-        }
-    }
+    if (flags & VIR_DOMAIN_AFFECT_LIVE)
+        if (virDomainDefSetMetadata(vm->def, type, metadata, key, uri) < 0)
+            return -1;
 
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-        switch ((virDomainMetadataType) type) {
-        case VIR_DOMAIN_METADATA_DESCRIPTION:
-            VIR_FREE(persistentDef->description);
-            if (VIR_STRDUP(persistentDef->description, metadata) < 0)
-                goto cleanup;
-            break;
-
-        case VIR_DOMAIN_METADATA_TITLE:
-            VIR_FREE(persistentDef->title);
-            if (VIR_STRDUP(persistentDef->title, metadata) < 0)
-                goto cleanup;
-            break;
-
-        case VIR_DOMAIN_METADATA_ELEMENT:
-            virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-                           _("<metadata> element is not supported"));
-            goto cleanup;
-
-         default:
-            virReportError(VIR_ERR_INVALID_ARG, "%s",
-                           _("unknown metadata type"));
-            goto cleanup;
-            break;
-        }
+        if (virDomainDefSetMetadata(persistentDef, type, metadata, key, uri) < 0)
+            return -1;
 
         if (virDomainSaveConfig(configDir, persistentDef) < 0)
-            goto cleanup;
+            return -1;
     }
 
-    ret = 0;
-
-cleanup:
-    return ret;
+    return 0;
 }
-- 
2.2.1