[Cluster-devel] cluster/fence/agents/scsi fence_scsi.pl scsi_r ...
rohara at sourceware.org
rohara at sourceware.org
Tue Dec 11 21:29:23 UTC 2007
CVSROOT: /cvs/cluster
Module name: cluster
Branch: RHEL46
Changes by: rohara at sourceware.org 2007-12-11 21:29:23
Modified files:
fence/agents/scsi: fence_scsi.pl scsi_reserve
Log message:
BZ 360681
- 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=RHEL46&r1=1.5.6.8&r2=1.5.6.8.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/scsi_reserve.diff?cvsroot=cluster&only_with_tag=RHEL46&r1=1.1.6.10&r2=1.1.6.10.4.1
--- cluster/fence/agents/scsi/fence_scsi.pl 2006/12/14 21:16:36 1.5.6.8
+++ cluster/fence/agents/scsi/fence_scsi.pl 2007/12/11 21:29:23 1.5.6.8.4.1
@@ -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;
@@ -176,8 +263,7 @@
s/^\s+0x//;
s/\s+$//;
- my $key = sprintf("%8.8x", hex($_));
- $key_list{$key} = 1;
+ $key_list{$_} = 1;
}
}
@@ -261,7 +347,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>)
{
@@ -306,7 +392,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>)
{
@@ -346,4 +432,3 @@
get_scsi_devices;
fence_node;
-
--- cluster/fence/agents/scsi/scsi_reserve 2007/01/26 20:03:51 1.1.6.10
+++ cluster/fence/agents/scsi/scsi_reserve 2007/12/11 21:29:23 1.1.6.10.4.1
@@ -14,13 +14,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 \
@@ -36,9 +29,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 "Cluster ID" | awk -F": " '{ print $2 }' )
+n_id=$( cman_tool status | grep "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 )
###############################################################################
@@ -71,7 +72,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 "register device $dev"
else
@@ -107,7 +108,7 @@
# stop the watchdog before we unregister
#
-if [ "${WATCHDOG}" == yes ]; then
+if [ "${WATCHDOG}" == yes ] ; then
echo -n "Stopping watchdog: "
if killproc watchdog ; then
@@ -130,7 +131,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
@@ -148,7 +149,7 @@
done
fi
- if [ $error -eq 0 ]; then
+ if [ $error -eq 0 ] ; then
success "unregister device $dev"
else
failure
@@ -170,7 +171,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
More information about the Cluster-devel
mailing list