diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100755 index 0000000000..d7c8f0941b --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,140 @@ +#!/bin/bash +# +# A simple script to simply the loading/unloading the ZFS module +# stack. It should probably be considered a first step towards +# a full ZFS init script when that is needed. +# + +. ../.script-config +PROG="" + +VERBOSE= +DUMP_LOG= +ERROR= +MODULES=() + +die() { + echo -e "${PROG}: $1" >&2 + exit 1 +} + +msg() { + if [ ${VERBOSE} ]; then + echo "$@" + fi +} + +spl_dump_log() { + sysctl -w kernel.spl.debug.dump=1 &>/dev/null + local NAME=`dmesg | tail -n 1 | cut -f5 -d' '` + ${SPLBUILD}/cmd/spl ${NAME} >${NAME}.log + echo + echo "Dumped debug log: ${NAME}.log" + tail -n1 ${NAME}.log + echo + return 0 +} + +check_modules() { + local LOADED_MODULES=() + local MISSING_MODULES=() + + for MOD in ${MODULES[*]}; do + local NAME=`basename $MOD .ko` + + if /sbin/lsmod | egrep -q "^${NAME}"; then + LOADED_MODULES=(${NAME} ${LOADED_MODULES[*]}) + fi + + if [ ! -f ${MOD} ]; then + MISSING_MODULES=("\t${MOD}\n" ${MISSING_MODULES[*]}) + fi + done + + if [ ${#LOADED_MODULES[*]} -gt 0 ]; then + ERROR="Unload these modules with '${PROG} -u':\n" + ERROR="${ERROR}${LOADED_MODULES[*]}" + return 1 + fi + + if [ ${#MISSING_MODULES[*]} -gt 0 ]; then + ERROR="The following modules can not be found," + ERROR="${ERROR} ensure your source trees are built:\n" + ERROR="${ERROR}${MISSING_MODULES[*]}" + return 1 + fi + + return 0 +} + +load_module() { + local NAME=`basename $1 .ko` + + if [ ${VERBOSE} ]; then + echo "Loading $NAME ($@)" + fi + + /sbin/insmod $* || ERROR="Failed to load $1" return 1 + + return 0 +} + +load_modules() { + + for MOD in ${MODULES[*]}; do + local NAME=`basename ${MOD} .ko` + local VALUE= + + for OPT in "$@"; do + OPT_NAME=`echo ${OPT} | cut -f1 -d'='` + + if [ ${NAME} = "${OPT_NAME}" ]; then + VALUE=`echo ${OPT} | cut -f2- -d'='` + fi + done + + load_module ${MOD} ${VALUE} || return 1 + done + + if [ ${VERBOSE} ]; then + echo "Successfully loaded ZFS module stack" + fi + + return 0 +} + +unload_module() { + local NAME=`basename $1 .ko` + + if [ ${VERBOSE} ]; then + echo "Unloading $NAME ($@)" + fi + + /sbin/rmmod $NAME || ERROR="Failed to unload $NAME" return 1 + + return 0 +} + +unload_modules() { + local MODULES_REVERSE=( $(echo ${MODULES[@]} | + awk '{for (i=NF;i>=1;i--) printf $i" "} END{print ""}') ) + + for MOD in ${MODULES_REVERSE[*]}; do + local NAME=`basename ${MOD} .ko` + + if /sbin/lsmod | egrep -q "^${NAME}"; then + + if [ "${DUMP_LOG}" -a ${NAME} = "spl" ]; then + spl_dump_log + fi + + unload_module ${MOD} || return 1 + fi + done + + if [ ${VERBOSE} ]; then + echo "Successfully unloaded ZFS module stack" + fi + + return 0 +} diff --git a/scripts/update-zfs.sh b/scripts/zfs-update.sh similarity index 100% rename from scripts/update-zfs.sh rename to scripts/zfs-update.sh diff --git a/scripts/zfs.sh b/scripts/zfs.sh index d1457c84ca..35c29b67df 100755 --- a/scripts/zfs.sh +++ b/scripts/zfs.sh @@ -5,19 +5,19 @@ # a full ZFS init script when that is needed. # -prog=zfs.sh -. ../.script-config +. ./common.sh +PROG=zfs.sh KMOD=/lib/modules/${KERNELSRCVER}/kernel -kernel_modules=( \ +KERNEL_MODULES=( \ $KMOD/lib/zlib_deflate/zlib_deflate.ko \ ) -spl_modules=( \ +SPL_MODULES=( \ ${SPLBUILD}/module/spl/spl.ko \ ) -zfs_modules=( \ +ZFS_MODULES=( \ ${MODDIR}/avl/zavl.ko \ ${MODDIR}/nvpair/znvpair.ko \ ${MODDIR}/unicode/zunicode.ko \ @@ -25,22 +25,12 @@ zfs_modules=( \ ${MODDIR}/zfs/zfs.ko \ ) -test_modules=( \ - ${MODDIR}/zpios/zpios.ko \ +MODULES=( \ + ${KERNEL_MODULES[*]} \ + ${SPL_MODULES[*]} \ + ${ZFS_MODULES[*]} \ ) -modules=( \ - ${kernel_modules[*]} \ - ${spl_modules[*]} \ - ${zfs_modules[*]} \ - ${test_modules[*]} \ -) - -die() { - echo -e "${prog}: $1" >&2 - exit 1 -} - usage() { cat << EOF USAGE: @@ -56,7 +46,7 @@ OPTIONS: -d Save debug log on unload MODULE-OPTIONS: - Must be of the frm module="options", for example: + Must be of the from module="options", for example: $0 zfs="zfs_prefetch_disable=1" $0 zfs="zfs_prefetch_disable=1 zfs_mdcomp_disable=1" @@ -65,115 +55,7 @@ $0 spl="spl_debug_mask=0" EOF } -check_modules() { - loaded_modules=() - missing_modules=() - - for module in ${modules[*]}; do - name=`basename $module .ko` - - if /sbin/lsmod | egrep -q "^${name}"; then - loaded_modules=(${name} ${loaded_modules[*]}) - fi - - if [ ! -f $module ]; then - missing_modules=("\t${module}\n" ${missing_modules[*]}) - fi - done - - if [ ${#loaded_modules[*]} -gt 0 ]; then - error="The following modules must be unloaded, manually run:\n" - die "${error}'/sbin/rmmod ${loaded_modules[*]}'" - fi - - if [ ${#missing_modules[*]} -gt 0 ]; then - error="The following modules can not be found," - error="${error} ensure your source trees are built:\n" - die "${error}${missing_modules[*]}" - fi -} - -spl_dump_log() { - sysctl -w kernel.spl.debug.dump=1 &>/dev/null - name=`dmesg | tail -n 1 | cut -f5 -d' '` - ${SPLBUILD}/cmd/spl ${name} >${name}.log - echo - echo "Dumped debug log: ${name}.log" - tail -n1 ${name}.log - echo -} - -load_module() { - name=`basename $module .ko` - - if [ ${verbose} ]; then - echo "Loading $name ($@)" - fi - - /sbin/insmod $* || die "Failed to load $1" -} - -load_modules() { - - for module in ${modules[*]}; do - name=`basename $module .ko` - value= - - for opt in "$@"; do - opt_name=`echo $opt | cut -f1 -d'='` - - if [ ${name} = "${opt_name}" ]; then - value=`echo $opt | cut -f2- -d'='` - fi - done - - load_module ${module} ${value} - done - - if [ ${verbose} ]; then - echo "Successfully loaded ZFS module stack" - fi -} - -unload_module() { - name=`basename $module .ko` - - if [ ${verbose} ]; then - echo "Unloading $name ($@)" - fi - - /sbin/rmmod $name || die "Failed to unload $name" -} - -unload_modules() { - modules_reverse=( $(echo ${modules[@]} | - awk '{for (i=NF;i>=1;i--) printf $i" "} END{print ""}') ) - - for module in ${modules_reverse[*]}; do - name=`basename $module .ko` - - if /sbin/lsmod | egrep -q "^${name}"; then - - if [ "${dump_log}" -a ${name} = "spl" ]; then - spl_dump_log - fi - - unload_module ${module} - fi - done - - if [ ${verbose} ]; then - echo "Successfully unloaded ZFS module stack" - fi -} - -if [ $(id -u) != 0 ]; then - die "Must run as root" -fi - -verbose= -unload= -dump_log= +UNLOAD= while getopts 'hvud' OPTION; do case $OPTION in @@ -182,13 +64,13 @@ while getopts 'hvud' OPTION; do exit 1 ;; v) - verbose=1 + VERBOSE=1 ;; u) - unload=1 + UNLOAD=1 ;; d) - dump_log=1 + DUMP_LOG=1 ;; ?) usage @@ -197,10 +79,14 @@ while getopts 'hvud' OPTION; do esac done -if [ ${unload} ]; then +if [ $(id -u) != 0 ]; then + die "Must run as root" +fi + +if [ ${UNLOAD} ]; then unload_modules else - check_modules + check_modules || die "${ERROR}" load_modules "$@" fi diff --git a/scripts/zpool-config/lo-raid0.cfg b/scripts/zpool-config/lo-raid0.cfg new file mode 100644 index 0000000000..99695f12e0 --- /dev/null +++ b/scripts/zpool-config/lo-raid0.cfg @@ -0,0 +1,2 @@ +#echo "${CMDDIR}/zpool/zpool create -f lustre ${DEVICES}" +#${CMDDIR}/zpool/zpool create -f lustre ${DEVICES} || exit 1 diff --git a/scripts/create-zpool.sh b/scripts/zpool-create.sh similarity index 96% rename from scripts/create-zpool.sh rename to scripts/zpool-create.sh index 3728c1fa1f..b22707557e 100755 --- a/scripts/create-zpool.sh +++ b/scripts/zpool-create.sh @@ -1,7 +1,7 @@ #!/bin/bash -prog=create-zpool.sh -. ../.script-config +. ./common.sh +PROG=create-zpool.sh # Device list, e.g. #