Whamcloud - gitweb
LU-13004 ptlrpc: Allow BULK_BUF_KIOV to accept a kvec
[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 [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
34 . "${ZED_ZEDLET_DIR}/zed-functions.sh"
35
36 LCTL=${LCTL:-/usr/sbin/lctl}
37 ZPOOL=${ZPOOL:-/usr/sbin/zpool}
38 ZFS=${ZFS:-/usr/sbin/zfs}
39
40 zed_check_cmd "$LCTL" || exit 1
41 zed_check_cmd "$ZPOOL" || exit 2
42 zed_check_cmd "$ZFS" || exit 3
43
44 #
45 # sync_degrade_state (dataset, state)
46 #
47 sync_degrade_state()
48 {
49         local dataset="$1"
50         local state="$2"
51         local service=$($ZFS list -H -o lustre:svname ${dataset})
52
53         zed_log_msg "Lustre:sync_degrade_state pool:${dataset} degraded:${state}"
54
55         if [ -n "${service}" ] && [ "${service}" != "-" ] ; then
56                 local current=$($LCTL get_param -n obdfilter.${service}.degraded)
57
58                 if [ "${current}" != "${state}" ] ; then
59                         $LCTL set_param obdfilter.${service}.degraded=${state}
60                 fi
61         fi
62 }
63
64 #
65 # use pool state as deciding factor
66 #
67 POOL_STATE=$($ZPOOL list -H -o health ${ZEVENT_POOL})
68
69 if [ "${POOL_STATE}" == "ONLINE" ] ; then
70         MODE="0"
71 elif [ "${POOL_STATE}" == "DEGRADED" ] ; then
72         MODE="1"
73 else
74         exit 4
75 fi
76
77 #
78 # visit target pool's datasets and adjust lustre service degrade mode
79 #
80 read -r -a DATASETS <<< \
81         $($ZFS get -rH -s local -t filesystem -o name lustre:svname ${ZEVENT_POOL})
82
83 for dataset in "${DATASETS[@]}" ; do
84         sync_degrade_state "${dataset}" "${MODE}"
85 done
86
87 exit 0