auto-format code using perltidy with Proxmox style guide
using the new top-level `make tidy` target, which calls perltidy via our wrapper to enforce the desired style as closely as possible. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
@ -17,12 +17,12 @@ my $get_lun_cmd_map = sub {
|
||||
my $sbdadmcmd = "/usr/sbin/sbdadm";
|
||||
|
||||
my $cmdmap = {
|
||||
create_lu => { cmd => $stmfadmcmd, method => 'create-lu' },
|
||||
delete_lu => { cmd => $stmfadmcmd, method => 'delete-lu' },
|
||||
import_lu => { cmd => $stmfadmcmd, method => 'import-lu' },
|
||||
modify_lu => { cmd => $stmfadmcmd, method => 'modify-lu' },
|
||||
add_view => { cmd => $stmfadmcmd, method => 'add-view' },
|
||||
list_view => { cmd => $stmfadmcmd, method => 'list-view' },
|
||||
create_lu => { cmd => $stmfadmcmd, method => 'create-lu' },
|
||||
delete_lu => { cmd => $stmfadmcmd, method => 'delete-lu' },
|
||||
import_lu => { cmd => $stmfadmcmd, method => 'import-lu' },
|
||||
modify_lu => { cmd => $stmfadmcmd, method => 'modify-lu' },
|
||||
add_view => { cmd => $stmfadmcmd, method => 'add-view' },
|
||||
list_view => { cmd => $stmfadmcmd, method => 'list-view' },
|
||||
list_lu => { cmd => $sbdadmcmd, method => 'list-lu' },
|
||||
};
|
||||
|
||||
@ -45,15 +45,15 @@ sub run_lun_command {
|
||||
$timeout = 10 if !$timeout;
|
||||
|
||||
my $output = sub {
|
||||
my $line = shift;
|
||||
$msg .= "$line\n";
|
||||
my $line = shift;
|
||||
$msg .= "$line\n";
|
||||
};
|
||||
|
||||
if ($method eq 'create_lu') {
|
||||
my $wcd = 'false';
|
||||
my $wcd = 'false';
|
||||
if ($scfg->{nowritecache}) {
|
||||
$wcd = 'true';
|
||||
}
|
||||
$wcd = 'true';
|
||||
}
|
||||
my $prefix = '600144f';
|
||||
my $digest = md5_hex($params[0]);
|
||||
$digest =~ /(\w{7}(.*))/;
|
||||
@ -68,13 +68,13 @@ sub run_lun_command {
|
||||
@params = undef;
|
||||
} elsif ($method eq 'add_view') {
|
||||
if ($scfg->{comstar_tg}) {
|
||||
unshift @params, $scfg->{comstar_tg};
|
||||
unshift @params, '--target-group';
|
||||
}
|
||||
unshift @params, $scfg->{comstar_tg};
|
||||
unshift @params, '--target-group';
|
||||
}
|
||||
if ($scfg->{comstar_hg}) {
|
||||
unshift @params, $scfg->{comstar_hg};
|
||||
unshift @params, '--host-group';
|
||||
}
|
||||
unshift @params, $scfg->{comstar_hg};
|
||||
unshift @params, '--host-group';
|
||||
}
|
||||
}
|
||||
|
||||
my $cmdmap = $get_lun_cmd_map->($method);
|
||||
@ -83,7 +83,15 @@ sub run_lun_command {
|
||||
|
||||
$target = 'root@' . $scfg->{portal};
|
||||
|
||||
my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $lunmethod, @params];
|
||||
my $cmd = [
|
||||
@ssh_cmd,
|
||||
'-i',
|
||||
"$id_rsa_path/$scfg->{portal}_id_rsa",
|
||||
$target,
|
||||
$luncmd,
|
||||
$lunmethod,
|
||||
@params,
|
||||
];
|
||||
|
||||
run_command($cmd, outfunc => $output, timeout => $timeout);
|
||||
|
||||
|
||||
@ -48,36 +48,42 @@ my $execute_command = sub {
|
||||
$timeout = 10 if !$timeout;
|
||||
|
||||
my $output = sub {
|
||||
my $line = shift;
|
||||
$msg .= "$line\n";
|
||||
my $line = shift;
|
||||
$msg .= "$line\n";
|
||||
};
|
||||
|
||||
my $errfunc = sub {
|
||||
my $line = shift;
|
||||
$err .= "$line";
|
||||
my $line = shift;
|
||||
$err .= "$line";
|
||||
};
|
||||
|
||||
if ($exec eq 'scp') {
|
||||
$target = 'root@[' . $scfg->{portal} . ']';
|
||||
$cmd = [@scp_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", '--', $method, "$target:$params[0]"];
|
||||
$cmd = [
|
||||
@scp_cmd,
|
||||
'-i',
|
||||
"$id_rsa_path/$scfg->{portal}_id_rsa",
|
||||
'--',
|
||||
$method,
|
||||
"$target:$params[0]",
|
||||
];
|
||||
} else {
|
||||
$target = 'root@' . $scfg->{portal};
|
||||
$cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, '--', $method, @params];
|
||||
$cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, '--', $method,
|
||||
@params];
|
||||
}
|
||||
|
||||
eval {
|
||||
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
||||
};
|
||||
eval { run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout); };
|
||||
if ($@) {
|
||||
$res = {
|
||||
result => 0,
|
||||
msg => $err,
|
||||
}
|
||||
};
|
||||
} else {
|
||||
$res = {
|
||||
result => 1,
|
||||
msg => $msg,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return $res;
|
||||
@ -104,10 +110,9 @@ my $read_config = sub {
|
||||
|
||||
$target = 'root@' . $scfg->{portal};
|
||||
|
||||
my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $CONFIG_FILE];
|
||||
eval {
|
||||
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
||||
};
|
||||
my $cmd =
|
||||
[@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $CONFIG_FILE];
|
||||
eval { run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout); };
|
||||
if ($@) {
|
||||
die $err if ($err !~ /No such file or directory/);
|
||||
die "No configuration found. Install iet on $scfg->{portal}" if $msg eq '';
|
||||
@ -141,7 +146,7 @@ my $parser = sub {
|
||||
foreach (@cfgfile) {
|
||||
$line++;
|
||||
if ($_ =~ /^\s*Target\s*([\w\-\:\.]+)\s*$/) {
|
||||
if ($1 eq $scfg->{target} && ! $cfg_target) {
|
||||
if ($1 eq $scfg->{target} && !$cfg_target) {
|
||||
# start colect info
|
||||
die "$line: Parse error [$_]" if $SETTINGS;
|
||||
$SETTINGS->{target} = $1;
|
||||
@ -157,7 +162,7 @@ my $parser = sub {
|
||||
} else {
|
||||
if ($cfg_target) {
|
||||
$SETTINGS->{text} .= "$_\n";
|
||||
next if ($_ =~ /^\s*#/ || ! $_);
|
||||
next if ($_ =~ /^\s*#/ || !$_);
|
||||
my $option = $_;
|
||||
if ($_ =~ /^(\w+)\s*#/) {
|
||||
$option = $1;
|
||||
@ -176,7 +181,7 @@ my $parser = sub {
|
||||
foreach (@lun) {
|
||||
my @lun_opt = split '=', $_;
|
||||
die "$line: Parse error [$option]" unless (scalar(@lun_opt) == 2);
|
||||
$conf->{$lun_opt[0]} = $lun_opt[1];
|
||||
$conf->{ $lun_opt[0] } = $lun_opt[1];
|
||||
}
|
||||
if ($conf->{Path} && $conf->{Path} =~ /^$base\/$scfg->{pool}\/([\w\-]+)$/) {
|
||||
$conf->{include} = 1;
|
||||
@ -184,7 +189,7 @@ my $parser = sub {
|
||||
$conf->{include} = 0;
|
||||
}
|
||||
$conf->{lun} = $num;
|
||||
push @{$SETTINGS->{luns}}, $conf;
|
||||
push @{ $SETTINGS->{luns} }, $conf;
|
||||
} else {
|
||||
die "$line: Parse error [$option]";
|
||||
}
|
||||
@ -202,19 +207,24 @@ my $update_config = sub {
|
||||
my $config = '';
|
||||
|
||||
while ((my $option, my $value) = each(%$SETTINGS)) {
|
||||
next if ($option eq 'include' || $option eq 'luns' || $option eq 'Path' || $option eq 'text' || $option eq 'used');
|
||||
next
|
||||
if ($option eq 'include'
|
||||
|| $option eq 'luns'
|
||||
|| $option eq 'Path'
|
||||
|| $option eq 'text'
|
||||
|| $option eq 'used');
|
||||
if ($option eq 'target') {
|
||||
$config = "\n\nTarget " . $SETTINGS->{target} . "\n" . $config;
|
||||
} else {
|
||||
$config .= "\t$option\t\t\t$value\n";
|
||||
}
|
||||
}
|
||||
foreach my $lun (@{$SETTINGS->{luns}}) {
|
||||
foreach my $lun (@{ $SETTINGS->{luns} }) {
|
||||
my $lun_opt = '';
|
||||
while ((my $option, my $value) = each(%$lun)) {
|
||||
next if ($option eq 'include' || $option eq 'lun' || $option eq 'Path');
|
||||
if ($lun_opt eq '') {
|
||||
$lun_opt = $option . '=' . $value;
|
||||
$lun_opt = $option . '=' . $value;
|
||||
} else {
|
||||
$lun_opt .= ',' . $option . '=' . $value;
|
||||
}
|
||||
@ -260,12 +270,12 @@ my $get_lu_name = sub {
|
||||
my $used = ();
|
||||
my $i;
|
||||
|
||||
if (! exists $SETTINGS->{used}) {
|
||||
if (!exists $SETTINGS->{used}) {
|
||||
for ($i = 0; $i < $MAX_LUNS; $i++) {
|
||||
$used->{$i} = 0;
|
||||
}
|
||||
foreach my $lun (@{$SETTINGS->{luns}}) {
|
||||
$used->{$lun->{lun}} = 1;
|
||||
foreach my $lun (@{ $SETTINGS->{luns} }) {
|
||||
$used->{ $lun->{lun} } = 1;
|
||||
}
|
||||
$SETTINGS->{used} = $used;
|
||||
}
|
||||
@ -282,14 +292,14 @@ my $get_lu_name = sub {
|
||||
my $init_lu_name = sub {
|
||||
my $used = ();
|
||||
|
||||
if (! exists($SETTINGS->{used})) {
|
||||
if (!exists($SETTINGS->{used})) {
|
||||
for (my $i = 0; $i < $MAX_LUNS; $i++) {
|
||||
$used->{$i} = 0;
|
||||
}
|
||||
$SETTINGS->{used} = $used;
|
||||
}
|
||||
foreach my $lun (@{$SETTINGS->{luns}}) {
|
||||
$SETTINGS->{used}->{$lun->{lun}} = 1;
|
||||
foreach my $lun (@{ $SETTINGS->{luns} }) {
|
||||
$SETTINGS->{used}->{ $lun->{lun} } = 1;
|
||||
}
|
||||
};
|
||||
|
||||
@ -297,7 +307,7 @@ my $free_lu_name = sub {
|
||||
my ($lu_name) = @_;
|
||||
my $new;
|
||||
|
||||
foreach my $lun (@{$SETTINGS->{luns}}) {
|
||||
foreach my $lun (@{ $SETTINGS->{luns} }) {
|
||||
if ($lun->{lun} != $lu_name) {
|
||||
push @$new, $lun;
|
||||
}
|
||||
@ -310,7 +320,8 @@ my $free_lu_name = sub {
|
||||
my $make_lun = sub {
|
||||
my ($scfg, $path) = @_;
|
||||
|
||||
die 'Maximum number of LUNs per target is 16384' if scalar @{$SETTINGS->{luns}} >= $MAX_LUNS;
|
||||
die 'Maximum number of LUNs per target is 16384'
|
||||
if scalar @{ $SETTINGS->{luns} } >= $MAX_LUNS;
|
||||
|
||||
my $lun = $get_lu_name->();
|
||||
my $conf = {
|
||||
@ -319,7 +330,7 @@ my $make_lun = sub {
|
||||
Type => 'blockio',
|
||||
include => 1,
|
||||
};
|
||||
push @{$SETTINGS->{luns}}, $conf;
|
||||
push @{ $SETTINGS->{luns} }, $conf;
|
||||
|
||||
return $conf;
|
||||
};
|
||||
@ -329,7 +340,7 @@ my $list_view = sub {
|
||||
my $lun = undef;
|
||||
|
||||
my $object = $params[0];
|
||||
foreach my $lun (@{$SETTINGS->{luns}}) {
|
||||
foreach my $lun (@{ $SETTINGS->{luns} }) {
|
||||
next unless $lun->{include} == 1;
|
||||
if ($lun->{Path} =~ /^$object$/) {
|
||||
return $lun->{lun} if (defined($lun->{lun}));
|
||||
@ -345,7 +356,7 @@ my $list_lun = sub {
|
||||
my $name = undef;
|
||||
|
||||
my $object = $params[0];
|
||||
foreach my $lun (@{$SETTINGS->{luns}}) {
|
||||
foreach my $lun (@{ $SETTINGS->{luns} }) {
|
||||
next unless $lun->{include} == 1;
|
||||
if ($lun->{Path} =~ /^$object$/) {
|
||||
return $lun->{Path};
|
||||
@ -381,12 +392,12 @@ my $create_lun = sub {
|
||||
|
||||
my $delete_lun = sub {
|
||||
my ($scfg, $timeout, $method, @params) = @_;
|
||||
my $res = {msg => undef};
|
||||
my $res = { msg => undef };
|
||||
|
||||
my $path = $params[0];
|
||||
my $tid = $get_target_tid->($scfg);
|
||||
|
||||
foreach my $lun (@{$SETTINGS->{luns}}) {
|
||||
foreach my $lun (@{ $SETTINGS->{luns} }) {
|
||||
if ($lun->{Path} eq $path) {
|
||||
@params = ('--op', 'delete', "--tid=$tid", "--lun=$lun->{lun}");
|
||||
$res = $execute_command->($scfg, 'ssh', $timeout, $ietadm, @params);
|
||||
@ -417,7 +428,7 @@ my $modify_lun = sub {
|
||||
my $path = $params[1];
|
||||
my $tid = $get_target_tid->($scfg);
|
||||
|
||||
foreach my $cfg (@{$SETTINGS->{luns}}) {
|
||||
foreach my $cfg (@{ $SETTINGS->{luns} }) {
|
||||
if ($cfg->{Path} eq $path) {
|
||||
$lun = $cfg;
|
||||
last;
|
||||
@ -446,13 +457,13 @@ my $get_lun_cmd_map = sub {
|
||||
my ($method) = @_;
|
||||
|
||||
my $cmdmap = {
|
||||
create_lu => { cmd => $create_lun },
|
||||
delete_lu => { cmd => $delete_lun },
|
||||
import_lu => { cmd => $import_lun },
|
||||
modify_lu => { cmd => $modify_lun },
|
||||
add_view => { cmd => $add_view },
|
||||
list_view => { cmd => $list_view },
|
||||
list_lu => { cmd => $list_lun },
|
||||
create_lu => { cmd => $create_lun },
|
||||
delete_lu => { cmd => $delete_lun },
|
||||
import_lu => { cmd => $import_lun },
|
||||
modify_lu => { cmd => $modify_lun },
|
||||
add_view => { cmd => $add_view },
|
||||
list_view => { cmd => $list_view },
|
||||
list_lu => { cmd => $list_lun },
|
||||
};
|
||||
|
||||
die "unknown command '$method'" unless exists $cmdmap->{$method};
|
||||
|
||||
@ -10,12 +10,12 @@ use warnings;
|
||||
use PVE::Tools qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach);
|
||||
|
||||
my @CONFIG_FILES = (
|
||||
'/usr/local/etc/istgt/istgt.conf', # FreeBSD, FreeNAS
|
||||
'/var/etc/iscsi/istgt.conf' # NAS4Free
|
||||
'/usr/local/etc/istgt/istgt.conf', # FreeBSD, FreeNAS
|
||||
'/var/etc/iscsi/istgt.conf' # NAS4Free
|
||||
);
|
||||
my @DAEMONS = (
|
||||
'/usr/local/etc/rc.d/istgt', # FreeBSD, FreeNAS
|
||||
'/var/etc/rc.d/istgt' # NAS4Free
|
||||
'/usr/local/etc/rc.d/istgt', # FreeBSD, FreeNAS
|
||||
'/var/etc/rc.d/istgt' # NAS4Free
|
||||
);
|
||||
|
||||
# A logical unit can max have 63 LUNs
|
||||
@ -69,13 +69,13 @@ my $read_config = sub {
|
||||
$timeout = 10 if !$timeout;
|
||||
|
||||
my $output = sub {
|
||||
my $line = shift;
|
||||
$msg .= "$line\n";
|
||||
my $line = shift;
|
||||
$msg .= "$line\n";
|
||||
};
|
||||
|
||||
my $errfunc = sub {
|
||||
my $line = shift;
|
||||
$err .= "$line";
|
||||
my $line = shift;
|
||||
$err .= "$line";
|
||||
};
|
||||
|
||||
$target = 'root@' . $scfg->{portal};
|
||||
@ -83,7 +83,8 @@ my $read_config = sub {
|
||||
my $daemon = 0;
|
||||
foreach my $config (@CONFIG_FILES) {
|
||||
$err = undef;
|
||||
my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $config];
|
||||
my $cmd =
|
||||
[@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $config];
|
||||
eval {
|
||||
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
||||
};
|
||||
@ -119,17 +120,17 @@ my $parse_size = sub {
|
||||
return 0 if !$text;
|
||||
|
||||
if ($text =~ m/^(\d+(\.\d+)?)([TGMK]B)?$/) {
|
||||
my ($size, $reminder, $unit) = ($1, $2, $3);
|
||||
return $size if !$unit;
|
||||
if ($unit eq 'KB') {
|
||||
$size *= 1024;
|
||||
} elsif ($unit eq 'MB') {
|
||||
$size *= 1024*1024;
|
||||
} elsif ($unit eq 'GB') {
|
||||
$size *= 1024*1024*1024;
|
||||
} elsif ($unit eq 'TB') {
|
||||
$size *= 1024*1024*1024*1024;
|
||||
}
|
||||
my ($size, $reminder, $unit) = ($1, $2, $3);
|
||||
return $size if !$unit;
|
||||
if ($unit eq 'KB') {
|
||||
$size *= 1024;
|
||||
} elsif ($unit eq 'MB') {
|
||||
$size *= 1024 * 1024;
|
||||
} elsif ($unit eq 'GB') {
|
||||
$size *= 1024 * 1024 * 1024;
|
||||
} elsif ($unit eq 'TB') {
|
||||
$size *= 1024 * 1024 * 1024 * 1024;
|
||||
}
|
||||
if ($reminder) {
|
||||
$size = ceil($size);
|
||||
}
|
||||
@ -151,9 +152,9 @@ my $size_with_unit = sub {
|
||||
if ($size =~ m/^\d+$/) {
|
||||
++$n and $size /= 1024 until $size < 1024;
|
||||
if ($size =~ /\./) {
|
||||
return sprintf "%.2f%s", $size, ( qw[bytes KB MB GB TB] )[ $n ];
|
||||
return sprintf "%.2f%s", $size, (qw[bytes KB MB GB TB])[$n];
|
||||
} else {
|
||||
return sprintf "%d%s", $size, ( qw[bytes KB MB GB TB] )[ $n ];
|
||||
return sprintf "%d%s", $size, (qw[bytes KB MB GB TB])[$n];
|
||||
}
|
||||
}
|
||||
die "$size: Not a number";
|
||||
@ -164,18 +165,18 @@ my $lun_dumper = sub {
|
||||
my $config = '';
|
||||
|
||||
$config .= "\n[$lun]\n";
|
||||
$config .= 'TargetName ' . $SETTINGS->{$lun}->{TargetName} . "\n";
|
||||
$config .= 'Mapping ' . $SETTINGS->{$lun}->{Mapping} . "\n";
|
||||
$config .= 'AuthGroup ' . $SETTINGS->{$lun}->{AuthGroup} . "\n";
|
||||
$config .= 'UnitType ' . $SETTINGS->{$lun}->{UnitType} . "\n";
|
||||
$config .= 'QueueDepth ' . $SETTINGS->{$lun}->{QueueDepth} . "\n";
|
||||
$config .= 'TargetName ' . $SETTINGS->{$lun}->{TargetName} . "\n";
|
||||
$config .= 'Mapping ' . $SETTINGS->{$lun}->{Mapping} . "\n";
|
||||
$config .= 'AuthGroup ' . $SETTINGS->{$lun}->{AuthGroup} . "\n";
|
||||
$config .= 'UnitType ' . $SETTINGS->{$lun}->{UnitType} . "\n";
|
||||
$config .= 'QueueDepth ' . $SETTINGS->{$lun}->{QueueDepth} . "\n";
|
||||
|
||||
foreach my $conf (@{$SETTINGS->{$lun}->{luns}}) {
|
||||
$config .= "$conf->{lun} Storage " . $conf->{Storage};
|
||||
foreach my $conf (@{ $SETTINGS->{$lun}->{luns} }) {
|
||||
$config .= "$conf->{lun} Storage " . $conf->{Storage};
|
||||
$config .= ' ' . $size_with_unit->($conf->{Size}) . "\n";
|
||||
foreach ($conf->{options}) {
|
||||
if ($_) {
|
||||
$config .= "$conf->{lun} Option " . $_ . "\n";
|
||||
$config .= "$conf->{lun} Option " . $_ . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -189,11 +190,11 @@ my $get_lu_name = sub {
|
||||
my $used = ();
|
||||
my $i;
|
||||
|
||||
if (! exists $SETTINGS->{$target}->{used}) {
|
||||
if (!exists $SETTINGS->{$target}->{used}) {
|
||||
for ($i = 0; $i < $MAX_LUNS; $i++) {
|
||||
$used->{$i} = 0;
|
||||
}
|
||||
foreach my $lun (@{$SETTINGS->{$target}->{luns}}) {
|
||||
foreach my $lun (@{ $SETTINGS->{$target}->{luns} }) {
|
||||
$lun->{lun} =~ /^LUN(\d+)$/;
|
||||
$used->{$1} = 1;
|
||||
}
|
||||
@ -213,13 +214,13 @@ my $init_lu_name = sub {
|
||||
my ($target) = @_;
|
||||
my $used = ();
|
||||
|
||||
if (! exists($SETTINGS->{$target}->{used})) {
|
||||
if (!exists($SETTINGS->{$target}->{used})) {
|
||||
for (my $i = 0; $i < $MAX_LUNS; $i++) {
|
||||
$used->{$i} = 0;
|
||||
}
|
||||
$SETTINGS->{$target}->{used} = $used;
|
||||
}
|
||||
foreach my $lun (@{$SETTINGS->{$target}->{luns}}) {
|
||||
foreach my $lun (@{ $SETTINGS->{$target}->{luns} }) {
|
||||
$lun->{lun} =~ /^LUN(\d+)$/;
|
||||
$SETTINGS->{$target}->{used}->{$1} = 1;
|
||||
}
|
||||
@ -236,7 +237,8 @@ my $make_lun = sub {
|
||||
my ($scfg, $path) = @_;
|
||||
|
||||
my $target = $SETTINGS->{current};
|
||||
die 'Maximum number of LUNs per target is 63' if scalar @{$SETTINGS->{$target}->{luns}} >= $MAX_LUNS;
|
||||
die 'Maximum number of LUNs per target is 63'
|
||||
if scalar @{ $SETTINGS->{$target}->{luns} } >= $MAX_LUNS;
|
||||
|
||||
my @options = ();
|
||||
my $lun = $get_lu_name->($target);
|
||||
@ -249,7 +251,7 @@ my $make_lun = sub {
|
||||
Size => 'AUTO',
|
||||
options => @options,
|
||||
};
|
||||
push @{$SETTINGS->{$target}->{luns}}, $conf;
|
||||
push @{ $SETTINGS->{$target}->{luns} }, $conf;
|
||||
|
||||
return $conf->{lun};
|
||||
};
|
||||
@ -290,7 +292,7 @@ my $parser = sub {
|
||||
if ($arg2 =~ /^Storage\s*(.+)/i) {
|
||||
$SETTINGS->{$lun}->{$arg1}->{storage} = $1;
|
||||
} elsif ($arg2 =~ /^Option\s*(.+)/i) {
|
||||
push @{$SETTINGS->{$lun}->{$arg1}->{options}}, $1;
|
||||
push @{ $SETTINGS->{$lun}->{$arg1}->{options} }, $1;
|
||||
} else {
|
||||
$SETTINGS->{$lun}->{$arg1} = $arg2;
|
||||
}
|
||||
@ -307,10 +309,10 @@ my $parser = sub {
|
||||
my $base = get_base;
|
||||
|
||||
for (my $i = 1; $i <= $max; $i++) {
|
||||
my $target = $SETTINGS->{nodebase}.':'.$SETTINGS->{"LogicalUnit$i"}->{TargetName};
|
||||
my $target = $SETTINGS->{nodebase} . ':' . $SETTINGS->{"LogicalUnit$i"}->{TargetName};
|
||||
if ($target eq $scfg->{target}) {
|
||||
my $lu = ();
|
||||
while ((my $key, my $val) = each(%{$SETTINGS->{"LogicalUnit$i"}})) {
|
||||
while ((my $key, my $val) = each(%{ $SETTINGS->{"LogicalUnit$i"} })) {
|
||||
if ($key =~ /^LUN\d+/) {
|
||||
$val->{storage} =~ /^([\w\/\-]+)\s+(\w+)/;
|
||||
my $storage = $1;
|
||||
@ -318,7 +320,7 @@ my $parser = sub {
|
||||
my $conf = undef;
|
||||
my @options = ();
|
||||
if ($val->{options}) {
|
||||
@options = @{$val->{options}};
|
||||
@options = @{ $val->{options} };
|
||||
}
|
||||
if ($storage =~ /^$base\/$scfg->{pool}\/([\w\-]+)$/) {
|
||||
$conf = {
|
||||
@ -326,7 +328,7 @@ my $parser = sub {
|
||||
Storage => $storage,
|
||||
Size => $size,
|
||||
options => @options,
|
||||
}
|
||||
};
|
||||
}
|
||||
push @$lu, $conf if $conf;
|
||||
delete $SETTINGS->{"LogicalUnit$i"}->{$key};
|
||||
@ -349,9 +351,9 @@ my $list_lun = sub {
|
||||
my $name = undef;
|
||||
|
||||
my $object = $params[0];
|
||||
for my $key (keys %$SETTINGS) {
|
||||
for my $key (keys %$SETTINGS) {
|
||||
next unless $key =~ /^LogicalUnit\d+$/;
|
||||
foreach my $lun (@{$SETTINGS->{$key}->{luns}}) {
|
||||
foreach my $lun (@{ $SETTINGS->{$key}->{luns} }) {
|
||||
if ($lun->{Storage} =~ /^$object$/) {
|
||||
return $lun->{Storage};
|
||||
}
|
||||
@ -399,7 +401,7 @@ my $delete_lun = sub {
|
||||
my $target = $SETTINGS->{current};
|
||||
my $luns = ();
|
||||
|
||||
foreach my $conf (@{$SETTINGS->{$target}->{luns}}) {
|
||||
foreach my $conf (@{ $SETTINGS->{$target}->{luns} }) {
|
||||
if ($conf->{Storage} =~ /^$params[0]$/) {
|
||||
$free_lu_name->($target, $conf->{lun});
|
||||
} else {
|
||||
@ -448,7 +450,7 @@ my $add_view = sub {
|
||||
params => \@params,
|
||||
};
|
||||
} else {
|
||||
@params = ('-HUP', '`cat '. "$SETTINGS->{pidfile}`");
|
||||
@params = ('-HUP', '`cat ' . "$SETTINGS->{pidfile}`");
|
||||
$cmdmap = {
|
||||
cmd => 'ssh',
|
||||
method => 'kill',
|
||||
@ -477,9 +479,9 @@ my $list_view = sub {
|
||||
my $lun = undef;
|
||||
|
||||
my $object = $params[0];
|
||||
for my $key (keys %$SETTINGS) {
|
||||
for my $key (keys %$SETTINGS) {
|
||||
next unless $key =~ /^LogicalUnit\d+$/;
|
||||
foreach my $lun (@{$SETTINGS->{$key}->{luns}}) {
|
||||
foreach my $lun (@{ $SETTINGS->{$key}->{luns} }) {
|
||||
if ($lun->{Storage} =~ /^$object$/) {
|
||||
if ($lun->{lun} =~ /^LUN(\d+)/) {
|
||||
return $1;
|
||||
@ -496,13 +498,13 @@ my $get_lun_cmd_map = sub {
|
||||
my ($method) = @_;
|
||||
|
||||
my $cmdmap = {
|
||||
create_lu => { cmd => $create_lun },
|
||||
delete_lu => { cmd => $delete_lun },
|
||||
import_lu => { cmd => $import_lun },
|
||||
modify_lu => { cmd => $modify_lun },
|
||||
add_view => { cmd => $add_view },
|
||||
list_view => { cmd => $list_view },
|
||||
list_lu => { cmd => $list_lun },
|
||||
create_lu => { cmd => $create_lun },
|
||||
delete_lu => { cmd => $delete_lun },
|
||||
import_lu => { cmd => $import_lun },
|
||||
modify_lu => { cmd => $modify_lun },
|
||||
add_view => { cmd => $add_view },
|
||||
list_view => { cmd => $list_view },
|
||||
list_lu => { cmd => $list_lun },
|
||||
};
|
||||
|
||||
die "unknown command '$method'" unless exists $cmdmap->{$method};
|
||||
@ -522,8 +524,8 @@ sub run_lun_command {
|
||||
my $is_add_view = 0;
|
||||
|
||||
my $output = sub {
|
||||
my $line = shift;
|
||||
$msg .= "$line\n";
|
||||
my $line = shift;
|
||||
$msg .= "$line\n";
|
||||
};
|
||||
|
||||
$target = 'root@' . $scfg->{portal};
|
||||
@ -531,18 +533,31 @@ sub run_lun_command {
|
||||
$parser->($scfg) unless $SETTINGS;
|
||||
my $cmdmap = $get_lun_cmd_map->($method);
|
||||
if ($method eq 'add_view') {
|
||||
$is_add_view = 1 ;
|
||||
$is_add_view = 1;
|
||||
$timeout = 15;
|
||||
}
|
||||
if (ref $cmdmap->{cmd} eq 'CODE') {
|
||||
$res = $cmdmap->{cmd}->($scfg, $timeout, $method, @params);
|
||||
if (ref $res) {
|
||||
$method = $res->{method};
|
||||
@params = @{$res->{params}};
|
||||
@params = @{ $res->{params} };
|
||||
if ($res->{cmd} eq 'scp') {
|
||||
$cmd = [@scp_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $method, "$target:$params[0]"];
|
||||
$cmd = [
|
||||
@scp_cmd,
|
||||
'-i',
|
||||
"$id_rsa_path/$scfg->{portal}_id_rsa",
|
||||
$method,
|
||||
"$target:$params[0]",
|
||||
];
|
||||
} else {
|
||||
$cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $method, @params];
|
||||
$cmd = [
|
||||
@ssh_cmd,
|
||||
'-i',
|
||||
"$id_rsa_path/$scfg->{portal}_id_rsa",
|
||||
$target,
|
||||
$method,
|
||||
@params,
|
||||
];
|
||||
}
|
||||
} else {
|
||||
return $res;
|
||||
@ -550,12 +565,18 @@ sub run_lun_command {
|
||||
} else {
|
||||
$luncmd = $cmdmap->{cmd};
|
||||
$method = $cmdmap->{method};
|
||||
$cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $method, @params];
|
||||
$cmd = [
|
||||
@ssh_cmd,
|
||||
'-i',
|
||||
"$id_rsa_path/$scfg->{portal}_id_rsa",
|
||||
$target,
|
||||
$luncmd,
|
||||
$method,
|
||||
@params,
|
||||
];
|
||||
}
|
||||
|
||||
eval {
|
||||
run_command($cmd, outfunc => $output, timeout => $timeout);
|
||||
};
|
||||
eval { run_command($cmd, outfunc => $output, timeout => $timeout); };
|
||||
if ($@ && $is_add_view) {
|
||||
my $err = $@;
|
||||
if ($OLD_CONFIG) {
|
||||
@ -565,15 +586,11 @@ sub run_lun_command {
|
||||
print $fh $OLD_CONFIG;
|
||||
close $fh;
|
||||
$cmd = [@scp_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $file, $CONFIG_FILE];
|
||||
eval {
|
||||
run_command($cmd, outfunc => $output, timeout => $timeout);
|
||||
};
|
||||
eval { run_command($cmd, outfunc => $output, timeout => $timeout); };
|
||||
$err1 = $@ if $@;
|
||||
unlink $file;
|
||||
die "$err\n$err1" if $err1;
|
||||
eval {
|
||||
run_lun_command($scfg, undef, 'add_view', 'restart');
|
||||
};
|
||||
eval { run_lun_command($scfg, undef, 'add_view', 'restart'); };
|
||||
die "$err\n$@" if ($@);
|
||||
}
|
||||
die $err;
|
||||
|
||||
@ -29,8 +29,8 @@ sub get_base;
|
||||
# targetcli constants
|
||||
# config file location differs from distro to distro
|
||||
my @CONFIG_FILES = (
|
||||
'/etc/rtslib-fb-target/saveconfig.json', # Debian 9.x et al
|
||||
'/etc/target/saveconfig.json' , # ArchLinux, CentOS
|
||||
'/etc/rtslib-fb-target/saveconfig.json', # Debian 9.x et al
|
||||
'/etc/target/saveconfig.json', # ArchLinux, CentOS
|
||||
);
|
||||
my $BACKSTORE = '/backstores/block';
|
||||
|
||||
@ -58,21 +58,27 @@ my $execute_remote_command = sub {
|
||||
my $errfunc = sub { $err .= "$_[0]\n" };
|
||||
|
||||
$target = 'root@' . $scfg->{portal};
|
||||
$cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, '--', $remote_command, @params];
|
||||
$cmd = [
|
||||
@ssh_cmd,
|
||||
'-i',
|
||||
"$id_rsa_path/$scfg->{portal}_id_rsa",
|
||||
$target,
|
||||
'--',
|
||||
$remote_command,
|
||||
@params,
|
||||
];
|
||||
|
||||
eval {
|
||||
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
||||
};
|
||||
eval { run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout); };
|
||||
if ($@) {
|
||||
$res = {
|
||||
result => 0,
|
||||
msg => $err,
|
||||
}
|
||||
$res = {
|
||||
result => 0,
|
||||
msg => $err,
|
||||
};
|
||||
} else {
|
||||
$res = {
|
||||
result => 1,
|
||||
msg => $msg,
|
||||
}
|
||||
$res = {
|
||||
result => 1,
|
||||
msg => $msg,
|
||||
};
|
||||
}
|
||||
|
||||
return $res;
|
||||
@ -96,14 +102,15 @@ my $read_config = sub {
|
||||
$target = 'root@' . $scfg->{portal};
|
||||
|
||||
foreach my $oneFile (@CONFIG_FILES) {
|
||||
my $cmd = [@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $oneFile];
|
||||
eval {
|
||||
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
||||
};
|
||||
if ($@) {
|
||||
die $err if ($err !~ /No such file or directory/);
|
||||
}
|
||||
return $msg if $msg ne '';
|
||||
my $cmd =
|
||||
[@ssh_cmd, '-i', "$id_rsa_path/$scfg->{portal}_id_rsa", $target, $luncmd, $oneFile];
|
||||
eval {
|
||||
run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout);
|
||||
};
|
||||
if ($@) {
|
||||
die $err if ($err !~ /No such file or directory/);
|
||||
}
|
||||
return $msg if $msg ne '';
|
||||
}
|
||||
|
||||
die "No configuration found. Install targetcli on $scfg->{portal}\n" if $msg eq '';
|
||||
@ -123,11 +130,11 @@ my $get_config = sub {
|
||||
|
||||
# Return settings of a specific target
|
||||
my $get_target_settings = sub {
|
||||
my ($scfg) = @_;
|
||||
my ($scfg) = @_;
|
||||
|
||||
my $id = "$scfg->{portal}.$scfg->{target}";
|
||||
return undef if !$SETTINGS;
|
||||
return $SETTINGS->{$id};
|
||||
my $id = "$scfg->{portal}.$scfg->{target}";
|
||||
return undef if !$SETTINGS;
|
||||
return $SETTINGS->{$id};
|
||||
};
|
||||
|
||||
# fetches and parses targetcli config from the portal
|
||||
@ -137,46 +144,47 @@ my $parser = sub {
|
||||
my $tpg_tag;
|
||||
|
||||
if ($tpg =~ /^tpg(\d+)$/) {
|
||||
$tpg_tag = $1;
|
||||
$tpg_tag = $1;
|
||||
} else {
|
||||
die "Target Portal Group has invalid value, must contain string 'tpg' and a suffix number, eg 'tpg17'\n";
|
||||
die
|
||||
"Target Portal Group has invalid value, must contain string 'tpg' and a suffix number, eg 'tpg17'\n";
|
||||
}
|
||||
|
||||
my $config = $get_config->($scfg);
|
||||
my $jsonconfig = JSON->new->utf8->decode($config);
|
||||
|
||||
my $haveTarget = 0;
|
||||
foreach my $target (@{$jsonconfig->{targets}}) {
|
||||
# only interested in iSCSI targets
|
||||
next if !($target->{fabric} eq 'iscsi' && $target->{wwn} eq $scfg->{target});
|
||||
# find correct TPG
|
||||
foreach my $tpg (@{$target->{tpgs}}) {
|
||||
if ($tpg->{tag} == $tpg_tag) {
|
||||
my $res = [];
|
||||
foreach my $lun (@{$tpg->{luns}}) {
|
||||
my ($idx, $storage_object);
|
||||
if ($lun->{index} =~ /^(\d+)$/) {
|
||||
$idx = $1;
|
||||
}
|
||||
if ($lun->{storage_object} =~ m|^($BACKSTORE/.*)$|) {
|
||||
$storage_object = $1;
|
||||
}
|
||||
die "Invalid lun definition in config!\n"
|
||||
if !(defined($idx) && defined($storage_object));
|
||||
push @$res, { index => $idx, storage_object => $storage_object };
|
||||
}
|
||||
foreach my $target (@{ $jsonconfig->{targets} }) {
|
||||
# only interested in iSCSI targets
|
||||
next if !($target->{fabric} eq 'iscsi' && $target->{wwn} eq $scfg->{target});
|
||||
# find correct TPG
|
||||
foreach my $tpg (@{ $target->{tpgs} }) {
|
||||
if ($tpg->{tag} == $tpg_tag) {
|
||||
my $res = [];
|
||||
foreach my $lun (@{ $tpg->{luns} }) {
|
||||
my ($idx, $storage_object);
|
||||
if ($lun->{index} =~ /^(\d+)$/) {
|
||||
$idx = $1;
|
||||
}
|
||||
if ($lun->{storage_object} =~ m|^($BACKSTORE/.*)$|) {
|
||||
$storage_object = $1;
|
||||
}
|
||||
die "Invalid lun definition in config!\n"
|
||||
if !(defined($idx) && defined($storage_object));
|
||||
push @$res, { index => $idx, storage_object => $storage_object };
|
||||
}
|
||||
|
||||
my $id = "$scfg->{portal}.$scfg->{target}";
|
||||
$SETTINGS->{$id}->{luns} = $res;
|
||||
$haveTarget = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
my $id = "$scfg->{portal}.$scfg->{target}";
|
||||
$SETTINGS->{$id}->{luns} = $res;
|
||||
$haveTarget = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# seriously unhappy if the target server lacks iSCSI target configuration ...
|
||||
if (!$haveTarget) {
|
||||
die "target portal group tpg$tpg_tag not found!\n";
|
||||
die "target portal group tpg$tpg_tag not found!\n";
|
||||
}
|
||||
};
|
||||
|
||||
@ -194,10 +202,10 @@ my $free_lu_name = sub {
|
||||
|
||||
my $new = [];
|
||||
my $target = $get_target_settings->($scfg);
|
||||
foreach my $lun (@{$target->{luns}}) {
|
||||
if ($lun->{storage_object} ne "$BACKSTORE/$lu_name") {
|
||||
push @$new, $lun;
|
||||
}
|
||||
foreach my $lun (@{ $target->{luns} }) {
|
||||
if ($lun->{storage_object} ne "$BACKSTORE/$lu_name") {
|
||||
push @$new, $lun;
|
||||
}
|
||||
}
|
||||
|
||||
$target->{luns} = $new;
|
||||
@ -208,12 +216,12 @@ my $register_lun = sub {
|
||||
my ($scfg, $idx, $volname) = @_;
|
||||
|
||||
my $conf = {
|
||||
index => $idx,
|
||||
storage_object => "$BACKSTORE/$volname",
|
||||
is_new => 1,
|
||||
index => $idx,
|
||||
storage_object => "$BACKSTORE/$volname",
|
||||
is_new => 1,
|
||||
};
|
||||
my $target = $get_target_settings->($scfg);
|
||||
push @{$target->{luns}}, $conf;
|
||||
push @{ $target->{luns} }, $conf;
|
||||
|
||||
return $conf;
|
||||
};
|
||||
@ -225,17 +233,17 @@ my $extract_volname = sub {
|
||||
|
||||
my $base = get_base;
|
||||
if ($lunpath =~ /^$base\/$scfg->{pool}\/([\w\-]+)$/) {
|
||||
$volname = $1;
|
||||
my $prefix = $get_backstore_prefix->($scfg);
|
||||
my $target = $get_target_settings->($scfg);
|
||||
foreach my $lun (@{$target->{luns}}) {
|
||||
# If we have a lun with the pool prefix matching this vol, then return this one
|
||||
# like pool-pve-vm-100-disk-0
|
||||
# Else, just fallback to the old name scheme which is vm-100-disk-0
|
||||
if ($lun->{storage_object} =~ /^$BACKSTORE\/($prefix$volname)$/) {
|
||||
return $1;
|
||||
}
|
||||
}
|
||||
$volname = $1;
|
||||
my $prefix = $get_backstore_prefix->($scfg);
|
||||
my $target = $get_target_settings->($scfg);
|
||||
foreach my $lun (@{ $target->{luns} }) {
|
||||
# If we have a lun with the pool prefix matching this vol, then return this one
|
||||
# like pool-pve-vm-100-disk-0
|
||||
# Else, just fallback to the old name scheme which is vm-100-disk-0
|
||||
if ($lun->{storage_object} =~ /^$BACKSTORE\/($prefix$volname)$/) {
|
||||
return $1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $volname;
|
||||
@ -252,10 +260,10 @@ my $list_view = sub {
|
||||
|
||||
return undef if !defined($volname); # nothing to search for..
|
||||
|
||||
foreach my $lun (@{$target->{luns}}) {
|
||||
if ($lun->{storage_object} eq "$BACKSTORE/$volname") {
|
||||
return $lun->{index};
|
||||
}
|
||||
foreach my $lun (@{ $target->{luns} }) {
|
||||
if ($lun->{storage_object} eq "$BACKSTORE/$volname") {
|
||||
return $lun->{index};
|
||||
}
|
||||
}
|
||||
|
||||
return $lun;
|
||||
@ -269,10 +277,10 @@ my $list_lun = sub {
|
||||
my $volname = $extract_volname->($scfg, $object);
|
||||
my $target = $get_target_settings->($scfg);
|
||||
|
||||
foreach my $lun (@{$target->{luns}}) {
|
||||
if ($lun->{storage_object} eq "$BACKSTORE/$volname") {
|
||||
return $object;
|
||||
}
|
||||
foreach my $lun (@{ $target->{luns} }) {
|
||||
if ($lun->{storage_object} eq "$BACKSTORE/$volname") {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
return undef;
|
||||
@ -283,7 +291,7 @@ my $create_lun = sub {
|
||||
my ($scfg, $timeout, $method, @params) = @_;
|
||||
|
||||
if ($list_lun->($scfg, $timeout, $method, @params)) {
|
||||
die "$params[0]: LUN already exists!";
|
||||
die "$params[0]: LUN already exists!";
|
||||
}
|
||||
|
||||
my $device = $params[0];
|
||||
@ -294,18 +302,18 @@ my $create_lun = sub {
|
||||
my $tpg = $scfg->{lio_tpg} || die "Target Portal Group not set, aborting!\n";
|
||||
|
||||
# step 1: create backstore for device
|
||||
my @cliparams = ($BACKSTORE, 'create', "name=$volname", "dev=$device" );
|
||||
my @cliparams = ($BACKSTORE, 'create', "name=$volname", "dev=$device");
|
||||
my $res = $execute_remote_command->($scfg, $timeout, $targetcli, @cliparams);
|
||||
die $res->{msg} if !$res->{result};
|
||||
|
||||
# step 2: enable unmap support on the backstore
|
||||
@cliparams = ($BACKSTORE . '/' . $volname, 'set', 'attribute', 'emulate_tpu=1' );
|
||||
@cliparams = ($BACKSTORE . '/' . $volname, 'set', 'attribute', 'emulate_tpu=1');
|
||||
$res = $execute_remote_command->($scfg, $timeout, $targetcli, @cliparams);
|
||||
die $res->{msg} if !$res->{result};
|
||||
|
||||
# step 3: register lun with target
|
||||
# targetcli /iscsi/iqn.2018-04.at.bestsolution.somehost:target/tpg1/luns/ create /backstores/block/foobar
|
||||
@cliparams = ("/iscsi/$scfg->{target}/$tpg/luns/", 'create', "$BACKSTORE/$volname" );
|
||||
@cliparams = ("/iscsi/$scfg->{target}/$tpg/luns/", 'create', "$BACKSTORE/$volname");
|
||||
$res = $execute_remote_command->($scfg, $timeout, $targetcli, @cliparams);
|
||||
die $res->{msg} if !$res->{result};
|
||||
|
||||
@ -314,9 +322,9 @@ my $create_lun = sub {
|
||||
# changed without our knowledge, so relying on the number that targetcli returns
|
||||
my $lun_idx;
|
||||
if ($res->{msg} =~ /LUN (\d+)/) {
|
||||
$lun_idx = $1;
|
||||
$lun_idx = $1;
|
||||
} else {
|
||||
die "unable to determine new LUN index: $res->{msg}";
|
||||
die "unable to determine new LUN index: $res->{msg}";
|
||||
}
|
||||
|
||||
$register_lun->($scfg, $lun_idx, $volname);
|
||||
@ -330,7 +338,7 @@ my $create_lun = sub {
|
||||
|
||||
my $delete_lun = sub {
|
||||
my ($scfg, $timeout, $method, @params) = @_;
|
||||
my $res = {msg => undef};
|
||||
my $res = { msg => undef };
|
||||
|
||||
my $tpg = $scfg->{lio_tpg} || die "Target Portal Group not set, aborting!\n";
|
||||
|
||||
@ -338,30 +346,30 @@ my $delete_lun = sub {
|
||||
my $volname = $extract_volname->($scfg, $path);
|
||||
my $target = $get_target_settings->($scfg);
|
||||
|
||||
foreach my $lun (@{$target->{luns}}) {
|
||||
next if $lun->{storage_object} ne "$BACKSTORE/$volname";
|
||||
foreach my $lun (@{ $target->{luns} }) {
|
||||
next if $lun->{storage_object} ne "$BACKSTORE/$volname";
|
||||
|
||||
# step 1: delete the lun
|
||||
my @cliparams = ("/iscsi/$scfg->{target}/$tpg/luns/", 'delete', "lun$lun->{index}" );
|
||||
my $res = $execute_remote_command->($scfg, $timeout, $targetcli, @cliparams);
|
||||
do {
|
||||
die $res->{msg};
|
||||
} unless $res->{result};
|
||||
# step 1: delete the lun
|
||||
my @cliparams = ("/iscsi/$scfg->{target}/$tpg/luns/", 'delete', "lun$lun->{index}");
|
||||
my $res = $execute_remote_command->($scfg, $timeout, $targetcli, @cliparams);
|
||||
do {
|
||||
die $res->{msg};
|
||||
} unless $res->{result};
|
||||
|
||||
# step 2: delete the backstore
|
||||
@cliparams = ($BACKSTORE, 'delete', $volname);
|
||||
$res = $execute_remote_command->($scfg, $timeout, $targetcli, @cliparams);
|
||||
do {
|
||||
die $res->{msg};
|
||||
} unless $res->{result};
|
||||
# step 2: delete the backstore
|
||||
@cliparams = ($BACKSTORE, 'delete', $volname);
|
||||
$res = $execute_remote_command->($scfg, $timeout, $targetcli, @cliparams);
|
||||
do {
|
||||
die $res->{msg};
|
||||
} unless $res->{result};
|
||||
|
||||
# step 3: save to be safe ...
|
||||
$execute_remote_command->($scfg, $timeout, $targetcli, 'saveconfig');
|
||||
# step 3: save to be safe ...
|
||||
$execute_remote_command->($scfg, $timeout, $targetcli, 'saveconfig');
|
||||
|
||||
# update internal cache
|
||||
$free_lu_name->($scfg, $volname);
|
||||
# update internal cache
|
||||
$free_lu_name->($scfg, $volname);
|
||||
|
||||
last;
|
||||
last;
|
||||
}
|
||||
|
||||
return $res->{msg};
|
||||
@ -387,13 +395,13 @@ my $add_view = sub {
|
||||
};
|
||||
|
||||
my %lun_cmd_map = (
|
||||
create_lu => $create_lun,
|
||||
delete_lu => $delete_lun,
|
||||
import_lu => $import_lun,
|
||||
modify_lu => $modify_lun,
|
||||
add_view => $add_view,
|
||||
list_view => $list_view,
|
||||
list_lu => $list_lun,
|
||||
create_lu => $create_lun,
|
||||
delete_lu => $delete_lun,
|
||||
import_lu => $import_lun,
|
||||
modify_lu => $modify_lun,
|
||||
add_view => $add_view,
|
||||
list_view => $list_view,
|
||||
list_lu => $list_lun,
|
||||
);
|
||||
|
||||
sub run_lun_command {
|
||||
@ -403,8 +411,8 @@ sub run_lun_command {
|
||||
my $timediff = time - $SETTINGS_TIMESTAMP;
|
||||
my $target = $get_target_settings->($scfg);
|
||||
if (!$target || $timediff > $SETTINGS_MAXAGE) {
|
||||
$SETTINGS_TIMESTAMP = time;
|
||||
$parser->($scfg);
|
||||
$SETTINGS_TIMESTAMP = time;
|
||||
$parser->($scfg);
|
||||
}
|
||||
|
||||
die "unknown command '$method'" unless exists $lun_cmd_map{$method};
|
||||
|
||||
Reference in New Issue
Block a user