From 949aa31053721ec04e7570862e80f269e980ac2c Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 23 Nov 2015 23:04:57 +0000 Subject: [PATCH] scstadmin: Improve copy manager support further Also restore pass-through LUNs git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6712 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-0.9.10/lib/SCST/SCST.pm | 6 ++- .../scst-0.9.10/t/01-start-scst.t | 2 + scstadmin/scstadmin.sysfs/scstadmin | 43 ++++++++++++++----- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm index 3e5ab798b..2eb5055e2 100644 --- a/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm @@ -3930,7 +3930,11 @@ sub handlerAttributes { } } - next if ($attribute eq SCST_MGMT_IO); + if ($attribute eq SCST_MGMT_IO) { + $attributes{$attribute}->{'static'} = TRUE; + $attributes{$attribute}->{'value'} = $value; + next; + } if (!(($mode & S_IRUSR) >> 6)) { $attributes{$attribute}->{'static'} = FALSE; diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/t/01-start-scst.t b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/01-start-scst.t index b30abe46a..703756e0f 100644 --- a/scstadmin/scstadmin.sysfs/scst-0.9.10/t/01-start-scst.t +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/t/01-start-scst.t @@ -9,6 +9,8 @@ BEGIN { if ($> == 0) { ok(system("killall iscsi-scstd >/dev/null 2>&1; " . + "modprobe -r scst_cdrom; " . + "modprobe -r scst_disk; " . "modprobe -r scst_local; " . "modprobe -r isert-scst; " . "modprobe -r iscsi-scst; " . diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 39c478e4b..81fec91cc 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -1334,6 +1334,25 @@ sub serializeNkAttr { return $result; } +# Return TRUE if and only if $1 is an SCST pass-through device. +sub isPassthroughDev { + my $dev = shift; + my $pt = FALSE; + + foreach my $handler (keys %{$CURRENT{'handler'}}) { + my ($ha, $errorString) = $SCST->handlerAttributes($handler); + next if ($ha->{'mgmt'} !~ 'echo "add_device H:C:I:L"'); + my @devs = @{$CURRENT{'handler'}->{$handler}}; + for my $i (0 .. $#devs) { + if ($dev eq @devs[$i]) { + $pt = TRUE; + last; + } + } + last if $pt; + } +} + # Returns 0 upon success and 1 upon error. sub writeConfiguration { my $nonkey = shift; @@ -1462,11 +1481,14 @@ sub writeConfiguration { my $t_lun_buff; foreach my $lun (sort numerically keys %{$luns}) { - # Do not save copy_manager LUN definitions. - next if ($driver eq 'copy_manager'); - my $lun_dev = $$luns{$lun}; + # Do not save copy_manager LUN definitions + # for LUNs associated with an SCST device + # handler. + next if ($driver eq 'copy_manager' && + isPassthroughDev($lun_dev)); + $t_lun_buff .= "\t\tLUN $lun $lun_dev"; my ($attributes, $errorString) = $SCST->lunAttributes($driver, $target, $lun); @@ -1895,7 +1917,7 @@ sub checkConfiguration { } } - if (!defined($$tgt{'LUN'}->{'0'})) { + if ($driver ne 'copy_manager' && !defined($$tgt{'LUN'}->{'0'})) { print "\t-> WARNING: No LUN 0 defined for driver/target '$driver/$target'. ". "Many initiators require a LUN 0 to be defined.\n\n"; $warnings++; @@ -2107,7 +2129,7 @@ sub applyConfigAssignments { if ($deletions) { removeLun($driver, $target, $lun); $changes++; - } else { + } elsif ($driver ne 'copy_manager') { print "\t-> Device '$device' at LUN '$lun' is not in configuration ". "for driver/target '$driver/$target'. ". "Use -force to remove it.\n"; @@ -2617,11 +2639,6 @@ sub applyLunAssignments { my $c_luns; my $changes = 0; - # Do not restore copy_manager LUN definitions. - if ($driver eq 'copy_manager') { - return 0; - } - if (defined($group)) { $c_luns = $CURRENT{'assign'}->{$driver}->{$target}->{'GROUP'}->{$group}->{'LUN'}; } else { @@ -4888,6 +4905,12 @@ sub addLun { my $attributes = shift; my $group = shift; + # Do not complain about existing copy manager LUNs. + if ($driver eq 'copy_manager' && + $SCST->lunExists($driver, $target, $lun, $group)) { + return FALSE; + } + if (defined($group)) { print "\t-> Adding device '$device' at LUN $lun to driver/target/group ". "'$driver/$target/$group': ";