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.
15 # Copyright (c) 2018, Intel Corporation.
19 # Adjust lustre service degrade state in response to a statechange
21 # ZEVENT_SUBCLASS: 'statechange'
22 # POOL HEALTH: status from "zpool list health" (either ONLINE or DEGRADED)
31 # 4: Pool status neither "ONLINE" nor "DEGRADED
33 [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
34 . "${ZED_ZEDLET_DIR}/zed-functions.sh"
36 LCTL=${LCTL:-/usr/sbin/lctl}
37 ZPOOL=${ZPOOL:-/usr/sbin/zpool}
38 ZFS=${ZFS:-/usr/sbin/zfs}
40 zed_check_cmd "$LCTL" || exit 1
41 zed_check_cmd "$ZPOOL" || exit 2
42 zed_check_cmd "$ZFS" || exit 3
45 # sync_degrade_state (dataset, state)
51 local service=$($ZFS list -H -o lustre:svname ${dataset})
53 zed_log_msg "Lustre:sync_degrade_state pool:${dataset} degraded:${state}"
55 if [ -n "${service}" ] && [ "${service}" != "-" ] ; then
56 local current=$($LCTL get_param -n obdfilter.${service}.degraded)
58 if [ "${current}" != "${state}" ] ; then
59 $LCTL set_param obdfilter.${service}.degraded=${state}
65 # use pool state as deciding factor
67 POOL_STATE=$($ZPOOL list -H -o health ${ZEVENT_POOL})
69 if [ "${POOL_STATE}" == "ONLINE" ] ; then
71 elif [ "${POOL_STATE}" == "DEGRADED" ] ; then
78 # visit target pool's datasets and adjust lustre service degrade mode
80 read -r -a DATASETS <<< \
81 $($ZFS get -rH -s local -t filesystem -o name lustre:svname ${ZEVENT_POOL})
83 for dataset in "${DATASETS[@]}" ; do
84 sync_degrade_state "${dataset}" "${MODE}"