| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# |
| 4 |
# ServeRAID |
| 5 |
# |
| 6 |
# Description: Enables/Disables shared ServeRAID merge groups |
| 7 |
# |
| 8 |
# Author: Alan Robertson, Renzo Alejandro Granados |
| 9 |
# |
| 10 |
# Support: [email protected] |
| 11 |
# |
| 12 |
# License: GNU General Public License (GPL) |
| 13 |
# |
| 14 |
# Copyright: (C) 2002-2005 International Business Machines |
| 15 |
# (C) 2002 Renzo Alejandro Granados |
| 16 |
# |
| 17 |
# usage: ./ServeRAID (start|stop|status|monitor|validate-all|meta-data) |
| 18 |
# |
| 19 |
# OCF parameters are as below: |
| 20 |
# OCF_RESKEY_serveraid |
| 21 |
# (Adapter number of the ServeRAID adapter) |
| 22 |
# OCF_RESKEY_mergegroup |
| 23 |
# (MergeGroup # of the logical drive under consideration) |
| 24 |
# |
| 25 |
# The ServeRAID clustering model is a bit odd, and its terminology needs |
| 26 |
# a little explanation |
| 27 |
# |
| 28 |
# Logical Volume - a particular SCSI id {target id and LUN} on |
| 29 |
# a particular controller. |
| 30 |
# |
| 31 |
# Merge Group - when active on one side or the other of the ServeRAID |
| 32 |
# configuration it corresponds with a logical drive. |
| 33 |
# Merge group numbers are permanently assigned to a particular |
| 34 |
# chunk of storage. Shared merge groups are in the |
| 35 |
# range of 1 to 8, and are largely arbitrary. |
| 36 |
# Unshared merge groups start at 200. |
| 37 |
# We can only deal with shared merge groups. When a merge |
| 38 |
# group is activated on one of the controllers, it becomes |
| 39 |
# a logical volume on that system. NOTE: The order in |
| 40 |
# which the Merge Groups are activated determines which |
| 41 |
# SCSI Ids they become. This makes for extra headaches |
| 42 |
# for this script to deal with. It also means that if |
| 43 |
# you have more than one shared ServeRAID merge group on |
| 44 |
# a particular controller, that the SCSI IDs will not |
| 45 |
# be constant. This requires mounting by uuid or label. |
| 46 |
# |
| 47 |
# One of the ServerRAID controllers has to be configured with |
| 48 |
# SCSI initiator ID 6, and the other with SCSI id 7. |
| 49 |
# |
| 50 |
# At this time, the ServeRAID clustering solution only works with |
| 51 |
# RAID 1 setups. It does NOT support RAID 5. This is a firmware |
| 52 |
# bug in the ServeRAID where it doesn't fail over correctly |
| 53 |
# if the RAID5 array is in a critical state... |
| 54 |
# |
| 55 |
# Note that this script requires ServeRAID software version 6.10 or |
| 56 |
# later. This software is now available from IBM. |
| 57 |
# |
| 58 |
# An example usage in /etc/ha.d/haresources: |
| 59 |
# node1 10.0.0.170 ServeRAID::1::1 |
| 60 |
# |
| 61 |
|
| 62 |
# Older ServeRAID utility returns 1 when it succeeds (weird) |
| 63 |
# BUT - the newly released version is more normal... |
| 64 |
|
| 65 |
####################################################################### |
| 66 |
# Initialization: |
| 67 |
|
| 68 |
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} |
| 69 |
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs |
| 70 |
|
| 71 |
# Parameter defaults |
| 72 |
|
| 73 |
OCF_RESKEY_serveraid_default="" |
| 74 |
OCF_RESKEY_mergegroup_default="" |
| 75 |
|
| 76 |
: ${OCF_RESKEY_serveraid=${OCF_RESKEY_serveraid_default}} |
| 77 |
: ${OCF_RESKEY_mergegroup=${OCF_RESKEY_mergegroup_default}} |
| 78 |
|
| 79 |
####################################################################### |
| 80 |
|
| 81 |
srsuccess=0 |
| 82 |
SCSI="scsi " |
| 83 |
|
| 84 |
usage() { |
| 85 |
cat <<-EOF |
| 86 |
usage: $0 (start|stop|status|monitor|validate-all|meta-data) |
| 87 |
|
| 88 |
You have to set the following environment virables before running $0 : |
| 89 |
OCF_RESKEY_serveraid |
| 90 |
(Adapter number of the ServeRAID adapter) |
| 91 |
OCF_RESKEY_mergegroup |
| 92 |
(MergeGroup # of the logical drive under consideration) |
| 93 |
|
| 94 |
ServeRAID adapters are numbered starting from 1. |
| 95 |
|
| 96 |
The shared merge group number is a number between 1 and 8 inclusive. |
| 97 |
It indicates to the controller which logical disk to fail over. |
| 98 |
|
| 99 |
node1 10.0.0.170 ServeRAID::1::1 |
| 100 |
|
| 101 |
PREREQUISITES: |
| 102 |
You must configure your ServeRAID adapters for clustering for this |
| 103 |
to work. |
| 104 |
|
| 105 |
To do this, you must use the bootable "ServeRAID Support CD" and right |
| 106 |
click your controller and pick "configure for clustering". The Linux |
| 107 |
version of the ServeRAID manager does not have the "configure for |
| 108 |
clustering" option. |
| 109 |
|
| 110 |
You will need at least version 6.10 (~July 2003 release) of the ipssend |
| 111 |
command for this script to work. |
| 112 |
|
| 113 |
EOF |
| 114 |
} |
| 115 |
|
| 116 |
meta_data() { |
| 117 |
cat <<END |
| 118 |
<?xml version="1.0"?> |
| 119 |
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> |
| 120 |
<resource-agent name="ServeRAID" version="1.0"> |
| 121 |
<version>1.0</version> |
| 122 |
|
| 123 |
<longdesc lang="en"> |
| 124 |
Resource script for ServeRAID. It enables/disables shared ServeRAID merge groups. |
| 125 |
</longdesc> |
| 126 |
<shortdesc lang="en">Enables and disables shared ServeRAID merge groups</shortdesc> |
| 127 |
|
| 128 |
<parameters> |
| 129 |
<parameter name="serveraid" unique="0" required="1"> |
| 130 |
<longdesc lang="en"> |
| 131 |
The adapter number of the ServeRAID adapter. |
| 132 |
</longdesc> |
| 133 |
<shortdesc lang="en">serveraid</shortdesc> |
| 134 |
<content type="integer" default="${OCF_RESKEY_serveraid_default}" /> |
| 135 |
</parameter> |
| 136 |
|
| 137 |
<parameter name="mergegroup" unique="0" required="1"> |
| 138 |
<longdesc lang="en"> |
| 139 |
The logical drive under consideration. |
| 140 |
</longdesc> |
| 141 |
<shortdesc lang="en">mergegroup</shortdesc> |
| 142 |
<content type="integer" default="${OCF_RESKEY_mergegroup_default}" /> |
| 143 |
</parameter> |
| 144 |
</parameters> |
| 145 |
|
| 146 |
<actions> |
| 147 |
<action name="start" timeout="40s" /> |
| 148 |
<action name="stop" timeout="40s" /> |
| 149 |
<action name="status" depth="0" timeout="20s" interval="10s" /> |
| 150 |
<action name="monitor" depth="0" timeout="20s" interval="10s" /> |
| 151 |
<action name="validate-all" timeout="5s" /> |
| 152 |
<action name="meta-data" timeout="5s" /> |
| 153 |
<action name="methods" timeout="5s" /> |
| 154 |
</actions> |
| 155 |
</resource-agent> |
| 156 |
END |
| 157 |
} |
| 158 |
|
| 159 |
ServeRAID_methods() { |
| 160 |
cat <<-! |
| 161 |
start |
| 162 |
stop |
| 163 |
status |
| 164 |
validate-all |
| 165 |
methods |
| 166 |
usage |
| 167 |
meta-data |
| 168 |
! |
| 169 |
} |
| 170 |
|
| 171 |
ServeRAIDSCSI="/proc/scsi/ips" |
| 172 |
|
| 173 |
|
| 174 |
IPS=ipssend |
| 175 |
proc_scsi=/proc/scsi/scsi |
| 176 |
|
| 177 |
|
| 178 |
parseinst() { |
| 179 |
sr_adapter=error |
| 180 |
sr_mergegroup=error |
| 181 |
hostid=error |
| 182 |
sr_logicaldrivenumber=error |
| 183 |
if |
| 184 |
[ $# -ne 2 ] |
| 185 |
then |
| 186 |
ocf_log err "Invalid ServeRAID instance: $*" |
| 187 |
exit $OCF_ERR_ARGS |
| 188 |
fi |
| 189 |
PerlScript='next unless /^Host/; $_ .= <>.<>; print "$1 " if /SERVERAID/ and /Proces/ and /scsi(\d+)/' |
| 190 |
# Get the list of host ids of the ServeRAID host adapters |
| 191 |
hostlist=`$PERL -ne "${PerlScript}" <$proc_scsi` |
| 192 |
# Figure the host id of the desired ServeRAID adapter |
| 193 |
hostid=`echo $hostlist | cut -d' ' -f$1` |
| 194 |
if |
| 195 |
[ ! -f "$ServeRAIDSCSI/$hostid" ] |
| 196 |
then |
| 197 |
ocf_log err "No such ServeRAID adapter: $1" |
| 198 |
exit $OCF_ERR_ARGS |
| 199 |
fi |
| 200 |
|
| 201 |
case $2 in |
| 202 |
[1-8]);; |
| 203 |
*) ocf_log err "Invalid Shared Merge Group Number: $2" |
| 204 |
exit $OCF_ERR_ARGS;; |
| 205 |
esac |
| 206 |
sr_adapter=$1 |
| 207 |
sr_mergegroup=$2 |
| 208 |
CheckRaidLevel |
| 209 |
return $? |
| 210 |
} |
| 211 |
|
| 212 |
SRLogicalDriveConfig() { |
| 213 |
$IPS getconfig $sr_adapter ld |
| 214 |
} |
| 215 |
|
| 216 |
MergeGroupToSCSI_ID() { |
| 217 |
|
| 218 |
PerlScript="while (<>) { |
| 219 |
/logical drive number *([0-9]+)/i && (\$ld=\$1); |
| 220 |
/part of merge group *: *$sr_mergegroup *\$/i && print \$ld - 1, \"\n\"; |
| 221 |
}" |
| 222 |
|
| 223 |
ID=`SRLogicalDriveConfig | $PERL -e "$PerlScript"` |
| 224 |
case $ID in |
| 225 |
[0-9]*) echo "$ID"; return 0;; |
| 226 |
*) return 1;; |
| 227 |
esac |
| 228 |
} |
| 229 |
|
| 230 |
MergeGroupRaidLevel() { |
| 231 |
|
| 232 |
PerlScript="while (<>) { |
| 233 |
/RAID level *: *([0-9]+[A-Za-z]*)/i && (\$ld=\$1); |
| 234 |
/part of merge group *: *$sr_mergegroup *\$/i && print \$ld, \"\n\"; |
| 235 |
}" |
| 236 |
|
| 237 |
Level=`SRLogicalDriveConfig | $PERL -e "$PerlScript"` |
| 238 |
case $Level in |
| 239 |
?*) echo "$Level"; return 0;; |
| 240 |
*) return 1;; |
| 241 |
esac |
| 242 |
} |
| 243 |
|
| 244 |
CheckRaidLevel() { |
| 245 |
RAIDlevel=`MergeGroupRaidLevel` |
| 246 |
case $RAIDlevel in |
| 247 |
*5*) |
| 248 |
ocf_log err "ServeRAID device $sr_adapter $sr_mergegroup is RAID level $RAIDlevel" |
| 249 |
ocf_log err "This level of ServeRAID RAID is not supported for failover by the firmware." |
| 250 |
exit $OCF_ERR_GENERIC;; |
| 251 |
esac |
| 252 |
return $OCF_SUCCESS |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
ReleaseSCSI() { |
| 259 |
targetid=`MergeGroupToSCSI_ID` |
| 260 |
echo "${SCSI}remove-single-device $hostid 0 $targetid 0" > $proc_scsi |
| 261 |
} |
| 262 |
|
| 263 |
AddSCSI() { |
| 264 |
targetid=`MergeGroupToSCSI_ID` |
| 265 |
echo "${SCSI}add-single-device $hostid 0 $targetid 0" > $proc_scsi |
| 266 |
} |
| 267 |
|
| 268 |
# |
| 269 |
# start: Enable the given ServeRAID device |
| 270 |
# |
| 271 |
ServeRAID_start() { |
| 272 |
if |
| 273 |
ServeRAID_status $serveraid $mergegroup |
| 274 |
then |
| 275 |
ocf_log debug "ServeRAID merge group $serveraid $mergegroup is running." |
| 276 |
return $OCF_SUCCESS |
| 277 |
else |
| 278 |
if |
| 279 |
# |
| 280 |
# Normally we do a MERGE PARTNER, but if we still own the drive for |
| 281 |
# some reason, then we'll need to do a MERGE OWN instead... |
| 282 |
# |
| 283 |
out=`$IPS MERGE $sr_adapter $sr_mergegroup PARTNER 2>&1` |
| 284 |
if |
| 285 |
[ $? -eq $srsuccess ] |
| 286 |
then |
| 287 |
ocf_log info "$out" |
| 288 |
else |
| 289 |
ocf_run $IPS MERGE $sr_adapter $sr_mergegroup OWN |
| 290 |
fi |
| 291 |
then |
| 292 |
: OK All is well! |
| 293 |
targetid=`MergeGroupToSCSI_ID` |
| 294 |
sr_logicaldrivenumber=`expr $targetid + 1` |
| 295 |
#run $IPS SYNCH $sr_adapter $sr_logicaldrivenumber & |
| 296 |
# This version of the SYNCH command requires the 6.10 or later |
| 297 |
# ServeRAID support CD. |
| 298 |
# To avoid issues when called by lrmd, redirect stdout->stderr. |
| 299 |
# Use () to create a subshell to make the redirection be synchronized. |
| 300 |
( ocf_run $IPS SYNCH $sr_adapter $sr_mergegroup & ) >&2 |
| 301 |
AddSCSI |
| 302 |
else |
| 303 |
return $OCF_ERR_GENERIC |
| 304 |
fi |
| 305 |
fi |
| 306 |
if |
| 307 |
ServeRAID_status "$@" |
| 308 |
then |
| 309 |
return $OCF_SUCCESS |
| 310 |
else |
| 311 |
ocf_log err "ServeRAID device $1 not active!" |
| 312 |
exit $OCF_ERR_GENERIC |
| 313 |
fi |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
# |
| 318 |
# stop: Disable the given ServeRAID device |
| 319 |
# |
| 320 |
ServeRAID_stop() { |
| 321 |
parseinst "$@" |
| 322 |
ReleaseSCSI |
| 323 |
if |
| 324 |
ocf_run $IPS UNMERGE $sr_adapter $sr_mergegroup |
| 325 |
then |
| 326 |
: UNMERGE $sr_adapter $sr_mergegroup worked |
| 327 |
fi |
| 328 |
if |
| 329 |
ServeRAID_status "$@" |
| 330 |
then |
| 331 |
ocf_log err "ServeRAID device $* is still active!" |
| 332 |
return $OCF_ERR_GENERIC |
| 333 |
else |
| 334 |
return $OCF_SUCCESS |
| 335 |
fi |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
# |
| 340 |
# status: is the given device now available? |
| 341 |
# |
| 342 |
ServeRAID_status() { |
| 343 |
parseinst "$@" |
| 344 |
# |
| 345 |
# The output we're looking for |
| 346 |
# Part of merge group : 2 |
| 347 |
# |
| 348 |
SRLogicalDriveConfig \ |
| 349 |
| grep -i "part of merge group[ ]*: *$sr_mergegroup *\$" >/dev/null |
| 350 |
} |
| 351 |
|
| 352 |
# |
| 353 |
# validate_all: are the OCF instance parameters valid? |
| 354 |
# |
| 355 |
ServeRAID_validate_all() { |
| 356 |
check_binary $PERL |
| 357 |
|
| 358 |
# parseinst() will do all the work... |
| 359 |
parseinst "$@" |
| 360 |
return $? |
| 361 |
} |
| 362 |
|
| 363 |
if |
| 364 |
( [ $# -ne 1 ] ) |
| 365 |
then |
| 366 |
usage |
| 367 |
exit $OCF_ERR_ARGS |
| 368 |
fi |
| 369 |
|
| 370 |
# These operations don't require OCF instance parameters to be set |
| 371 |
case "$1" in |
| 372 |
meta-data) |
| 373 |
meta_data |
| 374 |
exit $OCF_SUCCESS;; |
| 375 |
# |
| 376 |
# methods: What methods do we support? |
| 377 |
# |
| 378 |
methods) |
| 379 |
ServeRAID_methods |
| 380 |
exit $?;; |
| 381 |
usage) |
| 382 |
usage |
| 383 |
exit $OCF_SUCCESS;; |
| 384 |
*) |
| 385 |
;; |
| 386 |
esac |
| 387 |
|
| 388 |
if |
| 389 |
( [ -z "$OCF_RESKEY_serveraid" ] || [ -z "$OCF_RESKEY_mergegroup" ] ) |
| 390 |
then |
| 391 |
ocf_log err "You have to set the OCF_RESKEY_serveraid and OCF_RESKEY_mergegroup\n |
| 392 |
enviroment virables before running $0 !" |
| 393 |
# usage |
| 394 |
exit $OCF_ERR_GENERIC |
| 395 |
fi |
| 396 |
|
| 397 |
: Right Number of arguments.. |
| 398 |
serveraid=$OCF_RESKEY_serveraid |
| 399 |
mergegroup=$OCF_RESKEY_mergegroup |
| 400 |
|
| 401 |
# Look for the start, stop, status, or methods calls... |
| 402 |
case "$1" in |
| 403 |
stop) |
| 404 |
ServeRAID_stop $serveraid $mergegroup |
| 405 |
exit $?;; |
| 406 |
start) |
| 407 |
ServeRAID_start $serveraid $mergegroup |
| 408 |
exit $?;; |
| 409 |
status|monitor) |
| 410 |
if |
| 411 |
ServeRAID_status $serveraid $mergegroup |
| 412 |
then |
| 413 |
ocf_log debug "ServeRAID merge group $serveraid $mergegroup is running." |
| 414 |
exit $OCF_SUCCESS |
| 415 |
else |
| 416 |
ocf_log debug "ServeRAID merge group $serveraid $mergegroup is stopped." |
| 417 |
exit $OCF_NOT_RUNNING |
| 418 |
fi |
| 419 |
exit $?;; |
| 420 |
validate-all) |
| 421 |
ServeRAID_validate_all $serveraid $mergegroup |
| 422 |
exit $?;; |
| 423 |
*) |
| 424 |
usage |
| 425 |
exit $OCF_ERR_UNIMPLEMENTED;; |
| 426 |
|
| 427 |
esac |