From 3b3d8a35b7eb6de8c637e154f9509bb78695fece Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Mon, 6 Mar 2017 20:05:42 -0700 Subject: [PATCH] LU-9186 tests: fix sanityn test_76 and related code Fix sanityn.sh test_76 to skip already open files when checking whether mdt.*.exports.*.open_files accurately lists open files. Otherwise, if some previous test leaves a file descriptor open it will cause this test to fail spuriously. Limit the number of open files to 256*MDSCOUNT rather than 2048, so the test runs faster (80s vs. 215s in my VM with 2 MDTs). Properly close the open shell FDs using "FD<&-" rather than redirecting them to /dev/null, otherwise they stay open forever. Print a '.' only once per 32 files opened/closed. List open files in *.open_files in the order they were opened, rather than reverse order, since this makes it easier to see which files have been open longer. Print out the pathname of the open files being skipped. Don't explicitly mount $MOUNT2 in sanityn.sh. This is already handled inside check_and_setup_lustre() at the start of sanityn.sh. Improve free_fd() to accept a "last_fd" argument to avoid searching all open FDs on each call if it is known the fds are not closing. Test-Parameters: trivial Signed-off-by: Andreas Dilger Change-Id: I274b6db96f49a52c086f836c005558ef4b3ebbe5 Reviewed-on: https://review.whamcloud.com/25847 Tested-by: Jenkins Reviewed-by: Jian Yu Tested-by: Maloo Reviewed-by: Ashish Purkar Reviewed-by: Oleg Drokin --- lustre/mdt/mdt_open.c | 2 +- lustre/tests/sanityn.sh | 61 +++++++++++++++++++++++++----------------- lustre/tests/test-framework.sh | 25 ++++++++++------- 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index 934c6b8..63151d8 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -479,7 +479,7 @@ static int mdt_mfd_open(struct mdt_thread_info *info, struct mdt_object *p, mdt_mfd_close(info, mfd); } else { spin_lock(&med->med_open_lock); - list_add(&mfd->mfd_list, &med->med_open_head); + list_add_tail(&mfd->mfd_list, &med->med_open_head); spin_unlock(&med->med_open_lock); } diff --git a/lustre/tests/sanityn.sh b/lustre/tests/sanityn.sh index dc5f7ca..9c944ec 100644 --- a/lustre/tests/sanityn.sh +++ b/lustre/tests/sanityn.sh @@ -61,9 +61,6 @@ check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS build_test_filter -mkdir -p $MOUNT2 -mount_client $MOUNT2 - test_1a() { touch $DIR1/f1 [ -f $DIR2/f1 ] || error @@ -2930,7 +2927,7 @@ test_76() { #LU-946 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 @@ -2946,20 +2943,28 @@ test_76() { #LU-946 # 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 @@ -2969,19 +2974,28 @@ test_76() { #LU-946 # 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]}