qemu: Make qemuBuildVirtioDevProps() const correct

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>
This commit is contained in:
Andrea Bolognani 2021-10-20 12:01:03 +02:00
parent 8e3d58f245
commit 1cb48b00b5

View File

@ -812,7 +812,7 @@ qemuDeviceVideoGetModel(virQEMUCaps *qemuCaps,
static void static void
qemuBuildVirtioDevGetConfigDev(virDomainDeviceDef *device, qemuBuildVirtioDevGetConfigDev(const virDomainDeviceDef *device,
virQEMUCaps *qemuCaps, virQEMUCaps *qemuCaps,
const char **baseName, const char **baseName,
virDomainVirtioOptions **virtioOptions, virDomainVirtioOptions **virtioOptions,
@ -976,7 +976,7 @@ qemuBuildVirtioDevGetConfigDev(virDomainDeviceDef *device,
static int static int
qemuBuildVirtioDevGetConfig(virDomainDeviceDef *device, qemuBuildVirtioDevGetConfig(const virDomainDeviceDef *device,
virQEMUCaps *qemuCaps, virQEMUCaps *qemuCaps,
char **devtype, char **devtype,
virDomainVirtioOptions **virtioOptions, virDomainVirtioOptions **virtioOptions,
@ -1094,17 +1094,21 @@ qemuBuildVirtioDevGetConfig(virDomainDeviceDef *device,
*/ */
static virJSONValue * static virJSONValue *
qemuBuildVirtioDevProps(virDomainDeviceType devtype, qemuBuildVirtioDevProps(virDomainDeviceType devtype,
void *devdata, const void *devdata,
virQEMUCaps *qemuCaps) virQEMUCaps *qemuCaps)
{ {
g_autoptr(virJSONValue) props = NULL; g_autoptr(virJSONValue) props = NULL;
virDomainDeviceDef device = { .type = devtype }; const virDomainDeviceDef device = { .type = devtype };
g_autofree char *model = NULL; g_autofree char *model = NULL;
virTristateSwitch disableLegacy = VIR_TRISTATE_SWITCH_ABSENT; virTristateSwitch disableLegacy = VIR_TRISTATE_SWITCH_ABSENT;
virTristateSwitch disableModern = VIR_TRISTATE_SWITCH_ABSENT; virTristateSwitch disableModern = VIR_TRISTATE_SWITCH_ABSENT;
virDomainVirtioOptions *virtioOptions = NULL; 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, if (qemuBuildVirtioDevGetConfig(&device, qemuCaps, &model, &virtioOptions,
&disableLegacy, &disableModern) < 0) &disableLegacy, &disableModern) < 0)