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 "$!
";
+
+ waitpid($pid, 0);
+
+ die "Unable to execute cman_tool.
" if ($?>>8);
+
+ while (<$out>)
+ {
+ chomp;
+ print "OUT: $_
" 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 "$!
";
+ 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);
@@ -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