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:
|
cleanup:
|
||||||
return ret;
|
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,
|
virDomainXMLOptionPtr xmlopt,
|
||||||
unsigned int flags);
|
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 */
|
#endif /* __DOMAIN_CONF_H */
|
||||||
|
@ -327,6 +327,7 @@ virDomainObjListRemove;
|
|||||||
virDomainObjListRemoveLocked;
|
virDomainObjListRemoveLocked;
|
||||||
virDomainObjNew;
|
virDomainObjNew;
|
||||||
virDomainObjSetDefTransient;
|
virDomainObjSetDefTransient;
|
||||||
|
virDomainObjSetMetadata;
|
||||||
virDomainObjSetState;
|
virDomainObjSetState;
|
||||||
virDomainObjTaint;
|
virDomainObjTaint;
|
||||||
virDomainPausedReasonTypeFromString;
|
virDomainPausedReasonTypeFromString;
|
||||||
|
@ -15022,22 +15022,21 @@ static int
|
|||||||
qemuDomainSetMetadata(virDomainPtr dom,
|
qemuDomainSetMetadata(virDomainPtr dom,
|
||||||
int type,
|
int type,
|
||||||
const char *metadata,
|
const char *metadata,
|
||||||
const char *key ATTRIBUTE_UNUSED,
|
const char *key,
|
||||||
const char *uri ATTRIBUTE_UNUSED,
|
const char *uri,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virQEMUDriverPtr driver = dom->conn->privateData;
|
virQEMUDriverPtr driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virDomainDefPtr persistentDef;
|
|
||||||
int ret = -1;
|
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
virQEMUDriverConfigPtr cfg = NULL;
|
||||||
virCapsPtr caps = NULL;
|
virCapsPtr caps = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||||
|
|
||||||
if (!(vm = qemuDomObjFromDomain(dom)))
|
if (!(vm = qemuDomObjFromDomain(dom)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
cfg = virQEMUDriverGetConfig(driver);
|
cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
|
||||||
@ -15047,69 +15046,11 @@ qemuDomainSetMetadata(virDomainPtr dom,
|
|||||||
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
|
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags,
|
ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, caps,
|
||||||
&persistentDef) < 0)
|
driver->xmlopt, cfg->configDir, flags);
|
||||||
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;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (vm)
|
virObjectUnlock(vm);
|
||||||
virObjectUnlock(vm);
|
|
||||||
virObjectUnref(caps);
|
virObjectUnref(caps);
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user