]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/ISCSIPlugin.pm
cifs: check connection: bubble up NT_STATUS_LOGON_FAILURE
[pve-storage.git] / PVE / Storage / ISCSIPlugin.pm
index 2f917f4b871947e868bab6bb214fa8c091984e7a..a79fcb08c56df17e1570f732eec8986bd7751c0e 100644 (file)
@@ -73,13 +73,10 @@ sub iscsi_discovery {
 
     check_iscsi_support ();
 
-    my $cmd = [$ISCSIADM, '--mode', 'discovery', '--type', 'sendtargets',
-              '--portal', $portal];
-
     my $res = {};
-
     return $res if !iscsi_test_portal($portal); # fixme: raise exception here?
 
+    my $cmd = [$ISCSIADM, '--mode', 'discovery', '--type', 'sendtargets', '--portal', $portal];
     run_command($cmd, outfunc => sub {
        my $line = shift;
 
@@ -97,22 +94,20 @@ sub iscsi_discovery {
 sub iscsi_login {
     my ($target, $portal_in) = @_;
 
-    check_iscsi_support ();
+    check_iscsi_support();
 
-    eval { iscsi_discovery ($portal_in); };
+    eval { iscsi_discovery($portal_in); };
     warn $@ if $@;
 
-    my $cmd = [$ISCSIADM, '--mode', 'node', '--targetname',  $target, '--login'];
-    run_command($cmd);
+    run_command([$ISCSIADM, '--mode', 'node', '--targetname',  $target, '--login']);
 }
 
 sub iscsi_logout {
     my ($target, $portal) = @_;
 
-    check_iscsi_support ();
+    check_iscsi_support();
 
-    my $cmd = [$ISCSIADM, '--mode', 'node', '--targetname', $target, '--logout'];
-    run_command($cmd);
+    run_command([$ISCSIADM, '--mode', 'node', '--targetname', $target, '--logout']);
 }
 
 my $rescan_filename = "/var/run/pve-iscsi-rescan.lock";
@@ -151,11 +146,11 @@ sub load_stable_scsi_paths {
     my $stabledir = "/dev/disk/by-id";
 
     if (my $dh = IO::Dir->new($stabledir)) {
-       while (defined(my $tmp = $dh->read)) {
+       foreach my $tmp (sort $dh->read) {
            # exclude filenames with part in name (same disk but partitions)
            # use only filenames with scsi(with multipath i have the same device
           # with dm-uuid-mpath , dm-name and scsi in name)
-           if($tmp !~ m/-part\d+$/ && $tmp =~ m/^scsi-/) {
+           if($tmp !~ m/-part\d+$/ && ($tmp =~ m/^scsi-/ || $tmp =~ m/^dm-uuid-mpath-/)) {
                  my $path = "$stabledir/$tmp";
                  my $bdevdest = readlink($path);
                 if ($bdevdest && $bdevdest =~ m|^../../([^/]+)|) {
@@ -315,6 +310,20 @@ sub free_image {
     die "can't free space in iscsi storage\n";
 }
 
+# list all luns regardless of set content_types, since we need it for
+# listing in the gui and we can only have images anyway
+sub list_volumes {
+    my ($class, $storeid, $scfg, $vmid, $content_types) = @_;
+
+    my $res = $class->list_images($storeid, $scfg, $vmid);
+
+    for my $item (@$res) {
+       $item->{content} = 'images'; # we only have images
+    }
+
+    return $res;
+}
+
 sub list_images {
     my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
 
@@ -350,12 +359,17 @@ sub list_images {
     return $res;
 }
 
+sub iscsi_session {
+    my ($cache, $target) = @_;
+    $cache->{iscsi_sessions} = iscsi_session_list() if !$cache->{iscsi_sessions};
+    return $cache->{iscsi_sessions}->{$target};
+}
+
 sub status {
     my ($class, $storeid, $scfg, $cache) = @_;
 
-    $cache->{iscsi_sessions} = iscsi_session_list() if !$cache->{iscsi_sessions};
-
-    my $active = defined($cache->{iscsi_sessions}->{$scfg->{target}}) + 0;
+    my $session = iscsi_session($cache, $scfg->{target});
+    my $active = defined($session) ? 1 : 0;
 
     return (0, 0, 0, $active);
 }
@@ -365,15 +379,14 @@ sub activate_storage {
 
     return if !check_iscsi_support(1);
 
-    $cache->{iscsi_sessions} = iscsi_session_list() if !$cache->{iscsi_sessions};
+    my $session = iscsi_session($cache, $scfg->{target});
 
-    my $iscsi_sess = $cache->{iscsi_sessions}->{$scfg->{target}};
-    if (!defined ($iscsi_sess)) {
+    if (!defined ($session)) {
        eval { iscsi_login($scfg->{target}, $scfg->{portal}); };
        warn $@ if $@;
     } else {
        # make sure we get all devices
-       iscsi_session_rescan($iscsi_sess);
+       iscsi_session_rescan($session);
     }
 }
 
@@ -382,11 +395,7 @@ sub deactivate_storage {
 
     return if !check_iscsi_support(1);
 
-    $cache->{iscsi_sessions} = iscsi_session_list() if !$cache->{iscsi_sessions};
-
-    my $iscsi_sess = $cache->{iscsi_sessions}->{$scfg->{target}};
-
-    if (defined ($iscsi_sess)) {
+    if (defined(iscsi_session($cache, $scfg->{target}))) {
        iscsi_logout($scfg->{target}, $scfg->{portal});
     }
 }