[PATCH] ceph: drop stale dentry when ceph_unlink() gets -ENOENT
From: zhangdaolong
Date: Mon Nov 09 2026 - 21:07:48 EST
When a synchronous unlink, rmdir, or rmsnap request in ceph_unlink()
fails with -ENOENT (for example, because the target was already removed
on the MDS by another client or a snapshot was already purged before
the request reached the MDS), the MDS replies without a dentry trace.
Currently, ceph_fill_trace() only invalidates the parent directory when
result == 0, and neither ceph_unlink() nor the VFS layer unhashes the
dentry on error. As a result, the stale positive dentry remains hashed
in the dcache and the parent directory may retain CEPH_I_COMPLETE.
Fix this by clearing the parent directory's completeness and calling
d_drop(dentry) when ceph_mdsc_do_request() returns -ENOENT in
ceph_unlink().
Suggested-by: Xiubo Li <xiubli@xxxxxxxxxx>
Signed-off-by: zhangdaolong <dlzhangak@xxxxxxxxxxxxxx>
---
fs/ceph/dir.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 6eb5b1cb039b..f4c0521f3bcc 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -1473,8 +1473,12 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry)
} else {
set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
err = ceph_mdsc_do_request(mdsc, dir, req);
- if (!err && !req->r_reply_info.head->is_dentry)
+ if (!err && !req->r_reply_info.head->is_dentry) {
d_delete(dentry);
+ } else if (err == -ENOENT) {
+ ceph_dir_clear_complete(dir);
+ d_drop(dentry);
+ }
}
ceph_mdsc_put_request(req);
--
2.48.1