]> git.proxmox.com Git - mirror_zfs-debian.git/commitdiff
Add [-m map] option to zpool_layout
authorBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 15 Sep 2010 22:32:27 +0000 (15:32 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 17 Sep 2010 18:02:19 +0000 (11:02 -0700)
By default the zpool_layout command would always use the slot
number assigned by Linux when generating the zdev.conf file.
This is a reasonable default there are cases when it makes
sense to remap the slot id assigned by Linux using your own
custom mapping.

This commit adds support to zpool_layout to provide a custom
slot mapping file.  The file contains in the first column the
Linux slot it and in the second column the custom slot mapping.
By passing this map file with '-m map' to zpool_config the
mapping will be applied when generating zdev.conf.

Additionally, two sample mapping have been added which reflect
different ways to map the slots in the dragon drawers.

cmd/zpool_layout/zpool_layout
configure
configure.ac
scripts/Makefile.am
scripts/Makefile.in
scripts/zpool-layout/Makefile.am [new file with mode: 0644]
scripts/zpool-layout/dragon.ddn.conf [new file with mode: 0644]
scripts/zpool-layout/dragon.llnl.conf [new file with mode: 0644]

index 19cd1280799e79001ad8a3f81520d99b5a5f6907..432c1576eebe7b3d4e0bf4476001d4adaec69d01 100755 (executable)
 # /etc/zfs/zdev.conf file, it allows the by-path naming convertion
 # to change and still keep the simple <channel><rank> naming.
 #
+AWK=${AWK:-/bin/awk}
 CONFIG=${CONFIG:-/etc/zfs/zdev.conf}
 BUSES=( 01 02 03 )
 PORTS=( 4 0 )
 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 )
-TRIGGER=
+TRIGGER="no"
+MAPPING=linux
+
 
 usage() {
        cat << EOF
-Usage: zpool_layout [-th] [-c file] [-b buses] [-p ports] [-n channels]
-  -c    Alternate config file [default=/etc/zfs/zdev.conf]
-  -b    Enumerate buses [default="01 02 03"]
-  -p    Enumerate ports [default="4 0"]
+Usage: zpool_layout [-th] [-c file] [-b buses] [-p ports] [-n channels] [-m map]
+  -c    Alternate config file [default=${CONFIG}]
+  -b    Enumerate buses [default="${BUSES[*]}"]
+  -p    Enumerate ports [default="${PORTS[*]}"]
   -n    Channel names [default="A..Z"]
-  -t    Trigger and wait for udev to settle [default=no]
+  -t    Trigger and wait for udev to settle [default=${TRIGGER}]
+  -m    Slot mapping [default=${MAPPING}]
   -h    Show this message
 EOF
        exit 0
 }
 
-while getopts 'c:b:p:n:th' OPTION; do
+while getopts 'c:b:p:n:m:th' OPTION; do
        case ${OPTION} in
        c)
                CONFIG=${OPTARG}
@@ -45,8 +49,11 @@ while getopts 'c:b:p:n:th' OPTION; do
        n)
                CHANNELS=(${OPTARG})
                ;;
+       m)
+               MAPPING=`readlink -e ${OPTARG}`
+               ;;
        t)
-               TRIGGER=1
+               TRIGGER=yes
                ;;
        h)
                usage
@@ -54,11 +61,31 @@ while getopts 'c:b:p:n:th' OPTION; do
        esac
 done
 
+# Verify mapping file exists if specified.
+# Linux-Slot   Custom-Slot
+if [ ${MAPPING} != "linux" ] && [ ! -e ${MAPPING} ]; then
+       echo "Error: Mapping file '${MAPPING}' does not exist"
+       exit 1
+fi
+
 # Save stdout as fd #8, then redirect stdout to the config file.
 exec 8>&1
 exec >${CONFIG}
 pushd /dev/disk/by-path >/dev/null
 
