xref: /freebsd/sys/contrib/openzfs/cmd/zpool/zpool.d/ses (revision dae1713419a669d4f6c7acddf81a21297c809741)
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
14*dae17134SMartin 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
27eda14cbcSMatt Macy	if [ -z "$VDEV_ENC_SYSFS_PATH" ] ; then
28eda14cbcSMatt Macy		echo "$i="
29eda14cbcSMatt Macy		continue
30eda14cbcSMatt Macy	fi
31eda14cbcSMatt Macy
32eda14cbcSMatt Macy	val=""
33eda14cbcSMatt Macy	case $i in
34eda14cbcSMatt Macy	enc)
35eda14cbcSMatt Macy		val=$(ls "$VDEV_ENC_SYSFS_PATH/../../" 2>/dev/null)
36eda14cbcSMatt Macy		;;
37eda14cbcSMatt Macy	slot)
38eda14cbcSMatt Macy		val=$(cat "$VDEV_ENC_SYSFS_PATH/slot" 2>/dev/null)
39eda14cbcSMatt Macy		;;
40eda14cbcSMatt Macy	encdev)
41eda14cbcSMatt Macy		val=$(ls "$VDEV_ENC_SYSFS_PATH/../device/scsi_generic" 2>/dev/null)
42eda14cbcSMatt Macy		;;
43eda14cbcSMatt Macy	fault_led)
4481b22a98SMartin Matuska		# JBODs fault LED is called 'fault', NVMe fault LED is called
4581b22a98SMartin Matuska		# 'attention'.
4681b22a98SMartin Matuska		if [ -f "$VDEV_ENC_SYSFS_PATH/fault" ] ; then
47eda14cbcSMatt Macy			val=$(cat "$VDEV_ENC_SYSFS_PATH/fault" 2>/dev/null)
4881b22a98SMartin Matuska		elif [ -f "$VDEV_ENC_SYSFS_PATH/attention" ] ; then
4981b22a98SMartin Matuska			val=$(cat "$VDEV_ENC_SYSFS_PATH/attention" 2>/dev/null)
5081b22a98SMartin Matuska		fi
51eda14cbcSMatt Macy		;;
52eda14cbcSMatt Macy	locate_led)
53eda14cbcSMatt Macy		val=$(cat "$VDEV_ENC_SYSFS_PATH/locate" 2>/dev/null)
54eda14cbcSMatt Macy		;;
55eda14cbcSMatt Macy	esac
56eda14cbcSMatt Macy	echo "$i=$val"
57eda14cbcSMatt Macydone
58eda14cbcSMatt Macy
59