From cf4c66e1f441c06c2a4c4ca48107ebb1a835ae92 Mon Sep 17 00:00:00 2001 From: Mark Buechler Date: Fri, 7 Sep 2007 19:04:51 +0000 Subject: [PATCH] - Fix really stupid mistake where config commits were using same path for each device. - Added option processing. The new API wants the option BLOCKIO, but SCST then shows the device having been opened with option BIO. We now warp BIO to BLOCKIO. - Added the concept of handler aliases. Handler vdisk with option BLOCKIO shows as a handler of vdisk_blk. We now warp vdisk_blk to just vdisk. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@184 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/SCST/SCST.pm | 38 +++++++++++++++++++++++++++----------- scstadmin/scstadmin | 10 +++++----- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/scstadmin/SCST/SCST.pm b/scstadmin/SCST/SCST.pm index fc1257b99..f591b598a 100644 --- a/scstadmin/SCST/SCST.pm +++ b/scstadmin/SCST/SCST.pm @@ -33,9 +33,6 @@ my $_SCST_VERSION_IO_ = $_SCST_DIR_.'/version'; my $_SCST_USERS_IO_ = 'names'; my $_SCST_DEVICES_IO_ = 'devices'; -my @_AVAILABLE_OPTIONS_ = ('WRITE_THROUGH', 'O_DIRECT', 'READ_ONLY', - 'NULLIO', 'NV_CACHE', 'BLOCKIO'); - use vars qw(@ISA @EXPORT $VERSION $CDROM_TYPE $CHANGER_TYPE $DISK_TYPE $VDISK_TYPE $VCDROM_TYPE $DISKPERF_TYPE $MODISK_TYPE $MODISKPERF_TYPE $TAPE_TYPE $TAPEPERF_TYPE $PROCESSOR_TYPE $IOTYPE_PHYSICAL $IOTYPE_VIRTUAL @@ -57,7 +54,7 @@ $IOTYPE_PHYSICAL = 100; $IOTYPE_VIRTUAL = 101; $IOTYPE_PERFORMANCE = 102; -$VERSION = 0.7.1; +$VERSION = 0.7.2; my $_SCST_MIN_MAJOR_ = 0; my $_SCST_MIN_MINOR_ = 9; @@ -111,6 +108,16 @@ my %_IO_TYPES_ = ($CDROM_TYPE => $IOTYPE_PHYSICAL, $TAPEPERF_TYPE => $IOTYPE_PERFORMANCE, $PROCESSOR_TYPE => $IOTYPE_PHYSICAL); +my %_HANDLER_ALIASES_ = ('vdisk_blk' => 'vdisk'); + +my %_AVAILABLE_OPTIONS_ = ('WRITE_THROUGH' => 'WRITE_THROUGH', + 'O_DIRECT' => 'O_DIRECT', + 'READ_ONLY' => 'READ_ONLY', + 'NULLIO' => 'NULLIO', + 'NV_CACHE' => 'NV_CACHE', + 'BLOCKIO' => 'BLOCKIO', + 'BIO' => 'BLOCKIO'); + sub new { my $this = shift; my $debug = shift; @@ -333,6 +340,8 @@ sub devices { } my($vname, $handler) = split(/\s+/, $line); + + $handler = $_HANDLER_ALIASES_{$handler} if ($_HANDLER_ALIASES_{$handler}); $devices{$vname} = $_TYPE_MAP_{$handler}; } @@ -425,9 +434,12 @@ sub openDevice { my $options = shift; my $blocksize = shift; my $handler_io = $_IO_MAP_{$handler}; + my $valid_opts; - if ($self->checkOptions($options)) { - $self->{'error'} = "openDevice(): Invalid options '$options' given for device $device"; + ($options, $valid_opts) = $self->checkOptions($options); + + if (!$valid_opts) { + $self->{'error'} = "openDevice(): Invalid option(s) '$options' given for device $device"; return $TRUE; } @@ -642,6 +654,7 @@ sub clearUsers { sub handlerExists { my $self = shift; my $handler = shift; + my $handlers = $self->handlers(); foreach my $_handler (@{$handlers}) { @@ -927,16 +940,19 @@ sub group_private { sub checkOptions { my $self = shift; my $options = shift; + my $o_string; - return if (!$options); + return undef, $TRUE if (!$options); foreach my $option (split(/\s+/, $options)) { - foreach my $avail (@_AVAILABLE_OPTIONS_) { - return $FALSE if ($avail eq $option); - } + my $map = $_AVAILABLE_OPTIONS_{$option}; + return undef, $FALSE if (!$map); + $o_string .= ",$map"; } - return $TRUE; + $o_string =~ s/^\,//; + + return $o_string, $TRUE; } sub errorString { diff --git a/scstadmin/scstadmin b/scstadmin/scstadmin index 7c603cefa..64a66800f 100755 --- a/scstadmin/scstadmin +++ b/scstadmin/scstadmin @@ -62,7 +62,7 @@ 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, BLOCKIO + WRITE_THROUGH, READ_ONLY, O_DIRECT, NULLIO, NV_CACHE, BIO Examples: Enable target mode for fibre card specifying its WWN @@ -748,9 +748,7 @@ sub applyConfiguration { readWorkingConfig() if ($force); - foreach my $vname (keys %used_devs) { - my $_handler = $used_devs{$vname}; - + foreach my $_handler (sort keys %{$$config{'HANDLER'}}) { if (!$HANDLERS{$_HANDLER_MAP_{$_handler}}) { print "\t-> WARNING: Handler '$_handler' does not exist.\n"; $errs += 1; @@ -758,7 +756,7 @@ sub applyConfiguration { } foreach my $device (@{$$config{'HANDLER'}->{$_handler}->{'DEVICE'}}) { - my(undef, $path, $options, $blocksize) = split(/\,/, $device); + my($vname, $path, $options, $blocksize) = split(/\,/, $device); $path = cleanupString($path); $options =~ s/\s+//; $options =~ s/\|/,/; @@ -943,6 +941,7 @@ sub clearConfiguration { print "\nRemoving all handler devices:\n\n"; foreach my $device (keys %{$DEVICES}) { + next if (!$$DEVICES{$device}); next if ($SCST->handlerType($$DEVICES{$device}) != $SCST::SCST::IOTYPE_VIRTUAL); $errs += removeDevice($_REVERSE_MAP_{$$DEVICES{$device}}, $device); } @@ -1388,6 +1387,7 @@ sub readConfig { ($section, $arg) = split(/\s+/, $1, 2); } elsif ($section && $arg && $line) { my($parameter, $value) = split(/\s+/, $line, 2); + push @{$config{$section}->{$arg}->{$parameter}}, $value; } }