Whamcloud - gitweb
LU-5455 ptlrpc: fix magic return value of ptlrpc_init_portals
[fs/lustre-release.git] / lustre / ptlrpc / events.c
index ef0b698..96e68d4 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -68,19 +68,20 @@ void request_out_callback(lnet_event_t *ev)
         DEBUG_REQ(D_NET, req, "type %d, status %d", ev->type, ev->status);
 
         sptlrpc_request_out_callback(req);
+       spin_lock(&req->rq_lock);
         req->rq_real_sent = cfs_time_current_sec();
+       if (ev->unlinked)
+               req->rq_req_unlink = 0;
 
         if (ev->type == LNET_EVENT_UNLINK || ev->status != 0) {
 
                 /* Failed send: make it seem like the reply timed out, just
                  * like failing sends in client.c does currently...  */
 
-               spin_lock(&req->rq_lock);
                req->rq_net_err = 1;
-               spin_unlock(&req->rq_lock);
-
                 ptlrpc_client_wake_req(req);
         }
+       spin_unlock(&req->rq_lock);
 
         ptlrpc_req_finished(req);
 
@@ -110,7 +111,7 @@ void reply_in_callback(lnet_event_t *ev)
         req->rq_receiving_reply = 0;
         req->rq_early = 0;
         if (ev->unlinked)
-                req->rq_must_unlink = 0;
+               req->rq_reply_unlink = 0;
 
         if (ev->status)
                 goto out_wake;
@@ -153,6 +154,8 @@ void reply_in_callback(lnet_event_t *ev)
                 /* Real reply */
                 req->rq_rep_swab_mask = 0;
                 req->rq_replied = 1;
+               /* Got reply, no resend required */
+               req->rq_resend = 0;
                 req->rq_reply_off = ev->offset;
                 req->rq_nob_received = ev->mlength;
                 /* LNetMDUnlink can't be called under the LNET_LOCK,
@@ -201,28 +204,27 @@ void client_bulk_callback (lnet_event_t *ev)
                ev->type, ev->status, desc);
 
        spin_lock(&desc->bd_lock);
-        req = desc->bd_req;
-        LASSERT(desc->bd_network_rw);
-        desc->bd_network_rw = 0;
-
-        if (ev->type != LNET_EVENT_UNLINK && ev->status == 0) {
-                desc->bd_success = 1;
-                desc->bd_nob_transferred = ev->mlength;
-                desc->bd_sender = ev->sender;
-        } else {
-                /* start reconnect and resend if network error hit */
+       req = desc->bd_req;
+       LASSERT(desc->bd_md_count > 0);
+       desc->bd_md_count--;
+
+       if (ev->type != LNET_EVENT_UNLINK && ev->status == 0) {
+               desc->bd_nob_transferred += ev->mlength;
+               desc->bd_sender = ev->sender;
+       } else {
+               /* start reconnect and resend if network error hit */
                spin_lock(&req->rq_lock);
                req->rq_net_err = 1;
                spin_unlock(&req->rq_lock);
-        }
+       }
 
-        /* release the encrypted pages for write */
-        if (desc->bd_req->rq_bulk_write)
-                sptlrpc_enc_pool_put_pages(desc);
+       if (ev->status != 0)
+               desc->bd_failure = 1;
 
-        /* NB don't unlock till after wakeup; desc can disappear under us
-         * otherwise */
-        ptlrpc_client_wake_req(req);
+       /* NB don't unlock till after wakeup; desc can disappear under us
+        * otherwise */
+       if (desc->bd_md_count == 0)
+               ptlrpc_client_wake_req(desc->bd_req);
 
        spin_unlock(&desc->bd_lock);
        EXIT;
