Whamcloud - gitweb
Land b_smallfix onto HEAD (20040223_1817)
[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 <linux/kp30.h>
36 // #include <linux/obd.h>
37 #include <portals/p30.h>
38 #include <portals/lib-types.h>                  /* FIXME (for PTL_MD_MAX_IOV) */
39 #include <linux/lustre_idl.h>
40 #include <linux/lustre_ha.h>
41 #include <linux/lustre_import.h>
42 #include <linux/lprocfs_status.h>
43
44 /* Size over which to OBD_VMALLOC() rather than OBD_ALLOC() service request
45  * buffers */
46 #define SVC_BUF_VMALLOC_THRESHOLD (2*PAGE_SIZE)
47
48 /* The following constants determine how much memory is devoted to
49  * buffering in the lustre services.
50  *
51  * ?_NEVENTS            # event queue entries
52  *
53  * ?_NBUFS              # request buffers
54  * ?_BUFSIZE            # bytes in a single request buffer
55  * total memory = ?_NBUFS * ?_BUFSIZE
56  *
57  * ?_MAXREQSIZE         # maximum request service will receive
58  * messages larger than ?_MAXREQSIZE are dropped.
59  * request buffers are auto-unlinked when less than ?_MAXREQSIZE
60  * is left in them.
61  */
62
63 #define LDLM_NUM_THREADS        min(smp_num_cpus * smp_num_cpus * 8, 64)
64 #define LDLM_NBUF_MAX   256UL
65 #define LDLM_BUFSIZE    (8 * 1024)
66 #define LDLM_MAXREQSIZE (5 * 1024)
67 #define LDLM_MAXMEM      (num_physpages*(PAGE_SIZE/1024))
68 #define LDLM_NBUFS       min(LDLM_MAXMEM/LDLM_BUFSIZE, LDLM_NBUF_MAX)
69
70 #define MDT_MAX_THREADS 32UL
71 #define MDT_NUM_THREADS max(min_t(unsigned long, num_physpages / 8192, \
72                                   MDT_MAX_THREADS), 2UL)
73 #define MDS_NBUF_MAX    512UL
74 #define MDS_BUFSIZE     (8 * 1024)
75 /* Assume file name length = FNAME_MAX = 256 (true for extN).
76  *        path name length = PATH_MAX = 4096
77  *        LOV MD size max  = EA_MAX = 4000
78  * symlink:  FNAME_MAX + PATH_MAX  <- largest
79  * link:     FNAME_MAX + PATH_MAX  (mds_rec_link < mds_rec_create)
80  * rename:   FNAME_MAX + FNAME_MAX
81  * open:     FNAME_MAX + EA_MAX
82  *
83  * MDS_MAXREQSIZE ~= 4736 bytes =
84  * lustre_msg + ldlm_request + mds_body + mds_rec_create + FNAME_MAX + PATH_MAX
85  *
86  * Realistic size is about 512 bytes (20 character name + 128 char symlink),
87  * except in the open case where there are a large number of OSTs in a LOV.
88  */
89 #define MDS_MAXREQSIZE  (5 * 1024)
90 #define MDS_MAXMEM      (num_physpages*(PAGE_SIZE/128))
91 #define MDS_NBUFS       min(MDS_MAXMEM/MDS_BUFSIZE, MDS_NBUF_MAX)
92
93 #define OST_MAX_THREADS 36UL
94 #define OST_NUM_THREADS max(min_t(unsigned long, num_physpages / 8192, \
95                                   OST_MAX_THREADS), 2UL)
96 #define OST_NBUF_MAX    5000UL
97 #define OST_BUFSIZE     (8 * 1024)
98 /* OST_MAXREQSIZE ~= 1640 bytes =
99  * lustre_msg + obdo + 16 * obd_ioobj + 64 * niobuf_remote
100  *
101  * - single object with 16 pages is 512 bytes
102  * - OST_MAXREQSIZE must be at least 1 page of cookies plus some spillover
103  */
104 #define OST_MAXREQSIZE  (5 * 1024)
105 #define OST_MAXMEM      (num_physpages*(PAGE_SIZE/128))
106 #define OST_NBUFS       min(OST_MAXMEM/OST_BUFSIZE, OST_NBUF_MAX)
107
108 #define PTLBD_NUM_THREADS        4
109 #define PTLBD_NBUFS      20
110 #define PTLBD_BUFSIZE    (32 * 1024)
111 #define PTLBD_MAXREQSIZE 1024
112
113 struct ptlrpc_peer {
114         ptl_nid_t         peer_nid;
115         struct ptlrpc_ni *peer_ni;
116 };
117
118 struct ptlrpc_connection {
119         struct list_head        c_link;
120         struct ptlrpc_peer      c_peer;
121         struct obd_uuid         c_remote_uuid;
122         atomic_t                c_refcount;
123 };
124
125 struct ptlrpc_client {
126         __u32                     cli_request_portal;
127         __u32                     cli_reply_portal;
128         char                     *cli_name;
129 };
130
131 /* state flags of requests */
132 /* XXX only ones left are those used by the bulk descs as well! */
133 #define PTL_RPC_FL_INTR      (1 << 0)  /* reply wait was interrupted by user */
134 #define PTL_RPC_FL_TIMEOUT   (1 << 7)  /* request timed out waiting for reply */
135
136 #define REQ_MAX_ACK_LOCKS 8
137
138 #define SWAB_PARANOIA 1
139 #if SWAB_PARANOIA
140 /* unpacking: assert idx not unpacked already */
141 #define LASSERT_REQSWAB(rq, idx)                                \
142 do {                                                            \
143         LASSERT ((idx) < sizeof ((rq)->rq_req_swab_mask) * 8);  \
144         LASSERT (((rq)->rq_req_swab_mask & (1 << (idx))) == 0); \
145         (rq)->rq_req_swab_mask |= (1 << (idx));                 \
146 } while (0)
147
148 #define LASSERT_REPSWAB(rq, idx)                                \
149 do {                                                            \
150         LASSERT ((idx) < sizeof ((rq)->rq_rep_swab_mask) * 8);  \
151         LASSERT (((rq)->rq_rep_swab_mask & (1 << (idx))) == 0); \
152         (rq)->rq_rep_swab_mask |= (1 << (idx));                 \
153 } while (0)
154
155 /* just looking: assert idx already unpacked */
156 #define LASSERT_REQSWABBED(rq, idx)                     \
157 LASSERT ((idx) < sizeof ((rq)->rq_req_swab_mask) * 8 && \
158          ((rq)->rq_req_swab_mask & (1 << (idx))) != 0)
159
160 #define LASSERT_REPSWABBED(rq, idx)                     \
161 LASSERT ((idx) < sizeof ((rq)->rq_rep_swab_mask) * 8 && \
162          ((rq)->rq_rep_swab_mask & (1 << (idx))) != 0)
163 #else
164 #define LASSERT_REQSWAB(rq, idx)
165 #define LASSERT_REPSWAB(rq, idx)
166 #define LASSERT_REQSWABBED(rq, idx)
167 #define LASSERT_REPSWABBED(rq, idx)
168 #endif
169
170 union ptlrpc_async_args {
171         /* Scratchpad for passing args to completion interpreter. Users
172          * cast to the struct of their choosing, and LASSERT that this is
173          * big enough.  For _tons_ of context, OBD_ALLOC a struct and store
174          * a pointer to it here.  The pointer_arg ensures this struct is at
175          * least big enough for that. */
176         void      *pointer_arg[9];
177         __u64      space[4];
178 };
179
180 struct ptlrpc_request_set;
181 typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
182
183 struct ptlrpc_request_set {
184         int               set_remaining; /* # uncompleted requests */
185         wait_queue_head_t set_waitq;
186         wait_queue_head_t *set_wakeup_ptr;
187         struct list_head  set_requests;
188         set_interpreter_func    set_interpret; /* completion callback */
189         union ptlrpc_async_args set_args; /* completion context */
190         /* locked so that any old caller can communicate requests to
191          * the set holder who can then fold them into the lock-free set */
192         spinlock_t        set_new_req_lock;
193         struct list_head  set_new_requests;
194 };
195
196 struct ptlrpc_bulk_desc;
197
198 /*
199  * ptlrpc callback & work item stuff
200  */
201 struct ptlrpc_cb_id {
202         void   (*cbid_fn)(ptl_event_t *ev);     /* specific callback fn */
203         void    *cbid_arg;                      /* additional arg */
204 };
205
206 #define RS_MAX_LOCKS 4
207 #define RS_DEBUG     1
208
209 struct ptlrpc_reply_state {
210         struct ptlrpc_cb_id   rs_cb_id;
211         struct list_head      rs_list;
212         struct list_head      rs_exp_list;
213         struct list_head      rs_obd_list;
214 #if RS_DEBUG
215         struct list_head      rs_debug_list;
216 #endif
217         /* updates to following flag serialised by srv_request_lock */
218         unsigned int          rs_difficult:1;   /* ACK/commit stuff */
219         unsigned int          rs_scheduled:1;   /* being handled? */
220         unsigned int          rs_scheduled_ever:1; /* any schedule attempts? */
221         unsigned int          rs_handled:1;     /* been handled yet? */
222         unsigned int          rs_on_net:1;      /* reply_out_callback pending? */
223
224         int                   rs_size;
225         __u64                 rs_transno;
226         __u64                 rs_xid;
227         struct obd_export    *rs_export;
228         struct ptlrpc_srv_ni *rs_srv_ni;
229         ptl_handle_md_t       rs_md_h;
230
231         /* locks awaiting client reply ACK */
232         int                   rs_nlocks;
233         struct lustre_handle  rs_locks[RS_MAX_LOCKS];
234         ldlm_mode_t           rs_modes[RS_MAX_LOCKS];
235         /* last member: variable sized reply message */
236         struct lustre_msg     rs_msg;
237 };
238
239 struct ptlrpc_request {
240         int rq_type; /* one of PTL_RPC_MSG_* */
241         struct list_head rq_list;
242         int rq_status;
243         spinlock_t rq_lock;
244         /* client-side flags */
245         unsigned int rq_intr:1, rq_replied:1, rq_err:1,
246             rq_timedout:1, rq_resend:1, rq_restart:1, rq_replay:1,
247             rq_no_resend:1, rq_waiting:1, rq_receiving_reply:1;
248         int rq_phase;
249         /* client-side refcount for SENT race */
250         atomic_t rq_refcount;
251
252         int rq_request_portal; /* XXX FIXME bug 249 */
253         int rq_reply_portal; /* XXX FIXME bug 249 */
254
255         /* client-side # reply bytes actually received  */
256         int rq_nob_received;
257
258         int rq_reqlen;
259         struct lustre_msg *rq_reqmsg;
260
261         int rq_timeout;
262         int rq_replen;
263         struct lustre_msg *rq_repmsg;
264         __u64 rq_transno;
265         __u64 rq_xid;
266         struct list_head rq_replay_list;
267
268 #if SWAB_PARANOIA
269         __u32 rq_req_swab_mask;
270         __u32 rq_rep_swab_mask;
271 #endif
272
273         int rq_import_generation;
274         enum lustre_imp_state rq_send_state;
275
276         /* client+server request */
277         ptl_handle_md_t      rq_req_md_h;
278         struct ptlrpc_cb_id  rq_req_cbid;
279
280         /* server-side... */
281         struct timeval                     rq_arrival_time; /* request arrival time */
282         struct ptlrpc_reply_state         *rq_reply_state; /* separated reply state */
283         struct ptlrpc_request_buffer_desc *rq_rqbd; /* incoming request buffer */
284         
285         /* client-only incoming reply */
286         ptl_handle_md_t      rq_reply_md_h;
287         wait_queue_head_t    rq_reply_waitq;
288         struct ptlrpc_cb_id  rq_reply_cbid;
289         
290         struct ptlrpc_peer rq_peer; /* XXX see service.c can this be factored away? */
291         struct obd_export *rq_export;
292         struct obd_import *rq_import;
293         
294         void (*rq_replay_cb)(struct ptlrpc_request *);
295         void (*rq_commit_cb)(struct ptlrpc_request *);
296         void  *rq_cb_data;
297
298         struct ptlrpc_bulk_desc *rq_bulk;       /* client side bulk */
299         time_t rq_sent;                         /* when the request was sent */
300
301         /* Multi-rpc bits */
302         struct list_head rq_set_chain;
303         struct ptlrpc_request_set *rq_set;
304         void *rq_interpret_reply;               /* Async completion handler */
305         union ptlrpc_async_args rq_async_args;  /* Async completion context */
306 };
307
308
309 #define RQ_PHASE_NEW           0xebc0de00
310 #define RQ_PHASE_RPC           0xebc0de01
311 #define RQ_PHASE_BULK          0xebc0de02
312 #define RQ_PHASE_INTERPRET     0xebc0de03
313 #define RQ_PHASE_COMPLETE      0xebc0de04
314
315 /* Spare the preprocessor, spoil the bugs. */
316 #define FLAG(field, str) (field ? str : "")
317
318 #define PTLRPC_REQUEST_COMPLETE(req) ((req)->rq_phase > RQ_PHASE_RPC)
319
320 #define DEBUG_REQ_FLAGS(req)                                                    \
321         ((req->rq_phase == RQ_PHASE_NEW) ? "New" :                              \
322          (req->rq_phase == RQ_PHASE_RPC) ? "Rpc" :                              \
323          (req->rq_phase == RQ_PHASE_INTERPRET) ? "Interpret" :                  \
324          (req->rq_phase == RQ_PHASE_COMPLETE) ? "Complete" : "?phase?"),        \
325         FLAG(req->rq_intr, "I"), FLAG(req->rq_replied, "R"),                    \
326         FLAG(req->rq_err, "E"),                                                 \
327         FLAG(req->rq_timedout, "X") /* eXpired */, FLAG(req->rq_resend, "S"),   \
328         FLAG(req->rq_restart, "T"), FLAG(req->rq_replay, "P"),                  \
329         FLAG(req->rq_no_resend, "N"),                                           \
330         FLAG(req->rq_waiting, "W")
331
332 #define REQ_FLAGS_FMT "%s:%s%s%s%s%s%s%s%s%s"
333
334 #define DEBUG_REQ(level, req, fmt, args...)                                    \
335 do {                                                                           \
336 CDEBUG(level, "@@@ " fmt                                                       \
337        " req@%p x"LPD64"/t"LPD64" o%d->%s@%s:%d lens %d/%d ref %d fl "         \
338        REQ_FLAGS_FMT"/%x/%x rc %d/%d\n" , ## args, req, req->rq_xid,           \
339        req->rq_transno,                                                        \
340        req->rq_reqmsg ? req->rq_reqmsg->opc : -1,                              \
341        req->rq_import ? (char *)req->rq_import->imp_target_uuid.uuid : "<?>",  \
342        req->rq_import ?                                                        \
343           (char *)req->rq_import->imp_connection->c_remote_uuid.uuid : "<?>",  \
344        (req->rq_import && req->rq_import->imp_client) ?                        \
345            req->rq_import->imp_client->cli_request_portal : -1,                \
346        req->rq_reqlen, req->rq_replen,                                         \
347        atomic_read(&req->rq_refcount),                                         \
348        DEBUG_REQ_FLAGS(req),                                                   \
349        req->rq_reqmsg ? req->rq_reqmsg->flags : 0,                             \
350        req->rq_repmsg ? req->rq_repmsg->flags : 0,                             \
351        req->rq_status, req->rq_repmsg ? req->rq_repmsg->status : 0);           \
352 } while (0)
353
354 struct ptlrpc_bulk_page {
355         struct list_head bp_link;
356         int bp_buflen;
357         int bp_pageoffset;                      /* offset within a page */
358         struct page *bp_page;
359 };
360
361 #define BULK_GET_SOURCE   0
362 #define BULK_PUT_SINK     1
363 #define BULK_GET_SINK     2
364 #define BULK_PUT_SOURCE   3
365
366 struct ptlrpc_bulk_desc {
367         unsigned int bd_success:1;              /* completed successfully */
368         unsigned int bd_network_rw:1;           /* accessible to the network */
369         unsigned int bd_type:2;                 /* {put,get}{source,sink} */
370         unsigned int bd_registered:1;           /* client side */
371         spinlock_t   bd_lock;                   /* serialise with callback */
372         int bd_import_generation;
373         struct obd_export *bd_export;
374         struct obd_import *bd_import;
375         __u32 bd_portal;
376         struct ptlrpc_request *bd_req;          /* associated request */
377         wait_queue_head_t      bd_waitq;        /* server side only WQ */
378         int                    bd_page_count;   /* # pages (== entries in bd_iov) */
379         int                    bd_max_pages;    /* allocated size of bd_iov */
380         int                    bd_nob;          /* # bytes covered */
381         int                    bd_nob_transferred; /* # bytes GOT/PUT */
382
383         __u64                  bd_last_xid;
384
385         struct ptlrpc_cb_id    bd_cbid;         /* network callback info */
386         ptl_handle_md_t        bd_md_h;         /* associated MD */
387         
388 #ifdef __KERNEL__
389         ptl_kiov_t bd_iov[PTL_MD_MAX_IOV];
390 #else
391         struct iovec bd_iov[PTL_MD_MAX_IOV];
392 #endif
393 };
394
395 struct ptlrpc_thread {
396         struct list_head t_link;
397
398         __u32 t_flags;
399         wait_queue_head_t t_ctl_waitq;
400 };
401
402 struct ptlrpc_request_buffer_desc {
403         struct list_head       rqbd_list;
404         struct ptlrpc_srv_ni  *rqbd_srv_ni;
405         ptl_handle_md_t        rqbd_md_h;
406         int                    rqbd_refcount;
407         int                    rqbd_eventcount;
408         char                  *rqbd_buffer;
409         struct ptlrpc_cb_id    rqbd_cbid;
410         struct ptlrpc_request  rqbd_req;
411 };
412
413 /* event queues are per-ni, because one day we may get a hardware
414  * supported NAL that delivers events asynchonously wrt kernel portals
415  * into the eq.
416  */
417 struct ptlrpc_ni { /* Generic interface state */
418         char                   *pni_name;
419         int                     pni_number;
420         ptl_handle_ni_t         pni_ni_h;
421         ptl_handle_eq_t         pni_eq_h;
422 };
423
424 struct ptlrpc_srv_ni {
425         /* Interface-specific service state */
426         struct ptlrpc_service  *sni_service;    /* owning service */
427         struct ptlrpc_ni       *sni_ni;         /* network interface */
428         struct list_head        sni_rqbds;      /* all the request buffers */
429         struct list_head        sni_active_replies; /* all the active replies */
430         int                     sni_nrqbd_receiving; /* # posted request buffers */
431 };
432
433 typedef int (*svc_handler_t)(struct ptlrpc_request *req);
434
435 struct ptlrpc_service {
436         struct list_head srv_list;              /* chain thru all services */
437         int              srv_max_req_size;      /* biggest request to receive */
438         int              srv_buf_size;          /* size of individual buffers */
439         int              srv_nbufs;             /* total # req buffer descs allocated */
440         int              srv_nthreads;          /* # running threads */
441         int              srv_n_difficult_replies; /* # 'difficult' replies */
442         int              srv_n_active_reqs;     /* # reqs being served */
443         
444         __u32 srv_req_portal;
445         __u32 srv_rep_portal;
446
447         int               srv_n_queued_reqs;    /* # reqs waiting to be served */
448         struct list_head  srv_request_queue;    /* reqs waiting for service */
449
450         atomic_t          srv_outstanding_replies;
451         struct list_head  srv_reply_queue;      /* replies waiting for service */
452
453         wait_queue_head_t srv_waitq; /* all threads sleep on this */
454
455         struct list_head   srv_threads;
456         struct obd_device *srv_obddev;
457         svc_handler_t      srv_handler;
458         
459         char *srv_name;  /* only statically allocated strings here; we don't clean them */
460
461         spinlock_t               srv_lock;
462
463         struct proc_dir_entry   *srv_procroot;
464         struct lprocfs_stats    *srv_stats;
465         
466         struct ptlrpc_srv_ni srv_interfaces[0];
467 };
468
469 /* ptlrpc/events.c */
470 extern struct ptlrpc_ni ptlrpc_interfaces[];
471 extern int              ptlrpc_ninterfaces;
472 extern int ptlrpc_uuid_to_peer(struct obd_uuid *uuid, struct ptlrpc_peer *peer);
473 extern void request_out_callback (ptl_event_t *ev);
474 extern void reply_in_callback(ptl_event_t *ev);
475 extern void client_bulk_callback (ptl_event_t *ev);
476 extern void request_in_callback(ptl_event_t *ev);
477 extern void reply_out_callback(ptl_event_t *ev);
478 extern void server_bulk_callback (ptl_event_t *ev);
479
480 /* ptlrpc/connection.c */
481 void ptlrpc_dump_connections(void);
482 void ptlrpc_readdress_connection(struct ptlrpc_connection *, struct obd_uuid *);
483 struct ptlrpc_connection *ptlrpc_get_connection(struct ptlrpc_peer *peer,
484                                                 struct obd_uuid *uuid);
485 int ptlrpc_put_connection(struct ptlrpc_connection *c);
486 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
487 void ptlrpc_init_connection(void);
488 void ptlrpc_cleanup_connection(void);
489
490 /* ptlrpc/niobuf.c */
491 int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc);
492 void ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *desc);
493 int ptlrpc_register_bulk(struct ptlrpc_request *req);
494 void ptlrpc_unregister_bulk (struct ptlrpc_request *req);
495
496 static inline int ptlrpc_bulk_active (struct ptlrpc_bulk_desc *desc) 
497 {
498         unsigned long flags;
499         int           rc;
500
501         spin_lock_irqsave (&desc->bd_lock, flags);
502         rc = desc->bd_network_rw;
503         spin_unlock_irqrestore (&desc->bd_lock, flags);
504         return (rc);
505 }
506
507 int ptlrpc_send_reply(struct ptlrpc_request *req, int);
508 int ptlrpc_reply(struct ptlrpc_request *req);
509 int ptlrpc_error(struct ptlrpc_request *req);
510 void ptlrpc_resend_req(struct ptlrpc_request *request);
511 int ptl_send_rpc(struct ptlrpc_request *request);
512 void ptlrpc_register_rqbd (struct ptlrpc_request_buffer_desc *rqbd);
513
514 /* ptlrpc/client.c */
515 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
516                         struct ptlrpc_client *);
517 void ptlrpc_cleanup_client(struct obd_import *imp);
518 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
519
520 static inline int
521 ptlrpc_client_receiving_reply (struct ptlrpc_request *req)
522 {
523         unsigned long flags;
524         int           rc;
525         
526         spin_lock_irqsave(&req->rq_lock, flags);
527         rc = req->rq_receiving_reply;
528         spin_unlock_irqrestore(&req->rq_lock, flags);
529         return (rc);
530 }
531
532 static inline int
533 ptlrpc_client_replied (struct ptlrpc_request *req)
534 {
535         unsigned long flags;
536         int           rc;
537         
538         spin_lock_irqsave(&req->rq_lock, flags);
539         rc = req->rq_replied;
540         spin_unlock_irqrestore(&req->rq_lock, flags);
541         return (rc);
542 }
543
544 static inline void
545 ptlrpc_wake_client_req (struct ptlrpc_request *req)
546 {
547         if (req->rq_set == NULL)
548                 wake_up(&req->rq_reply_waitq);
549         else
550                 wake_up(&req->rq_set->set_waitq);
551 }
552
553 int ptlrpc_queue_wait(struct ptlrpc_request *req);
554 int ptlrpc_replay_req(struct ptlrpc_request *req);
555 void ptlrpc_unregister_reply(struct ptlrpc_request *req);
556 void ptlrpc_restart_req(struct ptlrpc_request *req);
557 void ptlrpc_abort_inflight(struct obd_import *imp);
558
559 struct ptlrpc_request_set *ptlrpc_prep_set(void);
560 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
561 int ptlrpc_check_set(struct ptlrpc_request_set *set);
562 int ptlrpc_set_wait(struct ptlrpc_request_set *);
563 int ptlrpc_expired_set(void *data);
564 void ptlrpc_interrupted_set(void *data);
565 void ptlrpc_mark_interrupted(struct ptlrpc_request *req);
566 void ptlrpc_set_destroy(struct ptlrpc_request_set *);
567 void ptlrpc_set_add_req(struct ptlrpc_request_set *, struct ptlrpc_request *);
568 void ptlrpc_set_add_new_req(struct ptlrpc_request_set *,
569                             struct ptlrpc_request *);
570
571 struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, int opcode,
572                                        int count, int *lengths, char **bufs);
573 void ptlrpc_free_req(struct ptlrpc_request *request);
574 void ptlrpc_req_finished(struct ptlrpc_request *request);
575 void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
576 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
577 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp (struct ptlrpc_request *req,
578                                                int npages, int type, int portal);
579 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_exp(struct ptlrpc_request *req,
580                                               int npages, int type, int portal);
581 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
582 void ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
583                            struct page *page, int pageoffset, int len);
584 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
585                                       struct obd_import *imp);
586 __u64 ptlrpc_next_xid(void);
587
588 /* ptlrpc/service.c */
589 void ptlrpc_save_lock (struct ptlrpc_request *req, 
590                        struct lustre_handle *lock, int mode);
591 void ptlrpc_commit_replies (struct obd_device *obd);
592 void ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs);
593 struct ptlrpc_service *ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
594                                        int req_portal, int rep_portal, 
595                                        svc_handler_t, char *name,
596                                        struct proc_dir_entry *proc_entry);
597 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
598 int ptlrpc_start_n_threads(struct obd_device *dev, struct ptlrpc_service *svc,
599                            int cnt, char *base_name);
600 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
601                         char *name);
602 int ptlrpc_unregister_service(struct ptlrpc_service *service);
603 int liblustre_check_services (void *arg);
604
605 struct ptlrpc_svc_data {
606         char *name;
607         struct ptlrpc_service *svc;
608         struct ptlrpc_thread *thread;
609         struct obd_device *dev;
610 };
611
612 /* ptlrpc/import.c */
613 int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid);
614 int ptlrpc_init_import(struct obd_import *imp);
615 int ptlrpc_disconnect_import(struct obd_import *imp);
616 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
617
618 /* ptlrpc/pack_generic.c */
619 int lustre_msg_swabbed(struct lustre_msg *msg);
620 int lustre_pack_request(struct ptlrpc_request *, int count, int *lens,
621                         char **bufs);
622 int lustre_pack_reply(struct ptlrpc_request *, int count, int *lens,
623                       char **bufs);
624 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
625 int lustre_msg_size(int count, int *lengths);
626 int lustre_unpack_msg(struct lustre_msg *m, int len);
627 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
628 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
629 void *lustre_swab_buf(struct lustre_msg *, int n, int minlen, void *swabber);
630 void *lustre_swab_reqbuf (struct ptlrpc_request *req, int n, int minlen,
631                           void *swabber);
632 void *lustre_swab_repbuf (struct ptlrpc_request *req, int n, int minlen,
633                           void *swabber);
634
635 /* ldlm/ldlm_lib.c */
636 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf);
637 int client_obd_cleanup(struct obd_device * obddev, int flags);
638 int client_connect_import(struct lustre_handle *conn, struct obd_device *obd,
639                           struct obd_uuid *cluuid);
640 int client_disconnect_export(struct obd_export *exp, int failover);
641
642 /* ptlrpc/pinger.c */
643 int ptlrpc_pinger_add_import(struct obd_import *imp);
644 int ptlrpc_pinger_del_import(struct obd_import *imp);
645
646 /* ptlrpc/ptlrpcd.c */
647 void ptlrpcd_wake(void);
648 void ptlrpcd_add_req(struct ptlrpc_request *req);
649 int ptlrpcd_addref(void);
650 void ptlrpcd_decref(void);
651
652 /* ptlrpc/lproc_ptlrpc.c */
653 #ifdef __KERNEL__
654 void ptlrpc_lprocfs_register_obd(struct obd_device *obddev);
655 void ptlrpc_lprocfs_unregister_obd(struct obd_device *obddev);
656 #else
657 #define ptlrpc_lprocfs_register_obd(param...) do{}while(0)
658 #define ptlrpc_lprocfs_unregister_obd(param...) do{}while(0)
659 #endif
660
661 /* ptlrpc/llog_server.c */
662 int llog_origin_handle_create(struct ptlrpc_request *req);
663 int llog_origin_handle_next_block(struct ptlrpc_request *req);
664 int llog_origin_handle_read_header(struct ptlrpc_request *req);
665 int llog_origin_handle_close(struct ptlrpc_request *req);
666 int llog_origin_handle_cancel(struct ptlrpc_request *req);
667 int llog_catinfo(struct ptlrpc_request *req);
668
669 /* ptlrpc/llog_client.c */
670 extern struct llog_operations llog_client_ops;
671
672 #endif