| 1 |
#! /bin/bash |
| 2 |
# |
| 3 |
# Copyright (C) 2014 FUJITSU LIMITED |
| 4 |
# |
| 5 |
# This library is free software; you can redistribute it and/or |
| 6 |
# modify it under the terms of version 2.1 of the GNU Lesser General Public |
| 7 |
# License as published by the Free Software Foundation. |
| 8 |
# |
| 9 |
# This library is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
# Lesser General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU Lesser General Public |
| 15 |
# License along with this library; If not, see <http://www.gnu.org/licenses/>. |
| 16 |
# |
| 17 |
# Usage: |
| 18 |
# block-drbd-probe devicename |
| 19 |
# |
| 20 |
# Return value: |
| 21 |
# 0: the device is drbd device |
| 22 |
# 1: the device is not drbd device |
| 23 |
# 2: unknown error |
| 24 |
# 3: the drbd device does not use protocol D |
| 25 |
# 4: the drbd device is not ready |
| 26 |
|
| 27 |
set -e |
| 28 |
|
| 29 |
drbd_res= |
| 30 |
|
| 31 |
function get_res_name() |
| 32 |
{ |
| 33 |
local drbd_dev=$1 |
| 34 |
local drbd_dev_list=($(drbdadm sh-dev all)) |
| 35 |
local drbd_res_list=($(drbdadm sh-resource all)) |
| 36 |
local temp_drbd_dev temp_drbd_res |
| 37 |
local found=0 |
| 38 |
|
| 39 |
for temp_drbd_dev in ${drbd_dev_list[@]}; do |
| 40 |
if [[ "$temp_drbd_dev" == "$drbd_dev" ]]; then |
| 41 |
found=1 |
| 42 |
break |
| 43 |
fi |
| 44 |
done |
| 45 |
|
| 46 |
if [[ $found -eq 0 ]]; then |
| 47 |
return 1 |
| 48 |
fi |
| 49 |
|
| 50 |
for temp_drbd_res in ${drbd_res_list[@]}; do |
| 51 |
temp_drbd_dev=$(drbdadm sh-dev $temp_drbd_res) |
| 52 |
if [[ "$temp_drbd_dev" == "$drbd_dev" ]]; then |
| 53 |
drbd_res="$temp_drbd_res" |
| 54 |
return 0 |
| 55 |
fi |
| 56 |
done |
| 57 |
|
| 58 |
# OOPS |
| 59 |
return 2 |
| 60 |
} |
| 61 |
|
| 62 |
get_res_name $1 |
| 63 |
rc=$? |
| 64 |
if [[ $rc -ne 0 ]]; then |
| 65 |
exit $rc |
| 66 |
fi |
| 67 |
|
| 68 |
# check protocol |
| 69 |
drbdsetup $1 show | grep -q "protocol D;" |
| 70 |
if [[ $? -ne 0 ]]; then |
| 71 |
exit 3 |
| 72 |
fi |
| 73 |
|
| 74 |
# check connect status |
| 75 |
state=$(drbdadm cstate "$drbd_res") |
| 76 |
if [[ "$state" != "Connected" ]]; then |
| 77 |
exit 4 |
| 78 |
fi |
| 79 |
|
| 80 |
# check role |
| 81 |
role=$(drbdadm role "$drbd_res") |
| 82 |
if [[ "$role" != "Primary/Secondary" ]]; then |
| 83 |
exit 4 |
| 84 |
fi |
| 85 |
|
| 86 |
exit 0 |