# Load a module on the system where this is running.
#
-# Synopsis: load_module module_name [module arguments for insmod/modprobe]
+# usage: load_module module_name [module arguments for insmod/modprobe]
#
# If module arguments are not given but MODOPTS_<MODULE> is set, then its value
# will be used as the arguments. Otherwise arguments will be obtained from
[ $# -gt 0 ] && echo "${module} options: '$*'"
- # Note that insmod will ignore anything in modprobe.conf, which is why we're
- # passing options on the command-line.
- if [ "$BASE" == "lnet_selftest" ] && \
- [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
- insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
- elif [ -f ${LUSTRE}/${module}${EXT} ]; then
- insmod ${LUSTRE}/${module}${EXT} "$@"
- else
- # must be testing a "make install" or "rpm" installation
- # note failed to load ptlrpc_gss is considered not fatal
- if [ "$BASE" == "ptlrpc_gss" ]; then
- modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
- else
- modprobe $BASE "$@"
- fi
- fi
+ # Note that insmod will ignore anything in modprobe.conf, which is why
+ # we're passing options on the command-line.
+ if [[ "$BASE" == "lnet_selftest" ]] &&
+ [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
+ insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
+ elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
+ [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
+ insmod ${LUSTRE}/${module}${EXT} "$@"
+ else
+ # must be testing a "make install" or "rpm" installation
+ # note failed to load ptlrpc_gss is considered not fatal
+ if [[ "$BASE" == "ptlrpc_gss" ]]; then
+ modprobe $BASE "$@" 2>/dev/null ||
+ echo "gss/krb5 is not supported"
+ else
+ modprobe $BASE "$@"
+ fi
+ fi
}
llite_lloop_enabled() {
load_module ../ldiskfs/ldiskfs
load_module osd-ldiskfs/osd_ldiskfs
fi
- load_module nodemap/nodemap
load_module mgs/mgs
load_module mdd/mdd
load_module mdt/mdt
$LCTL modules > $OGDB/ogdb-$HOSTNAME
# 'mount' doesn't look in $PATH, just sbin
- local MOUNT_LUSTRE=$LUSTRE/utils/mount.lustre
- if [ -f $MOUNT_LUSTRE ]; then
- if grep -qe "/sbin/mount\.lustre " /proc/mounts; then
- cmp $MOUNT_LUSTRE /sbin/mount.lustre ||
- umount /sbin/mount.lustre
+ local mount_lustre=$LUSTRE/utils/mount.lustre
+ if [ -f $mount_lustre ]; then
+ local sbin_mount=/sbin/mount.lustre
+ if grep -qw "$sbin_mount" /proc/mounts; then
+ cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
fi
- if ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
- [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
- mount --bind $MOUNT_LUSTRE /sbin/mount.lustre
+ if ! grep -qw "$sbin_mount" /proc/mounts; then
+ [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
+ if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
+ cat <<- EOF > "$sbin_mount"
+ #!/bin/sh
+ #STUB MARK
+ echo "This $sbin_mount just a mountpoint." 1>&2
+ echo "It is never supposed to be run." 1>&2
+ logger -p emerg -- "using stub $sbin_mount $@"
+ exit 1
+ EOF
+ chmod a+x $sbin_mount
+ fi
+ mount --bind $mount_lustre $sbin_mount ||
+ error "can't bind $mount_lustre to $sbin_mount"
fi
fi
}
fi
fi
- if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
- umount /sbin/mount.lustre || true
- [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
- rm -f /sbin/mount.lustre || true
- fi
+ local sbin_mount=/sbin/mount.lustre
+ if grep -qe "$sbin_mount " /proc/mounts; then
+ umount $sbin_mount || true
+ [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
+ rm -f $sbin_mount
+ fi
- check_mem_leak || return 254
+ check_mem_leak || return 254
- echo "modules unloaded."
- return 0
+ echo "modules unloaded."
+ return 0
}
fs_log_size() {
echo -n $fstypes
}
+facet_index() {
+ local facet=$1
+ local num=$(facet_number $facet)
+ local index
+
+ if [[ $(facet_type $facet) = OST ]]; then
+ index=OSTINDEX${num}
+ if [[ -n "${!index}" ]]; then
+ echo -n ${!index}
+ return
+ fi
+
+ index=${OST_INDICES[num - 1]}
+ fi
+
+ [[ -n "$index" ]] || index=$((num - 1))
+ echo -n $index
+}
+
devicelabel() {
local facet=$1
local dev=$2
else
set_default_debug_facet $facet
+ if [[ $facet == mds* ]]; then
+ do_facet $facet \
+ lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
+ 2>/dev/null
+ fi
+
label=$(devicelabel ${facet} ${!dev})
[ -z "$label" ] && echo no label for ${!dev} && exit 1
eval export ${facet}_svc=${label}
wait_delete_completed_mds() {
local MAX_WAIT=${1:-20}
+ # for ZFS, waiting more time for DMUs to be committed
+ local ZFS_WAIT=${2:-5}
local mds2sync=""
local stime=$(date +%s)
local etime
if [[ $changes -eq 0 ]]; then
etime=$(date +%s)
#echo "delete took $((etime - stime)) seconds"
+
+ # the occupied disk space will be released
+ # only after DMUs are committed
+ if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
+ echo "sleep $ZFS_WAIT for ZFS OSD"
+ sleep $ZFS_WAIT
+ fi
+
return
fi
sleep 1
done
myList="${myList%* }";
- # We can select an object at a offset in the list
+ # We can select an object at an offset in the list
[ $# -eq 2 ] && {
cnt=0
for item in $myList; do
local facet
for var in ${!MODOPTS_*}; do
- value=${!var}
+ value=${!var//\"/\\\"}
echo -n " ${var}=\"$value\""
done
eval VDEVPTR="";;
zfs )
#if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
- # Device formated by zfs
+ # Device formatted by zfs
DEVNAME=OSTDEV$num
eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
* )
echo -n $VDEVPTR
}
-# Logical device formated for lustre
+# Logical device formatted for lustre
mdsdevname() {
local num=$1
local DEVNAME=MDSDEV$num
eval VDEVPTR="";;
zfs )
# if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
- # Device formated by ZFS
+ # Device formatted by ZFS
local DEVNAME=MDSDEV$num
eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
* )
local dev=$2
local fsname=${3:-"$FSNAME"}
local type=$(facet_type $facet)
- local index=$(($(facet_number $facet) - 1))
+ local index=$(facet_index $facet)
local fstype=$(facet_fstype $facet)
local host=$(facet_host $facet)
local opts
local fs_mkfs_opts
local var
- if [ $type == MGS ] && combined_mgs_mds; then
- return 1
- fi
-
if [ $type == MGS ] || ( [ $type == MDS ] &&
[ "$dev" == $(mgsdevname) ] &&
[ "$host" == "$(facet_host mgs)" ] ); then
echo -n "$opts"
}
+check_ost_indices() {
+ local index_count=${#OST_INDICES[@]}
+ [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
+
+ # OST count is greater than the index count in $OST_INDEX_LIST.
+ # We need check whether there are duplicate indices.
+ local i
+ local j
+ local index
+ for i in $(seq $((index_count + 1)) $OSTCOUNT); do
+ index=$(facet_index ost$i)
+ for j in $(seq 0 $((index_count - 1))); do
+ [[ $index -ne ${OST_INDICES[j]} ]] ||
+ error "ost$i has the same index $index as ost$((j+1))"
+ done
+ done
+}
+
formatall() {
local quiet
${quiet:+>/dev/null} || exit 10
done
+ export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
+ check_ost_indices
for num in $(seq $OSTCOUNT); do
echo "Format ost$num: $(ostdevname $num)"
add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
return $rc
}
+dump_file_contents() {
+ local nodes=$1
+ local dir=$2
+ local logname=$3
+ local node
+
+ if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
+ error_noexit false \
+ "Invalid parameters for dump_file_contents()"
+ return 1
+ fi
+ for node in ${nodes}; do
+ do_node $node "for i in \\\$(find $dir -type f); do
+ echo ====\\\${i}=======================;
+ cat \\\${i};
+ done" >> ${logname}.${node}.log
+ done
+}
+
+dump_command_output() {
+ local nodes=$1
+ local cmd=$2
+ local logname=$3
+ local node
+
+ if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
+ error_noexit false \
+ "Invalid parameters for dump_command_output()"
+ return 1
+ fi
+
+ for node in ${nodes}; do
+ do_node $node "echo ====${cmd}=======================;
+ $cmd" >> ${logname}.${node}.log
+ done
+}
+
+log_zfs_info() {
+ local logname=$1
+
+ # dump file contents from /proc/spl in case of zfs test
+ if [ "$(facet_fstype ost1)" = "zfs" ]; then
+ dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
+ dump_command_output \
+ "$(osts_nodes)" "zpool events -v" "${logname}"
+ fi
+
+ if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
+ dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
+ dump_command_output \
+ "$(mdts_nodes)" "zpool events -v" "${logname}"
+ fi
+}
+
check_and_cleanup_lustre() {
if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
get_svr_devs
cleanupall -f || error "cleanup failed"
unset I_MOUNTED
fi
-
- if grep -qe "/sbin/mount\.lustre " /proc/mounts; then
- umount /sbin/mount.lustre
- fi
}
#######
}
drop_bl_callback_once() {
- rc=0
+ local rc=0
do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
#define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
do_facet client lctl set_param fail_loc=0x80000305
do_facet client "$@" || rc=$?
do_facet client lctl set_param fail_loc=0
+ do_facet client lctl set_param fail_val=0
do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
return $rc
}
do_facet client lctl set_param fail_loc=0x305
do_facet client "$@" || rc=$?
do_facet client lctl set_param fail_loc=0
+ do_facet client lctl set_param fail_val=0
do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
return $rc
}
}
# prints bash call stack
-log_trace_dump() {
+print_stack_trace() {
echo " Trace dump:"
for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
local s=${BASH_SOURCE[$i]}
log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
- log_trace_dump
+ print_stack_trace >&2
mkdir -p $LOGDIR
# We need to dump the logs on all nodes
}
log() {
- echo "$*"
+ echo "$*" >&2
module_loaded lnet || load_modules
local MSG="$*"
local TEST_ERROR
local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
local test_log=$LOGDIR/$name
+ local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
+ local zfs_debug_log=$LOGDIR/$zfs_log_name
rm -rf $LOGDIR/err
rm -rf $LOGDIR/ignore
rm -rf $LOGDIR/skip
fi
if [ -f $LOGDIR/err ]; then
+ log_zfs_info "$zfs_debug_log"
$FAIL_ON_ERROR && exit $RC
fi
}
check_catastrophe() {
- local rnodes=${1:-$(comma_list $(remote_nodes_list))}
- VAR=$(lctl get_param -n catastrophe 2>&1)
- if [ $? = 0 ] ; then
- if [ $VAR != 0 ]; then
- return 1
- fi
- fi
-
- [ -z "$rnodes" ] && return 0
-
- local data
- data=$(do_nodes "$rnodes" "rc=\\\$(lctl get_param -n catastrophe);
- if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
- exit \\\$rc")
- local rc=$?
- if [ -n "$data" ]; then
- echo $data
- return $rc
- fi
- return 0
-}
+ local nodes=${1:-$(comma_list $(nodes_list))}
-# CMD: determine mds index where directory inode presents
-get_mds_dir () {
- local dir=$1
- local file=$dir/f0.get_mds_dir_tmpfile
-
- mkdir -p $dir
- rm -f $file
- sleep 1
- local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
- local -a oldused=($iused)
-
- openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
- sleep 1
- iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
- local -a newused=($iused)
-
- local num=0
- for ((i=0; i<${#newused[@]}; i++)); do
- if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
- echo $(( i + 1 ))
- rm -f $file
- return 0
- fi
- done
- error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
+ do_nodes $nodes "rc=0;
+val=\\\$($LCTL get_param -n catastrophe 2>&1);
+if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
+ echo \\\$(hostname -s): \\\$val;
+ rc=\\\$val;
+fi;
+exit \\\$rc"
}
mdsrate_cleanup () {
return $rc
}
-# target_start_and_reset_recovery_timer()
-# service_time = at_est2timeout(service_time);
-# service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
-# INITIAL_CONNECT_TIMEOUT);
-# CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
-#define CONNECTION_SWITCH_INC 1
-#define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
-#define CONNECTION_SWITCH_MIN 5U
+# check_and_start_recovery_timer()
+# service_time = at_est2timeout(service_time);
+# service_time += 2 * INITIAL_CONNECT_TIMEOUT;
+# service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
-max_recovery_time () {
- local init_connect_timeout=$(( TIMEOUT / 20 ))
- [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
+#define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
+#define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
+#define CONNECTION_SWITCH_MIN 5
+#define CONNECTION_SWITCH_INC 5
+max_recovery_time() {
+ local init_connect_timeout=$((TIMEOUT / 20))
+ ((init_connect_timeout >= 5)) || init_connect_timeout=5
- local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
+ local service_time=$(($(at_max_get client) * 9 / 4 + 5))
+ service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
- echo $service_time
+ echo -n $service_time
}
get_clients_mount_count () {
# make directory on different MDTs
test_mkdir() {
- local option
- local parent
- local child
local path
local p_option
- local option2
local stripe_count=2
- local rc=0
-
- case $# in
- 1) path=$1;;
- 2) option=$1
- path=$2;;
- 3) option=$1
- option2=$2
- path=$3;;
- *) error "Only creating single directory is supported";;
- esac
-
- child=$(basename $path)
- parent=$(dirname $path)
-
- if [ "$option" == "-p" -o "$option2" == "-p" ]; then
- if [ -d $parent/$child ]; then
- return $rc
- fi
- p_option="-p"
- fi
+ local stripe_index=-1
+ local OPTIND=1
+
+ while getopts "c:i:p" opt; do
+ case $opt in
+ c) stripe_count=$OPTARG;;
+ i) stripe_index=$OPTARG;;
+ p) p_option="-p";;
+ \?) error "only support -i -c -p";;
+ esac
+ done
- if [ "${option:0:2}" == "-c" ]; then
- stripe_count=$(echo $option | sed 's/^-c//')
- fi
+ shift $((OPTIND - 1))
+ [ $# -eq 1 ] || error "Only creating single directory is supported"
+ path="$*"
- if [ "${option2:0:2}" == "-c" ]; then
- stripe_count=$(echo $option2 | sed 's/^-c//')
- fi
+ if [ "$p_option" == "-p" ]; then
+ local parent=$(dirname $path)
- if [ ! -d ${parent} ]; then
- if [ "$p_option" == "-p" ]; then
- mkdir -p ${parent}
- else
- return 1
- fi
+ [ -d $path ] && return 0
+ [ ! -d ${parent} ] && mkdir -p ${parent}
fi
if [ $MDSCOUNT -le 1 ]; then
- mkdir $p_option $parent/$child || rc=$?
+ mkdir $path
else
- local mdt_idx=$($LFS getstripe -M $parent)
local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
+ local mdt_index
- mdt_idx=$((test_num % MDSCOUNT))
- echo "striped dir -i$mdt_idx -c$stripe_count $path"
- $LFS setdirstripe -i$mdt_idx -c$stripe_count $path || rc=$?
+ if [ $stripe_index -eq -1 ]; then
+ mdt_index=$((test_num % MDSCOUNT))
+ else
+ mdt_index=$stripe_index
+ fi
+ echo "striped dir -i$mdt_index -c$stripe_count $path"
+ $LFS setdirstripe -i$mdt_index -c$stripe_count $path
fi
- return $rc
}
# find the smallest and not in use file descriptor
rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
+ for idx in $(seq $MDSCOUNT); do
+ local name="MDT$(printf '%04x' $((idx - 1)))"
+ rm -rf $MOUNT/.lustre/lost+found/$name/*
+ done
}
# calcule how many ost-objects to be created.
local mdt_name="MDT$(printf '%04x' $mdt_idx)"
local ost_name="OST$(printf '%04x' $ost_idx)"
local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
- local last_id=$(do_facet mds${mdt_idx} lctl get_param -n \
+ local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
osp.$proc_path.prealloc_last_id)
- local next_id=$(do_facet mds${mdt_idx} lctl get_param -n \
+ local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
osp.$proc_path.prealloc_next_id)
-
echo $((last_id - next_id + 1))
}
error_noexit "Pool $FSNAME.$pool is not destroyed"
return 3
}
+
+# Get and check the actual stripe count of one file.
+# Usage: check_stripe_count <file> <expected_stripe_count>
+check_stripe_count() {
+ local file=$1
+ local expected=$2
+ local actual
+
+ [[ -z "$file" || -z "$expected" ]] &&
+ error "check_stripe_count: invalid argument"
+
+ local cmd="$GETSTRIPE -c $file"
+ actual=$($cmd) || error "$cmd failed"
+ actual=${actual%% *}
+
+ if [[ $actual -ne $expected ]]; then
+ [[ $expected -eq -1 ]] ||
+ error "$cmd wrong: found $actual, expected $expected"
+ [[ $actual -eq $OSTCOUNT ]] ||
+ error "$cmd wrong: found $actual, expected $OSTCOUNT"
+ fi
+}
+
+# Get and check the actual list of OST indices on one file.
+# Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
+check_obdidx() {
+ local file=$1
+ local expected=$2
+ local obdidx
+
+ [[ -z "$file" || -z "$expected" ]] &&
+ error "check_obdidx: invalid argument!"
+
+ obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
+ grep -v obdidx | awk '{print $1}' | xargs))
+
+ [[ $obdidx = $expected ]] ||
+ error "list of OST indices on $file is $obdidx," \
+ "should be $expected"
+}
+
+# Get and check the actual OST index of the first stripe on one file.
+# Usage: check_start_ost_idx <file> <expected_start_ost_idx>
+check_start_ost_idx() {
+ local file=$1
+ local expected=$2
+ local start_ost_idx
+
+ [[ -z "$file" || -z "$expected" ]] &&
+ error "check_start_ost_idx: invalid argument!"
+
+ start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
+ awk '{print $1}')
+
+ [[ $start_ost_idx = $expected ]] ||
+ error "OST index of the first stripe on $file is" \
+ "$start_ost_idx, should be $expected"
+}