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/kp30.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 - PAGE_SHIFT)), 2UL)
104 #define FLD_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
105 num_physpages >> (25 - PAGE_SHIFT)), 2UL)
106 #define SEQ_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
107 num_physpages >> (25 - 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_history_list; /* server-side history */
297 __u64 rq_history_seq; /* history sequence # */
300 /* client-side flags */
301 unsigned long rq_intr:1, rq_replied:1, rq_err:1,
302 rq_timedout:1, rq_resend:1, rq_restart:1,
304 * when ->rq_replay is set, request is kept by the client even
305 * after server commits corresponding transaction. This is
306 * used for operations that require sequence of multiple
307 * requests to be replayed. The only example currently is file
308 * open/close/dw/setattr. When last request in such a sequence
309 * is committed, ->rq_replay is cleared on all requests in the
313 /* this is the last request in the sequence. */
315 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
316 rq_no_delay:1, rq_net_err:1, rq_wait_ctx:1;
317 enum rq_phase rq_phase; /* one of RQ_PHASE_* */
318 atomic_t rq_refcount; /* client-side refcount for SENT race */
320 struct ptlrpc_thread *rq_svc_thread; /* initial thread servicing req */
322 int rq_request_portal; /* XXX FIXME bug 249 */
323 int rq_reply_portal; /* XXX FIXME bug 249 */
325 int rq_nob_received; /* client-side # reply bytes actually received */
328 struct lustre_msg *rq_reqmsg;
330 int rq_timeout; /* time to wait for reply (seconds) */
332 struct lustre_msg *rq_repmsg;
335 struct list_head rq_replay_list;
336 struct list_head rq_mod_list;
338 struct ptlrpc_cli_ctx *rq_cli_ctx; /* client's half ctx */
339 struct ptlrpc_svc_ctx *rq_svc_ctx; /* server's half ctx */
340 struct list_head rq_ctx_chain; /* link to waited ctx */
342 struct sptlrpc_flavor rq_flvr; /* client & server */
343 enum lustre_sec_part rq_sp_from;
345 unsigned long /* client/server security flags */
346 rq_ctx_init:1, /* context initiation */
347 rq_ctx_fini:1, /* context destroy */
348 rq_bulk_read:1, /* request bulk read */
349 rq_bulk_write:1, /* request bulk write */
350 /* server authentication flags */
351 rq_auth_gss:1, /* authenticated by gss */
352 rq_auth_remote:1, /* authed as remote user */
353 rq_auth_usr_root:1, /* authed as root */
354 rq_auth_usr_mdt:1, /* authed as mdt */
355 /* security tfm flags */
358 /* doesn't expect reply FIXME */
361 uid_t rq_auth_uid; /* authed uid */
362 uid_t rq_auth_mapped_uid; /* authed uid mapped to */
364 /* (server side), pointed directly into req buffer */
365 struct ptlrpc_user_desc *rq_user_desc;
367 /* various buffer pointers */
368 struct lustre_msg *rq_reqbuf; /* req wrapper */
369 int rq_reqbuf_len; /* req wrapper buf len */
370 int rq_reqdata_len; /* req wrapper msg len */
371 struct lustre_msg *rq_repbuf; /* rep wrapper */
372 int rq_repbuf_len; /* rep wrapper buf len */
373 int rq_repdata_len; /* rep wrapper msg len */
374 struct lustre_msg *rq_clrbuf; /* only in priv mode */
375 int rq_clrbuf_len; /* only in priv mode */
376 int rq_clrdata_len; /* only in priv mode */
378 __u32 rq_req_swab_mask;
379 __u32 rq_rep_swab_mask;
381 int rq_import_generation;
382 enum lustre_imp_state rq_send_state;
384 /* client+server request */
385 lnet_handle_md_t rq_req_md_h;
386 struct ptlrpc_cb_id rq_req_cbid;
389 struct timeval rq_arrival_time; /* request arrival time */
390 struct ptlrpc_reply_state *rq_reply_state; /* separated reply state */
391 struct ptlrpc_request_buffer_desc *rq_rqbd; /* incoming request buffer*/
393 __u32 rq_uid; /* peer uid, used in MDS only */
396 /* client-only incoming reply */
397 lnet_handle_md_t rq_reply_md_h;
398 cfs_waitq_t rq_reply_waitq;
399 struct ptlrpc_cb_id rq_reply_cbid;
402 lnet_process_id_t rq_peer;
403 struct obd_export *rq_export;
404 struct obd_import *rq_import;
406 void (*rq_replay_cb)(struct ptlrpc_request *);
407 void (*rq_commit_cb)(struct ptlrpc_request *);
410 struct ptlrpc_bulk_desc *rq_bulk; /* client side bulk */
411 time_t rq_sent; /* when request sent, seconds,
412 * or time when request should
415 struct list_head rq_set_chain;
416 struct ptlrpc_request_set *rq_set;
417 void *rq_interpret_reply; /* Async completion handler */
418 union ptlrpc_async_args rq_async_args; /* Async completion context */
419 struct ptlrpc_request_pool *rq_pool; /* Pool if request from
421 struct lu_context rq_session;
424 struct req_capsule rq_pill;
427 static inline void ptlrpc_close_replay_seq(struct ptlrpc_request *req)
429 spin_lock(&req->rq_lock);
431 req->rq_sequence = 1;
432 spin_unlock(&req->rq_lock);
435 static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
437 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
438 LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
439 req->rq_req_swab_mask |= 1 << index;
442 static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
444 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
445 LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
446 req->rq_rep_swab_mask |= 1 << index;
449 static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
451 LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
452 return req->rq_req_swab_mask & (1 << index);
455 static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
457 LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
458 return req->rq_rep_swab_mask & (1 << index);
461 static inline const char *
462 ptlrpc_rqphase2str(const struct ptlrpc_request *req)
464 switch (req->rq_phase) {
471 case RQ_PHASE_INTERPRET:
473 case RQ_PHASE_COMPLETE:
480 /* Spare the preprocessor, spoil the bugs. */
481 #define FLAG(field, str) (field ? str : "")
483 #define DEBUG_REQ_FLAGS(req) \
484 ptlrpc_rqphase2str(req), \
485 FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"), \
486 FLAG(req->rq_err, "E"), \
487 FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"), \
488 FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"), \
489 FLAG(req->rq_no_resend, "N"), \
490 FLAG(req->rq_waiting, "W"), \
491 FLAG(req->rq_wait_ctx, "C")
493 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s%s"
495 void _debug_req(struct ptlrpc_request *req, __u32 mask,
496 struct libcfs_debug_msg_data *data, const char *fmt, ...)
497 __attribute__ ((format (printf, 4, 5)));
499 #define debug_req(cdls, level, req, file, func, line, fmt, a...) \
503 if (((level) & D_CANTMASK) != 0 || \
504 ((libcfs_debug & (level)) != 0 && \
505 (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) { \
506 static struct libcfs_debug_msg_data _req_dbg_data = \
507 DEBUG_MSG_DATA_INIT(cdls, DEBUG_SUBSYSTEM, file, func, line); \
508 _debug_req((req), (level), &_req_dbg_data, fmt, ##a); \
512 /* for most callers (level is a constant) this is resolved at compile time */
513 #define DEBUG_REQ(level, req, fmt, args...) \
515 if ((level) & (D_ERROR | D_WARNING)) { \
516 static cfs_debug_limit_state_t cdls; \
517 debug_req(&cdls, level, req, __FILE__, __func__, __LINE__, \
518 "@@@ "fmt" ", ## args); \
520 debug_req(NULL, level, req, __FILE__, __func__, __LINE__, \
521 "@@@ "fmt" ", ## args); \
524 struct ptlrpc_bulk_page {
525 struct list_head bp_link;
527 int bp_pageoffset; /* offset within a page */
528 struct page *bp_page;
531 #define BULK_GET_SOURCE 0
532 #define BULK_PUT_SINK 1
533 #define BULK_GET_SINK 2
534 #define BULK_PUT_SOURCE 3
536 struct ptlrpc_bulk_desc {
537 unsigned long bd_success:1; /* completed successfully */
538 unsigned long bd_network_rw:1; /* accessible to the network */
539 unsigned long bd_type:2; /* {put,get}{source,sink} */
540 unsigned long bd_registered:1; /* client side */
541 spinlock_t bd_lock; /* serialise with callback */
542 int bd_import_generation;
543 struct obd_export *bd_export;
544 struct obd_import *bd_import;
546 struct ptlrpc_request *bd_req; /* associated request */
547 cfs_waitq_t bd_waitq; /* server side only WQ */
548 int bd_iov_count; /* # entries in bd_iov */
549 int bd_max_iov; /* allocated size of bd_iov */
550 int bd_nob; /* # bytes covered */
551 int bd_nob_transferred; /* # bytes GOT/PUT */
555 struct ptlrpc_cb_id bd_cbid; /* network callback info */
556 lnet_handle_md_t bd_md_h; /* associated MD */
557 lnet_nid_t bd_sender; /* stash event::sender */
559 cfs_page_t **bd_enc_pages;
560 #if defined(__KERNEL__)
561 lnet_kiov_t bd_iov[0];
563 lnet_md_iovec_t bd_iov[0];
567 struct ptlrpc_thread {
569 struct list_head t_link; /* active threads for service, from svc->srv_threads */
571 void *t_data; /* thread-private data (preallocated memory) */
574 unsigned int t_id; /* service thread index, from ptlrpc_start_threads */
575 cfs_waitq_t t_ctl_waitq;
576 struct lu_env *t_env;
579 struct ptlrpc_request_buffer_desc {
580 struct list_head rqbd_list;
581 struct list_head rqbd_reqs;
582 struct ptlrpc_service *rqbd_service;
583 lnet_handle_md_t rqbd_md_h;
586 struct ptlrpc_cb_id rqbd_cbid;
587 struct ptlrpc_request rqbd_req;
590 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
591 typedef void (*svcreq_printfn_t)(void *, struct ptlrpc_request *);
593 struct ptlrpc_service {
594 struct list_head srv_list; /* chain thru all services */
595 int srv_max_req_size; /* biggest request to receive */
596 int srv_max_reply_size; /* biggest reply to send */
597 int srv_buf_size; /* size of individual buffers */
598 int srv_nbuf_per_group; /* # buffers to allocate in 1 group */
599 int srv_nbufs; /* total # req buffer descs allocated */
600 int srv_threads_min; /* threads to start at SOW */
601 int srv_threads_max; /* thread upper limit */
602 int srv_threads_started; /* index of last started thread */
603 int srv_threads_running; /* # running threads */
604 int srv_n_difficult_replies; /* # 'difficult' replies */
605 int srv_n_active_reqs; /* # reqs being served */
606 cfs_duration_t srv_rqbd_timeout; /* timeout before re-posting reqs, in tick */
607 int srv_watchdog_timeout; /* soft watchdog timeout, in ms */
608 unsigned srv_cpu_affinity:1; /* bind threads to CPUs */
610 __u32 srv_req_portal;
611 __u32 srv_rep_portal;
613 int srv_n_queued_reqs; /* # reqs waiting to be served */
614 struct list_head srv_request_queue; /* reqs waiting for service */
616 struct list_head srv_request_history; /* request history */
617 __u64 srv_request_seq; /* next request sequence # */
618 __u64 srv_request_max_cull_seq; /* highest seq culled from history */
619 svcreq_printfn_t srv_request_history_print_fn; /* service-specific print fn */
621 struct list_head srv_idle_rqbds; /* request buffers to be reposted */
622 struct list_head srv_active_rqbds; /* req buffers receiving */
623 struct list_head srv_history_rqbds; /* request buffer history */
624 int srv_nrqbd_receiving; /* # posted request buffers */
625 int srv_n_history_rqbds; /* # request buffers in history */
626 int srv_max_history_rqbds;/* max # request buffers in history */
628 atomic_t srv_outstanding_replies;
629 struct list_head srv_active_replies; /* all the active replies */
630 struct list_head srv_reply_queue; /* replies waiting for service */
632 cfs_waitq_t srv_waitq; /* all threads sleep on this. This
633 * wait-queue is signalled when new
634 * incoming request arrives and when
635 * difficult reply has to be handled. */
637 struct list_head srv_threads; /* service thread list */
638 svc_handler_t srv_handler;
640 char *srv_name; /* only statically allocated strings here; we don't clean them */
641 char *srv_thread_name; /* only statically allocated strings here; we don't clean them */
645 cfs_proc_dir_entry_t *srv_procroot;
646 struct lprocfs_stats *srv_stats;
648 /* List of free reply_states */
649 struct list_head srv_free_rs_list;
650 /* waitq to run, when adding stuff to srv_free_rs_list */
651 cfs_waitq_t srv_free_rs_waitq;
654 * Tags for lu_context associated with this thread, see struct
659 * if non-NULL called during thread creation (ptlrpc_start_thread())
660 * to initialize service specific per-thread state.
662 int (*srv_init)(struct ptlrpc_thread *thread);
664 * if non-NULL called during thread shutdown (ptlrpc_main()) to
665 * destruct state created by ->srv_init().
667 void (*srv_done)(struct ptlrpc_thread *thread);
669 //struct ptlrpc_srv_ni srv_interfaces[0];
672 /* ptlrpc/events.c */
673 extern lnet_handle_eq_t ptlrpc_eq_h;
674 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
675 lnet_process_id_t *peer, lnet_nid_t *self);
676 extern void request_out_callback (lnet_event_t *ev);
677 extern void reply_in_callback(lnet_event_t *ev);
678 extern void client_bulk_callback (lnet_event_t *ev);
679 extern void request_in_callback(lnet_event_t *ev);
680 extern void reply_out_callback(lnet_event_t *ev);
681 extern void server_bulk_callback (lnet_event_t *ev);
683 /* ptlrpc/connection.c */
684 void ptlrpc_dump_connections(void);
685 void ptlrpc_readdress_connection(struct ptlrpc_connection *, struct obd_uuid *);
686 struct ptlrpc_connection *ptlrpc_get_connection(lnet_process_id_t peer,
687 lnet_nid_t self, struct obd_uuid *uuid);
688 int ptlrpc_put_connection(struct ptlrpc_connection *c);
689 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
690 int ptlrpc_init_connection(void);
691 void ptlrpc_cleanup_connection(void);
692 extern lnet_pid_t ptl_get_pid(void);
694 /* ptlrpc/niobuf.c */
695 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
696 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
697 int ptlrpc_register_bulk(struct ptlrpc_request *req);
698 void ptlrpc_unregister_bulk (struct ptlrpc_request *req);
700 static inline int ptlrpc_bulk_active (struct ptlrpc_bulk_desc *desc)
704 spin_lock(&desc->bd_lock);
705 rc = desc->bd_network_rw;
706 spin_unlock(&desc->bd_lock);
710 int ptlrpc_send_reply(struct ptlrpc_request *req, int);
711 int ptlrpc_reply(struct ptlrpc_request *req);
712 int ptlrpc_error(struct ptlrpc_request *req);
713 void ptlrpc_resend_req(struct ptlrpc_request *request);
714 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
715 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
717 /* ptlrpc/client.c */
718 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
719 struct ptlrpc_client *);
720 void ptlrpc_cleanup_client(struct obd_import *imp);
721 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
724 ptlrpc_client_receiving_reply (struct ptlrpc_request *req)
728 spin_lock(&req->rq_lock);
729 rc = req->rq_receiving_reply;
730 spin_unlock(&req->rq_lock);
735 ptlrpc_client_replied (struct ptlrpc_request *req)
739 spin_lock(&req->rq_lock);
740 rc = req->rq_replied;
741 spin_unlock(&req->rq_lock);
746 ptlrpc_wake_client_req (struct ptlrpc_request *req)
748 if (req->rq_set == NULL)
749 cfs_waitq_signal(&req->rq_reply_waitq);
751 cfs_waitq_signal(&req->rq_set->set_waitq);
754 int ptlrpc_queue_wait(struct ptlrpc_request *req);
755 int ptlrpc_replay_req(struct ptlrpc_request *req);
756 void ptlrpc_unregister_reply(struct ptlrpc_request *req);
757 void ptlrpc_restart_req(struct ptlrpc_request *req);
758 void ptlrpc_abort_inflight(struct obd_import *imp);
760 struct ptlrpc_request_set *ptlrpc_prep_set(void);
761 int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
762 set_interpreter_func fn, void *data);
763 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
764 int ptlrpc_check_set(struct ptlrpc_request_set *set);
765 int ptlrpc_set_wait(struct ptlrpc_request_set *);
766 int ptlrpc_expired_set(void *data);
767 void ptlrpc_interrupted_set(void *data);
768 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
769 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
770 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
771 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *,
772 struct ptlrpc_request *);
774 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
775 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
776 struct ptlrpc_request_pool *ptlrpc_init_rq_pool(int, int,
777 void (*populate_pool)(struct ptlrpc_request_pool *, int));
778 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
779 const struct req_format *format);
780 struct ptlrpc_request *ptlrpc_request_alloc_pool(struct obd_import *imp,
781 struct ptlrpc_request_pool *,
782 const struct req_format *format);
783 void ptlrpc_request_free(struct ptlrpc_request *request);
784 int ptlrpc_request_pack(struct ptlrpc_request *request,
785 __u32 version, int opcode);
786 struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
787 const struct req_format *format,
788 __u32 version, int opcode);
789 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
790 __u32 version, int opcode, char **bufs,
791 struct ptlrpc_cli_ctx *ctx);
792 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
793 int opcode, int count, int *lengths,
795 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
796 __u32 version, int opcode,
797 int count, int *lengths, char **bufs,
798 struct ptlrpc_request_pool *pool);
799 void ptlrpc_free_req(struct ptlrpc_request *request);
800 void ptlrpc_req_finished(struct ptlrpc_request *request);
801 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
802 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
803 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
804 int npages, int type, int portal);
805 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
806 int npages, int type, int portal);
807 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
808 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
809 cfs_page_t *page, int pageoffset, int len);
810 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
811 struct obd_import *imp);
812 __u64 ptlrpc_next_xid(void);
813 __u64 ptlrpc_sample_next_xid(void);
814 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
816 struct ptlrpc_service_conf {
819 int psc_max_req_size;
820 int psc_max_reply_size;
823 int psc_watchdog_timeout; /* in ms */
829 /* ptlrpc/service.c */
830 void ptlrpc_save_lock (struct ptlrpc_request *req,
831 struct lustre_handle *lock, int mode);
832 void ptlrpc_commit_replies (struct obd_device *obd);
833 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
834 struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
835 svc_handler_t h, char *name,
836 struct proc_dir_entry *proc_entry,
837 svcreq_printfn_t prntfn,
840 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
842 int req_portal, int rep_portal,
843 int watchdog_timeout, /* in ms */
844 svc_handler_t, char *name,
845 cfs_proc_dir_entry_t *proc_entry,
847 int min_threads, int max_threads,
848 char *threadname, __u32 ctx_tags);
849 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
851 int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc);
852 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc);
853 int ptlrpc_unregister_service(struct ptlrpc_service *service);
854 int liblustre_check_services (void *arg);
855 void ptlrpc_daemonize(char *name);
856 int ptlrpc_service_health_check(struct ptlrpc_service *);
859 struct ptlrpc_svc_data {
861 struct ptlrpc_service *svc;
862 struct ptlrpc_thread *thread;
863 struct obd_device *dev;
866 /* ptlrpc/import.c */
867 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
868 int ptlrpc_init_import(struct obd_import *imp);
869 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
870 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
872 /* ptlrpc/pack_generic.c */
873 int ptlrpc_reconnect_import(struct obd_import *imp);
874 int lustre_msg_swabbed(struct lustre_msg *msg);
875 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
876 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
878 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
879 int *lens, char **bufs);
880 int lustre_pack_reply(struct ptlrpc_request *, int count, int *lens,
882 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
883 int *lens, char **bufs);
884 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
885 unsigned int newlen, int move_data);
886 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
887 int lustre_msg_hdr_size(__u32 magic, int count);
888 int lustre_msg_size(__u32 magic, int count, int *lengths);
889 int lustre_msg_size_v2(int count, int *lengths);
890 int lustre_packed_msg_size(struct lustre_msg *msg);
891 int lustre_unpack_msg(struct lustre_msg *m, int len);
892 void *lustre_msg_buf_v1(void *msg, int n, int min_size);
893 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
894 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
895 int lustre_msg_buflen(struct lustre_msg *m, int n);
896 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
897 int lustre_msg_bufcount(struct lustre_msg *m);
898 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
899 void *lustre_swab_buf(struct lustre_msg *, int n, int minlen, void *swabber);
900 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int n, int minlen,
902 void *lustre_swab_repbuf(struct ptlrpc_request *req, int n, int minlen,
904 __u32 lustre_msg_get_flags(struct lustre_msg *msg);
905 void lustre_msg_add_flags(struct lustre_msg *msg, int flags);
906 void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
907 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
908 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
909 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
910 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
911 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
912 __u32 lustre_msg_get_type(struct lustre_msg *msg);
913 __u32 lustre_msg_get_version(struct lustre_msg *msg);
914 void lustre_msg_add_version(struct lustre_msg *msg, int version);
915 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
916 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
917 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
918 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
919 __u64 lustre_msg_get_slv(struct lustre_msg *msg);
920 __u32 lustre_msg_get_limit(struct lustre_msg *msg);
921 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
922 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
923 int lustre_msg_get_status(struct lustre_msg *msg);
924 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
925 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
926 void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle);
927 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
928 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
929 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
930 void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed);
931 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
932 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
933 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
934 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, int *sizes);
935 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
938 lustre_shrink_reply(struct ptlrpc_request *req, int segment,
939 unsigned int newlen, int move_data)
941 LASSERT(req->rq_reply_state);
942 LASSERT(req->rq_repmsg);
943 req->rq_replen = lustre_shrink_msg(req->rq_repmsg, segment,
948 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
950 LASSERT(atomic_read(&rs->rs_refcount) > 0);
951 atomic_inc(&rs->rs_refcount);
955 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
957 LASSERT(atomic_read(&rs->rs_refcount) > 0);
958 if (atomic_dec_and_test(&rs->rs_refcount))
959 lustre_free_reply_state(rs);
962 static inline __u32 lustre_request_magic(struct ptlrpc_request *req)
964 return lustre_msg_get_magic(req->rq_reqmsg);
967 static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req)
969 switch (req->rq_reqmsg->lm_magic) {
970 case LUSTRE_MSG_MAGIC_V1:
971 CERROR("function not supported for lustre_msg V1!\n");
973 case LUSTRE_MSG_MAGIC_V2:
974 return req->rq_reqmsg->lm_repsize;
976 LASSERTF(0, "incorrect message magic: %08x\n",
977 req->rq_reqmsg->lm_magic);
982 /* ldlm/ldlm_lib.c */
983 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
984 int client_obd_cleanup(struct obd_device *obddev);
985 int client_connect_import(const struct lu_env *env,
986 struct lustre_handle *conn, struct obd_device *obd,
987 struct obd_uuid *cluuid, struct obd_connect_data *,
989 int client_disconnect_export(struct obd_export *exp);
990 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
992 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
993 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
995 /* ptlrpc/pinger.c */
996 int ptlrpc_pinger_add_import(struct obd_import *imp);
997 int ptlrpc_pinger_del_import(struct obd_import *imp);
998 cfs_time_t ptlrpc_suspend_wakeup_time(void);
1000 void ping_evictor_start(void);
1001 void ping_evictor_stop(void);
1003 #define ping_evictor_start() do {} while (0)
1004 #define ping_evictor_stop() do {} while (0)
1006 int ptlrpc_check_and_wait_suspend(struct ptlrpc_request *req);
1008 /* ptlrpc/ptlrpcd.c */
1009 void ptlrpcd_wake(struct ptlrpc_request *req);
1010 void ptlrpcd_add_req(struct ptlrpc_request *req);
1011 int ptlrpcd_addref(void);
1012 void ptlrpcd_decref(void);
1014 /* ptlrpc/lproc_ptlrpc.c */
1015 const char* ll_opcode2str(__u32 opcode);
1017 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
1018 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
1019 void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int opc, int bytes);
1021 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
1022 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
1023 static inline void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int opc,
1027 /* ptlrpc/llog_server.c */
1028 int llog_origin_handle_create(struct ptlrpc_request *req);
1029 int llog_origin_handle_destroy(struct ptlrpc_request *req);
1030 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
1031 int llog_origin_handle_next_block(struct ptlrpc_request *req);
1032 int llog_origin_handle_read_header(struct ptlrpc_request *req);
1033 int llog_origin_handle_close(struct ptlrpc_request *req);
1034 int llog_origin_handle_cancel(struct ptlrpc_request *req);
1035 int llog_catinfo(struct ptlrpc_request *req);
1037 /* ptlrpc/llog_client.c */
1038 extern struct llog_operations llog_client_ops;