[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] cluster/fence/agents/scsi fence_scsi.pl scsi_r ...



CVSROOT:	/cvs/cluster
Module name:	cluster
Branch: 	RHEL5
Changes by:	rohara sourceware org	2007-11-08 18:48:09

Modified files:
	fence/agents/scsi: fence_scsi.pl scsi_reserve 

Log message:
	BZ 248715
	- Use cluster ID and node ID for key rather than IP address.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/fence_scsi.pl.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.5.2.5&r2=1.5.2.6
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/scsi_reserve.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.7&r2=1.1.2.8

--- cluster/fence/agents/scsi/fence_scsi.pl	2007/09/21 03:09:04	1.5.2.5
+++ cluster/fence/agents/scsi/fence_scsi.pl	2007/11/08 18:48:08	1.5.2.6
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
 use Getopt::Std;
+use XML::LibXML;
 use IPC::Open3;
 use POSIX;
 
@@ -61,13 +62,52 @@
     exit 1;
 }
 
-sub get_key
+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);
+
+    die "Unable to execute cman_tool.\n" if ($?>>8);
+
+    while (<$out>)
+    {
+	chomp;
+	print "OUT: $_\n" if $opt_v;
+
+	my ($name, $value) = split(/\s*:\s*/, $_);
+
+	if ($name eq "Cluster Id")
+	{
+	    $cluster_id = $value;
+	    last;
+	}
+    }
+
+    close($in);
+    close($out);
+    close($err);
+
+    return $cluster_id;
+}
+
+sub get_node_id
 {
     ($node)= _;
 
-    my $addr = gethostbyname($node) or die "$!\n";
+    my $xml = XML::LibXML->new();
+    my $tree = $xml->parse_file("/etc/cluster/cluster.conf");
+
+    my $xpath = "//cluster/clusternodes/clusternode[\ name='$node']/\ nodeid";
+
+    my $node_id = $tree->findvalue($xpath);
 
-    return unpack("H*", $addr);
+    return $node_id;
 }
 
 sub get_node_name
@@ -75,6 +115,40 @@
     return $opt_n;
 }
 
+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);
+
+    die "Unable to execute cman_tool.\n" if ($?>>8);
+
+    while (<$out>)
+    {
+	chomp;
+	print "OUT: $_\n" if $opt_v;
+
+	my ($name, $value) = split(/\s*:\s*/, $_);
+
+	if ($name eq "Node ID")
+	{
+	    $host_id = $value;
+	    last;
+	}
+    }
+
+    close($in);
+    close($out);
+    close($err);
+
+    return $host_id;
+}
+
 sub get_host_name
 {
     my $host_name;
@@ -109,6 +183,19 @@
     return $host_name;
 }
 
+sub get_key
+{
+    ($node)= _;
+
+    my $cluster_id = get_cluster_id;
+    my $node_id = get_node_id($node);
+
+    my $key = sprintf "%x%.4x", $cluster_id, $node_id;
+
+    return $key;
+}
+
+
 sub get_options_stdin
 {
     my $opt;
@@ -180,8 +267,7 @@
 	    s/^\s+0x//;
 	    s/\s+$//;
 
-	    my $key = sprintf("%8.8x", hex($_));
-	    $key_list{$key} = 1;
+	    $key_list{$_} = 1;
 	}
     }
 
@@ -265,7 +351,7 @@
 
     waitpid($pid, 0);
 
-    die "Unable to execute sg_persist.\n" if ($?>>8);
+    die "Unable to execute sg_persist ($dev).\n" if ($?>>8);
 
     while (<$out>)
     {
@@ -310,7 +396,7 @@
 
 	waitpid($pid, 0);
 
-	die "Unable to execute sg_persist.\n" if ($?>>8);
+	die "Unable to execute sg_persist ($dev).\n" if ($?>>8);
 
 	while (<$out>)
 	{
@@ -350,4 +436,3 @@
 get_scsi_devices;
 
 fence_node;
-
--- cluster/fence/agents/scsi/scsi_reserve	2006/12/14 18:32:43	1.1.2.7
+++ cluster/fence/agents/scsi/scsi_reserve	2007/11/08 18:48:08	1.1.2.8
@@ -12,13 +12,6 @@
    exit 2
 fi
 
-# check for gethostip command provided by syslinux package
-#
-if ! gethostip -h &> /dev/null ; then
-   echo "error: gethostip not found"
-   exit 3
-fi
-
 # get scsi devices that are part of clustered volumes
 #
 scsi_devices=$( lvs -o vg_attr,devices --noheadings \
@@ -34,9 +27,17 @@
 node_name=$( cman_tool status | grep "Node name" | awk -F": " '{ print $2 }' )
 node_addr=$( cman_tool status | grep "Node addr" | awk -F": " '{ print $2 }' )
 
+# get cluster id and node id from cman
+#
+c_id=$( cman_tool status | grep -i "Cluster ID" | awk -F": " '{ print $2 }' )
+n_id=$( cman_tool status | grep -i "Node ID"    | awk -F": " '{ print $2 }' )
+
+[ -z "$c_id" ] && exit 1
+[ -z "$n_id" ] && exit 1
+
 # create unique key for this host
 #
-key=$( gethostip -x $node_name )
+key=$( printf "%x%.4x" $c_id $n_id )
 
 ###############################################################################
 
@@ -46,7 +47,7 @@
 
 rval=0
 
-touch /var/lock/subsys/scsi_reserve
+echo "$key" > /var/lock/subsys/scsi_reserve
 
 cat /dev/null > /var/run/scsi_reserve
 
@@ -69,7 +70,7 @@
   else
       # perhaps we are already resgistered
       #
-      if sg_persist -d $dev -i -k 2>/dev/null | grep -qiE "${key#0}" ; then
+      if sg_persist -d $dev -i -k 2>/dev/null | grep -qiE "$key" ; then
 	  echo $dev >> /var/run/scsi_reserve
           success
       else
@@ -103,7 +104,7 @@
 
   # check if this node/key is the node/key holding the reservation
   #
-  if sg_persist -d $dev -i -r 2>/dev/null | grep -qiE "${key#0}" ; then
+  if sg_persist -d $dev -i -r 2>/dev/null | grep -qiE "$key" ; then
       if echo "$reg_keys" | grep -qivE "${key#0}" ; then
 	  error=1
       else
@@ -122,7 +123,7 @@
   fi
 
   if [ $error -eq 0 ]; then
-      success
+      success "unregister device $dev"
   else
       failure
       rval=1
@@ -143,7 +144,7 @@
 #
 for dev in $scsi_devices
 do
-  if sg_persist -d $dev -i -k 2>/dev/null | grep -qiE "${key#0}" ; then
+  if sg_persist -d $dev -i -k 2>/dev/null | grep -qiE "$key" ; then
       devices[${#devices[ ]}]=$dev
   fi
 done


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]