[pve-devel] [PATCH qemu-server v2 10/32] drive: move storage_allows_io_uring_default() and drive_uses_cache_direct() helpers to drive module

Fiona Ebner f.ebner at proxmox.com
Wed Jun 18 15:01:47 CEST 2025


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

No changes in v2.

 src/PVE/QemuServer.pm       | 47 ++++++++++---------------------------
 src/PVE/QemuServer/Drive.pm | 33 ++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 76fc121c..a3c37707 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -56,8 +56,16 @@ use PVE::QemuServer::Cloudinit;
 use PVE::QemuServer::CGroup;
 use PVE::QemuServer::CPUConfig
     qw(print_cpu_device get_cpu_options get_cpu_bitness is_native_arch get_amd_sev_object get_amd_sev_type);
-use PVE::QemuServer::Drive
-    qw(is_valid_drivename checked_volume_format drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive);
+use PVE::QemuServer::Drive qw(
+    is_valid_drivename
+    checked_volume_format
+    drive_is_cloudinit
+    drive_is_cdrom
+    drive_is_read_only
+    parse_drive
+    print_drive
+    storage_allows_io_uring_default
+);
 use PVE::QemuServer::Machine;
 use PVE::QemuServer::Memory qw(get_current_memory);
 use PVE::QemuServer::MetaInfo;
@@ -1497,37 +1505,6 @@ sub get_initiator_name {
     return $initiator;
 }
 
-my sub storage_allows_io_uring_default {
-    my ($scfg, $cache_direct) = @_;
-
-    # io_uring with cache mode writeback or writethrough on krbd will hang...
-    return if $scfg && $scfg->{type} eq 'rbd' && $scfg->{krbd} && !$cache_direct;
-
-    # io_uring with cache mode writeback or writethrough on LVM will hang, without cache only
-    # sometimes, just plain disable...
-    return if $scfg && $scfg->{type} eq 'lvm';
-
-    # io_uring causes problems when used with CIFS since kernel 5.15
-    # Some discussion: https://www.spinics.net/lists/linux-cifs/msg26734.html
-    return if $scfg && $scfg->{type} eq 'cifs';
-
-    return 1;
-}
-
-my sub drive_uses_cache_direct {
-    my ($drive, $scfg) = @_;
-
-    my $cache_direct = 0;
-
-    if (my $cache = $drive->{cache}) {
-        $cache_direct = $cache =~ /^(?:off|none|directsync)$/;
-    } elsif (!drive_is_cdrom($drive) && !($scfg && $scfg->{type} eq 'btrfs' && !$scfg->{nocow})) {
-        $cache_direct = 1;
-    }
-
-    return $cache_direct;
-}
-
 sub print_drive_commandline_full {
     my ($storecfg, $vmid, $drive, $live_restore_name) = @_;
 
@@ -1589,7 +1566,7 @@ sub print_drive_commandline_full {
         $opts .= ",format=$format";
     }
 
-    my $cache_direct = drive_uses_cache_direct($drive, $scfg);
+    my $cache_direct = PVE::QemuServer::Drive::drive_uses_cache_direct($drive, $scfg);
 
     $opts .= ",cache=none" if !$drive->{cache} && $cache_direct;
 
@@ -8864,7 +8841,7 @@ my sub clone_disk_check_io_uring {
     my $src_scfg = PVE::Storage::storage_config($storecfg, $src_storeid);
     my $dst_scfg = PVE::Storage::storage_config($storecfg, $dst_storeid);
 
-    my $cache_direct = drive_uses_cache_direct($src_drive, $src_scfg);
+    my $cache_direct = PVE::QemuServer::Drive::drive_uses_cache_direct($src_drive, $src_scfg);
 
     my $src_uses_io_uring;
     if ($src_drive->{aio}) {
diff --git a/src/PVE/QemuServer/Drive.pm b/src/PVE/QemuServer/Drive.pm
index 96bb12c4..377cf54e 100644
--- a/src/PVE/QemuServer/Drive.pm
+++ b/src/PVE/QemuServer/Drive.pm
@@ -24,6 +24,7 @@ our @EXPORT_OK = qw(
     get_scsi_devicetype
     parse_drive
     print_drive
+    storage_allows_io_uring_default
 );
 
 my $DROPPED_PROPERTIES = ['cyls', 'heads', 'secs', 'trans'];
@@ -1060,4 +1061,36 @@ sub get_scsi_device_type {
 
     return $devicetype;
 }
+
+sub storage_allows_io_uring_default {
+    my ($scfg, $cache_direct) = @_;
+
+    # io_uring with cache mode writeback or writethrough on krbd will hang...
+    return if $scfg && $scfg->{type} eq 'rbd' && $scfg->{krbd} && !$cache_direct;
+
+    # io_uring with cache mode writeback or writethrough on LVM will hang, without cache only
+    # sometimes, just plain disable...
+    return if $scfg && $scfg->{type} eq 'lvm';
+
+    # io_uring causes problems when used with CIFS since kernel 5.15
+    # Some discussion: https://www.spinics.net/lists/linux-cifs/msg26734.html
+    return if $scfg && $scfg->{type} eq 'cifs';
+
+    return 1;
+}
+
+sub drive_uses_cache_direct {
+    my ($drive, $scfg) = @_;
+
+    my $cache_direct = 0;
+
+    if (my $cache = $drive->{cache}) {
+        $cache_direct = $cache =~ /^(?:off|none|directsync)$/;
+    } elsif (!drive_is_cdrom($drive) && !($scfg && $scfg->{type} eq 'btrfs' && !$scfg->{nocow})) {
+        $cache_direct = 1;
+    }
+
+    return $cache_direct;
+}
+
 1;
-- 
2.39.5





More information about the pve-devel mailing list