Whamcloud - gitweb
43b33893f45f33b5c8ae50b9ea06850c0b6ef6ad
[fs/lustre-release.git] / lustre / scripts / statechange-lustre.sh
1 #!/bin/sh
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License Version 1.0 (CDDL-1.0).
7 # You can obtain a copy of the license from the top-level file
8 # "OPENSOLARIS.LICENSE" or at <http://opensource.org/licenses/CDDL-1.0>.
9 # You may not use this file except in compliance with the license.
10 #
11 # CDDL HEADER END
12 #
13
14 #
15 # Copyright (c) 2018, Intel Corporation.
16 #
17
18 #
19 # Adjust lustre service degrade state in response to a statechange
20 #
21 # ZEVENT_SUBCLASS: 'statechange'
22 # POOL HEALTH: status from "zpool list health" (either ONLINE or DEGRADED)
23 #
24 # depends on lctl(1)
25 #
26 # Exit codes:
27 #   0: normal exit
28 #   1: lctl missing
29 #   2: zpool missing
30 #   3: zfs missing
31 #   4: Pool status neither "ONLINE" nor "DEGRADED
32 #
33 # This script is also symlinked as vdev_attach-lustre.sh, vdev_remove-lustre.sh
34 # and vdev_clear-lustre.sh, since it needs to take the same action on those
35 # ZFS events as well.
36
37 [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
38 . "${ZED_ZEDLET_DIR}/zed-functions.sh"
39
40 LCTL=${LCTL:-/usr/sbin/lctl}
41 ZPOOL=${ZPOOL:-/usr/sbin/zpool}
42 ZFS=${ZFS:-/usr/sbin/zfs}
43
44 zed_check_cmd "$LCTL" || exit 1
45 zed_check_cmd "$ZPOOL" || exit 2
46 zed_check_cmd "$ZFS" || exit 3
47
48 #
49 # sync_degrade_state (dataset, state)
50 #
51 sync_degrade_state()
52 {
53         local dataset="$1"
54         local state="$2"
55         local service=$($ZFS list -H -o lustre:svname ${dataset})
56
57         zed_log_msg "Lustre:sync_degrade_state pool:${dataset} degraded:${state}"
58
59         if [ -n "${service}" ] && [ "${service}" != "-" ] ; then
60                 local current=$($LCTL get_param -n obdfilter.${service}.degraded)
61
62                 if [ "${current}" != "${state}" ] ; then
63                         $LCTL set_param obdfilter.${service}.degraded=${state}
64                 fi
65         fi
66 }
67
68 #
69 # use pool state as deciding factor
70 #
71 POOL_STATE=$($ZPOOL list -H -o health ${ZEVENT_POOL})
72
73 if [ "${POOL_STATE}" == "ONLINE" ] ; then
74         MODE="0"
75 elif [ "${POOL_STATE}" == "DEGRADED" ] ; then
76         MODE="1"
77 else
78         exit 4
79 fi
80
81 #
82 # visit target pool's datasets and adjust lustre service degrade mode
83 #
84 read -r -a DATASETS <<< \
85         $($ZFS get -rH -s local -t filesystem -o name lustre:svname ${ZEVENT_POOL})
86
87 for dataset in "${DATASETS[@]}" ; do
88         sync_degrade_state "${dataset}" "${MODE}"
89 done
90
91 exit 0