The test driver and qemu driver share the same code in
virDomainGetMessages(), so extract it to a function.
Signed-off-by: Luke Yue <lukedyue(a)gmail.com>
---
src/conf/domain_conf.c | 53 ++++++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 5 ++++
src/libvirt_private.syms | 1 +
src/qemu/qemu_driver.c | 34 +-------------------------
src/test/test_driver.c | 34 +-------------------------
5 files changed, 61 insertions(+), 66 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d78f846a52..f5b7cc8dc4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31153,3 +31153,56 @@ virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
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, n;
+ int nmsgs;
+ int rv = -1;
+
+ *msgs = NULL;
+ 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;
+
+ return rv;
+}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f706c498ff..71b9c69e2c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -4138,3 +4138,8 @@ virHostdevIsMdevDevice(const virDomainHostdevDef *hostdev)
bool
virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
ATTRIBUTE_NONNULL(1);
+
+int
+virDomainObjGetMessages(virDomainObj *vm,
+ char ***msgs,
+ unsigned int flags);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 68e4b6aab8..17d2cfbdbe 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -562,6 +562,7 @@ virDomainObjDeprecation;
virDomainObjEndAPI;
virDomainObjFormat;
virDomainObjGetDefs;
+virDomainObjGetMessages;
virDomainObjGetMetadata;
virDomainObjGetOneDef;
virDomainObjGetOneDefState;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 235f575901..592e1236e7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20319,8 +20319,6 @@ qemuDomainGetMessages(virDomainPtr dom,
{
virDomainObj *vm = NULL;
int rv = -1;
- size_t i, n;
- int nmsgs;
virCheckFlags(VIR_DOMAIN_MESSAGE_DEPRECATION |
VIR_DOMAIN_MESSAGE_TAINTING, -1);
@@ -20331,37 +20329,7 @@ qemuDomainGetMessages(virDomainPtr dom,
if (virDomainGetMessagesEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
- *msgs = NULL;
- 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;
+ rv = virDomainObjGetMessages(vm, msgs, flags);
cleanup:
virDomainObjEndAPI(&vm);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 06ba7c4cd2..b389e3412b 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -9353,8 +9353,6 @@ testDomainGetMessages(virDomainPtr dom,
{
virDomainObj *vm = NULL;
int rv = -1;
- size_t i, n;
- int nmsgs;
virCheckFlags(VIR_DOMAIN_MESSAGE_DEPRECATION |
VIR_DOMAIN_MESSAGE_TAINTING, -1);
@@ -9362,39 +9360,9 @@ testDomainGetMessages(virDomainPtr dom,
if (!(vm = testDomObjFromDomain(dom)))
return -1;
- *msgs = NULL;
- nmsgs = 0;
- n = 0;
-
testDomainObjCheckTaint(vm);
- 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;
+ rv = virDomainObjGetMessages(vm, msgs, flags);
virDomainObjEndAPI(&vm);
return rv;
--
2.32.0