Add support to manage multiple control ports. Basically add the ability to pass through "-C NNNN" (or --control_port NNNN") option to tgtadm Signed-Off-By: Chandra Seetharaman <sekharan at us.ibm.com --------------------------- --- tgt-admin 2010-04-01 10:09:06.000000000 -0700 +++ /usr/sbin/tgt-admin 2010-04-07 07:09:25.000000000 -0700 @@ -29,6 +29,7 @@ --update <value> update configuration for all or selected targets (see "--update help" for more info) -s, --show show all the targets + -C, --control_port <num> specify an alternative configuration file -c, --conf <conf file> specify an alternative configuration file --ignore-errors continue even if tgtadm exits with non-zero code -f, --force force some operations even if the target is in use @@ -57,6 +58,8 @@ my $dump = 0; my $verbose = 0; my $help = 0; +my $control_port=0; +Getopt::Long::Configure("no_ignore_case"); my $result = GetOptions ( "e|execute" => \$execute, "delete=s" => \$delete, @@ -71,6 +74,7 @@ "dump" => \$dump, "v|verbose" => \$verbose, "h|help" => \$help, + "C|control_port=s" => \$control_port, ); if (($help == 1) || ($param eq undef)) { @@ -79,7 +83,7 @@ # Show all the targets and exit if ($show == 1) { - execute("tgtadm --op show --mode target"); + execute("tgtadm -C $control_port --op show --mode target"); exit; } @@ -97,7 +101,7 @@ die("You must be root to run this program.\n"); } - my @show_target = `tgtadm --op show --mode target`; + my @show_target = `tgtadm -C $control_port --op show --mode target`; my $tid; my $targetname; # Here, we create hashes of target names (all target data) and target tids @@ -152,8 +156,8 @@ my $configured = $_[1]; my $connected = $_[2]; my $in_configfile = $_[3]; - foreach my $k (sort keys %conf) { + foreach my $k (sort keys %conf) { if ($k eq "default-driver") { if (not length ref($conf{$k})) { $default_driver = $conf{$k}; @@ -166,9 +170,16 @@ if ($conf{$k} eq "yes") { $ignore_errors = 1; } + } elsif ($k eq "control-port") { + if ($control_port eq 0) { + $control_port = $conf{$k}; + } else { + print "Multiple control-port definitions are not allowed!\n"; + print "Check your config file for errors.\n"; + exit 1; + } } } - # If $default_driver is empty, default to iscsi if (not defined $default_driver) { execute("# default-driver not defined, defaulting to iscsi.\n"); @@ -228,7 +239,7 @@ } my $driver = $target_options{"driver"}; execute("# Adding target: $target"); - execute("tgtadm --lld $driver --op new --mode target --tid $next_tid -T $target"); + execute("tgtadm -C $control_port --lld $driver --op new --mode target --tid $next_tid -T $target"); foreach my $k3 (sort keys %{$conf{$k}{$k2}}) { $option = $k3; $value = $conf{$k}{$k2}{$k3}; @@ -242,7 +253,7 @@ } if ($allowall == 1) { - execute("tgtadm --lld $driver --op bind --mode target --tid $next_tid -I ALL"); + execute("tgtadm -C $control_port --lld $driver --op bind --mode target --tid $next_tid -I ALL"); } } else { @@ -330,7 +341,7 @@ if ($param eq "write-cache") { if ($param_value eq "off") { - return("tgtadm --lld $driver --op update --mode logicalunit --tid $next_tid --lun=$lun --params mode_page=8:0:18:0x10:0:0xff:0xff:0:0:0xff:0xff:0xff:0xff:0x80:0x14:0:0:0:0:0:0"); + return("tgtadm -C $control_port --lld $driver --op update --mode logicalunit --tid $next_tid --lun=$lun --params mode_page=8:0:18:0x10:0:0xff:0xff:0:0:0xff:0xff:0xff:0xff:0x80:0x14:0:0:0:0:0:0"); } elsif ($param_value eq "on" || not length $param_value) { return("# Write cache is enabled (default) for lun $lun."); } else { @@ -341,10 +352,10 @@ if ($param eq "scsi_id" || $param eq "scsi_sn" || $param eq "vendor_id" || $param eq "product_id" || $param eq "product_rev" || $param eq "sense_format" || $param eq "removable" || $param eq "online" || $param eq "path" || $param eq "mode_page") { - return("tgtadm --lld $driver --op update --mode logicalunit --tid $next_tid --lun=$lun --params $param=\"$param_value\""); + return("tgtadm -C $control_port --lld $driver --op update --mode logicalunit --tid $next_tid --lun=$lun --params $param=\"$param_value\""); } if ($param eq "params") { - return("tgtadm --lld $driver --op update --mode logicalunit --tid $next_tid --lun=$lun --params \"$param_value\""); + return("tgtadm -C $control_port --lld $driver --op update --mode logicalunit --tid $next_tid --lun=$lun --params \"$param_value\""); } } @@ -564,7 +575,7 @@ # Execute commands for a given LUN if (length $device_type) { $device_type = "--device-type $device_type" }; if (length $bs_type) { $bs_type = "--bstype $bs_type" }; - execute("tgtadm --lld $driver --op new --mode logicalunit --tid $next_tid --lun $lun -b $backing_store $device_type $bs_type"); + execute("tgtadm -C $control_port --lld $driver --op new --mode logicalunit --tid $next_tid --lun $lun -b $backing_store $device_type $bs_type"); # Commands should be executed in order my @execute_last; @@ -638,9 +649,9 @@ foreach my $incominguser (@value_arr) { my @userpass = split(/ /, $incominguser); check_value($userpass[1]); - execute("tgtadm --lld $driver --mode account --op delete --user=$userpass[0]"); - execute("tgtadm --lld $driver --mode account --op new --user=$userpass[0] --password=$userpass[1]"); - execute("tgtadm --lld $driver --mode account --op bind --tid=$next_tid --user=$userpass[0]"); + execute("tgtadm -C $control_port --lld $driver --mode account --op delete --user=$userpass[0]"); + execute("tgtadm -C $control_port --lld $driver --mode account --op new --user=$userpass[0] --password=$userpass[1]"); + execute("tgtadm -C $control_port --lld $driver --mode account --op bind --tid=$next_tid --user=$userpass[0]"); } } @@ -652,9 +663,9 @@ } my @userpass = split(/ /, @$value[0]); check_value($userpass[1]); - execute("tgtadm --lld $driver --mode account --op delete --user=$userpass[0]"); - execute("tgtadm --lld $driver --mode account --op new --user=$userpass[0] --password=$userpass[1]"); - execute("tgtadm --lld $driver --mode account --op bind --tid=$next_tid --user=$userpass[0] --outgoing"); + execute("tgtadm -C $control_port --lld $driver --mode account --op delete --user=$userpass[0]"); + execute("tgtadm -C $control_port --lld $driver --mode account --op new --user=$userpass[0] --password=$userpass[1]"); + execute("tgtadm -C $control_port --lld $driver --mode account --op bind --tid=$next_tid --user=$userpass[0] --outgoing"); } if ($option eq "initiator-address") { @@ -663,7 +674,7 @@ my @value_arr = @$value; foreach my $initiator_address (@value_arr) { check_value($initiator_address); - execute("tgtadm --lld $driver --op bind --mode target --tid $next_tid -I $initiator_address"); + execute("tgtadm -C $control_port --lld $driver --op bind --mode target --tid $next_tid -I $initiator_address"); } } @@ -692,7 +703,7 @@ execute("# Warning: only one $option is allowed. Will only use the first one."); } check_value($option); - execute("tgtadm --lld $driver --mode target --op update --tid $next_tid --name $option --value $$value[0]"); + execute("tgtadm -C $control_port --lld $driver --mode target --op update --tid $next_tid --name $option --value $$value[0]"); } } @@ -809,15 +820,15 @@ # Run over all targets and offline/ready them my @all_targets = keys %tgtadm_output_tid; foreach my $existing_target (@all_targets) { - execute("tgtadm --op update --mode target --tid=$tgtadm_output_tid{$existing_target} -n state -v $var"); + execute("tgtadm -C $control_port --op update --mode target --tid=$tgtadm_output_tid{$existing_target} -n state -v $var"); } } elsif ($off_ready =~ m/tid=(.+)/) { process_targets; - execute("tgtadm --op update --mode target --tid=$1 -n state -v $var"); + execute("tgtadm -C $control_port --op update --mode target --tid=$1 -n state -v $var"); } else { process_targets; if (length $tgtadm_output_tid{$off_ready}) { - execute("tgtadm --op update --mode target --tid=$tgtadm_output_tid{$off_ready} --name=\"$off_ready\" -n state -v $var"); + execute("tgtadm -C $control_port --op update --mode target --tid=$tgtadm_output_tid{$off_ready} --name=\"$off_ready\" -n state -v $var"); } else { print "There is no target with name \"$off_ready\", can't $var it!\n"; exit 1; @@ -913,16 +924,16 @@ # Remove ACLs first my @acl_info = show_target_info($current_target, "acl_information"); foreach my $acl (@acl_info) { - execute("tgtadm --op unbind --mode target --tid $tgtadm_output_tid{$current_target} -I $acl"); + execute("tgtadm -C $control_port --op unbind --mode target --tid $tgtadm_output_tid{$current_target} -I $acl"); } # Now, remove all sessions / connections from that tid my %sessions = show_target_info($current_target, "sessions"); foreach my $sid (keys %sessions) { foreach my $cid ($sessions{$sid}) { - execute("tgtadm --op delete --mode conn --tid $tgtadm_output_tid{$current_target} --sid $sid --cid $cid"); + execute("tgtadm -C $control_port --op delete --mode conn --tid $tgtadm_output_tid{$current_target} --sid $sid --cid $cid"); } } - execute("tgtadm --mode target --op delete --tid=$tgtadm_output_tid{$current_target}"); + execute("tgtadm -C $control_port --mode target --op delete --tid=$tgtadm_output_tid{$current_target}"); } else { if ($update ne 0) { $del_upd_text = "updated"; @@ -934,7 +945,7 @@ } } elsif (length $tgtadm_output_tid{$current_target}) { execute("# Removing target: $current_target"); - execute("tgtadm --mode target --op delete --tid=$tgtadm_output_tid{$current_target}"); + execute("tgtadm -C $control_port --mode target --op delete --tid=$tgtadm_output_tid{$current_target}"); } else { if (length $current_tid) { execute("# Target with tid $current_tid does not exist!"); @@ -1204,8 +1215,8 @@ } if ($execute == 1) { - process_targets; parse_configs; + process_targets; add_targets; remove_targets; } elsif ($delete ne 0) { -- To unsubscribe from this list: send the line "unsubscribe stgt" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html |