]> git.proxmox.com Git - pve-storage.git/blame - PVE/Storage/ISCSIDirectPlugin.pm
nexenta: volume_size_info
[pve-storage.git] / PVE / Storage / ISCSIDirectPlugin.pm
CommitLineData
b345cad3
AD
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
2677f623
DM
14sub iscsi_ls {
15 my ($scfg, $storeid) = @_;
b345cad3
AD
16
17 my $portal = $scfg->{portal};
18 my $cmd = ['/usr/bin/iscsi-ls', '-s', 'iscsi://'.$portal ];
19 my $list = {};
20 my $test = "";
2677f623 21
b345cad3
AD
22 my $errfunc = sub {
23 my $line = shift;
24 $line = trim($line);
25
26 die $line if $line;
27 };
28
29 eval {
30
2677f623 31 run_command($cmd, errmsg => "iscsi error", errfunc => $errfunc, outfunc => sub {
b345cad3
AD
32 my $line = shift;
33 $line = trim($line);
34 if( $line =~ /Lun:(\d+)\s+([A-Za-z0-9\-\_\.\:]*)\s+\(Size:(\d+)G\)/ ) {
35 $test = $1;
2677f623 36
b345cad3
AD
37 my $image = $1;
38 my $size = $3;
2677f623 39
b345cad3
AD
40 $list->{$storeid}->{$image} = {
41 name => $image,
42 size => $size,
43 };
44 }
45 });
46 };
47
48 my $err = $@;
49 die $err if $err && $err !~ m/TESTUNITREADY failed with SENSE KEY/ ;
50 return $list;
b345cad3
AD
51}
52
53# Configuration
54
55sub type {
56 return 'iscsidirect';
57}
58
59sub plugindata {
60 return {
61 content => [ {images => 1, none => 1}, { images => 1 }],
62 };
63}
64
65sub options {
66 return {
67 portal => { fixed => 1 },
68 target => { fixed => 1 },
69 nodes => { optional => 1},
70 disable => { optional => 1},
71 content => { optional => 1},
72 };
73}
74
b345cad3
AD
75# Storage implementation
76
77sub parse_volname {
78 my ($class, $volname) = @_;
79
2677f623 80
b345cad3
AD
81 if ($volname =~ m/^(\d+)$/) {
82 return ('images', $1, undef);
83 }
84
85 die "unable to parse iscsi volume name '$volname'\n";
86
87}
88
89sub path {
90 my ($class, $scfg, $volname) = @_;
91
92 my ($vtype, $lun, $vmid) = $class->parse_volname($volname);
93
94 my $target = $scfg->{target};
95 my $portal = $scfg->{portal};
96
97 my $path = "iscsi://$portal/$target/$lun";
98
99 return ($path, $vmid, $vtype);
100}
101
102
103sub alloc_image {
104 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
105
106 die "can't allocate space in iscsi storage\n";
107}
108
109sub free_image {
110 my ($class, $storeid, $scfg, $volname) = @_;
111
112 die "can't free space in iscsi storage\n";
113}
114
115
116sub list_images {
117 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
118
119 my $res = [];
120
121 $cache->{directiscsi} = iscsi_ls($scfg,$storeid) if !$cache->{directiscsi};
122
123 # we have no owner for iscsi devices
124
125 my $target = $scfg->{target};
126
127 if (my $dat = $cache->{directiscsi}->{$storeid}) {
128
129 foreach my $volname (keys %$dat) {
130
131 my $volid = "$storeid:$volname";
132
133 if ($vollist) {
134 my $found = grep { $_ eq $volid } @$vollist;
135 next if !$found;
136 } else {
137 # we have no owner for iscsi devices
138 next if defined($vmid);
139 }
140
141 my $info = $dat->{$volname};
142 $info->{volid} = $volid;
143
144 push @$res, $info;
145 }
146 }
147
148 return $res;
149}
150
151
152sub status {
153 my ($class, $storeid, $scfg, $cache) = @_;
154
155 my $total = 0;
156 my $free = 0;
157 my $used = 0;
158 my $active = 1;
159 return ($total,$free,$used,$active);
160
161 return undef;
162}
163
164sub activate_storage {
165 my ($class, $storeid, $scfg, $cache) = @_;
166 return 1;
167}
168
169sub deactivate_storage {
170 my ($class, $storeid, $scfg, $cache) = @_;
171 return 1;
172}
173
174sub activate_volume {
175 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
176 return 1;
177}
178
179sub deactivate_volume {
180 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
181 return 1;
182}
183
baf69659
AD
184sub volume_size_info {
185 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
186
187 return undef;
188}
189
b345cad3 1901;