提交 5b3248c6 编写于 作者: X Xiubo Li 提交者: Ilya Dryomov

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: NXiubo Li <xiubli@redhat.com>
Reviewed-by: NJeff Layton <jlayton@kernel.org>
Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
上级 4fbc0c71
...@@ -538,7 +538,7 @@ const char *ceph_session_state_name(int s) ...@@ -538,7 +538,7 @@ const char *ceph_session_state_name(int s)
} }
} }
static struct ceph_mds_session *get_session(struct ceph_mds_session *s) struct ceph_mds_session *ceph_get_mds_session(struct ceph_mds_session *s)
{ {
if (refcount_inc_not_zero(&s->s_ref)) { if (refcount_inc_not_zero(&s->s_ref)) {
dout("mdsc get_session %p %d -> %d\n", s, 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, ...@@ -569,7 +569,7 @@ struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc,
{ {
if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) if (mds >= mdsc->max_sessions || !mdsc->sessions[mds])
return NULL; return NULL;
return get_session(mdsc->sessions[mds]); return ceph_get_mds_session(mdsc->sessions[mds]);
} }
static bool __have_session(struct ceph_mds_client *mdsc, int mds) 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, ...@@ -1979,7 +1979,7 @@ void ceph_flush_cap_releases(struct ceph_mds_client *mdsc,
if (mdsc->stopping) if (mdsc->stopping)
return; return;
get_session(session); ceph_get_mds_session(session);
if (queue_work(mdsc->fsc->cap_wq, if (queue_work(mdsc->fsc->cap_wq,
&session->s_cap_release_work)) { &session->s_cap_release_work)) {
dout("cap release work queued\n"); dout("cap release work queued\n");
...@@ -2615,7 +2615,7 @@ static void __do_request(struct ceph_mds_client *mdsc, ...@@ -2615,7 +2615,7 @@ static void __do_request(struct ceph_mds_client *mdsc,
goto finish; goto finish;
} }
} }
req->r_session = get_session(session); req->r_session = ceph_get_mds_session(session);
dout("do_request mds%d session %p state %s\n", mds, session, dout("do_request mds%d session %p state %s\n", mds, session,
ceph_session_state_name(session->s_state)); ceph_session_state_name(session->s_state));
...@@ -3139,7 +3139,7 @@ static void handle_session(struct ceph_mds_session *session, ...@@ -3139,7 +3139,7 @@ static void handle_session(struct ceph_mds_session *session,
mutex_lock(&mdsc->mutex); mutex_lock(&mdsc->mutex);
if (op == CEPH_SESSION_CLOSE) { if (op == CEPH_SESSION_CLOSE) {
get_session(session); ceph_get_mds_session(session);
__unregister_session(mdsc, session); __unregister_session(mdsc, session);
} }
/* FIXME: this ttl calculation is generous */ /* FIXME: this ttl calculation is generous */
...@@ -3801,7 +3801,7 @@ static void check_new_map(struct ceph_mds_client *mdsc, ...@@ -3801,7 +3801,7 @@ static void check_new_map(struct ceph_mds_client *mdsc,
if (i >= newmap->possible_max_rank) { if (i >= newmap->possible_max_rank) {
/* force close session for stopped mds */ /* force close session for stopped mds */
get_session(s); ceph_get_mds_session(s);
__unregister_session(mdsc, s); __unregister_session(mdsc, s);
__wake_requests(mdsc, &s->s_waiting); __wake_requests(mdsc, &s->s_waiting);
mutex_unlock(&mdsc->mutex); mutex_unlock(&mdsc->mutex);
...@@ -4402,7 +4402,7 @@ void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc) ...@@ -4402,7 +4402,7 @@ void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc)
mutex_lock(&mdsc->mutex); mutex_lock(&mdsc->mutex);
for (i = 0; i < mdsc->max_sessions; i++) { for (i = 0; i < mdsc->max_sessions; i++) {
if (mdsc->sessions[i]) { if (mdsc->sessions[i]) {
session = get_session(mdsc->sessions[i]); session = ceph_get_mds_session(mdsc->sessions[i]);
__unregister_session(mdsc, session); __unregister_session(mdsc, session);
mutex_unlock(&mdsc->mutex); mutex_unlock(&mdsc->mutex);
mutex_lock(&session->s_mutex); mutex_lock(&session->s_mutex);
...@@ -4630,7 +4630,7 @@ static struct ceph_connection *con_get(struct ceph_connection *con) ...@@ -4630,7 +4630,7 @@ static struct ceph_connection *con_get(struct ceph_connection *con)
{ {
struct ceph_mds_session *s = con->private; struct ceph_mds_session *s = con->private;
if (get_session(s)) if (ceph_get_mds_session(s))
return con; return con;
return NULL; return NULL;
} }
......
...@@ -452,15 +452,10 @@ extern const char *ceph_mds_op_name(int op); ...@@ -452,15 +452,10 @@ extern const char *ceph_mds_op_name(int op);
extern struct ceph_mds_session * extern struct ceph_mds_session *
__ceph_lookup_mds_session(struct ceph_mds_client *, int mds); __ceph_lookup_mds_session(struct ceph_mds_client *, int mds);
static inline struct ceph_mds_session *
ceph_get_mds_session(struct ceph_mds_session *s)
{
refcount_inc(&s->s_ref);
return s;
}
extern const char *ceph_session_state_name(int s); extern const char *ceph_session_state_name(int s);
extern struct ceph_mds_session *
ceph_get_mds_session(struct ceph_mds_session *s);
extern void ceph_put_mds_session(struct ceph_mds_session *s); extern void ceph_put_mds_session(struct ceph_mds_session *s);
extern int ceph_send_msg_mds(struct ceph_mds_client *mdsc, extern int ceph_send_msg_mds(struct ceph_mds_client *mdsc,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册