提交 4fe59789 编写于 作者: Y Yan, Zheng

ceph: handle cap export race in try_flush_caps()

auth cap may change after releasing the i_ceph_lock
Signed-off-by: NYan, Zheng <zheng.z.yan@intel.com>
上级 fc12c80a
...@@ -1735,13 +1735,12 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags, ...@@ -1735,13 +1735,12 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags,
/* /*
* Try to flush dirty caps back to the auth mds. * Try to flush dirty caps back to the auth mds.
*/ */
static int try_flush_caps(struct inode *inode, struct ceph_mds_session *session, static int try_flush_caps(struct inode *inode, unsigned *flush_tid)
unsigned *flush_tid)
{ {
struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc; struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_info *ci = ceph_inode(inode);
int unlock_session = session ? 0 : 1;
int flushing = 0; int flushing = 0;
struct ceph_mds_session *session = NULL;
retry: retry:
spin_lock(&ci->i_ceph_lock); spin_lock(&ci->i_ceph_lock);
...@@ -1755,13 +1754,14 @@ static int try_flush_caps(struct inode *inode, struct ceph_mds_session *session, ...@@ -1755,13 +1754,14 @@ static int try_flush_caps(struct inode *inode, struct ceph_mds_session *session,
int want = __ceph_caps_wanted(ci); int want = __ceph_caps_wanted(ci);
int delayed; int delayed;
if (!session) { if (!session || session != cap->session) {
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
if (session)
mutex_unlock(&session->s_mutex);
session = cap->session; session = cap->session;
mutex_lock(&session->s_mutex); mutex_lock(&session->s_mutex);
goto retry; goto retry;
} }
BUG_ON(session != cap->session);
if (cap->session->s_state < CEPH_MDS_SESSION_OPEN) if (cap->session->s_state < CEPH_MDS_SESSION_OPEN)
goto out; goto out;
...@@ -1780,7 +1780,7 @@ static int try_flush_caps(struct inode *inode, struct ceph_mds_session *session, ...@@ -1780,7 +1780,7 @@ static int try_flush_caps(struct inode *inode, struct ceph_mds_session *session,
out: out:
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
out_unlocked: out_unlocked:
if (session && unlock_session) if (session)
mutex_unlock(&session->s_mutex); mutex_unlock(&session->s_mutex);
return flushing; return flushing;
} }
...@@ -1865,7 +1865,7 @@ int ceph_fsync(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -1865,7 +1865,7 @@ int ceph_fsync(struct file *file, loff_t start, loff_t end, int datasync)
return ret; return ret;
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
dirty = try_flush_caps(inode, NULL, &flush_tid); dirty = try_flush_caps(inode, &flush_tid);
dout("fsync dirty caps are %s\n", ceph_cap_string(dirty)); dout("fsync dirty caps are %s\n", ceph_cap_string(dirty));
/* /*
...@@ -1900,7 +1900,7 @@ int ceph_write_inode(struct inode *inode, struct writeback_control *wbc) ...@@ -1900,7 +1900,7 @@ int ceph_write_inode(struct inode *inode, struct writeback_control *wbc)
dout("write_inode %p wait=%d\n", inode, wait); dout("write_inode %p wait=%d\n", inode, wait);
if (wait) { if (wait) {
dirty = try_flush_caps(inode, NULL, &flush_tid); dirty = try_flush_caps(inode, &flush_tid);
if (dirty) if (dirty)
err = wait_event_interruptible(ci->i_cap_wq, err = wait_event_interruptible(ci->i_cap_wq,
caps_are_flushed(inode, flush_tid)); caps_are_flushed(inode, flush_tid));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册