Whamcloud - gitweb
* Split struct niobuf into niobuf_local and niobuf_remote
[fs/lustre-release.git] / lustre / ptlrpc / client.c
index 4557395..288d43f 100644 (file)
 
 #define EXPORT_SYMTAB
 
-#include <linux/config.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-
 #define DEBUG_SUBSYSTEM S_RPC
 
-#include <linux/obd_support.h>
-#include <linux/obd_class.h>
-#include <linux/lustre_net.h>
+#include <linux/lustre_ha.h>
 
-int ptlrpc_enqueue(struct ptlrpc_client *peer, struct ptlrpc_request *req)
+void ptlrpc_init_client(struct recovd_obd *recovd, 
+                        int (*recover)(struct ptlrpc_client *recover),
+                        int req_portal,
+                        int rep_portal, struct ptlrpc_client *cl)
 {
-       struct ptlrpc_request *srv_req;
-       
-       if (!peer->cli_obd) { 
-               EXIT;
-               return -1;
-       }
-
-       OBD_ALLOC(srv_req, sizeof(*srv_req));
-       if (!srv_req) { 
-               EXIT;
-               return -ENOMEM;
-       }
-
-        CDEBUG(0, "peer obd minor %d, incoming req %p, srv_req %p\n",
-              peer->cli_obd->obd_minor, req, srv_req);
-
-       memset(srv_req, 0, sizeof(*req)); 
-
-       /* move the request buffer */
-       srv_req->rq_reqbuf = req->rq_reqbuf;
-       srv_req->rq_reqlen = req->rq_reqlen;
-       srv_req->rq_obd = peer->cli_obd;
-
-       /* remember where it came from */
-       srv_req->rq_reply_handle = req;
-
-       list_add(&srv_req->rq_list, &peer->cli_obd->obd_req_list); 
-       wake_up(&peer->cli_obd->obd_req_waitq);
-       return 0;
+        memset(cl, 0, sizeof(*cl));
+        cl->cli_recovd = recovd;
+        cl->cli_recover = recover;
+        if (recovd)
+                recovd_cli_manage(recovd, cl);
+        cl->cli_obd = NULL;
+        cl->cli_request_portal = req_portal;
+        cl->cli_reply_portal = rep_portal;
+        INIT_LIST_HEAD(&cl->cli_delayed_head);
+        INIT_LIST_HEAD(&cl->cli_sending_head);
+        INIT_LIST_HEAD(&cl->cli_dying_head);
+        spin_lock_init(&cl->cli_lock);
+        sema_init(&cl->cli_rpc_sem, 32);
 }
 
-int ptlrpc_connect_client(int dev, char *uuid, int req_portal, int rep_portal, 
-                          req_pack_t req_pack, rep_unpack_t rep_unpack,
-                          struct ptlrpc_client *cl)
+__u8 *ptlrpc_req_to_uuid(struct ptlrpc_request *req)
 {
-        int err; 
+        return req->rq_connection->c_remote_uuid;
+}
 
-        memset(cl, 0, sizeof(*cl));
-        spin_lock_init(&cl->cli_lock);
-       cl->cli_xid = 1;
-       cl->cli_obd = NULL; 
-       cl->cli_request_portal = req_portal;
-       cl->cli_reply_portal = rep_portal;
-       cl->cli_rep_unpack = rep_unpack;
-       cl->cli_req_pack = req_pack;
-
-       /* non networked client */
-       if (dev >= 0 && dev < MAX_OBD_DEVICES) {
-               struct obd_device *obd = &obd_dev[dev];
-               
-               if ((!obd->obd_flags & OBD_ATTACHED) ||
-                   (!obd->obd_flags & OBD_SET_UP)) { 
-                       CERROR("target device %d not att or setup\n", dev);
-                       return -EINVAL;
-               }
-                if (strcmp(obd->obd_type->typ_name, "ost") && 
-                    strcmp(obd->obd_type->typ_name, "mds")) { 
-                        return -EINVAL;
-                }
+struct ptlrpc_connection *ptlrpc_uuid_to_connection(char *uuid)
+{
+        struct ptlrpc_connection *c;
+        struct lustre_peer peer;
+        int err;
+
+        err = kportal_uuid_to_peer(uuid, &peer);
+        if (err != 0) {
+                CERROR("cannot find peer %s!\n", uuid);
+                return NULL;
+        }
 
-               cl->cli_obd = &obd_dev[dev];
-               return 0;
-       }
+        c = ptlrpc_get_connection(&peer);
+        if (c)
+                c->c_epoch++;
 
-       /* networked */
-       err = kportal_uuid_to_peer(uuid, &cl->cli_server);
-       if (err != 0) { 
-               CERROR("cannot find peer %s!", uuid); 
-       }
+        return c;
+}
 
