mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
conf: domain: Introduce and use virDomainObjGetMessages()
The test driver and qemu driver could share the same code in virDomainGetMessages(), so extract it to a function. Signed-off-by: Luke Yue <lukedyue@gmail.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
444c7c2725
commit
8a7cfb10b8
@ -31209,3 +31209,55 @@ virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
|
|||||||
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
|
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
|
||||||
hostdev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO;
|
hostdev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virDomainObjGetMessages:
|
||||||
|
* @vm: domain object
|
||||||
|
* @msgs: pointer to a variable to store messages
|
||||||
|
* @flags: zero or more virDomainMessageType flags
|
||||||
|
*
|
||||||
|
* Returns number of messages stored in @msgs, -1 otherwise.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virDomainObjGetMessages(virDomainObj *vm,
|
||||||
|
char ***msgs,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
size_t n = 0;
|
||||||
|
int nmsgs = 0;
|
||||||
|
int rv = -1;
|
||||||
|
|
||||||
|
*msgs = NULL;
|
||||||
|
|
||||||
|
if (!flags || (flags & VIR_DOMAIN_MESSAGE_TAINTING)) {
|
||||||
|
nmsgs += __builtin_popcount(vm->taint);
|
||||||
|
*msgs = g_renew(char *, *msgs, nmsgs+1);
|
||||||
|
|
||||||
|
for (i = 0; i < VIR_DOMAIN_TAINT_LAST; i++) {
|
||||||
|
if (vm->taint & (1 << i)) {
|
||||||
|
(*msgs)[n++] = g_strdup_printf(
|
||||||
|
_("tainted: %s"),
|
||||||
|
_(virDomainTaintMessageTypeToString(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flags || (flags & VIR_DOMAIN_MESSAGE_DEPRECATION)) {
|
||||||
|
nmsgs += vm->ndeprecations;
|
||||||
|
*msgs = g_renew(char *, *msgs, nmsgs+1);
|
||||||
|
|
||||||
|
for (i = 0; i < vm->ndeprecations; i++) {
|
||||||
|
(*msgs)[n++] = g_strdup_printf(
|
||||||
|
_("deprecated configuration: %s"),
|
||||||
|
vm->deprecations[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(*msgs)[nmsgs] = NULL;
|
||||||
|
|
||||||
|
rv = nmsgs;
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
@ -4165,3 +4165,8 @@ virHostdevIsMdevDevice(const virDomainHostdevDef *hostdev)
|
|||||||
bool
|
bool
|
||||||
virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
|
virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
|
||||||
ATTRIBUTE_NONNULL(1);
|
ATTRIBUTE_NONNULL(1);
|
||||||
|
|
||||||
|
int
|
||||||
|
virDomainObjGetMessages(virDomainObj *vm,
|
||||||
|
char ***msgs,
|
||||||
|
unsigned int flags);
|
||||||
|
@ -567,6 +567,7 @@ virDomainObjDeprecation;
|
|||||||
virDomainObjEndAPI;
|
virDomainObjEndAPI;
|
||||||
virDomainObjFormat;
|
virDomainObjFormat;
|
||||||
virDomainObjGetDefs;
|
virDomainObjGetDefs;
|
||||||
|
virDomainObjGetMessages;
|
||||||
virDomainObjGetMetadata;
|
virDomainObjGetMetadata;
|
||||||
virDomainObjGetOneDef;
|
virDomainObjGetOneDef;
|
||||||
virDomainObjGetOneDefState;
|
virDomainObjGetOneDefState;
|
||||||
|
@ -20362,8 +20362,6 @@ qemuDomainGetMessages(virDomainPtr dom,
|
|||||||
{
|
{
|
||||||
virDomainObj *vm = NULL;
|
virDomainObj *vm = NULL;
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
size_t i, n;
|
|
||||||
int nmsgs;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_MESSAGE_DEPRECATION |
|
virCheckFlags(VIR_DOMAIN_MESSAGE_DEPRECATION |
|
||||||
VIR_DOMAIN_MESSAGE_TAINTING, -1);
|
VIR_DOMAIN_MESSAGE_TAINTING, -1);
|
||||||
@ -20374,37 +20372,7 @@ qemuDomainGetMessages(virDomainPtr dom,
|
|||||||
if (virDomainGetMessagesEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainGetMessagesEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
*msgs = NULL;
|
rv = virDomainObjGetMessages(vm, msgs, flags);
|
||||||
nmsgs = 0;
|
|
||||||
n = 0;
|
|
||||||
|
|
||||||
if (!flags || (flags & VIR_DOMAIN_MESSAGE_TAINTING)) {
|
|
||||||
nmsgs += __builtin_popcount(vm->taint);
|
|
||||||
*msgs = g_renew(char *, *msgs, nmsgs+1);
|
|
||||||
|
|
||||||
for (i = 0; i < VIR_DOMAIN_TAINT_LAST; i++) {
|
|
||||||
if (vm->taint & (1 << i)) {
|
|
||||||
(*msgs)[n++] = g_strdup_printf(
|
|
||||||
_("tainted: %s"),
|
|
||||||
_(virDomainTaintMessageTypeToString(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!flags || (flags & VIR_DOMAIN_MESSAGE_DEPRECATION)) {
|
|
||||||
nmsgs += vm->ndeprecations;
|
|
||||||
*msgs = g_renew(char *, *msgs, nmsgs+1);
|
|
||||||
|
|
||||||
for (i = 0; i < vm->ndeprecations; i++) {
|
|
||||||
(*msgs)[n++] = g_strdup_printf(
|
|
||||||
_("deprecated configuration: %s"),
|
|
||||||
vm->deprecations[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(*msgs)[nmsgs] = NULL;
|
|
||||||
|
|
||||||
rv = nmsgs;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
|
Loading…
Reference in New Issue
Block a user