xref: /freebsd/sys/contrib/openzfs/cmd/zpool/zpool.d/dm-deps (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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
12# shellcheck disable=SC2154
13dev="$VDEV_PATH"
14
15# If the VDEV path is a symlink, resolve it to a real device
16if [ -L "$dev" ] ; then
17	dev=$(readlink "$dev")
18fi
19
20dev="${dev##*/}"
21val=""
22if [ -d "/sys/class/block/$dev/slaves" ] ; then
23	# ls -C: output in columns, no newlines, two spaces (change to one)
24	# shellcheck disable=SC2012
25	val=$(ls -C "/sys/class/block/$dev/slaves" | tr -s '[:space:]' ' ')
26fi
27
28echo "dm-deps=$val"
29