From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ryan O'Hara Date: Mon, 6 Dec 2010 18:30:27 -0600 Subject: [Cluster-devel] [PATCH] fence_scsi_test: add 'clear' action Message-ID: <20101207003027.GA16607@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Added new 'clear' action that will remove all registrations and reservations on device(s). This action requires that the node be registered with the devices to be cleared. See sg_persit(3) for more information, specifically the -C option. Resolves: rhbz#603838 Signed-off-by: Ryan O'Hara --- fence/agents/scsi/fence_scsi_test.pl | 87 ++++++++++++++++++++++++--------- 1 files changed, 63 insertions(+), 24 deletions(-) diff --git a/fence/agents/scsi/fence_scsi_test.pl b/fence/agents/scsi/fence_scsi_test.pl index 25db6ba..5c2302c 100755 --- a/fence/agents/scsi/fence_scsi_test.pl +++ b/fence/agents/scsi/fence_scsi_test.pl @@ -68,6 +68,26 @@ sub do_action_off ($$$) return ($err); } +sub do_action_clear ($$) +{ + my ($dev, $rk) = @_; + + return (0) unless get_keys_register ($dev); + + my $cmd = "sg_persist -n -o -C -K $rk -d $dev"; + my @out = qx { $cmd 2> /dev/null }; + my $err = ($?>>8); + + if (defined $options{'v'}) { + $self = (caller(0))[3]; + print " $self (dev=$dev rk=$rk)\n"; + print " cmd=$cmd\n"; + print " err=$err\n"; + } + + return ($err); +} + sub do_verify_on (\@$$) { my @devices = @{(shift)}; @@ -119,6 +139,25 @@ sub do_verify_off ($$$) return ($err); } +sub do_verify_clear ($$) +{ + my ($dev, $host_key) = @_; + my $err = 0; + + if (defined $options{'v'}) { + $self = (caller(0))[3]; + print " $self (dev=$dev host_key=$host_key)\n"; + } + + @keys = get_keys_register ($dev); + + if (scalar (@keys) != 0) { + $err++; + } + + return ($err); +} + sub do_key_write ($) { my $key = shift; @@ -259,24 +298,6 @@ sub do_preempt_abort ($$$) return ($err); } -sub do_clear ($$) -{ - my ($dev, $rk) = @_; - - my $cmd = "sg_persist -n -o -C -K $rk -d $dev"; - my @out = qx { $cmd 2> /dev/null }; - my $err = ($?>>8); - - if (defined $options{'v'}) { - $self = (caller(0))[3]; - print " $self (dev=$dev rk=$rk)\n"; - print " cmd=$cmd\n"; - print " err=$err\n"; - } - - return ($err); -} - sub do_reset ($) { my ($dev) = @_; @@ -575,15 +596,17 @@ sub print_results ($) sub print_usage { print "\n"; - print "Usage: fence_scsi_test -o -k [options]\n"; + print "Usage: fence_scsi_test -o [options]\n"; print "\n"; print "Actions:\n"; print "\n"; print " on Register with the devices.\n"; - print " off Remove form the devices.\n"; + print " off Remove from the devices.\n"; + print " clear Remove all registrations from the devices.\n"; print "\n"; print "Options:\n"; print "\n"; + print " -k, --key=VALUE Key to use with current action.\n"; print " -d, --devices=LIST Devices used for the current action.\n"; print " -h, --help Display this help and exit.\n"; print " -v, --verbose Verbose mode.\n"; @@ -622,10 +645,12 @@ if (defined $options{'t'}) { } } -if ($options{'k'} =~ /^[[:xdigit:]]+$/) { - $node_key = lc ($options{'k'}); -} else { - print_usage (); +if ($options{'o'} !~ /^clear$/i) { + if ($options{'k'} =~ /^[[:xdigit:]]+$/) { + $node_key = lc ($options{'k'}); + } else { + print_usage (); + } } for ($options{'o'}) { @@ -637,6 +662,10 @@ for ($options{'o'}) { do_key_read (\$host_key); last; }; + ($_ =~ /^clear/i) && do { + do_key_read (\$host_key); + last; + }; print_usage (); } @@ -690,5 +719,15 @@ for ($options{'o'}) { print "\n" if (!defined $options{'v'}); last; }; + ($_ =~ /^clear$/i) && do { + print "\n" if (!defined $options{'v'}); + foreach (@devices) { + $results{$_}[0] = do_action_clear ($devices_name{$_}, $host_key); + $results{$_}[1] = do_verify_clear ($devices_name{$_}, $host_key); + print_results ($_); + } + print "\n" if (!defined $options{'v'}); + last; + }; print_usage (); } -- 1.7.2.3