Skip to content

Commit c4853e9

Browse files
xiubliidryomov
authored andcommitted
ceph: retry the same mds later after the new session is opened
If max_mds > 1 and a request is submitted that chooses a random mds rank, and the relating session is not opened yet, the request will wait until the session has been opened and resend again. Every time the request goes through __do_request, it will release the req->session first and choose a random one again, which may be a completely different rank than the one it just waited on. In the worst case, it will open all the mds sessions one by one just before the request can be successfully sent out. Signed-off-by: Xiubo Li <xiubli@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 9782005 commit c4853e9

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎fs/ceph/mds_client.c‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,8 @@ static struct inode *get_nonsnap_parent(struct dentry *dentry)
878878
* Called under mdsc->mutex.
879879
*/
880880
static int __choose_mds(struct ceph_mds_client *mdsc,
881-
struct ceph_mds_request *req)
881+
struct ceph_mds_request *req,
882+
bool *random)
882883
{
883884
struct inode *inode;
884885
struct ceph_inode_info *ci;
@@ -888,6 +889,9 @@ static int __choose_mds(struct ceph_mds_client *mdsc,
888889
u32 hash = req->r_direct_hash;
889890
bool is_hash = test_bit(CEPH_MDS_R_DIRECT_IS_HASH, &req->r_req_flags);
890891

892+
if (random)
893+
*random = false;
894+
891895
/*
892896
* is there a specific mds we should try? ignore hint if we have
893897
* no session and the mds is not up (active or recovering).
@@ -1023,6 +1027,9 @@ static int __choose_mds(struct ceph_mds_client *mdsc,
10231027
return mds;
10241028

10251029
random:
1030+
if (random)
1031+
*random = true;
1032+
10261033
mds = ceph_mdsmap_get_random_mds(mdsc->mdsmap);
10271034
dout("choose_mds chose random mds%d\n", mds);
10281035
return mds;
@@ -2551,6 +2558,7 @@ static void __do_request(struct ceph_mds_client *mdsc,
25512558
struct ceph_mds_session *session = NULL;
25522559
int mds = -1;
25532560
int err = 0;
2561+
bool random;
25542562

25552563
if (req->r_err || test_bit(CEPH_MDS_R_GOT_RESULT, &req->r_req_flags)) {
25562564
if (test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags))
@@ -2590,7 +2598,7 @@ static void __do_request(struct ceph_mds_client *mdsc,
25902598

25912599
put_request_session(req);
25922600

2593-
mds = __choose_mds(mdsc, req);
2601+
mds = __choose_mds(mdsc, req, &random);
25942602
if (mds < 0 ||
25952603
ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) {
25962604
dout("do_request no mds or not active, waiting for map\n");
@@ -2618,8 +2626,12 @@ static void __do_request(struct ceph_mds_client *mdsc,
26182626
goto out_session;
26192627
}
26202628
if (session->s_state == CEPH_MDS_SESSION_NEW ||
2621-
session->s_state == CEPH_MDS_SESSION_CLOSING)
2629+
session->s_state == CEPH_MDS_SESSION_CLOSING) {
26222630
__open_session(mdsc, session);
2631+
/* retry the same mds later */
2632+
if (random)
2633+
req->r_resend_mds = mds;
2634+
}
26232635
list_add(&req->r_wait, &session->s_waiting);
26242636
goto out_session;
26252637
}
@@ -2883,7 +2895,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
28832895
mutex_unlock(&mdsc->mutex);
28842896
goto out;
28852897
} else {
2886-
int mds = __choose_mds(mdsc, req);
2898+
int mds = __choose_mds(mdsc, req, NULL);
28872899
if (mds >= 0 && mds != req->r_session->s_mds) {
28882900
dout("but auth changed, so resending\n");
28892901
__do_request(mdsc, req);

0 commit comments

Comments
 (0)