diff --git a/scstadmin/scstadmin.sysfs b/scstadmin/scstadmin.sysfs index 1a3cf634d..852d0ef67 100755 --- a/scstadmin/scstadmin.sysfs +++ b/scstadmin/scstadmin.sysfs @@ -46,7 +46,7 @@ Query Operations -list_sessions : List all current initiator sessions. -Set Operations +Set Attribute Operations -set_scst_attr : Sets SCST attribute(s)

to value . -attributes -set_hnd_attr : Sets handler attribute(s)

to value . @@ -69,6 +69,20 @@ Set Operations -group -attributes +Add Dynamic Attribute Operations + -add_drv_attr : Adds driver attribute(s)

to value . + -attributes + -add_tgt_attr : Adds target attribute(s)

to value . + -driver + -attributes + +Remove Dynamic Attribute Operations + -rem_drv_attr : Remove driver attribute(s)

to value . + -attributes + -rem_tgt_attr : Remove target attribute(s)

to value . + -driver + -attributes + Device Operations -open_dev : Adds a new device using handler . -handler @@ -2950,31 +2964,56 @@ sub readOldConfig { if ($driver) { %{$new{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'enabled'}->{'1'}} = (); - - foreach my $group (keys %{$config{'GROUP'}}) { - %{$new{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'GROUP'}->{$group}} = (); - if (defined($config{'GROUP'}->{$group}->{'USER'})) { - foreach my $user (@{$config{'GROUP'}->{$group}->{'USER'}}) { - %{$new{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'GROUP'}->{$group}->{'INITIATOR'}->{$user}} = (); - } - } - } - - foreach my $group (keys %{$config{'ASSIGNMENT'}}) { - foreach my $device (@{$config{'ASSIGNMENT'}->{$group}->{'DEVICE'}}) { - my($device, $lun) = split(/\,/, $device); - %{$new{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'GROUP'}->{$group}->{'LUN'}->{$lun}->{$device}} = (); - } - } + addTargetToConfig(\%config, \%new, $driver, $target); } else { immediateExit("Unable to determine target driver information for target '$wwn'. ". "Please ensure this target driver is loaded."); } } + if (!scalar keys %{$new{'TARGET_DRIVER'}}) { + # Fill in with known targets, all disabled. + print "WARNING: There are no enabled targets in your configuration. I'll use existing targets, however, ". + "this will make assignments available for all loaded targets.\n\n"; + my $drivers = $SCST->drivers(); + + foreach my $driver (@{$drivers}) { + my $targets = $SCST->targets($driver); + + foreach my $target (@{$targets}) { + %{$new{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'enabled'}->{'0'}} = (); + + addTargetToConfig(\%config, \%new, $driver, $target); + } + } + } + return \%new; } +sub addTargetToConfig { + my $config = shift; + my $new = shift; + my $driver = shift; + my $target = shift; + + foreach my $group (keys %{$$config{'GROUP'}}) { + %{$$new{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'GROUP'}->{$group}} = (); + if (defined($$config{'GROUP'}->{$group}->{'USER'})) { + foreach my $user (@{$$config{'GROUP'}->{$group}->{'USER'}}) { + %{$$new{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'GROUP'}->{$group}->{'INITIATOR'}->{$user}} = (); + } + } + } + + foreach my $group (keys %{$$config{'ASSIGNMENT'}}) { + foreach my $device (@{$$config{'ASSIGNMENT'}->{$group}->{'DEVICE'}}) { + my($device, $lun) = split(/\,/, $device); + %{$$new{'TARGET_DRIVER'}->{$driver}->{'TARGET'}->{$target}->{'GROUP'}->{$group}->{'LUN'}->{$lun}->{$device}} = (); + } + } +} + sub findTargetDriver { my $target = shift;