[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] cluster/fence/agents/scsi scsi_reserve



CVSROOT:	/cvs/cluster
Module name:	cluster
Branch: 	RHEL4
Changes by:	rohara sourceware org	2006-11-27 22:27:39

Added files:
	fence/agents/scsi: scsi_reserve 

Log message:
	Initial checkin for scsi_reserve init script (RHEL4).

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/scsi_reserve.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=NONE&r2=1.1.6.1

/cvs/cluster/cluster/fence/agents/scsi/scsi_reserve,v  -->  standard output
revision 1.1.6.1
--- cluster/fence/agents/scsi/scsi_reserve
+++ -	2006-11-27 22:27:40.515592000 +0000
@@ -0,0 +1,163 @@
+#!/bin/bash
+#
+# chkconfig: 345 25 75
+# description: start/stop persistent reservation service for lvm
+
+. /etc/init.d/functions
+
+# check for sg_persist command provided by sg3_utils package
+#
+if ! sg_persist -V &> /dev/null ; then
+   echo "error: sg_persist not found"
+   exit 2
+fi
+
+# debug
+#
+echo "debug: found sg_persist"
+
+# check for gethostip command provided by syslinux package
+#
+if ! gethostip -h &> /dev/null ; then
+   echo "error: gethostip not found"
+   exit 3
+fi
+
+# debug
+#
+echo "debug: found gethostip"
+
+# get scsi devices that are part of clustered volumes
+#
+scsi_devices=$( lvs -o vg_attr,devices --noheadings \
+		| awk --posix ' $1 ~ /[-a-z]{5}c/ { print $2 } ' \
+		| sed -e 's/([0-9]*)//' | sort | uniq )
+
+# debug
+#
+for dev in $scsi_devices
+do
+  echo "debug: scsi_device = $dev"
+done
+
+# if no scsi devices were found we can exit now
+#
+[ -z "$scsi_devices" ] && exit 0
+
+# get the node name and node addr from cman
+#
+node_name=$( cman_tool status | grep "Node name" | awk -F": " '{ print $2 }' )
+node_addr=$( cman_tool status | grep "Node addr" | awk -F": " '{ print $2 }' )
+
+# debug
+#
+echo "debug: node_name = $node_name"
+echo "debug: node_addr = $node_addr"
+
+# create unique key for this host
+#
+key=$( gethostip -x $node_name )
+
+# debug
+#
+echo "debug: key = $key"
+
+################################################################################
+
+case $1 in
+
+start)
+
+rval=0
+
+touch /var/lock/subsys/${0##*/}
+
+# register each device using our key
+#
+for dev in $scsi_devices
+do
+  echo -n "Registering device: $dev"
+
+  for error in 1
+  do
+    sg_persist -d $dev -o -G -S $key &>/dev/null || break
+    error=0
+  done
+
+  if [ $error -eq 0 ]; then
+      success
+  else
+      failure
+      rval=1
+  fi
+
+  # create a reservation
+  #
+  sg_persist -d $dev -o -R -K $key -T 5 &>/dev/null
+
+done
+;;
+
+stop)
+
+rval=0
+
+# unregister each device for this node
+#
+for dev in $scsi_devices
+do
+  if sg_persist -d $dev -i -r 2>/dev/null | grep -qiE "${key#0}" ; then
+      echo "Unable to unregister device: $dev"
+      error=1
+  else
+      echo -n "Unregistering device: $dev"
+      for error in 1
+      do
+	sg_persist -d $dev -o -G -K $key -S 0 &>/dev/null || break
+	error=0
+      done
+  fi
+
+  if [ $error -eq 0 ]; then
+      success
+  else
+      failure
+      rval=1
+  fi
+
+  echo
+done
+
+rm -f /var/lock/subsys/${0##*/}
+
+;;
+
+status)
+
+rval=0
+
+# find devices that are registered with our key
+#
+for dev in $scsi_devices
+do
+  if sg_persist -d $dev -i -k 2>/dev/null | grep -qiE "${key#0}" ; then
+      devices[${#devices[ ]}]=$dev
+  fi
+done
+
+if [ -z $devices ]; then
+    echo "No devices resgistered."
+else
+    echo "Found ${#devices[ ]} registered device(s):"
+
+    for i in "${devices[ ]}" ; do
+	echo $i
+    done
+fi
+
+;;
+
+esac
+
+exit $status
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]