From 0bbd7257c478811cb118f8a23f54de5a24eda7f7 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 22 Jul 2022 11:29:54 +0200 Subject: [PATCH] qemu: Setup disk throttling for SD cards via monitor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set it same way we set throttling for other disks in qemuProcessSetupDiskThrottling. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina Reviewed-by: Ján Tomko --- src/qemu/qemu_command.c | 42 ----------------------------------------- src/qemu/qemu_process.c | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 50 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index fbcd5421e6..c5e41ac619 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1676,46 +1676,6 @@ qemuBuildDriveSourceStr(virDomainDiskDef *disk, } -static void -qemuBuildDiskThrottling(virDomainDiskDef *disk, - virBuffer *buf) -{ -#define IOTUNE_ADD(_field, _label) \ - if (disk->blkdeviotune._field) { \ - virBufferAsprintf(buf, ",throttling." _label "=%llu", \ - disk->blkdeviotune._field); \ - } - - IOTUNE_ADD(total_bytes_sec, "bps-total"); - IOTUNE_ADD(read_bytes_sec, "bps-read"); - IOTUNE_ADD(write_bytes_sec, "bps-write"); - IOTUNE_ADD(total_iops_sec, "iops-total"); - IOTUNE_ADD(read_iops_sec, "iops-read"); - IOTUNE_ADD(write_iops_sec, "iops-write"); - - IOTUNE_ADD(total_bytes_sec_max, "bps-total-max"); - IOTUNE_ADD(read_bytes_sec_max, "bps-read-max"); - IOTUNE_ADD(write_bytes_sec_max, "bps-write-max"); - IOTUNE_ADD(total_iops_sec_max, "iops-total-max"); - IOTUNE_ADD(read_iops_sec_max, "iops-read-max"); - IOTUNE_ADD(write_iops_sec_max, "iops-write-max"); - - IOTUNE_ADD(size_iops_sec, "iops-size"); - if (disk->blkdeviotune.group_name) { - virBufferAddLit(buf, ",throttling.group="); - virQEMUBuildBufferEscapeComma(buf, disk->blkdeviotune.group_name); - } - - IOTUNE_ADD(total_bytes_sec_max_length, "bps-total-max-length"); - IOTUNE_ADD(read_bytes_sec_max_length, "bps-read-max-length"); - IOTUNE_ADD(write_bytes_sec_max_length, "bps-write-max-length"); - IOTUNE_ADD(total_iops_sec_max_length, "iops-total-max-length"); - IOTUNE_ADD(read_iops_sec_max_length, "iops-read-max-length"); - IOTUNE_ADD(write_iops_sec_max_length, "iops-write-max-length"); -#undef IOTUNE_ADD -} - - static void qemuBuildDiskGetErrorPolicy(virDomainDiskDef *disk, const char **wpolicy, @@ -1790,8 +1750,6 @@ qemuBuildDriveStr(virDomainDiskDef *disk) } } - qemuBuildDiskThrottling(disk, &opt); - return virBufferContentAndReset(&opt); } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index efd8706957..ce4257d671 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7198,7 +7198,7 @@ qemuProcessGenID(virDomainObj *vm, /** - * qemuProcessSetupDiskThrottlingBlockdev: + * qemuProcessSetupDiskThrottling: * * Sets up disk trottling for -blockdev via block_set_io_throttle monitor * command. This hack should be replaced by proper use of the 'throttle' @@ -7206,8 +7206,8 @@ qemuProcessGenID(virDomainObj *vm, * Same hack is done in qemuDomainAttachDiskGeneric. */ static int -qemuProcessSetupDiskThrottlingBlockdev(virDomainObj *vm, - virDomainAsyncJob asyncJob) +qemuProcessSetupDiskThrottling(virDomainObj *vm, + virDomainAsyncJob asyncJob) { size_t i; int ret = -1; @@ -7220,10 +7220,12 @@ qemuProcessSetupDiskThrottlingBlockdev(virDomainObj *vm, for (i = 0; i < vm->def->ndisks; i++) { virDomainDiskDef *disk = vm->def->disks[i]; qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); + g_autofree char *drivealias = NULL; - /* sd-cards are instantiated via -drive */ - if (qemuDiskBusIsSD(disk->bus)) - continue; + if (!QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName) { + if (!(drivealias = qemuAliasDiskDriveFromDisk(disk))) + goto cleanup; + } /* Setting throttling for empty drives fails */ if (virStorageSourceIsEmpty(disk->src)) @@ -7232,7 +7234,7 @@ qemuProcessSetupDiskThrottlingBlockdev(virDomainObj *vm, if (!qemuDiskConfigBlkdeviotuneEnabled(disk)) continue; - if (qemuMonitorSetBlockIoThrottle(qemuDomainGetMonitor(vm), NULL, + if (qemuMonitorSetBlockIoThrottle(qemuDomainGetMonitor(vm), drivealias, diskPriv->qomName, &disk->blkdeviotune) < 0) goto cleanup; } @@ -7745,7 +7747,7 @@ qemuProcessLaunch(virConnectPtr conn, if (qemuProcessSetupBalloon(vm, asyncJob) < 0) goto cleanup; - if (qemuProcessSetupDiskThrottlingBlockdev(vm, asyncJob) < 0) + if (qemuProcessSetupDiskThrottling(vm, asyncJob) < 0) goto cleanup; /* Since CPUs were not started yet, the balloon could not return the memory