[stgt] PATCH: support shared accounts in targets.conf
Dax Kelson
dkelson at gurulabs.com
Wed Apr 28 21:46:28 CEST 2010
I tried creating a targets.conf with multiple targets, all with the same
outgoing account.
Snippet from my targets.conf:
<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>
<target iqn.1999-07.com.gurulabs:station3>
backing-store /srv/iscsi-luns/station3
incominguser station3 letmein
outgoinguser server1 itsreallyme
</target>
The current logic in tgt-admin doesn't having the same account (incoming
or outgoing) defined on multiple targets. The current logic always
deletes an account before adding which removes the account from any
already defined targets.
Attached is a tested patch to support the configuration above:
--- /usr/sbin/tgt-admin.orig 2010-04-28 12:49:49.000000000 -0600
+++ /usr/sbin/tgt-admin 2010-04-28 13:42:16.000000000 -0600
@@ -92,6 +92,7 @@
my %tgtadm_output_name;
my @largest_tid;
my $next_tid;
+my %existing_accounts;
# Look up which targets are configured
sub process_targets {
@@ -121,6 +122,21 @@
$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 an array 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
@@ -599,8 +615,12 @@
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]");
}
}
@@ -613,8 +633,12 @@
}
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");
}
@@ -1166,12 +1190,14 @@
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;
--
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