use strict;
use warnings;
+
use File::stat;
use IO::Dir;
use IO::File;
-use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach $IPV4RE $IPV6RE);
-use PVE::Storage::Plugin;
+
use PVE::JSONSchema qw(get_standard_option);
+use PVE::Storage::Plugin;
+use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach $IPV4RE $IPV6RE);
use base qw(PVE::Storage::Plugin);
eval {
run_command($cmd, errmsg => 'iscsi session scan failed', outfunc => sub {
my $line = shift;
-
+
if ($line =~ m/^tcp:\s+\[(\S+)\]\s+\S+\s+(\S+)(\s+\S+)?\s*$/) {
my ($session, $target) = ($1, $2);
# there can be several sessions per target (multipath)
- push @{$res->{$target}}, $session;
+ push @{$res->{$target}}, $session;
}
});
};
check_iscsi_support ();
- my $cmd = [$ISCSIADM, '--mode', 'discovery', '--type', 'sendtargets',
+ my $cmd = [$ISCSIADM, '--mode', 'discovery', '--type', 'sendtargets',
'--portal', $portal];
my $res = {};
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
+ # 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|^../../([^/]+)|) {
}
return if !$bdev;
- #check multipath
- if (-d "/sys/block/$bdev/holders") {
+ #check multipath
+ if (-d "/sys/block/$bdev/holders") {
my $multipathdev = dir_glob_regex("/sys/block/$bdev/holders", '[A-Za-z]\S*');
$bdev = $multipathdev if $multipathdev;
}
my $volid = "$channel.$id.$lun.$blockdev";
$res->{$target}->{$volid} = {
- 'format' => 'raw',
- 'size' => int($size * 512),
+ 'format' => 'raw',
+ 'size' => int($size * 512),
'vmid' => 0, # not assigned to any vm
'channel' => int($channel),
'id' => int($id),
'lun' => int($lun),
};
- #print "TEST: $target $session $host,$bus,$tg,$lun $blockdev\n";
+ #print "TEST: $target $session $host,$bus,$tg,$lun $blockdev\n";
});
});
die "snapshot is not possible on iscsi storage\n" if defined($snapname);
my ($vtype, $name, $vmid) = $class->parse_volname($volname);
-
+
my $path = "/dev/disk/by-id/$name";
return wantarray ? ($path, $vmid, $vtype) : $path;
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) = @_;
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}});
+ my $session = iscsi_session($cache, $scfg->{target});
+ my $active = defined($session) ? 1 : 0;
return (0, 0, 0, $active);
}
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);
}
}
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});
}
}