]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Extract disk setup done via QMP into a separate helper
authorPeter Krempa <pkrempa@redhat.com>
Thu, 29 Jan 2026 10:15:04 +0000 (11:15 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 Feb 2026 09:22:26 +0000 (10:22 +0100)
Introduce 'qemuProcessSetupDiskPropsRuntime' helper function which will
collect all code used for runtime setup of a disk.

This is currently old-style throttling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_hotplug.c
src/qemu/qemu_process.c
src/qemu/qemu_process.h

index e1e56889421386118aa21f729647bce688aa5e58..467efc15a0991daeec97bc81e676636137b1064e 100644 (file)
@@ -567,13 +567,8 @@ qemuDomainChangeMediaBlockdev(virDomainObj *vm,
     }
 
     /* set throttling for the new image */
-    if (rc == 0 &&
-        !virStorageSourceIsEmpty(newsrc) &&
-        qemuDiskConfigBlkdeviotuneEnabled(disk)) {
-        rc = qemuMonitorSetBlockIoThrottle(priv->mon,
-                                           diskPriv->qomName,
-                                           &disk->blkdeviotune);
-    }
+    if (rc == 0)
+        rc = qemuProcessSetupDiskPropsRuntime(priv->mon, disk);
 
     /* Close any device with a tray since we've opened it before (regardless
      * of the current state if it e.g. wasn't updated) */
@@ -798,20 +793,10 @@ qemuDomainAttachDiskGeneric(virDomainObj *vm,
     if (rc == 0)
         rc = qemuMonitorAddDeviceProps(priv->mon, &devprops);
 
-    /* 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 (rc == 0) {
-        qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
-
-        if (qemuDiskConfigBlkdeviotuneEnabled(disk)) {
-            if (qemuMonitorSetBlockIoThrottle(priv->mon, diskPriv->qomName,
-                                              &disk->blkdeviotune) < 0)
-                VIR_WARN("failed to set blkdeviotune for '%s' of '%s'", disk->dst, vm->def->name);
-        }
+        /* There isn't anything sane to do if this fails (rollback would
+         * require hot-unplug), let's just return success. */
+        ignore_value(qemuProcessSetupDiskPropsRuntime(priv->mon, disk));
     }
 
     if (rc == 0 &&
index 1b7658a07939727a098adae7b1ac146c061e3768..417784b7589c88e80539b6daf538cb194f7e85d8 100644 (file)
@@ -7941,6 +7941,32 @@ qemuProcessGenID(virDomainObj *vm,
 }
 
 
+/**
+ * qemuProcessSetupDiskPropsRuntime:
+ * @mon: qemu monitor object
+ * @disk: disk definition
+ *
+ * This function expects that caller already entered 'monitor' context.
+ *
+ * Sets up disk properties which are only possible to be set in runtime.
+ */
+int
+qemuProcessSetupDiskPropsRuntime(qemuMonitor *mon,
+                                 virDomainDiskDef *disk)
+{
+    if (virStorageSourceIsEmpty(disk->src))
+        return 0;
+
+    if (qemuDiskConfigBlkdeviotuneEnabled(disk) &&
+        qemuMonitorSetBlockIoThrottle(mon,
+                                      QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName,
+                                      &disk->blkdeviotune) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 /**
  * qemuProcessSetupDiskThrottling:
  *
@@ -7964,16 +7990,7 @@ qemuProcessSetupDiskThrottling(virDomainObj *vm,
     for (i = 0; i < vm->def->ndisks; i++) {
         virDomainDiskDef *disk = vm->def->disks[i];
 
-        /* Setting throttling for empty drives fails */
-        if (virStorageSourceIsEmpty(disk->src))
-            continue;
-
-        if (!qemuDiskConfigBlkdeviotuneEnabled(disk))
-            continue;
-
-        if (qemuMonitorSetBlockIoThrottle(qemuDomainGetMonitor(vm),
-                                          QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName,
-                                          &disk->blkdeviotune) < 0)
+        if (qemuProcessSetupDiskPropsRuntime(qemuDomainGetMonitor(vm), disk) < 0)
             goto cleanup;
     }
 
index d96502b6014eee3a3586b4b27b7a7f0ab6a07912..6ba846b7b19af22269656058225bf72f784a3295 100644 (file)
@@ -146,6 +146,9 @@ int qemuProcessPrepareHostStorageSourceChain(virDomainObj *vm,
 int qemuProcessPrepareHostStorageDisk(virDomainObj *vm,
                                   virDomainDiskDef *disk);
 
+int qemuProcessSetupDiskPropsRuntime(qemuMonitor *mon,
+                                     virDomainDiskDef *disk);
+
 int qemuProcessDeleteThreadContext(virDomainObj *vm);
 
 int qemuProcessLaunch(virConnectPtr conn,