Whamcloud - gitweb
LU-13004 ptlrpc: Allow BULK_BUF_KIOV to accept a kvec
[fs/lustre-release.git] / lustre / ptlrpc / events.c
index 0dfe3a1..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, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #define DEBUG_SUBSYSTEM S_RPC
 
-#ifndef __KERNEL__
-# include <liblustre.h>
-#else
-# include <libcfs/libcfs.h>
-# ifdef __mips64__
-#  include <linux/kernel.h>
-# endif
-#endif
-
+#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;
-        ENTRY;
-
-        LASSERT (ev->type == LNET_EVENT_SEND ||
-                 ev->type == LNET_EVENT_UNLINK);
-        LASSERT (ev->unlinked);
-
-        DEBUG_REQ(D_NET, req, "type %d, status %d", ev->type, ev->status);
+       struct ptlrpc_cb_id   *cbid = ev->md.user_ptr;
+       struct ptlrpc_request *req = cbid->cbid_arg;
+       bool                   wakeup = false;
+       ENTRY;
 
-        sptlrpc_request_out_callback(req);
-        req->rq_real_sent = cfs_time_current_sec();
+       LASSERT(ev->type == LNET_EVENT_SEND || ev->type == LNET_EVENT_UNLINK);
+       LASSERT(ev->unlinked);
 
-        if (ev->type == LNET_EVENT_UNLINK || ev->status != 0) {
+       DEBUG_REQ(D_NET, req, "type %d, status %d", ev->type, ev->status);
 
-                /* Failed send: make it seem like the reply timed out, just
-                 * like failing sends in client.c does currently...  */
+       sptlrpc_request_out_callback(req);
 
-               spin_lock(&req->rq_lock);
+       spin_lock(&req->rq_lock);
+       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)
+               wakeup = true;
+
+       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...  */
                req->rq_net_err = 1;
-               spin_unlock(&req->rq_lock);
+               wakeup = true;
+       }
 
-                ptlrpc_client_wake_req(req);
-        }
+       if (wakeup)
+               ptlrpc_client_wake_req(req);
 
-        ptlrpc_req_finished(req);
+       spin_unlock(&req->rq_lock);
 
-        EXIT;
+       ptlrpc_req_finished(req);
+       EXIT;
 }
 
 /*
  * 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;
@@ -107,10 +102,10 @@ void reply_in_callback(lnet_event_t *ev)
 
        spin_lock(&req->rq_lock);
 
-        req->rq_receiving_reply = 0;
-        req->rq_early = 0;
-        if (ev->unlinked)
-                req->rq_must_unlink = 0;
+       req->rq_receiving_reply = 0;
+       req->rq_early = 0;
+       if (ev->unlinked)
+               req->rq_reply_unlinked = 1;
 
         if (ev->status)
                 goto out_wake;
@@ -124,25 +119,27 @@ void reply_in_callback(lnet_event_t *ev)
         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_reply_truncated = 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 */
-                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 */
 
-                if (req->rq_replied)   /* already got the real reply */
-                        goto out_wake;
+               /* already got the real reply or buffers are already unlinked */
+               if (req->rq_replied ||
+                   req->rq_reply_unlinked == 1)
+                       goto out_wake;
 
                 req->rq_early = 1;
                 req->rq_reply_off = ev->offset;
@@ -153,6 +150,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,
@@ -163,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;
 }
@@ -176,19 +176,19 @@ 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;
         struct ptlrpc_request   *req;
         ENTRY;
 
-        LASSERT ((desc->bd_type == BULK_PUT_SINK &&
-                  ev->type == LNET_EVENT_PUT) ||
-                 (desc->bd_type == BULK_GET_SOURCE &&
-                  ev->type == LNET_EVENT_GET) ||
-                 ev->type == LNET_EVENT_UNLINK);
-        LASSERT (ev->unlinked);
+       LASSERT((ptlrpc_is_bulk_put_sink(desc->bd_type) &&
+                ev->type == LNET_EVENT_PUT) ||
+               (ptlrpc_is_bulk_get_source(desc->bd_type) &&
+                ev->type == LNET_EVENT_GET) ||
+               ev->type == LNET_EVENT_UNLINK);
+       LASSERT(ev->unlinked);
 
         if (CFS_FAIL_CHECK_ORSET(OBD_FAIL_PTLRPC_CLIENT_BULK_CB, CFS_FAIL_ONCE))
                 ev->status = -EIO;
