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 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.
40 #if defined(__linux__)
41 #include <linux/lustre_net.h>
42 #elif defined(__APPLE__)
43 #include <darwin/lustre_net.h>
44 #elif defined(__WINNT__)
45 #include <winnt/lustre_net.h>
47 #error Unsupported operating system.
50 #include <libcfs/libcfs.h>
52 #include <lnet/lnet.h>
53 #include <lustre/lustre_idl.h>
54 #include <lustre_ha.h>
55 #include <lustre_sec.h>
56 #include <lustre_import.h>
57 #include <lprocfs_status.h>
58 #include <lu_object.h>
59 #include <lustre_req_layout.h>
61 #include <obd_support.h>
63 /* MD flags we _always_ use */
64 #define PTLRPC_MD_OPTIONS 0
66 /* Define maxima for bulk I/O
67 * CAVEAT EMPTOR, with multinet (i.e. routers forwarding between networks)
68 * these limits are system wide and not interface-local. */
69 #define PTLRPC_MAX_BRW_BITS LNET_MTU_BITS
70 #define PTLRPC_MAX_BRW_SIZE (1<<LNET_MTU_BITS)
71 #define PTLRPC_MAX_BRW_PAGES (PTLRPC_MAX_BRW_SIZE >> CFS_PAGE_SHIFT)
73 /* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
75 # if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
76 # error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
78 # if (PTLRPC_MAX_BRW_SIZE != (PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE))
79 # error "PTLRPC_MAX_BRW_SIZE isn't PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE"
81 # if (PTLRPC_MAX_BRW_SIZE > LNET_MTU)
82 # error "PTLRPC_MAX_BRW_SIZE too big"
84 # if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV)
85 # error "PTLRPC_MAX_BRW_PAGES too big"
87 #endif /* __KERNEL__ */
89 /* Size over which to OBD_VMALLOC() rather than OBD_ALLOC() service request
91 #define SVC_BUF_VMALLOC_THRESHOLD (2 * CFS_PAGE_SIZE)
93 /* The following constants determine how memory is used to buffer incoming
96 * ?_NBUFS # buffers to allocate when growing the pool
97 * ?_BUFSIZE # bytes in a single request buffer
98 * ?_MAXREQSIZE # maximum request service will receive
100 * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
101 * of ?_NBUFS is added to the pool.
103 * Messages larger than ?_MAXREQSIZE are dropped. Request buffers are
104 * considered full when less than ?_MAXREQSIZE is left in them.
107 #define LDLM_THREADS_AUTO_MIN (2)
108 #define LDLM_THREADS_AUTO_MAX min_t(unsigned, cfs_num_online_cpus() * \
109 cfs_num_online_cpus() * 32, 128)
110 #define LDLM_BL_THREADS LDLM_THREADS_AUTO_MIN
111 #define LDLM_NBUFS (64 * cfs_num_online_cpus())
112 #define LDLM_BUFSIZE (8 * 1024)
113 #define LDLM_MAXREQSIZE (5 * 1024)
114 #define LDLM_MAXREPSIZE (1024)
116 #define MDT_MIN_THREADS 2UL
117 #define MDT_MAX_THREADS 512UL
118 #define MDT_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
119 cfs_num_physpages >> (25 - CFS_PAGE_SHIFT)), \
121 #define FLD_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
122 cfs_num_physpages >> (25 - CFS_PAGE_SHIFT)), \
124 #define SEQ_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
125 cfs_num_physpages >> (25 - CFS_PAGE_SHIFT)), \
128 /* Absolute limits */
129 #define MDS_THREADS_MIN 2
130 #define MDS_THREADS_MAX 512
131 #define MDS_THREADS_MIN_READPAGE 2
132 #define MDS_NBUFS (64 * cfs_num_online_cpus())
133 #define MDS_BUFSIZE (8 * 1024)
134 /* Assume file name length = FNAME_MAX = 256 (true for ext3).
135 * path name length = PATH_MAX = 4096
136 * LOV MD size max = EA_MAX = 4000
137 * symlink: FNAME_MAX + PATH_MAX <- largest
138 * link: FNAME_MAX + PATH_MAX (mds_rec_link < mds_rec_create)
139 * rename: FNAME_MAX + FNAME_MAX
140 * open: FNAME_MAX + EA_MAX
142 * MDS_MAXREQSIZE ~= 4736 bytes =
143 * lustre_msg + ldlm_request + mds_body + mds_rec_create + FNAME_MAX + PATH_MAX
144 * MDS_MAXREPSIZE ~= 8300 bytes = lustre_msg + llog_header
145 * or, for mds_close() and mds_reint_unlink() on a many-OST filesystem:
146 * = 9210 bytes = lustre_msg + mds_body + 160 * (easize + cookiesize)
148 * Realistic size is about 512 bytes (20 character name + 128 char symlink),
149 * except in the open case where there are a large number of OSTs in a LOV.
151 #define MDS_MAXREQSIZE (5 * 1024)
152 #define MDS_MAXREPSIZE max(9 * 1024, 362 + LOV_MAX_STRIPE_COUNT * 56)
154 /* FLD_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + md_fld */
155 #define FLD_MAXREQSIZE (160)
157 /* FLD_MAXREPSIZE == lustre_msg + ptlrpc_body + md_fld */
158 #define FLD_MAXREPSIZE (152)
160 /* SEQ_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + lu_range +
162 #define SEQ_MAXREQSIZE (160)
164 /* SEQ_MAXREPSIZE == lustre_msg + ptlrpc_body + lu_range */
165 #define SEQ_MAXREPSIZE (152)
167 #define MGS_THREADS_AUTO_MIN 2
168 #define MGS_THREADS_AUTO_MAX 32
169 #define MGS_NBUFS (64 * cfs_num_online_cpus())
170 #define MGS_BUFSIZE (8 * 1024)
171 #define MGS_MAXREQSIZE (7 * 1024)
172 #define MGS_MAXREPSIZE (9 * 1024)
174 /* Absolute limits */
175 #define OSS_THREADS_MIN 3 /* difficult replies, HPQ, others */
176 #define OSS_THREADS_MAX 512
177 #define OST_NBUFS (64 * cfs_num_online_cpus())
178 #define OST_BUFSIZE (8 * 1024)
179 /* OST_MAXREQSIZE ~= 4768 bytes =
180 * lustre_msg + obdo + 16 * obd_ioobj + 256 * niobuf_remote
182 * - single object with 16 pages is 512 bytes
183 * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
185 #define OST_MAXREQSIZE (5 * 1024)
186 #define OST_MAXREPSIZE (9 * 1024)
188 /* Macro to hide a typecast. */
189 #define ptlrpc_req_async_args(req) ((void *)&req->rq_async_args)
191 struct ptlrpc_connection {
192 cfs_hlist_node_t c_hash;
194 lnet_process_id_t c_peer;
195 struct obd_uuid c_remote_uuid;
196 cfs_atomic_t c_refcount;
199 struct ptlrpc_client {
200 __u32 cli_request_portal;
201 __u32 cli_reply_portal;
205 /* state flags of requests */
206 /* XXX only ones left are those used by the bulk descs as well! */
207 #define PTL_RPC_FL_INTR (1 << 0) /* reply wait was interrupted by user */
208 #define PTL_RPC_FL_TIMEOUT (1 << 7) /* request timed out waiting for reply */
210 #define REQ_MAX_ACK_LOCKS 8
212 union ptlrpc_async_args {
213 /* Scratchpad for passing args to completion interpreter. Users
214 * cast to the struct of their choosing, and LASSERT that this is
215 * big enough. For _tons_ of context, OBD_ALLOC a struct and store
216 * a pointer to it here. The pointer_arg ensures this struct is at
217 * least big enough for that. */
218 void *pointer_arg[11];
222 struct ptlrpc_request_set;
223 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
225 struct ptlrpc_request_set {
226 int set_remaining; /* # uncompleted requests */
227 cfs_waitq_t set_waitq;
228 cfs_waitq_t *set_wakeup_ptr;
229 cfs_list_t set_requests;
230 cfs_list_t set_cblist; /* list of completion callbacks */
231 set_interpreter_func set_interpret; /* completion callback */
232 void *set_arg; /* completion context */
233 /* locked so that any old caller can communicate requests to
234 * the set holder who can then fold them into the lock-free set */
235 cfs_spinlock_t set_new_req_lock;
236 cfs_list_t set_new_requests;
239 struct ptlrpc_set_cbdata {
241 set_interpreter_func psc_interpret;
245 struct ptlrpc_bulk_desc;
248 * ptlrpc callback & work item stuff
250 struct ptlrpc_cb_id {
251 void (*cbid_fn)(lnet_event_t *ev); /* specific callback fn */
252 void *cbid_arg; /* additional arg */
255 #define RS_MAX_LOCKS 8
258 struct ptlrpc_reply_state {
259 struct ptlrpc_cb_id rs_cb_id;
261 cfs_list_t rs_exp_list;
262 cfs_list_t rs_obd_list;
264 cfs_list_t rs_debug_list;
266 /* A spinlock to protect the reply state flags */
267 cfs_spinlock_t rs_lock;
268 /* Reply state flags */
269 unsigned long rs_difficult:1; /* ACK/commit stuff */
270 unsigned long rs_no_ack:1; /* no ACK, even for
271 difficult requests */
272 unsigned long rs_scheduled:1; /* being handled? */
273 unsigned long rs_scheduled_ever:1;/* any schedule attempts? */
274 unsigned long rs_handled:1; /* been handled yet? */
275 unsigned long rs_on_net:1; /* reply_out_callback pending? */
276 unsigned long rs_prealloc:1; /* rs from prealloc list */
277 unsigned long rs_committed:1;/* the transaction was committed
278 and the rs was dispatched
279 by ptlrpc_commit_replies */
284 struct obd_export *rs_export;
285 struct ptlrpc_service *rs_service;
286 lnet_handle_md_t rs_md_h;
287 cfs_atomic_t rs_refcount;
289 struct ptlrpc_svc_ctx *rs_svc_ctx;
290 struct lustre_msg *rs_repbuf; /* wrapper */
291 int rs_repbuf_len; /* wrapper buf length */
292 int rs_repdata_len; /* wrapper msg length */
293 struct lustre_msg *rs_msg; /* reply message */
295 /* locks awaiting client reply ACK */
297 struct lustre_handle rs_locks[RS_MAX_LOCKS];
298 ldlm_mode_t rs_modes[RS_MAX_LOCKS];
301 struct ptlrpc_thread;
304 RQ_PHASE_NEW = 0xebc0de00,
305 RQ_PHASE_RPC = 0xebc0de01,
306 RQ_PHASE_BULK = 0xebc0de02,
307 RQ_PHASE_INTERPRET = 0xebc0de03,
308 RQ_PHASE_COMPLETE = 0xebc0de04,
309 RQ_PHASE_UNREGISTERING = 0xebc0de05,
310 RQ_PHASE_UNDEFINED = 0xebc0de06
313 /** Type of request interpreter call-back */
314 typedef int (*ptlrpc_interpterer_t)(const struct lu_env *env,
315 struct ptlrpc_request *req,
318 struct ptlrpc_request_pool {
319 cfs_spinlock_t prp_lock;
320 cfs_list_t prp_req_list; /* list of ptlrpc_request structs */
322 void (*prp_populate)(struct ptlrpc_request_pool *, int);
330 struct ptlrpc_hpreq_ops {
332 * Check if the lock handle of the given lock is the same as
333 * taken from the request.
335 int (*hpreq_lock_match)(struct ptlrpc_request *, struct ldlm_lock *);
337 * Check if the request is a high priority one.
339 int (*hpreq_check)(struct ptlrpc_request *);
343 * Represents remote procedure call.
345 struct ptlrpc_request {
346 int rq_type; /* one of PTL_RPC_MSG_* */
348 cfs_list_t rq_timed_list; /* server-side early replies */
349 cfs_list_t rq_history_list; /* server-side history */
350 cfs_list_t rq_exp_list; /* server-side per-export list */
351 struct ptlrpc_hpreq_ops *rq_ops; /* server-side hp handlers */
352 __u64 rq_history_seq; /* history sequence # */
353 /* the index of service's srv_at_array into which request is linked */
356 cfs_spinlock_t rq_lock;
357 /* client-side flags are serialized by rq_lock */
358 unsigned long rq_intr:1, rq_replied:1, rq_err:1,
359 rq_timedout:1, rq_resend:1, rq_restart:1,
361 * when ->rq_replay is set, request is kept by the client even
362 * after server commits corresponding transaction. This is
363 * used for operations that require sequence of multiple
364 * requests to be replayed. The only example currently is file
365 * open/close. When last request in such a sequence is
366 * committed, ->rq_replay is cleared on all requests in the
370 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
371 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
372 rq_early:1, rq_must_unlink:1,
373 rq_fake:1, /* this fake req */
374 /* server-side flags */
375 rq_packed_final:1, /* packed final reply */
376 rq_hp:1, /* high priority RPC */
377 rq_at_linked:1, /* link into service's srv_at_array */
381 enum rq_phase rq_phase; /* one of RQ_PHASE_* */
382 enum rq_phase rq_next_phase; /* one of RQ_PHASE_* to be used next */
383 cfs_atomic_t rq_refcount;/* client-side refcount for SENT race,
384 server-side refcounf for multiple replies */
386 struct ptlrpc_thread *rq_svc_thread; /* initial thread servicing req */
388 int rq_request_portal; /* XXX FIXME bug 249 */
389 int rq_reply_portal; /* XXX FIXME bug 249 */
391 int rq_nob_received; /* client-side # reply bytes actually received */
394 struct lustre_msg *rq_reqmsg;
397 struct lustre_msg *rq_repmsg;
400 cfs_list_t rq_replay_list;
402 struct ptlrpc_cli_ctx *rq_cli_ctx; /* client's half ctx */
403 struct ptlrpc_svc_ctx *rq_svc_ctx; /* server's half ctx */
404 cfs_list_t rq_ctx_chain; /* link to waited ctx */
406 struct sptlrpc_flavor rq_flvr; /* client & server */
407 enum lustre_sec_part rq_sp_from;
409 unsigned long /* client/server security flags */
410 rq_ctx_init:1, /* context initiation */
411 rq_ctx_fini:1, /* context destroy */
412 rq_bulk_read:1, /* request bulk read */
413 rq_bulk_write:1, /* request bulk write */
414 /* server authentication flags */
415 rq_auth_gss:1, /* authenticated by gss */
416 rq_auth_remote:1, /* authed as remote user */
417 rq_auth_usr_root:1, /* authed as root */
418 rq_auth_usr_mdt:1, /* authed as mdt */
419 /* security tfm flags */
422 /* doesn't expect reply FIXME */
424 rq_pill_init:1; /* pill initialized */
426 uid_t rq_auth_uid; /* authed uid */
427 uid_t rq_auth_mapped_uid; /* authed uid mapped to */
429 /* (server side), pointed directly into req buffer */
430 struct ptlrpc_user_desc *rq_user_desc;
432 /* early replies go to offset 0, regular replies go after that */
433 unsigned int rq_reply_off;
435 /* various buffer pointers */
436 struct lustre_msg *rq_reqbuf; /* req wrapper */
437 int rq_reqbuf_len; /* req wrapper buf len */
438 int rq_reqdata_len; /* req wrapper msg len */
439 char *rq_repbuf; /* rep buffer */
440 int rq_repbuf_len; /* rep buffer len */
441 struct lustre_msg *rq_repdata; /* rep wrapper msg */
442 int rq_repdata_len; /* rep wrapper msg len */
443 struct lustre_msg *rq_clrbuf; /* only in priv mode */
444 int rq_clrbuf_len; /* only in priv mode */
445 int rq_clrdata_len; /* only in priv mode */
447 __u32 rq_req_swab_mask;
448 __u32 rq_rep_swab_mask;
450 int rq_import_generation;
451 enum lustre_imp_state rq_send_state;
453 int rq_early_count; /* how many early replies (for stats) */
455 /* client+server request */
456 lnet_handle_md_t rq_req_md_h;
457 struct ptlrpc_cb_id rq_req_cbid;
460 struct timeval rq_arrival_time; /* request arrival time */
461 struct ptlrpc_reply_state *rq_reply_state; /* separated reply state */
462 struct ptlrpc_request_buffer_desc *rq_rqbd; /* incoming request buffer*/
464 __u32 rq_uid; /* peer uid, used in MDS only */
467 /* client-only incoming reply */
468 lnet_handle_md_t rq_reply_md_h;
469 cfs_waitq_t rq_reply_waitq;
470 struct ptlrpc_cb_id rq_reply_cbid;
473 lnet_process_id_t rq_peer;
474 struct obd_export *rq_export;
475 struct obd_import *rq_import;
477 void (*rq_replay_cb)(struct ptlrpc_request *);
478 void (*rq_commit_cb)(struct ptlrpc_request *);
481 struct ptlrpc_bulk_desc *rq_bulk;/* client side bulk */
483 /* client outgoing req */
484 time_t rq_sent; /* when request/reply sent (secs), or
485 * time when request should be sent */
487 volatile time_t rq_deadline; /* when request must finish. volatile
488 so that servers' early reply updates to the deadline aren't
489 kept in per-cpu cache */
490 time_t rq_reply_deadline; /* when req reply unlink must finish. */
491 time_t rq_bulk_deadline; /* when req bulk unlink must finish. */
492 int rq_timeout; /* service time estimate (secs) */
495 cfs_list_t rq_set_chain;
496 struct ptlrpc_request_set *rq_set;
497 /** Async completion handler */
498 ptlrpc_interpterer_t rq_interpret_reply;
499 union ptlrpc_async_args rq_async_args; /* Async completion context */
500 struct ptlrpc_request_pool *rq_pool; /* Pool if request from
502 struct lu_context rq_session;
503 struct lu_context rq_recov_session;
506 struct req_capsule rq_pill;
509 static inline int ptlrpc_req_interpret(const struct lu_env *env,
510 struct ptlrpc_request *req, int rc)
512 if (req->rq_interpret_reply != NULL) {
513 req->rq_status = req->rq_interpret_reply(env, req,
516 return req->rq_status;
521 static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
523 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
524 return req->rq_req_swab_mask & (1 << index);
527 static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
529 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
530 return req->rq_rep_swab_mask & (1 << index);
533 static inline int ptlrpc_req_need_swab(struct ptlrpc_request *req)
535 return lustre_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
538 static inline int ptlrpc_rep_need_swab(struct ptlrpc_request *req)
540 return lustre_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
543 static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
545 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
546 LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
547 req->rq_req_swab_mask |= 1 << index;
550 static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
552 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
553 LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
554 req->rq_rep_swab_mask |= 1 << index;
557 static inline const char *
558 ptlrpc_phase2str(enum rq_phase phase)
567 case RQ_PHASE_INTERPRET:
569 case RQ_PHASE_COMPLETE:
571 case RQ_PHASE_UNREGISTERING:
572 return "Unregistering";
578 static inline const char *
579 ptlrpc_rqphase2str(struct ptlrpc_request *req)
581 return ptlrpc_phase2str(req->rq_phase);
584 /* Spare the preprocessor, spoil the bugs. */
585 #define FLAG(field, str) (field ? str : "")
587 #define DEBUG_REQ_FLAGS(req) \
588 ptlrpc_rqphase2str(req), \
589 FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"), \
590 FLAG(req->rq_err, "E"), \
591 FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"), \
592 FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"), \
593 FLAG(req->rq_no_resend, "N"), \
594 FLAG(req->rq_waiting, "W"), \
595 FLAG(req->rq_wait_ctx, "C"), FLAG(req->rq_hp, "H")
597 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s%s"
599 void _debug_req(struct ptlrpc_request *req, __u32 mask,
600 struct libcfs_debug_msg_data *data, const char *fmt, ...)
601 __attribute__ ((format (printf, 4, 5)));
603 #define debug_req(cdls, level, req, file, func, line, fmt, a...) \
607 if (((level) & D_CANTMASK) != 0 || \
608 ((libcfs_debug & (level)) != 0 && \
609 (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) { \
610 static struct libcfs_debug_msg_data _req_dbg_data = \
611 DEBUG_MSG_DATA_INIT(cdls, DEBUG_SUBSYSTEM, file, func, line); \
612 _debug_req((req), (level), &_req_dbg_data, fmt, ##a); \
616 /* for most callers (level is a constant) this is resolved at compile time */
617 #define DEBUG_REQ(level, req, fmt, args...) \
619 if ((level) & (D_ERROR | D_WARNING)) { \
620 static cfs_debug_limit_state_t cdls; \
621 debug_req(&cdls, level, req, __FILE__, __func__, __LINE__, \
622 "@@@ "fmt" ", ## args); \
624 debug_req(NULL, level, req, __FILE__, __func__, __LINE__, \
625 "@@@ "fmt" ", ## args); \
628 struct ptlrpc_bulk_page {
631 int bp_pageoffset; /* offset within a page */
632 struct page *bp_page;
635 #define BULK_GET_SOURCE 0
636 #define BULK_PUT_SINK 1
637 #define BULK_GET_SINK 2
638 #define BULK_PUT_SOURCE 3
640 struct ptlrpc_bulk_desc {
641 unsigned long bd_success:1; /* completed successfully */
642 unsigned long bd_network_rw:1; /* accessible to the network */
643 unsigned long bd_type:2; /* {put,get}{source,sink} */
644 unsigned long bd_registered:1; /* client side */
645 cfs_spinlock_t bd_lock; /* serialise with callback */
646 int bd_import_generation;
647 struct obd_export *bd_export;
648 struct obd_import *bd_import;
650 struct ptlrpc_request *bd_req; /* associated request */
651 cfs_waitq_t bd_waitq; /* server side only WQ */
652 int bd_iov_count; /* # entries in bd_iov */
653 int bd_max_iov; /* allocated size of bd_iov */
654 int bd_nob; /* # bytes covered */
655 int bd_nob_transferred; /* # bytes GOT/PUT */
659 struct ptlrpc_cb_id bd_cbid; /* network callback info */
660 lnet_handle_md_t bd_md_h; /* associated MD */
661 lnet_nid_t bd_sender; /* stash event::sender */
663 #if defined(__KERNEL__)
665 * encrypt iov, size is either 0 or bd_iov_count.
667 lnet_kiov_t *bd_enc_iov;
669 lnet_kiov_t bd_iov[0];
671 lnet_md_iovec_t bd_iov[0];
675 struct ptlrpc_thread {
677 * active threads in svc->srv_threads
681 * thread-private data (preallocated memory)
686 * service thread index, from ptlrpc_start_threads
694 * put watchdog in the structure per thread b=14840
696 struct lc_watchdog *t_watchdog;
698 * the svc this thread belonged to b=18582
700 struct ptlrpc_service *t_svc;
701 cfs_waitq_t t_ctl_waitq;
702 struct lu_env *t_env;
705 struct ptlrpc_request_buffer_desc {
706 cfs_list_t rqbd_list;
707 cfs_list_t rqbd_reqs;
708 struct ptlrpc_service *rqbd_service;
709 lnet_handle_md_t rqbd_md_h;
712 struct ptlrpc_cb_id rqbd_cbid;
713 struct ptlrpc_request rqbd_req;
716 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
717 typedef void (*svcreq_printfn_t)(void *, struct ptlrpc_request *);
718 typedef int (*svc_hpreq_handler_t)(struct ptlrpc_request *);
720 #define PTLRPC_SVC_HP_RATIO 10
722 struct ptlrpc_service {
723 cfs_list_t srv_list; /* chain thru all services */
724 int srv_max_req_size; /* biggest request to receive */
725 int srv_max_reply_size; /* biggest reply to send */
726 int srv_buf_size; /* size of individual buffers */
727 int srv_nbuf_per_group; /* # buffers to allocate in 1 group */
728 int srv_nbufs; /* total # req buffer descs allocated */
729 int srv_threads_min; /* threads to start at SOW */
730 int srv_threads_max; /* thread upper limit */
731 int srv_threads_started; /* index of last started thread */
732 int srv_threads_running; /* # running threads */
733 cfs_atomic_t srv_n_difficult_replies; /* # 'difficult' replies */
734 int srv_n_active_reqs; /* # reqs being served */
735 int srv_n_hpreq; /* # HPreqs being served */
736 cfs_duration_t srv_rqbd_timeout; /* timeout before re-posting reqs, in tick */
737 int srv_watchdog_factor; /* soft watchdog timeout multiplier */
738 unsigned srv_cpu_affinity:1; /* bind threads to CPUs */
739 unsigned srv_at_check:1; /* check early replies */
740 unsigned srv_is_stopping:1; /* under unregister_service */
741 cfs_time_t srv_at_checktime; /* debug */
743 __u32 srv_req_portal;
744 __u32 srv_rep_portal;
747 struct adaptive_timeout srv_at_estimate;/* estimated rpc service time */
748 cfs_spinlock_t srv_at_lock;
749 struct ptlrpc_at_array srv_at_array; /* reqs waiting for replies */
750 cfs_timer_t srv_at_timer; /* early reply timer */
752 int srv_n_queued_reqs; /* # reqs in either of the queues below */
753 int srv_hpreq_count; /* # hp requests handled */
754 int srv_hpreq_ratio; /* # hp per lp reqs to handle */
755 cfs_list_t srv_req_in_queue; /* incoming reqs */
756 cfs_list_t srv_request_queue; /* reqs waiting for service */
757 cfs_list_t srv_request_hpq; /* high priority queue */
759 cfs_list_t srv_request_history; /* request history */
760 __u64 srv_request_seq; /* next request sequence # */
761 __u64 srv_request_max_cull_seq; /* highest seq culled from history */
762 svcreq_printfn_t srv_request_history_print_fn; /* service-specific print fn */
764 cfs_list_t srv_idle_rqbds; /* request buffers to be reposted */
765 cfs_list_t srv_active_rqbds; /* req buffers receiving */
766 cfs_list_t srv_history_rqbds; /* request buffer history */
767 int srv_nrqbd_receiving; /* # posted request buffers */
768 int srv_n_history_rqbds; /* # request buffers in history */
769 int srv_max_history_rqbds;/* max # request buffers in history */
771 cfs_atomic_t srv_outstanding_replies;
772 cfs_list_t srv_active_replies; /* all the active replies */
774 cfs_list_t srv_reply_queue; /* replies waiting for service */
776 cfs_waitq_t srv_waitq; /* all threads sleep on this. This
777 * wait-queue is signalled when new
778 * incoming request arrives and when
779 * difficult reply has to be handled. */
781 cfs_list_t srv_threads; /* service thread list */
782 svc_handler_t srv_handler;
783 svc_hpreq_handler_t srv_hpreq_handler; /* hp request handler */
785 char *srv_name; /* only statically allocated strings here; we don't clean them */
786 char *srv_thread_name; /* only statically allocated strings here; we don't clean them */
788 cfs_spinlock_t srv_lock;
790 cfs_proc_dir_entry_t *srv_procroot;
791 struct lprocfs_stats *srv_stats;
793 /* List of free reply_states */
794 cfs_list_t srv_free_rs_list;
795 /* waitq to run, when adding stuff to srv_free_rs_list */
796 cfs_waitq_t srv_free_rs_waitq;
799 * Tags for lu_context associated with this thread, see struct
804 * if non-NULL called during thread creation (ptlrpc_start_thread())
805 * to initialize service specific per-thread state.
807 int (*srv_init)(struct ptlrpc_thread *thread);
809 * if non-NULL called during thread shutdown (ptlrpc_main()) to
810 * destruct state created by ->srv_init().
812 void (*srv_done)(struct ptlrpc_thread *thread);
814 //struct ptlrpc_srv_ni srv_interfaces[0];
819 * Ptlrpc thread control flags (LIOD_START, LIOD_STOP, LIOD_FORCE)
821 unsigned long pc_flags;
823 * Thread lock protecting structure fields.
825 cfs_spinlock_t pc_lock;
829 cfs_completion_t pc_starting;
833 cfs_completion_t pc_finishing;
835 * Thread requests set.
837 struct ptlrpc_request_set *pc_set;
839 * Thread name used in cfs_daemonize()
843 * Environment for request interpreters to run in.
845 struct lu_env pc_env;
848 * Async rpcs flag to make sure that ptlrpcd_check() is called only
853 * Currently not used.
857 * User-space async rpcs callback.
859 void *pc_wait_callback;
861 * User-space check idle rpcs callback.
863 void *pc_idle_callback;
867 /* Bits for pc_flags */
868 enum ptlrpcd_ctl_flags {
870 * Ptlrpc thread start flag.
874 * Ptlrpc thread stop flag.
878 * Ptlrpc thread force flag (only stop force so far).
879 * This will cause aborting any inflight rpcs handled
880 * by thread if LIOD_STOP is specified.
884 * This is a recovery ptlrpc thread.
886 LIOD_RECOVERY = 1 << 3
889 /* ptlrpc/events.c */
890 extern lnet_handle_eq_t ptlrpc_eq_h;
891 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
892 lnet_process_id_t *peer, lnet_nid_t *self);
893 extern void request_out_callback (lnet_event_t *ev);
894 extern void reply_in_callback(lnet_event_t *ev);
895 extern void client_bulk_callback (lnet_event_t *ev);
896 extern void request_in_callback(lnet_event_t *ev);
897 extern void reply_out_callback(lnet_event_t *ev);
898 extern void server_bulk_callback (lnet_event_t *ev);
900 /* ptlrpc/connection.c */
901 struct ptlrpc_connection *ptlrpc_connection_get(lnet_process_id_t peer,
903 struct obd_uuid *uuid);
904 int ptlrpc_connection_put(struct ptlrpc_connection *c);
905 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
906 int ptlrpc_connection_init(void);
907 void ptlrpc_connection_fini(void);
908 extern lnet_pid_t ptl_get_pid(void);
910 /* ptlrpc/niobuf.c */
911 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
912 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
913 int ptlrpc_register_bulk(struct ptlrpc_request *req);
914 int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async);
916 static inline int ptlrpc_server_bulk_active(struct ptlrpc_bulk_desc *desc)
920 LASSERT(desc != NULL);
922 cfs_spin_lock(&desc->bd_lock);
923 rc = desc->bd_network_rw;
924 cfs_spin_unlock(&desc->bd_lock);
928 static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req)
930 struct ptlrpc_bulk_desc *desc = req->rq_bulk;
933 LASSERT(req != NULL);
935 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) &&
936 req->rq_bulk_deadline > cfs_time_current_sec())
942 cfs_spin_lock(&desc->bd_lock);
943 rc = desc->bd_network_rw;
944 cfs_spin_unlock(&desc->bd_lock);
948 #define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
949 #define PTLRPC_REPLY_EARLY 0x02
950 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
951 int ptlrpc_reply(struct ptlrpc_request *req);
952 int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
953 int ptlrpc_error(struct ptlrpc_request *req);
954 void ptlrpc_resend_req(struct ptlrpc_request *request);
955 int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
956 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
957 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
959 /* ptlrpc/client.c */
960 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
961 struct ptlrpc_client *);
962 void ptlrpc_cleanup_client(struct obd_import *imp);
963 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
965 int ptlrpc_queue_wait(struct ptlrpc_request *req);
966 int ptlrpc_replay_req(struct ptlrpc_request *req);
967 int ptlrpc_unregister_reply(struct ptlrpc_request *req, int async);
968 void ptlrpc_restart_req(struct ptlrpc_request *req);
969 void ptlrpc_abort_inflight(struct obd_import *imp);
970 void ptlrpc_cleanup_imp(struct obd_import *imp);
971 void ptlrpc_abort_set(struct ptlrpc_request_set *set);
973 struct ptlrpc_request_set *ptlrpc_prep_set(void);
974 int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
975 set_interpreter_func fn, void *data);
976 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
977 int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set);
978 int ptlrpc_set_wait(struct ptlrpc_request_set *);
979 int ptlrpc_expired_set(void *data);
980 void ptlrpc_interrupted_set(void *data);
981 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
982 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
983 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
984 int ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
985 struct ptlrpc_request *req);
987 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
988 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
990 struct ptlrpc_request_pool *
991 ptlrpc_init_rq_pool(int, int,
992 void (*populate_pool)(struct ptlrpc_request_pool *, int));
994 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
995 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
996 const struct req_format *format);
997 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
998 struct ptlrpc_request_pool *,
999 const struct req_format *format);
1000 void ptlrpc_request_free(struct ptlrpc_request *request);
1001 int ptlrpc_request_pack(struct ptlrpc_request *request,
1002 __u32 version, int opcode);
1003 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
1004 const struct req_format *format,
1005 __u32 version, int opcode);
1006 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
1007 __u32 version, int opcode, char **bufs,
1008 struct ptlrpc_cli_ctx *ctx);
1009 struct ptlrpc_request *ptlrpc_prep_fakereq(struct obd_import *imp,
1010 unsigned int timeout,
1011 ptlrpc_interpterer_t interpreter);
1012 void ptlrpc_fakereq_finished(struct ptlrpc_request *req);
1014 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
1015 int opcode, int count, __u32 *lengths,
1017 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
1018 __u32 version, int opcode,
1019 int count, __u32 *lengths, char **bufs,
1020 struct ptlrpc_request_pool *pool);
1021 void ptlrpc_req_finished(struct ptlrpc_request *request);
1022 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
1023 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
1024 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
1025 int npages, int type, int portal);
1026 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
1027 int npages, int type, int portal);
1028 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
1029 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
1030 cfs_page_t *page, int pageoffset, int len);
1031 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
1032 struct obd_import *imp);
1033 __u64 ptlrpc_next_xid(void);
1034 __u64 ptlrpc_sample_next_xid(void);
1035 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
1037 struct ptlrpc_service_conf {
1040 int psc_max_req_size;
1041 int psc_max_reply_size;
1044 int psc_watchdog_factor;
1045 int psc_min_threads;
1046 int psc_max_threads;
1050 /* ptlrpc/service.c */
1051 void ptlrpc_save_lock (struct ptlrpc_request *req,
1052 struct lustre_handle *lock, int mode, int no_ack);
1053 void ptlrpc_commit_replies(struct obd_export *exp);
1054 void ptlrpc_dispatch_difficult_reply (struct ptlrpc_reply_state *rs);
1055 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
1056 struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
1057 svc_handler_t h, char *name,
1058 struct proc_dir_entry *proc_entry,
1059 svcreq_printfn_t prntfn,
1062 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
1064 int req_portal, int rep_portal,
1065 int watchdog_factor,
1066 svc_handler_t, char *name,
1067 cfs_proc_dir_entry_t *proc_entry,
1069 int min_threads, int max_threads,
1070 char *threadname, __u32 ctx_tags,
1071 svc_hpreq_handler_t);
1072 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
1074 int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc);
1075 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc);
1076 int ptlrpc_unregister_service(struct ptlrpc_service *service);
1077 int liblustre_check_services (void *arg);
1078 void ptlrpc_daemonize(char *name);
1079 int ptlrpc_service_health_check(struct ptlrpc_service *);
1080 void ptlrpc_hpreq_reorder(struct ptlrpc_request *req);
1081 void ptlrpc_server_active_request_inc(struct ptlrpc_request *req);
1082 void ptlrpc_server_active_request_dec(struct ptlrpc_request *req);
1083 void ptlrpc_server_drop_request(struct ptlrpc_request *req);
1086 int ptlrpc_hr_init(void);
1087 void ptlrpc_hr_fini(void);
1089 # define ptlrpc_hr_init() (0)
1090 # define ptlrpc_hr_fini() do {} while(0)
1093 struct ptlrpc_svc_data {
1095 struct ptlrpc_service *svc;
1096 struct ptlrpc_thread *thread;
1097 struct obd_device *dev;
1100 /* ptlrpc/import.c */
1101 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
1102 int ptlrpc_init_import(struct obd_import *imp);
1103 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
1104 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
1106 /* ptlrpc/pack_generic.c */
1107 int ptlrpc_reconnect_import(struct obd_import *imp);
1109 /** ptlrpc mgs buffer swab interface */
1110 int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
1112 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
1114 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len);
1115 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len);
1117 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
1118 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
1120 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
1121 __u32 *lens, char **bufs);
1122 int lustre_pack_reply(struct ptlrpc_request *, int count, __u32 *lens,
1124 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
1125 __u32 *lens, char **bufs, int flags);
1126 #define LPRFL_EARLY_REPLY 1
1127 int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens,
1128 char **bufs, int flags);
1129 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
1130 unsigned int newlen, int move_data);
1131 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
1132 int __lustre_unpack_msg(struct lustre_msg *m, int len);
1133 int lustre_msg_hdr_size(__u32 magic, int count);
1134 int lustre_msg_size(__u32 magic, int count, __u32 *lengths);
1135 int lustre_msg_size_v2(int count, __u32 *lengths);
1136 int lustre_packed_msg_size(struct lustre_msg *msg);
1137 int lustre_msg_early_size(void);
1138 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
1139 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
1140 int lustre_msg_buflen(struct lustre_msg *m, int n);
1141 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
1142 int lustre_msg_bufcount(struct lustre_msg *m);
1143 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
1144 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
1145 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
1146 __u32 lustre_msg_get_flags(struct lustre_msg *msg);
1147 void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
1148 void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
1149 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
1150 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
1151 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
1152 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
1153 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
1154 __u32 lustre_msg_get_type(struct lustre_msg *msg);
1155 __u32 lustre_msg_get_version(struct lustre_msg *msg);
1156 void lustre_msg_add_version(struct lustre_msg *msg, int version);
1157 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
1158 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
1159 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
1160 __u64 *lustre_msg_get_versions(struct lustre_msg *msg);
1161 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
1162 __u64 lustre_msg_get_slv(struct lustre_msg *msg);
1163 __u32 lustre_msg_get_limit(struct lustre_msg *msg);
1164 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
1165 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
1166 int lustre_msg_get_status(struct lustre_msg *msg);
1167 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
1168 int lustre_msg_is_v1(struct lustre_msg *msg);
1169 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
1170 __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
1171 __u32 lustre_msg_get_service_time(struct lustre_msg *msg);
1172 __u32 lustre_msg_get_cksum(struct lustre_msg *msg);
1173 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
1174 void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
1175 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
1176 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
1177 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
1178 void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed);
1179 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions);
1180 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
1181 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
1182 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
1183 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *sizes);
1184 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
1185 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
1186 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
1187 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
1190 lustre_shrink_reply(struct ptlrpc_request *req, int segment,
1191 unsigned int newlen, int move_data)
1193 LASSERT(req->rq_reply_state);
1194 LASSERT(req->rq_repmsg);
1195 req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
1200 ptlrpc_rqphase_move(struct ptlrpc_request *req, enum rq_phase new_phase)
1202 if (req->rq_phase == new_phase)
1205 if (new_phase == RQ_PHASE_UNREGISTERING) {
1206 req->rq_next_phase = req->rq_phase;
1208 cfs_atomic_inc(&req->rq_import->imp_unregistering);
1211 if (req->rq_phase == RQ_PHASE_UNREGISTERING) {
1213 cfs_atomic_dec(&req->rq_import->imp_unregistering);
1216 DEBUG_REQ(D_INFO, req, "move req \"%s\" -> \"%s\"",
1217 ptlrpc_rqphase2str(req), ptlrpc_phase2str(new_phase));
1219 req->rq_phase = new_phase;
1223 ptlrpc_client_early(struct ptlrpc_request *req)
1225 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1226 req->rq_reply_deadline > cfs_time_current_sec())
1228 return req->rq_early;
1232 ptlrpc_client_replied(struct ptlrpc_request *req)
1234 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1235 req->rq_reply_deadline > cfs_time_current_sec())
1237 return req->rq_replied;
1241 ptlrpc_client_recv(struct ptlrpc_request *req)
1243 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1244 req->rq_reply_deadline > cfs_time_current_sec())
1246 return req->rq_receiving_reply;
1250 ptlrpc_client_recv_or_unlink(struct ptlrpc_request *req)
1254 cfs_spin_lock(&req->rq_lock);
1255 if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
1256 req->rq_reply_deadline > cfs_time_current_sec()) {
1257 cfs_spin_unlock(&req->rq_lock);
1260 rc = req->rq_receiving_reply || req->rq_must_unlink;
1261 cfs_spin_unlock(&req->rq_lock);
1266 ptlrpc_client_wake_req(struct ptlrpc_request *req)
1268 if (req->rq_set == NULL)
1269 cfs_waitq_signal(&req->rq_reply_waitq);
1271 cfs_waitq_signal(&req->rq_set->set_waitq);
1275 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
1277 LASSERT(cfs_atomic_read(&rs->rs_refcount) > 0);
1278 cfs_atomic_inc(&rs->rs_refcount);
1282 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
1284 LASSERT(cfs_atomic_read(&rs->rs_refcount) > 0);
1285 if (cfs_atomic_dec_and_test(&rs->rs_refcount))
1286 lustre_free_reply_state(rs);
1289 /* Should only be called once per req */
1290 static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
1292 if (req->rq_reply_state == NULL)
1293 return; /* shouldn't occur */
1294 ptlrpc_rs_decref(req->rq_reply_state);
1295 req->rq_reply_state = NULL;
1296 req->rq_repmsg = NULL;
1299 static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
1301 return lustre_msg_get_magic(req->rq_reqmsg);
1304 static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
1306 switch (req->rq_reqmsg->lm_magic) {
1307 case LUSTRE_MSG_MAGIC_V2:
1308 return req->rq_reqmsg->lm_repsize;
1310 LASSERTF(0, "incorrect message magic: %08x\n",
1311 req->rq_reqmsg->lm_magic);
1316 /* ldlm/ldlm_lib.c */
1317 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
1318 int client_obd_cleanup(struct obd_device *obddev);
1319 int client_connect_import(const struct lu_env *env,
1320 struct obd_export **exp, struct obd_device *obd,
1321 struct obd_uuid *cluuid, struct obd_connect_data *,
1323 int client_disconnect_export(struct obd_export *exp);
1324 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
1326 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
1327 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
1328 void client_destroy_import(struct obd_import *imp);
1330 int server_disconnect_export(struct obd_export *exp);
1332 /* ptlrpc/pinger.c */
1333 enum timeout_event {
1336 struct timeout_item;
1337 typedef int (*timeout_cb_t)(struct timeout_item *, void *);
1338 int ptlrpc_pinger_add_import(struct obd_import *imp);
1339 int ptlrpc_pinger_del_import(struct obd_import *imp);
1340 int ptlrpc_add_timeout_client(int time, enum timeout_event event,
1341 timeout_cb_t cb, void *data,
1342 cfs_list_t *obd_list);
1343 int ptlrpc_del_timeout_client(cfs_list_t *obd_list,
1344 enum timeout_event event);
1345 struct ptlrpc_request * ptlrpc_prep_ping(struct obd_import *imp);
1346 int ptlrpc_obd_ping(struct obd_device *obd);
1347 cfs_time_t ptlrpc_suspend_wakeup_time(void);
1349 void ping_evictor_start(void);
1350 void ping_evictor_stop(void);
1352 #define ping_evictor_start() do {} while (0)
1353 #define ping_evictor_stop() do {} while (0)
1355 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req);
1357 /* ptlrpc/ptlrpcd.c */
1360 * Ptlrpcd scope is a set of two threads: ptlrpcd-foo and ptlrpcd-foo-rcv,
1361 * these threads are used to asynchronously send requests queued with
1362 * ptlrpcd_add_req(req, PCSOPE_FOO), and to handle completion call-backs for
1363 * such requests. Multiple scopes are needed to avoid dead-locks.
1365 enum ptlrpcd_scope {
1366 /** Scope of bulk read-write rpcs. */
1368 /** Everything else. */
1373 int ptlrpcd_start(const char *name, struct ptlrpcd_ctl *pc);
1374 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force);
1375 void ptlrpcd_wake(struct ptlrpc_request *req);
1376 int ptlrpcd_add_req(struct ptlrpc_request *req, enum ptlrpcd_scope scope);
1377 void ptlrpcd_add_rqset(struct ptlrpc_request_set *set);
1378 int ptlrpcd_addref(void);
1379 void ptlrpcd_decref(void);
1381 /* ptlrpc/lproc_ptlrpc.c */
1382 const char* ll_opcode2str(__u32 opcode);
1384 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
1385 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
1386 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes);
1388 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
1389 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
1390 static inline void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes) {}
1393 /* ptlrpc/llog_server.c */
1394 int llog_origin_handle_create(struct ptlrpc_request *req);
1395 int llog_origin_handle_destroy(struct ptlrpc_request *req);
1396 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
1397 int llog_origin_handle_next_block(struct ptlrpc_request *req);
1398 int llog_origin_handle_read_header(struct ptlrpc_request *req);
1399 int llog_origin_handle_close(struct ptlrpc_request *req);
1400 int llog_origin_handle_cancel(struct ptlrpc_request *req);
1401 int llog_catinfo(struct ptlrpc_request *req);
1403 /* ptlrpc/llog_client.c */
1404 extern struct llog_operations llog_client_ops;