3 # Set BUSES and PORTS to match the topology of your system. As each
4 # port is enumerated it will be assigned the next channel name. The
5 # current script enumerates each port on a bus before moving on to
6 # enumerate the next bus.
8 # Every distribution, version of udev, and type of attached storage
9 # seems to result in slightly different formatting of the by-path
10 # name. For this reason you may need to adjust the parsing below
11 # to suit your needs. This is one of the reasons to use a custom
12 # /etc/zfs/zdev.conf file, it allows the by-path naming convertion
13 # to change and still keep the simple <channel><rank> naming.
15 CONFIG=${CONFIG:-/etc/zfs/zdev.conf}
18 CHANNELS=( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z )
23 Usage: zpool_layout [-th] [-c file] [-b buses] [-p ports] [-n channels]
24 -c Alternate config file [default=/etc/zfs/zdev.conf]
25 -b Enumerate buses [default="01 02 03"]
26 -p Enumerate ports [default="4 0"]
27 -n Channel names [default="A..Z"]
28 -t Trigger and wait for udev to settle [default=no]
34 while getopts 'c:b:p:n:th' OPTION; do
57 # Save stdout as fd #8, then redirect stdout to the config file.
60 pushd /dev/disk/by-path >/dev/null
62 # Generate comment header.
64 echo "# Custom /dev/disk/by-path to /dev/disk/zpool mapping, "
65 echo "# based of the following physical cable layout."
68 # Generate host port layout table for comment header.
69 echo "# ------------------ Host Port Layout ---------------------"
71 for (( i=0; i<${#BUSES[*]}; i++ )); do
72 printf "%-8d" ${BUSES[$i]}
76 for (( i=0, k=0; i<${#PORTS[*]}; i++ )); do
77 printf "# Port %-2d " ${PORTS[$i]}
79 for (( j=0; j<${#BUSES[*]}; j++, k++ )); do
80 let k=$j*${#PORTS[*]}+$i
81 printf "%-8s" ${CHANNELS[$k]}
87 # Generate channel/disk layout table for comment header.
88 echo "# ----------------- Channel/Disk Layout -------------------"
89 echo "# Channel Disks"
90 for (( i=0, k=0; i<${#BUSES[*]}; i++ )); do
91 for (( j=0; j<${#PORTS[*]}; j++, k++ )); do
92 printf "# %-9s" ${CHANNELS[$k]}
93 ls *:${BUSES[$i]}:*:${PORTS[$j]}* 2>/dev/null | \
94 cut -f7 -d'-' | sort -u -n | tr '\n' ','
100 # Generate mapping from <channel><rank> to by-path name.
104 for (( i=0, k=0; i<${#BUSES[*]}; i++ )); do
105 for (( j=0; j<${#PORTS[*]}; j++, k++ )); do
106 ls *:${BUSES[$i]}:*:${PORTS[$j]}* 2>/dev/null | \
107 grep -v part | sort -n -k7 -t'-'>${TMP_FILE}
110 echo -n "# Channel ${CHANNELS[$k]}, "
111 echo "Bus ${BUSES[$i]}, Port ${PORTS[$j]}"
112 ${AWK} -F '-' -v ch="${CHANNELS[$k]}" \
113 '{print ch$7 "\t" $0 }' ${TMP_FILE}
117 # Restore stdout from fd #8 and close fd #8.
122 if [ ${TRIGGER} ]; then