fence-agents: master - fence_scsi: properly log errors for all commands

rohara rohara at fedoraproject.org
Mon Feb 7 18:44:24 UTC 2011


Gitweb:        http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=commitdiff;h=8a0edf9d60fcc781bc4222c5f320da3a23c98faf
Commit:        8a0edf9d60fcc781bc4222c5f320da3a23c98faf
Parent:        d9e40ee832d3705c3e952f11efa79d6e155d6277
Author:        Ryan O'Hara <rohara at redhat.com>
AuthorDate:    Tue Jan 25 11:16:10 2011 -0600
Committer:     Ryan O'Hara <rohara at redhat.com>
CommitterDate: Mon Feb 7 12:42:54 2011 -0600

fence_scsi: properly log errors for all commands

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 at redhat.com>
Reviewed-by: Lon Hohberger <lhh at 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 0512f3e..6f68203 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;


More information about the cluster-commits mailing list