]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
kclient: avoid session lookup in mdsc
authorSage Weil <sage@newdream.net>
Thu, 27 Aug 2009 22:52:50 +0000 (15:52 -0700)
committerSage Weil <sage@newdream.net>
Thu, 27 Aug 2009 22:52:50 +0000 (15:52 -0700)
src/kernel/caps.c
src/kernel/mds_client.c
src/kernel/super.h

index 79ad8a94c134627fcc6fe3b909cd6e954e48691a..8bef8b05ef82f1ee7a5ebed10c6396fc88388bc7 100644 (file)
@@ -2507,11 +2507,11 @@ static void handle_cap_import(struct ceph_mds_client *mdsc,
  * Identify the appropriate session, inode, and call the right handler
  * based on the cap op.
  */
-void ceph_handle_caps(struct ceph_mds_client *mdsc,
+void ceph_handle_caps(struct ceph_mds_session *session,
                      struct ceph_msg *msg)
 {
+       struct ceph_mds_client *mdsc = session->s_mdsc;
        struct super_block *sb = mdsc->client->sb;
-       struct ceph_mds_session *session;
        struct inode *inode;
        struct ceph_cap *cap;
        struct ceph_mds_caps *h;
@@ -2538,15 +2538,6 @@ void ceph_handle_caps(struct ceph_mds_client *mdsc,
        size = le64_to_cpu(h->size);
        max_size = le64_to_cpu(h->max_size);
 
-       /* find session */
-       mutex_lock(&mdsc->mutex);
-       session = __ceph_lookup_mds_session(mdsc, mds);
-       mutex_unlock(&mdsc->mutex);
-       if (!session) {
-               dout("WTF, got cap but no session for mds%d\n", mds);
-               return;
-       }
-
        mutex_lock(&session->s_mutex);
        session->s_seq++;
        dout(" mds%d seq %lld cap seq %u\n", session->s_mds, session->s_seq,
index ede54022de958e6fe82575979141d3b5bbd05808..c365cd355747105f276ea88c8e5b7832c42d094f 100644 (file)
@@ -1629,8 +1629,9 @@ int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
  * This preserves the logical ordering of replies, capabilities, etc., sent
  * by the MDS as they are applied to our local cache.
  */
-static void handle_reply(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
+static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
 {
+       struct ceph_mds_client *mdsc = session->s_mdsc;
        struct ceph_mds_request *req;
        struct ceph_mds_reply_head *head = msg->front.iov_base;
        struct ceph_mds_reply_info_parsed *rinfo;  /* parsed reply info */
@@ -1657,6 +1658,15 @@ static void handle_reply(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
        dout("handle_reply %p\n", req);
        mds = le32_to_cpu(msg->hdr.src.name.num);
 
+       /* correct session? */
+       if (!req->r_session && req->r_session != session) {
+               pr_err("ceph_mdsc_handle_reply got %llu on session mds%d"
+                      " not mds%d\n", tid, session->s_mds,
+                      req->r_session ? req->r_session->s_mds : -1);
+               mutex_unlock(&mdsc->mutex);
+               goto out;
+       }
+
        /* dup? */
        if ((req->r_got_unsafe && !head->safe) ||
            (req->r_got_safe && head->safe)) {
@@ -1691,16 +1701,6 @@ static void handle_reply(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
                }
        }
 
-       if (req->r_session && req->r_session->s_mds != mds) {
-               ceph_put_mds_session(req->r_session);
-               req->r_session = __ceph_lookup_mds_session(mdsc, mds);
-       }
-       if (req->r_session == NULL) {
-               pr_err("ceph_mdsc_handle_reply got %llu, but no session for"
-                      " mds%d\n", tid, mds);
-               mutex_unlock(&mdsc->mutex);
-               goto out;
-       }
        BUG_ON(req->r_reply);
 
        if (!head->safe) {
@@ -1710,7 +1710,7 @@ static void handle_reply(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
 
        mutex_unlock(&mdsc->mutex);
 
-       mutex_lock(&req->r_session->s_mutex);
+       mutex_lock(&session->s_mutex);
 
        /* parse */
        rinfo = &req->r_reply_info;
@@ -1770,7 +1770,7 @@ out_err:
        }
 
        add_cap_releases(mdsc, req->r_session, -1);
-       mutex_unlock(&req->r_session->s_mutex);
+       mutex_unlock(&session->s_mutex);
 
        /* kick calling process */
        complete_request(mdsc, req);
@@ -1850,11 +1850,12 @@ bad:
 /*
  * handle a mds session control message
  */
-static void handle_session(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
+static void handle_session(struct ceph_mds_session *session,
+                          struct ceph_msg *msg)
 {
+       struct ceph_mds_client *mdsc = session->s_mdsc;
        u32 op;
        u64 seq;
-       struct ceph_mds_session *session = NULL;
        int mds;
        struct ceph_mds_session_head *h = msg->front.iov_base;
        int wake = 0;
@@ -1870,20 +1871,9 @@ static void handle_session(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
        seq = le64_to_cpu(h->seq);
 
        mutex_lock(&mdsc->mutex);
-       session = __ceph_lookup_mds_session(mdsc, mds);
-       if (session && mdsc->mdsmap)
-               /* FIXME: this ttl calculation is generous */
-               session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose;
-       mutex_unlock(&mdsc->mutex);
-
-       if (!session) {
-               if (op != CEPH_SESSION_OPEN) {
-                       dout("handle_session no session for mds%d\n", mds);
-                       return;
-               }
-               dout("handle_session creating session for mds%d\n", mds);
-               session = register_session(mdsc, mds);
-       }
+       /* FIXME: this ttl calculation is generous */
+       session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose;
+       mutex_unlock(&mdsc->mutex);     
 
        mutex_lock(&session->s_mutex);
 
@@ -1942,7 +1932,6 @@ static void handle_session(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
                __wake_requests(mdsc, &session->s_waiting);
                mutex_unlock(&mdsc->mutex);
        }
-       ceph_put_mds_session(session);
        return;
 
 bad:
@@ -2896,16 +2885,16 @@ static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
                ceph_mdsc_handle_map(mdsc, msg);
                break;
        case CEPH_MSG_CLIENT_SESSION:
-               handle_session(mdsc, msg);
+               handle_session(s, msg);
                break;
        case CEPH_MSG_CLIENT_REPLY:
-               handle_reply(mdsc, msg);
+               handle_reply(s, msg);
                break;
        case CEPH_MSG_CLIENT_REQUEST_FORWARD:
                handle_forward(mdsc, msg);
                break;
        case CEPH_MSG_CLIENT_CAPS:
-               ceph_handle_caps(mdsc, msg);
+               ceph_handle_caps(s, msg);
                break;
        case CEPH_MSG_CLIENT_SNAP:
                ceph_handle_snap(mdsc, msg);
index ddde2b0f75bf8f84b18b962f64d1206271c7070b..8a12f9eb275ecbbe052fc9f2947b727ac745b820 100644 (file)
@@ -842,7 +842,7 @@ extern void __ceph_build_xattrs_blob(struct ceph_inode_info *ci);
 
 /* caps.c */
 extern const char *ceph_cap_string(int c);
-extern void ceph_handle_caps(struct ceph_mds_client *mdsc,
+extern void ceph_handle_caps(struct ceph_mds_session *session,
                             struct ceph_msg *msg);
 extern int ceph_add_cap(struct inode *inode,
                        struct ceph_mds_session *session, u64 cap_id,