[libvirt] [PATCH 0/3] qemu: Fix disk IO tuning on hotplug with -blockdev (blockdev-add saga)

Few cleanups and a bugfix as with blockdev we need to issue an extra command to honour disk throttling config. Peter Krempa (3): qemu: hotplug: Simplify cleanup in qemuDomainChangeMediaLegacy qemu: hotplug: Use VIR_AUTOFREE in qemuDomainAttachDiskGeneric qemu: hotplug: Setup disk throttling with blockdev src/qemu/qemu_hotplug.c | 52 ++++++++++++++++++++++++----------------- src/qemu/qemu_process.c | 1 + 2 files changed, 32 insertions(+), 21 deletions(-) -- 2.21.0

Switch to using VIR_AUTOFREE and remove the cleanup label. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_hotplug.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 63acb9c451..c91dfc9f6b 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -258,48 +258,48 @@ qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver, virStorageSourcePtr newsrc, bool force) { - int ret = -1, rc; - char *driveAlias = NULL; + int rc; + VIR_AUTOFREE(char *) driveAlias = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); const char *format = NULL; - char *sourcestr = NULL; + VIR_AUTOFREE(char *) sourcestr = NULL; if (!disk->info.alias) { virReportError(VIR_ERR_INTERNAL_ERROR, _("missing disk device alias name for %s"), disk->dst); - goto cleanup; + return -1; } if (!(driveAlias = qemuAliasDiskDriveFromDisk(disk))) - goto cleanup; + return -1; qemuDomainObjEnterMonitor(driver, vm); rc = qemuMonitorEjectMedia(priv->mon, driveAlias, force); if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; + return -1; /* If the tray is present wait for it to open. */ if (!force && diskPriv->tray) { rc = qemuHotplugWaitForTrayEject(vm, disk); if (rc < 0) - goto cleanup; + return -1; /* re-issue ejection command to pop out the media */ qemuDomainObjEnterMonitor(driver, vm); rc = qemuMonitorEjectMedia(priv->mon, driveAlias, false); if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) - goto cleanup; + return -1; } else { /* otherwise report possible errors from the attempt to eject the media*/ if (rc < 0) - goto cleanup; + return -1; } if (!virStorageSourceIsEmpty(newsrc)) { if (qemuGetDriveSourceString(newsrc, NULL, &sourcestr) < 0) - goto cleanup; + return -1; if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) format = virStorageFileFormatTypeToString(newsrc->format); @@ -310,18 +310,13 @@ qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver, sourcestr, format); if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; + return -1; } if (rc < 0) - goto cleanup; - - ret = 0; + return -1; - cleanup: - VIR_FREE(driveAlias); - VIR_FREE(sourcestr); - return ret; + return 0; } -- 2.21.0

On Thu, Sep 05, 2019 at 04:20:04PM +0200, Peter Krempa wrote:
Switch to using VIR_AUTOFREE and remove the cleanup label.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_hotplug.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Get rid of the last manually freed var. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_hotplug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index c91dfc9f6b..30aa6d2344 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -613,7 +613,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, VIR_AUTOPTR(qemuBlockStorageSourceChainData) data = NULL; int ret = -1; qemuDomainObjPrivatePtr priv = vm->privateData; - char *devstr = NULL; + VIR_AUTOFREE(char *) devstr = NULL; VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); VIR_AUTOPTR(virJSONValue) corProps = NULL; VIR_AUTOFREE(char *) corAlias = NULL; @@ -679,7 +679,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, cleanup: qemuDomainSecretDiskDestroy(disk); - VIR_FREE(devstr); return ret; exit_monitor: -- 2.21.0

On Thu, Sep 05, 2019 at 04:20:05PM +0200, Peter Krempa wrote:
Get rid of the last manually freed var.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_hotplug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

With blockdev we must issue the block_set_io_throttle QMP command to setup disk throttling as we currently can't do it with the 'throttle' layer. Unfortunately there's nothing we can do if it fails. https://bugzilla.redhat.com/show_bug.cgi?id=1733163 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_hotplug.c | 18 +++++++++++++++++- src/qemu/qemu_process.c | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 30aa6d2344..a7034fd298 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -617,6 +617,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver); VIR_AUTOPTR(virJSONValue) corProps = NULL; VIR_AUTOFREE(char *) corAlias = NULL; + bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); if (qemuDomainStorageSourceChainAccessAllow(driver, vm, disk->src) < 0) goto cleanup; @@ -627,7 +628,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0) goto error; - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (blockdev) { if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON && !(corProps = qemuBlockStorageGetCopyOnReadProps(disk))) goto cleanup; @@ -667,6 +668,21 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, goto exit_monitor; } + /* Setup throttling of disk via block_set_io_throttle QMP command. This + * is a hack until the 'throttle' blockdev driver will support modification + * of the trhottle group. See also qemuProcessSetupDiskThrottlingBlockdev. + * As there isn't anything sane to do if this fails, let's just return + * success. + */ + if (blockdev && + qemuDiskConfigBlkdeviotuneEnabled(disk)) { + qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); + if (qemuMonitorSetBlockIoThrottle(priv->mon, NULL, diskPriv->qomName, + &disk->blkdeviotune, + true, true, true) < 0) + VIR_WARN("failed to set blkdeviotune for '%s' of '%s'", disk->dst, vm->def->name); + } + if (qemuDomainObjExitMonitor(driver, vm) < 0) { ret = -2; goto error; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c9921646e9..61b03c8a2d 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6671,6 +6671,7 @@ qemuProcessGenID(virDomainObjPtr vm, * Sets up disk trottling for -blockdev via block_set_io_throttle monitor * command. This hack should be replaced by proper use of the 'throttle' * blockdev driver in qemu once it will support changing of the throttle group. + * Same hack is done in qemuDomainAttachDiskGeneric. */ static int qemuProcessSetupDiskThrottlingBlockdev(virQEMUDriverPtr driver, -- 2.21.0

On Thu, Sep 05, 2019 at 04:20:06PM +0200, Peter Krempa wrote:
With blockdev we must issue the block_set_io_throttle QMP command to setup disk throttling as we currently can't do it with the 'throttle' layer.
Unfortunately there's nothing we can do if it fails.
Sigh,
https://bugzilla.redhat.com/show_bug.cgi?id=1733163
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_hotplug.c | 18 +++++++++++++++++- src/qemu/qemu_process.c | 1 + 2 files changed, 18 insertions(+), 1 deletion(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Peter Krempa