FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 01-25-2011, 04:39 PM
"Ryan O'Hara"
 
Default 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@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
" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self
" 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)
" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self ($dev)
" 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
" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self
" 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
" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self
" 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
" if ($?>>8);
+ # die "[error]: $self
" 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
" if ($?>>8);
+ # die "[error]: $self
" 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
" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self
" 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
" if ($?>>8);
+ if ($err != 0) {
+ log_error ("$self (err=$err)");
+ }
+
+ # die "[error]: $self
" 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
" if ($?>>8);
+ # die "[error]: $self
" 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
" if ($?>>8);
+ # die "[error]: $self
" 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
" if ($?>>8);
+ # die "[error]: $self
" if ($?>>8);

foreach (@out) {
chomp;
--
1.7.3.4
 

Thread Tools




All times are GMT. The time now is 05:09 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org