@@ -261,7 +263,9 @@ static void ptlrpc_req_add_history(struct ptlrpc_service_part *svcpt,
         * it must be called with hold svcpt::scp_lock */
 
        new_seq = (sec << REQS_SEC_SHIFT) |
-                 (usec << REQS_USEC_SHIFT) | svcpt->scp_cpt;
+                 (usec << REQS_USEC_SHIFT) |
+                 (svcpt->scp_cpt < 0 ? 0 : svcpt->scp_cpt);
+
        if (new_seq > svcpt->scp_hist_seq) {
                /* This handles the initial case of scp_hist_seq == 0 or
                 * we just jumped into a new time window */
@@ -279,7 +283,7 @@ static void ptlrpc_req_add_history(struct ptlrpc_service_part *svcpt,
 
        req->rq_history_seq = new_seq;
 
-       cfs_list_add_tail(&req->rq_history_list, &svcpt->scp_hist_reqs);
+       list_add_tail(&req->rq_history_list, &svcpt->scp_hist_reqs);
 }
 
 /*
@@ -318,7 +322,7 @@ void request_in_callback(lnet_event_t *ev)
                         /* We moaned above already... */
                         return;
                 }
-                OBD_ALLOC_GFP(req, sizeof(*req), CFS_ALLOC_ATOMIC_TRY);
+               req = ptlrpc_request_cache_alloc(ALLOC_ATOMIC_TRY);
                 if (req == NULL) {
                         CERROR("Can't allocate incoming request descriptor: "
                                "Dropping %s RPC from %s\n",
@@ -333,22 +337,22 @@ void request_in_callback(lnet_event_t *ev)
          * size to non-zero if this was a successful receive. */
         req->rq_xid = ev->match_bits;
         req->rq_reqbuf = ev->md.start + ev->offset;
-        if (ev->type == LNET_EVENT_PUT && ev->status == 0)
-                req->rq_reqdata_len = ev->mlength;
-        cfs_gettimeofday(&req->rq_arrival_time);
-        req->rq_peer = ev->initiator;
-        req->rq_self = ev->target.nid;
-        req->rq_rqbd = rqbd;
+       if (ev->type == LNET_EVENT_PUT && ev->status == 0)
+               req->rq_reqdata_len = ev->mlength;
+       do_gettimeofday(&req->rq_arrival_time);
+       req->rq_peer = ev->initiator;
+       req->rq_self = ev->target.nid;
+       req->rq_rqbd = rqbd;
         req->rq_phase = RQ_PHASE_NEW;
        spin_lock_init(&req->rq_lock);
-        CFS_INIT_LIST_HEAD(&req->rq_timed_list);
-       CFS_INIT_LIST_HEAD(&req->rq_exp_list);
-        cfs_atomic_set(&req->rq_refcount, 1);
-        if (ev->type == LNET_EVENT_PUT)
-                CDEBUG(D_INFO, "incoming req@%p x"LPU64" msgsize %u\n",
-                       req, req->rq_xid, ev->mlength);
+       INIT_LIST_HEAD(&req->rq_timed_list);
+       INIT_LIST_HEAD(&req->rq_exp_list);
+       atomic_set(&req->rq_refcount, 1);
+       if (ev->type == LNET_EVENT_PUT)
+               CDEBUG(D_INFO, "incoming req@%p x"LPU64" 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\n", libcfs_id2str(req->rq_peer));
 
        spin_lock(&svcpt->scp_lock);
 
@@ -373,12 +377,12 @@ void request_in_callback(lnet_event_t *ev)
                 rqbd->rqbd_refcount++;
         }
 
-       cfs_list_add_tail(&req->rq_list, &svcpt->scp_req_incoming);
+       list_add_tail(&req->rq_list, &svcpt->scp_req_incoming);
        svcpt->scp_nreqs_incoming++;
 
        /* NB everything can disappear under us once the request
         * has been queued and we unlock, so do the wake now... */
-       cfs_waitq_signal(&svcpt->scp_waitq);
+       wake_up(&svcpt->scp_waitq);
 
        spin_unlock(&svcpt->scp_lock);
        EXIT;
@@ -433,16 +437,16 @@ void reply_out_callback(lnet_event_t *ev)
  */
 void server_bulk_callback (lnet_event_t *ev)
 {
-        struct ptlrpc_cb_id     *cbid = ev->md.user_ptr;
-        struct ptlrpc_bulk_desc *desc = cbid->cbid_arg;
-        ENTRY;
+       struct ptlrpc_cb_id     *cbid = ev->md.user_ptr;
+       struct ptlrpc_bulk_desc *desc = cbid->cbid_arg;
+       ENTRY;
 
-        LASSERT (ev->type == LNET_EVENT_SEND ||
-                 ev->type == LNET_EVENT_UNLINK ||
-                 (desc->bd_type == BULK_PUT_SOURCE &&
-                  ev->type == LNET_EVENT_ACK) ||
-                 (desc->bd_type == BULK_GET_SINK &&
-                  ev->type == LNET_EVENT_REPLY));
+       LASSERT(ev->type == LNET_EVENT_SEND ||
+               ev->type == LNET_EVENT_UNLINK ||
+               (desc->bd_type == BULK_PUT_SOURCE &&
+                ev->type == LNET_EVENT_ACK) ||
+               (desc->bd_type == BULK_GET_SINK &&
+                ev->type == LNET_EVENT_REPLY));
 
         CDEBUG((ev->status == 0) ? D_NET : D_ERROR,
                "event type %d, status %d, desc %p\n",
@@ -450,22 +454,27 @@ void server_bulk_callback (lnet_event_t *ev)
 
        spin_lock(&desc->bd_lock);
 
-        if ((ev->type == LNET_EVENT_ACK ||
-             ev->type == LNET_EVENT_REPLY) &&
-            ev->status == 0) {
-                /* We heard back from the peer, so even if we get this
-                 * before the SENT event (oh yes we can), we know we
-                 * read/wrote the peer buffer and how much... */
-                desc->bd_success = 1;
-                desc->bd_nob_transferred = ev->mlength;
-                desc->bd_sender = ev->sender;
-        }
+       LASSERT(desc->bd_md_count > 0);
 
-        if (ev->unlinked) {
-                /* This is the last callback no matter what... */
-                desc->bd_network_rw = 0;
-                cfs_waitq_signal(&desc->bd_waitq);
-        }
+       if ((ev->type == LNET_EVENT_ACK ||
+            ev->type == LNET_EVENT_REPLY) &&
+           ev->status == 0) {
+               /* We heard back from the peer, so even if we get this
+                * before the SENT event (oh yes we can), we know we
+                * read/wrote the peer buffer and how much... */
+               desc->bd_nob_transferred += ev->mlength;
+               desc->bd_sender = ev->sender;
+       }
+
+       if (ev->status != 0)
+               desc->bd_failure = 1;
+
+       if (ev->unlinked) {
+               desc->bd_md_count--;
+               /* This is the last callback no matter what... */
+               if (desc->bd_md_count == 0)
+                       wake_up(&desc->bd_waitq);
+       }
 
        spin_unlock(&desc->bd_lock);
        EXIT;
@@ -547,38 +556,38 @@ int ptlrpc_uuid_to_peer (struct obd_uuid *uuid,
 
 void ptlrpc_ni_fini(void)
 {
-        cfs_waitq_t         waitq;
-        struct l_wait_info  lwi;
-        int                 rc;
-        int                 retries;
-
-        /* Wait for the event queue to become idle since there may still be
-         * messages in flight with pending events (i.e. the fire-and-forget
-         * messages == client requests and "non-difficult" server
-         * replies */
-
-        for (retries = 0;; retries++) {
-                rc = LNetEQFree(ptlrpc_eq_h);
-                switch (rc) {
-                default:
-                        LBUG();
-
-                case 0:
-                        LNetNIFini();
-                        return;
-
-                case -EBUSY:
-                        if (retries != 0)
-                                CWARN("Event queue still busy\n");
-
-                        /* Wait for a bit */
-                        cfs_waitq_init(&waitq);
-                        lwi = LWI_TIMEOUT(cfs_time_seconds(2), NULL, NULL);
-                        l_wait_event(waitq, 0, &lwi);
-                        break;
-                }
-        }
-        /* notreached */
+       wait_queue_head_t         waitq;
+       struct l_wait_info  lwi;
+       int                 rc;
+       int                 retries;
+
+       /* Wait for the event queue to become idle since there may still be
+        * messages in flight with pending events (i.e. the fire-and-forget
+        * messages == client requests and "non-difficult" server
+        * replies */
+
+       for (retries = 0;; retries++) {
+               rc = LNetEQFree(ptlrpc_eq_h);
+               switch (rc) {
+               default:
+                       LBUG();
+
+               case 0:
+                       LNetNIFini();
+                       return;
+
+               case -EBUSY:
+                       if (retries != 0)
+                               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);
+                       break;
+               }
+       }
+       /* notreached */
 }
 
 lnet_pid_t ptl_get_pid(void)
@@ -605,7 +614,7 @@ int ptlrpc_ni_init(void)
         rc = LNetNIInit(pid);
         if (rc < 0) {
                 CDEBUG (D_NET, "Can't init network interface: %d\n", rc);
-                return (-ENOENT);
+               return rc;
         }
 
         /* CAVEAT EMPTOR: how we process portals events is _radically_
@@ -628,18 +637,18 @@ int ptlrpc_ni_init(void)
         CERROR ("Failed to allocate event queue: %d\n", rc);
         LNetNIFini();
 
-        return (-ENOMEM);
+       return rc;
 }
 
 #ifndef __KERNEL__
-CFS_LIST_HEAD(liblustre_wait_callbacks);
-CFS_LIST_HEAD(liblustre_idle_callbacks);
+struct list_head liblustre_wait_callbacks;
+struct list_head liblustre_idle_callbacks;
 void *liblustre_services_callback;
 
 void *
-liblustre_register_waitidle_callback (cfs_list_t *callback_list,
-                                      const char *name,
-                                      int (*fn)(void *arg), void *arg)
+liblustre_register_waitidle_callback(struct list_head *callback_list,
+                                    const char *name,
+                                    int (*fn)(void *arg), void *arg)
 {
         struct liblustre_wait_callback *llwc;
 
@@ -649,7 +658,7 @@ liblustre_register_waitidle_callback (cfs_list_t *callback_list,
         llwc->llwc_name = name;
         llwc->llwc_fn = fn;
         llwc->llwc_arg = arg;
-        cfs_list_add_tail(&llwc->llwc_list, callback_list);
+       list_add_tail(&llwc->llwc_list, callback_list);
 
         return (llwc);
 }
@@ -657,10 +666,10 @@ liblustre_register_waitidle_callback (cfs_list_t *callback_list,
 void
 liblustre_deregister_waitidle_callback (void *opaque)
 {
-        struct liblustre_wait_callback *llwc = opaque;
+       struct liblustre_wait_callback *llwc = opaque;
 
-        cfs_list_del(&llwc->llwc_list);
-        OBD_FREE(llwc, sizeof(*llwc));
+       list_del(&llwc->llwc_list);
+       OBD_FREE(llwc, sizeof(*llwc));
 }
 
 void *
@@ -721,7 +730,7 @@ int liblustre_waiting = 0;
 int
 liblustre_wait_event (int timeout)
 {
-        cfs_list_t                     *tmp;
+       struct list_head                     *tmp;
         struct liblustre_wait_callback *llwc;
         int                             found_something = 0;
 
@@ -734,8 +743,8 @@ liblustre_wait_event (int timeout)
                         found_something = 1;
 
                 /* Give all registered callbacks a bite at the cherry */
-                cfs_list_for_each(tmp, &liblustre_wait_callbacks) {
-                        llwc = cfs_list_entry(tmp,
+               list_for_each(tmp, &liblustre_wait_callbacks) {
+                       llwc = list_entry(tmp,
                                               struct liblustre_wait_callback,
                                               llwc_list);
 
@@ -761,10 +770,9 @@ void
 liblustre_wait_idle(void)
 {
         static int recursed = 0;
-
-        cfs_list_t                     *tmp;
-        struct liblustre_wait_callback *llwc;
-        int                             idle = 0;
+       struct list_head                *tmp;
+       struct liblustre_wait_callback  *llwc;
+       int                              idle = 0;
 
         LASSERT(!recursed);
         recursed = 1;
@@ -774,11 +782,9 @@ liblustre_wait_idle(void)
 
                 idle = 1;
 
-                cfs_list_for_each(tmp, &liblustre_idle_callbacks) {
-                        llwc = cfs_list_entry(tmp,
-                                              struct liblustre_wait_callback,
-                                              llwc_list);
-
+               list_for_each(tmp, &liblustre_idle_callbacks) {
+                       llwc = list_entry(tmp, struct liblustre_wait_callback,
+                                         llwc_list);
                         if (!llwc->llwc_fn(llwc->llwc_arg)) {
                                 idle = 0;
                                 break;
@@ -798,9 +804,12 @@ int ptlrpc_init_portals(void)
 
         if (rc != 0) {
                 CERROR("network initialisation failed\n");
-                return -EIO;
+               return rc;
         }
 #ifndef __KERNEL__
+       INIT_LIST_HEAD(&liblustre_wait_callbacks);
+       INIT_LIST_HEAD(&liblustre_idle_callbacks);
+
         liblustre_services_callback =
                 liblustre_register_wait_callback("liblustre_check_services",
                                                  &liblustre_check_services,