提交 99c51af2 编写于 作者: P Peter Krempa

qemu: Factor out body of qemuDomainGetMetadata 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.
上级 cb356928
......@@ -18531,3 +18531,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;
}
......@@ -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 */
......@@ -309,6 +309,7 @@ virDomainNostateReasonTypeFromString;
virDomainNostateReasonTypeToString;
virDomainObjAssignDef;
virDomainObjCopyPersistentDef;
virDomainObjGetMetadata;
virDomainObjGetPersistentDef;
virDomainObjGetState;
virDomainObjListAdd;
......
......@@ -15118,21 +15118,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;
......@@ -15140,43 +15135,9 @@ 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);
virObjectUnref(caps);
return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册