From e5d9a6869ef6345a344f97d3d83d029f70bfd278 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 16:50:16 +0000 Subject: [PATCH 01/42] scst_vdisk: Avoid that setting numa_node_id causes unloading scst_vdisk to hang This patch fixes a bug that was introduced by r7075 / bdb23b89 ("scst: performance improvements"). Reported-by: Marc Smith git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7927 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 56fd89639..228ae222b 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -7833,6 +7833,13 @@ static void vdev_check_node(struct scst_vdisk_dev **pvirt_dev, int orig_nodeid) } *v = *virt_dev; kfree(virt_dev); + /* + * Since the address of the virtual device changed, update all + * pointers in the virtual device that point to the virtual + * device itself. + */ + INIT_WORK(&virt_dev->vdev_inq_changed_work, + vdev_inq_changed_fn); *pvirt_dev = v; } From a645fe52945b8a0f7a0e6a2c244937bbc56a93a4 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 17:13:50 +0000 Subject: [PATCH 02/42] scstadmin: Enable Perl warnings in tests scripts git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7929 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scst-1.0.0/t/01-start-scst.t | 1 + scstadmin/scstadmin.sysfs/scst-1.0.0/t/02-scst-attr.t | 1 + scstadmin/scstadmin.sysfs/scst-1.0.0/t/03-targets.t | 1 + scstadmin/scstadmin.sysfs/scst-1.0.0/t/04-alua.t | 1 + scstadmin/scstadmin.sysfs/scst-1.0.0/t/05-dynattr.t | 1 + scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t | 1 + scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t | 1 + scstadmin/scstadmin.sysfs/scst-1.0.0/t/08-scstadmin-close-dev.t | 1 + scstadmin/scstadmin.sysfs/scst-1.0.0/t/99-stop-scst.t | 1 + 9 files changed, 9 insertions(+) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/01-start-scst.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/01-start-scst.t index 34bf666bb..661c968d9 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/01-start-scst.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/01-start-scst.t @@ -1,6 +1,7 @@ #!perl use strict; +use warnings; use Test; BEGIN { diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/02-scst-attr.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/02-scst-attr.t index 267423138..372c70e87 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/02-scst-attr.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/02-scst-attr.t @@ -1,6 +1,7 @@ #!perl use strict; +use warnings; use Test; BEGIN { diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/03-targets.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/03-targets.t index d07b11a34..26ca57fe6 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/03-targets.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/03-targets.t @@ -1,6 +1,7 @@ #!perl use strict; +use warnings; use Test; BEGIN { diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/04-alua.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/04-alua.t index 72db337a2..04843eb67 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/04-alua.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/04-alua.t @@ -1,6 +1,7 @@ #!perl use strict; +use warnings; use Test; BEGIN { diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/05-dynattr.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/05-dynattr.t index d31c739bf..c4cd84585 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/05-dynattr.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/05-dynattr.t @@ -1,6 +1,7 @@ #!perl use strict; +use warnings; use Test; BEGIN { diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t index 3bc6fd6b7..5d68de95c 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t @@ -1,6 +1,7 @@ #!perl use strict; +use warnings; use Cwd qw(abs_path); use File::Basename; use File::Spec; diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t index 2178c7344..8cc23759f 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t @@ -1,6 +1,7 @@ #!perl use strict; +use warnings; use Cwd qw(abs_path); use File::Basename; use File::Spec; diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/08-scstadmin-close-dev.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/08-scstadmin-close-dev.t index cac3a5e02..7755ec669 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/08-scstadmin-close-dev.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/08-scstadmin-close-dev.t @@ -1,6 +1,7 @@ #!perl use strict; +use warnings; use Cwd qw(abs_path); use File::Basename; use File::Spec; diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/99-stop-scst.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/99-stop-scst.t index c2cad55cf..b8fca3d32 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/99-stop-scst.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/99-stop-scst.t @@ -1,6 +1,7 @@ #!perl use strict; +use warnings; use Test; BEGIN { From b2119c2133e98811836e93be2f65bc3aa7899e96 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 17:15:45 +0000 Subject: [PATCH 03/42] scstadmin: Sort output of -list_* options alphabetically Making the output of these options predictable is necessary because a later patch will add regression tests for the -list_* options. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7930 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/lib/SCST/SCST.pm | 3 +++ scstadmin/scstadmin.sysfs/scstadmin | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm index e73570395..be4576410 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm @@ -556,6 +556,7 @@ sub drivers { push @drivers, $driver; } } + @drivers = sort(@drivers); close $dHandle; } else { return (undef, "drivers(): Unable to read directory '$_path': $!"); @@ -3834,6 +3835,8 @@ sub handlers { close $hHandle; + @handlers = sort(@handlers); + return (\@handlers, undef); } diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 078602551..51947df28 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -3062,7 +3062,7 @@ sub listHandler { }; print "\n"; - foreach my $handler (keys %toprint) { + foreach my $handler (sort keys %toprint) { my ($devices, $errorString) = $SCST->devicesByHandler($handler); my $first = TRUE; @@ -3070,7 +3070,7 @@ sub listHandler { push @{$devices}, '-'; } - foreach my $device (@{$devices}) { + foreach my $device (sort @{$devices}) { if ($first) { printf("\t%-*s %-*s\n", $l_handler, $handler, $l_device, $device); $first = FALSE; @@ -3343,7 +3343,7 @@ sub listTargets { my %p; - foreach my $driver (keys %toprint) { + foreach my $driver (sort keys %toprint) { my ($targets, $errorString) = $SCST->targets($driver); foreach my $target (@{$targets}) { @@ -3739,7 +3739,7 @@ sub listHandlerAttributes { print "\n\tDevice CREATE attributes available\n"; print "\t----------------------------------\n"; - foreach my $attribute (keys %{$attributes}) { + foreach my $attribute (sort keys %{$attributes}) { print "\t$attribute\n"; } @@ -3765,7 +3765,7 @@ sub listDriverAttributes { print "\n\tDynamic attributes available\n"; print "\t----------------------------\n"; - foreach my $attribute (keys %{$attributes}) { + foreach my $attribute (sort keys %{$attributes}) { print "\t$attribute\n"; } } @@ -3778,7 +3778,7 @@ sub listDriverAttributes { print "\n\tTarget CREATE attributes available:\n"; print "\t-----------------------------------\n"; - foreach my $attribute (keys %{$attributes}) { + foreach my $attribute (sort keys %{$attributes}) { print "\t$attribute\n"; } } @@ -3811,7 +3811,7 @@ sub listTargetAttributes { print "\n\tDynamic attributes available\n"; print "\t----------------------------\n"; - foreach my $attribute (keys %{$attributes}) { + foreach my $attribute (sort keys %{$attributes}) { print "\t$attribute\n"; } } @@ -3825,7 +3825,7 @@ sub listTargetAttributes { print "\n\tLUN CREATE attributes available\n"; print "\t-------------------------------\n"; - foreach my $attribute (keys %{$attributes}) { + foreach my $attribute (sort keys %{$attributes}) { print "\t$attribute\n"; } @@ -3858,7 +3858,7 @@ sub listGroupAttributes { print "\n\tLUN CREATE attributes available\n"; print "\t-------------------------------\n"; - foreach my $attribute (keys %{$attributes}) { + foreach my $attribute (sort keys %{$attributes}) { print "\t$attribute\n"; } From 52f9a2b285dd1fca6f5598b66b87a0d8dd4863c5 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 17:37:12 +0000 Subject: [PATCH 04/42] scstadmin: Improve test script robustness Check the return value of most system() calls. Use gawk instead of awk when using GNU extensions. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7931 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/t/06-cont-on-err.t | 14 ++++-- .../scst-1.0.0/t/07-scstadmin-args.t | 50 +++++++++++-------- .../scst-1.0.0/t/08-scstadmin-close-dev.t | 50 +++++++++++-------- 3 files changed, 67 insertions(+), 47 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t index 5d68de95c..713fb982c 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t @@ -20,7 +20,7 @@ BEGIN { unless(grep /blib/, @INC) { unshift(@INC, File::Spec->catdir($scstadmin_pm_dir, "lib")); } - plan tests => 2; + plan tests => 5; } use Data::Dumper; @@ -45,11 +45,17 @@ sub testRestoreConfig { my $diff = File::Spec->catfile(File::Spec->tmpdir(), "scstadmin-test-06-$$-diff"); - system("$scstadmin -clear_config -force -noprompt -no_lip >/dev/null"); + ok(system("$scstadmin -clear_config -force -noprompt -no_lip >/dev/null"), 0); system("$scstadmin -cont_on_err -no_lip -config $to_be_restored" . " >/dev/null"); - system("$scstadmin -write_config $tmpfilename1 >/dev/null"); - system("awk 'BEGIN {t = 0 } /^# Automatically generated by SCST Configurator v/ { \$0 = \"# Automatically generated by SCST Configurator v...\" } /^TARGET_DRIVER.*{\$/ { if (\$0 != \"TARGET_DRIVER scst_local {\") t = 1 } /^}\$/ { if (t == 1) t = 2 } /^\$/ { if (t == 2) { t = 3 } } /^./ { if (t == 3) { t = 0 } } { if (t == 0) print }' <$tmpfilename1 >$tmpfilename2"); + ok(system("$scstadmin -write_config $tmpfilename1 >/dev/null"), 0); + ok(system("awk 'BEGIN {t = 0 } /^# Automatically generated by SCST Configurator v/ " . + '{ $0 = "# Automatically generated by SCST Configurator v..." } ' . + '/^TARGET_DRIVER.*{$/ { if ($0 != "TARGET_DRIVER scst_local {") t = 1 } ' . + '/^}$/ { if (t == 1) t = 2 }' . + '/^$/ { if (t == 2) { t = 3 } }' . + '/^./ { if (t == 3) { t = 0 } }' . + "{ if (t == 0) print }' <$tmpfilename1 >$tmpfilename2"), 0); my $compare_result = system("diff -u $tmpfilename2 $expected >$diff"); ok($compare_result, 0); if ($compare_result == 0) { diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t index 8cc23759f..7d8d43235 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t @@ -22,7 +22,7 @@ BEGIN { unless(grep /blib/, @INC) { unshift(@INC, File::Spec->catdir($scstadmin_pm_dir, "lib")); } - plan tests => 2; + plan tests => 16; } use Data::Dumper; @@ -35,7 +35,7 @@ sub setup { my ($drivers, $errorString) = $SCST->drivers(); my %drivers = map { $_ => 1 } @{$drivers}; ok(exists($drivers{'scst_local'})); - system("dd if=/dev/zero of=/dev/scstadmin-regression-test-vdisk bs=1M count=1 >/dev/null 2>&1"); + ok(system("dd if=/dev/zero of=/dev/scstadmin-regression-test-vdisk bs=1M count=1 >/dev/null 2>&1"), 0); } sub teardown { @@ -51,26 +51,34 @@ sub attributeTest { my $diff = File::Spec->catfile(File::Spec->tmpdir(), "scstadmin-test-07-$$-diff"); - system("$scstadmin -clear_config -force -noprompt -no_lip $redirect"); - system("$scstadmin -open_dev nodev -handler vdisk_nullio -attributes dummy=1 $redirect"); - system("$scstadmin -open_dev disk0 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,read_only=1 $redirect"); - system("$scstadmin -open_dev disk1 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,nv_cache=1 $redirect"); - system("$scstadmin -driver scst_local -add_target local $redirect"); - system("$scstadmin -driver scst_local -target local " . - "-add_lun 0 -device nodev $redirect"); - system("$scstadmin -driver scst_local -target local -add_group ig " . - "$redirect"); - system("$scstadmin -driver scst_local -target local -group ig " . - "-add_init ini1 $redirect"); - system("$scstadmin -driver scst_local -target local -group ig " . - "-add_init ini2 $redirect"); - system("$scstadmin -driver scst_local -target local -group ig " . - "-add_lun 0 -device disk0 $redirect"); - system("$scstadmin -driver scst_local -target local -group ig " . - "-add_lun 1 -device disk1 $redirect"); - system("$scstadmin -write_config $tmpfilename1 >/dev/null"); + ok(system("$scstadmin -clear_config -force -noprompt -no_lip $redirect"), 0); + ok(system("$scstadmin -open_dev nodev -handler vdisk_nullio -attributes dummy=1 $redirect"), 0); + ok(system("$scstadmin -open_dev disk0 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,read_only=1 $redirect"), 0); + ok(system("$scstadmin -open_dev disk1 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,nv_cache=1 $redirect"), 0); + ok(system("$scstadmin -driver scst_local -add_target local $redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local " . + "-add_lun 0 -device nodev $redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local -add_group ig " . + "$redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local -group ig " . + "-add_init ini1 $redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local -group ig " . + "-add_init ini2 $redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local -group ig " . + "-add_lun 0 -device disk0 $redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local -group ig " . + "-add_lun 1 -device disk1 $redirect"), 0); + ok(system("$scstadmin -write_config $tmpfilename1 >/dev/null"), 0); # Keep only the scst_local target driver information. - system("awk 'BEGIN { t = 0 } /^# Automatically generated by SCST Configurator v/ { \$0 = \"# Automatically generated by SCST Configurator v...\" } /^TARGET_DRIVER.*{\$/ { if (match(\$0, \"TARGET_DRIVER ([^ ]*) {\", d) && d[1] != \"scst_local\") t = 1 } /^}\$/ { if (t == 1) t = 2 } /^\$/ { if (t == 2) { t = 3 } } /^./ { if (t == 3) { t = 0 } } { if (t == 0) print }' <$tmpfilename1 >$tmpfilename2"); + my $cmd = "gawk 'BEGIN { t = 0 } /^# Automatically generated by SCST Configurator v/ {" . + '$0 = "# Automatically generated by SCST Configurator v..." } ' . + '/^TARGET_DRIVER.*{$/ { if (match($0, "TARGET_DRIVER ([^ ]*) {", d) && d[1] != "scst_local") t = 1 } ' . + '/^}$/ { if (t == 1) t = 2 } ' . + '/^$/ { if (t == 2) { t = 3 } } ' . + '/^./ { if (t == 3) { t = 0 } } ' . + '{ if (t == 0) print }' . + "' <$tmpfilename1 >$tmpfilename2"; + ok(system($cmd), 0); my $compare_result = system("diff -u $tmpfilename2 $expected >$diff"); ok($compare_result, 0); if ($compare_result == 0) { diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/08-scstadmin-close-dev.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/08-scstadmin-close-dev.t index 7755ec669..45f97bb08 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/08-scstadmin-close-dev.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/08-scstadmin-close-dev.t @@ -22,7 +22,7 @@ BEGIN { unless(grep /blib/, @INC) { unshift(@INC, File::Spec->catdir($scstadmin_pm_dir, "lib")); } - plan tests => 9; + plan tests => 24; } use Data::Dumper; @@ -35,7 +35,7 @@ sub setup { my ($drivers, $errorString) = $SCST->drivers(); my %drivers = map { $_ => 1 } @{$drivers}; ok(exists($drivers{'scst_local'})); - system("dd if=/dev/zero of=/dev/scstadmin-regression-test-vdisk bs=1M count=1 >/dev/null 2>&1"); + ok(system("dd if=/dev/zero of=/dev/scstadmin-regression-test-vdisk bs=1M count=1 >/dev/null 2>&1"), 0); } sub teardown { @@ -46,7 +46,13 @@ sub filterScstLocal { my $in = shift; my $out = shift; - system("awk 'BEGIN { t = 0 } /^# Automatically generated by SCST Configurator v/ { \$0 = \"# Automatically generated by SCST Configurator v...\" } /^TARGET_DRIVER.*{\$/ { if (match(\$0, \"TARGET_DRIVER ([^ ]*) {\", d) && d[1] != \"scst_local\") t = 1 } /^}\$/ { if (t == 1) t = 2 } /^\$/ { if (t == 2) { t = 3 } } /^./ { if (t == 3) { t = 0 } } { if (t == 0) print }' <" . '"' . "$in" . '" >"' . "$out" . '"'); + ok(system("awk 'BEGIN { t = 0 } /^# Automatically generated by SCST Configurator v/ " . + '{ $0 = "# Automatically generated by SCST Configurator v..." } ' . + '/^TARGET_DRIVER.*{$/ { if (match($0, "TARGET_DRIVER ([^ ]*) {", d) && d[1] != "scst_local") t = 1 } ' . + '/^}$/ { if (t == 1) t = 2 }' . + '/^$/ { if (t == 2) { t = 3 } }' . + '/^./ { if (t == 3) { t = 0 } } ' . + "{ if (t == 0) print }' <" . '"' . "$in" . '" >"' . "$out" . '"'), 0); } sub closeDevs { @@ -68,27 +74,27 @@ sub closeDevTest { "scstadmin-test-08-$$-2"); my $rc; - system("$scstadmin -clear_config -force -noprompt -no_lip $redirect"); - system("$scstadmin -open_dev nodev -handler vdisk_nullio -attributes dummy=1 $redirect"); - system("$scstadmin -open_dev disk0 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,read_only=1 $redirect"); - system("$scstadmin -open_dev disk1 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,nv_cache=1 $redirect"); - system("$scstadmin -driver scst_local -add_target local $redirect"); - system("$scstadmin -driver scst_local -target local " . - "-add_lun 0 -device nodev $redirect"); - system("$scstadmin -driver scst_local -target local -add_group ig " . - "$redirect"); - system("$scstadmin -driver scst_local -target local -group ig " . - "-add_init ini1 $redirect"); - system("$scstadmin -driver scst_local -target local -group ig " . - "-add_init ini2 $redirect"); - system("$scstadmin -driver scst_local -target local -group ig " . - "-add_lun 0 -device disk0 $redirect"); - system("$scstadmin -driver scst_local -target local -group ig " . - "-add_lun 1 -device disk1 $redirect"); - system("$scstadmin -write_config $tmpfilename1 >/dev/null"); + ok(system("$scstadmin -clear_config -force -noprompt -no_lip $redirect"), 0); + ok(system("$scstadmin -open_dev nodev -handler vdisk_nullio -attributes dummy=1 $redirect"), 0); + ok(system("$scstadmin -open_dev disk0 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,read_only=1 $redirect"), 0); + ok(system("$scstadmin -open_dev disk1 -handler vdisk_fileio -attributes filename=/dev/scstadmin-regression-test-vdisk,nv_cache=1 $redirect"), 0); + ok(system("$scstadmin -driver scst_local -add_target local $redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local " . + "-add_lun 0 -device nodev $redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local -add_group ig " . + "$redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local -group ig " . + "-add_init ini1 $redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local -group ig " . + "-add_init ini2 $redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local -group ig " . + "-add_lun 0 -device disk0 $redirect"), 0); + ok(system("$scstadmin -driver scst_local -target local -group ig " . + "-add_lun 1 -device disk1 $redirect"), 0); + ok(system("$scstadmin -write_config $tmpfilename1 >/dev/null"), 0); # Keep only the scst_local target driver information. filterScstLocal("$tmpfilename1", "$tmpfilename2"); - system("cd /sys/kernel/scst_tgt && find -ls $redirect"); + ok(system("cd /sys/kernel/scst_tgt && find -ls $redirect"), 0); $rc = system("$scstadmin -dumpAttrs $redirect"); ok($rc, 0); $rc = closeDevs("nodev"); From 64b7f7057dd91e5253afb7f9c69f2784cdc69335 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 17:40:56 +0000 Subject: [PATCH 05/42] scstadmin: Add tests for the scstadmin -list_* options git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7932 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/t/07-result.conf | 28 ++ .../scst-1.0.0/t/07-scstadmin-args.t | 366 +++++++++++++++++- 2 files changed, 393 insertions(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-result.conf b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-result.conf index 8bee55a95..628162104 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-result.conf +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-result.conf @@ -36,3 +36,31 @@ TARGET_DRIVER scst_local { } } +DEVICE_GROUP dgroup1 { + TARGET_GROUP tgroup1 { + group_id 256 + state active + + TARGET local + } + + TARGET_GROUP tgroup2 { + group_id 257 + state active + } +} + +DEVICE_GROUP dgroup2 { + TARGET_GROUP tgroup1 { + group_id 258 + state active + + TARGET local + } + + TARGET_GROUP tgroup2 { + group_id 259 + state active + } +} + diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t index 7d8d43235..a31ef042f 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t @@ -22,7 +22,7 @@ BEGIN { unless(grep /blib/, @INC) { unshift(@INC, File::Spec->catdir($scstadmin_pm_dir, "lib")); } - plan tests => 16; + plan tests => 55; } use Data::Dumper; @@ -68,6 +68,20 @@ sub attributeTest { "-add_lun 0 -device disk0 $redirect"), 0); ok(system("$scstadmin -driver scst_local -target local -group ig " . "-add_lun 1 -device disk1 $redirect"), 0); + ok(system("$scstadmin -add_dgrp dgroup1 $redirect"), 0); + ok(system("$scstadmin -add_dgrp dgroup2 $redirect"), 0); + ok(system("$scstadmin -add_tgrp tgroup1 -dev_group dgroup1 $redirect"), 0); + ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup1 -dev_group dgroup1 -attributes group_id=256 $redirect"), 0); + ok(system("$scstadmin -add_tgrp tgroup2 -dev_group dgroup1 $redirect"), 0); + ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup2 -dev_group dgroup1 -attributes group_id=257 $redirect"), 0); + ok(system("$scstadmin -add_tgrp tgroup1 -dev_group dgroup2 $redirect"), 0); + ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup1 -dev_group dgroup2 -attributes group_id=258 $redirect"), 0); + ok(system("$scstadmin -add_tgrp tgroup2 -dev_group dgroup2 $redirect"), 0); + ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup2 -dev_group dgroup2 -attributes group_id=259 $redirect"), 0); + ok(system("$scstadmin -add_tgrp_tgt local -dev_group dgroup1 -tgt_group tgroup1 $redirect"), 0); + ok(system("$scstadmin -add_tgrp_tgt local -dev_group dgroup2 -tgt_group tgroup1 $redirect"), 0); + ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup1 -dev_group dgroup1 -attributes rel_tgt_id=1 $redirect"), 0); + ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup1 -dev_group dgroup2 -attributes rel_tgt_id=2 $redirect"), 0); ok(system("$scstadmin -write_config $tmpfilename1 >/dev/null"), 0); # Keep only the scst_local target driver information. my $cmd = "gawk 'BEGIN { t = 0 } /^# Automatically generated by SCST Configurator v/ {" . @@ -88,6 +102,354 @@ sub attributeTest { } } +# Run shell command $1 and return what it wrote to stdout and stderr as a +# string. +sub run { + my ($cmd) = @_; + my $tmpfile = File::Spec->catfile(File::Spec->tmpdir(), + "scstadmin-test-07-$$-3"); + my $res; + my $rc; + + $rc = system("$cmd >$tmpfile 2>&1"); + if ($rc != 0) { + $res = "exit code $rc"; + } elsif (!open(my $file, $tmpfile)) { + $res = "failed to read $tmpfile"; + } else { + local $/ = undef; + binmode $file; + $res = <$file>; + if (!defined($res)) { + $res = ""; + } + close $file; + } + unlink($tmpfile); + return $res; +} + +# Test the scstadmin -list_* options. +sub listTest { + my $result; + + $result = <<'EOS'; + +Collecting current configuration: done. + + Handler + ------------- + vcdrom + vdisk_blockio + vdisk_fileio + vdisk_nullio + +All done. +EOS + ok(run("$scstadmin -list_handler"), $result); + + $result = <<'EOS'; + +Collecting current configuration: done. + + Handler Device + ----------------------- + vcdrom - + vdisk_blockio - + vdisk_fileio disk0 + disk1 + vdisk_nullio nodev + +All done. +EOS + ok(run("$scstadmin -list_device"), $result); + + $result = <<'EOS'; + +Collecting current configuration: done. + + Attribute Value Writable KEY + ------------------------------------------------------------------------ + filename /dev/scstadmin-regression-test-vdisk Yes Yes + read_only 1 No Yes + size 1048576 No Yes + +All done. +EOS + ok(run("$scstadmin -list_device disk0"), $result); + + $result = <<'EOS'; + +Collecting current configuration: done. + + Device Group + ------------ + dgroup1 + + dgroup2 + + +All done. +EOS + ok(run("$scstadmin -list_dgrp"), $result); + + $result = "exit code 256"; + ok(run("$scstadmin -list_tgrp tgrp"), $result); + + $result = <<'EOS'; + +Collecting current configuration: done. + + Driver + ------------ + copy_manager + ib_srpt + iscsi + scst_local + +All done. +EOS + ok(run("$scstadmin -list_driver"), $result); + $result = <<'EOS'; + +Collecting current configuration: done. + + Driver Target + ----------------------------- + copy_manager copy_manager_tgt + scst_local local + +All done. +EOS + ok(run("$scstadmin -list_target"), $result); + + $result = <<'EOS'; + +Collecting current configuration: done. + +Driver: copy_manager +Target: copy_manager_tgt + +Assigned LUNs: + + LUN Device + ---------- + 10 disk1 + 8 nodev + 9 disk0 + +Driver: scst_local +Target: local + +Assigned LUNs: + + LUN Device + ---------- + 0 nodev + +Group: ig + +Assigned LUNs: + + LUN Device + ---------- + 0 disk0 + 1 disk1 + +Assigned Initiators: + + Initiator + ---- + ini1 + ini2 + + + +All done. +EOS + ok(run("$scstadmin -list_group"), $result); + + + $result = <<'EOS'; + +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + +All done. +EOS + ok(run("$scstadmin -list_scst_attr"), $result); + $result = <<'EOS'; + +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + + Device CREATE attributes available + ---------------------------------- + tst + +All done. +EOS + ok(run("$scstadmin -list_hnd_attr vcdrom"), $result); + + $result = <<'EOS'; + +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + + Device CREATE attributes available + ---------------------------------- + active + bind_alua_state + blocksize + cluster_mode + dif_filename + dif_mode + dif_static_app_tag + dif_type + filename + numa_node_id + nv_cache + read_only + removable + rotational + thin_provisioned + tst + write_through + +All done. +EOS + ok(run("$scstadmin -list_hnd_attr vdisk_blockio"), $result); + + $result = <<'EOS'; + +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + + Device CREATE attributes available + ---------------------------------- + async + blocksize + cluster_mode + dif_filename + dif_mode + dif_static_app_tag + dif_type + filename + numa_node_id + nv_cache + o_direct + read_only + removable + rotational + thin_provisioned + tst + write_through + zero_copy + +All done. +EOS + ok(run("$scstadmin -list_hnd_attr vdisk_fileio"), $result); + $result = <<'EOS'; + +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + + Device CREATE attributes available + ---------------------------------- + blocksize + cluster_mode + dif_mode + dif_static_app_tag + dif_type + dummy + numa_node_id + read_only + removable + rotational + size + size_mb + tst + +All done. +EOS + ok(run("$scstadmin -list_hnd_attr vdisk_nullio"), $result); + + $result = "exit code 256"; + ok(run("$scstadmin -list_dev_attr disk00"), $result); + ok(run("$scstadmin -list_dev_attr disk01"), $result); + + $result = <<'EOS'; + +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + +All done. +EOS + ok(run("$scstadmin -list_drv_attr ib_srpt"), $result); + + $result = "exit code 256"; + ok(run("$scstadmin -list_tgrp_attr"), $result); + ok(run("$scstadmin -list_tgtt_attr"), $result); + ok(run("$scstadmin -list_tgt_attr local"), $result); + ok(run("$scstadmin -list_grp_attr ig"), $result); + ok(run("$scstadmin -list_lun_attr 0"), $result); + ok(run("$scstadmin -list_lun_attr 1"), $result); + ok(run("$scstadmin -list_init_attr ini1"), $result); + ok(run("$scstadmin -list_init_attr ini2"), $result); + $result = <<'EOS'; + +Collecting current configuration: done. + +Driver/Target: copy_manager/copy_manager_tgt + + Session: copy_manager_sess + + Attribute Value Writable KEY + --------------------------------------------------------------------- + active_commands 0 Yes No + bidi_cmd_count 0 Yes No + bidi_io_count_kb 0 Yes No + bidi_unaligned_cmd_count 0 Yes No + commands 0 Yes No + dif_checks_failed app ref guard Yes No + initiator_name copy_manager_sess Yes No + none_cmd_count 0 Yes No + read_cmd_count 11 Yes No + read_io_count_kb 44 Yes No + read_unaligned_cmd_count 0 Yes No + unknown_cmd_count 0 Yes No + write_cmd_count 0 Yes No + write_io_count_kb 0 Yes No + write_unaligned_cmd_count 0 Yes No + +Driver/Target: scst_local/local + + (no sessions) + + +All done. +EOS + ok(run("$scstadmin -list_sessions"), $result); +} + my $_DEBUG_ = 0; if ($_DEBUG_) { $redirect = ">>$redirect_file"; @@ -104,4 +466,6 @@ setup($SCST); attributeTest(File::Spec->catfile($testdir, "07-result.conf")); +listTest(); + teardown(); From 1d85efa936a224410a7f7d900eef46ad5ec0ca37 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 17:47:12 +0000 Subject: [PATCH 06/42] scstadmin: Improve handling of write-only ALUA attributes git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7933 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm index be4576410..47523d126 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm @@ -768,10 +768,14 @@ sub aluaAttributes { my $io = new IO::File $pPath, O_RDONLY; if (!$io) { - return (undef, "deviceGroupsAttributes(): Unable to read device attribute '$attribute': $!"); + return (undef, "aluaAttributes(): Unable to read device attribute '$attribute': $!"); } my $value = <$io>; + if (!defined($value)) { + $value = ""; + } + chomp $value; my $second_line = <$io>; From 27893e7e58628119614975fc21be569a48bf0720 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 18:31:19 +0000 Subject: [PATCH 07/42] scstadmin: Avoid shadowed declarations in test 03 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7934 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scst-1.0.0/t/03-targets.t | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/03-targets.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/03-targets.t index 26ca57fe6..095232154 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/03-targets.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/03-targets.t @@ -14,11 +14,13 @@ use SCST::SCST; sub addTargets { my $SCST = shift; + my $errorString; ok(Dumper($SCST->targets('no-such-driver')), Dumper(undef, "targets(): Driver 'no-such-driver' is not available")); - my ($drivers, $errorString) = $SCST->drivers(); + my $drivers; + ($drivers, $errorString) = $SCST->drivers(); my %drivers = map { $_ => 1 } @{$drivers}; ok(exists($drivers{'iscsi'})); ok(exists($drivers{'scst_local'})); @@ -26,7 +28,8 @@ sub addTargets { my $all_hw_tgt = 1; for my $driver (@{$drivers}) { next if $driver eq 'copy_manager'; - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + ($targets, $errorString) = $SCST->targets($driver); for my $target (@{$targets}) { if ($SCST->targetType($driver, $target) != $SCST::SCST::TGT_TYPE_HARDWARE) { From b56d94a1538a2b04c5eb6d92a1c80a1e20b79c29 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 18:32:42 +0000 Subject: [PATCH 08/42] scstadmin: Make it easier to debug regression test 06 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7935 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t index 713fb982c..8027c5a68 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/06-cont-on-err.t @@ -11,8 +11,12 @@ my $testdir; my $scstadmin_pm_dir; my $scstadmin_dir; my $scstadmin; +my $redirect_file; +my $redirect; BEGIN { + $redirect_file = "/tmp/scstadmin-test-06-output.txt"; + unlink($redirect_file); $testdir = dirname(abs_path($0)); $scstadmin_pm_dir = dirname($testdir); $scstadmin_dir = dirname($scstadmin_pm_dir); @@ -45,7 +49,7 @@ sub testRestoreConfig { my $diff = File::Spec->catfile(File::Spec->tmpdir(), "scstadmin-test-06-$$-diff"); - ok(system("$scstadmin -clear_config -force -noprompt -no_lip >/dev/null"), 0); + ok(system("$scstadmin -clear_config -force -noprompt -no_lip $redirect"), 0); system("$scstadmin -cont_on_err -no_lip -config $to_be_restored" . " >/dev/null"); ok(system("$scstadmin -write_config $tmpfilename1 >/dev/null"), 0); @@ -66,6 +70,13 @@ sub testRestoreConfig { } my $_DEBUG_ = 0; +if ($_DEBUG_) { + $redirect = ">>$redirect_file"; + open(my $logfile, '>>', $redirect_file); + select $logfile; +} else { + $redirect = ">/dev/null"; +} my $SCST = eval { new SCST::SCST($_DEBUG_) }; die("Creation of SCST object failed") if (!defined($SCST)); From 2a84df8445d4cc3b51e57b58195ad65131ea55a3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 18:44:33 +0000 Subject: [PATCH 09/42] scstadmin: Avoid shadowing the errorString declaration This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7936 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/lib/SCST/SCST.pm | 55 +++-- scstadmin/scstadmin.sysfs/scstadmin | 216 ++++++++++++------ 2 files changed, 175 insertions(+), 96 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm index 47523d126..b9c394438 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm @@ -644,6 +644,7 @@ sub initiators { my $target = shift; my $group = shift; my @initiators; + my $errorString; return (undef, "Too few arguments") if (!defined($driver) || !defined($target) || !defined($group)); @@ -652,7 +653,6 @@ sub initiators { my $_path = make_path(SCST_TARGETS_DIR(), $driver, $target, SCST_GROUPS, $group, SCST_INITIATORS); if (!(opendir $iHandle, $_path)) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "initiators(): Driver '$driver' is not available"; } elsif ($self->targetExists($driver, $target) != TRUE) { @@ -682,6 +682,7 @@ sub luns { my $driver = shift; my $target = shift; my $group = shift; + my $errorString; return (undef, "Too few arguments") if (!defined($driver) || !defined($target)); @@ -698,7 +699,6 @@ sub luns { my $lHandle = new IO::Handle; if (!(opendir $lHandle, $_path)) { - my $errorString; if (defined($group) && $self->groupExists($driver, $target, $group) != TRUE) { $errorString = "initiators(): Group '$group' does not exist"; } elsif ($self->driverExists($driver) != TRUE) { @@ -828,13 +828,13 @@ sub deviceGroupDevices { my $self = shift; my $group = shift; my @devices; + my $errorString; return (undef, "Too few arguments") if (!defined($group)); my $dHandle = new IO::Handle; my $_path = make_path(SCST_DEV_GROUP_DIR(), $group, SCST_DG_DEVICES); if (!(opendir $dHandle, $_path)) { - my $errorString; if ($self->deviceGroupExists($group) != TRUE) { $errorString = "deviceGroupDevices(): Device group '$group' does not exist"; } else { @@ -860,13 +860,13 @@ sub targetGroups { my $self = shift; my $group = shift; my @tgroups; + my $errorString; return (undef, "Too few arguments") if (!defined($group)); my $dHandle = new IO::Handle; my $_path = make_path(SCST_DEV_GROUP_DIR(), $group, SCST_DG_TGROUPS); if (!(opendir $dHandle, $_path)) { - my $errorString; if ($self->deviceGroupExists($group) != TRUE) { $errorString = "targetGroups(): Device group '$group' does not exist"; } else { @@ -893,13 +893,13 @@ sub targetGroupTargets { my $group = shift; my $tgroup = shift; my @targets; + my $errorString; return (undef, "Too few arguments") if (!defined($group) || !defined($tgroup)); my $dHandle = new IO::Handle; my $_path = make_path(SCST_DEV_GROUP_DIR(), $group, SCST_DG_TGROUPS, $tgroup); if (!(opendir $dHandle, $_path)) { - my $errorString; if ($self->deviceGroupExists($group) != TRUE) { $errorString = "targetGroupTargets(): Device group '$group' does not exist"; } elsif ($self->targetGroupExists($group, $tgroup) != TRUE) { @@ -943,6 +943,7 @@ sub driverDynamicAttributes { my $driver = shift; my %attributes; my $available; + my $errorString; return (undef, "Too few arguments") if (!defined($driver)); @@ -961,7 +962,6 @@ sub driverDynamicAttributes { SCST_MGMT_IO), O_RDONLY; if (!$io) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "driverDynamicAttributes(): Driver '$driver' ". "is not available"; @@ -1144,11 +1144,13 @@ sub targetType { my $self = shift; my $driver = shift; my $target = shift; + my $errorString; return (undef, "Too few arguments") if (!defined($driver) || !defined($target)); if ($self->driverIsVirtualCapable($driver)) { - my ($attribs, $errorString) = $self->targetAttributes($driver, $target); + my $attribs; + ($attribs, $errorString) = $self->targetAttributes($driver, $target); if (defined($$attribs{'hw_target'}) && ($$attribs{'hw_target'}->{'value'} == TRUE)) { @@ -1224,6 +1226,7 @@ sub targetDynamicAttributes { my $driver = shift; my %attributes; my $available; + my $errorString; return (undef, "Too few arguments") if (!defined($driver)); @@ -1242,7 +1245,6 @@ sub targetDynamicAttributes { SCST_MGMT_IO), O_RDONLY; if (!$io) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "targetDynamicAttributes(): Driver '$driver' ". "is not available"; @@ -1728,6 +1730,7 @@ sub addDeviceGroupDevice { my $self = shift; my $group = shift; my $device = shift; + my $errorString; return SCST_C_DGRP_ADD_DEV_FAIL if (!defined($group) || !defined($device)); @@ -1769,8 +1772,9 @@ sub addDeviceGroupDevice { my ($dgroups, $errorString) = $self->deviceGroups(); foreach my $dgroup (@{$dgroups}) { - my ($devs, $errorString) = $self->deviceGroupDevices($dgroup); + my $devs; + ($devs, $errorString) = $self->deviceGroupDevices($dgroup); foreach my $dev (@{$devs}) { return SCST_C_DGRP_DEVICE_OTHER if ($dev eq $device); } @@ -2586,11 +2590,12 @@ sub deviceAttributes { my $self = shift; my $device = shift; my %attributes; + my $errorString; + my $dca; my $pHandle = new IO::Handle; my $_path = make_path(SCST_DEVICES_DIR(), $device); if (!(opendir $pHandle, $_path)) { - my $errorString; if ($self->deviceOpen($device) != TRUE) { $errorString = "deviceAttributes(): Device '$device' is not open"; } else { @@ -2599,7 +2604,7 @@ sub deviceAttributes { return (undef, $errorString); } - my ($dca, $errorString) = $self->deviceCreateAttributes($self->deviceHandler($device)); + ($dca, $errorString) = $self->deviceCreateAttributes($self->deviceHandler($device)); foreach my $attribute (readdir($pHandle)) { next if ($attribute eq '.' || $attribute eq '..' || @@ -2722,11 +2727,11 @@ sub driverAttributes { my $self = shift; my $driver = shift; my %attributes; + my $errorString; my $pHandle = new IO::Handle; my $_path = make_path(SCST_TARGETS_DIR(), $driver); if (!(opendir $pHandle, $_path)) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "driverAttributes(): Driver '$driver' is not available"; } else { @@ -2853,13 +2858,13 @@ sub targetAttributes { my $driver = shift; my $target = shift; my %attributes; + my $errorString; return (undef, "Too few arguments") if (!defined($driver) || !defined($target)); my $pHandle = new IO::Handle; my $_path = make_path(SCST_TARGETS_DIR(), $driver, $target); if (!(opendir $pHandle, $_path)) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "targetAttributes(): Driver '$driver' is not available"; } elsif ($self->targetExists($driver, $target) != TRUE) { @@ -3005,12 +3010,12 @@ sub groupAttributes { my $target = shift; my $group = shift; my %attributes; + my $errorString; my $pHandle = new IO::Handle; my $_path = make_path(SCST_TARGETS_DIR(), $driver, $target, SCST_GROUPS, $group); if (!(opendir $pHandle, $_path)) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "groupAttributes(): Driver '$driver' is not available"; } elsif ($self->targetExists($driver, $target) != TRUE) { @@ -3313,12 +3318,12 @@ sub initiatorAttributes { my $group = shift; my $initiator = shift; my %attributes; + my $errorString; my $pHandle = new IO::Handle; my $_path = make_path(SCST_TARGETS_DIR(), $driver, $target, SCST_GROUPS, $group, SCST_INITIATORS, $initiator); if (!(opendir $pHandle, $_path)) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "initiatorAttributes(): Driver '$driver' is not available"; } elsif ($self->targetExists($driver, $target) != TRUE) { @@ -3444,11 +3449,11 @@ sub deviceGroupAttributes { my $self = shift; my $group = shift; my %attributes; + my $errorString; my $pHandle = new IO::Handle; my $_path = make_path(SCST_DEV_GROUP_DIR(), $group); if (!(opendir $pHandle, $_path)) { - my $errorString; if ($self->deviceGroupExists($group) != TRUE) { $errorString = "deviceGroupAttributes(): Device group '$group' does not exist"; } else { @@ -3522,11 +3527,11 @@ sub targetGroupAttributes { my $group = shift; my $tgroup = shift; my %attributes; + my $errorString; my $pHandle = new IO::Handle; my $_path = make_path(SCST_DEV_GROUP_DIR(), $group, SCST_DG_TGROUPS, $tgroup); if (!(opendir $pHandle, $_path)) { - my $errorString; if ($self->deviceGroupExists($group) != TRUE) { $errorString = "targetGroupAttributes(): Device group '$group' does not exist"; } elsif ($self->targetGroupExists($group, $tgroup) != TRUE) { @@ -3604,6 +3609,7 @@ sub targetGroupTargetAttributes { my $tgt = shift; my $local_tgt = shift; my %attributes; + my $errorString; my $pHandle = new IO::Handle; my $_path = make_path(SCST_DEV_GROUP_DIR(), $group, SCST_DG_TGROUPS, $tgroup, $tgt); @@ -3612,7 +3618,6 @@ sub targetGroupTargetAttributes { } if (!(opendir $pHandle, $_path)) { - my $errorString; if ($self->deviceGroupExists($group) != TRUE) { $errorString = "targetGroupTargetAttributes(): Device group '$group' does not exist"; } elsif ($self->targetGroupExists($group, $tgroup) != TRUE) { @@ -3894,6 +3899,7 @@ sub handlerAttributes { my $self = shift; my $handler = shift; my %attributes; + my $errorString; my ($a, $errorString) = devices($self, $handler); $attributes{'devices'}->{'value'} = $a; @@ -3901,7 +3907,6 @@ sub handlerAttributes { my $hHandle = new IO::Handle; my $_path = make_path(SCST_HANDLERS_DIR(), $handler); if (!(opendir $hHandle, $_path)) { - my $errorString; if ($self->handlerExists($handler) != TRUE) { $errorString = "handlerAttributes(): Handler '$handler' is not available"; } else { @@ -4042,11 +4047,11 @@ sub handlerDeviceExists { sub devicesByHandler { my $self = shift; my $handler = shift; + my $errorString; my ($attributes, $errorString) = $self->handlerAttributes($handler); if (!defined($attributes)) { - my $errorString; if ($self->handlerExists($handler) != TRUE) { $errorString = "devicesByHandler(): Handler '$handler' is not available"; } else { @@ -4094,6 +4099,7 @@ sub deviceCreateAttributes { my $handler = shift; my $available; my %attributes; + my $errorString; if (new_sysfs_interface()) { my $io = new IO::File make_path(SCST_HANDLERS_DIR(), $handler, @@ -4109,7 +4115,6 @@ sub deviceCreateAttributes { SCST_MGMT_IO), O_RDONLY; if (!$io) { - my $errorString; if ($self->handlerExists($handler) != TRUE) { $errorString = "deviceCreateAttributes(): Handler '$handler' ". "is not available"; @@ -4314,6 +4319,7 @@ sub targetCreateAttributes { my $driver = shift; my $available; my %attributes; + my $errorString; if (new_sysfs_interface()) { my $io = new IO::File make_path(SCST_TARGETS_DIR(), $driver, @@ -4328,7 +4334,6 @@ sub targetCreateAttributes { SCST_MGMT_IO), O_RDONLY; if (!$io) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "targetCreateAttributes(): Driver '$driver' ". "is not available"; @@ -4506,6 +4511,7 @@ sub lunCreateAttributes { my $group = shift; my $available; my %attributes; + my $errorString; my $_path; @@ -4543,7 +4549,6 @@ sub lunCreateAttributes { my $io = new IO::File $_path, O_RDONLY; if (!$io) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "lunCreateAttributes(): Driver '$driver' ". "is not available"; @@ -4628,6 +4633,7 @@ sub initiatorCreateAttributes { my $group = shift; my $available; my %attributes; + my $errorString; if (new_sysfs_interface()) { # Do nothing - there are no initiator attributes (yet). @@ -4638,7 +4644,6 @@ sub initiatorCreateAttributes { O_RDONLY; if (!$io) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "initiatorCreateAttributes(): Driver '$driver' ". "is not available"; @@ -4680,6 +4685,7 @@ sub sessions { my $driver = shift; my $target = shift; my %_sessions; + my $errorString; return (undef, "Too few arguments") if (!defined($driver) || !defined($target)); @@ -4687,7 +4693,6 @@ sub sessions { my $_path = make_path(SCST_TARGETS_DIR(), $driver, $target, SCST_SESSIONS); if (!(opendir $sHandle, $_path)) { - my $errorString; if ($self->driverExists($driver) != TRUE) { $errorString = "sessions(): Driver '$driver' ". "is not available"; diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 51947df28..7d70dfd91 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -1358,6 +1358,7 @@ sub main { sub readWorkingConfig { my $force = shift; + my $errorString; print "\nCollecting current configuration: "; @@ -1365,11 +1366,14 @@ sub readWorkingConfig { # Get current handlers/devices - my ($handlers, $errorString) = $SCST->handlers(); + my $handlers; + ($handlers, $errorString) = $SCST->handlers(); immediateExit($errorString); foreach my $handler (@{$handlers}) { - my ($devices, $errorString) = $SCST->devicesByHandler($handler); + my $devices; + + ($devices, $errorString) = $SCST->devicesByHandler($handler); immediateExit($errorString); $CURRENT{'handler'}->{$handler} = $devices; } @@ -1382,40 +1386,48 @@ sub readWorkingConfig { foreach my $driver (@{$drivers}) { my %empty; $CURRENT{'assign'}->{$driver} = \%empty; - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + ($targets, $errorString) = $SCST->targets($driver); immediateExit($errorString); foreach my $target (@{$targets}) { my %empty; $CURRENT{'assign'}->{$driver}->{$target} = \%empty; - my ($luns, $errorString) = $SCST->luns($driver, $target); + my $luns; + ($luns, $errorString) = $SCST->luns($driver, $target); $CURRENT{'assign'}->{$driver}->{$target}->{'LUN'} = $luns if (defined($luns)); - my ($groups, $errorString) = $SCST->groups($driver, $target); + my $groups; + ($groups, $errorString) = $SCST->groups($driver, $target); immediateExit($errorString); foreach my $group (@{$groups}) { - my ($initiators, $errorString) = $SCST->initiators($driver, $target, $group); + my $initiators; + ($initiators, $errorString) = $SCST->initiators($driver, $target, $group); immediateExit($errorString); $CURRENT{'assign'}->{$driver}->{$target}->{'GROUP'}->{$group}->{'INITIATORS'} = $initiators; - my ($luns, $errorString) = $SCST->luns($driver, $target, $group); + ($luns, $errorString) = $SCST->luns($driver, $target, $group); $CURRENT{'assign'}->{$driver}->{$target}->{'GROUP'}->{$group}->{'LUN'} = $luns; immediateExit($errorString); } } } - my ($dgroups, $errorString) = $SCST->deviceGroups(); + my $dgroups; + ($dgroups, $errorString) = $SCST->deviceGroups(); immediateExit($errorString); foreach my $dgroup (@{$dgroups}) { - my ($dgd, $errorString) = $SCST->deviceGroupDevices($dgroup); + my $dgd; + ($dgd, $errorString) = $SCST->deviceGroupDevices($dgroup); immediateExit($errorString); $CURRENT{'dgroups'}->{$dgroup}->{'devices'} = $dgd; - my ($tgroups, $errorString) = $SCST->targetGroups($dgroup); + my $tgroups; + ($tgroups, $errorString) = $SCST->targetGroups($dgroup); immediateExit($errorString); foreach my $tgroup (@{$tgroups}) { - my ($tgt, $errorString) = $SCST->targetGroupTargets($dgroup, $tgroup); + my $tgt; + ($tgt, $errorString) = $SCST->targetGroupTargets($dgroup, $tgroup); $CURRENT{'dgroups'}->{$dgroup}->{'tgroups'}->{$tgroup}->{'targets'} = $tgt; } } @@ -1532,9 +1544,11 @@ sub serializeNkAttr { sub isPassthroughDev { my $dev = shift; my $pt = FALSE; + my $errorString; foreach my $handler (keys %{$CURRENT{'handler'}}) { - my ($ha, $errorString) = $SCST->handlerAttributes($handler); + my $ha; + ($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) { @@ -1550,6 +1564,7 @@ sub isPassthroughDev { # Returns 0 upon success and 1 upon error. sub writeConfiguration { my $nonkey = shift; + my $errorString; my $io = new IO::File $CONFIGFILE, O_CREAT|O_WRONLY|O_TRUNC; @@ -1563,7 +1578,8 @@ sub writeConfiguration { print $io "# Automatically generated by $Version.\n\n"; { - my ($attributes, $errorString) = $SCST->scstAttributes(); + my $attributes; + ($attributes, $errorString) = $SCST->scstAttributes(); immediateExit($errorString); print $io serializeKeyAttr("", $attributes); @@ -1580,10 +1596,11 @@ sub writeConfiguration { foreach my $handler (sort keys %{$CURRENT{'handler'}}) { my $handler_buff; my $handler_buff_nk; + my $handler_attrs; + my $attributes; - my ($handler_attrs, $errorString) = $SCST->deviceCreateAttributes($handler); - my ($attributes, $errorString) = $SCST->handlerAttributes($handler); - + ($handler_attrs, $errorString) = $SCST->deviceCreateAttributes($handler); + ($attributes, $errorString) = $SCST->handlerAttributes($handler); $handler_buff = serializeKeyAttr("\t", $attributes); $handler_buff_nk = serializeNkAttr("\t", $attributes) if ($nonkey); @@ -1593,11 +1610,11 @@ sub writeConfiguration { foreach my $device (sort @{$devices}) { $device_buff .= "\tDEVICE $device"; - my ($attributes, $errorString) = $SCST->deviceAttributes($device); - + my $attributes; my $attribute_buff; my $attribute_buff_nk; + ($attributes, $errorString) = $SCST->deviceAttributes($device); $attribute_buff = serializeKeyAttr("\t\t", $attributes, $handler_attrs); $attribute_buff_nk = serializeNkAttr("\t\t", $attributes, $handler_attrs) if ($nonkey); $attribute_buff .= "\n" if ($attribute_buff); @@ -1638,28 +1655,29 @@ sub writeConfiguration { foreach my $driver (sort keys %{$CURRENT{'assign'}}) { my $driver_buff; - my ($drv_attrs, $errorString) = $SCST->driverAttributes($driver); - + my $drv_attrs; my $drv_attr_buff; my $drv_attr_buff_nk; + ($drv_attrs, $errorString) = $SCST->driverAttributes($driver); $drv_attr_buff = serializeKeyAttr("\t", $drv_attrs); $drv_attr_buff_nk = serializeNkAttr("\t", $drv_attrs) if ($nonkey); $drv_attr_buff .= "\n" if ($drv_attr_buff); $drv_attr_buff_nk .= "\n" if ($drv_attr_buff_nk); my $targets = $CURRENT{'assign'}->{$driver}; - my ($tgt_attrs, $errorString) = $SCST->targetCreateAttributes($driver); + my $tgt_attrs; + ($tgt_attrs, $errorString) = $SCST->targetCreateAttributes($driver); my $target_buff; foreach my $target (sort keys %{$targets}) { $target_buff .= "\tTARGET $target"; - my ($attributes, $errorString) = $SCST->targetAttributes($driver, $target); - + my $attributes; my $attribute_buff; my $attribute_buff_nk; + ($attributes, $errorString) = $SCST->targetAttributes($driver, $target); if (defined($$attributes{'hw_target'}) && ($$attributes{'hw_target'}->{'value'} == TRUE)) { $attribute_buff = "\t\tHW_TARGET\n\n"; @@ -1671,7 +1689,8 @@ sub writeConfiguration { $attribute_buff_nk .= "\n" if ($attribute_buff_nk); my $luns = $CURRENT{'assign'}->{$driver}->{$target}->{'LUN'}; - my ($lun_attrs, $errorString) = $SCST->lunCreateAttributes($driver, $target); + my $lun_attrs; + ($lun_attrs, $errorString) = $SCST->lunCreateAttributes($driver, $target); my $t_lun_buff; foreach my $lun (sort numerically keys %{$luns}) { @@ -1685,7 +1704,8 @@ sub writeConfiguration { $t_lun_buff .= "\t\tLUN $lun $lun_dev"; - my ($attributes, $errorString) = $SCST->lunAttributes($driver, $target, $lun); + my $attributes; + ($attributes, $errorString) = $SCST->lunAttributes($driver, $target, $lun); my $l_attribute_buff = serializeKeyAttr("\t\t\t", $attributes, @@ -1716,9 +1736,11 @@ sub writeConfiguration { my $group_buff; foreach my $group (sort keys %{$groups}) { - my ($lun_attrs, $errorString) = $SCST->lunCreateAttributes($driver, $target, $group); - my ($ini_attrs, $errorString) = $SCST->initiatorCreateAttributes($driver, $target, $group); + my $lun_attrs; + my $ini_attrs; + ($lun_attrs, $errorString) = $SCST->lunCreateAttributes($driver, $target, $group); + ($ini_attrs, $errorString) = $SCST->initiatorCreateAttributes($driver, $target, $group); $group_buff .= "\t\tGROUP $group"; my $luns = $CURRENT{'assign'}->{$driver}->{$target}->{'GROUP'}->{$group}->{'LUN'}; @@ -1729,7 +1751,8 @@ sub writeConfiguration { $lun_buff .= "\t\t\tLUN $lun $lun_dev"; - my ($attributes, $errorString) = $SCST->lunAttributes($driver, $target, $lun, $group); + my $attributes; + ($attributes, $errorString) = $SCST->lunAttributes($driver, $target, $lun, $group); my $l_attribute_buff = serializeKeyAttr("\t\t\t\t", @@ -1761,7 +1784,8 @@ sub writeConfiguration { foreach my $init (sort @{$inits}) { $init_buff .= "\n\t\t\tINITIATOR " . escapeMeta($init); - my ($attributes, $errorString) = $SCST->initiatorAttributes($driver, $target, $group, $init); + my $attributes; + ($attributes, $errorString) = $SCST->initiatorAttributes($driver, $target, $group, $init); my $i_attribute_buff = serializeKeyAttr("\t\t\t\t", @@ -1787,7 +1811,8 @@ sub writeConfiguration { } } - my ($grp_attributes, $errorString) = $SCST->groupAttributes($driver, $target, $group); + my $grp_attributes; + ($grp_attributes, $errorString) = $SCST->groupAttributes($driver, $target, $group); my $g_attribute_buff = serializeKeyAttr("\t\t\t", $grp_attributes); @@ -1858,7 +1883,8 @@ sub writeConfiguration { } } - my ($dga, $errorString) = $SCST->aluaAttributes(); + my $dga; + ($dga, $errorString) = $SCST->aluaAttributes(); my $dga_buff = serializeKeyAttr("\t", $dga); my $dga_buff_nk = serializeNkAttr("\t", $dga) if ($nonkey); if ($dga_buff_nk) { @@ -1873,12 +1899,11 @@ sub writeConfiguration { foreach my $dgroup (sort keys %{$CURRENT{'dgroups'}}) { my $dgroup_buff; - - my ($dgroup_attrs, $errorString) = $SCST->deviceGroupAttributes($dgroup); - + my $dgroup_attrs; my $dgrp_attr_buff; my $dgrp_attr_buff_nk; + ($dgroup_attrs, $errorString) = $SCST->deviceGroupAttributes($dgroup); $dgrp_attr_buff = serializeKeyAttr("\t", $dgroup_attrs); $dgrp_attr_buff_nk = serializeNkAttr("\t", $dgroup_attrs) if ($nonkey); $dgrp_attr_buff .= "\n" if ($dgrp_attr_buff); @@ -1901,11 +1926,11 @@ sub writeConfiguration { foreach my $tgroup (sort keys %{$tgroups}) { $tgroup_buff .= "\tTARGET_GROUP $tgroup"; - my ($attributes, $errorString) = $SCST->targetGroupAttributes($dgroup, $tgroup); - + my $attributes; my $attribute_buff; my $attribute_buff_nk; + ($attributes, $errorString) = $SCST->targetGroupAttributes($dgroup, $tgroup); $attribute_buff .= serializeKeyAttr("\t\t", $attributes); $attribute_buff_nk .= serializeNkAttr("\t\t", $attributes) if ($nonkey); $attribute_buff .= "\n" if ($attribute_buff); @@ -1917,7 +1942,9 @@ sub writeConfiguration { foreach my $tgt (@{$tgts}) { $tgt_buff .= "\t\tTARGET $tgt"; - my ($tgt_attrs, $errorString) = $SCST->targetGroupTargetAttributes($dgroup, $tgroup, $tgt); + my $tgt_attrs; + + ($tgt_attrs, $errorString) = $SCST->targetGroupTargetAttributes($dgroup, $tgroup, $tgt); my $t_attribute_buff = serializeKeyAttr("\t\t\t", $tgt_attrs); @@ -2211,14 +2238,16 @@ sub applyConfigDevices { my $config = shift; my $deletions = shift; my $changes = 0; + my $errorString; my $handlers = $CURRENT{'handler'}; foreach my $handler (keys %{$handlers}) { foreach my $device (@{$$handlers{$handler}}) { if (!defined($$config{'HANDLER'}->{$handler}->{'DEVICE'}->{$device})) { - my ($attributes, $errorString) = $SCST->deviceAttributes($device); + my $attributes; + ($attributes, $errorString) = $SCST->deviceAttributes($device); if ($deletions) { closeDevice($handler, $device, $deletions); $changes++; @@ -2244,13 +2273,15 @@ sub applyConfigDevices { my $attributes = configToAttr(\%_attributes); my $create_attrs = configToAttr(\%_attributes); - my ($possible, $errorString) = $SCST->deviceCreateAttributes($handler); + my $possible; + ($possible, $errorString) = $SCST->deviceCreateAttributes($handler); condExit($errorString); filterCreateAttributes($possible, $create_attrs, FALSE); filterCreateAttributes($possible, $attributes, TRUE); if (handlerHasDevice($handler, $device)) { - my ($old_create_attrs, $errorString) = $SCST->deviceAttributes($device); + my $old_create_attrs; + ($old_create_attrs, $errorString) = $SCST->deviceAttributes($device); condExit($errorString); filterCreateAttributes($possible, $old_create_attrs, FALSE); @@ -2308,6 +2339,7 @@ sub applyConfigAssignments { my $deletions = shift; my $only_del = shift; my $changes = 0; + my $errorString; my $assignments = $CURRENT{'assign'}; @@ -2330,9 +2362,11 @@ sub applyConfigAssignments { } } else { my $c_attrs = configToAttr($$config{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'LUN'}->{$lun}->{$device}); - my ($o_attrs, $errorString) = $SCST->lunAttributes($driver, $target, $lun); + my $o_attrs; + ($o_attrs, $errorString) = $SCST->lunAttributes($driver, $target, $lun); condExit($errorString); - my ($possible, $errorString) = $SCST->lunCreateAttributes($driver, $target); + my $possible; + ($possible, $errorString) = $SCST->lunCreateAttributes($driver, $target); condExit($errorString); filterCreateAttributes($possible, $c_attrs, FALSE); @@ -2373,9 +2407,11 @@ sub applyConfigAssignments { } } else { my $c_attrs = configToAttr($$config{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'GROUP'}->{$group}->{'LUN'}->{$lun}->{$device}); - my ($o_attrs, $errorString) = $SCST->lunAttributes($driver, $target, $lun, $group); + my $o_attrs; + ($o_attrs, $errorString) = $SCST->lunAttributes($driver, $target, $lun, $group); condExit($errorString); - my ($possible, $errorString) = $SCST->lunCreateAttributes($driver, $target, $group); + my $possible; + ($possible, $errorString) = $SCST->lunCreateAttributes($driver, $target, $group); condExit($errorString); filterCreateAttributes($possible, $c_attrs, FALSE); @@ -2445,6 +2481,7 @@ sub applyConfigEnableDrivers { my $config = shift; my $deletions = shift; my $changes = 0; + my $errorString; my $assignments = $$config{'TARGET_DRIVER'}; @@ -2457,7 +2494,8 @@ sub applyConfigEnableDrivers { } my $attributes = configToAttr(\%_attributes); - my ($d_attributes, $errorString) = $SCST->driverAttributes($driver); + my $d_attributes; + ($d_attributes, $errorString) = $SCST->driverAttributes($driver); if (defined($$d_attributes{'enabled'}) && ($$d_attributes{'enabled'}->{'value'} != $$attributes{'enabled'})) { @@ -2762,6 +2800,7 @@ sub applyConfigEnableTargets { my $config = shift; my $deletions = shift; my $changes = 0; + my $errorString; my $assignments = $$config{'TARGET_DRIVER'}; @@ -2778,7 +2817,8 @@ sub applyConfigEnableTargets { } my $attributes = configToAttr(\%_attributes); - my ($t_attributes, $errorString) = $SCST->targetAttributes($driver, $target); + my $t_attributes; + ($t_attributes, $errorString) = $SCST->targetAttributes($driver, $target); if (defined($$t_attributes{'enabled'}) && ($$t_attributes{'enabled'}->{'value'} != $$attributes{'enabled'})) { @@ -2898,6 +2938,7 @@ sub compareToKeyAttribute { sub clearConfiguration { my $dgroups = $CURRENT{'dgroups'}; my $assignments = $CURRENT{'assign'}; + my $errorString; print "-> Clearing running configuration.\n"; @@ -2937,7 +2978,9 @@ sub clearConfiguration { foreach my $handler (sort keys %{$handlers}) { foreach my $device (@{$$handlers{$handler}}) { - my ($attributes, $errorString) = $SCST->deviceAttributes($device); + my $attributes; + + ($attributes, $errorString) = $SCST->deviceAttributes($device); closeDevice($handler, $device, TRUE); } } @@ -2947,8 +2990,9 @@ sub clearConfiguration { my ($drivers, $errorString) = $SCST->drivers(); foreach my $driver (@{$drivers}) { - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + ($targets, $errorString) = $SCST->targets($driver); foreach my $target (@{$targets}) { disableTarget($driver, $target); } @@ -2970,8 +3014,9 @@ sub addVirtualTarget { my ($targets, $errorString) = $SCST->targets($driver); foreach my $_target (@{$targets}) { - my ($attributes, $errorString) = $SCST->targetAttributes($driver, $_target); + my $attributes; + ($attributes, $errorString) = $SCST->targetAttributes($driver, $_target); if (defined($$attributes{'hw_target'}) && !$$attributes{'enabled'}->{'value'}) { enableTarget($driver, $_target); @@ -3042,8 +3087,9 @@ sub listHandler { $l_handler = length($handler) if ($l_handler < length($handler)); - my ($devices, $errorString) = $SCST->devicesByHandler($handler); + my $devices; + ($devices, $errorString) = $SCST->devicesByHandler($handler); if ($#{$devices} == -1) { push @{$devices}, '-'; } @@ -3063,9 +3109,10 @@ sub listHandler { print "\n"; foreach my $handler (sort keys %toprint) { - my ($devices, $errorString) = $SCST->devicesByHandler($handler); + my $devices; my $first = TRUE; + ($devices, $errorString) = $SCST->devicesByHandler($handler); if ($#{$devices} == -1) { push @{$devices}, '-'; } @@ -3325,7 +3372,8 @@ sub listTargets { $l_driver = length($driver) if ($l_driver < length($driver)); - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + ($targets, $errorString) = $SCST->targets($driver); foreach my $target (@{$targets}) { $l_target = length($target) if ($l_target < length($target)); @@ -3344,8 +3392,9 @@ sub listTargets { my %p; foreach my $driver (sort keys %toprint) { - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + ($targets, $errorString) = $SCST->targets($driver); foreach my $target (@{$targets}) { if (!defined($p{$driver})) { printf("\t%-*s %-*s\n", $l_driver, $driver, $l_target, $target); @@ -3366,14 +3415,16 @@ sub listSessions { my ($drivers, $errorString) = $SCST->drivers(); foreach my $driver (@{$drivers}) { - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + ($targets, $errorString) = $SCST->targets($driver); foreach my $target (@{$targets}) { my $had_sessions = FALSE; + my $sessions; print "Driver/Target: $driver/$target\n\n"; - my ($sessions, $errorString) = $SCST->sessions($driver, $target); + ($sessions, $errorString) = $SCST->sessions($driver, $target); foreach my $session (keys %{$sessions}) { print "\tSession: $session\n\n"; @@ -3499,7 +3550,9 @@ sub listGroups { $driver = $_driver if (!$got_driver); if ($driver eq $_driver) { - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + + ($targets, $errorString) = $SCST->targets($driver); foreach my $_target (@{$targets}) { $target = $_target if (!$got_target); @@ -3512,7 +3565,9 @@ sub listGroups { print "\n"; - my ($groups, $errorString) = $SCST->groups($driver, $target); + my $groups; + + ($groups, $errorString) = $SCST->groups($driver, $target); foreach my $_group (@{$groups}) { $group = $_group if (!$got_group); @@ -3770,8 +3825,9 @@ sub listDriverAttributes { } } - my ($attributes, $errorString) = $SCST->targetCreateAttributes($driver); + my $attributes; + ($attributes, $errorString) = $SCST->targetCreateAttributes($driver); return TRUE if issueWarning($errorString); return TRUE if (!scalar keys %{$attributes}); @@ -4827,11 +4883,14 @@ sub addTargetGroupTarget { sub removeDeviceGroup { my $group = shift; my $force = shift; + my $errorString; if (!$force) { - my ($devices, $errorString) = $SCST->deviceGroupDevices($group); - my ($tgroups, $errorString) = $SCST->targetGroups($group); + my $devices; + my $tgroups; + ($devices, $errorString) = $SCST->deviceGroupDevices($group); + ($tgroups, $errorString) = $SCST->targetGroups($group); if (($#{$devices} > -1) || ($#{$tgroups} > -1)) { print "\n"; listDeviceGroup($group); @@ -4854,10 +4913,12 @@ sub removeTargetGroup { my $group = shift; my $tgroup = shift; my $force = shift; + my $errorString; if (!$force) { - my ($tgts, $errorString) = $SCST->targetGroupTargets($group, $tgroup); + my $tgts; + ($tgts, $errorString) = $SCST->targetGroupTargets($group, $tgroup); if ($#{$tgts} > -1) { print "\n"; listTargetGroup($group, $tgroup); @@ -4912,14 +4973,17 @@ sub removeDeviceGroupDevice { my $group = shift; my $device = shift; my $force = shift; + my $errorString; if (!$force) { my $found = FALSE; - my ($tgroups, $errorString) = $SCST->targetGroups($group); + my $tgroups; + ($tgroups, $errorString) = $SCST->targetGroups($group); foreach my $tgroup (@{$tgroups}) { - my ($targets, $errorString) = $SCST->targetGroupTargets($group, $tgroup); + my $targets; + ($targets, $errorString) = $SCST->targetGroupTargets($group, $tgroup); if ($#{$targets} > -1) { print "\n"; listTargetGroup($group, $tgroup); @@ -4966,11 +5030,14 @@ sub removeGroup { my $target = shift; my $group = shift; my $force = shift; + my $errorString; if (!$force) { - my ($luns, $errorString) = $SCST->luns($driver, $target, $group); - my ($initiators, $errorString) = $SCST->initiators($driver, $target, $group); + my $luns; + my $initiators; + ($luns, $errorString) = $SCST->luns($driver, $target, $group); + ($initiators, $errorString) = $SCST->initiators($driver, $target, $group); if ((keys %{$luns}) || ($#{$initiators} > -1)) { listGroup($driver, $target, $group, $luns, $initiators); immediateExit("Group is still in use, aborting. Use -force to override."); @@ -5273,15 +5340,18 @@ sub issueLip { my $driver = shift; my $target = shift; my $warn = shift; + my $errorString; if (defined($driver) && defined($target)) { return _issueLip($driver, $target, $warn); } else { - my ($drivers, $errorString) = $SCST->drivers(); + my $drivers; + ($drivers, $errorString) = $SCST->drivers(); foreach my $driver(@{$drivers}) { - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + ($targets, $errorString) = $SCST->targets($driver); foreach my $target (@{$targets}) { my $rc = _issueLip($driver, $target, $warn); @@ -5560,8 +5630,9 @@ sub readOldConfigFile { my($device, $lun) = split(/\,/, $device); foreach my $driver (@{$drivers}) { - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + ($targets, $errorString) = $SCST->targets($driver); foreach my $target (@{$targets}) { $new{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'LUN'}->{$lun}->{$device} = {}; } @@ -5573,8 +5644,9 @@ sub readOldConfigFile { my $found_t = FALSE; # Find the associated target foreach my $driver (@{$drivers}) { - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + ($targets, $errorString) = $SCST->targets($driver); foreach my $target (@{$targets}) { if ($target eq $group_t) { foreach my $device (@{$config{'ASSIGNMENT'}->{$group}->{'DEVICE'}}) { @@ -5625,8 +5697,9 @@ sub readOldConfigFile { # Fill in with known targets, all disabled. foreach my $driver (@{$drivers}) { - my ($targets, $errorString) = $SCST->targets($driver); + my $targets; + ($targets, $errorString) = $SCST->targets($driver); foreach my $target (@{$targets}) { addAllGroupsToTarget(\%config, \%new, $driver, $target); } @@ -5644,8 +5717,9 @@ sub readOldConfigFile { foreach my $driver (keys %{$new{'TARGET_DRIVER'}}) { next if ($driver =~ /^qla/); - my ($attributes, $errorString) = $SCST->driverAttributes($driver); + my $attributes; + ($attributes, $errorString) = $SCST->driverAttributes($driver); if (defined($$attributes{'enabled'})) { $new{'TARGET_DRIVER'}->{$driver}->{'enabled'}->{'1'} = {}; } From 6b566f8adf1d4b8ea1ba8109325300f3676d6c47 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 18:59:50 +0000 Subject: [PATCH 10/42] scstadmin: Avoid shadowing the errorString declaration, part 2 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7937 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm index b9c394438..6ed59b059 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm @@ -1730,6 +1730,7 @@ sub addDeviceGroupDevice { my $self = shift; my $group = shift; my $device = shift; + my $dgroups; my $errorString; return SCST_C_DGRP_ADD_DEV_FAIL if (!defined($group) || !defined($device)); @@ -1769,8 +1770,7 @@ sub addDeviceGroupDevice { return $rc if ($rc > 1); # Check all device groups for this device - my ($dgroups, $errorString) = $self->deviceGroups(); - + ($dgroups, $errorString) = $self->deviceGroups(); foreach my $dgroup (@{$dgroups}) { my $devs; @@ -3900,8 +3900,9 @@ sub handlerAttributes { my $handler = shift; my %attributes; my $errorString; + my $a; - my ($a, $errorString) = devices($self, $handler); + ($a, $errorString) = devices($self, $handler); $attributes{'devices'}->{'value'} = $a; my $hHandle = new IO::Handle; @@ -4048,9 +4049,9 @@ sub devicesByHandler { my $self = shift; my $handler = shift; my $errorString; + my $attributes; - my ($attributes, $errorString) = $self->handlerAttributes($handler); - + ($attributes, $errorString) = $self->handlerAttributes($handler); if (!defined($attributes)) { if ($self->handlerExists($handler) != TRUE) { $errorString = "devicesByHandler(): Handler '$handler' is not available"; From 2b238a6abb408f828ae5538b18c6bfc1327e48eb Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 19:03:39 +0000 Subject: [PATCH 11/42] scstadmin: Avoid shadowing the errorString declaration, part 3 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7938 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 7d70dfd91..6ee9c3d7e 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -1380,7 +1380,8 @@ sub readWorkingConfig { # Get current assignments - my ($drivers, $errorString) = $SCST->drivers(); + my $drivers; + ($drivers, $errorString) = $SCST->drivers(); immediateExit($errorString); foreach my $driver (@{$drivers}) { From 7d9212affbc00f2c68ff278db4e7ad90d4af1e76 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 19:08:50 +0000 Subject: [PATCH 12/42] scstadmin: Avoid shadowing the errorString declaration, part 4 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7939 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 6ee9c3d7e..d65011feb 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -2988,7 +2988,8 @@ sub clearConfiguration { # Todo - check return code - my ($drivers, $errorString) = $SCST->drivers(); + my $drivers; + ($drivers, $errorString) = $SCST->drivers(); foreach my $driver (@{$drivers}) { my $targets; From 0f2dae492fe7bc9109b36581021f6c5ab6505b63 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 19:11:27 +0000 Subject: [PATCH 13/42] scstadmin: Rearrange addVirtualTarget() This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7940 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index d65011feb..9f209097c 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -3011,10 +3011,11 @@ sub addVirtualTarget { my $driver = shift; my $target = shift; my $attributes = shift; + my $errorString; + my $targets; # Enable all hardware targets before creating virtual ones - my ($targets, $errorString) = $SCST->targets($driver); - + ($targets, $errorString) = $SCST->targets($driver); foreach my $_target (@{$targets}) { my $attributes; From 0c676b034dd818360845eb718d8d36ff22cf5af7 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 16 Feb 2019 19:19:48 +0000 Subject: [PATCH 14/42] scstadmin: Avoid shadowing the errorString declaration, part 5 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7941 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 9f209097c..8de5a1814 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -5242,14 +5242,17 @@ sub clearLuns { sub clearDriverDynamicAttributes { my $driver = shift; + my $errorString; return TRUE if (!$SCST->driverIsVirtualCapable($driver)); print "\t-> Removing all dynamic attributes from driver '$driver': "; - my ($attributes, $errorString) = $SCST->driverAttributes($driver); - my ($dynamic, $errorString) = $SCST->driverDynamicAttributes($driver); + my $attributes; + my $dynamic; + ($attributes, $errorString) = $SCST->driverAttributes($driver); + ($dynamic, $errorString) = $SCST->driverDynamicAttributes($driver); foreach my $attribute (keys %{$attributes}) { if (defined($$dynamic{$attribute})) { if (defined($$attributes{$attribute}->{'keys'})) { @@ -5271,14 +5274,17 @@ sub clearDriverDynamicAttributes { sub clearTargetDynamicAttributes { my $driver = shift; my $target = shift; + my $errorString; return TRUE if (!$SCST->driverIsVirtualCapable($driver)); print "\t-> Removing all dynamic attributes from driver/target '$driver/$target': "; - my ($attributes, $errorString) = $SCST->targetAttributes($driver, $target); - my ($dynamic, $errorString) = $SCST->targetDynamicAttributes($driver); + my $attributes; + my $dynamic; + ($attributes, $errorString) = $SCST->targetAttributes($driver, $target); + ($dynamic, $errorString) = $SCST->targetDynamicAttributes($driver); foreach my $attribute (keys %{$attributes}) { if (defined($$dynamic{$attribute})) { if (defined($$attributes{$attribute}->{'keys'})) { From b347e79a4016dedc33b4f67c6360eec6a88011bb Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 Feb 2019 19:26:50 +0000 Subject: [PATCH 15/42] scstadmin: Fix an ALUA command line option error message git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7942 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 8de5a1814..8368f75e6 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -707,7 +707,7 @@ sub getArgs { if ((defined($addTargetGroupTarget) || defined($removeTargetGroupTarget)) && (($deviceGroup eq '') || ($targetGroup eq ''))) { - print "Please specify -dev_group and -tgt_group with -add_tgrp_init/-rem_tgrp_init.\n"; + print "Please specify -dev_group and -tgt_group with -add_tgrp_tgt/-rem_tgrp_tgt.\n"; exit 1; } From b75421e3ef315d928205797de2adac50e87c83e3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 Feb 2019 19:29:46 +0000 Subject: [PATCH 16/42] scstadmin: Add a test for the messages printed for invalid args git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7943 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/t/09-scstadmin-invalid-args.t | 167 ++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 scstadmin/scstadmin.sysfs/scst-1.0.0/t/09-scstadmin-invalid-args.t diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/09-scstadmin-invalid-args.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/09-scstadmin-invalid-args.t new file mode 100644 index 000000000..8ab2fc455 --- /dev/null +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/09-scstadmin-invalid-args.t @@ -0,0 +1,167 @@ +#!perl + +use strict; +use warnings; +use Cwd qw(abs_path); +use File::Basename; +use File::Spec; +use Test; + +my $testdir; +my $scstadmin_pm_dir; +my $scstadmin_dir; +my $scstadmin; +my $redirect_file; +my $redirect; + +BEGIN { + $redirect_file = "/tmp/scstadmin-test-06-output.txt"; + unlink($redirect_file); + $testdir = dirname(abs_path($0)); + $scstadmin_pm_dir = dirname($testdir); + $scstadmin_dir = dirname($scstadmin_pm_dir); + $scstadmin = File::Spec->catfile($scstadmin_dir, "scstadmin"); + unless(grep /blib/, @INC) { + unshift(@INC, File::Spec->catdir($scstadmin_pm_dir, "lib")); + } + plan tests => 43; +} + +use SCST::SCST; + +sub setup { + my $SCST = shift; + + my ($drivers, $errorString) = $SCST->drivers(); + my %drivers = map { $_ => 1 } @{$drivers}; + ok(exists($drivers{'ib_srpt'})); +} + +# Run shell command $1 and return what it wrote to stdout and stderr as a +# string. +sub run { + my ($cmd) = @_; + my $tmpfile = File::Spec->catfile(File::Spec->tmpdir(), + "scstadmin-test-07-$$-3"); + my $res; + my $rc; + + $rc = system("$cmd >$tmpfile 2>&1"); + if (!open(my $file, $tmpfile)) { + $res = "failed to read $tmpfile"; + } else { + local $/ = undef; + binmode $file; + $res = <$file>; + if (!defined($res)) { + $res = ""; + } + close $file; + } + unlink($tmpfile); + return $res; +} + +sub testInvalidArgs { + ok(run("$scstadmin -open_dev -handler h -set_scst_attr $redirect"), + "Please specify only one non-query operation at a time.\n"); + ok(run("$scstadmin -clear_config $redirect"), + "Please specify -force with -clear_config.\n"); + ok(run("$scstadmin -list_tgrp $redirect"), + "Please specify -dev_group with -list_tgrp.\n"); + ok(run("$scstadmin -list_tgt_attr t $redirect"), + "Please specify -driver with -list_tgt_attr.\n"); + ok(run("$scstadmin -list_grp_attr g $redirect"), + "Please specify -driver, -target and group with -list_grp_attr.\n"); + ok(run("$scstadmin -list_lun_attr l $redirect"), + "Please specify -driver and -target with -list_lun_attr.\n"); + ok(run("$scstadmin -list_init_attr i $redirect"), + "Please specify -driver, -target and -group with -list_init_attr.\n"); + ok(run("$scstadmin -list_tgrp_attr tg $redirect"), + "Please specify -dev_group with -list_tgrp_attr.\n"); + ok(run("$scstadmin -list_ttgt_attr tt $redirect"), + "Please specify -dev_group and -tgt_group with -list_ttgt_attr.\n"); + ok(run("$scstadmin -set_scst_attr $redirect"), + "Please specify -attributes with -set_scst_attr.\n"); + ok(run("$scstadmin -set_hnd_attr h $redirect"), + "Please specify -attributes with -set_hnd_attr.\n"); + ok(run("$scstadmin -set_dev_attr d $redirect"), + "Please specify -attributes with -set_dev_attr.\n"); + ok(run("$scstadmin -set_dgrp_attr dg $redirect"), + "Please specify -attributes with -set_dgrp_attr.\n"); + ok(run("$scstadmin -set_tgrp_attr tg $redirect"), + "Please specify -dev_group and -attributes with -set_tgrp_attr.\n"); + ok(run("$scstadmin -set_drv_attr d $redirect"), + "Please specify -attributes with -set_drv_attr.\n"); + ok(run("$scstadmin -set_tgt_attr t $redirect"), + "Please specify -driver and -attributes with -set_tgt_attr.\n"); + ok(run("$scstadmin -set_lun_attr l $redirect"), + "Please specify -driver -target -group and -attributes with -set_lun_attr.\n"); + ok(run("$scstadmin -set_init_attr i $redirect"), + "Please specify -driver -target -group and -attributes with -set_init_attr.\n"); + ok(run("$scstadmin -add_drv_attr d $redirect"), + "Please specify -attributes with -add_drv_attr.\n"); + ok(run("$scstadmin -add_tgt_attr t $redirect"), + "Please specify -driver and -attributes with -add_tgt_attr.\n"); + ok(run("$scstadmin -rem_drv_attr d $redirect"), + "Please specify -attributes with -rem_drv_attr.\n"); + ok(run("$scstadmin -rem_tgt_attr t $redirect"), + "Please specify -driver and -attributes with -rem_tgt_attr.\n"); + ok(run("$scstadmin -open_dev d $redirect"), + "Please specify -handler with -open_dev/-close_dev.\n"); + ok(run("$scstadmin -close_dev d $redirect"), + "Please specify -handler with -open_dev/-close_dev.\n"); + ok(run("$scstadmin -add_target t $redirect"), + "Please specify -driver with -add_target.\n"); + ok(run("$scstadmin -rem_target t $redirect"), + "Please specify -driver with -rem_target.\n"); + ok(run("$scstadmin -add_group g $redirect"), + "Please specify -driver and -target with -add_group/-rem_group.\n"); + ok(run("$scstadmin -rem_group g $redirect"), + "Please specify -driver and -target with -add_group/-rem_group.\n"); + ok(run("$scstadmin -add_init i $redirect"), + "Please specify -driver -target and -group with -add_init/-rem_init/-clear_inits.\n"); + ok(run("$scstadmin -rem_init i $redirect"), + "Please specify -driver -target and -group with -add_init/-rem_init/-clear_inits.\n"); + ok(run("$scstadmin -clear_inits $redirect"), + "Please specify -driver -target and -group with -add_init/-rem_init/-clear_inits.\n"); + ok(run("$scstadmin -move_init i $redirect"), + "Please specify -driver -target -group and -to with -move_init.\n"); + ok(run("$scstadmin -add_lun l $redirect"), + "Please specify -driver -target and -device with -add_lun/-replace_lun.\n"); + ok(run("$scstadmin -replace_lun l $redirect"), + "Please specify -driver -target and -device with -add_lun/-replace_lun.\n"); + ok(run("$scstadmin -rem_lun l $redirect"), + "Please specify -driver and -target with -rem_lun/-clear_luns.\n"); + ok(run("$scstadmin -clear_luns $redirect"), + "Please specify -driver and -target with -rem_lun/-clear_luns.\n"); + ok(run("$scstadmin -add_dgrp_dev dg $redirect"), + "Please specify -dev_group with -add_dgrp_dev/-rem_dgrp_dev.\n"); + ok(run("$scstadmin -rem_dgrp_dev dg $redirect"), + "Please specify -dev_group with -add_dgrp_dev/-rem_dgrp_dev.\n"); + ok(run("$scstadmin -add_tgrp tg $redirect"), + "Please specify -dev_group with -add_tgrp/-rem_tgrp.\n"); + ok(run("$scstadmin -rem_tgrp tg $redirect"), + "Please specify -dev_group with -add_tgrp/-rem_tgrp.\n"); + ok(run("$scstadmin -add_tgrp_tgt t $redirect"), + "Please specify -dev_group and -tgt_group with -add_tgrp_tgt/-rem_tgrp_tgt.\n"); + ok(run("$scstadmin -rem_tgrp_tgt t $redirect"), + "Please specify -dev_group and -tgt_group with -add_tgrp_tgt/-rem_tgrp_tgt.\n"); +} + +my $_DEBUG_ = 0; +if ($_DEBUG_) { + $redirect = ">>$redirect_file"; + open(my $logfile, '>>', $redirect_file); + select $logfile; +} else { + $redirect = ">/dev/null"; +} + +my $SCST = eval { new SCST::SCST($_DEBUG_) }; +die("Creation of SCST object failed") if (!defined($SCST)); + +setup($SCST); + +testInvalidArgs; + From d5c1e5ba793d4525e5d5a1abc483aea3b79749b2 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 Feb 2019 19:33:44 +0000 Subject: [PATCH 17/42] scstadmin: Use defined() instead of !... eq '' to check whether arguments have been specified This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7944 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 66 ++++++++++++++--------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 8368f75e6..95c71650f 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -536,177 +536,177 @@ sub getArgs { exit 1; } - if (defined($listTargetGroup) && ($deviceGroup eq '')) { + if (defined($listTargetGroup) && !defined($deviceGroup)) { print "Please specify -dev_group with -list_tgrp.\n"; exit 1; } - if (defined($listTargetAttr) && ($driver eq '')) { + if (defined($listTargetAttr) && !defined($driver)) { print "Please specify -driver with -list_tgt_attr.\n"; exit 1; } - if (defined($listGroupAttr) && (($driver eq '') || ($target eq ''))) { + if (defined($listGroupAttr) && (!defined($driver) || !defined($target))) { print "Please specify -driver, -target and group with -list_grp_attr.\n"; exit 1; } - if (defined($listLunAttr) && (($driver eq '') || ($target eq ''))) { + if (defined($listLunAttr) && (!defined($driver) || !defined($target))) { print "Please specify -driver and -target with -list_lun_attr.\n"; exit 1; } - if (defined($listInitiatorAttr) && (($driver eq '') || ($target eq '') || ($group eq ''))) { + if (defined($listInitiatorAttr) && (!defined($driver) || !defined($target) || !defined($group))) { print "Please specify -driver, -target and -group with -list_init_attr.\n"; exit 1; } - if (defined($listTargetGroupAttr) && ($deviceGroup eq '')) { + if (defined($listTargetGroupAttr) && !defined($deviceGroup)) { print "Please specify -dev_group with -list_tgrp_attr.\n"; exit 1; } - if (defined($listTargetGroupTargetAttr) && (($deviceGroup eq '') || ($targetGroup eq ''))) { + if (defined($listTargetGroupTargetAttr) && (!defined($deviceGroup) || !defined($targetGroup))) { print "Please specify -dev_group and -tgt_group with -list_ttgt_attr.\n"; exit 1; } - if (defined($setScstAttr) && ($attributes eq '')) { + if (defined($setScstAttr) && !defined($attributes)) { print "Please specify -attributes with -set_scst_attr.\n"; exit 1; } - if (defined($setHandlerAttr) && ($attributes eq '')) { + if (defined($setHandlerAttr) && !defined($attributes)) { print "Please specify -attributes with -set_hnd_attr.\n"; exit 1; } - if (defined($setDeviceAttr) && ($attributes eq '')) { + if (defined($setDeviceAttr) && !defined($attributes)) { print "Please specify -attributes with -set_dev_attr.\n"; exit 1; } - if (defined($setDeviceGroupAttr) && ($attributes eq '')) { + if (defined($setDeviceGroupAttr) && !defined($attributes)) { print "Please specify -attributes with -set_dgrp_attr.\n"; exit 1; } - if (defined($setTargetGroupAttr) && (($deviceGroup eq '') || ($attributes eq ''))) { + if (defined($setTargetGroupAttr) && (!defined($deviceGroup) || !defined($attributes))) { print "Please specify -dev_group and -attributes with -set_tgrp_attr.\n"; exit 1; } - if (defined($setTargetGroupTargetAttr) && (($deviceGroup eq '') || ($targetGroup eq '') || ($attributes eq ''))) { + if (defined($setTargetGroupTargetAttr) && (!defined($deviceGroup) || !defined($targetGroup) || !defined($attributes))) { print "Please specify -dev_group -tgt_group and -attributes with -set_ttgt_attr.\n"; exit 1; } - if (defined($setDriverAttr) && ($attributes eq '')) { + if (defined($setDriverAttr) && !defined($attributes)) { print "Please specify -attributes with -set_drv_attr.\n"; exit 1; } - if (defined($setTargetAttr) && (($driver eq '') || ($attributes eq ''))) { + if (defined($setTargetAttr) && (!defined($driver) || !defined($attributes))) { print "Please specify -driver and -attributes with -set_tgt_attr.\n"; exit 1; } - if (defined($setGroupAttr) && (($driver eq '') || ($target eq '') || ($attributes eq ''))) { + if (defined($setGroupAttr) && (!defined($driver) || !defined($target) || !defined($attributes))) { print "Please specify -driver -target and -attributes with -set_grp_attr.\n"; exit 1; } if (defined($setLunAttr) && - (($driver eq '') || ($target eq '') || ($attributes eq ''))) { + (!defined($driver) || !defined($target) || !defined($attributes))) { print "Please specify -driver -target -group and -attributes with -set_lun_attr.\n"; exit 1; } if (defined($setInitiatorAttr) && - (($driver eq '') || ($target eq '') || ($group eq '') || ($attributes eq ''))) { + (!defined($driver) || !defined($target) || !defined($group) || !defined($attributes))) { print "Please specify -driver -target -group and -attributes with -set_init_attr.\n"; exit 1; } - if (defined($addDriverAttr) && ($attributes eq '')) { + if (defined($addDriverAttr) && !defined($attributes)) { print "Please specify -attributes with -add_drv_attr.\n"; exit 1; } if (defined($addTargetAttr) && - (($driver eq '') || ($attributes eq ''))) { + (!defined($driver) || !defined($attributes))) { print "Please specify -driver and -attributes with -add_tgt_attr.\n"; exit 1; } - if (defined($remDriverAttr) && ($attributes eq '')) { + if (defined($remDriverAttr) && !defined($attributes)) { print "Please specify -attributes with -rem_drv_attr.\n"; exit 1; } if (defined($remTargetAttr) && - (($driver eq '') || ($attributes eq ''))) { + (!defined($driver) || !defined($attributes))) { print "Please specify -driver and -attributes with -rem_tgt_attr.\n"; exit 1; } - if ((defined($openDev) || defined($closeDev)) && ($handler eq '')) { + if ((defined($openDev) || defined($closeDev)) && !defined($handler)) { print "Please specify -handler with -open_dev/-close_dev.\n"; exit 1; } - if (defined($addTarget) && ($driver eq '')) { + if (defined($addTarget) && !defined($driver)) { print "Please specify -driver with -add_target.\n"; exit 1; } - if (defined($removeTarget) && ($driver eq '')) { + if (defined($removeTarget) && !defined($driver)) { print "Please specify -driver with -rem_target.\n"; exit 1; } if ((defined($addGroup) || defined($removeGroup)) && - (($driver eq '') || ($target eq ''))) { + (!defined($driver) || !defined($target))) { print "Please specify -driver and -target with -add_group/-rem_group.\n"; exit 1; } if ((defined($addInitiator) || defined($removeInitiator) || defined($clearInitiators)) && - (($target eq '') || ($driver eq '') || ($group eq ''))) { + (!defined($target) || !defined($driver) || !defined($group))) { print "Please specify -driver -target and -group with ". "-add_init/-rem_init/-clear_inits.\n"; exit 1; } if (defined($moveInitiator) && - (($driver eq '') || ($target eq '') || ($group eq '') || ($to eq ''))) { + (!defined($driver) || !defined($target) || !defined($group) || !defined($to))) { print "Please specify -driver -target -group and -to with -move_init.\n"; exit 1; } if ((defined($addLun) || defined($replaceLun)) && - (($driver eq '') || ($target eq '') || ($device eq ''))) { + (!defined($driver) || !defined($target) || !defined($device))) { print "Please specify -driver -target and -device with -add_lun/-replace_lun.\n"; exit 1; } - if ((defined($clearLuns) || defined($removeLun)) && (($driver eq '') || ($target eq ''))) { + if ((defined($clearLuns) || defined($removeLun)) && (!defined($driver) || !defined($target))) { print "Please specify -driver and -target with -rem_lun/-clear_luns.\n"; exit 1; } - if ((defined($addDevGroupDevice) || defined($removeDevGroupDevice)) && ($deviceGroup eq '')) { + if ((defined($addDevGroupDevice) || defined($removeDevGroupDevice)) && !defined($deviceGroup)) { print "Please specify -dev_group with -add_dgrp_dev/-rem_dgrp_dev.\n"; exit 1; } - if ((defined($addTargetGroup) || defined($removeTargetGroup)) && ($deviceGroup eq '')) { + if ((defined($addTargetGroup) || defined($removeTargetGroup)) && !defined($deviceGroup)) { print "Please specify -dev_group with -add_tgrp/-rem_tgrp.\n"; exit 1; } if ((defined($addTargetGroupTarget) || defined($removeTargetGroupTarget)) && - (($deviceGroup eq '') || ($targetGroup eq ''))) { + (!defined($deviceGroup) || !defined($targetGroup))) { print "Please specify -dev_group and -tgt_group with -add_tgrp_tgt/-rem_tgrp_tgt.\n"; exit 1; } From 477c49a7a6d651ca136a893dfc0d0204cd3e3475 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 Feb 2019 22:05:12 +0000 Subject: [PATCH 18/42] scstadmin: Fix regression test 07 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7945 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/t/07-scstadmin-args.t | 138 +++++++++++++++--- 1 file changed, 121 insertions(+), 17 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t index a31ef042f..d252696eb 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t @@ -112,9 +112,7 @@ sub run { my $rc; $rc = system("$cmd >$tmpfile 2>&1"); - if ($rc != 0) { - $res = "exit code $rc"; - } elsif (!open(my $file, $tmpfile)) { + if (!open(my $file, $tmpfile)) { $res = "failed to read $tmpfile"; } else { local $/ = undef; @@ -193,8 +191,15 @@ All done. EOS ok(run("$scstadmin -list_dgrp"), $result); - $result = "exit code 256"; - ok(run("$scstadmin -list_tgrp tgrp"), $result); + $result = " +Collecting current configuration: done. + + Targets + ------- + +All done. +"; + ok(run("$scstadmin -list_tgrp tgrp -dev_group dgroup1"), $result); $result = <<'EOS'; @@ -389,9 +394,30 @@ All done. EOS ok(run("$scstadmin -list_hnd_attr vdisk_nullio"), $result); - $result = "exit code 256"; - ok(run("$scstadmin -list_dev_attr disk00"), $result); - ok(run("$scstadmin -list_dev_attr disk01"), $result); + $result = " +Collecting current configuration: done. + + Attribute Value Writable KEY + ------------------------------------------------------------------------ + filename /dev/scstadmin-regression-test-vdisk Yes Yes + read_only 1 No Yes + size 1048576 No Yes + +All done. +"; + ok(run("$scstadmin -list_dev_attr disk0"), $result); + $result = " +Collecting current configuration: done. + + Attribute Value Writable KEY + ------------------------------------------------------------------------ + filename /dev/scstadmin-regression-test-vdisk Yes Yes + nv_cache 1 No Yes + size 1048576 No Yes + +All done. +"; + ok(run("$scstadmin -list_dev_attr disk1"), $result); $result = <<'EOS'; @@ -405,15 +431,93 @@ All done. EOS ok(run("$scstadmin -list_drv_attr ib_srpt"), $result); - $result = "exit code 256"; - ok(run("$scstadmin -list_tgrp_attr"), $result); - ok(run("$scstadmin -list_tgtt_attr"), $result); - ok(run("$scstadmin -list_tgt_attr local"), $result); - ok(run("$scstadmin -list_grp_attr ig"), $result); - ok(run("$scstadmin -list_lun_attr 0"), $result); - ok(run("$scstadmin -list_lun_attr 1"), $result); - ok(run("$scstadmin -list_init_attr ini1"), $result); - ok(run("$scstadmin -list_init_attr ini2"), $result); + $result = " +Collecting current configuration: done. + + Attribute Value Writable KEY + ------------------------------------------ + group_id 256 Yes Yes + state active Yes Yes + +All done. +"; + ok(run("$scstadmin -list_tgrp_attr tgroup1 -dev_group dgroup1"), $result); + $result = " +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + +All done. +"; + ok(run("$scstadmin -list_ttgt_attr local -tgt_group tgroup1 -dev_group dgroup1"), $result); + $result = " +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + + LUN CREATE attributes available + ------------------------------- + read_only + +All done. +"; + ok(run("$scstadmin -list_tgt_attr local -driver scst_local"), $result); + $result = " +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + + LUN CREATE attributes available + ------------------------------- + read_only + +All done. +"; + ok(run("$scstadmin -list_grp_attr ig -driver scst_local -target local -group ip"), $result); + $result = " +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + +All done. +"; + ok(run("$scstadmin -list_lun_attr 0 -driver scst_local -target local"), $result); + $result = "\nCollecting current configuration: done.\n\n\tAttribute Value Writable KEY\n\t-----------------------------------------\n\t(none)\n\nAll done.\n"; + ok(run("$scstadmin -list_lun_attr 1 -driver scst_local -target local -group ig"), $result); + $result = " +Collecting current configuration: done. + + + +WARNING: Received the following error: + + initiatorAttributes(): Unable to read directory '/sys/kernel/scst_tgt/targets/scst_local/local/ini_groups/ig/initiators/ini1': Bad file descriptor + + +All done. +"; + ok(run("$scstadmin -list_init_attr ini1 -driver scst_local -target local -group ig"), $result); + $result = " +Collecting current configuration: done. + + + +WARNING: Received the following error: + + initiatorAttributes(): Unable to read directory '/sys/kernel/scst_tgt/targets/scst_local/local/ini_groups/ig/initiators/ini2': Bad file descriptor + + +All done. +"; + ok(run("$scstadmin -list_init_attr ini2 -driver scst_local -target local -group ig"), $result); $result = <<'EOS'; Collecting current configuration: done. From 2da0ddd47d3552fab5c94162bf924a2183c10374 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 Feb 2019 22:07:35 +0000 Subject: [PATCH 19/42] scstadmin: Avoid passing 'undef' to chomp() This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7946 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/lib/SCST/SCST.pm | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm index 6ed59b059..fca271819 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm @@ -458,7 +458,8 @@ sub scstAttributes { } my $value = <$io>; - chomp $value if (defined($value)); + $value = "" if (!defined($value)); + chomp $value; my $is_key = <$io>; $is_key = new_sysfs_interface() && !$is_static || @@ -772,10 +773,7 @@ sub aluaAttributes { } my $value = <$io>; - if (!defined($value)) { - $value = ""; - } - + $value = "" if (!defined($value)); chomp $value; my $second_line = <$io>; @@ -2768,6 +2766,7 @@ sub driverAttributes { } my $value = <$io>; + $value = "" if (!defined($value)); chomp $value; my $is_key = <$io>; @@ -2924,7 +2923,8 @@ sub targetAttributes { } my $value = <$io>; - chomp $value if (defined($value)); + $value = "" if (!defined($value)); + chomp $value; my $is_key = <$io>; close $io; @@ -3058,6 +3058,7 @@ sub groupAttributes { } my $value = <$io>; + $value = "" if (!defined($value)); chomp $value; my $is_key = <$io>; @@ -3213,6 +3214,7 @@ sub lunAttributes { } my $value = <$io>; + $value = "" if (!defined($value)); chomp $value; my $is_key = <$io>; @@ -3367,6 +3369,7 @@ sub initiatorAttributes { } my $value = <$io>; + $value = "" if (!defined($value)); chomp $value; my $is_key = <$io>; @@ -3489,6 +3492,7 @@ sub deviceGroupAttributes { } my $value = <$io>; + $value = "" if (!defined($value)); chomp $value; my $is_key = <$io>; @@ -3569,6 +3573,7 @@ sub targetGroupAttributes { } my $value = <$io>; + $value = "" if (!defined($value)); chomp $value; my $is_key = <$io>; @@ -3658,6 +3663,7 @@ sub targetGroupTargetAttributes { } my $value = <$io>; + $value = "" if (!defined($value)); chomp $value; my $is_key = <$io>; @@ -3940,7 +3946,8 @@ sub handlerAttributes { } my $value = <$io>; - chomp $value if (defined($value)); + $value = "" if (!defined($value)); + chomp $value; my $is_key = <$io>; $is_key = new_sysfs_interface() && !$is_static || @@ -4757,8 +4764,9 @@ sub sessions { } my $value = <$io>; - close $io; + $value = "" if (!defined($value)); chomp $value; + close $io; $_sessions{$session}->{$attribute}->{'value'} = $value; $_sessions{$session}->{$attribute}->{'static'} = $is_static; From f2b4c0d256d9dff1ba296c33d7a23da450fe6de0 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 17 Feb 2019 22:08:58 +0000 Subject: [PATCH 20/42] scstadmin: Restrict a source code line to 80 columns This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7947 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 95c71650f..67f504f20 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -3671,8 +3671,8 @@ sub listAttributes { } } - printf("\t%-*s %-*s %-*s %-*s\n", $l_attr, 'Attribute', $l_value, - 'Value', 9, 'Writable', 3, 'KEY'); + printf("\t%-*s %-*s %-*s %-*s\n", $l_attr, 'Attribute', + $l_value, 'Value', 9, 'Writable', 3, 'KEY'); print "\t"; for (my $x = 0; $x < ($l_attr + $l_value + 27); $x++) { print "-"; From 4f762acebdf753035819d0fd792d786951f896e3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 00:34:03 +0000 Subject: [PATCH 21/42] scstadmin: Set remote targets and remote rel_tgt_ids in test 07 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7948 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/t/07-result.conf | 8 ++++++++ .../scst-1.0.0/t/07-scstadmin-args.t | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-result.conf b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-result.conf index 628162104..01383a020 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-result.conf +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-result.conf @@ -47,6 +47,10 @@ DEVICE_GROUP dgroup1 { TARGET_GROUP tgroup2 { group_id 257 state active + + TARGET remote { + rel_tgt_id 11 + } } } @@ -61,6 +65,10 @@ DEVICE_GROUP dgroup2 { TARGET_GROUP tgroup2 { group_id 259 state active + + TARGET remote { + rel_tgt_id 12 + } } } diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t index d252696eb..f0a536cc9 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t @@ -22,7 +22,7 @@ BEGIN { unless(grep /blib/, @INC) { unshift(@INC, File::Spec->catdir($scstadmin_pm_dir, "lib")); } - plan tests => 55; + plan tests => 58; } use Data::Dumper; @@ -68,21 +68,28 @@ sub attributeTest { "-add_lun 0 -device disk0 $redirect"), 0); ok(system("$scstadmin -driver scst_local -target local -group ig " . "-add_lun 1 -device disk1 $redirect"), 0); + ok(system("$scstadmin -add_dgrp dgroup1 $redirect"), 0); - ok(system("$scstadmin -add_dgrp dgroup2 $redirect"), 0); ok(system("$scstadmin -add_tgrp tgroup1 -dev_group dgroup1 $redirect"), 0); ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup1 -dev_group dgroup1 -attributes group_id=256 $redirect"), 0); + ok(system("$scstadmin -add_tgrp_tgt local -dev_group dgroup1 -tgt_group tgroup1 $redirect"), 0); ok(system("$scstadmin -add_tgrp tgroup2 -dev_group dgroup1 $redirect"), 0); ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup2 -dev_group dgroup1 -attributes group_id=257 $redirect"), 0); + ok(system("$scstadmin -add_tgrp_tgt remote -dev_group dgroup1 -tgt_group tgroup2 $redirect"), 0); + ok(system("{ echo 11 > /sys/kernel/scst_tgt/device_groups/dgroup1/target_groups/tgroup2/remote/rel_tgt_id; } $redirect"), 0); + + ok(system("$scstadmin -add_dgrp dgroup2 $redirect"), 0); ok(system("$scstadmin -add_tgrp tgroup1 -dev_group dgroup2 $redirect"), 0); ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup1 -dev_group dgroup2 -attributes group_id=258 $redirect"), 0); + ok(system("$scstadmin -add_tgrp_tgt local -dev_group dgroup2 -tgt_group tgroup1 $redirect"), 0); ok(system("$scstadmin -add_tgrp tgroup2 -dev_group dgroup2 $redirect"), 0); ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup2 -dev_group dgroup2 -attributes group_id=259 $redirect"), 0); - ok(system("$scstadmin -add_tgrp_tgt local -dev_group dgroup1 -tgt_group tgroup1 $redirect"), 0); - ok(system("$scstadmin -add_tgrp_tgt local -dev_group dgroup2 -tgt_group tgroup1 $redirect"), 0); - ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup1 -dev_group dgroup1 -attributes rel_tgt_id=1 $redirect"), 0); ok(system("$scstadmin -noprompt -set_tgrp_attr tgroup1 -dev_group dgroup2 -attributes rel_tgt_id=2 $redirect"), 0); + ok(system("$scstadmin -add_tgrp_tgt remote -dev_group dgroup2 -tgt_group tgroup2 $redirect"), 0); + ok(system("{ echo 12 > /sys/kernel/scst_tgt/device_groups/dgroup2/target_groups/tgroup2/remote/rel_tgt_id; } $redirect"), 0); + ok(system("$scstadmin -write_config $tmpfilename1 >/dev/null"), 0); + # Keep only the scst_local target driver information. my $cmd = "gawk 'BEGIN { t = 0 } /^# Automatically generated by SCST Configurator v/ {" . '$0 = "# Automatically generated by SCST Configurator v..." } ' . @@ -556,7 +563,7 @@ EOS my $_DEBUG_ = 0; if ($_DEBUG_) { - $redirect = ">>$redirect_file"; + $redirect = ">>$redirect_file 2>&1"; open(my $logfile, '>>', $redirect_file); select $logfile; } else { From 27d90a356337d18b5693132626ddc602da064372 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 00:34:48 +0000 Subject: [PATCH 22/42] scstadmin: Improve the consistency of test 07 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7949 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/t/07-scstadmin-args.t | 74 +++++++++++++------ 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t index f0a536cc9..0c3227499 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t @@ -198,14 +198,15 @@ All done. EOS ok(run("$scstadmin -list_dgrp"), $result); - $result = " + $result = <<'EOS'; + Collecting current configuration: done. Targets ------- All done. -"; +EOS ok(run("$scstadmin -list_tgrp tgrp -dev_group dgroup1"), $result); $result = <<'EOS'; @@ -222,6 +223,7 @@ Collecting current configuration: done. All done. EOS ok(run("$scstadmin -list_driver"), $result); + $result = <<'EOS'; Collecting current configuration: done. @@ -281,7 +283,6 @@ All done. EOS ok(run("$scstadmin -list_group"), $result); - $result = <<'EOS'; Collecting current configuration: done. @@ -293,6 +294,7 @@ Collecting current configuration: done. All done. EOS ok(run("$scstadmin -list_scst_attr"), $result); + $result = <<'EOS'; Collecting current configuration: done. @@ -373,6 +375,7 @@ Collecting current configuration: done. All done. EOS ok(run("$scstadmin -list_hnd_attr vdisk_fileio"), $result); + $result = <<'EOS'; Collecting current configuration: done. @@ -401,7 +404,8 @@ All done. EOS ok(run("$scstadmin -list_hnd_attr vdisk_nullio"), $result); - $result = " + $result = <<'EOS'; + Collecting current configuration: done. Attribute Value Writable KEY @@ -411,9 +415,11 @@ Collecting current configuration: done. size 1048576 No Yes All done. -"; +EOS ok(run("$scstadmin -list_dev_attr disk0"), $result); - $result = " + + $result = <<'EOS'; + Collecting current configuration: done. Attribute Value Writable KEY @@ -423,7 +429,7 @@ Collecting current configuration: done. size 1048576 No Yes All done. -"; +EOS ok(run("$scstadmin -list_dev_attr disk1"), $result); $result = <<'EOS'; @@ -438,7 +444,8 @@ All done. EOS ok(run("$scstadmin -list_drv_attr ib_srpt"), $result); - $result = " + $result = <<'EOS'; + Collecting current configuration: done. Attribute Value Writable KEY @@ -447,9 +454,11 @@ Collecting current configuration: done. state active Yes Yes All done. -"; +EOS ok(run("$scstadmin -list_tgrp_attr tgroup1 -dev_group dgroup1"), $result); - $result = " + + $result = <<'EOS'; + Collecting current configuration: done. Attribute Value Writable KEY @@ -457,9 +466,11 @@ Collecting current configuration: done. (none) All done. -"; +EOS ok(run("$scstadmin -list_ttgt_attr local -tgt_group tgroup1 -dev_group dgroup1"), $result); - $result = " + + $result = <<'EOS'; + Collecting current configuration: done. Attribute Value Writable KEY @@ -471,9 +482,11 @@ Collecting current configuration: done. read_only All done. -"; +EOS ok(run("$scstadmin -list_tgt_attr local -driver scst_local"), $result); - $result = " + + $result = <<'EOS'; + Collecting current configuration: done. Attribute Value Writable KEY @@ -485,9 +498,11 @@ Collecting current configuration: done. read_only All done. -"; +EOS ok(run("$scstadmin -list_grp_attr ig -driver scst_local -target local -group ip"), $result); - $result = " + + $result = <<'EOS'; + Collecting current configuration: done. Attribute Value Writable KEY @@ -495,11 +510,23 @@ Collecting current configuration: done. (none) All done. -"; +EOS ok(run("$scstadmin -list_lun_attr 0 -driver scst_local -target local"), $result); - $result = "\nCollecting current configuration: done.\n\n\tAttribute Value Writable KEY\n\t-----------------------------------------\n\t(none)\n\nAll done.\n"; + + $result = <<'EOS'; + +Collecting current configuration: done. + + Attribute Value Writable KEY + ----------------------------------------- + (none) + +All done. +EOS ok(run("$scstadmin -list_lun_attr 1 -driver scst_local -target local -group ig"), $result); - $result = " + + $result = <<'EOS'; + Collecting current configuration: done. @@ -510,9 +537,11 @@ WARNING: Received the following error: All done. -"; +EOS ok(run("$scstadmin -list_init_attr ini1 -driver scst_local -target local -group ig"), $result); - $result = " + + $result = <<'EOS'; + Collecting current configuration: done. @@ -523,8 +552,9 @@ WARNING: Received the following error: All done. -"; +EOS ok(run("$scstadmin -list_init_attr ini2 -driver scst_local -target local -group ig"), $result); + $result = <<'EOS'; Collecting current configuration: done. From c4cc4bdcbca19ea148cd58d3fe2c5d6405da135a Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 00:38:50 +0000 Subject: [PATCH 23/42] scstadmin: Avoid dereferencing variables that have the value undef git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7950 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm index fca271819..e66934ece 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm @@ -777,6 +777,7 @@ sub aluaAttributes { chomp $value; my $second_line = <$io>; + $second_line = "" if (!defined($second_line)); if (new_sysfs_interface() && !$is_static || ($second_line =~ /\[key\]/)) { my $key = 0; @@ -2633,6 +2634,7 @@ sub deviceAttributes { } elsif ($linked =~ /^(\.\.\/)*$t\/([^\/]+)\/([^\/]+)\/$l\/(\d+)$/) { $driver = $2; $target = $3; + $group = ""; $lun = $4; } else { print("internal error: could not parse $linked\n"); From bad428c6152b778e68eb6f0e8d784c3b931fbd16 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 00:40:23 +0000 Subject: [PATCH 24/42] scstadmin: Initialize container variables explicitly git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7951 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/lib/SCST/SCST.pm | 36 +++++++++---------- scstadmin/scstadmin.sysfs/scstadmin | 8 ++--- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm index e66934ece..bef8acf58 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm @@ -422,7 +422,7 @@ sub scstVersion { sub scstAttributes { my $self = shift; - my %attributes; + my %attributes = ( ); my $pHandle = new IO::Handle; my $_path = SCST_ROOT_DIR(); @@ -747,7 +747,7 @@ sub luns { sub aluaAttributes { my $self = shift; - my %attributes; + my %attributes = ( ); my $pHandle = new IO::Handle; my $_path = SCST_DEV_GROUP_DIR(); @@ -940,7 +940,7 @@ sub driverExists { sub driverDynamicAttributes { my $self = shift; my $driver = shift; - my %attributes; + my %attributes = ( ); my $available; my $errorString; @@ -1223,7 +1223,7 @@ sub addVirtualTarget { sub targetDynamicAttributes { my $self = shift; my $driver = shift; - my %attributes; + my %attributes = ( ); my $available; my $errorString; @@ -2588,7 +2588,7 @@ sub deviceOpen { sub deviceAttributes { my $self = shift; my $device = shift; - my %attributes; + my %attributes = ( ); my $errorString; my $dca; @@ -2726,7 +2726,7 @@ sub deviceAttributes { sub driverAttributes { my $self = shift; my $driver = shift; - my %attributes; + my %attributes = ( ); my $errorString; my $pHandle = new IO::Handle; @@ -2858,7 +2858,7 @@ sub targetAttributes { my $self = shift; my $driver = shift; my $target = shift; - my %attributes; + my %attributes = ( ); my $errorString; return (undef, "Too few arguments") if (!defined($driver) || !defined($target)); @@ -3011,7 +3011,7 @@ sub groupAttributes { my $driver = shift; my $target = shift; my $group = shift; - my %attributes; + my %attributes = ( ); my $errorString; my $pHandle = new IO::Handle; @@ -3151,7 +3151,7 @@ sub lunAttributes { my $lun = shift; my $group = shift; my $errorString; - my %attributes; + my %attributes = ( ); my ($_path, $luncrattr); @@ -3321,7 +3321,7 @@ sub initiatorAttributes { my $target = shift; my $group = shift; my $initiator = shift; - my %attributes; + my %attributes = ( ); my $errorString; my $pHandle = new IO::Handle; @@ -3453,7 +3453,7 @@ sub setInitiatorAttribute { sub deviceGroupAttributes { my $self = shift; my $group = shift; - my %attributes; + my %attributes = ( ); my $errorString; my $pHandle = new IO::Handle; @@ -3532,7 +3532,7 @@ sub targetGroupAttributes { my $self = shift; my $group = shift; my $tgroup = shift; - my %attributes; + my %attributes = ( ); my $errorString; my $pHandle = new IO::Handle; @@ -3615,7 +3615,7 @@ sub targetGroupTargetAttributes { my $tgroup = shift; my $tgt = shift; my $local_tgt = shift; - my %attributes; + my %attributes = ( ); my $errorString; my $pHandle = new IO::Handle; @@ -3906,7 +3906,7 @@ sub setHandlerAttribute { sub handlerAttributes { my $self = shift; my $handler = shift; - my %attributes; + my %attributes = ( ); my $errorString; my $a; @@ -4108,7 +4108,7 @@ sub deviceCreateAttributes { my $self = shift; my $handler = shift; my $available; - my %attributes; + my %attributes = ( ); my $errorString; if (new_sysfs_interface()) { @@ -4328,7 +4328,7 @@ sub targetCreateAttributes { my $self = shift; my $driver = shift; my $available; - my %attributes; + my %attributes = ( ); my $errorString; if (new_sysfs_interface()) { @@ -4520,7 +4520,7 @@ sub lunCreateAttributes { my $target = shift; my $group = shift; my $available; - my %attributes; + my %attributes = ( ); my $errorString; my $_path; @@ -4642,7 +4642,7 @@ sub initiatorCreateAttributes { my $target = shift; my $group = shift; my $available; - my %attributes; + my %attributes = ( ); my $errorString; if (new_sysfs_interface()) { diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 67f504f20..c15b78cd4 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -1484,7 +1484,7 @@ sub serializeKeyAttr { my $prefix = shift; my $attributes = shift; my $attr_filter = shift; - my $result; + my $result = ""; foreach my $attribute (sort keys %{$attributes}) { next if defined($$attributes{$attribute}->{'set'}); @@ -1520,7 +1520,7 @@ sub serializeNkAttr { my $prefix = shift; my $attributes = shift; my $attr_filter = shift; - my $result; + my $result = ""; foreach my $attribute (sort keys %{$attributes}) { if (!defined($$attributes{$attribute}->{'set'}) @@ -3431,7 +3431,7 @@ sub listSessions { foreach my $session (keys %{$sessions}) { print "\tSession: $session\n\n"; - my %attributes; + my %attributes = ( ); foreach my $attr (keys %{$$sessions{$session}}) { if ($attr eq 'luns') { foreach my $lun (keys %{$$sessions{$session}->{'luns'}}) { @@ -5840,7 +5840,7 @@ sub arrayHasValue { sub configToAttr { my $config = shift; - my %attributes; + my %attributes = ( ); foreach my $attr (keys %{$config}) { if (!scalar keys %{$$config{$attr}}) { From a1b1a880afe13b87bcc909dfb87c742a44d534aa Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 00:41:48 +0000 Subject: [PATCH 25/42] scstadmin: Remove a superfluous declaration git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7952 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 2 -- 1 file changed, 2 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index c15b78cd4..810b2883f 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -831,8 +831,6 @@ sub getArgs { } sub main { - my $rc = 0; - STDOUT->autoflush(1); # We need to run as root From b79fa94a27dddfff6e9d015dca409a12dbb96cd2 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 00:46:27 +0000 Subject: [PATCH 26/42] scstadmin: Initialize container variables explicitly git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7953 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 77 ++++++++++++++--------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 810b2883f..60dcfb0da 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -1593,8 +1593,8 @@ sub writeConfiguration { } foreach my $handler (sort keys %{$CURRENT{'handler'}}) { - my $handler_buff; - my $handler_buff_nk; + my $handler_buff = ""; + my $handler_buff_nk = ""; my $handler_attrs; my $attributes; @@ -1605,13 +1605,13 @@ sub writeConfiguration { my $devices = $CURRENT{'handler'}->{$handler}; - my $device_buff; + my $device_buff = ""; foreach my $device (sort @{$devices}) { $device_buff .= "\tDEVICE $device"; my $attributes; - my $attribute_buff; - my $attribute_buff_nk; + my $attribute_buff = ""; + my $attribute_buff_nk = ""; ($attributes, $errorString) = $SCST->deviceAttributes($device); $attribute_buff = serializeKeyAttr("\t\t", $attributes, $handler_attrs); @@ -1652,11 +1652,11 @@ sub writeConfiguration { } foreach my $driver (sort keys %{$CURRENT{'assign'}}) { - my $driver_buff; + my $driver_buff = ""; my $drv_attrs; - my $drv_attr_buff; - my $drv_attr_buff_nk; + my $drv_attr_buff = ""; + my $drv_attr_buff_nk = ""; ($drv_attrs, $errorString) = $SCST->driverAttributes($driver); $drv_attr_buff = serializeKeyAttr("\t", $drv_attrs); @@ -1668,13 +1668,13 @@ sub writeConfiguration { my $tgt_attrs; ($tgt_attrs, $errorString) = $SCST->targetCreateAttributes($driver); - my $target_buff; + my $target_buff = ""; foreach my $target (sort keys %{$targets}) { $target_buff .= "\tTARGET $target"; my $attributes; - my $attribute_buff; - my $attribute_buff_nk; + my $attribute_buff = ""; + my $attribute_buff_nk = ""; ($attributes, $errorString) = $SCST->targetAttributes($driver, $target); if (defined($$attributes{'hw_target'}) && @@ -1691,7 +1691,7 @@ sub writeConfiguration { my $lun_attrs; ($lun_attrs, $errorString) = $SCST->lunCreateAttributes($driver, $target); - my $t_lun_buff; + my $t_lun_buff = ""; foreach my $lun (sort numerically keys %{$luns}) { my $lun_dev = $$luns{$lun}; @@ -1733,7 +1733,7 @@ sub writeConfiguration { my $groups = $CURRENT{'assign'}->{$driver}->{$target}->{'GROUP'}; - my $group_buff; + my $group_buff = ""; foreach my $group (sort keys %{$groups}) { my $lun_attrs; my $ini_attrs; @@ -1744,7 +1744,7 @@ sub writeConfiguration { my $luns = $CURRENT{'assign'}->{$driver}->{$target}->{'GROUP'}->{$group}->{'LUN'}; - my $lun_buff; + my $lun_buff = ""; foreach my $lun (sort numerically keys %{$luns}) { my $lun_dev = $$luns{$lun}; @@ -1779,7 +1779,7 @@ sub writeConfiguration { my $inits = $CURRENT{'assign'}->{$driver}->{$target}->{'GROUP'}->{$group}->{'INITIATORS'}; - my $init_buff; + my $init_buff = ""; foreach my $init (sort @{$inits}) { $init_buff .= "\n\t\t\tINITIATOR " . escapeMeta($init); @@ -1897,10 +1897,10 @@ sub writeConfiguration { } foreach my $dgroup (sort keys %{$CURRENT{'dgroups'}}) { - my $dgroup_buff; + my $dgroup_buff = ""; my $dgroup_attrs; - my $dgrp_attr_buff; - my $dgrp_attr_buff_nk; + my $dgrp_attr_buff = ""; + my $dgrp_attr_buff_nk = ""; ($dgroup_attrs, $errorString) = $SCST->deviceGroupAttributes($dgroup); $dgrp_attr_buff = serializeKeyAttr("\t", $dgroup_attrs); @@ -1908,7 +1908,7 @@ sub writeConfiguration { $dgrp_attr_buff .= "\n" if ($dgrp_attr_buff); $dgrp_attr_buff_nk .= "\n" if ($dgrp_attr_buff_nk); - my $devices_buff; + my $devices_buff = ""; my $devices = $CURRENT{'dgroups'}->{$dgroup}->{'devices'}; @@ -1920,14 +1920,14 @@ sub writeConfiguration { my $tgroups = $CURRENT{'dgroups'}->{$dgroup}->{'tgroups'}; - my $tgroup_buff; + my $tgroup_buff = ""; foreach my $tgroup (sort keys %{$tgroups}) { $tgroup_buff .= "\tTARGET_GROUP $tgroup"; my $attributes; - my $attribute_buff; - my $attribute_buff_nk; + my $attribute_buff = ""; + my $attribute_buff_nk = ""; ($attributes, $errorString) = $SCST->targetGroupAttributes($dgroup, $tgroup); $attribute_buff .= serializeKeyAttr("\t\t", $attributes); @@ -1937,7 +1937,7 @@ sub writeConfiguration { my $tgts = $CURRENT{'dgroups'}->{$dgroup}->{'tgroups'}->{$tgroup}->{'targets'}; - my $tgt_buff; + my $tgt_buff = ""; foreach my $tgt (@{$tgts}) { $tgt_buff .= "\t\tTARGET $tgt"; @@ -3051,7 +3051,7 @@ sub listHandlers { my ($handlers, $errorString) = $SCST->handlers(); - my $l_handler; + my $l_handler = 0; foreach my $handler (@{$handlers}) { $l_handler = length($handler) if ($l_handler < length($handler)); } @@ -3077,9 +3077,8 @@ sub listHandler { my $got_handler = ($handler ne ''); my ($handlers, $errorString) = $SCST->handlers(); - my $l_device; - my $l_handler; - + my $l_device = 0; + my $l_handler = 0; foreach my $_handler (@{$handlers}) { $handler = $_handler if (!$got_handler); @@ -3166,7 +3165,7 @@ sub listDeviceGroups { my ($groups, $errorString) = $SCST->deviceGroups(); - my $l_group; + my $l_group = 0; foreach my $group (@{$groups}) { $l_group = length($group) if ($l_group < length($group)); } @@ -3193,7 +3192,7 @@ sub listDeviceGroup { my ($devices, $errorString) = $SCST->deviceGroupDevices($group); - my $l_device; + my $l_device = 0; foreach my $device (@{$devices}) { $l_device = length($device) if ($l_device < length($device)); } @@ -3213,7 +3212,7 @@ sub listDeviceGroup { my ($tgroups, $errorString) = $SCST->targetGroups($group); - my $l_tgroup; + my $l_tgroup = 0; foreach my $tgroup (@{$tgroups}) { $l_tgroup = length($tgroup) if ($l_tgroup < length($tgroup)); } @@ -3244,7 +3243,7 @@ sub listTargetGroups { my ($tgroups, $errorString) = $SCST->targetGroups($group); - my $l_tgroup; + my $l_tgroup = 0; foreach my $tgroup (@{$tgroups}) { $l_tgroup = length($tgroup) if ($l_tgroup < length($tgroup)); } @@ -3275,7 +3274,7 @@ sub listTargetGroup { my ($targets, $errorString) = $SCST->targetGroupTargets($group, $tgroup); - my $l_tgt; + my $l_tgt = 0; foreach my $tgt (@{$targets}) { $l_tgt = length($tgt) if ($l_tgt < length($tgt)); } @@ -3304,7 +3303,7 @@ sub listDeviceGroupDevices { my ($devices, $errorString) = $SCST->deviceGroupDevices($group); - my $l_device; + my $l_device = 0; foreach my $device (@{$devices}) { $l_device = length($device) if ($l_device < length($device)); } @@ -3332,7 +3331,7 @@ sub listDrivers { my ($drivers, $errorString) = $SCST->drivers(); - my $l_driver; + my $l_driver = 0; foreach my $driver (@{$drivers}) { $l_driver = length($driver) if ($l_driver < length($driver)); } @@ -3362,9 +3361,8 @@ sub listTargets { my ($drivers, $errorString) = $SCST->drivers(); - my $l_driver; - my $l_target; - + my $l_driver = 0; + my $l_target = 0; foreach my $_driver (@{$drivers}) { $driver = $_driver if (!$got_driver); @@ -3472,13 +3470,12 @@ sub listGroup { } if ((keys %{$luns}) || ($#{$initiators} > -1)) { - my $l_device; - my $l_initiator; - + my $l_device = 0; foreach my $lun (keys %{$luns}) { $l_device = length($$luns{$lun}) if (length($$luns{$lun}) > $l_device); } + my $l_initiator = 0; foreach my $initiator (@{$initiators}) { $l_initiator = length($initiator) if (length($initiator) > $l_initiator); } From bf45a6162f103c22dbe26879cd3ee328a682814f Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 01:29:40 +0000 Subject: [PATCH 27/42] scstadmin: Add a test that causes scstadmin to display a prompt git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7954 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/t/07-scstadmin-args.t | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t index 0c3227499..7c458d074 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t @@ -22,7 +22,7 @@ BEGIN { unless(grep /blib/, @INC) { unshift(@INC, File::Spec->catdir($scstadmin_pm_dir, "lib")); } - plan tests => 58; + plan tests => 59; } use Data::Dumper; @@ -134,6 +134,16 @@ sub run { return $res; } +# Trigger the scstadmin prompt() subroutine. +sub testPrompt { + my $result; + + $result = <<'EOS'; +are you sure you wish to continue (y/[n]) ? +EOS + ok(run("$scstadmin -clear_config -force catfile($testdir, "07-result.conf")); +testPrompt(); + listTest(); teardown(); From 9fb607fe1230073a43fb35621b2faa91184fafc8 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 01:30:13 +0000 Subject: [PATCH 28/42] scstadmin: Check $answer before using it git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7955 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 60dcfb0da..3b10e9b6c 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -5929,7 +5929,8 @@ sub prompt { "are you sure you wish to continue (y/[n]) ? "; my $answer = ; - if (($answer =~ /^y$/i) || ($answer =~ /^yes$/i)) { + if (defined($answer) && + (($answer =~ /^y$/i) || ($answer =~ /^yes$/i))) { return FALSE; } From 1eae6633b4d0852162da10fd6fb9a814f4614af8 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 01:38:14 +0000 Subject: [PATCH 29/42] scstadmin: Fix Perl warnings Modify those constructs that trigger warnings with 'use warnings'. This patch does not modify any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7956 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 40 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 3b10e9b6c..79d71ad08 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -1466,7 +1466,7 @@ sub readWorkingConfig { sub escapeMeta { my $value = shift; - $value =~ s/([\\\#])/\\\1/g; + $value =~ s/([\\\#])/\\$1/g; if ($value =~ / /) { $value = "\"$value\""; } @@ -1548,10 +1548,11 @@ sub isPassthroughDev { foreach my $handler (keys %{$CURRENT{'handler'}}) { my $ha; ($ha, $errorString) = $SCST->handlerAttributes($handler); - next if ($ha->{'mgmt'} !~ 'echo "add_device H:C:I:L"'); + next if (defined($ha->{'mgmt'}) && + $ha->{'mgmt'} !~ 'echo "add_device H:C:I:L"'); my @devs = @{$CURRENT{'handler'}->{$handler}}; for my $i (0 .. $#devs) { - if ($dev eq @devs[$i]) { + if ($dev eq $devs[$i]) { $pt = TRUE; last; } @@ -3074,7 +3075,7 @@ sub listHandler { my $handler = shift; my %toprint; - my $got_handler = ($handler ne ''); + my $got_handler = defined($handler); my ($handlers, $errorString) = $SCST->handlers(); my $l_device = 0; @@ -3189,10 +3190,11 @@ sub listDeviceGroups { sub listDeviceGroup { my $group = shift; - - my ($devices, $errorString) = $SCST->deviceGroupDevices($group); - + my $errorString; + my $devices; my $l_device = 0; + + ($devices, $errorString) = $SCST->deviceGroupDevices($group); foreach my $device (@{$devices}) { $l_device = length($device) if ($l_device < length($device)); } @@ -3210,9 +3212,10 @@ sub listDeviceGroup { print "\t$device\n"; } - my ($tgroups, $errorString) = $SCST->targetGroups($group); - + my $tgroups; my $l_tgroup = 0; + + ($tgroups, $errorString) = $SCST->targetGroups($group); foreach my $tgroup (@{$tgroups}) { $l_tgroup = length($tgroup) if ($l_tgroup < length($tgroup)); } @@ -3357,7 +3360,7 @@ sub listTargets { return listGroups($driver, $target, undef) if (($target ne '') && ($driver ne '')); - my $got_driver = ($driver ne ''); + my $got_driver = defined($driver); my ($drivers, $errorString) = $SCST->drivers(); @@ -3464,7 +3467,7 @@ sub listGroup { my $errorString; ($luns, $errorString) = $SCST->luns($driver, $target, $group) if (!$luns); - if (($initiators eq '') && ($group ne '')) { + if (($initiators eq '') && defined($group)) { ($initiators, $errorString) = $SCST->initiators($driver, $target, $group); return TRUE if issueWarning($errorString); } @@ -5450,7 +5453,7 @@ sub readConfigFile { } } - $line =~ s/\\(.)/\1/g; + $line =~ s/\\(.)/$1/g; $buffer .= $line; } @@ -5489,8 +5492,11 @@ sub parseStanza { if ($char eq "\n") { my %empty; - parseLine($line, \%hash, \%empty); - $line = undef; + + if ($line) { + parseLine($line, \%hash, \%empty); + $line = undef; + } } else { $line .= $char; } @@ -5513,9 +5519,9 @@ sub parseLine { push @elements, defined($1) ? $1:$3; } - my $attribute = @elements[0]; - my $value = @elements[1]; - my $value2 = @elements[2]; + my $attribute = $elements[0]; + my $value = $elements[1]; + my $value2 = $elements[2]; if (defined($attribute) && defined($value) && defined($value2)) { $$hash{$attribute}->{$value}->{$value2} = $child; From 4ed48121e321f07351b99773018245d899d1a062 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 01:40:37 +0000 Subject: [PATCH 30/42] scstadmin: Update expected output of test 07 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7957 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t index 7c458d074..8d299cbd1 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/t/07-scstadmin-args.t @@ -139,7 +139,12 @@ sub testPrompt { my $result; $result = <<'EOS'; -are you sure you wish to continue (y/[n]) ? + +Collecting current configuration: done. + +Performing this action may result in lost or corrupt data, are you sure you wish to continue (y/[n]) ? Aborting action. + +All done. EOS ok(run("$scstadmin -clear_config -force Date: Mon, 18 Feb 2019 01:45:42 +0000 Subject: [PATCH 31/42] scstadmin: Avoid triggering Perl warnings git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7958 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 79d71ad08..ed5f9a856 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -3467,7 +3467,7 @@ sub listGroup { my $errorString; ($luns, $errorString) = $SCST->luns($driver, $target, $group) if (!$luns); - if (($initiators eq '') && defined($group)) { + if (!defined($initiators) && defined($group)) { ($initiators, $errorString) = $SCST->initiators($driver, $target, $group); return TRUE if issueWarning($errorString); } From 906c18ae832e275ee76f95b476dcd550074a72cb Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 01:49:44 +0000 Subject: [PATCH 32/42] scstadmin: Update copyright git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7959 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm | 2 +- scstadmin/scstadmin.sysfs/scstadmin | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm index bef8acf58..75d14a76a 100644 --- a/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm @@ -5,7 +5,7 @@ package SCST::SCST; # Author: Mark R. Buechler # License: GPLv2 # Copyright (c) 2005-2011 Mark R. Buechler -# Copyright (c) 2011-2015 Bart Van Assche . +# Copyright (c) 2011-2019 Bart Van Assche . use 5.005; use Fcntl ':mode'; diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index ed5f9a856..8a1b50642 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -7,7 +7,7 @@ $Version = 'SCST Configurator v3.3.0-pre1'; # Author: Mark R. Buechler # License: GPLv2 # Copyright (c) 2005-2011 Mark R. Buechler -# Copyright (C) 2011-2015 Bart Van Assche +# Copyright (C) 2011-2019 Bart Van Assche sub usage { From 281801a266b3b311db6982dcebe41e41deaa5eb2 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 01:51:36 +0000 Subject: [PATCH 33/42] scstadmin: Make $Version a local variable git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7960 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 8a1b50642..89fbe6928 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -1,6 +1,6 @@ #!/usr/bin/perl -$Version = 'SCST Configurator v3.3.0-pre1'; +my $Version = 'SCST Configurator v3.3.0-pre1'; # Configures SCST # From 589dad39971df59a76a303a38950167106f7d1cc Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 22:18:06 +0000 Subject: [PATCH 34/42] scst: Rework the scst_data_direction enum Since there is no relationship between enum dma_data_direction and the SCST data direction enum, introduce a new enumeration type for the SCST data direction. This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7961 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst.h | 2 -- scst/include/scst_const.h | 12 +++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scst/include/scst.h b/scst/include/scst.h index 68027ec4b..ecaf73e14 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -759,8 +759,6 @@ struct scst_opcode_descriptor; */ #define NO_SUCH_LUN ((uint64_t)-1) -typedef enum dma_data_direction scst_data_direction; - /* * SCST target template: defines target driver's parameters and callback * functions. diff --git a/scst/include/scst_const.h b/scst/include/scst_const.h index cb0caa2ea..a232de5e9 100644 --- a/scst/include/scst_const.h +++ b/scst/include/scst_const.h @@ -239,11 +239,13 @@ enum scst_cdb_flags { ** Data direction aliases. Changing it don't forget to change ** scst_to_tgt_dma_dir and SCST_DATA_DIR_MAX as well!! *************************************************************/ -#define SCST_DATA_UNKNOWN 0 -#define SCST_DATA_WRITE 1 -#define SCST_DATA_READ 2 -#define SCST_DATA_BIDI (SCST_DATA_WRITE | SCST_DATA_READ) -#define SCST_DATA_NONE 4 +typedef enum scst_data_direction { + SCST_DATA_UNKNOWN = 0, + SCST_DATA_WRITE = 1, + SCST_DATA_READ = 2, + SCST_DATA_BIDI = (SCST_DATA_WRITE | SCST_DATA_READ), + SCST_DATA_NONE = 4, +} scst_data_direction; #define SCST_DATA_DIR_MAX (SCST_DATA_NONE+1) From 5dfaf65dfc49d51d88405d6a1c3ba807cf741098 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 22:20:58 +0000 Subject: [PATCH 35/42] scst_vdisk: Make the 'async' attribute modifiable Make it possible to change the 'async' attribute after a virtual disk device has been created. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7962 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 228ae222b..663e32903 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -511,6 +511,8 @@ static ssize_t vdev_sysfs_inq_vend_specific_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf); static ssize_t vdev_zero_copy_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf); +static ssize_t vdev_async_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count); static ssize_t vdev_async_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf); static ssize_t vdev_dif_filename_show(struct kobject *kobj, @@ -612,7 +614,7 @@ static struct kobj_attribute vdev_inq_vend_specific_attr = static struct kobj_attribute vdev_zero_copy_attr = __ATTR(zero_copy, S_IRUGO, vdev_zero_copy_show, NULL); static struct kobj_attribute vdev_async_attr = - __ATTR(async, S_IRUGO, vdev_async_show, NULL); + __ATTR(async, S_IWUSR|S_IRUGO, vdev_async_show, vdev_async_store); static struct kobj_attribute vdev_dif_filename_attr = __ATTR(dif_filename, S_IRUGO, vdev_dif_filename_show, NULL); @@ -10441,6 +10443,28 @@ static ssize_t vdev_zero_copy_show(struct kobject *kobj, return pos; } +static ssize_t vdev_async_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct scst_device *dev = + container_of(kobj, struct scst_device, dev_kobj); + struct scst_vdisk_dev *virt_dev = dev->dh_priv; + long val; + int res; + + res = kstrtol(buf, 0, &val); + if (res) + return res; + if (val != !!val) + return -EINVAL; + + spin_lock(&virt_dev->flags_lock); + virt_dev->async = val; + spin_unlock(&virt_dev->flags_lock); + + return count; +} + static ssize_t vdev_async_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { From 9649e0af962067f813a6478cf3c08dd55108ecf7 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 22:21:23 +0000 Subject: [PATCH 36/42] scst_vdisk: Add a comment git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7963 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 663e32903..c392b7489 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -7850,6 +7850,10 @@ out: return; } +/* + * Parse the add_device parameters. @allowed_params restricts which + * parameters can be specified at device creation time. + */ static int vdev_parse_add_dev_params(struct scst_vdisk_dev *virt_dev, char *params, const char *const allowed_params[]) { From f5709940008265e8de999af82af543aac5d317b7 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 22:27:04 +0000 Subject: [PATCH 37/42] scst: Change add_device_parameters from a string into an array This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7964 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst.h | 7 +- scst/src/dev_handlers/scst_vdisk.c | 121 ++++++++++++++++------------- scst/src/scst_sysfs.c | 37 +++++++-- 3 files changed, 104 insertions(+), 61 deletions(-) diff --git a/scst/include/scst.h b/scst/include/scst.h index ecaf73e14..19281a170 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -1734,8 +1734,11 @@ struct scst_dev_type { /* Optional help string for mgmt_cmd commands */ const char *mgmt_cmd_help; - /* List of parameters for add_device command, if any */ - const char *add_device_parameters; + /* + * Array with parameters for add_device command, if any. NULL + * terminated. + */ + const char *const *add_device_parameters; /* * List of optional, i.e. which could be added by add_attribute command diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index c392b7489..04ca40ea9 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -754,6 +754,28 @@ static vdisk_op_fn fileio_ops[256]; static vdisk_op_fn blockio_ops[256]; static vdisk_op_fn nullio_ops[256]; +static const char *fileio_add_dev_params[] = { + "async", + "blocksize", + "cluster_mode", + "dif_filename", + "dif_mode", + "dif_static_app_tag", + "dif_type", + "filename", + "numa_node_id", + "nv_cache", + "o_direct", + "read_only", + "removable", + "rotational", + "thin_provisioned", + "tst", + "write_through", + "zero_copy", + NULL +}; + /* * Be careful changing "name" field, since it is the name of the corresponding * /sys/kernel/scst_tgt entry, hence a part of user space ABI. @@ -786,25 +808,7 @@ static struct scst_dev_type vdisk_file_devtype = { .add_device = vdisk_add_fileio_device, .del_device = vdisk_del_device, .dev_attrs = vdisk_fileio_attrs, - .add_device_parameters = - "async, " - "blocksize, " - "cluster_mode, " - "filename, " - "numa_node_id, " - "nv_cache, " - "o_direct, " - "read_only, " - "removable, " - "rotational, " - "thin_provisioned, " - "tst, " - "write_through, " - "zero_copy, " - "dif_mode, " - "dif_type, " - "dif_static_app_tag, " - "dif_filename", + .add_device_parameters = fileio_add_dev_params, #endif #if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, @@ -818,6 +822,27 @@ static struct scst_dev_type vdisk_file_devtype = { static struct kmem_cache *blockio_work_cachep; +static const char *blockio_add_dev_params[] = { + "active", + "bind_alua_state", + "blocksize", + "cluster_mode", + "dif_filename", + "dif_mode", + "dif_static_app_tag", + "dif_type", + "filename", + "numa_node_id", + "nv_cache", + "read_only", + "removable", + "rotational", + "thin_provisioned", + "tst", + "write_through", + NULL +}; + static struct scst_dev_type vdisk_blk_devtype = { .name = "vdisk_blockio", .type = TYPE_DISK, @@ -843,24 +868,7 @@ static struct scst_dev_type vdisk_blk_devtype = { .add_device = vdisk_add_blockio_device, .del_device = vdisk_del_device, .dev_attrs = vdisk_blockio_attrs, - .add_device_parameters = - "active, " - "bind_alua_state, " - "blocksize, " - "dif_mode, " - "dif_type, " - "dif_static_app_tag, " - "dif_filename, " - "filename, " - "numa_node_id, " - "nv_cache, " - "cluster_mode, " - "read_only, " - "removable, " - "rotational, " - "thin_provisioned, " - "tst, " - "write_through", + .add_device_parameters = blockio_add_dev_params, #endif #if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, @@ -872,6 +880,23 @@ static struct scst_dev_type vdisk_blk_devtype = { #endif }; +static const char *nullio_add_dev_params[] = { + "blocksize", + "cluster_mode", + "dif_mode", + "dif_static_app_tag", + "dif_type", + "dummy", + "numa_node_id", + "read_only", + "removable", + "rotational", + "size", + "size_mb", + "tst", + NULL +}; + static struct scst_dev_type vdisk_null_devtype = { .name = "vdisk_nullio", .type = TYPE_DISK, @@ -895,20 +920,7 @@ static struct scst_dev_type vdisk_null_devtype = { .add_device = vdisk_add_nullio_device, .del_device = vdisk_del_device, .dev_attrs = vdisk_nullio_attrs, - .add_device_parameters = - "blocksize, " - "dif_mode, " - "dif_type, " - "dif_static_app_tag, " - "dummy, " - "numa_node_id, " - "cluster_mode, " - "read_only, " - "removable, " - "rotational, " - "size, " - "size_mb, " - "tst", + .add_device_parameters = nullio_add_dev_params, #endif #if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, @@ -920,6 +932,11 @@ static struct scst_dev_type vdisk_null_devtype = { #endif }; +static const char *cdrom_add_dev_params[] = { + "tst", + NULL, +}; + static struct scst_dev_type vcdrom_devtype = { .name = "vcdrom", .type = TYPE_ROM, @@ -943,7 +960,7 @@ static struct scst_dev_type vcdrom_devtype = { .add_device = vcdrom_add_device, .del_device = vcdrom_del_device, .dev_attrs = vcdrom_attrs, - .add_device_parameters = "tst", + .add_device_parameters = cdrom_add_dev_params, #endif #if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index b41296141..dc26bc668 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -5771,6 +5771,28 @@ static struct kobj_type scst_devt_ktype = { .default_attrs = scst_devt_default_attrs, }; +static char *scst_dev_params(struct scst_dev_type *devt) +{ + char *p, *r; + const char *const *q; + bool comma = false; + + if (!devt->add_device_parameters) + return NULL; + p = kstrdup("The following parameters available: ", GFP_KERNEL); + if (!p) + return NULL; + for (q = devt->add_device_parameters; *q; q++) { + r = kasprintf(GFP_KERNEL, "%s%s%s", p, comma ? ", " : "", *q); + kfree(p); + if (!r) + return NULL; + p = r; + comma = true; + } + return p; +} + static ssize_t scst_devt_mgmt_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -5782,12 +5804,14 @@ static ssize_t scst_devt_mgmt_show(struct kobject *kobj, "\n" "where parameters are one or more " "param_name=value pairs separated by ';'\n\n" - "%s%s%s%s%s%s%s%s%s%s\n"; + "%s%s%s%s%s%s%s%s%s\n"; struct scst_dev_type *devt; + char *p; + int res; devt = container_of(kobj, struct scst_dev_type, devt_kobj); - - return scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, help, + p = scst_dev_params(devt); + res = scnprintf(buf, SCST_SYSFS_BLOCK_SIZE, help, (devt->devt_optional_attributes != NULL) ? " echo \"add_attribute \" >mgmt\n" " echo \"del_attribute \" >mgmt\n" : "", @@ -5796,10 +5820,7 @@ static ssize_t scst_devt_mgmt_show(struct kobject *kobj, " echo \"del_device_attribute device_name \" >mgmt\n" : "", (devt->mgmt_cmd_help) ? devt->mgmt_cmd_help : "", (devt->mgmt_cmd_help) ? "\n" : "", - (devt->add_device_parameters != NULL) ? - "The following parameters available: " : "", - (devt->add_device_parameters != NULL) ? - devt->add_device_parameters : "", + p ? : "", (devt->add_device_parameters != NULL) ? "\n" : "", (devt->devt_optional_attributes != NULL) ? "The following dev handler attributes available: " : "", @@ -5811,6 +5832,8 @@ static ssize_t scst_devt_mgmt_show(struct kobject *kobj, (devt->dev_optional_attributes != NULL) ? devt->dev_optional_attributes : "", (devt->dev_optional_attributes != NULL) ? "\n" : ""); + kfree(p); + return res; } static int scst_process_devt_mgmt_store(char *buffer, From 0cbfed3042aba94ebfb2a8dff7e22f3e06d809c2 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 18 Feb 2019 22:28:25 +0000 Subject: [PATCH 38/42] scst_vdisk: Avoid duplicating the add_device parameters This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7965 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 04ca40ea9..852b1f161 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -8193,14 +8193,6 @@ out_destroy: static int vdev_blockio_add_device(const char *device_name, char *params) { int res = 0; - const char *const allowed_params[] = { "filename", "read_only", "write_through", - "removable", "blocksize", "nv_cache", - "rotational", "cluster_mode", - "thin_provisioned", "tst", "active", - "bind_alua_state", "numa_node_id", - "dif_mode", - "dif_type", "dif_static_app_tag", - "dif_filename", NULL }; struct scst_vdisk_dev *virt_dev; TRACE_ENTRY(); @@ -8216,7 +8208,8 @@ static int vdev_blockio_add_device(const char *device_name, char *params) sprintf(virt_dev->t10_vend_id, "%.*s", (int)sizeof(virt_dev->t10_vend_id) - 1, SCST_BIO_VENDOR); - res = vdev_parse_add_dev_params(virt_dev, params, allowed_params); + res = vdev_parse_add_dev_params(virt_dev, params, + virt_dev->vdev_devt->add_device_parameters); if (res != 0) goto out_destroy; @@ -8264,11 +8257,6 @@ out_destroy: static int vdev_nullio_add_device(const char *device_name, char *params) { int res = 0; - static const char *const allowed_params[] = { - "read_only", "dummy", "removable", "blocksize", "rotational", - "size", "size_mb", "tst", "numa_node_id", - "cluster_mode", "dif_mode", "dif_type", "dif_static_app_tag", NULL - }; struct scst_vdisk_dev *virt_dev; TRACE_ENTRY(); @@ -8282,7 +8270,8 @@ static int vdev_nullio_add_device(const char *device_name, char *params) virt_dev->nullio = 1; virt_dev->file_size = VDISK_NULLIO_SIZE; - res = vdev_parse_add_dev_params(virt_dev, params, allowed_params); + res = vdev_parse_add_dev_params(virt_dev, params, + virt_dev->vdev_devt->add_device_parameters); if (res != 0) goto out_destroy; @@ -8441,7 +8430,6 @@ out: static ssize_t __vcdrom_add_device(const char *device_name, char *params) { int res = 0; - static const char *const allowed_params[] = { "tst", NULL }; struct scst_vdisk_dev *virt_dev; TRACE_ENTRY(); @@ -8464,7 +8452,8 @@ static ssize_t __vcdrom_add_device(const char *device_name, char *params) virt_dev->blk_shift = DEF_CDROM_BLOCK_SHIFT; - res = vdev_parse_add_dev_params(virt_dev, params, allowed_params); + res = vdev_parse_add_dev_params(virt_dev, params, + virt_dev->vdev_devt->add_device_parameters); if (res != 0) goto out_destroy; From 50d93363e28f59c55e75e15cdea650695d872704 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 19 Feb 2019 01:21:37 +0000 Subject: [PATCH 39/42] scst_disk: Remove forward declarations This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7966 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_disk.c | 214 ++++++++++++++---------------- 1 file changed, 102 insertions(+), 112 deletions(-) diff --git a/scst/src/dev_handlers/scst_disk.c b/scst/src/dev_handlers/scst_disk.c index e5ede7d66..59e8bfe4f 100644 --- a/scst/src/dev_handlers/scst_disk.c +++ b/scst/src/dev_handlers/scst_disk.c @@ -42,118 +42,6 @@ #define DISK_DEF_BLOCK_SHIFT 9 -static int disk_attach(struct scst_device *dev); -static void disk_detach(struct scst_device *dev); -static int disk_parse(struct scst_cmd *cmd); -static enum scst_exec_res disk_perf_exec(struct scst_cmd *cmd); -static int disk_done(struct scst_cmd *cmd); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) -static enum scst_exec_res disk_exec(struct scst_cmd *cmd); -static bool disk_on_sg_tablesize_low(struct scst_cmd *cmd); -#endif - -static struct scst_dev_type disk_devtype = { - .name = DISK_NAME, - .type = TYPE_DISK, - .threads_num = 1, - .parse_atomic = 1, - .dev_done_atomic = 1, - .attach = disk_attach, - .detach = disk_detach, - .parse = disk_parse, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) - .exec = disk_exec, - .on_sg_tablesize_low = disk_on_sg_tablesize_low, -#endif - .dev_done = disk_done, -#if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) - .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, - .trace_flags = &trace_flag, -#endif -}; - -static struct scst_dev_type disk_devtype_perf = { - .name = DISK_PERF_NAME, - .type = TYPE_DISK, - .parse_atomic = 1, - .dev_done_atomic = 1, - .attach = disk_attach, - .detach = disk_detach, - .parse = disk_parse, - .exec = disk_perf_exec, - .dev_done = disk_done, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) - .on_sg_tablesize_low = disk_on_sg_tablesize_low, -#endif -#if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) - .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, - .trace_flags = &trace_flag, -#endif -}; - -static int __init init_scst_disk_driver(void) -{ - int res = 0; - - TRACE_ENTRY(); - - disk_devtype.module = THIS_MODULE; - - res = scst_register_dev_driver(&disk_devtype); - if (res < 0) - goto out; - - disk_devtype_perf.module = THIS_MODULE; - - res = scst_register_dev_driver(&disk_devtype_perf); - if (res < 0) - goto out_unreg; - -#ifdef CONFIG_SCST_PROC - res = scst_dev_handler_build_std_proc(&disk_devtype); - if (res != 0) - goto out_unreg1; - - res = scst_dev_handler_build_std_proc(&disk_devtype_perf); - if (res != 0) - goto out_unreg2; -#endif - -out: - TRACE_EXIT_RES(res); - return res; - -#ifdef CONFIG_SCST_PROC -out_unreg2: - scst_dev_handler_destroy_std_proc(&disk_devtype); - -out_unreg1: - scst_unregister_dev_driver(&disk_devtype_perf); -#endif - -out_unreg: - scst_unregister_dev_driver(&disk_devtype); - goto out; -} - -static void __exit exit_scst_disk_driver(void) -{ - TRACE_ENTRY(); - -#ifdef CONFIG_SCST_PROC - scst_dev_handler_destroy_std_proc(&disk_devtype_perf); - scst_dev_handler_destroy_std_proc(&disk_devtype); -#endif - scst_unregister_dev_driver(&disk_devtype_perf); - scst_unregister_dev_driver(&disk_devtype); - - TRACE_EXIT(); - return; -} - -module_init(init_scst_disk_driver); -module_exit(exit_scst_disk_driver); - static int disk_attach(struct scst_device *dev) { int res, rc; @@ -624,6 +512,108 @@ out_complete: goto out; } +static struct scst_dev_type disk_devtype = { + .name = DISK_NAME, + .type = TYPE_DISK, + .threads_num = 1, + .parse_atomic = 1, + .dev_done_atomic = 1, + .attach = disk_attach, + .detach = disk_detach, + .parse = disk_parse, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) + .exec = disk_exec, + .on_sg_tablesize_low = disk_on_sg_tablesize_low, +#endif + .dev_done = disk_done, +#if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) + .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, + .trace_flags = &trace_flag, +#endif +}; + +static struct scst_dev_type disk_devtype_perf = { + .name = DISK_PERF_NAME, + .type = TYPE_DISK, + .parse_atomic = 1, + .dev_done_atomic = 1, + .attach = disk_attach, + .detach = disk_detach, + .parse = disk_parse, + .exec = disk_perf_exec, + .dev_done = disk_done, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) + .on_sg_tablesize_low = disk_on_sg_tablesize_low, +#endif +#if defined(CONFIG_SCST_DEBUG) || defined(CONFIG_SCST_TRACING) + .default_trace_flags = SCST_DEFAULT_DEV_LOG_FLAGS, + .trace_flags = &trace_flag, +#endif +}; + +static int __init init_scst_disk_driver(void) +{ + int res = 0; + + TRACE_ENTRY(); + + disk_devtype.module = THIS_MODULE; + + res = scst_register_dev_driver(&disk_devtype); + if (res < 0) + goto out; + + disk_devtype_perf.module = THIS_MODULE; + + res = scst_register_dev_driver(&disk_devtype_perf); + if (res < 0) + goto out_unreg; + +#ifdef CONFIG_SCST_PROC + res = scst_dev_handler_build_std_proc(&disk_devtype); + if (res != 0) + goto out_unreg1; + + res = scst_dev_handler_build_std_proc(&disk_devtype_perf); + if (res != 0) + goto out_unreg2; +#endif + +out: + TRACE_EXIT_RES(res); + return res; + +#ifdef CONFIG_SCST_PROC +out_unreg2: + scst_dev_handler_destroy_std_proc(&disk_devtype); + +out_unreg1: + scst_unregister_dev_driver(&disk_devtype_perf); +#endif + +out_unreg: + scst_unregister_dev_driver(&disk_devtype); + goto out; +} + +static void __exit exit_scst_disk_driver(void) +{ + TRACE_ENTRY(); + +#ifdef CONFIG_SCST_PROC + scst_dev_handler_destroy_std_proc(&disk_devtype_perf); + scst_dev_handler_destroy_std_proc(&disk_devtype); +#endif + scst_unregister_dev_driver(&disk_devtype_perf); + scst_unregister_dev_driver(&disk_devtype); + + TRACE_EXIT(); + return; +} + +module_init(init_scst_disk_driver); +module_exit(exit_scst_disk_driver); + MODULE_AUTHOR("Vladislav Bolkhovitin & Leonid Stoljar"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("SCSI disk (type 0) dev handler for SCST"); From e6fe4d8dd4f94e84045990ec48d6178fb75f59a9 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 19 Feb 2019 01:27:49 +0000 Subject: [PATCH 40/42] scst/README: Add a diagram that illustrates an active/non-optimized setup git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7967 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/README | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/scst/README b/scst/README index 08aa28fa4..6e0a28477 100644 --- a/scst/README +++ b/scst/README @@ -1948,23 +1948,50 @@ information about ALUA support in Windows Server, see also: Active/Non-Optimized via internal redirection ............................................. -The Active-Standby configuration is simple to understand and setup, -however, it might have serious interoperability issues, because not all -initiators handle Standby state correctly. For instance, some versions -of VMware reported to have such issues. Same for Windows. +The Active-Standby configuration is simple to understand and to set up. +However, it might cause serious interoperability issues because not all +initiators handle the ALUA state 'standby' state correctly. For instance, +some versions of VMware reported to have such issues. Same for Windows. -Hence, it is better to use Non-Optimized state on the passive node -instead of Standby with internal commands redirection to the active -node. This is what the vast majority of storage vendors are doing, which -is, actually, the reason why Standby and Unavailable states have all -those initiator issues. Simply, they have had too few testing, because -only marginally used. +It is better to use the 'nonoptimized' state on the passive node instead +of 'standby' with internal commands redirection to the active node. This +is what the vast majority of storage vendors are doing. This is actually +the reason why the 'standby' and 'unavailable' states have all those +initiator interoperability issues. The latter combination has received +too few testing because it is only marginally used. -SCST has necessary support for such redirection, it just needs to be +SCST has the necessary support for such redirection, it just needs to be configured correctly. It's a little bit of effort, especially to understand how it's going to function, but then it would work MUCH more reliable for full range of initiators. Ever poor initiators, who have no -idea about ALUA (boot from SAN, e.g.) would work now. +idea about ALUA (boot from SAN, e.g.) would work now. The following +diagram illustrates this approach: + +................................................................ +. . . +. Initiator A . Initiator B . +. | . | . +................................................................ +. | . | . +. target port C . target port D . +. | . | . +. SCST . SCST . +. Instance E - target . target - Instance F . +. / \ port G . port H / \ . +. / \ \./ / \ . +. / \ /.\ / \ . +. vdisk_blockio dev_disk / . \ dev_disk vdisk_blockio . +. handler handler / . \ handler handler . +. | | / . \ | | . +. block device SCSI / . SCSI block device . +. I initiator . initiator J . +. | node K . node L | . +. |______________________ .______________________| . +................................................................ +The link between block devices I and J stands for synchronous replication. + + +Such a setup can be configured as follows: 1. Build SCST with CONFIG_SCST_FORWARD_MODE_PASS_THROUGH enabled in scst.h From 7812dd27387f0b057714f244bb271ba631e2e653 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 19 Feb 2019 01:41:46 +0000 Subject: [PATCH 41/42] scst_vdisk: Introduce the execute_async flag This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7968 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 852b1f161..1ad9ef9c0 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -284,7 +284,8 @@ struct vdisk_cmd_params { }; struct scst_cmd *cmd; loff_t loff; - int fua; + unsigned int fua:1; + unsigned int execute_async:1; }; static bool vdev_saved_mode_pages_enabled = true; @@ -3010,7 +3011,7 @@ static bool vdisk_parse_offset(struct vdisk_cmd_params *p, struct scst_cmd *cmd) struct scst_device *dev = cmd->dev; struct scst_vdisk_dev *virt_dev = dev->dh_priv; bool res; - int fua = 0; + bool fua = false; TRACE_ENTRY(); @@ -3371,6 +3372,8 @@ static enum compl_status_e fileio_exec_async(struct vdisk_cmd_params *p) return CMD_SUCCEEDED; } + p->execute_async = true; + kvec = p->async.kvec; length = scst_get_buf_first(cmd, &address); while (length) { @@ -3429,7 +3432,7 @@ static enum compl_status_e fileio_exec_async(struct vdisk_cmd_params *p) static void vdisk_on_free_cmd_params(const struct vdisk_cmd_params *p) { - if (!do_fileio_async(p)) { + if (!p->execute_async) { if (p->sync.iv != p->sync.small_iv) kfree(p->sync.iv); } From 9608cd5781c43fca772515d876f1c5a20acaba85 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 21 Feb 2019 16:07:52 +0000 Subject: [PATCH 42/42] scst_pres: Make PERSISTENT RESERVE OUT ALL_TG_PT flag support remote ports Instead of only iterating over local ports, also iterate over remote ports. Signed-off-by: Sergey Lysanov [bvanassche: edited patch title and description, introduced a helper function, register remote ports once, added error checking] git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7969 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_pres.c | 42 +++++++++++++++++++++++++++++++++++++++++- scst/src/scst_priv.h | 1 + scst/src/scst_tg.c | 5 +++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/scst/src/scst_pres.c b/scst/src/scst_pres.c index 1f69d1380..e1bf203cf 100644 --- a/scst/src/scst_pres.c +++ b/scst/src/scst_pres.c @@ -1549,7 +1549,44 @@ out: return res; } -/* Called with dev_pr_mutex locked, no IRQ */ +/* Add registrants for remote ports. Called with dev_pr_mutex locked, no IRQ. */ +static int scst_register_remote_ports(struct scst_cmd *cmd, uint8_t *buffer, + int buffer_size, bool spec_i_pt, struct list_head *rollback_list) +{ + struct scst_dev_group *dg; + struct scst_target_group *tg; + struct scst_tg_tgt *tgtgt; + int res = 0; + + scst_alua_lock(); + + dg = scst_lookup_dg_by_dev(cmd->dev); + if (!dg) + goto out_unlock; + + list_for_each_entry(tg, &dg->tg_list, entry) { + list_for_each_entry(tgtgt, &tg->tgt_list, entry) { + /* Skip local target ports */ + if (tgtgt->tgt) + continue; + /* To do: check the initiator port transport ID. */ + if (tgtgt->rel_tgt_id == 0) + continue; + res = scst_pr_register_on_tgt_id(cmd, tgtgt->rel_tgt_id, + buffer, buffer_size, + spec_i_pt, + rollback_list); + if (res != 0) + goto out_unlock; + } + } +out_unlock: + scst_alua_unlock(); + + return res; +} + +/* Register all target ports. Called with dev_pr_mutex locked, no IRQ. */ static int scst_pr_register_all_tg_pt(struct scst_cmd *cmd, uint8_t *buffer, int buffer_size, bool spec_i_pt, struct list_head *rollback_list) { @@ -1594,6 +1631,9 @@ static int scst_pr_register_all_tg_pt(struct scst_cmd *cmd, uint8_t *buffer, } } + res = scst_register_remote_ports(cmd, buffer, buffer_size, spec_i_pt, + rollback_list); + out_unlock: mutex_unlock(&scst_mutex2); diff --git a/scst/src/scst_priv.h b/scst/src/scst_priv.h index a5bab7e9e..9e933314d 100644 --- a/scst/src/scst_priv.h +++ b/scst/src/scst_priv.h @@ -488,6 +488,7 @@ void scst_tg_cleanup(void); int scst_dg_add(struct kobject *parent, const char *name); int scst_dg_remove(const char *name); struct scst_dev_group *scst_lookup_dg_by_kobj(struct kobject *kobj); +struct scst_dev_group *scst_lookup_dg_by_dev(struct scst_device *dev); int scst_dg_dev_add(struct scst_dev_group *dg, const char *name); int scst_dg_dev_remove_by_name(struct scst_dev_group *dg, const char *name); int scst_dg_dev_remove_by_dev(struct scst_device *dev); diff --git a/scst/src/scst_tg.c b/scst/src/scst_tg.c index bdd8437ba..719e4d336 100644 --- a/scst/src/scst_tg.c +++ b/scst/src/scst_tg.c @@ -1403,6 +1403,11 @@ out: return dg; } +struct scst_dev_group *scst_lookup_dg_by_dev(struct scst_device *dev) +{ + return __lookup_dg_by_dev(dev); +} + /* * Target group module management.