cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] cluster/fence/agents/scsi fence_scsi
@ 2006-06-29 17:23 rohara
  0 siblings, 0 replies; 3+ messages in thread
From: rohara @ 2006-06-29 17:23 UTC (permalink / raw)
  To: cluster-devel.redhat.com

CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	rohara at sourceware.org	2006-06-29 17:23:12

Added files:
	fence/agents/scsi: fence_scsi 

Log message:
	Initial check-in of SCSI persistent reservation fence agent.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/fence_scsi.diff?cvsroot=cluster&r1=NONE&r2=1.1

/cvs/cluster/cluster/fence/agents/scsi/fence_scsi,v  -->  standard output
revision 1.1
--- cluster/fence/agents/scsi/fence_scsi
+++ -	2006-06-29 17:23:14.171028000 +0000
@@ -0,0 +1,218 @@
+#!/usr/bin/perl
+
+use Getopt::Std;
+use IPC::Open3;
+use POSIX;
+
+my $verbose = 0;
+my @volumes;
+
+$_ = $0;
+s/.*\///;
+my $pname = $_;
+
+sub usage
+{
+    print "Usage\n";
+    print "\n";
+    print "$pname [options]\n";
+    print "\n";
+    print "Options\n";
+    print "  -n <node>        IP address or hostname of node to fence\n";
+    print "  -h               usage\n";
+    print "  -V               version\n";
+    print "  -v               verbose\n";
+
+    exit 0;
+}
+
+sub version
+{
+    print "$pname $FENCE_RELEASE_NAME $BUILD_DATE\n";
+    print "$REDHAT_COPYRIGHT\n" if ( $REDHAT_COPYRIGHT );
+
+    exit 0;
+}
+
+sub fail
+{
+    ($msg)=@_;
+
+    print $msg."\n" unless defined $opt_q;
+
+    exit 1;
+}
+
+sub fail_usage
+{
+    ($msg)=@_;
+
+    print STDERR $msg."\n" if $msg;
+    print STDERR "Please use '-h' for usage.\n";
+
+    exit 1;
+}
+
+sub get_key
+{
+    ($node)=@_;
+
+    my $addr = gethostbyname($node) or die "$!\n";
+
+    return unpack("H*", $addr);
+}
+
+sub get_options_stdin
+{
+    my $opt;
+    my $line = 0;
+
+    while (defined($in = <>))
+    {
+	$_ = $in;
+	chomp;
+
+	# strip leading and trailing whitespace
+	s/^\s*//;
+	s/\s*$//;
+
+	# skip comments
+	next if /^#/;
+
+	$line += 1;
+	$opt = $_;
+
+	next unless $opt;
+
+	($name, $val) = split /\s*=\s/, $opt;
+
+	if ($name eq "")
+	{
+	    print STDERR "parse error: illegal name in option $line\n";
+	    exit 2;
+	}
+	elsif ($name eq "agent")
+	{
+	}
+	elsif ($name eq "node")
+	{
+	    $opt_n = $val;
+	}
+	elsif ($name eq "verbose")
+	{
+	    $opt_v = $val;
+	}
+	else
+	{
+	    fail "parse error: unknown option \"$opt\"";
+	}
+    }
+}
+
+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 /:/, $_, 3;
+
+	if ($vg_attrs =~ /.*c$/)
+	{
+	    $device =~ s/\(.*\)//;
+	    push @volumes, $device;
+	}
+    }
+}
+
+sub check_sg_persist
+{
+    my ($in, $out, $err);
+    my $cmd = "sg_persist -V";
+    my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
+
+    waitpid($pid, 0);
+
+    die "Unable to execute sg_persist.\n" if ($?>>8);
+
+    close($in);
+    close($out);
+    close($err);
+}
+
+sub fence_node
+{
+    my $name = (POSIX::uname())[1];
+
+    my $host_key = get_key($name);
+    my $node_key = get_key($opt_n);
+
+    foreach $dev (@volumes)
+    {
+	my ($in, $out, $err);
+
+	if ($host_key eq $node_key)
+	{
+	    my $cmd = "sg_persist -d $dev -o -G -K $host_key -S 0";
+	}
+	else
+	{
+	    my $cmd = "sg_persist -d $dev -o -A -K $host_key -S $node_key -T 5";
+	}
+
+	my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
+
+	waitpid($pid, 0);
+
+	die "Unable to execute sg_persist.\n" if ($?>>8);
+
+	if ($opt_v)
+	{
+	    print "$cmd\n";
+	    while (<$out>)
+	    {
+		chomp;
+		print "OUT: $_\n";
+	    }
+	}
+
+	close($in);
+	close($out);
+	close($err);
+    }
+}
+
+### MAIN #######################################################
+
+if (@ARGV > 0) {
+
+    getopts("n:hqvV") || fail_usage;
+
+    usage if defined $opt_h;
+    version if defined $opt_V;
+
+    fail_usage "Unkown parameter." if (@ARGV > 0);
+    fail_usage "No '-n' flag specified." unless defined $opt_n;
+
+} else {
+
+    get_options_stdin();
+
+    fail "failed: missing 'node'" unless defined $node;
+
+}
+
+check_sg_persist;
+
+get_scsi_devices;
+
+fence_node;



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Cluster-devel] cluster/fence/agents/scsi fence_scsi
@ 2006-06-29 20:36 rohara
  0 siblings, 0 replies; 3+ messages in thread
