Whamcloud - gitweb
b=16909 Console message cleanup
[fs/lustre-release.git] / lustre / ptlrpc / events.c
index 5133fb6..69716b3 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
 #ifndef __KERNEL__
 # include <liblustre.h>
 #else
+# include <libcfs/libcfs.h>
 # ifdef __mips64__
 #  include <linux/kernel.h>
 # endif
 #endif
+
 #include <obd_class.h>
 #include <lustre_net.h>
 #include <lustre_sec.h>
@@ -63,21 +65,21 @@ void request_out_callback(lnet_event_t *ev)
                  ev->type == LNET_EVENT_UNLINK);
         LASSERT (ev->unlinked);
 
-        DEBUG_REQ((ev->status == 0) ? D_NET : D_ERROR, req,
-                  "type %d, status %d", ev->type, ev->status);
+        DEBUG_REQ(D_NET, req, "type %d, status %d", ev->type, ev->status);
 
         sptlrpc_request_out_callback(req);
+        req->rq_real_sent = cfs_time_current_sec();
 
         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);
+                cfs_spin_lock(&req->rq_lock);
                 req->rq_net_err = 1;
-                spin_unlock(&req->rq_lock);
+                cfs_spin_unlock(&req->rq_lock);
 
-                ptlrpc_wake_client_req(req);
+                ptlrpc_client_wake_req(req);
         }
 
         ptlrpc_req_finished(req);
@@ -94,29 +96,41 @@ void reply_in_callback(lnet_event_t *ev)
         struct ptlrpc_request *req = cbid->cbid_arg;
         ENTRY;
 
-        DEBUG_REQ((ev->status == 0) ? D_NET : D_ERROR, req,
-                  "type %d, status %d", ev->type, ev->status);
+        DEBUG_REQ(D_NET, req, "type %d, status %d", ev->type, ev->status);
 
         LASSERT (ev->type == LNET_EVENT_PUT || ev->type == LNET_EVENT_UNLINK);
         LASSERT (ev->md.start == req->rq_repbuf);
-        LASSERT (ev->mlength <= req->rq_repbuf_len);
+        LASSERT (ev->offset + ev->mlength <= req->rq_repbuf_len);
         /* We've set LNET_MD_MANAGE_REMOTE for all outgoing requests
            for adaptive timeouts' early reply. */
         LASSERT((ev->md.options & LNET_MD_MANAGE_REMOTE) != 0);
 
-        spin_lock(&req->rq_lock);
+        cfs_spin_lock(&req->rq_lock);
 
         req->rq_receiving_reply = 0;
         req->rq_early = 0;
+        if (ev->unlinked)
+                req->rq_must_unlink = 0;
 
         if (ev->status)
                 goto out_wake;
+
         if (ev->type == LNET_EVENT_UNLINK) {
-                req->rq_must_unlink = 0;
+                LASSERT(ev->unlinked);
                 DEBUG_REQ(D_RPCTRACE, req, "unlink");
                 goto out_wake;
         }
 
+        if (ev->mlength < ev->rlength ) {
+                CDEBUG(D_RPCTRACE, "truncate req %p rpc %d - %d+%d\n", req,
+                       req->rq_replen, ev->rlength, ev->offset);
+                req->rq_reply_truncate = 1;
+                req->rq_replied = 1;
+                req->rq_status = -EOVERFLOW;
+                req->rq_nob_received = ev->rlength + ev->offset;
+                goto out_wake;
+        }
+
         if ((ev->offset == 0) &&
             ((lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))) {
                 /* Early reply */
@@ -126,18 +140,10 @@ void reply_in_callback(lnet_event_t *ev)
                           req->rq_replen, req->rq_replied, ev->unlinked);
 
                 req->rq_early_count++; /* number received, client side */
-                if (req->rq_replied) {
-                        /* If we already got the real reply, then we need to
-                         * check if lnet_finalize() unlinked the md.  In that
-                         * case, there will be no further callback of type
-                         * LNET_EVENT_UNLINK.
-                         */
-                        if (ev->unlinked)
-                                req->rq_must_unlink = 0;
-                        else
-                                DEBUG_REQ(D_RPCTRACE, req, "unlinked in reply");
+
+                if (req->rq_replied)   /* already got the real reply */
                         goto out_wake;
-                }
+
                 req->rq_early = 1;
                 req->rq_reply_off = ev->offset;
                 req->rq_nob_received = ev->mlength;
@@ -145,6 +151,7 @@ void reply_in_callback(lnet_event_t *ev)
                 req->rq_receiving_reply = 1;
         } else {
                 /* Real reply */
+                req->rq_rep_swab_mask = 0;
                 req->rq_replied = 1;
                 req->rq_reply_off = ev->offset;
                 req->rq_nob_received = ev->mlength;
@@ -161,8 +168,8 @@ void reply_in_callback(lnet_event_t *ev)
 out_wake:
         /* NB don't unlock till after wakeup; req can disappear under us
          * since we don't have our own ref */
-        ptlrpc_wake_client_req(req);
-        spin_unlock(&req->rq_lock);
+        ptlrpc_client_wake_req(req);
+        cfs_spin_unlock(&req->rq_lock);
         EXIT;
 }
 
