xref: /freebsd/sys/contrib/openzfs/cmd/zpool/zpool.d/dm-deps (revision cc68614da8232d8baaca0ae0d0dd8f890f06623e)
1#!/bin/sh
2#
3# Show device mapper dependent / underlying devices.  This is useful for
4# looking up the /dev/sd* devices associated with a dm or multipath device.
5#
6
7if [ "$1" = "-h" ] ; then
8	echo "Show device mapper dependent (underlying) devices."
9	exit
10fi
11
12dev="$VDEV_PATH"
13
14# If the VDEV path is a symlink, resolve it to a real device
15if [ -L "$dev" ] ; then
16	dev=$(readlink "$dev")
17fi
18
19dev="${dev##*/}"
20val=""
21if [ -d "/sys/class/block/$dev/slaves" ] ; then
22	# ls -C: output in columns, no newlines, two spaces (change to one)
23	# shellcheck disable=SC2012
24	val=$(ls -C "/sys/class/block/$dev/slaves" | tr -s '[:space:]' ' ')
25fi
26
27echo "dm-deps=$val"
28