Whamcloud - gitweb
LU-445 lnet: Send timestamps with LNet counters
[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 (c) 2007, 2010, Oracle and/or its affiliates. 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 srpc_service;
79 struct sfw_test_unit;
80 struct sfw_test_instance;
81
82 /* services below SRPC_FRAMEWORK_SERVICE_MAX_ID are framework
83  * services, e.g. create/modify session.
84  */
85 #define SRPC_SERVICE_DEBUG              0
86 #define SRPC_SERVICE_MAKE_SESSION       1
87 #define SRPC_SERVICE_REMOVE_SESSION     2
88 #define SRPC_SERVICE_BATCH              3
89 #define SRPC_SERVICE_TEST               4
90 #define SRPC_SERVICE_QUERY_STAT         5
91 #define SRPC_SERVICE_JOIN               6
92 #define SRPC_FRAMEWORK_SERVICE_MAX_ID   10
93 /* other services start from SRPC_FRAMEWORK_SERVICE_MAX_ID+1 */
94 #define SRPC_SERVICE_BRW                11
95 #define SRPC_SERVICE_PING               12
96 #define SRPC_SERVICE_MAX_ID             12
97
98 #define SRPC_REQUEST_PORTAL             50
99 /* a lazy portal for framework RPC requests */
100 #define SRPC_FRAMEWORK_REQUEST_PORTAL   51
101 /* all reply/bulk RDMAs go to this portal */
102 #define SRPC_RDMA_PORTAL                52
103
104 static inline srpc_msg_type_t
105 srpc_service2request (int service)
106 {
107         switch (service) {
108         default:
109                 LBUG ();
110         case SRPC_SERVICE_DEBUG:
111                 return SRPC_MSG_DEBUG_REQST;
112
113         case SRPC_SERVICE_MAKE_SESSION:
114                 return SRPC_MSG_MKSN_REQST;
115
116         case SRPC_SERVICE_REMOVE_SESSION:
117                 return SRPC_MSG_RMSN_REQST;
118
119         case SRPC_SERVICE_BATCH:
120                 return SRPC_MSG_BATCH_REQST;
121
122         case SRPC_SERVICE_TEST:
123                 return SRPC_MSG_TEST_REQST;
124
125         case SRPC_SERVICE_QUERY_STAT:
126                 return SRPC_MSG_STAT_REQST;
127
128         case SRPC_SERVICE_BRW:
129                 return SRPC_MSG_BRW_REQST;
130
131         case SRPC_SERVICE_PING:
132                 return SRPC_MSG_PING_REQST;
133
134         case SRPC_SERVICE_JOIN:
135                 return SRPC_MSG_JOIN_REQST;
136         }
137 }
138
139 static inline srpc_msg_type_t
140 srpc_service2reply (int service)
141 {
142         return srpc_service2request(service) + 1;
143 }
144
145 typedef enum {
146         SRPC_BULK_REQ_RCVD   = 1, /* passive bulk request(PUT sink/GET source) received */
147         SRPC_BULK_PUT_SENT   = 2, /* active bulk PUT sent (source) */
148         SRPC_BULK_GET_RPLD   = 3, /* active bulk GET replied (sink) */
149         SRPC_REPLY_RCVD      = 4, /* incoming reply received */
150         SRPC_REPLY_SENT      = 5, /* outgoing reply sent */
151         SRPC_REQUEST_RCVD    = 6, /* incoming request received */
152         SRPC_REQUEST_SENT    = 7, /* outgoing request sent */
153 } srpc_event_type_t;
154
155 /* RPC event */
156 typedef struct {
157         srpc_event_type_t ev_type;   /* what's up */
158         lnet_event_kind_t ev_lnet;   /* LNet event type */
159         int               ev_fired;  /* LNet event fired? */
160         int               ev_status; /* LNet event status */
161         void             *ev_data;   /* owning server/client RPC */
162 } srpc_event_t;
163
164 typedef struct {
165         int              bk_len;  /* len of bulk data */
166         lnet_handle_md_t bk_mdh;
167         int              bk_sink; /* sink/source */
168         int              bk_niov; /* # iov in bk_iovs */
169 #ifdef __KERNEL__
170         lnet_kiov_t      bk_iovs[0];
171 #else
172         cfs_page_t     **bk_pages;
173         lnet_md_iovec_t  bk_iovs[0];
174 #endif
175 } srpc_bulk_t; /* bulk descriptor */
176
177 /* message buffer descriptor */
178 typedef struct {
179         cfs_list_t           buf_list; /* chain on srpc_service::*_msgq */
180         srpc_msg_t           buf_msg;
181         lnet_handle_md_t     buf_mdh;
182         lnet_nid_t           buf_self;
183         lnet_process_id_t    buf_peer;
184 } srpc_buffer_t;
185
186 struct swi_workitem;
187 typedef int (*swi_action_t) (struct swi_workitem *);
188
189 typedef struct swi_workitem {
190         cfs_workitem_t       swi_workitem;
191         swi_action_t         swi_action;
192         int                  swi_state;
193 } swi_workitem_t;
194
195 /* server-side state of a RPC */
196 typedef struct srpc_server_rpc {
197         cfs_list_t           srpc_list;    /* chain on srpc_service::*_rpcq */
198         struct srpc_service *srpc_service;
199         swi_workitem_t       srpc_wi;
200         srpc_event_t         srpc_ev;      /* bulk/reply event */
201         lnet_nid_t           srpc_self;
202         lnet_process_id_t    srpc_peer;
203         srpc_msg_t           srpc_replymsg;
204         lnet_handle_md_t     srpc_replymdh;
205         srpc_buffer_t       *srpc_reqstbuf;
206         srpc_bulk_t         *srpc_bulk;
207
208         unsigned int         srpc_aborted; /* being given up */
209         int                  srpc_status;
210         void               (*srpc_done)(struct srpc_server_rpc *);
211 } srpc_server_rpc_t;
212
213 /* client-side state of a RPC */
214 typedef struct srpc_client_rpc {
215         cfs_list_t           crpc_list;   /* chain on user's lists */
216         cfs_spinlock_t       crpc_lock;   /* serialize */
217         int                  crpc_service;
218         cfs_atomic_t         crpc_refcount;
219         int                  crpc_timeout; /* # seconds to wait for reply */
220         stt_timer_t          crpc_timer;
221         swi_workitem_t       crpc_wi;
222         lnet_process_id_t    crpc_dest;
223
224         void               (*crpc_done)(struct srpc_client_rpc *);
225         void               (*crpc_fini)(struct srpc_client_rpc *);
226         int                  crpc_status;    /* completion status */
227         void                *crpc_priv;      /* caller data */
228
229         /* state flags */
230         unsigned int         crpc_aborted:1; /* being given up */
231         unsigned int         crpc_closed:1;  /* completed */
232
233         /* RPC events */
234         srpc_event_t         crpc_bulkev;    /* bulk event */
235         srpc_event_t         crpc_reqstev;   /* request event */
236         srpc_event_t         crpc_replyev;   /* reply event */
237
238         /* bulk, request(reqst), and reply exchanged on wire */
239         srpc_msg_t           crpc_reqstmsg;
240         srpc_msg_t           crpc_replymsg;
241         lnet_handle_md_t     crpc_reqstmdh;
242         lnet_handle_md_t     crpc_replymdh;
243         srpc_bulk_t          crpc_bulk;
244 } srpc_client_rpc_t;
245
246 #define srpc_client_rpc_size(rpc)                                       \
247 offsetof(srpc_client_rpc_t, crpc_bulk.bk_iovs[(rpc)->crpc_bulk.bk_niov])
248
249 #define srpc_client_rpc_addref(rpc)                                     \
250 do {                                                                    \
251         CDEBUG(D_NET, "RPC[%p] -> %s (%d)++\n",                         \
252                (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
253                cfs_atomic_read(&(rpc)->crpc_refcount));                 \
254         LASSERT(cfs_atomic_read(&(rpc)->crpc_refcount) > 0);            \
255         cfs_atomic_inc(&(rpc)->crpc_refcount);                          \
256 } while (0)
257
258 #define srpc_client_rpc_decref(rpc)                                     \
259 do {                                                                    \
260         CDEBUG(D_NET, "RPC[%p] -> %s (%d)--\n",                         \
261                (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
262                cfs_atomic_read(&(rpc)->crpc_refcount));                 \
263         LASSERT(cfs_atomic_read(&(rpc)->crpc_refcount) > 0);            \
264         if (cfs_atomic_dec_and_test(&(rpc)->crpc_refcount))             \
265                 srpc_destroy_client_rpc(rpc);                           \
266 } while (0)
267
268 #define srpc_event_pending(rpc)   ((rpc)->crpc_bulkev.ev_fired == 0 ||  \
269                                    (rpc)->crpc_reqstev.ev_fired == 0 || \
270                                    (rpc)->crpc_replyev.ev_fired == 0)
271
272 typedef struct srpc_service {
273         int                sv_id;            /* service id */
274         const char        *sv_name;          /* human readable name */
275         int                sv_nprune;        /* # posted RPC to be pruned */
276         int                sv_concur;        /* max # concurrent RPCs */
277
278         cfs_spinlock_t     sv_lock;
279         int                sv_shuttingdown;
280         srpc_event_t       sv_ev;            /* LNet event */
281         int                sv_nposted_msg;   /* # posted message buffers */
282         cfs_list_t         sv_free_rpcq;     /* free RPC descriptors */
283         cfs_list_t         sv_active_rpcq;   /* in-flight RPCs */
284         cfs_list_t         sv_posted_msgq;   /* posted message buffers */
285         cfs_list_t         sv_blocked_msgq;  /* blocked for RPC descriptor */
286
287         /* Service callbacks:
288          * - sv_handler: process incoming RPC request
289          * - sv_bulk_ready: notify bulk data
290          */
291         int              (*sv_handler) (srpc_server_rpc_t *);
292         int              (*sv_bulk_ready) (srpc_server_rpc_t *, int);
293 } srpc_service_t;
294
295 #define SFW_POST_BUFFERS         256
296 #define SFW_SERVICE_CONCURRENCY  (SFW_POST_BUFFERS/2)
297
298 typedef struct {
299         cfs_list_t        sn_list;    /* chain on fw_zombie_sessions */
300         lst_sid_t         sn_id;      /* unique identifier */
301         unsigned int      sn_timeout; /* # seconds' inactivity to expire */
302         int               sn_timer_active;
303         stt_timer_t       sn_timer;
304         cfs_list_t        sn_batches; /* list of batches */
305         char              sn_name[LST_NAME_SIZE];
306         cfs_atomic_t      sn_refcount;
307         cfs_atomic_t      sn_brw_errors;
308         cfs_atomic_t      sn_ping_errors;
309         cfs_time_t        sn_started;
310 } sfw_session_t;
311
312 #define sfw_sid_equal(sid0, sid1)     ((sid0).ses_nid == (sid1).ses_nid && \
313                                        (sid0).ses_stamp == (sid1).ses_stamp)
314
315 typedef struct {
316         cfs_list_t        bat_list;      /* chain on sn_batches */
317         lst_bid_t         bat_id;        /* batch id */
318         int               bat_error;     /* error code of batch */
319         sfw_session_t    *bat_session;   /* batch's session */
320         cfs_atomic_t      bat_nactive;   /* # of active tests */
321         cfs_list_t        bat_tests;     /* test instances */
322 } sfw_batch_t;
323
324 typedef struct {
325         int  (*tso_init)(struct sfw_test_instance *tsi); /* intialize test client */
326         void (*tso_fini)(struct sfw_test_instance *tsi); /* finalize test client */
327         int  (*tso_prep_rpc)(struct sfw_test_unit *tsu,
328                              lnet_process_id_t dest,
329                              srpc_client_rpc_t **rpc);   /* prep a tests rpc */
330         void (*tso_done_rpc)(struct sfw_test_unit *tsu,
331                              srpc_client_rpc_t *rpc);    /* done a test rpc */
332 } sfw_test_client_ops_t;
333
334 typedef struct sfw_test_instance {
335         cfs_list_t              tsi_list;         /* chain on batch */
336         int                     tsi_service;      /* test type */
337         sfw_batch_t            *tsi_batch;        /* batch */
338         sfw_test_client_ops_t  *tsi_ops;          /* test client operations */
339
340         /* public parameter for all test units */
341         int                     tsi_is_client:1;     /* is test client */
342         int                     tsi_stoptsu_onerr:1; /* stop tsu on error */
343         int                     tsi_concur;          /* concurrency */
344         int                     tsi_loop;            /* loop count */
345
346         /* status of test instance */
347         cfs_spinlock_t          tsi_lock;         /* serialize */
348         int                     tsi_stopping:1;   /* test is stopping */
349         cfs_atomic_t            tsi_nactive;      /* # of active test unit */
350         cfs_list_t              tsi_units;        /* test units */
351         cfs_list_t              tsi_free_rpcs;    /* free rpcs */
352         cfs_list_t              tsi_active_rpcs;  /* active rpcs */
353
354         union {
355                 test_bulk_req_t bulk;             /* bulk parameter */
356                 test_ping_req_t ping;             /* ping parameter */
357         } tsi_u;
358 } sfw_test_instance_t;
359
360 /* XXX: trailing (CFS_PAGE_SIZE % sizeof(lnet_process_id_t)) bytes at
361  * the end of pages are not used */
362 #define SFW_MAX_CONCUR     LST_MAX_CONCUR
363 #define SFW_ID_PER_PAGE    (CFS_PAGE_SIZE / sizeof(lnet_process_id_packed_t))
364 #define SFW_MAX_NDESTS     (LNET_MAX_IOV * SFW_ID_PER_PAGE)
365 #define sfw_id_pages(n)    (((n) + SFW_ID_PER_PAGE - 1) / SFW_ID_PER_PAGE)
366
367 typedef struct sfw_test_unit {
368         cfs_list_t            tsu_list;         /* chain on lst_test_instance */
369         lnet_process_id_t     tsu_dest;         /* id of dest node */
370         int                   tsu_loop;         /* loop count of the test */
371         sfw_test_instance_t  *tsu_instance;     /* pointer to test instance */
372         void                 *tsu_private;      /* private data */
373         swi_workitem_t        tsu_worker;       /* workitem of the test unit */
374 } sfw_test_unit_t;
375
376 typedef struct {
377         cfs_list_t              tsc_list;         /* chain on fw_tests */
378         srpc_service_t         *tsc_srv_service;  /* test service */
379         sfw_test_client_ops_t  *tsc_cli_ops;      /* ops of test client */
380 } sfw_test_case_t;
381
382 srpc_client_rpc_t *
383 sfw_create_rpc(lnet_process_id_t peer, int service, int nbulkiov, int bulklen,
384                void (*done) (srpc_client_rpc_t *), void *priv);
385 int sfw_create_test_rpc(sfw_test_unit_t *tsu, lnet_process_id_t peer,
386                         int nblk, int blklen, srpc_client_rpc_t **rpc);
387 void sfw_abort_rpc(srpc_client_rpc_t *rpc);
388 void sfw_post_rpc(srpc_client_rpc_t *rpc);
389 void sfw_client_rpc_done(srpc_client_rpc_t *rpc);
390 void sfw_unpack_message(srpc_msg_t *msg);
391 void sfw_free_pages(srpc_server_rpc_t *rpc);
392 void sfw_add_bulk_page(srpc_bulk_t *bk, cfs_page_t *pg, int i);
393 int sfw_alloc_pages(srpc_server_rpc_t *rpc, int npages, int sink);
394 int sfw_make_session (srpc_mksn_reqst_t *request, srpc_mksn_reply_t *reply);
395
396 srpc_client_rpc_t *
397 srpc_create_client_rpc(lnet_process_id_t peer, int service,
398                        int nbulkiov, int bulklen,
399                        void (*rpc_done)(srpc_client_rpc_t *),
400                        void (*rpc_fini)(srpc_client_rpc_t *), void *priv);
401 void srpc_post_rpc(srpc_client_rpc_t *rpc);
402 void srpc_abort_rpc(srpc_client_rpc_t *rpc, int why);
403 void srpc_free_bulk(srpc_bulk_t *bk);
404 srpc_bulk_t *srpc_alloc_bulk(int npages, int sink);
405 int srpc_send_rpc(swi_workitem_t *wi);
406 int srpc_send_reply(srpc_server_rpc_t *rpc);
407 int srpc_add_service(srpc_service_t *sv);
408 int srpc_remove_service(srpc_service_t *sv);
409 void srpc_shutdown_service(srpc_service_t *sv);
410 void srpc_abort_service(srpc_service_t *sv);
411 int srpc_finish_service(srpc_service_t *sv);
412 int srpc_service_add_buffers(srpc_service_t *sv, int nbuffer);
413 void srpc_service_remove_buffers(srpc_service_t *sv, int nbuffer);
414 void srpc_get_counters(srpc_counters_t *cnt);
415 void srpc_set_counters(const srpc_counters_t *cnt);
416
417 static inline int
418 swi_wi_action(cfs_workitem_t *wi)
419 {
420         swi_workitem_t *swi = container_of(wi, swi_workitem_t, swi_workitem);
421
422         return swi->swi_action(swi);
423 }
424
425 static inline void
426 swi_init_workitem (swi_workitem_t *swi, void *data,
427                    swi_action_t action, short sched_id)
428 {
429         swi->swi_action = action;
430         swi->swi_state  = SWI_STATE_NEWBORN;
431         cfs_wi_init(&swi->swi_workitem, data, swi_wi_action, sched_id);
432 }
433
434 static inline void
435 swi_schedule_workitem(swi_workitem_t *wi)
436 {
437         cfs_wi_schedule(&wi->swi_workitem);
438 }
439
440 static inline void
441 swi_kill_workitem(swi_workitem_t *swi)
442 {
443         cfs_wi_exit(&swi->swi_workitem);
444 }
445
446 #ifndef __KERNEL__
447 static inline int
448 swi_check_events(void)
449 {
450         return cfs_wi_check_events();
451 }
452 #endif
453
454 int sfw_startup(void);
455 int srpc_startup(void);
456 void sfw_shutdown(void);
457 void srpc_shutdown(void);
458
459 static inline void
460 srpc_destroy_client_rpc (srpc_client_rpc_t *rpc)
461 {
462         LASSERT (rpc != NULL);
463         LASSERT (!srpc_event_pending(rpc));
464         LASSERT (cfs_atomic_read(&rpc->crpc_refcount) == 0);
465 #ifndef __KERNEL__
466         LASSERT (rpc->crpc_bulk.bk_pages == NULL);
467 #endif
468
469         if (rpc->crpc_fini == NULL) {
470                 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
471         } else {
472                 (*rpc->crpc_fini) (rpc);
473         }
474
475         return;
476 }
477
478 static inline void
479 srpc_init_client_rpc (srpc_client_rpc_t *rpc, lnet_process_id_t peer,
480                       int service, int nbulkiov, int bulklen,
481                       void (*rpc_done)(srpc_client_rpc_t *),
482                       void (*rpc_fini)(srpc_client_rpc_t *), void *priv)
483 {
484         LASSERT (nbulkiov <= LNET_MAX_IOV);
485
486         memset(rpc, 0, offsetof(srpc_client_rpc_t,
487                                 crpc_bulk.bk_iovs[nbulkiov]));
488
489         CFS_INIT_LIST_HEAD(&rpc->crpc_list);
490         swi_init_workitem(&rpc->crpc_wi, rpc, srpc_send_rpc,
491                           CFS_WI_SCHED_ANY);
492         cfs_spin_lock_init(&rpc->crpc_lock);
493         cfs_atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */
494
495         rpc->crpc_dest         = peer;
496         rpc->crpc_priv         = priv;
497         rpc->crpc_service      = service;
498         rpc->crpc_bulk.bk_len  = bulklen;
499         rpc->crpc_bulk.bk_niov = nbulkiov;
500         rpc->crpc_done         = rpc_done;
501         rpc->crpc_fini         = rpc_fini;
502         LNetInvalidateHandle(&rpc->crpc_reqstmdh);
503         LNetInvalidateHandle(&rpc->crpc_replymdh);
504         LNetInvalidateHandle(&rpc->crpc_bulk.bk_mdh);
505
506         /* no event is expected at this point */
507         rpc->crpc_bulkev.ev_fired  =
508         rpc->crpc_reqstev.ev_fired =
509         rpc->crpc_replyev.ev_fired = 1;
510
511         rpc->crpc_reqstmsg.msg_magic   = SRPC_MSG_MAGIC;
512         rpc->crpc_reqstmsg.msg_version = SRPC_MSG_VERSION;
513         rpc->crpc_reqstmsg.msg_type    = srpc_service2request(service);
514         return;
515 }
516
517 static inline const char *
518 swi_state2str (int state)
519 {
520 #define STATE2STR(x) case x: return #x
521         switch(state) {
522                 default:
523                         LBUG();
524                 STATE2STR(SWI_STATE_NEWBORN);
525                 STATE2STR(SWI_STATE_REPLY_SUBMITTED);
526                 STATE2STR(SWI_STATE_REPLY_SENT);
527                 STATE2STR(SWI_STATE_REQUEST_SUBMITTED);
528                 STATE2STR(SWI_STATE_REQUEST_SENT);
529                 STATE2STR(SWI_STATE_REPLY_RECEIVED);
530                 STATE2STR(SWI_STATE_BULK_STARTED);
531                 STATE2STR(SWI_STATE_DONE);
532         }
533 #undef STATE2STR
534 }
535
536 #define UNUSED(x)       ( (void)(x) )
537
538 #ifndef __KERNEL__
539
540 int stt_poll_interval(void);
541 int sfw_session_removed(void);
542
543 int stt_check_events(void);
544 int srpc_check_event(int timeout);
545
546 int lnet_selftest_init(void);
547 void lnet_selftest_fini(void);
548 int selftest_wait_events(void);
549
550 #else
551
552 #define selftest_wait_events()    cfs_pause(cfs_time_seconds(1))
553
554 #endif
555
556 #define lst_wait_until(cond, lock, fmt, ...)                            \
557 do {                                                                    \
558         int __I = 2;                                                    \
559         while (!(cond)) {                                               \
560                 CDEBUG(IS_PO2(++__I) ? D_WARNING : D_NET,               \
561                        fmt, ## __VA_ARGS__);                            \
562                 cfs_spin_unlock(&(lock));                               \
563                                                                         \
564                 selftest_wait_events();                                 \
565                                                                         \
566                 cfs_spin_lock(&(lock));                                 \
567         }                                                               \
568 } while (0)
569
570 static inline void
571 srpc_wait_service_shutdown (srpc_service_t *sv)
572 {
573         int i = 2;
574
575         cfs_spin_lock(&sv->sv_lock);
576         LASSERT (sv->sv_shuttingdown);
577         cfs_spin_unlock(&sv->sv_lock);
578
579         while (srpc_finish_service(sv) == 0) {
580                 i++;
581                 CDEBUG (((i & -i) == i) ? D_WARNING : D_NET,
582                         "Waiting for %s service to shutdown...\n",
583                         sv->sv_name);
584                 selftest_wait_events();
585         }
586 }
587
588 #endif /* __SELFTEST_SELFTEST_H__ */