1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002, 2003 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
27 #include <liblustre.h>
30 #include <linux/obd_support.h>
31 #include <linux/obd_class.h>
32 #include <linux/lustre_lib.h>
33 #include <linux/lustre_ha.h>
34 #include <linux/lustre_import.h>
35 #include <linux/lustre_sec.h>
37 #include "ptlrpc_internal.h"
39 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
40 struct ptlrpc_client *cl)
42 cl->cli_request_portal = req_portal;
43 cl->cli_reply_portal = rep_portal;
47 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid)
49 struct ptlrpc_connection *c;
50 struct ptlrpc_peer peer;
53 err = ptlrpc_uuid_to_peer(uuid, &peer);
55 CERROR("cannot find peer %s!\n", uuid->uuid);
59 c = ptlrpc_get_connection(&peer, uuid);
61 memcpy(c->c_remote_uuid.uuid,
62 uuid->uuid, sizeof(c->c_remote_uuid.uuid));
65 CDEBUG(D_INFO, "%s -> %p\n", uuid->uuid, c);
70 void ptlrpc_readdress_connection(struct ptlrpc_connection *conn,
71 struct obd_uuid *uuid)
73 struct ptlrpc_peer peer;
76 err = ptlrpc_uuid_to_peer(uuid, &peer);
78 CERROR("cannot find peer %s!\n", uuid->uuid);
82 memcpy(&conn->c_peer, &peer, sizeof (peer));
86 static inline struct ptlrpc_bulk_desc *new_bulk(int npages, int type, int portal)
88 struct ptlrpc_bulk_desc *desc;
90 OBD_ALLOC(desc, offsetof (struct ptlrpc_bulk_desc, bd_iov[npages]));
94 spin_lock_init(&desc->bd_lock);
95 init_waitqueue_head(&desc->bd_waitq);
96 desc->bd_max_iov = npages;
97 desc->bd_iov_count = 0;
98 desc->bd_md_h = PTL_INVALID_HANDLE;
99 desc->bd_portal = portal;
100 desc->bd_type = type;
105 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
106 int npages, int type, int portal)
108 struct obd_import *imp = req->rq_import;
109 struct ptlrpc_bulk_desc *desc;
111 LASSERT(type == BULK_PUT_SINK || type == BULK_GET_SOURCE);
112 desc = new_bulk(npages, type, portal);
116 desc->bd_import_generation = req->rq_import_generation;
117 desc->bd_import = class_import_get(imp);
120 desc->bd_cbid.cbid_fn = client_bulk_callback;
121 desc->bd_cbid.cbid_arg = desc;
123 /* This makes req own desc, and free it when she frees herself */
129 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp (struct ptlrpc_request *req,
130 int npages, int type, int portal)
132 struct obd_export *exp = req->rq_export;
133 struct ptlrpc_bulk_desc *desc;
135 LASSERT(type == BULK_PUT_SOURCE || type == BULK_GET_SINK);
137 desc = new_bulk(npages, type, portal);
141 desc->bd_export = class_export_get(exp);
144 desc->bd_cbid.cbid_fn = server_bulk_callback;
145 desc->bd_cbid.cbid_arg = desc;
147 /* NB we don't assign rq_bulk here; server-side requests are
148 * re-used, and the handler frees the bulk desc explicitly. */
153 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
154 struct page *page, int pageoffset, int len)
156 LASSERT(desc->bd_iov_count < desc->bd_max_iov);
157 LASSERT(page != NULL);
158 LASSERT(pageoffset >= 0);
160 LASSERT(pageoffset + len <= PAGE_SIZE);
164 ptlrpc_add_bulk_page(desc, page, pageoffset, len);
167 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *desc)
171 LASSERT(desc != NULL);
172 LASSERT(desc->bd_iov_count != LI_POISON); /* not freed already */
173 LASSERT(!desc->bd_network_rw); /* network hands off or */
174 LASSERT((desc->bd_export != NULL) ^ (desc->bd_import != NULL));
176 class_export_put(desc->bd_export);
178 class_import_put(desc->bd_import);
180 OBD_FREE(desc, offsetof(struct ptlrpc_bulk_desc,
181 bd_iov[desc->bd_max_iov]));
185 /* FIXME prep_req now should return error code other than NULL. but
186 * this is called everywhere :(
188 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
189 int opcode, int count, int *lengths,
192 struct ptlrpc_request *request;
196 LASSERT((unsigned long)imp > 0x1000);
198 OBD_ALLOC(request, sizeof(*request));
200 CERROR("request allocation out of memory\n");
204 request->rq_import = class_import_get(imp);
206 rc = ptlrpcs_req_get_cred(request);
208 CDEBUG(D_SEC, "failed to get credential\n");
212 /* just a try on refresh, but we proceed even if it failed */
213 rc = ptlrpcs_cred_refresh(request->rq_cred);
214 if (!ptlrpcs_cred_is_uptodate(request->rq_cred)) {
215 CERROR("req %p: failed to refresh cred %p, rc %d, continue\n",
216 request, request->rq_cred, rc);
219 rc = lustre_pack_request(request, count, lengths, bufs);
221 CERROR("cannot pack request %d\n", rc);
224 request->rq_reqmsg->version |= version;
226 if (imp->imp_server_timeout)
227 request->rq_timeout = obd_timeout / 2;
229 request->rq_timeout = obd_timeout;
231 request->rq_send_state = LUSTRE_IMP_FULL;
232 request->rq_type = PTL_RPC_MSG_REQUEST;
234 request->rq_req_cbid.cbid_fn = request_out_callback;
235 request->rq_req_cbid.cbid_arg = request;
237 request->rq_reply_cbid.cbid_fn = reply_in_callback;
238 request->rq_reply_cbid.cbid_arg = request;
240 request->rq_phase = RQ_PHASE_NEW;
242 /* XXX FIXME bug 249 */
243 request->rq_request_portal = imp->imp_client->cli_request_portal;
244 request->rq_reply_portal = imp->imp_client->cli_reply_portal;
246 spin_lock_init(&request->rq_lock);
247 INIT_LIST_HEAD(&request->rq_list);
248 INIT_LIST_HEAD(&request->rq_replay_list);
249 INIT_LIST_HEAD(&request->rq_set_chain);
250 init_waitqueue_head(&request->rq_reply_waitq);
251 request->rq_xid = ptlrpc_next_xid();
252 atomic_set(&request->rq_refcount, 1);
254 request->rq_reqmsg->opc = opcode;
255 request->rq_reqmsg->flags = 0;
258 ptlrpcs_req_drop_cred(request);
260 class_import_put(imp);
261 OBD_FREE(request, sizeof(*request));
265 struct ptlrpc_request_set *ptlrpc_prep_set(void)
267 struct ptlrpc_request_set *set;
269 OBD_ALLOC(set, sizeof *set);
272 INIT_LIST_HEAD(&set->set_requests);
273 init_waitqueue_head(&set->set_waitq);
274 set->set_remaining = 0;
275 spin_lock_init(&set->set_new_req_lock);
276 INIT_LIST_HEAD(&set->set_new_requests);
281 /* Finish with this set; opposite of prep_set. */
282 void ptlrpc_set_destroy(struct ptlrpc_request_set *set)
284 struct list_head *tmp;
285 struct list_head *next;
290 /* Requests on the set should either all be completed, or all be new */
291 expected_phase = (set->set_remaining == 0) ?
292 RQ_PHASE_COMPLETE : RQ_PHASE_NEW;
293 list_for_each (tmp, &set->set_requests) {
294 struct ptlrpc_request *req =
295 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
297 LASSERT(req->rq_phase == expected_phase);
301 LASSERT(set->set_remaining == 0 || set->set_remaining == n);
303 list_for_each_safe(tmp, next, &set->set_requests) {
304 struct ptlrpc_request *req =
305 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
306 list_del_init(&req->rq_set_chain);
308 LASSERT(req->rq_phase == expected_phase);
310 if (req->rq_phase == RQ_PHASE_NEW) {
312 if (req->rq_interpret_reply != NULL) {
313 int (*interpreter)(struct ptlrpc_request *,
315 req->rq_interpret_reply;
317 /* higher level (i.e. LOV) failed;
318 * let the sub reqs clean up */
319 req->rq_status = -EBADR;
320 interpreter(req, &req->rq_async_args,
323 set->set_remaining--;
327 ptlrpc_req_finished (req);
330 LASSERT(set->set_remaining == 0);
332 OBD_FREE(set, sizeof(*set));
336 void ptlrpc_set_add_req(struct ptlrpc_request_set *set,
337 struct ptlrpc_request *req)
339 /* The set takes over the caller's request reference */
340 list_add_tail(&req->rq_set_chain, &set->set_requests);
342 set->set_remaining++;
343 atomic_inc(&req->rq_import->imp_inflight);
346 /* lock so many callers can add things, the context that owns the set
347 * is supposed to notice these and move them into the set proper. */
348 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *set,
349 struct ptlrpc_request *req)
352 spin_lock_irqsave(&set->set_new_req_lock, flags);
353 /* The set takes over the caller's request reference */
354 list_add_tail(&req->rq_set_chain, &set->set_new_requests);
356 spin_unlock_irqrestore(&set->set_new_req_lock, flags);
360 * Based on the current state of the import, determine if the request
361 * can be sent, is an error, or should be delayed.
363 * Returns true if this request should be delayed. If false, and
364 * *status is set, then the request can not be sent and *status is the
365 * error code. If false and status is 0, then request can be sent.
367 * The imp->imp_lock must be held.
369 static int ptlrpc_import_delay_req(struct obd_import *imp,
370 struct ptlrpc_request *req, int *status)
375 LASSERT (status != NULL);
378 if (imp->imp_state == LUSTRE_IMP_NEW) {
379 DEBUG_REQ(D_ERROR, req, "Uninitialized import.");
383 else if (imp->imp_state == LUSTRE_IMP_CLOSED) {
384 DEBUG_REQ(D_ERROR, req, "IMP_CLOSED ");
387 /* allow CONNECT even if import is invalid */
388 else if (req->rq_send_state == LUSTRE_IMP_CONNECTING &&
389 imp->imp_state == LUSTRE_IMP_CONNECTING) {
393 * If the import has been invalidated (such as by an OST failure), the
394 * request must fail with -EIO.
396 else if (imp->imp_invalid) {
397 DEBUG_REQ(D_ERROR, req, "IMP_INVALID");
400 else if (req->rq_import_generation != imp->imp_generation) {
401 DEBUG_REQ(D_ERROR, req, "req wrong generation:");
404 else if (req->rq_send_state != imp->imp_state) {
405 if (imp->imp_obd->obd_no_recov || imp->imp_dlm_fake
407 *status = -EWOULDBLOCK;
415 static int ptlrpc_check_reply(struct ptlrpc_request *req)
421 /* serialise with network callback */
422 spin_lock_irqsave (&req->rq_lock, flags);
424 if (req->rq_replied) {
425 DEBUG_REQ(D_NET, req, "REPLIED:");
429 if (req->rq_net_err && !req->rq_timedout) {
430 spin_unlock_irqrestore (&req->rq_lock, flags);
431 rc = ptlrpc_expire_one_request(req);
432 spin_lock_irqsave (&req->rq_lock, flags);
437 DEBUG_REQ(D_ERROR, req, "ABORTED:");
441 if (req->rq_resend) {
442 DEBUG_REQ(D_ERROR, req, "RESEND:");
446 if (req->rq_restart) {
447 DEBUG_REQ(D_ERROR, req, "RESTART:");
452 spin_unlock_irqrestore (&req->rq_lock, flags);
453 DEBUG_REQ(D_NET, req, "rc = %d for", rc);
457 static int ptlrpc_check_status(struct ptlrpc_request *req)
462 err = req->rq_repmsg->status;
463 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
464 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err == %d",
466 RETURN(err < 0 ? err : -EINVAL);
470 DEBUG_REQ(D_INFO, req, "status is %d", err);
471 } else if (err > 0) {
472 /* XXX: translate this error from net to host */
473 DEBUG_REQ(D_INFO, req, "status is %d", err);
479 static int after_reply(struct ptlrpc_request *req)
482 struct obd_import *imp = req->rq_import;
486 LASSERT(!req->rq_receiving_reply);
488 /* NB Until this point, the whole of the incoming message,
489 * including buflens, status etc is in the sender's byte order. */
492 /* Clear reply swab mask; this is a new reply in sender's byte order */
493 req->rq_rep_swab_mask = 0;
495 LASSERT (req->rq_nob_received <= req->rq_repbuf_len);
496 rc = ptlrpcs_cli_unwrap_reply(req);
498 CERROR("verify reply error: %d\n", rc);
501 /* unwrap_reply may request rpc be resend */
502 if (req->rq_ptlrpcs_restart) {
507 /* unwrap_reply will set rq_replen as the actual received
510 rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
512 CERROR("unpack_rep failed: %d\n", rc);
516 if (req->rq_repmsg->type != PTL_RPC_MSG_REPLY &&
517 req->rq_repmsg->type != PTL_RPC_MSG_ERR) {
518 CERROR("invalid packet type received (type=%u)\n",
519 req->rq_repmsg->type);
523 rc = ptlrpc_check_status(req);
525 /* Either we've been evicted, or the server has failed for
526 * some reason. Try to reconnect, and if that fails, punt to the
528 if (rc == -ENOTCONN) {
529 if (req->rq_send_state != LUSTRE_IMP_FULL ||
530 imp->imp_obd->obd_no_recov || imp->imp_dlm_fake) {
534 ptlrpc_request_handle_notconn(req);
539 /* Store transno in reqmsg for replay. */
540 req->rq_reqmsg->transno = req->rq_transno = req->rq_repmsg->transno;
543 if (req->rq_import->imp_replayable) {
544 spin_lock_irqsave(&imp->imp_lock, flags);
545 if (req->rq_transno != 0)
546 ptlrpc_retain_replayable_request(req, imp);
547 else if (req->rq_commit_cb != NULL) {
548 spin_unlock_irqrestore(&imp->imp_lock, flags);
549 req->rq_commit_cb(req);
550 spin_lock_irqsave(&imp->imp_lock, flags);
553 if (req->rq_transno > imp->imp_max_transno)
554 imp->imp_max_transno = req->rq_transno;
556 /* Replay-enabled imports return commit-status information. */
557 if (req->rq_repmsg->last_committed)
558 imp->imp_peer_committed_transno =
559 req->rq_repmsg->last_committed;
560 ptlrpc_free_committed(imp);
561 spin_unlock_irqrestore(&imp->imp_lock, flags);
567 static int ptlrpc_send_new_req(struct ptlrpc_request *req)
569 char str[PTL_NALFMT_SIZE];
570 struct obd_import *imp;
575 LASSERT(req->rq_phase == RQ_PHASE_NEW);
576 req->rq_phase = RQ_PHASE_RPC;
578 imp = req->rq_import;
579 spin_lock_irqsave(&imp->imp_lock, flags);
581 req->rq_import_generation = imp->imp_generation;
583 if (ptlrpc_import_delay_req(imp, req, &rc)) {
584 spin_lock (&req->rq_lock);
586 spin_unlock (&req->rq_lock);
588 DEBUG_REQ(D_HA, req, "req from PID %d waiting for recovery: "
590 req->rq_reqmsg->status,
591 ptlrpc_import_state_name(req->rq_send_state),
592 ptlrpc_import_state_name(imp->imp_state));
593 LASSERT(list_empty (&req->rq_list));
595 list_add_tail(&req->rq_list, &imp->imp_delayed_list);
596 spin_unlock_irqrestore(&imp->imp_lock, flags);
601 spin_unlock_irqrestore(&imp->imp_lock, flags);
603 req->rq_phase = RQ_PHASE_INTERPRET;
607 /* XXX this is the same as ptlrpc_queue_wait */
608 LASSERT(list_empty(&req->rq_list));
609 list_add_tail(&req->rq_list, &imp->imp_sending_list);
610 spin_unlock_irqrestore(&imp->imp_lock, flags);
612 req->rq_reqmsg->status = current->pid;
613 CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:ni:nid:opc"
614 " %s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
615 imp->imp_obd->obd_uuid.uuid, req->rq_reqmsg->status,
617 imp->imp_connection->c_peer.peer_ni->pni_name,
618 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
619 req->rq_reqmsg->opc);
621 rc = ptl_send_rpc(req);
623 DEBUG_REQ(D_HA, req, "send failed (%d); expect timeout", rc);
630 int ptlrpc_check_set(struct ptlrpc_request_set *set)
632 char str[PTL_NALFMT_SIZE];
634 struct list_head *tmp;
635 int force_timer_recalc = 0;
638 if (set->set_remaining == 0)
641 list_for_each(tmp, &set->set_requests) {
642 struct ptlrpc_request *req =
643 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
644 struct obd_import *imp = req->rq_import;
647 if (req->rq_phase == RQ_PHASE_NEW &&
648 ptlrpc_send_new_req(req)) {
649 force_timer_recalc = 1;
652 if (!(req->rq_phase == RQ_PHASE_RPC ||
653 req->rq_phase == RQ_PHASE_BULK ||
654 req->rq_phase == RQ_PHASE_INTERPRET ||
655 req->rq_phase == RQ_PHASE_COMPLETE)) {
656 DEBUG_REQ(D_ERROR, req, "bad phase %x", req->rq_phase);
660 if (req->rq_phase == RQ_PHASE_COMPLETE)
663 if (req->rq_phase == RQ_PHASE_INTERPRET)
664 GOTO(interpret, req->rq_status);
666 if (req->rq_net_err && !req->rq_timedout)
667 ptlrpc_expire_one_request(req);
670 ptlrpc_unregister_reply(req);
671 if (req->rq_status == 0)
672 req->rq_status = -EIO;
673 req->rq_phase = RQ_PHASE_INTERPRET;
675 spin_lock_irqsave(&imp->imp_lock, flags);
676 list_del_init(&req->rq_list);
677 spin_unlock_irqrestore(&imp->imp_lock, flags);
679 GOTO(interpret, req->rq_status);
682 /* ptlrpc_queue_wait->l_wait_event guarantees that rq_intr
683 * will only be set after rq_timedout, but the oig waiting
684 * path sets rq_intr irrespective of whether ptlrpcd has
685 * seen a timeout. our policy is to only interpret
686 * interrupted rpcs after they have timed out */
687 if (req->rq_intr && (req->rq_timedout || req->rq_waiting)) {
688 /* NB could be on delayed list */
689 ptlrpc_unregister_reply(req);
690 req->rq_status = -EINTR;
691 req->rq_phase = RQ_PHASE_INTERPRET;
693 spin_lock_irqsave(&imp->imp_lock, flags);
694 list_del_init(&req->rq_list);
695 spin_unlock_irqrestore(&imp->imp_lock, flags);
697 GOTO(interpret, req->rq_status);
700 if (req->rq_phase == RQ_PHASE_RPC) {
701 if (req->rq_timedout||req->rq_waiting||req->rq_resend) {
704 ptlrpc_unregister_reply(req);
706 spin_lock_irqsave(&imp->imp_lock, flags);
708 if (ptlrpc_import_delay_req(imp, req, &status)){
709 spin_unlock_irqrestore(&imp->imp_lock,
714 list_del_init(&req->rq_list);
716 req->rq_status = status;
717 req->rq_phase = RQ_PHASE_INTERPRET;
718 spin_unlock_irqrestore(&imp->imp_lock,
720 GOTO(interpret, req->rq_status);
722 if (req->rq_no_resend) {
723 req->rq_status = -ENOTCONN;
724 req->rq_phase = RQ_PHASE_INTERPRET;
725 spin_unlock_irqrestore(&imp->imp_lock,
727 GOTO(interpret, req->rq_status);
729 list_add_tail(&req->rq_list,
730 &imp->imp_sending_list);
732 spin_unlock_irqrestore(&imp->imp_lock, flags);
735 if (req->rq_resend) {
736 if (!req->rq_ptlrpcs_restart)
737 lustre_msg_add_flags(
741 __u64 old_xid = req->rq_xid;
743 ptlrpc_unregister_bulk (req);
745 /* ensure previous bulk fails */
746 req->rq_xid = ptlrpc_next_xid();
747 CDEBUG(D_HA, "resend bulk "
750 old_xid, req->rq_xid);
754 rc = ptl_send_rpc(req);
756 DEBUG_REQ(D_HA, req, "send failed (%d)",
758 force_timer_recalc = 1;
761 /* need to reset the timeout */
762 force_timer_recalc = 1;
765 /* Still waiting for a reply? */
766 if (ptlrpc_client_receiving_reply(req))
769 /* Did we actually receive a reply? */
770 if (!ptlrpc_client_replied(req))
773 spin_lock_irqsave(&imp->imp_lock, flags);
774 list_del_init(&req->rq_list);
775 spin_unlock_irqrestore(&imp->imp_lock, flags);
777 req->rq_status = after_reply(req);
778 if (req->rq_resend) {
779 /* Add this req to the delayed list so
780 it can be errored if the import is
781 evicted after recovery. */
782 spin_lock_irqsave (&req->rq_lock, flags);
783 list_add_tail(&req->rq_list,
784 &imp->imp_delayed_list);
785 spin_unlock_irqrestore(&req->rq_lock, flags);
789 /* If there is no bulk associated with this request,
790 * then we're done and should let the interpreter
791 * process the reply. Similarly if the RPC returned
792 * an error, and therefore the bulk will never arrive.
794 if (req->rq_bulk == NULL || req->rq_status != 0) {
795 req->rq_phase = RQ_PHASE_INTERPRET;
796 GOTO(interpret, req->rq_status);
799 req->rq_phase = RQ_PHASE_BULK;
802 LASSERT(req->rq_phase == RQ_PHASE_BULK);
803 if (ptlrpc_bulk_active(req->rq_bulk))
806 if (!req->rq_bulk->bd_success) {
807 /* The RPC reply arrived OK, but the bulk screwed
808 * up! Dead wierd since the server told us the RPC
809 * was good after getting the REPLY for her GET or
810 * the ACK for her PUT. */
811 DEBUG_REQ(D_ERROR, req, "bulk transfer failed");
815 req->rq_phase = RQ_PHASE_INTERPRET;
818 LASSERT(req->rq_phase == RQ_PHASE_INTERPRET);
819 LASSERT(!req->rq_receiving_reply);
821 ptlrpc_unregister_reply(req);
822 if (req->rq_bulk != NULL)
823 ptlrpc_unregister_bulk (req);
825 req->rq_phase = RQ_PHASE_COMPLETE;
827 if (req->rq_interpret_reply != NULL) {
828 int (*interpreter)(struct ptlrpc_request *,void *,int) =
829 req->rq_interpret_reply;
830 req->rq_status = interpreter(req, &req->rq_async_args,
834 CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:ni:nid:"
835 "opc %s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
836 imp->imp_obd->obd_uuid.uuid, req->rq_reqmsg->status,
838 imp->imp_connection->c_peer.peer_ni->pni_name,
839 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
840 req->rq_reqmsg->opc);
842 set->set_remaining--;
844 atomic_dec(&imp->imp_inflight);
845 wake_up(&imp->imp_recovery_waitq);
848 /* If we hit an error, we want to recover promptly. */
849 RETURN(set->set_remaining == 0 || force_timer_recalc);
852 int ptlrpc_expire_one_request(struct ptlrpc_request *req)
855 struct obd_import *imp = req->rq_import;
859 DEBUG_REQ(D_ERROR, req, "timeout (sent at %lu, %lus ago)",
860 (long)req->rq_sent, LTIME_S(CURRENT_TIME) - req->rq_sent);
862 spin_lock_irqsave (&req->rq_lock, flags);
863 replied = req->rq_replied;
865 req->rq_timedout = 1;
866 spin_unlock_irqrestore (&req->rq_lock, flags);
871 DEBUG_REQ(D_ERROR, req, "timeout (sent at %lu)", (long)req->rq_sent);
873 ptlrpc_unregister_reply (req);
875 if (obd_dump_on_timeout)
876 portals_debug_dumplog();
878 if (req->rq_bulk != NULL)
879 ptlrpc_unregister_bulk (req);
882 DEBUG_REQ(D_HA, req, "NULL import: already cleaned up?");
886 /* The DLM server doesn't want recovery run on its imports. */
887 if (imp->imp_dlm_fake)
890 /* If this request is for recovery or other primordial tasks,
891 * then error it out here. */
892 if (req->rq_send_state != LUSTRE_IMP_FULL ||
893 imp->imp_obd->obd_no_recov) {
894 spin_lock_irqsave (&req->rq_lock, flags);
895 req->rq_status = -ETIMEDOUT;
897 spin_unlock_irqrestore (&req->rq_lock, flags);
901 ptlrpc_fail_import(imp, req->rq_import_generation);
906 int ptlrpc_expired_set(void *data)
908 struct ptlrpc_request_set *set = data;
909 struct list_head *tmp;
910 time_t now = LTIME_S(CURRENT_TIME);
913 LASSERT(set != NULL);
915 /* A timeout expired; see which reqs it applies to... */
916 list_for_each (tmp, &set->set_requests) {
917 struct ptlrpc_request *req =
918 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
920 /* request in-flight? */
921 if (!((req->rq_phase == RQ_PHASE_RPC && !req->rq_waiting
922 && !req->rq_resend) ||
923 (req->rq_phase == RQ_PHASE_BULK)))
926 if (req->rq_timedout || /* already dealt with */
927 req->rq_sent + req->rq_timeout > now) /* not expired */
930 /* deal with this guy */
931 ptlrpc_expire_one_request (req);
934 /* When waiting for a whole set, we always to break out of the
935 * sleep so we can recalculate the timeout, or enable interrupts
936 * iff everyone's timed out.
941 void ptlrpc_mark_interrupted(struct ptlrpc_request *req)
944 spin_lock_irqsave(&req->rq_lock, flags);
946 spin_unlock_irqrestore(&req->rq_lock, flags);
949 void ptlrpc_interrupted_set(void *data)
951 struct ptlrpc_request_set *set = data;
952 struct list_head *tmp;
954 LASSERT(set != NULL);
955 CERROR("INTERRUPTED SET %p\n", set);
957 list_for_each(tmp, &set->set_requests) {
958 struct ptlrpc_request *req =
959 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
961 if (req->rq_phase != RQ_PHASE_RPC)
964 ptlrpc_mark_interrupted(req);
968 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set)
970 struct list_head *tmp;
971 time_t now = LTIME_S(CURRENT_TIME);
974 struct ptlrpc_request *req;
977 SIGNAL_MASK_ASSERT(); /* XXX BUG 1511 */
979 list_for_each(tmp, &set->set_requests) {
980 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
982 /* request in-flight? */
983 if (!((req->rq_phase == RQ_PHASE_RPC && !req->rq_waiting) ||
984 (req->rq_phase == RQ_PHASE_BULK)))
987 if (req->rq_timedout) /* already timed out */
990 deadline = req->rq_sent + req->rq_timeout;
991 if (deadline <= now) /* actually expired already */
992 timeout = 1; /* ASAP */
993 else if (timeout == 0 || timeout > deadline - now)
994 timeout = deadline - now;
1000 int ptlrpc_set_wait(struct ptlrpc_request_set *set)
1002 struct list_head *tmp;
1003 struct ptlrpc_request *req;
1004 struct l_wait_info lwi;
1008 LASSERT(!list_empty(&set->set_requests));
1009 list_for_each(tmp, &set->set_requests) {
1010 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
1011 if (req->rq_phase == RQ_PHASE_NEW)
1012 (void)ptlrpc_send_new_req(req);
1016 timeout = ptlrpc_set_next_timeout(set);
1018 /* wait until all complete, interrupted, or an in-flight
1020 CDEBUG(D_HA, "set %p going to sleep for %d seconds\n",
1022 lwi = LWI_TIMEOUT_INTR((timeout ? timeout : 1) * HZ,
1024 ptlrpc_interrupted_set, set);
1025 rc = l_wait_event(set->set_waitq, ptlrpc_check_set(set), &lwi);
1027 LASSERT(rc == 0 || rc == -EINTR || rc == -ETIMEDOUT);
1029 /* -EINTR => all requests have been flagged rq_intr so next
1031 * -ETIMEOUTD => someone timed out. When all reqs have
1032 * timed out, signals are enabled allowing completion with
1034 * I don't really care if we go once more round the loop in
1035 * the error cases -eeb. */
1036 } while (rc != 0 || set->set_remaining != 0);
1038 LASSERT(set->set_remaining == 0);
1041 list_for_each(tmp, &set->set_requests) {
1042 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
1044 LASSERT(req->rq_phase == RQ_PHASE_COMPLETE);
1045 if (req->rq_status != 0)
1046 rc = req->rq_status;
1049 if (set->set_interpret != NULL) {
1050 int (*interpreter)(struct ptlrpc_request_set *set,void *,int) =
1052 rc = interpreter (set, set->set_arg, rc);
1058 static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked)
1061 if (request == NULL) {
1066 LASSERTF(!request->rq_receiving_reply, "req %p\n", request);
1067 LASSERTF(request->rq_rqbd == NULL, "req %p\n",request);/* client-side */
1068 LASSERTF(list_empty(&request->rq_list), "req %p\n", request);
1069 LASSERTF(list_empty(&request->rq_set_chain), "req %p\n", request);
1070 LASSERT(request->rq_cred);
1072 /* We must take it off the imp_replay_list first. Otherwise, we'll set
1073 * request->rq_reqmsg to NULL while osc_close is dereferencing it. */
1074 if (request->rq_import != NULL) {
1075 unsigned long flags = 0;
1077 spin_lock_irqsave(&request->rq_import->imp_lock, flags);
1078 list_del_init(&request->rq_replay_list);
1080 spin_unlock_irqrestore(&request->rq_import->imp_lock,
1083 LASSERTF(list_empty(&request->rq_replay_list), "req %p\n", request);
1085 if (atomic_read(&request->rq_refcount) != 0) {
1086 DEBUG_REQ(D_ERROR, request,
1087 "freeing request with nonzero refcount");
1091 if (request->rq_repbuf != NULL)
1092 ptlrpcs_cli_free_repbuf(request);
1093 if (request->rq_reqbuf != NULL)
1094 ptlrpcs_cli_free_reqbuf(request);
1096 if (request->rq_export != NULL) {
1097 class_export_put(request->rq_export);
1098 request->rq_export = NULL;
1100 if (request->rq_import != NULL) {
1101 class_import_put(request->rq_import);
1102 request->rq_import = NULL;
1104 if (request->rq_bulk != NULL)
1105 ptlrpc_free_bulk(request->rq_bulk);
1107 ptlrpcs_req_drop_cred(request);
1108 OBD_FREE(request, sizeof(*request));
1112 void ptlrpc_free_req(struct ptlrpc_request *request)
1114 __ptlrpc_free_req(request, 0);
1117 static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked);
1118 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request)
1120 LASSERT_SPIN_LOCKED(&request->rq_import->imp_lock);
1121 (void)__ptlrpc_req_finished(request, 1);
1124 static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked)
1127 if (request == NULL)
1130 if (request == LP_POISON ||
1131 request->rq_reqmsg == LP_POISON) {
1132 CERROR("dereferencing freed request (bug 575)\n");
1137 DEBUG_REQ(D_INFO, request, "refcount now %u",
1138 atomic_read(&request->rq_refcount) - 1);
1140 if (atomic_dec_and_test(&request->rq_refcount)) {
1141 __ptlrpc_free_req(request, locked);
1148 void ptlrpc_req_finished(struct ptlrpc_request *request)
1150 __ptlrpc_req_finished(request, 0);
1153 /* Disengage the client's reply buffer from the network
1154 * NB does _NOT_ unregister any client-side bulk.
1155 * IDEMPOTENT, but _not_ safe against concurrent callers.
1156 * The request owner (i.e. the thread doing the I/O) must call...
1158 void ptlrpc_unregister_reply (struct ptlrpc_request *request)
1161 wait_queue_head_t *wq;
1162 struct l_wait_info lwi;
1164 LASSERT(!in_interrupt ()); /* might sleep */
1166 if (!ptlrpc_client_receiving_reply(request))
1169 PtlMDUnlink (request->rq_reply_md_h);
1171 /* We have to l_wait_event() whatever the result, to give liblustre
1172 * a chance to run reply_in_callback() */
1174 if (request->rq_set != NULL)
1175 wq = &request->rq_set->set_waitq;
1177 wq = &request->rq_reply_waitq;
1180 /* Network access will complete in finite time but the HUGE
1181 * timeout lets us CWARN for visibility of sluggish NALs */
1182 lwi = LWI_TIMEOUT(300 * HZ, NULL, NULL);
1183 rc = l_wait_event (*wq, !ptlrpc_client_receiving_reply(request), &lwi);
1187 LASSERT (rc == -ETIMEDOUT);
1188 DEBUG_REQ(D_WARNING, request, "Unexpectedly long timeout");
1192 /* caller must hold imp->imp_lock */
1193 void ptlrpc_free_committed(struct obd_import *imp)
1195 struct list_head *tmp, *saved;
1196 struct ptlrpc_request *req;
1197 struct ptlrpc_request *last_req = NULL; /* temporary fire escape */
1200 LASSERT(imp != NULL);
1202 LASSERT_SPIN_LOCKED(&imp->imp_lock);
1204 CDEBUG(D_HA, "%s: committing for last_committed "LPU64"\n",
1205 imp->imp_obd->obd_name, imp->imp_peer_committed_transno);
1207 list_for_each_safe(tmp, saved, &imp->imp_replay_list) {
1208 req = list_entry(tmp, struct ptlrpc_request, rq_replay_list);
1210 /* XXX ok to remove when 1357 resolved - rread 05/29/03 */
1211 LASSERT(req != last_req);
1214 if (req->rq_import_generation < imp->imp_generation) {
1215 DEBUG_REQ(D_HA, req, "freeing request with old gen");
1219 if (req->rq_replay) {
1220 DEBUG_REQ(D_HA, req, "keeping (FL_REPLAY)");
1224 /* not yet committed */
1225 if (req->rq_transno > imp->imp_peer_committed_transno) {
1226 DEBUG_REQ(D_HA, req, "stopping search");
1230 DEBUG_REQ(D_HA, req, "committing (last_committed "LPU64")",
1231 imp->imp_peer_committed_transno);
1233 if (req->rq_commit_cb != NULL)
1234 req->rq_commit_cb(req);
1235 list_del_init(&req->rq_replay_list);
1236 __ptlrpc_req_finished(req, 1);
1243 void ptlrpc_cleanup_client(struct obd_import *imp)
1250 void ptlrpc_resend_req(struct ptlrpc_request *req)
1252 unsigned long flags;
1254 DEBUG_REQ(D_HA, req, "going to resend");
1255 req->rq_reqmsg->handle.cookie = 0;
1256 req->rq_status = -EAGAIN;
1258 spin_lock_irqsave (&req->rq_lock, flags);
1260 req->rq_net_err = 0;
1261 req->rq_timedout = 0;
1263 __u64 old_xid = req->rq_xid;
1265 /* ensure previous bulk fails */
1266 req->rq_xid = ptlrpc_next_xid();
1267 CDEBUG(D_HA, "resend bulk old x"LPU64" new x"LPU64"\n",
1268 old_xid, req->rq_xid);
1270 ptlrpc_wake_client_req(req);
1271 spin_unlock_irqrestore (&req->rq_lock, flags);
1274 /* XXX: this function and rq_status are currently unused */
1275 void ptlrpc_restart_req(struct ptlrpc_request *req)
1277 unsigned long flags;
1279 DEBUG_REQ(D_HA, req, "restarting (possibly-)completed request");
1280 req->rq_status = -ERESTARTSYS;
1282 spin_lock_irqsave (&req->rq_lock, flags);
1283 req->rq_restart = 1;
1284 req->rq_timedout = 0;
1285 ptlrpc_wake_client_req(req);
1286 spin_unlock_irqrestore (&req->rq_lock, flags);
1289 static int expired_request(void *data)
1291 struct ptlrpc_request *req = data;
1294 RETURN(ptlrpc_expire_one_request(req));
1297 static void interrupted_request(void *data)
1299 unsigned long flags;
1301 struct ptlrpc_request *req = data;
1302 DEBUG_REQ(D_HA, req, "request interrupted");
1303 spin_lock_irqsave (&req->rq_lock, flags);
1305 spin_unlock_irqrestore (&req->rq_lock, flags);
1308 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req)
1311 atomic_inc(&req->rq_refcount);
1315 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
1316 struct obd_import *imp)
1318 struct list_head *tmp;
1320 LASSERT_SPIN_LOCKED(&imp->imp_lock);
1322 /* clear this for new requests that were resent as well
1323 as resent replayed requests. */
1324 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1326 /* don't re-add requests that have been replayed */
1327 if (!list_empty(&req->rq_replay_list))
1330 lustre_msg_add_flags(req->rq_reqmsg, MSG_REPLAY);
1332 LASSERT(imp->imp_replayable);
1333 /* Balanced in ptlrpc_free_committed, usually. */
1334 ptlrpc_request_addref(req);
1335 list_for_each_prev(tmp, &imp->imp_replay_list) {
1336 struct ptlrpc_request *iter =
1337 list_entry(tmp, struct ptlrpc_request, rq_replay_list);
1339 /* We may have duplicate transnos if we create and then
1340 * open a file, or for closes retained if to match creating
1341 * opens, so use req->rq_xid as a secondary key.
1342 * (See bugs 684, 685, and 428.)
1343 * XXX no longer needed, but all opens need transnos!
1345 if (iter->rq_transno > req->rq_transno)
1348 if (iter->rq_transno == req->rq_transno) {
1349 LASSERT(iter->rq_xid != req->rq_xid);
1350 if (iter->rq_xid > req->rq_xid)
1354 list_add(&req->rq_replay_list, &iter->rq_replay_list);
1358 list_add_tail(&req->rq_replay_list, &imp->imp_replay_list);
1361 int ptlrpc_queue_wait(struct ptlrpc_request *req)
1363 char str[PTL_NALFMT_SIZE];
1366 struct l_wait_info lwi;
1367 struct obd_import *imp = req->rq_import;
1368 unsigned long flags;
1372 LASSERT(req->rq_set == NULL);
1373 LASSERT(!req->rq_receiving_reply);
1374 atomic_inc(&imp->imp_inflight);
1376 if (imp->imp_connection == NULL) {
1377 CERROR("request on not connected import %s\n",
1378 imp->imp_obd->obd_name);
1382 /* for distributed debugging */
1383 req->rq_reqmsg->status = current->pid;
1384 LASSERT(imp->imp_obd != NULL);
1385 CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:ni:nid:opc "
1386 "%s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
1387 imp->imp_obd->obd_uuid.uuid,
1388 req->rq_reqmsg->status, req->rq_xid,
1389 imp->imp_connection->c_peer.peer_ni->pni_name,
1390 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
1391 req->rq_reqmsg->opc);
1393 /* Mark phase here for a little debug help */
1394 req->rq_phase = RQ_PHASE_RPC;
1396 spin_lock_irqsave(&imp->imp_lock, flags);
1397 req->rq_import_generation = imp->imp_generation;
1399 if (ptlrpc_import_delay_req(imp, req, &rc)) {
1400 list_del(&req->rq_list);
1402 list_add_tail(&req->rq_list, &imp->imp_delayed_list);
1403 spin_unlock_irqrestore(&imp->imp_lock, flags);
1405 DEBUG_REQ(D_HA, req, "\"%s\" waiting for recovery: (%s != %s)",
1407 ptlrpc_import_state_name(req->rq_send_state),
1408 ptlrpc_import_state_name(imp->imp_state));
1409 lwi = LWI_INTR(interrupted_request, req);
1410 rc = l_wait_event(req->rq_reply_waitq,
1411 (req->rq_send_state == imp->imp_state ||
1414 DEBUG_REQ(D_HA, req, "\"%s\" awake: (%s == %s or %d == 1)",
1416 ptlrpc_import_state_name(imp->imp_state),
1417 ptlrpc_import_state_name(req->rq_send_state),
1420 spin_lock_irqsave(&imp->imp_lock, flags);
1421 list_del_init(&req->rq_list);
1426 else if (req->rq_intr) {
1429 else if (req->rq_no_resend) {
1430 spin_unlock_irqrestore(&imp->imp_lock, flags);
1431 GOTO(out, rc = -ETIMEDOUT);
1439 list_del_init(&req->rq_list);
1440 spin_unlock_irqrestore(&imp->imp_lock, flags);
1441 req->rq_status = rc; // XXX this ok?
1445 if (req->rq_resend) {
1446 if (!req->rq_ptlrpcs_restart)
1447 lustre_msg_add_flags(req->rq_reqmsg, MSG_RESENT);
1449 if (req->rq_bulk != NULL)
1450 ptlrpc_unregister_bulk (req);
1452 DEBUG_REQ(D_HA, req, "resending: ");
1455 /* XXX this is the same as ptlrpc_set_wait */
1456 LASSERT(list_empty(&req->rq_list));
1457 list_add_tail(&req->rq_list, &imp->imp_sending_list);
1458 spin_unlock_irqrestore(&imp->imp_lock, flags);
1460 rc = ptl_send_rpc(req);
1462 DEBUG_REQ(D_HA, req, "send failed (%d); recovering", rc);
1465 timeout = MAX(req->rq_timeout * HZ, 1);
1466 DEBUG_REQ(D_NET, req, "-- sleeping for %d jiffies", timeout);
1468 lwi = LWI_TIMEOUT_INTR(timeout, expired_request, interrupted_request,
1470 l_wait_event(req->rq_reply_waitq, ptlrpc_check_reply(req), &lwi);
1471 DEBUG_REQ(D_NET, req, "-- done sleeping");
1473 CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:ni:nid:opc "
1474 "%s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
1475 imp->imp_obd->obd_uuid.uuid,
1476 req->rq_reqmsg->status, req->rq_xid,
1477 imp->imp_connection->c_peer.peer_ni->pni_name,
1478 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
1479 req->rq_reqmsg->opc);
1481 spin_lock_irqsave(&imp->imp_lock, flags);
1482 list_del_init(&req->rq_list);
1483 spin_unlock_irqrestore(&imp->imp_lock, flags);
1485 /* If the reply was received normally, this just grabs the spinlock
1486 * (ensuring the reply callback has returned), sees that
1487 * req->rq_receiving_reply is clear and returns. */
1488 ptlrpc_unregister_reply (req);
1491 GOTO(out, rc = -EIO);
1493 /* Resend if we need to, unless we were interrupted. */
1494 if (req->rq_resend && !req->rq_intr) {
1495 /* ...unless we were specifically told otherwise. */
1496 if (req->rq_no_resend)
1497 GOTO(out, rc = -ETIMEDOUT);
1498 spin_lock_irqsave(&imp->imp_lock, flags);
1503 /* Should only be interrupted if we timed out. */
1504 if (!req->rq_timedout)
1505 DEBUG_REQ(D_ERROR, req,
1506 "rq_intr set but rq_timedout not");
1507 GOTO(out, rc = -EINTR);
1510 if (req->rq_timedout) { /* non-recoverable timeout */
1511 GOTO(out, rc = -ETIMEDOUT);
1514 if (!req->rq_replied) {
1515 /* How can this be? -eeb */
1516 DEBUG_REQ(D_ERROR, req, "!rq_replied: ");
1518 GOTO(out, rc = req->rq_status);
1521 rc = after_reply (req);
1522 /* NB may return +ve success rc */
1523 if (req->rq_resend) {
1524 spin_lock_irqsave(&imp->imp_lock, flags);
1529 if (req->rq_bulk != NULL) {
1531 /* success so far. Note that anything going wrong
1532 * with bulk now, is EXTREMELY strange, since the
1533 * server must have believed that the bulk
1534 * tranferred OK before she replied with success to
1536 lwi = LWI_TIMEOUT(timeout, NULL, NULL);
1537 brc = l_wait_event(req->rq_reply_waitq,
1538 !ptlrpc_bulk_active(req->rq_bulk),
1540 LASSERT(brc == 0 || brc == -ETIMEDOUT);
1542 LASSERT(brc == -ETIMEDOUT);
1543 DEBUG_REQ(D_ERROR, req, "bulk timed out");
1545 } else if (!req->rq_bulk->bd_success) {
1546 DEBUG_REQ(D_ERROR, req, "bulk transfer failed");
1551 ptlrpc_unregister_bulk (req);
1554 LASSERT(!req->rq_receiving_reply);
1555 req->rq_phase = RQ_PHASE_INTERPRET;
1557 atomic_dec(&imp->imp_inflight);
1558 wake_up(&imp->imp_recovery_waitq);
1562 struct ptlrpc_replay_async_args {
1564 int praa_old_status;
1567 static int ptlrpc_replay_interpret(struct ptlrpc_request *req,
1568 void * data, int rc)
1570 struct ptlrpc_replay_async_args *aa = data;
1571 struct obd_import *imp = req->rq_import;
1572 unsigned long flags;
1574 atomic_dec(&imp->imp_replay_inflight);
1576 if (!req->rq_replied) {
1577 CERROR("request replay timed out, restarting recovery\n");
1578 GOTO(out, rc = -ETIMEDOUT);
1582 /* Clear reply swab mask; this is a new reply in sender's byte order */
1583 req->rq_rep_swab_mask = 0;
1585 LASSERT (req->rq_nob_received <= req->rq_repbuf_len);
1586 rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
1588 CERROR("unpack_rep failed: %d\n", rc);
1589 GOTO(out, rc = -EPROTO);
1592 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR &&
1593 req->rq_repmsg->status == -ENOTCONN)
1594 GOTO(out, rc = req->rq_repmsg->status);
1596 /* The transno had better not change over replay. */
1597 LASSERT(req->rq_reqmsg->transno == req->rq_repmsg->transno);
1599 DEBUG_REQ(D_HA, req, "got rep");
1601 /* let the callback do fixups, possibly including in the request */
1602 if (req->rq_replay_cb)
1603 req->rq_replay_cb(req);
1605 if (req->rq_replied && req->rq_repmsg->status != aa->praa_old_status) {
1606 DEBUG_REQ(D_ERROR, req, "status %d, old was %d",
1607 req->rq_repmsg->status, aa->praa_old_status);
1609 /* Put it back for re-replay. */
1610 req->rq_repmsg->status = aa->praa_old_status;
1613 spin_lock_irqsave(&imp->imp_lock, flags);
1614 imp->imp_last_replay_transno = req->rq_transno;
1615 spin_unlock_irqrestore(&imp->imp_lock, flags);
1617 /* continue with recovery */
1618 rc = ptlrpc_import_recovery_state_machine(imp);
1620 req->rq_send_state = aa->praa_old_state;
1623 /* this replay failed, so restart recovery */
1624 ptlrpc_connect_import(imp, NULL);
1630 int ptlrpc_replay_req(struct ptlrpc_request *req)
1632 struct ptlrpc_replay_async_args *aa;
1635 LASSERT(req->rq_import->imp_state == LUSTRE_IMP_REPLAY);
1637 /* Not handling automatic bulk replay yet (or ever?) */
1638 LASSERT(req->rq_bulk == NULL);
1640 DEBUG_REQ(D_HA, req, "REPLAY");
1642 LASSERT (sizeof (*aa) <= sizeof (req->rq_async_args));
1643 aa = (struct ptlrpc_replay_async_args *)&req->rq_async_args;
1644 memset(aa, 0, sizeof *aa);
1646 /* Prepare request to be resent with ptlrpcd */
1647 aa->praa_old_state = req->rq_send_state;
1648 req->rq_send_state = LUSTRE_IMP_REPLAY;
1649 req->rq_phase = RQ_PHASE_NEW;
1650 aa->praa_old_status = req->rq_repmsg->status;
1653 req->rq_interpret_reply = ptlrpc_replay_interpret;
1654 atomic_inc(&req->rq_import->imp_replay_inflight);
1655 ptlrpc_request_addref(req); /* ptlrpcd needs a ref */
1657 ptlrpcd_add_req(req);
1661 void ptlrpc_abort_inflight(struct obd_import *imp)
1663 unsigned long flags;
1664 struct list_head *tmp, *n;
1667 /* Make sure that no new requests get processed for this import.
1668 * ptlrpc_{queue,set}_wait must (and does) hold imp_lock while testing
1669 * this flag and then putting requests on sending_list or delayed_list.
1671 spin_lock_irqsave(&imp->imp_lock, flags);
1673 /* XXX locking? Maybe we should remove each request with the list
1674 * locked? Also, how do we know if the requests on the list are
1675 * being freed at this time?
1677 list_for_each_safe(tmp, n, &imp->imp_sending_list) {
1678 struct ptlrpc_request *req =
1679 list_entry(tmp, struct ptlrpc_request, rq_list);
1681 DEBUG_REQ(D_HA, req, "inflight");
1683 spin_lock (&req->rq_lock);
1684 if (req->rq_import_generation < imp->imp_generation) {
1686 ptlrpc_wake_client_req(req);
1688 spin_unlock (&req->rq_lock);
1691 list_for_each_safe(tmp, n, &imp->imp_delayed_list) {
1692 struct ptlrpc_request *req =
1693 list_entry(tmp, struct ptlrpc_request, rq_list);
1695 DEBUG_REQ(D_HA, req, "aborting waiting req");
1697 spin_lock (&req->rq_lock);
1698 if (req->rq_import_generation < imp->imp_generation) {
1700 ptlrpc_wake_client_req(req);
1702 spin_unlock (&req->rq_lock);
1705 list_for_each_safe(tmp, n, &imp->imp_rawrpc_list) {
1706 struct ptlrpc_request *req =
1707 list_entry(tmp, struct ptlrpc_request, rq_list);
1709 DEBUG_REQ(D_HA, req, "aborting raw rpc");
1711 spin_lock(&req->rq_lock);
1713 ptlrpc_wake_client_req(req);
1714 spin_unlock(&req->rq_lock);
1717 /* Last chance to free reqs left on the replay list, but we
1718 * will still leak reqs that haven't comitted. */
1719 if (imp->imp_replayable)
1720 ptlrpc_free_committed(imp);
1722 spin_unlock_irqrestore(&imp->imp_lock, flags);
1727 static __u64 ptlrpc_last_xid = 0;
1728 static spinlock_t ptlrpc_last_xid_lock = SPIN_LOCK_UNLOCKED;
1730 __u64 ptlrpc_next_xid(void)
1733 spin_lock(&ptlrpc_last_xid_lock);
1734 tmp = ++ptlrpc_last_xid;
1735 spin_unlock(&ptlrpc_last_xid_lock);