Re: tgt-admin and a -C, --control-port argument

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2010-03-31 at 10:48 +0200, Tomasz Chmielewski wrote:
> ronnie sahlberg wrote:
> > Hi Tomasz
> > 
> > tgtd and tgtadm now supports a -C, --control-port=X argument  allowing
> > to run multiple instances of tgtd in parallel, each one bound to a
> > dedicated ip address or port.
> > 
> > As the developer/maintainer of tgt-admin, would you consider adding a
> > -C, --control-port argument to tgt-admin?
> > If this argument is used, all calls to tgtadm would be changed to use
> > --control-port=X too ?
> 
> Sure, I'll add it to my list.
> 
> 
Hello Team,

How does the following patch look ( I just added a -C option and passing
it to tgtadm commands, to  keep it simple).

regards,

chandra
------------------------------------------
--- tgt-admin	2010-04-01 10:09:06.000000000 -0700
+++ /usr/sbin/tgt-admin	2010-04-05 09:30:32.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
@@ -228,7 +232,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 +246,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 +334,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 +345,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 +568,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 +642,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 +656,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 +667,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 +696,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 +813,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 +917,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 +938,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!");


--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux