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 != 0x5a5a5a5a); /* 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 if (imp->imp_server_timeout)
207 request->rq_timeout = obd_timeout / 2;
209 request->rq_timeout = obd_timeout;
210 request->rq_send_state = LUSTRE_IMP_FULL;
211 request->rq_type = PTL_RPC_MSG_REQUEST;
212 request->rq_import = class_import_get(imp);
214 request->rq_req_cbid.cbid_fn = request_out_callback;
215 request->rq_req_cbid.cbid_arg = request;
217 request->rq_reply_cbid.cbid_fn = reply_in_callback;
218 request->rq_reply_cbid.cbid_arg = request;
220 request->rq_phase = RQ_PHASE_NEW;
222 /* XXX FIXME bug 249 */
223 request->rq_request_portal = imp->imp_client->cli_request_portal;
224 request->rq_reply_portal = imp->imp_client->cli_reply_portal;
226 spin_lock_init(&request->rq_lock);
227 INIT_LIST_HEAD(&request->rq_list);
228 INIT_LIST_HEAD(&request->rq_replay_list);
229 INIT_LIST_HEAD(&request->rq_set_chain);
230 init_waitqueue_head(&request->rq_reply_waitq);
231 request->rq_xid = ptlrpc_next_xid();
232 atomic_set(&request->rq_refcount, 1);
234 request->rq_reqmsg->opc = opcode;
235 request->rq_reqmsg->flags = 0;
240 struct ptlrpc_request_set *ptlrpc_prep_set(void)
242 struct ptlrpc_request_set *set;
244 OBD_ALLOC(set, sizeof *set);
247 INIT_LIST_HEAD(&set->set_requests);
248 init_waitqueue_head(&set->set_waitq);
249 set->set_remaining = 0;
250 spin_lock_init(&set->set_new_req_lock);
251 INIT_LIST_HEAD(&set->set_new_requests);
256 /* Finish with this set; opposite of prep_set. */
257 void ptlrpc_set_destroy(struct ptlrpc_request_set *set)
259 struct list_head *tmp;
260 struct list_head *next;
265 /* Requests on the set should either all be completed, or all be new */
266 expected_phase = (set->set_remaining == 0) ?
267 RQ_PHASE_COMPLETE : RQ_PHASE_NEW;
268 list_for_each (tmp, &set->set_requests) {
269 struct ptlrpc_request *req =
270 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
272 LASSERT(req->rq_phase == expected_phase);
276 LASSERT(set->set_remaining == 0 || set->set_remaining == n);
278 list_for_each_safe(tmp, next, &set->set_requests) {
279 struct ptlrpc_request *req =
280 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
281 list_del_init(&req->rq_set_chain);
283 LASSERT(req->rq_phase == expected_phase);
285 if (req->rq_phase == RQ_PHASE_NEW) {
287 if (req->rq_interpret_reply != NULL) {
288 int (*interpreter)(struct ptlrpc_request *,
290 req->rq_interpret_reply;
292 /* higher level (i.e. LOV) failed;
293 * let the sub reqs clean up */
294 req->rq_status = -EBADR;
295 interpreter(req, &req->rq_async_args,
298 set->set_remaining--;
302 ptlrpc_req_finished (req);
305 LASSERT(set->set_remaining == 0);
307 OBD_FREE(set, sizeof(*set));
311 void ptlrpc_set_add_req(struct ptlrpc_request_set *set,
312 struct ptlrpc_request *req)
314 /* The set takes over the caller's request reference */
315 list_add_tail(&req->rq_set_chain, &set->set_requests);
317 set->set_remaining++;
318 atomic_inc(&req->rq_import->imp_inflight);
321 /* lock so many callers can add things, the context that owns the set
322 * is supposed to notice these and move them into the set proper. */
323 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *set,
324 struct ptlrpc_request *req)
327 spin_lock_irqsave(&set->set_new_req_lock, flags);
328 /* The set takes over the caller's request reference */
329 list_add_tail(&req->rq_set_chain, &set->set_new_requests);
331 spin_unlock_irqrestore(&set->set_new_req_lock, flags);
335 * Based on the current state of the import, determine if the request
336 * can be sent, is an error, or should be delayed.
338 * Returns true if this request should be delayed. If false, and
339 * *status is set, then the request can not be sent and *status is the
340 * error code. If false and status is 0, then request can be sent.
342 * The imp->imp_lock must be held.
344 static int ptlrpc_import_delay_req(struct obd_import *imp,
345 struct ptlrpc_request *req, int *status)
350 LASSERT (status != NULL);
353 if (imp->imp_state == LUSTRE_IMP_NEW) {
354 DEBUG_REQ(D_ERROR, req, "Uninitialized import.");
358 else if (imp->imp_state == LUSTRE_IMP_CLOSED) {
359 DEBUG_REQ(D_ERROR, req, "IMP_CLOSED ");
362 /* allow CONNECT even if import is invalid */
363 else if (req->rq_send_state == LUSTRE_IMP_CONNECTING &&
364 imp->imp_state == LUSTRE_IMP_CONNECTING) {
368 * If the import has been invalidated (such as by an OST failure), the
369 * request must fail with -EIO.
371 else if (imp->imp_invalid) {
372 DEBUG_REQ(D_ERROR, req, "IMP_INVALID");
375 else if (req->rq_import_generation != imp->imp_generation) {
376 DEBUG_REQ(D_ERROR, req, "req wrong generation:");
379 else if (req->rq_send_state != imp->imp_state) {
380 if (imp->imp_obd->obd_no_recov || imp->imp_dlm_fake
382 *status = -EWOULDBLOCK;
390 static int ptlrpc_check_reply(struct ptlrpc_request *req)
396 /* serialise with network callback */
397 spin_lock_irqsave (&req->rq_lock, flags);
399 if (req->rq_replied) {
400 DEBUG_REQ(D_NET, req, "REPLIED:");
405 DEBUG_REQ(D_ERROR, req, "ABORTED:");
409 if (req->rq_resend) {
410 DEBUG_REQ(D_ERROR, req, "RESEND:");
414 if (req->rq_restart) {
415 DEBUG_REQ(D_ERROR, req, "RESTART:");
420 spin_unlock_irqrestore (&req->rq_lock, flags);
421 DEBUG_REQ(D_NET, req, "rc = %d for", rc);
425 static int ptlrpc_check_status(struct ptlrpc_request *req)
430 err = req->rq_repmsg->status;
431 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
432 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err == %d",
434 RETURN(err < 0 ? err : -EINVAL);
438 DEBUG_REQ(D_INFO, req, "status is %d", err);
439 } else if (err > 0) {
440 /* XXX: translate this error from net to host */
441 DEBUG_REQ(D_INFO, req, "status is %d", err);
447 static int after_reply(struct ptlrpc_request *req)
450 struct obd_import *imp = req->rq_import;
454 LASSERT(!req->rq_receiving_reply);
456 /* NB Until this point, the whole of the incoming message,
457 * including buflens, status etc is in the sender's byte order. */
460 /* Clear reply swab mask; this is a new reply in sender's byte order */
461 req->rq_rep_swab_mask = 0;
463 LASSERT (req->rq_nob_received <= req->rq_replen);
464 rc = lustre_unpack_msg(req->rq_repmsg, req->rq_nob_received);
466 CERROR("unpack_rep failed: %d\n", rc);
470 if (req->rq_repmsg->type != PTL_RPC_MSG_REPLY &&
471 req->rq_repmsg->type != PTL_RPC_MSG_ERR) {
472 CERROR("invalid packet type received (type=%u)\n",
473 req->rq_repmsg->type);
477 /* Store transno in reqmsg for replay. */
478 req->rq_reqmsg->transno = req->rq_transno = req->rq_repmsg->transno;
480 rc = ptlrpc_check_status(req);
482 /* Either we've been evicted, or the server has failed for
483 * some reason. Try to reconnect, and if that fails, punt to the
485 if (rc == -ENOTCONN) {
486 if (req->rq_send_state != LUSTRE_IMP_FULL ||
487 imp->imp_obd->obd_no_recov || imp->imp_dlm_fake) {
491 ptlrpc_request_handle_notconn(req);
496 if (req->rq_import->imp_replayable) {
497 spin_lock_irqsave(&imp->imp_lock, flags);
498 if (req->rq_replay || req->rq_transno != 0)
499 ptlrpc_retain_replayable_request(req, imp);
500 else if (req->rq_commit_cb != NULL) {
501 spin_unlock_irqrestore(&imp->imp_lock, flags);
502 req->rq_commit_cb(req);
503 spin_lock_irqsave(&imp->imp_lock, flags);
506 if (req->rq_transno > imp->imp_max_transno)
507 imp->imp_max_transno = req->rq_transno;
509 /* Replay-enabled imports return commit-status information. */
510 if (req->rq_repmsg->last_committed)
511 imp->imp_peer_committed_transno =
512 req->rq_repmsg->last_committed;
513 ptlrpc_free_committed(imp);
514 spin_unlock_irqrestore(&imp->imp_lock, flags);
520 static int ptlrpc_send_new_req(struct ptlrpc_request *req)
522 char str[PTL_NALFMT_SIZE];
523 struct obd_import *imp;
528 LASSERT(req->rq_phase == RQ_PHASE_NEW);
529 req->rq_phase = RQ_PHASE_RPC;
531 imp = req->rq_import;
532 spin_lock_irqsave(&imp->imp_lock, flags);
534 req->rq_import_generation = imp->imp_generation;
536 if (ptlrpc_import_delay_req(imp, req, &rc)) {
537 spin_lock (&req->rq_lock);
539 spin_unlock (&req->rq_lock);
541 DEBUG_REQ(D_HA, req, "req from PID %d waiting for recovery: "
543 req->rq_reqmsg->status,
544 ptlrpc_import_state_name(req->rq_send_state),
545 ptlrpc_import_state_name(imp->imp_state));
546 LASSERT(list_empty (&req->rq_list));
548 list_add_tail(&req->rq_list, &imp->imp_delayed_list);
549 spin_unlock_irqrestore(&imp->imp_lock, flags);
554 spin_unlock_irqrestore(&imp->imp_lock, flags);
556 req->rq_phase = RQ_PHASE_INTERPRET;
560 /* XXX this is the same as ptlrpc_queue_wait */
561 LASSERT(list_empty(&req->rq_list));
562 list_add_tail(&req->rq_list, &imp->imp_sending_list);
563 spin_unlock_irqrestore(&imp->imp_lock, flags);
565 req->rq_reqmsg->status = current->pid;
566 CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:ni:nid:opc"
567 " %s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
568 imp->imp_obd->obd_uuid.uuid, req->rq_reqmsg->status,
570 imp->imp_connection->c_peer.peer_ni->pni_name,
571 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
572 req->rq_reqmsg->opc);
574 rc = ptl_send_rpc(req);
576 DEBUG_REQ(D_HA, req, "send failed (%d); expect timeout", rc);
583 int ptlrpc_check_set(struct ptlrpc_request_set *set)
585 char str[PTL_NALFMT_SIZE];
587 struct list_head *tmp;
588 int force_timer_recalc = 0;
591 if (set->set_remaining == 0)
594 list_for_each(tmp, &set->set_requests) {
595 struct ptlrpc_request *req =
596 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
597 struct obd_import *imp = req->rq_import;
600 if (req->rq_phase == RQ_PHASE_NEW &&
601 ptlrpc_send_new_req(req)) {
602 force_timer_recalc = 1;
605 if (!(req->rq_phase == RQ_PHASE_RPC ||
606 req->rq_phase == RQ_PHASE_BULK ||
607 req->rq_phase == RQ_PHASE_INTERPRET ||
608 req->rq_phase == RQ_PHASE_COMPLETE)) {
609 DEBUG_REQ(D_ERROR, req, "bad phase %x", req->rq_phase);
613 if (req->rq_phase == RQ_PHASE_COMPLETE)
616 if (req->rq_phase == RQ_PHASE_INTERPRET)
617 GOTO(interpret, req->rq_status);
620 ptlrpc_unregister_reply(req);
621 if (req->rq_status == 0)
622 req->rq_status = -EIO;
623 req->rq_phase = RQ_PHASE_INTERPRET;
625 spin_lock_irqsave(&imp->imp_lock, flags);
626 list_del_init(&req->rq_list);
627 spin_unlock_irqrestore(&imp->imp_lock, flags);
629 GOTO(interpret, req->rq_status);
632 /* ptlrpc_queue_wait->l_wait_event guarantees that rq_intr
633 * will only be set after rq_timedout, but the oig waiting
634 * path sets rq_intr irrespective of whether ptlrpcd has
635 * seen a timeout. our policy is to only interpret
636 * interrupted rpcs after they have timed out */
637 if (req->rq_intr && (req->rq_timedout || req->rq_waiting)) {
638 /* NB could be on delayed list */
639 ptlrpc_unregister_reply(req);
640 req->rq_status = -EINTR;
641 req->rq_phase = RQ_PHASE_INTERPRET;
643 spin_lock_irqsave(&imp->imp_lock, flags);
644 list_del_init(&req->rq_list);
645 spin_unlock_irqrestore(&imp->imp_lock, flags);
647 GOTO(interpret, req->rq_status);
650 if (req->rq_phase == RQ_PHASE_RPC) {
651 if (req->rq_waiting || req->rq_resend) {
654 LASSERT (!ptlrpc_client_receiving_reply(req));
655 LASSERT (req->rq_bulk == NULL ||
656 !ptlrpc_bulk_active(req->rq_bulk));
658 spin_lock_irqsave(&imp->imp_lock, flags);
660 if (ptlrpc_import_delay_req(imp, req, &status)) {
661 spin_unlock_irqrestore(&imp->imp_lock,
666 list_del_init(&req->rq_list);
668 req->rq_status = status;
669 req->rq_phase = RQ_PHASE_INTERPRET;
670 spin_unlock_irqrestore(&imp->imp_lock,
672 GOTO(interpret, req->rq_status);
674 if (req->rq_no_resend) {
675 req->rq_status = -ENOTCONN;
676 req->rq_phase = RQ_PHASE_INTERPRET;
677 spin_unlock_irqrestore(&imp->imp_lock,
679 GOTO(interpret, req->rq_status);
681 list_add_tail(&req->rq_list,
682 &imp->imp_sending_list);
684 spin_unlock_irqrestore(&imp->imp_lock, flags);
687 if (req->rq_resend) {
688 lustre_msg_add_flags(req->rq_reqmsg,
690 ptlrpc_unregister_reply(req);
692 __u64 old_xid = req->rq_xid;
694 /* ensure previous bulk fails */
695 req->rq_xid = ptlrpc_next_xid();
696 CDEBUG(D_HA, "resend bulk "
699 old_xid, req->rq_xid);
703 rc = ptl_send_rpc(req);
705 DEBUG_REQ(D_HA, req, "send failed (%d)",
707 force_timer_recalc = 1;
710 /* need to reset the timeout */
711 force_timer_recalc = 1;
714 /* Still waiting for a reply? */
715 if (ptlrpc_client_receiving_reply(req))
718 /* Did we actually receive a reply? */
719 if (!ptlrpc_client_replied(req))
722 spin_lock_irqsave(&imp->imp_lock, flags);
723 list_del_init(&req->rq_list);
724 spin_unlock_irqrestore(&imp->imp_lock, flags);
726 req->rq_status = after_reply(req);
727 if (req->rq_resend) {
728 /* Add this req to the delayed list so
729 it can be errored if the import is
730 evicted after recovery. */
731 spin_lock_irqsave (&req->rq_lock, flags);
732 list_add_tail(&req->rq_list,
733 &imp->imp_delayed_list);
734 spin_unlock_irqrestore(&req->rq_lock, flags);
738 /* If there is no bulk associated with this request,
739 * then we're done and should let the interpreter
740 * process the reply. Similarly if the RPC returned
741 * an error, and therefore the bulk will never arrive.
743 if (req->rq_bulk == NULL || req->rq_status != 0) {
744 req->rq_phase = RQ_PHASE_INTERPRET;
745 GOTO(interpret, req->rq_status);
748 req->rq_phase = RQ_PHASE_BULK;
751 LASSERT(req->rq_phase == RQ_PHASE_BULK);
752 if (ptlrpc_bulk_active(req->rq_bulk))
755 if (!req->rq_bulk->bd_success) {
756 /* The RPC reply arrived OK, but the bulk screwed
757 * up! Dead wierd since the server told us the RPC
758 * was good after getting the REPLY for her GET or
759 * the ACK for her PUT. */
760 DEBUG_REQ(D_ERROR, req, "bulk transfer failed");
764 req->rq_phase = RQ_PHASE_INTERPRET;
767 LASSERT(req->rq_phase == RQ_PHASE_INTERPRET);
768 LASSERT(!req->rq_receiving_reply);
770 ptlrpc_unregister_reply(req);
771 if (req->rq_bulk != NULL)
772 ptlrpc_unregister_bulk (req);
774 req->rq_phase = RQ_PHASE_COMPLETE;
776 if (req->rq_interpret_reply != NULL) {
777 int (*interpreter)(struct ptlrpc_request *,void *,int) =
778 req->rq_interpret_reply;
779 req->rq_status = interpreter(req, &req->rq_async_args,
783 CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:ni:nid:"
784 "opc %s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
785 imp->imp_obd->obd_uuid.uuid, req->rq_reqmsg->status,
787 imp->imp_connection->c_peer.peer_ni->pni_name,
788 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
789 req->rq_reqmsg->opc);
791 set->set_remaining--;
793 atomic_dec(&imp->imp_inflight);
794 wake_up(&imp->imp_recovery_waitq);
797 /* If we hit an error, we want to recover promptly. */
798 RETURN(set->set_remaining == 0 || force_timer_recalc);
801 int ptlrpc_expire_one_request(struct ptlrpc_request *req)
804 struct obd_import *imp = req->rq_import;
807 DEBUG_REQ(D_ERROR, req, "timeout");
809 spin_lock_irqsave (&req->rq_lock, flags);
810 req->rq_timedout = 1;
811 spin_unlock_irqrestore (&req->rq_lock, flags);
813 ptlrpc_unregister_reply (req);
815 if (req->rq_bulk != NULL)
816 ptlrpc_unregister_bulk (req);
819 DEBUG_REQ(D_HA, req, "NULL import: already cleaned up?");
823 /* The DLM server doesn't want recovery run on its imports. */
824 if (imp->imp_dlm_fake)
827 /* If this request is for recovery or other primordial tasks,
828 * then error it out here. */
829 if (req->rq_send_state != LUSTRE_IMP_FULL ||
830 imp->imp_obd->obd_no_recov) {
831 spin_lock_irqsave (&req->rq_lock, flags);
832 req->rq_status = -ETIMEDOUT;
834 spin_unlock_irqrestore (&req->rq_lock, flags);
838 ptlrpc_fail_import(imp, req->rq_import_generation);
843 int ptlrpc_expired_set(void *data)
845 struct ptlrpc_request_set *set = data;
846 struct list_head *tmp;
847 time_t now = LTIME_S (CURRENT_TIME);
850 LASSERT(set != NULL);
852 /* A timeout expired; see which reqs it applies to... */
853 list_for_each (tmp, &set->set_requests) {
854 struct ptlrpc_request *req =
855 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
857 /* request in-flight? */
858 if (!((req->rq_phase == RQ_PHASE_RPC && !req->rq_waiting
859 && !req->rq_resend) ||
860 (req->rq_phase == RQ_PHASE_BULK)))
863 if (req->rq_timedout || /* already dealt with */
864 req->rq_sent + req->rq_timeout > now) /* not expired */
867 /* deal with this guy */
868 ptlrpc_expire_one_request (req);
871 /* When waiting for a whole set, we always to break out of the
872 * sleep so we can recalculate the timeout, or enable interrupts
873 * iff everyone's timed out.
878 void ptlrpc_mark_interrupted(struct ptlrpc_request *req)
881 spin_lock_irqsave(&req->rq_lock, flags);
883 spin_unlock_irqrestore(&req->rq_lock, flags);
886 void ptlrpc_interrupted_set(void *data)
888 struct ptlrpc_request_set *set = data;
889 struct list_head *tmp;
891 LASSERT(set != NULL);
892 CERROR("INTERRUPTED SET %p\n", set);
894 list_for_each(tmp, &set->set_requests) {
895 struct ptlrpc_request *req =
896 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
898 if (req->rq_phase != RQ_PHASE_RPC)
901 ptlrpc_mark_interrupted(req);
905 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set)
907 struct list_head *tmp;
908 time_t now = LTIME_S(CURRENT_TIME);
911 struct ptlrpc_request *req;
914 SIGNAL_MASK_ASSERT(); /* XXX BUG 1511 */
916 list_for_each(tmp, &set->set_requests) {
917 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
919 /* request in-flight? */
920 if (!((req->rq_phase == RQ_PHASE_RPC && !req->rq_waiting) ||
921 (req->rq_phase == RQ_PHASE_BULK)))
924 if (req->rq_timedout) /* already timed out */
927 deadline = req->rq_sent + req->rq_timeout;
928 if (deadline <= now) /* actually expired already */
929 timeout = 1; /* ASAP */
930 else if (timeout == 0 || timeout > deadline - now)
931 timeout = deadline - now;
937 int ptlrpc_set_wait(struct ptlrpc_request_set *set)
939 struct list_head *tmp;
940 struct ptlrpc_request *req;
941 struct l_wait_info lwi;
945 LASSERT(!list_empty(&set->set_requests));
946 list_for_each(tmp, &set->set_requests) {
947 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
948 if (req->rq_phase == RQ_PHASE_NEW)
949 (void)ptlrpc_send_new_req(req);
953 timeout = ptlrpc_set_next_timeout(set);
955 /* wait until all complete, interrupted, or an in-flight
957 CDEBUG(D_HA, "set %p going to sleep for %d seconds\n",
959 lwi = LWI_TIMEOUT_INTR((timeout ? timeout : 1) * HZ,
961 ptlrpc_interrupted_set, set);
962 rc = l_wait_event(set->set_waitq, ptlrpc_check_set(set), &lwi);
964 LASSERT(rc == 0 || rc == -EINTR || rc == -ETIMEDOUT);
966 /* -EINTR => all requests have been flagged rq_intr so next
968 * -ETIMEOUTD => someone timed out. When all reqs have
969 * timed out, signals are enabled allowing completion with
971 * I don't really care if we go once more round the loop in
972 * the error cases -eeb. */
975 LASSERT(set->set_remaining == 0);
978 list_for_each(tmp, &set->set_requests) {
979 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
981 LASSERT(req->rq_phase == RQ_PHASE_COMPLETE);
982 if (req->rq_status != 0)
986 if (set->set_interpret != NULL) {
987 int (*interpreter)(struct ptlrpc_request_set *set,void *,int) =
989 rc = interpreter (set, &set->set_args, rc);
995 static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked)
998 if (request == NULL) {
1003 LASSERTF(!request->rq_receiving_reply, "req %p\n", request);
1004 LASSERTF(request->rq_rqbd == NULL, "req %p\n",request);/* client-side */
1005 LASSERTF(list_empty(&request->rq_list), "req %p\n", request);
1006 LASSERTF(list_empty(&request->rq_set_chain), "req %p\n", request);
1008 /* We must take it off the imp_replay_list first. Otherwise, we'll set
1009 * request->rq_reqmsg to NULL while osc_close is dereferencing it. */
1010 if (request->rq_import != NULL) {
1011 unsigned long flags = 0;
1013 spin_lock_irqsave(&request->rq_import->imp_lock, flags);
1014 list_del_init(&request->rq_replay_list);
1016 spin_unlock_irqrestore(&request->rq_import->imp_lock,
1019 LASSERTF(list_empty(&request->rq_replay_list), "req %p\n", request);
1021 if (atomic_read(&request->rq_refcount) != 0) {
1022 DEBUG_REQ(D_ERROR, request,
1023 "freeing request with nonzero refcount");
1027 if (request->rq_repmsg != NULL) {
1028 OBD_FREE(request->rq_repmsg, request->rq_replen);
1029 request->rq_repmsg = NULL;
1031 if (request->rq_reqmsg != NULL) {
1032 OBD_FREE(request->rq_reqmsg, request->rq_reqlen);
1033 request->rq_reqmsg = NULL;
1035 if (request->rq_export != NULL) {
1036 class_export_put(request->rq_export);
1037 request->rq_export = NULL;
1039 if (request->rq_import != NULL) {
1040 class_import_put(request->rq_import);
1041 request->rq_import = NULL;
1043 if (request->rq_bulk != NULL)
1044 ptlrpc_free_bulk(request->rq_bulk);
1046 OBD_FREE(request, sizeof(*request));
1050 void ptlrpc_free_req(struct ptlrpc_request *request)
1052 __ptlrpc_free_req(request, 0);
1055 static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked);
1056 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request)
1058 LASSERT_SPIN_LOCKED(&request->rq_import->imp_lock);
1059 (void)__ptlrpc_req_finished(request, 1);
1062 static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked)
1065 if (request == NULL)
1068 if (request == LP_POISON ||
1069 request->rq_reqmsg == LP_POISON) {
1070 CERROR("dereferencing freed request (bug 575)\n");
1075 DEBUG_REQ(D_INFO, request, "refcount now %u",
1076 atomic_read(&request->rq_refcount) - 1);
1078 if (atomic_dec_and_test(&request->rq_refcount)) {
1079 __ptlrpc_free_req(request, locked);
1086 void ptlrpc_req_finished(struct ptlrpc_request *request)
1088 __ptlrpc_req_finished(request, 0);
1091 /* Disengage the client's reply buffer from the network
1092 * NB does _NOT_ unregister any client-side bulk.
1093 * IDEMPOTENT, but _not_ safe against concurrent callers.
1094 * The request owner (i.e. the thread doing the I/O) must call...
1096 void ptlrpc_unregister_reply (struct ptlrpc_request *request)
1099 wait_queue_head_t *wq;
1100 struct l_wait_info lwi;
1102 LASSERT(!in_interrupt ()); /* might sleep */
1104 if (!ptlrpc_client_receiving_reply(request))
1107 PtlMDUnlink (request->rq_reply_md_h);
1109 /* We have to l_wait_event() whatever the result, to give liblustre
1110 * a chance to run reply_in_callback() */
1112 if (request->rq_set == NULL)
1113 wq = &request->rq_set->set_waitq;
1115 wq = &request->rq_reply_waitq;
1118 /* Network access will complete in finite time but the HUGE
1119 * timeout lets us CWARN for visibility of sluggish NALs */
1120 lwi = LWI_TIMEOUT(300 * HZ, NULL, NULL);
1121 rc = l_wait_event (*wq, !ptlrpc_client_receiving_reply(request), &lwi);
1125 LASSERT (rc == -ETIMEDOUT);
1126 DEBUG_REQ(D_WARNING, request, "Unexpectedly long timeout");
1130 /* caller must hold imp->imp_lock */
1131 void ptlrpc_free_committed(struct obd_import *imp)
1133 struct list_head *tmp, *saved;
1134 struct ptlrpc_request *req;
1135 struct ptlrpc_request *last_req = NULL; /* temporary fire escape */
1138 LASSERT(imp != NULL);
1140 LASSERT_SPIN_LOCKED(&imp->imp_lock);
1142 CDEBUG(D_HA, "%s: committing for last_committed "LPU64"\n",
1143 imp->imp_obd->obd_name, imp->imp_peer_committed_transno);
1145 list_for_each_safe(tmp, saved, &imp->imp_replay_list) {
1146 req = list_entry(tmp, struct ptlrpc_request, rq_replay_list);
1148 /* XXX ok to remove when 1357 resolved - rread 05/29/03 */
1149 LASSERT(req != last_req);
1152 if (req->rq_import_generation < imp->imp_generation) {
1153 DEBUG_REQ(D_HA, req, "freeing request with old gen");
1157 if (req->rq_replay) {
1158 DEBUG_REQ(D_HA, req, "keeping (FL_REPLAY)");
1162 /* not yet committed */
1163 if (req->rq_transno > imp->imp_peer_committed_transno) {
1164 DEBUG_REQ(D_HA, req, "stopping search");
1168 DEBUG_REQ(D_HA, req, "committing (last_committed "LPU64")",
1169 imp->imp_peer_committed_transno);
1171 if (req->rq_commit_cb != NULL)
1172 req->rq_commit_cb(req);
1173 list_del_init(&req->rq_replay_list);
1174 __ptlrpc_req_finished(req, 1);
1181 void ptlrpc_cleanup_client(struct obd_import *imp)
1188 void ptlrpc_resend_req(struct ptlrpc_request *req)
1190 unsigned long flags;
1192 DEBUG_REQ(D_HA, req, "going to resend");
1193 req->rq_reqmsg->handle.cookie = 0;
1194 req->rq_status = -EAGAIN;
1196 spin_lock_irqsave (&req->rq_lock, flags);
1198 req->rq_timedout = 0;
1200 __u64 old_xid = req->rq_xid;
1202 /* ensure previous bulk fails */
1203 req->rq_xid = ptlrpc_next_xid();
1204 CDEBUG(D_HA, "resend bulk old x"LPU64" new x"LPU64"\n",
1205 old_xid, req->rq_xid);
1207 ptlrpc_wake_client_req(req);
1208 spin_unlock_irqrestore (&req->rq_lock, flags);
1211 /* XXX: this function and rq_status are currently unused */
1212 void ptlrpc_restart_req(struct ptlrpc_request *req)
1214 unsigned long flags;
1216 DEBUG_REQ(D_HA, req, "restarting (possibly-)completed request");
1217 req->rq_status = -ERESTARTSYS;
1219 spin_lock_irqsave (&req->rq_lock, flags);
1220 req->rq_restart = 1;
1221 req->rq_timedout = 0;
1222 ptlrpc_wake_client_req(req);
1223 spin_unlock_irqrestore (&req->rq_lock, flags);
1226 static int expired_request(void *data)
1228 struct ptlrpc_request *req = data;
1231 RETURN(ptlrpc_expire_one_request(req));
1234 static void interrupted_request(void *data)
1236 unsigned long flags;
1238 struct ptlrpc_request *req = data;
1239 DEBUG_REQ(D_HA, req, "request interrupted");
1240 spin_lock_irqsave (&req->rq_lock, flags);
1242 spin_unlock_irqrestore (&req->rq_lock, flags);
1245 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req)
1248 atomic_inc(&req->rq_refcount);
1252 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
1253 struct obd_import *imp)
1255 struct list_head *tmp;
1257 LASSERT_SPIN_LOCKED(&imp->imp_lock);
1259 /* don't re-add requests that have been replayed */
1260 if (!list_empty(&req->rq_replay_list))
1263 lustre_msg_add_flags(req->rq_reqmsg,
1266 LASSERT(imp->imp_replayable);
1267 /* Balanced in ptlrpc_free_committed, usually. */
1268 ptlrpc_request_addref(req);
1269 list_for_each_prev(tmp, &imp->imp_replay_list) {
1270 struct ptlrpc_request *iter =
1271 list_entry(tmp, struct ptlrpc_request, rq_replay_list);
1273 /* We may have duplicate transnos if we create and then
1274 * open a file, or for closes retained if to match creating
1275 * opens, so use req->rq_xid as a secondary key.
1276 * (See bugs 684, 685, and 428.)
1277 * XXX no longer needed, but all opens need transnos!
1279 if (iter->rq_transno > req->rq_transno)
1282 if (iter->rq_transno == req->rq_transno) {
1283 LASSERT(iter->rq_xid != req->rq_xid);
1284 if (iter->rq_xid > req->rq_xid)
1288 list_add(&req->rq_replay_list, &iter->rq_replay_list);
1292 list_add_tail(&req->rq_replay_list, &imp->imp_replay_list);
1295 int ptlrpc_queue_wait(struct ptlrpc_request *req)
1297 char str[PTL_NALFMT_SIZE];
1300 struct l_wait_info lwi;
1301 struct obd_import *imp = req->rq_import;
1302 unsigned long flags;
1306 LASSERT(req->rq_set == NULL);
1307 LASSERT(!req->rq_receiving_reply);
1308 atomic_inc(&imp->imp_inflight);
1310 /* for distributed debugging */
1311 req->rq_reqmsg->status = current->pid;
1312 LASSERT(imp->imp_obd != NULL);
1313 CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:ni:nid:opc "
1314 "%s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
1315 imp->imp_obd->obd_uuid.uuid,
1316 req->rq_reqmsg->status, req->rq_xid,
1317 imp->imp_connection->c_peer.peer_ni->pni_name,
1318 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
1319 req->rq_reqmsg->opc);
1321 /* Mark phase here for a little debug help */
1322 req->rq_phase = RQ_PHASE_RPC;
1324 spin_lock_irqsave(&imp->imp_lock, flags);
1325 req->rq_import_generation = imp->imp_generation;
1327 if (ptlrpc_import_delay_req(imp, req, &rc)) {
1328 list_del(&req->rq_list);
1330 list_add_tail(&req->rq_list, &imp->imp_delayed_list);
1331 spin_unlock_irqrestore(&imp->imp_lock, flags);
1333 DEBUG_REQ(D_HA, req, "\"%s\" waiting for recovery: (%s != %s)",
1335 ptlrpc_import_state_name(req->rq_send_state),
1336 ptlrpc_import_state_name(imp->imp_state));
1337 lwi = LWI_INTR(interrupted_request, req);
1338 rc = l_wait_event(req->rq_reply_waitq,
1339 (req->rq_send_state == imp->imp_state ||
1342 DEBUG_REQ(D_HA, req, "\"%s\" awake: (%s == %s or %d == 1)",
1344 ptlrpc_import_state_name(imp->imp_state),
1345 ptlrpc_import_state_name(req->rq_send_state),
1348 spin_lock_irqsave(&imp->imp_lock, flags);
1349 list_del_init(&req->rq_list);
1354 else if (req->rq_intr) {
1357 else if (req->rq_no_resend) {
1358 spin_unlock_irqrestore(&imp->imp_lock, flags);
1359 GOTO(out, rc = -ETIMEDOUT);
1367 list_del_init(&req->rq_list);
1368 spin_unlock_irqrestore(&imp->imp_lock, flags);
1369 req->rq_status = rc; // XXX this ok?
1373 if (req->rq_resend) {
1374 lustre_msg_add_flags(req->rq_reqmsg, MSG_RESENT);
1376 if (req->rq_bulk != NULL)
1377 ptlrpc_unregister_bulk (req);
1379 DEBUG_REQ(D_HA, req, "resending: ");
1382 /* XXX this is the same as ptlrpc_set_wait */
1383 LASSERT(list_empty(&req->rq_list));
1384 list_add_tail(&req->rq_list, &imp->imp_sending_list);
1385 spin_unlock_irqrestore(&imp->imp_lock, flags);
1387 rc = ptl_send_rpc(req);
1389 DEBUG_REQ(D_HA, req, "send failed (%d); recovering", rc);
1392 timeout = MAX(req->rq_timeout * HZ, 1);
1393 DEBUG_REQ(D_NET, req, "-- sleeping");
1395 lwi = LWI_TIMEOUT_INTR(timeout, expired_request, interrupted_request,
1397 l_wait_event(req->rq_reply_waitq, ptlrpc_check_reply(req), &lwi);
1398 DEBUG_REQ(D_NET, req, "-- done sleeping");
1400 CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:ni:nid:opc "
1401 "%s:%s:%d:"LPU64":%s:%s:%d\n", current->comm,
1402 imp->imp_obd->obd_uuid.uuid,
1403 req->rq_reqmsg->status, req->rq_xid,
1404 imp->imp_connection->c_peer.peer_ni->pni_name,
1405 ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
1406 req->rq_reqmsg->opc);
1408 spin_lock_irqsave(&imp->imp_lock, flags);
1409 list_del_init(&req->rq_list);
1410 spin_unlock_irqrestore(&imp->imp_lock, flags);
1412 /* If the reply was received normally, this just grabs the spinlock
1413 * (ensuring the reply callback has returned), sees that
1414 * req->rq_receiving_reply is clear and returns. */
1415 ptlrpc_unregister_reply (req);
1418 GOTO(out, rc = -EIO);
1420 /* Resend if we need to, unless we were interrupted. */
1421 if (req->rq_resend && !req->rq_intr) {
1422 /* ...unless we were specifically told otherwise. */
1423 if (req->rq_no_resend)
1424 GOTO(out, rc = -ETIMEDOUT);
1425 spin_lock_irqsave(&imp->imp_lock, flags);
1430 /* Should only be interrupted if we timed out. */
1431 if (!req->rq_timedout)
1432 DEBUG_REQ(D_ERROR, req,
1433 "rq_intr set but rq_timedout not");
1434 GOTO(out, rc = -EINTR);
1437 if (req->rq_timedout) { /* non-recoverable timeout */
1438 GOTO(out, rc = -ETIMEDOUT);
1441 if (!req->rq_replied) {
1442 /* How can this be? -eeb */
1443 DEBUG_REQ(D_ERROR, req, "!rq_replied: ");
1445 GOTO(out, rc = req->rq_status);
1448 rc = after_reply (req);
1449 /* NB may return +ve success rc */
1450 if (req->rq_resend) {
1451 spin_lock_irqsave(&imp->imp_lock, flags);
1456 if (req->rq_bulk != NULL) {
1458 /* success so far. Note that anything going wrong
1459 * with bulk now, is EXTREMELY strange, since the
1460 * server must have believed that the bulk
1461 * tranferred OK before she replied with success to
1463 lwi = LWI_TIMEOUT(timeout, NULL, NULL);
1464 brc = l_wait_event(req->rq_reply_waitq,
1465 !ptlrpc_bulk_active(req->rq_bulk),
1467 LASSERT(brc == 0 || brc == -ETIMEDOUT);
1469 LASSERT(brc == -ETIMEDOUT);
1470 DEBUG_REQ(D_ERROR, req, "bulk timed out");
1472 } else if (!req->rq_bulk->bd_success) {
1473 DEBUG_REQ(D_ERROR, req, "bulk transfer failed");
1478 ptlrpc_unregister_bulk (req);
1481 LASSERT(!req->rq_receiving_reply);
1482 req->rq_phase = RQ_PHASE_INTERPRET;
1484 atomic_dec(&imp->imp_inflight);
1485 wake_up(&imp->imp_recovery_waitq);
1489 struct ptlrpc_replay_async_args {
1491 int praa_old_status;
1494 static int ptlrpc_replay_interpret(struct ptlrpc_request *req,
1495 void * data, int rc)
1497 struct ptlrpc_replay_async_args *aa = data;
1498 struct obd_import *imp = req->rq_import;
1499 unsigned long flags;
1501 atomic_dec(&imp->imp_replay_inflight);
1503 if (!req->rq_replied) {
1504 CERROR("request replay timed out, restarting recovery\n");
1505 GOTO(out, rc = -ETIMEDOUT);
1509 /* Clear reply swab mask; this is a new reply in sender's byte order */
1510 req->rq_rep_swab_mask = 0;
1512 LASSERT (req->rq_nob_received <= req->rq_replen);
1513 rc = lustre_unpack_msg(req->rq_repmsg, req->rq_nob_received);
1515 CERROR("unpack_rep failed: %d\n", rc);
1516 GOTO(out, rc = -EPROTO);
1519 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR &&
1520 req->rq_repmsg->status == -ENOTCONN)
1521 GOTO(out, rc = req->rq_repmsg->status);
1523 /* The transno had better not change over replay. */
1524 LASSERT(req->rq_reqmsg->transno == req->rq_repmsg->transno);
1526 DEBUG_REQ(D_HA, req, "got rep");
1528 /* let the callback do fixups, possibly including in the request */
1529 if (req->rq_replay_cb)
1530 req->rq_replay_cb(req);
1532 if (req->rq_replied && req->rq_repmsg->status != aa->praa_old_status) {
1533 DEBUG_REQ(D_ERROR, req, "status %d, old was %d",
1534 req->rq_repmsg->status, aa->praa_old_status);
1536 /* Put it back for re-replay. */
1537 req->rq_repmsg->status = aa->praa_old_status;
1540 spin_lock_irqsave(&imp->imp_lock, flags);
1541 imp->imp_last_replay_transno = req->rq_transno;
1542 spin_unlock_irqrestore(&imp->imp_lock, flags);
1544 /* continue with recovery */
1545 rc = ptlrpc_import_recovery_state_machine(imp);
1547 req->rq_send_state = aa->praa_old_state;
1550 /* this replay failed, so restart recovery */
1551 ptlrpc_connect_import(imp, NULL);
1557 int ptlrpc_replay_req(struct ptlrpc_request *req)
1559 struct ptlrpc_replay_async_args *aa;
1562 LASSERT(req->rq_import->imp_state == LUSTRE_IMP_REPLAY);
1564 /* Not handling automatic bulk replay yet (or ever?) */
1565 LASSERT(req->rq_bulk == NULL);
1567 DEBUG_REQ(D_HA, req, "REPLAY");
1569 LASSERT (sizeof (*aa) <= sizeof (req->rq_async_args));
1570 aa = (struct ptlrpc_replay_async_args *)&req->rq_async_args;
1571 memset(aa, 0, sizeof *aa);
1573 /* Prepare request to be resent with ptlrpcd */
1574 aa->praa_old_state = req->rq_send_state;
1575 req->rq_send_state = LUSTRE_IMP_REPLAY;
1576 req->rq_phase = RQ_PHASE_NEW;
1578 * Q: "How can a req get on the replay list if it wasn't replied?"
1579 * A: "If we failed during the replay of this request, it will still
1580 * be on the list, but rq_replied will have been reset to 0."
1582 if (req->rq_replied) {
1583 aa->praa_old_status = req->rq_repmsg->status;
1585 req->rq_replied = 0;
1588 req->rq_interpret_reply = ptlrpc_replay_interpret;
1589 atomic_inc(&req->rq_import->imp_replay_inflight);
1590 ptlrpc_request_addref(req); /* ptlrpcd needs a ref */
1592 ptlrpcd_add_req(req);
1596 void ptlrpc_abort_inflight(struct obd_import *imp)
1598 unsigned long flags;
1599 struct list_head *tmp, *n;
1602 /* Make sure that no new requests get processed for this import.
1603 * ptlrpc_{queue,set}_wait must (and does) hold imp_lock while testing
1604 * this flag and then putting requests on sending_list or delayed_list.
1606 spin_lock_irqsave(&imp->imp_lock, flags);
1608 /* XXX locking? Maybe we should remove each request with the list
1609 * locked? Also, how do we know if the requests on the list are
1610 * being freed at this time?
1612 list_for_each_safe(tmp, n, &imp->imp_sending_list) {
1613 struct ptlrpc_request *req =
1614 list_entry(tmp, struct ptlrpc_request, rq_list);
1616 DEBUG_REQ(D_HA, req, "inflight");
1618 spin_lock (&req->rq_lock);
1619 if (req->rq_import_generation < imp->imp_generation) {
1621 ptlrpc_wake_client_req(req);
1623 spin_unlock (&req->rq_lock);
1626 list_for_each_safe(tmp, n, &imp->imp_delayed_list) {
1627 struct ptlrpc_request *req =
1628 list_entry(tmp, struct ptlrpc_request, rq_list);
1630 DEBUG_REQ(D_HA, req, "aborting waiting req");
1632 spin_lock (&req->rq_lock);
1633 if (req->rq_import_generation < imp->imp_generation) {
1635 ptlrpc_wake_client_req(req);
1637 spin_unlock (&req->rq_lock);
1640 /* Last chance to free reqs left on the replay list, but we
1641 * will still leak reqs that haven't comitted. */
1642 if (imp->imp_replayable)
1643 ptlrpc_free_committed(imp);
1645 spin_unlock_irqrestore(&imp->imp_lock, flags);
1650 static __u64 ptlrpc_last_xid = 0;
1651 static spinlock_t ptlrpc_last_xid_lock = SPIN_LOCK_UNLOCKED;
1653 __u64 ptlrpc_next_xid(void)
1656 spin_lock(&ptlrpc_last_xid_lock);
1657 tmp = ++ptlrpc_last_xid;
1658 spin_unlock(&ptlrpc_last_xid_lock);