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

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Jun 13 12:28:29 CEST 2025


On June 12, 2025 4:02 pm, Fiona Ebner wrote:
> 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>
> ---
>  PVE/QemuServer.pm | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index 82304096..f9e1b3f9 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -1317,6 +1317,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, $machine_type);
> @@ -1327,7 +1329,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);
>  
> @@ -1403,6 +1404,15 @@ sub print_drivedevice_full {
>  	$device .= ",serial=$serial";
>      }
>  
> +    if (min_version($machine_version, 10, 0)) {

should we add a comment here (and for similar conditionals in following
patches) that this is for the switch to blockdev? obvious now, might be
lass obvious down the line ;)

> +	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
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 




More information about the pve-devel mailing list