[PATCH 03/14] qemu: Factor out body of qemuDomainGetMetadata 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   | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |  7 ++++++
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_driver.c   | 49 +++++-------------------------------------
 4 files changed, 68 insertions(+), 44 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index aed2a9d..d9ed985 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18527,3 +18527,58 @@ virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def)
     }
     return false;
 }
+
+
+char *
+virDomainObjGetMetadata(virDomainObjPtr vm,
+                        int type,
+                        const char *uri ATTRIBUTE_UNUSED,
+                        virCapsPtr caps,
+                        virDomainXMLOptionPtr xmlopt,
+                        unsigned int flags)
+{
+    virDomainDefPtr def;
+    char *field = NULL;
+    char *ret = NULL;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, NULL);
+
+    if (virDomainLiveConfigHelperMethod(caps, xmlopt, vm, &flags, &def) < 0)
+        goto cleanup;
+
+    /* use correct domain definition according to flags */
+    if (flags & VIR_DOMAIN_AFFECT_LIVE)
+        def = vm->def;
+
+    switch ((virDomainMetadataType) type) {
+    case VIR_DOMAIN_METADATA_DESCRIPTION:
+        field = def->description;
+        break;
+
+    case VIR_DOMAIN_METADATA_TITLE:
+        field = def->title;
+        break;
+
+    case VIR_DOMAIN_METADATA_ELEMENT:
+        virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+                       _("<metadata> element is not yet supported"));
+        goto cleanup;
+        break;
+
+    default:
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("unknown metadata type"));
+        goto cleanup;
+        break;
+    }
+
+    if (!field)
+        virReportError(VIR_ERR_NO_DOMAIN_METADATA, "%s",
+                       _("Requested metadata element is not present"));
+
+    ignore_value(VIR_STRDUP(ret, field));
+
+cleanup:
+    return ret;
+}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 539bc1c..173d302 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2738,4 +2738,11 @@ bool virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def)

 void virDomainChrSourceDefClear(virDomainChrSourceDefPtr def);

+char *virDomainObjGetMetadata(virDomainObjPtr vm,
+                              int type,
+                              const char *uri,
+                              virCapsPtr caps,
+                              virDomainXMLOptionPtr xmlopt,
+                              unsigned int flags);
+
 #endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 35f0f1b..2516b9c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -309,6 +309,7 @@ virDomainNostateReasonTypeFromString;
 virDomainNostateReasonTypeToString;
 virDomainObjAssignDef;
 virDomainObjCopyPersistentDef;
+virDomainObjGetMetadata;
 virDomainObjGetPersistentDef;
 virDomainObjGetState;
 virDomainObjListAdd;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9b5d126..9d5e825 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15144,21 +15144,16 @@ cleanup:
 static char *
 qemuDomainGetMetadata(virDomainPtr dom,
                       int type,
-                      const char *uri ATTRIBUTE_UNUSED,
+                      const char *uri,
                       unsigned int flags)
 {
     virQEMUDriverPtr driver = dom->conn->privateData;
+    virCapsPtr caps = NULL;
     virDomainObjPtr vm;
-    virDomainDefPtr def;
     char *ret = NULL;
-    char *field = NULL;
-    virCapsPtr caps = NULL;
-
-    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
-                  VIR_DOMAIN_AFFECT_CONFIG, NULL);

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

     if (virDomainGetMetadataEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
@@ -15166,44 +15161,10 @@ qemuDomainGetMetadata(virDomainPtr dom,
     if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
         goto cleanup;

-    if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags, &def) < 0)
-        goto cleanup;
-
-    /* use correct domain definition according to flags */
-    if (flags & VIR_DOMAIN_AFFECT_LIVE)
-        def = vm->def;
-
-    switch ((virDomainMetadataType) type) {
-    case VIR_DOMAIN_METADATA_DESCRIPTION:
-        field = def->description;
-        break;
-    case VIR_DOMAIN_METADATA_TITLE:
-        field = def->title;
-        break;
-    case VIR_DOMAIN_METADATA_ELEMENT:
-        virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-                       _("QEMU driver does not support "
-                         "<metadata> element"));
-        goto cleanup;
-        break;
-    default:
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("unknown metadata type"));
-        goto cleanup;
-        break;
-    }
-
-    if (!field) {
-        virReportError(VIR_ERR_NO_DOMAIN_METADATA, "%s",
-                       _("Requested metadata element is not present"));
-        goto cleanup;
-    }
-
-    ignore_value(VIR_STRDUP(ret, field));
+    ret = virDomainObjGetMetadata(vm, type, uri, caps, driver->xmlopt, flags);

 cleanup:
-    if (vm)
-        virObjectUnlock(vm);
+    virObjectUnlock(vm);
     virObjectUnref(caps);
     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]