+map_slot() {
+       local LINUX_SLOT=$1
+       local MAPPED_SLOT=
+
+       if [ ${MAPPING} = "linux" ]; then
+               MAPPED_SLOT=${LINUX_SLOT}
+       else
+               MAPPED_SLOT=`${AWK} "\\$1 == ${LINUX_SLOT} && !/^#/ \
+                       { print \\$2; exit }" $MAPPING`
+       fi
+       printf "%d" ${MAPPED_SLOT}
+}
+
 # Generate comment header.
 echo "#"
 echo "# Custom /dev/disk/by-path to /dev/disk/zpool mapping, "
@@ -98,28 +125,34 @@ done
 echo "#"
 
 # Generate mapping from <channel><rank> to by-path name.
-TMP_FILE=`mktemp`
-AWK=${AWK:-/bin/awk}
-
 for (( i=0, k=0; i<${#BUSES[*]}; i++ )); do
        for (( j=0; j<${#PORTS[*]}; j++, k++ )); do
-               ls *:${BUSES[$i]}:*:${PORTS[$j]}*  2>/dev/null | \
-                       grep -v part | sort -n -k7 -t'-'>${TMP_FILE}
+               BYPATH=(`ls *:${BUSES[$i]}:*:${PORTS[$j]}* 2>/dev/null | \
+                       grep -v part | sort -n -k7 -t'-' | cut -f1-6 -d'-'`)
+               SLOTS=(`ls *:${BUSES[$i]}:*:${PORTS[$j]}* 2>/dev/null |  \
+                       grep -v part | sort -n -k7 -t'-' | cut -f7 -d'-'`)
+               TMP_FILE=`mktemp`
+
+               for (( l=0; l<${#SLOTS[*]}; l++ )); do
+                       MAPPED_SLOT=`map_slot ${SLOTS[$l]}`
+                       printf "%s%d\t%s-%d\n" \
+                               ${CHANNELS[$k]} ${MAPPED_SLOT} \
+                               ${BYPATH[$l]} ${SLOTS[$l]} >>${TMP_FILE}
+               done
 
                echo
                echo -n "# Channel ${CHANNELS[$k]}, "
                echo "Bus ${BUSES[$i]}, Port ${PORTS[$j]}"
-               ${AWK} -F '-' -v ch="${CHANNELS[$k]}" \
-                       '{print ch$7 "\t" $0 }' ${TMP_FILE}
+               cat ${TMP_FILE} | sort -n -k2 -t${CHANNELS[$k]}
+               rm -f ${TMP_FILE}
        done
 done
 
 # Restore stdout from fd #8 and close fd #8.
 exec 1>&8 8>&-
-rm -f ${TMP_FILE}
 popd >/dev/null
 
-if [ ${TRIGGER} ]; then
+if [ ${TRIGGER} = "yes" ]; then
        udevadm trigger
        udevadm settle
 fi
index f386dd8bd7c65809d3d90780ab119f3b164f2371..7bb25aba68a09ae4567eba271299037647182894 100755 (executable)
--- a/configure
+++ b/configure
@@ -17904,7 +17904,7 @@ fi
 $as_echo "$enable_debug" >&6; }
 
 
-ac_config_files="$ac_config_files Makefile etc/Makefile man/Makefile man/man8/Makefile lib/Makefile lib/libspl/Makefile lib/libspl/asm-generic/Makefile lib/libspl/asm-i386/Makefile lib/libspl/asm-x86_64/Makefile lib/libspl/include/Makefile lib/libspl/include/ia32/Makefile lib/libspl/include/ia32/sys/Makefile lib/libspl/include/rpc/Makefile lib/libspl/include/sys/Makefile lib/libspl/include/sys/sysevent/Makefile lib/libspl/include/sys/dktp/Makefile lib/libspl/include/util/Makefile lib/libavl/Makefile lib/libefi/Makefile lib/libnvpair/Makefile lib/libunicode/Makefile lib/libuutil/Makefile lib/libzpool/Makefile lib/libzfs/Makefile cmd/Makefile cmd/zdb/Makefile cmd/zfs/Makefile cmd/zinject/Makefile cmd/zpool/Makefile cmd/zpool_id/Makefile cmd/zpool_layout/Makefile cmd/ztest/Makefile cmd/zpios/Makefile module/Makefile module/avl/Makefile module/nvpair/Makefile module/unicode/Makefile module/zcommon/Makefile module/zfs/Makefile module/zpios/Makefile include/Makefile include/sys/Makefile include/sys/fs/Makefile include/sys/fm/Makefile include/sys/fm/fs/Makefile scripts/Makefile scripts/zpios-profile/Makefile scripts/zpios-test/Makefile scripts/zpool-config/Makefile scripts/common.sh zfs.spec zfs-modules.spec zfs-script-config.sh"
+ac_config_files="$ac_config_files Makefile etc/Makefile man/Makefile man/man8/Makefile lib/Makefile lib/libspl/Makefile lib/libspl/asm-generic/Makefile lib/libspl/asm-i386/Makefile lib/libspl/asm-x86_64/Makefile lib/libspl/include/Makefile lib/libspl/include/ia32/Makefile lib/libspl/include/ia32/sys/Makefile lib/libspl/include/rpc/Makefile lib/libspl/include/sys/Makefile lib/libspl/include/sys/sysevent/Makefile lib/libspl/include/sys/dktp/Makefile lib/libspl/include/util/Makefile lib/libavl/Makefile lib/libefi/Makefile lib/libnvpair/Makefile lib/libunicode/Makefile lib/libuutil/Makefile lib/libzpool/Makefile lib/libzfs/Makefile cmd/Makefile cmd/zdb/Makefile cmd/zfs/Makefile cmd/zinject/Makefile cmd/zpool/Makefile cmd/zpool_id/Makefile cmd/zpool_layout/Makefile cmd/ztest/Makefile cmd/zpios/Makefile module/Makefile module/avl/Makefile module/nvpair/Makefile module/unicode/Makefile module/zcommon/Makefile module/zfs/Makefile module/zpios/Makefile include/Makefile include/sys/Makefile include/sys/fs/Makefile include/sys/fm/Makefile include/sys/fm/fs/Makefile scripts/Makefile scripts/zpios-profile/Makefile scripts/zpios-test/Makefile scripts/zpool-config/Makefile scripts/zpool-layout/Makefile scripts/common.sh zfs.spec zfs-modules.spec zfs-script-config.sh"
 
 
 cat >confcache <<\_ACEOF
@@ -18869,6 +18869,7 @@ do
     "scripts/zpios-profile/Makefile") CONFIG_FILES="$CONFIG_FILES scripts/zpios-profile/Makefile" ;;
     "scripts/zpios-test/Makefile") CONFIG_FILES="$CONFIG_FILES scripts/zpios-test/Makefile" ;;
     "scripts/zpool-config/Makefile") CONFIG_FILES="$CONFIG_FILES scripts/zpool-config/Makefile" ;;
+    "scripts/zpool-layout/Makefile") CONFIG_FILES="$CONFIG_FILES scripts/zpool-layout/Makefile" ;;
     "scripts/common.sh") CONFIG_FILES="$CONFIG_FILES scripts/common.sh" ;;
     "zfs.spec") CONFIG_FILES="$CONFIG_FILES zfs.spec" ;;
     "zfs-modules.spec") CONFIG_FILES="$CONFIG_FILES zfs-modules.spec" ;;
index d42b0c9f55d1006dab2b496833021d5f17c35f74..593271061da9c705b16d4a274333164058038854 100644 (file)
@@ -103,6 +103,7 @@ AC_CONFIG_FILES([
        scripts/zpios-profile/Makefile
        scripts/zpios-test/Makefile
        scripts/zpool-config/Makefile
+       scripts/zpool-layout/Makefile
        scripts/common.sh
        zfs.spec
        zfs-modules.spec
index cc8c6960279750ab8ba82c6d341c3392c29d488f..4df4b277cb2afb53aa9270456e5f772a835724ef 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = zpool-config zpios-test zpios-profile
+SUBDIRS = zpool-config zpool-layout zpios-test zpios-profile
 
 pkglibexecdir = $(libexecdir)/@PACKAGE@
 dist_pkglibexec_SCRIPTS = \
index 3154ed7d7d1ab6c3a3f87e831dfe33e050ebbae1..cd9971b0ae86b54edb34edad5c670a047c206a17 100644 (file)
@@ -311,7 +311,7 @@ target_vendor = @target_vendor@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-SUBDIRS = zpool-config zpios-test zpios-profile
+SUBDIRS = zpool-config zpool-layout zpios-test zpios-profile
 dist_pkglibexec_SCRIPTS = \
        $(top_builddir)/scripts/common.sh \
        $(top_srcdir)/scripts/zconfig.sh \
diff --git a/scripts/zpool-layout/Makefile.am b/scripts/zpool-layout/Makefile.am
new file mode 100644 (file)
index 0000000..3eef241
--- /dev/null
@@ -0,0 +1,22 @@
+pkglibexecdir = $(libexecdir)/@PACKAGE@/zpool-layout
+dist_pkglibexec_SCRIPTS = \
+       $(top_srcdir)/scripts/zpool-layout/dragon.ddn.conf \
+       $(top_srcdir)/scripts/zpool-layout/dragon.llnl.conf
+
+all:
+       @list='$(dist_pkglibexec_SCRIPTS)'; \
+       for file in $$list; do \
+               link=$$(basename $$file); \
+               if [ ! -e $$link ]; then \
+                       $(LN_S) $$file $$link; \
+               fi \
+       done
+
+clean:
+       @list='$(dist_pkglibexec_SCRIPTS)'; \
+       for file in $$list; do \
+               link=$$(basename $$file); \
+               if [ -L $$link ]; then \
+                       $(RM) $$link; \
+               fi \
+       done
diff --git a/scripts/zpool-layout/dragon.ddn.conf b/scripts/zpool-layout/dragon.ddn.conf
new file mode 100644 (file)
index 0000000..c797b4d
--- /dev/null
@@ -0,0 +1,67 @@
+#
+# Custom DDN slot mapping for zpool_layout command and
+# StorageScaler 6000 enclosures (Dragon Drawer).
+#
+# Linux        DDN
+# Slot Slot
+#
+1      1
+2      13
+3      25
+4      37
+5      49
+6      2
+7      14
+8      26
+9      38
+10     50
+11     3
+12     15
+13     27
+14     39
+15     51
+16     4
+17     16
+18     28
+19     40
+20     52
+21     5
+22     17
+23     29
+24     41
+25     53
+26     6
+27     18
+28     30
+29     42
+30     54
+31     7
+32     19
+33     31
+34     43
+35     55
+36     8
+37     20
+38     32
+39     44
+40     56
+41     9
+42     21
+43     33
+44     45
+45     57
+46     10
+47     22
+48     34
+49     46
+50     58
+51     11
+52     23
+53     35
+54     47
+55     59
+56     12
+57     24
+58     36
+59     48
+60     60
diff --git a/scripts/zpool-layout/dragon.llnl.conf b/scripts/zpool-layout/dragon.llnl.conf
new file mode 100644 (file)
index 0000000..0c684c7
--- /dev/null
@@ -0,0 +1,67 @@
+#
+# Custom LLNL slot mapping for zpool_layout command and
+# StorageScaler 6000 enclosures (Dragon Drawer).
+#
+# Linux        LLNL
+# Slot Slot
+#
+1      25
+2      19
+3      13
+4      7
+5      1
+6      26
+7      20
+8      14
+9      8
+10     2
+11     27
+12     21
+13     15
+14     9
+15     3
+16     28
+17     22
+18     16
+19     10
+20     4
+21     29
+22     23
+23     17
+24     11
+25     5
+26     30
+27     24
+28     18
+29     12
+30     6
+31     60
+32     54
+33     48
+34     42
+35     36
+36     59
+37     53
+38     47
+39     41
+40     35
+41     58
+42     52
+43     46
+44     40
+45     34
+46     57
+47     51
+48     45
+49     39
+50     33
+51     56
+52     50
+53     44
+54     38
+55     32
+56     55
+57     49
+58     43
+59     37
+60     31