diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index f135660a2479d26cbb7affac7d93c2fae43c03e0..d555d27906198faccc9a5c8f801ca292316d69a5 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2044,12 +2044,24 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags, if (mutex_trylock(&session->s_mutex) == 0) { dout("inverting session/ino locks on %p\n", session); + session = ceph_get_mds_session(session); spin_unlock(&ci->i_ceph_lock); if (took_snap_rwsem) { up_read(&mdsc->snap_rwsem); took_snap_rwsem = 0; } - mutex_lock(&session->s_mutex); + if (session) { + mutex_lock(&session->s_mutex); + ceph_put_mds_session(session); + } else { + /* + * Because we take the reference while + * holding the i_ceph_lock, it should + * never be NULL. Throw a warning if it + * ever is. + */ + WARN_ON_ONCE(true); + } goto retry; } }