]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/ISCSIDirectPlugin.pm
1 package PVE
::Storage
::ISCSIDirectPlugin
;
8 use PVE
::Tools
qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach);
9 use PVE
::Storage
::Plugin
;
10 use PVE
::JSONSchema
qw(get_standard_option);
12 use base
qw(PVE::Storage::Plugin);
15 my ($scfg, $storeid) = @_;
17 my $portal = $scfg->{portal
};
18 my $cmd = ['/usr/bin/iscsi-ls', '-s', 'iscsi://'.$portal ];
23 "G" => 1024*1024*1024,
24 "T" => 1024*1024*1024*1024
28 run_command
($cmd, errmsg
=> "iscsi error", errfunc
=> sub {}, outfunc
=> sub {
31 if( $line =~ /Lun:(\d+)\s+([A-Za-z0-9\-\_\.\:]*)\s+\(Size:([0-9\.]*)(k|M|G|T)\)/ ) {
36 $list->{$storeid}->{$image} = {
38 size
=> $size * $unittobytes{$unit},
45 die $err if $err && $err !~ m/TESTUNITREADY failed with SENSE KEY/ ;
59 content
=> [ {images
=> 1, none
=> 1}, { images
=> 1 }],
65 portal
=> { fixed
=> 1 },
66 target
=> { fixed
=> 1 },
67 nodes
=> { optional
=> 1},
68 disable
=> { optional
=> 1},
69 content
=> { optional
=> 1},
73 # Storage implementation
76 my ($class, $volname) = @_;
79 if ($volname =~ m/^lun(\d+)$/) {
80 return ('images', $1, undef);
83 die "unable to parse iscsi volume name '$volname'\n";
88 my ($class, $scfg, $volname) = @_;
90 my ($vtype, $lun, $vmid) = $class->parse_volname($volname);
92 my $target = $scfg->{target
};
93 my $portal = $scfg->{portal
};
95 my $path = "iscsi://$portal/$target/$lun";
97 return ($path, $vmid, $vtype);
102 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
104 die "can't allocate space in iscsi storage\n";
108 my ($class, $storeid, $scfg, $volname) = @_;
110 die "can't free space in iscsi storage\n";
115 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
119 $cache->{directiscsi
} = iscsi_ls
($scfg,$storeid) if !$cache->{directiscsi
};
121 # we have no owner for iscsi devices
123 my $target = $scfg->{target
};
125 if (my $dat = $cache->{directiscsi
}->{$storeid}) {
127 foreach my $volname (keys %$dat) {
129 my $volid = "$storeid:$volname";
132 my $found = grep { $_ eq $volid } @$vollist;
135 # we have no owner for iscsi devices
136 next if defined($vmid);
139 my $info = $dat->{$volname};
140 $info->{volid
} = $volid;
151 my ($class, $storeid, $scfg, $cache) = @_;
157 return ($total,$free,$used,$active);
162 sub activate_storage
{
163 my ($class, $storeid, $scfg, $cache) = @_;
167 sub deactivate_storage
{
168 my ($class, $storeid, $scfg, $cache) = @_;
172 sub activate_volume
{
173 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
177 sub deactivate_volume
{
178 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
182 sub volume_size_info
{
183 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
185 my $vollist = iscsi_ls
($scfg,$storeid);
186 my $info = $vollist->{$storeid}->{$volname};
188 return $info->{size
};
192 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
193 die "volume resize is not possible on iscsi device";