mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
qemu: Factor out body of qemuDomainSetMetadata for universal use
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.
This commit is contained in:
parent
99c51af2ee
commit
f87a7c67de
@ -18586,3 +18586,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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -327,6 +327,7 @@ virDomainObjListRemove;
|
||||
virDomainObjListRemoveLocked;
|
||||
virDomainObjNew;
|
||||
virDomainObjSetDefTransient;
|
||||
virDomainObjSetMetadata;
|
||||
virDomainObjSetState;
|
||||
virDomainObjTaint;
|
||||
virDomainPausedReasonTypeFromString;
|
||||
|
@ -15022,22 +15022,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);
|
||||
|
||||
@ -15047,68 +15046,10 @@ 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);
|
||||
virObjectUnref(caps);
|
||||
virObjectUnref(cfg);
|
||||
|
Loading…
Reference in New Issue
Block a user