From 4be7ffa4da4e5abc21ad217bf5e7933e4eb0f762 Mon Sep 17 00:00:00 2001 From: Mark Buechler Date: Wed, 23 Sep 2009 14:58:19 +0000 Subject: [PATCH] - Replace a device on a given LUN when applying the configuration instead of removing the old device and assigning the new one. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@1131 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/ChangeLog | 2 + scstadmin/scst-0.8.21/lib/SCST/SCST.pm | 2 +- scstadmin/scstadmin | 59 +++++++++++++++++--------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/scstadmin/ChangeLog b/scstadmin/ChangeLog index f5560d6e1..844acb428 100644 --- a/scstadmin/ChangeLog +++ b/scstadmin/ChangeLog @@ -2,6 +2,8 @@ Changes for 1.0.9 - Move a user from one group to another when applying the configuration instead of deleting from one and adding to another the same user. +- Replace a device on a given LUN when applying the configuration instead of removing + the old device and assigning the new one. - Add the ability to specify options (ie: READ_ONLY) in assignments in scst.conf. - Remove unused references to handler IOs that don't exist and cleanup the write configuration function to only write vdisk and vcdrom devices. All other devices diff --git a/scstadmin/scst-0.8.21/lib/SCST/SCST.pm b/scstadmin/scst-0.8.21/lib/SCST/SCST.pm index b845d3b5b..d8302c27d 100644 --- a/scstadmin/scst-0.8.21/lib/SCST/SCST.pm +++ b/scstadmin/scst-0.8.21/lib/SCST/SCST.pm @@ -915,7 +915,7 @@ sub replaceDeviceInGroup { ($options, $valid_opts) = $self->checkOptions($options, 'ASSIGN'); if (!$valid_opts) { - $self->{'error'} = "assignDeviceToGroup(): Invalid option(s) '$options' given for ". + $self->{'error'} = "replaceDeviceInGroup(): Invalid option(s) '$options' given for ". "device '$newDevice'"; return 1; } diff --git a/scstadmin/scstadmin b/scstadmin/scstadmin index b610ec782..03d68dd7b 100755 --- a/scstadmin/scstadmin +++ b/scstadmin/scstadmin @@ -703,9 +703,10 @@ sub applyConfiguration { foreach my $device (sort keys %{$_assignments}) { if (!defined($used_assignments{$group}->{$device}) || ($$_assignments{$device} != $used_assignments{$group}->{$device})) { - if ($$_assignments{$device} != $used_assignments{$group}->{$device}) { - print "\t-> WARNING: Device '$device' assigned to group '$group' is at LUN ". - $used_assignments{$group}->{$device}. + if (defined($used_assignments{$group}->{$device}) && + ($$_assignments{$device} != $used_assignments{$group}->{$device})) { + print "\t-> WARNING: Device '$device' assigned to group '$group' ". + "is at LUN ".$used_assignments{$group}->{$device}. " whereas working configuration reflects LUN ".$$_assignments{$device}; } else { print "\t-> WARNING: Device '$device' is not associated with group ". @@ -713,11 +714,25 @@ sub applyConfiguration { } if (!$check) { - print ", releasing.\n"; - if (releaseDevice($group, $device)) { - $errs++; + my $_lun = $$_assignments{$device}; + + my $replace_dev = findAssignedLun($used_assignments{$group}, $_lun); + + if (defined($replace_dev) && ($replace_dev ne $device)) { + print ", replacing with device '$replace_dev'.\n"; + + if (replaceDevice($group, $replace_dev, $_lun)) { + $errs++; + } else { + $changes++; + } } else { - $changes++; + print ", releasing.\n"; + if (releaseDevice($group, $device)) { + $errs++; + } else { + $changes++; + } } } else { print ".\n"; @@ -953,6 +968,14 @@ sub applyConfiguration { ", whereas the working configuration reflects LUN $lun.\n". "\t Use -ForceConfig to force this LUN change.\n" if (!$force && !$check); } else { + my $replace_dev = findAssignedLun($_assignments, $lun); + + if (defined($replace_dev) && ($vname ne $replace_dev)) { + print "\t-> WARNING: Use -ForceConfig to replace device '$replace_dev' ". + "with device '$vname' for group '$group'.\n" if (!$force); + next; + } + if ($check) { $lun = 'auto' if (!defined($lun)); print "\t-> New device assignment for '$vname' to group '$group' at LUN $lun.\n"; @@ -1722,27 +1745,21 @@ sub findUserGroupInCurrent { return undef; } -sub findDeviceGroup { - my $device = shift; - my $config = shift; +sub findAssignedLun { + my $associations = shift; + my $lun = shift; - foreach my $group (keys %{$$config{'ASSIGNMENT'}}) { - foreach my $device (@{$$config{'ASSIGNMENT'}->{$group}->{'DEVICE'}}) { - my($vname, $arg) = split(/\,/, $device, 2); - $vname = cleanupString($vname); - return $group if ($vname eq $device); + return undef if (!defined($lun)); + + foreach my $device (keys %{$associations}) { + if ($$associations{$device} == $lun) { + return $device; } } return undef; } -sub findDeviceGroupInCurrent { - my $device = shift; - - return undef; -} - sub cleanupString { my $string = shift;