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 # 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
37 [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
38 . "${ZED_ZEDLET_DIR}/zed-functions.sh"
40 LCTL=${LCTL:-/usr/sbin/lctl}
41 ZPOOL=${ZPOOL:-/usr/sbin/zpool}
42 ZFS=${ZFS:-/usr/sbin/zfs}
44 zed_check_cmd "$LCTL" || exit 1
45 zed_check_cmd "$ZPOOL" || exit 2
46 zed_check_cmd "$ZFS" || exit 3
49 # sync_degrade_state (dataset, state)
55 local service=$($ZFS list -H -o lustre:svname ${dataset})
56 local autodegrade=$($ZFS get -rH -s local -t filesystem -o value \
57 lustre:autodegrade ${dataset})
59 if [ -n "${service}" ] && [ "${service}" != "-" ] ; then
60 local current=$($LCTL get_param -n obdfilter.${service}.degraded)
62 if [ "${current}" != "${state}" ] &&
63 [ "${autodegrade}" == "on" ] ; then
64 $LCTL set_param obdfilter.${service}.degraded=${state}
65 ds_state="pool:${dataset} degraded:${state}"
66 zed_log_msg "Lustre:sync_degrade_state $ds_state"
72 # use pool state as deciding factor
74 POOL_STATE=$($ZPOOL list -H -o health ${ZEVENT_POOL})
76 if [ "${POOL_STATE}" == "ONLINE" ] ; then
78 elif [ "${POOL_STATE}" == "DEGRADED" ] ; then
85 # visit target pool's datasets and adjust lustre service degrade mode
87 read -r -a DATASETS <<< \
88 $($ZFS get -rH -s local -t filesystem -o name lustre:svname ${ZEVENT_POOL})
90 for dataset in "${DATASETS[@]}" ; do
91 sync_degrade_state "${dataset}" "${MODE}"