From df985c474a05caadcd39e125d9cdda84d34d0dd9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 9 Sep 2009 12:27:46 -0700 Subject: [PATCH] mds: avoid client lookup by using per-connection msgr state --- src/mds/Server.cc | 23 ++++++++++++++++++++--- src/mds/Server.h | 1 + src/mds/SessionMap.h | 9 ++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/mds/Server.cc b/src/mds/Server.cc index b611cd89a930f..911397ec1814f 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -159,11 +159,28 @@ public: } }; +Session *Server::get_session(Message *m) +{ + Session *session = (Session *)m->get_connection()->get_priv(); + if (session) { + dout(20) << "get_session got " << session->inst << " from message" << dendl; + session->put(); // not carry ref + } else { + session = mds->sessionmap.get_session(m->get_source()); + if (session) { + dout(20) << "get_session set " << session->inst << " in connection" << dendl; + m->get_connection()->set_priv(session); + } else { + dout(20) << "get_session " << m->get_source() << " dne" << dendl; + } + } + return session; +} void Server::handle_client_session(MClientSession *m) { version_t pv, piv = 0; - Session *session = mds->sessionmap.get_session(m->get_source()); + Session *session = get_session(m); dout(3) << "handle_client_session " << *m << " from " << m->get_source() << dendl; assert(m->get_source().is_client()); // should _not_ come from an mds! @@ -440,7 +457,7 @@ void Server::handle_client_reconnect(MClientReconnect *m) { dout(7) << "handle_client_reconnect " << m->get_source() << dendl; int from = m->get_source().num(); - Session *session = mds->sessionmap.get_session(m->get_source()); + Session *session = get_session(m); if (!session) { dout(1) << " no session for " << m->get_source() << ", ignoring reconnect, sending close" << dendl; @@ -891,7 +908,7 @@ void Server::handle_client_request(MClientRequest *req) // active session? Session *session = 0; if (req->get_orig_source().is_client()) { - session = mds->sessionmap.get_session(req->get_orig_source()); + session = get_session(req); if (!session) { dout(5) << "no session for " << req->get_orig_source() << ", dropping" << dendl; delete req; diff --git a/src/mds/Server.h b/src/mds/Server.h index 50c5bc706eac1..75e76d206ee5c 100644 --- a/src/mds/Server.h +++ b/src/mds/Server.h @@ -67,6 +67,7 @@ public: utime_t reconnect_start; set client_reconnect_gather; // clients i need a reconnect msg from. + Session *get_session(Message *m); void handle_client_session(class MClientSession *m); void _session_logged(Session *session, bool open, version_t pv, interval_set& inos,version_t piv); void _finish_session_purge(Session *); diff --git a/src/mds/SessionMap.h b/src/mds/SessionMap.h index 7885c888c0c78..f89b54c524a93 100644 --- a/src/mds/SessionMap.h +++ b/src/mds/SessionMap.h @@ -30,13 +30,13 @@ class CInode; class MDRequest; #include "Capability.h" - +#include "msg/Message.h" /* * session */ -class Session { +class Session : public RefCountedObject { // -- state etc -- public: static const int STATE_UNDEF = 0; @@ -146,6 +146,9 @@ public: state(STATE_UNDEF), session_list_item(this), cap_push_seq(0) { } + ~Session() { + assert(!session_list_item.is_on_xlist()); + } void encode(bufferlist& bl) const { __u8 v = 1; @@ -211,7 +214,7 @@ public: s->trim_completed_requests(0); s->session_list_item.remove_myself(); session_map.erase(s->inst.name); - delete s; + s->put(); } void touch_session(Session *session) { by_state[session->state].push_back(&session->session_list_item); -- 2.39.5