From c121a6ded80956246e0d088861160e9e27b91589 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 14 Sep 2020 01:53:27 +0000 Subject: [PATCH 1/3] scstadmin: Adjust source code formatting Remove a single space that follows a unary negation operator. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@9156 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm | 2 +- 1 file changed, 1 insertion(+), 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 f8a05928c..63471d0ed 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 @@ -490,7 +490,7 @@ sub setScstAttribute { return TRUE if (!length($attribute) || !length($value)); - my $bytes = - ENOENT; + my $bytes = -ENOENT; my $path = make_path(SCST_ROOT_DIR(), $attribute); my $io = new IO::File $path, O_WRONLY; if ($io) { From 7e3fe7a80e4fe684ee247d8a61c0f95b2a36cf96 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 14 Sep 2020 01:54:26 +0000 Subject: [PATCH 2/3] scstadmin: Fix the readOnly() subroutine git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@9157 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scst-1.0.0/lib/SCST/SCST.pm | 6 +++++- scstadmin/scstadmin.sysfs/scst-1.0.0/t/02-scst-attr.t | 2 +- 2 files changed, 6 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 63471d0ed..2e995b107 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 @@ -359,7 +359,11 @@ sub readOnly { my ($path) = @_; my $mode = (stat($path))[2]; - return ($mode & S_IWUSR) != 0; + if (!defined($mode)) { + cluck("invalid path $path"); + return undef; + } + return ($mode & S_IWUSR) == 0; } sub scstVersion { 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 0bd7c9801..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 @@ -30,7 +30,7 @@ ok($SCST->setScstAttribute('no-such-attribute', '1'), $SCST->SCST_C_BAD_ATTRIBUTES); ok($SCST->setScstAttribute('last_sysfs_mgmt_res', '1'), - $SCST->SCST_C_SETATTR_FAIL); + $SCST->SCST_C_ATTRIBUTE_STATIC); my $threads = getScstThreadCount($SCST); ok(ref(\$threads), "SCALAR"); From 6d60231631fd21af354c08da40b94407af012013 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 14 Sep 2020 01:56:26 +0000 Subject: [PATCH 3/3] scstadmin: Support passing an empty string to set*Attribute() Validate the $value argument of set functions with defined() instead of length(). Append a newline to the end of $value before writing it into a sysfs attribute to make sure something gets written if $value eq "". git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@9158 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../scst-1.0.0/lib/SCST/SCST.pm | 33 ++++++++++++------- .../scst-1.0.0/t/02-scst-attr.t | 21 +++++++++++- 2 files changed, 42 insertions(+), 12 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 2e995b107..9f69ba3f4 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 @@ -492,7 +492,7 @@ sub setScstAttribute { my $attribute = shift; my $value = shift; - return TRUE if (!length($attribute) || !length($value)); + return TRUE if (!length($attribute) || !defined($value)); my $bytes = -ENOENT; my $path = make_path(SCST_ROOT_DIR(), $attribute); @@ -501,6 +501,7 @@ sub setScstAttribute { if ($self->{'debug'}) { print "DBG($$): $path -> $attribute = $value\n"; } else { + $value .= "\n"; $bytes = _syswrite($io, $value, length($value)); } close $io; @@ -2587,7 +2588,7 @@ sub setDriverAttribute { my $attribute = shift; my $value = shift; - return TRUE if (!length($attribute) || !length($value)); + return TRUE if (!length($attribute) || !defined($value)); my $path = make_path(SCST_TARGETS_DIR(), $driver, $attribute); @@ -2597,6 +2598,7 @@ sub setDriverAttribute { if ($self->{'debug'}) { print "DBG($$): $path -> $attribute = $value\n"; } else { + $value .= "\n"; $bytes = _syswrite($io, $value, length($value)); } close $io; @@ -2724,7 +2726,7 @@ sub setTargetAttribute { my $value = shift; return TRUE if (!length($driver) || !length($target) || - !length($attribute) || !length($value)); + !length($attribute) || !defined($value)); my ($path, $cmd); $path = make_path(SCST_TARGETS_DIR(), $driver, $target, $attribute); @@ -2850,7 +2852,7 @@ sub setGroupAttribute { my $attribute = shift; my $value = shift; - return TRUE if (!length($attribute) || !length($value)); + return TRUE if (!length($attribute) || !defined($value)); my ($path, $cmd); $path = make_path(SCST_TARGETS_DIR(), $driver, $target, SCST_GROUPS, @@ -2863,6 +2865,7 @@ sub setGroupAttribute { if ($self->{'debug'}) { print "DBG($$): $cmd > $path\n"; } else { + $value .= "\n"; $bytes = _syswrite($io, $value, length($value)); } close $io; @@ -3002,7 +3005,7 @@ sub setLunAttribute { return SCST_C_LUN_SETATTR_FAIL if (!length($driver) || !length($target) || !length($lun) || - !length($attribute) || !length($value)); + !length($attribute) || !defined($value)); my $path; @@ -3021,6 +3024,7 @@ sub setLunAttribute { if ($self->{'debug'}) { print "DBG($$): $path -> $attribute = $value\n"; } else { + $value .= "\n"; $bytes = _syswrite($io, $value, length($value)); } close $io; @@ -3152,7 +3156,7 @@ sub setInitiatorAttribute { my $attribute = shift; my $value = shift; - return TRUE if (!length($attribute) || !length($value)); + return TRUE if (!length($attribute) || !defined($value)); my $path = make_path(SCST_TARGETS_DIR(), $driver, $target, SCST_GROUPS, $group, SCST_LUNS, $initiator, $attribute); @@ -3163,6 +3167,7 @@ sub setInitiatorAttribute { if ($self->{'debug'}) { print "DBG($$): $path -> $attribute = $value\n"; } else { + $value .= "\n"; $bytes = _syswrite($io, $value, length($value)); } close $io; @@ -3439,7 +3444,7 @@ sub setAluaAttribute { my $attribute = shift; my $value = shift; - return TRUE if (!length($attribute) || !length($value)); + return TRUE if (!length($attribute) || !defined($value)); my $bytes = - ENOENT; my $path = make_path(SCST_DEV_GROUP_DIR(), $attribute); @@ -3448,6 +3453,7 @@ sub setAluaAttribute { if ($self->{'debug'}) { print "DBG($$): $value > $path\n"; } else { + $value .= "\n"; $bytes = _syswrite($io, $value, length($value)); } close $io; @@ -3465,7 +3471,7 @@ sub setDeviceGroupAttribute { my $attribute = shift; my $value = shift; - return TRUE if (!length($attribute) || !length($value)); + return TRUE if (!length($attribute) || !defined($value)); my $bytes = - ENOENT; my $path = make_path(SCST_DEV_GROUP_DIR(), $group, $attribute); @@ -3474,6 +3480,7 @@ sub setDeviceGroupAttribute { if ($self->{'debug'}) { print "DBG($$): $path -> $attribute = $value\n"; } else { + $value .= "\n"; $bytes = _syswrite($io, $value, length($value)); } close $io; @@ -3497,7 +3504,7 @@ sub setTargetGroupAttribute { my $value = shift; return TRUE if (!length($group) || !length($tgroup) || - !length($attribute) || !length($value)); + !length($attribute) || !defined($value)); my $bytes = - ENOENT; my $path = make_path(SCST_DEV_GROUP_DIR(), $group, SCST_DG_TGROUPS, $tgroup, $attribute); @@ -3506,6 +3513,7 @@ sub setTargetGroupAttribute { if ($self->{'debug'}) { print "DBG($$): $path -> $attribute = $value\n"; } else { + $value .= "\n"; $bytes = _syswrite($io, $value, length($value)); } close $io; @@ -3535,7 +3543,7 @@ sub setTargetGroupTargetAttribute { return TRUE if (!length($group) || !length($tgroup) || !length($tgt) || !length($attribute) || - !length($value)); + !defined($value)); my $bytes = - ENOENT; my $path = make_path(SCST_DEV_GROUP_DIR(), $group, SCST_DG_TGROUPS, @@ -3545,6 +3553,7 @@ sub setTargetGroupTargetAttribute { if ($self->{'debug'}) { print "DBG($$): $path -> $attribute = $value\n"; } else { + $value .= "\n"; $bytes = _syswrite($io, $value, length($value)); } close $io; @@ -3616,7 +3625,7 @@ sub setHandlerAttribute { my $attribute = shift; my $value = shift; - return TRUE if (!length($attribute) || !length($value)); + return TRUE if (!length($attribute) || !defined($value)); my $bytes = - ENOENT; my $path = make_path(SCST_HANDLERS_DIR(), $handler, $attribute); @@ -3625,6 +3634,7 @@ sub setHandlerAttribute { if ($self->{'debug'}) { print "DBG($$): $path -> $attribute = $value\n"; } else { + $value .= "\n"; $bytes = _syswrite($io, $value, length($value)); } close $io; @@ -4622,6 +4632,7 @@ sub make_path { if ($path && rindex($path, '/') != length($path) - 1) { $path .= '/'; } + cluck("make_path: invalid argument") if !length($element); $path .= $element; } 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 372c70e87..52321f5b9 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 @@ -5,7 +5,7 @@ use warnings; use Test; BEGIN { - plan tests => 6 + ($> == 0 ? 4 : 0); + plan tests => 7 + ($> == 0 ? 8 : 0); } use SCST::SCST; @@ -22,13 +22,21 @@ my $_DEBUG_ = 0; my $SCST = eval { new SCST::SCST($_DEBUG_) }; die("Creation of SCST object failed") if (!defined($SCST)); +# Missing `attribute` and `value` arguments. ok($SCST->setScstAttribute(), 1); +# `attribute` argument is an empty string. +ok($SCST->setScstAttribute(''), 1); + +# `attribute` argument is not an existing attribute and the `value` argument is +# missing. ok($SCST->setScstAttribute('no-such-attribute'), 1); +# `attribute` argument is not an existing attribute. ok($SCST->setScstAttribute('no-such-attribute', '1'), $SCST->SCST_C_BAD_ATTRIBUTES); +# Attempt to modify a read-only attribute. ok($SCST->setScstAttribute('last_sysfs_mgmt_res', '1'), $SCST->SCST_C_ATTRIBUTE_STATIC); @@ -36,6 +44,7 @@ my $threads = getScstThreadCount($SCST); ok(ref(\$threads), "SCALAR"); ok(defined($threads)); +# $> represents the effective user ID of this process. if ($> == 0) { ok($SCST->setScstAttribute('threads', $threads + 1), 0); @@ -44,4 +53,14 @@ if ($> == 0) { ok($SCST->setScstAttribute('threads', $threads), 0); ok(getScstThreadCount($SCST), $threads); + + ok($SCST->setScstAttribute('measure_latency', undef), 1); + + ok($SCST->setScstAttribute('measure_latency', ""), + $SCST->SCST_C_SETATTR_FAIL); + + ok($SCST->setScstAttribute('measure_latency', "."), + $SCST->SCST_C_SETATTR_FAIL); + + ok($SCST->setScstAttribute('measure_latency', "0"), 0); }