@@ -252,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 */
@@ -280,13 +280,13 @@ 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);
 }
 
 /*
  * 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;
@@ -319,7 +319,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(GFP_ATOMIC);
                 if (req == NULL) {
                         CERROR("Can't allocate incoming request descriptor: "
                                "Dropping %s RPC from %s\n",
@@ -329,27 +329,27 @@ void request_in_callback(lnet_event_t *ev)
                 }
         }
 
-        /* NB we ABSOLUTELY RELY on req being zeroed, so pointers are NULL,
-         * flags are reset and scalars are zero.  We only set the message
-         * 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;
-        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);
-
-        CDEBUG(D_RPCTRACE, "peer: %s\n", libcfs_id2str(req->rq_peer));
+       ptlrpc_srv_req_init(req);
+       /* NB we ABSOLUTELY RELY on req being zeroed, so pointers are NULL,
+        * flags are reset and scalars are zero.  We only set the message
+        * 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;
+       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;
+       if (ev->type == LNET_EVENT_PUT)
+               CDEBUG(D_INFO, "incoming req@%p x%llu msgsize %u\n",
+                      req, req->rq_xid, ev->mlength);
+
+       CDEBUG(D_RPCTRACE, "peer: %s (source: %s)\n",
+               libcfs_id2str(req->rq_peer), libcfs_id2str(req->rq_source));
 
        spin_lock(&svcpt->scp_lock);
 
@@ -374,12 +374,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;
@@ -388,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;
@@ -419,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);
@@ -432,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;
@@ -440,9 +441,9 @@ void server_bulk_callback (lnet_event_t *ev)
 
        LASSERT(ev->type == LNET_EVENT_SEND ||
                ev->type == LNET_EVENT_UNLINK ||
-               (desc->bd_type == BULK_PUT_SOURCE &&
+               (ptlrpc_is_bulk_put_source(desc->bd_type) &&
                 ev->type == LNET_EVENT_ACK) ||
-               (desc->bd_type == BULK_GET_SINK &&
+               (ptlrpc_is_bulk_get_sink(desc->bd_type) &&
                 ev->type == LNET_EVENT_REPLY));
 
         CDEBUG((ev->status == 0) ? D_NET : D_ERROR,
@@ -470,7 +471,7 @@ void server_bulk_callback (lnet_event_t *ev)
                desc->bd_md_count--;
                /* This is the last callback no matter what... */
                if (desc->bd_md_count == 0)
-                       cfs_waitq_signal(&desc->bd_waitq);
+                       wake_up(&desc->bd_waitq);
        }
 
        spin_unlock(&desc->bd_lock);
@@ -478,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);
@@ -498,105 +499,87 @@ 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               portals_compatibility;
-        int               dist;
-        __u32             order;
-        lnet_nid_t        dst_nid;
-        lnet_nid_t        src_nid;
-
-        portals_compatibility = LNetCtl(IOC_LIBCFS_PORTALS_COMPATIBILITY, NULL);
-
-        peer->pid = LUSTRE_SRV_LNET_PID;
-
-        /* 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;
-
-                if (dist == 0) {                /* local! use loopback LND */
-                        peer->nid = *self = LNET_MKNID(LNET_MKNET(LOLND, 0), 0);
-                        rc = 0;
-                        break;
-                }
-
-                if (rc < 0 ||
-                    dist < best_dist ||
-                    (dist == best_dist && order < best_order)) {
-                        best_dist = dist;
-                        best_order = order;
-
-                        if (portals_compatibility > 1) {
-                                /* Strong portals compatibility: Zero the nid's
-                                 * NET, so if I'm reading new config logs, or
-                                 * getting configured by (new) lconf I can
-                                 * still talk to old servers. */
-                                dst_nid = LNET_MKNID(0, LNET_NIDADDR(dst_nid));
-                                src_nid = LNET_MKNID(0, LNET_NIDADDR(src_nid));
-                        }
-                        peer->nid = dst_nid;
-                        *self = src_nid;
-                        rc = 0;
-                }
-        }
+       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) {
+               if (peer->nid != LNET_NID_ANY && LNET_NIDADDR(peer->nid) == 0 &&
+                   LNET_NIDNET(dst_nid) != LNET_NIDNET(peer->nid))
+                       continue;
+
+               dist = LNetDist(dst_nid, &src_nid, &order);
+               if (dist < 0)
+                       continue;
+
+               if (dist == 0) {                /* local! use loopback LND */
+                       peer->nid = *self = LNET_MKNID(LNET_MKNET(LOLND, 0), 0);
+                       rc = 0;
+                       break;
+               }
+
+               if (rc < 0 ||
+                   dist < best_dist ||
+                   (dist == best_dist && order < best_order)) {
+                       best_dist = dist;
+                       best_order = order;
+
+                       peer->nid = dst_nid;
+                       *self = src_nid;
+                       rc = 0;
+               }
+       }
 
-        CDEBUG(D_NET,"%s->%s\n", uuid->uuid, libcfs_id2str(*peer));
-        return rc;
+       CDEBUG(D_NET, "%s->%s\n", uuid->uuid, libcfs_id2str(*peer));
+       return rc;
 }
 
 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 */
+       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 */
+                       ssleep(2);
+                       break;
+               }
+       }
+       /* notreached */
 }
 
 lnet_pid_t ptl_get_pid(void)
 {
-        lnet_pid_t        pid;
-
-#ifndef  __KERNEL__
-        pid = getpid();
-#else
-        pid = LUSTRE_SRV_LNET_PID;
-#endif
-        return pid;
+       return LNET_PID_LUSTRE;
 }
 
 int ptlrpc_ni_init(void)
@@ -611,192 +594,25 @@ 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_
          * different depending on... */
