iscsidirect plugin: do not use cache in list_images()
A static cache key 'directiscsi' was used to cache storeid-specific information. This was causing issues in case of multiple instances. Drop $cache usage instead of fixing the issue as there is no caller using it and the same portal/storeid multiple times. Remove $storeid from iscsi_ls() and its callers. Signed-off-by: Dmitry Petrov <dpetrov67@gmail.com>
This commit is contained in:
committed by
Fabian Grünbichler
parent
9b7c1746f1
commit
bdabd1296b
@ -15,7 +15,7 @@ use PVE::JSONSchema qw(get_standard_option);
|
|||||||
use base qw(PVE::Storage::Plugin);
|
use base qw(PVE::Storage::Plugin);
|
||||||
|
|
||||||
sub iscsi_ls {
|
sub iscsi_ls {
|
||||||
my ($scfg, $storeid) = @_;
|
my ($scfg) = @_;
|
||||||
|
|
||||||
my $portal = $scfg->{portal};
|
my $portal = $scfg->{portal};
|
||||||
my $cmd = ['/usr/bin/iscsi-ls', '-s', 'iscsi://'.$portal ];
|
my $cmd = ['/usr/bin/iscsi-ls', '-s', 'iscsi://'.$portal ];
|
||||||
@ -27,29 +27,27 @@ sub iscsi_ls {
|
|||||||
"T" => 1024*1024*1024*1024
|
"T" => 1024*1024*1024*1024
|
||||||
);
|
);
|
||||||
eval {
|
eval {
|
||||||
|
|
||||||
run_command($cmd, errmsg => "iscsi error", errfunc => sub {}, outfunc => sub {
|
run_command($cmd, errmsg => "iscsi error", errfunc => sub {}, outfunc => sub {
|
||||||
my $line = shift;
|
my $line = shift;
|
||||||
$line = trim($line);
|
$line = trim($line);
|
||||||
if( $line =~ /Lun:(\d+)\s+([A-Za-z0-9\-\_\.\:]*)\s+\(Size:([0-9\.]*)(k|M|G|T)\)/ ) {
|
if( $line =~ /Lun:(\d+)\s+([A-Za-z0-9\-\_\.\:]*)\s+\(Size:([0-9\.]*)(k|M|G|T)\)/ ) {
|
||||||
my $image = "lun".$1;
|
my $image = "lun".$1;
|
||||||
my $size = $3;
|
my $size = $3;
|
||||||
my $unit = $4;
|
my $unit = $4;
|
||||||
|
|
||||||
$list->{$storeid}->{$image} = {
|
$list->{$image} = {
|
||||||
name => $image,
|
name => $image,
|
||||||
size => $size * $unittobytes{$unit},
|
size => $size * $unittobytes{$unit},
|
||||||
format => 'raw',
|
format => 'raw',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
my $err = $@;
|
my $err = $@;
|
||||||
die $err if $err && $err !~ m/TESTUNITREADY failed with SENSE KEY/ ;
|
die $err if $err && $err !~ m/TESTUNITREADY failed with SENSE KEY/;
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
@ -130,43 +128,34 @@ sub free_image {
|
|||||||
die "can't free space in iscsi storage\n";
|
die "can't free space in iscsi storage\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub list_images {
|
sub list_images {
|
||||||
my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
|
my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
|
||||||
|
|
||||||
my $res = [];
|
my $res = [];
|
||||||
|
|
||||||
$cache->{directiscsi} = iscsi_ls($scfg,$storeid) if !$cache->{directiscsi};
|
|
||||||
|
|
||||||
# we have no owner for iscsi devices
|
# we have no owner for iscsi devices
|
||||||
|
|
||||||
my $target = $scfg->{target};
|
my $dat = iscsi_ls($scfg);
|
||||||
|
foreach my $volname (keys %$dat) {
|
||||||
|
my $volid = "$storeid:$volname";
|
||||||
|
|
||||||
if (my $dat = $cache->{directiscsi}->{$storeid}) {
|
if ($vollist) {
|
||||||
|
my $found = grep { $_ eq $volid } @$vollist;
|
||||||
|
next if !$found;
|
||||||
|
} else {
|
||||||
|
# we have no owner for iscsi devices
|
||||||
|
next if defined($vmid);
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $volname (keys %$dat) {
|
my $info = $dat->{$volname};
|
||||||
|
$info->{volid} = $volid;
|
||||||
|
|
||||||
my $volid = "$storeid:$volname";
|
push @$res, $info;
|
||||||
|
|
||||||
if ($vollist) {
|
|
||||||
my $found = grep { $_ eq $volid } @$vollist;
|
|
||||||
next if !$found;
|
|
||||||
} else {
|
|
||||||
# we have no owner for iscsi devices
|
|
||||||
next if defined($vmid);
|
|
||||||
}
|
|
||||||
|
|
||||||
my $info = $dat->{$volname};
|
|
||||||
$info->{volid} = $volid;
|
|
||||||
|
|
||||||
push @$res, $info;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub status {
|
sub status {
|
||||||
my ($class, $storeid, $scfg, $cache) = @_;
|
my ($class, $storeid, $scfg, $cache) = @_;
|
||||||
|
|
||||||
@ -208,8 +197,8 @@ sub deactivate_volume {
|
|||||||
sub volume_size_info {
|
sub volume_size_info {
|
||||||
my ($class, $scfg, $storeid, $volname, $timeout) = @_;
|
my ($class, $scfg, $storeid, $volname, $timeout) = @_;
|
||||||
|
|
||||||
my $vollist = iscsi_ls($scfg,$storeid);
|
my $vollist = iscsi_ls($scfg);
|
||||||
my $info = $vollist->{$storeid}->{$volname};
|
my $info = $vollist->{$volname};
|
||||||
|
|
||||||
return wantarray ? ($info->{size}, 'raw', 0, undef) : $info->{size};
|
return wantarray ? ($info->{size}, 'raw', 0, undef) : $info->{size};
|
||||||
}
|
}
|
||||||
@ -236,7 +225,7 @@ sub volume_snapshot_delete {
|
|||||||
|
|
||||||
sub volume_has_feature {
|
sub volume_has_feature {
|
||||||
my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
|
my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
|
||||||
|
|
||||||
my $features = {
|
my $features = {
|
||||||
copy => { current => 1},
|
copy => { current => 1},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user