mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
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.
This commit is contained in:
parent
cb356928a6
commit
99c51af2ee
@ -18531,3 +18531,58 @@ virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def)
|
|||||||
}
|
}
|
||||||
return false;
|
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);
|
void virDomainChrSourceDefClear(virDomainChrSourceDefPtr def);
|
||||||
|
|
||||||
|
char *virDomainObjGetMetadata(virDomainObjPtr vm,
|
||||||
|
int type,
|
||||||
|
const char *uri,
|
||||||
|
virCapsPtr caps,
|
||||||
|
virDomainXMLOptionPtr xmlopt,
|
||||||
|
unsigned int flags);
|
||||||
|
|
||||||
#endif /* __DOMAIN_CONF_H */
|
#endif /* __DOMAIN_CONF_H */
|
||||||
|
@ -309,6 +309,7 @@ virDomainNostateReasonTypeFromString;
|
|||||||
virDomainNostateReasonTypeToString;
|
virDomainNostateReasonTypeToString;
|
||||||
virDomainObjAssignDef;
|
virDomainObjAssignDef;
|
||||||
virDomainObjCopyPersistentDef;
|
virDomainObjCopyPersistentDef;
|
||||||
|
virDomainObjGetMetadata;
|
||||||
virDomainObjGetPersistentDef;
|
virDomainObjGetPersistentDef;
|
||||||
virDomainObjGetState;
|
virDomainObjGetState;
|
||||||
virDomainObjListAdd;
|
virDomainObjListAdd;
|
||||||
|
@ -15118,21 +15118,16 @@ cleanup:
|
|||||||
static char *
|
static char *
|
||||||
qemuDomainGetMetadata(virDomainPtr dom,
|
qemuDomainGetMetadata(virDomainPtr dom,
|
||||||
int type,
|
int type,
|
||||||
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;
|
|
||||||
virDomainDefPtr def;
|
|
||||||
char *ret = NULL;
|
|
||||||
char *field = NULL;
|
|
||||||
virCapsPtr caps = NULL;
|
virCapsPtr caps = NULL;
|
||||||
|
virDomainObjPtr vm;
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
char *ret = NULL;
|
||||||
VIR_DOMAIN_AFFECT_CONFIG, NULL);
|
|
||||||
|
|
||||||
if (!(vm = qemuDomObjFromDomain(dom)))
|
if (!(vm = qemuDomObjFromDomain(dom)))
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
if (virDomainGetMetadataEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainGetMetadataEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -15140,44 +15135,10 @@ qemuDomainGetMetadata(virDomainPtr dom,
|
|||||||
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
|
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags, &def) < 0)
|
ret = virDomainObjGetMetadata(vm, type, uri, caps, driver->xmlopt, flags);
|
||||||
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));
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (vm)
|
virObjectUnlock(vm);
|
||||||
virObjectUnlock(vm);
|
|
||||||
virObjectUnref(caps);
|
virObjectUnref(caps);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user