build_test_filter
-mkdir -p $MOUNT2
-mount_client $MOUNT2
-
test_1a() {
touch $DIR1/f1
[ -f $DIR2/f1 ] || error
skip "Need MDS version at least 2.5.53" && return
remote_mds_nodsh && skip "remote MDS with nodsh" && return
- local fcount=2048
+ local fcount=$((MDSCOUNT * 256))
declare -a fd_list
declare -a fid_list
# drop all open locks and close any cached "open" files on the client
cancel_lru_locks mdc
- echo -n "open files "
- ulimit -n 8096
+ local open_fids_cmd="$LCTL get_param -n mdt.*.exports.'$nid'.open_files"
+ local fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
+ local already=${#fid_list[@]}
+ for (( i = 0; i < $already; i++ )) ; do
+ log "already open[$i]: $($LFS fid2path $DIR2 ${fid_list[i]})"
+ done
+
+ echo -n "opening files: "
+ ulimit -n $((fcount + 50))
for ((i = 0; i < $fcount; i++)); do
touch $DIR/$tdir/f_$i
- local fd=$(free_fd)
- local cmd="exec $fd<$DIR/$tdir/f_$i"
- eval $cmd
+ local fd=$(free_fd ${fd_list[i]})
+ local open_cmd="exec $fd<$DIR/$tdir/f_$i"
+ eval $open_cmd
+
fd_list[i]=$fd
- echo -n "."
+
+ (( $i % 32 == 0 )) && echo -n "."
done
echo
- local get_open_fids="$LCTL get_param -n mdt.*.exports.'$nid'.open_files"
- local fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $get_open_fids))
+ fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
# Possible errors in openfiles FID list.
# 1. Missing FIDs. Check 1
# 5. Valid FID, points to some other file. Check 3
# Check 1
- [ ${#fid_list[@]} -ne $fcount ] &&
- error "${#fid_list[@]} != $fcount open files"
-
- for (( i = 0; i < $fcount; i++ )) ; do
- cmd="exec ${fd_list[i]}</dev/null"
- eval $cmd
- filename=$($LFS fid2path $DIR2 ${fid_list[i]})
+ [ ${#fid_list[@]} -ne $((fcount + already)) ] &&
+ error "${#fid_list[@]} != $fcount (+$already old) open files"
+
+ echo -n "closing files: "
+ for (( fd = 0, fid = 0; fd < $fcount; fd++, fid++ )) ; do
+ local close_cmd="exec ${fd_list[fd]}<&-"
+ eval $close_cmd
+ filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
+
+ while [[ ! "$filename" =~ "$DIR2/$tdir/f_" ]]; do
+ echo "skip old open file $filename"
+ ((fid++))
+ filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
+ done
# Check 2
rm --interactive=no $filename
[ $? -ne 0 ] &&
- error "Nonexisting fid ${fid_list[i]} listed."
+ error "Nonexisting fid ${fid_list[fid]} listed."
+ (( $fd % 32 == 0 )) && echo -n "."
done
+ echo
# Check 3
ls_op=$(ls $DIR2/$tdir | wc -l)
rm -rf $DIR/$tdir
}
-run_test 76 "Verify MDS open_files tracking for 2048 files"
+run_test 76 "Verify MDT open_files listing"
nrs_write_read() {
local n=16
# kill and wait in each test only guarentee script finish, but command in script
# like 'rm' 'chmod' may still be running, wait for all commands to finish
# otherwise umount below will fail
-wait_update $HOSTNAME "fuser -m $MOUNT2" "" || true
-
-[ "$(mount | grep $MOUNT2)" ] && umount $MOUNT2
+[ "$(mount | grep $MOUNT2)" ] && wait_update $HOSTNAME "fuser -m $MOUNT2" "" ||
+ true
complete $SECONDS
rm -f $SAMPLE_FILE
# commit the device label change to disk
if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
echo "Commit the device label on ${!dev}"
- do_facet $facet "sync; sync; sync"
- sleep 5
+ do_facet $facet "sync; sleep 5; sync"
fi
fi
}
-# find the smallest and not in use file descriptor
+# free_fd: find the smallest and not in use file descriptor [above @last_fd]
+#
+# If called many times, passing @last_fd will avoid repeated searching
+# already-open FDs repeatedly if we know they are still in use.
+#
+# usage: free_fd [last_fd]
free_fd()
{
- local max_fd=$(ulimit -n)
- local fd=3
- while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
- ((++fd))
- done
- [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
- echo $fd
+ local max_fd=$(ulimit -n)
+ local fd=$((${1:-2} + 1))
+
+ while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
+ ((++fd))
+ done
+ [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
+ echo $fd
}
check_mount_and_prep()