]> git.proxmox.com Git - qemu-server.git/commitdiff
drive commandline: factor out determining direct cache usage into helper
authorFiona Ebner <f.ebner@proxmox.com>
Fri, 10 Feb 2023 14:19:11 +0000 (15:19 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 14 Feb 2023 09:09:04 +0000 (10:09 +0100)
In preparation to re-use it for a check for live disk cloning.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
PVE/QemuServer.pm

index 10d29a069e6319e77d2e4e2cdc4b7c1abcd77725..d4b1a984b0863e14f73a48df9ee6ea65f1a04036 100644 (file)
@@ -1615,6 +1615,20 @@ my sub storage_allows_io_uring_default {
     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, $pbs_name, $io_uring) = @_;
 
@@ -1688,14 +1702,9 @@ sub print_drive_commandline_full {
        $opts .= ",format=$format";
     }
 
-    my $cache_direct = 0;
+    my $cache_direct = drive_uses_cache_direct($drive, $scfg);
 
-    if (my $cache = $drive->{cache}) {
-       $cache_direct = $cache =~ /^(?:off|none|directsync)$/;
-    } elsif (!drive_is_cdrom($drive) && !($scfg && $scfg->{type} eq 'btrfs' && !$scfg->{nocow})) {
-       $opts .= ",cache=none";
-       $cache_direct = 1;
-    }
+    $opts .= ",cache=none" if !$drive->{cache} && $cache_direct;
 
     if (!$drive->{aio}) {
        if ($io_uring && storage_allows_io_uring_default($scfg, $cache_direct)) {