]>
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},
46 die $err if $err && $err !~ m/TESTUNITREADY failed with SENSE KEY/ ;
60 content
=> [ {images
=> 1, none
=> 1}, { images
=> 1 }],
67 portal
=> { fixed
=> 1 },
68 target
=> { fixed
=> 1 },
69 nodes
=> { optional
=> 1},
70 disable
=> { optional
=> 1},
71 content
=> { optional
=> 1},
72 bwlimit
=> { optional
=> 1 },
76 # Storage implementation
79 my ($class, $volname) = @_;
82 if ($volname =~ m/^lun(\d+)$/) {
83 return ('images', $1, undef, undef, undef, undef, 'raw');
86 die "unable to parse iscsi volume name '$volname'\n";
91 my ($class, $scfg, $volname, $storeid, $snapname) = @_;
93 die "volume snapshot is not possible on iscsi device"
94 if defined($snapname);
96 my ($vtype, $lun, $vmid) = $class->parse_volname($volname);
98 my $target = $scfg->{target
};
99 my $portal = $scfg->{portal
};
101 my $path = "iscsi://$portal/$target/$lun";
103 return ($path, $vmid, $vtype);
107 my ($class, $storeid, $scfg, $volname) = @_;
109 die "can't create base images in iscsi storage\n";
113 my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
115 die "can't clone images in iscsi storage\n";
119 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
121 die "can't allocate space in iscsi storage\n";
125 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
127 die "can't free space in iscsi storage\n";
132 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
136 $cache->{directiscsi
} = iscsi_ls
($scfg,$storeid) if !$cache->{directiscsi
};
138 # we have no owner for iscsi devices
140 my $target = $scfg->{target
};
142 if (my $dat = $cache->{directiscsi
}->{$storeid}) {
144 foreach my $volname (keys %$dat) {
146 my $volid = "$storeid:$volname";
149 my $found = grep { $_ eq $volid } @$vollist;
152 # we have no owner for iscsi devices
153 next if defined($vmid);
156 my $info = $dat->{$volname};
157 $info->{volid
} = $volid;
168 my ($class, $storeid, $scfg, $cache) = @_;
174 return ($total,$free,$used,$active);
179 sub activate_storage
{
180 my ($class, $storeid, $scfg, $cache) = @_;
184 sub deactivate_storage
{
185 my ($class, $storeid, $scfg, $cache) = @_;
189 sub activate_volume
{
190 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
192 die "volume snapshot is not possible on iscsi device" if $snapname;
197 sub deactivate_volume
{
198 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
200 die "volume snapshot is not possible on iscsi device" if $snapname;
205 sub volume_size_info
{
206 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
208 my $vollist = iscsi_ls
($scfg,$storeid);
209 my $info = $vollist->{$storeid}->{$volname};
211 return $info->{size
};
215 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
216 die "volume resize is not possible on iscsi device";
219 sub volume_snapshot
{
220 my ($class, $scfg, $storeid, $volname, $snap) = @_;
221 die "volume snapshot is not possible on iscsi device";
224 sub volume_snapshot_rollback
{
225 my ($class, $scfg, $storeid, $volname, $snap) = @_;
226 die "volume snapshot rollback is not possible on iscsi device";
229 sub volume_snapshot_delete
{
230 my ($class, $scfg, $storeid, $volname, $snap) = @_;
231 die "volume snapshot delete is not possible on iscsi device";
234 sub volume_has_feature
{
235 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
238 copy
=> { current
=> 1},
241 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
242 $class->parse_volname($volname);
248 $key = $isBase ?
'base' : 'current';
250 return 1 if $features->{$feature}->{$key};