[pve-devel] [PATCH qemu-server v2 26/32] print drive device: explicitly set write-cache starting with machine version 10.0

Fiona Ebner f.ebner at proxmox.com
Wed Jun 18 15:02:03 CEST 2025


With the 'blockdev' command line option, the cache options are split
up. While cache.direct and cache.no-flush can be set in the -blockdev
options, cache.writeback is a front-end property and was intentionally
removed from the 'blockdev' options by QEMU commit aaa436f998 ("block:
Remove cache.writeback from blockdev-add"). It needs to be configured
as the 'write-cache' property for the ide-hd/scsi-hd/virtio-blk
device.

Table from 'man kvm':

┌─────────────┬─────────────────┬──────────────┬────────────────┐
│             │ cache.writeback │ cache.direct │ cache.no-flush │
├─────────────┼─────────────────┼──────────────┼────────────────┤
│writeback    │ on              │ off          │ off            │
├─────────────┼─────────────────┼──────────────┼────────────────┤
│none         │ on              │ on           │ off            │
├─────────────┼─────────────────┼──────────────┼────────────────┤
│writethrough │ off             │ off          │ off            │
├─────────────┼─────────────────┼──────────────┼────────────────┤
│directsync   │ off             │ on           │ off            │
├─────────────┼─────────────────┼──────────────┼────────────────┤
│unsafe       │ on              │ off          │ on             │
└─────────────┴─────────────────┴──────────────┴────────────────┘

Suggested-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---

Changes in v2:
* Comment that the version guard is for the switch to -blockdev.

 src/PVE/QemuServer.pm | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index f8adb890..0b983ab9 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -1403,6 +1403,8 @@ sub print_drivedevice_full {
     my $device = '';
     my $maxdev = 0;
 
+    my $machine_version = extract_version($machine_type, kvm_user_version());
+
     my $drive_id = PVE::QemuServer::Drive::get_drive_id($drive);
     if ($drive->{interface} eq 'virtio') {
         my $pciaddr = print_pci_addr("$drive_id", $bridges, $arch);
@@ -1413,7 +1415,6 @@ sub print_drivedevice_full {
         my ($maxdev, $controller, $controller_prefix) = scsihw_infos($conf, $drive);
         my $unit = $drive->{index} % $maxdev;
 
-        my $machine_version = extract_version($machine_type, kvm_user_version());
         my $device_type =
             PVE::QemuServer::Drive::get_scsi_device_type($drive, $storecfg, $machine_version);
 
@@ -1489,6 +1490,16 @@ sub print_drivedevice_full {
         $device .= ",serial=$serial";
     }
 
+    if (min_version($machine_version, 10, 0)) { # for the switch to -blockdev
+        if (!drive_is_cdrom($drive)) {
+            my $write_cache = 'on';
+            if (my $cache = $drive->{cache}) {
+                $write_cache = 'off' if $cache eq 'writethrough' || $cache eq 'directsync';
+            }
+            $device .= ",write-cache=$write_cache";
+        }
+    }
+
     return $device;
 }
 
-- 
2.39.5





More information about the pve-devel mailing list