1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #if defined(__linux__)
27 #include <linux/lustre_net.h>
28 #elif defined(__APPLE__)
29 #include <darwin/lustre_net.h>
30 #elif defined(__WINNT__)
31 #include <winnt/lustre_net.h>
33 #error Unsupported operating system.
36 #include <libcfs/libcfs.h>
38 #include <lnet/lnet.h>
39 #include <lustre/lustre_idl.h>
40 #include <lustre_ha.h>
41 #include <lustre_sec.h>
42 #include <lustre_import.h>
43 #include <lprocfs_status.h>
44 #include <lu_object.h>
45 #include <lustre_req_layout.h>
47 /* MD flags we _always_ use */
48 #define PTLRPC_MD_OPTIONS 0
50 /* Define maxima for bulk I/O
51 * CAVEAT EMPTOR, with multinet (i.e. routers forwarding between networks)
52 * these limits are system wide and not interface-local. */
53 #define PTLRPC_MAX_BRW_BITS LNET_MTU_BITS
54 #define PTLRPC_MAX_BRW_SIZE (1<<LNET_MTU_BITS)
55 #define PTLRPC_MAX_BRW_PAGES (PTLRPC_MAX_BRW_SIZE >> CFS_PAGE_SHIFT)
57 /* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
59 # if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
60 # error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
62 # if (PTLRPC_MAX_BRW_SIZE != (PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE))
63 # error "PTLRPC_MAX_BRW_SIZE isn't PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE"
65 # if (PTLRPC_MAX_BRW_SIZE > LNET_MTU)
66 # error "PTLRPC_MAX_BRW_SIZE too big"
68 # if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV)
69 # error "PTLRPC_MAX_BRW_PAGES too big"
71 #endif /* __KERNEL__ */
73 /* Size over which to OBD_VMALLOC() rather than OBD_ALLOC() service request
75 #define SVC_BUF_VMALLOC_THRESHOLD (2 * CFS_PAGE_SIZE)
77 /* The following constants determine how memory is used to buffer incoming
80 * ?_NBUFS # buffers to allocate when growing the pool
81 * ?_BUFSIZE # bytes in a single request buffer
82 * ?_MAXREQSIZE # maximum request service will receive
84 * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
85 * of ?_NBUFS is added to the pool.
87 * Messages larger than ?_MAXREQSIZE are dropped. Request buffers are
88 * considered full when less than ?_MAXREQSIZE is left in them.
91 #define LDLM_THREADS_AUTO_MIN \
92 min((int)(num_online_cpus() * num_online_cpus() * 2), 8)
93 #define LDLM_THREADS_AUTO_MAX (LDLM_THREADS_AUTO_MIN * 16)
94 #define LDLM_BL_THREADS LDLM_THREADS_AUTO_MIN
95 #define LDLM_NBUFS (64 * num_online_cpus())
96 #define LDLM_BUFSIZE (8 * 1024)
97 #define LDLM_MAXREQSIZE (5 * 1024)
98 #define LDLM_MAXREPSIZE (1024)
100 #define MDT_MIN_THREADS 2UL
101 #define MDT_MAX_THREADS 512UL
102 #define MDT_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
103 num_physpages >> (25 - CFS_PAGE_SHIFT)), 2UL)
104 #define FLD_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
105 num_physpages >> (25 - CFS_PAGE_SHIFT)), 2UL)
106 #define SEQ_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
107 num_physpages >> (25 - CFS_PAGE_SHIFT)), 2UL)
109 /* Absolute limits */
110 #define MDS_THREADS_MIN 2
111 #define MDS_THREADS_MAX 512
112 #define MDS_THREADS_MIN_READPAGE 2
113 #define MDS_NBUFS (64 * num_online_cpus())
114 #define MDS_BUFSIZE (8 * 1024)
115 /* Assume file name length = FNAME_MAX = 256 (true for ext3).
116 * path name length = PATH_MAX = 4096
117 * LOV MD size max = EA_MAX = 4000
118 * symlink: FNAME_MAX + PATH_MAX <- largest
119 * link: FNAME_MAX + PATH_MAX (mds_rec_link < mds_rec_create)
120 * rename: FNAME_MAX + FNAME_MAX
121 * open: FNAME_MAX + EA_MAX
123 * MDS_MAXREQSIZE ~= 4736 bytes =
124 * lustre_msg + ldlm_request + mds_body + mds_rec_create + FNAME_MAX + PATH_MAX
125 * MDS_MAXREPSIZE ~= 8300 bytes = lustre_msg + llog_header
126 * or, for mds_close() and mds_reint_unlink() on a many-OST filesystem:
127 * = 9210 bytes = lustre_msg + mds_body + 160 * (easize + cookiesize)
129 * Realistic size is about 512 bytes (20 character name + 128 char symlink),
130 * except in the open case where there are a large number of OSTs in a LOV.
132 #define MDS_MAXREQSIZE (5 * 1024)
133 #define MDS_MAXREPSIZE max(9 * 1024, 280 + LOV_MAX_STRIPE_COUNT * 56)
135 /* FLD_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + md_fld */
136 #define FLD_MAXREQSIZE (160)
138 /* FLD_MAXREPSIZE == lustre_msg + ptlrpc_body + md_fld */
139 #define FLD_MAXREPSIZE (152)
141 /* SEQ_MAXREQSIZE == lustre_msg + __u32 padding + ptlrpc_body + opc + lu_range +
143 #define SEQ_MAXREQSIZE (160)
145 /* SEQ_MAXREPSIZE == lustre_msg + ptlrpc_body + lu_range */
146 #define SEQ_MAXREPSIZE (152)
148 #define MGS_THREADS_AUTO_MIN 2
149 #define MGS_THREADS_AUTO_MAX 32
150 #define MGS_NBUFS (64 * num_online_cpus())
151 #define MGS_BUFSIZE (8 * 1024)
152 #define MGS_MAXREQSIZE (7 * 1024)
153 #define MGS_MAXREPSIZE (9 * 1024)
155 /* Absolute limits */
156 #define OSS_THREADS_MIN 2
157 #define OSS_THREADS_MAX 512
158 #define OST_NBUFS (64 * num_online_cpus())
159 #define OST_BUFSIZE (8 * 1024)
160 /* OST_MAXREQSIZE ~= 4768 bytes =
161 * lustre_msg + obdo + 16 * obd_ioobj + 256 * niobuf_remote
163 * - single object with 16 pages is 512 bytes
164 * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
166 #define OST_MAXREQSIZE (5 * 1024)
167 #define OST_MAXREPSIZE (9 * 1024)
169 struct ptlrpc_connection {
170 struct list_head c_link;
171 struct hlist_node c_hash;
173 lnet_process_id_t c_peer;
174 struct obd_uuid c_remote_uuid;
178 struct ptlrpc_client {
179 __u32 cli_request_portal;
180 __u32 cli_reply_portal;
184 /* state flags of requests */
185 /* XXX only ones left are those used by the bulk descs as well! */
186 #define PTL_RPC_FL_INTR (1 << 0) /* reply wait was interrupted by user */
187 #define PTL_RPC_FL_TIMEOUT (1 << 7) /* request timed out waiting for reply */
189 #define REQ_MAX_ACK_LOCKS 8
191 union ptlrpc_async_args {
192 /* Scratchpad for passing args to completion interpreter. Users
193 * cast to the struct of their choosing, and LASSERT that this is
194 * big enough. For _tons_ of context, OBD_ALLOC a struct and store
195 * a pointer to it here. The pointer_arg ensures this struct is at
196 * least big enough for that. */
197 void *pointer_arg[9];
201 struct ptlrpc_request_set;
202 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
204 struct ptlrpc_request_set {
205 int set_remaining; /* # uncompleted requests */
206 cfs_waitq_t set_waitq;
207 cfs_waitq_t *set_wakeup_ptr;
208 struct list_head set_requests;
209 struct list_head set_cblist; /* list of completion callbacks */
210 set_interpreter_func set_interpret; /* completion callback */
211 void *set_arg; /* completion context */
212 /* locked so that any old caller can communicate requests to
213 * the set holder who can then fold them into the lock-free set */
214 spinlock_t set_new_req_lock;
215 struct list_head set_new_requests;
218 struct ptlrpc_set_cbdata {
219 struct list_head psc_item;
220 set_interpreter_func psc_interpret;
224 struct ptlrpc_bulk_desc;
227 * ptlrpc callback & work item stuff
229 struct ptlrpc_cb_id {
230 void (*cbid_fn)(lnet_event_t *ev); /* specific callback fn */
231 void *cbid_arg; /* additional arg */
234 #define RS_MAX_LOCKS 4
237 struct ptlrpc_reply_state {
238 struct ptlrpc_cb_id rs_cb_id;
239 struct list_head rs_list;
240 struct list_head rs_exp_list;
241 struct list_head rs_obd_list;
243 struct list_head rs_debug_list;
245 /* updates to following flag serialised by srv_request_lock */
246 unsigned long rs_difficult:1; /* ACK/commit stuff */
247 unsigned long rs_scheduled:1; /* being handled? */
248 unsigned long rs_scheduled_ever:1;/* any schedule attempts? */
249 unsigned long rs_handled:1; /* been handled yet? */
250 unsigned long rs_on_net:1; /* reply_out_callback pending? */
251 unsigned long rs_prealloc:1; /* rs from prealloc list */
256 struct obd_export *rs_export;
257 struct ptlrpc_service *rs_service;
258 lnet_handle_md_t rs_md_h;
259 atomic_t rs_refcount;
261 struct ptlrpc_svc_ctx *rs_svc_ctx;
262 struct lustre_msg *rs_repbuf; /* wrapper */
263 int rs_repbuf_len; /* wrapper buf length */
264 int rs_repdata_len; /* wrapper msg length */
265 struct lustre_msg *rs_msg; /* reply message */
267 /* locks awaiting client reply ACK */
269 struct lustre_handle rs_locks[RS_MAX_LOCKS];
270 ldlm_mode_t rs_modes[RS_MAX_LOCKS];
273 struct ptlrpc_thread;
276 RQ_PHASE_NEW = 0xebc0de00,
277 RQ_PHASE_RPC = 0xebc0de01,
278 RQ_PHASE_BULK = 0xebc0de02,
279 RQ_PHASE_INTERPRET = 0xebc0de03,
280 RQ_PHASE_COMPLETE = 0xebc0de04,
283 struct ptlrpc_request_pool {
285 struct list_head prp_req_list; /* list of ptlrpc_request structs */
287 void (*prp_populate)(struct ptlrpc_request_pool *, int);
293 struct ptlrpc_request {
294 int rq_type; /* one of PTL_RPC_MSG_* */
295 struct list_head rq_list;
296 struct list_head rq_timed_list; /* server-side early replies */
297 struct list_head rq_history_list; /* server-side history */
298 __u64 rq_history_seq; /* history sequence # */
301 /* client-side flags are serialized by rq_lock */
302 unsigned long rq_intr:1, rq_replied:1, rq_err:1,
303 rq_timedout:1, rq_resend:1, rq_restart:1,
305 * when ->rq_replay is set, request is kept by the client even
306 * after server commits corresponding transaction. This is
307 * used for operations that require sequence of multiple
308 * requests to be replayed. The only example currently is file
309 * open/close/dw/setattr. When last request in such a sequence
310 * is committed, ->rq_replay is cleared on all requests in the
314 /* this is the last request in the sequence. */
316 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
317 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1,
318 rq_early:1, rq_must_unlink:1,
319 /* server-side flags */
320 rq_packed_final:1, /* packed final reply */
321 rq_sent_final:1; /* stop sending early replies */
323 enum rq_phase rq_phase; /* one of RQ_PHASE_* */
324 atomic_t rq_refcount; /* client-side refcount for SENT race,
325 server-side refcounf for multiple replies */
327 struct ptlrpc_thread *rq_svc_thread; /* initial thread servicing req */
329 int rq_request_portal; /* XXX FIXME bug 249 */
330 int rq_reply_portal; /* XXX FIXME bug 249 */
332 int rq_nob_received; /* client-side # reply bytes actually received */
335 struct lustre_msg *rq_reqmsg;
338 struct lustre_msg *rq_repmsg;
341 struct list_head rq_replay_list;
342 struct list_head rq_mod_list;
344 struct ptlrpc_cli_ctx *rq_cli_ctx; /* client's half ctx */
345 struct ptlrpc_svc_ctx *rq_svc_ctx; /* server's half ctx */
346 struct list_head rq_ctx_chain; /* link to waited ctx */
348 struct sptlrpc_flavor rq_flvr; /* client & server */
349 enum lustre_sec_part rq_sp_from;
351 unsigned long /* client/server security flags */
352 rq_ctx_init:1, /* context initiation */
353 rq_ctx_fini:1, /* context destroy */
354 rq_bulk_read:1, /* request bulk read */
355 rq_bulk_write:1, /* request bulk write */
356 /* server authentication flags */
357 rq_auth_gss:1, /* authenticated by gss */
358 rq_auth_remote:1, /* authed as remote user */
359 rq_auth_usr_root:1, /* authed as root */
360 rq_auth_usr_mdt:1, /* authed as mdt */
361 /* security tfm flags */
364 /* doesn't expect reply FIXME */
367 uid_t rq_auth_uid; /* authed uid */
368 uid_t rq_auth_mapped_uid; /* authed uid mapped to */
370 /* (server side), pointed directly into req buffer */
371 struct ptlrpc_user_desc *rq_user_desc;
373 /* early replies go to offset 0, regular replies go after that */
374 unsigned int rq_reply_off;
376 /* various buffer pointers */
377 struct lustre_msg *rq_reqbuf; /* req wrapper */
378 int rq_reqbuf_len; /* req wrapper buf len */
379 int rq_reqdata_len; /* req wrapper msg len */
380 char *rq_repbuf; /* rep buffer */
381 int rq_repbuf_len; /* rep buffer len */
382 struct lustre_msg *rq_repdata; /* rep wrapper msg */
383 int rq_repdata_len; /* rep wrapper msg len */
384 struct lustre_msg *rq_clrbuf; /* only in priv mode */
385 int rq_clrbuf_len; /* only in priv mode */
386 int rq_clrdata_len; /* only in priv mode */
388 __u32 rq_req_swab_mask;
389 __u32 rq_rep_swab_mask;
391 int rq_import_generation;
392 enum lustre_imp_state rq_send_state;
394 int rq_early_count; /* how many early replies (for stats) */
396 /* client+server request */
397 lnet_handle_md_t rq_req_md_h;
398 struct ptlrpc_cb_id rq_req_cbid;
401 struct timeval rq_arrival_time; /* request arrival time */
402 struct ptlrpc_reply_state *rq_reply_state; /* separated reply state */
403 struct ptlrpc_request_buffer_desc *rq_rqbd; /* incoming request buffer*/
405 __u32 rq_uid; /* peer uid, used in MDS only */
408 /* client-only incoming reply */
409 lnet_handle_md_t rq_reply_md_h;
410 cfs_waitq_t rq_reply_waitq;
411 struct ptlrpc_cb_id rq_reply_cbid;
414 lnet_process_id_t rq_peer;
415 struct obd_export *rq_export;
416 struct obd_import *rq_import;
418 void (*rq_replay_cb)(struct ptlrpc_request *);
419 void (*rq_commit_cb)(struct ptlrpc_request *);
422 struct ptlrpc_bulk_desc *rq_bulk;/* client side bulk */
424 /* client outgoing req */
425 time_t rq_sent; /* when request/reply sent (secs), or
426 * time when request should be sent */
428 volatile time_t rq_deadline; /* when request must finish. volatile
429 so that servers' early reply updates to the deadline aren't
430 kept in per-cpu cache */
431 int rq_timeout; /* service time estimate (secs) */
434 struct list_head rq_set_chain;
435 struct ptlrpc_request_set *rq_set;
436 void *rq_interpret_reply; /* Async completion handler */
437 union ptlrpc_async_args rq_async_args; /* Async completion context */
438 struct ptlrpc_request_pool *rq_pool; /* Pool if request from
440 struct lu_context rq_session;
443 struct req_capsule rq_pill;
446 static inline void ptlrpc_close_replay_seq(struct ptlrpc_request *req)
448 spin_lock(&req->rq_lock);
450 req->rq_sequence = 1;
451 spin_unlock(&req->rq_lock);
454 static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
456 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
457 LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
458 req->rq_req_swab_mask |= 1 << index;
461 static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
463 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
464 LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
465 req->rq_rep_swab_mask |= 1 << index;
468 static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
470 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
471 return req->rq_req_swab_mask & (1 << index);
474 static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
476 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
477 return req->rq_rep_swab_mask & (1 << index);
480 static inline const char *
481 ptlrpc_rqphase2str(const struct ptlrpc_request *req)
483 switch (req->rq_phase) {
490 case RQ_PHASE_INTERPRET:
492 case RQ_PHASE_COMPLETE:
499 /* Spare the preprocessor, spoil the bugs. */
500 #define FLAG(field, str) (field ? str : "")
502 #define DEBUG_REQ_FLAGS(req) \
503 ptlrpc_rqphase2str(req), \
504 FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"), \
505 FLAG(req->rq_err, "E"), \
506 FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"), \
507 FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"), \
508 FLAG(req->rq_no_resend, "N"), \
509 FLAG(req->rq_waiting, "W"), \
510 FLAG(req->rq_wait_ctx, "C")
512 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s"
514 void _debug_req(struct ptlrpc_request *req, __u32 mask,
515 struct libcfs_debug_msg_data *data, const char *fmt, ...)
516 __attribute__ ((format (printf, 4, 5)));
518 #define debug_req(cdls, level, req, file, func, line, fmt, a...) \
522 if (((level) & D_CANTMASK) != 0 || \
523 ((libcfs_debug & (level)) != 0 && \
524 (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) { \
525 static struct libcfs_debug_msg_data _req_dbg_data = \
526 DEBUG_MSG_DATA_INIT(cdls, DEBUG_SUBSYSTEM, file, func, line); \
527 _debug_req((req), (level), &_req_dbg_data, fmt, ##a); \
531 /* for most callers (level is a constant) this is resolved at compile time */
532 #define DEBUG_REQ(level, req, fmt, args...) \
534 if ((level) & (D_ERROR | D_WARNING)) { \
535 static cfs_debug_limit_state_t cdls; \
536 debug_req(&cdls, level, req, __FILE__, __func__, __LINE__, \
537 "@@@ "fmt" ", ## args); \
539 debug_req(NULL, level, req, __FILE__, __func__, __LINE__, \
540 "@@@ "fmt" ", ## args); \
543 struct ptlrpc_bulk_page {
544 struct list_head bp_link;
546 int bp_pageoffset; /* offset within a page */
547 struct page *bp_page;
550 #define BULK_GET_SOURCE 0
551 #define BULK_PUT_SINK 1
552 #define BULK_GET_SINK 2
553 #define BULK_PUT_SOURCE 3
555 struct ptlrpc_bulk_desc {
556 unsigned long bd_success:1; /* completed successfully */
557 unsigned long bd_network_rw:1; /* accessible to the network */
558 unsigned long bd_type:2; /* {put,get}{source,sink} */
559 unsigned long bd_registered:1; /* client side */
560 spinlock_t bd_lock; /* serialise with callback */
561 int bd_import_generation;
562 struct obd_export *bd_export;
563 struct obd_import *bd_import;
565 struct ptlrpc_request *bd_req; /* associated request */
566 cfs_waitq_t bd_waitq; /* server side only WQ */
567 int bd_iov_count; /* # entries in bd_iov */
568 int bd_max_iov; /* allocated size of bd_iov */
569 int bd_nob; /* # bytes covered */
570 int bd_nob_transferred; /* # bytes GOT/PUT */
574 struct ptlrpc_cb_id bd_cbid; /* network callback info */
575 lnet_handle_md_t bd_md_h; /* associated MD */
576 lnet_nid_t bd_sender; /* stash event::sender */
578 cfs_page_t **bd_enc_pages;
579 #if defined(__KERNEL__)
580 lnet_kiov_t bd_iov[0];
582 lnet_md_iovec_t bd_iov[0];
586 struct ptlrpc_thread {
588 struct list_head t_link; /* active threads for service, from svc->srv_threads */
590 void *t_data; /* thread-private data (preallocated memory) */
593 unsigned int t_id; /* service thread index, from ptlrpc_start_threads */
594 cfs_waitq_t t_ctl_waitq;
595 struct lu_env *t_env;
598 struct ptlrpc_request_buffer_desc {
599 struct list_head rqbd_list;
600 struct list_head rqbd_reqs;
601 struct ptlrpc_service *rqbd_service;
602 lnet_handle_md_t rqbd_md_h;
605 struct ptlrpc_cb_id rqbd_cbid;
606 struct ptlrpc_request rqbd_req;
609 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
610 typedef void (*svcreq_printfn_t)(void *, struct ptlrpc_request *);
612 struct ptlrpc_service {
613 struct list_head srv_list; /* chain thru all services */
614 int srv_max_req_size; /* biggest request to receive */
615 int srv_max_reply_size; /* biggest reply to send */
616 int srv_buf_size; /* size of individual buffers */
617 int srv_nbuf_per_group; /* # buffers to allocate in 1 group */
618 int srv_nbufs; /* total # req buffer descs allocated */
619 int srv_threads_min; /* threads to start at SOW */
620 int srv_threads_max; /* thread upper limit */
621 int srv_threads_started; /* index of last started thread */
622 int srv_threads_running; /* # running threads */
623 int srv_n_difficult_replies; /* # 'difficult' replies */
624 int srv_n_active_reqs; /* # reqs being served */
625 cfs_duration_t srv_rqbd_timeout; /* timeout before re-posting reqs, in tick */
626 int srv_watchdog_factor; /* soft watchdog timeout mutiplier */
627 unsigned srv_cpu_affinity:1; /* bind threads to CPUs */
628 unsigned srv_at_check:1; /* check early replies */
629 cfs_time_t srv_at_checktime; /* debug */
631 __u32 srv_req_portal;
632 __u32 srv_rep_portal;
635 struct adaptive_timeout srv_at_estimate;/* estimated rpc service time */
636 spinlock_t srv_at_lock;
637 struct list_head srv_at_list; /* reqs waiting for replies */
638 cfs_timer_t srv_at_timer; /* early reply timer */
640 int srv_n_queued_reqs; /* # reqs in either of the queues below */
641 struct list_head srv_req_in_queue; /* incoming reqs */
642 struct list_head srv_request_queue; /* reqs waiting for service */
644 struct list_head srv_request_history; /* request history */
645 __u64 srv_request_seq; /* next request sequence # */
646 __u64 srv_request_max_cull_seq; /* highest seq culled from history */
647 svcreq_printfn_t srv_request_history_print_fn; /* service-specific print fn */
649 struct list_head srv_idle_rqbds; /* request buffers to be reposted */
650 struct list_head srv_active_rqbds; /* req buffers receiving */
651 struct list_head srv_history_rqbds; /* request buffer history */
652 int srv_nrqbd_receiving; /* # posted request buffers */
653 int srv_n_history_rqbds; /* # request buffers in history */
654 int srv_max_history_rqbds;/* max # request buffers in history */
656 atomic_t srv_outstanding_replies;
657 struct list_head srv_active_replies; /* all the active replies */
658 struct list_head srv_reply_queue; /* replies waiting for service */
660 cfs_waitq_t srv_waitq; /* all threads sleep on this. This
661 * wait-queue is signalled when new
662 * incoming request arrives and when
663 * difficult reply has to be handled. */
665 struct list_head srv_threads; /* service thread list */
666 svc_handler_t srv_handler;
668 char *srv_name; /* only statically allocated strings here; we don't clean them */
669 char *srv_thread_name; /* only statically allocated strings here; we don't clean them */
673 cfs_proc_dir_entry_t *srv_procroot;
674 struct lprocfs_stats *srv_stats;
676 /* List of free reply_states */
677 struct list_head srv_free_rs_list;
678 /* waitq to run, when adding stuff to srv_free_rs_list */
679 cfs_waitq_t srv_free_rs_waitq;
682 * Tags for lu_context associated with this thread, see struct
687 * if non-NULL called during thread creation (ptlrpc_start_thread())
688 * to initialize service specific per-thread state.
690 int (*srv_init)(struct ptlrpc_thread *thread);
692 * if non-NULL called during thread shutdown (ptlrpc_main()) to
693 * destruct state created by ->srv_init().
695 void (*srv_done)(struct ptlrpc_thread *thread);
697 //struct ptlrpc_srv_ni srv_interfaces[0];
700 /* ptlrpc/events.c */
701 extern lnet_handle_eq_t ptlrpc_eq_h;
702 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
703 lnet_process_id_t *peer, lnet_nid_t *self);
704 extern void request_out_callback (lnet_event_t *ev);
705 extern void reply_in_callback(lnet_event_t *ev);
706 extern void client_bulk_callback (lnet_event_t *ev);
707 extern void request_in_callback(lnet_event_t *ev);
708 extern void reply_out_callback(lnet_event_t *ev);
709 extern void server_bulk_callback (lnet_event_t *ev);
711 /* ptlrpc/connection.c */
712 void ptlrpc_dump_connections(void);
713 void ptlrpc_readdress_connection(struct ptlrpc_connection *, struct obd_uuid *);
714 struct ptlrpc_connection *ptlrpc_get_connection(lnet_process_id_t peer,
715 lnet_nid_t self, struct obd_uuid *uuid);
716 int ptlrpc_put_connection(struct ptlrpc_connection *c);
717 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
718 int ptlrpc_init_connection(void);
719 void ptlrpc_cleanup_connection(void);
720 extern lnet_pid_t ptl_get_pid(void);
722 /* ptlrpc/niobuf.c */
723 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
724 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
725 int ptlrpc_register_bulk(struct ptlrpc_request *req);
726 void ptlrpc_unregister_bulk (struct ptlrpc_request *req);
728 static inline int ptlrpc_bulk_active (struct ptlrpc_bulk_desc *desc)
732 spin_lock(&desc->bd_lock);
733 rc = desc->bd_network_rw;
734 spin_unlock(&desc->bd_lock);
738 #define PTLRPC_REPLY_MAYBE_DIFFICULT 0x01
739 #define PTLRPC_REPLY_EARLY 0x02
740 int ptlrpc_send_reply(struct ptlrpc_request *req, int flags);
741 int ptlrpc_reply(struct ptlrpc_request *req);
742 int ptlrpc_send_error(struct ptlrpc_request *req, int difficult);
743 int ptlrpc_error(struct ptlrpc_request *req);
744 void ptlrpc_resend_req(struct ptlrpc_request *request);
745 int ptlrpc_at_get_net_latency(struct ptlrpc_request *req);
746 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
747 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
749 /* ptlrpc/client.c */
750 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
751 struct ptlrpc_client *);
752 void ptlrpc_cleanup_client(struct obd_import *imp);
753 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
756 ptlrpc_client_recv_or_unlink (struct ptlrpc_request *req)
760 spin_lock(&req->rq_lock);
761 rc = req->rq_receiving_reply || req->rq_must_unlink;
762 spin_unlock(&req->rq_lock);
767 ptlrpc_wake_client_req (struct ptlrpc_request *req)
769 if (req->rq_set == NULL)
770 cfs_waitq_signal(&req->rq_reply_waitq);
772 cfs_waitq_signal(&req->rq_set->set_waitq);
775 int ptlrpc_queue_wait(struct ptlrpc_request *req);
776 int ptlrpc_replay_req(struct ptlrpc_request *req);
777 void ptlrpc_unregister_reply(struct ptlrpc_request *req);
778 void ptlrpc_restart_req(struct ptlrpc_request *req);
779 void ptlrpc_abort_inflight(struct obd_import *imp);
781 struct ptlrpc_request_set *ptlrpc_prep_set(void);
782 int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
783 set_interpreter_func fn, void *data);
784 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
785 int ptlrpc_check_set(struct ptlrpc_request_set *set);
786 int ptlrpc_set_wait(struct ptlrpc_request_set *);
787 int ptlrpc_expired_set(void *data);
788 void ptlrpc_interrupted_set(void *data);
789 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
790 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
791 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
792 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *,
793 struct ptlrpc_request *);
795 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
796 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
797 struct ptlrpc_request_pool *ptlrpc_init_rq_pool(int, int,
798 void (*populate_pool)(struct ptlrpc_request_pool *, int));
799 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
800 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
801 const struct req_format *format);
802 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
803 struct ptlrpc_request_pool *,
804 const struct req_format *format);
805 void ptlrpc_request_free(struct ptlrpc_request *request);
806 int ptlrpc_request_pack(struct ptlrpc_request *request,
807 __u32 version, int opcode);
808 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
809 const struct req_format *format,
810 __u32 version, int opcode);
811 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
812 __u32 version, int opcode, char **bufs,
813 struct ptlrpc_cli_ctx *ctx);
814 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
815 int opcode, int count, int *lengths,
817 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
818 __u32 version, int opcode,
819 int count, int *lengths, char **bufs,
820 struct ptlrpc_request_pool *pool);
821 void ptlrpc_free_req(struct ptlrpc_request *request);
822 void ptlrpc_req_finished(struct ptlrpc_request *request);
823 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
824 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
825 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
826 int npages, int type, int portal);
827 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
828 int npages, int type, int portal);
829 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
830 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
831 cfs_page_t *page, int pageoffset, int len);
832 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
833 struct obd_import *imp);
834 __u64 ptlrpc_next_xid(void);
835 __u64 ptlrpc_sample_next_xid(void);
836 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
838 struct ptlrpc_service_conf {
841 int psc_max_req_size;
842 int psc_max_reply_size;
845 int psc_watchdog_factor;
851 /* ptlrpc/service.c */
852 void ptlrpc_save_lock (struct ptlrpc_request *req,
853 struct lustre_handle *lock, int mode);
854 void ptlrpc_commit_replies (struct obd_device *obd);
855 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
856 struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
857 svc_handler_t h, char *name,
858 struct proc_dir_entry *proc_entry,
859 svcreq_printfn_t prntfn,
862 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
864 int req_portal, int rep_portal,
866 svc_handler_t, char *name,
867 cfs_proc_dir_entry_t *proc_entry,
869 int min_threads, int max_threads,
870 char *threadname, __u32 ctx_tags);
871 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
873 int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc);
874 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc);
875 int ptlrpc_unregister_service(struct ptlrpc_service *service);
876 int liblustre_check_services (void *arg);
877 void ptlrpc_daemonize(char *name);
878 int ptlrpc_service_health_check(struct ptlrpc_service *);
881 struct ptlrpc_svc_data {
883 struct ptlrpc_service *svc;
884 struct ptlrpc_thread *thread;
885 struct obd_device *dev;
888 /* ptlrpc/import.c */
889 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
890 int ptlrpc_init_import(struct obd_import *imp);
891 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
892 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
894 /* ptlrpc/pack_generic.c */
895 int ptlrpc_reconnect_import(struct obd_import *imp);
896 int lustre_msg_swabbed(struct lustre_msg *msg);
897 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
898 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
900 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
901 int *lens, char **bufs);
902 int lustre_pack_reply(struct ptlrpc_request *, int count, int *lens,
904 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
905 int *lens, char **bufs, int flags);
906 #define LPRFL_EARLY_REPLY 1
907 int lustre_pack_reply_flags(struct ptlrpc_request *, int count, int *lens,
908 char **bufs, int flags);
909 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
910 unsigned int newlen, int move_data);
911 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
912 int lustre_msg_hdr_size(__u32 magic, int count);
913 int lustre_msg_size(__u32 magic, int count, int *lengths);
914 int lustre_msg_size_v2(int count, int *lengths);
915 int lustre_packed_msg_size(struct lustre_msg *msg);
916 int lustre_msg_early_size(void);
917 int lustre_unpack_msg(struct lustre_msg *m, int len);
918 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
919 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
920 int lustre_msg_buflen(struct lustre_msg *m, int n);
921 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
922 int lustre_msg_bufcount(struct lustre_msg *m);
923 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
924 void *lustre_swab_buf(struct lustre_msg *, int n, int minlen, void *swabber);
925 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int n, int minlen,
927 void *lustre_swab_repbuf(struct ptlrpc_request *req, int n, int minlen,
929 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
930 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags);
931 __u32 lustre_msg_get_flags(struct lustre_msg *msg);
932 void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
933 void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
934 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
935 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
936 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
937 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
938 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
939 __u32 lustre_msg_get_type(struct lustre_msg *msg);
940 __u32 lustre_msg_get_version(struct lustre_msg *msg);
941 void lustre_msg_add_version(struct lustre_msg *msg, int version);
942 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
943 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
944 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
945 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
946 __u64 lustre_msg_get_slv(struct lustre_msg *msg);
947 __u32 lustre_msg_get_limit(struct lustre_msg *msg);
948 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
949 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
950 int lustre_msg_get_status(struct lustre_msg *msg);
951 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
952 int lustre_msg_is_v1(struct lustre_msg *msg);
953 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
954 __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
955 __u32 lustre_msg_get_service_time(struct lustre_msg *msg);
956 __u32 lustre_msg_get_cksum(struct lustre_msg *msg);
957 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
958 void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
959 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
960 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
961 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
962 void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed);
963 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
964 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
965 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
966 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, int *sizes);
967 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
968 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
969 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
970 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum);
973 lustre_shrink_reply(struct ptlrpc_request *req, int segment,
974 unsigned int newlen, int move_data)
976 LASSERT(req->rq_reply_state);
977 LASSERT(req->rq_repmsg);
978 req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
983 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
985 LASSERT(atomic_read(&rs->rs_refcount) > 0);
986 atomic_inc(&rs->rs_refcount);
990 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
992 LASSERT(atomic_read(&rs->rs_refcount) > 0);
993 if (atomic_dec_and_test(&rs->rs_refcount))
994 lustre_free_reply_state(rs);
997 /* Should only be called once per req */
998 static inline void ptlrpc_req_drop_rs(struct ptlrpc_request *req)
1000 if (req->rq_reply_state == NULL)
1001 return; /* shouldn't occur */
1002 ptlrpc_rs_decref(req->rq_reply_state);
1003 req->rq_reply_state = NULL;
1004 req->rq_repmsg = NULL;
1007 static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
1009 return lustre_msg_get_magic(req->rq_reqmsg);
1012 static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
1014 switch (req->rq_reqmsg->lm_magic) {
1015 case LUSTRE_MSG_MAGIC_V2:
1016 return req->rq_reqmsg->lm_repsize;
1018 LASSERTF(0, "incorrect message magic: %08x\n",
1019 req->rq_reqmsg->lm_magic);
1024 /* ldlm/ldlm_lib.c */
1025 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
1026 int client_obd_cleanup(struct obd_device *obddev);
1027 int client_connect_import(const struct lu_env *env,
1028 struct lustre_handle *conn, struct obd_device *obd,
1029 struct obd_uuid *cluuid, struct obd_connect_data *,
1031 int client_disconnect_export(struct obd_export *exp);
1032 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
1034 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
1035 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
1037 /* ptlrpc/pinger.c */
1038 int ptlrpc_pinger_add_import(struct obd_import *imp);
1039 int ptlrpc_pinger_del_import(struct obd_import *imp);
1040 cfs_time_t ptlrpc_suspend_wakeup_time(void);
1042 void ping_evictor_start(void);
1043 void ping_evictor_stop(void);
1045 #define ping_evictor_start() do {} while (0)
1046 #define ping_evictor_stop() do {} while (0)
1048 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req);
1050 /* ptlrpc/ptlrpcd.c */
1051 void ptlrpcd_wake(struct ptlrpc_request *req);
1052 void ptlrpcd_add_req(struct ptlrpc_request *req);
1053 int ptlrpcd_addref(void);
1054 void ptlrpcd_decref(void);
1056 /* ptlrpc/lproc_ptlrpc.c */
1057 const char* ll_opcode2str(__u32 opcode);
1059 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
1060 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
1061 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int opc, int bytes);
1063 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
1064 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
1065 static inline void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int opc,
1069 /* ptlrpc/llog_server.c */
1070 int llog_origin_handle_create(struct ptlrpc_request *req);
1071 int llog_origin_handle_destroy(struct ptlrpc_request *req);
1072 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
1073 int llog_origin_handle_next_block(struct ptlrpc_request *req);
1074 int llog_origin_handle_read_header(struct ptlrpc_request *req);
1075 int llog_origin_handle_close(struct ptlrpc_request *req);
1076 int llog_origin_handle_cancel(struct ptlrpc_request *req);
1077 int llog_catinfo(struct ptlrpc_request *req);
1079 /* ptlrpc/llog_client.c */
1080 extern struct llog_operations llog_client_ops;