xref: /freebsd/sys/contrib/openzfs/cmd/zpool/zpool.d/ses (revision e92ffd9b626833ebdbf2742c8ffddc6cd94b963e)
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
27*e92ffd9bSMartin 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)
36eda14cbcSMatt Macy		val=$(ls "$VDEV_ENC_SYSFS_PATH/../../" 2>/dev/null)
37eda14cbcSMatt Macy		;;
38eda14cbcSMatt Macy	slot)
39eda14cbcSMatt Macy		val=$(cat "$VDEV_ENC_SYSFS_PATH/slot" 2>/dev/null)
40eda14cbcSMatt Macy		;;
41eda14cbcSMatt Macy	encdev)
42eda14cbcSMatt Macy		val=$(ls "$VDEV_ENC_SYSFS_PATH/../device/scsi_generic" 2>/dev/null)
43eda14cbcSMatt Macy		;;
44eda14cbcSMatt Macy	fault_led)
4581b22a98SMartin Matuska		# JBODs fault LED is called 'fault', NVMe fault LED is called
4681b22a98SMartin Matuska		# 'attention'.
4781b22a98SMartin Matuska		if [ -f "$VDEV_ENC_SYSFS_PATH/fault" ] ; then
48eda14cbcSMatt Macy			val=$(cat "$VDEV_ENC_SYSFS_PATH/fault" 2>/dev/null)
4981b22a98SMartin Matuska		elif [ -f "$VDEV_ENC_SYSFS_PATH/attention" ] ; then
5081b22a98SMartin Matuska			val=$(cat "$VDEV_ENC_SYSFS_PATH/attention" 2>/dev/null)
5181b22a98SMartin Matuska		fi
52eda14cbcSMatt Macy		;;
53eda14cbcSMatt Macy	locate_led)
54eda14cbcSMatt Macy		val=$(cat "$VDEV_ENC_SYSFS_PATH/locate" 2>/dev/null)
55eda14cbcSMatt Macy		;;
56*e92ffd9bSMartin Matuska	*)
57*e92ffd9bSMartin Matuska		val=invalid
58*e92ffd9bSMartin Matuska		;;
59eda14cbcSMatt Macy	esac
60eda14cbcSMatt Macy	echo "$i=$val"
61eda14cbcSMatt Macydone
62