-        return err;
+void ptlrpc_readdress_connection(struct ptlrpc_connection *conn, char *uuid)
+{
+        struct lustre_peer peer;
+        int err;
+
+        err = kportal_uuid_to_peer(uuid, &peer);
+        if (err != 0) {
+                CERROR("cannot find peer %s!\n", uuid);
+                return;
+        }
+        
+        memcpy(&conn->c_peer, &peer, sizeof(peer)); 
+        return;
 }
 
-struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct lustre_peer *peer)
+struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct ptlrpc_connection *conn)
 {
         struct ptlrpc_bulk_desc *bulk;
 
         OBD_ALLOC(bulk, sizeof(*bulk));
         if (bulk != NULL) {
-                memset(bulk, 0, sizeof(*bulk));
-                memcpy(&bulk->b_peer, peer, sizeof(*peer));
+                bulk->b_connection = ptlrpc_connection_addref(conn);
                 init_waitqueue_head(&bulk->b_waitq);
+                INIT_LIST_HEAD(&bulk->b_page_list);
         }
 
         return bulk;
 }
 
-struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl, 
-                                       int opcode, int namelen, char *name,
-                                       int tgtlen, char *tgt)
+struct ptlrpc_bulk_page *ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc)
 {
-       struct ptlrpc_request *request;
-       int rc;
-       ENTRY; 
-
-       OBD_ALLOC(request, sizeof(*request));
-       if (!request) { 
-               CERROR("request allocation out of memory\n");
-               return NULL;
-       }
-
-       memset(request, 0, sizeof(*request));
-
-        spin_lock(&cl->cli_lock);
-       request->rq_xid = cl->cli_xid++;
-        spin_unlock(&cl->cli_lock);
-
-       rc = cl->cli_req_pack(name, namelen, tgt, tgtlen,
-                         &request->rq_reqhdr, &request->rq_req,
-                         &request->rq_reqlen, &request->rq_reqbuf);
-       if (rc) { 
-               CERROR("cannot pack request %d\n", rc); 
-               return NULL;
-       }
-       request->rq_reqhdr->opc = opcode;
-       request->rq_reqhdr->xid = request->rq_xid;
-
-       EXIT;
-       return request;
+        struct ptlrpc_bulk_page *page;
+
+        OBD_ALLOC(page, sizeof(*page));
+        if (page != NULL) {
+                page->b_desc = desc;
+                ptl_set_inv_handle(&page->b_md_h);
+                ptl_set_inv_handle(&page->b_me_h);
+                list_add(&page->b_link, &desc->b_page_list);
+                desc->b_page_count++;
+        }
+        return page;
+}
+
+void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk)
+{
+        struct list_head *tmp, *next;
+        ENTRY;
+        if (bulk == NULL) {
+                EXIT;
+                return;
+        }
+
+        list_for_each_safe(tmp, next, &bulk->b_page_list) {
+                struct ptlrpc_bulk_page *page;
+                page = list_entry(tmp, struct ptlrpc_bulk_page, b_link);
+                ptlrpc_free_bulk_page(page);
+        }
+
+        ptlrpc_put_connection(bulk->b_connection);
+
+        OBD_FREE(bulk, sizeof(*bulk));
+        EXIT;
+}
+
+void ptlrpc_free_bulk_page(struct ptlrpc_bulk_page *page)
+{
+        ENTRY;
+        if (page == NULL) {
+                EXIT;
+                return;
+        }
+
+        list_del(&page->b_link);
+        page->b_desc->b_page_count--;
+        OBD_FREE(page, sizeof(*page));
+        EXIT;
+}
+
+struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl,
+                                       struct ptlrpc_connection *conn,
+                                       int opcode, int count, int *lengths,
+                                       char **bufs)
+{
+        struct ptlrpc_request *request;
+        int rc;
+        ENTRY;
+
+        OBD_ALLOC(request, sizeof(*request));
+        if (!request) {
+                CERROR("request allocation out of memory\n");
+                RETURN(NULL);
+        }
+
+        rc = lustre_pack_msg(count, lengths, bufs,
+                             &request->rq_reqlen, &request->rq_reqmsg);
+        if (rc) {
+                CERROR("cannot pack request %d\n", rc);
+                RETURN(NULL);
+        }
+
+        request->rq_type = PTL_RPC_TYPE_REQUEST;
+        request->rq_connection = ptlrpc_connection_addref(conn);
+
+        request->rq_reqmsg->conn = (__u64)(unsigned long)conn->c_remote_conn;
+        request->rq_reqmsg->token = conn->c_remote_token;
+        request->rq_reqmsg->opc = HTON__u32(opcode);
+        request->rq_reqmsg->type = HTON__u32(PTL_RPC_MSG_REQUEST);
+        INIT_LIST_HEAD(&request->rq_list);
+
+        /* this will be dec()d once in req_finished, once in free_committed */
+        atomic_set(&request->rq_refcount, 2);
+
+        spin_lock(&conn->c_lock);
+        request->rq_reqmsg->xid = HTON__u32(++conn->c_xid_out);
+        request->rq_xid = conn->c_xid_out;
+        spin_unlock(&conn->c_lock);
+
+        request->rq_client = cl;
+
+        RETURN(request);
+}
+
+void ptlrpc_req_finished(struct ptlrpc_request *request)
+{
+        if (request == NULL)
+                return;
+
+        if (request->rq_repmsg != NULL) { 
+                OBD_FREE(request->rq_repmsg, request->rq_replen);
+                request->rq_repmsg = NULL;
+                request->rq_reply_md.start = NULL; 
+        }
+
+        if (atomic_dec_and_test(&request->rq_refcount))
+                ptlrpc_free_req(request);
 }
 
 void ptlrpc_free_req(struct ptlrpc_request *request)
