ARC: Cache arc_c value during arc_evict()
[zfs.git] / cmd / zed / zed.d / statechange-slot_off.sh
blob06acce93b8aa384e72a89d3f9e778854f9894916
1 #!/bin/sh
2 # shellcheck disable=SC3014,SC2154,SC2086,SC2034
4 # Turn off disk's enclosure slot if it becomes FAULTED.
6 # Bad SCSI disks can often "disappear and reappear" causing all sorts of chaos
7 # as they flip between FAULTED and ONLINE. If
8 # ZED_POWER_OFF_ENCLOSURE_SLOT_ON_FAULT is set in zed.rc, and the disk gets
9 # FAULTED, then power down the slot via sysfs:
11 # /sys/class/enclosure/<enclosure>/<slot>/power_status
13 # We assume the user will be responsible for turning the slot back on again.
15 # Note that this script requires that your enclosure be supported by the
16 # Linux SCSI Enclosure services (SES) driver. The script will do nothing
17 # if you have no enclosure, or if your enclosure isn't supported.
19 # Exit codes:
20 # 0: slot successfully powered off
21 # 1: enclosure not available
22 # 2: ZED_POWER_OFF_ENCLOSURE_SLOT_ON_FAULT disabled
23 # 3: vdev was not FAULTED
24 # 4: The enclosure sysfs path passed from ZFS does not exist
25 # 5: Enclosure slot didn't actually turn off after we told it to
27 [ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
28 . "${ZED_ZEDLET_DIR}/zed-functions.sh"
30 if [ ! -d /sys/class/enclosure ] ; then
31 # No JBOD enclosure or NVMe slots
32 exit 1
35 if [ "${ZED_POWER_OFF_ENCLOSURE_SLOT_ON_FAULT}" != "1" ] ; then
36 exit 2
39 if [ "$ZEVENT_VDEV_STATE_STR" != "FAULTED" ] ; then
40 exit 3
43 if [ ! -f "$ZEVENT_VDEV_ENC_SYSFS_PATH/power_status" ] ; then
44 exit 4
47 # Turn off the slot and wait for sysfs to report that the slot is off.
48 # It can take ~400ms on some enclosures and multiple retries may be needed.
49 for i in $(seq 1 20) ; do
50 echo "off" | tee "$ZEVENT_VDEV_ENC_SYSFS_PATH/power_status"
52 for j in $(seq 1 5) ; do
53 if [ "$(cat $ZEVENT_VDEV_ENC_SYSFS_PATH/power_status)" == "off" ] ; then
54 break 2
56 sleep 0.1
57 done
58 done
60 if [ "$(cat $ZEVENT_VDEV_ENC_SYSFS_PATH/power_status)" != "off" ] ; then
61 exit 5
64 zed_log_msg "powered down slot $ZEVENT_VDEV_ENC_SYSFS_PATH for $ZEVENT_VDEV_PATH"