Whamcloud - gitweb
Don't LBUG on OOM in setup.
[fs/lustre-release.git] / lustre / ptlrpc / client.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #define DEBUG_SUBSYSTEM S_RPC
24
25 #include <linux/obd_support.h>
26 #include <linux/obd_class.h>
27 #include <linux/lustre_lib.h>
28 #include <linux/lustre_ha.h>
29 #include <linux/lustre_import.h>
30
31 void ptlrpc_init_client(int req_portal, int rep_portal, char *name, 
32                         struct ptlrpc_client *cl)
33 {
34         cl->cli_request_portal = req_portal;
35         cl->cli_reply_portal   = rep_portal;
36         cl->cli_name           = name;
37 }
38
39 __u8 *ptlrpc_req_to_uuid(struct ptlrpc_request *req)
40 {
41         return req->rq_connection->c_remote_uuid;
42 }
43
44 struct ptlrpc_connection *ptlrpc_uuid_to_connection(obd_uuid_t uuid)
45 {
46         struct ptlrpc_connection *c;
47         struct lustre_peer peer;
48         int err;
49
50         err = kportal_uuid_to_peer(uuid, &peer);
51         if (err != 0) {
52                 CERROR("cannot find peer %s!\n", uuid);
53                 return NULL;
54         }
55
56         c = ptlrpc_get_connection(&peer, uuid);
57         if (c) { 
58                 memcpy(c->c_remote_uuid, uuid, sizeof(c->c_remote_uuid));
59                 c->c_epoch++;
60         }
61
62         CDEBUG(D_INFO, "%s -> %p\n", uuid, c);
63
64         return c;
65 }
66
67 void ptlrpc_readdress_connection(struct ptlrpc_connection *conn,obd_uuid_t uuid)
68 {
69         struct lustre_peer peer;
70         int err;
71
72         err = kportal_uuid_to_peer(uuid, &peer);
73         if (err != 0) {
74                 CERROR("cannot find peer %s!\n", uuid);
75                 return;
76         }
77         
78         memcpy(&conn->c_peer, &peer, sizeof(peer)); 
79         return;
80 }
81
82 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct ptlrpc_connection *conn)
83 {
84         struct ptlrpc_bulk_desc *desc;
85
86         OBD_ALLOC(desc, sizeof(*desc));
87         if (desc != NULL) {
88                 desc->bd_connection = ptlrpc_connection_addref(conn);
89                 atomic_set(&desc->bd_refcount, 1);
90                 init_waitqueue_head(&desc->bd_waitq);
91                 INIT_LIST_HEAD(&desc->bd_page_list);
92                 ptl_set_inv_handle(&desc->bd_md_h);
93                 ptl_set_inv_handle(&desc->bd_me_h);
94         }
95
96         return desc;
97 }
98
99 struct ptlrpc_bulk_page *ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc)
100 {
101         struct ptlrpc_bulk_page *bulk;
102
103         OBD_ALLOC(bulk, sizeof(*bulk));
104         if (bulk != NULL) {
105                 bulk->bp_desc = desc;
106                 list_add_tail(&bulk->bp_link, &desc->bd_page_list);
107                 desc->bd_page_count++;
108         }
109         return bulk;
110 }
111
112 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *desc)
113 {
114         struct list_head *tmp, *next;
115         ENTRY;
116         if (desc == NULL) {
117                 EXIT;
118                 return;
119         }
120
121         list_for_each_safe(tmp, next, &desc->bd_page_list) {
122                 struct ptlrpc_bulk_page *bulk;
123                 bulk = list_entry(tmp, struct ptlrpc_bulk_page, bp_link);
124                 ptlrpc_free_bulk_page(bulk);
125         }
126
127         ptlrpc_put_connection(desc->bd_connection);
128
129         OBD_FREE(desc, sizeof(*desc));
130         EXIT;
131 }
132
133 void ptlrpc_free_bulk_page(struct ptlrpc_bulk_page *bulk)
134 {
135         ENTRY;
136         if (bulk == NULL) {
137                 EXIT;
138                 return;
139         }
140
141         list_del(&bulk->bp_link);
142         bulk->bp_desc->bd_page_count--;
143         OBD_FREE(bulk, sizeof(*bulk));
144         EXIT;
145 }
146
147 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, int opcode,
148                                        int count, int *lengths, char **bufs)
149 {
150         struct ptlrpc_connection *conn = imp->imp_connection;
151         struct ptlrpc_request *request;
152         int rc;
153         ENTRY;
154
155         OBD_ALLOC(request, sizeof(*request));
156         if (!request) {
157                 CERROR("request allocation out of memory\n");
158                 RETURN(NULL);
159         }
160
161         rc = lustre_pack_msg(count, lengths, bufs,
162                              &request->rq_reqlen, &request->rq_reqmsg);
163         if (rc) {
164                 CERROR("cannot pack request %d\n", rc);
165                 OBD_FREE(request, sizeof(*request));
166                 RETURN(NULL);
167         }
168
169         request->rq_level = LUSTRE_CONN_FULL;
170         request->rq_type = PTL_RPC_MSG_REQUEST;
171         request->rq_import = imp;
172         request->rq_connection = ptlrpc_connection_addref(conn);
173
174         INIT_LIST_HEAD(&request->rq_list);
175         /*
176          * This will be reduced once when the sender is finished (waiting for
177          * reply, f.e.), once when the request has been committed and is
178          * removed from the to-be-committed list, and once when portals is
179          * finished with it and has called request_out_callback.
180          *
181          * (Except in the DLM server case, where it will be dropped twice
182          * by the sender, and then the last time by request_out_callback.)
183          */
184         atomic_set(&request->rq_refcount, 3);
185
186         spin_lock(&conn->c_lock);
187         request->rq_xid = HTON__u32(++conn->c_xid_out);
188         spin_unlock(&conn->c_lock);
189
190         request->rq_reqmsg->magic = PTLRPC_MSG_MAGIC; 
191         request->rq_reqmsg->version = PTLRPC_MSG_VERSION;
192         request->rq_reqmsg->opc = HTON__u32(opcode);
193
194         ptlrpc_hdl2req(request, &imp->imp_handle);
195         RETURN(request);
196 }
197
198 void ptlrpc_req_finished(struct ptlrpc_request *request)
199 {
200         if (request == NULL)
201                 return;
202
203         if (request->rq_repmsg != NULL) { 
204                 OBD_FREE(request->rq_repmsg, request->rq_replen);
205                 request->rq_repmsg = NULL;
206                 request->rq_reply_md.start = NULL; 
207         }
208
209         if (atomic_dec_and_test(&request->rq_refcount))
210                 ptlrpc_free_req(request);
211 }
212
213 void ptlrpc_free_req(struct ptlrpc_request *request)
214 {
215         ENTRY;
216         if (request == NULL) {
217                 EXIT;
218                 return;
219         }
220
221         if (request->rq_repmsg != NULL)
222                 OBD_FREE(request->rq_repmsg, request->rq_replen);
223         if (request->rq_reqmsg != NULL)
224                 OBD_FREE(request->rq_reqmsg, request->rq_reqlen);
225
226         if (request->rq_connection) {
227                 spin_lock(&request->rq_connection->c_lock);
228                 list_del_init(&request->rq_list);
229                 spin_unlock(&request->rq_connection->c_lock);
230         }
231
232         ptlrpc_put_connection(request->rq_connection);
233         OBD_FREE(request, sizeof(*request));
234         EXIT;
235 }
236
237 static int ptlrpc_check_reply(struct ptlrpc_request *req)
238 {
239         int rc = 0;
240
241         if (req->rq_repmsg != NULL) {
242                 req->rq_transno = NTOH__u64(req->rq_repmsg->transno);
243                 req->rq_flags |= PTL_RPC_FL_REPLIED;
244                 GOTO(out, rc = 1);
245         }
246
247         if (req->rq_flags & PTL_RPC_FL_RESEND) { 
248                 CERROR("-- RESTART --\n");
249                 GOTO(out, rc = 1);
250         }
251
252  out:
253         CDEBUG(D_NET, "req = %p, rc = %d\n", req, rc);
254         return rc;
255 }
256
257 int ptlrpc_check_status(struct ptlrpc_request *req, int err)
258 {
259         ENTRY;
260
261         if (err != 0) {
262                 CERROR("err is %d\n", err);
263                 RETURN(err);
264         }
265
266         if (req == NULL) {
267                 CERROR("req == NULL\n");
268                 RETURN(-ENOMEM);
269         }
270
271         if (req->rq_repmsg == NULL) {
272                 CERROR("req->rq_repmsg == NULL\n");
273                 RETURN(-ENOMEM);
274         }
275
276         err = req->rq_repmsg->status;
277         if (req->rq_repmsg->type == NTOH__u32(PTL_RPC_MSG_ERR)) {
278                 CERROR("req->rq_repmsg->type == PTL_RPC_MSG_ERR\n");
279                 RETURN(err ? err : -EINVAL);
280         }
281
282         if (err != 0) {
283                 if (err < 0)
284                         CERROR("req->rq_repmsg->status is %d\n", err);
285                 else
286                         CDEBUG(D_INFO, "req->rq_repmsg->status is %d\n", err);
287                 /* XXX: translate this error from net to host */
288                 RETURN(err);
289         }
290
291         RETURN(0);
292 }
293
294 static void ptlrpc_cleanup_request_buf(struct ptlrpc_request *request)
295 {
296         OBD_FREE(request->rq_reqmsg, request->rq_reqlen);
297         request->rq_reqmsg = NULL;
298         request->rq_reqlen = 0;
299 }
300
301 /* Abort this request and cleanup any resources associated with it. */
302 static int ptlrpc_abort(struct ptlrpc_request *request)
303 {
304         /* First remove the ME for the reply; in theory, this means
305          * that we can tear down the buffer safely. */
306         PtlMEUnlink(request->rq_reply_me_h);
307         OBD_FREE(request->rq_reply_md.start, request->rq_replen);
308         request->rq_repmsg = NULL;
309         request->rq_replen = 0;
310         return 0;
311 }
312
313 /* caller must hold conn->c_lock */
314 void ptlrpc_free_committed(struct ptlrpc_connection *conn)
315 {
316         struct list_head *tmp, *saved;
317         struct ptlrpc_request *req;
318
319 restart:
320         list_for_each_safe(tmp, saved, &conn->c_sending_head) {
321                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
322
323                 if (req->rq_flags & PTL_RPC_FL_REPLAY) {
324                         CDEBUG(D_INFO, "Keeping req %p xid "LPD64" for replay\n",
325                                req, req->rq_xid);
326                         continue;
327                 }
328
329                 if (!(req->rq_flags & PTL_RPC_FL_REPLIED)) {
330                         CDEBUG(D_INFO, "Keeping in-flight req %p xid "LPD64
331                                " for replay\n", req, req->rq_xid);
332                         continue;
333                 }
334
335                 /* not yet committed */
336                 if (req->rq_transno > conn->c_last_committed)
337                         break;
338                 
339                 CDEBUG(D_INFO, "Marking request %p xid %Ld as committed "
340                        "transno=%Lu, last_committed=%Lu\n", req,
341                        (long long)req->rq_xid, (long long)req->rq_transno,
342                        (long long)conn->c_last_committed);
343                 if (atomic_dec_and_test(&req->rq_refcount)) {
344                         req->rq_import = NULL;
345
346                         /* We do this to prevent free_req deadlock.  Restarting
347                          * after each removal is not so bad, as we are almost
348                          * always deleting the first item in the list.
349                          */
350                         spin_unlock(&conn->c_lock);
351                         ptlrpc_free_req(req);
352                         spin_lock(&conn->c_lock);
353                         goto restart;
354                 } else {
355                         list_del(&req->rq_list);
356                         list_add(&req->rq_list, &conn->c_dying_head);
357                 }
358         }
359
360         EXIT;
361         return;
362 }
363
364 void ptlrpc_cleanup_client(struct obd_import *imp)
365 {
366         struct list_head *tmp, *saved;
367         struct ptlrpc_request *req;
368         struct ptlrpc_connection *conn = imp->imp_connection;
369         ENTRY;
370
371         LASSERT(conn);
372
373 restart1:
374         spin_lock(&conn->c_lock);
375         list_for_each_safe(tmp, saved, &conn->c_sending_head) {
376                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
377                 if (req->rq_import != imp)
378                         continue;
379                 CDEBUG(D_INFO, "Cleaning req %p from sending list.\n", req);
380                 list_del_init(&req->rq_list);
381                 req->rq_import = NULL;
382                 spin_unlock(&conn->c_lock);
383                 ptlrpc_free_req(req);
384                 goto restart1;
385         }
386 restart2:
387         list_for_each_safe(tmp, saved, &conn->c_dying_head) {
388                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
389                 if (req->rq_import != imp)
390                         continue;
391                 CERROR("Request %p is on the dying list at cleanup!\n", req);
392                 list_del_init(&req->rq_list);
393                 req->rq_import = NULL;
394                 spin_unlock(&conn->c_lock);
395                 ptlrpc_free_req(req); 
396                 spin_lock(&conn->c_lock);
397                 goto restart2;
398         }
399         spin_unlock(&conn->c_lock);
400
401         EXIT;
402         return;
403 }
404
405 void ptlrpc_continue_req(struct ptlrpc_request *req)
406 {
407         ENTRY;
408         CDEBUG(D_INODE, "continue delayed request "LPD64" opc %d\n", 
409                req->rq_xid, req->rq_reqmsg->opc); 
410         req->rq_reqmsg->addr = req->rq_import->imp_handle.addr;
411         req->rq_reqmsg->cookie = req->rq_import->imp_handle.cookie;
412         wake_up(&req->rq_wait_for_rep); 
413         EXIT;
414 }
415
416 void ptlrpc_resend_req(struct ptlrpc_request *req)
417 {
418         ENTRY;
419         CDEBUG(D_INODE, "resend request "LPD64", opc %d\n", 
420                req->rq_xid, req->rq_reqmsg->opc);
421         req->rq_reqmsg->addr = req->rq_import->imp_handle.addr;
422         req->rq_reqmsg->cookie = req->rq_import->imp_handle.cookie;
423         req->rq_status = -EAGAIN;
424         req->rq_level = LUSTRE_CONN_RECOVD;
425         req->rq_flags |= PTL_RPC_FL_RESEND;
426         req->rq_flags &= ~PTL_RPC_FL_TIMEOUT;
427         wake_up(&req->rq_wait_for_rep);
428         EXIT;
429 }
430
431 void ptlrpc_restart_req(struct ptlrpc_request *req)
432 {
433         ENTRY;
434         CDEBUG(D_INODE, "restart completed request "LPD64", opc %d\n", 
435                req->rq_xid, req->rq_reqmsg->opc);
436         req->rq_status = -ERESTARTSYS;
437         req->rq_flags |= PTL_RPC_FL_RECOVERY;
438         req->rq_flags &= ~PTL_RPC_FL_TIMEOUT;
439         wake_up(&req->rq_wait_for_rep);
440         EXIT;
441 }
442
443 static int expired_request(void *data)
444 {
445         struct ptlrpc_request *req = data;
446
447         ENTRY;
448         CERROR("req xid "LPD64" op %d: timeout on conn to %s:%d\n",
449                (unsigned long long)req->rq_xid, req->rq_reqmsg->opc,
450                req->rq_connection->c_remote_uuid,
451                req->rq_import->imp_client->cli_request_portal);
452         req->rq_flags |= PTL_RPC_FL_TIMEOUT;
453         if (!req->rq_import->imp_connection->c_recovd_data.rd_recovd)
454                 RETURN(1);
455
456         req->rq_timeout = 0;
457         req->rq_connection->c_level = LUSTRE_CONN_RECOVD;
458         recovd_conn_fail(req->rq_import->imp_connection);
459
460         /* If this request is for recovery or other primordial tasks,
461          * don't go back to sleep.
462          */
463         if (req->rq_level < LUSTRE_CONN_FULL)
464                 RETURN(1);
465         RETURN(0);
466 }
467
468 static int interrupted_request(void *data)
469 {
470         struct ptlrpc_request *req = data;
471         ENTRY;
472         req->rq_flags |= PTL_RPC_FL_INTR;
473         RETURN(1); /* ignored, as of this writing */
474 }
475
476 int ptlrpc_queue_wait(struct ptlrpc_request *req)
477 {
478         int rc = 0;
479         struct l_wait_info lwi;
480         struct ptlrpc_client *cli = req->rq_import->imp_client;
481         struct ptlrpc_connection *conn = req->rq_import->imp_connection;
482         ENTRY;
483
484         init_waitqueue_head(&req->rq_wait_for_rep);
485         CDEBUG(D_NET, "subsys: %s req "LPD64" opc %d level %d, conn level %d\n",
486                cli->cli_name, req->rq_xid, req->rq_reqmsg->opc, req->rq_level,
487                req->rq_connection->c_level);
488
489         /* XXX probably both an import and connection level are needed */
490         if (req->rq_level > conn->c_level) { 
491                 spin_lock(&conn->c_lock);
492                 if (conn->c_flags & CONN_INVALID) {
493                         /* being torn down by "umount -f" */
494                         CERROR("req xid "LPD64" op %d to %s:%d: CONN_INVALID\n",
495                                (unsigned long long)req->rq_xid,
496                                req->rq_reqmsg->opc,
497                                req->rq_connection->c_remote_uuid,
498                                req->rq_import->imp_client->cli_request_portal);
499                         spin_unlock(&conn->c_lock);
500                         RETURN(-EIO);
501                 }
502                 list_del(&req->rq_list);
503                 list_add_tail(&req->rq_list, &conn->c_delayed_head);
504                 spin_unlock(&conn->c_lock);
505
506                 CERROR("req xid "LPD64" op %d to %s:%d: waiting for recovery "
507                        "(%d < %d)\n",
508                        (unsigned long long)req->rq_xid, req->rq_reqmsg->opc,
509                        req->rq_connection->c_remote_uuid,
510                        req->rq_import->imp_client->cli_request_portal,
511                        req->rq_level, conn->c_level);
512
513                 lwi = LWI_INTR(NULL, NULL);
514                 rc = l_wait_event(req->rq_wait_for_rep,
515                                   (req->rq_level <= conn->c_level) ||
516                                   (req->rq_flags & PTL_RPC_FL_ERR), &lwi);
517
518                 spin_lock(&conn->c_lock);
519                 list_del_init(&req->rq_list);
520                 spin_unlock(&conn->c_lock);
521
522                 if (req->rq_flags & PTL_RPC_FL_ERR)
523                         RETURN(-EIO);
524
525                 if (rc)
526                         RETURN(rc);
527                 
528                 CERROR("process %d resumed\n", current->pid);
529         }
530  resend:
531         req->rq_timeout = obd_timeout;
532         spin_lock(&conn->c_lock);
533         if (conn->c_flags & CONN_INVALID) {
534                 CERROR("req xid "LPD64" op %d to %s:%d: CONN_INVALID\n",
535                        (unsigned long long)req->rq_xid, req->rq_reqmsg->opc,
536                        req->rq_connection->c_remote_uuid,
537                        req->rq_import->imp_client->cli_request_portal);
538                 spin_unlock(&conn->c_lock); /* being torn down by "umount -f" */
539                 RETURN(-EIO);
540         }
541         
542         list_del(&req->rq_list);
543         list_add_tail(&req->rq_list, &conn->c_sending_head);
544         spin_unlock(&conn->c_lock);
545         rc = ptl_send_rpc(req);
546         if (rc) {
547                 CERROR("error %d, opcode %d, need recovery\n", rc,
548                        req->rq_reqmsg->opc);
549                 /* the sleep below will time out, triggering recovery */
550         }
551
552         CDEBUG(D_OTHER, "-- sleeping on xid "LPD64"\n", req->rq_xid);
553         lwi = LWI_TIMEOUT_INTR(req->rq_timeout * HZ, expired_request,
554                                interrupted_request,req);
555         l_wait_event(req->rq_wait_for_rep, ptlrpc_check_reply(req), &lwi);
556         CDEBUG(D_OTHER, "-- done sleeping on xid "LPD64"\n", req->rq_xid);
557
558         /* Don't resend if we were interrupted. */
559         if ((req->rq_flags & (PTL_RPC_FL_RESEND | PTL_RPC_FL_INTR)) ==
560             PTL_RPC_FL_RESEND) {
561                 req->rq_flags &= ~PTL_RPC_FL_RESEND;
562                 CDEBUG(D_OTHER, "resending req %p xid "LPD64"\n",
563                        req, req->rq_xid);
564                 goto resend;
565         }
566
567         // up(&cli->cli_rpc_sem);
568         if (req->rq_flags & PTL_RPC_FL_INTR) {
569                 if (!(req->rq_flags & PTL_RPC_FL_TIMEOUT))
570                         LBUG(); /* should only be interrupted if we timed out */
571                 /* Clean up the dangling reply buffers */
572                 ptlrpc_abort(req);
573                 GOTO(out, rc = -EINTR);
574         }
575
576         if (req->rq_flags & PTL_RPC_FL_TIMEOUT)
577                 GOTO(out, rc = -ETIMEDOUT);
578
579         if (!(req->rq_flags & PTL_RPC_FL_REPLIED))
580                 GOTO(out, rc = req->rq_status);
581
582         rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
583         if (rc) {
584                 CERROR("unpack_rep failed: %d\n", rc);
585                 GOTO(out, rc);
586         }
587 #if 0
588         /* FIXME: Enable when BlueArc makes new release */
589         if (req->rq_repmsg->type != PTL_RPC_MSG_REPLY &&
590             req->rq_repmsg->type != PTL_RPC_MSG_ERR) {
591                 CERROR("invalid packet type received (type=%u)\n",
592                        req->rq_repmsg->type);
593                 LBUG();
594                 GOTO(out, rc = -EINVAL);
595         }
596 #endif
597         CDEBUG(D_NET, "got rep "LPD64"\n", req->rq_xid);
598         if (req->rq_repmsg->status == 0)
599                 CDEBUG(D_NET, "--> buf %p len %d status %d\n", req->rq_repmsg,
600                        req->rq_replen, req->rq_repmsg->status);
601
602         spin_lock(&conn->c_lock);
603         conn->c_last_xid = req->rq_repmsg->last_xid;
604         conn->c_last_committed = req->rq_repmsg->last_committed;
605         ptlrpc_free_committed(conn);
606         spin_unlock(&conn->c_lock);
607
608         EXIT;
609  out:
610         return rc;
611 }
612
613 int ptlrpc_replay_req(struct ptlrpc_request *req)
614 {
615         int rc = 0;
616         // struct ptlrpc_client *cli = req->rq_import->imp_client;
617         struct l_wait_info lwi;
618         ENTRY;
619
620         init_waitqueue_head(&req->rq_wait_for_rep);
621         CDEBUG(D_NET, "req "LPD64" opc %d level %d, conn level %d\n",
622                req->rq_xid, req->rq_reqmsg->opc, req->rq_level,
623                req->rq_connection->c_level);
624
625         req->rq_timeout = obd_timeout;
626         req->rq_reqmsg->addr = req->rq_import->imp_handle.addr;
627         req->rq_reqmsg->cookie = req->rq_import->imp_handle.cookie;
628         rc = ptl_send_rpc(req);
629         if (rc) {
630                 CERROR("error %d, opcode %d\n", rc, req->rq_reqmsg->opc);
631                 ptlrpc_cleanup_request_buf(req);
632                 // up(&cli->cli_rpc_sem);
633                 RETURN(-rc);
634         }
635
636         CDEBUG(D_OTHER, "-- sleeping\n");
637         lwi = LWI_INTR(NULL, NULL);
638         l_wait_event(req->rq_wait_for_rep, ptlrpc_check_reply(req), &lwi);
639         CDEBUG(D_OTHER, "-- done\n");
640
641         // up(&cli->cli_rpc_sem);
642
643         if (!(req->rq_flags & PTL_RPC_FL_REPLIED)) {
644                 CERROR("Unknown reason for wakeup\n");
645                 /* XXX Phil - I end up here when I kill obdctl */
646                 ptlrpc_abort(req);
647                 GOTO(out, rc = -EINTR);
648         }
649
650         rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
651         if (rc) {
652                 CERROR("unpack_rep failed: %d\n", rc);
653                 GOTO(out, rc);
654         }
655
656         CDEBUG(D_NET, "got rep "LPD64"\n", req->rq_xid);
657         if (req->rq_repmsg->status == 0)
658                 CDEBUG(D_NET, "--> buf %p len %d status %d\n", req->rq_repmsg,
659                        req->rq_replen, req->rq_repmsg->status);
660         else {
661                 CERROR("recovery failed: "); 
662                 CERROR("req "LPD64" opc %d level %d, conn level %d\n", 
663                        req->rq_xid, req->rq_reqmsg->opc, req->rq_level,
664                        req->rq_connection->c_level);
665                 LBUG();
666         }
667
668         if (req->rq_replay_cb)
669                 req->rq_replay_cb(req, &req->rq_replay_cb_handle);
670
671  out:
672         RETURN(rc);
673 }