cluster/fence/agents/scsi fence_scsi.pl
CVSROOT: /cvs/cluster
Module name: cluster
Branch: RHEL4
Changes by: rohara at sourceware.org 2006-12-14 21:16:36
Modified files:
fence/agents/scsi: fence_scsi.pl
Log message:
Attempt to register the node in the case where it must perform fence_scsi fencing but is not registered with the device(s) that must be fence. With SCSI persistent reservations, in order to do a "preempt and abort" (which we are using to fence a node), the node doing this operation must be registered with the device. This fix will check to see the the node that is performing the fencing is registered with the device(s). If it is not, then it attempts to register with the device(s) so that it can then continue with the fence operation normally. Note that this situation should never happen, especially if things are configured properly.
fence/agents/scsi/fence_scsi.pl +62 -1
@@ -156,6 +156,38 @@ } } +sub get_key_list +{ + ($dev) = @_; + + my ($in, $out, $err); + my $cmd = "sg_persist -d $dev -i -k"; + my $pid = open3($in, $out, $err, $cmd) or die "$!\n"; + + waitpid($pid, 0); + + die "Unable to execute sg_persist.\n" if ($?>>8); + + while (<$out>) + { + chomp; + if ($_ =~ /^\s*0x/) + { + s/^\s+0x//; + s/\s+$//; + + my $key = sprintf("%8.8x", hex($_)); + $key_list{$key} = 1; + } + } + + close($in); + close($out); + close($err); + + return %key_list; +} + #sub get_scsi_devices #{ # my ($in, $out, $err);
@@ -219,6 +251,29 @@ close($err); } +sub do_register +{ + ($dev, $key) = @_; + + my ($in, $out, $err); + my $cmd = "sg_persist -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.\n" if ($?>>8); + + while (<$out>) + { + chomp; + print "OUT: $_\n" if $opt_v; + } + + close($in); + close($out); + close($err); +} + sub fence_node { my $host_name = get_host_name();
@@ -227,11 +282,17 @@ my $host_key = get_key($host_name); my $node_key = get_key($node_name); - my $cmd; my ($in, $out, $err); foreach $dev (@volumes) { + my %key_list = get_key_list($dev); + + if (!$key_list{$host_key}) + { + do_register($dev, $host_key); + } + if ($host_key eq $node_key) { $cmd = "sg_persist -d $dev -o -G -K $host_key -S 0";