-#ifdef __KERNEL__
        /* kernel LNet calls our master callback when there are new event,
         * because we are guaranteed to get every event via callback,
         * so we just set EQ size to 0 to avoid overhread of serializing
         * enqueue/dequeue operations in LNet. */
        rc = LNetEQAlloc(0, ptlrpc_master_callback, &ptlrpc_eq_h);
-#else
-        /* liblustre calls the master callback when it removes events from the
-         * event queue.  The event queue has to be big enough not to drop
-         * anything */
-        rc = LNetEQAlloc(10240, LNET_EQ_HANDLER_NONE, &ptlrpc_eq_h);
-#endif
         if (rc == 0)
                 return 0;
 
         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);
-void *liblustre_services_callback;
-
-void *
-liblustre_register_waitidle_callback (cfs_list_t *callback_list,
-                                      const char *name,
-                                      int (*fn)(void *arg), void *arg)
-{
-        struct liblustre_wait_callback *llwc;
-
-        OBD_ALLOC(llwc, sizeof(*llwc));
-        LASSERT (llwc != NULL);
-
-        llwc->llwc_name = name;
-        llwc->llwc_fn = fn;
-        llwc->llwc_arg = arg;
-        cfs_list_add_tail(&llwc->llwc_list, callback_list);
-
-        return (llwc);
-}
-
-void
-liblustre_deregister_waitidle_callback (void *opaque)
-{
-        struct liblustre_wait_callback *llwc = opaque;
-
-        cfs_list_del(&llwc->llwc_list);
-        OBD_FREE(llwc, sizeof(*llwc));
-}
-
-void *
-liblustre_register_wait_callback (const char *name,
-                                  int (*fn)(void *arg), void *arg)
-{
-        return liblustre_register_waitidle_callback(&liblustre_wait_callbacks,
-                                                    name, fn, arg);
-}
-
-void
-liblustre_deregister_wait_callback (void *opaque)
-{
-        liblustre_deregister_waitidle_callback(opaque);
-}
-
-void *
-liblustre_register_idle_callback (const char *name,
-                                  int (*fn)(void *arg), void *arg)
-{
-        return liblustre_register_waitidle_callback(&liblustre_idle_callbacks,
-                                                    name, fn, arg);
-}
-
-void
-liblustre_deregister_idle_callback (void *opaque)
-{
-        liblustre_deregister_waitidle_callback(opaque);
-}
-
-int
-liblustre_check_events (int timeout)
-{
-        lnet_event_t ev;
-        int         rc;
-        int         i;
-        ENTRY;
-
-        rc = LNetEQPoll(&ptlrpc_eq_h, 1, timeout * 1000, &ev, &i);
-        if (rc == 0)
-                RETURN(0);
-
-        LASSERT (rc == -EOVERFLOW || rc == 1);
-
-        /* liblustre: no asynch callback so we can't afford to miss any
-         * events... */
-        if (rc == -EOVERFLOW) {
-                CERROR ("Dropped an event!!!\n");
-                abort();
-        }
-
-        ptlrpc_master_callback (&ev);
-        RETURN(1);
-}
-
-int liblustre_waiting = 0;
-
-int
-liblustre_wait_event (int timeout)
-{
-        cfs_list_t                     *tmp;
-        struct liblustre_wait_callback *llwc;
-        int                             found_something = 0;
-
-        /* single threaded recursion check... */
-        liblustre_waiting = 1;
-
-        for (;;) {
-                /* Deal with all pending events */
-                while (liblustre_check_events(0))
-                        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,
-                                              struct liblustre_wait_callback,
-                                              llwc_list);
-
-                        if (llwc->llwc_fn(llwc->llwc_arg))
-                                found_something = 1;
-                }
-
-                if (found_something || timeout == 0)
-                        break;
-
-                /* Nothing so far, but I'm allowed to block... */
-                found_something = liblustre_check_events(timeout);
-                if (!found_something)           /* still nothing */
-                        break;                  /* I timed out */
-        }
-
-        liblustre_waiting = 0;
-
-        return found_something;
-}
-
-void
-liblustre_wait_idle(void)
-{
-        static int recursed = 0;
-
-        cfs_list_t                     *tmp;
-        struct liblustre_wait_callback *llwc;
-        int                             idle = 0;
-
-        LASSERT(!recursed);
-        recursed = 1;
-
-        do {
-                liblustre_wait_event(0);
-
-                idle = 1;
-
-                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;
-}
-
-#endif /* __KERNEL__ */
 
 int ptlrpc_init_portals(void)
 {
@@ -804,32 +620,19 @@ int ptlrpc_init_portals(void)
 
         if (rc != 0) {
                 CERROR("network initialisation failed\n");
-                return -EIO;
+               return rc;
         }
-#ifndef __KERNEL__
-        liblustre_services_callback =
-                liblustre_register_wait_callback("liblustre_check_services",
-                                                 &liblustre_check_services,
-                                                 NULL);
-       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);
-#endif
         ptlrpc_ni_fini();
         return rc;
 }
 
 void ptlrpc_exit_portals(void)
 {
-#ifndef __KERNEL__
-        liblustre_deregister_wait_callback(liblustre_services_callback);
-#endif
         ptlrpcd_decref();
         ptlrpc_ni_fini();
 }