#! /bin/bash # SPDX-License-Identifier: GPL-2.0 # Copyright (C) 2018 CTERA Networks. All Rights Reserved. # # FS QA Test No. 058 # # Test decoding overlay file handles with warm/cold dentry cache # # When opening a non-dir by file handle and the decoded inode/dentry # are not in cache, the resulting dentry is "disconnected" (i.e. unknown # path). This is a common case that is already covered by previous tests. # This test covers the case of decoding an overlay file handle, while a # disconnected dentry is still in cache. # # This test requires and enables overlayfs NFS export support. # NFS export support depends on and requires overlayfs index feature. # seq=`basename $0` seqres=$RESULT_DIR/$seq echo "QA output created by $seq" here=`pwd` tmp=/tmp/$$ status=1 # failure is the default! trap "_cleanup; exit \$status" 0 1 2 3 15 _cleanup() { $KILLALL_PROG -9 open_by_handle >/dev/null 2>&1 wait cd / rm -f $tmp.* } # get standard environment, filters and checks . ./common/rc . ./common/filter # real QA test starts here _supported_fs overlay _require_scratch _require_test_program "open_by_handle" # We need to require all features together, because nfs_export cannot # be enabled when index is disabled _require_scratch_overlay_features index nfs_export _require_command "$KILLALL_PROG" killall # All overlay dirs are on scratch partition lower=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER upper=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER work=$OVL_BASE_SCRATCH_MNT/$OVL_WORK # Keep this number > 1, because open_by_handle -rp does faccessat() # on file file000000, which makes that dentry connected NUMFILES=10 # Create test dir and empty test files create_test_files() { local dir=$1 local opt=$2 mkdir -p $dir $here/src/open_by_handle -cp $opt $dir $NUMFILES } # Test encode/decode file handles on overlay mount test_file_handles() { local dir=$1 shift echo test_file_handles $dir $* | _filter_scratch | \ sed -e "s,$tmp\.,,g" $here/src/open_by_handle $* $dir $NUMFILES } # Create lower/upper dir and files _scratch_mkfs create_test_files $upper/uppertestdir -w create_test_files $lower/lowertestdir -w _scratch_mount -o "index=on,nfs_export=on" # Encode upper file handles test_file_handles $SCRATCH_MNT/uppertestdir -p -o $tmp.upper_file_handles # Encode lower file handles test_file_handles $SCRATCH_MNT/lowertestdir -p -o $tmp.lower_file_handles # Check decode and read from stored file handles with warm caches - # At this time, all non-dir dentries are connected, because the entries # were created on lookup, before encoding the file handles. test_file_handles $SCRATCH_MNT -rnp -i $tmp.upper_file_handles test_file_handles $SCRATCH_MNT -rnp -i $tmp.lower_file_handles # Check decode and read/readdir from stored file handles with cold caches - # -s sleeps in the background to keep files open and keep disconnected # overlay dentries in cache _scratch_cycle_mount "index=on,nfs_export=on" test_file_handles $SCRATCH_MNT -rnps -i $tmp.upper_file_handles & # Give the above 1 second to get to sleep loop sleep 1 test_file_handles $SCRATCH_MNT -rnps -i $tmp.lower_file_handles & # Give the above 1 second to get to sleep loop sleep 1 # Check decode and read/readdir from stored file handles with warm caches - # At this time, all non-dir dentries are disconnected, because there was # no lookup to the files since drop caches. The expection to this rule # is lower and upper file000000. open_by_handle -rp above did faccessat() # on file file000000, which created a connected dentry alias in addition # to the disconnected dentry alias. test_file_handles $SCRATCH_MNT -rnp -i $tmp.upper_file_handles test_file_handles $SCRATCH_MNT -rnp -i $tmp.lower_file_handles # SIGPIPE avoids Terminated/Killed message from bash $KILLALL_PROG -q -13 open_by_handle wait status=0 exit