[PATCH v3 0/3] Implement virDomainGetMessages for test driver

v3: - Squash tests commit - Extract the same code in test driver and qemu driver to a function Luke Yue (3): test_driver: Implement virDomainGetMessages test_driver: Introduce testDomainObjCheckTaint conf: domain: Introduce and use virDomainObjGetMessages() 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 | 78 ++++++++++++++++++++++++++++++++++++++++ tests/virshtest.c | 2 ++ 6 files changed, 140 insertions(+), 33 deletions(-) -- 2.32.0

Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ef0ddab54d..35742fcde3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9291,6 +9291,58 @@ testDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, return ret; } +static int +testDomainGetMessages(virDomainPtr dom, + char ***msgs, + unsigned int flags) +{ + virDomainObj *vm = NULL; + int rv = -1; + size_t i, n; + int nmsgs; + + virCheckFlags(VIR_DOMAIN_MESSAGE_DEPRECATION | + VIR_DOMAIN_MESSAGE_TAINTING, -1); + + if (!(vm = testDomObjFromDomain(dom))) + return -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; + + virDomainObjEndAPI(&vm); + return rv; +} + /* * Test driver */ @@ -9448,6 +9500,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainCheckpointLookupByName = testDomainCheckpointLookupByName, /* 5.6.0 */ .domainCheckpointGetParent = testDomainCheckpointGetParent, /* 5.6.0 */ .domainCheckpointDelete = testDomainCheckpointDelete, /* 5.6.0 */ + .domainGetMessages = testDomainGetMessages, /* 7.6.0 */ }; static virNetworkDriver testNetworkDriver = { -- 2.32.0

On Wed, Jun 30, 2021 at 10:53:44AM +0800, Luke Yue wrote:
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
If you first abstract the code from qemu driver then there's less code move to add this functionality. Also one more thing to check is whether qemu driver is the only one that has this code and that it is not duplicated anywhere else - we could dedup even more code ;)

On Fri, 2021-07-09 at 15:10 +0200, Martin Kletzander wrote:
On Wed, Jun 30, 2021 at 10:53:44AM +0800, Luke Yue wrote:
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
If you first abstract the code from qemu driver then there's less code move to add this functionality. Also one more thing to check is whether qemu driver is the only one that has this code and that it is not duplicated anywhere else - we could dedup even more code ;)
Thanks! But I'm sorry that I find out that qemu driver seems to be the only one that has this code (what I extracted to virDomainObjGetMessages), do I miss something? Or it's just a general suggestion for future development work?

On Mon, Jul 12, 2021 at 11:16:50AM +0800, Luke Yue wrote:
On Fri, 2021-07-09 at 15:10 +0200, Martin Kletzander wrote:
On Wed, Jun 30, 2021 at 10:53:44AM +0800, Luke Yue wrote:
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
If you first abstract the code from qemu driver then there's less code move to add this functionality. Also one more thing to check is whether qemu driver is the only one that has this code and that it is not duplicated anywhere else - we could dedup even more code ;)
Thanks! But I'm sorry that I find out that qemu driver seems to be the only one that has this code (what I extracted to virDomainObjGetMessages), do I miss something? Or it's just a general suggestion for future development work?
Just a general suggestion. I did not know whether qemu driver is the only one that has this code or not, but since you checked you already did what I suggested ;) I'd still switch it around and first abstract the qemu code and then implement the test driver one.

