xref: /freebsd/sys/contrib/openzfs/cmd/zpool/zpool.d/ses (revision 14c2e0a0c57e48a41433fdca668fac8882fb04df)
1eda14cbcSMatt Macy#!/bin/sh
2eda14cbcSMatt Macy#
3eda14cbcSMatt Macy# Print SCSI Enclosure Services (SES) info. The output is dependent on the name
4eda14cbcSMatt Macy# of the script/symlink used to call it.
5eda14cbcSMatt Macy#
6eda14cbcSMatt Macyhelpstr="
7eda14cbcSMatt Macyenc:		Show disk enclosure w:x:y:z value.
8eda14cbcSMatt Macyslot:		Show disk slot number as reported by the enclosure.
9eda14cbcSMatt Macyencdev:		Show /dev/sg* device associated with the enclosure disk slot.
10eda14cbcSMatt Macyfault_led:	Show value of the disk enclosure slot fault LED.
11eda14cbcSMatt Macylocate_led:	Show value of the disk enclosure slot locate LED.
12eda14cbcSMatt Macyses:		Show disk's enc, enc device, slot, and fault/locate LED values."
13eda14cbcSMatt Macy
14dae17134SMartin Matuskascript="${0##*/}"
15eda14cbcSMatt Macyif [ "$1" = "-h" ] ; then
16eda14cbcSMatt Macy	echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2-
17eda14cbcSMatt Macy	exit
18eda14cbcSMatt Macyfi
19eda14cbcSMatt Macy
20eda14cbcSMatt Macyif [ "$script" = "ses" ] ; then
21eda14cbcSMatt Macy	scripts='enc encdev slot fault_led locate_led'
22eda14cbcSMatt Macyelse
23eda14cbcSMatt Macy	scripts="$script"
24eda14cbcSMatt Macyfi
25eda14cbcSMatt Macy
26eda14cbcSMatt Macyfor i in $scripts ; do
27e92ffd9bSMartin Matuska	# shellcheck disable=SC2154
28eda14cbcSMatt Macy	if [ -z "$VDEV_ENC_SYSFS_PATH" ] ; then
29eda14cbcSMatt Macy		echo "$i="
30eda14cbcSMatt Macy		continue
31eda14cbcSMatt Macy	fi
32eda14cbcSMatt Macy
33eda14cbcSMatt Macy	val=""
34eda14cbcSMatt Macy	case $i in
35eda14cbcSMatt Macy	enc)
36*14c2e0a0SMartin Matuska		if echo "$VDEV_ENC_SYSFS_PATH" | grep -q '/sys/bus/pci/slots' ; then
37*14c2e0a0SMartin Matuska			val="$VDEV_ENC_SYSFS_PATH"
38*14c2e0a0SMartin Matuska		else
39*14c2e0a0SMartin Matuska			val="$(ls """$VDEV_ENC_SYSFS_PATH/../../""" 2>/dev/null)"
40*14c2e0a0SMartin Matuska		fi
41eda14cbcSMatt Macy		;;
42eda14cbcSMatt Macy	slot)
43*14c2e0a0SMartin Matuska		if echo "$VDEV_ENC_SYSFS_PATH" | grep -q '/sys/bus/pci/slots' ; then
44*14c2e0a0SMartin Matuska			val="$(basename """$VDEV_ENC_SYSFS_PATH""")"
45*14c2e0a0SMartin Matuska		else
46*14c2e0a0SMartin Matuska			val="$(cat """$VDEV_ENC_SYSFS_PATH/slot""" 2>/dev/null)"
47*14c2e0a0SMartin Matuska		fi
48eda14cbcSMatt Macy		;;
49eda14cbcSMatt Macy	encdev)
50eda14cbcSMatt Macy		val=$(ls "$VDEV_ENC_SYSFS_PATH/../device/scsi_generic" 2>/dev/null)
51eda14cbcSMatt Macy		;;
52eda14cbcSMatt Macy	fault_led)
5381b22a98SMartin Matuska		# JBODs fault LED is called 'fault', NVMe fault LED is called
5481b22a98SMartin Matuska		# 'attention'.
5581b22a98SMartin Matuska		if [ -f "$VDEV_ENC_SYSFS_PATH/fault" ] ; then
56eda14cbcSMatt Macy			val=$(cat "$VDEV_ENC_SYSFS_PATH/fault" 2>/dev/null)
5781b22a98SMartin Matuska		elif [ -f "$VDEV_ENC_SYSFS_PATH/attention" ] ; then
5881b22a98SMartin Matuska			val=$(cat "$VDEV_ENC_SYSFS_PATH/attention" 2>/dev/null)
5981b22a98SMartin Matuska		fi
60eda14cbcSMatt Macy		;;
61eda14cbcSMatt Macy	locate_led)
62eda14cbcSMatt Macy		val=$(cat "$VDEV_ENC_SYSFS_PATH/locate" 2>/dev/null)
63eda14cbcSMatt Macy		;;
64e92ffd9bSMartin Matuska	*)
65e92ffd9bSMartin Matuska		val=invalid
66e92ffd9bSMartin Matuska		;;
67eda14cbcSMatt Macy	esac
68eda14cbcSMatt Macy	echo "$i=$val"
69eda14cbcSMatt Macydone
70