]> git.proxmox.com Git - pve-storage.git/blame_incremental - PVE/Storage/ISCSIDirectPlugin.pm
remove running from Storage and check it in QemuServer
[pve-storage.git] / PVE / Storage / ISCSIDirectPlugin.pm
... / ...
CommitLineData
1package PVE::Storage::ISCSIDirectPlugin;
2
3use strict;
4use warnings;
5use IO::File;
6use HTTP::Request;
7use LWP::UserAgent;
8use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach);
9use PVE::Storage::Plugin;
10use PVE::JSONSchema qw(get_standard_option);
11
12use base qw(PVE::Storage::Plugin);
13
14sub iscsi_ls {
15 my ($scfg, $storeid) = @_;
16
17 my $portal = $scfg->{portal};
18 my $cmd = ['/usr/bin/iscsi-ls', '-s', 'iscsi://'.$portal ];
19 my $list = {};
20 my %unittobytes = (
21 "k" => 1024,
22 "M" => 1024*1024,
23 "G" => 1024*1024*1024,
24 "T" => 1024*1024*1024*1024
25 );
26 eval {
27
28 run_command($cmd, errmsg => "iscsi error", errfunc => sub {}, outfunc => sub {
29 my $line = shift;
30 $line = trim($line);
31 if( $line =~ /Lun:(\d+)\s+([A-Za-z0-9\-\_\.\:]*)\s+\(Size:([0-9\.]*)(k|M|G|T)\)/ ) {
32 my $image = "lun".$1;
33 my $size = $3;
34 my $unit = $4;
35
36 $list->{$storeid}->{$image} = {
37 name => $image,
38 size => $size * $unittobytes{$unit},
39 };
40 }
41 });
42 };
43
44 my $err = $@;
45 die $err if $err && $err !~ m/TESTUNITREADY failed with SENSE KEY/ ;
46
47 return $list;
48
49}
50
51# Configuration
52
53sub type {
54 return 'iscsidirect';
55}
56
57sub plugindata {
58 return {
59 content => [ {images => 1, none => 1}, { images => 1 }],
60 };
61}
62
63sub options {
64 return {
65 portal => { fixed => 1 },
66 target => { fixed => 1 },
67 nodes => { optional => 1},
68 disable => { optional => 1},
69 content => { optional => 1},
70 };
71}
72
73# Storage implementation
74
75sub parse_volname {
76 my ($class, $volname) = @_;
77
78
79 if ($volname =~ m/^lun(\d+)$/) {
80 return ('images', $1, undef);
81 }
82
83 die "unable to parse iscsi volume name '$volname'\n";
84
85}
86
87sub path {
88 my ($class, $scfg, $volname) = @_;
89
90 my ($vtype, $lun, $vmid) = $class->parse_volname($volname);
91
92 my $target = $scfg->{target};
93 my $portal = $scfg->{portal};
94
95 my $path = "iscsi://$portal/$target/$lun";
96
97 return ($path, $vmid, $vtype);
98}
99
100sub create_base {
101 my ($class, $storeid, $scfg, $volname) = @_;
102
103 die "can't create base images in iscsi storage\n";
104}
105
106sub clone_image {
107 my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
108
109 die "can't clone images in iscsi storage\n";
110}
111
112sub alloc_image {
113 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
114
115 die "can't allocate space in iscsi storage\n";
116}
117
118sub free_image {
119 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
120
121 die "can't free space in iscsi storage\n";
122}
123
124
125sub list_images {
126 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
127
128 my $res = [];
129
130 $cache->{directiscsi} = iscsi_ls($scfg,$storeid) if !$cache->{directiscsi};
131
132 # we have no owner for iscsi devices
133
134 my $target = $scfg->{target};
135
136 if (my $dat = $cache->{directiscsi}->{$storeid}) {
137
138 foreach my $volname (keys %$dat) {
139
140 my $volid = "$storeid:$volname";
141
142 if ($vollist) {
143 my $found = grep { $_ eq $volid } @$vollist;
144 next if !$found;
145 } else {
146 # we have no owner for iscsi devices
147 next if defined($vmid);
148 }
149
150 my $info = $dat->{$volname};
151 $info->{volid} = $volid;
152
153 push @$res, $info;
154 }
155 }
156
157 return $res;
158}
159
160
161sub status {
162 my ($class, $storeid, $scfg, $cache) = @_;
163
164 my $total = 0;
165 my $free = 0;
166 my $used = 0;
167 my $active = 1;
168 return ($total,$free,$used,$active);
169
170 return undef;
171}
172
173sub activate_storage {
174 my ($class, $storeid, $scfg, $cache) = @_;
175 return 1;
176}
177
178sub deactivate_storage {
179 my ($class, $storeid, $scfg, $cache) = @_;
180 return 1;
181}
182
183sub activate_volume {
184 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
185 return 1;
186}
187
188sub deactivate_volume {
189 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
190 return 1;
191}
192
193sub volume_size_info {
194 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
195
196 my $vollist = iscsi_ls($scfg,$storeid);
197 my $info = $vollist->{$storeid}->{$volname};
198
199 return $info->{size};
200}
201
202sub volume_resize {
203 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
204 die "volume resize is not possible on iscsi device";
205}
206
207sub volume_snapshot {
208 my ($class, $scfg, $storeid, $volname, $snap) = @_;
209 die "volume snapshot is not possible on iscsi device";
210}
211
212sub volume_snapshot_rollback {
213 my ($class, $scfg, $storeid, $volname, $snap) = @_;
214 die "volume snapshot rollback is not possible on iscsi device";
215}
216
217sub volume_snapshot_delete {
218 my ($class, $scfg, $storeid, $volname, $snap) = @_;
219 die "volume snapshot delete is not possible on iscsi device";
220}
221
222sub volume_has_feature {
223 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
224
225 my $features = {
226 copy => { current => 1},
227 };
228
229 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
230 $class->parse_volname($volname);
231
232 my $key = undef;
233 if($snapname){
234 $key = 'snap';
235 }else{
236 $key = $isBase ? 'base' : 'current';
237 }
238 return 1 if $features->{$feature}->{$key};
239
240 return undef;
241}
242
2431;