]> git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/ISCSIDirectPlugin.pm
cleanup white space errors
[pve-storage.git] / PVE / Storage / ISCSIDirectPlugin.pm
1 package PVE::Storage::ISCSIDirectPlugin;
2
3 use strict;
4 use warnings;
5 use IO::File;
6 use HTTP::Request;
7 use LWP::UserAgent;
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);
11
12 use base qw(PVE::Storage::Plugin);
13
14 sub 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 $test = "";
21
22 my $errfunc = sub {
23 my $line = shift;
24 $line = trim($line);
25
26 die $line if $line;
27 };
28
29 eval {
30
31 run_command($cmd, errmsg => "iscsi error", errfunc => $errfunc, outfunc => sub {
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;
36
37 my $image = $1;
38 my $size = $3;
39
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;
51 }
52
53 # Configuration
54
55 sub type {
56 return 'iscsidirect';
57 }
58
59 sub plugindata {
60 return {
61 content => [ {images => 1, none => 1}, { images => 1 }],
62 };
63 }
64
65 sub 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
75 # Storage implementation
76
77 sub parse_volname {
78 my ($class, $volname) = @_;
79
80
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
89 sub 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
103 sub alloc_image {
104 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
105
106 die "can't allocate space in iscsi storage\n";
107 }
108
109 sub free_image {
110 my ($class, $storeid, $scfg, $volname) = @_;
111
112 die "can't free space in iscsi storage\n";
113 }
114
115
116 sub 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
152 sub 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
164 sub activate_storage {
165 my ($class, $storeid, $scfg, $cache) = @_;
166 return 1;
167 }
168
169 sub deactivate_storage {
170 my ($class, $storeid, $scfg, $cache) = @_;
171 return 1;
172 }
173
174 sub activate_volume {
175 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
176 return 1;
177 }
178
179 sub deactivate_volume {
180 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
181 return 1;
182 }
183
184 1;