- Replace a device on a given LUN when applying the configuration instead of removing
authormgandalf <mgandalf@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Wed, 23 Sep 2009 14:58:19 +0000 (14:58 +0000)
committermgandalf <mgandalf@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Wed, 23 Sep 2009 14:58:19 +0000 (14:58 +0000)
  the old device and assigning the new one.

git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@1131 d57e44dd-8a1f-0410-8b47-8ef2f437770f

scstadmin/ChangeLog
scstadmin/scst-0.8.21/lib/SCST/SCST.pm
scstadmin/scstadmin

index f5560d6..844acb4 100644 (file)
@@ -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
index b845d3b..d8302c2 100644 (file)
@@ -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;
        }
index b610ec7..03d68dd 100755 (executable)
@@ -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;