diff --git a/scstadmin/ChangeLog b/scstadmin/ChangeLog index a5dad581c..c76bef504 100644 --- a/scstadmin/ChangeLog +++ b/scstadmin/ChangeLog @@ -1,3 +1,15 @@ +Changes since 1.0.2 + +- Simplified/fixed options parsing. Thanks to Witold Kowolik. +- Use cluck() instead of print in module. +- Added a new option REMOVABLE. +- Allow options to be specified lowercase. + +Changes since 1.0.1 + +- Module install/uninstall added +- Added mapping NV -> NV_CACHE + Changes since 1.0.0 - Added a proper Makefile.PL to SCST::SCST so now we have a also a diff --git a/scstadmin/scst-0.7.4/lib/SCST/SCST.pm b/scstadmin/scst-0.7.4/lib/SCST/SCST.pm index 6f4d106b1..0e7fafb86 100644 --- a/scstadmin/scst-0.7.4/lib/SCST/SCST.pm +++ b/scstadmin/scst-0.7.4/lib/SCST/SCST.pm @@ -2,13 +2,13 @@ package SCST::SCST; # Author: Mark R. Buechler # License: GPLv2 -# Copyright (c) 2005-2007 Mark R. Buechler +# Copyright (c) 2005-2008 Mark R. Buechler use 5.005; use IO::Handle; use IO::File; use strict; -use Carp; +use Carp qw(cluck); my $TRUE = 1; my $FALSE = 0; @@ -55,7 +55,7 @@ $IOTYPE_PHYSICAL = 100; $IOTYPE_VIRTUAL = 101; $IOTYPE_PERFORMANCE = 102; -$VERSION = 0.7.4; +$VERSION = 0.7.5; my $_SCST_MIN_MAJOR_ = 0; my $_SCST_MIN_MINOR_ = 9; @@ -112,13 +112,19 @@ my %_IO_TYPES_ = ($CDROM_TYPE => $IOTYPE_PHYSICAL, my %_HANDLER_ALIASES_ = ('vdisk_blk' => 'vdisk'); my %_AVAILABLE_OPTIONS_ = ('WRITE_THROUGH' => 'WRITE_THROUGH', + 'WT' => 'WRITE_THROUGH', 'O_DIRECT' => 'O_DIRECT', + 'DR' => 'O_DIRECT', 'READ_ONLY' => 'READ_ONLY', + 'RO' => 'READ_ONLY', 'NULLIO' => 'NULLIO', + 'NIO' => 'NULLIO', 'NV_CACHE' => 'NV_CACHE', 'NV' => 'NV_CACHE', 'BLOCKIO' => 'BLOCKIO', - 'BIO' => 'BLOCKIO'); + 'BIO' => 'BLOCKIO', + 'REMOVABLE' => 'REMOVABLE', + 'RM' => 'REMOVABLE'); sub new { my $this = shift; @@ -372,7 +378,7 @@ sub handlerDevices { my $io = new IO::File $handler_io, O_RDONLY; if (!$io) { - print "WARNING: handlerDevices(): Failed to open handler IO $handler_io, assuming disabled.\n"; + cluck("WARNING: handlerDevices(): Failed to open handler IO $handler_io, assuming disabled"); return \%devices; # Return an empty hash } @@ -384,14 +390,22 @@ sub handlerDevices { next; } - my ($vname, $size, $blocksize, $options, $path) = split(/\s+/, $line); + my ($vname, $size, $blocksize, $options, $path) = + ($line =~ /(\S+)\s+(\S+)\s+(\S+)\s+(.*?)\s+(\S+)\s*$/); - if ($options =~ /^\//) { - $path = $options; - $options = ""; + my $options_t; + foreach my $option (split(/\s/, cleanupString($options))) { + if (defined($_AVAILABLE_OPTIONS_{$option})) { + $options_t .= $_AVAILABLE_OPTIONS_{$option}.','; + } else { + cluck("WARNING: Unknown option '$option', please update your SCST module"); + } } - $devices{$vname}->{'OPTIONS'} = cleanupString($options); + $options_t =~ s/\,$//; + + $devices{$vname}->{'OPTIONS'} = $options_t; + $devices{$vname}->{'SIZE'} = cleanupString($size); $devices{$vname}->{'PATH'} = cleanupString($path); $devices{$vname}->{'BLOCKSIZE'} = cleanupString($blocksize); @@ -462,6 +476,7 @@ sub openDevice { } $options = cleanupString($options); + $options =~ s/,/ /g; my $cmd = "open $device $path $blocksize $options\n"; @@ -878,7 +893,7 @@ sub handler_private { my $io = new IO::File $handler_io, O_WRONLY; if (!$io) { - print "WARNING: SCST/SCST.pm: Failed to open handler IO $handler_io, assuming disabled.\n"; + cluck("WARNING: SCST/SCST.pm: Failed to open handler IO $handler_io, assuming disabled"); return $FALSE; } @@ -943,13 +958,25 @@ sub checkOptions { my $self = shift; my $options = shift; my $o_string; + my $b_string; + my $bad = $FALSE; return undef, $TRUE if (!$options); - foreach my $option (split(/\s+/, $options)) { + foreach my $option (split(/[\s+|\,]/, $options)) { my $map = $_AVAILABLE_OPTIONS_{$option}; - return undef, $FALSE if (!$map); - $o_string .= ",$map"; + + if (!$map) { + $bad = $TRUE; + $b_string .= ",$option"; + } else { + $o_string .= ",$map"; + } + } + + if ($bad) { + $b_string =~ s/^\,//; + return $b_string, $FALSE; } $o_string =~ s/^\,//; diff --git a/scstadmin/scstadmin b/scstadmin/scstadmin index 1f74e4593..01052da02 100755 --- a/scstadmin/scstadmin +++ b/scstadmin/scstadmin @@ -1,5 +1,5 @@ #!/usr/bin/perl -$Version = 'SCST Configurator v1.0.1'; +$Version = 'SCST Configurator v1.0.2'; # Configures SCST # @@ -64,8 +64,8 @@ Available Handlers: disk, vdisk, disk_perf, cdrom, vcdrom, changer, modisk, modisk_perf, tape, tape_perf Available Options for create and open: - WRITE_THROUGH, READ_ONLY, O_DIRECT, NULLIO, NV_CACHE, BIO - + WRITE_THROUGH, READ_ONLY, O_DIRECT, NULLIO, NV_CACHE, BLOCK_IO, REMOVABLE + Examples: Enable target mode for fibre card specifying its WWN scstadmin -enable 50:06:0B:00:00:39:71:78 @@ -294,6 +294,7 @@ sub getArgs { $showSessions = $TRUE if (defined($showSessions)); $enable =~ tr/A-Z/a-z/; $disable =~ tr/A-Z/a-z/; + $options =~ tr/a-z/A-Z/ if ($options); if ((defined($showSessions) + defined($addDev) + defined($removeDev) + defined($addUser) + defined($enable) + defined($disable) + @@ -505,7 +506,8 @@ sub writeConfiguration { foreach my $device (sort keys %{$devices}) { my $options = $$devices{$device}->{'OPTIONS'}; - $options =~ s/\,/\|/; + + $options =~ s/\,/\|/g; print $io "DEVICE $device,".$$devices{$device}->{'PATH'}; print $io ",$options"; @@ -750,7 +752,7 @@ sub applyConfiguration { } } - print "Applying configurations additions..\n" if (!$check); + print "Applying configuration additions..\n" if (!$check); print "\n"; readWorkingConfig() if ($force); @@ -765,7 +767,7 @@ sub applyConfiguration { foreach my $device (@{$$config{'HANDLER'}->{$_handler}->{'DEVICE'}}) { my($vname, $path, $options, $blocksize) = split(/\,/, $device); $path = cleanupString($path); - $options =~ s/\s+//; $options =~ s/\|/,/; + $options =~ s/\s+//g; if (defined($$DEVICES{$vname}) && ($_HANDLER_MAP_{$_handler} == $$DEVICES{$vname})) { next; @@ -1000,8 +1002,6 @@ sub addDevice { my $options = shift; my $blocksize = shift; - $options =~ s/\,/ /; - my $_handler = $_HANDLER_MAP_{$handler}; my $htype = $SCST->handlerType($_handler);