From: Ryan O'Hara <rohara@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 3/3] fence_scsi: properly log errors for all commands
Date: Tue, 25 Jan 2011 11:39:51 -0600 [thread overview]
Message-ID: <1295977191-6249-1-git-send-email-rohara@redhat.com> (raw)
There are a number of places in fence_scsi that call sg_persist commands
via Perl's qx command. If an error occurs, the script simply dies and
reports the name of the subroutine that the script died in. This can be
improved by replacing the die call with log_error, such that any errors
get properly written to the logfile, if any. This patch also logs the
error code returned from the failed command.
This patch also redirects stderr to /dev/null for all commands executed
via qx.
Signed-off-by: Ryan O'Hara <rohara@redhat.com>
---
fence/agents/scsi/fence_scsi.pl | 99 ++++++++++++++++++++++++++++++--------
1 files changed, 78 insertions(+), 21 deletions(-)
diff --git a/fence/agents/scsi/fence_scsi.pl b/fence/agents/scsi/fence_scsi.pl
index efeeba3..ae658ab 100644
--- a/fence/agents/scsi/fence_scsi.pl
+++ b/fence/agents/scsi/fence_scsi.pl
@@ -185,14 +185,20 @@ sub do_register ($$$)
my $cmd;
my $out;
+ my $err;
do_reset ($dev);
$cmd = "sg_persist -n -o -G -K $host_key -S $node_key -d $dev";
$cmd .= " -Z" if (defined $opt_a);
- $out = qx { $cmd };
+ $out = qx { $cmd 2> /dev/null };
+ $err = ($?>>8);
- die "[error]: $self\n" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self\n" if ($?>>8);
return;
}
@@ -216,14 +222,20 @@ sub do_register_ignore ($$)
my $cmd;
my $out;
+ my $err;
do_reset ($dev);
$cmd = "sg_persist -n -o -I -S $node_key -d $dev";
$cmd .= " -Z" if (defined $opt_a);
- $out = qx { $cmd };
+ $out = qx { $cmd 2> /dev/null };
+ $err = ($?>>8);
- die "[error]: $self ($dev)\n" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self ($dev)\n" if ($?>>8);
return;
}
@@ -236,9 +248,14 @@ sub do_reserve ($$)
log_debug ("$self (host_key=$host_key, dev=$dev)");
my $cmd = "sg_persist -n -o -R -T 5 -K $host_key -d $dev";
- my $out = qx { $cmd };
+ my $out = qx { $cmd 2> /dev/null };
+ my $err = ($?>>8);
- die "[error]: $self\n" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self\n" if ($?>>8);
return;
}
@@ -251,9 +268,14 @@ sub do_release ($$)
log_debug ("$self (host_key=$host_key, dev=$dev)");
my $cmd = "sg_persist -n -o -L -T 5 -K $host_key -d $dev";
- my $out = qx { $cmd };
+ my $out = qx { $cmd 2> /dev/null };
+ my $err = ($?>>8);
- die "[error]: $self\n" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self\n" if ($?>>8);
return;
}
@@ -266,9 +288,14 @@ sub do_preempt ($$$)
log_debug ("$self (host_key=$host_key, node_key=$node_key, dev=$dev)");
my $cmd = "sg_persist -n -o -P -T 5 -K $host_key -S $node_key -d $dev";
- my $out = qx { $cmd };
+ my $out = qx { $cmd 2> /dev/null };
+ my $err = ($?>>8);
+
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
- die "[error]: $self\n" if ($?>>8);
+ # die "[error]: $self\n" if ($?>>8);
return;
}
@@ -281,9 +308,14 @@ sub do_preempt_abort ($$$)
log_debug ("$self (host_key=$host_key, node_key=$node_key, dev=$dev)");
my $cmd = "sg_persist -n -o -A -T 5 -K $host_key -S $node_key -d $dev";
- my $out = qx { $cmd };
+ my $out = qx { $cmd 2> /dev/null };
+ my $err = ($?>>8);
+
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
- die "[error]: $self\n" if ($?>>8);
+ # die "[error]: $self\n" if ($?>>8);
return;
}
@@ -343,9 +375,14 @@ sub get_node_id ($)
my $node_id;
my $cmd = "cman_tool nodes -n $_[0] -F id";
- my $out = qx { $cmd };
+ my $out = qx { $cmd 2> /dev/null };
+ my $err = ($?>>8);
- die "[error]: $self\n" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self\n" if ($?>>8);
chomp ($out);
@@ -360,9 +397,14 @@ sub get_cluster_id ()
my $cluster_id;
my $cmd = "cman_tool status";
- my @out = qx { $cmd };
+ my @out = qx { $cmd 2> /dev/null };
+ my $err = ($?>>8);
- die "[error]: $self\n" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self\n" if ($?>>8);
foreach (@out) {
chomp;
@@ -388,8 +430,13 @@ sub get_devices_clvm ()
" devices { preferred_names = [ \"^/dev/dm\" ] }'";
my @out = qx { $cmd 2> /dev/null };
+ my $err = ($?>>8);
+
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
- die "[error]: $self\n" if ($?>>8);
+ # die "[error]: $self\n" if ($?>>8);
foreach (@out) {
chomp;
@@ -479,9 +526,14 @@ sub get_registration_keys ($)
my @keys;
my $cmd = "sg_persist -n -i -k -d $dev";
- my @out = qx { $cmd };
+ my @out = qx { $cmd 2> /dev/null };
+ my $err = ($?>>8);
+
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
- die "[error]: $self\n" if ($?>>8);
+ # die "[error]: $self\n" if ($?>>8);
foreach (@out) {
chomp;
@@ -500,9 +552,14 @@ sub get_reservation_key ($)
my $key;
my $cmd = "sg_persist -n -i -r -d $dev";
- my @out = qx { $cmd };
+ my @out = qx { $cmd 2> /dev/null };
+ my $err = ($?>>8);
+
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
- die "[error]: $self\n" if ($?>>8);
+ # die "[error]: $self\n" if ($?>>8);
foreach (@out) {
chomp;
--
1.7.3.4
next reply other threads:[~2011-01-25 17:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-25 17:39 Ryan O'Hara [this message]
2011-01-31 23:23 ` [Cluster-devel] [PATCH 3/3] fence_scsi: properly log errors for all commands Lon Hohberger
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=1295977191-6249-1-git-send-email-rohara@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).