Whamcloud - gitweb
modify dt_index_operations to be usable as generic index
[fs/lustre-release.git] / lustre / include / linux / 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 #ifdef __KERNEL__
27 #include <linux/version.h>
28 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
29 #include <linux/tqueue.h>
30 #else
31 #include <linux/workqueue.h>
32 #endif
33 #endif
34
35 #include <libcfs/kp30.h>
36 // #include <linux/obd.h>
37 #include <lnet/lnet.h>
38 #include <linux/lustre_idl.h>
39 #include <linux/lustre_ha.h>
40 #include <linux/lustre_import.h>
41 #include <linux/lprocfs_status.h>
42
43 /* MD flags we _always_ use */
44 #define PTLRPC_MD_OPTIONS  0
45
46 /* Define maxima for bulk I/O
47  * CAVEAT EMPTOR, with multinet (i.e. routers forwarding between networks)
48  * these limits are system wide and not interface-local. */
49 #define PTLRPC_MAX_BRW_SIZE     LNET_MTU
50 #define PTLRPC_MAX_BRW_PAGES    (PTLRPC_MAX_BRW_SIZE/PAGE_SIZE)
51
52 /* When PAGE_SIZE is a constant, we can check our arithmetic here with cpp! */
53 #ifdef __KERNEL__
54 # if ((PTLRPC_MAX_BRW_PAGES & (PTLRPC_MAX_BRW_PAGES - 1)) != 0)
55 #  error "PTLRPC_MAX_BRW_PAGES isn't a power of two"
56 # endif
57 # if (PTLRPC_MAX_BRW_SIZE != (PTLRPC_MAX_BRW_PAGES * PAGE_SIZE))
58 #  error "PTLRPC_MAX_BRW_SIZE isn't PTLRPC_MAX_BRW_PAGES * PAGE_SIZE"
59 # endif
60 # if (PTLRPC_MAX_BRW_SIZE > LNET_MTU)
61 #  error "PTLRPC_MAX_BRW_SIZE too big"
62 # endif
63 # if (PTLRPC_MAX_BRW_PAGES > LNET_MAX_IOV)
64 #  error "PTLRPC_MAX_BRW_PAGES too big"
65 # endif
66 #endif /* __KERNEL__ */
67
68 /* Size over which to OBD_VMALLOC() rather than OBD_ALLOC() service request
69  * buffers */
70 #define SVC_BUF_VMALLOC_THRESHOLD (2 * PAGE_SIZE)
71
72 /* The following constants determine how memory is used to buffer incoming
73  * service requests.
74  *
75  * ?_NBUFS              # buffers to allocate when growing the pool
76  * ?_BUFSIZE            # bytes in a single request buffer
77  * ?_MAXREQSIZE         # maximum request service will receive
78  *
79  * When fewer than ?_NBUFS/2 buffers are posted for receive, another chunk
80  * of ?_NBUFS is added to the pool.
81  *
82  * Messages larger than ?_MAXREQSIZE are dropped.  Request buffers are
83  * considered full when less than ?_MAXREQSIZE is left in them.
84  */
85
86 #define LDLM_NUM_THREADS min((int)(smp_num_cpus * smp_num_cpus * 8), 64)
87 #define LDLM_NBUFS      (64 * smp_num_cpus)
88 #define LDLM_BUFSIZE    (8 * 1024)
89 #define LDLM_MAXREQSIZE (5 * 1024)
90 #define LDLM_MAXREPSIZE (1024)
91
92 #define MDT_MIN_THREADS 2UL
93 #define MDT_MAX_THREADS 32UL
94 #define MDT_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
95                                   num_physpages >> (25 - PAGE_SHIFT)), 2UL)
96 #define FLD_NUM_THREADS max(min_t(unsigned long, MDT_MAX_THREADS, \
97                                   num_physpages >> (25 - PAGE_SHIFT)), 2UL)
98
99 #define MDS_NBUFS       (64 * smp_num_cpus)
100 #define MDS_BUFSIZE     (8 * 1024)
101 /* Assume file name length = FNAME_MAX = 256 (true for ext3).
102  *        path name length = PATH_MAX = 4096
103  *        LOV MD size max  = EA_MAX = 4000
104  * symlink:  FNAME_MAX + PATH_MAX  <- largest
105  * link:     FNAME_MAX + PATH_MAX  (mds_rec_link < mds_rec_create)
106  * rename:   FNAME_MAX + FNAME_MAX
107  * open:     FNAME_MAX + EA_MAX
108  *
109  * MDS_MAXREQSIZE ~= 4736 bytes =
110  * lustre_msg + ldlm_request + mds_body + mds_rec_create + FNAME_MAX + PATH_MAX
111  * MDS_MAXREPSIZE ~= 8300 bytes = lustre_msg + llog_header
112  * or, for mds_close() and mds_reint_unlink() on a many-OST filesystem:
113  *      = 9210 bytes = lustre_msg + mds_body + 160 * (easize + cookiesize)
114  *
115  * Realistic size is about 512 bytes (20 character name + 128 char symlink),
116  * except in the open case where there are a large number of OSTs in a LOV.
117  */
118 #define MDS_MAXREQSIZE  (5 * 1024)
119 #define MDS_MAXREPSIZE  max(9 * 1024, 280 + LOV_MAX_STRIPE_COUNT * 56)
120
121 /* FIXME fix all constants here */
122 #define MGS_MAX_THREADS 8UL
123 #define MGS_NUM_THREADS max(2UL, min_t(unsigned long, MGS_MAX_THREADS, \
124                             num_physpages * smp_num_cpus >> (26 - PAGE_SHIFT)))
125
126 #define MGS_NBUFS       (64 * smp_num_cpus)
127 #define MGS_BUFSIZE     (8 * 1024)
128 #define MGS_MAXREQSIZE  (5 * 1024)
129 #define MGS_MAXREPSIZE  (9 * 1024)
130
131 #define OST_MAX_THREADS 512UL
132 #define OST_DEF_THREADS max_t(unsigned long, 2, \
133                               (num_physpages >> (26-PAGE_SHIFT)) * smp_num_cpus)
134 #define OST_NBUFS       (64 * smp_num_cpus)
135 #define OST_BUFSIZE     (8 * 1024)
136 /* OST_MAXREQSIZE ~= 4768 bytes =
137  * lustre_msg + obdo + 16 * obd_ioobj + 256 * niobuf_remote
138  *
139  * - single object with 16 pages is 512 bytes
140  * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
141  */
142 #define OST_MAXREQSIZE  (5 * 1024)
143 #define OST_MAXREPSIZE  (9 * 1024)
144
145 struct ptlrpc_connection {
146         struct list_head        c_link;
147         lnet_nid_t              c_self;
148         lnet_process_id_t       c_peer;
149         struct obd_uuid         c_remote_uuid;
150         atomic_t                c_refcount;
151 };
152
153 struct ptlrpc_client {
154         __u32                     cli_request_portal;
155         __u32                     cli_reply_portal;
156         char                     *cli_name;
157 };
158
159 /* state flags of requests */
160 /* XXX only ones left are those used by the bulk descs as well! */
161 #define PTL_RPC_FL_INTR      (1 << 0)  /* reply wait was interrupted by user */
162 #define PTL_RPC_FL_TIMEOUT   (1 << 7)  /* request timed out waiting for reply */
163
164 #define REQ_MAX_ACK_LOCKS 8
165
166 #define SWAB_PARANOIA 1
167 #if SWAB_PARANOIA
168 /* unpacking: assert idx not unpacked already */
169 #define LASSERT_REQSWAB(rq, idx)                                \
170 do {                                                            \
171         LASSERT ((idx) < sizeof ((rq)->rq_req_swab_mask) * 8);  \
172         LASSERT (((rq)->rq_req_swab_mask & (1 << (idx))) == 0); \
173         (rq)->rq_req_swab_mask |= (1 << (idx));                 \
174 } while (0)
175
176 #define LASSERT_REPSWAB(rq, idx)                                \
177 do {                                                            \
178         LASSERT ((idx) < sizeof ((rq)->rq_rep_swab_mask) * 8);  \
179         LASSERT (((rq)->rq_rep_swab_mask & (1 << (idx))) == 0); \
180         (rq)->rq_rep_swab_mask |= (1 << (idx));                 \
181 } while (0)
182
183 /* just looking: assert idx already unpacked */
184 #define LASSERT_REQSWABBED(rq, idx)                     \
185 LASSERT ((idx) < sizeof ((rq)->rq_req_swab_mask) * 8 && \
186          ((rq)->rq_req_swab_mask & (1 << (idx))) != 0)
187
188 #define LASSERT_REPSWABBED(rq, idx)                     \
189 LASSERT ((idx) < sizeof ((rq)->rq_rep_swab_mask) * 8 && \
190          ((rq)->rq_rep_swab_mask & (1 << (idx))) != 0)
191 #else
192 #define LASSERT_REQSWAB(rq, idx)
193 #define LASSERT_REPSWAB(rq, idx)
194 #define LASSERT_REQSWABBED(rq, idx)
195 #define LASSERT_REPSWABBED(rq, idx)
196 #endif
197
198 union ptlrpc_async_args {
199         /* Scratchpad for passing args to completion interpreter. Users
200          * cast to the struct of their choosing, and LASSERT that this is
201          * big enough.  For _tons_ of context, OBD_ALLOC a struct and store
202          * a pointer to it here.  The pointer_arg ensures this struct is at
203          * least big enough for that. */
204         void      *pointer_arg[9];
205         __u64      space[4];
206 };
207
208 struct ptlrpc_request_set;
209 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
210
211 struct ptlrpc_request_set {
212         int               set_remaining; /* # uncompleted requests */
213         wait_queue_head_t set_waitq;
214         wait_queue_head_t *set_wakeup_ptr;
215         struct list_head  set_requests;
216         set_interpreter_func    set_interpret; /* completion callback */
217         void              *set_arg; /* completion context */
218         /* locked so that any old caller can communicate requests to
219          * the set holder who can then fold them into the lock-free set */
220         spinlock_t        set_new_req_lock;
221         struct list_head  set_new_requests;
222 };
223
224 struct ptlrpc_bulk_desc;
225
226 /*
227  * ptlrpc callback & work item stuff
228  */
229 struct ptlrpc_cb_id {
230         void   (*cbid_fn)(lnet_event_t *ev);     /* specific callback fn */
231         void    *cbid_arg;                      /* additional arg */
232 };
233
234 #define RS_MAX_LOCKS 4
235 #define RS_DEBUG     1
236
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;
242 #if RS_DEBUG
243         struct list_head       rs_debug_list;
244 #endif
245         /* updates to following flag serialised by srv_request_lock */
246         unsigned int           rs_difficult:1;     /* ACK/commit stuff */
247         unsigned int           rs_scheduled:1;     /* being handled? */
248         unsigned int           rs_scheduled_ever:1;/* any schedule attempts? */
249         unsigned int           rs_handled:1;  /* been handled yet? */
250         unsigned int           rs_on_net:1;   /* reply_out_callback pending? */
251         unsigned int           rs_prealloc:1; /* rs from prealloc list */
252
253         int                    rs_size;
254         __u64                  rs_transno;
255         __u64                  rs_xid;
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;
260
261         /* locks awaiting client reply ACK */
262         int                    rs_nlocks;
263         struct lustre_handle   rs_locks[RS_MAX_LOCKS];
264         ldlm_mode_t            rs_modes[RS_MAX_LOCKS];
265         /* last member: variable sized reply message */
266         struct lustre_msg      rs_msg;
267 };
268
269 struct ptlrpc_thread;
270
271 enum rq_phase {
272         RQ_PHASE_NEW         = 0xebc0de00,
273         RQ_PHASE_RPC         = 0xebc0de01,
274         RQ_PHASE_BULK        = 0xebc0de02,
275         RQ_PHASE_INTERPRET   = 0xebc0de03,
276         RQ_PHASE_COMPLETE    = 0xebc0de04,
277 };
278
279 struct ptlrpc_request_pool {
280         spinlock_t prp_lock;
281         struct list_head prp_req_list;    /* list of ptlrpc_request structs */
282         int prp_rq_size;
283         void (*prp_populate)(struct ptlrpc_request_pool *, int);
284 };
285
286 struct ptlrpc_request {
287         int rq_type; /* one of PTL_RPC_MSG_* */
288         struct list_head rq_list;
289         struct list_head rq_history_list;       /* server-side history */
290         __u64            rq_history_seq;        /* history sequence # */
291         int rq_status;
292         spinlock_t rq_lock;
293         /* client-side flags */
294         unsigned int rq_intr:1, rq_replied:1, rq_err:1,
295                 rq_timedout:1, rq_resend:1, rq_restart:1,
296                 /*
297                  * when ->rq_replay is set, request is kept by the client even
298                  * after server commits corresponding transaction. This is
299                  * used for operations that require sequence of multiple
300                  * requests to be replayed. The only example currently is file
301                  * open/close. When last request in such a sequence is
302                  * committed, ->rq_replay is cleared on all requests in the
303                  * sequence.
304                  */
305                 rq_replay:1,
306                 rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1,
307                 rq_no_delay:1, rq_net_err:1;
308         enum rq_phase rq_phase; /* one of RQ_PHASE_* */
309         atomic_t rq_refcount;   /* client-side refcount for SENT race */
310
311         struct ptlrpc_thread *rq_svc_thread; /* initial thread servicing req */
312
313         int rq_request_portal;  /* XXX FIXME bug 249 */
314         int rq_reply_portal;    /* XXX FIXME bug 249 */
315
316         int rq_nob_received; /* client-side # reply bytes actually received  */
317
318         int rq_reqlen;
319         struct lustre_msg *rq_reqmsg;
320
321         int rq_timeout;         /* time to wait for reply (seconds) */
322         int rq_replen;
323         struct lustre_msg *rq_repmsg;
324         __u64 rq_transno;
325         __u64 rq_xid;
326         struct list_head rq_replay_list;
327
328 #if SWAB_PARANOIA
329         __u32 rq_req_swab_mask;
330         __u32 rq_rep_swab_mask;
331 #endif
332
333         int rq_import_generation;
334         enum lustre_imp_state rq_send_state;
335
336         /* client+server request */
337         lnet_handle_md_t     rq_req_md_h;
338         struct ptlrpc_cb_id  rq_req_cbid;
339
340         /* server-side... */
341         struct timeval       rq_arrival_time;       /* request arrival time */
342         struct ptlrpc_reply_state *rq_reply_state;  /* separated reply state */
343         struct ptlrpc_request_buffer_desc *rq_rqbd; /* incoming request buffer*/
344 #if CRAY_XT3
345         __u32                rq_uid;            /* peer uid, used in MDS only */
346 #endif
347
348         /* client-only incoming reply */
349         lnet_handle_md_t     rq_reply_md_h;
350         wait_queue_head_t    rq_reply_waitq;
351         struct ptlrpc_cb_id  rq_reply_cbid;
352
353         lnet_nid_t           rq_self;
354         lnet_process_id_t    rq_peer;
355         struct obd_export   *rq_export;
356         struct obd_import   *rq_import;
357
358         void (*rq_replay_cb)(struct ptlrpc_request *);
359         void (*rq_commit_cb)(struct ptlrpc_request *);
360         void  *rq_cb_data;
361
362         struct ptlrpc_bulk_desc *rq_bulk;       /* client side bulk */
363         time_t rq_sent;                         /* when request sent, seconds */
364
365         /* Multi-rpc bits */
366         struct list_head rq_set_chain;
367         struct ptlrpc_request_set *rq_set;
368         void *rq_interpret_reply;               /* Async completion handler */
369         union ptlrpc_async_args rq_async_args;  /* Async completion context */
370         void *rq_ptlrpcd_data;
371         struct ptlrpc_request_pool *rq_pool;    /* Pool if request from
372                                                    preallocated list */
373 };
374
375 static inline const char *
376 ptlrpc_rqphase2str(struct ptlrpc_request *req)
377 {
378         switch (req->rq_phase) {
379         case RQ_PHASE_NEW:
380                 return "New";
381         case RQ_PHASE_RPC:
382                 return "Rpc";
383         case RQ_PHASE_BULK:
384                 return "Bulk";
385         case RQ_PHASE_INTERPRET:
386                 return "Interpret";
387         case RQ_PHASE_COMPLETE:
388                 return "Complete";
389         default:
390                 return "?Phase?";
391         }
392 }
393
394 /* Spare the preprocessor, spoil the bugs. */
395 #define FLAG(field, str) (field ? str : "")
396
397 #define DEBUG_REQ_FLAGS(req)                                                    \
398         ptlrpc_rqphase2str(req),                                                \
399         FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"),                    \
400         FLAG(req->rq_err, "E"),                                                 \
401         FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"),   \
402         FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"),                  \
403         FLAG(req->rq_no_resend, "N"),                                           \
404         FLAG(req->rq_waiting, "W")
405
406 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s"
407
408 #define __DEBUG_REQ(CDEB_TYPE, level, req, fmt, args...)                       \
409 CDEB_TYPE(level, "@@@ " fmt                                                    \
410        " req@%p x"LPD64"/t"LPD64" o%d->%s@%s:%d lens %d/%d ref %d fl "         \
411        REQ_FLAGS_FMT"/%x/%x rc %d/%d\n" , ## args, req, req->rq_xid,           \
412        req->rq_transno,                                                        \
413        req->rq_reqmsg ? req->rq_reqmsg->opc : -1,                              \
414        req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) : "<?>",  \
415        req->rq_import ?                                                        \
416           (char *)req->rq_import->imp_connection->c_remote_uuid.uuid : "<?>",  \
417        (req->rq_import && req->rq_import->imp_client) ?                        \
418            req->rq_import->imp_client->cli_request_portal : -1,                \
419        req->rq_reqlen, req->rq_replen,                                         \
420        atomic_read(&req->rq_refcount),                                         \
421        DEBUG_REQ_FLAGS(req),                                                   \
422        req->rq_reqmsg ? req->rq_reqmsg->flags : 0,                             \
423        req->rq_repmsg ? req->rq_repmsg->flags : 0,                             \
424        req->rq_status, req->rq_repmsg ? req->rq_repmsg->status : 0)
425
426 /* for most callers (level is a constant) this is resolved at compile time */
427 #define DEBUG_REQ(level, req, fmt, args...)                                    \
428 do {                                                                           \
429         if ((level) & (D_ERROR | D_WARNING))                                   \
430             __DEBUG_REQ(CDEBUG_LIMIT, level, req, fmt, ## args);               \
431         else                                                                   \
432             __DEBUG_REQ(CDEBUG, level, req, fmt, ## args);                     \
433 } while (0)
434
435 #define DEBUG_REQ_EX(level, req, fmt, args...)                          \
436 do {                                                                    \
437         if ((level) & (D_ERROR | D_WARNING))                            \
438             __DEBUG_REQ(CDEBUG_LIMIT, D_ERROR, req, fmt, ## args);      \
439         else                                                            \
440             __DEBUG_REQ(CDEBUG_EX, level, req, fmt, ## args);           \
441 } while (0)
442
443 struct ptlrpc_bulk_page {
444         struct list_head bp_link;
445         int bp_buflen;
446         int bp_pageoffset;                      /* offset within a page */
447         struct page *bp_page;
448 };
449
450 #define BULK_GET_SOURCE   0
451 #define BULK_PUT_SINK     1
452 #define BULK_GET_SINK     2
453 #define BULK_PUT_SOURCE   3
454
455 struct ptlrpc_bulk_desc {
456         unsigned int bd_success:1;              /* completed successfully */
457         unsigned int bd_network_rw:1;           /* accessible to the network */
458         unsigned int bd_type:2;                 /* {put,get}{source,sink} */
459         unsigned int bd_registered:1;           /* client side */
460         spinlock_t   bd_lock;                   /* serialise with callback */
461         int bd_import_generation;
462         struct obd_export *bd_export;
463         struct obd_import *bd_import;
464         __u32 bd_portal;
465         struct ptlrpc_request *bd_req;          /* associated request */
466         wait_queue_head_t      bd_waitq;        /* server side only WQ */
467         int                    bd_iov_count;    /* # entries in bd_iov */
468         int                    bd_max_iov;      /* allocated size of bd_iov */
469         int                    bd_nob;          /* # bytes covered */
470         int                    bd_nob_transferred; /* # bytes GOT/PUT */
471
472         __u64                  bd_last_xid;
473
474         struct ptlrpc_cb_id    bd_cbid;         /* network callback info */
475         lnet_handle_md_t        bd_md_h;         /* associated MD */
476
477 #if defined(__KERNEL__)
478         lnet_kiov_t             bd_iov[0];
479 #else
480         lnet_md_iovec_t         bd_iov[0];
481 #endif
482 };
483
484 struct lu_context;
485 struct ptlrpc_thread {
486
487         struct list_head t_link; /* active threads for service, from svc->srv_threads */
488
489         void *t_data;            /* thread-private data (preallocated memory) */
490         __u32 t_flags;
491
492         unsigned int t_id; /* service thread index, from ptlrpc_start_threads */
493         wait_queue_head_t t_ctl_waitq;
494         struct lu_context *t_ctx;
495 };
496
497 struct ptlrpc_request_buffer_desc {
498         struct list_head       rqbd_list;
499         struct list_head       rqbd_reqs;
500         struct ptlrpc_service *rqbd_service;
501         lnet_handle_md_t       rqbd_md_h;
502         int                    rqbd_refcount;
503         char                  *rqbd_buffer;
504         struct ptlrpc_cb_id    rqbd_cbid;
505         struct ptlrpc_request  rqbd_req;
506 };
507
508 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
509 typedef void (*svcreq_printfn_t)(void *, struct ptlrpc_request *);
510
511 struct ptlrpc_service {
512         struct list_head srv_list;              /* chain thru all services */
513         int              srv_max_req_size;      /* biggest request to receive */
514         int              srv_max_reply_size;    /* biggest reply to send */
515         int              srv_buf_size;          /* size of individual buffers */
516         int              srv_nbuf_per_group;    /* # buffers to allocate in 1 group */
517         int              srv_nbufs;             /* total # req buffer descs allocated */
518         int              srv_nthreads;          /* # running threads */
519         int              srv_n_difficult_replies; /* # 'difficult' replies */
520         int              srv_n_active_reqs;     /* # reqs being served */
521         int              srv_rqbd_timeout;      /* timeout before re-posting reqs */
522         int              srv_watchdog_timeout; /* soft watchdog timeout, in ms */
523         int              srv_num_threads;       /* # threads to start/started */
524         unsigned         srv_cpu_affinity:1;    /* bind threads to CPUs */
525
526         __u32            srv_req_portal;
527         __u32            srv_rep_portal;
528
529         int               srv_n_queued_reqs;    /* # reqs waiting to be served */
530         struct list_head  srv_request_queue;    /* reqs waiting for service */
531
532         struct list_head  srv_request_history;  /* request history */
533         __u64             srv_request_seq;      /* next request sequence # */
534         __u64             srv_request_max_cull_seq; /* highest seq culled from history */
535         svcreq_printfn_t  srv_request_history_print_fn; /* service-specific print fn */
536
537         struct list_head  srv_idle_rqbds;       /* request buffers to be reposted */
538         struct list_head  srv_active_rqbds;     /* req buffers receiving */
539         struct list_head  srv_history_rqbds;    /* request buffer history */
540         int               srv_nrqbd_receiving;  /* # posted request buffers */
541         int               srv_n_history_rqbds;  /* # request buffers in history */
542         int               srv_max_history_rqbds; /* max # request buffers in history */
543
544         atomic_t          srv_outstanding_replies;
545         struct list_head  srv_active_replies;   /* all the active replies */
546         struct list_head  srv_reply_queue;      /* replies waiting for service */
547
548         wait_queue_head_t srv_waitq; /* all threads sleep on this. This
549                                       * wait-queue is signalled when new
550                                       * incoming request arrives and when
551                                       * difficult reply has to be handled. */
552
553         struct list_head   srv_threads;
554         svc_handler_t      srv_handler;
555
556         char *srv_name;  /* only statically allocated strings here; we don't clean them */
557
558         spinlock_t               srv_lock;
559
560         struct proc_dir_entry   *srv_procroot;
561         struct lprocfs_stats    *srv_stats;
562
563         /* List of free reply_states */
564         struct list_head         srv_free_rs_list;
565         /* waitq to run, when adding stuff to srv_free_rs_list */
566         wait_queue_head_t        srv_free_rs_waitq;
567
568         /*
569          * if non-NULL called during thread creation (ptlrpc_start_thread())
570          * to initialize service specific per-thread state.
571          */
572         int (*srv_init)(struct ptlrpc_thread *thread);
573         /*
574          * if non-NULL called during thread shutdown (ptlrpc_main()) to
575          * destruct state created by ->srv_init().
576          */
577         void (*srv_done)(struct ptlrpc_thread *thread);
578
579         //struct ptlrpc_srv_ni srv_interfaces[0];
580 };
581
582 /* ptlrpc/events.c */
583 extern lnet_handle_eq_t ptlrpc_eq_h;
584 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
585                                lnet_process_id_t *peer, lnet_nid_t *self);
586 extern void request_out_callback (lnet_event_t *ev);
587 extern void reply_in_callback(lnet_event_t *ev);
588 extern void client_bulk_callback (lnet_event_t *ev);
589 extern void request_in_callback(lnet_event_t *ev);
590 extern void reply_out_callback(lnet_event_t *ev);
591 extern void server_bulk_callback (lnet_event_t *ev);
592
593 /* ptlrpc/connection.c */
594 void ptlrpc_dump_connections(void);
595 void ptlrpc_readdress_connection(struct ptlrpc_connection *, struct obd_uuid *);
596 struct ptlrpc_connection *ptlrpc_get_connection(lnet_process_id_t peer,
597                                                 lnet_nid_t self, struct obd_uuid *uuid);
598 int ptlrpc_put_connection(struct ptlrpc_connection *c);
599 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
600 void ptlrpc_init_connection(void);
601 void ptlrpc_cleanup_connection(void);
602 extern lnet_pid_t ptl_get_pid(void);
603
604 /* ptlrpc/niobuf.c */
605 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
606 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
607 int ptlrpc_register_bulk(struct ptlrpc_request *req);
608 void ptlrpc_unregister_bulk (struct ptlrpc_request *req);
609
610 static inline int ptlrpc_bulk_active (struct ptlrpc_bulk_desc *desc)
611 {
612         unsigned long flags;
613         int           rc;
614
615         spin_lock_irqsave (&desc->bd_lock, flags);
616         rc = desc->bd_network_rw;
617         spin_unlock_irqrestore (&desc->bd_lock, flags);
618         return (rc);
619 }
620
621 int ptlrpc_send_reply(struct ptlrpc_request *req, int);
622 int ptlrpc_reply(struct ptlrpc_request *req);
623 int ptlrpc_error(struct ptlrpc_request *req);
624 void ptlrpc_resend_req(struct ptlrpc_request *request);
625 int ptl_send_rpc(struct ptlrpc_request *request, int noreply);
626 int ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
627
628 /* ptlrpc/client.c */
629 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
630                         struct ptlrpc_client *);
631 void ptlrpc_cleanup_client(struct obd_import *imp);
632 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
633
634 static inline int
635 ptlrpc_client_receiving_reply (struct ptlrpc_request *req)
636 {
637         unsigned long flags;
638         int           rc;
639
640         spin_lock_irqsave(&req->rq_lock, flags);
641         rc = req->rq_receiving_reply;
642         spin_unlock_irqrestore(&req->rq_lock, flags);
643         return (rc);
644 }
645
646 static inline int
647 ptlrpc_client_replied (struct ptlrpc_request *req)
648 {
649         unsigned long flags;
650         int           rc;
651
652         spin_lock_irqsave(&req->rq_lock, flags);
653         rc = req->rq_replied;
654         spin_unlock_irqrestore(&req->rq_lock, flags);
655         return (rc);
656 }
657
658 static inline void
659 ptlrpc_wake_client_req (struct ptlrpc_request *req)
660 {
661         if (req->rq_set == NULL)
662                 wake_up(&req->rq_reply_waitq);
663         else
664                 wake_up(&req->rq_set->set_waitq);
665 }
666
667 int ptlrpc_queue_wait(struct ptlrpc_request *req);
668 int ptlrpc_replay_req(struct ptlrpc_request *req);
669 void ptlrpc_unregister_reply(struct ptlrpc_request *req);
670 void ptlrpc_restart_req(struct ptlrpc_request *req);
671 void ptlrpc_abort_inflight(struct obd_import *imp);
672
673 struct ptlrpc_request_set *ptlrpc_prep_set(void);
674 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
675 int ptlrpc_check_set(struct ptlrpc_request_set *set);
676 int ptlrpc_set_wait(struct ptlrpc_request_set *);
677 int ptlrpc_expired_set(void *data);
678 void ptlrpc_interrupted_set(void *data);
679 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
680 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
681 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
682 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *,
683                             struct ptlrpc_request *);
684
685 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
686 void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
687 struct ptlrpc_request_pool *ptlrpc_init_rq_pool(int, int,
688                                                 void (*populate_pool)(struct ptlrpc_request_pool *, int));
689 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version, int opcode,
690                                        int count, int *lengths, char **bufs);
691 struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp, __u32 version, int opcode,
692                                             int count, int *lengths, char **bufs,
693                                             struct ptlrpc_request_pool *pool);
694 void ptlrpc_free_req(struct ptlrpc_request *request);
695 void ptlrpc_req_finished(struct ptlrpc_request *request);
696 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
697 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
698 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
699                                                int npages, int type, int portal);
700 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
701                                               int npages, int type, int portal);
702 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
703 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
704                            struct page *page, int pageoffset, int len);
705 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
706                                       struct obd_import *imp);
707 __u64 ptlrpc_next_xid(void);
708 __u64 ptlrpc_sample_next_xid(void);
709 __u64 ptlrpc_req_xid(struct ptlrpc_request *request);
710
711 struct ptlrpc_service_conf {
712         int psc_nbufs;
713         int psc_bufsize;
714         int psc_max_req_size;
715         int psc_max_reply_size;
716         int psc_req_portal;
717         int psc_rep_portal;
718         int psc_watchdog_timeout; /* in ms */
719         int psc_num_threads;
720 };
721
722
723 /* ptlrpc/service.c */
724 void ptlrpc_save_lock (struct ptlrpc_request *req,
725                        struct lustre_handle *lock, int mode);
726 void ptlrpc_commit_replies (struct obd_device *obd);
727 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
728
729 struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
730                                             svc_handler_t h, char *name,
731                                             struct proc_dir_entry *proc_entry,
732                                             svcreq_printfn_t prntfn);
733
734 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
735                                        int max_reply_size,
736                                        int req_portal, int rep_portal,
737                                        int watchdog_timeout, /* in ms */
738                                        svc_handler_t, char *name,
739                                        struct proc_dir_entry *proc_entry,
740                                        svcreq_printfn_t, int num_threads);
741 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
742
743 int ptlrpc_start_threads(struct obd_device *dev, struct ptlrpc_service *svc,
744                          char *base_name);
745 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
746                         char *name, int id);
747 int ptlrpc_unregister_service(struct ptlrpc_service *service);
748 int liblustre_check_services (void *arg);
749 void ptlrpc_daemonize(char *name);
750 int ptlrpc_service_health_check(struct ptlrpc_service *);
751
752
753 struct ptlrpc_svc_data {
754         char *name;
755         struct ptlrpc_service *svc;
756         struct ptlrpc_thread *thread;
757         struct obd_device *dev;
758 };
759
760 /* ptlrpc/import.c */
761 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
762 int ptlrpc_init_import(struct obd_import *imp);
763 int ptlrpc_disconnect_import(struct obd_import *imp);
764 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
765
766 /* ptlrpc/pack_generic.c */
767 int lustre_msg_swabbed(struct lustre_msg *msg);
768 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
769 int lustre_pack_request(struct ptlrpc_request *, int count, const int *lens,
770                         char **bufs);
771 int lustre_pack_reply(struct ptlrpc_request *, int count, const int *lens,
772                       char **bufs);
773 void lustre_shrink_reply(struct ptlrpc_request *req,
774                          int segment, unsigned int newlen, int move_data);
775 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
776 int lustre_msg_size(int count, const int *lengths);
777 int lustre_unpack_msg(struct lustre_msg *m, int len);
778 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
779 int lustre_msg_buflen(struct lustre_msg *m, int n);
780 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
781 void *lustre_swab_buf(struct lustre_msg *, int n, int minlen, void *swabber);
782 void *lustre_swab_reqbuf (struct ptlrpc_request *req, int n, int minlen,
783                           void *swabber);
784 void *lustre_swab_repbuf (struct ptlrpc_request *req, int n, int minlen,
785                           void *swabber);
786
787 static inline void
788 ptlrpc_rs_addref(struct ptlrpc_reply_state *rs)
789 {
790         LASSERT(atomic_read(&rs->rs_refcount) > 0);
791         atomic_inc(&rs->rs_refcount);
792 }
793
794 static inline void
795 ptlrpc_rs_decref(struct ptlrpc_reply_state *rs)
796 {
797         LASSERT(atomic_read(&rs->rs_refcount) > 0);
798         if (atomic_dec_and_test(&rs->rs_refcount))
799                 lustre_free_reply_state(rs);
800 }
801
802 /* ldlm/ldlm_lib.c */
803 int client_obd_setup(struct obd_device *obddev, struct lustre_cfg* lcfg);
804 int client_obd_cleanup(struct obd_device * obddev);
805 int client_connect_import(struct lustre_handle *conn, struct obd_device *obd,
806                           struct obd_uuid *cluuid, struct obd_connect_data *);
807 int client_disconnect_export(struct obd_export *exp);
808 int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
809                            int priority);
810 int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid);
811 int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
812
813 /* ptlrpc/pinger.c */
814 int ptlrpc_pinger_add_import(struct obd_import *imp);
815 int ptlrpc_pinger_del_import(struct obd_import *imp);
816 #ifdef __KERNEL__
817 void ping_evictor_start(void);
818 void ping_evictor_stop(void);
819 #else
820 #define ping_evictor_start()    do {} while (0)
821 #define ping_evictor_stop()     do {} while (0)
822 #endif
823
824 /* ptlrpc/ptlrpcd.c */
825 void ptlrpcd_wake(struct ptlrpc_request *req);
826 void ptlrpcd_add_req(struct ptlrpc_request *req);
827 int ptlrpcd_addref(void);
828 void ptlrpcd_decref(void);
829
830 /* ptlrpc/lproc_ptlrpc.c */
831 #ifdef LPROCFS
832 void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
833 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
834 #else
835 static inline void ptlrpc_lprocfs_register_obd(struct obd_device *obd) {}
836 static inline void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) {}
837 #endif
838
839 /* ptlrpc/llog_server.c */
840 int llog_origin_handle_create(struct ptlrpc_request *req);
841 int llog_origin_handle_destroy(struct ptlrpc_request *req);
842 int llog_origin_handle_prev_block(struct ptlrpc_request *req);
843 int llog_origin_handle_next_block(struct ptlrpc_request *req);
844 int llog_origin_handle_read_header(struct ptlrpc_request *req);
845 int llog_origin_handle_close(struct ptlrpc_request *req);
846 int llog_origin_handle_cancel(struct ptlrpc_request *req);
847 int llog_catinfo(struct ptlrpc_request *req);
848
849 /* ptlrpc/llog_client.c */
850 extern struct llog_operations llog_client_ops;
851
852 #endif