Commit a096b09a authored by Yan, Zheng's avatar Yan, Zheng Committed by Sage Weil

ceph: queue cap release in __ceph_remove_cap()

call __queue_cap_release() in __ceph_remove_cap(), this avoids
acquiring s_cap_lock twice.
Signed-off-by: default avatarYan, Zheng <zheng.z.yan@intel.com>
Reviewed-by: default avatarSage Weil <sage@inktank.com>
parent 81c6aea5
...@@ -897,7 +897,7 @@ static int __ceph_is_any_caps(struct ceph_inode_info *ci) ...@@ -897,7 +897,7 @@ static int __ceph_is_any_caps(struct ceph_inode_info *ci)
* caller should hold i_ceph_lock. * caller should hold i_ceph_lock.
* caller will not hold session s_mutex if called from destroy_inode. * caller will not hold session s_mutex if called from destroy_inode.
*/ */
void __ceph_remove_cap(struct ceph_cap *cap) void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release)
{ {
struct ceph_mds_session *session = cap->session; struct ceph_mds_session *session = cap->session;
struct ceph_inode_info *ci = cap->ci; struct ceph_inode_info *ci = cap->ci;
...@@ -909,6 +909,10 @@ void __ceph_remove_cap(struct ceph_cap *cap) ...@@ -909,6 +909,10 @@ void __ceph_remove_cap(struct ceph_cap *cap)
/* remove from session list */ /* remove from session list */
spin_lock(&session->s_cap_lock); spin_lock(&session->s_cap_lock);
if (queue_release)
__queue_cap_release(session, ci->i_vino.ino, cap->cap_id,
cap->mseq, cap->issue_seq);
if (session->s_cap_iterator == cap) { if (session->s_cap_iterator == cap) {
/* not yet, we are iterating over this very cap */ /* not yet, we are iterating over this very cap */
dout("__ceph_remove_cap delaying %p removal from session %p\n", dout("__ceph_remove_cap delaying %p removal from session %p\n",
...@@ -1023,7 +1027,6 @@ void __queue_cap_release(struct ceph_mds_session *session, ...@@ -1023,7 +1027,6 @@ void __queue_cap_release(struct ceph_mds_session *session,
struct ceph_mds_cap_release *head; struct ceph_mds_cap_release *head;
struct ceph_mds_cap_item *item; struct ceph_mds_cap_item *item;
spin_lock(&session->s_cap_lock);
BUG_ON(!session->s_num_cap_releases); BUG_ON(!session->s_num_cap_releases);
msg = list_first_entry(&session->s_cap_releases, msg = list_first_entry(&session->s_cap_releases,
struct ceph_msg, list_head); struct ceph_msg, list_head);
...@@ -1052,7 +1055,6 @@ void __queue_cap_release(struct ceph_mds_session *session, ...@@ -1052,7 +1055,6 @@ void __queue_cap_release(struct ceph_mds_session *session,
(int)CEPH_CAPS_PER_RELEASE, (int)CEPH_CAPS_PER_RELEASE,
(int)msg->front.iov_len); (int)msg->front.iov_len);
} }
spin_unlock(&session->s_cap_lock);
} }
/* /*
...@@ -1067,12 +1069,8 @@ void ceph_queue_caps_release(struct inode *inode) ...@@ -1067,12 +1069,8 @@ void ceph_queue_caps_release(struct inode *inode)
p = rb_first(&ci->i_caps); p = rb_first(&ci->i_caps);
while (p) { while (p) {
struct ceph_cap *cap = rb_entry(p, struct ceph_cap, ci_node); struct ceph_cap *cap = rb_entry(p, struct ceph_cap, ci_node);
struct ceph_mds_session *session = cap->session;
__queue_cap_release(session, ceph_ino(inode), cap->cap_id,
cap->mseq, cap->issue_seq);
p = rb_next(p); p = rb_next(p);
__ceph_remove_cap(cap); __ceph_remove_cap(cap, true);
} }
} }
...@@ -2791,7 +2789,7 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex, ...@@ -2791,7 +2789,7 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
} }
spin_unlock(&mdsc->cap_dirty_lock); spin_unlock(&mdsc->cap_dirty_lock);
} }
__ceph_remove_cap(cap); __ceph_remove_cap(cap, false);
} }
/* else, we already released it */ /* else, we already released it */
...@@ -2931,9 +2929,12 @@ void ceph_handle_caps(struct ceph_mds_session *session, ...@@ -2931,9 +2929,12 @@ void ceph_handle_caps(struct ceph_mds_session *session,
if (!inode) { if (!inode) {
dout(" i don't have ino %llx\n", vino.ino); dout(" i don't have ino %llx\n", vino.ino);
if (op == CEPH_CAP_OP_IMPORT) if (op == CEPH_CAP_OP_IMPORT) {
spin_lock(&session->s_cap_lock);
__queue_cap_release(session, vino.ino, cap_id, __queue_cap_release(session, vino.ino, cap_id,
mseq, seq); mseq, seq);
spin_unlock(&session->s_cap_lock);
}
goto flush_cap_releases; goto flush_cap_releases;
} }
......
...@@ -986,7 +986,7 @@ static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap, ...@@ -986,7 +986,7 @@ static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap,
dout("removing cap %p, ci is %p, inode is %p\n", dout("removing cap %p, ci is %p, inode is %p\n",
cap, ci, &ci->vfs_inode); cap, ci, &ci->vfs_inode);
spin_lock(&ci->i_ceph_lock); spin_lock(&ci->i_ceph_lock);
__ceph_remove_cap(cap); __ceph_remove_cap(cap, false);
if (!__ceph_is_any_real_caps(ci)) { if (!__ceph_is_any_real_caps(ci)) {
struct ceph_mds_client *mdsc = struct ceph_mds_client *mdsc =
ceph_sb_to_client(inode->i_sb)->mdsc; ceph_sb_to_client(inode->i_sb)->mdsc;
...@@ -1231,9 +1231,7 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg) ...@@ -1231,9 +1231,7 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg)
session->s_trim_caps--; session->s_trim_caps--;
if (oissued) { if (oissued) {
/* we aren't the only cap.. just remove us */ /* we aren't the only cap.. just remove us */
__queue_cap_release(session, ceph_ino(inode), cap->cap_id, __ceph_remove_cap(cap, true);
cap->mseq, cap->issue_seq);
__ceph_remove_cap(cap);
} else { } else {
/* try to drop referring dentries */ /* try to drop referring dentries */
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
......
...@@ -741,13 +741,7 @@ extern int ceph_add_cap(struct inode *inode, ...@@ -741,13 +741,7 @@ extern int ceph_add_cap(struct inode *inode,
int fmode, unsigned issued, unsigned wanted, int fmode, unsigned issued, unsigned wanted,
unsigned cap, unsigned seq, u64 realmino, int flags, unsigned cap, unsigned seq, u64 realmino, int flags,
struct ceph_cap_reservation *caps_reservation); struct ceph_cap_reservation *caps_reservation);
extern void __ceph_remove_cap(struct ceph_cap *cap); extern void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release);
static inline void ceph_remove_cap(struct ceph_cap *cap)
{
spin_lock(&cap->ci->i_ceph_lock);
__ceph_remove_cap(cap);
spin_unlock(&cap->ci->i_ceph_lock);
}
extern void ceph_put_cap(struct ceph_mds_client *mdsc, extern void ceph_put_cap(struct ceph_mds_client *mdsc,
struct ceph_cap *cap); struct ceph_cap *cap);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment