]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Make qemuBuildVirtioDevProps() const correct
authorAndrea Bolognani <abologna@redhat.com>
Wed, 20 Oct 2021 10:01:03 +0000 (12:01 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Wed, 20 Oct 2021 14:53:05 +0000 (16:53 +0200)
This involves a bit of a hack, but is overall preferable to
forcing callers to pass non-const devdata as argument.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c

index 035943fa9626d4dc363cd54668b58b75bce9cd97..d6df50ec73cd6efb659d53991fb7e34274bbd7e1 100644 (file)
@@ -812,7 +812,7 @@ qemuDeviceVideoGetModel(virQEMUCaps *qemuCaps,
 
 
 static void
-qemuBuildVirtioDevGetConfigDev(virDomainDeviceDef *device,
+qemuBuildVirtioDevGetConfigDev(const virDomainDeviceDef *device,
                                virQEMUCaps *qemuCaps,
                                const char **baseName,
                                virDomainVirtioOptions **virtioOptions,
@@ -976,7 +976,7 @@ qemuBuildVirtioDevGetConfigDev(virDomainDeviceDef *device,
 
 
 static int
-qemuBuildVirtioDevGetConfig(virDomainDeviceDef *device,
+qemuBuildVirtioDevGetConfig(const virDomainDeviceDef *device,
                             virQEMUCaps *qemuCaps,
                             char **devtype,
                             virDomainVirtioOptions **virtioOptions,
@@ -1094,17 +1094,21 @@ qemuBuildVirtioDevGetConfig(virDomainDeviceDef *device,
  */
 static virJSONValue *
 qemuBuildVirtioDevProps(virDomainDeviceType devtype,
-                        void *devdata,
+                        const void *devdata,
                         virQEMUCaps *qemuCaps)
 {
     g_autoptr(virJSONValue) props = NULL;
-    virDomainDeviceDef device = { .type = devtype };
+    const virDomainDeviceDef device = { .type = devtype };
     g_autofree char *model = NULL;
     virTristateSwitch disableLegacy = VIR_TRISTATE_SWITCH_ABSENT;
     virTristateSwitch disableModern = VIR_TRISTATE_SWITCH_ABSENT;
     virDomainVirtioOptions *virtioOptions = NULL;
 
-    virDomainDeviceSetData(&device, devdata);
+    /* We temporarily cast the const away here, but that's safe to do
+     * because the called function simply sets the correct member of
+     * device to devdata based on devtype. Futher uses of device will
+     * not touch its contents */
+    virDomainDeviceSetData((virDomainDeviceDef *) &device, (void *) devdata);
 
     if (qemuBuildVirtioDevGetConfig(&device, qemuCaps, &model, &virtioOptions,
                                     &disableLegacy, &disableModern) < 0)