Whamcloud - gitweb
LU-7734 lnet: cpt locking
[fs/lustre-release.git] / lustre / ptlrpc / niobuf.c
index 7c841a2..268965f 100644 (file)
  * Returns 0 on success or error code.
  */
 static int ptl_send_buf(lnet_handle_md_t *mdh, void *base, int len,
-                        lnet_ack_req_t ack, struct ptlrpc_cb_id *cbid,
+                       lnet_ack_req_t ack, struct ptlrpc_cb_id *cbid,
                        lnet_nid_t self, lnet_process_id_t peer_id,
-                        int portal, __u64 xid, unsigned int offset)
+                       int portal, __u64 xid, unsigned int offset,
+                       lnet_handle_md_t *bulk_cookie)
 {
-        int              rc;
-        lnet_md_t         md;
-        ENTRY;
+       int              rc;
+       lnet_md_t         md;
+       ENTRY;
 
-        LASSERT (portal != 0);
-        CDEBUG (D_INFO, "peer_id %s\n", libcfs_id2str(peer_id));
-        md.start     = base;
-        md.length    = len;
-        md.threshold = (ack == LNET_ACK_REQ) ? 2 : 1;
-        md.options   = PTLRPC_MD_OPTIONS;
-        md.user_ptr  = cbid;
-        md.eq_handle = ptlrpc_eq_h;
+       LASSERT (portal != 0);
+       CDEBUG (D_INFO, "peer_id %s\n", libcfs_id2str(peer_id));
+       md.start     = base;
+       md.length    = len;
+       md.threshold = (ack == LNET_ACK_REQ) ? 2 : 1;
+       md.options   = PTLRPC_MD_OPTIONS;
+       md.user_ptr  = cbid;
+       md.eq_handle = ptlrpc_eq_h;
+       LNetInvalidateHandle(&md.bulk_handle);
 
-        if (unlikely(ack == LNET_ACK_REQ &&
-                     OBD_FAIL_CHECK_ORSET(OBD_FAIL_PTLRPC_ACK, OBD_FAIL_ONCE))){
-                /* don't ask for the ack to simulate failing client */
-                ack = LNET_NOACK_REQ;
-        }
+       if (bulk_cookie) {
+               md.bulk_handle = *bulk_cookie;
+               md.options |= LNET_MD_BULK_HANDLE;
+       }
 
-        rc = LNetMDBind (md, LNET_UNLINK, mdh);
-        if (unlikely(rc != 0)) {
-                CERROR ("LNetMDBind failed: %d\n", rc);
-                LASSERT (rc == -ENOMEM);
-                RETURN (-ENOMEM);
-        }
+       if (unlikely(ack == LNET_ACK_REQ &&
+                    OBD_FAIL_CHECK_ORSET(OBD_FAIL_PTLRPC_ACK, OBD_FAIL_ONCE))){
+               /* don't ask for the ack to simulate failing client */
+               ack = LNET_NOACK_REQ;
+       }
+
+       rc = LNetMDBind (md, LNET_UNLINK, mdh);
+       if (unlikely(rc != 0)) {
+               CERROR ("LNetMDBind failed: %d\n", rc);
+               LASSERT (rc == -ENOMEM);
+               RETURN (-ENOMEM);
+       }
 
        CDEBUG(D_NET, "Sending %d bytes to portal %d, xid %lld, offset %u\n",
-               len, portal, xid, offset);
-
-        rc = LNetPut(self, *mdh, ack,
-                     peer_id, portal, xid, offset, 0);
-        if (unlikely(rc != 0)) {
-                int rc2;
-                /* We're going to get an UNLINK event when I unlink below,
-                 * which will complete just like any other failed send, so
-                 * I fall through and return success here! */
+              len, portal, xid, offset);
+
+       rc = LNetPut(self, *mdh, ack,
+                    peer_id, portal, xid, offset, 0);
+       if (unlikely(rc != 0)) {
+               int rc2;
+               /* We're going to get an UNLINK event when I unlink below,
+                * which will complete just like any other failed send, so
+                * I fall through and return success here! */
                CERROR("LNetPut(%s, %d, %lld) failed: %d\n",
                       libcfs_id2str(peer_id), portal, xid, rc);
-                rc2 = LNetMDUnlink(*mdh);
-                LASSERTF(rc2 == 0, "rc2 = %d\n", rc2);
-        }
+               rc2 = LNetMDUnlink(*mdh);
+               LASSERTF(rc2 == 0, "rc2 = %d\n", rc2);
+       }
 
-        RETURN (0);
+       RETURN (0);
 }
 
 static void mdunlink_iterate_helper(lnet_handle_md_t *bd_mds, int count)
