1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
23 #define DEBUG_SUBSYSTEM S_RPC
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>
31 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
32 struct ptlrpc_client *cl)
34 cl->cli_request_portal = req_portal;
35 cl->cli_reply_portal = rep_portal;
39 __u8 *ptlrpc_req_to_uuid(struct ptlrpc_request *req)
41 return req->rq_connection->c_remote_uuid;
44 struct ptlrpc_connection *ptlrpc_uuid_to_connection(obd_uuid_t uuid)
46 struct ptlrpc_connection *c;
47 struct lustre_peer peer;
50 err = kportal_uuid_to_peer(uuid, &peer);
52 CERROR("cannot find peer %s!\n", uuid);
56 c = ptlrpc_get_connection(&peer, uuid);
58 memcpy(c->c_remote_uuid, uuid, sizeof(c->c_remote_uuid));
62 CDEBUG(D_INFO, "%s -> %p\n", uuid, c);
67 void ptlrpc_readdress_connection(struct ptlrpc_connection *conn,obd_uuid_t uuid)
69 struct lustre_peer peer;
72 err = kportal_uuid_to_peer(uuid, &peer);
74 CERROR("cannot find peer %s!\n", uuid);
78 memcpy(&conn->c_peer, &peer, sizeof(peer));
82 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct ptlrpc_connection *conn)
84 struct ptlrpc_bulk_desc *desc;
86 OBD_ALLOC(desc, sizeof(*desc));
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 INIT_LIST_HEAD(&desc->bd_set_chain);
93 ptl_set_inv_handle(&desc->bd_md_h);
94 ptl_set_inv_handle(&desc->bd_me_h);
100 int ptlrpc_bulk_error(struct ptlrpc_bulk_desc *desc)
103 if (desc->bd_flags & PTL_RPC_FL_TIMEOUT) {
104 rc = (desc->bd_flags & PTL_RPC_FL_INTR ? -ERESTARTSYS :
110 struct ptlrpc_bulk_page *ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc)
112 struct ptlrpc_bulk_page *bulk;
114 OBD_ALLOC(bulk, sizeof(*bulk));
116 bulk->bp_desc = desc;
117 list_add_tail(&bulk->bp_link, &desc->bd_page_list);
118 desc->bd_page_count++;
123 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *desc)
125 struct list_head *tmp, *next;
132 LASSERT(list_empty(&desc->bd_set_chain));
134 if (atomic_read(&desc->bd_refcount) != 0)
135 CERROR("freeing desc %p with refcount %d!\n", desc,
136 atomic_read(&desc->bd_refcount));
138 list_for_each_safe(tmp, next, &desc->bd_page_list) {
139 struct ptlrpc_bulk_page *bulk;
140 bulk = list_entry(tmp, struct ptlrpc_bulk_page, bp_link);
141 ptlrpc_free_bulk_page(bulk);
144 ptlrpc_put_connection(desc->bd_connection);
146 OBD_FREE(desc, sizeof(*desc));
150 void ptlrpc_free_bulk_page(struct ptlrpc_bulk_page *bulk)
158 list_del(&bulk->bp_link);
159 bulk->bp_desc->bd_page_count--;
160 OBD_FREE(bulk, sizeof(*bulk));
164 static int ll_sync_brw_timeout(void *data)
166 struct obd_brw_set *set = data;
167 struct list_head *tmp;
173 set->brw_flags |= PTL_RPC_FL_TIMEOUT;
175 list_for_each(tmp, &set->brw_desc_head) {
176 struct ptlrpc_bulk_desc *desc =
177 list_entry(tmp, struct ptlrpc_bulk_desc, bd_set_chain);
179 /* Skip descriptors that were completed successfully. */
180 if (desc->bd_flags & (PTL_BULK_FL_RCVD | PTL_BULK_FL_SENT))
183 LASSERT(desc->bd_connection);
185 /* If PtlMDUnlink succeeds, then it hasn't completed yet. If it
186 * fails, the bulk finished _just_ in time (after the timeout
187 * fired but before we got this far) and we'll let it live.
189 if (PtlMDUnlink(desc->bd_md_h) != 0) {
190 CERROR("Near-miss on OST %s -- need to adjust "
192 desc->bd_connection->c_remote_uuid);
196 CERROR("IO of %d pages to/from %s:%d (conn %p) timed out\n",
197 desc->bd_page_count, desc->bd_connection->c_remote_uuid,
198 desc->bd_portal, desc->bd_connection);
200 /* This one will "never" arrive, don't wait for it. */
201 if (atomic_dec_and_test(&set->brw_refcount))
202 wake_up(&set->brw_waitq);
204 if (class_signal_connection_failure)
205 class_signal_connection_failure(desc->bd_connection);
210 /* 0 = We go back to sleep, until we're resumed or interrupted */
211 /* 1 = We can't be recovered, just abort the syscall with -ETIMEDOUT */
215 static int ll_sync_brw_intr(void *data)
217 struct obd_brw_set *set = data;
220 set->brw_flags |= PTL_RPC_FL_INTR;
221 RETURN(1); /* ignored, as of this writing */
224 int ll_brw_sync_wait(struct obd_brw_set *set, int phase)
226 struct l_wait_info lwi;
227 struct list_head *tmp, *next;
233 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ll_sync_brw_timeout,
234 ll_sync_brw_intr, set);
235 rc = l_wait_event(set->brw_waitq,
236 atomic_read(&set->brw_refcount) == 0, &lwi);
238 list_for_each_safe(tmp, next, &set->brw_desc_head) {
239 struct ptlrpc_bulk_desc *desc =
240 list_entry(tmp, struct ptlrpc_bulk_desc,
242 list_del_init(&desc->bd_set_chain);
243 ptlrpc_bulk_decref(desc);
246 case CB_PHASE_FINISH:
247 if (atomic_dec_and_test(&set->brw_refcount))
248 wake_up(&set->brw_waitq);
257 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, int opcode,
258 int count, int *lengths, char **bufs)
260 struct ptlrpc_connection *conn;
261 struct ptlrpc_request *request;
266 LASSERT((unsigned long)imp > 0x1000);
267 conn = imp->imp_connection;
269 OBD_ALLOC(request, sizeof(*request));
271 CERROR("request allocation out of memory\n");
275 rc = lustre_pack_msg(count, lengths, bufs,
276 &request->rq_reqlen, &request->rq_reqmsg);
278 CERROR("cannot pack request %d\n", rc);
279 OBD_FREE(request, sizeof(*request));
283 request->rq_level = LUSTRE_CONN_FULL;
284 request->rq_type = PTL_RPC_MSG_REQUEST;
285 request->rq_import = imp;
287 /* XXX FIXME bug 625069 */
288 request->rq_request_portal = imp->imp_client->cli_request_portal;
289 request->rq_reply_portal = imp->imp_client->cli_reply_portal;
291 request->rq_connection = ptlrpc_connection_addref(conn);
293 INIT_LIST_HEAD(&request->rq_list);
294 atomic_set(&request->rq_refcount, 1);
296 spin_lock_irqsave(&imp->imp_lock, flags);
297 request->rq_xid = HTON__u32(++imp->imp_last_xid);
298 spin_unlock_irqrestore(&imp->imp_lock, flags);
300 request->rq_reqmsg->magic = PTLRPC_MSG_MAGIC;
301 request->rq_reqmsg->version = PTLRPC_MSG_VERSION;
302 request->rq_reqmsg->opc = HTON__u32(opcode);
303 request->rq_reqmsg->flags = 0;
305 ptlrpc_hdl2req(request, &imp->imp_handle);
309 static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked)
312 if (request == NULL) {
317 if (atomic_read(&request->rq_refcount) != 0) {
318 CERROR("freeing request %p (%d->%s:%d) with refcount %d\n",
319 request, request->rq_reqmsg->opc,
320 request->rq_connection->c_remote_uuid,
321 request->rq_import->imp_client->cli_request_portal,
322 atomic_read (&request->rq_refcount));
326 if (request->rq_repmsg != NULL) {
327 OBD_FREE(request->rq_repmsg, request->rq_replen);
328 request->rq_repmsg = NULL;
329 request->rq_reply_md.start = NULL;
331 if (request->rq_reqmsg != NULL) {
332 OBD_FREE(request->rq_reqmsg, request->rq_reqlen);
333 request->rq_reqmsg = NULL;
336 if (request->rq_import) {
337 unsigned long flags = 0;
339 spin_lock_irqsave(&request->rq_import->imp_lock, flags);
340 list_del_init(&request->rq_list);
342 spin_unlock_irqrestore(&request->rq_import->imp_lock,
346 ptlrpc_put_connection(request->rq_connection);
347 OBD_FREE(request, sizeof(*request));
351 void ptlrpc_free_req(struct ptlrpc_request *request)
353 __ptlrpc_free_req(request, 0);
356 static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked)
362 if (request == (void *)(long)(0x5a5a5a5a5a5a5a5a)) {
363 CERROR("dereferencing freed request (bug 575)\n");
368 DEBUG_REQ(D_INFO, request, "refcount now %u",
369 atomic_read(&request->rq_refcount) - 1);
371 if (atomic_dec_and_test(&request->rq_refcount)) {
372 __ptlrpc_free_req(request, locked);
379 void ptlrpc_req_finished(struct ptlrpc_request *request)
381 __ptlrpc_req_finished(request, 0);
384 static int ptlrpc_check_reply(struct ptlrpc_request *req)
389 if (req->rq_repmsg != NULL) {
390 req->rq_transno = NTOH__u64(req->rq_repmsg->transno);
391 /* Store transno in reqmsg for replay. */
392 req->rq_reqmsg->transno = req->rq_repmsg->transno;
393 req->rq_flags |= PTL_RPC_FL_REPLIED;
397 if (req->rq_flags & PTL_RPC_FL_RESEND) {
399 DEBUG_REQ(D_ERROR, req, "RESEND:");
403 if (req->rq_flags & PTL_RPC_FL_ERR) {
405 DEBUG_REQ(D_ERROR, req, "ABORTED:");
409 if (req->rq_flags & PTL_RPC_FL_RESTART) {
410 DEBUG_REQ(D_ERROR, req, "RESTART:");
415 DEBUG_REQ(D_NET, req, "rc = %d for", rc);
419 static int ptlrpc_check_status(struct ptlrpc_request *req)
424 err = req->rq_repmsg->status;
425 if (req->rq_repmsg->type == NTOH__u32(PTL_RPC_MSG_ERR)) {
426 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR (%d)", err);
427 RETURN(err ? err : -EINVAL);
431 DEBUG_REQ(D_ERROR, req, "status is %d", err);
432 } else if (err > 0) {
433 /* XXX: translate this error from net to host */
434 DEBUG_REQ(D_INFO, req, "status is %d", err);
440 static void ptlrpc_cleanup_request_buf(struct ptlrpc_request *request)
442 OBD_FREE(request->rq_reqmsg, request->rq_reqlen);
443 request->rq_reqmsg = NULL;
444 request->rq_reqlen = 0;
447 /* Abort this request and cleanup any resources associated with it. */
448 static int ptlrpc_abort(struct ptlrpc_request *request)
450 /* First remove the ME for the reply; in theory, this means
451 * that we can tear down the buffer safely. */
452 if (PtlMEUnlink(request->rq_reply_me_h) != PTL_OK)
454 OBD_FREE(request->rq_reply_md.start, request->rq_replen);
456 memset(&request->rq_reply_me_h, 0, sizeof(request->rq_reply_me_h));
457 request->rq_reply_md.start = NULL;
458 request->rq_repmsg = NULL;
462 /* caller must hold imp->imp_lock */
463 void ptlrpc_free_committed(struct obd_import *imp)
465 struct list_head *tmp, *saved;
466 struct ptlrpc_request *req;
470 LASSERT(spin_is_locked(&imp->imp_lock));
473 CDEBUG(D_HA, "committing for xid "LPU64", last_committed "LPU64"\n",
474 imp->imp_peer_last_xid, imp->imp_peer_committed_transno);
476 list_for_each_safe(tmp, saved, &imp->imp_replay_list) {
477 req = list_entry(tmp, struct ptlrpc_request, rq_list);
479 if (req->rq_flags & PTL_RPC_FL_REPLAY) {
480 DEBUG_REQ(D_HA, req, "keeping (FL_REPLAY)");
484 /* not yet committed */
485 if (req->rq_transno > imp->imp_peer_committed_transno) {
486 DEBUG_REQ(D_HA, req, "stopping search");
490 DEBUG_REQ(D_HA, req, "committing (last_committed "LPU64")",
491 imp->imp_peer_committed_transno);
492 __ptlrpc_req_finished(req, 1);
499 void ptlrpc_cleanup_client(struct obd_import *imp)
501 struct list_head *tmp, *saved;
502 struct ptlrpc_request *req;
503 struct ptlrpc_connection *conn = imp->imp_connection;
509 spin_lock_irqsave(&imp->imp_lock, flags);
510 list_for_each_safe(tmp, saved, &imp->imp_replay_list) {
511 req = list_entry(tmp, struct ptlrpc_request, rq_list);
513 /* XXX we should make sure that nobody's sleeping on these! */
514 DEBUG_REQ(D_HA, req, "cleaning up from sending list");
515 list_del_init(&req->rq_list);
516 req->rq_import = NULL;
517 __ptlrpc_req_finished(req, 0);
519 spin_unlock_irqrestore(&imp->imp_lock, flags);
525 void ptlrpc_continue_req(struct ptlrpc_request *req)
528 DEBUG_REQ(D_HA, req, "continuing delayed request");
529 req->rq_reqmsg->addr = req->rq_import->imp_handle.addr;
530 req->rq_reqmsg->cookie = req->rq_import->imp_handle.cookie;
531 wake_up(&req->rq_wait_for_rep);
535 void ptlrpc_resend_req(struct ptlrpc_request *req)
538 DEBUG_REQ(D_HA, req, "resending");
539 req->rq_reqmsg->addr = req->rq_import->imp_handle.addr;
540 req->rq_reqmsg->cookie = req->rq_import->imp_handle.cookie;
541 req->rq_status = -EAGAIN;
542 req->rq_level = LUSTRE_CONN_RECOVD;
543 req->rq_flags |= PTL_RPC_FL_RESEND;
544 req->rq_flags &= ~PTL_RPC_FL_TIMEOUT;
545 wake_up(&req->rq_wait_for_rep);
549 void ptlrpc_restart_req(struct ptlrpc_request *req)
552 DEBUG_REQ(D_HA, req, "restarting (possibly-)completed request");
553 req->rq_status = -ERESTARTSYS;
554 req->rq_flags |= PTL_RPC_FL_RESTART;
555 req->rq_flags &= ~PTL_RPC_FL_TIMEOUT;
556 wake_up(&req->rq_wait_for_rep);
560 static int expired_request(void *data)
562 struct ptlrpc_request *req = data;
571 DEBUG_REQ(D_ERROR, req, "timeout");
573 req->rq_flags |= PTL_RPC_FL_TIMEOUT;
575 if (!req->rq_import) {
576 DEBUG_REQ(D_ERROR, req, "NULL import");
581 if (!req->rq_import->imp_connection) {
582 DEBUG_REQ(D_ERROR, req, "NULL connection");
587 if (!req->rq_import->imp_connection->c_recovd_data.rd_recovd)
590 recovd_conn_fail(req->rq_import->imp_connection);
592 /* If this request is for recovery or other primordial tasks,
593 * don't go back to sleep.
595 if (req->rq_level < LUSTRE_CONN_FULL)
600 static int interrupted_request(void *data)
602 struct ptlrpc_request *req = data;
604 req->rq_flags |= PTL_RPC_FL_INTR;
605 RETURN(1); /* ignored, as of this writing */
608 int ptlrpc_queue_wait(struct ptlrpc_request *req)
611 struct l_wait_info lwi;
612 struct obd_import *imp = req->rq_import;
613 struct ptlrpc_connection *conn = imp->imp_connection;
617 init_waitqueue_head(&req->rq_wait_for_rep);
619 /* for distributed debugging */
620 req->rq_reqmsg->status = HTON__u32(current->pid);
621 CDEBUG(D_RPCTRACE, "Sending RPC pid:xid:nid:opc %d:"LPU64":%x:%d\n",
622 NTOH__u32(req->rq_reqmsg->status), req->rq_xid,
623 conn->c_peer.peer_nid, NTOH__u32(req->rq_reqmsg->opc));
625 spin_lock_irqsave(&imp->imp_lock, flags);
628 * If the import has been invalidated (such as by an OST failure), the
629 * request must fail with -EIO.
631 if (req->rq_import->imp_flags & IMP_INVALID) {
632 DEBUG_REQ(D_ERROR, req, "IMP_INVALID:");
633 spin_unlock_irqrestore(&imp->imp_lock, flags);
637 if (req->rq_level > imp->imp_level) {
638 list_del(&req->rq_list);
639 list_add_tail(&req->rq_list, &imp->imp_delayed_list);
640 spin_unlock_irqrestore(&imp->imp_lock, flags);
642 DEBUG_REQ(D_HA, req, "\"%s\" waiting for recovery: (%d < %d)",
643 current->comm, req->rq_level, imp->imp_level);
644 lwi = LWI_INTR(NULL, NULL);
645 rc = l_wait_event(req->rq_wait_for_rep,
646 (req->rq_level <= imp->imp_level) ||
647 (req->rq_flags & PTL_RPC_FL_ERR), &lwi);
649 spin_lock_irqsave(&imp->imp_lock, flags);
650 list_del_init(&req->rq_list);
652 if (req->rq_flags & PTL_RPC_FL_ERR)
656 spin_unlock_irqrestore(&imp->imp_lock, flags);
660 CERROR("process %d resumed\n", current->pid);
664 LASSERT(list_empty(&req->rq_list));
665 list_add_tail(&req->rq_list, &imp->imp_sending_list);
666 spin_unlock_irqrestore(&imp->imp_lock, flags);
667 rc = ptl_send_rpc(req);
669 CDEBUG(D_HA, "error %d, opcode %d, need recovery\n", rc,
670 req->rq_reqmsg->opc);
671 /* sleep for a jiffy, then trigger recovery */
672 lwi = LWI_TIMEOUT_INTR(1, expired_request,
673 interrupted_request, req);
675 DEBUG_REQ(D_NET, req, "-- sleeping");
676 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, expired_request,
677 interrupted_request, req);
679 l_wait_event(req->rq_wait_for_rep, ptlrpc_check_reply(req), &lwi);
680 DEBUG_REQ(D_NET, req, "-- done sleeping");
682 spin_lock_irqsave(&imp->imp_lock, flags);
683 list_del_init(&req->rq_list);
684 spin_unlock_irqrestore(&imp->imp_lock, flags);
686 if (req->rq_flags & PTL_RPC_FL_ERR) {
688 GOTO(out, rc = -EIO);
691 /* Don't resend if we were interrupted. */
692 if ((req->rq_flags & (PTL_RPC_FL_RESEND | PTL_RPC_FL_INTR)) ==
694 req->rq_flags &= ~PTL_RPC_FL_RESEND;
695 lustre_msg_add_flags(req->rq_reqmsg, MSG_RESENT);
696 DEBUG_REQ(D_HA, req, "resending: ");
697 spin_lock_irqsave(&imp->imp_lock, flags);
701 if (req->rq_flags & PTL_RPC_FL_INTR) {
702 if (!(req->rq_flags & PTL_RPC_FL_TIMEOUT))
703 LBUG(); /* should only be interrupted if we timed out */
704 /* Clean up the dangling reply buffers */
706 GOTO(out, rc = -EINTR);
709 if (req->rq_flags & PTL_RPC_FL_TIMEOUT)
710 GOTO(out, rc = -ETIMEDOUT);
712 if (!(req->rq_flags & PTL_RPC_FL_REPLIED))
713 GOTO(out, rc = req->rq_status);
715 rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
717 CERROR("unpack_rep failed: %d\n", rc);
721 /* FIXME: Enable when BlueArc makes new release */
722 if (req->rq_repmsg->type != PTL_RPC_MSG_REPLY &&
723 req->rq_repmsg->type != PTL_RPC_MSG_ERR) {
724 CERROR("invalid packet type received (type=%u)\n",
725 req->rq_repmsg->type);
727 GOTO(out, rc = -EINVAL);
730 DEBUG_REQ(D_NET, req, "status %d", req->rq_repmsg->status);
732 /* We're a rejected connection, need to invalidate and rebuild. */
733 if (req->rq_repmsg->status == -ENOTCONN) {
734 spin_lock_irqsave(&imp->imp_lock, flags);
735 /* If someone else is reconnecting us (CONN_RECOVD) or has
736 * already completed it (handle mismatch), then we just need
739 if (imp->imp_level == LUSTRE_CONN_RECOVD ||
740 imp->imp_handle.addr != req->rq_reqmsg->addr ||
741 imp->imp_handle.cookie != req->rq_reqmsg->cookie) {
742 spin_unlock_irqrestore(&imp->imp_lock, flags);
743 GOTO(out, rc = -EIO);
745 imp->imp_level = LUSTRE_CONN_RECOVD;
746 spin_unlock_irqrestore(&imp->imp_lock, flags);
747 rc = imp->imp_recover(imp, PTLRPC_RECOVD_PHASE_NOTCONN);
750 GOTO(out, rc = -EIO);
753 rc = ptlrpc_check_status(req);
755 if (req->rq_import->imp_flags & IMP_REPLAYABLE) {
756 spin_lock_irqsave(&imp->imp_lock, flags);
757 if ((req->rq_flags & PTL_RPC_FL_REPLAY || req->rq_transno != 0)
759 /* Balanced in ptlrpc_free_committed, usually. */
760 atomic_inc(&req->rq_refcount);
761 list_add_tail(&req->rq_list, &imp->imp_replay_list);
764 if (req->rq_transno > imp->imp_max_transno) {
765 imp->imp_max_transno = req->rq_transno;
766 } else if (req->rq_transno != 0 &&
767 imp->imp_level == LUSTRE_CONN_FULL) {
768 CDEBUG(D_HA, "got transno "LPD64" after "LPD64
769 ": recovery may not work\n", req->rq_transno,
770 imp->imp_max_transno);
773 /* Replay-enabled imports return commit-status information. */
774 imp->imp_peer_last_xid = req->rq_repmsg->last_xid;
775 imp->imp_peer_committed_transno =
776 req->rq_repmsg->last_committed;
777 ptlrpc_free_committed(imp);
778 spin_unlock_irqrestore(&imp->imp_lock, flags);
786 int ptlrpc_replay_req(struct ptlrpc_request *req)
788 int rc = 0, old_level, old_status = 0;
789 // struct ptlrpc_client *cli = req->rq_import->imp_client;
790 struct l_wait_info lwi;
793 init_waitqueue_head(&req->rq_wait_for_rep);
794 DEBUG_REQ(D_NET, req, "");
796 req->rq_reqmsg->addr = req->rq_import->imp_handle.addr;
797 req->rq_reqmsg->cookie = req->rq_import->imp_handle.cookie;
799 /* temporarily set request to RECOVD level (reset at out:) */
800 old_level = req->rq_level;
801 if (req->rq_flags & PTL_RPC_FL_REPLIED)
802 old_status = req->rq_repmsg->status;
803 req->rq_level = LUSTRE_CONN_RECOVD;
804 rc = ptl_send_rpc(req);
806 CERROR("error %d, opcode %d\n", rc, req->rq_reqmsg->opc);
807 ptlrpc_cleanup_request_buf(req);
808 // up(&cli->cli_rpc_sem);
812 CDEBUG(D_OTHER, "-- sleeping\n");
813 lwi = LWI_INTR(NULL, NULL); /* XXX needs timeout, nested recovery */
814 l_wait_event(req->rq_wait_for_rep, ptlrpc_check_reply(req), &lwi);
815 CDEBUG(D_OTHER, "-- done\n");
817 // up(&cli->cli_rpc_sem);
819 if (!(req->rq_flags & PTL_RPC_FL_REPLIED)) {
820 CERROR("Unknown reason for wakeup\n");
821 /* XXX Phil - I end up here when I kill obdctl */
823 GOTO(out, rc = -EINTR);
826 rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
828 CERROR("unpack_rep failed: %d\n", rc);
832 CDEBUG(D_NET, "got rep "LPD64"\n", req->rq_xid);
834 /* let the callback do fixups, possibly including in the request */
835 if (req->rq_replay_cb)
836 req->rq_replay_cb(req);
838 if ((req->rq_flags & PTL_RPC_FL_REPLIED) &&
839 req->rq_repmsg->status != old_status) {
840 DEBUG_REQ(D_HA, req, "status %d, old was %d",
841 req->rq_repmsg->status, old_status);
845 req->rq_level = old_level;
849 /* XXX looks a lot like super.c:invalidate_request_list, don't it? */
850 void ptlrpc_abort_inflight(struct obd_import *imp)
853 struct list_head *tmp, *n;
855 /* Make sure that no new requests get processed for this import.
856 * ptlrpc_queue_wait must (and does) hold imp_lock while testing this
857 * flag and then putting requests on sending_list or delayed_list.
859 spin_lock_irqsave(&imp->imp_lock, flags);
860 imp->imp_flags |= IMP_INVALID;
861 spin_unlock_irqrestore(&imp->imp_lock, flags);
863 list_for_each_safe(tmp, n, &imp->imp_sending_list) {
864 struct ptlrpc_request *req =
865 list_entry(tmp, struct ptlrpc_request, rq_list);
867 DEBUG_REQ(D_HA, req, "inflight");
868 req->rq_flags |= PTL_RPC_FL_ERR;
869 wake_up(&req->rq_wait_for_rep);
872 list_for_each_safe(tmp, n, &imp->imp_delayed_list) {
873 struct ptlrpc_request *req =
874 list_entry(tmp, struct ptlrpc_request, rq_list);
876 DEBUG_REQ(D_HA, req, "aborting waiting req");
877 req->rq_flags |= PTL_RPC_FL_ERR;
878 wake_up(&req->rq_wait_for_rep);