Gitweb:
http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=...
Commit: eb8ab370049d458eae33773826b8f7ece31b21df
Parent: abf96e2fbe89852fa67e9c5120a0cbe4b9d8d090
Author: Ryan O'Hara <rohara(a)redhat.com>
AuthorDate: Wed Apr 7 11:26:43 2010 -0500
Committer: Ryan O'Hara <rohara(a)redhat.com>
CommitterDate: Wed Apr 7 11:26:43 2010 -0500
fence_scsi: replace open3 calls with qx commands
The open3 calls will block when the buffer becomes full, which causes
fence_scsi to block. This can occur if fence_scsi needs to process
several devices. All open3 calls should be replaced with qx commands,
which does not suffer from this problem. (BZ 545193)
Signed-off-by: Ryan O'Hara <rohara(a)redhat.com>
---
fence/agents/scsi/fence_scsi.pl | 134 ++++++++++-----------------------------
1 files changed, 33 insertions(+), 101 deletions(-)
diff --git a/fence/agents/scsi/fence_scsi.pl b/fence/agents/scsi/fence_scsi.pl
index 9c0a5c3..7ab621e 100755
--- a/fence/agents/scsi/fence_scsi.pl
+++ b/fence/agents/scsi/fence_scsi.pl
@@ -2,9 +2,17 @@
use Getopt::Std;
use XML::LibXML;
-use IPC::Open3;
use POSIX;
+my $ME = $0;
+
+END {
+ defined fileno STDOUT or return;
+ close STDOUT and return;
+ warn "$ME: failed to close standard output: $!\n";
+ $? ||= 1;
+}
+
my @device_list;
$_ = $0;
@@ -63,32 +71,23 @@ sub get_cluster_id
{
my $cluster_id;
- my ($in, $out, $err);
my $cmd = "cman_tool status";
-
- my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
-
- waitpid($pid, 0);
+ my @out = qx { $cmd };
die "Unable to execute cman_tool.\n" if ($?>>8);
- while (<$out>)
+ foreach (@out)
{
chomp;
- my ($name, $value) = split(/\s*:\s*/, $_);
+ my ($param, $value) = split(/\s*:\s*/, $_);
- if ($name eq "Cluster ID")
- {
+ if ($param =~ /^cluster\s+id/i) {
$cluster_id = $value;
last;
}
}
- close($in);
- close($out);
- close($err);
-
print "[$pname]: get_cluster_id: cluster_id=$cluster_id\n" if $opt_v;
return $cluster_id;
@@ -121,32 +120,23 @@ sub get_host_id
{
my $host_id;
- my ($in, $out, $err);
my $cmd = "cman_tool status";
-
- my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
-
- waitpid($pid, 0);
+ my @out = qx { $cmd };
die "Unable to execute cman_tool.\n" if ($?>>8);
- while (<$out>)
+ foreach (@out)
{
chomp;
- my ($name, $value) = split(/\s*:\s*/, $_);
+ my ($param, $value) = split(/\s*:\s*/, $_);
- if ($name eq "Node ID")
- {
+ if ($param =~ /^node\s+id/i) {
$host_id = $value;
last;
}
}
- close($in);
- close($out);
- close($err);
-
print "[$pname]: get_host_id: host_id=$host_id\n" if $opt_v;
return $host_id;
@@ -156,32 +146,23 @@ sub get_host_name
{
my $host_name;
- my ($in, $out, $err);
my $cmd = "cman_tool status";
-
- my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
-
- waitpid($pid, 0);
+ my @out = qx { $cmd };
die "Unable to execute cman_tool.\n" if ($?>>8);
- while (<$out>)
+ foreach (@out)
{
chomp;
- my ($name, $value) = split(/\s*:\s*/, $_);
+ my ($param, $value) = split(/\s*:\s*/, $_);
- if ($name eq "Node name")
- {
+ if ($param =~ /^node\s+name/i) {
$host_name = $value;
last;
}
}
- close($in);
- close($out);
- close($err);
-
print "[$pname]: get_host_name: host_name=$host_name\n" if $opt_v;
return $host_name;
@@ -260,26 +241,23 @@ sub get_key_list
{
($dev) = @_;
- my ($in, $out, $err);
-
my $cmd = "sg_persist -d $dev -i -k";
- my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
-
- waitpid($pid, 0);
+ my @out = qx { $cmd };
die "Unable to execute sg_persist.\n" if ($?>>8);
my %key_list;
- while (<$out>)
+ foreach (@out)
{
chomp;
+
if ($_ =~ /^\s*0x/)
{
s/^\s+0x//;
s/\s+$//;
- $key_list{$_} = 1;
+ $key_list{$_} = undef;
}
}
@@ -299,27 +277,19 @@ sub get_key_list
}
}
- close($in);
- close($out);
- close($err);
-
return %key_list;
}
sub get_scsi_devices
{
- my ($in, $out, $err);
-
my $cmd = "vgs --config 'global { locking_type = 0 }'" .
- " --noheadings --separator : -o vg_attr,pv_name 2>
/dev/null";
+ " --noheadings --separator : -o vg_attr,pv_name";
- my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
-
- waitpid($pid, 0);
+ my @out = qx { $cmd 2> /dev/null};
die "Unable to execute vgs.\n" if ($?>>8);
- while (<$out>)
+ foreach (@out)
{
chomp;
@@ -347,42 +317,14 @@ sub get_scsi_devices
$index++;
}
}
-
- close($in);
- close($out);
- close($err);
}
sub check_sg_persist
{
- my ($in, $out, $err);
my $cmd = "sg_persist -V";
- my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
-
- waitpid($pid, 0);
+ my $out = qx { $cmd };
die "Unable to execute sg_persist.\n" if ($?>>8);
-
- close($in);
- close($out);
- close($err);
-}
-
-sub do_register
-{
- ($dev, $key) = @_;
-
- my ($in, $out, $err);
- my $cmd = "sg_persist -n -d $dev -o -G -S $key";
- my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
-
- waitpid($pid, 0);
-
- die "Unable to execute sg_persist ($dev).\n" if ($?>>8);
-
- close($in);
- close($out);
- close($err);
}
sub fence_node
@@ -406,17 +348,13 @@ sub fence_node
print "[$pname]: unregister key 0x$node_key from device $dev\n";
}
- if (!$key_list{$host_key})
+ if (! exists $key_list{$host_key})
{
- do_register($dev, $host_key);
+ fail "Unable to perform fence operation.";
}
- if (!$key_list{$node_key})
+ if (! exists $key_list{$node_key})
{
- if ($opt_v)
- {
- print "[$pname]: key 0x$node_key is not registered with device $dev\n";
- }
next;
}
@@ -429,15 +367,9 @@ sub fence_node
$cmd = "sg_persist -n -d $dev -o -A -K $host_key -S $node_key -T 5";
}
- my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
-
- waitpid($pid, 0);
+ my $out = qx { $cmd };
die "Unable to execute sg_persist ($dev).\n" if ($?>>8);
-
- close($in);
- close($out);
- close($err);
}
}