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

[Cluster-devel] [PATCH] fence_scsi_test: add 'clear' action



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 <rohara redhat com>
---
 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 <on|off> -k <key> [options]\n";
+    print "Usage: fence_scsi_test -o <action> [options]\n";
     print "\n";
     print "Actions:\n";
     print "\n";
     print "  on                    Register <key> with the devices.\n";
-    print "  off                   Remove <key> form the devices.\n";
+    print "  off                   Remove <key> 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


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