1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see [sun.com URL with a
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_RPC
41 #include <liblustre.h>
44 #include <obd_support.h>
45 #include <obd_class.h>
46 #include <lustre_lib.h>
47 #include <lustre_ha.h>
48 #include <lustre_import.h>
49 #include <lustre_req_layout.h>
51 #include "ptlrpc_internal.h"
53 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
54 struct ptlrpc_client *cl)
56 cl->cli_request_portal = req_portal;
57 cl->cli_reply_portal = rep_portal;
61 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid)
63 struct ptlrpc_connection *c;
65 lnet_process_id_t peer;
68 err = ptlrpc_uuid_to_peer(uuid, &peer, &self);
70 CERROR("cannot find peer %s!\n", uuid->uuid);
74 c = ptlrpc_get_connection(peer, self, uuid);
76 memcpy(c->c_remote_uuid.uuid,
77 uuid->uuid, sizeof(c->c_remote_uuid.uuid));
80 CDEBUG(D_INFO, "%s -> %p\n", uuid->uuid, c);
85 void ptlrpc_readdress_connection(struct ptlrpc_connection *conn,
86 struct obd_uuid *uuid)
89 lnet_process_id_t peer;
92 err = ptlrpc_uuid_to_peer(uuid, &peer, &self);
94 CERROR("cannot find peer %s!\n", uuid->uuid);
103 static inline struct ptlrpc_bulk_desc *new_bulk(int npages, int type, int portal)
105 struct ptlrpc_bulk_desc *desc;
107 OBD_ALLOC(desc, offsetof (struct ptlrpc_bulk_desc, bd_iov[npages]));
111 spin_lock_init(&desc->bd_lock);
112 cfs_waitq_init(&desc->bd_waitq);
113 desc->bd_max_iov = npages;
114 desc->bd_iov_count = 0;
115 desc->bd_md_h = LNET_INVALID_HANDLE;
116 desc->bd_portal = portal;
117 desc->bd_type = type;
122 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
123 int npages, int type, int portal)
125 struct obd_import *imp = req->rq_import;
126 struct ptlrpc_bulk_desc *desc;
129 LASSERT(type == BULK_PUT_SINK || type == BULK_GET_SOURCE);
130 desc = new_bulk(npages, type, portal);
134 desc->bd_import_generation = req->rq_import_generation;
135 desc->bd_import = class_import_get(imp);
138 desc->bd_cbid.cbid_fn = client_bulk_callback;
139 desc->bd_cbid.cbid_arg = desc;
141 /* This makes req own desc, and free it when she frees herself */
147 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
148 int npages, int type, int portal)
150 struct obd_export *exp = req->rq_export;
151 struct ptlrpc_bulk_desc *desc;
154 LASSERT(type == BULK_PUT_SOURCE || type == BULK_GET_SINK);
156 desc = new_bulk(npages, type, portal);
160 desc->bd_export = class_export_get(exp);
163 desc->bd_cbid.cbid_fn = server_bulk_callback;
164 desc->bd_cbid.cbid_arg = desc;
166 /* NB we don't assign rq_bulk here; server-side requests are
167 * re-used, and the handler frees the bulk desc explicitly. */
172 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
173 cfs_page_t *page, int pageoffset, int len)
175 LASSERT(desc->bd_iov_count < desc->bd_max_iov);
176 LASSERT(page != NULL);
177 LASSERT(pageoffset >= 0);
179 LASSERT(pageoffset + len <= CFS_PAGE_SIZE);
183 ptlrpc_add_bulk_page(desc, page, pageoffset, len);
186 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *desc)
190 LASSERT(desc != NULL);
191 LASSERT(desc->bd_iov_count != LI_POISON); /* not freed already */
192 LASSERT(!desc->bd_network_rw); /* network hands off or */
193 LASSERT((desc->bd_export != NULL) ^ (desc->bd_import != NULL));
195 sptlrpc_enc_pool_put_pages(desc);
198 class_export_put(desc->bd_export);
200 class_import_put(desc->bd_import);
202 OBD_FREE(desc, offsetof(struct ptlrpc_bulk_desc,
203 bd_iov[desc->bd_max_iov]));
207 /* Set server timelimit for this req */
208 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req)
214 LASSERT(req->rq_import);
217 /* non-AT settings */
218 req->rq_timeout = req->rq_import->imp_server_timeout ?
219 obd_timeout / 2 : obd_timeout;
220 lustre_msg_set_timeout(req->rq_reqmsg, req->rq_timeout);
224 at = &req->rq_import->imp_at;
225 idx = import_at_get_index(req->rq_import,
226 req->rq_request_portal);
227 serv_est = at_get(&at->iat_service_estimate[idx]);
228 /* add an arbitrary minimum: 125% +5 sec */
229 req->rq_timeout = serv_est + (serv_est >> 2) + 5;
230 /* We could get even fancier here, using history to predict increased
233 /* Let the server know what this RPC timeout is by putting it in the
235 lustre_msg_set_timeout(req->rq_reqmsg, req->rq_timeout);
238 /* Adjust max service estimate based on server value */
239 static void ptlrpc_at_adj_service(struct ptlrpc_request *req)
242 unsigned int serv_est, oldse;
243 struct imp_at *at = &req->rq_import->imp_at;
245 LASSERT(req->rq_import);
247 /* service estimate is returned in the repmsg timeout field,
249 serv_est = lustre_msg_get_timeout(req->rq_repmsg);
251 idx = import_at_get_index(req->rq_import, req->rq_request_portal);
252 /* max service estimates are tracked on the server side,
253 so just keep minimal history here */
254 oldse = at_add(&at->iat_service_estimate[idx], serv_est);
256 CDEBUG(D_ADAPTTO, "The RPC service estimate for %s ptl %d "
257 "has changed from %d to %d\n",
258 req->rq_import->imp_obd->obd_name,req->rq_request_portal,
259 oldse, at_get(&at->iat_service_estimate[idx]));
262 /* Expected network latency per remote node (secs) */
263 int ptlrpc_at_get_net_latency(struct ptlrpc_request *req)
265 return AT_OFF ? 0 : at_get(&req->rq_import->imp_at.iat_net_latency);
268 /* Adjust expected network latency */
269 static void ptlrpc_at_adj_net_latency(struct ptlrpc_request *req)
271 unsigned int st, nl, oldnl;
272 struct imp_at *at = &req->rq_import->imp_at;
273 time_t now = cfs_time_current_sec();
275 LASSERT(req->rq_import);
277 st = lustre_msg_get_service_time(req->rq_repmsg);
279 /* Network latency is total time less server processing time */
280 nl = max_t(int, now - req->rq_sent - st, 0) + 1/*st rounding*/;
281 if (st > now - req->rq_sent + 2 /* rounding */)
282 CERROR("Reported service time %u > total measured time %ld\n",
283 st, now - req->rq_sent);
285 oldnl = at_add(&at->iat_net_latency, nl);
287 CDEBUG(D_ADAPTTO, "The network latency for %s (nid %s) "
288 "has changed from %d to %d\n",
289 req->rq_import->imp_obd->obd_name,
291 &req->rq_import->imp_connection->c_remote_uuid),
292 oldnl, at_get(&at->iat_net_latency));
295 static int unpack_reply(struct ptlrpc_request *req)
299 /* Clear reply swab mask; we may have already swabbed an early reply */
300 req->rq_rep_swab_mask = 0;
302 rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
304 DEBUG_REQ(D_ERROR, req, "unpack_rep failed: %d", rc);
308 rc = lustre_unpack_rep_ptlrpc_body(req, MSG_PTLRPC_BODY_OFF);
310 DEBUG_REQ(D_ERROR, req, "unpack ptlrpc body failed: %d", rc);
317 * Handle an early reply message, called with the rq_lock held.
318 * If anything goes wrong just ignore it - same as if it never happened
320 static int ptlrpc_at_recv_early_reply(struct ptlrpc_request *req) {
326 spin_unlock(&req->rq_lock);
328 rc = sptlrpc_cli_unwrap_early_reply(req);
332 rc = unpack_reply(req);
334 GOTO(out_cleanup, rc);
336 /* Expecting to increase the service time estimate here */
337 ptlrpc_at_adj_service(req);
338 ptlrpc_at_adj_net_latency(req);
340 /* Adjust the local timeout for this req */
341 ptlrpc_at_set_req_timeout(req);
343 olddl = req->rq_deadline;
344 /* server assumes it now has rq_timeout from when it sent the
345 early reply, so client should give it at least that long. */
346 req->rq_deadline = cfs_time_current_sec() + req->rq_timeout +
347 ptlrpc_at_get_net_latency(req);
349 DEBUG_REQ(D_ADAPTTO, req,
350 "Early reply #%d, new deadline in %lds (%+lds)",
351 req->rq_early_count, req->rq_deadline -
352 cfs_time_current_sec(), req->rq_deadline - olddl);
355 sptlrpc_cli_finish_early_reply(req);
357 spin_lock(&req->rq_lock);
361 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool)
363 struct list_head *l, *tmp;
364 struct ptlrpc_request *req;
369 list_for_each_safe(l, tmp, &pool->prp_req_list) {
370 req = list_entry(l, struct ptlrpc_request, rq_list);
371 list_del(&req->rq_list);
372 LASSERT(req->rq_reqbuf);
373 LASSERT(req->rq_reqbuf_len == pool->prp_rq_size);
374 OBD_FREE(req->rq_reqbuf, pool->prp_rq_size);
375 OBD_FREE(req, sizeof(*req));
377 OBD_FREE(pool, sizeof(*pool));
380 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq)
385 while (size < pool->prp_rq_size + SPTLRPC_MAX_PAYLOAD)
388 LASSERTF(list_empty(&pool->prp_req_list) || size == pool->prp_rq_size,
389 "Trying to change pool size with nonempty pool "
390 "from %d to %d bytes\n", pool->prp_rq_size, size);
392 spin_lock(&pool->prp_lock);
393 pool->prp_rq_size = size;
394 for (i = 0; i < num_rq; i++) {
395 struct ptlrpc_request *req;
396 struct lustre_msg *msg;
398 spin_unlock(&pool->prp_lock);
399 OBD_ALLOC(req, sizeof(struct ptlrpc_request));
402 OBD_ALLOC_GFP(msg, size, CFS_ALLOC_STD);
404 OBD_FREE(req, sizeof(struct ptlrpc_request));
407 req->rq_reqbuf = msg;
408 req->rq_reqbuf_len = size;
410 spin_lock(&pool->prp_lock);
411 list_add_tail(&req->rq_list, &pool->prp_req_list);
413 spin_unlock(&pool->prp_lock);
417 struct ptlrpc_request_pool *ptlrpc_init_rq_pool(int num_rq, int msgsize,
418 void (*populate_pool)(struct ptlrpc_request_pool *, int))
420 struct ptlrpc_request_pool *pool;
422 OBD_ALLOC(pool, sizeof (struct ptlrpc_request_pool));
426 /* Request next power of two for the allocation, because internally
427 kernel would do exactly this */
429 spin_lock_init(&pool->prp_lock);
430 CFS_INIT_LIST_HEAD(&pool->prp_req_list);
431 pool->prp_rq_size = msgsize;
432 pool->prp_populate = populate_pool;
434 populate_pool(pool, num_rq);
436 if (list_empty(&pool->prp_req_list)) {
437 /* have not allocated a single request for the pool */
438 OBD_FREE(pool, sizeof (struct ptlrpc_request_pool));
444 static struct ptlrpc_request *ptlrpc_prep_req_from_pool(struct ptlrpc_request_pool *pool)
446 struct ptlrpc_request *request;
447 struct lustre_msg *reqbuf;
452 spin_lock(&pool->prp_lock);
454 /* See if we have anything in a pool, and bail out if nothing,
455 * in writeout path, where this matters, this is safe to do, because
456 * nothing is lost in this case, and when some in-flight requests
457 * complete, this code will be called again. */
458 if (unlikely(list_empty(&pool->prp_req_list))) {
459 spin_unlock(&pool->prp_lock);
463 request = list_entry(pool->prp_req_list.next, struct ptlrpc_request,
465 list_del(&request->rq_list);
466 spin_unlock(&pool->prp_lock);
468 LASSERT(request->rq_reqbuf);
469 LASSERT(request->rq_pool);
471 reqbuf = request->rq_reqbuf;
472 memset(request, 0, sizeof(*request));
473 request->rq_reqbuf = reqbuf;
474 request->rq_reqbuf_len = pool->prp_rq_size;
475 request->rq_pool = pool;
479 static void __ptlrpc_free_req_to_pool(struct ptlrpc_request *request)
481 struct ptlrpc_request_pool *pool = request->rq_pool;
483 spin_lock(&pool->prp_lock);
484 LASSERT(list_empty(&request->rq_list));
485 list_add_tail(&request->rq_list, &pool->prp_req_list);
486 spin_unlock(&pool->prp_lock);
489 static int __ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
490 __u32 version, int opcode,
491 int count, __u32 *lengths, char **bufs,
492 struct ptlrpc_cli_ctx *ctx)
494 struct obd_import *imp = request->rq_import;
499 request->rq_cli_ctx = sptlrpc_cli_ctx_get(ctx);
501 rc = sptlrpc_req_get_ctx(request);
506 sptlrpc_req_set_flavor(request, opcode);
508 rc = lustre_pack_request(request, imp->imp_msg_magic, count,
511 LASSERT(!request->rq_pool);
515 lustre_msg_add_version(request->rq_reqmsg, version);
516 request->rq_send_state = LUSTRE_IMP_FULL;
517 request->rq_type = PTL_RPC_MSG_REQUEST;
518 request->rq_export = NULL;
520 request->rq_req_cbid.cbid_fn = request_out_callback;
521 request->rq_req_cbid.cbid_arg = request;
523 request->rq_reply_cbid.cbid_fn = reply_in_callback;
524 request->rq_reply_cbid.cbid_arg = request;
526 request->rq_phase = RQ_PHASE_NEW;
528 request->rq_request_portal = imp->imp_client->cli_request_portal;
529 request->rq_reply_portal = imp->imp_client->cli_reply_portal;
531 ptlrpc_at_set_req_timeout(request);
533 spin_lock_init(&request->rq_lock);
534 CFS_INIT_LIST_HEAD(&request->rq_list);
535 CFS_INIT_LIST_HEAD(&request->rq_timed_list);
536 CFS_INIT_LIST_HEAD(&request->rq_replay_list);
537 CFS_INIT_LIST_HEAD(&request->rq_mod_list);
538 CFS_INIT_LIST_HEAD(&request->rq_ctx_chain);
539 CFS_INIT_LIST_HEAD(&request->rq_set_chain);
540 CFS_INIT_LIST_HEAD(&request->rq_history_list);
541 cfs_waitq_init(&request->rq_reply_waitq);
542 request->rq_xid = ptlrpc_next_xid();
543 atomic_set(&request->rq_refcount, 1);
545 lustre_msg_set_opc(request->rq_reqmsg, opcode);
549 sptlrpc_cli_ctx_put(request->rq_cli_ctx, 1);
551 class_import_put(imp);
555 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
556 __u32 version, int opcode, char **bufs,
557 struct ptlrpc_cli_ctx *ctx)
561 count = req_capsule_filled_sizes(&request->rq_pill, RCL_CLIENT);
562 return __ptlrpc_request_bufs_pack(request, version, opcode, count,
563 request->rq_pill.rc_area[RCL_CLIENT],
566 EXPORT_SYMBOL(ptlrpc_request_bufs_pack);
568 int ptlrpc_request_pack(struct ptlrpc_request *request,
569 __u32 version, int opcode)
571 return ptlrpc_request_bufs_pack(request, version, opcode, NULL, NULL);
575 struct ptlrpc_request *__ptlrpc_request_alloc(struct obd_import *imp,
576 struct ptlrpc_request_pool *pool)
578 struct ptlrpc_request *request = NULL;
581 request = ptlrpc_prep_req_from_pool(pool);
584 OBD_ALLOC_PTR(request);
587 LASSERT((unsigned long)imp > 0x1000);
588 LASSERT(imp != LP_POISON);
589 LASSERT((unsigned long)imp->imp_client > 0x1000);
590 LASSERT(imp->imp_client != LP_POISON);
592 request->rq_import = class_import_get(imp);
594 CERROR("request allocation out of memory\n");
600 static struct ptlrpc_request *
601 ptlrpc_request_alloc_internal(struct obd_import *imp,
602 struct ptlrpc_request_pool * pool,
603 const struct req_format *format)
605 struct ptlrpc_request *request;
607 request = __ptlrpc_request_alloc(imp, pool);
611 req_capsule_init(&request->rq_pill, request, RCL_CLIENT);
612 req_capsule_set(&request->rq_pill, format);
616 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
617 const struct req_format *format)
619 return ptlrpc_request_alloc_internal(imp, NULL, format);
622 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
623 struct ptlrpc_request_pool * pool,
624 const struct req_format *format)
626 return ptlrpc_request_alloc_internal(imp, pool, format);
629 void ptlrpc_request_free(struct ptlrpc_request *request)
631 if (request->rq_pool)
632 __ptlrpc_free_req_to_pool(request);
634 OBD_FREE_PTR(request);
637 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
638 const struct req_format *format,
639 __u32 version, int opcode)
641 struct ptlrpc_request *req = ptlrpc_request_alloc(imp, format);
645 rc = ptlrpc_request_pack(req, version, opcode);
647 ptlrpc_request_free(req);
654 struct ptlrpc_request *
655 ptlrpc_prep_req_pool(struct obd_import *imp,
656 __u32 version, int opcode,
657 int count, __u32 *lengths, char **bufs,
658 struct ptlrpc_request_pool *pool)
660 struct ptlrpc_request *request;
663 request = __ptlrpc_request_alloc(imp, pool);
667 rc = __ptlrpc_request_bufs_pack(request, version, opcode, count,
668 lengths, bufs, NULL);
670 ptlrpc_request_free(request);
676 struct ptlrpc_request *
677 ptlrpc_prep_req(struct obd_import *imp, __u32 version, int opcode, int count,
678 __u32 *lengths, char **bufs)
680 return ptlrpc_prep_req_pool(imp, version, opcode, count, lengths, bufs,
684 struct ptlrpc_request_set *ptlrpc_prep_set(void)
686 struct ptlrpc_request_set *set;
689 OBD_ALLOC(set, sizeof *set);
692 CFS_INIT_LIST_HEAD(&set->set_requests);
693 cfs_waitq_init(&set->set_waitq);
694 set->set_remaining = 0;
695 spin_lock_init(&set->set_new_req_lock);
696 CFS_INIT_LIST_HEAD(&set->set_new_requests);
697 CFS_INIT_LIST_HEAD(&set->set_cblist);
702 /* Finish with this set; opposite of prep_set. */
703 void ptlrpc_set_destroy(struct ptlrpc_request_set *set)
705 struct list_head *tmp;
706 struct list_head *next;
711 /* Requests on the set should either all be completed, or all be new */
712 expected_phase = (set->set_remaining == 0) ?
713 RQ_PHASE_COMPLETE : RQ_PHASE_NEW;
714 list_for_each (tmp, &set->set_requests) {
715 struct ptlrpc_request *req =
716 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
718 LASSERT(req->rq_phase == expected_phase);
722 LASSERT(set->set_remaining == 0 || set->set_remaining == n);
724 list_for_each_safe(tmp, next, &set->set_requests) {
725 struct ptlrpc_request *req =
726 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
727 list_del_init(&req->rq_set_chain);
729 LASSERT(req->rq_phase == expected_phase);
731 if (req->rq_phase == RQ_PHASE_NEW) {
733 if (req->rq_interpret_reply != NULL) {
734 int (*interpreter)(struct ptlrpc_request *,
736 req->rq_interpret_reply;
738 /* higher level (i.e. LOV) failed;
739 * let the sub reqs clean up */
740 req->rq_status = -EBADR;
741 interpreter(req, &req->rq_async_args,
744 set->set_remaining--;
748 ptlrpc_req_finished (req);
751 LASSERT(set->set_remaining == 0);
753 OBD_FREE(set, sizeof(*set));
757 int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
758 set_interpreter_func fn, void *data)
760 struct ptlrpc_set_cbdata *cbdata;
762 OBD_ALLOC_PTR(cbdata);
766 cbdata->psc_interpret = fn;
767 cbdata->psc_data = data;
768 list_add_tail(&cbdata->psc_item, &set->set_cblist);
773 void ptlrpc_set_add_req(struct ptlrpc_request_set *set,
774 struct ptlrpc_request *req)
776 /* The set takes over the caller's request reference */
777 list_add_tail(&req->rq_set_chain, &set->set_requests);
779 set->set_remaining++;
781 atomic_inc(&req->rq_import->imp_inflight);
784 /* lock so many callers can add things, the context that owns the set
785 * is supposed to notice these and move them into the set proper. */
786 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *set,
787 struct ptlrpc_request *req)
789 spin_lock(&set->set_new_req_lock);
790 /* The set takes over the caller's request reference */
791 list_add_tail(&req->rq_set_chain, &set->set_new_requests);
793 spin_unlock(&set->set_new_req_lock);
797 * Based on the current state of the import, determine if the request
798 * can be sent, is an error, or should be delayed.
800 * Returns true if this request should be delayed. If false, and
801 * *status is set, then the request can not be sent and *status is the
802 * error code. If false and status is 0, then request can be sent.
804 * The imp->imp_lock must be held.
806 static int ptlrpc_import_delay_req(struct obd_import *imp,
807 struct ptlrpc_request *req, int *status)
812 LASSERT (status != NULL);
815 if (req->rq_ctx_init || req->rq_ctx_fini) {
816 /* always allow ctx init/fini rpc go through */
817 } else if (imp->imp_state == LUSTRE_IMP_NEW) {
818 DEBUG_REQ(D_ERROR, req, "Uninitialized import.");
821 } else if (imp->imp_state == LUSTRE_IMP_CLOSED) {
822 DEBUG_REQ(D_ERROR, req, "IMP_CLOSED ");
824 } else if (req->rq_send_state == LUSTRE_IMP_CONNECTING &&
825 imp->imp_state == LUSTRE_IMP_CONNECTING) {
826 /* allow CONNECT even if import is invalid */ ;
827 if (atomic_read(&imp->imp_inval_count) != 0) {
828 DEBUG_REQ(D_ERROR, req, "invalidate in flight");
831 } else if ((imp->imp_invalid && (!imp->imp_recon_bk)) ||
832 imp->imp_obd->obd_no_recov) {
833 /* If the import has been invalidated (such as by an OST
834 * failure), and if the import(MGC) tried all of its connection
835 * list (Bug 13464), the request must fail with -ESHUTDOWN.
836 * This indicates the requests should be discarded; an -EIO
837 * may result in a resend of the request. */
838 if (!imp->imp_deactive)
839 DEBUG_REQ(D_ERROR, req, "IMP_INVALID");
840 *status = -ESHUTDOWN; /* bz 12940 */
841 } else if (req->rq_import_generation != imp->imp_generation) {
842 DEBUG_REQ(D_ERROR, req, "req wrong generation:");
844 } else if (req->rq_send_state != imp->imp_state) {
845 /* invalidate in progress - any requests should be drop */
846 if (atomic_read(&imp->imp_inval_count) != 0) {
847 DEBUG_REQ(D_ERROR, req, "invalidate in flight");
849 } else if (imp->imp_dlm_fake || req->rq_no_delay) {
850 *status = -EWOULDBLOCK;
859 static int ptlrpc_check_reply(struct ptlrpc_request *req)
864 /* serialise with network callback */
865 spin_lock(&req->rq_lock);
870 if (req->rq_net_err && !req->rq_timedout) {
871 spin_unlock(&req->rq_lock);
872 rc = ptlrpc_expire_one_request(req);
873 spin_lock(&req->rq_lock);
887 ptlrpc_at_recv_early_reply(req);
888 GOTO(out, rc = 0); /* keep waiting */
893 spin_unlock(&req->rq_lock);
894 DEBUG_REQ(D_NET, req, "rc = %d for", rc);
898 static int ptlrpc_check_status(struct ptlrpc_request *req)
903 err = lustre_msg_get_status(req->rq_repmsg);
904 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
905 struct obd_import *imp = req->rq_import;
906 __u32 opc = lustre_msg_get_opc(req->rq_reqmsg);
907 LCONSOLE_ERROR_MSG(0x011,"an error occurred while communicating"
908 " with %s. The %s operation failed with %d\n",
909 libcfs_nid2str(imp->imp_connection->c_peer.nid),
910 ll_opcode2str(opc), err);
911 RETURN(err < 0 ? err : -EINVAL);
915 DEBUG_REQ(D_INFO, req, "status is %d", err);
916 } else if (err > 0) {
917 /* XXX: translate this error from net to host */
918 DEBUG_REQ(D_INFO, req, "status is %d", err);
925 * Callback function called when client receives RPC reply for \a req.
927 static int after_reply(struct ptlrpc_request *req)
929 struct obd_import *imp = req->rq_import;
930 struct obd_device *obd = req->rq_import->imp_obd;
932 struct timeval work_start;
936 LASSERT(!req->rq_receiving_reply);
938 LASSERT(req->rq_nob_received <= req->rq_repbuf_len);
941 * NB Until this point, the whole of the incoming message,
942 * including buflens, status etc is in the sender's byte order.
945 rc = sptlrpc_cli_unwrap_reply(req);
947 DEBUG_REQ(D_ERROR, req, "unwrap reply failed (%d):", rc);
952 * Security layer unwrap might ask resend this request.
957 rc = unpack_reply(req);
961 do_gettimeofday(&work_start);
962 timediff = cfs_timeval_sub(&work_start, &req->rq_arrival_time, NULL);
963 if (obd->obd_svc_stats != NULL)
964 lprocfs_counter_add(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR,
967 if (lustre_msg_get_type(req->rq_repmsg) != PTL_RPC_MSG_REPLY &&
968 lustre_msg_get_type(req->rq_repmsg) != PTL_RPC_MSG_ERR) {
969 DEBUG_REQ(D_ERROR, req, "invalid packet received (type=%u)",
970 lustre_msg_get_type(req->rq_repmsg));
974 OBD_FAIL_TIMEOUT(OBD_FAIL_PTLRPC_PAUSE_REP, obd_fail_val);
975 ptlrpc_at_adj_service(req);
976 ptlrpc_at_adj_net_latency(req);
978 rc = ptlrpc_check_status(req);
979 imp->imp_connect_error = rc;
983 * Either we've been evicted, or the server has failed for
984 * some reason. Try to reconnect, and if that fails, punt to
987 if (ll_rpc_recoverable_error(rc)) {
988 if (req->rq_send_state != LUSTRE_IMP_FULL ||
989 imp->imp_obd->obd_no_recov || imp->imp_dlm_fake) {
992 ptlrpc_request_handle_notconn(req);
997 * Let's look if server sent slv. Do it only for RPC with
1000 ldlm_cli_update_pool(req);
1004 * Store transno in reqmsg for replay.
1006 req->rq_transno = lustre_msg_get_transno(req->rq_repmsg);
1007 lustre_msg_set_transno(req->rq_reqmsg, req->rq_transno);
1009 if (req->rq_import->imp_replayable) {
1010 spin_lock(&imp->imp_lock);
1012 * No point in adding already-committed requests to the replay
1013 * list, we will just remove them immediately. b=9829
1015 if (req->rq_transno != 0 &&
1017 lustre_msg_get_last_committed(req->rq_repmsg) ||
1019 ptlrpc_retain_replayable_request(req, imp);
1020 else if (req->rq_commit_cb != NULL) {
1021 spin_unlock(&imp->imp_lock);
1022 req->rq_commit_cb(req);
1023 spin_lock(&imp->imp_lock);
1027 * Replay-enabled imports return commit-status information.
1029 if (lustre_msg_get_last_committed(req->rq_repmsg)) {
1030 imp->imp_peer_committed_transno =
1031 lustre_msg_get_last_committed(req->rq_repmsg);
1033 ptlrpc_free_committed(imp);
1034 spin_unlock(&imp->imp_lock);
1040 static int ptlrpc_send_new_req(struct ptlrpc_request *req)
1042 struct obd_import *imp;
1046 LASSERT(req->rq_phase == RQ_PHASE_NEW);
1047 if (req->rq_sent && (req->rq_sent > cfs_time_current_sec()))
1050 req->rq_phase = RQ_PHASE_RPC;
1052 imp = req->rq_import;
1053 spin_lock(&imp->imp_lock);
1055 req->rq_import_generation = imp->imp_generation;
1057 if (ptlrpc_import_delay_req(imp, req, &rc)) {
1058 spin_lock (&req->rq_lock);
1059 req->rq_waiting = 1;
1060 spin_unlock (&req->rq_lock);
1062 DEBUG_REQ(D_HA, req, "req from PID %d waiting for recovery: "
1064 lustre_msg_get_status(req->rq_reqmsg) ,
1065 ptlrpc_import_state_name(req->rq_send_state),
1066 ptlrpc_import_state_name(imp->imp_state));
1067 LASSERT(list_empty (&req->rq_list));
1069 list_add_tail(&req->rq_list, &imp->imp_delayed_list);
1070 spin_unlock(&imp->imp_lock);
1075 spin_unlock(&imp->imp_lock);
1076 req->rq_status = rc;
1077 req->rq_phase = RQ_PHASE_INTERPRET;
1081 /* XXX this is the same as ptlrpc_queue_wait */
1082 LASSERT(list_empty(&req->rq_list));
1083 list_add_tail(&req->rq_list, &imp->imp_sending_list);
1084 spin_unlock(&imp->imp_lock);
1086 lustre_msg_set_status(req->rq_reqmsg, cfs_curproc_pid());
1088 rc = sptlrpc_req_refresh_ctx(req, -1);
1091 req->rq_status = rc;
1094 /* here begins timeout counting */
1095 req->rq_sent = cfs_time_current_sec();
1096 req->rq_wait_ctx = 1;
1101 CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:nid:opc"
1102 " %s:%s:%d:"LPU64":%s:%d\n", cfs_curproc_comm(),
1103 imp->imp_obd->obd_uuid.uuid,
1104 lustre_msg_get_status(req->rq_reqmsg), req->rq_xid,
1105 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1106 lustre_msg_get_opc(req->rq_reqmsg));
1108 rc = ptl_send_rpc(req, 0);
1110 DEBUG_REQ(D_HA, req, "send failed (%d); expect timeout", rc);
1111 req->rq_net_err = 1;
1117 /* this sends any unsent RPCs in @set and returns TRUE if all are sent */
1118 int ptlrpc_check_set(struct ptlrpc_request_set *set)
1120 struct list_head *tmp;
1121 int force_timer_recalc = 0;
1124 if (set->set_remaining == 0)
1127 list_for_each(tmp, &set->set_requests) {
1128 struct ptlrpc_request *req =
1129 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
1130 struct obd_import *imp = req->rq_import;
1133 if (req->rq_phase == RQ_PHASE_NEW &&
1134 ptlrpc_send_new_req(req)) {
1135 force_timer_recalc = 1;
1137 /* delayed send - skip */
1138 if (req->rq_phase == RQ_PHASE_NEW && req->rq_sent)
1141 if (!(req->rq_phase == RQ_PHASE_RPC ||
1142 req->rq_phase == RQ_PHASE_BULK ||
1143 req->rq_phase == RQ_PHASE_INTERPRET ||
1144 req->rq_phase == RQ_PHASE_COMPLETE)) {
1145 DEBUG_REQ(D_ERROR, req, "bad phase %x", req->rq_phase);
1149 if (req->rq_phase == RQ_PHASE_COMPLETE)
1152 if (req->rq_phase == RQ_PHASE_INTERPRET)
1153 GOTO(interpret, req->rq_status);
1155 if (req->rq_net_err && !req->rq_timedout)
1156 ptlrpc_expire_one_request(req);
1159 ptlrpc_unregister_reply(req);
1160 req->rq_replied = 0;
1161 if (req->rq_status == 0)
1162 req->rq_status = -EIO;
1163 req->rq_phase = RQ_PHASE_INTERPRET;
1165 spin_lock(&imp->imp_lock);
1166 list_del_init(&req->rq_list);
1167 spin_unlock(&imp->imp_lock);
1169 GOTO(interpret, req->rq_status);
1172 /* ptlrpc_queue_wait->l_wait_event guarantees that rq_intr
1173 * will only be set after rq_timedout, but the oig waiting
1174 * path sets rq_intr irrespective of whether ptlrpcd has
1175 * seen a timeout. our policy is to only interpret
1176 * interrupted rpcs after they have timed out */
1177 if (req->rq_intr && (req->rq_timedout || req->rq_waiting ||
1178 req->rq_wait_ctx)) {
1179 /* NB could be on delayed list */
1180 ptlrpc_unregister_reply(req);
1181 req->rq_status = -EINTR;
1182 req->rq_phase = RQ_PHASE_INTERPRET;
1184 spin_lock(&imp->imp_lock);
1185 list_del_init(&req->rq_list);
1186 spin_unlock(&imp->imp_lock);
1188 GOTO(interpret, req->rq_status);
1191 if (req->rq_phase == RQ_PHASE_RPC) {
1192 if (req->rq_timedout || req->rq_resend ||
1193 req->rq_waiting || req->rq_wait_ctx) {
1196 /* rq_wait_ctx is only touched in ptlrpcd,
1197 * no lock needed here.
1199 if (req->rq_wait_ctx)
1202 ptlrpc_unregister_reply(req);
1204 spin_lock(&imp->imp_lock);
1206 if (ptlrpc_import_delay_req(imp, req, &status)){
1207 spin_unlock(&imp->imp_lock);
1211 list_del_init(&req->rq_list);
1213 req->rq_status = status;
1214 req->rq_phase = RQ_PHASE_INTERPRET;
1215 spin_unlock(&imp->imp_lock);
1216 GOTO(interpret, req->rq_status);
1218 if (req->rq_no_resend && !req->rq_wait_ctx) {
1219 req->rq_status = -ENOTCONN;
1220 req->rq_phase = RQ_PHASE_INTERPRET;
1221 spin_unlock(&imp->imp_lock);
1222 GOTO(interpret, req->rq_status);
1224 list_add_tail(&req->rq_list,
1225 &imp->imp_sending_list);
1227 spin_unlock(&imp->imp_lock);
1229 req->rq_waiting = 0;
1230 if (req->rq_resend) {
1231 lustre_msg_add_flags(req->rq_reqmsg,
1234 __u64 old_xid = req->rq_xid;
1236 ptlrpc_unregister_bulk (req);
1238 /* ensure previous bulk fails */
1239 req->rq_xid = ptlrpc_next_xid();
1240 CDEBUG(D_HA, "resend bulk "
1243 old_xid, req->rq_xid);
1247 status = sptlrpc_req_refresh_ctx(req, -1);
1250 req->rq_status = status;
1251 force_timer_recalc = 1;
1253 if (!req->rq_wait_ctx) {
1254 /* begins timeout counting */
1255 req->rq_sent = cfs_time_current_sec();
1256 req->rq_wait_ctx = 1;
1261 req->rq_wait_ctx = 0;
1264 rc = ptl_send_rpc(req, 0);
1266 DEBUG_REQ(D_HA, req, "send failed (%d)",
1268 force_timer_recalc = 1;
1269 req->rq_net_err = 1;
1271 /* need to reset the timeout */
1272 force_timer_recalc = 1;
1275 spin_lock(&req->rq_lock);
1277 if (req->rq_early) {
1278 ptlrpc_at_recv_early_reply(req);
1279 spin_unlock(&req->rq_lock);
1283 /* Still waiting for a reply? */
1284 if (req->rq_receiving_reply) {
1285 spin_unlock(&req->rq_lock);
1289 /* Did we actually receive a reply? */
1290 if (!req->rq_replied) {
1291 spin_unlock(&req->rq_lock);
1295 spin_unlock(&req->rq_lock);
1297 spin_lock(&imp->imp_lock);
1298 list_del_init(&req->rq_list);
1299 spin_unlock(&imp->imp_lock);
1301 req->rq_status = after_reply(req);
1302 if (req->rq_resend) {
1303 /* Add this req to the delayed list so
1304 it can be errored if the import is
1305 evicted after recovery. */
1306 spin_lock(&imp->imp_lock);
1307 list_add_tail(&req->rq_list,
1308 &imp->imp_delayed_list);
1309 spin_unlock(&imp->imp_lock);
1313 /* If there is no bulk associated with this request,
1314 * then we're done and should let the interpreter
1315 * process the reply. Similarly if the RPC returned
1316 * an error, and therefore the bulk will never arrive.
1318 if (req->rq_bulk == NULL || req->rq_status != 0) {
1319 req->rq_phase = RQ_PHASE_INTERPRET;
1320 GOTO(interpret, req->rq_status);
1323 req->rq_phase = RQ_PHASE_BULK;
1326 LASSERT(req->rq_phase == RQ_PHASE_BULK);
1327 if (ptlrpc_bulk_active(req->rq_bulk))
1330 if (!req->rq_bulk->bd_success) {
1331 /* The RPC reply arrived OK, but the bulk screwed
1332 * up! Dead wierd since the server told us the RPC
1333 * was good after getting the REPLY for her GET or
1334 * the ACK for her PUT. */
1335 DEBUG_REQ(D_ERROR, req, "bulk transfer failed");
1339 req->rq_phase = RQ_PHASE_INTERPRET;
1342 LASSERT(req->rq_phase == RQ_PHASE_INTERPRET);
1343 LASSERT(!req->rq_receiving_reply);
1345 ptlrpc_unregister_reply(req);
1346 if (req->rq_bulk != NULL)
1347 ptlrpc_unregister_bulk (req);
1349 if (req->rq_interpret_reply != NULL) {
1350 int (*interpreter)(struct ptlrpc_request *,void *,int) =
1351 req->rq_interpret_reply;
1352 req->rq_status = interpreter(req, &req->rq_async_args,
1355 req->rq_phase = RQ_PHASE_COMPLETE;
1357 CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:nid:"
1358 "opc %s:%s:%d:"LPU64":%s:%d\n", cfs_curproc_comm(),
1359 imp->imp_obd->obd_uuid.uuid,
1360 lustre_msg_get_status(req->rq_reqmsg), req->rq_xid,
1361 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1362 lustre_msg_get_opc(req->rq_reqmsg));
1364 atomic_dec(&imp->imp_inflight);
1365 set->set_remaining--;
1366 cfs_waitq_signal(&imp->imp_recovery_waitq);
1369 /* If we hit an error, we want to recover promptly. */
1370 RETURN(set->set_remaining == 0 || force_timer_recalc);
1373 /* Return 1 if we should give up, else 0 */
1374 int ptlrpc_expire_one_request(struct ptlrpc_request *req)
1376 struct obd_import *imp = req->rq_import;
1380 DEBUG_REQ(D_ERROR|D_NETERROR, req,
1381 "%s (sent at %lu, "CFS_DURATION_T"s ago)",
1382 req->rq_net_err ? "network error" : "timeout",
1383 (long)req->rq_sent, cfs_time_current_sec() - req->rq_sent);
1386 LCONSOLE_WARN("Request x"LPU64" sent from %s to NID %s %lus ago"
1387 " has timed out (limit %lus).\n", req->rq_xid,
1388 req->rq_import->imp_obd->obd_name,
1389 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1390 cfs_time_current_sec() - req->rq_sent,
1391 req->rq_deadline - req->rq_sent);
1394 if (imp != NULL && obd_debug_peer_on_timeout)
1395 LNetCtl(IOC_LIBCFS_DEBUG_PEER, &imp->imp_connection->c_peer);
1397 spin_lock(&req->rq_lock);
1398 req->rq_timedout = 1;
1399 req->rq_wait_ctx = 0;
1400 spin_unlock(&req->rq_lock);
1402 ptlrpc_unregister_reply (req);
1404 if (obd_dump_on_timeout)
1405 libcfs_debug_dumplog();
1407 if (req->rq_bulk != NULL)
1408 ptlrpc_unregister_bulk (req);
1411 DEBUG_REQ(D_HA, req, "NULL import: already cleaned up?");
1415 /* The DLM server doesn't want recovery run on its imports. */
1416 if (imp->imp_dlm_fake)
1419 /* If this request is for recovery or other primordial tasks,
1420 * then error it out here. */
1421 if (req->rq_ctx_init || req->rq_ctx_fini ||
1422 req->rq_send_state != LUSTRE_IMP_FULL ||
1423 imp->imp_obd->obd_no_recov) {
1424 DEBUG_REQ(D_RPCTRACE, req, "err -110, sent_state=%s (now=%s)",
1425 ptlrpc_import_state_name(req->rq_send_state),
1426 ptlrpc_import_state_name(imp->imp_state));
1427 spin_lock(&req->rq_lock);
1428 req->rq_status = -ETIMEDOUT;
1430 spin_unlock(&req->rq_lock);
1434 /* if a request can't be resent we can't wait for an answer after
1436 if (req->rq_no_resend) {
1437 DEBUG_REQ(D_RPCTRACE, req, "TIMEOUT-NORESEND:");
1441 ptlrpc_fail_import(imp, lustre_msg_get_conn_cnt(req->rq_reqmsg));
1446 int ptlrpc_expired_set(void *data)
1448 struct ptlrpc_request_set *set = data;
1449 struct list_head *tmp;
1450 time_t now = cfs_time_current_sec();
1453 LASSERT(set != NULL);
1455 /* A timeout expired; see which reqs it applies to... */
1456 list_for_each (tmp, &set->set_requests) {
1457 struct ptlrpc_request *req =
1458 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
1460 /* request in-flight? */
1461 if (!(((req->rq_phase == RQ_PHASE_RPC) && !req->rq_waiting &&
1463 (req->rq_phase == RQ_PHASE_BULK)))
1466 if (req->rq_timedout || /* already dealt with */
1467 req->rq_deadline > now) /* not expired */
1470 /* deal with this guy */
1471 ptlrpc_expire_one_request (req);
1474 /* When waiting for a whole set, we always to break out of the
1475 * sleep so we can recalculate the timeout, or enable interrupts
1476 * iff everyone's timed out.
1481 void ptlrpc_mark_interrupted(struct ptlrpc_request *req)
1483 spin_lock(&req->rq_lock);
1485 spin_unlock(&req->rq_lock);
1488 void ptlrpc_interrupted_set(void *data)
1490 struct ptlrpc_request_set *set = data;
1491 struct list_head *tmp;
1493 LASSERT(set != NULL);
1494 CERROR("INTERRUPTED SET %p\n", set);
1496 list_for_each(tmp, &set->set_requests) {
1497 struct ptlrpc_request *req =
1498 list_entry(tmp, struct ptlrpc_request, rq_set_chain);
1500 if (req->rq_phase != RQ_PHASE_RPC)
1503 ptlrpc_mark_interrupted(req);
1507 /* get the smallest timeout in the set; this does NOT set a timeout. */
1508 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set)
1510 struct list_head *tmp;
1511 time_t now = cfs_time_current_sec();
1513 struct ptlrpc_request *req;
1517 SIGNAL_MASK_ASSERT(); /* XXX BUG 1511 */
1519 list_for_each(tmp, &set->set_requests) {
1520 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
1522 /* request in-flight? */
1523 if (!((req->rq_phase == RQ_PHASE_RPC && !req->rq_waiting) ||
1524 (req->rq_phase == RQ_PHASE_BULK) ||
1525 (req->rq_phase == RQ_PHASE_NEW)))
1528 if (req->rq_timedout) /* already timed out */
1531 if (req->rq_phase == RQ_PHASE_NEW)
1532 deadline = req->rq_sent;
1534 deadline = req->rq_sent + req->rq_timeout;
1536 if (deadline <= now) /* actually expired already */
1537 timeout = 1; /* ASAP */
1538 else if (timeout == 0 || timeout > deadline - now)
1539 timeout = deadline - now;
1544 int ptlrpc_set_wait(struct ptlrpc_request_set *set)
1546 struct list_head *tmp;
1547 struct ptlrpc_request *req;
1548 struct l_wait_info lwi;
1552 if (list_empty(&set->set_requests))
1555 list_for_each(tmp, &set->set_requests) {
1556 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
1557 if (req->rq_phase == RQ_PHASE_NEW)
1558 (void)ptlrpc_send_new_req(req);
1562 timeout = ptlrpc_set_next_timeout(set);
1564 /* wait until all complete, interrupted, or an in-flight
1566 CDEBUG(D_RPCTRACE, "set %p going to sleep for %d seconds\n",
1568 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(timeout ? timeout : 1),
1570 ptlrpc_interrupted_set, set);
1571 rc = l_wait_event(set->set_waitq, ptlrpc_check_set(set), &lwi);
1573 LASSERT(rc == 0 || rc == -EINTR || rc == -ETIMEDOUT);
1575 /* -EINTR => all requests have been flagged rq_intr so next
1577 * -ETIMEOUTD => someone timed out. When all reqs have
1578 * timed out, signals are enabled allowing completion with
1580 * I don't really care if we go once more round the loop in
1581 * the error cases -eeb. */
1582 } while (rc != 0 || set->set_remaining != 0);
1584 LASSERT(set->set_remaining == 0);
1587 list_for_each(tmp, &set->set_requests) {
1588 req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
1590 LASSERT(req->rq_phase == RQ_PHASE_COMPLETE);
1591 if (req->rq_status != 0)
1592 rc = req->rq_status;
1595 if (set->set_interpret != NULL) {
1596 int (*interpreter)(struct ptlrpc_request_set *set,void *,int) =
1598 rc = interpreter (set, set->set_arg, rc);
1600 struct ptlrpc_set_cbdata *cbdata, *n;
1603 list_for_each_entry_safe(cbdata, n,
1604 &set->set_cblist, psc_item) {
1605 list_del_init(&cbdata->psc_item);
1606 err = cbdata->psc_interpret(set, cbdata->psc_data, rc);
1609 OBD_FREE_PTR(cbdata);
1616 static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked)
1619 if (request == NULL) {
1624 LASSERTF(!request->rq_receiving_reply, "req %p\n", request);
1625 LASSERTF(request->rq_rqbd == NULL, "req %p\n",request);/* client-side */
1626 LASSERTF(list_empty(&request->rq_list), "req %p\n", request);
1627 LASSERTF(list_empty(&request->rq_set_chain), "req %p\n", request);
1628 LASSERT(request->rq_cli_ctx);
1630 req_capsule_fini(&request->rq_pill);
1632 /* We must take it off the imp_replay_list first. Otherwise, we'll set
1633 * request->rq_reqmsg to NULL while osc_close is dereferencing it. */
1634 if (request->rq_import != NULL) {
1636 spin_lock(&request->rq_import->imp_lock);
1637 list_del_init(&request->rq_mod_list);
1638 list_del_init(&request->rq_replay_list);
1640 spin_unlock(&request->rq_import->imp_lock);
1642 LASSERTF(list_empty(&request->rq_replay_list), "req %p\n", request);
1644 if (atomic_read(&request->rq_refcount) != 0) {
1645 DEBUG_REQ(D_ERROR, request,
1646 "freeing request with nonzero refcount");
1650 if (request->rq_repbuf != NULL)
1651 sptlrpc_cli_free_repbuf(request);
1652 if (request->rq_export != NULL) {
1653 class_export_put(request->rq_export);
1654 request->rq_export = NULL;
1656 if (request->rq_import != NULL) {
1657 class_import_put(request->rq_import);
1658 request->rq_import = NULL;
1660 if (request->rq_bulk != NULL)
1661 ptlrpc_free_bulk(request->rq_bulk);
1663 if (request->rq_reqbuf != NULL || request->rq_clrbuf != NULL)
1664 sptlrpc_cli_free_reqbuf(request);
1666 sptlrpc_req_put_ctx(request, !locked);
1668 if (request->rq_pool)
1669 __ptlrpc_free_req_to_pool(request);
1671 OBD_FREE(request, sizeof(*request));
1675 void ptlrpc_free_req(struct ptlrpc_request *request)
1677 __ptlrpc_free_req(request, 0);
1680 static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked);
1681 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request)
1683 LASSERT_SPIN_LOCKED(&request->rq_import->imp_lock);
1684 (void)__ptlrpc_req_finished(request, 1);
1687 static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked)
1690 if (request == NULL)
1693 if (request == LP_POISON ||
1694 request->rq_reqmsg == LP_POISON) {
1695 CERROR("dereferencing freed request (bug 575)\n");
1700 DEBUG_REQ(D_INFO, request, "refcount now %u",
1701 atomic_read(&request->rq_refcount) - 1);
1703 if (atomic_dec_and_test(&request->rq_refcount)) {
1704 __ptlrpc_free_req(request, locked);
1711 void ptlrpc_req_finished(struct ptlrpc_request *request)
1713 __ptlrpc_req_finished(request, 0);
1716 __u64 ptlrpc_req_xid(struct ptlrpc_request *request)
1718 return request->rq_xid;
1720 EXPORT_SYMBOL(ptlrpc_req_xid);
1722 /* Disengage the client's reply buffer from the network
1723 * NB does _NOT_ unregister any client-side bulk.
1724 * IDEMPOTENT, but _not_ safe against concurrent callers.
1725 * The request owner (i.e. the thread doing the I/O) must call...
1727 void ptlrpc_unregister_reply (struct ptlrpc_request *request)
1731 struct l_wait_info lwi;
1733 LASSERT(!in_interrupt ()); /* might sleep */
1734 if (!ptlrpc_client_recv_or_unlink(request))
1735 /* Nothing left to do */
1738 LNetMDUnlink (request->rq_reply_md_h);
1740 /* We have to l_wait_event() whatever the result, to give liblustre
1741 * a chance to run reply_in_callback(), and to make sure we've
1742 * unlinked before returning a req to the pool */
1744 if (request->rq_set != NULL)
1745 wq = &request->rq_set->set_waitq;
1747 wq = &request->rq_reply_waitq;
1750 /* Network access will complete in finite time but the HUGE
1751 * timeout lets us CWARN for visibility of sluggish NALs */
1752 lwi = LWI_TIMEOUT(cfs_time_seconds(LONG_UNLINK), NULL, NULL);
1753 rc = l_wait_event (*wq, !ptlrpc_client_recv_or_unlink(request),
1758 LASSERT (rc == -ETIMEDOUT);
1759 DEBUG_REQ(D_WARNING, request, "Unexpectedly long timeout "
1760 "rvcng=%d unlnk=%d", request->rq_receiving_reply,
1761 request->rq_must_unlink);
1765 /* caller must hold imp->imp_lock */
1766 void ptlrpc_free_committed(struct obd_import *imp)
1768 struct list_head *tmp, *saved;
1769 struct ptlrpc_request *req;
1770 struct ptlrpc_request *last_req = NULL; /* temporary fire escape */
1773 LASSERT(imp != NULL);
1775 LASSERT_SPIN_LOCKED(&imp->imp_lock);
1778 if (imp->imp_peer_committed_transno == imp->imp_last_transno_checked &&
1779 imp->imp_generation == imp->imp_last_generation_checked) {
1780 CDEBUG(D_RPCTRACE, "%s: skip recheck: last_committed "LPU64"\n",
1781 imp->imp_obd->obd_name, imp->imp_peer_committed_transno);
1786 CDEBUG(D_RPCTRACE, "%s: committing for last_committed "LPU64" gen %d\n",
1787 imp->imp_obd->obd_name, imp->imp_peer_committed_transno,
1788 imp->imp_generation);
1789 imp->imp_last_transno_checked = imp->imp_peer_committed_transno;
1790 imp->imp_last_generation_checked = imp->imp_generation;
1792 list_for_each_safe(tmp, saved, &imp->imp_replay_list) {
1793 req = list_entry(tmp, struct ptlrpc_request, rq_replay_list);
1795 /* XXX ok to remove when 1357 resolved - rread 05/29/03 */
1796 LASSERT(req != last_req);
1799 if (req->rq_import_generation < imp->imp_generation) {
1800 DEBUG_REQ(D_RPCTRACE, req, "free request with old gen");
1804 if (req->rq_replay) {
1805 DEBUG_REQ(D_RPCTRACE, req, "keeping (FL_REPLAY)");
1809 /* not yet committed */
1810 if (req->rq_transno > imp->imp_peer_committed_transno) {
1811 DEBUG_REQ(D_RPCTRACE, req, "stopping search");
1815 DEBUG_REQ(D_RPCTRACE, req, "commit (last_committed "LPU64")",
1816 imp->imp_peer_committed_transno);
1818 spin_lock(&req->rq_lock);
1820 spin_unlock(&req->rq_lock);
1821 if (req->rq_commit_cb != NULL)
1822 req->rq_commit_cb(req);
1823 list_del_init(&req->rq_replay_list);
1824 __ptlrpc_req_finished(req, 1);
1831 void ptlrpc_cleanup_client(struct obd_import *imp)
1838 void ptlrpc_resend_req(struct ptlrpc_request *req)
1840 DEBUG_REQ(D_HA, req, "going to resend");
1841 lustre_msg_set_handle(req->rq_reqmsg, &(struct lustre_handle){ 0 });
1842 req->rq_status = -EAGAIN;
1844 spin_lock(&req->rq_lock);
1846 req->rq_net_err = 0;
1847 req->rq_timedout = 0;
1849 __u64 old_xid = req->rq_xid;
1851 /* ensure previous bulk fails */
1852 req->rq_xid = ptlrpc_next_xid();
1853 CDEBUG(D_HA, "resend bulk old x"LPU64" new x"LPU64"\n",
1854 old_xid, req->rq_xid);
1856 ptlrpc_wake_client_req(req);
1857 spin_unlock(&req->rq_lock);
1860 /* XXX: this function and rq_status are currently unused */
1861 void ptlrpc_restart_req(struct ptlrpc_request *req)
1863 DEBUG_REQ(D_HA, req, "restarting (possibly-)completed request");
1864 req->rq_status = -ERESTARTSYS;
1866 spin_lock(&req->rq_lock);
1867 req->rq_restart = 1;
1868 req->rq_timedout = 0;
1869 ptlrpc_wake_client_req(req);
1870 spin_unlock(&req->rq_lock);
1873 static int expired_request(void *data)
1875 struct ptlrpc_request *req = data;
1878 /* some failure can suspend regular timeouts */
1879 if (ptlrpc_check_suspend())
1882 /* deadline may have changed with an early reply */
1883 if (req->rq_deadline > cfs_time_current_sec())
1886 RETURN(ptlrpc_expire_one_request(req));
1889 static void interrupted_request(void *data)
1891 struct ptlrpc_request *req = data;
1892 DEBUG_REQ(D_HA, req, "request interrupted");
1893 spin_lock(&req->rq_lock);
1895 spin_unlock(&req->rq_lock);
1898 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req)
1901 atomic_inc(&req->rq_refcount);
1905 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
1906 struct obd_import *imp)
1908 struct list_head *tmp;
1910 LASSERT_SPIN_LOCKED(&imp->imp_lock);
1912 /* clear this for new requests that were resent as well
1913 as resent replayed requests. */
1914 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1916 /* don't re-add requests that have been replayed */
1917 if (!list_empty(&req->rq_replay_list))
1920 lustre_msg_add_flags(req->rq_reqmsg, MSG_REPLAY);
1922 LASSERT(imp->imp_replayable);
1923 /* Balanced in ptlrpc_free_committed, usually. */
1924 ptlrpc_request_addref(req);
1925 list_for_each_prev(tmp, &imp->imp_replay_list) {
1926 struct ptlrpc_request *iter =
1927 list_entry(tmp, struct ptlrpc_request, rq_replay_list);
1929 /* We may have duplicate transnos if we create and then
1930 * open a file, or for closes retained if to match creating
1931 * opens, so use req->rq_xid as a secondary key.
1932 * (See bugs 684, 685, and 428.)
1933 * XXX no longer needed, but all opens need transnos!
1935 if (iter->rq_transno > req->rq_transno)
1938 if (iter->rq_transno == req->rq_transno) {
1939 LASSERT(iter->rq_xid != req->rq_xid);
1940 if (iter->rq_xid > req->rq_xid)
1944 list_add(&req->rq_replay_list, &iter->rq_replay_list);
1948 list_add_tail(&req->rq_replay_list, &imp->imp_replay_list);
1951 int ptlrpc_queue_wait(struct ptlrpc_request *req)
1955 struct l_wait_info lwi;
1956 struct obd_import *imp = req->rq_import;
1957 cfs_duration_t timeout = CFS_TICK;
1961 LASSERT(req->rq_set == NULL);
1962 LASSERT(!req->rq_receiving_reply);
1963 atomic_inc(&imp->imp_inflight);
1965 /* for distributed debugging */
1966 lustre_msg_set_status(req->rq_reqmsg, cfs_curproc_pid());
1967 LASSERT(imp->imp_obd != NULL);
1968 CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:nid:opc "
1969 "%s:%s:%d:"LPU64":%s:%d\n", cfs_curproc_comm(),
1970 imp->imp_obd->obd_uuid.uuid,
1971 lustre_msg_get_status(req->rq_reqmsg), req->rq_xid,
1972 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1973 lustre_msg_get_opc(req->rq_reqmsg));
1975 /* Mark phase here for a little debug help */
1976 req->rq_phase = RQ_PHASE_RPC;
1978 spin_lock(&imp->imp_lock);
1979 req->rq_import_generation = imp->imp_generation;
1981 if (ptlrpc_import_delay_req(imp, req, &rc)) {
1982 list_del(&req->rq_list);
1984 list_add_tail(&req->rq_list, &imp->imp_delayed_list);
1985 spin_unlock(&imp->imp_lock);
1987 DEBUG_REQ(D_HA, req, "\"%s\" waiting for recovery: (%s != %s)",
1989 ptlrpc_import_state_name(req->rq_send_state),
1990 ptlrpc_import_state_name(imp->imp_state));
1991 lwi = LWI_INTR(interrupted_request, req);
1992 rc = l_wait_event(req->rq_reply_waitq,
1993 (req->rq_send_state == imp->imp_state ||
1994 req->rq_err || req->rq_intr),
1996 DEBUG_REQ(D_HA, req, "\"%s\" awake: (%s == %s or %d/%d == 1)",
1998 ptlrpc_import_state_name(imp->imp_state),
1999 ptlrpc_import_state_name(req->rq_send_state),
2000 req->rq_err, req->rq_intr);
2002 spin_lock(&imp->imp_lock);
2003 list_del_init(&req->rq_list);
2006 /* rq_status was set locally */
2009 else if (req->rq_intr) {
2012 else if (req->rq_no_resend) {
2013 spin_unlock(&imp->imp_lock);
2014 GOTO(out, rc = -ETIMEDOUT);
2022 list_del_init(&req->rq_list);
2023 spin_unlock(&imp->imp_lock);
2024 req->rq_status = rc; // XXX this ok?
2028 if (req->rq_resend) {
2029 lustre_msg_add_flags(req->rq_reqmsg, MSG_RESENT);
2031 if (req->rq_bulk != NULL) {
2032 ptlrpc_unregister_bulk (req);
2034 /* bulk requests are supposed to be
2035 * idempotent, so we are free to bump the xid
2036 * here, which we need to do before
2037 * registering the bulk again (bug 6371).
2038 * print the old xid first for sanity.
2040 DEBUG_REQ(D_HA, req, "bumping xid for bulk: ");
2041 req->rq_xid = ptlrpc_next_xid();
2044 DEBUG_REQ(D_HA, req, "resending: ");
2047 /* XXX this is the same as ptlrpc_set_wait */
2048 LASSERT(list_empty(&req->rq_list));
2049 list_add_tail(&req->rq_list, &imp->imp_sending_list);
2050 spin_unlock(&imp->imp_lock);
2052 rc = sptlrpc_req_refresh_ctx(req, 0);
2055 /* we got fatal ctx refresh error, directly jump out
2056 * thus we can pass back the actual error code.
2058 spin_lock(&imp->imp_lock);
2059 list_del_init(&req->rq_list);
2060 spin_unlock(&imp->imp_lock);
2062 CERROR("Failed to refresh ctx of req %p: %d\n", req, rc);
2065 /* simulating we got error during send rpc */
2069 rc = ptl_send_rpc(req, 0);
2071 DEBUG_REQ(D_HA, req, "send failed (%d); recovering", rc);
2074 timeoutl = req->rq_deadline - cfs_time_current_sec();
2075 timeout = (timeoutl <= 0 || rc) ? CFS_TICK :
2076 cfs_time_seconds(timeoutl);
2077 DEBUG_REQ(D_NET, req,
2078 "-- sleeping for "CFS_DURATION_T" ticks", timeout);
2079 lwi = LWI_TIMEOUT_INTR(timeout, expired_request, interrupted_request,
2081 rc = l_wait_event(req->rq_reply_waitq, ptlrpc_check_reply(req), &lwi);
2082 if (rc == -ETIMEDOUT && ((req->rq_deadline > cfs_time_current_sec()) ||
2083 ptlrpc_check_and_wait_suspend(req)))
2087 CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:nid:opc "
2088 "%s:%s:%d:"LPU64":%s:%d\n", cfs_curproc_comm(),
2089 imp->imp_obd->obd_uuid.uuid,
2090 lustre_msg_get_status(req->rq_reqmsg), req->rq_xid,
2091 libcfs_nid2str(imp->imp_connection->c_peer.nid),
2092 lustre_msg_get_opc(req->rq_reqmsg));
2094 spin_lock(&imp->imp_lock);
2095 list_del_init(&req->rq_list);
2096 spin_unlock(&imp->imp_lock);
2098 /* If the reply was received normally, this just grabs the spinlock
2099 * (ensuring the reply callback has returned), sees that
2100 * req->rq_receiving_reply is clear and returns. */
2101 ptlrpc_unregister_reply (req);
2105 DEBUG_REQ(D_RPCTRACE, req, "err rc=%d status=%d",
2106 rc, req->rq_status);
2107 GOTO(out, rc = -EIO);
2111 /* Should only be interrupted if we timed out. */
2112 if (!req->rq_timedout)
2113 DEBUG_REQ(D_ERROR, req,
2114 "rq_intr set but rq_timedout not");
2115 GOTO(out, rc = -EINTR);
2118 /* Resend if we need to */
2119 if (req->rq_resend) {
2120 /* ...unless we were specifically told otherwise. */
2121 if (req->rq_no_resend)
2122 GOTO(out, rc = -ETIMEDOUT);
2123 spin_lock(&imp->imp_lock);
2127 if (req->rq_timedout) { /* non-recoverable timeout */
2128 GOTO(out, rc = -ETIMEDOUT);
2131 if (!req->rq_replied) {
2132 /* How can this be? -eeb */
2133 DEBUG_REQ(D_ERROR, req, "!rq_replied: ");
2135 GOTO(out, rc = req->rq_status);
2138 rc = after_reply(req);
2139 /* NB may return +ve success rc */
2140 if (req->rq_resend) {
2141 spin_lock(&imp->imp_lock);
2146 if (req->rq_bulk != NULL) {
2148 /* success so far. Note that anything going wrong
2149 * with bulk now, is EXTREMELY strange, since the
2150 * server must have believed that the bulk
2151 * tranferred OK before she replied with success to
2153 lwi = LWI_TIMEOUT(timeout, NULL, NULL);
2154 brc = l_wait_event(req->rq_reply_waitq,
2155 !ptlrpc_bulk_active(req->rq_bulk),
2157 LASSERT(brc == 0 || brc == -ETIMEDOUT);
2159 LASSERT(brc == -ETIMEDOUT);
2160 DEBUG_REQ(D_ERROR, req, "bulk timed out");
2162 } else if (!req->rq_bulk->bd_success) {
2163 DEBUG_REQ(D_ERROR, req, "bulk transfer failed");
2168 ptlrpc_unregister_bulk (req);
2171 LASSERT(!req->rq_receiving_reply);
2172 req->rq_phase = RQ_PHASE_INTERPRET;
2174 atomic_dec(&imp->imp_inflight);
2175 cfs_waitq_signal(&imp->imp_recovery_waitq);
2179 struct ptlrpc_replay_async_args {
2181 int praa_old_status;
2184 static int ptlrpc_replay_interpret(struct ptlrpc_request *req,
2185 void * data, int rc)
2187 struct ptlrpc_replay_async_args *aa = data;
2188 struct obd_import *imp = req->rq_import;
2191 atomic_dec(&imp->imp_replay_inflight);
2193 if (!req->rq_replied) {
2194 CERROR("request replay timed out, restarting recovery\n");
2195 GOTO(out, rc = -ETIMEDOUT);
2198 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR &&
2199 (lustre_msg_get_status(req->rq_repmsg) == -ENOTCONN ||
2200 lustre_msg_get_status(req->rq_repmsg) == -ENODEV))
2201 GOTO(out, rc = lustre_msg_get_status(req->rq_repmsg));
2203 /* The transno had better not change over replay. */
2204 LASSERT(lustre_msg_get_transno(req->rq_reqmsg) ==
2205 lustre_msg_get_transno(req->rq_repmsg));
2207 DEBUG_REQ(D_HA, req, "got rep");
2209 /* let the callback do fixups, possibly including in the request */
2210 if (req->rq_replay_cb)
2211 req->rq_replay_cb(req);
2213 if (req->rq_replied &&
2214 lustre_msg_get_status(req->rq_repmsg) != aa->praa_old_status) {
2215 DEBUG_REQ(D_ERROR, req, "status %d, old was %d",
2216 lustre_msg_get_status(req->rq_repmsg),
2217 aa->praa_old_status);
2219 /* Put it back for re-replay. */
2220 lustre_msg_set_status(req->rq_repmsg, aa->praa_old_status);
2224 * Errors while replay can set transno to 0, but
2225 * imp_last_replay_transno shouldn't be set to 0 anyway
2227 if (req->rq_transno > 0) {
2228 spin_lock(&imp->imp_lock);
2229 LASSERT(req->rq_transno <= imp->imp_last_replay_transno);
2230 imp->imp_last_replay_transno = req->rq_transno;
2231 spin_unlock(&imp->imp_lock);
2233 CERROR("Transno is 0 during replay!\n");
2234 /* continue with recovery */
2235 rc = ptlrpc_import_recovery_state_machine(imp);
2237 req->rq_send_state = aa->praa_old_state;
2240 /* this replay failed, so restart recovery */
2241 ptlrpc_connect_import(imp, NULL);
2246 int ptlrpc_replay_req(struct ptlrpc_request *req)
2248 struct ptlrpc_replay_async_args *aa;
2251 LASSERT(req->rq_import->imp_state == LUSTRE_IMP_REPLAY);
2252 /* Not handling automatic bulk replay yet (or ever?) */
2253 LASSERT(req->rq_bulk == NULL);
2255 LASSERT (sizeof (*aa) <= sizeof (req->rq_async_args));
2256 aa = ptlrpc_req_async_args(req);
2257 memset(aa, 0, sizeof *aa);
2259 /* Prepare request to be resent with ptlrpcd */
2260 aa->praa_old_state = req->rq_send_state;
2261 req->rq_send_state = LUSTRE_IMP_REPLAY;
2262 req->rq_phase = RQ_PHASE_NEW;
2264 aa->praa_old_status = lustre_msg_get_status(req->rq_repmsg);
2266 req->rq_interpret_reply = ptlrpc_replay_interpret;
2267 /* Readjust the timeout for current conditions */
2268 ptlrpc_at_set_req_timeout(req);
2270 DEBUG_REQ(D_HA, req, "REPLAY");
2272 atomic_inc(&req->rq_import->imp_replay_inflight);
2273 ptlrpc_request_addref(req); /* ptlrpcd needs a ref */
2275 ptlrpcd_add_req(req);
2279 void ptlrpc_abort_inflight(struct obd_import *imp)
2281 struct list_head *tmp, *n;
2284 /* Make sure that no new requests get processed for this import.
2285 * ptlrpc_{queue,set}_wait must (and does) hold imp_lock while testing
2286 * this flag and then putting requests on sending_list or delayed_list.
2288 spin_lock(&imp->imp_lock);
2290 /* XXX locking? Maybe we should remove each request with the list
2291 * locked? Also, how do we know if the requests on the list are
2292 * being freed at this time?
2294 list_for_each_safe(tmp, n, &imp->imp_sending_list) {
2295 struct ptlrpc_request *req =
2296 list_entry(tmp, struct ptlrpc_request, rq_list);
2298 DEBUG_REQ(D_RPCTRACE, req, "inflight");
2300 spin_lock (&req->rq_lock);
2301 if (req->rq_import_generation < imp->imp_generation) {
2303 req->rq_status = -EINTR;
2304 ptlrpc_wake_client_req(req);
2306 spin_unlock (&req->rq_lock);
2309 list_for_each_safe(tmp, n, &imp->imp_delayed_list) {
2310 struct ptlrpc_request *req =
2311 list_entry(tmp, struct ptlrpc_request, rq_list);
2313 DEBUG_REQ(D_RPCTRACE, req, "aborting waiting req");
2315 spin_lock (&req->rq_lock);
2316 if (req->rq_import_generation < imp->imp_generation) {
2318 req->rq_status = -EINTR;
2319 ptlrpc_wake_client_req(req);
2321 spin_unlock (&req->rq_lock);
2324 /* Last chance to free reqs left on the replay list, but we
2325 * will still leak reqs that haven't committed. */
2326 if (imp->imp_replayable)
2327 ptlrpc_free_committed(imp);
2329 spin_unlock(&imp->imp_lock);
2334 static __u64 ptlrpc_last_xid = 0;
2335 spinlock_t ptlrpc_last_xid_lock;
2337 __u64 ptlrpc_next_xid(void)
2340 spin_lock(&ptlrpc_last_xid_lock);
2341 tmp = ++ptlrpc_last_xid;
2342 spin_unlock(&ptlrpc_last_xid_lock);
2346 __u64 ptlrpc_sample_next_xid(void)
2349 spin_lock(&ptlrpc_last_xid_lock);
2350 tmp = ptlrpc_last_xid + 1;
2351 spin_unlock(&ptlrpc_last_xid_lock);
2354 EXPORT_SYMBOL(ptlrpc_sample_next_xid);