[PATCH 04/14] qemu: Factor out body of qemuDomainSetMetadata for universal use

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The function impelemnted common behavior that can be reused for other
hypervisor drivers that use the virDomainObj data structures. Factor out
the core into a separate helper func.
---
 src/conf/domain_conf.c   | 85 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   | 10 ++++++
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_driver.c   | 73 ++++-------------------------------------
 4 files changed, 103 insertions(+), 66 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d9ed985..e157d49 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18582,3 +18582,88 @@ virDomainObjGetMetadata(virDomainObjPtr vm,
 cleanup:
     return ret;
 }
+
+int
+virDomainObjSetMetadata(virDomainObjPtr vm,
+                        int type,
+                        const char *metadata,
+                        const char *key ATTRIBUTE_UNUSED,
+                        const char *uri ATTRIBUTE_UNUSED,
+                        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;
+
+    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_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 (virDomainSaveConfig(configDir, persistentDef) < 0)
+            goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    return ret;
+}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 173d302..e4dfee9 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2745,4 +2745,14 @@ char *virDomainObjGetMetadata(virDomainObjPtr vm,
                               virDomainXMLOptionPtr xmlopt,
                               unsigned int flags);

+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);
+
 #endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2516b9c..0631941 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -327,6 +327,7 @@ virDomainObjListRemove;
 virDomainObjListRemoveLocked;
 virDomainObjNew;
 virDomainObjSetDefTransient;
+virDomainObjSetMetadata;
 virDomainObjSetState;
 virDomainObjTaint;
 virDomainPausedReasonTypeFromString;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9d5e825..2468310 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15048,22 +15048,21 @@ static int
 qemuDomainSetMetadata(virDomainPtr dom,
                       int type,
                       const char *metadata,
-                      const char *key ATTRIBUTE_UNUSED,
-                      const char *uri ATTRIBUTE_UNUSED,
+                      const char *key,
+                      const char *uri,
                       unsigned int flags)
 {
     virQEMUDriverPtr driver = dom->conn->privateData;
     virDomainObjPtr vm;
-    virDomainDefPtr persistentDef;
-    int ret = -1;
     virQEMUDriverConfigPtr cfg = NULL;
     virCapsPtr caps = NULL;
+    int ret = -1;

     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);

     if (!(vm = qemuDomObjFromDomain(dom)))
-        goto cleanup;
+        return -1;

     cfg = virQEMUDriverGetConfig(driver);

@@ -15073,69 +15072,11 @@ qemuDomainSetMetadata(virDomainPtr dom,
     if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
         goto cleanup;

-    if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags,
-                                        &persistentDef) < 0)
-        goto cleanup;
-
-    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",
-                           _("QEmu driver does not support modifying "
-                             "<metadata> element"));
-            goto cleanup;
-            break;
-        default:
-            virReportError(VIR_ERR_INVALID_ARG, "%s",
-                           _("unknown metadata type"));
-            goto cleanup;
-            break;
-        }
-    }
-
-    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",
-                           _("QEMU driver does not support "
-                             "<metadata> element"));
-            goto cleanup;
-         default:
-            virReportError(VIR_ERR_INVALID_ARG, "%s",
-                           _("unknown metadata type"));
-            goto cleanup;
-            break;
-        }
-
-        if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)
-            goto cleanup;
-    }
-
-    ret = 0;
+    ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, caps,
+                                  driver->xmlopt, cfg->configDir, flags);

 cleanup:
-    if (vm)
-        virObjectUnlock(vm);
+    virObjectUnlock(vm);
     virObjectUnref(caps);
     virObjectUnref(cfg);
     return ret;
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]