mirror of
https://github.com/SCST-project/scst.git
synced 2026-05-28 17:30:18 +00:00
- Properly re-open devices where create attributes have changed.
- Remove unconfigured virtual targets. - A few minor fixes. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@1986 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -146,7 +146,7 @@ my %VERBOSE_ERROR = (
|
||||
(SCST_C_TGT_ADDATTR_FAIL) => 'Failed to add target dynamic attribute. See "dmesg" for more information.',
|
||||
(SCST_C_TGT_REMATTR_FAIL) => 'Failed to remove target dynamic attribute. See "dmesg" for more information.',
|
||||
(SCST_C_TGT_NO_LUN) => 'No such LUN exists.',
|
||||
(SCST_C_TGT_ADD_LUN_FAIL) => 'Failed to add LUN. See "dmesg" for more information.',
|
||||
(SCST_C_TGT_ADD_LUN_FAIL) => 'Failed to add LUN to target. See "dmesg" for more information.',
|
||||
(SCST_C_TGT_LUN_EXISTS) => 'LUN already exists.',
|
||||
(SCST_C_TGT_BAD_ATTRIBUTES) => 'Bad attributes given for target.',
|
||||
(SCST_C_TGT_ATTRIBUTE_STATIC) => 'Target attribute specified is static.',
|
||||
@@ -160,7 +160,7 @@ my %VERBOSE_ERROR = (
|
||||
|
||||
(SCST_C_GRP_NO_LUN) => 'No such LUN exists.',
|
||||
(SCST_C_GRP_LUN_EXISTS) => 'LUN already exists.',
|
||||
(SCST_C_GRP_ADD_LUN_FAIL) => 'Failed to add LUN. See "dmesg" for more information.',
|
||||
(SCST_C_GRP_ADD_LUN_FAIL) => 'Failed to add LUN to group. See "dmesg" for more information.',
|
||||
(SCST_C_GRP_REM_LUN_FAIL) => 'Failed to remove LUN. See "dmesg" for more information.',
|
||||
(SCST_C_GRP_CLR_LUN_FAIL) => 'Failed to clear LUNs from group. See "dmesg" for more information.',
|
||||
(SCST_C_GRP_BAD_ATTRIBUTES) => 'Bad attributes given for group.',
|
||||
|
||||
@@ -211,6 +211,7 @@ MAX_LUNS => 255,
|
||||
|
||||
my $SCST;
|
||||
my $CONFIG;
|
||||
my $CONFIGFILE;
|
||||
my $_DEBUG_;
|
||||
my $_NOPROMPT_;
|
||||
|
||||
@@ -606,18 +607,21 @@ sub main {
|
||||
|
||||
SWITCH: {
|
||||
defined($applyConfig) && do {
|
||||
$rc = checkConfiguration($applyConfig);
|
||||
$CONFIGFILE = $applyConfig;
|
||||
$rc = checkConfiguration();
|
||||
immediateExit("Configuration has errors, aborting.") if ($rc);
|
||||
last if ($force && prompt());
|
||||
$rc = applyConfiguration($applyConfig, $force);
|
||||
$rc = applyConfiguration($force);
|
||||
last SWITCH;
|
||||
};
|
||||
defined($checkConfig) && do {
|
||||
$rc = checkConfiguration($checkConfig);
|
||||
$CONFIGFILE = $checkConfig;
|
||||
$rc = checkConfiguration();
|
||||
last SWITCH;
|
||||
};
|
||||
defined($writeConfig) && do {
|
||||
$rc = writeConfiguration($writeConfig, $nonkey);
|
||||
$CONFIGFILE = $writeConfig;
|
||||
$rc = writeConfiguration($nonkey);
|
||||
last SWITCH;
|
||||
};
|
||||
defined($clearConfig) && do {
|
||||
@@ -888,25 +892,24 @@ sub readWorkingConfig {
|
||||
}
|
||||
|
||||
sub writeConfiguration {
|
||||
my $file = shift;
|
||||
my $nonkey = shift;
|
||||
|
||||
if (-f $file) {
|
||||
if (!unlink $file) {
|
||||
if (-f $CONFIGFILE) {
|
||||
if (!unlink $CONFIGFILE) {
|
||||
print "Failed to save current configuration, specified ".
|
||||
"file exists and cannot be deleted.\n";
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
my $io = new IO::File $file, O_CREAT|O_WRONLY;
|
||||
|
||||
my $io = new IO::File $CONFIGFILE, O_CREAT|O_WRONLY;
|
||||
|
||||
if (!$io) {
|
||||
print "Failed to save configuration to file '$file': $!\n";
|
||||
print "Failed to save configuration to file '$CONFIGFILE': $!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
print "Writing current configuration to file '$file'.. ";
|
||||
print "Writing current configuration to file '$CONFIGFILE'.. ";
|
||||
|
||||
print $io "# Automatically generated by $Version.\n\n";
|
||||
|
||||
@@ -1372,15 +1375,14 @@ sub writeConfiguration {
|
||||
}
|
||||
|
||||
sub checkConfiguration {
|
||||
my $file = shift;
|
||||
my $no_drivers;
|
||||
my $no_handlers;
|
||||
my $warnings = 0;
|
||||
my $errors = 0;
|
||||
|
||||
print "-> Checking configuration file '$file' for errors.\n";
|
||||
print "-> Checking configuration file '$CONFIGFILE' for errors.\n";
|
||||
|
||||
$CONFIG = readConfig($file) if (!$CONFIG);
|
||||
readConfigFile() if (!$CONFIG);
|
||||
|
||||
# Check for a minimum sane configuration
|
||||
if (!defined($$CONFIG{'TARGET_DRIVER'}) ||
|
||||
@@ -1516,10 +1518,9 @@ sub checkConfiguration {
|
||||
}
|
||||
|
||||
sub applyConfiguration {
|
||||
my $file = shift;
|
||||
my $force = shift;
|
||||
|
||||
$CONFIG = readConfig($file) if (!$CONFIG);
|
||||
readConfigFile() if (!$CONFIG);
|
||||
|
||||
# Apply config deletions
|
||||
if ($force) {
|
||||
@@ -1574,6 +1575,7 @@ sub applyConfigDevices {
|
||||
|
||||
foreach my $device (sort keys %{$devices}) {
|
||||
my %_attributes;
|
||||
my %_cattributes;
|
||||
foreach my $item (keys %{$$devices{$device}}) {
|
||||
next if ($item eq 'CREATE_ATTRIBUTES');
|
||||
$_attributes{$item} = $$devices{$device}->{$item};
|
||||
@@ -1582,6 +1584,23 @@ sub applyConfigDevices {
|
||||
my $attributes = configToAttr(\%_attributes);
|
||||
|
||||
if (handlerHasDevice($handler, $device)) {
|
||||
my $create_attrs = configToAttr($$devices{$device}->{'CREATE_ATTRIBUTES'});
|
||||
my $old_create_attrs = $SCST->deviceAttributes($device);
|
||||
|
||||
if (compareToKeyAttribute($create_attrs, $old_create_attrs)) {
|
||||
print "-> Device '$device' is configured for different CREATE attributes.\n";
|
||||
|
||||
if ($deletions) {
|
||||
print "\t-> Closing and re-opening with new attributes.\n";
|
||||
closeDevice($handler, $device, $deletions);
|
||||
openDevice($handler, $device, $create_attrs);
|
||||
readWorkingConfig();
|
||||
} else {
|
||||
print "\t-> Use -force to re-open device with new attributes. ".
|
||||
"NOTE: This will disrupt all initiators using this device.\n";
|
||||
}
|
||||
}
|
||||
|
||||
setDeviceAttributes($device, $attributes, $deletions)
|
||||
if (scalar keys %{$attributes});
|
||||
next;
|
||||
@@ -1709,6 +1728,17 @@ sub applyTargetAssignments {
|
||||
my $targets = shift;
|
||||
my $deletions = shift;
|
||||
|
||||
foreach my $target (keys %{$CURRENT{'assign'}->{$driver}}) {
|
||||
if (!defined($$targets{$target})) {
|
||||
if ($deletions) {
|
||||
removeVirtualTarget($driver, $target);
|
||||
} else {
|
||||
print "-> Virtual target '$target' for driver '$driver' is not in configuration. ".
|
||||
"Use -force to remove it.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $target (sort keys %{$targets}) {
|
||||
if (!defined($CURRENT{'assign'}->{$driver}->{$target})) {
|
||||
if (!$SCST->driverIsVirtualCapable($driver)) {
|
||||
@@ -1810,6 +1840,18 @@ sub applyInitiatorAssignments {
|
||||
}
|
||||
}
|
||||
|
||||
sub compareToKeyAttribute {
|
||||
my $first = shift;
|
||||
my $second = shift;
|
||||
|
||||
foreach my $attr (keys %{$first}) {
|
||||
next if (!defined($$second{$attr}->{'keys'}->{'0'}->{'value'}) && ($$first{$attr} == 0));
|
||||
return TRUE if ($$first{$attr} ne $$second{$attr}->{'keys'}->{'0'}->{'value'});
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
sub clearConfiguration {
|
||||
my $force = shift;
|
||||
|
||||
@@ -3391,15 +3433,14 @@ sub issueLip {
|
||||
|
||||
####################################################################
|
||||
|
||||
sub readConfig {
|
||||
my $file = shift;
|
||||
sub readConfigFile {
|
||||
my $buffer;
|
||||
my @stanza;
|
||||
my $level;
|
||||
|
||||
my $io = new IO::File $file, O_RDONLY;
|
||||
my $io = new IO::File $CONFIGFILE, O_RDONLY;
|
||||
|
||||
immediateExit("Unable to open configuration file '$file': $!")
|
||||
immediateExit("Unable to open configuration file '$CONFIGFILE': $!")
|
||||
if (!$io);
|
||||
|
||||
while (my $line = <$io>) {
|
||||
@@ -3409,10 +3450,10 @@ sub readConfig {
|
||||
|
||||
if (($parm eq 'HANDLER') || ($parm eq 'GROUP') ||
|
||||
($parm eq 'ASSIGNMENT')) {
|
||||
print "\nWARNING: Using a deprecated configuration file. ".
|
||||
print "\nNOTE: Using a deprecated configuration file. ".
|
||||
"I will attempt to convert it for you.\n\n";
|
||||
|
||||
return readOldConfig($file);
|
||||
return readOldConfigFile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3422,7 +3463,7 @@ sub readConfig {
|
||||
my @buff_a;
|
||||
@buff_a = split(//, $buffer);
|
||||
|
||||
return parseStanza(\@buff_a);
|
||||
$CONFIG = parseStanza(\@buff_a);
|
||||
}
|
||||
|
||||
sub parseStanza {
|
||||
@@ -3490,8 +3531,7 @@ sub parseLine {
|
||||
}
|
||||
}
|
||||
|
||||
sub readOldConfig {
|
||||
my $confile = shift;
|
||||
sub readOldConfigFile {
|
||||
my $ignoreError = shift;
|
||||
my %config;
|
||||
my $section;
|
||||
@@ -3500,12 +3540,12 @@ sub readOldConfig {
|
||||
my $last_arg;
|
||||
my %empty;
|
||||
|
||||
my $io = new IO::File $confile, O_RDONLY;
|
||||
my $io = new IO::File $CONFIGFILE, O_RDONLY;
|
||||
|
||||
if (!$io) {
|
||||
return undef if ($ignoreError);
|
||||
|
||||
die("FATAL: Unable to open specified configuration file $confile: $!\n");
|
||||
die("FATAL: Unable to open specified configuration file 'CONFIGFILE': $!\n");
|
||||
}
|
||||
|
||||
while (my $line = <$io>) {
|
||||
@@ -3627,7 +3667,7 @@ sub readOldConfig {
|
||||
}
|
||||
|
||||
if (!$found_t) {
|
||||
print "WARNING: Unable to find target $group. I will add this target to ".
|
||||
print "NOTE: Unable to find target $group. I will add this target to ".
|
||||
"all drivers capable of creating targets.\n";
|
||||
|
||||
foreach my $driver (@{$drivers}) {
|
||||
@@ -3659,7 +3699,7 @@ sub readOldConfig {
|
||||
}
|
||||
|
||||
if (!$has_enabled) {
|
||||
print "WARNING: No targets set to 'enable' within your configuration file. Please be sure to ".
|
||||
print "NOTE: No targets set to 'enable' within your configuration file. Please be sure to ".
|
||||
"save write your configuration with -write_config and review it carefully.\n\n";
|
||||
|
||||
# Fill in with known targets, all disabled.
|
||||
@@ -3696,7 +3736,7 @@ sub readOldConfig {
|
||||
}
|
||||
}
|
||||
|
||||
return \%new;
|
||||
$CONFIG = \%new;
|
||||
}
|
||||
|
||||
sub addAllGroupsToTarget {
|
||||
|
||||
Reference in New Issue
Block a user