All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ceph: don't return -ESTALE if there's still an open file
@ 2020-05-14 11:14 Luis Henriques
  2020-05-14 12:10 ` Jeff Layton
  0 siblings, 1 reply; 14+ messages in thread
From: Luis Henriques @ 2020-05-14 11:14 UTC (permalink / raw)
  To: Jeff Layton, Ilya Dryomov; +Cc: ceph-devel, linux-kernel

Similarly to commit 03f219041fdb ("ceph: check i_nlink while converting
a file handle to dentry"), this fixes another corner case with
name_to_handle_at/open_by_handle_at.  The issue has been detected by
xfstest generic/467, when doing:

 - name_to_handle_at("/cephfs/myfile")
 - open("/cephfs/myfile")
 - unlink("/cephfs/myfile")
 - open_by_handle_at()

The call to open_by_handle_at should not fail because the file still
exists and we do have a valid handle to it.

Signed-off-by: Luis Henriques <lhenriques@suse.com>
---
 fs/ceph/export.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/ceph/export.c b/fs/ceph/export.c
index 79dc06881e78..8556df9d94d0 100644
--- a/fs/ceph/export.c
+++ b/fs/ceph/export.c
@@ -171,12 +171,21 @@ struct inode *ceph_lookup_inode(struct super_block *sb, u64 ino)
 
 static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
 {
+	struct ceph_inode_info *ci;
 	struct inode *inode = __lookup_inode(sb, ino);
+
 	if (IS_ERR(inode))
 		return ERR_CAST(inode);
 	if (inode->i_nlink == 0) {
-		iput(inode);
-		return ERR_PTR(-ESTALE);
+		bool is_open;
+		ci = ceph_inode(inode);
+		spin_lock(&ci->i_ceph_lock);
+		is_open = __ceph_is_file_opened(ci);
+		spin_unlock(&ci->i_ceph_lock);
+		if (!is_open) {
+			iput(inode);
+			return ERR_PTR(-ESTALE);
+		}
 	}
 	return d_obtain_alias(inode);
 }

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-05-19 10:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 11:14 [PATCH] ceph: don't return -ESTALE if there's still an open file Luis Henriques
2020-05-14 12:10 ` Jeff Layton
2020-05-14 12:48   ` Luis Henriques
2020-05-14 13:15     ` Jeff Layton
2020-05-15  6:42       ` Amir Goldstein
2020-05-15 11:15         ` Luis Henriques
2020-05-15 11:38           ` Jeff Layton
2020-05-15 16:56             ` Amir Goldstein
2020-05-15 19:14               ` Jeff Layton
2020-05-16  6:58                 ` Amir Goldstein
2020-05-16 12:10                   ` Jeff Layton
2020-05-18 22:30                 ` Gregory Farnum
2020-05-19  4:00                   ` Amir Goldstein
2020-05-19 10:43                     ` Jeff Layton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.