Skip to content

Commit 5b3248c

Browse files
lxbszidryomov
authored andcommitted
ceph: rename get_session and switch to use ceph_get_mds_session
Just in case the session's refcount reach 0 and is releasing, and if we get the session without checking it, we may encounter kernel crash. Rename get_session to ceph_get_mds_session and make it global. Signed-off-by: Xiubo Li <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 4fbc0c7 commit 5b3248c

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

fs/ceph/mds_client.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ const char *ceph_session_state_name(int s)
538538
}
539539
}
540540

541-
static struct ceph_mds_session *get_session(struct ceph_mds_session *s)
541+
struct ceph_mds_session *ceph_get_mds_session(struct ceph_mds_session *s)
542542
{
543543
if (refcount_inc_not_zero(&s->s_ref)) {
544544
dout("mdsc get_session %p %d -> %d\n", s,
@@ -569,7 +569,7 @@ struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc,
569569
{
570570
if (mds >= mdsc->max_sessions || !mdsc->sessions[mds])
571571
return NULL;
572-
return get_session(mdsc->sessions[mds]);
572+
return ceph_get_mds_session(mdsc->sessions[mds]);
573573
}
574574

575575
static bool __have_session(struct ceph_mds_client *mdsc, int mds)
@@ -1979,7 +1979,7 @@ void ceph_flush_cap_releases(struct ceph_mds_client *mdsc,
19791979
if (mdsc->stopping)
19801980
return;
19811981

1982-
get_session(session);
1982+
ceph_get_mds_session(session);
19831983
if (queue_work(mdsc->fsc->cap_wq,
19841984
&session->s_cap_release_work)) {
19851985
dout("cap release work queued\n");
@@ -2615,7 +2615,7 @@ static void __do_request(struct ceph_mds_client *mdsc,
26152615
goto finish;
26162616
}
26172617
}
2618-
req->r_session = get_session(session);
2618+
req->r_session = ceph_get_mds_session(session);
26192619

26202620
dout("do_request mds%d session %p state %s\n", mds, session,
26212621
ceph_session_state_name(session->s_state));
@@ -3139,7 +3139,7 @@ static void handle_session(struct ceph_mds_session *session,
31393139

31403140
mutex_lock(&mdsc->mutex);
31413141
if (op == CEPH_SESSION_CLOSE) {
3142-
get_session(session);
3142+
ceph_get_mds_session(session);
31433143
__unregister_session(mdsc, session);
31443144
}
31453145
/* FIXME: this ttl calculation is generous */
@@ -3801,7 +3801,7 @@ static void check_new_map(struct ceph_mds_client *mdsc,
38013801

38023802
if (i >= newmap->possible_max_rank) {
38033803
/* force close session for stopped mds */
3804-
get_session(s);
3804+
ceph_get_mds_session(s);
38053805
__unregister_session(mdsc, s);
38063806
__wake_requests(mdsc, &s->s_waiting);
38073807
mutex_unlock(&mdsc->mutex);
@@ -4402,7 +4402,7 @@ void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc)
44024402
mutex_lock(&mdsc->mutex);
44034403
for (i = 0; i < mdsc->max_sessions; i++) {
44044404
if (mdsc->sessions[i]) {
4405-
session = get_session(mdsc->sessions[i]);
4405+
session = ceph_get_mds_session(mdsc->sessions[i]);
44064406
__unregister_session(mdsc, session);
44074407
mutex_unlock(&mdsc->mutex);
44084408
mutex_lock(&session->s_mutex);
@@ -4630,7 +4630,7 @@ static struct ceph_connection *con_get(struct ceph_connection *con)
46304630
{
46314631
struct ceph_mds_session *s = con->private;
46324632

4633-
if (get_session(s))
4633+
if (ceph_get_mds_session(s))
46344634
return con;
46354635
return NULL;
46364636
}

fs/ceph/mds_client.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,10 @@ extern const char *ceph_mds_op_name(int op);
452452
extern struct ceph_mds_session *
453453
__ceph_lookup_mds_session(struct ceph_mds_client *, int mds);
454454

455-
static inline struct ceph_mds_session *
456-
ceph_get_mds_session(struct ceph_mds_session *s)
457-
{
458-
refcount_inc(&s->s_ref);
459-
return s;
460-
}
461-
462455
extern const char *ceph_session_state_name(int s);
463456

457+
extern struct ceph_mds_session *
458+
ceph_get_mds_session(struct ceph_mds_session *s);
464459
extern void ceph_put_mds_session(struct ceph_mds_session *s);
465460

466461
extern int ceph_send_msg_mds(struct ceph_mds_client *mdsc,

0 commit comments

Comments
 (0)