[PATCH 3/4] qemuDomainSetThrottleGroup: Always honour thottle group name passed as argument

Peter Krempa via Devel posted 4 patches 1 week, 6 days ago
[PATCH 3/4] qemuDomainSetThrottleGroup: Always honour thottle group name passed as argument
Posted by Peter Krempa via Devel 1 week, 6 days ago
From: Peter Krempa <pkrempa@redhat.com>

Due to the code share with 'qemuDomainSetBlockIoTune' the throttle group
setting code accepts the throttle group name also via typed parameters.

In 'qemuDomainSetThrottleGroup', this means that there are 2 ways to
pass it the throttle group name and both are handled slightly
differently. Specifically the name of the group used in the list of
groups is the name taken from the typed parameters rather than the one
passed via API. We also don't validate that they match.

Now if the name in the typed parameters is missing we'd add empty string
to the group list which would later crash when looking up the group
name.

To avoid this problem always use the name passed via argument. This is
achieved by passing it into 'qemuDomainSetBlockIoTuneFields' so that it
overrides whatever is in the typed parameters.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_driver.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8c7a2e9fe2..9addad3b9e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15177,6 +15177,7 @@ static int
 qemuDomainSetBlockIoTuneFields(virDomainBlockIoTuneInfo *info,
                                virTypedParameterPtr params,
                                int nparams,
+                               const char *group_name,
                                qemuBlockIoTuneSetFlags *set_fields,
                                virTypedParameterPtr *eventParams,
                                int *eventNparams,
@@ -15247,6 +15248,10 @@ qemuDomainSetBlockIoTuneFields(virDomainBlockIoTuneInfo *info,
                          WRITE_IOPS_SEC_MAX_LENGTH);
     }

+    /* The name of the throttle group passed via API always takes precedence */
+    if (group_name)
+        param_group_name = group_name;
+
     if (param_group_name) {
         info->group_name = g_strdup(param_group_name);
         *set_fields |= QEMU_BLOCK_IOTUNE_SET_GROUP_NAME;
@@ -15394,6 +15399,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
     if (qemuDomainSetBlockIoTuneFields(&info,
                                        params,
                                        nparams,
+                                       NULL,
                                        &set_fields,
                                        &eventParams,
                                        &eventNparams,
@@ -20388,6 +20394,7 @@ qemuDomainSetThrottleGroup(virDomainPtr dom,
     if (qemuDomainSetBlockIoTuneFields(&info,
                                        params,
                                        nparams,
+                                       groupname,
                                        &set_fields,
                                        &eventParams,
                                        &eventNparams,
-- 
2.52.0