In order to test the virDomainGetMessages for test driver, we need to check some taints or deprecations, so introduce testDomainObjCheckTaint for checking taints. As we introduced testDomainObjCheckTaint for test driver, the `dominfo` command in virshtest will now print tainting messages, so add them for test. Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 57 ++++++++++++++++++++++++++++++++++++++++++ tests/virshtest.c | 2 ++ 2 files changed, 59 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 35742fcde3..06ba7c4cd2 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9291,6 +9291,61 @@ testDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, return ret; } +static void +testDomainObjCheckDiskTaint(virDomainObj *obj, + virDomainDiskDef *disk) +{ + if (disk->rawio == VIR_TRISTATE_BOOL_YES) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES); + + if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM && + virStorageSourceGetActualType(disk->src) == VIR_STORAGE_TYPE_BLOCK && + disk->src->path && virFileIsCDROM(disk->src->path) == 1) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH); +} + +static void +testDomainObjCheckHostdevTaint(virDomainObj *obj, + virDomainHostdevDef *hostdev) +{ + if (!virHostdevIsSCSIDevice(hostdev)) + return; + + if (hostdev->source.subsys.u.scsi.rawio == VIR_TRISTATE_BOOL_YES) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES); +} + +static void +testDomainObjCheckNetTaint(virDomainObj *obj, + virDomainNetDef *net) +{ + /* script is only useful for NET_TYPE_ETHERNET (qemu) and + * NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for + * any interface type. In any case, it's adding user sauce into + * the soup, so it should taint the domain. + */ + if (net->script != NULL) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_SHELL_SCRIPTS); +} + +static void +testDomainObjCheckTaint(virDomainObj *obj) +{ + size_t i; + + for (i = 0; i < obj->def->ndisks; i++) + testDomainObjCheckDiskTaint(obj, obj->def->disks[i]); + + for (i = 0; i < obj->def->nhostdevs; i++) + testDomainObjCheckHostdevTaint(obj, obj->def->hostdevs[i]); + + for (i = 0; i < obj->def->nnets; i++) + testDomainObjCheckNetTaint(obj, obj->def->nets[i]); + + if (obj->def->os.dtb) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CUSTOM_DTB); +} + static int testDomainGetMessages(virDomainPtr dom, char ***msgs, @@ -9311,6 +9366,8 @@ testDomainGetMessages(virDomainPtr dom, 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); diff --git a/tests/virshtest.c b/tests/virshtest.c index c1974c46cb..937448cefc 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -22,6 +22,7 @@ main(void) # define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493" # define SECURITY_LABEL "libvirt-test (enforcing)" +# define MESSAGES "tainted: network configuration using opaque shell scripts" static const char *dominfo_fc4 = "\ Id: 2\n\ @@ -38,6 +39,7 @@ Managed save: no\n\ Security model: testSecurity\n\ Security DOI: \n\ Security label: " SECURITY_LABEL "\n\ +Messages: " MESSAGES "\n\ \n"; static const char *domuuid_fc4 = DOM_UUID "\n\n"; static const char *domid_fc4 = "2\n\n"; -- 2.32.0

On Wed, Jun 30, 2021 at 10:53:45AM +0800, Luke Yue wrote:
In order to test the virDomainGetMessages for test driver, we need to check some taints or deprecations, so introduce testDomainObjCheckTaint for checking taints.
As we introduced testDomainObjCheckTaint for test driver, the `dominfo` command in virshtest will now print tainting messages, so add them for test.
I do not know whether I'd duplicate all of the qemu driver code to exercise some test driver APIs, but it's better than nothing. To be honest I don't know about any other better option =)
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 57 ++++++++++++++++++++++++++++++++++++++++++ tests/virshtest.c | 2 ++ 2 files changed, 59 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 35742fcde3..06ba7c4cd2 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9291,6 +9291,61 @@ testDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, return ret; }
+static void +testDomainObjCheckDiskTaint(virDomainObj *obj, + virDomainDiskDef *disk) +{ + if (disk->rawio == VIR_TRISTATE_BOOL_YES) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES); + + if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM && + virStorageSourceGetActualType(disk->src) == VIR_STORAGE_TYPE_BLOCK && + disk->src->path && virFileIsCDROM(disk->src->path) == 1) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH); +} + +static void +testDomainObjCheckHostdevTaint(virDomainObj *obj, + virDomainHostdevDef *hostdev) +{ + if (!virHostdevIsSCSIDevice(hostdev)) + return; + + if (hostdev->source.subsys.u.scsi.rawio == VIR_TRISTATE_BOOL_YES) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES); +} + +static void +testDomainObjCheckNetTaint(virDomainObj *obj, + virDomainNetDef *net) +{ + /* script is only useful for NET_TYPE_ETHERNET (qemu) and + * NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for + * any interface type. In any case, it's adding user sauce into + * the soup, so it should taint the domain. + */ + if (net->script != NULL) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_SHELL_SCRIPTS); +} + +static void +testDomainObjCheckTaint(virDomainObj *obj) +{ + size_t i; + + for (i = 0; i < obj->def->ndisks; i++) + testDomainObjCheckDiskTaint(obj, obj->def->disks[i]); + + for (i = 0; i < obj->def->nhostdevs; i++) + testDomainObjCheckHostdevTaint(obj, obj->def->hostdevs[i]); + + for (i = 0; i < obj->def->nnets; i++) + testDomainObjCheckNetTaint(obj, obj->def->nets[i]); + + if (obj->def->os.dtb) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CUSTOM_DTB); +} + static int testDomainGetMessages(virDomainPtr dom, char ***msgs, @@ -9311,6 +9366,8 @@ testDomainGetMessages(virDomainPtr dom, nmsgs = 0; n = 0;
+ testDomainObjCheckTaint(vm); +
I know it works here, but I would rather do it in testParseDomains() and when creating a domain. To make it done in a single place you could utilise xmlopt callbacks which are called at different stages of parsing an XML, be it domain or any other one. That way this function does not do anything that other drivers don't.
if (!flags || (flags & VIR_DOMAIN_MESSAGE_TAINTING)) { nmsgs += __builtin_popcount(vm->taint); *msgs = g_renew(char *, *msgs, nmsgs+1); diff --git a/tests/virshtest.c b/tests/virshtest.c index c1974c46cb..937448cefc 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -22,6 +22,7 @@ main(void)
# define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493" # define SECURITY_LABEL "libvirt-test (enforcing)" +# define MESSAGES "tainted: network configuration using opaque shell scripts"
static const char *dominfo_fc4 = "\ Id: 2\n\ @@ -38,6 +39,7 @@ Managed save: no\n\ Security model: testSecurity\n\ Security DOI: \n\ Security label: " SECURITY_LABEL "\n\ +Messages: " MESSAGES "\n\
Pity there's not much more than this, but again - better than nothing.
\n"; static const char *domuuid_fc4 = DOM_UUID "\n\n"; static const char *domid_fc4 = "2\n\n"; -- 2.32.0

On Fri, 2021-07-09 at 15:07 +0200, Martin Kletzander wrote:
On Wed, Jun 30, 2021 at 10:53:45AM +0800, Luke Yue wrote:
In order to test the virDomainGetMessages for test driver, we need to check some taints or deprecations, so introduce testDomainObjCheckTaint for checking taints.
As we introduced testDomainObjCheckTaint for test driver, the `dominfo` command in virshtest will now print tainting messages, so add them for test.
I do not know whether I'd duplicate all of the qemu driver code to exercise some test driver APIs, but it's better than nothing. To be honest I don't know about any other better option =)
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 57 ++++++++++++++++++++++++++++++++++++++++++ tests/virshtest.c | 2 ++ 2 files changed, 59 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 35742fcde3..06ba7c4cd2 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9291,6 +9291,61 @@ testDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, return ret; }
hostdevs[i]);
+static void +testDomainObjCheckDiskTaint(virDomainObj *obj, + virDomainDiskDef *disk) +{ + if (disk->rawio == VIR_TRISTATE_BOOL_YES) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES); + + if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM && + virStorageSourceGetActualType(disk->src) == VIR_STORAGE_TYPE_BLOCK && + disk->src->path && virFileIsCDROM(disk->src->path) == 1) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH); +} + +static void +testDomainObjCheckHostdevTaint(virDomainObj *obj, + virDomainHostdevDef *hostdev) +{ + if (!virHostdevIsSCSIDevice(hostdev)) + return; + + if (hostdev->source.subsys.u.scsi.rawio == VIR_TRISTATE_BOOL_YES) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES); +} + +static void +testDomainObjCheckNetTaint(virDomainObj *obj, + virDomainNetDef *net) +{ + /* script is only useful for NET_TYPE_ETHERNET (qemu) and + * NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for + * any interface type. In any case, it's adding user sauce into + * the soup, so it should taint the domain. + */ + if (net->script != NULL) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_SHELL_SCRIPTS); +} + +static void +testDomainObjCheckTaint(virDomainObj *obj) +{ + size_t i; + + for (i = 0; i < obj->def->ndisks; i++) + testDomainObjCheckDiskTaint(obj, obj->def->disks[i]); + + for (i = 0; i < obj->def->nhostdevs; i++) + testDomainObjCheckHostdevTaint(obj, obj->def- + + for (i = 0; i < obj->def->nnets; i++) + testDomainObjCheckNetTaint(obj, obj->def->nets[i]); + + if (obj->def->os.dtb) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CUSTOM_DTB); +} + static int testDomainGetMessages(virDomainPtr dom, char ***msgs, @@ -9311,6 +9366,8 @@ testDomainGetMessages(virDomainPtr dom, nmsgs = 0; n = 0;
+ testDomainObjCheckTaint(vm); +
I know it works here, but I would rather do it in testParseDomains() and when creating a domain. To make it done in a single place you could utilise xmlopt callbacks which are called at different stages of parsing an XML, be it domain or any other one. That way this function does not do anything that other drivers don't.
Thanks, I will take your advice and put it in testParseDomains()
if (!flags || (flags & VIR_DOMAIN_MESSAGE_TAINTING)) { nmsgs += __builtin_popcount(vm->taint); *msgs = g_renew(char *, *msgs, nmsgs+1); diff --git a/tests/virshtest.c b/tests/virshtest.c index c1974c46cb..937448cefc 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -22,6 +22,7 @@ main(void)
# define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493" # define SECURITY_LABEL "libvirt-test (enforcing)" +# define MESSAGES "tainted: network configuration using opaque shell scripts"
static const char *dominfo_fc4 = "\ Id: 2\n\ @@ -38,6 +39,7 @@ Managed save: no\n\ Security model: testSecurity\n\ Security DOI: \n\ Security label: " SECURITY_LABEL "\n\ +Messages: " MESSAGES "\n\
Pity there's not much more than this, but again - better than nothing.
I created a new xml for testing and added more tainted configurations, will send it with v4 Thanks!
\n"; static const char *domuuid_fc4 = DOM_UUID "\n\n"; static const char *domid_fc4 = "2\n\n"; -- 2.32.0

The test driver and qemu driver share the same code in virDomainGetMessages(), so extract it to a function. Signed-off-by: Luke Yue <lukedyue@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
participants (2)
-
Luke Yue
-
Martin Kletzander