From: rohara@sourceware.org <rohara@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/fence/agents/scsi fence_scsi.pl scsi_r ...
Date: 8 Nov 2007 17:00:50 -0000 [thread overview]
Message-ID: <20071108170050.10477.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: cluster
Branch: RHEL4
Changes by: rohara at sourceware.org 2007-11-08 17:00:49
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=RHEL4&r1=1.5.6.8&r2=1.5.6.9
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/scsi_reserve.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.1.6.10&r2=1.1.6.11
--- 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/11/08 17:00:44 1.5.6.9
@@ -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/11/08 17:00:44 1.1.6.11
@@ -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
next reply other threads:[~2007-11-08 17:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-08 17:00 rohara [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-11-08 18:48 [Cluster-devel] cluster/fence/agents/scsi fence_scsi.pl scsi_r rohara
2007-12-11 21:29 rohara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071108170050.10477.qmail@sourceware.org \
--to=rohara@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.