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>
36 #include "ptlrpc_internal.h"
38 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
39 struct ptlrpc_client *cl)
41 cl->cli_request_portal = req_portal;
42 cl->cli_reply_portal = rep_portal;
46 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid)
48 struct ptlrpc_connection *c;
49 struct ptlrpc_peer peer;
52 err = ptlrpc_uuid_to_peer(uuid, &peer);
54 CERROR("cannot find peer %s!\n", uuid->uuid);
58 c = ptlrpc_get_connection(&peer, uuid);
60 memcpy(c->c_remote_uuid.uuid,
61 uuid->uuid, sizeof(c->c_remote_uuid.uuid));
64 CDEBUG(D_INFO, "%s -> %p\n", uuid->uuid, c);
69 void ptlrpc_readdress_connection(struct ptlrpc_connection *conn,
70 struct obd_uuid *uuid)
72 struct ptlrpc_peer peer;
75 err = ptlrpc_uuid_to_peer(uuid, &peer);
77 CERROR("cannot find peer %s!\n", uuid->uuid);
81 memcpy(&conn->c_peer, &peer, sizeof (peer));
85 static inline struct ptlrpc_bulk_desc *new_bulk(int npages, int type, int portal)
87 struct ptlrpc_bulk_desc *desc;
89 OBD_ALLOC(desc, offsetof (struct ptlrpc_bulk_desc, bd_iov[npages]));
93 spin_lock_init(&desc->bd_lock);
94 init_waitqueue_head(&desc->bd_waitq);
95 desc->bd_max_iov = npages;
96 desc->bd_iov_count = 0;
97 desc->bd_md_h = PTL_INVALID_HANDLE;
98 desc->bd_portal = portal;
104 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
105 int npages, int type, int portal)
107 struct obd_import *imp = req->rq_import;
108 struct ptlrpc_bulk_desc *desc;
110 LASSERT(type == BULK_PUT_SINK || type == BULK_GET_SOURCE);
111 desc = new_bulk(npages, type, portal);
115 desc->bd_import_generation = req->rq_import_generation;
116 desc->bd_import = class_import_get(imp);
119 desc->bd_cbid.cbid_fn = client_bulk_callback;
120 desc->bd_cbid.cbid_arg = desc;
122 /* This makes req own desc, and free it when she frees herself */
128 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp (struct ptlrpc_request *req,
129 int npages, int type, int portal)
131 struct obd_export *exp = req->rq_export;
132 struct ptlrpc_bulk_desc *desc;
134 LASSERT(type == BULK_PUT_SOURCE || type == BULK_GET_SINK);
136 desc = new_bulk(npages, type, portal);
140 desc->bd_export = class_export_get(exp);
143 desc->bd_cbid.cbid_fn = server_bulk_callback;
144 desc->bd_cbid.cbid_arg = desc;
146 /* NB we don't assign rq_bulk here; server-side requests are
147 * re-used, and the handler frees the bulk desc explicitly. */
152 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
153 struct page *page, int pageoffset, int len)
155 LASSERT(desc->bd_iov_count < desc->bd_max_iov);
156 LASSERT(page != NULL);
157 LASSERT(pageoffset >= 0);
159 LASSERT(pageoffset + len <= PAGE_SIZE);
163 ptlrpc_add_bulk_page(desc, page, pageoffset, len);
166 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *desc)
170 LASSERT(desc != NULL);
171 LASSERT(desc->bd_iov_count != LI_POISON); /* not freed already */
172 LASSERT(!desc->bd_network_rw); /* network hands off or */
173 LASSERT((desc->bd_export != NULL) ^ (desc->bd_import != NULL));
175 class_export_put(desc->bd_export);
177 class_import_put(desc->bd_import);
179 OBD_FREE(desc, offsetof(struct ptlrpc_bulk_desc,
180 bd_iov[desc->bd_max_iov]));
184 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, int opcode,
185 int count, int *lengths, char **bufs)
187 struct ptlrpc_request *request;
191 LASSERT((unsigned long)imp > 0x1000);
193 OBD_ALLOC(request, sizeof(*request));
195 CERROR("request allocation out of memory\n");
199 rc = lustre_pack_request(request, count, lengths, bufs);
201 CERROR("cannot pack request %d\n", rc);
202 OBD_FREE(request, sizeof(*request));
206 request->rq_timeout = obd_timeout;
207 request->rq_send_state = LUSTRE_IMP_FULL;
208 request->rq_type = PTL_RPC_MSG_REQUEST;
209 request->rq_import = class_import_get(imp);
211 request->rq_req_cbid.cbid_fn = request_out_callback;
212 request->rq_req_cbid.cbid_arg = request;
214 request->rq_reply_cbid.cbid_fn = reply_in_callback;
215 request->rq_reply_cbid.cbid_arg = request;
217 request->rq_phase = RQ_PHASE_NEW;
219 /* XXX FIXME bug 249 */
220 request->rq_request_portal = imp->imp_client->cli_request_portal;
221 request->rq_reply_portal = imp->imp_client->cli_reply_portal;
223 spin_lock_init(&request->rq_lock);
224 INIT_LIST_HEAD(&request->rq_list);
225 INIT_LIST_HEAD(&request->rq_replay_list);
226 INIT_LIST_HEAD(&request->rq_set_chain);
227 init_waitqueue_head(&request->rq_reply_waitq);
228 request->rq_xid = ptlrpc_next_xid();
229 atomic_set(&request->rq_refcount, 1);
231 request->rq_reqmsg->opc = opcode;
232 request->rq_reqmsg->flags = 0;
237 struct ptlrpc_request_set *ptlrpc_prep_set(void)
239 struct ptlrpc_request_set *set;
241 OBD_ALLOC(set, sizeof *set);
244 INIT_LIST_HEAD(&set->set_requests);
245 init_waitqueue_head(&set->set_waitq);
246 set->set_remaining = 0;
247 spin_lock_init(&set->set_new_req_lock);
248 INIT_LIST_HEAD(&set->set_new_requests);
253 /* Finish with this set; opposite of prep_set. */
254 void ptlrpc_set_destroy(struct ptlrpc_request_set *set)
256 struct list_head *tmp;
257 struct list_head *next;
262 /* Requests on the set should either all be completed, or all be new */
263 expected_phase = (set->set_remaining == 0) ?
264 RQ_PHASE_COMPLETE : RQ_PHASE_NEW;
265 list_for_each (tmp, &set->set_requests) {
266 struct ptlrpc_request *req =
267 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
269 LASSERT(req->rq_phase == expected_phase);
273 LASSERT(set->set_remaining == 0 || set->set_remaining == n);
275 list_for_each_safe(tmp, next, &set->set_requests) {
276 struct ptlrpc_request *req =
277 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
278 list_del_init(&req->rq_set_chain);
280 LASSERT(req->rq_phase == expected_phase);
282 if (req->rq_phase == RQ_PHASE_NEW) {
284 if (req->rq_interpret_reply != NULL) {
285 int (*interpreter)(struct ptlrpc_request *,
287 req->rq_interpret_reply;
289 /* higher level (i.e. LOV) failed;
290 * let the sub reqs clean up */
291 req->rq_status = -EBADR;
292 interpreter(req, &req->rq_async_args,
295 set->set_remaining--;
299 ptlrpc_req_finished (req);
302 LASSERT(set->set_remaining == 0);
304 OBD_FREE(set, sizeof(*set));
308 void ptlrpc_set_add_req(struct ptlrpc_request_set *set,
309 struct ptlrpc_request *req)
311 /* The set takes over the caller's request reference */
312 list_add_tail(&req->rq_set_chain, &set->set_requests);
314 set->set_remaining++;
315 atomic_inc(&req->rq_import->imp_inflight);
318 /* lock so many callers can add things, the context that owns the set
319 * is supposed to notice these and move them into the set proper. */
320 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *set,
321 struct ptlrpc_request *req)
324 spin_lock_irqsave(&set->set_new_req_lock, flags);
325 /* The set takes over the caller's request reference */
326 list_add_tail(&req->rq_set_chain, &set->set_new_requests);
328 spin_unlock_irqrestore(&set->set_new_req_lock, flags);
332 * Based on the current state of the import, determine if the request
333 * can be sent, is an error, or should be delayed.
335 * Returns true if this request should be delayed. If false, and
336 * *status is set, then the request can not be sent and *status is the
337 * error code. If false and status is 0, then request can be sent.
339 * The imp->imp_lock must be held.
341 static int ptlrpc_import_delay_req(struct obd_import *imp,
342 struct ptlrpc_request *req, int *status)
347 LASSERT (status != NULL);
350 if (imp->imp_state == LUSTRE_IMP_NEW) {
351 DEBUG_REQ(D_ERROR, req, "Uninitialized import.");
355 else if (imp->imp_state == LUSTRE_IMP_CLOSED) {
356 DEBUG_REQ(D_ERROR, req, "IMP_CLOSED ");
359 /* allow CONNECT even if import is invalid */
360 else if (req->rq_send_state == LUSTRE_IMP_CONNECTING &&
361 imp->imp_state == LUSTRE_IMP_CONNECTING) {
365 * If the import has been invalidated (such as by an OST failure), the
366 * request must fail with -EIO.
368 else if (imp->imp_invalid) {
369 DEBUG_REQ(D_ERROR, req, "IMP_INVALID");
372 else if (req->rq_import_generation != imp->imp_generation) {
373 DEBUG_REQ(D_ERROR, req, "req wrong generation:");
376 else if (req->rq_send_state != imp->imp_state) {
377 if (imp->imp_obd->obd_no_recov || imp->imp_dlm_fake
379 *status = -EWOULDBLOCK;
387 static int ptlrpc_check_reply(struct ptlrpc_request *req)
393 /* serialise with network callback */
394 spin_lock_irqsave (&req->rq_lock, flags);
396 if (req->rq_replied) {
397 DEBUG_REQ(D_NET, req, "REPLIED:");
401 if (req->rq_net_err && !req->rq_timedout) {
402 spin_unlock_irqrestore (&req->rq_lock, flags);
403 rc = ptlrpc_expire_one_request(req);
404 spin_lock_irqsave (&req->rq_lock, flags);
409 DEBUG_REQ(D_ERROR, req, "ABORTED:");
413 if (req->rq_resend) {
414 DEBUG_REQ(D_ERROR, req, "RESEND:");
418 if (req->rq_restart) {
419 DEBUG_REQ(D_ERROR, req, "RESTART:");
424 spin_unlock_irqrestore (&req->rq_lock, flags);
425 DEBUG_REQ(D_NET, req, "rc = %d for", rc);
429 static int ptlrpc_check_status(struct ptlrpc_request *req)
434 err = req->rq_repmsg->status;
435 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
436 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err == %d",
438 RETURN(err < 0 ? err : -EINVAL);
442 DEBUG_REQ(D_INFO, req, "status is %d", err);
443 } else if (err > 0) {
444 /* XXX: translate this error from net to host */
445 DEBUG_REQ(D_INFO, req, "status is %d", err);
451 static int after_reply(struct ptlrpc_request *req)
454 struct obd_import *imp = req->rq_import;
458 LASSERT(!req->rq_receiving_reply);
460 /* NB Until this point, the whole of the incoming message,
461 * including buflens, status etc is in the sender's byte order. */
464 /* Clear reply swab mask; this is a new reply in sender's byte order */
465 req->rq_rep_swab_mask = 0;
467 LASSERT (req->rq_nob_received <= req->rq_replen);
468 rc = lustre_unpack_msg(req->rq_repmsg, req->rq_nob_received);
470 CERROR("unpack_rep failed: %d\n", rc);
474 if (req->rq_repmsg->type != PTL_RPC_MSG_REPLY &&
475 req->rq_repmsg->type != PTL_RPC_MSG_ERR) {
476 CERROR("invalid packet type received (type=%u)\n",
477 req->rq_repmsg->type);
481 /* Store transno in reqmsg for replay. */
482 req->rq_reqmsg->transno = req->rq_transno = req->rq_repmsg->transno;
484 rc = ptlrpc_check_status(req);
486 /* Either we've been evicted, or the server has failed for
487 * some reason. Try to reconnect, and if that fails, punt to the
489 if (rc == -ENOTCONN) {
490 if (req->rq_send_state != LUSTRE_IMP_FULL ||
491 imp->imp_obd->obd_no_recov || imp->imp_dlm_fake) {
495 ptlrpc_request_handle_notconn(req);
500 if (req->rq_import->imp_replayable) {
501 spin_lock_irqsave(&imp->imp_lock, flags);
502 if (req->rq_replay || req->rq_transno != 0)
503 ptlrpc_retain_replayable_request(req, imp);
504 else if (req->rq_commit_cb != NULL) {
505 spin_unlock_irqrestore(&imp->imp_lock, flags);
506 req->rq_commit_cb(req);
507 spin_lock_irqsave(&imp->imp_lock, flags);
510 if (req->rq_transno > imp->imp_max_transno)
511 imp->imp_max_transno = req->rq_transno;
513 /* Replay-enabled imports return commit-status information. */
514 if (req->rq_repmsg->last_committed)
515 imp->imp_peer_committed_transno =
516 req->rq_repmsg->last_committed;
517 ptlrpc_free_committed(imp);
518 spin_unlock_irqrestore(&imp->imp_lock, flags);
524 static int ptlrpc_send_new_req(struct ptlrpc_request *req)
526 char str[PTL_NALFMT_SIZE];
527 struct obd_import *imp;
532 LASSERT(req->rq_phase == RQ_PHASE_NEW);
533 req->rq_phase = RQ_PHASE_RPC;
535 imp = req->rq_import;
536 spin_lock_irqsave(&imp->imp_lock, flags);
538 req->rq_import_generation = imp->imp_generation;
540 if (ptlrpc_import_delay_req(imp, req, &rc)) {
541 spin_lock (&req->rq_lock);
543 spin_unlock (&req->rq_lock);
545 DEBUG_REQ(D_HA, req, "req from PID %d waiting for recovery: "
547 req->rq_reqmsg->status,
548 ptlrpc_import_state_name(req->rq_send_state),
549 ptlrpc_import_state_name(imp->imp_state));
550 LASSERT(list_empty (&req->rq_list));
552 list_add_tail(&req->rq_list, &imp->imp_delayed_list);
553 spin_unlock_irqrestore(&imp->imp_lock, flags);
558 spin_unlock_irqrestore(&imp->imp_lock, flags);
560 req->rq_phase = RQ_PHASE_INTERPRET;
564 /* XXX this is the same as ptlrpc_queue_wait */
565 LASSERT(list_empty(&req->rq_list));
566 list_add_tail(&req->rq_list, &imp->imp_sending_list);
567 spin_unlock_irqrestore(&imp->imp_lock, flags);
569 req->rq_reqmsg->status = current->pid;
570 CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:ni:nid:opc"
571 " %s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
572 imp->imp_obd->obd_uuid.uuid, req->rq_reqmsg->status,
574 imp->imp_connection->c_peer.peer_ni->pni_name,
575 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
576 req->rq_reqmsg->opc);
578 rc = ptl_send_rpc(req);
580 DEBUG_REQ(D_HA, req, "send failed (%d); expect timeout", rc);
587 int ptlrpc_check_set(struct ptlrpc_request_set *set)
589 char str[PTL_NALFMT_SIZE];
591 struct list_head *tmp;
592 int force_timer_recalc = 0;
595 if (set->set_remaining == 0)
598 list_for_each(tmp, &set->set_requests) {
599 struct ptlrpc_request *req =
600 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
601 struct obd_import *imp = req->rq_import;
604 if (req->rq_phase == RQ_PHASE_NEW &&
605 ptlrpc_send_new_req(req)) {
606 force_timer_recalc = 1;
609 if (!(req->rq_phase == RQ_PHASE_RPC ||
610 req->rq_phase == RQ_PHASE_BULK ||
611 req->rq_phase == RQ_PHASE_INTERPRET ||
612 req->rq_phase == RQ_PHASE_COMPLETE)) {
613 DEBUG_REQ(D_ERROR, req, "bad phase %x", req->rq_phase);
617 if (req->rq_phase == RQ_PHASE_COMPLETE)
620 if (req->rq_phase == RQ_PHASE_INTERPRET)
621 GOTO(interpret, req->rq_status);
623 if (req->rq_net_err && !req->rq_timedout)
624 ptlrpc_expire_one_request(req);
627 ptlrpc_unregister_reply(req);
628 if (req->rq_status == 0)
629 req->rq_status = -EIO;
630 req->rq_phase = RQ_PHASE_INTERPRET;
632 spin_lock_irqsave(&imp->imp_lock, flags);
633 list_del_init(&req->rq_list);
634 spin_unlock_irqrestore(&imp->imp_lock, flags);
636 GOTO(interpret, req->rq_status);
639 /* ptlrpc_queue_wait->l_wait_event guarantees that rq_intr
640 * will only be set after rq_timedout, but the oig waiting
641 * path sets rq_intr irrespective of whether ptlrpcd has
642 * seen a timeout. our policy is to only interpret
643 * interrupted rpcs after they have timed out */
644 if (req->rq_intr && (req->rq_timedout || req->rq_waiting)) {
645 /* NB could be on delayed list */
646 ptlrpc_unregister_reply(req);
647 req->rq_status = -EINTR;
648 req->rq_phase = RQ_PHASE_INTERPRET;
650 spin_lock_irqsave(&imp->imp_lock, flags);
651 list_del_init(&req->rq_list);
652 spin_unlock_irqrestore(&imp->imp_lock, flags);
654 GOTO(interpret, req->rq_status);
657 if (req->rq_phase == RQ_PHASE_RPC) {
658 if (req->rq_waiting || req->rq_resend) {
661 ptlrpc_unregister_reply(req);
663 spin_lock_irqsave(&imp->imp_lock, flags);
665 if (ptlrpc_import_delay_req(imp, req, &status)){
666 spin_unlock_irqrestore(&imp->imp_lock,
671 list_del_init(&req->rq_list);
673 req->rq_status = status;
674 req->rq_phase = RQ_PHASE_INTERPRET;
675 spin_unlock_irqrestore(&imp->imp_lock,
677 GOTO(interpret, req->rq_status);
679 if (req->rq_no_resend) {
680 req->rq_status = -ENOTCONN;
681 req->rq_phase = RQ_PHASE_INTERPRET;
682 spin_unlock_irqrestore(&imp->imp_lock,
684 GOTO(interpret, req->rq_status);
686 list_add_tail(&req->rq_list,
687 &imp->imp_sending_list);
689 spin_unlock_irqrestore(&imp->imp_lock, flags);
692 if (req->rq_resend) {
693 lustre_msg_add_flags(req->rq_reqmsg,
696 __u64 old_xid = req->rq_xid;
698 ptlrpc_unregister_bulk (req);
700 /* ensure previous bulk fails */
701 req->rq_xid = ptlrpc_next_xid();
702 CDEBUG(D_HA, "resend bulk "
705 old_xid, req->rq_xid);
709 rc = ptl_send_rpc(req);
711 DEBUG_REQ(D_HA, req, "send failed (%d)",
713 force_timer_recalc = 1;
716 /* need to reset the timeout */
717 force_timer_recalc = 1;
720 /* Still waiting for a reply? */
721 if (ptlrpc_client_receiving_reply(req))
724 /* Did we actually receive a reply? */
725 if (!ptlrpc_client_replied(req))
728 spin_lock_irqsave(&imp->imp_lock, flags);
729 list_del_init(&req->rq_list);
730 spin_unlock_irqrestore(&imp->imp_lock, flags);
732 req->rq_status = after_reply(req);
733 if (req->rq_resend) {
734 /* Add this req to the delayed list so
735 it can be errored if the import is
736 evicted after recovery. */
737 spin_lock_irqsave (&req->rq_lock, flags);
738 list_add_tail(&req->rq_list,
739 &imp->imp_delayed_list);
740 spin_unlock_irqrestore(&req->rq_lock, flags);
744 /* If there is no bulk associated with this request,
745 * then we're done and should let the interpreter
746 * process the reply. Similarly if the RPC returned
747 * an error, and therefore the bulk will never arrive.
749 if (req->rq_bulk == NULL || req->rq_status != 0) {
750 req->rq_phase = RQ_PHASE_INTERPRET;
751 GOTO(interpret, req->rq_status);
754 req->rq_phase = RQ_PHASE_BULK;
757 LASSERT(req->rq_phase == RQ_PHASE_BULK);
758 if (ptlrpc_bulk_active(req->rq_bulk))
761 if (!req->rq_bulk->bd_success) {
762 /* The RPC reply arrived OK, but the bulk screwed
763 * up! Dead wierd since the server told us the RPC
764 * was good after getting the REPLY for her GET or
765 * the ACK for her PUT. */
766 DEBUG_REQ(D_ERROR, req, "bulk transfer failed");
770 req->rq_phase = RQ_PHASE_INTERPRET;
773 LASSERT(req->rq_phase == RQ_PHASE_INTERPRET);
774 LASSERT(!req->rq_receiving_reply);
776 ptlrpc_unregister_reply(req);
777 if (req->rq_bulk != NULL)
778 ptlrpc_unregister_bulk (req);
780 req->rq_phase = RQ_PHASE_COMPLETE;
782 if (req->rq_interpret_reply != NULL) {
783 int (*interpreter)(struct ptlrpc_request *,void *,int) =
784 req->rq_interpret_reply;
785 req->rq_status = interpreter(req, &req->rq_async_args,
789 CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:ni:nid:"
790 "opc %s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
791 imp->imp_obd->obd_uuid.uuid, req->rq_reqmsg->status,
793 imp->imp_connection->c_peer.peer_ni->pni_name,
794 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
795 req->rq_reqmsg->opc);
797 set->set_remaining--;
799 atomic_dec(&imp->imp_inflight);
800 wake_up(&imp->imp_recovery_waitq);
803 /* If we hit an error, we want to recover promptly. */
804 RETURN(set->set_remaining == 0 || force_timer_recalc);
807 int ptlrpc_expire_one_request(struct ptlrpc_request *req)
810 struct obd_import *imp = req->rq_import;
813 DEBUG_REQ(D_ERROR, req, "timeout");
815 spin_lock_irqsave (&req->rq_lock, flags);
816 req->rq_timedout = 1;
817 spin_unlock_irqrestore (&req->rq_lock, flags);
819 ptlrpc_unregister_reply (req);
821 if (req->rq_bulk != NULL)
822 ptlrpc_unregister_bulk (req);
825 DEBUG_REQ(D_HA, req, "NULL import: already cleaned up?");
829 /* The DLM server doesn't want recovery run on its imports. */
830 if (imp->imp_dlm_fake)
833 /* If this request is for recovery or other primordial tasks,
834 * then error it out here. */
835 if (req->rq_send_state != LUSTRE_IMP_FULL ||
836 imp->imp_obd->obd_no_recov) {
837 spin_lock_irqsave (&req->rq_lock, flags);
838 req->rq_status = -ETIMEDOUT;
840 spin_unlock_irqrestore (&req->rq_lock, flags);
844 ptlrpc_fail_import(imp, req->rq_import_generation);
849 int ptlrpc_expired_set(void *data)
851 struct ptlrpc_request_set *set = data;
852 struct list_head *tmp;
853 time_t now = LTIME_S (CURRENT_TIME);
856 LASSERT(set != NULL);
858 /* A timeout expired; see which reqs it applies to... */
859 list_for_each (tmp, &set->set_requests) {
860 struct ptlrpc_request *req =
861 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
863 /* request in-flight? */
864 if (!((req->rq_phase == RQ_PHASE_RPC && !req->rq_waiting
865 && !req->rq_resend) ||
866 (req->rq_phase == RQ_PHASE_BULK)))
869 if (req->rq_timedout || /* already dealt with */
870 req->rq_sent + req->rq_timeout > now) /* not expired */
873 /* deal with this guy */
874 ptlrpc_expire_one_request (req);
877 /* When waiting for a whole set, we always to break out of the
878 * sleep so we can recalculate the timeout, or enable interrupts
879 * iff everyone's timed out.
884 void ptlrpc_mark_interrupted(struct ptlrpc_request *req)
887 spin_lock_irqsave(&req->rq_lock, flags);
889 spin_unlock_irqrestore(&req->rq_lock, flags);
892 void ptlrpc_interrupted_set(void *data)
894 struct ptlrpc_request_set *set = data;
895 struct list_head *tmp;
897 LASSERT(set != NULL);
898 CERROR("INTERRUPTED SET %p\n", set);
900 list_for_each(tmp, &set->set_requests) {
901 struct ptlrpc_request *req =
902 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
904 if (req->rq_phase != RQ_PHASE_RPC)
907 ptlrpc_mark_interrupted(req);
911 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set)
913 struct list_head *tmp;
914 time_t now = LTIME_S(CURRENT_TIME);
917 struct ptlrpc_request *req;
920 SIGNAL_MASK_ASSERT(); /* XXX BUG 1511 */
922 list_for_each(tmp, &set->set_requests) {
923 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
925 /* request in-flight? */
926 if (!((req->rq_phase == RQ_PHASE_RPC && !req->rq_waiting) ||
927 (req->rq_phase == RQ_PHASE_BULK)))
930 if (req->rq_timedout) /* already timed out */
933 deadline = req->rq_sent + req->rq_timeout;
934 if (deadline <= now) /* actually expired already */
935 timeout = 1; /* ASAP */
936 else if (timeout == 0 || timeout > deadline - now)
937 timeout = deadline - now;
943 int ptlrpc_set_wait(struct ptlrpc_request_set *set)
945 struct list_head *tmp;
946 struct ptlrpc_request *req;
947 struct l_wait_info lwi;
951 LASSERT(!list_empty(&set->set_requests));
952 list_for_each(tmp, &set->set_requests) {
953 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
954 if (req->rq_phase == RQ_PHASE_NEW)
955 (void)ptlrpc_send_new_req(req);
959 timeout = ptlrpc_set_next_timeout(set);
961 /* wait until all complete, interrupted, or an in-flight
963 CDEBUG(D_HA, "set %p going to sleep for %d seconds\n",
965 lwi = LWI_TIMEOUT_INTR((timeout ? timeout : 1) * HZ,
967 ptlrpc_interrupted_set, set);
968 rc = l_wait_event(set->set_waitq, ptlrpc_check_set(set), &lwi);
970 LASSERT(rc == 0 || rc == -EINTR || rc == -ETIMEDOUT);
972 /* -EINTR => all requests have been flagged rq_intr so next
974 * -ETIMEOUTD => someone timed out. When all reqs have
975 * timed out, signals are enabled allowing completion with
977 * I don't really care if we go once more round the loop in
978 * the error cases -eeb. */
981 LASSERT(set->set_remaining == 0);
984 list_for_each(tmp, &set->set_requests) {
985 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
987 LASSERT(req->rq_phase == RQ_PHASE_COMPLETE);
988 if (req->rq_status != 0)
992 if (set->set_interpret != NULL) {
993 int (*interpreter)(struct ptlrpc_request_set *set,void *,int) =
995 rc = interpreter (set, &set->set_args, rc);
1001 static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked)
1004 if (request == NULL) {
1009 LASSERTF(!request->rq_receiving_reply, "req %p\n", request);
1010 LASSERTF(request->rq_rqbd == NULL, "req %p\n",request);/* client-side */
1011 LASSERTF(list_empty(&request->rq_list), "req %p\n", request);
1012 LASSERTF(list_empty(&request->rq_set_chain), "req %p\n", request);
1014 /* We must take it off the imp_replay_list first. Otherwise, we'll set
1015 * request->rq_reqmsg to NULL while osc_close is dereferencing it. */
1016 if (request->rq_import != NULL) {
1017 unsigned long flags = 0;
1019 spin_lock_irqsave(&request->rq_import->imp_lock, flags);
1020 list_del_init(&request->rq_replay_list);
1022 spin_unlock_irqrestore(&request->rq_import->imp_lock,
1025 LASSERTF(list_empty(&request->rq_replay_list), "req %p\n", request);
1027 if (atomic_read(&request->rq_refcount) != 0) {
1028 DEBUG_REQ(D_ERROR, request,
1029 "freeing request with nonzero refcount");
1033 if (request->rq_repmsg != NULL) {
1034 OBD_FREE(request->rq_repmsg, request->rq_replen);
1035 request->rq_repmsg = NULL;
1037 if (request->rq_reqmsg != NULL) {
1038 OBD_FREE(request->rq_reqmsg, request->rq_reqlen);
1039 request->rq_reqmsg = NULL;
1041 if (request->rq_export != NULL) {
1042 class_export_put(request->rq_export);
1043 request->rq_export = NULL;
1045 if (request->rq_import != NULL) {
1046 class_import_put(request->rq_import);
1047 request->rq_import = NULL;
1049 if (request->rq_bulk != NULL)
1050 ptlrpc_free_bulk(request->rq_bulk);
1052 OBD_FREE(request, sizeof(*request));
1056 void ptlrpc_free_req(struct ptlrpc_request *request)
1058 __ptlrpc_free_req(request, 0);
1061 static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked);
1062 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request)
1064 LASSERT_SPIN_LOCKED(&request->rq_import->imp_lock);
1065 (void)__ptlrpc_req_finished(request, 1);
1068 static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked)
1071 if (request == NULL)
1074 if (request == LP_POISON ||
1075 request->rq_reqmsg == LP_POISON) {
1076 CERROR("dereferencing freed request (bug 575)\n");
1081 DEBUG_REQ(D_INFO, request, "refcount now %u",
1082 atomic_read(&request->rq_refcount) - 1);
1084 if (atomic_dec_and_test(&request->rq_refcount)) {
1085 __ptlrpc_free_req(request, locked);
1092 void ptlrpc_req_finished(struct ptlrpc_request *request)
1094 __ptlrpc_req_finished(request, 0);
1097 /* Disengage the client's reply buffer from the network
1098 * NB does _NOT_ unregister any client-side bulk.
1099 * IDEMPOTENT, but _not_ safe against concurrent callers.
1100 * The request owner (i.e. the thread doing the I/O) must call...
1102 void ptlrpc_unregister_reply (struct ptlrpc_request *request)
1105 wait_queue_head_t *wq;
1106 struct l_wait_info lwi;
1108 LASSERT(!in_interrupt ()); /* might sleep */
1110 if (!ptlrpc_client_receiving_reply(request))
1113 PtlMDUnlink (request->rq_reply_md_h);
1115 /* We have to l_wait_event() whatever the result, to give liblustre
1116 * a chance to run reply_in_callback() */
1118 if (request->rq_set == NULL)
1119 wq = &request->rq_set->set_waitq;
1121 wq = &request->rq_reply_waitq;
1124 /* Network access will complete in finite time but the HUGE
1125 * timeout lets us CWARN for visibility of sluggish NALs */
1126 lwi = LWI_TIMEOUT(300 * HZ, NULL, NULL);
1127 rc = l_wait_event (*wq, !ptlrpc_client_receiving_reply(request), &lwi);
1131 LASSERT (rc == -ETIMEDOUT);
1132 DEBUG_REQ(D_WARNING, request, "Unexpectedly long timeout");
1136 /* caller must hold imp->imp_lock */
1137 void ptlrpc_free_committed(struct obd_import *imp)
1139 struct list_head *tmp, *saved;
1140 struct ptlrpc_request *req;
1141 struct ptlrpc_request *last_req = NULL; /* temporary fire escape */
1144 LASSERT(imp != NULL);
1146 LASSERT_SPIN_LOCKED(&imp->imp_lock);
1148 CDEBUG(D_HA, "%s: committing for last_committed "LPU64"\n",
1149 imp->imp_obd->obd_name, imp->imp_peer_committed_transno);
1151 list_for_each_safe(tmp, saved, &imp->imp_replay_list) {
1152 req = list_entry(tmp, struct ptlrpc_request, rq_replay_list);
1154 /* XXX ok to remove when 1357 resolved - rread 05/29/03 */
1155 LASSERT(req != last_req);
1158 if (req->rq_import_generation < imp->imp_generation) {
1159 DEBUG_REQ(D_HA, req, "freeing request with old gen");
1163 if (req->rq_replay) {
1164 DEBUG_REQ(D_HA, req, "keeping (FL_REPLAY)");
1168 /* not yet committed */
1169 if (req->rq_transno > imp->imp_peer_committed_transno) {
1170 DEBUG_REQ(D_HA, req, "stopping search");
1174 DEBUG_REQ(D_HA, req, "committing (last_committed "LPU64")",
1175 imp->imp_peer_committed_transno);
1177 if (req->rq_commit_cb != NULL)
1178 req->rq_commit_cb(req);
1179 list_del_init(&req->rq_replay_list);
1180 __ptlrpc_req_finished(req, 1);
1187 void ptlrpc_cleanup_client(struct obd_import *imp)
1194 void ptlrpc_resend_req(struct ptlrpc_request *req)
1196 unsigned long flags;
1198 DEBUG_REQ(D_HA, req, "going to resend");
1199 req->rq_reqmsg->handle.cookie = 0;
1200 req->rq_status = -EAGAIN;
1202 spin_lock_irqsave (&req->rq_lock, flags);
1204 req->rq_net_err = 0;
1205 req->rq_timedout = 0;
1207 __u64 old_xid = req->rq_xid;
1209 /* ensure previous bulk fails */
1210 req->rq_xid = ptlrpc_next_xid();
1211 CDEBUG(D_HA, "resend bulk old x"LPU64" new x"LPU64"\n",
1212 old_xid, req->rq_xid);
1214 ptlrpc_wake_client_req(req);
1215 spin_unlock_irqrestore (&req->rq_lock, flags);
1218 /* XXX: this function and rq_status are currently unused */
1219 void ptlrpc_restart_req(struct ptlrpc_request *req)
1221 unsigned long flags;
1223 DEBUG_REQ(D_HA, req, "restarting (possibly-)completed request");
1224 req->rq_status = -ERESTARTSYS;
1226 spin_lock_irqsave (&req->rq_lock, flags);
1227 req->rq_restart = 1;
1228 req->rq_timedout = 0;
1229 ptlrpc_wake_client_req(req);
1230 spin_unlock_irqrestore (&req->rq_lock, flags);
1233 static int expired_request(void *data)
1235 struct ptlrpc_request *req = data;
1238 RETURN(ptlrpc_expire_one_request(req));
1241 static void interrupted_request(void *data)
1243 unsigned long flags;
1245 struct ptlrpc_request *req = data;
1246 DEBUG_REQ(D_HA, req, "request interrupted");
1247 spin_lock_irqsave (&req->rq_lock, flags);
1249 spin_unlock_irqrestore (&req->rq_lock, flags);
1252 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req)
1255 atomic_inc(&req->rq_refcount);
1259 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
1260 struct obd_import *imp)
1262 struct list_head *tmp;
1264 LASSERT_SPIN_LOCKED(&imp->imp_lock);
1266 /* clear this for new requests that were resent as well
1267 as resent replayed requests. */
1268 lustre_msg_clear_flags(req->rq_reqmsg,
1271 /* don't re-add requests that have been replayed */
1272 if (!list_empty(&req->rq_replay_list))
1275 lustre_msg_add_flags(req->rq_reqmsg,
1278 LASSERT(imp->imp_replayable);
1279 /* Balanced in ptlrpc_free_committed, usually. */
1280 ptlrpc_request_addref(req);
1281 list_for_each_prev(tmp, &imp->imp_replay_list) {
1282 struct ptlrpc_request *iter =
1283 list_entry(tmp, struct ptlrpc_request, rq_replay_list);
1285 /* We may have duplicate transnos if we create and then
1286 * open a file, or for closes retained if to match creating
1287 * opens, so use req->rq_xid as a secondary key.
1288 * (See bugs 684, 685, and 428.)
1289 * XXX no longer needed, but all opens need transnos!
1291 if (iter->rq_transno > req->rq_transno)
1294 if (iter->rq_transno == req->rq_transno) {
1295 LASSERT(iter->rq_xid != req->rq_xid);
1296 if (iter->rq_xid > req->rq_xid)
1300 list_add(&req->rq_replay_list, &iter->rq_replay_list);
1304 list_add_tail(&req->rq_replay_list, &imp->imp_replay_list);
1307 int ptlrpc_queue_wait(struct ptlrpc_request *req)
1309 char str[PTL_NALFMT_SIZE];
1312 struct l_wait_info lwi;
1313 struct obd_import *imp = req->rq_import;
1314 unsigned long flags;
1318 LASSERT(req->rq_set == NULL);
1319 LASSERT(!req->rq_receiving_reply);
1320 atomic_inc(&imp->imp_inflight);
1322 /* for distributed debugging */
1323 req->rq_reqmsg->status = current->pid;
1324 LASSERT(imp->imp_obd != NULL);
1325 CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:ni:nid:opc "
1326 "%s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
1327 imp->imp_obd->obd_uuid.uuid,
1328 req->rq_reqmsg->status, req->rq_xid,
1329 imp->imp_connection->c_peer.peer_ni->pni_name,
1330 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
1331 req->rq_reqmsg->opc);
1333 /* Mark phase here for a little debug help */
1334 req->rq_phase = RQ_PHASE_RPC;
1336 spin_lock_irqsave(&imp->imp_lock, flags);
1337 req->rq_import_generation = imp->imp_generation;
1339 if (ptlrpc_import_delay_req(imp, req, &rc)) {
1340 list_del(&req->rq_list);
1342 list_add_tail(&req->rq_list, &imp->imp_delayed_list);
1343 spin_unlock_irqrestore(&imp->imp_lock, flags);
1345 DEBUG_REQ(D_HA, req, "\"%s\" waiting for recovery: (%s != %s)",
1347 ptlrpc_import_state_name(req->rq_send_state),
1348 ptlrpc_import_state_name(imp->imp_state));
1349 lwi = LWI_INTR(interrupted_request, req);
1350 rc = l_wait_event(req->rq_reply_waitq,
1351 (req->rq_send_state == imp->imp_state ||
1354 DEBUG_REQ(D_HA, req, "\"%s\" awake: (%s == %s or %d == 1)",
1356 ptlrpc_import_state_name(imp->imp_state),
1357 ptlrpc_import_state_name(req->rq_send_state),
1360 spin_lock_irqsave(&imp->imp_lock, flags);
1361 list_del_init(&req->rq_list);
1366 else if (req->rq_intr) {
1369 else if (req->rq_no_resend) {
1370 spin_unlock_irqrestore(&imp->imp_lock, flags);
1371 GOTO(out, rc = -ETIMEDOUT);
1379 list_del_init(&req->rq_list);
1380 spin_unlock_irqrestore(&imp->imp_lock, flags);
1381 req->rq_status = rc; // XXX this ok?
1385 if (req->rq_resend) {
1386 lustre_msg_add_flags(req->rq_reqmsg, MSG_RESENT);
1388 if (req->rq_bulk != NULL)
1389 ptlrpc_unregister_bulk (req);
1391 DEBUG_REQ(D_HA, req, "resending: ");
1394 /* XXX this is the same as ptlrpc_set_wait */
1395 LASSERT(list_empty(&req->rq_list));
1396 list_add_tail(&req->rq_list, &imp->imp_sending_list);
1397 spin_unlock_irqrestore(&imp->imp_lock, flags);
1399 rc = ptl_send_rpc(req);
1401 DEBUG_REQ(D_HA, req, "send failed (%d); recovering", rc);
1404 timeout = MAX(req->rq_timeout * HZ, 1);
1405 DEBUG_REQ(D_NET, req, "-- sleeping");
1407 lwi = LWI_TIMEOUT_INTR(timeout, expired_request, interrupted_request,
1409 l_wait_event(req->rq_reply_waitq, ptlrpc_check_reply(req), &lwi);
1410 DEBUG_REQ(D_NET, req, "-- done sleeping");
1412 CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:ni:nid:opc "
1413 "%s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
1414 imp->imp_obd->obd_uuid.uuid,
1415 req->rq_reqmsg->status, req->rq_xid,
1416 imp->imp_connection->c_peer.peer_ni->pni_name,
1417 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
1418 req->rq_reqmsg->opc);
1420 spin_lock_irqsave(&imp->imp_lock, flags);
1421 list_del_init(&req->rq_list);
1422 spin_unlock_irqrestore(&imp->imp_lock, flags);
1424 /* If the reply was received normally, this just grabs the spinlock
1425 * (ensuring the reply callback has returned), sees that
1426 * req->rq_receiving_reply is clear and returns. */
1427 ptlrpc_unregister_reply (req);
1430 GOTO(out, rc = -EIO);
1432 /* Resend if we need to, unless we were interrupted. */
1433 if (req->rq_resend && !req->rq_intr) {
1434 /* ...unless we were specifically told otherwise. */
1435 if (req->rq_no_resend)
1436 GOTO(out, rc = -ETIMEDOUT);
1437 spin_lock_irqsave(&imp->imp_lock, flags);
1442 /* Should only be interrupted if we timed out. */
1443 if (!req->rq_timedout)
1444 DEBUG_REQ(D_ERROR, req,
1445 "rq_intr set but rq_timedout not");
1446 GOTO(out, rc = -EINTR);
1449 if (req->rq_timedout) { /* non-recoverable timeout */
1450 GOTO(out, rc = -ETIMEDOUT);
1453 if (!req->rq_replied) {
1454 /* How can this be? -eeb */
1455 DEBUG_REQ(D_ERROR, req, "!rq_replied: ");
1457 GOTO(out, rc = req->rq_status);
1460 rc = after_reply (req);
1461 /* NB may return +ve success rc */
1462 if (req->rq_resend) {
1463 spin_lock_irqsave(&imp->imp_lock, flags);
1468 if (req->rq_bulk != NULL) {
1470 /* success so far. Note that anything going wrong
1471 * with bulk now, is EXTREMELY strange, since the
1472 * server must have believed that the bulk
1473 * tranferred OK before she replied with success to
1475 lwi = LWI_TIMEOUT(timeout, NULL, NULL);
1476 brc = l_wait_event(req->rq_reply_waitq,
1477 !ptlrpc_bulk_active(req->rq_bulk),
1479 LASSERT(brc == 0 || brc == -ETIMEDOUT);
1481 LASSERT(brc == -ETIMEDOUT);
1482 DEBUG_REQ(D_ERROR, req, "bulk timed out");
1484 } else if (!req->rq_bulk->bd_success) {
1485 DEBUG_REQ(D_ERROR, req, "bulk transfer failed");
1490 ptlrpc_unregister_bulk (req);
1493 LASSERT(!req->rq_receiving_reply);
1494 req->rq_phase = RQ_PHASE_INTERPRET;
1496 atomic_dec(&imp->imp_inflight);
1497 wake_up(&imp->imp_recovery_waitq);
1501 struct ptlrpc_replay_async_args {
1503 int praa_old_status;
1506 static int ptlrpc_replay_interpret(struct ptlrpc_request *req,
1507 void * data, int rc)
1509 struct ptlrpc_replay_async_args *aa = data;
1510 struct obd_import *imp = req->rq_import;
1511 unsigned long flags;
1513 atomic_dec(&imp->imp_replay_inflight);
1515 if (!req->rq_replied) {
1516 CERROR("request replay timed out, restarting recovery\n");
1517 GOTO(out, rc = -ETIMEDOUT);
1521 /* Clear reply swab mask; this is a new reply in sender's byte order */
1522 req->rq_rep_swab_mask = 0;
1524 LASSERT (req->rq_nob_received <= req->rq_replen);
1525 rc = lustre_unpack_msg(req->rq_repmsg, req->rq_nob_received);
1527 CERROR("unpack_rep failed: %d\n", rc);
1528 GOTO(out, rc = -EPROTO);
1531 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR &&
1532 req->rq_repmsg->status == -ENOTCONN)
1533 GOTO(out, rc = req->rq_repmsg->status);
1535 /* The transno had better not change over replay. */
1536 LASSERT(req->rq_reqmsg->transno == req->rq_repmsg->transno);
1538 DEBUG_REQ(D_HA, req, "got rep");
1540 /* let the callback do fixups, possibly including in the request */
1541 if (req->rq_replay_cb)
1542 req->rq_replay_cb(req);
1544 if (req->rq_replied && req->rq_repmsg->status != aa->praa_old_status) {
1545 DEBUG_REQ(D_ERROR, req, "status %d, old was %d",
1546 req->rq_repmsg->status, aa->praa_old_status);
1548 /* Put it back for re-replay. */
1549 req->rq_repmsg->status = aa->praa_old_status;
1552 spin_lock_irqsave(&imp->imp_lock, flags);
1553 imp->imp_last_replay_transno = req->rq_transno;
1554 spin_unlock_irqrestore(&imp->imp_lock, flags);
1556 /* continue with recovery */
1557 rc = ptlrpc_import_recovery_state_machine(imp);
1559 req->rq_send_state = aa->praa_old_state;
1562 /* this replay failed, so restart recovery */
1563 ptlrpc_connect_import(imp, NULL);
1569 int ptlrpc_replay_req(struct ptlrpc_request *req)
1571 struct ptlrpc_replay_async_args *aa;
1574 LASSERT(req->rq_import->imp_state == LUSTRE_IMP_REPLAY);
1576 /* Not handling automatic bulk replay yet (or ever?) */
1577 LASSERT(req->rq_bulk == NULL);
1579 DEBUG_REQ(D_HA, req, "REPLAY");
1581 LASSERT (sizeof (*aa) <= sizeof (req->rq_async_args));
1582 aa = (struct ptlrpc_replay_async_args *)&req->rq_async_args;
1583 memset(aa, 0, sizeof *aa);
1585 /* Prepare request to be resent with ptlrpcd */
1586 aa->praa_old_state = req->rq_send_state;
1587 req->rq_send_state = LUSTRE_IMP_REPLAY;
1588 req->rq_phase = RQ_PHASE_NEW;
1589 aa->praa_old_status = req->rq_repmsg->status;
1592 req->rq_interpret_reply = ptlrpc_replay_interpret;
1593 atomic_inc(&req->rq_import->imp_replay_inflight);
1594 ptlrpc_request_addref(req); /* ptlrpcd needs a ref */
1596 ptlrpcd_add_req(req);
1600 void ptlrpc_abort_inflight(struct obd_import *imp)
1602 unsigned long flags;
1603 struct list_head *tmp, *n;
1606 /* Make sure that no new requests get processed for this import.
1607 * ptlrpc_{queue,set}_wait must (and does) hold imp_lock while testing
1608 * this flag and then putting requests on sending_list or delayed_list.
1610 spin_lock_irqsave(&imp->imp_lock, flags);
1612 /* XXX locking? Maybe we should remove each request with the list
1613 * locked? Also, how do we know if the requests on the list are
1614 * being freed at this time?
1616 list_for_each_safe(tmp, n, &imp->imp_sending_list) {
1617 struct ptlrpc_request *req =
1618 list_entry(tmp, struct ptlrpc_request, rq_list);
1620 DEBUG_REQ(D_HA, req, "inflight");
1622 spin_lock (&req->rq_lock);
1623 if (req->rq_import_generation < imp->imp_generation) {
1625 ptlrpc_wake_client_req(req);
1627 spin_unlock (&req->rq_lock);
1630 list_for_each_safe(tmp, n, &imp->imp_delayed_list) {
1631 struct ptlrpc_request *req =
1632 list_entry(tmp, struct ptlrpc_request, rq_list);
1634 DEBUG_REQ(D_HA, req, "aborting waiting req");
1636 spin_lock (&req->rq_lock);
1637 if (req->rq_import_generation < imp->imp_generation) {
1639 ptlrpc_wake_client_req(req);
1641 spin_unlock (&req->rq_lock);
1644 /* Last chance to free reqs left on the replay list, but we
1645 * will still leak reqs that haven't comitted. */
1646 if (imp->imp_replayable)
1647 ptlrpc_free_committed(imp);
1649 spin_unlock_irqrestore(&imp->imp_lock, flags);
1654 static __u64 ptlrpc_last_xid = 0;
1655 static spinlock_t ptlrpc_last_xid_lock = SPIN_LOCK_UNLOCKED;
1657 __u64 ptlrpc_next_xid(void)
1660 spin_lock(&ptlrpc_last_xid_lock);
1661 tmp = ++ptlrpc_last_xid;
1662 spin_unlock(&ptlrpc_last_xid_lock);