Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > d236c5da97a239a1b6991cfba2865b66 > files > 86

cman-2.0.115-68.el5_6.1.src.rpm

commit f35e432fd553ecc59486b56a91748097f10af96b
Author: Ryan O'Hara <rohara@redhat.com>
Date:   Wed Apr 7 11:40:09 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.
    
    Resolves: rhbz#564468
    
    Signed-off-by: Ryan O'Hara <rohara@redhat.com>

diff --git a/fence/agents/scsi/fence_scsi.pl b/fence/agents/scsi/fence_scsi.pl
index 0c2ff51..91f113d 100755
--- a/fence/agents/scsi/fence_scsi.pl
+++ b/fence/agents/scsi/fence_scsi.pl
@@ -2,7 +2,6 @@
 
 use Getopt::Std;
 use XML::LibXML;
-use IPC::Open3;
 use POSIX;
 
 my $ME = $0;
@@ -72,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 (uc($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\n" if $opt_v;
 
     return $cluster_id;
@@ -130,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 (uc($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\n" if $opt_v;
 
     return $host_id;
@@ -165,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 (uc($name) eq "NODE NAME")
-	{
+	if ($param =~ /^node\s+name/i) {
 	    $host_name = $value;
 	    last;
 	}
     }
 
-    close($in);
-    close($out);
-    close($err);
-
     print "[$pname]: get_host_nam = $host_name\n" if $opt_v;
 
     return $host_name;
@@ -269,18 +241,14 @@ sub get_key_list
 {
     ($device) = @_;
 
-    my ($in, $out, $err);
-
     my $cmd = "sg_persist -d $device -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;
 
@@ -309,33 +277,25 @@ 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,pv_uuid 2> /dev/null";
-
-    my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
+              "    --noheadings --separator : -o vg_attr,pv_name,pv_uuid";
 
-    waitpid($pid, 0);
+    my @out = qx { $cmd 2> /dev/null};
 
     die "Unable to execute vgs.\n" if ($?>>8);
 
-    while (<$out>)
+    foreach (@out)
     {
 	chomp;
 
 	my ($vg_attrs, $pv_name, $pv_uuid) = split(/:/, $_);
 
-	if ($vg_attrs =~ /.*c$/)
+	if ($vg_attrs =~ /c$/)
 	{
 	    $device_list{"\U$pv_uuid"} = $pv_name;
 	}
@@ -356,26 +316,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 fence_node
@@ -386,8 +334,6 @@ sub fence_node
     my $host_key = get_key($host_name);
     my $node_key = get_key($node_name);
 
-    my ($in, $out, $err);
-
     for $uuid (sort keys %device_list)
     {
 	my $device = $device_list{$uuid};
@@ -412,15 +358,9 @@ sub fence_node
 	    $cmd = "sg_persist -n -d $device -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);
     }
 }