Skip to content

Commit 7f47f7f

Browse files
nielsdosidryomov
authored andcommitted
ceph: get snap_rwsem read lock in handle_cap_export for ceph_add_cap
ceph_add_cap says in its function documentation that the caller should hold the read lock on the session snap_rwsem. Furthermore, not only ceph_add_cap needs that lock, when it calls to ceph_lookup_snap_realm it eventually calls ceph_get_snap_realm which states via lockdep that snap_rwsem needs to be held. handle_cap_export calls ceph_add_cap without that mdsc->snap_rwsem held. Thus, since ceph_get_snap_realm and ceph_add_cap both need the lock, the common place to acquire that lock is inside handle_cap_export. Signed-off-by: Niels Dossche <[email protected]> Reviewed-by: Xiubo Li <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent dc9b0dc commit 7f47f7f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/ceph/caps.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,7 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
38703870
dout("handle_cap_export inode %p ci %p mds%d mseq %d target %d\n",
38713871
inode, ci, mds, mseq, target);
38723872
retry:
3873+
down_read(&mdsc->snap_rwsem);
38733874
spin_lock(&ci->i_ceph_lock);
38743875
cap = __get_cap_for_mds(ci, mds);
38753876
if (!cap || cap->cap_id != le64_to_cpu(ex->cap_id))
@@ -3933,6 +3934,7 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
39333934
}
39343935

39353936
spin_unlock(&ci->i_ceph_lock);
3937+
up_read(&mdsc->snap_rwsem);
39363938
mutex_unlock(&session->s_mutex);
39373939

39383940
/* open target session */
@@ -3958,6 +3960,7 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
39583960

39593961
out_unlock:
39603962
spin_unlock(&ci->i_ceph_lock);
3963+
up_read(&mdsc->snap_rwsem);
39613964
mutex_unlock(&session->s_mutex);
39623965
if (tsession) {
39633966
mutex_unlock(&tsession->s_mutex);

0 commit comments

Comments
 (0)