From: rohara @ 2006-06-29 20:36 UTC (permalink / raw)
  To: cluster-devel.redhat.com

CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	rohara at sourceware.org	2006-06-29 20:36:12

Modified files:
	fence/agents/scsi: fence_scsi 

Log message:
	Fix perl cmd declaration that caused sg_persist to fail.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/fence_scsi.diff?cvsroot=cluster&r1=1.1&r2=1.2

--- cluster/fence/agents/scsi/fence_scsi	2006/06/29 17:23:12	1.1
+++ cluster/fence/agents/scsi/fence_scsi	2006/06/29 20:36:12	1.2
@@ -155,26 +155,25 @@
 
     my $host_key = get_key($name);
     my $node_key = get_key($opt_n);
+    
+    my $cmd;
+    my ($in, $out, $err);
 
     foreach $dev (@volumes)
     {
-	my ($in, $out, $err);
-
 	if ($host_key eq $node_key)
 	{
-	    my $cmd = "sg_persist -d $dev -o -G -K $host_key -S 0";
+	    $cmd = "sg_persist -d $dev -o -G -K $host_key -S 0";
 	}
 	else
 	{
-	    my $cmd = "sg_persist -d $dev -o -A -K $host_key -S $node_key -T 5";
+	    $cmd = "sg_persist -d $dev -o -A -K $host_key -S $node_key -T 5";
 	}
 
 	my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
 
 	waitpid($pid, 0);
 
-	die "Unable to execute sg_persist.\n" if ($?>>8);
-
 	if ($opt_v)
 	{
 	    print "$cmd\n";
@@ -185,6 +184,8 @@
 	    }
 	}
 
+	die "Unable to execute sg_persist.\n" if ($?>>8);
+
 	close($in);
 	close($out);
 	close($err);



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Cluster-devel] cluster/fence/agents/scsi fence_scsi
@ 2006-06-29 22:16 jparsons
  0 siblings, 0 replies; 3+ messages in thread
From: jparsons @ 2006-06-29 22:16 UTC (permalink / raw)
  To: cluster-devel.redhat.com

CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	jparsons at sourceware.org	2006-06-29 22:16:43

Removed files:
	fence/agents/scsi: fence_scsi 

Log message:
	remove this file in preference for the version with filetype extension, like other agents. The Makefile generates the version for the sbin dir without extension.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/fence_scsi.diff?cvsroot=cluster&r1=1.2&r2=NONE



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-06-29 22:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-29 17:23 [Cluster-devel] cluster/fence/agents/scsi fence_scsi rohara
  -- strict thread matches above, loose matches on Subject: below --
2006-06-29 20:36 rohara
2006-06-29 22:16 jparsons

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).