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
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
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 (c) 2007, 2010, Oracle and/or its affiliates. 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.
36 /** \defgroup PtlRPC Portal RPC and networking module.
38 * PortalRPC is the layer used by rest of lustre code to achieve network
39 * communications: establish connections with corresponding export and import
40 * states, listen for a service, send and receive RPCs.
41 * PortalRPC also includes base recovery framework: packet resending and
42 * replaying, reconnections, pinger.
44 * PortalRPC utilizes LNet as its transport layer.
58 #if defined(__linux__)
59 #include <linux/lustre_net.h>
60 #elif defined(__APPLE__)
61 #include <darwin/lustre_net.h>
62 #elif defined(__WINNT__)
63 #include <winnt/lustre_net.h>
65 #error Unsupported operating system.
68 #include <libcfs/libcfs.h>
70 #include <lnet/lnet.h>
71 #include <lustre/lustre_idl.h>
72 #include <lustre_ha.h>
73 #include <lustre_sec.h>
74 #include <lustre_import.h>
75 #include <lprocfs_status.h>
76 #include <lu_object.h>
77 #include <lustre_req_layout.h>
79 #include <obd_support.h>
80 #include <lustre_ver.h>
82 /* MD flags we _always_ use */
83 #define PTLRPC_MD_OPTIONS 0
86 * Define maxima for bulk I/O
87 * CAVEAT EMPTOR, with multinet (i.e. routers forwarding between networks)
88 * these limits are system wide and not interface-local. */
89 #define PTLRPC_MAX_BRW_BITS LNET_MTU_BITS
90 #define PTLRPC_MAX_BRW_SIZE (1<<LNET_MTU_BITS)
91 #define PTLRPC_MAX_BRW_PAGES (PTLRPC_MAX_BRW_SIZE >> CFS_PAGE_SHIFT)
93 /* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
95 # if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
96 # error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
98 # if (PTLRPC_MAX_BRW_SIZE != (PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE))
99 # error "PTLRPC_MAX_BRW_SIZE isn't PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE"
101 # if (PTLRPC_MAX_BRW_SIZE > LNET_MTU)
102 # error "PTLRPC_MAX_BRW_SIZE too big"
104 # if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV)
105 # error "PTLRPC_MAX_BRW_PAGES too big"
107 #endif /* __KERNEL__ */
110 * The following constants determine how memory is used to buffer incoming
113 * ?_NBUFS # buffers to allocate when growing the pool
114 * ?_BUFSIZE # bytes in a single request buffer
115 * ?_MAXREQSIZE # maximum request service will receive
117 * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
118 * of ?_NBUFS is added to the pool.
120 * Messages larger than ?_MAXREQSIZE are dropped. Request buffers are
121 * considered full when less than ?_MAXREQSIZE is left in them.
123 #define LDLM_THREADS_AUTO_MIN (2)
124 #define LDLM_THREADS_AUTO_MAX min_t(unsigned, cfs_num_online_cpus() * \
125 cfs_num_online_cpus() * 32, 128)
126 #define LDLM_BL_THREADS LDLM_THREADS_AUTO_MIN
127 #define LDLM_NBUFS (64 * cfs_num_online_cpus())
128 #define LDLM_BUFSIZE (8 * 1024)
129 #define LDLM_MAXREQSIZE (5 * 1024)
130 #define LDLM_MAXREPSIZE (1024)
132 /** Absolute limits */
133 #define MDT_MIN_THREADS 2UL
134 #ifndef MDT_MAX_THREADS
135 #define MDT_MAX_THREADS 512UL
137 #define MDS_NBUFS (64 * cfs_num_online_cpus())
138 #define MDS_BUFSIZE (8 * 1024)
140 * Assume file name length = FNAME_MAX = 256 (true for ext3).
141 * path name length = PATH_MAX = 4096
142 * LOV MD size max = EA_MAX = 4000
143 * symlink: FNAME_MAX + PATH_MAX <- largest
144 * link: FNAME_MAX + PATH_MAX (mds_rec_link < mds_rec_create)
145 * rename: FNAME_MAX + FNAME_MAX
146 * open: FNAME_MAX + EA_MAX
148 * MDS_MAXREQSIZE ~= 4736 bytes =
149 * lustre_msg + ldlm_request + mds_body + mds_rec_create + FNAME_MAX + PATH_MAX
150 * MDS_MAXREPSIZE ~= 8300 bytes = lustre_msg + llog_header
151 * or, for mds_close() and mds_reint_unlink() on a many-OST filesystem:
152 * = 9210 bytes = lustre_msg + mds_body + 160 * (easize + cookiesize)
154 * Realistic size is about 512 bytes (20 character name + 128 char symlink),
155 * except in the open case where there are a large number of OSTs in a LOV.
157 #define MDS_MAXREQSIZE (5 * 1024)
158 #define MDS_MAXREPSIZE max(9 * 1024, 362 + LOV_MAX_STRIPE_COUNT * 56)
160 /** FLD_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + md_fld */
161 #define FLD_MAXREQSIZE (160)
163 /** FLD_MAXREPSIZE == lustre_msg + ptlrpc_body + md_fld */
164 #define FLD_MAXREPSIZE (152)
167 * SEQ_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + lu_range +
169 #define SEQ_MAXREQSIZE (160)
171 /** SEQ_MAXREPSIZE == lustre_msg + ptlrpc_body + lu_range */
172 #define SEQ_MAXREPSIZE (152)
174 /** MGS threads must be >= 3, see bug 22458 comment #28 */
175 #define MGS_THREADS_AUTO_MIN 3
176 #define MGS_THREADS_AUTO_MAX 32
177 #define MGS_NBUFS (64 * cfs_num_online_cpus())
178 #define MGS_BUFSIZE (8 * 1024)
179 #define MGS_MAXREQSIZE (7 * 1024)
180 #define MGS_MAXREPSIZE (9 * 1024)
182 /** Absolute OSS limits */
183 #define OSS_THREADS_MIN 3 /* difficult replies, HPQ, others */
184 #define OSS_THREADS_MAX 512
185 #define OST_NBUFS (64 * cfs_num_online_cpus())
186 #define OST_BUFSIZE (8 * 1024)
189 * OST_MAXREQSIZE ~= 4768 bytes =
190 * lustre_msg + obdo + 16 * obd_ioobj + 256 * niobuf_remote
192 * - single object with 16 pages is 512 bytes
193 * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
195 #define OST_MAXREQSIZE (5 * 1024)
196 #define OST_MAXREPSIZE (9 * 1024)
198 /* Macro to hide a typecast. */
199 #define ptlrpc_req_async_args(req) ((void *)&req->rq_async_args)
202 * Structure to single define portal connection.
204 struct ptlrpc_connection {
205 /** linkage for connections hash table */
206 cfs_hlist_node_t c_hash;
207 /** Our own lnet nid for this connection */
209 /** Remote side nid for this connection */
210 lnet_process_id_t c_peer;
211 /** UUID of the other side */
212 struct obd_uuid c_remote_uuid;
213 /** reference counter for this connection */
214 cfs_atomic_t c_refcount;
217 /** Client definition for PortalRPC */
218 struct ptlrpc_client {
219 /** What lnet portal does this client send messages to by default */
220 __u32 cli_request_portal;
221 /** What portal do we expect replies on */
222 __u32 cli_reply_portal;
223 /** Name of the client */
227 /** state flags of requests */
228 /* XXX only ones left are those used by the bulk descs as well! */
229 #define PTL_RPC_FL_INTR (1 << 0) /* reply wait was interrupted by user */
230 #define PTL_RPC_FL_TIMEOUT (1 << 7) /* request timed out waiting for reply */
232 #define REQ_MAX_ACK_LOCKS 8
234 union ptlrpc_async_args {
236 * Scratchpad for passing args to completion interpreter. Users
237 * cast to the struct of their choosing, and CLASSERT that this is
238 * big enough. For _tons_ of context, OBD_ALLOC a struct and store
239 * a pointer to it here. The pointer_arg ensures this struct is at
240 * least big enough for that.
242 void *pointer_arg[11];
246 struct ptlrpc_request_set;
247 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
250 * Definition of request set structure.
251 * Request set is a list of requests (not necessary to the same target) that
252 * once populated with RPCs could be sent in parallel.
253 * There are two kinds of request sets. General purpose and with dedicated
254 * serving thread. Example of the latter is ptlrpcd set.
255 * For general purpose sets once request set started sending it is impossible
256 * to add new requests to such set.
257 * Provides a way to call "completion callbacks" when all requests in the set
260 struct ptlrpc_request_set {
261 /** number of uncompleted requests */
262 cfs_atomic_t set_remaining;
263 /** wait queue to wait on for request events */
264 cfs_waitq_t set_waitq;
265 cfs_waitq_t *set_wakeup_ptr;
266 /** List of requests in the set */
267 cfs_list_t set_requests;
269 * List of completion callbacks to be called when the set is completed
270 * This is only used if \a set_interpret is NULL.
271 * Links struct ptlrpc_set_cbdata.
273 cfs_list_t set_cblist;
274 /** Completion callback, if only one. */
275 set_interpreter_func set_interpret;
276 /** opaq argument passed to completion \a set_interpret callback. */
279 * Lock for \a set_new_requests manipulations
280 * locked so that any old caller can communicate requests to
281 * the set holder who can then fold them into the lock-free set
283 cfs_spinlock_t set_new_req_lock;
284 /** List of new yet unsent requests. Only used with ptlrpcd now. */
285 cfs_list_t set_new_requests;
289 * Description of a single ptrlrpc_set callback
291 struct ptlrpc_set_cbdata {
292 /** List linkage item */
294 /** Pointer to interpreting function */
295 set_interpreter_func psc_interpret;
296 /** Opaq argument to pass to the callback */
300 struct ptlrpc_bulk_desc;
303 * ptlrpc callback & work item stuff
305 struct ptlrpc_cb_id {
306 void (*cbid_fn)(lnet_event_t *ev); /* specific callback fn */
307 void *cbid_arg; /* additional arg */
310 /** Maximum number of locks to fit into reply state */
311 #define RS_MAX_LOCKS 8
315 * Structure to define reply state on the server
316 * Reply state holds various reply message information. Also for "difficult"
317 * replies (rep-ack case) we store the state after sending reply and wait
318 * for the client to acknowledge the reception. In these cases locks could be
319 * added to the state for replay/failover consistency guarantees.
321 struct ptlrpc_reply_state {
322 /** Callback description */
323 struct ptlrpc_cb_id rs_cb_id;
324 /** Linkage for list of all reply states in a system */
326 /** Linkage for list of all reply states on same export */
327 cfs_list_t rs_exp_list;
328 /** Linkage for list of all reply states for same obd */
329 cfs_list_t rs_obd_list;
331 cfs_list_t rs_debug_list;
333 /** A spinlock to protect the reply state flags */
334 cfs_spinlock_t rs_lock;
335 /** Reply state flags */
336 unsigned long rs_difficult:1; /* ACK/commit stuff */
337 unsigned long rs_no_ack:1; /* no ACK, even for
338 difficult requests */
339 unsigned long rs_scheduled:1; /* being handled? */
340 unsigned long rs_scheduled_ever:1;/* any schedule attempts? */
341 unsigned long rs_handled:1; /* been handled yet? */
342 unsigned long rs_on_net:1; /* reply_out_callback pending? */
343 unsigned long rs_prealloc:1; /* rs from prealloc list */
344 unsigned long rs_committed:1;/* the transaction was committed
345 and the rs was dispatched
346 by ptlrpc_commit_replies */
347 /** Size of the state */
351 /** Transaction number */
355 struct obd_export *rs_export;
356 struct ptlrpc_service *rs_service;
357 /** Lnet metadata handle for the reply */
358 lnet_handle_md_t rs_md_h;
359 cfs_atomic_t rs_refcount;
361 /** Context for the sevice thread */
362 struct ptlrpc_svc_ctx *rs_svc_ctx;
363 /** Reply buffer (actually sent to the client), encoded if needed */
364 struct lustre_msg *rs_repbuf; /* wrapper */
365 /** Size of the reply buffer */
366 int rs_repbuf_len; /* wrapper buf length */
367 /** Size of the reply message */
368 int rs_repdata_len; /* wrapper msg length */
370 * Actual reply message. Its content is encrupted (if needed) to
371 * produce reply buffer for actual sending. In simple case
372 * of no network encryption we jus set \a rs_repbuf to \a rs_msg
374 struct lustre_msg *rs_msg; /* reply message */
376 /** Number of locks awaiting client ACK */
378 /** Handles of locks awaiting client reply ACK */
379 struct lustre_handle rs_locks[RS_MAX_LOCKS];
380 /** Lock modes of locks in \a rs_locks */
381 ldlm_mode_t rs_modes[RS_MAX_LOCKS];
384 struct ptlrpc_thread;
388 RQ_PHASE_NEW = 0xebc0de00,
389 RQ_PHASE_RPC = 0xebc0de01,
390 RQ_PHASE_BULK = 0xebc0de02,
391 RQ_PHASE_INTERPRET = 0xebc0de03,
392 RQ_PHASE_COMPLETE = 0xebc0de04,
393 RQ_PHASE_UNREGISTERING = 0xebc0de05,
394 RQ_PHASE_UNDEFINED = 0xebc0de06
397 /** Type of request interpreter call-back */
398 typedef int (*ptlrpc_interpterer_t)(const struct lu_env *env,
399 struct ptlrpc_request *req,
403 * Definition of request pool structure.
404 * The pool is used to store empty preallocated requests for the case
405 * when we would actually need to send something without performing
406 * any allocations (to avoid e.g. OOM).
408 struct ptlrpc_request_pool {
409 /** Locks the list */
410 cfs_spinlock_t prp_lock;
411 /** list of ptlrpc_request structs */
412 cfs_list_t prp_req_list;
413 /** Maximum message size that would fit into a rquest from this pool */
415 /** Function to allocate more requests for this pool */
416 void (*prp_populate)(struct ptlrpc_request_pool *, int);
425 * Basic request prioritization operations structure.
426 * The whole idea is centered around locks and RPCs that might affect locks.
427 * When a lock is contended we try to give priority to RPCs that might lead
428 * to fastest release of that lock.
429 * Currently only implemented for OSTs only in a way that makes all
430 * IO and truncate RPCs that are coming from a locked region where a lock is
431 * contended a priority over other requests.
433 struct ptlrpc_hpreq_ops {
435 * Check if the lock handle of the given lock is the same as
436 * taken from the request.
438 int (*hpreq_lock_match)(struct ptlrpc_request *, struct ldlm_lock *);
440 * Check if the request is a high priority one.
442 int (*hpreq_check)(struct ptlrpc_request *);
444 * Called after the request has been handled.
446 void (*hpreq_fini)(struct ptlrpc_request *);
450 * Represents remote procedure call.
452 * This is a staple structure used by everybody wanting to send a request
455 struct ptlrpc_request {
456 /* Request type: one of PTL_RPC_MSG_* */
459 * Linkage item through which this request is included into
460 * sending/delayed lists on client and into rqbd list on server
464 * Server side list of incoming unserved requests sorted by arrival
465 * time. Traversed from time to time to notice about to expire
466 * requests and sent back "early replies" to clients to let them
467 * know server is alive and well, just very busy to service their
470 cfs_list_t rq_timed_list;
471 /** server-side history, used for debuging purposes. */
472 cfs_list_t rq_history_list;
473 /** server-side per-export list */
474 cfs_list_t rq_exp_list;
475 /** server-side hp handlers */
476 struct ptlrpc_hpreq_ops *rq_ops;
477 /** history sequence # */
478 __u64 rq_history_seq;
479 /** the index of service's srv_at_array into which request is linked */
481 /** Result of request processing */
483 /** Lock to protect request flags and some other important bits, like
486 cfs_spinlock_t rq_lock;
487 /** client-side flags are serialized by rq_lock */
488 unsigned long rq_intr:1, rq_replied:1, rq_err:1,
489 rq_timedout:1, rq_resend:1, rq_restart:1,
491 * when ->rq_replay is set, request is kept by the client even
492 * after server commits corresponding transaction. This is
493 * used for operations that require sequence of multiple
494 * requests to be replayed. The only example currently is file
495 * open/close. When last request in such a sequence is
496 * committed, ->rq_replay is cleared on all requests in the
500 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
501 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
502 rq_early:1, rq_must_unlink:1,
503 rq_fake:1, /* this fake req */
504 rq_memalloc:1, /* req originated from "kswapd" */
505 /* server-side flags */
506 rq_packed_final:1, /* packed final reply */
507 rq_hp:1, /* high priority RPC */
508 rq_at_linked:1, /* link into service's srv_at_array */
511 /* whether the "rq_set" is a valid one */
514 enum rq_phase rq_phase; /* one of RQ_PHASE_* */
515 enum rq_phase rq_next_phase; /* one of RQ_PHASE_* to be used next */
516 cfs_atomic_t rq_refcount;/* client-side refcount for SENT race,
517 server-side refcounf for multiple replies */
519 /** initial thread servicing this request */
520 struct ptlrpc_thread *rq_svc_thread;
522 /** Portal to which this request would be sent */
523 int rq_request_portal; /* XXX FIXME bug 249 */
524 /** Portal where to wait for reply and where reply would be sent */
525 int rq_reply_portal; /* XXX FIXME bug 249 */
529 * !rq_truncate : # reply bytes actually received,
530 * rq_truncate : required repbuf_len for resend
533 /** Request length */
535 /** Request message - what client sent */
536 struct lustre_msg *rq_reqmsg;
540 /** Reply message - server response */
541 struct lustre_msg *rq_repmsg;
542 /** Transaction number */
547 * List item to for replay list. Not yet commited requests get linked
549 * Also see \a rq_replay comment above.
551 cfs_list_t rq_replay_list;
554 * security and encryption data
556 struct ptlrpc_cli_ctx *rq_cli_ctx; /**< client's half ctx */
557 struct ptlrpc_svc_ctx *rq_svc_ctx; /**< server's half ctx */
558 cfs_list_t rq_ctx_chain; /**< link to waited ctx */
560 struct sptlrpc_flavor rq_flvr; /**< for client & server */
561 enum lustre_sec_part rq_sp_from;
563 unsigned long /* client/server security flags */
564 rq_ctx_init:1, /* context initiation */
565 rq_ctx_fini:1, /* context destroy */
566 rq_bulk_read:1, /* request bulk read */
567 rq_bulk_write:1, /* request bulk write */
568 /* server authentication flags */
569 rq_auth_gss:1, /* authenticated by gss */
570 rq_auth_remote:1, /* authed as remote user */
571 rq_auth_usr_root:1, /* authed as root */
572 rq_auth_usr_mdt:1, /* authed as mdt */
573 rq_auth_usr_ost:1, /* authed as ost */
574 /* security tfm flags */
577 /* doesn't expect reply FIXME */
579 rq_pill_init:1; /* pill initialized */
581 uid_t rq_auth_uid; /* authed uid */
582 uid_t rq_auth_mapped_uid; /* authed uid mapped to */
584 /* (server side), pointed directly into req buffer */
585 struct ptlrpc_user_desc *rq_user_desc;
587 /** early replies go to offset 0, regular replies go after that */
588 unsigned int rq_reply_off;
590 /* various buffer pointers */
591 struct lustre_msg *rq_reqbuf; /* req wrapper */
592 int rq_reqbuf_len; /* req wrapper buf len */
593 int rq_reqdata_len; /* req wrapper msg len */
594 char *rq_repbuf; /* rep buffer */
595 int rq_repbuf_len; /* rep buffer len */
596 struct lustre_msg *rq_repdata; /* rep wrapper msg */
597 int rq_repdata_len; /* rep wrapper msg len */
598 struct lustre_msg *rq_clrbuf; /* only in priv mode */
599 int rq_clrbuf_len; /* only in priv mode */
600 int rq_clrdata_len; /* only in priv mode */
604 /** Fields that help to see if request and reply were swabbed or not */
605 __u32 rq_req_swab_mask;
606 __u32 rq_rep_swab_mask;
608 /** What was import generation when this request was sent */
609 int rq_import_generation;
610 enum lustre_imp_state rq_send_state;
612 /** how many early replies (for stats) */
615 /** client+server request */
616 lnet_handle_md_t rq_req_md_h;
617 struct ptlrpc_cb_id rq_req_cbid;
618 /** optional time limit for send attempts */
619 cfs_duration_t rq_delay_limit;
620 /** time request was first queued */
621 cfs_time_t rq_queued_time;
624 /** request arrival time */
625 struct timeval rq_arrival_time;
626 /** separated reply state */
627 struct ptlrpc_reply_state *rq_reply_state;
628 /** incoming request buffer */
629 struct ptlrpc_request_buffer_desc *rq_rqbd;
631 __u32 rq_uid; /* peer uid, used in MDS only */
634 /** client-only incoming reply */
635 lnet_handle_md_t rq_reply_md_h;
636 cfs_waitq_t rq_reply_waitq;
637 struct ptlrpc_cb_id rq_reply_cbid;
641 /** Peer description (the other side) */
642 lnet_process_id_t rq_peer;
643 /** Server-side, export on which request was received */
644 struct obd_export *rq_export;
645 /** Client side, import where request is being sent */
646 struct obd_import *rq_import;
648 /** Replay callback, called after request is replayed at recovery */
649 void (*rq_replay_cb)(struct ptlrpc_request *);
651 * Commit callback, called when request is committed and about to be
654 void (*rq_commit_cb)(struct ptlrpc_request *);
655 /** Opaq data for replay and commit callbacks. */
658 /** For bulk requests on client only: bulk descriptor */
659 struct ptlrpc_bulk_desc *rq_bulk;
661 /** client outgoing req */
663 * when request/reply sent (secs), or time when request should be sent
666 /** time for request really sent out */
669 /** when request must finish. volatile
670 * so that servers' early reply updates to the deadline aren't
671 * kept in per-cpu cache */
672 volatile time_t rq_deadline;
673 /** when req reply unlink must finish. */
674 time_t rq_reply_deadline;
675 /** when req bulk unlink must finish. */
676 time_t rq_bulk_deadline;
678 * service time estimate (secs)
679 * If the requestsis not served by this time, it is marked as timed out.
683 /** Multi-rpc bits */
684 /** Link item for request set lists */
685 cfs_list_t rq_set_chain;
686 /** Per-request waitq introduced by bug 21938 for recovery waiting */
687 cfs_waitq_t rq_set_waitq;
688 /** Link back to the request set */
689 struct ptlrpc_request_set *rq_set;
690 /** Async completion handler, called when reply is received */
691 ptlrpc_interpterer_t rq_interpret_reply;
692 /** Async completion context */
693 union ptlrpc_async_args rq_async_args;
695 /** Pool if request is from preallocated list */
696 struct ptlrpc_request_pool *rq_pool;
698 struct lu_context rq_session;
699 struct lu_context rq_recov_session;
701 /** request format description */
702 struct req_capsule rq_pill;
706 * Call completion handler for rpc if any, return it's status or original
707 * rc if there was no handler defined for this request.
709 static inline int ptlrpc_req_interpret(const struct lu_env *env,
710 struct ptlrpc_request *req, int rc)
712 if (req->rq_interpret_reply != NULL) {
713 req->rq_status = req->rq_interpret_reply(env, req,
716 return req->rq_status;
722 * Returns 1 if request buffer at offset \a index was already swabbed
724 static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
726 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
727 return req->rq_req_swab_mask & (1 << index);
731 * Returns 1 if request reply buffer at offset \a index was already swabbed
733 static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
735 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
736 return req->rq_rep_swab_mask & (1 << index);
740 * Returns 1 if request needs to be swabbed into local cpu byteorder
742 static inline int ptlrpc_req_need_swab(struct ptlrpc_request *req)
744 return lustre_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
748 * Returns 1 if request reply needs to be swabbed into local cpu byteorder
750 static inline int ptlrpc_rep_need_swab(struct ptlrpc_request *req)
752 return lustre_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
756 * Mark request buffer at offset \a index that it was already swabbed
758 static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
760 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
761 LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
762 req->rq_req_swab_mask |= 1 << index;
766 * Mark request reply buffer at offset \a index that it was already swabbed
768 static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
770 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
771 LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
772 req->rq_rep_swab_mask |= 1 << index;
776 * Convert numerical request phase value \a phase into text string description
778 static inline const char *
779 ptlrpc_phase2str(enum rq_phase phase)
788 case RQ_PHASE_INTERPRET:
790 case RQ_PHASE_COMPLETE:
792 case RQ_PHASE_UNREGISTERING:
793 return "Unregistering";
800 * Convert numerical request phase of the request \a req into text stringi
803 static inline const char *
804 ptlrpc_rqphase2str(struct ptlrpc_request *req)
806 return ptlrpc_phase2str(req->rq_phase);
810 * Debugging functions and helpers to print request structure into debug log
813 /* Spare the preprocessor, spoil the bugs. */
814 #define FLAG(field, str) (field ? str : "")
816 /** Convert bit flags into a string */
817 #define DEBUG_REQ_FLAGS(req) \
818 ptlrpc_rqphase2str(req), \
819 FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"), \
820 FLAG(req->rq_err, "E"), \
821 FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"), \
822 FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"), \
823 FLAG(req->rq_no_resend, "N"), \
824 FLAG(req->rq_waiting, "W"), \
825 FLAG(req->rq_wait_ctx, "C"), FLAG(req->rq_hp, "H"), \
826 FLAG(req->rq_committed, "M")
828 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s%s%s"
830 void _debug_req(struct ptlrpc_request *req, __u32 mask,
831 struct libcfs_debug_msg_data *data, const char *fmt, ...)
832 __attribute__ ((format (printf, 4, 5)));
835 * Helper that decides if we need to print request accordig to current debug
838 #define debug_req(cdls, level, req, file, func, line, fmt, a...) \
842 if (((level) & D_CANTMASK) != 0 || \
843 ((libcfs_debug & (level)) != 0 && \
844 (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) { \
845 static struct libcfs_debug_msg_data _req_dbg_data = \
846 DEBUG_MSG_DATA_INIT(cdls, DEBUG_SUBSYSTEM, file, func, line); \
847 _debug_req((req), (level), &_req_dbg_data, fmt, ##a); \
852 * This is the debug print function you need to use to print request sturucture
853 * content into lustre debug log.
854 * for most callers (level is a constant) this is resolved at compile time */
855 #define DEBUG_REQ(level, req, fmt, args...) \
857 if ((level) & (D_ERROR | D_WARNING)) { \
858 static cfs_debug_limit_state_t cdls; \
859 debug_req(&cdls, level, req, __FILE__, __func__, __LINE__, \
860 "@@@ "fmt" ", ## args); \
862 debug_req(NULL, level, req, __FILE__, __func__, __LINE__, \
863 "@@@ "fmt" ", ## args); \
868 * Structure that defines a single page of a bulk transfer
870 struct ptlrpc_bulk_page {
871 /** Linkage to list of pages in a bulk */
874 * Number of bytes in a page to transfer starting from \a bp_pageoffset
877 /** offset within a page */
879 /** The page itself */
880 struct page *bp_page;
883 #define BULK_GET_SOURCE 0
884 #define BULK_PUT_SINK 1
885 #define BULK_GET_SINK 2
886 #define BULK_PUT_SOURCE 3
889 * Definition of buk descriptor.
890 * Bulks are special "Two phase" RPCs where initial request message
891 * is sent first and it is followed bt a transfer (o receiving) of a large
892 * amount of data to be settled into pages referenced from the bulk descriptors.
893 * Bulks transfers (the actual data following the small requests) are done
894 * on separate LNet portals.
895 * In lustre we use bulk transfers for READ and WRITE transfers from/to OSTs.
896 * Another user is readpage for MDT.
898 struct ptlrpc_bulk_desc {
899 /** completed successfully */
900 unsigned long bd_success:1;
901 /** accessible to the network (network io potentially in progress) */
902 unsigned long bd_network_rw:1;
903 /** {put,get}{source,sink} */
904 unsigned long bd_type:2;
906 unsigned long bd_registered:1;
907 /** For serialization with callback */
908 cfs_spinlock_t bd_lock;
909 /** Import generation when request for this bulk was sent */
910 int bd_import_generation;
911 /** Server side - export this bulk created for */
912 struct obd_export *bd_export;
913 /** Client side - import this bulk was sent on */
914 struct obd_import *bd_import;
915 /** LNet portal for this bulk */
917 /** Back pointer to the request */
918 struct ptlrpc_request *bd_req;
919 cfs_waitq_t bd_waitq; /* server side only WQ */
920 int bd_iov_count; /* # entries in bd_iov */
921 int bd_max_iov; /* allocated size of bd_iov */
922 int bd_nob; /* # bytes covered */
923 int bd_nob_transferred; /* # bytes GOT/PUT */
927 struct ptlrpc_cb_id bd_cbid; /* network callback info */
928 lnet_handle_md_t bd_md_h; /* associated MD */
929 lnet_nid_t bd_sender; /* stash event::sender */
931 #if defined(__KERNEL__)
933 * encrypt iov, size is either 0 or bd_iov_count.
935 lnet_kiov_t *bd_enc_iov;
937 lnet_kiov_t bd_iov[0];
939 lnet_md_iovec_t bd_iov[0];
944 SVC_STOPPED = 1 << 0,
945 SVC_STOPPING = 1 << 1,
946 SVC_STARTING = 1 << 2,
947 SVC_RUNNING = 1 << 3,
953 * Definition of server service thread structure
955 struct ptlrpc_thread {
957 * List of active threads in svc->srv_threads
961 * thread-private data (preallocated memory)
966 * service thread index, from ptlrpc_start_threads
974 * put watchdog in the structure per thread b=14840
976 struct lc_watchdog *t_watchdog;
978 * the svc this thread belonged to b=18582
980 struct ptlrpc_service *t_svc;
981 cfs_waitq_t t_ctl_waitq;
982 struct lu_env *t_env;
986 * Request buffer descriptor structure.
987 * This is a structure that contains one posted request buffer for service.
988 * Once data land into a buffer, event callback creates actual request and
989 * notifies wakes one of the service threads to process new incoming request.
990 * More than one request can fit into the buffer.
992 struct ptlrpc_request_buffer_desc {
993 /** Link item for rqbds on a service */
994 cfs_list_t rqbd_list;
995 /** History of requests for this buffer */
996 cfs_list_t rqbd_reqs;
997 /** Back pointer to service for which this buffer is registered */
998 struct ptlrpc_service *rqbd_service;
999 /** LNet descriptor */
1000 lnet_handle_md_t rqbd_md_h;
1002 /** The buffer itself */
1004 struct ptlrpc_cb_id rqbd_cbid;
1006 * This "embedded" request structure is only used for the
1007 * last request to fit into the buffer
1009 struct ptlrpc_request rqbd_req;
1012 typedef int (*svc_thr_init_t)(struct ptlrpc_thread *thread);
1013 typedef void (*svc_thr_done_t)(struct ptlrpc_thread *thread);
1014 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
1015 typedef int (*svc_hpreq_handler_t)(struct ptlrpc_request *);
1016 typedef void (*svc_req_printfn_t)(void *, struct ptlrpc_request *);
1018 #ifndef __cfs_cacheline_aligned
1019 /* NB: put it here for reducing patche dependence */
1020 # define __cfs_cacheline_aligned
1024 * How many high priority requests to serve before serving one normal
1027 #define PTLRPC_SVC_HP_RATIO 10
1030 * Definition of PortalRPC service.
1031 * The service is listening on a particular portal (like tcp port)
1032 * and perform actions for a specific server like IO service for OST
1033 * or general metadata service for MDS.
1035 * ptlrpc service has four locks:
1037 * serialize operations on rqbd and requests waiting for preprocess
1039 * serialize operations active requests sent to this portal
1041 * serialize adaptive timeout stuff
1043 * serialize operations on RS list (reply states)
1045 * We don't have any use-case to take two or more locks at the same time
1046 * for now, so there is no lock order issue.
1048 struct ptlrpc_service {
1049 /** most often accessed fields */
1050 /** chain thru all services */
1051 cfs_list_t srv_list;
1052 /** only statically allocated strings here; we don't clean them */
1054 /** only statically allocated strings here; we don't clean them */
1055 char *srv_thread_name;
1056 /** service thread list */
1057 cfs_list_t srv_threads;
1058 /** threads to start at beginning of service */
1059 int srv_threads_min;
1060 /** thread upper limit */
1061 int srv_threads_max;
1062 /** always increasing number */
1063 unsigned srv_threads_next_id;
1064 /** # of starting threads */
1065 int srv_threads_starting;
1066 /** # running threads */
1067 int srv_threads_running;
1069 /** service operations, move to ptlrpc_svc_ops_t in the future */
1072 * if non-NULL called during thread creation (ptlrpc_start_thread())
1073 * to initialize service specific per-thread state.
1075 svc_thr_init_t srv_init;
1077 * if non-NULL called during thread shutdown (ptlrpc_main()) to
1078 * destruct state created by ->srv_init().
1080 svc_thr_done_t srv_done;
1081 /** Handler function for incoming requests for this service */
1082 svc_handler_t srv_handler;
1083 /** hp request handler */
1084 svc_hpreq_handler_t srv_hpreq_handler;
1085 /** service-specific print fn */
1086 svc_req_printfn_t srv_req_printfn;
1089 /** Root of /proc dir tree for this service */
1090 cfs_proc_dir_entry_t *srv_procroot;
1091 /** Pointer to statistic data for this service */
1092 struct lprocfs_stats *srv_stats;
1093 /** # hp per lp reqs to handle */
1094 int srv_hpreq_ratio;
1095 /** biggest request to receive */
1096 int srv_max_req_size;
1097 /** biggest reply to send */
1098 int srv_max_reply_size;
1099 /** size of individual buffers */
1101 /** # buffers to allocate in 1 group */
1102 int srv_nbuf_per_group;
1103 /** Local portal on which to receive requests */
1104 __u32 srv_req_portal;
1105 /** Portal on the client to send replies to */
1106 __u32 srv_rep_portal;
1108 * Tags for lu_context associated with this thread, see struct
1112 /** soft watchdog timeout multiplier */
1113 int srv_watchdog_factor;
1114 /** bind threads to CPUs */
1115 unsigned srv_cpu_affinity:1;
1116 /** under unregister_service */
1117 unsigned srv_is_stopping:1;
1120 * serialize the following fields, used for protecting
1121 * rqbd list and incoming requests waiting for preprocess
1123 cfs_spinlock_t srv_lock __cfs_cacheline_aligned;
1124 /** incoming reqs */
1125 cfs_list_t srv_req_in_queue;
1126 /** total # req buffer descs allocated */
1128 /** # posted request buffers */
1129 int srv_nrqbd_receiving;
1130 /** timeout before re-posting reqs, in tick */
1131 cfs_duration_t srv_rqbd_timeout;
1132 /** request buffers to be reposted */
1133 cfs_list_t srv_idle_rqbds;
1134 /** req buffers receiving */
1135 cfs_list_t srv_active_rqbds;
1136 /** request buffer history */
1137 cfs_list_t srv_history_rqbds;
1138 /** # request buffers in history */
1139 int srv_n_history_rqbds;
1140 /** max # request buffers in history */
1141 int srv_max_history_rqbds;
1142 /** request history */
1143 cfs_list_t srv_request_history;
1144 /** next request sequence # */
1145 __u64 srv_request_seq;
1146 /** highest seq culled from history */
1147 __u64 srv_request_max_cull_seq;
1149 * all threads sleep on this. This wait-queue is signalled when new
1150 * incoming request arrives and when difficult reply has to be handled.
1152 cfs_waitq_t srv_waitq;
1155 * serialize the following fields, used for processing requests
1156 * sent to this portal
1158 cfs_spinlock_t srv_rq_lock __cfs_cacheline_aligned;
1159 /** # reqs in either of the queues below */
1160 /** reqs waiting for service */
1161 cfs_list_t srv_request_queue;
1162 /** high priority queue */
1163 cfs_list_t srv_request_hpq;
1164 /** # incoming reqs */
1165 int srv_n_queued_reqs;
1166 /** # reqs being served */
1167 int srv_n_active_reqs;
1168 /** # HPreqs being served */
1169 int srv_n_active_hpreq;
1170 /** # hp requests handled */
1171 int srv_hpreq_count;
1176 * serialize the following fields, used for changes on
1179 cfs_spinlock_t srv_at_lock __cfs_cacheline_aligned;
1180 /** estimated rpc service time */
1181 struct adaptive_timeout srv_at_estimate;
1182 /** reqs waiting for replies */
1183 struct ptlrpc_at_array srv_at_array;
1184 /** early reply timer */
1185 cfs_timer_t srv_at_timer;
1186 /** check early replies */
1187 unsigned srv_at_check;
1189 cfs_time_t srv_at_checktime;
1193 * serialize the following fields, used for processing
1194 * replies for this portal
1196 cfs_spinlock_t srv_rs_lock __cfs_cacheline_aligned;
1197 /** all the active replies */
1198 cfs_list_t srv_active_replies;
1200 /** replies waiting for service */
1201 cfs_list_t srv_reply_queue;
1203 /** List of free reply_states */
1204 cfs_list_t srv_free_rs_list;
1205 /** waitq to run, when adding stuff to srv_free_rs_list */
1206 cfs_waitq_t srv_free_rs_waitq;
1207 /** # 'difficult' replies */
1208 cfs_atomic_t srv_n_difficult_replies;
1209 //struct ptlrpc_srv_ni srv_interfaces[0];
1213 * Declaration of ptlrpcd control structure
1215 struct ptlrpcd_ctl {
1217 * Ptlrpc thread control flags (LIOD_START, LIOD_STOP, LIOD_FORCE)
1219 unsigned long pc_flags;
1221 * Thread lock protecting structure fields.
1223 cfs_spinlock_t pc_lock;
1227 cfs_completion_t pc_starting;
1231 cfs_completion_t pc_finishing;
1233 * Thread requests set.
1235 struct ptlrpc_request_set *pc_set;
1237 * Thread name used in cfs_daemonize()
1241 * Environment for request interpreters to run in.
1243 struct lu_env pc_env;
1246 * Async rpcs flag to make sure that ptlrpcd_check() is called only
1251 * Currently not used.
1255 * User-space async rpcs callback.
1257 void *pc_wait_callback;
1259 * User-space check idle rpcs callback.
1261 void *pc_idle_callback;
1265 /* Bits for pc_flags */
1266 enum ptlrpcd_ctl_flags {
1268 * Ptlrpc thread start flag.
1270 LIOD_START = 1 << 0,
1272 * Ptlrpc thread stop flag.
1276 * Ptlrpc thread force flag (only stop force so far).
1277 * This will cause aborting any inflight rpcs handled
1278 * by thread if LIOD_STOP is specified.
1280 LIOD_FORCE = 1 << 2,
1282 * This is a recovery ptlrpc thread.
1284 LIOD_RECOVERY = 1 << 3
1287 /* ptlrpc/events.c */
1288 extern lnet_handle_eq_t ptlrpc_eq_h;
1289 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
1290 lnet_process_id_t *peer, lnet_nid_t *self);
1292 * These callbacks are invoked by LNet when something happened to
1296 extern void request_out_callback (lnet_event_t *ev);
1297 extern void reply_in_callback(lnet_event_t *ev);
1298 extern void client_bulk_callback (lnet_event_t *ev);
1299 extern void request_in_callback(lnet_event_t *ev);
1300 extern void reply_out_callback(lnet_event_t *ev);
1301 extern void server_bulk_callback (lnet_event_t *ev);
1304 /* ptlrpc/connection.c */
1305 struct ptlrpc_connection *ptlrpc_connection_get(lnet_process_id_t peer,
1307 struct obd_uuid *uuid);
1308 int ptlrpc_connection_put(struct ptlrpc_connection *c);
1309 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
1310 int ptlrpc_connection_init(void);
1311 void ptlrpc_connection_fini(void);
1312 extern lnet_pid_t ptl_get_pid(void);
1314 /* ptlrpc/niobuf.c */
1316 * Actual interfacing with LNet to put/get/register/unregister stuff
1319 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
1320 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
1321 int ptlrpc_register_bulk(struct ptlrpc_request *req);
1322 int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async);
1324 static inline int ptlrpc_server_bulk_active(struct ptlrpc_bulk_desc *desc)
1328 LASSERT(desc != NULL);
1330 cfs_spin_lock(&desc->bd_lock);
1331 rc = desc->bd_network_rw;
1332 cfs_spin_unlock(&desc->bd_lock);
1336 static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req)
1338 struct ptlrpc_bulk_desc *desc = req->rq_bulk;
1341 LASSERT(req != NULL);
1343 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) &&
1344 req->rq_bulk_deadline > cfs_time_current_sec())
1350 cfs_spin_lock(&desc->bd_lock);
1351 rc = desc->bd_network_rw;
1352 cfs_spin_unlock(&desc->bd_lock);
1356 #define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
1357 #define PTLRPC_REPLY_EARLY 0x02
1358 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
1359 int ptlrpc_reply(struct ptlrpc_request *req);
1360 int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
1361 int ptlrpc_error(struct ptlrpc_request *req);
1362 void ptlrpc_resend_req(struct ptlrpc_request *request);
1363 int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
1364 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
1365 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
1368 /* ptlrpc/client.c */
1370 * Client-side portals API. Everything to send requests, receive replies,
1371 * request queues, request management, etc.
1374 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
1375 struct ptlrpc_client *);
1376 void ptlrpc_cleanup_client(struct obd_import *imp);
1377 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
1379 int ptlrpc_queue_wait(struct ptlrpc_request *req);
1380 int ptlrpc_replay_req(struct ptlrpc_request *req);
1381 int ptlrpc_unregister_reply(struct ptlrpc_request *req, int async);
1382 void ptlrpc_restart_req(struct ptlrpc_request *req);
1383 void ptlrpc_abort_inflight(struct obd_import *imp);
1384 void ptlrpc_cleanup_imp(struct obd_import *imp);
1385 void ptlrpc_abort_set(struct ptlrpc_request_set *set);
1387 struct ptlrpc_request_set *ptlrpc_prep_set(void);
1388 int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
1389 set_interpreter_func fn, void *data);
1390 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
1391 int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set);
1392 int ptlrpc_set_wait(struct ptlrpc_request_set *);
1393 int ptlrpc_expired_set(void *data);
1394 void ptlrpc_interrupted_set(void *data);
1395 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
1396 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
1397 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
1398 int ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
1399 struct ptlrpc_request *req);
1401 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
1402 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
1404 struct ptlrpc_request_pool *
1405 ptlrpc_init_rq_pool(int, int,
1406 void (*populate_pool)(struct ptlrpc_request_pool *, int));
1408 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
1409 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
1410 const struct req_format *format);
1411 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
1412 struct ptlrpc_request_pool *,
1413 const struct req_format *format);
1414 void ptlrpc_request_free(struct ptlrpc_request *request);
1415 int ptlrpc_request_pack(struct ptlrpc_request *request,
1416 __u32 version, int opcode);
1417 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
1418 const struct req_format *format,
1419 __u32 version, int opcode);
1420 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
1421 __u32 version, int opcode, char **bufs,
1422 struct ptlrpc_cli_ctx *ctx);
1423 struct ptlrpc_request *ptlrpc_prep_fakereq(struct obd_import *imp,
1424 unsigned int timeout,
1425 ptlrpc_interpterer_t interpreter);
1426 void ptlrpc_fakereq_finished(struct ptlrpc_request *req);
1428 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
1429 int opcode, int count, __u32 *lengths,
1431 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
1432 __u32 version, int opcode,
1433 int count, __u32 *lengths, char **bufs,
1434 struct ptlrpc_request_pool *pool);
1435 void ptlrpc_req_finished(struct ptlrpc_request *request);
1436 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
1437 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
1438 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
1439 int npages, int type, int portal);
1440 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
1441 int npages, int type, int portal);
1442 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
1443 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
1444 cfs_page_t *page, int pageoffset, int len);
1445 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
1446 struct obd_import *imp);
1447 __u64 ptlrpc_next_xid(void);
1448 __u64 ptlrpc_sample_next_xid(void);
1449 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
1453 struct ptlrpc_service_conf {
1456 int psc_max_req_size;
1457 int psc_max_reply_size;
1460 int psc_watchdog_factor;
1461 int psc_min_threads;
1462 int psc_max_threads;
1466 /* ptlrpc/service.c */
1468 * Server-side services API. Register/unregister service, request state
1469 * management, service thread management
1473 void ptlrpc_save_lock (struct ptlrpc_request *req,
1474 struct lustre_handle *lock, int mode, int no_ack);
1475 void ptlrpc_commit_replies(struct obd_export *exp);
1476 void ptlrpc_dispatch_difficult_reply (struct ptlrpc_reply_state *rs);
1477 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
1478 struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
1479 svc_handler_t h, char *name,
1480 struct proc_dir_entry *proc_entry,
1481 svc_req_printfn_t prntfn,
1484 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
1486 int req_portal, int rep_portal,
1487 int watchdog_factor,
1488 svc_handler_t, char *name,
1489 cfs_proc_dir_entry_t *proc_entry,
1491 int min_threads, int max_threads,
1492 char *threadname, __u32 ctx_tags,
1493 svc_hpreq_handler_t);
1494 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
1496 int ptlrpc_start_threads(struct ptlrpc_service *svc);
1497 int ptlrpc_start_thread(struct ptlrpc_service *svc);
1498 int ptlrpc_unregister_service(struct ptlrpc_service *service);
1499 int liblustre_check_services (void *arg);
1500 void ptlrpc_daemonize(char *name);
1501 int ptlrpc_service_health_check(struct ptlrpc_service *);
1502 void ptlrpc_hpreq_reorder(struct ptlrpc_request *req);
1503 void ptlrpc_server_drop_request(struct ptlrpc_request *req);
1506 int ptlrpc_hr_init(void);
1507 void ptlrpc_hr_fini(void);
1509 # define ptlrpc_hr_init() (0)
1510 # define ptlrpc_hr_fini() do {} while(0)
1513 struct ptlrpc_svc_data {
1515 struct ptlrpc_service *svc;
1516 struct ptlrpc_thread *thread;
1520 /* ptlrpc/import.c */
1525 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
1526 int ptlrpc_init_import(struct obd_import *imp);
1527 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
1528 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
1530 /* ptlrpc/pack_generic.c */
1531 int ptlrpc_reconnect_import(struct obd_import *imp);
1535 * ptlrpc msg buffer and swab interface
1539 int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
1541 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
1543 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len);
1544 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len);
1546 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
1547 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
1549 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
1550 __u32 *lens, char **bufs);
1551 int lustre_pack_reply(struct ptlrpc_request *, int count, __u32 *lens,
1553 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
1554 __u32 *lens, char **bufs, int flags);
1555 #define LPRFL_EARLY_REPLY 1
1556 int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens,
1557 char **bufs, int flags);
1558 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
1559 unsigned int newlen, int move_data);
1560 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
1561 int __lustre_unpack_msg(struct lustre_msg *m, int len);
1562 int lustre_msg_hdr_size(__u32 magic, int count);
1563 int lustre_msg_size(__u32 magic, int count, __u32 *lengths);
1564 int lustre_msg_size_v2(int count, __u32 *lengths);
1565 int lustre_packed_msg_size(struct lustre_msg *msg);
1566 int lustre_msg_early_size(void);
1567 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
1568 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
1569 int lustre_msg_buflen(struct lustre_msg *m, int n);
1570 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
1571 int lustre_msg_bufcount(struct lustre_msg *m);
1572 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
1573 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
1574 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
1575 __u32 lustre_msg_get_flags(struct lustre_msg *msg);
1576 void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
1577 void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
1578 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
1579 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
1580 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
1581 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
1582 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
1583 __u32 lustre_msg_get_type(struct lustre_msg *msg);
1584 __u32 lustre_msg_get_version(struct lustre_msg *msg);
1585 void lustre_msg_add_version(struct lustre_msg *msg, int version);
1586 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
1587 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
1588 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
1589 __u64 *lustre_msg_get_versions(struct lustre_msg *msg);
1590 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
1591 __u64 lustre_msg_get_slv(struct lustre_msg *msg);
1592 __u32 lustre_msg_get_limit(struct lustre_msg *msg);
1593 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
1594 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
1595 int lustre_msg_get_status(struct lustre_msg *msg);
1596 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
1597 int lustre_msg_is_v1(struct lustre_msg *msg);
1598 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
1599 __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
1600 __u32 lustre_msg_get_service_time(struct lustre_msg *msg);
1601 __u32 lustre_msg_get_cksum(struct lustre_msg *msg);
1602 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 0, 0)
1603 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg, int compat18);
1605 # warning "remove checksum compatibility support for b1_8"
1606 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
1608 void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
1609 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
1610 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
1611 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
1612 void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed);
1613 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions);
1614 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
1615 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
1616 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
1617 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *sizes);
1618 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
1619 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
1620 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
1621 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
1624 lustre_shrink_reply(struct ptlrpc_request *req, int segment,
1625 unsigned int newlen, int move_data)
1627 LASSERT(req->rq_reply_state);
1628 LASSERT(req->rq_repmsg);
1629 req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
1634 /** Change request phase of \a req to \a new_phase */
1636 ptlrpc_rqphase_move(struct ptlrpc_request *req, enum rq_phase new_phase)
1638 if (req->rq_phase == new_phase)
1641 if (new_phase == RQ_PHASE_UNREGISTERING) {
1642 req->rq_next_phase = req->rq_phase;
1644 cfs_atomic_inc(&req->rq_import->imp_unregistering);
1647 if (req->rq_phase == RQ_PHASE_UNREGISTERING) {
1649 cfs_atomic_dec(&req->rq_import->imp_unregistering);
1652 DEBUG_REQ(D_INFO, req, "move req \"%s\" -> \"%s\"",
1653 ptlrpc_rqphase2str(req), ptlrpc_phase2str(new_phase));
1655 req->rq_phase = new_phase;
1659 * Returns true if request \a req got early reply and hard deadline is not met
1662 ptlrpc_client_early(struct ptlrpc_request *req)
1664 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1665 req->rq_reply_deadline > cfs_time_current_sec())
1667 return req->rq_early;
1671 * Returns true if we got real reply from server for this request
1674 ptlrpc_client_replied(struct ptlrpc_request *req)
1676 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1677 req->rq_reply_deadline > cfs_time_current_sec())
1679 return req->rq_replied;
1682 /** Returns true if request \a req is in process of receiving server reply */
1684 ptlrpc_client_recv(struct ptlrpc_request *req)
1686 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1687 req->rq_reply_deadline > cfs_time_current_sec())
1689 return req->rq_receiving_reply;
1693 ptlrpc_client_recv_or_unlink(struct ptlrpc_request *req)
1697 cfs_spin_lock(&req->rq_lock);
1698 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1699 req->rq_reply_deadline > cfs_time_current_sec()) {
1700 cfs_spin_unlock(&req->rq_lock);
1703 rc = req->rq_receiving_reply || req->rq_must_unlink;
1704 cfs_spin_unlock(&req->rq_lock);
1709 ptlrpc_client_wake_req(struct ptlrpc_request *req)
1711 if (req->rq_set == NULL)
1712 cfs_waitq_signal(&req->rq_reply_waitq);
1714 cfs_waitq_signal(&req->rq_set->set_waitq);
1718 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
1720 LASSERT(cfs_atomic_read(&rs->rs_refcount) > 0);
1721 cfs_atomic_inc(&rs->rs_refcount);
1725 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
1727 LASSERT(cfs_atomic_read(&rs->rs_refcount) > 0);
1728 if (cfs_atomic_dec_and_test(&rs->rs_refcount))
1729 lustre_free_reply_state(rs);
1732 /* Should only be called once per req */
1733 static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
1735 if (req->rq_reply_state == NULL)
1736 return; /* shouldn't occur */
1737 ptlrpc_rs_decref(req->rq_reply_state);
1738 req->rq_reply_state = NULL;
1739 req->rq_repmsg = NULL;
1742 static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
1744 return lustre_msg_get_magic(req->rq_reqmsg);
1747 static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
1749 switch (req->rq_reqmsg->lm_magic) {
1750 case LUSTRE_MSG_MAGIC_V2:
1751 return req->rq_reqmsg->lm_repsize;
1753 LASSERTF(0, "incorrect message magic: %08x\n",
1754 req->rq_reqmsg->lm_magic);
1759 static inline int ptlrpc_send_limit_expired(struct ptlrpc_request *req)
1761 if (req->rq_delay_limit != 0 &&
1762 cfs_time_before(cfs_time_add(req->rq_queued_time,
1763 cfs_time_seconds(req->rq_delay_limit)),
1764 cfs_time_current())) {
1770 static inline int ptlrpc_no_resend(struct ptlrpc_request *req)
1772 if (!req->rq_no_resend && ptlrpc_send_limit_expired(req)) {
1773 cfs_spin_lock(&req->rq_lock);
1774 req->rq_no_resend = 1;
1775 cfs_spin_unlock(&req->rq_lock);
1777 return req->rq_no_resend;
1780 /* ldlm/ldlm_lib.c */
1782 * Target client logic
1785 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
1786 int client_obd_cleanup(struct obd_device *obddev);
1787 int client_connect_import(const struct lu_env *env,
1788 struct obd_export **exp, struct obd_device *obd,
1789 struct obd_uuid *cluuid, struct obd_connect_data *,
1791 int client_disconnect_export(struct obd_export *exp);
1792 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
1794 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
1795 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
1796 void client_destroy_import(struct obd_import *imp);
1799 int server_disconnect_export(struct obd_export *exp);
1801 /* ptlrpc/pinger.c */
1803 * Pinger API (client side only)
1806 enum timeout_event {
1809 struct timeout_item;
1810 typedef int (*timeout_cb_t)(struct timeout_item *, void *);
1811 int ptlrpc_pinger_add_import(struct obd_import *imp);
1812 int ptlrpc_pinger_del_import(struct obd_import *imp);
1813 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
1814 timeout_cb_t cb, void *data,
1815 cfs_list_t *obd_list);
1816 int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
1817 enum timeout_event event);
1818 struct ptlrpc_request * ptlrpc_prep_ping(struct obd_import *imp);
1819 int ptlrpc_obd_ping(struct obd_device *obd);
1820 cfs_time_t ptlrpc_suspend_wakeup_time(void);
1822 void ping_evictor_start(void);
1823 void ping_evictor_stop(void);
1825 #define ping_evictor_start() do {} while (0)
1826 #define ping_evictor_stop() do {} while (0)
1828 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req);
1831 /* ptlrpc/ptlrpcd.c */
1834 * Ptlrpcd scope is a set of two threads: ptlrpcd-foo and ptlrpcd-foo-rcv,
1835 * these threads are used to asynchronously send requests queued with
1836 * ptlrpcd_add_req(req, PCSOPE_FOO), and to handle completion call-backs for
1837 * such requests. Multiple scopes are needed to avoid dead-locks.
1839 enum ptlrpcd_scope {
1840 /** Scope of bulk read-write rpcs. */
1842 /** Everything else. */
1847 int ptlrpcd_start(const char *name, struct ptlrpcd_ctl *pc);
1848 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force);
1849 void ptlrpcd_wake(struct ptlrpc_request *req);
1850 int ptlrpcd_add_req(struct ptlrpc_request *req, enum ptlrpcd_scope scope);
1851 void ptlrpcd_add_rqset(struct ptlrpc_request_set *set);
1852 int ptlrpcd_addref(void);
1853 void ptlrpcd_decref(void);
1855 /* ptlrpc/lproc_ptlrpc.c */
1857 * procfs output related functions
1860 const char* ll_opcode2str(__u32 opcode);
1862 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
1863 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
1864 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes);
1866 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
1867 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
1868 static inline void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes) {}
1872 /* ptlrpc/llog_server.c */
1873 int llog_origin_handle_create(struct ptlrpc_request *req);
1874 int llog_origin_handle_destroy(struct ptlrpc_request *req);
1875 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
1876 int llog_origin_handle_next_block(struct ptlrpc_request *req);
1877 int llog_origin_handle_read_header(struct ptlrpc_request *req);
1878 int llog_origin_handle_close(struct ptlrpc_request *req);
1879 int llog_origin_handle_cancel(struct ptlrpc_request *req);
1880 int llog_catinfo(struct ptlrpc_request *req);
1882 /* ptlrpc/llog_client.c */
1883 extern struct llog_operations llog_client_ops;