cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Ryan O'Hara <rohara@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH] fence_scsi_test: add 'clear' action
Date: Mon, 6 Dec 2010 18:30:27 -0600	[thread overview]
Message-ID: <20101207003027.GA16607@redhat.com> (raw)

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



                 reply	other threads:[~2010-12-07  0:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101207003027.GA16607@redhat.com \
    --to=rohara@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).