drbd resource script patch
"Martin Bene" <[email protected]> Wed, 8 May 2002 16:55:52 +0200
| Newsgroups | gmane.linux.failsafe |
|---|---|
| Message-ID | <[email protected]> |
Hi Lars,
below is a patch for the drbd resource scripts, which makes current versions of drbd work with failsafe again. The drbd version I'm using here is 0.6.1-pre10.
* change drbdsetup command for primary / secondary mode ("PRI" ==> "primary", "SEC" ==> secondary")
* change exclusivity check:
- failsafe exclusivity check should return "running" only on a node where the resource is localy active, so check for "Primary/" status, i.e primary on this node.
- if sync is in progress (quicksync or syncall), drbd cannot be set to secondary. so, DON'T return running status if sync is in progress.
* change startup: fail startup if the other node is in primary status. this can happen if a sync is in progress, see previous point.
drbd is a nasty resource to handle while resync is in progress: it can not be stopped, and for successfull startup, it MUST be started on the node where it's already primary. The patch tries to accomodate this by moving some of the startup checks from exclusive to start: for exclusive check, the node where the resource will be started is still unknown, so it's not possible to handle drbds requirements. Correct check can only be made at start time. Fortunately, failsafe is persistent enough to get the drbd resource correctly online for all reasonable device states.
drbd without sync in progress: handled correctly by exclusive script - if it's up on a node, stop script gets called before startup. no problem.
drbd with sync in progress: exclusive script says "not running" on both nodes.
startup on primary node: no problem, works
startup on secondary node:
- start script fails
- failsafe calls stop on secondary node, OK
- failsafe tries starting on other (primary) node, success.
Hope this is useful for someone else :-)
********************************************************
Martin Bene, CTO
icomedias GmbH, A-8020 Graz, Nikolaiplatz 4
t +43 (316) 721671-14, f +43 (316) 721671-26
e [email protected], i http://www.icomedias.com
********************************************************
drbd.patch
(application/octet-stream, 2.5 KB)
Index: cluster_services/cmd/srm/scripts/drbd/control
===================================================================
RCS file: /cvs/failsafe/FailSafe/cluster_services/cmd/srm/scripts/drbd/control,v
retrieving revision 1.1
diff -u -r1.1 control
--- cluster_services/cmd/srm/scripts/drbd/control 2001/09/24 13:35:59 1.1
+++ cluster_services/cmd/srm/scripts/drbd/control 2002/05/08 14:30:30
@@ -1,4 +1,4 @@
-#!/bin/sh -xv
+#!/bin/sh
#
# Control script for drbd resource
#
@@ -52,19 +52,27 @@
case $action in
start)
- HA_CMD="$DRBDSETUP $Device PRI"
- s2_run_command "$HA_CMD" "Setting $Device to PRIMARY"
- exit_status=$?
+ # fail if other side is primary
+ DEVNO=`echo $Device | sed -e 's/\/dev\/nb//'`
+ grep -E "^${DEVNO}.*/Primary" /proc/drbd >/dev/null 2>&1
+ if [ $? = 0 ]; then
+ s2_log "$Device is active (Primary) on other Node"
+ exit_status=1
+ else
+ HA_CMD="$DRBDSETUP $Device primary"
+ s2_run_command "$HA_CMD" "Setting $Device to PRIMARY"
+ exit_status=$?
+ fi
;;
stop)
- HA_CMD="$DRBDSETUP $Device SEC"
+ HA_CMD="$DRBDSETUP $Device secondary"
s2_run_command "$HA_CMD" "Setting $Device to SECONDARY"
exit_status=$?
;;
restart)
- HA_CMD="$DRBDSETUP $Device PRI"
+ HA_CMD="$DRBDSETUP $Device primary"
s2_run_command "$HA_CMD" "Setting $Device to PRIMARY"
exit_status=$?
;;
@@ -72,7 +80,7 @@
monitor)
STATUS=`get_dev_status $Device`
case "$STATUS" in
- Unconnected|WFConnection|WFReportParams|SyncingAll|SyncingQuick|Connected|Timeout)
+ StandAlone|Unconnected|BrokenPipe|WFConnection|WFReportParams|SyncingAll|SyncingQuick|Connected|Timeout)
exit_status=0
;;
@@ -88,12 +96,22 @@
;;
exclusive)
+ STATUS=`get_dev_status $Device`
DEVNO=`echo $Device | sed -e 's/\/dev\/nb//'`
- grep -E "^${DEVNO}.*Primary" /proc/drbd >/dev/null 2>&1
+ grep -E "^${DEVNO}.*Primary/" /proc/drbd >/dev/null 2>&1
if [ $? = 0 ]; then
- s2_log "Found at least one active Primary Node for this device"
- s2_log "Cannot go online"
- exit_status=1
+ case "$STATUS" in
+ SyncingAll|SyncingQuick)
+ s2_log "$Device is active (Primary) on this node, but sync in progress - allow startup to proceed"
+ exit_status=0
+ ;;
+
+ *)
+ s2_log "$Device is active (Primary) on this node"
+ s2_log "Cannot go online"
+ exit_status=1
+ ;;
+ esac
else
s2_log "resource $Device not running"
exit_status=0