From 0ac83dc97cdd7ec37476d06bcb3eec443a910ed5 Mon Sep 17 00:00:00 2001
From: adilger <adilger>
Date: Tue, 10 Feb 2004 00:02:17 +0000
Subject: [PATCH] Don't leave stale dentries around after renames (from 1.0.4).
 b=2428

---
 lustre/ChangeLog       |  1 +
 lustre/llite/namei.c   |  4 ++++
 lustre/tests/sanity.sh | 13 ++++++++++++-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/lustre/ChangeLog b/lustre/ChangeLog
index 562d2491f5..7fb431f361 100644
--- a/lustre/ChangeLog
+++ b/lustre/ChangeLog
@@ -22,6 +22,7 @@ tbd         Cluster File Systems, Inc. <info@clusterfs.com>
 	- ensure len(uuid) < 37 in lmc (1171)
 	- fix ia64 OOPS in llog_test (2255)
 	- zero end of page at obdfilter for partial page writes (2648)
+	- don't leave stale dentries around after renames (bug 2428)
 
 2004-01-27  Cluster File Systems, Inc. <info@clusterfs.com>
        * version 1.0.3
diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c
index da53dcb31a..7056f6544b 100644
--- a/lustre/llite/namei.c
+++ b/lustre/llite/namei.c
@@ -279,6 +279,10 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset,
                 if (rc)
                         RETURN(rc);
 
+                CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%lu/%u)\n",
+                       inode, inode->i_ino, inode->i_generation);
+                mdc_set_lock_data(&it->d.lustre.it_lock_handle, inode);
+
                 /* If this is a stat, get the authoritative file size */
                 if (it->it_op == IT_GETATTR && S_ISREG(inode->i_mode) &&
                     ll_i2info(inode)->lli_smd != NULL) {
diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh
index 584a57a201..5337a4293d 100644
--- a/lustre/tests/sanity.sh
+++ b/lustre/tests/sanity.sh
@@ -628,6 +628,17 @@ test_24m() {
 }
 run_test 24m "Renaming a file to a hard link to itself ========="
 
+test_24n() {
+    f="$DIR/f24n"
+    # this stats the old file after it was renamed, so it should fail
+    touch ${f}
+    $CHECKSTAT ${f}
+    mv ${f} ${f}.rename
+    $CHECKSTAT ${f}.rename
+    $CHECKSTAT -a ${f}
+}
+run_test 24n "Statting the old file after renameing (Posix rename 2)"
+
 test_25a() {
 	echo '== symlink sanity ============================================='
 	mkdir $DIR/d25
@@ -1634,7 +1645,7 @@ test_61() {
 	multiop $f OSMWUc || error
 	sync
 }
-run_test 61 "mmap() writes don't make sync hang =========="
+run_test 61 "mmap() writes don't make sync hang ================"
 
 # bug 2330 - insufficient obd_match error checking causes LBUG
 test_62() {
-- 
GitLab