+test_421a() {
+ local cnt
+ local fid1
+ local fid2
+
+ [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
+ skip "Need MDS version at least 2.12.54"
+
+ test_mkdir $DIR/$tdir
+ createmany -o $DIR/$tdir/f 3
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt != 3 ] && error "unexpected #files: $cnt"
+
+ fid1=$(lfs path2fid $DIR/$tdir/f1)
+ fid2=$(lfs path2fid $DIR/$tdir/f2)
+ $LFS rmfid $DIR $fid1 $fid2 || error "rmfid failed"
+
+ stat $DIR/$tdir/f1 && error "f1 still visible on the client"
+ stat $DIR/$tdir/f2 && error "f2 still visible on the client"
+
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt == 1 ] || error "unexpected #files after: $cnt"
+
+ rm -f $DIR/$tdir/f3 || error "can't remove f3"
+ createmany -o $DIR/$tdir/f 3
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt != 3 ] && error "unexpected #files: $cnt"
+
+ fid1=$(lfs path2fid $DIR/$tdir/f1)
+ fid2=$(lfs path2fid $DIR/$tdir/f2)
+ echo "remove using fsname $FSNAME"
+ $LFS rmfid $FSNAME $fid1 $fid2 || error "rmfid with fsname failed"
+
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt == 1 ] || error "unexpected #files after: $cnt"
+}
+run_test 421a "simple rm by fid"
+
+test_421b() {
+ local cnt
+ local FID1
+ local FID2
+
+ [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
+ skip "Need MDS version at least 2.12.54"
+
+ test_mkdir $DIR/$tdir
+ createmany -o $DIR/$tdir/f 3
+ multiop_bg_pause $DIR/$tdir/f1 o_c || error "multiop failed to start"
+ MULTIPID=$!
+
+ FID1=$(lfs path2fid $DIR/$tdir/f1)
+ FID2=$(lfs path2fid $DIR/$tdir/f2)
+ $LFS rmfid $DIR $FID1 $FID2 && error "rmfid didn't fail"
+
+ kill -USR1 $MULTIPID
+ wait
+
+ cnt=$(ls $DIR/$tdir | wc -l)
+ [ $cnt == 2 ] || error "unexpected #files after: $cnt"
+}
+run_test 421b "rm by fid on open file"
+
+test_421c() {
+ local cnt
+ local FIDS
+
+ [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
+ skip "Need MDS version at least 2.12.54"
+
+ test_mkdir $DIR/$tdir
+ createmany -o $DIR/$tdir/f 3
+ touch $DIR/$tdir/$tfile
+ createmany -l$DIR/$tdir/$tfile $DIR/$tdir/h 180
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt != 184 ] && error "unexpected #files: $cnt"
+
+ FID1=$(lfs path2fid $DIR/$tdir/$tfile)
+ $LFS rmfid $DIR $FID1 || error "rmfid failed"
+
+ cnt=$(ls $DIR/$tdir | wc -l)
+ [ $cnt == 3 ] || error "unexpected #files after: $cnt"
+}
+run_test 421c "rm by fid against hardlinked files"
+
+test_421d() {
+ local cnt
+ local FIDS
+
+ [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
+ skip "Need MDS version at least 2.12.54"
+
+ test_mkdir $DIR/$tdir
+ createmany -o $DIR/$tdir/f 4097
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt != 4097 ] && error "unexpected #files: $cnt"
+
+ FIDS=$(lfs path2fid $DIR/$tdir/f* | sed "s/[/][^:]*://g")
+ $LFS rmfid $DIR $FIDS || error "rmfid failed"
+
+ cnt=$(ls $DIR/$tdir | wc -l)
+ rm -rf $DIR/$tdir
+ [ $cnt == 0 ] || error "unexpected #files after: $cnt"
+}
+run_test 421d "rmfid en masse"
+
+test_421e() {
+ local cnt
+ local FID
+
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
+ [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
+ skip "Need MDS version at least 2.12.54"
+
+ mkdir -p $DIR/$tdir
+ $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
+ createmany -o $DIR/$tdir/striped_dir/f 512
+ cnt=$(ls -1 $DIR/$tdir/striped_dir | wc -l)
+ [ $cnt != 512 ] && error "unexpected #files: $cnt"
+
+ FIDS=$(lfs path2fid $DIR/$tdir/striped_dir/f* |
+ sed "s/[/][^:]*://g")
+ $LFS rmfid $DIR $FIDS || error "rmfid failed"
+
+ cnt=$(ls $DIR/$tdir/striped_dir | wc -l)
+ rm -rf $DIR/$tdir
+ [ $cnt == 0 ] || error "unexpected #files after: $cnt"
+}
+run_test 421e "rmfid in DNE"
+
+test_421f() {
+ local cnt
+ local FID
+
+ [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
+ skip "Need MDS version at least 2.12.54"
+
+ test_mkdir $DIR/$tdir
+ touch $DIR/$tdir/f
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt != 1 ] && error "unexpected #files: $cnt"
+
+ FID=$(lfs path2fid $DIR/$tdir/f)
+ $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail (1)"
+ # rmfid should fail
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt != 1 ] && error "unexpected #files after (2): $cnt"
+
+ chmod a+rw $DIR/$tdir
+ ls -la $DIR/$tdir
+ $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail (2)"
+ # rmfid should fail
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt != 1 ] && error "unexpected #files after (3): $cnt"
+
+ rm -f $DIR/$tdir/f
+ $RUNAS touch $DIR/$tdir/f
+ FID=$(lfs path2fid $DIR/$tdir/f)
+ echo "rmfid as root"
+ $LFS rmfid $DIR $FID || error "rmfid as root failed"
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt == 0 ] || error "unexpected #files after (4): $cnt"
+
+ rm -f $DIR/$tdir/f
+ $RUNAS touch $DIR/$tdir/f
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt != 1 ] && error "unexpected #files (4): $cnt"
+ FID=$(lfs path2fid $DIR/$tdir/f)
+ # rmfid w/o user_fid2path mount option should fail
+ $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail(3)"
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt == 1 ] || error "unexpected #files after (5): $cnt"
+
+ umount_client $MOUNT || error "failed to umount client"
+ mount_client $MOUNT "$MOUNT_OPTS,user_fid2path" ||
+ error "failed to mount client'"
+
+ $RUNAS $LFS rmfid $DIR $FID || error "rmfid failed"
+ # rmfid should succeed
+ cnt=$(ls -1 $DIR/$tdir | wc -l)
+ [ $cnt == 0 ] || error "unexpected #files after (6): $cnt"
+
+ # rmfid shouldn't allow to remove files due to dir's permission
+ chmod a+rwx $DIR/$tdir
+ touch $DIR/$tdir/f
+ ls -la $DIR/$tdir
+ FID=$(lfs path2fid $DIR/$tdir/f)
+ $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail"
+
+ umount_client $MOUNT || error "failed to umount client"
+ mount_client $MOUNT "$MOUNT_OPTS" ||
+ error "failed to mount client'"
+
+}
+run_test 421f "rmfid checks permissions"
+
+test_421g() {
+ local cnt
+ local FIDS
+
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
+ [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
+ skip "Need MDS version at least 2.12.54"
+
+ mkdir -p $DIR/$tdir
+ $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
+ createmany -o $DIR/$tdir/striped_dir/f 512
+ cnt=$(ls -1 $DIR/$tdir/striped_dir | wc -l)
+ [ $cnt != 512 ] && error "unexpected #files: $cnt"
+
+ FIDS=$(lfs path2fid $DIR/$tdir/striped_dir/f* |
+ sed "s/[/][^:]*://g")
+
+ rm -f $DIR/$tdir/striped_dir/f1*
+ cnt=$(ls -1 $DIR/$tdir/striped_dir | wc -l)
+ removed=$((512 - cnt))
+
+ # few files have been just removed, so we expect
+ # rmfid to fail on their fids
+ errors=$($LFS rmfid $DIR $FIDS 2>&1 | wc -l)
+ [ $removed != $errors ] && error "$errors != $removed"
+
+ cnt=$(ls $DIR/$tdir/striped_dir | wc -l)
+ rm -rf $DIR/$tdir
+ [ $cnt == 0 ] || error "unexpected #files after: $cnt"
+}
+run_test 421g "rmfid to return errors properly"
+
+test_422() {
+ test_mkdir -i 0 -c 1 -p $DIR/$tdir/d1
+ test_mkdir -i 0 -c 1 -p $DIR/$tdir/d2
+ test_mkdir -i 0 -c 1 -p $DIR/$tdir/d3
+ dd if=/dev/zero of=$DIR/$tdir/d1/file1 bs=1k count=1
+ dd if=/dev/zero of=$DIR/$tdir/d2/file1 bs=1k count=1
+
+ local amc=$(at_max_get client)
+ local amo=$(at_max_get mds1)
+ local timeout=`lctl get_param -n timeout`
+
+ at_max_set 0 client
+ at_max_set 0 mds1
+
+#define OBD_FAIL_PTLRPC_PAUSE_REQ 0x50a
+ do_facet mds1 $LCTL set_param fail_loc=0x8000050a \
+ fail_val=$(((2*timeout + 10)*1000))
+ touch $DIR/$tdir/d3/file &
+ sleep 2
+#define OBD_FAIL_TGT_REPLY_DATA_RACE 0x722
+ do_facet mds1 $LCTL set_param fail_loc=0x80000722 \
+ fail_val=$((2*timeout + 5))
+ mv $DIR/$tdir/d1/file1 $DIR/$tdir/d1/file2 &
+ local pid=$!
+ sleep 1
+ kill -9 $pid
+ sleep $((2 * timeout))
+ echo kill $pid
+ kill -9 $pid
+ lctl mark touch
+ touch $DIR/$tdir/d2/file3
+ touch $DIR/$tdir/d2/file4
+ touch $DIR/$tdir/d2/file5
+
+ wait
+ at_max_set $amc client
+ at_max_set $amo mds1
+
+ # LU-12838 - verify the ptlrpc thread watchdog is not always throttled
+ do_facet mds1 "dmesg | grep 'Dumping the stack trace for debugging'" ||
+ error "Watchdog is always throttled"
+}
+run_test 422 "kill a process with RPC in progress"
+