From eff5466a6e7ca4c5b324e091c2be00e8fa71a338 Mon Sep 17 00:00:00 2001 Message-Id: From: Peter Krempa Date: Thu, 22 Jan 2015 15:53:40 +0100 Subject: [PATCH] qemu: Factor out body of qemuDomainSetMetadata 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 f87a7c67de946f941fddde44d5959baaac6c7de4) Signed-off-by: Jiri Denemark --- 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 b052924..7bfb602 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19031,3 +19031,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", + _(" 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", + _(" 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 08c677f..eaeea03 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2778,4 +2778,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 40007e1..61d8d26 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -331,6 +331,7 @@ virDomainObjListRemove; virDomainObjListRemoveLocked; virDomainObjNew; virDomainObjSetDefTransient; +virDomainObjSetMetadata; virDomainObjSetState; virDomainObjTaint; virDomainPausedReasonTypeFromString; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3beed9a..57583e8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15862,22 +15862,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); @@ -15887,69 +15886,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 " - " 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 " - " 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; -- 2.2.1