Blob Blame History Raw
From: Jeff Layton <jlayton@kernel.org>
Date: Tue, 1 Jun 2021 09:40:25 -0400
Subject: ceph: must hold snap_rwsem when filling inode for async create
Git-commit: 27171ae6a0fdc75571e5bf3d0961631a1e4fb765
Patch-mainline: v5.13
References: bsc#1187927

...and add a lockdep assertion for it to ceph_fill_inode().

Cc: stable@vger.kernel.org # v5.7+
Fixes: 9a8d03ca2e2c3 ("ceph: attempt to do async create when possible")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
[luis: inlined ceph_sb_to_mdsc() helper, as we don't have commit
 2678da88f4b4 ]
Acked-by: Luis Henriques <lhenriques@suse.com>
---
 fs/ceph/file.c  |    3 +++
 fs/ceph/inode.c |    2 ++
 2 files changed, 5 insertions(+)

--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -579,6 +579,7 @@ static int ceph_finish_async_create(stru
 	struct ceph_inode_info *ci = ceph_inode(dir);
 	struct inode *inode;
 	struct timespec64 now;
+	struct ceph_mds_client *mdsc = ceph_sb_to_client(dir->i_sb)->mdsc;
 	struct ceph_vino vino = { .ino = req->r_deleg_ino,
 				  .snap = CEPH_NOSNAP };
 
@@ -616,8 +617,10 @@ static int ceph_finish_async_create(stru
 
 	ceph_file_layout_to_legacy(lo, &in.layout);
 
+	down_read(&mdsc->snap_rwsem);
 	ret = ceph_fill_inode(inode, NULL, &iinfo, NULL, req->r_session,
 			      req->r_fmode, NULL);
+	up_read(&mdsc->snap_rwsem);
 	if (ret) {
 		dout("%s failed to fill inode: %d\n", __func__, ret);
 		ceph_dir_clear_complete(dir);
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -768,6 +768,8 @@ int ceph_fill_inode(struct inode *inode,
 	bool new_version = false;
 	bool fill_inline = false;
 
+	lockdep_assert_held(&mdsc->snap_rwsem);
+
 	dout("%s %p ino %llx.%llx v %llu had %llu\n", __func__,
 	     inode, ceph_vinop(inode), le64_to_cpu(info->version),
 	     ci->i_version);