From 135eeb60e3d7b1cda9f48bdd38542bb3c06e2638 Mon Sep 17 00:00:00 2001
Message-Id: <135eeb60e3d7b1cda9f48bdd38542bb3c06e2638@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 22 Jan 2015 15:53:39 +0100
Subject: [PATCH] qemu: Factor out body of qemuDomainGetMetadata for universal
use
https://bugzilla.redhat.com/show_bug.cgi?id=1184929
The function implemented 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.
(cherry picked from commit 99c51af2ee42de980c258ecb52cf20f96c69ff83)
Conflicts:
src/conf/domain_conf.h - context
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
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 922c5e6..b052924 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18976,3 +18976,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 00e66ae..08c677f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2771,4 +2771,11 @@ int virDomainDefFindDevice(virDomainDefPtr def,
bool virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def)
ATTRIBUTE_NONNULL(1);
+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 5cf7039..40007e1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -313,6 +313,7 @@ virDomainNostateReasonTypeFromString;
virDomainNostateReasonTypeToString;
virDomainObjAssignDef;
virDomainObjCopyPersistentDef;
+virDomainObjGetMetadata;
virDomainObjGetPersistentDef;
virDomainObjGetState;
virDomainObjListAdd;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b0d4f33..3beed9a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15958,21 +15958,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;
@@ -15980,44 +15975,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;
}
--
2.2.1