From 67c0c58800d6ca2fc71578c9be415b4d0a774c5a Mon Sep 17 00:00:00 2001 From: Etienne AUJAMES Date: Fri, 28 Mar 2025 18:57:11 +0100 Subject: [PATCH] LU-18860 mdd: fix CLF_UNLINK_LAST on open file unlink The flag CLF_UNLINK_LAST should be set for UNLINK changelog if the last link is removed. This flag is not set if the file is open on a client. If the file open, Lustre will re-link the file in the PENDING MDT directory. So, la_nlink == 1 after mdd_finish_unlink() and CLF_UNLINK_LAST will not be set. Check if the object is dead instead of relying on la_nlink to set the flag. Update the sanity 161c for that use case. Test-Parameters: testlist=sanity env=ONLY=161c,ONLY_REPEAT=20 Test-Parameters: testlist=sanity env=ONLY=161 Signed-off-by: Etienne AUJAMES Change-Id: I35ef530cd55cd5e07ad79a7cdae056de95735f61 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58578 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Qian Yingjin Reviewed-by: Lai Siyao Reviewed-by: Oleg Drokin --- lustre/mdd/mdd_dir.c | 2 +- lustre/tests/sanity.sh | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index b1c1a6d..a70086f 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -2210,7 +2210,7 @@ cleanup: mdd_write_unlock(env, mdd_cobj); if (rc == 0) { - if (cattr->la_nlink == 0) + if (mdd_is_dead_obj(mdd_cobj)) cl_flags |= CLF_UNLINK_LAST; else cl_flags &= ~CLF_UNLINK_HSM_EXISTS; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index d460b3c..fa71e02 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -20675,6 +20675,23 @@ test_161c() { error "flag $flags is not 0x0" fi echo "unlink a file having nlink > 1, changelog record flags '$flags'" + + (( MDS1_VERSION >= $(version_code v2_16_53-39) )) || + { echo "CLF_UNLINK_LAST is not set with open file (LU-18860)"; + return 0; } + + # unlink a file open having nlink = 1 (changelog flag 0x1) + local pid + touch $DIR/$tdir/open_161c + tail -f $DIR/$tdir/open_161c & pid=$! + sleep 0.2 + unlink $DIR/$tdir/open_161c + kill $pid + changelog_dump | grep UNLNK | tail -n 5 + flags=$(changelog_dump | awk '/UNLNK/ {f=$5} END {print f}') + changelog_clear 0 || error "changelog_clear failed" + [[ "$flags" == "0x1" ]] || error "flag $flags is not 0x1" + echo "unlink a open file having nlink = 1, changelog record has flags of $flags" } run_test 161c "check CL_RENME[UNLINK] changelog record flags" -- 1.8.3.1