public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* cluster: RHEL55 - CMAN: fence_scsi support for 2 node clusters
@ 2009-08-31 13:41 rohara
  0 siblings, 0 replies; only message in thread
From: rohara @ 2009-08-31 13:41 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=66c513bfc91bdd325c3620b4da9c66d5028fcf23
Commit:        66c513bfc91bdd325c3620b4da9c66d5028fcf23
Parent:        d4de56c4c8f6d91a98fbb80e9eed8aebc4a8edf9
Author:        Ryan O'Hara <rohara@redhat.com>
AuthorDate:    Mon Aug 31 08:36:57 2009 -0500
Committer:     Ryan O'Hara <rohara@redhat.com>
CommitterDate: Mon Aug 31 08:36:57 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#516085
---
 fence/agents/scsi/fence_scsi.pl |  104 +++++++++++++++------------------------
 1 files changed, 39 insertions(+), 65 deletions(-)

diff --git a/fence/agents/scsi/fence_scsi.pl b/fence/agents/scsi/fence_scsi.pl
index fb68ff6..e452e7c 100755
--- a/fence/agents/scsi/fence_scsi.pl
+++ b/fence/agents/scsi/fence_scsi.pl
@@ -14,7 +14,7 @@ END {
   $? ||= 1;
 }
 
-my @device_list;
+my %device_list;
 
 $_ = $0;
 s/.*\///;
@@ -87,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;
@@ -98,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;
 }
@@ -145,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;
@@ -156,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;
 }
@@ -180,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;
@@ -191,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;
 }
@@ -267,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);
@@ -283,12 +283,13 @@ sub get_key_list
     while (<$out>)
     {
 	chomp;
+
 	if ($_ =~ /^\s*0x/)
 	{
 	    s/^\s+0x//;
 	    s/\s+$//;
 
-	    $key_list{$_} = 1;
+	    $key_list{$_} = undef;
 	}
     }
 
@@ -299,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)
 	{
@@ -320,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";
 
@@ -332,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;
 	}
     }
 
@@ -345,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++;
 	}
     }
@@ -366,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);
@@ -404,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";
@@ -471,8 +445,8 @@ if (@ARGV > 0) {
 
 }
 
-check_sg_persist;
+check_sg_persist();
 
-get_scsi_devices;
+get_scsi_devices();
 
-fence_node;
+fence_node();


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-08-31 13:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-31 13:41 cluster: RHEL55 - CMAN: fence_scsi support for 2 node clusters rohara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).