ceph: clean up handle_cap_grant, handle_caps wrt session mutex
Drop session mutex unconditionally in handle_cap_grant, and do the check_caps from the handle_cap_grant helper. This avoids using a magic return value. Also avoid using a flag variable in the IMPORT case and call check_caps at the appropriate point. Signed-off-by: Sage Weil <sage@newdream.net>
This commit is contained in:
@@ -2195,18 +2195,19 @@ void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr,
|
|||||||
* Handle a cap GRANT message from the MDS. (Note that a GRANT may
|
* Handle a cap GRANT message from the MDS. (Note that a GRANT may
|
||||||
* actually be a revocation if it specifies a smaller cap set.)
|
* actually be a revocation if it specifies a smaller cap set.)
|
||||||
*
|
*
|
||||||
* caller holds s_mutex.
|
* caller holds s_mutex and i_lock, we drop both.
|
||||||
|
*
|
||||||
* return value:
|
* return value:
|
||||||
* 0 - ok
|
* 0 - ok
|
||||||
* 1 - check_caps on auth cap only (writeback)
|
* 1 - check_caps on auth cap only (writeback)
|
||||||
* 2 - check_caps (ack revoke)
|
* 2 - check_caps (ack revoke)
|
||||||
*/
|
*/
|
||||||
static int handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
|
static void handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
|
||||||
struct ceph_mds_session *session,
|
struct ceph_mds_session *session,
|
||||||
struct ceph_cap *cap,
|
struct ceph_cap *cap,
|
||||||
struct ceph_buffer *xattr_buf)
|
struct ceph_buffer *xattr_buf)
|
||||||
__releases(inode->i_lock)
|
__releases(inode->i_lock)
|
||||||
|
__releases(session->s_mutex)
|
||||||
{
|
{
|
||||||
struct ceph_inode_info *ci = ceph_inode(inode);
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
||||||
int mds = session->s_mds;
|
int mds = session->s_mds;
|
||||||
@@ -2216,7 +2217,7 @@ static int handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
|
|||||||
u64 size = le64_to_cpu(grant->size);
|
u64 size = le64_to_cpu(grant->size);
|
||||||
u64 max_size = le64_to_cpu(grant->max_size);
|
u64 max_size = le64_to_cpu(grant->max_size);
|
||||||
struct timespec mtime, atime, ctime;
|
struct timespec mtime, atime, ctime;
|
||||||
int reply = 0;
|
int check_caps = 0;
|
||||||
int wake = 0;
|
int wake = 0;
|
||||||
int writeback = 0;
|
int writeback = 0;
|
||||||
int revoked_rdcache = 0;
|
int revoked_rdcache = 0;
|
||||||
@@ -2329,10 +2330,10 @@ static int handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
|
|||||||
if ((used & ~newcaps) & CEPH_CAP_FILE_BUFFER)
|
if ((used & ~newcaps) & CEPH_CAP_FILE_BUFFER)
|
||||||
writeback = 1; /* will delay ack */
|
writeback = 1; /* will delay ack */
|
||||||
else if (dirty & ~newcaps)
|
else if (dirty & ~newcaps)
|
||||||
reply = 1; /* initiate writeback in check_caps */
|
check_caps = 1; /* initiate writeback in check_caps */
|
||||||
else if (((used & ~newcaps) & CEPH_CAP_FILE_CACHE) == 0 ||
|
else if (((used & ~newcaps) & CEPH_CAP_FILE_CACHE) == 0 ||
|
||||||
revoked_rdcache)
|
revoked_rdcache)
|
||||||
reply = 2; /* send revoke ack in check_caps */
|
check_caps = 2; /* send revoke ack in check_caps */
|
||||||
cap->issued = newcaps;
|
cap->issued = newcaps;
|
||||||
cap->implemented |= newcaps;
|
cap->implemented |= newcaps;
|
||||||
} else if (cap->issued == newcaps) {
|
} else if (cap->issued == newcaps) {
|
||||||
@@ -2361,7 +2362,14 @@ static int handle_cap_grant(struct inode *inode, struct ceph_mds_caps *grant,
|
|||||||
ceph_queue_invalidate(inode);
|
ceph_queue_invalidate(inode);
|
||||||
if (wake)
|
if (wake)
|
||||||
wake_up(&ci->i_cap_wq);
|
wake_up(&ci->i_cap_wq);
|
||||||
return reply;
|
|
||||||
|
if (check_caps == 1)
|
||||||
|
ceph_check_caps(ci, CHECK_CAPS_NODELAY|CHECK_CAPS_AUTHONLY,
|
||||||
|
session);
|
||||||
|
else if (check_caps == 2)
|
||||||
|
ceph_check_caps(ci, CHECK_CAPS_NODELAY, session);
|
||||||
|
else
|
||||||
|
mutex_unlock(&session->s_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2622,9 +2630,7 @@ void ceph_handle_caps(struct ceph_mds_session *session,
|
|||||||
u64 cap_id;
|
u64 cap_id;
|
||||||
u64 size, max_size;
|
u64 size, max_size;
|
||||||
u64 tid;
|
u64 tid;
|
||||||
int check_caps = 0;
|
|
||||||
void *snaptrace;
|
void *snaptrace;
|
||||||
int r;
|
|
||||||
|
|
||||||
dout("handle_caps from mds%d\n", mds);
|
dout("handle_caps from mds%d\n", mds);
|
||||||
|
|
||||||
@@ -2669,8 +2675,9 @@ void ceph_handle_caps(struct ceph_mds_session *session,
|
|||||||
case CEPH_CAP_OP_IMPORT:
|
case CEPH_CAP_OP_IMPORT:
|
||||||
handle_cap_import(mdsc, inode, h, session,
|
handle_cap_import(mdsc, inode, h, session,
|
||||||
snaptrace, le32_to_cpu(h->snap_trace_len));
|
snaptrace, le32_to_cpu(h->snap_trace_len));
|
||||||
check_caps = 1; /* we may have sent a RELEASE to the old auth */
|
ceph_check_caps(ceph_inode(inode), CHECK_CAPS_NODELAY,
|
||||||
goto done;
|
session);
|
||||||
|
goto done_unlocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the rest require a cap */
|
/* the rest require a cap */
|
||||||
@@ -2687,19 +2694,8 @@ void ceph_handle_caps(struct ceph_mds_session *session,
|
|||||||
switch (op) {
|
switch (op) {
|
||||||
case CEPH_CAP_OP_REVOKE:
|
case CEPH_CAP_OP_REVOKE:
|
||||||
case CEPH_CAP_OP_GRANT:
|
case CEPH_CAP_OP_GRANT:
|
||||||
r = handle_cap_grant(inode, h, session, cap, msg->middle);
|
handle_cap_grant(inode, h, session, cap, msg->middle);
|
||||||
if (r == 1) {
|
goto done_unlocked;
|
||||||
ceph_check_caps(ceph_inode(inode),
|
|
||||||
CHECK_CAPS_NODELAY|CHECK_CAPS_AUTHONLY,
|
|
||||||
session);
|
|
||||||
session = NULL;
|
|
||||||
} else if (r == 2) {
|
|
||||||
ceph_check_caps(ceph_inode(inode),
|
|
||||||
CHECK_CAPS_NODELAY,
|
|
||||||
session);
|
|
||||||
session = NULL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CEPH_CAP_OP_FLUSH_ACK:
|
case CEPH_CAP_OP_FLUSH_ACK:
|
||||||
handle_cap_flush_ack(inode, tid, h, session, cap);
|
handle_cap_flush_ack(inode, tid, h, session, cap);
|
||||||
@@ -2716,11 +2712,8 @@ void ceph_handle_caps(struct ceph_mds_session *session,
|
|||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (session)
|
mutex_unlock(&session->s_mutex);
|
||||||
mutex_unlock(&session->s_mutex);
|
done_unlocked:
|
||||||
|
|
||||||
if (check_caps)
|
|
||||||
ceph_check_caps(ceph_inode(inode), CHECK_CAPS_NODELAY, NULL);
|
|
||||||
if (inode)
|
if (inode)
|
||||||
iput(inode);
|
iput(inode);
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user