From 8db1080d78ca379aea73f4b84e861bca6d42ed58 Mon Sep 17 00:00:00 2001 From: Mark Buechler Date: Tue, 15 Dec 2009 20:01:01 +0000 Subject: [PATCH] - Added -noprompt option. Use with care! - Added support for T10 device ID. Applied modified patch by witoldk1@open-e.com. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@1395 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/ChangeLog | 5 + scstadmin/Makefile | 2 +- scstadmin/examples/scst.conf | 4 +- .../{scst-0.8.21 => scst-0.8.22}/MANIFEST | 0 .../{scst-0.8.21 => scst-0.8.22}/Makefile.PL | 0 scstadmin/{scst-0.8.21 => scst-0.8.22}/README | 0 .../lib/SCST/SCST.pm | 73 ++++++++++++++- scstadmin/scstadmin | 92 ++++++++++++++++--- 8 files changed, 154 insertions(+), 22 deletions(-) rename scstadmin/{scst-0.8.21 => scst-0.8.22}/MANIFEST (100%) rename scstadmin/{scst-0.8.21 => scst-0.8.22}/Makefile.PL (100%) rename scstadmin/{scst-0.8.21 => scst-0.8.22}/README (100%) rename scstadmin/{scst-0.8.21 => scst-0.8.22}/lib/SCST/SCST.pm (94%) diff --git a/scstadmin/ChangeLog b/scstadmin/ChangeLog index 579d54051..9da298fcc 100644 --- a/scstadmin/ChangeLog +++ b/scstadmin/ChangeLog @@ -1,3 +1,8 @@ +Changes for 1.0.11 + +- Added -noprompt option. Use with care! +- Added support for T10 device ID. + Changes for 1.0.10 - Added new [OPTIONS] section to config file. diff --git a/scstadmin/Makefile b/scstadmin/Makefile index a4316f0ef..db0f5d62e 100644 --- a/scstadmin/Makefile +++ b/scstadmin/Makefile @@ -1,4 +1,4 @@ -MODULE_VERSION = 0.8.21 +MODULE_VERSION = 0.8.22 TOOL = scstadmin SBINDIR := $(PREFIX)/usr/local/sbin diff --git a/scstadmin/examples/scst.conf b/scstadmin/examples/scst.conf index 78d2417df..b4af9e82e 100644 --- a/scstadmin/examples/scst.conf +++ b/scstadmin/examples/scst.conf @@ -1,4 +1,4 @@ -# Automatically generated by SCST Configurator v1.0.10. +# Automatically generated by SCST Configurator v1.0.11. # NOTE: Options are pipe (|) seperated. @@ -10,7 +10,7 @@ KEEP_CONFIG TRUE ISSUE_LIP FALSE [HANDLER vdisk] -#DEVICE ,,, +#DEVICE ,,,, DEVICE GW15K000,/dev/evms/GW15K000,,512 DEVICE GW15K001,/dev/evms/GW15K001,,512 DEVICE MP15K004,/dev/evms/MP15K004,,512 diff --git a/scstadmin/scst-0.8.21/MANIFEST b/scstadmin/scst-0.8.22/MANIFEST similarity index 100% rename from scstadmin/scst-0.8.21/MANIFEST rename to scstadmin/scst-0.8.22/MANIFEST diff --git a/scstadmin/scst-0.8.21/Makefile.PL b/scstadmin/scst-0.8.22/Makefile.PL similarity index 100% rename from scstadmin/scst-0.8.21/Makefile.PL rename to scstadmin/scst-0.8.22/Makefile.PL diff --git a/scstadmin/scst-0.8.21/README b/scstadmin/scst-0.8.22/README similarity index 100% rename from scstadmin/scst-0.8.21/README rename to scstadmin/scst-0.8.22/README diff --git a/scstadmin/scst-0.8.21/lib/SCST/SCST.pm b/scstadmin/scst-0.8.22/lib/SCST/SCST.pm similarity index 94% rename from scstadmin/scst-0.8.21/lib/SCST/SCST.pm rename to scstadmin/scst-0.8.22/lib/SCST/SCST.pm index 1941c310f..495c7b1a2 100644 --- a/scstadmin/scst-0.8.21/lib/SCST/SCST.pm +++ b/scstadmin/scst-0.8.22/lib/SCST/SCST.pm @@ -43,11 +43,11 @@ $IOTYPE_PHYSICAL = 100; $IOTYPE_VIRTUAL = 101; $IOTYPE_PERFORMANCE = 102; -$VERSION = 0.8.21; +$VERSION = 0.8.22; -my $_SCST_MIN_MAJOR_ = 1; +my $_SCST_MIN_MAJOR_ = 2; my $_SCST_MIN_MINOR_ = 0; -my $_SCST_MIN_RELEASE_ = 2; +my $_SCST_MIN_RELEASE_ = 0; my %_IO_MAP_ = ($VDISK_TYPE => $_SCST_VDISK_IO_, $VCDROM_TYPE => $_SCST_VCDROM_IO_); @@ -89,6 +89,7 @@ my %_IO_TYPES_ = ($CDROM_TYPE => $IOTYPE_PHYSICAL, $PROCESSOR_TYPE => $IOTYPE_PHYSICAL); my %_HANDLER_ALIASES_ = ('vdisk_blk' => 'vdisk', + 'vdisk_fileio' => 'vdisk', 'vdisk_blockio' => 'vdisk', 'vdisk_nullio' => 'vdisk'); @@ -413,8 +414,22 @@ sub handlerDevices { next; } - my ($vname, $size, $blocksize, $options, $path) = - ($line =~ /(\S+)\s+(\S+)\s+(\S+)\s+(.*?)\s+(\S+)\s*$/); + my ($vname, $size, $blocksize, $options, $path, $t10_id) = + ($line =~ '(\S+)\s+(\S+)\s+(\S+)\s+(.*?)\s+(/\S+)\s+(.*)$'); + + $t10_id = cleanupString($t10_id); + + if ($options =~ /^\//) { + $t10_id = $path; + $path = $options; + $options = ""; + } + + if ($t10_id =~ /^\//) { + $options .= " ".$path; + $path = $t10_id; + $t10_id = ""; + } my $options_t; foreach my $option (split(/\s/, cleanupString($options))) { @@ -432,6 +447,7 @@ sub handlerDevices { $devices{$vname}->{'SIZE'} = cleanupString($size); $devices{$vname}->{'PATH'} = cleanupString($path); $devices{$vname}->{'BLOCKSIZE'} = cleanupString($blocksize); + $devices{$vname}->{'T10_DEVICE_ID'} = $t10_id; } close $io; @@ -596,6 +612,44 @@ sub resyncDevice { return $rc; } +sub setT10DeviceId { + my $self = shift; + my $handler = shift; + my $device = shift; + my $t10_id = shift; + my $handler_io = $_IO_MAP_{$handler}; + + if (!$handler_io) { + $self->{'error'} = "setT10DeviceId(): Failed to open handler IO $handler_io or handler $handler invalid"; + return 1; + } + + if (!$self->handlerExists($handler)) { + $self->{'error'} = "setT10DeviceId(): Handler $handler does not exist"; + return 1; + } + + if (!$self->handlerDeviceExists($handler, $device)) { + $self->{'error'} = "setT10DeviceId(): Device $device is not open"; + return 2; + } + + my $cmd = "set_t10_dev_id $device $t10_id\n"; + + my $rc = $self->handler_private($handler_io, $cmd); + + return 0 if ($self->{'debug'}); + return $rc if ($rc); + + my $devices = $self->handlerDevices($handler); + + if ($$devices{$device}->{'T10_DEVICE_ID'} ne $t10_id) { + $self->{'error'} = "setT10DeviceId(): An error occured while setting T10 device ID to '$t10_id' ". + "for device '$device'. See dmesg/kernel log for more information."; + return 1; + } +} + sub userExists { my $self = shift; my $user = shift; @@ -1336,6 +1390,15 @@ Arguments: (int) $handler, (string) $device, (string) $path Returns: (int) $success +=item SCST::SCST->setT10DeviceId(); + +Changes the T10 device ID for the specified device and handler. Returns +0 upon success, 1 if unsuccessfull and 2 of the device does not exist. + +Arguments: (int) $handler, (string) $device, (string) $t10_dev_id + +Returns: (int) $success + =item SCST::SCST->userExists(); Checks for a specified user with the specified security group. diff --git a/scstadmin/scstadmin b/scstadmin/scstadmin index b2edcb2b4..84bb2e1cf 100755 --- a/scstadmin/scstadmin +++ b/scstadmin/scstadmin @@ -1,5 +1,5 @@ #!/usr/bin/perl -$Version = 'SCST Configurator v1.0.10'; +$Version = 'SCST Configurator v1.0.11'; # Configures SCST # @@ -35,6 +35,9 @@ Device Operations -handler -RemoveDev : Remove a device from a handler. -handler + -SetT10DeviceId : Sets the T10 Device ID of a device. + -device + -handler User Operations -adduser : Adds a user to a security group. @@ -69,6 +72,7 @@ Assignment Operations Options -ForceConfig : Force all configuration changes, even deletions (DANGER!). + -noprompt : Do not prompt or pause. Use with caution! Debugging (limited support) -debug : Debug mode - don\'t do anything destructive. @@ -94,6 +98,9 @@ Examples: Create a device given an already existing disk file: scstadmin -adddev DISK01 -handler vdisk -path /vdisks/disk01.dsk -options READ_ONLY,WRITE_THROUGH + + Setting the T10 Device ID of a device + scstadmin -SetT10DeviceId test_disk -device disk1 -handler vdisk Assign a device to a security group: scstadmin -assigndev DISK01 -group HOST01 -lun 1 @@ -197,6 +204,7 @@ sub getArgs { my $resyncDev; my $replaceDev; my $removeDev; + my $sett10id; my $addUser; my $moveUser; my $removeUser; @@ -211,12 +219,14 @@ sub getArgs { my $clearDevs; my $devLun; my $handler; + my $device; my $group; my $options; my $blocksize; my $enable; my $disable; my $issuelip; + my $noprompt; my $p = new Getopt::Long::Parser; @@ -230,6 +240,7 @@ sub getArgs { 'path=s' => \$devPath, 'ReplaceDev=s' => \$replaceDev, 'RemoveDev=s' => \$removeDev, + 'SetT10DeviceId=s' => \$sett10id, 'lun=s' => \$devLun, 'adduser=s' => \$addUser, 'MoveUser=s' => \$moveUser, @@ -244,12 +255,14 @@ sub getArgs { 'ReleaseDev=s' => \$releaseDev, 'ClearDevs' => \$clearDevs, 'handler=s' => \$handler, + 'device=s' => \$device, 'group=s' => \$group, 'options=s' => \$options, 'blocksize=s' => \$blocksize, 'enable=s' => \$enable, 'disable=s' => \$disable, 'issuelip' => \$issuelip, + 'noprompt' => \$noprompt, 'debug' => \$_DEBUG_)) { &usage(); } @@ -343,6 +356,11 @@ sub getArgs { usage(); } + if ($sett10id && (!$device || !$handler)) { + print "Please specify -device and -handler with -SetT10DeviceId.\n\n"; + usage(); + } + if ($clearDevs && !defined($group)) { print "Please specify -group with -ClearDevs.\n\n"; usage(); @@ -358,6 +376,7 @@ sub getArgs { $forceConfig = $TRUE if (defined($forceConfig)); $showSessions = $TRUE if (defined($showSessions)); $issuelip = $TRUE if (defined($issuelip)); + $noprompt = $TRUE if (defined($noprompt)); $enable =~ tr/A-Z/a-z/; $disable =~ tr/A-Z/a-z/; $options =~ tr/a-z/A-Z/ if ($options); @@ -366,7 +385,8 @@ sub getArgs { defined($removeDev)+ defined($addUser) + defined($enable) + defined($disable) + defined($removeUser) + defined($clearUsers) + defined($assignDev) + defined($releaseDev) + defined($clearDevs) + defined($applyConfig) + - defined($clearConfig) + defined($writeConfig) + defined($checkConfig)) > 1) { + defined($clearConfig) + defined($writeConfig) + defined($checkConfig) + + defined($sett10id)) > 1) { print "Please specify only one operation at a time.\n"; usage(); } @@ -376,8 +396,9 @@ sub getArgs { return ($enable, $disable, $issuelip, $addDev, $devPath, $devLun, $resyncDev, $removeDev, $addUser, $moveUser, $removeUser, $clearUsers, $addGroup, $renameGroup, $toGroup, $removeGroup, - $assignDev, $replaceDev, $releaseDev, $clearDevs, $handler, $group, $options, $blocksize, - $applyConfig, $forceConfig, $clearConfig, $writeConfig, $checkConfig, $showSessions); + $assignDev, $replaceDev, $releaseDev, $sett10id, $clearDevs, $handler, $device, $group, + $options, $blocksize, $applyConfig, $forceConfig, $clearConfig, $writeConfig, $checkConfig, + $showSessions, $noprompt); } sub main { @@ -390,8 +411,9 @@ sub main { my ($enable, $disable, $issuelip, $addDev, $devPath, $devLun, $resyncDev, $removeDev, $addUser, $moveUser, $removeUser, $clearUsers, $addGroup, $renameGroup, $toGroup, $removeGroup, - $assignDev, $replaceDev, $releaseDev, $clearDevs, $handler, $group, $options, $blocksize, - $applyConfig, $forceConfig, $clearConfig, $writeConfig, $checkConfig, $showSessions) = getArgs(); + $assignDev, $replaceDev, $releaseDev, $sett10id, $clearDevs, $handler, $device, $group, + $options, $blocksize, $applyConfig, $forceConfig, $clearConfig, $writeConfig, $checkConfig, + $showSessions, $noprompt) = getArgs(); $SCST = new SCST::SCST($_DEBUG_); @@ -403,8 +425,10 @@ sub main { $rc = applyConfiguration($applyConfig, $TRUE, $TRUE); die("Configuration errors found, aborting.\n") if ($rc); - print "\nConfiguration will apply in 10 seconds, type ctrl-c to abort..\n"; - sleep 10; + if (!$noprompt) { + print "\nConfiguration will apply in 10 seconds, type ctrl-c to abort..\n"; + sleep 10; + } } readWorkingConfig(); @@ -424,7 +448,7 @@ sub main { last SWITCH; }; defined($clearConfig) && do { - $rc = clearConfiguration(); + $rc = clearConfiguration($noprompt); last SWITCH; }; $addDev && do { @@ -439,6 +463,10 @@ sub main { $rc = removeDevice($handler, $removeDev); last SWITCH; }; + $sett10id && do { + $rc = setT10DeviceId($handler, $device, $sett10id); + last SWITCH; + }; $addUser && do { $rc = addUser($group, $addUser); last SWITCH; @@ -612,7 +640,7 @@ sub writeConfiguration { print $io "[HANDLER ".$_REVERSE_MAP_{$handler}."]\n"; print $io "#DEVICE ,"; if ($handler == $SCST::SCST::VDISK_TYPE) { - print $io ",,\n"; + print $io ",,,\n"; } else { print $io "\n"; } @@ -629,6 +657,7 @@ sub writeConfiguration { print $io "DEVICE $device,".$$devices{$device}->{'PATH'}; print $io ",$options"; print $io ",".$$devices{$device}->{'BLOCKSIZE'}; + print $io ",".$$devices{$device}->{'T10_DEVICE_ID'}; print $io "\n"; } @@ -936,7 +965,7 @@ sub applyConfiguration { } foreach my $device (@{$$config{'HANDLER'}->{$_handler}->{'DEVICE'}}) { - my($vname, $path, $options, $blocksize) = split(/\,/, $device); + my($vname, $path, $options, $blocksize, $t10_id) = split(/\,/, $device); $path = cleanupString($path); $options =~ s/\s+//g; @@ -962,6 +991,14 @@ sub applyConfiguration { } else { $changes++; } + + if ($t10_id ne '') { + if (setT10DeviceId($_handler, $vname, $t10_id)) { + $errs++; + } else { + $changes++; + } + } } } } @@ -1168,11 +1205,14 @@ sub applyConfiguration { } sub clearConfiguration { + my $noprompt = shift; my $errs; - print "WARNING: This removes ALL applied SCST configuration and may result in data loss!\n"; - print "If this is not what you intend, press ctrl-c now. Waiting 10 seconds.\n\n"; - sleep 10; + if (!$noprompt) { + print "WARNING: This removes ALL applied SCST configuration and may result in data loss!\n"; + print "If this is not what you intend, press ctrl-c now. Waiting 10 seconds.\n\n"; + sleep 10; + } print "\nRemoving all users and groups:\n\n"; foreach my $group (keys %GROUPS) { @@ -1318,6 +1358,30 @@ sub removeDevice { return $FALSE; } +sub setT10DeviceId { + my $handler = shift; + my $device = shift; + my $t10_id = shift; + + my $_handler = $_HANDLER_MAP_{$handler}; + my $htype = $SCST->handlerType($_handler); + + if (!defined($$DEVICES{$device})) { + print "WARNING: Device '$device' not defined.\n"; + return $TRUE; + } + + print "\t-> Changing T10 Device ID of virtual device '$device' to '$t10_id'..\n"; + + if ($SCST->setT10DeviceId($_handler, $device, $t10_id)) { + print "WARNING: Failed to changing T10 Device ID of virtual device '$device': ". + $SCST->errorString()."\n"; + return $TRUE; + } + + return $FALSE; +} + sub addGroup { my $group = shift;