]> git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/LunCmd/Comstar.pm
Added "nowritecache" option to ZFS storage plugin. Turns off write caching on Comstar...
[pve-storage.git] / PVE / Storage / LunCmd / Comstar.pm
1 package PVE::Storage::LunCmd::Comstar;
2
3 use strict;
4 use warnings;
5 use Digest::MD5 qw(md5_hex);
6 use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach);
7 use Data::Dumper;
8
9 my @ssh_opts = ('-o', 'BatchMode=yes');
10 my @ssh_cmd = ('/usr/bin/ssh', @ssh_opts);
11 my $id_rsa_path = '/etc/pve/priv/zfs';
12
13 my $get_lun_cmd_map = sub {
14 my ($method) = @_;
15
16 my $stmfadmcmd = "/usr/sbin/stmfadm";
17 my $sbdadmcmd = "/usr/sbin/sbdadm";
18
19 my $cmdmap = {
20 create_lu => { cmd => $stmfadmcmd, method => 'create-lu' },
21 delete_lu => { cmd => $stmfadmcmd, method => 'delete-lu' },
22 import_lu => { cmd => $stmfadmcmd, method => 'import-lu' },
23 modify_lu => { cmd => $stmfadmcmd, method => 'modify-lu' },
24 add_view => { cmd => $stmfadmcmd, method => 'add-view' },
25 list_view => { cmd => $stmfadmcmd, method => 'list-view' },
26 list_lu => { cmd => $sbdadmcmd, method => 'list-lu' },
27 };
28
29 die "unknown command '$method'" unless exists $cmdmap->{$method};
30
31 return $cmdmap->{$method};
32 };
33
34 sub get_base {
35 return '/dev/zvol/rdsk';
36 }
37
38 sub run_lun_command {
39 my ($scfg, $timeout, $method, @params) = @_;
40
41 my $msg = '';
42 my $luncmd;
43 my $target;
44 my $guid;
45 $timeout = 10 if !$timeout;
46
47 my $output = sub {
48 my $line = shift;
49 $msg .= "$line\n";
50 };
51
52 if ($method eq 'create_lu') {
53 my $wcd = 'false';
54 if ($scfg->{nowritecache}) {
55 $wcd = 'true';
56 }
57 my $prefix = '600144f';
58 my $digest = md5_hex($params[0]);
59 $digest =~ /(\w{7}(.*))/;
60 $guid = "$prefix$2";
61 @params = ('-p', "wcd=$wcd", '-p', "guid=$guid", @params);
62 } elsif ($method eq 'modify_lu') {
63 @params = ('-s', @params);
64 } elsif ($method eq 'list_view') {
65 @params = ('-l', @params);
66 } elsif ($method eq 'list_lu') {
67 $guid = $params[0];
68 @params = undef;
69 }
70
71 my $cmdmap = $get_lun_cmd_map->($method);
72 $luncmd = $cmdmap->{cmd};
73 my $lunmethod = $cmdmap->{method};
74
75 $target = 'root@' . $scfg->{portal};
76
77 my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $lunmethod, @params];
78
79 run_command($cmd, outfunc => $output, timeout => $timeout);
80
81 if ($method eq 'list_view') {
82 my @lines = split /\n/, $msg;
83 $msg = undef;
84 foreach my $line (@lines) {
85 if ($line =~ /^\s*LUN\s*:\s*(\d+)$/) {
86 $msg = $1;
87 last;
88 }
89 }
90 } elsif ($method eq 'list_lu') {
91 my $object = $guid;
92 my @lines = split /\n/, $msg;
93 $msg = undef;
94 foreach my $line (@lines) {
95 if ($line =~ /(\w+)\s+\d+\s+$object$/) {
96 $msg = $1;
97 last;
98 }
99 }
100 } elsif ($method eq 'create_lu') {
101 $msg = $guid;
102 }
103
104 return $msg;
105 }
106