@@ -160,27 +213,72 @@ void ptlrpc_free_req(struct ptlrpc_request *request)
         if (request == NULL)
                 return;
 
-        if (request->rq_repbuf != NULL)
-                OBD_FREE(request->rq_repbuf, request->rq_replen);
-       OBD_FREE(request, sizeof(*request));
+        if (request->rq_repmsg != NULL)
+                OBD_FREE(request->rq_repmsg, request->rq_replen);
+        if (request->rq_reqmsg != NULL)
+                OBD_FREE(request->rq_reqmsg, request->rq_reqlen);
+
+        if (request->rq_client) {
+                spin_lock(&request->rq_client->cli_lock);
+                list_del_init(&request->rq_list);
+                spin_unlock(&request->rq_client->cli_lock);
+        }
+
+        ptlrpc_put_connection(request->rq_connection);
+
+        OBD_FREE(request, sizeof(*request));
 }
 
 static int ptlrpc_check_reply(struct ptlrpc_request *req)
 {
-        if (req->rq_repbuf != NULL) {
-                req->rq_flags = PTL_RPC_REPLY;
-                EXIT;
-                return 1;
+        int rc = 0;
+
+        if (req->rq_repmsg != NULL) {
+                req->rq_transno = NTOH__u64(req->rq_repmsg->transno);
+                req->rq_flags |= PTL_RPC_FL_REPLIED;
+                GOTO(out, rc = 1);
+        }
+
+        if (req->rq_flags & PTL_RPC_FL_RESEND) { 
+                CERROR("-- RESEND --\n");
+                GOTO(out, rc = 1);
+        }
+
+        if (req->rq_flags & PTL_RPC_FL_RECOVERY) { 
+                CERROR("-- RESTART --\n");
+                GOTO(out, rc = 1);
+        }
+
+
+        if (CURRENT_TIME - req->rq_time >= req->rq_timeout) {
+                CERROR("-- REQ TIMEOUT --\n");
+                /* clear the timeout */
+                req->rq_timeout = 0;
+                req->rq_connection->c_level = LUSTRE_CONN_RECOVD;
+                req->rq_flags |= PTL_RPC_FL_TIMEOUT;
+                if (req->rq_client && req->rq_client->cli_recovd)
+                        recovd_cli_fail(req->rq_client);
+                if (req->rq_level < LUSTRE_CONN_FULL)
+                        rc = -ETIMEDOUT;
+                else 
+                        rc = 0;
+
+                GOTO(out, rc);
+        }
+
+        if (req->rq_timeout) { 
+                schedule_timeout(req->rq_timeout * HZ);
         }
 
         if (sigismember(&(current->pending.signal), SIGKILL) ||
-            sigismember(&(current->pending.signal), SIGINT)) { 
-                req->rq_flags = PTL_RPC_INTR;
-                EXIT;
-                return 1;
+            sigismember(&(current->pending.signal), SIGTERM) ||
+            sigismember(&(current->pending.signal), SIGINT)) {
+                req->rq_flags |= PTL_RPC_FL_INTR;
+                GOTO(out, rc = 1);
         }
 
-        return 0;
+ out:
+        return rc;
 }
 
 int ptlrpc_check_status(struct ptlrpc_request *req, int err)
@@ -189,100 +287,292 @@ int ptlrpc_check_status(struct ptlrpc_request *req, int err)
 
         if (err != 0) {
                 CERROR("err is %d\n", err);
-                EXIT;
-                return err;
+                RETURN(err);
         }
 
         if (req == NULL) {
                 CERROR("req == NULL\n");
-                EXIT;
-                return -ENOMEM;
+                RETURN(-ENOMEM);
         }
 
-        if (req->rq_rephdr == NULL) {
-                CERROR("req->rq_rephdr == NULL\n");
-                EXIT;
-                return -ENOMEM;
+        if (req->rq_repmsg == NULL) {
+                CERROR("req->rq_repmsg == NULL\n");
+                RETURN(-ENOMEM);
         }
 
-        if (req->rq_rephdr->status != 0) {
-                CERROR("req->rq_rephdr->status is %d\n",
-                       req->rq_rephdr->status);
-                EXIT;
+        if (req->rq_repmsg->type == NTOH__u32(PTL_RPC_MSG_ERR)) {
+                CERROR("req->rq_repmsg->type == PTL_RPC_MSG_ERR\n");
+                RETURN(-EINVAL);
+        }
+
+        if (req->rq_repmsg->status != 0) {
+                CERROR("req->rq_repmsg->status is %d\n",
+                       req->rq_repmsg->status);
                 /* XXX: translate this error from net to host */
-                return req->rq_rephdr->status;
+                RETURN(req->rq_repmsg->status);
         }
 
-        EXIT;
-        return 0;
+        RETURN(0);
+}
+
+static void ptlrpc_cleanup_request_buf(struct ptlrpc_request *request)
+{
+        OBD_FREE(request->rq_reqmsg, request->rq_reqlen);
+        request->rq_reqmsg = NULL;
+        request->rq_reqlen = 0;
 }
 
 /* Abort this request and cleanup any resources associated with it. */
-int ptlrpc_abort(struct ptlrpc_request *request)
+static int ptlrpc_abort(struct ptlrpc_request *request)
 {
-        /* First remove the MD for the reply; in theory, this means
+        /* First remove the ME for the reply; in theory, this means
          * that we can tear down the buffer safely. */
         PtlMEUnlink(request->rq_reply_me_h);
-        PtlMDUnlink(request->rq_reply_md_h);
-        OBD_FREE(request->rq_repbuf, request->rq_replen);
-        request->rq_repbuf = NULL;
+        OBD_FREE(request->rq_reply_md.start, request->rq_replen);
+        request->rq_repmsg = NULL;
         request->rq_replen = 0;
-
         return 0;
 }
 
-int ptlrpc_queue_wait(struct ptlrpc_client *cl, struct ptlrpc_request *req)
-                             
+/* caller must lock cli */
+void ptlrpc_free_committed(struct ptlrpc_client *cli)
 {
-       int rc;
+        struct list_head *tmp, *saved;
+        struct ptlrpc_request *req;
+
+        list_for_each_safe(tmp, saved, &cli->cli_sending_head) {
+                req = list_entry(tmp, struct ptlrpc_request, rq_list);
+
+                if ( (req->rq_flags & PTL_RPC_FL_REPLAY) ) { 
+                        CDEBUG(D_INFO, "Retaining request %Ld for replay\n",
+                               req->rq_xid);
+                        continue;
+                }
+                        
+                /* not yet committed */ 
+                if (!req->rq_transno ||
+                    req->rq_transno > cli->cli_last_committed)
+                        break; 
+
+                CDEBUG(D_INFO, "Marking request %Ld as committed ("
+                       "transno=%Lu, last_committed=%Lu\n", 
+                       req->rq_xid, req->rq_transno, 
+                       cli->cli_last_committed);
+                if (atomic_dec_and_test(&req->rq_refcount)) {
+                        /* we do this to prevent free_req deadlock */
+                        list_del_init(&req->rq_list); 
+                        req->rq_client = NULL;
+                        ptlrpc_free_req(req);
+                } else {
+                        list_del_init(&req->rq_list);
+                        list_add(&req->rq_list, &cli->cli_dying_head);
+                }
+        }
+
+        EXIT;
+        return;
+}
+
+void ptlrpc_cleanup_client(struct ptlrpc_client *cli)
+{
+        struct list_head *tmp, *saved;
+        struct ptlrpc_request *req;
         ENTRY;
 
-       init_waitqueue_head(&req->rq_wait_for_rep);
-
-       if (cl->cli_obd) {
-               /* Local delivery */
-                ENTRY;
-               rc = ptlrpc_enqueue(cl, req); 
-       } else {
-               /* Remote delivery via portals. */
-               req->rq_req_portal = cl->cli_request_portal;
-               req->rq_reply_portal = cl->cli_reply_portal;
-               rc = ptl_send_rpc(req, &cl->cli_server);
-       }
-       if (rc) { 
-                CERROR("error %d, opcode %d\n", rc, req->rq_reqhdr->opc);
-               return -rc;
-       }
+        spin_lock(&cli->cli_lock);
+        list_for_each_safe(tmp, saved, &cli->cli_sending_head) {
+                req = list_entry(tmp, struct ptlrpc_request, rq_list);
+                CDEBUG(D_INFO, "Cleaning req %p from sending list.\n", req);
+                list_del_init(&req->rq_list);
+                req->rq_client = NULL;
+                ptlrpc_free_req(req); 
+        }
+        list_for_each_safe(tmp, saved, &cli->cli_dying_head) {
+                req = list_entry(tmp, struct ptlrpc_request, rq_list);
+                CERROR("Request %p is on the dying list at cleanup!\n", req);
+                list_del_init(&req->rq_list);
+                req->rq_client = NULL;
+                ptlrpc_free_req(req); 
+        }
+        spin_unlock(&cli->cli_lock);
+
+        EXIT;
+        return;
+}
+
+void ptlrpc_continue_req(struct ptlrpc_request *req)
+{
+        ENTRY;
+        CDEBUG(D_INODE, "continue delayed request %Ld opc %d\n", 
+               req->rq_xid, req->rq_reqmsg->opc); 
+        wake_up_interruptible(&req->rq_wait_for_rep); 
+        EXIT;
+}
+
+void ptlrpc_resend_req(struct ptlrpc_request *req)
+{
+        ENTRY;
+        CDEBUG(D_INODE, "resend request %Ld, opc %d\n", 
+               req->rq_xid, req->rq_reqmsg->opc);
+        req->rq_status = -EAGAIN;
+        req->rq_level = LUSTRE_CONN_RECOVD;
+        req->rq_flags |= PTL_RPC_FL_RESEND;
+        req->rq_flags &= ~PTL_RPC_FL_TIMEOUT;
+        wake_up_interruptible(&req->rq_wait_for_rep);
+        EXIT;
+}
+
+void ptlrpc_restart_req(struct ptlrpc_request *req)
+{
+        ENTRY;
+        CDEBUG(D_INODE, "restart completed request %Ld, opc %d\n", 
+               req->rq_xid, req->rq_reqmsg->opc);
+        req->rq_status = -ERESTARTSYS;
+        req->rq_flags |= PTL_RPC_FL_RECOVERY;
+        req->rq_flags &= ~PTL_RPC_FL_TIMEOUT;
+        wake_up_interruptible(&req->rq_wait_for_rep);
+        EXIT;
+}
+
+int ptlrpc_queue_wait(struct ptlrpc_request *req)
+{
+        int rc = 0;
+        struct ptlrpc_client *cli = req->rq_client;
+        ENTRY;
+
+        init_waitqueue_head(&req->rq_wait_for_rep);
+        CERROR("subsys: %s req %Ld opc %d level %d, conn level %d\n", 
+               cli->cli_name, req->rq_xid, req->rq_reqmsg->opc, req->rq_level,
+               req->rq_connection->c_level);
+
+        /* XXX probably both an import and connection level are needed */
+        if (req->rq_level > req->rq_connection->c_level) { 
+                CERROR("process %d waiting for recovery\n", current->pid);
+                spin_lock(&cli->cli_lock);
+                list_del_init(&req->rq_list);
+                list_add(&req->rq_list, cli->cli_delayed_head.prev); 
+                spin_unlock(&cli->cli_lock);
+                wait_event_interruptible
+                        (req->rq_wait_for_rep, 
+                         req->rq_level <= req->rq_connection->c_level);
+                spin_lock(&cli->cli_lock);
+                list_del_init(&req->rq_list);
+                spin_unlock(&cli->cli_lock);
+                CERROR("process %d resumed\n", current->pid);
+        }
+ resend:
+        req->rq_time = CURRENT_TIME;
+        req->rq_timeout = 30;
+        rc = ptl_send_rpc(req);
+        if (rc) {
+                CERROR("error %d, opcode %d\n", rc, req->rq_reqmsg->opc);
+                if ( rc > 0 ) 
+                        rc = -rc;
+                ptlrpc_cleanup_request_buf(req);
+                up(&cli->cli_rpc_sem);
+                RETURN(-rc);
+        }
+
+        spin_lock(&cli->cli_lock);
+        list_del_init(&req->rq_list);
+        list_add(&req->rq_list, cli->cli_sending_head.prev);
+        spin_unlock(&cli->cli_lock);
 
         CDEBUG(D_OTHER, "-- sleeping\n");
-        wait_event_interruptible(req->rq_wait_for_rep, ptlrpc_check_reply(req));
+        wait_event_interruptible(req->rq_wait_for_rep, 
+                                 ptlrpc_check_reply(req));
         CDEBUG(D_OTHER, "-- done\n");
-        
-        if (req->rq_flags == PTL_RPC_INTR) { 
+
+        if (req->rq_flags & PTL_RPC_FL_RESEND) {
+                req->rq_flags &= ~PTL_RPC_FL_RESEND;
+                goto resend;
+        }
+
+        up(&cli->cli_rpc_sem);
+        if (req->rq_flags & PTL_RPC_FL_INTR) {
                 /* Clean up the dangling reply buffers */
                 ptlrpc_abort(req);
-                EXIT;
-                return -EINTR;
+                GOTO(out, rc = -EINTR);
+        }
+
+        if (! (req->rq_flags & PTL_RPC_FL_REPLIED)) {
+                GOTO(out, rc = req->rq_status);
         }
 
-        if (req->rq_flags != PTL_RPC_REPLY) { 
+        rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
+        if (rc) {
+                CERROR("unpack_rep failed: %d\n", rc);
+                GOTO(out, rc);
+        }
+        CDEBUG(D_NET, "got rep %d\n", req->rq_repmsg->xid);
+        if (req->rq_repmsg->status == 0)
+                CDEBUG(D_NET, "--> buf %p len %d status %d\n", req->rq_repmsg,
+                       req->rq_replen, req->rq_repmsg->status);
+
+        spin_lock(&cli->cli_lock);
+        cli->cli_last_rcvd = req->rq_repmsg->last_rcvd;
+        cli->cli_last_committed = req->rq_repmsg->last_committed;
+        ptlrpc_free_committed(cli); 
+        spin_unlock(&cli->cli_lock);
+
+        EXIT;
+ out:
+        return rc;
+}
+
+int ptlrpc_replay_req(struct ptlrpc_request *req)
+{
+        int rc = 0;
+        struct ptlrpc_client *cli = req->rq_client;
+        ENTRY;
+
+        init_waitqueue_head(&req->rq_wait_for_rep);
+        CERROR("req %Ld opc %d level %d, conn level %d\n", 
+               req->rq_xid, req->rq_reqmsg->opc, req->rq_level,
+               req->rq_connection->c_level);
+
+        req->rq_time = CURRENT_TIME;
+        req->rq_timeout = 3;
+        rc = ptl_send_rpc(req);
+        if (rc) {
+                CERROR("error %d, opcode %d\n", rc, req->rq_reqmsg->opc);
+                ptlrpc_cleanup_request_buf(req);
+                up(&cli->cli_rpc_sem);
+                RETURN(-rc);
+        }
+
+        CDEBUG(D_OTHER, "-- sleeping\n");
+        wait_event_interruptible(req->rq_wait_for_rep, 
+                                 ptlrpc_check_reply(req));
+        CDEBUG(D_OTHER, "-- done\n");
+
+        up(&cli->cli_rpc_sem);
+
+        if (!(req->rq_flags & PTL_RPC_FL_REPLIED)) {
                 CERROR("Unknown reason for wakeup\n");
-                EXIT;
-                return -EINTR;
+                /* XXX Phil - I end up here when I kill obdctl */
+                ptlrpc_abort(req);
+                GOTO(out, rc = -EINTR);
         }
 
-       rc = cl->cli_rep_unpack(req->rq_repbuf, req->rq_replen,
-                                &req->rq_rephdr, &req->rq_rep);
-       if (rc) {
-               CERROR("unpack_rep failed: %d\n", rc);
-               return rc;
-       }
-        CDEBUG(D_NET, "got rep %d\n", req->rq_rephdr->xid);
+        rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
+        if (rc) {
+                CERROR("unpack_rep failed: %d\n", rc);
+                GOTO(out, rc);
+        }
 
-       if ( req->rq_rephdr->status == 0 )
-                CDEBUG(D_NET, "--> buf %p len %d status %d\n", req->rq_repbuf,
-                       req->rq_replen, req->rq_rephdr->status);
+        CDEBUG(D_NET, "got rep %d\n", req->rq_repmsg->xid);
+        if (req->rq_repmsg->status == 0)
+                CDEBUG(D_NET, "--> buf %p len %d status %d\n", req->rq_repmsg,
+                       req->rq_replen, req->rq_repmsg->status);
+        else {
+                CERROR("recovery failed: "); 
+                CERROR("req %Ld opc %d level %d, conn level %d\n", 
+                       req->rq_xid, req->rq_reqmsg->opc, req->rq_level,
+                       req->rq_connection->c_level);
+                LBUG();
+        }
 
-       EXIT;
-       return 0;
+ out:
+        RETURN(rc);
 }