@@ -545,9 +552,9 @@ static void ptlrpc_at_set_reply(struct ptlrpc_request *req, int flags)
  */
 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags)
 {
-        struct ptlrpc_reply_state *rs = req->rq_reply_state;
-        struct ptlrpc_connection  *conn;
-        int                        rc;
+       struct ptlrpc_reply_state *rs = req->rq_reply_state;
+       struct ptlrpc_connection  *conn;
+       int                        rc;
 
         /* We must already have a reply buffer (only ptlrpc_error() may be
          * called without one). The reply generated by sptlrpc layer (e.g.
@@ -616,12 +623,12 @@ int ptlrpc_send_reply(struct ptlrpc_request *req, int flags)
 
         req->rq_sent = cfs_time_current_sec();
 
-        rc = ptl_send_buf(&rs->rs_md_h, rs->rs_repbuf, rs->rs_repdata_len,
-                          (rs->rs_difficult && !rs->rs_no_ack) ?
-                          LNET_ACK_REQ : LNET_NOACK_REQ,
+       rc = ptl_send_buf(&rs->rs_md_h, rs->rs_repbuf, rs->rs_repdata_len,
+                         (rs->rs_difficult && !rs->rs_no_ack) ?
+                         LNET_ACK_REQ : LNET_NOACK_REQ,
                          &rs->rs_cb_id, req->rq_self, req->rq_source,
                          ptlrpc_req2svc(req)->srv_rep_portal,
-                          req->rq_xid, req->rq_reply_off);
+                         req->rq_xid, req->rq_reply_off, NULL);
 out:
         if (unlikely(rc != 0))
                 ptlrpc_req_drop_rs(req);
@@ -677,15 +684,18 @@ int ptlrpc_error(struct ptlrpc_request *req)
  */
 int ptl_send_rpc(struct ptlrpc_request *request, int noreply)
 {
-        int rc;
-        int rc2;
-        int mpflag = 0;
-        struct ptlrpc_connection *connection;
-        lnet_handle_me_t  reply_me_h;
-        lnet_md_t         reply_md;
+       int rc;
+       int rc2;
+       int mpflag = 0;
+       lnet_handle_md_t bulk_cookie;
+       struct ptlrpc_connection *connection;
+       lnet_handle_me_t  reply_me_h;
+       lnet_md_t         reply_md;
        struct obd_import *imp = request->rq_import;
        struct obd_device *obd = imp->imp_obd;
-        ENTRY;
+       ENTRY;
+
+       LNetInvalidateHandle(&bulk_cookie);
 
         if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_DROP_RPC))
                 RETURN(0);
@@ -775,12 +785,18 @@ int ptl_send_rpc(struct ptlrpc_request *request, int noreply)
        if (rc)
                GOTO(out, rc);
 
-        /* bulk register should be done after wrap_request() */
-        if (request->rq_bulk != NULL) {
-                rc = ptlrpc_register_bulk (request);
-                if (rc != 0)
-                        GOTO(out, rc);
-        }
+       /* bulk register should be done after wrap_request() */
+       if (request->rq_bulk != NULL) {
+               rc = ptlrpc_register_bulk (request);
+               if (rc != 0)
+                       GOTO(out, rc);
+               /*
+                * All the mds in the request will have the same cpt
+                * encoded in the cookie. So we can just get the first
+                * one.
+                */
+               bulk_cookie = request->rq_bulk->bd_mds[0];
+       }
 
         if (!noreply) {
                 LASSERT (request->rq_replen != 0);
@@ -877,14 +893,14 @@ int ptl_send_rpc(struct ptlrpc_request *request, int noreply)
 
        ptlrpc_pinger_sending_on_import(imp);
 
-        DEBUG_REQ(D_INFO, request, "send flg=%x",
-                  lustre_msg_get_flags(request->rq_reqmsg));
-        rc = ptl_send_buf(&request->rq_req_md_h,
-                          request->rq_reqbuf, request->rq_reqdata_len,
-                          LNET_NOACK_REQ, &request->rq_req_cbid,
+       DEBUG_REQ(D_INFO, request, "send flg=%x",
+                 lustre_msg_get_flags(request->rq_reqmsg));
+       rc = ptl_send_buf(&request->rq_req_md_h,
+                         request->rq_reqbuf, request->rq_reqdata_len,
+                         LNET_NOACK_REQ, &request->rq_req_cbid,
                          LNET_NID_ANY, connection->c_peer,
-                          request->rq_request_portal,
-                          request->rq_xid, 0);
+                         request->rq_request_portal,
+                         request->rq_xid, 0, &bulk_cookie);
        if (likely(rc == 0))
                GOTO(out, rc);