[pve-devel] [PATCH v2 storage 2/2] zfs over iscsi: on-add hook: dynamically determine base path

Fiona Ebner f.ebner at proxmox.com
Tue May 27 15:34:31 CEST 2025


This reduces the potential breakage from commit "fix #5071: zfs over
iscsi: add 'zfs-base-path' configuration option". Only setups where
'/dev/zvol' exists, but is not a valid base, will still be affected.

Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---

This one is optional, not sure if it's worth it.

Changes in v2:
* Actually check remote host.

 src/PVE/Storage/ZFSPlugin.pm | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/PVE/Storage/ZFSPlugin.pm b/src/PVE/Storage/ZFSPlugin.pm
index 64f1eda..343f1ec 100644
--- a/src/PVE/Storage/ZFSPlugin.pm
+++ b/src/PVE/Storage/ZFSPlugin.pm
@@ -3,9 +3,10 @@ package PVE::Storage::ZFSPlugin;
 use strict;
 use warnings;
 use IO::File;
-use POSIX;
+use POSIX qw(ENOENT);
 use PVE::Tools qw(run_command);
 use PVE::Storage::ZFSPoolPlugin;
+use PVE::RESTEnvironment qw(log_warn);
 use PVE::RPCEnvironment;
 
 use base qw(PVE::Storage::ZFSPoolPlugin);
@@ -246,9 +247,26 @@ sub on_add_hook {
 	    $base_path = PVE::Storage::LunCmd::Istgt::get_base($scfg);
 	} elsif ($scfg->{iscsiprovider} eq 'iet' || $scfg->{iscsiprovider} eq 'LIO') {
 	    # Provider implementations hard-code '/dev/', which does not work for distributions like
-	    # Debian 12. Keep that implementation as-is for backwards compatibility, but use
-	    # '/dev/zvol' here.
-	    $base_path = '/dev/zvol';
+	    # Debian 12. Keep that implementation as-is for backwards compatibility, but use custom
+	    # logic here.
+	    my $target = 'root@' . $scfg->{portal};
+	    my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target];
+	    push $cmd->@*, 'ls', '/dev/zvol';
+
+	    my $rc = eval { run_command($cmd, timeout => 10, noerr => 1, quiet => 1) };
+	    my $err = $@;
+	    if (defined($rc) && $rc == 0) {
+		$base_path = '/dev/zvol';
+	    } elsif (defined($rc) && $rc == ENOENT) {
+		$base_path = '/dev';
+	    } else {
+		my $message = $err ? $err : "remote command failed";
+		chomp($message);
+		$message .= " ($rc)" if defined($rc);
+		$message .= " - check 'zfs-base-path' setting manually!";
+		log_warn($message);
+		$base_path = '/dev/zvol';
+	    }
 	} else {
 	    $zfs_unknown_scsi_provider->($scfg->{iscsiprovider});
 	}
-- 
2.39.5





More information about the pve-devel mailing list