Whamcloud - gitweb
- update from b1_4_mountconf
[fs/lustre-release.git] / lustre / include / lustre_net.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  *
21  */
22
23 #ifndef _LUSTRE_NET_H
24 #define _LUSTRE_NET_H
25
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>
32 #else
33 #error Unsupported operating system.
34 #endif
35
36 #include <libcfs/kp30.h>
37 // #include <obd.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>
43
44 /* MD flags we _always_ use */
45 #define PTLRPC_MD_OPTIONS  0
46
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)
52
53 /* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
54 #ifdef __KERNEL__
55 # if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
56 #  error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
57 # endif
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"
60 # endif
61 # if (PTLRPC_MAX_BRW_SIZE > LNET_MTU)
62 #  error "PTLRPC_MAX_BRW_SIZE too big"
63 # endif
64 # if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV)
65 #  error "PTLRPC_MAX_BRW_PAGES too big"
66 # endif
67 #endif /* __KERNEL__ */
68
69 /* Size over which to OBD_VMALLOC() rather than OBD_ALLOC() service request
70  * buffers */
71 #define SVC_BUF_VMALLOC_THRESHOLD (2 * PAGE_SIZE)
72
73 /* The following constants determine how memory is used to buffer incoming
74  * service requests.
75  *
76  * ?_NBUFS              # buffers to allocate when growing the pool
77  * ?_BUFSIZE            # bytes in a single request buffer
78  * ?_MAXREQSIZE         # maximum request service will receive
79  *
80  * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
81  * of ?_NBUFS is added to the pool.
82  *
83  * Messages larger than ?_MAXREQSIZE are dropped.  Request buffers are
84  * considered full when less than ?_MAXREQSIZE is left in them.
85  */
86
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)
92
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)
99
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
112  *
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)
118  *
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.
121  */
122 #define MDS_MAXREQSIZE  (5 * 1024)
123 #define MDS_MAXREPSIZE  max(9 * 1024, 280 + LOV_MAX_STRIPE_COUNT * 56)
124
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)))
129                                   
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)
134
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
142  *
143  * - single object with 16 pages is 512 bytes
144  * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
145  */
146 #define OST_MAXREQSIZE  (5 * 1024)
147 #define OST_MAXREPSIZE  (9 * 1024)
148
149 struct ptlrpc_connection {
150         struct list_head        c_link;
151         lnet_nid_t              c_self;
152         lnet_process_id_t       c_peer;
153         struct obd_uuid         c_remote_uuid;
154         atomic_t                c_refcount;
155 };
156
157 struct ptlrpc_client {
158         __u32                     cli_request_portal;
159         __u32                     cli_reply_portal;
160         char                     *cli_name;
161 };
162
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 */
167
168 #define REQ_MAX_ACK_LOCKS 8
169
170 #define SWAB_PARANOIA 1
171 #if SWAB_PARANOIA
172 /* unpacking: assert idx not unpacked already */
173 #define LASSERT_REQSWAB(rq, idx)                                \
174 do {                                                            \
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));                 \
178 } while (0)
179
180 #define LASSERT_REPSWAB(rq, idx)                                \
181 do {                                                            \
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));                 \
185 } while (0)
186
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)
191
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)
195 #else
196 #define LASSERT_REQSWAB(rq, idx)
197 #define LASSERT_REPSWAB(rq, idx)
198 #define LASSERT_REQSWABBED(rq, idx)
199 #define LASSERT_REPSWABBED(rq, idx)
200 #endif
201
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];
209         __u64      space[4];
210 };
211
212 struct ptlrpc_request_set;
213 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
214
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;
226 };
227
228 struct ptlrpc_bulk_desc;
229
230 /*
231  * ptlrpc callback & work item stuff
232  */
233 struct ptlrpc_cb_id {
234         void   (*cbid_fn)(lnet_event_t *ev);     /* specific callback fn */
235         void    *cbid_arg;                      /* additional arg */
236 };
237
238 #define RS_MAX_LOCKS 4
239 #define RS_DEBUG     1
240
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;
246 #if RS_DEBUG
247         struct list_head       rs_debug_list;
248 #endif
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 */
256
257         int                    rs_size;
258         __u64                  rs_transno;
259         __u64                  rs_xid;
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;
264
265         /* locks awaiting client reply ACK */
266         int                    rs_nlocks;
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;
271 };
272
273 struct ptlrpc_thread;
274
275 enum rq_phase {
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,
281 };
282
283 struct ptlrpc_request_pool {
284         spinlock_t prp_lock;
285         struct list_head prp_req_list;    /* list of ptlrpc_request structs */
286         int prp_rq_size;
287         void (*prp_populate)(struct ptlrpc_request_pool *, int);
288 };
289
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 # */
295         int rq_status;
296         spinlock_t rq_lock;
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,
300                 /*
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
307                  * sequence.
308                  */
309                 rq_replay:1,
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 */
314
315         struct ptlrpc_thread *rq_svc_thread; /* initial thread servicing req */
316
317         int rq_request_portal;  /* XXX FIXME bug 249 */
318         int rq_reply_portal;    /* XXX FIXME bug 249 */
319
320         int rq_nob_received; /* client-side # reply bytes actually received  */
321
322         int rq_reqlen;
323         struct lustre_msg *rq_reqmsg;
324
325         int rq_timeout;         /* time to wait for reply (seconds) */
326         int rq_replen;
327         struct lustre_msg *rq_repmsg;
328         __u64 rq_transno;
329         __u64 rq_xid;
330         struct list_head rq_replay_list;
331
332 #if SWAB_PARANOIA
333         __u32 rq_req_swab_mask;
334         __u32 rq_rep_swab_mask;
335 #endif
336
337         int rq_import_generation;
338         enum lustre_imp_state rq_send_state;
339
340         /* client+server request */
341         lnet_handle_md_t     rq_req_md_h;
342         struct ptlrpc_cb_id  rq_req_cbid;
343
344         /* server-side... */
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*/
348 #if CRAY_XT3
349         __u32                rq_uid;            /* peer uid, used in MDS only */
350 #endif
351
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;
356
357         lnet_nid_t           rq_self;
358         lnet_process_id_t    rq_peer;
359         struct obd_export   *rq_export;
360         struct obd_import   *rq_import;
361
362         void (*rq_replay_cb)(struct ptlrpc_request *);
363         void (*rq_commit_cb)(struct ptlrpc_request *);
364         void  *rq_cb_data;
365
366         struct ptlrpc_bulk_desc *rq_bulk;       /* client side bulk */
367         time_t rq_sent;                         /* when request sent, seconds */
368
369         /* Multi-rpc bits */
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
376                                                    preallocated list */
377 };
378
379 static inline const char *
380 ptlrpc_rqphase2str(const struct ptlrpc_request *req)
381 {
382         switch (req->rq_phase) {
383         case RQ_PHASE_NEW:
384                 return "New";
385         case RQ_PHASE_RPC:
386                 return "Rpc";
387         case RQ_PHASE_BULK:
388                 return "Bulk";
389         case RQ_PHASE_INTERPRET:
390                 return "Interpret";
391         case RQ_PHASE_COMPLETE:
392                 return "Complete";
393         default:
394                 return "?Phase?";
395         }
396 }
397
398 /* Spare the preprocessor, spoil the bugs. */
399 #define FLAG(field, str) (field ? str : "")
400
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")
409
410 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s"
411
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,           \
416        req->rq_transno,                                                        \
417        req->rq_reqmsg ? req->rq_reqmsg->opc : -1,                              \
418        req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) : "<?>",  \
419        req->rq_import ?                                                        \
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)
429
430 /* for most callers (level is a constant) this is resolved at compile time */
431 #define DEBUG_REQ(level, req, fmt, args...)                                    \
432 do {                                                                           \
433         if ((level) & (D_ERROR | D_WARNING))                                   \
434             __DEBUG_REQ(CDEBUG_LIMIT, level, req, fmt, ## args);               \
435         else                                                                   \
436             __DEBUG_REQ(CDEBUG, level, req, fmt, ## args);                     \
437 } while (0)
438
439 #define DEBUG_REQ_EX(level, req, fmt, args...)                          \
440 do {                                                                    \
441         if ((level) & (D_ERROR | D_WARNING))                            \
442             __DEBUG_REQ(CDEBUG_LIMIT, D_ERROR, req, fmt, ## args);      \
443         else                                                            \
444             __DEBUG_REQ(CDEBUG_EX, level, req, fmt, ## args);           \
445 } while (0)
446
447 struct ptlrpc_bulk_page {
448         struct list_head bp_link;
449         int bp_buflen;
450         int bp_pageoffset;                      /* offset within a page */
451         struct page *bp_page;
452 };
453
454 #define BULK_GET_SOURCE   0
455 #define BULK_PUT_SINK     1
456 #define BULK_GET_SINK     2
457 #define BULK_PUT_SOURCE   3
458
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;
468         __u32 bd_portal;
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 */
475
476         __u64                  bd_last_xid;
477
478         struct ptlrpc_cb_id    bd_cbid;         /* network callback info */
479         lnet_handle_md_t        bd_md_h;         /* associated MD */
480
481 #if defined(__KERNEL__)
482         lnet_kiov_t             bd_iov[0];
483 #else
484         lnet_md_iovec_t         bd_iov[0];
485 #endif
486 };
487
488 struct lu_context;
489 struct ptlrpc_thread {
490
491         struct list_head t_link; /* active threads for service, from svc->srv_threads */
492
493         void *t_data;            /* thread-private data (preallocated memory) */
494         __u32 t_flags;
495
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;
499 };
500
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;
506         int                    rqbd_refcount;
507         char                  *rqbd_buffer;
508         struct ptlrpc_cb_id    rqbd_cbid;
509         struct ptlrpc_request  rqbd_req;
510 };
511
512 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
513 typedef void (*svcreq_printfn_t)(void *, struct ptlrpc_request *);
514
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 */
529
530         __u32            srv_req_portal;
531         __u32            srv_rep_portal;
532
533         int               srv_n_queued_reqs;    /* # reqs waiting to be served */
534         struct list_head  srv_request_queue;    /* reqs waiting for service */
535
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 */
540
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 */
547
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 */
551
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. */
556
557         struct list_head   srv_threads;
558         svc_handler_t      srv_handler;
559
560         char *srv_name;  /* only statically allocated strings here; we don't clean them */
561
562         spinlock_t               srv_lock;
563
564         cfs_proc_dir_entry_t    *srv_procroot;
565         struct lprocfs_stats    *srv_stats;
566
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;
571         
572         /*
573          * if non-NULL called during thread creation (ptlrpc_start_thread())
574          * to initialize service specific per-thread state.
575          */
576         int (*srv_init)(struct ptlrpc_thread *thread);
577         /*
578          * if non-NULL called during thread shutdown (ptlrpc_main()) to
579          * destruct state created by ->srv_init().
580          */
581         void (*srv_done)(struct ptlrpc_thread *thread);
582
583         //struct ptlrpc_srv_ni srv_interfaces[0];
584 };
585
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);
596
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);
607
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);
613
614 static inline int ptlrpc_bulk_active (struct ptlrpc_bulk_desc *desc)
615 {
616         unsigned long flags;
617         int           rc;
618
619         spin_lock_irqsave (&desc->bd_lock, flags);
620         rc = desc->bd_network_rw;
621         spin_unlock_irqrestore (&desc->bd_lock, flags);
622         return (rc);
623 }
624
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);
631
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);
637
638 static inline int
639 ptlrpc_client_receiving_reply (struct ptlrpc_request *req)
640 {
641         unsigned long flags;
642         int           rc;
643
644         spin_lock_irqsave(&req->rq_lock, flags);
645         rc = req->rq_receiving_reply;
646         spin_unlock_irqrestore(&req->rq_lock, flags);
647         return (rc);
648 }
649
650 static inline int
651 ptlrpc_client_replied (struct ptlrpc_request *req)
652 {
653         unsigned long flags;
654         int           rc;
655
656         spin_lock_irqsave(&req->rq_lock, flags);
657         rc = req->rq_replied;
658         spin_unlock_irqrestore(&req->rq_lock, flags);
659         return (rc);
660 }
661
662 static inline void
663 ptlrpc_wake_client_req (struct ptlrpc_request *req)
664 {
665         if (req->rq_set == NULL)
666                 cfs_waitq_signal(&req->rq_reply_waitq);
667         else
668                 cfs_waitq_signal(&req->rq_set->set_waitq);
669 }
670
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);
676
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 *);
688
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,
698                                             char **bufs,
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);
716
717 struct ptlrpc_service_conf {
718         int psc_nbufs;
719         int psc_bufsize;
720         int psc_max_req_size;
721         int psc_max_reply_size;
722         int psc_req_portal;
723         int psc_rep_portal;
724         int psc_watchdog_timeout; /* in ms */
725         int psc_num_threads;
726 };
727
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);
737
738 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
739                                        int max_reply_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);
746
747 int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc,
748                          char *base_name);
749 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
750                         char *name, int id);
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 *);
755
756
757 struct ptlrpc_svc_data {
758         char *name;
759         struct ptlrpc_service *svc;
760         struct ptlrpc_thread *thread;
761         struct obd_device *dev;
762 };
763
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);
769
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,
774                         char **bufs);
775 int lustre_pack_reply(struct ptlrpc_request *, int count, const int *lens,
776                       char **bufs);
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,
787                           void *swabber);
788 void *lustre_swab_repbuf (struct ptlrpc_request *req, int n, int minlen,
789                           void *swabber);
790
791 static inline void
792 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
793 {
794         LASSERT(atomic_read(&rs->rs_refcount) > 0);
795         atomic_inc(&rs->rs_refcount);
796 }
797
798 static inline void
799 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
800 {
801         LASSERT(atomic_read(&rs->rs_refcount) > 0);
802         if (atomic_dec_and_test(&rs->rs_refcount))
803                 lustre_free_reply_state(rs);
804 }
805
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,
813                            int priority);
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);
816
817 /* ptlrpc/pinger.c */
818 int ptlrpc_pinger_add_import(struct obd_import *imp);
819 int ptlrpc_pinger_del_import(struct obd_import *imp);
820 #ifdef __KERNEL__
821 void ping_evictor_start(void);
822 void ping_evictor_stop(void);
823 #else
824 #define ping_evictor_start()    do {} while (0)
825 #define ping_evictor_stop()     do {} while (0)
826 #endif
827
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);
833
834 /* ptlrpc/lproc_ptlrpc.c */
835 #ifdef LPROCFS
836 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
837 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
838 #else
839 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
840 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
841 #endif
842
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);
852
853 /* ptlrpc/llog_client.c */
854 extern struct llog_operations llog_client_ops;
855
856 #endif