Whamcloud - gitweb
b=19720
[fs/lustre-release.git] / lnet / selftest / selftest.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  * copy of GPLv2].
22  *
23  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24  * CA 95054 USA or visit www.sun.com if you need additional information or
25  * have any questions.
26  *
27  * GPL HEADER END
28  */
29 /*
30  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
31  * Use is subject to license terms.
32  */
33 /*
34  * This file is part of Lustre, http://www.lustre.org/
35  * Lustre is a trademark of Sun Microsystems, Inc.
36  *
37  * lnet/selftest/selftest.h
38  *
39  * Author: Isaac Huang <isaac@clusterfs.com>
40  */
41 #ifndef __SELFTEST_SELFTEST_H__
42 #define __SELFTEST_SELFTEST_H__
43
44 #define LNET_ONLY
45
46 #ifndef __KERNEL__
47
48 /* XXX workaround XXX */
49 #ifdef HAVE_SYS_TYPES_H
50 #include <sys/types.h>
51 #endif
52
53 #endif
54 #include <libcfs/libcfs.h>
55 #include <lnet/lnet.h>
56 #include <lnet/lib-lnet.h>
57 #include <lnet/lib-types.h>
58 #include <lnet/lnetst.h>
59
60 #include "rpc.h"
61 #include "timer.h"
62
63 #ifndef MADE_WITHOUT_COMPROMISE
64 #define MADE_WITHOUT_COMPROMISE
65 #endif
66
67
68 #define SWI_STATE_NEWBORN                  0
69 #define SWI_STATE_REPLY_SUBMITTED          1
70 #define SWI_STATE_REPLY_SENT               2
71 #define SWI_STATE_REQUEST_SUBMITTED        3
72 #define SWI_STATE_REQUEST_SENT             4
73 #define SWI_STATE_REPLY_RECEIVED           5
74 #define SWI_STATE_BULK_STARTED             6
75 #define SWI_STATE_DONE                     10
76
77 /* forward refs */
78 struct swi_workitem;
79 struct srpc_service;
80 struct sfw_test_unit;
81 struct sfw_test_instance;
82
83 /*
84  * A workitems is deferred work with these semantics:
85  * - a workitem always runs in thread context.
86  * - a workitem can be concurrent with other workitems but is strictly
87  *   serialized with respect to itself.
88  * - no CPU affinity, a workitem does not necessarily run on the same CPU
89  *   that schedules it. However, this might change in the future.
90  * - if a workitem is scheduled again before it has a chance to run, it
91  *   runs only once.
92  * - if a workitem is scheduled while it runs, it runs again after it
93  *   completes; this ensures that events occurring while other events are
94  *   being processed receive due attention. This behavior also allows a
95  *   workitem to reschedule itself.
96  *
97  * Usage notes:
98  * - a workitem can sleep but it should be aware of how that sleep might
99  *   affect others.
100  * - a workitem runs inside a kernel thread so there's no user space to access.
101  * - do not use a workitem if the scheduling latency can't be tolerated.
102  *
103  * When wi_action returns non-zero, it means the workitem has either been
104  * freed or reused and workitem scheduler won't touch it any more.
105  */
106 typedef int (*swi_action_t) (struct swi_workitem *);
107 typedef struct swi_workitem {
108         struct list_head wi_list;        /* chain on runq */
109         int              wi_state;
110         swi_action_t     wi_action;
111         void            *wi_data;
112         unsigned int     wi_running:1;
113         unsigned int     wi_scheduled:1;
114 } swi_workitem_t;
115
116 static inline void
117 swi_init_workitem (swi_workitem_t *wi, void *data, swi_action_t action)
118 {
119         CFS_INIT_LIST_HEAD(&wi->wi_list);
120
121         wi->wi_running   = 0;
122         wi->wi_scheduled = 0;
123         wi->wi_data      = data;
124         wi->wi_action    = action;
125         wi->wi_state     = SWI_STATE_NEWBORN;
126 }
127
128 #define SWI_RESCHED    128         /* # workitem scheduler loops before reschedule */
129
130 /* services below SRPC_FRAMEWORK_SERVICE_MAX_ID are framework
131  * services, e.g. create/modify session.
132  */
133 #define SRPC_SERVICE_DEBUG              0
134 #define SRPC_SERVICE_MAKE_SESSION       1
135 #define SRPC_SERVICE_REMOVE_SESSION     2
136 #define SRPC_SERVICE_BATCH              3
137 #define SRPC_SERVICE_TEST               4
138 #define SRPC_SERVICE_QUERY_STAT         5
139 #define SRPC_SERVICE_JOIN               6
140 #define SRPC_FRAMEWORK_SERVICE_MAX_ID   10
141 /* other services start from SRPC_FRAMEWORK_SERVICE_MAX_ID+1 */
142 #define SRPC_SERVICE_BRW                11
143 #define SRPC_SERVICE_PING               12
144 #define SRPC_SERVICE_MAX_ID             12
145
146 #define SRPC_REQUEST_PORTAL             50
147 /* a lazy portal for framework RPC requests */
148 #define SRPC_FRAMEWORK_REQUEST_PORTAL   51
149 /* all reply/bulk RDMAs go to this portal */
150 #define SRPC_RDMA_PORTAL                52
151
152 static inline srpc_msg_type_t
153 srpc_service2request (int service)
154 {
155         switch (service) {
156         default:
157                 LBUG ();
158         case SRPC_SERVICE_DEBUG:
159                 return SRPC_MSG_DEBUG_REQST;
160
161         case SRPC_SERVICE_MAKE_SESSION:
162                 return SRPC_MSG_MKSN_REQST;
163
164         case SRPC_SERVICE_REMOVE_SESSION:
165                 return SRPC_MSG_RMSN_REQST;
166
167         case SRPC_SERVICE_BATCH:
168                 return SRPC_MSG_BATCH_REQST;
169
170         case SRPC_SERVICE_TEST:
171                 return SRPC_MSG_TEST_REQST;
172
173         case SRPC_SERVICE_QUERY_STAT:
174                 return SRPC_MSG_STAT_REQST;
175
176         case SRPC_SERVICE_BRW:
177                 return SRPC_MSG_BRW_REQST;
178
179         case SRPC_SERVICE_PING:
180                 return SRPC_MSG_PING_REQST;
181
182         case SRPC_SERVICE_JOIN:
183                 return SRPC_MSG_JOIN_REQST;
184         }
185 }
186
187 static inline srpc_msg_type_t
188 srpc_service2reply (int service)
189 {
190         return srpc_service2request(service) + 1;
191 }
192
193 typedef enum {
194         SRPC_BULK_REQ_RCVD   = 1, /* passive bulk request(PUT sink/GET source) received */
195         SRPC_BULK_PUT_SENT   = 2, /* active bulk PUT sent (source) */
196         SRPC_BULK_GET_RPLD   = 3, /* active bulk GET replied (sink) */
197         SRPC_REPLY_RCVD      = 4, /* incoming reply received */
198         SRPC_REPLY_SENT      = 5, /* outgoing reply sent */
199         SRPC_REQUEST_RCVD    = 6, /* incoming request received */
200         SRPC_REQUEST_SENT    = 7, /* outgoing request sent */
201 } srpc_event_type_t;
202
203 /* RPC event */
204 typedef struct {
205         srpc_event_type_t ev_type;   /* what's up */
206         lnet_event_kind_t ev_lnet;   /* LNet event type */
207         int               ev_fired;  /* LNet event fired? */
208         int               ev_status; /* LNet event status */
209         void             *ev_data;   /* owning server/client RPC */
210 } srpc_event_t;
211
212 typedef struct {
213         int              bk_len;  /* len of bulk data */
214         lnet_handle_md_t bk_mdh;
215         int              bk_sink; /* sink/source */
216         int              bk_niov; /* # iov in bk_iovs */
217 #ifdef __KERNEL__
218         lnet_kiov_t      bk_iovs[0];
219 #else
220         cfs_page_t     **bk_pages;
221         lnet_md_iovec_t  bk_iovs[0];
222 #endif
223 } srpc_bulk_t; /* bulk descriptor */
224
225 /* message buffer descriptor */
226 typedef struct {
227         struct list_head     buf_list; /* chain on srpc_service::*_msgq */
228         srpc_msg_t           buf_msg;
229         lnet_handle_md_t     buf_mdh;
230         lnet_nid_t           buf_self;
231         lnet_process_id_t    buf_peer;
232 } srpc_buffer_t;
233
234 /* server-side state of a RPC */
235 typedef struct srpc_server_rpc {
236         struct list_head     srpc_list;    /* chain on srpc_service::*_rpcq */
237         struct srpc_service *srpc_service;
238         swi_workitem_t       srpc_wi;
239         srpc_event_t         srpc_ev;      /* bulk/reply event */
240         lnet_nid_t           srpc_self;
241         lnet_process_id_t    srpc_peer;
242         srpc_msg_t           srpc_replymsg;
243         lnet_handle_md_t     srpc_replymdh;
244         srpc_buffer_t       *srpc_reqstbuf;
245         srpc_bulk_t         *srpc_bulk;
246
247         unsigned int         srpc_aborted; /* being given up */
248         int                  srpc_status;
249         void               (*srpc_done)(struct srpc_server_rpc *);
250 } srpc_server_rpc_t;
251
252 /* client-side state of a RPC */
253 typedef struct srpc_client_rpc {
254         struct list_head     crpc_list;   /* chain on user's lists */
255         spinlock_t           crpc_lock;   /* serialize */
256         int                  crpc_service;
257         atomic_t             crpc_refcount;
258         int                  crpc_timeout; /* # seconds to wait for reply */
259         stt_timer_t          crpc_timer;
260         swi_workitem_t       crpc_wi;
261         lnet_process_id_t    crpc_dest;
262
263         void               (*crpc_done)(struct srpc_client_rpc *);
264         void               (*crpc_fini)(struct srpc_client_rpc *);
265         int                  crpc_status;    /* completion status */
266         void                *crpc_priv;      /* caller data */
267
268         /* state flags */
269         unsigned int         crpc_aborted:1; /* being given up */
270         unsigned int         crpc_closed:1;  /* completed */
271
272         /* RPC events */
273         srpc_event_t         crpc_bulkev;    /* bulk event */
274         srpc_event_t         crpc_reqstev;   /* request event */
275         srpc_event_t         crpc_replyev;   /* reply event */
276
277         /* bulk, request(reqst), and reply exchanged on wire */
278         srpc_msg_t           crpc_reqstmsg;
279         srpc_msg_t           crpc_replymsg;
280         lnet_handle_md_t     crpc_reqstmdh;
281         lnet_handle_md_t     crpc_replymdh;
282         srpc_bulk_t          crpc_bulk;
283 } srpc_client_rpc_t;
284
285 #define srpc_client_rpc_size(rpc)                                       \
286 offsetof(srpc_client_rpc_t, crpc_bulk.bk_iovs[(rpc)->crpc_bulk.bk_niov])
287
288 #define srpc_client_rpc_addref(rpc)                                     \
289 do {                                                                    \
290         CDEBUG(D_NET, "RPC[%p] -> %s (%d)++\n",                         \
291                (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
292                atomic_read(&(rpc)->crpc_refcount));                     \
293         LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0);                \
294         atomic_inc(&(rpc)->crpc_refcount);                              \
295 } while (0)
296
297 #define srpc_client_rpc_decref(rpc)                                     \
298 do {                                                                    \
299         CDEBUG(D_NET, "RPC[%p] -> %s (%d)--\n",                         \
300                (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
301                atomic_read(&(rpc)->crpc_refcount));                     \
302         LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0);                \
303         if (atomic_dec_and_test(&(rpc)->crpc_refcount))                 \
304                 srpc_destroy_client_rpc(rpc);                           \
305 } while (0)
306
307 #define srpc_event_pending(rpc)   ((rpc)->crpc_bulkev.ev_fired == 0 ||  \
308                                    (rpc)->crpc_reqstev.ev_fired == 0 || \
309                                    (rpc)->crpc_replyev.ev_fired == 0)
310
311 typedef struct srpc_service {
312         int                sv_id;            /* service id */
313         const char        *sv_name;          /* human readable name */
314         int                sv_nprune;        /* # posted RPC to be pruned */
315         int                sv_concur;        /* max # concurrent RPCs */
316
317         spinlock_t         sv_lock;
318         int                sv_shuttingdown;
319         srpc_event_t       sv_ev;            /* LNet event */
320         int                sv_nposted_msg;   /* # posted message buffers */
321         struct list_head   sv_free_rpcq;     /* free RPC descriptors */
322         struct list_head   sv_active_rpcq;   /* in-flight RPCs */
323         struct list_head   sv_posted_msgq;   /* posted message buffers */
324         struct list_head   sv_blocked_msgq;  /* blocked for RPC descriptor */
325
326         /* Service callbacks:
327          * - sv_handler: process incoming RPC request
328          * - sv_bulk_ready: notify bulk data
329          */
330         int                (*sv_handler) (srpc_server_rpc_t *);
331         int                (*sv_bulk_ready) (srpc_server_rpc_t *, int);
332 } srpc_service_t;
333
334 #define SFW_POST_BUFFERS         256
335 #define SFW_SERVICE_CONCURRENCY  (SFW_POST_BUFFERS/2)
336
337 typedef struct {
338         struct list_head  sn_list;    /* chain on fw_zombie_sessions */
339         lst_sid_t         sn_id;      /* unique identifier */
340         unsigned int      sn_timeout; /* # seconds' inactivity to expire */
341         int               sn_timer_active;
342         stt_timer_t       sn_timer;
343         struct list_head  sn_batches; /* list of batches */
344         char              sn_name[LST_NAME_SIZE];
345         atomic_t          sn_refcount;
346         atomic_t          sn_brw_errors;
347         atomic_t          sn_ping_errors;
348 } sfw_session_t;
349
350 #define sfw_sid_equal(sid0, sid1)     ((sid0).ses_nid == (sid1).ses_nid && \
351                                        (sid0).ses_stamp == (sid1).ses_stamp)
352
353 typedef struct {
354         struct list_head  bat_list;      /* chain on sn_batches */
355         lst_bid_t         bat_id;        /* batch id */
356         int               bat_error;     /* error code of batch */
357         sfw_session_t    *bat_session;   /* batch's session */
358         atomic_t          bat_nactive;   /* # of active tests */
359         struct list_head  bat_tests;     /* test instances */
360 } sfw_batch_t;
361
362 typedef struct {
363         int  (*tso_init)(struct sfw_test_instance *tsi); /* intialize test client */
364         void (*tso_fini)(struct sfw_test_instance *tsi); /* finalize test client */
365         int  (*tso_prep_rpc)(struct sfw_test_unit *tsu,
366                              lnet_process_id_t dest,
367                              srpc_client_rpc_t **rpc);   /* prep a tests rpc */
368         void (*tso_done_rpc)(struct sfw_test_unit *tsu,
369                              srpc_client_rpc_t *rpc);    /* done a test rpc */
370 } sfw_test_client_ops_t;
371
372 typedef struct sfw_test_instance {
373         struct list_head        tsi_list;         /* chain on batch */
374         int                     tsi_service;      /* test type */
375         sfw_batch_t            *tsi_batch;        /* batch */
376         sfw_test_client_ops_t  *tsi_ops;          /* test client operations */
377
378         /* public parameter for all test units */
379         int                     tsi_is_client:1;     /* is test client */
380         int                     tsi_stoptsu_onerr:1; /* stop tsu on error */
381         int                     tsi_concur;          /* concurrency */
382         int                     tsi_loop;            /* loop count */
383
384         /* status of test instance */
385         spinlock_t              tsi_lock;         /* serialize */
386         int                     tsi_stopping:1;   /* test is stopping */
387         atomic_t                tsi_nactive;      /* # of active test unit */
388         struct list_head        tsi_units;        /* test units */
389         struct list_head        tsi_free_rpcs;    /* free rpcs */
390         struct list_head        tsi_active_rpcs;  /* active rpcs */
391
392         union {
393                 test_bulk_req_t bulk;             /* bulk parameter */
394                 test_ping_req_t ping;             /* ping parameter */
395         } tsi_u;
396 } sfw_test_instance_t;
397
398 /* XXX: trailing (CFS_PAGE_SIZE % sizeof(lnet_process_id_t)) bytes at
399  * the end of pages are not used */
400 #define SFW_MAX_CONCUR     LST_MAX_CONCUR
401 #define SFW_ID_PER_PAGE    (CFS_PAGE_SIZE / sizeof(lnet_process_id_t))
402 #define SFW_MAX_NDESTS     (LNET_MAX_IOV * SFW_ID_PER_PAGE)
403 #define sfw_id_pages(n)    (((n) + SFW_ID_PER_PAGE - 1) / SFW_ID_PER_PAGE)
404
405 typedef struct sfw_test_unit {
406         struct list_head        tsu_list;         /* chain on lst_test_instance */
407         lnet_process_id_t       tsu_dest;         /* id of dest node */
408         int                     tsu_loop;         /* loop count of the test */
409         sfw_test_instance_t    *tsu_instance;     /* pointer to test instance */
410         void                   *tsu_private;      /* private data */
411         swi_workitem_t          tsu_worker;       /* workitem of the test unit */
412 } sfw_test_unit_t;
413
414 typedef struct {
415         struct list_head        tsc_list;         /* chain on fw_tests */
416         srpc_service_t         *tsc_srv_service;  /* test service */
417         sfw_test_client_ops_t  *tsc_cli_ops;      /* ops of test client */
418 } sfw_test_case_t;
419
420
421 srpc_client_rpc_t *
422 sfw_create_rpc(lnet_process_id_t peer, int service, int nbulkiov, int bulklen,
423                void (*done) (srpc_client_rpc_t *), void *priv);
424 int sfw_create_test_rpc(sfw_test_unit_t *tsu, lnet_process_id_t peer,
425                         int nblk, int blklen, srpc_client_rpc_t **rpc);
426 void sfw_abort_rpc(srpc_client_rpc_t *rpc);
427 void sfw_post_rpc(srpc_client_rpc_t *rpc);
428 void sfw_client_rpc_done(srpc_client_rpc_t *rpc);
429 void sfw_unpack_message(srpc_msg_t *msg);
430 void sfw_free_pages(srpc_server_rpc_t *rpc);
431 void sfw_add_bulk_page(srpc_bulk_t *bk, cfs_page_t *pg, int i);
432 int sfw_alloc_pages(srpc_server_rpc_t *rpc, int npages, int sink);
433 int sfw_make_session (srpc_mksn_reqst_t *request, srpc_mksn_reply_t *reply);
434
435 srpc_client_rpc_t *
436 srpc_create_client_rpc(lnet_process_id_t peer, int service,
437                        int nbulkiov, int bulklen,
438                        void (*rpc_done)(srpc_client_rpc_t *),
439                        void (*rpc_fini)(srpc_client_rpc_t *), void *priv);
440 void srpc_post_rpc(srpc_client_rpc_t *rpc);
441 void srpc_abort_rpc(srpc_client_rpc_t *rpc, int why);
442 void srpc_free_bulk(srpc_bulk_t *bk);
443 srpc_bulk_t *srpc_alloc_bulk(int npages, int sink);
444 int srpc_send_rpc(swi_workitem_t *wi);
445 int srpc_send_reply(srpc_server_rpc_t *rpc);
446 int srpc_add_service(srpc_service_t *sv);
447 int srpc_remove_service(srpc_service_t *sv);
448 void srpc_shutdown_service(srpc_service_t *sv);
449 void srpc_abort_service(srpc_service_t *sv);
450 int srpc_finish_service(srpc_service_t *sv);
451 int srpc_service_add_buffers(srpc_service_t *sv, int nbuffer);
452 void srpc_service_remove_buffers(srpc_service_t *sv, int nbuffer);
453 void srpc_get_counters(srpc_counters_t *cnt);
454 void srpc_set_counters(const srpc_counters_t *cnt);
455
456 void swi_kill_workitem(swi_workitem_t *wi);
457 void swi_schedule_workitem(swi_workitem_t *wi);
458 void swi_schedule_serial_workitem(swi_workitem_t *wi);
459 int swi_startup(void);
460 int sfw_startup(void);
461 int srpc_startup(void);
462 void swi_shutdown(void);
463 void sfw_shutdown(void);
464 void srpc_shutdown(void);
465
466 static inline void
467 srpc_destroy_client_rpc (srpc_client_rpc_t *rpc)
468 {
469         LASSERT (rpc != NULL);
470         LASSERT (!srpc_event_pending(rpc));
471         LASSERT (atomic_read(&rpc->crpc_refcount) == 0);
472 #ifndef __KERNEL__
473         LASSERT (rpc->crpc_bulk.bk_pages == NULL);
474 #endif
475
476         if (rpc->crpc_fini == NULL) {
477                 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
478         } else {
479                 (*rpc->crpc_fini) (rpc);
480         }
481
482         return;
483 }
484
485 static inline void
486 srpc_init_client_rpc (srpc_client_rpc_t *rpc, lnet_process_id_t peer,
487                       int service, int nbulkiov, int bulklen,
488                       void (*rpc_done)(srpc_client_rpc_t *),
489                       void (*rpc_fini)(srpc_client_rpc_t *), void *priv)
490 {
491         LASSERT (nbulkiov <= LNET_MAX_IOV);
492
493         memset(rpc, 0, offsetof(srpc_client_rpc_t,
494                                 crpc_bulk.bk_iovs[nbulkiov]));
495
496         CFS_INIT_LIST_HEAD(&rpc->crpc_list);
497         swi_init_workitem(&rpc->crpc_wi, rpc, srpc_send_rpc);
498         spin_lock_init(&rpc->crpc_lock);
499         atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */
500
501         rpc->crpc_dest         = peer;
502         rpc->crpc_priv         = priv;
503         rpc->crpc_service      = service;
504         rpc->crpc_bulk.bk_len  = bulklen;
505         rpc->crpc_bulk.bk_niov = nbulkiov;
506         rpc->crpc_done         = rpc_done;
507         rpc->crpc_fini         = rpc_fini;
508         LNetInvalidateHandle(&rpc->crpc_reqstmdh);
509         LNetInvalidateHandle(&rpc->crpc_replymdh);
510         LNetInvalidateHandle(&rpc->crpc_bulk.bk_mdh);
511
512         /* no event is expected at this point */
513         rpc->crpc_bulkev.ev_fired  =
514         rpc->crpc_reqstev.ev_fired =
515         rpc->crpc_replyev.ev_fired = 1;
516
517         rpc->crpc_reqstmsg.msg_magic   = SRPC_MSG_MAGIC;
518         rpc->crpc_reqstmsg.msg_version = SRPC_MSG_VERSION;
519         rpc->crpc_reqstmsg.msg_type    = srpc_service2request(service);
520         return;
521 }
522
523 static inline const char *
524 swi_state2str (int state)
525 {
526 #define STATE2STR(x) case x: return #x
527         switch(state) {
528                 default:
529                         LBUG();
530                 STATE2STR(SWI_STATE_NEWBORN);
531                 STATE2STR(SWI_STATE_REPLY_SUBMITTED);
532                 STATE2STR(SWI_STATE_REPLY_SENT);
533                 STATE2STR(SWI_STATE_REQUEST_SUBMITTED);
534                 STATE2STR(SWI_STATE_REQUEST_SENT);
535                 STATE2STR(SWI_STATE_REPLY_RECEIVED);
536                 STATE2STR(SWI_STATE_BULK_STARTED);
537                 STATE2STR(SWI_STATE_DONE);
538         }
539 #undef STATE2STR
540 }
541
542 #define UNUSED(x)       ( (void)(x) )
543
544 #ifndef __KERNEL__
545
546 int stt_poll_interval(void);
547 int sfw_session_removed(void);
548
549 int stt_check_events(void);
550 int swi_check_events(void);
551 int srpc_check_event(int timeout);
552
553 int lnet_selftest_init(void);
554 void lnet_selftest_fini(void);
555 int selftest_wait_events(void);
556
557 #else
558
559 #define selftest_wait_events()    cfs_pause(cfs_time_seconds(1))
560
561 #endif
562
563 #define lst_wait_until(cond, lock, fmt, ...)                            \
564 do {                                                                    \
565         int __I = 2;                                                    \
566         while (!(cond)) {                                               \
567                 CDEBUG(IS_PO2(++__I) ? D_WARNING : D_NET,               \
568                        fmt, ## __VA_ARGS__);                            \
569                 spin_unlock(&(lock));                                   \
570                                                                         \
571                 selftest_wait_events();                                 \
572                                                                         \
573                 spin_lock(&(lock));                                     \
574         }                                                               \
575 } while (0)
576
577 static inline void
578 srpc_wait_service_shutdown (srpc_service_t *sv)
579 {
580         int i = 2;
581
582         spin_lock(&sv->sv_lock);
583         LASSERT (sv->sv_shuttingdown);
584         spin_unlock(&sv->sv_lock);
585
586         while (srpc_finish_service(sv) == 0) {
587                 i++;
588                 CDEBUG (((i & -i) == i) ? D_WARNING : D_NET,
589                         "Waiting for %s service to shutdown...\n",
590                         sv->sv_name);
591                 selftest_wait_events();
592         }
593 }
594
595 #endif /* __SELFTEST_SELFTEST_H__ */