[stgt] [PATCH] Change tgt-admin to re-uses existing accounts
Dax Kelson
dkelson at gurulabs.com
Thu May 6 05:34:11 CEST 2010
Currently tgt-admin always deletes and add accounts. The effect
of the current behavior is that multiple targets can't use the
same incoming or outgoing account. This patch allows multiple
targets to use the same incoming and/or outgoing accounts and
supports a targets.conf with the following configuration:
<target iqn.1999-07.com.gurulabs:station1>
backing-store /srv/iscsi-luns/station1
incominguser station1 letmein
outgoinguser server1 itsreallyme
</target>
<target iqn.1999-07.com.gurulabs:station2>
backing-store /srv/iscsi-luns/station2
incominguser station2 letmein
outgoinguser server1 itsreallyme
</target>
Signed-off-by: Dax Kelson <dkelson at gurulabs.com>
---
scripts/tgt-admin | 34 ++++++++++++++++++++++++++++++----
1 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/scripts/tgt-admin b/scripts/tgt-admin
index fa0db57..99754bf 100755
--- a/scripts/tgt-admin
+++ b/scripts/tgt-admin
@@ -89,6 +89,7 @@ my %tgtadm_output_tid;
my %tgtadm_output_name;
my @largest_tid;
my $next_tid;
+my %existing_accounts;
# Look up which targets are configured
sub process_targets {
@@ -118,6 +119,21 @@ sub process_targets {
$next_tid = $largest_tid[$#largest_tid];
}
+sub process_accounts {
+ # We need to run as root
+ if ( $> ) {
+ die("You must be root to run this program.\n");
+ }
+
+ my @show_account = `tgtadm --op show --mode account`;
+ # Here, we create a hash of accounts
+ foreach my $show_account_line (@show_account) {
+ if ( $show_account_line =~ m/^\s+(.*?)$/ ) {
+ $existing_accounts{$1} = 1;
+ }
+ }
+}
+
# Parse config file(s)
sub parse_configs {
# Parse the config
@@ -638,8 +654,12 @@ sub process_options {
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]");
+ # Only delete or create account if it doesn't already exist
+ if (! exists $existing_accounts{$userpass[0]} ) {
+ 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]");
+ $existing_accounts{$userpass[0]} = 1;
+ }
execute("tgtadm --lld $driver --mode account --op bind --tid=$next_tid --user=$userpass[0]");
}
}
@@ -652,8 +672,12 @@ sub process_options {
}
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]");
+ # Only delete or create account if it doesn't already exist
+ if (! exists $existing_accounts{$userpass[0]} ) {
+ 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]");
+ $existing_accounts{$userpass[0]} = 1;
+ }
execute("tgtadm --lld $driver --mode account --op bind --tid=$next_tid --user=$userpass[0] --outgoing");
}
@@ -1205,12 +1229,14 @@ sub execute {
if ($execute == 1) {
process_targets;
+ process_accounts;
parse_configs;
add_targets;
remove_targets;
} elsif ($delete ne 0) {
delete_targets;
} elsif ($update ne 0) {
+ process_accounts;
update_targets;
} elsif ($dump == 1) {
dump_config;
--
1.6.6.1
--
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
More information about the stgt
mailing list