@@ -186,7 +193,7 @@ void client_bulk_callback (lnet_event_t *ev)
                "event type %d, status %d, desc %p\n",
                ev->type, ev->status, desc);
 
-        spin_lock(&desc->bd_lock);
+        cfs_spin_lock(&desc->bd_lock);
 
         LASSERT(desc->bd_network_rw);
         desc->bd_network_rw = 0;
@@ -197,13 +204,15 @@ void client_bulk_callback (lnet_event_t *ev)
                 desc->bd_sender = ev->sender;
         }
 
-        sptlrpc_enc_pool_put_pages(desc);
+        /* release the encrypted pages for write */
+        if (desc->bd_req->rq_bulk_write)
+                sptlrpc_enc_pool_put_pages(desc);
 
         /* NB don't unlock till after wakeup; desc can disappear under us
          * otherwise */
-        ptlrpc_wake_client_req(desc->bd_req);
+        ptlrpc_client_wake_req(desc->bd_req);
 
-        spin_unlock(&desc->bd_lock);
+        cfs_spin_unlock(&desc->bd_lock);
         EXIT;
 }
 
@@ -259,7 +268,7 @@ 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);
+        cfs_gettimeofday(&req->rq_arrival_time);
         req->rq_peer = ev->initiator;
         req->rq_self = ev->target.nid;
         req->rq_rqbd = rqbd;
@@ -267,18 +276,19 @@ void request_in_callback(lnet_event_t *ev)
 #ifdef CRAY_XT3
         req->rq_uid = ev->uid;
 #endif
-        spin_lock_init(&req->rq_lock);
+        cfs_spin_lock_init(&req->rq_lock);
         CFS_INIT_LIST_HEAD(&req->rq_timed_list);
-        atomic_set(&req->rq_refcount, 1);
+        cfs_atomic_set(&req->rq_refcount, 1);
         if (ev->type == LNET_EVENT_PUT)
-                DEBUG_REQ(D_RPCTRACE, req, "incoming req");
+                CDEBUG(D_RPCTRACE, "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));
 
-        spin_lock(&service->srv_lock);
+        cfs_spin_lock(&service->srv_lock);
 
         req->rq_history_seq = service->srv_request_seq++;
-        list_add_tail(&req->rq_history_list, &service->srv_request_history);
+        cfs_list_add_tail(&req->rq_history_list, &service->srv_request_history);
 
         if (ev->unlinked) {
                 service->srv_nrqbd_receiving--;
@@ -299,14 +309,14 @@ void request_in_callback(lnet_event_t *ev)
                 rqbd->rqbd_refcount++;
         }
 
-        list_add_tail(&req->rq_list, &service->srv_req_in_queue);
+        cfs_list_add_tail(&req->rq_list, &service->srv_req_in_queue);
         service->srv_n_queued_reqs++;
 
         /* NB everything can disappear under us once the request
          * has been queued and we unlock, so do the wake now... */
         cfs_waitq_signal(&service->srv_waitq);
 
-        spin_unlock(&service->srv_lock);
+        cfs_spin_unlock(&service->srv_lock);
         EXIT;
 }
 
@@ -329,7 +339,7 @@ void reply_out_callback(lnet_event_t *ev)
                  * net's ref on 'rs' */
                 LASSERT (ev->unlinked);
                 ptlrpc_rs_decref(rs);
-                atomic_dec (&svc->srv_outstanding_replies);
+                cfs_atomic_dec (&svc->srv_outstanding_replies);
                 EXIT;
                 return;
         }
@@ -337,14 +347,16 @@ void reply_out_callback(lnet_event_t *ev)
         LASSERT (rs->rs_on_net);
 
         if (ev->unlinked) {
-                /* Last network callback.  The net's ref on 'rs' stays put
-                 * until ptlrpc_server_handle_reply() is done with it */
-                spin_lock(&svc->srv_lock);
+                /* Last network callback. The net's ref on 'rs' stays put
+                 * until ptlrpc_handle_rs() is done with it */
+                cfs_spin_lock(&svc->srv_lock);
+                cfs_spin_lock(&rs->rs_lock);
                 rs->rs_on_net = 0;
                 if (!rs->rs_no_ack ||
                     rs->rs_transno <= rs->rs_export->exp_obd->obd_last_committed)
                         ptlrpc_schedule_difficult_reply (rs);
-                spin_unlock(&svc->srv_lock);
+                cfs_spin_unlock(&rs->rs_lock);
+                cfs_spin_unlock(&svc->srv_lock);
         }
 
         EXIT;
@@ -370,7 +382,7 @@ void server_bulk_callback (lnet_event_t *ev)
                "event type %d, status %d, desc %p\n",
                ev->type, ev->status, desc);
 
