diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm b/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm index 44749e934..e26660b8a 100644 --- a/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/lib/SCST/SCST.pm @@ -151,18 +151,22 @@ SCST_C_DGRP_REM_GRP_FAIL => 135, SCST_C_DGRP_NO_GROUP => 136, SCST_C_DGRP_GROUP_EXISTS => 137, -SCST_C_TGRP_BAD_ATTRIBUTES => 140, -SCST_C_TGRP_ATTRIBUTE_STATIC => 141, -SCST_C_TGRP_SETATTR_FAIL => 142, +SCST_C_DGRP_BAD_ATTRIBUTES => 140, +SCST_C_DGRP_ATTRIBUTE_STATIC => 141, +SCST_C_DGRP_SETATTR_FAIL => 142, -SCST_C_TGRP_ADD_INI_FAIL => 150, -SCST_C_TGRP_REM_INI_FAIL => 151, -SCST_C_TGRP_NO_INI => 152, -SCST_C_TGRP_INI_EXISTS => 153, +SCST_C_TGRP_BAD_ATTRIBUTES => 150, +SCST_C_TGRP_ATTRIBUTE_STATIC => 151, +SCST_C_TGRP_SETATTR_FAIL => 152, -SCST_C_TGRP_INI_BAD_ATTR => 160, -SCST_C_TGRP_INI_ATTR_STATIC => 161, -SCST_C_TGRP_INI_SETATTR_FAIL => 162, +SCST_C_TGRP_ADD_INI_FAIL => 160, +SCST_C_TGRP_REM_INI_FAIL => 161, +SCST_C_TGRP_NO_INI => 162, +SCST_C_TGRP_INI_EXISTS => 163, + +SCST_C_TGRP_INI_BAD_ATTR => 170, +SCST_C_TGRP_INI_ATTR_STATIC => 171, +SCST_C_TGRP_INI_SETATTR_FAIL => 172, }; my %VERBOSE_ERROR = ( @@ -256,6 +260,10 @@ my %VERBOSE_ERROR = ( (SCST_C_DGRP_NO_GROUP) => 'No such target group exists within device group.', (SCST_C_DGRP_GROUP_EXISTS) => 'Target group already exists within device group.', +(SCST_C_DGRP_BAD_ATTRIBUTES) => 'Bad attributes for device group.', +(SCST_C_DGRP_ATTRIBUTE_STATIC) => 'Device group attribute specified is static.', +(SCST_C_DGRP_SETATTR_FAIL) => 'Failed to set device group attribute. See "dmesg" for more information.', + (SCST_C_TGRP_BAD_ATTRIBUTES) => 'Bad attributes for target group.', (SCST_C_TGRP_ATTRIBUTE_STATIC) => 'Target group attribute specified is static.', (SCST_C_TGRP_SETATTR_FAIL) => 'Failed to set target group attribute. See "dmesg" for more information.', @@ -3373,6 +3381,81 @@ sub setInitiatorAttribute { return SCST_C_INI_SETATTR_FAIL; } +sub deviceGroupAttributes { + my $self = shift; + my $group = shift; + my %attributes; + + if ($self->deviceGroupExists($group) != TRUE) { + $self->{'err_string'} = "targetGroupAttributes(): Device group '$group' does not exist"; + return undef; + } + + my $pHandle = new IO::Handle; + my $_path = make_path(SCST_DEV_GROUP_DIR(), $group); + if (!(opendir $pHandle, $_path)) { + $self->{'err_string'} = "deviceGroupAttributes(): Unable to read directory '$_path': $!"; + return undef; + } + + foreach my $attribute (readdir($pHandle)) { + next if ($attribute eq '.' || $attribute eq '..' || + $attribute eq SCST_MGMT_IO); + my $pPath = make_path(SCST_DEV_GROUP_DIR(), $group, $attribute); + my $mode = (stat($pPath))[2]; + if (-d $pPath) { + # Skip directories + } else { + if (!(($mode & S_IRUSR) >> 6)) { + $attributes{$attribute}->{'static'} = FALSE; + $attributes{$attribute}->{'value'} = undef; + } else { + my $is_static; + if (($mode & S_IWUSR) >> 6) { + $is_static = FALSE; + } else { + $is_static = TRUE; + } + + my $io = new IO::File $pPath, O_RDONLY; + + if (!$io) { + $self->{'err_string'} = "deviceGroupAttributes(): Unable to read ". + "device group attribute '$attribute': $!"; + return undef; + } + + my $value = <$io>; + chomp $value; + + my $is_key = <$io>; + $is_key = new_sysfs_interface() && !$is_static || + ($is_key =~ /\[key\]/) ? TRUE : FALSE; + + my $key = 0; + if ($is_key) { + if ($attribute =~ /.*(\d+)$/) { + $key = $1; + $attribute =~ s/\d+$//; + } + } + + next if ($attribute eq SCST_MGMT_IO); + + $attributes{$attribute}->{'static'} = $is_static; + + if ($is_key) { + $attributes{$attribute}->{'keys'}->{$key}->{'value'} = $value; + } else { + $attributes{$attribute}->{'value'} = $value; + } + } + } + } + + return \%attributes; +} + sub targetGroupAttributes { my $self = shift; my $group = shift; @@ -3542,6 +3625,43 @@ sub targetGroupInitiatorAttributes { return \%attributes; } +sub setDeviceGroupAttribute { + my $self = shift; + my $group = shift; + my $attribute = shift; + my $value = shift; + + my $rc = $self->deviceGroupExists($group); + return SCST_C_DEV_GRP_NO_GROUP if (!$rc); + return $rc if ($rc > 1); + + return TRUE if (!defined($attribute) || !defined($value)); + + my $attributes = $self->deviceGroupAttributes($group); + + return SCST_C_DGRP_BAD_ATTRIBUTES if (!defined($$attributes{$attribute})); + return SCST_C_DGRP_ATTRIBUTE_STATIC if ($$attributes{$attribute}->{'static'}); + + my $path = make_path(SCST_DEV_GROUP_DIR(), $group, $attribute); + + my $io = new IO::File $path, O_WRONLY; + + return SCST_C_DGRP_SETATTR_FAIL if (!$io); + + my $bytes; + + if ($self->{'debug'}) { + print "DBG($$): $path -> $attribute = $value\n"; + } else { + $bytes = _syswrite($io, $value, length($value)); + } + + close $io; + + return FALSE if ($self->{'debug'} || $bytes); + return SCST_C_DGRP_SETATTR_FAIL; +} + sub setTargetGroupAttribute { my $self = shift; my $group = shift; diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index aa825e15a..0a6550360 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -40,6 +40,9 @@ Query Operations -list_hnd_attr : List all attributes for a given handler. -list_dev_attr : List all attributes for a given device. -list_drv_attr : List all attributes for a given driver. + -list_dgrp_attr : List all attributes for a given device group. + -list_tgrp_attr + -target : List all attributes for a device group/target. -list_tgt_attr : List all attributes for a given driver/target. -driver -list_grp_attr : List all attributes for a given group. @@ -258,6 +261,8 @@ sub getArgs { my $listScstAttr; my $listHandlerAttr; my $listDeviceAttr; + my $listDevGroupAttr; + my $listTargetGroupAttr; my $listGroupAttr; my $listDriverAttr; my $listTargetAttr; @@ -339,6 +344,8 @@ sub getArgs { 'list_scst_attr' => \$listScstAttr, 'list_hnd_attr=s' => \$listHandlerAttr, 'list_dev_attr=s' => \$listDeviceAttr, + 'list_dgrp_attr=s' => \$listDevGroupAttr, + 'list_tgrp_attr=s' => \$listTargetGroupAttr, 'list_drv_attr=s' => \$listDriverAttr, 'list_tgt_attr=s' => \$listTargetAttr, 'list_grp_attr=s' => \$listGroupAttr, @@ -422,7 +429,8 @@ sub getArgs { my $query_mode = defined($listHandler) || defined($listDevice) || defined($listDeviceGroup) || defined($listTargetGroup) || defined($listDriver) || defined($listTarget) || defined($listGroup) || defined($listSessions) || defined($listScstAttr) || defined($listHandlerAttr) || defined($listDeviceAttr) || defined($listDriverAttr) || - defined($listTargetAttr) || defined($listGroupAttr) || defined($listLunAttr) || defined($listInitiatorAttr); + defined($listTargetAttr) || defined($listGroupAttr) || defined($listLunAttr) || defined($listInitiatorAttr) || + defined($listDevGroupAttr) || defined($listTargetGroupAttr); my $set_mode = defined($setScstAttr) + defined($setHandlerAttr) + defined($setDeviceAttr) + defined($setDriverAttr) + defined($setTargetAttr) + defined($setGroupAttr) + @@ -467,6 +475,11 @@ sub getArgs { exit 1; } + if (defined($listTargetGroupAttr) && ($target eq '')) { + print "Please specify -target with -list_tgrp_attr.\n"; + exit 1; + } + if (defined($setScstAttr) && ($attributes eq '')) { print "Please specify -attributes with -set_scst_attr.\n"; exit 1; @@ -601,7 +614,7 @@ sub getArgs { return ($applyConfig, $clearConfig, $writeConfig, $checkConfig, $listScstAttr, $listHandler, $listDevice, $listDeviceGroup, $listTargetGroup, $listDriver, $listTarget, $listGroup, - $listSessions, $listHandlerAttr, $listDeviceAttr, $listDriverAttr, $listTargetAttr, + $listSessions, $listHandlerAttr, $listDeviceAttr, $listDriverAttr, $listTargetAttr, $listDevGroupAttr, $listTargetGroupAttr, $listGroupAttr, $listLunAttr, $listInitiatorAttr, $setScstAttr, $setHandlerAttr, $setDeviceAttr, $setDriverAttr, $setTargetAttr, $setGroupAttr, $setLunAttr, $setInitiatorAttr, $addDriverAttr, $addTargetAttr, $remDriverAttr, $remTargetAttr, @@ -627,7 +640,7 @@ sub main { my ($applyConfig, $clearConfig, $writeConfig, $checkConfig, $listScstAttr, $listHandler, $listDevice, $listDeviceGroup, $listTargetGroup, $listDriver, $listTarget, $listGroup, - $listSessions, $listHandlerAttr, $listDeviceAttr, $listDriverAttr, $listTargetAttr, + $listSessions, $listHandlerAttr, $listDeviceAttr, $listDriverAttr, $listTargetAttr, $listDevGroupAttr, $listTargetGroupAttr, $listGroupAttr, $listLunAttr, $listInitiatorAttr, $setScstAttr, $setHandlerAttr, $setDeviceAttr, $setDriverAttr, $setTargetAttr, $setGroupAttr, $setLunAttr, $setInitiatorAttr, $addDriverAttr, $addTargetAttr, $remDriverAttr, $remTargetAttr, @@ -739,6 +752,14 @@ sub main { $rc = listInitiatorAttributes($driver, $target, $group, $listInitiatorAttr, $nonkey); $all_good = TRUE; }; + defined($listDevGroupAttr) && do { + $rc = listDeviceGroupAttributes($listDevGroupAttr, $nonkey); + $all_good = TRUE; + }; + defined($listTargetGroupAttr) && do { + $rc = listTargetGroupAttributes($listTargetGroupAttr, $target, $nonkey); + $all_good = TRUE; + }; defined($setScstAttr) && do { last if (prompt()); print "\n-> Making requested changes.\n"; @@ -3205,6 +3226,40 @@ sub listInitiatorAttributes { return listAttributes($attributes, $nonkey); } +sub listDeviceGroupAttributes { + my $group = shift; + my $nonkey = shift; + + my $attributes = $SCST->deviceGroupAttributes($group); + + return TRUE if issueWarning($SCST->errorString()); + + # Special case - as of writing, device group attributes didn't exist. + if (!scalar(keys %{$attributes})) { + print "No such device group '$group' found or device group as no attributes.\n"; + return; + } + + return listAttributes($attributes, $nonkey); +} + +sub listTargetGroupAttributes { + my $group = shift; + my $tgroup = shift; + my $nonkey = shift; + + my $attributes = $SCST->targetGroupAttributes($group, $tgroup); + + return TRUE if issueWarning($SCST->errorString()); + + if (!scalar(keys %{$attributes})) { + print "No such device group/target group '$group/$tgroup' found.\n"; + return; + } + + return listAttributes($attributes, $nonkey); +} + sub listTargetGroupInitiatorAttributes { my $group = shift; my $tgroup = shift;