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_import.h>
42 #include <lprocfs_status.h>
44 /* MD flags we _always_ use */
45 #define PTLRPC_MD_OPTIONS 0
47 /* Define maxima for bulk I/O
48 * CAVEAT EMPTOR, with multinet (i.e. routers forwarding between networks)
49 * these limits are system wide and not interface-local. */
50 #define PTLRPC_MAX_BRW_SIZE LNET_MTU
51 #define PTLRPC_MAX_BRW_PAGES (PTLRPC_MAX_BRW_SIZE/CFS_PAGE_SIZE)
53 /* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
55 # if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
56 # error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
58 # if (PTLRPC_MAX_BRW_SIZE != (PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE))
59 # error "PTLRPC_MAX_BRW_SIZE isn't PTLRPC_MAX_BRW_PAGES * CFS_PAGE_SIZE"
61 # if (PTLRPC_MAX_BRW_SIZE > LNET_MTU)
62 # error "PTLRPC_MAX_BRW_SIZE too big"
64 # if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV)
65 # error "PTLRPC_MAX_BRW_PAGES too big"
67 #endif /* __KERNEL__ */
69 /* Size over which to OBD_VMALLOC() rather than OBD_ALLOC() service request
71 #define SVC_BUF_VMALLOC_THRESHOLD (2 * PAGE_SIZE)
73 /* The following constants determine how memory is used to buffer incoming
76 * ?_NBUFS # buffers to allocate when growing the pool
77 * ?_BUFSIZE # bytes in a single request buffer
78 * ?_MAXREQSIZE # maximum request service will receive
80 * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
81 * of ?_NBUFS is added to the pool.
83 * Messages larger than ?_MAXREQSIZE are dropped. Request buffers are
84 * considered full when less than ?_MAXREQSIZE is left in them.
87 #define LDLM_NUM_THREADS min((int)(smp_num_cpus * smp_num_cpus * 8), 64)
88 #define LDLM_NBUFS (64 * smp_num_cpus)
89 #define LDLM_BUFSIZE (8 * 1024)
90 #define LDLM_MAXREQSIZE (5 * 1024)
91 #define LDLM_MAXREPSIZE (1024)
93 #define MDT_MIN_THREADS 2UL
94 #define MDT_MAX_THREADS 32UL
95 #define MDT_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
96 num_physpages >> (25 - PAGE_SHIFT)), 2UL)
97 #define FLD_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
98 num_physpages >> (25 - PAGE_SHIFT)), 2UL)
100 #define MDS_MAX_THREADS 512UL
101 #define MDS_DEF_THREADS max(2UL, min_t(unsigned long, 32, \
102 num_physpages * smp_num_cpus >> (26 - PAGE_SHIFT)))
103 #define MDS_NBUFS (64 * smp_num_cpus)
104 #define MDS_BUFSIZE (8 * 1024)
105 /* Assume file name length = FNAME_MAX = 256 (true for ext3).
106 * path name length = PATH_MAX = 4096
107 * LOV MD size max = EA_MAX = 4000
108 * symlink: FNAME_MAX + PATH_MAX <- largest
109 * link: FNAME_MAX + PATH_MAX (mds_rec_link < mds_rec_create)
110 * rename: FNAME_MAX + FNAME_MAX
111 * open: FNAME_MAX + EA_MAX
113 * MDS_MAXREQSIZE ~= 4736 bytes =
114 * lustre_msg + ldlm_request + mds_body + mds_rec_create + FNAME_MAX + PATH_MAX
115 * MDS_MAXREPSIZE ~= 8300 bytes = lustre_msg + llog_header
116 * or, for mds_close() and mds_reint_unlink() on a many-OST filesystem:
117 * = 9210 bytes = lustre_msg + mds_body + 160 * (easize + cookiesize)
119 * Realistic size is about 512 bytes (20 character name + 128 char symlink),
120 * except in the open case where there are a large number of OSTs in a LOV.
122 #define MDS_MAXREQSIZE (5 * 1024)
123 #define MDS_MAXREPSIZE max(9 * 1024, 280 + LOV_MAX_STRIPE_COUNT * 56)
125 /* FIXME fix all constants here. Andreas suggests dyamically adding threads. */
126 #define MGS_MAX_THREADS 8UL
127 #define MGS_NUM_THREADS max(2UL, min_t(unsigned long, MGS_MAX_THREADS, \
128 num_physpages * smp_num_cpus >> (26 - PAGE_SHIFT)))
130 #define MGS_NBUFS (64 * smp_num_cpus)
131 #define MGS_BUFSIZE (8 * 1024)
132 #define MGS_MAXREQSIZE (5 * 1024)
133 #define MGS_MAXREPSIZE (9 * 1024)
135 #define OST_MAX_THREADS 512UL
136 #define OST_DEF_THREADS max_t(unsigned long, 2, \
137 (num_physpages >> (26-PAGE_SHIFT)) * smp_num_cpus)
138 #define OST_NBUFS (64 * smp_num_cpus)
139 #define OST_BUFSIZE (8 * 1024)
140 /* OST_MAXREQSIZE ~= 4768 bytes =
141 * lustre_msg + obdo + 16 * obd_ioobj + 256 * niobuf_remote
143 * - single object with 16 pages is 512 bytes
144 * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
146 #define OST_MAXREQSIZE (5 * 1024)
147 #define OST_MAXREPSIZE (9 * 1024)
149 struct ptlrpc_connection {
150 struct list_head c_link;
152 lnet_process_id_t c_peer;
153 struct obd_uuid c_remote_uuid;
157 struct ptlrpc_client {
158 __u32 cli_request_portal;
159 __u32 cli_reply_portal;
163 /* state flags of requests */
164 /* XXX only ones left are those used by the bulk descs as well! */
165 #define PTL_RPC_FL_INTR (1 << 0) /* reply wait was interrupted by user */
166 #define PTL_RPC_FL_TIMEOUT (1 << 7) /* request timed out waiting for reply */
168 #define REQ_MAX_ACK_LOCKS 8
170 #define SWAB_PARANOIA 1
172 /* unpacking: assert idx not unpacked already */
173 #define LASSERT_REQSWAB(rq, idx) \
175 LASSERT ((idx) < sizeof ((rq)->rq_req_swab_mask) * 8); \
176 LASSERT (((rq)->rq_req_swab_mask & (1 << (idx))) == 0); \
177 (rq)->rq_req_swab_mask |= (1 << (idx)); \
180 #define LASSERT_REPSWAB(rq, idx) \
182 LASSERT ((idx) < sizeof ((rq)->rq_rep_swab_mask) * 8); \
183 LASSERT (((rq)->rq_rep_swab_mask & (1 << (idx))) == 0); \
184 (rq)->rq_rep_swab_mask |= (1 << (idx)); \
187 /* just looking: assert idx already unpacked */
188 #define LASSERT_REQSWABBED(rq, idx) \
189 LASSERT ((idx) < sizeof ((rq)->rq_req_swab_mask) * 8 && \
190 ((rq)->rq_req_swab_mask & (1 << (idx))) != 0)
192 #define LASSERT_REPSWABBED(rq, idx) \
193 LASSERT ((idx) < sizeof ((rq)->rq_rep_swab_mask) * 8 && \
194 ((rq)->rq_rep_swab_mask & (1 << (idx))) != 0)
196 #define LASSERT_REQSWAB(rq, idx)
197 #define LASSERT_REPSWAB(rq, idx)
198 #define LASSERT_REQSWABBED(rq, idx)
199 #define LASSERT_REPSWABBED(rq, idx)
202 union ptlrpc_async_args {
203 /* Scratchpad for passing args to completion interpreter. Users
204 * cast to the struct of their choosing, and LASSERT that this is
205 * big enough. For _tons_ of context, OBD_ALLOC a struct and store
206 * a pointer to it here. The pointer_arg ensures this struct is at
207 * least big enough for that. */
208 void *pointer_arg[9];
212 struct ptlrpc_request_set;
213 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
215 struct ptlrpc_request_set {
216 int set_remaining; /* # uncompleted requests */
217 cfs_waitq_t set_waitq;
218 cfs_waitq_t *set_wakeup_ptr;
219 struct list_head set_requests;
220 set_interpreter_func set_interpret; /* completion callback */
221 void *set_arg; /* completion context */
222 /* locked so that any old caller can communicate requests to
223 * the set holder who can then fold them into the lock-free set */
224 spinlock_t set_new_req_lock;
225 struct list_head set_new_requests;
228 struct ptlrpc_bulk_desc;
231 * ptlrpc callback & work item stuff
233 struct ptlrpc_cb_id {
234 void (*cbid_fn)(lnet_event_t *ev); /* specific callback fn */
235 void *cbid_arg; /* additional arg */
238 #define RS_MAX_LOCKS 4
241 struct ptlrpc_reply_state {
242 struct ptlrpc_cb_id rs_cb_id;
243 struct list_head rs_list;
244 struct list_head rs_exp_list;
245 struct list_head rs_obd_list;
247 struct list_head rs_debug_list;
249 /* updates to following flag serialised by srv_request_lock */
250 unsigned int rs_difficult:1; /* ACK/commit stuff */
251 unsigned int rs_scheduled:1; /* being handled? */
252 unsigned int rs_scheduled_ever:1;/* any schedule attempts? */
253 unsigned int rs_handled:1; /* been handled yet? */
254 unsigned int rs_on_net:1; /* reply_out_callback pending? */
255 unsigned int rs_prealloc:1; /* rs from prealloc list */
260 struct obd_export *rs_export;
261 struct ptlrpc_service *rs_service;
262 lnet_handle_md_t rs_md_h;
263 atomic_t rs_refcount;
265 /* locks awaiting client reply ACK */
267 struct lustre_handle rs_locks[RS_MAX_LOCKS];
268 ldlm_mode_t rs_modes[RS_MAX_LOCKS];
269 /* last member: variable sized reply message */
270 struct lustre_msg rs_msg;
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);
290 struct ptlrpc_request {
291 int rq_type; /* one of PTL_RPC_MSG_* */
292 struct list_head rq_list;
293 struct list_head rq_history_list; /* server-side history */
294 __u64 rq_history_seq; /* history sequence # */
297 /* client-side flags */
298 unsigned int rq_intr:1, rq_replied:1, rq_err:1,
299 rq_timedout:1, rq_resend:1, rq_restart:1,
301 * when ->rq_replay is set, request is kept by the client even
302 * after server commits corresponding transaction. This is
303 * used for operations that require sequence of multiple
304 * requests to be replayed. The only example currently is file
305 * open/close. When last request in such a sequence is
306 * committed, ->rq_replay is cleared on all requests in the
310 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
311 rq_no_delay:1, rq_net_err:1;
312 enum rq_phase rq_phase; /* one of RQ_PHASE_* */
313 atomic_t rq_refcount; /* client-side refcount for SENT race */
315 struct ptlrpc_thread *rq_svc_thread; /* initial thread servicing req */
317 int rq_request_portal; /* XXX FIXME bug 249 */
318 int rq_reply_portal; /* XXX FIXME bug 249 */
320 int rq_nob_received; /* client-side # reply bytes actually received */
323 struct lustre_msg *rq_reqmsg;
325 int rq_timeout; /* time to wait for reply (seconds) */
327 struct lustre_msg *rq_repmsg;
330 struct list_head rq_replay_list;
333 __u32 rq_req_swab_mask;
334 __u32 rq_rep_swab_mask;
337 int rq_import_generation;
338 enum lustre_imp_state rq_send_state;
340 /* client+server request */
341 lnet_handle_md_t rq_req_md_h;
342 struct ptlrpc_cb_id rq_req_cbid;
345 struct timeval rq_arrival_time; /* request arrival time */
346 struct ptlrpc_reply_state *rq_reply_state; /* separated reply state */
347 struct ptlrpc_request_buffer_desc *rq_rqbd; /* incoming request buffer*/
349 __u32 rq_uid; /* peer uid, used in MDS only */
352 /* client-only incoming reply */
353 lnet_handle_md_t rq_reply_md_h;
354 cfs_waitq_t rq_reply_waitq;
355 struct ptlrpc_cb_id rq_reply_cbid;
358 lnet_process_id_t rq_peer;
359 struct obd_export *rq_export;
360 struct obd_import *rq_import;
362 void (*rq_replay_cb)(struct ptlrpc_request *);
363 void (*rq_commit_cb)(struct ptlrpc_request *);
366 struct ptlrpc_bulk_desc *rq_bulk; /* client side bulk */
367 time_t rq_sent; /* when request sent, seconds */
370 struct list_head rq_set_chain;
371 struct ptlrpc_request_set *rq_set;
372 void *rq_interpret_reply; /* Async completion handler */
373 union ptlrpc_async_args rq_async_args; /* Async completion context */
374 void *rq_ptlrpcd_data;
375 struct ptlrpc_request_pool *rq_pool; /* Pool if request from
379 static inline const char *
380 ptlrpc_rqphase2str(const struct ptlrpc_request *req)
382 switch (req->rq_phase) {
389 case RQ_PHASE_INTERPRET:
391 case RQ_PHASE_COMPLETE:
398 /* Spare the preprocessor, spoil the bugs. */
399 #define FLAG(field, str) (field ? str : "")
401 #define DEBUG_REQ_FLAGS(req) \
402 ptlrpc_rqphase2str(req), \
403 FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"), \
404 FLAG(req->rq_err, "E"), \
405 FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"), \
406 FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"), \
407 FLAG(req->rq_no_resend, "N"), \
408 FLAG(req->rq_waiting, "W")
410 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s"
412 #define __DEBUG_REQ(CDEB_TYPE, level, req, fmt, args...) \
413 CDEB_TYPE(level, "@@@ " fmt \
414 " req@%p x"LPD64"/t"LPD64" o%d->%s@%s:%d lens %d/%d ref %d fl " \
415 REQ_FLAGS_FMT"/%x/%x rc %d/%d\n" , ## args, req, req->rq_xid, \
417 req->rq_reqmsg ? req->rq_reqmsg->opc : -1, \
418 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) : "<?>", \
420 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid : "<?>", \
421 (req->rq_import && req->rq_import->imp_client) ? \
422 req->rq_import->imp_client->cli_request_portal : -1, \
423 req->rq_reqlen, req->rq_replen, \
424 atomic_read(&req->rq_refcount), \
425 DEBUG_REQ_FLAGS(req), \
426 req->rq_reqmsg ? req->rq_reqmsg->flags : 0, \
427 req->rq_repmsg ? req->rq_repmsg->flags : 0, \
428 req->rq_status, req->rq_repmsg ? req->rq_repmsg->status : 0)
430 /* for most callers (level is a constant) this is resolved at compile time */
431 #define DEBUG_REQ(level, req, fmt, args...) \
433 if ((level) & (D_ERROR | D_WARNING)) \
434 __DEBUG_REQ(CDEBUG_LIMIT, level, req, fmt, ## args); \
436 __DEBUG_REQ(CDEBUG, level, req, fmt, ## args); \
439 #define DEBUG_REQ_EX(level, req, fmt, args...) \
441 if ((level) & (D_ERROR | D_WARNING)) \
442 __DEBUG_REQ(CDEBUG_LIMIT, D_ERROR, req, fmt, ## args); \
444 __DEBUG_REQ(CDEBUG_EX, level, req, fmt, ## args); \
447 struct ptlrpc_bulk_page {
448 struct list_head bp_link;
450 int bp_pageoffset; /* offset within a page */
451 struct page *bp_page;
454 #define BULK_GET_SOURCE 0
455 #define BULK_PUT_SINK 1
456 #define BULK_GET_SINK 2
457 #define BULK_PUT_SOURCE 3
459 struct ptlrpc_bulk_desc {
460 unsigned int bd_success:1; /* completed successfully */
461 unsigned int bd_network_rw:1; /* accessible to the network */
462 unsigned int bd_type:2; /* {put,get}{source,sink} */
463 unsigned int bd_registered:1; /* client side */
464 spinlock_t bd_lock; /* serialise with callback */
465 int bd_import_generation;
466 struct obd_export *bd_export;
467 struct obd_import *bd_import;
469 struct ptlrpc_request *bd_req; /* associated request */
470 cfs_waitq_t bd_waitq; /* server side only WQ */
471 int bd_iov_count; /* # entries in bd_iov */
472 int bd_max_iov; /* allocated size of bd_iov */
473 int bd_nob; /* # bytes covered */
474 int bd_nob_transferred; /* # bytes GOT/PUT */
478 struct ptlrpc_cb_id bd_cbid; /* network callback info */
479 lnet_handle_md_t bd_md_h; /* associated MD */
481 #if defined(__KERNEL__)
482 lnet_kiov_t bd_iov[0];
484 lnet_md_iovec_t bd_iov[0];
489 struct ptlrpc_thread {
491 struct list_head t_link; /* active threads for service, from svc->srv_threads */
493 void *t_data; /* thread-private data (preallocated memory) */
496 unsigned int t_id; /* service thread index, from ptlrpc_start_threads */
497 cfs_waitq_t t_ctl_waitq;
498 struct lu_context *t_ctx;
501 struct ptlrpc_request_buffer_desc {
502 struct list_head rqbd_list;
503 struct list_head rqbd_reqs;
504 struct ptlrpc_service *rqbd_service;
505 lnet_handle_md_t rqbd_md_h;
508 struct ptlrpc_cb_id rqbd_cbid;
509 struct ptlrpc_request rqbd_req;
512 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
513 typedef void (*svcreq_printfn_t)(void *, struct ptlrpc_request *);
515 struct ptlrpc_service {
516 struct list_head srv_list; /* chain thru all services */
517 int srv_max_req_size; /* biggest request to receive */
518 int srv_max_reply_size; /* biggest reply to send */
519 int srv_buf_size; /* size of individual buffers */
520 int srv_nbuf_per_group; /* # buffers to allocate in 1 group */
521 int srv_nbufs; /* total # req buffer descs allocated */
522 int srv_nthreads; /* # running threads */
523 int srv_n_difficult_replies; /* # 'difficult' replies */
524 int srv_n_active_reqs; /* # reqs being served */
525 cfs_duration_t srv_rqbd_timeout; /* timeout before re-posting reqs, in tick */
526 int srv_watchdog_timeout; /* soft watchdog timeout, in ms */
527 int srv_num_threads; /* # threads to start/started */
528 unsigned srv_cpu_affinity:1; /* bind threads to CPUs */
530 __u32 srv_req_portal;
531 __u32 srv_rep_portal;
533 int srv_n_queued_reqs; /* # reqs waiting to be served */
534 struct list_head srv_request_queue; /* reqs waiting for service */
536 struct list_head srv_request_history; /* request history */
537 __u64 srv_request_seq; /* next request sequence # */
538 __u64 srv_request_max_cull_seq; /* highest seq culled from history */
539 svcreq_printfn_t srv_request_history_print_fn; /* service-specific print fn */
541 struct list_head srv_idle_rqbds; /* request buffers to be reposted */
542 struct list_head srv_active_rqbds; /* req buffers receiving */
543 struct list_head srv_history_rqbds; /* request buffer history */
544 int srv_nrqbd_receiving; /* # posted request buffers */
545 int srv_n_history_rqbds; /* # request buffers in history */
546 int srv_max_history_rqbds; /* max # request buffers in history */
548 atomic_t srv_outstanding_replies;
549 struct list_head srv_active_replies; /* all the active replies */
550 struct list_head srv_reply_queue; /* replies waiting for service */
552 cfs_waitq_t srv_waitq; /* all threads sleep on this. This
553 * wait-queue is signalled when new
554 * incoming request arrives and when
555 * difficult reply has to be handled. */
557 struct list_head srv_threads;
558 svc_handler_t srv_handler;
560 char *srv_name; /* only statically allocated strings here; we don't clean them */
564 cfs_proc_dir_entry_t *srv_procroot;
565 struct lprocfs_stats *srv_stats;
567 /* List of free reply_states */
568 struct list_head srv_free_rs_list;
569 /* waitq to run, when adding stuff to srv_free_rs_list */
570 cfs_waitq_t srv_free_rs_waitq;
573 * if non-NULL called during thread creation (ptlrpc_start_thread())
574 * to initialize service specific per-thread state.
576 int (*srv_init)(struct ptlrpc_thread *thread);
578 * if non-NULL called during thread shutdown (ptlrpc_main()) to
579 * destruct state created by ->srv_init().
581 void (*srv_done)(struct ptlrpc_thread *thread);
583 //struct ptlrpc_srv_ni srv_interfaces[0];
586 /* ptlrpc/events.c */
587 extern lnet_handle_eq_t ptlrpc_eq_h;
588 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
589 lnet_process_id_t *peer, lnet_nid_t *self);
590 extern void request_out_callback (lnet_event_t *ev);
591 extern void reply_in_callback(lnet_event_t *ev);
592 extern void client_bulk_callback (lnet_event_t *ev);
593 extern void request_in_callback(lnet_event_t *ev);
594 extern void reply_out_callback(lnet_event_t *ev);
595 extern void server_bulk_callback (lnet_event_t *ev);
597 /* ptlrpc/connection.c */
598 void ptlrpc_dump_connections(void);
599 void ptlrpc_readdress_connection(struct ptlrpc_connection *, struct obd_uuid *);
600 struct ptlrpc_connection *ptlrpc_get_connection(lnet_process_id_t peer,
601 lnet_nid_t self, struct obd_uuid *uuid);
602 int ptlrpc_put_connection(struct ptlrpc_connection *c);
603 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
604 void ptlrpc_init_connection(void);
605 void ptlrpc_cleanup_connection(void);
606 extern lnet_pid_t ptl_get_pid(void);
608 /* ptlrpc/niobuf.c */
609 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
610 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
611 int ptlrpc_register_bulk(struct ptlrpc_request *req);
612 void ptlrpc_unregister_bulk (struct ptlrpc_request *req);
614 static inline int ptlrpc_bulk_active (struct ptlrpc_bulk_desc *desc)
619 spin_lock_irqsave (&desc->bd_lock, flags);
620 rc = desc->bd_network_rw;
621 spin_unlock_irqrestore (&desc->bd_lock, flags);
625 int ptlrpc_send_reply(struct ptlrpc_request *req, int);
626 int ptlrpc_reply(struct ptlrpc_request *req);
627 int ptlrpc_error(struct ptlrpc_request *req);
628 void ptlrpc_resend_req(struct ptlrpc_request *request);
629 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
630 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
632 /* ptlrpc/client.c */
633 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
634 struct ptlrpc_client *);
635 void ptlrpc_cleanup_client(struct obd_import *imp);
636 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
639 ptlrpc_client_receiving_reply (struct ptlrpc_request *req)
644 spin_lock_irqsave(&req->rq_lock, flags);
645 rc = req->rq_receiving_reply;
646 spin_unlock_irqrestore(&req->rq_lock, flags);
651 ptlrpc_client_replied (struct ptlrpc_request *req)
656 spin_lock_irqsave(&req->rq_lock, flags);
657 rc = req->rq_replied;
658 spin_unlock_irqrestore(&req->rq_lock, flags);
663 ptlrpc_wake_client_req (struct ptlrpc_request *req)
665 if (req->rq_set == NULL)
666 cfs_waitq_signal(&req->rq_reply_waitq);
668 cfs_waitq_signal(&req->rq_set->set_waitq);
671 int ptlrpc_queue_wait(struct ptlrpc_request *req);
672 int ptlrpc_replay_req(struct ptlrpc_request *req);
673 void ptlrpc_unregister_reply(struct ptlrpc_request *req);
674 void ptlrpc_restart_req(struct ptlrpc_request *req);
675 void ptlrpc_abort_inflight(struct obd_import *imp);
677 struct ptlrpc_request_set *ptlrpc_prep_set(void);
678 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
679 int ptlrpc_check_set(struct ptlrpc_request_set *set);
680 int ptlrpc_set_wait(struct ptlrpc_request_set *);
681 int ptlrpc_expired_set(void *data);
682 void ptlrpc_interrupted_set(void *data);
683 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
684 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
685 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
686 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *,
687 struct ptlrpc_request *);
689 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
690 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
691 struct ptlrpc_request_pool *ptlrpc_init_rq_pool(int, int,
692 void (*populate_pool)(struct ptlrpc_request_pool *, int));
693 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
694 int opcode, int count,
695 int *lengths, char **bufs);
696 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp, __u32 version,
697 int opcode, int count, int *lengths,
699 struct ptlrpc_request_pool *pool);
700 void ptlrpc_free_req(struct ptlrpc_request *request);
701 void ptlrpc_req_finished(struct ptlrpc_request *request);
702 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
703 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
704 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
705 int npages, int type, int portal);
706 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
707 int npages, int type, int portal);
708 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
709 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
710 cfs_page_t *page, int pageoffset, int len);
711 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
712 struct obd_import *imp);
713 __u64 ptlrpc_next_xid(void);
714 __u64 ptlrpc_sample_next_xid(void);
715 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
717 struct ptlrpc_service_conf {
720 int psc_max_req_size;
721 int psc_max_reply_size;
724 int psc_watchdog_timeout; /* in ms */
728 /* ptlrpc/service.c */
729 void ptlrpc_save_lock (struct ptlrpc_request *req,
730 struct lustre_handle *lock, int mode);
731 void ptlrpc_commit_replies (struct obd_device *obd);
732 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
733 struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
734 svc_handler_t h, char *name,
735 struct proc_dir_entry *proc_entry,
736 svcreq_printfn_t prntfn);
738 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
740 int req_portal, int rep_portal,
741 int watchdog_timeout, /* in ms */
742 svc_handler_t, char *name,
743 cfs_proc_dir_entry_t *proc_entry,
744 svcreq_printfn_t, int num_threads);
745 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
747 int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc,
749 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
751 int ptlrpc_unregister_service(struct ptlrpc_service *service);
752 int liblustre_check_services (void *arg);
753 void ptlrpc_daemonize(char *name);
754 int ptlrpc_service_health_check(struct ptlrpc_service *);
757 struct ptlrpc_svc_data {
759 struct ptlrpc_service *svc;
760 struct ptlrpc_thread *thread;
761 struct obd_device *dev;
764 /* ptlrpc/import.c */
765 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
766 int ptlrpc_init_import(struct obd_import *imp);
767 int ptlrpc_disconnect_import(struct obd_import *imp);
768 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
770 /* ptlrpc/pack_generic.c */
771 int lustre_msg_swabbed(struct lustre_msg *msg);
772 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
773 int lustre_pack_request(struct ptlrpc_request *, int count, const int *lens,
775 int lustre_pack_reply(struct ptlrpc_request *, int count, const int *lens,
777 void lustre_shrink_reply(struct ptlrpc_request *req,
778 int segment, unsigned int newlen, int move_data);
779 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
780 int lustre_msg_size(int count, const int *lengths);
781 int lustre_unpack_msg(struct lustre_msg *m, int len);
782 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
783 int lustre_msg_buflen(struct lustre_msg *m, int n);
784 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
785 void *lustre_swab_buf(struct lustre_msg *, int n, int minlen, void *swabber);
786 void *lustre_swab_reqbuf (struct ptlrpc_request *req, int n, int minlen,
788 void *lustre_swab_repbuf (struct ptlrpc_request *req, int n, int minlen,
792 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
794 LASSERT(atomic_read(&rs->rs_refcount) > 0);
795 atomic_inc(&rs->rs_refcount);
799 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
801 LASSERT(atomic_read(&rs->rs_refcount) > 0);
802 if (atomic_dec_and_test(&rs->rs_refcount))
803 lustre_free_reply_state(rs);
806 /* ldlm/ldlm_lib.c */
807 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
808 int client_obd_cleanup(struct obd_device *obddev);
809 int client_connect_import(struct lustre_handle *conn, struct obd_device *obd,
810 struct obd_uuid *cluuid, struct obd_connect_data *);
811 int client_disconnect_export(struct obd_export *exp);
812 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
814 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
815 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
817 /* ptlrpc/pinger.c */
818 int ptlrpc_pinger_add_import(struct obd_import *imp);
819 int ptlrpc_pinger_del_import(struct obd_import *imp);
821 void ping_evictor_start(void);
822 void ping_evictor_stop(void);
824 #define ping_evictor_start() do {} while (0)
825 #define ping_evictor_stop() do {} while (0)
828 /* ptlrpc/ptlrpcd.c */
829 void ptlrpcd_wake(struct ptlrpc_request *req);
830 void ptlrpcd_add_req(struct ptlrpc_request *req);
831 int ptlrpcd_addref(void);
832 void ptlrpcd_decref(void);
834 /* ptlrpc/lproc_ptlrpc.c */
836 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
837 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
839 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
840 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
843 /* ptlrpc/llog_server.c */
844 int llog_origin_handle_create(struct ptlrpc_request *req);
845 int llog_origin_handle_destroy(struct ptlrpc_request *req);
846 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
847 int llog_origin_handle_next_block(struct ptlrpc_request *req);
848 int llog_origin_handle_read_header(struct ptlrpc_request *req);
849 int llog_origin_handle_close(struct ptlrpc_request *req);
850 int llog_origin_handle_cancel(struct ptlrpc_request *req);
851 int llog_catinfo(struct ptlrpc_request *req);
853 /* ptlrpc/llog_client.c */
854 extern struct llog_operations llog_client_ops;