-        spin_lock(&desc->bd_lock);
+        cfs_spin_lock(&desc->bd_lock);
 
         if ((ev->type == LNET_EVENT_ACK ||
              ev->type == LNET_EVENT_REPLY) &&
@@ -389,7 +401,7 @@ void server_bulk_callback (lnet_event_t *ev)
                 cfs_waitq_signal(&desc->bd_waitq);
         }
 
-        spin_unlock(&desc->bd_lock);
+        cfs_spin_unlock(&desc->bd_lock);
         EXIT;
 }
 
@@ -460,8 +472,6 @@ int ptlrpc_uuid_to_peer (struct obd_uuid *uuid,
         }
 
         CDEBUG(D_NET,"%s->%s\n", uuid->uuid, libcfs_id2str(*peer));
-        if (rc != 0)
-                CERROR("No NID found for %s\n", uuid->uuid);
         return rc;
 }
 
@@ -556,7 +566,7 @@ CFS_LIST_HEAD(liblustre_idle_callbacks);
 void *liblustre_services_callback;
 
 void *
-liblustre_register_waitidle_callback (struct list_head *callback_list,
+liblustre_register_waitidle_callback (cfs_list_t *callback_list,
                                       const char *name,
                                       int (*fn)(void *arg), void *arg)
 {
@@ -568,7 +578,7 @@ liblustre_register_waitidle_callback (struct list_head *callback_list,
         llwc->llwc_name = name;
         llwc->llwc_fn = fn;
         llwc->llwc_arg = arg;
-        list_add_tail(&llwc->llwc_list, callback_list);
+        cfs_list_add_tail(&llwc->llwc_list, callback_list);
 
         return (llwc);
 }
@@ -578,7 +588,7 @@ liblustre_deregister_waitidle_callback (void *opaque)
 {
         struct liblustre_wait_callback *llwc = opaque;
 
-        list_del(&llwc->llwc_list);
+        cfs_list_del(&llwc->llwc_list);
         OBD_FREE(llwc, sizeof(*llwc));
 }
 
@@ -624,7 +634,7 @@ liblustre_check_events (int timeout)
 
         LASSERT (rc == -EOVERFLOW || rc == 1);
 
-        /* liblustre: no asynch callback so we can't affort to miss any
+        /* liblustre: no asynch callback so we can't afford to miss any
          * events... */
         if (rc == -EOVERFLOW) {
                 CERROR ("Dropped an event!!!\n");
@@ -640,7 +650,7 @@ int liblustre_waiting = 0;
 int
 liblustre_wait_event (int timeout)
 {
-        struct list_head               *tmp;
+        cfs_list_t                     *tmp;
         struct liblustre_wait_callback *llwc;
         int                             found_something = 0;
 
@@ -653,9 +663,10 @@ liblustre_wait_event (int timeout)
                         found_something = 1;
 
                 /* Give all registered callbacks a bite at the cherry */
-                list_for_each(tmp, &liblustre_wait_callbacks) {
-                        llwc = list_entry(tmp, struct liblustre_wait_callback,
-                                          llwc_list);
+                cfs_list_for_each(tmp, &liblustre_wait_callbacks) {
+                        llwc = cfs_list_entry(tmp,
+                                              struct liblustre_wait_callback,
+                                              llwc_list);
 
                         if (llwc->llwc_fn(llwc->llwc_arg))
                                 found_something = 1;
@@ -679,29 +690,30 @@ void
 liblustre_wait_idle(void)
 {
         static int recursed = 0;
-        
-        struct list_head               *tmp;
+
+        cfs_list_t                     *tmp;
         struct liblustre_wait_callback *llwc;
         int                             idle = 0;
 
         LASSERT(!recursed);
         recursed = 1;
-        
+
         do {
                 liblustre_wait_event(0);
 
                 idle = 1;
 
-                list_for_each(tmp, &liblustre_idle_callbacks) {
-                        llwc = list_entry(tmp, struct liblustre_wait_callback,
-                                          llwc_list);
-                        
+                cfs_list_for_each(tmp, &liblustre_idle_callbacks) {
+                        llwc = cfs_list_entry(tmp,
+                                              struct liblustre_wait_callback,
+                                              llwc_list);
+
                         if (!llwc->llwc_fn(llwc->llwc_arg)) {
                                 idle = 0;
                                 break;
                         }
                 }
-                        
+
         } while (!idle);
 
         recursed = 0;
@@ -722,11 +734,12 @@ int ptlrpc_init_portals(void)
                 liblustre_register_wait_callback("liblustre_check_services",
                                                  &liblustre_check_services,
                                                  NULL);
+        cfs_init_completion_module(liblustre_wait_event);
 #endif
         rc = ptlrpcd_addref();
         if (rc == 0)
                 return 0;
-        
+
         CERROR("rpcd initialisation failed\n");
 #ifndef __KERNEL__
         liblustre_deregister_wait_callback(liblustre_services_callback);