Skip to contentSkip to conversation

cluster/fence/agents/scsi fence_scsi.pl fence_ ...

Cluster-devel [email protected] 1 participant 1 message Dec 14, 2006

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/cluster
Module name: cluster
Branch: RHEL50
Changes by: rohara at sourceware.org 2006-12-14 22:41:56

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

Log message:
Update all changes/fixes that went into RHEL5 branch.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/fence_scsi.pl.diff?cvsroot=cluster&only_with_tag=RHEL50&r1=1.5.4.1&r2=1.5.4.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/fence_scsi_test.pl.diff?cvsroot=cluster&only_with_tag=RHEL50&r1=1.1&r2=1.1.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/scsi_reserve.diff?cvsroot=cluster&only_with_tag=RHEL50&r1=1.1.4.1&r2=1.1.4.2

fence/agents/scsi/fence_scsi.pl +88 -14
@@ -12,8 +12,8 @@
 
 # WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and
 # "#END_VERSION_GENERATION"  It is generated by the Makefile
-#BEGIN_VERSION_GENERATION
 
+#BEGIN_VERSION_GENERATION
 $FENCE_RELEASE_NAME="";
 $REDHAT_COPYRIGHT="";
 $BUILD_DATE="";
@@ -131,7 +131,7 @@
 
 	next unless $opt;
 
-	($name, $val) = split /\s*=\s*/, $opt;
+	($name, $val) = split(/\s*=\s*/, $opt);
 
 	if ($name eq "")
 	{
@@ -156,33 +156,78 @@
     }
 }
 
-sub get_scsi_devices
+sub get_key_list
 {
+    ($dev) = @_;
+
     my ($in, $out, $err);
-    my $cmd = "lvs --noheadings --separator : -o vg_attr,devices";
+    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 lvs.\n" if ($?>>8);
+    die "Unable to execute sg_persist.\n" if ($?>>8);
 
     while (<$out>)
     {
 	chomp;
-	print "OUT: $_\n" if $opt_v;
-
-	my ($vg_attrs, $device) = split /:/, $_, 3;
-
-	if ($vg_attrs =~ /.*c$/)
+	if ($_ =~ /^\s*0x/)
 	{
-	    $device =~ s/\(.*\)//;
-	    push @volumes, $device;
+	    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);
+#    my $cmd = "lvs --noheadings --separator : -o vg_attr,devices";
+#    my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
+#
+#    waitpid($pid, 0);
+#
+#    die "Unable to execute lvs.\n" if ($?>>8);
+#
+#    while (<$out>)
+#    {
+#	chomp;
+#	print "OUT: $_\n" if $opt_v;
+#
+#	my ($vg_attrs, $device) = split(/:/, $_);
+#
+#	if ($vg_attrs =~ /.*c$/)
+#	{
+#	    $device =~ s/\(.*\)//;
+#	    push(@volumes, $device);
+#	}
+#    }
+#
+#    close($in);
+#    close($out);
+#    close($err);
+#}
+
+sub get_scsi_devices
+{
+    open(FILE, "/var/run/scsi_reserve") or die "$!\n";
+
+    while (<FILE>)
+    {
+	chomp;
+	push(@volumes, $_);
+    }
+
+    close FILE;
 }
 
 sub check_sg_persist
@@ -206,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();
@@ -213,12 +281,18 @@
 
     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";
fence/agents/scsi/fence_scsi_test.pl +12 -9
@@ -19,6 +19,7 @@
 
 sub get_key
 {
+    my $name = @_;
     my $addr = gethostbyname($name) or die "$!\n";
 
     return unpack("H*", $addr);
@@ -32,7 +33,7 @@
     print "DEBUG: $func ($dev, $key)\n" if ($opt_d);
 
     my ($in, $out, $err);
-    my $cmd = "sg_persist $dev -o -G -S $key";
+    my $cmd = "sg_persist -d $dev -o -G -S $key";
 
     my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
 
@@ -42,7 +43,7 @@
 
     $results{$dev}[0] = $rval;
 
-    print "DEBUG: [$rval] $cmd\n" if $opt_d;
+    print "DEBUG: [$rval] $cmd\n" if ($opt_d);
 
     close($in);
     close($out);
@@ -56,10 +57,10 @@
     my $func = (caller(0))[3];
     my ($dev, $key) = @_;
 
-    print "DEBUG: $func ($dev, $key)\n" if $opt_d;
+    print "DEBUG: $func ($dev, $key)\n" if ($opt_d);
 
     my ($in, $out, $err);
-    my $cmd = "sg_persist $dev -o -G -K $key -S 0";
+    my $cmd = "sg_persist -d $dev -o -G -K $key -S 0";
 
     my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
 
@@ -69,7 +70,7 @@
 
     $results{$dev}[1] = $rval;
 
-    print "DEBUG: [$rval] $cmd\n" if $opt_d;
+    print "DEBUG: [$rval] $cmd\n" if ($opt_d);
 
     close($in);
     close($out);
@@ -98,6 +99,7 @@
 {
     my ($in, $out, $err);
     my $cmd = "lvs --noheadings --separator : -o vg_attr,devices";
+
     my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
 
     waitpid($pid, 0);
@@ -108,7 +110,7 @@
     {
 	chomp;
 
-	my ($vg_attr, $dev) = split /:/, $_, 3;
+	my ($vg_attr, $dev) = split(/:/, $_);
 
 	if ($vg_attr =~ /.*c$/)
 	{
@@ -125,8 +127,7 @@
 sub test_devices
 {
     my $name = hostname() or die "$!\n";
-    my $addr = gethostbyname($name) or die "$!\n";
-    my $key = unpack("H*", $addr);
+    my $key = get_key($name);
 
     foreach $dev (@devices)
     {
@@ -195,7 +196,7 @@
     print "  -h     Help. Prints out this usage information.\n\n";
 }
 
-### main ###
+### MAIN #######################################################
 
 if (getopts("cdhsv") == 0)
 {
@@ -232,3 +233,5 @@
 
 print_results;
 
+exit 0;
+
fence/agents/scsi/scsi_reserve +38 -15

116 lines not on this page · raw message