* [Cluster-devel] [PATCH] fence_scsi_test: add 'clear' action
@ 2010-12-07 0:30 Ryan O'Hara
0 siblings, 0 replies; only message in thread
From: Ryan O'Hara @ 2010-12-07 0:30 UTC (permalink / raw)
To: cluster-devel.redhat.com
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2010-12-07 0:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-07 0:30 [Cluster-devel] [PATCH] fence_scsi_test: add 'clear' action Ryan O'Hara
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).