This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
cluster: RHEL54 - CMAN: fence_scsi support for 2 node clusters
- From: rohara <rohara at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Wed, 2 Sep 2009 15:08:25 +0000 (UTC)
- Subject: cluster: RHEL54 - CMAN: fence_scsi support for 2 node clusters
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=5f64f4eba4ee0bc415b7a98a4efd16c6e788d16b
Commit: 5f64f4eba4ee0bc415b7a98a4efd16c6e788d16b
Parent: 806274ceb8d9bffbb96d7e64e987f2817fc2f362
Author: Ryan O'Hara <rohara@redhat.com>
AuthorDate: Wed Sep 2 10:06:15 2009 -0500
Committer: Ryan O'Hara <rohara@redhat.com>
CommitterDate: Wed Sep 2 10:06:15 2009 -0500
CMAN: fence_scsi support for 2 node clusters
This patch allows fence_scsi to work with 2 node cluster. This patch
removes the code that would register with a device "on-the-fly" at fence
time. Also, add code to sort devices by UUID.
rhbz#520823
Conflicts:
fence/agents/scsi/fence_scsi.pl
---
fence/agents/scsi/fence_scsi.pl | 113 ++++++++++++++++----------------------
1 files changed, 48 insertions(+), 65 deletions(-)
diff --git a/fence/agents/scsi/fence_scsi.pl b/fence/agents/scsi/fence_scsi.pl
index 62454c7..e452e7c 100755
--- a/fence/agents/scsi/fence_scsi.pl
+++ b/fence/agents/scsi/fence_scsi.pl
@@ -5,7 +5,16 @@ use XML::LibXML;
use IPC::Open3;
use POSIX;
-my @device_list;
+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;
s/.*\///;
@@ -78,7 +87,7 @@ sub get_cluster_id
my ($name, $value) = split(/\s*:\s*/, $_);
- if ($name eq "Cluster Id")
+ if (uc($name) eq "CLUSTER ID")
{
$cluster_id = $value;
last;
@@ -89,30 +98,30 @@ sub get_cluster_id
close($out);
close($err);
- print "[$pname]: get_cluster_id: cluster_id=$cluster_id\n" if $opt_v;
+ print "[$pname]: get_cluster_id = $cluster_id\n" if $opt_v;
return $cluster_id;
}
sub get_node_id
{
- ($node)=@_;
+ ($name)=@_;
my $xml = XML::LibXML->new();
my $tree = $xml->parse_file("/etc/cluster/cluster.conf");
- my $xpath = "//cluster/clusternodes/clusternode[\@name='$node']/\@nodeid";
+ my $xpath = "//cluster/clusternodes/clusternode[\@name='$name']/\@nodeid";
my $node_id = $tree->findvalue($xpath);
- print "[$pname]: get_node_id ($node): node_id=$node_id\n" if $opt_v;
+ print "[$pname]: get_node_id ($name) = $node_id\n" if $opt_v;
return $node_id;
}
sub get_node_name
{
- print "[$pname]: get_hode_name: node_name=$opt_n\n" if $opt_v;
+ print "[$pname]: get_hode_name = $opt_n\n" if $opt_v;
return $opt_n;
}
@@ -136,7 +145,7 @@ sub get_host_id
my ($name, $value) = split(/\s*:\s*/, $_);
- if ($name eq "Node ID")
+ if (uc($name) eq "NODE ID")
{
$host_id = $value;
last;
@@ -147,7 +156,7 @@ sub get_host_id
close($out);
close($err);
- print "[$pname]: get_host_id: host_id=$host_id\n" if $opt_v;
+ print "[$pname]: get_host_id = $host_id\n" if $opt_v;
return $host_id;
}
@@ -171,7 +180,7 @@ sub get_host_name
my ($name, $value) = split(/\s*:\s*/, $_);
- if ($name eq "Node name")
+ if (uc($name) eq "NODE NAME")
{
$host_name = $value;
last;
@@ -182,25 +191,25 @@ sub get_host_name
close($out);
close($err);
- print "[$pname]: get_host_name: host_name=$host_name\n" if $opt_v;
+ print "[$pname]: get_host_nam = $host_name\n" if $opt_v;
return $host_name;
}
sub get_key
{
- ($node)=@_;
+ ($name)=@_;
- my $cluster_id = get_cluster_id;
- my $node_id = get_node_id($node);
+ my $cluster_id = get_cluster_id();
+ my $node_id = get_node_id($name);
if ($node_id == 0) {
- die "Unable to determine nodeid for $node.\n";
+ die "Unable to determine nodeid for $name.\n";
}
my $key = sprintf "%x%.4x", $cluster_id, $node_id;
- print "[$pname]: get_key ($node): key=$key\n" if $opt_v;
+ print "[$pname]: get_key ($name) = $key\n" if $opt_v;
return $key;
}
@@ -258,11 +267,11 @@ sub get_options_stdin
sub get_key_list
{
- ($dev) = @_;
+ ($device) = @_;
my ($in, $out, $err);
- my $cmd = "sg_persist -d $dev -i -k";
+ my $cmd = "sg_persist -d $device -i -k";
my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
waitpid($pid, 0);
@@ -274,12 +283,13 @@ sub get_key_list
while (<$out>)
{
chomp;
+
if ($_ =~ /^\s*0x/)
{
s/^\s+0x//;
s/\s+$//;
- $key_list{$_} = 1;
+ $key_list{$_} = undef;
}
}
@@ -290,7 +300,7 @@ sub get_key_list
my $count = keys %key_list;
my $index = 0;
- print "[$pname]: get_key_list: found $count keys registered with $dev\n";
+ print "[$pname]: get_key_list: found $count keys registered with $device\n";
for $key (keys %key_list)
{
@@ -311,7 +321,7 @@ 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,pv_uuid 2> /dev/null";
my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
@@ -323,12 +333,11 @@ sub get_scsi_devices
{
chomp;
- my ($vg_attrs, $dev) = split(/:/, $_);
+ my ($vg_attrs, $pv_name, $pv_uuid) = split(/:/, $_);
if ($vg_attrs =~ /.*c$/)
{
- $dev =~ s/\(.*\)//;
- push(@device_list, $dev);
+ $device_list{"\U$pv_uuid"} = $pv_name;
}
}
@@ -336,14 +345,14 @@ sub get_scsi_devices
#
if ($opt_v)
{
- my $count = scalar @device_list;
+ my $count = keys %device_list;
my $index = 0;
print "[$pname]: get_scsi_devices: found $count devices\n";
- for $dev (@device_list)
+ for $uuid (sort keys %device_list)
{
- print "[$pname]: ($index) dev=$dev\n";
+ print "[$pname]: ($index) device=$device_list{$uuid} UUID=$uuid\n";
$index++;
}
}
@@ -357,28 +366,12 @@ 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);
-
- 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);
+ die "Unable to execute sg_persist.\n" if ($?>>8);
close($in);
close($out);
@@ -395,38 +388,28 @@ sub fence_node
my ($in, $out, $err);
- foreach $dev (@device_list)
+ for $uuid (sort keys %device_list)
{
- my %key_list = get_key_list($dev);
-
- # DEBUG: use -v option
- #
- if ($opt_v)
- {
- print "[$pname]: unregister key 0x$node_key from device $dev\n";
- }
+ my $device = $device_list{$uuid};
+ my %key_list = get_key_list($device);
- 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;
}
if ($host_key eq $node_key)
{
- $cmd = "sg_persist -n -d $dev -o -G -K $host_key -S 0";
+ $cmd = "sg_persist -n -d $device -o -G -K $host_key -S 0";
}
else
{
- $cmd = "sg_persist -n -d $dev -o -A -K $host_key -S $node_key -T 5";
+ $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";
@@ -462,8 +445,8 @@ if (@ARGV > 0) {
}
-check_sg_persist;
+check_sg_persist();
-get_scsi_devices;
+get_scsi_devices();
-fence_node;
+fence_node();