Whamcloud - gitweb
LU-13004 ptlrpc: Allow BULK_BUF_KIOV to accept a kvec
[fs/lustre-release.git] / lustre / ptlrpc / events.c
index 03d514e..660a05c 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2015, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #include <libcfs/libcfs.h>
 #include <linux/kernel.h>
+#include <linux/delay.h>
 #include <obd_class.h>
 #include <lustre_net.h>
 #include <lustre_sec.h>
 #include "ptlrpc_internal.h"
 
-lnet_handle_eq_t   ptlrpc_eq_h;
+struct lnet_handle_eq ptlrpc_eq_h;
 
 /*
  *  Client's outgoing request callback
  */
-void request_out_callback(lnet_event_t *ev)
+void request_out_callback(struct lnet_event *ev)
 {
        struct ptlrpc_cb_id   *cbid = ev->md.user_ptr;
        struct ptlrpc_request *req = cbid->cbid_arg;
@@ -63,7 +60,7 @@ void request_out_callback(lnet_event_t *ev)
        sptlrpc_request_out_callback(req);
 
        spin_lock(&req->rq_lock);
-       req->rq_real_sent = cfs_time_current_sec();
+       req->rq_real_sent = ktime_get_real_seconds();
        req->rq_req_unlinked = 1;
        /* reply_in_callback happened before request_out_callback? */
        if (req->rq_reply_unlinked)
@@ -88,7 +85,7 @@ void request_out_callback(lnet_event_t *ev)
 /*
  * Client's incoming reply callback
  */
-void reply_in_callback(lnet_event_t *ev)
+void reply_in_callback(struct lnet_event *ev)
 {
         struct ptlrpc_cb_id   *cbid = ev->md.user_ptr;
         struct ptlrpc_request *req = cbid->cbid_arg;
@@ -129,15 +126,15 @@ void reply_in_callback(lnet_event_t *ev)
                 goto out_wake;
         }
 
-        if ((ev->offset == 0) &&
-            ((lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))) {
-                /* Early reply */
-                DEBUG_REQ(D_ADAPTTO, req,
-                          "Early reply received: mlen=%u offset=%d replen=%d "
-                          "replied=%d unlinked=%d", ev->mlength, ev->offset,
-                          req->rq_replen, req->rq_replied, ev->unlinked);
+       if ((ev->offset == 0) &&
+           ((lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))) {
+               /* Early reply */
+               DEBUG_REQ(D_ADAPTTO, req,
+                         "Early reply received, mlen=%u offset=%d replen=%d replied=%d unlinked=%d",
+                         ev->mlength, ev->offset,
+                         req->rq_replen, req->rq_replied, ev->unlinked);
 
-                req->rq_early_count++; /* number received, client side */
+               req->rq_early_count++; /* number received, client side */
 
                /* already got the real reply or buffers are already unlinked */
                if (req->rq_replied ||
@@ -165,12 +162,13 @@ void reply_in_callback(lnet_event_t *ev)
                           ev->mlength, ev->offset, req->rq_replen);
         }
 
-        req->rq_import->imp_last_reply_time = cfs_time_current_sec();
+       if (lustre_msg_get_opc(req->rq_reqmsg) != OBD_PING)
+               req->rq_import->imp_last_reply_time = ktime_get_real_seconds();
 
 out_wake:
-        /* NB don't unlock till after wakeup; req can disappear under us
-         * since we don't have our own ref */
-        ptlrpc_client_wake_req(req);
+       /* NB don't unlock till after wakeup; req can disappear under us
+        * since we don't have our own ref */
+       ptlrpc_client_wake_req(req);
        spin_unlock(&req->rq_lock);
        EXIT;
 }
@@ -178,7 +176,7 @@ out_wake:
 /*
  * Client's bulk has been written/read
  */
-void client_bulk_callback (lnet_event_t *ev)
+void client_bulk_callback(struct lnet_event *ev)
 {
         struct ptlrpc_cb_id     *cbid = ev->md.user_ptr;
         struct ptlrpc_bulk_desc *desc = cbid->cbid_arg;
@@ -254,9 +252,9 @@ void client_bulk_callback (lnet_event_t *ev)
 static void ptlrpc_req_add_history(struct ptlrpc_service_part *svcpt,
                                   struct ptlrpc_request *req)
 {
-       __u64   sec = req->rq_arrival_time.tv_sec;
-       __u32   usec = req->rq_arrival_time.tv_usec >> 4; /* usec / 16 */
-       __u64   new_seq;
+       u64 sec = req->rq_arrival_time.tv_sec;
+       u32 usec = req->rq_arrival_time.tv_nsec / NSEC_PER_USEC / 16; /* usec / 16 */
+       u64 new_seq;
 
        /* set sequence ID for request and add it to history list,
         * it must be called with hold svcpt::scp_lock */
@@ -288,7 +286,7 @@ static void ptlrpc_req_add_history(struct ptlrpc_service_part *svcpt,
 /*
  * Server's incoming request callback
  */
-void request_in_callback(lnet_event_t *ev)
+void request_in_callback(struct lnet_event *ev)
 {
        struct ptlrpc_cb_id               *cbid = ev->md.user_ptr;
        struct ptlrpc_request_buffer_desc *rqbd = cbid->cbid_arg;
@@ -339,8 +337,10 @@ void request_in_callback(lnet_event_t *ev)
        req->rq_reqbuf = ev->md.start + ev->offset;
        if (ev->type == LNET_EVENT_PUT && ev->status == 0)
                req->rq_reqdata_len = ev->mlength;
-       do_gettimeofday(&req->rq_arrival_time);
+       ktime_get_real_ts64(&req->rq_arrival_time);
+       /* Multi-Rail: keep track of both initiator and source NID. */
        req->rq_peer = ev->initiator;
+       req->rq_source = ev->source;
        req->rq_self = ev->target.nid;
        req->rq_rqbd = rqbd;
        req->rq_phase = RQ_PHASE_NEW;
@@ -348,7 +348,8 @@ void request_in_callback(lnet_event_t *ev)
                CDEBUG(D_INFO, "incoming req@%p x%llu msgsize %u\n",
                       req, req->rq_xid, ev->mlength);
 
-       CDEBUG(D_RPCTRACE, "peer: %s\n", libcfs_id2str(req->rq_peer));
+       CDEBUG(D_RPCTRACE, "peer: %s (source: %s)\n",
+               libcfs_id2str(req->rq_peer), libcfs_id2str(req->rq_source));
 
        spin_lock(&svcpt->scp_lock);
 
@@ -387,7 +388,7 @@ void request_in_callback(lnet_event_t *ev)
 /*
  *  Server's outgoing reply callback
  */
-void reply_out_callback(lnet_event_t *ev)
+void reply_out_callback(struct lnet_event *ev)
 {
        struct ptlrpc_cb_id       *cbid = ev->md.user_ptr;
        struct ptlrpc_reply_state *rs = cbid->cbid_arg;
@@ -418,7 +419,8 @@ void reply_out_callback(lnet_event_t *ev)
                rs->rs_on_net = 0;
                if (!rs->rs_no_ack ||
                    rs->rs_transno <=
-                   rs->rs_export->exp_obd->obd_last_committed)
+                   rs->rs_export->exp_obd->obd_last_committed ||
+                   list_empty(&rs->rs_obd_list))
                        ptlrpc_schedule_difficult_reply(rs);
 
                spin_unlock(&rs->rs_lock);
@@ -431,7 +433,7 @@ void reply_out_callback(lnet_event_t *ev)
 /*
  * Server's bulk completion callback
  */
-void server_bulk_callback (lnet_event_t *ev)
+void server_bulk_callback(struct lnet_event *ev)
 {
        struct ptlrpc_cb_id     *cbid = ev->md.user_ptr;
        struct ptlrpc_bulk_desc *desc = cbid->cbid_arg;
@@ -477,10 +479,10 @@ void server_bulk_callback (lnet_event_t *ev)
 }
 #endif
 
-static void ptlrpc_master_callback(lnet_event_t *ev)
+static void ptlrpc_master_callback(struct lnet_event *ev)
 {
         struct ptlrpc_cb_id *cbid = ev->md.user_ptr;
-        void (*callback)(lnet_event_t *ev) = cbid->cbid_fn;
+       void (*callback)(struct lnet_event *ev) = cbid->cbid_fn;
 
         /* Honestly, it's best to find out early. */
         LASSERT (cbid->cbid_arg != LP_POISON);
@@ -497,52 +499,54 @@ static void ptlrpc_master_callback(lnet_event_t *ev)
         callback (ev);
 }
 
-int ptlrpc_uuid_to_peer (struct obd_uuid *uuid,
-                         lnet_process_id_t *peer, lnet_nid_t *self)
+int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
+                       struct lnet_process_id *peer, lnet_nid_t *self)
 {
-        int               best_dist = 0;
-        __u32             best_order = 0;
-        int               count = 0;
-        int               rc = -ENOENT;
-        int               dist;
-        __u32             order;
-        lnet_nid_t        dst_nid;
-        lnet_nid_t        src_nid;
+       int               best_dist = 0;
+       __u32             best_order = 0;
+       int               count = 0;
+       int               rc = -ENOENT;
+       int               dist;
+       __u32             order;
+       lnet_nid_t        dst_nid;
+       lnet_nid_t        src_nid;
 
        peer->pid = LNET_PID_LUSTRE;
 
-        /* Choose the matching UUID that's closest */
-        while (lustre_uuid_to_peer(uuid->uuid, &dst_nid, count++) == 0) {
-                dist = LNetDist(dst_nid, &src_nid, &order);
-                if (dist < 0)
-                        continue;
+       /* Choose the matching UUID that's closest */
+       while (lustre_uuid_to_peer(uuid->uuid, &dst_nid, count++) == 0) {
+               if (peer->nid != LNET_NID_ANY && LNET_NIDADDR(peer->nid) == 0 &&
+                   LNET_NIDNET(dst_nid) != LNET_NIDNET(peer->nid))
+                       continue;
 
-                if (dist == 0) {                /* local! use loopback LND */
-                        peer->nid = *self = LNET_MKNID(LNET_MKNET(LOLND, 0), 0);
-                        rc = 0;
-                        break;
-                }
+               dist = LNetDist(dst_nid, &src_nid, &order);
+               if (dist < 0)
+                       continue;
 
-                if (rc < 0 ||
-                    dist < best_dist ||
-                    (dist == best_dist && order < best_order)) {
-                        best_dist = dist;
-                        best_order = order;
+               if (dist == 0) {                /* local! use loopback LND */
+                       peer->nid = *self = LNET_MKNID(LNET_MKNET(LOLND, 0), 0);
+                       rc = 0;
+                       break;
+               }
 
-                        peer->nid = dst_nid;
-                        *self = src_nid;
-                        rc = 0;
-                }
-        }
+               if (rc < 0 ||
+                   dist < best_dist ||
+                   (dist == best_dist && order < best_order)) {
+                       best_dist = dist;
+                       best_order = order;
 
-        CDEBUG(D_NET,"%s->%s\n", uuid->uuid, libcfs_id2str(*peer));
-        return rc;
+                       peer->nid = dst_nid;
+                       *self = src_nid;
+                       rc = 0;
+               }
+       }
+
+       CDEBUG(D_NET, "%s->%s\n", uuid->uuid, libcfs_id2str(*peer));
+       return rc;
 }
 
 void ptlrpc_ni_fini(void)
 {
-       wait_queue_head_t         waitq;
-       struct l_wait_info  lwi;
        int                 rc;
        int                 retries;
 
@@ -566,9 +570,7 @@ void ptlrpc_ni_fini(void)
                                CWARN("Event queue still busy\n");
 
                        /* Wait for a bit */
-                       init_waitqueue_head(&waitq);
-                       lwi = LWI_TIMEOUT(cfs_time_seconds(2), NULL, NULL);
-                       l_wait_event(waitq, 0, &lwi);
+                       ssleep(2);
                        break;
                }
        }