Merge branch 'svn-trunk' into master

This commit is contained in:
Bart Van Assche
2020-09-13 19:14:20 -07:00
2 changed files with 49 additions and 15 deletions

View File

@@ -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 {
@@ -488,15 +492,16 @@ 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 $bytes = -ENOENT;
my $path = make_path(SCST_ROOT_DIR(), $attribute);
my $io = new IO::File $path, O_WRONLY;
if ($io) {
if ($self->{'debug'}) {
print "DBG($$): $path -> $attribute = $value\n";
} else {
$value .= "\n";
$bytes = _syswrite($io, $value, length($value));
}
close $io;
@@ -2583,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);
@@ -2593,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;
@@ -2720,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);
@@ -2846,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,
@@ -2859,6 +2865,7 @@ sub setGroupAttribute {
if ($self->{'debug'}) {
print "DBG($$): $cmd > $path\n";
} else {
$value .= "\n";
$bytes = _syswrite($io, $value, length($value));
}
close $io;
@@ -2998,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;
@@ -3017,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;
@@ -3148,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);
@@ -3159,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;
@@ -3435,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);
@@ -3444,6 +3453,7 @@ sub setAluaAttribute {
if ($self->{'debug'}) {
print "DBG($$): $value > $path\n";
} else {
$value .= "\n";
$bytes = _syswrite($io, $value, length($value));
}
close $io;
@@ -3461,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);
@@ -3470,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;
@@ -3493,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);
@@ -3502,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;
@@ -3531,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,
@@ -3541,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;
@@ -3612,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);
@@ -3621,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;
@@ -4618,6 +4632,7 @@ sub make_path {
if ($path && rindex($path, '/') != length($path) - 1) {
$path .= '/';
}
cluck("make_path: invalid argument") if !length($element);
$path .= $element;
}

View File

@@ -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,20 +22,29 @@ 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_SETATTR_FAIL);
$SCST->SCST_C_ATTRIBUTE_STATIC);
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);
}