Whamcloud - gitweb
b=20805 rate limit D_NETERR messages
[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 } sfw_session_t;
310
311 #define sfw_sid_equal(sid0, sid1)     ((sid0).ses_nid == (sid1).ses_nid && \
312                                        (sid0).ses_stamp == (sid1).ses_stamp)
313
314 typedef struct {
315         cfs_list_t        bat_list;      /* chain on sn_batches */
316         lst_bid_t         bat_id;        /* batch id */
317         int               bat_error;     /* error code of batch */
318         sfw_session_t    *bat_session;   /* batch's session */
319         cfs_atomic_t      bat_nactive;   /* # of active tests */
320         cfs_list_t        bat_tests;     /* test instances */
321 } sfw_batch_t;
322
323 typedef struct {
324         int  (*tso_init)(struct sfw_test_instance *tsi); /* intialize test client */
325         void (*tso_fini)(struct sfw_test_instance *tsi); /* finalize test client */
326         int  (*tso_prep_rpc)(struct sfw_test_unit *tsu,
327                              lnet_process_id_t dest,
328                              srpc_client_rpc_t **rpc);   /* prep a tests rpc */
329         void (*tso_done_rpc)(struct sfw_test_unit *tsu,
330                              srpc_client_rpc_t *rpc);    /* done a test rpc */
331 } sfw_test_client_ops_t;
332
333 typedef struct sfw_test_instance {
334         cfs_list_t              tsi_list;         /* chain on batch */
335         int                     tsi_service;      /* test type */
336         sfw_batch_t            *tsi_batch;        /* batch */
337         sfw_test_client_ops_t  *tsi_ops;          /* test client operations */
338
339         /* public parameter for all test units */
340         int                     tsi_is_client:1;     /* is test client */
341         int                     tsi_stoptsu_onerr:1; /* stop tsu on error */
342         int                     tsi_concur;          /* concurrency */
343         int                     tsi_loop;            /* loop count */
344
345         /* status of test instance */
346         cfs_spinlock_t          tsi_lock;         /* serialize */
347         int                     tsi_stopping:1;   /* test is stopping */
348         cfs_atomic_t            tsi_nactive;      /* # of active test unit */
349         cfs_list_t              tsi_units;        /* test units */
350         cfs_list_t              tsi_free_rpcs;    /* free rpcs */
351         cfs_list_t              tsi_active_rpcs;  /* active rpcs */
352
353         union {
354                 test_bulk_req_t bulk;             /* bulk parameter */
355                 test_ping_req_t ping;             /* ping parameter */
356         } tsi_u;
357 } sfw_test_instance_t;
358
359 /* XXX: trailing (CFS_PAGE_SIZE % sizeof(lnet_process_id_t)) bytes at
360  * the end of pages are not used */
361 #define SFW_MAX_CONCUR     LST_MAX_CONCUR
362 #define SFW_ID_PER_PAGE    (CFS_PAGE_SIZE / sizeof(lnet_process_id_packed_t))
363 #define SFW_MAX_NDESTS     (LNET_MAX_IOV * SFW_ID_PER_PAGE)
364 #define sfw_id_pages(n)    (((n) + SFW_ID_PER_PAGE - 1) / SFW_ID_PER_PAGE)
365
366 typedef struct sfw_test_unit {
367         cfs_list_t            tsu_list;         /* chain on lst_test_instance */
368         lnet_process_id_t     tsu_dest;         /* id of dest node */
369         int                   tsu_loop;         /* loop count of the test */
370         sfw_test_instance_t  *tsu_instance;     /* pointer to test instance */
371         void                 *tsu_private;      /* private data */
372         swi_workitem_t        tsu_worker;       /* workitem of the test unit */
373 } sfw_test_unit_t;
374
375 typedef struct {
376         cfs_list_t              tsc_list;         /* chain on fw_tests */
377         srpc_service_t         *tsc_srv_service;  /* test service */
378         sfw_test_client_ops_t  *tsc_cli_ops;      /* ops of test client */
379 } sfw_test_case_t;
380
381 srpc_client_rpc_t *
382 sfw_create_rpc(lnet_process_id_t peer, int service, int nbulkiov, int bulklen,
383                void (*done) (srpc_client_rpc_t *), void *priv);
384 int sfw_create_test_rpc(sfw_test_unit_t *tsu, lnet_process_id_t peer,
385                         int nblk, int blklen, srpc_client_rpc_t **rpc);
386 void sfw_abort_rpc(srpc_client_rpc_t *rpc);
387 void sfw_post_rpc(srpc_client_rpc_t *rpc);
388 void sfw_client_rpc_done(srpc_client_rpc_t *rpc);
389 void sfw_unpack_message(srpc_msg_t *msg);
390 void sfw_free_pages(srpc_server_rpc_t *rpc);
391 void sfw_add_bulk_page(srpc_bulk_t *bk, cfs_page_t *pg, int i);
392 int sfw_alloc_pages(srpc_server_rpc_t *rpc, int npages, int sink);
393 int sfw_make_session (srpc_mksn_reqst_t *request, srpc_mksn_reply_t *reply);
394
395 srpc_client_rpc_t *
396 srpc_create_client_rpc(lnet_process_id_t peer, int service,
397                        int nbulkiov, int bulklen,
398                        void (*rpc_done)(srpc_client_rpc_t *),
399                        void (*rpc_fini)(srpc_client_rpc_t *), void *priv);
400 void srpc_post_rpc(srpc_client_rpc_t *rpc);
401 void srpc_abort_rpc(srpc_client_rpc_t *rpc, int why);
402 void srpc_free_bulk(srpc_bulk_t *bk);
403 srpc_bulk_t *srpc_alloc_bulk(int npages, int sink);
404 int srpc_send_rpc(swi_workitem_t *wi);
405 int srpc_send_reply(srpc_server_rpc_t *rpc);
406 int srpc_add_service(srpc_service_t *sv);
407 int srpc_remove_service(srpc_service_t *sv);
408 void srpc_shutdown_service(srpc_service_t *sv);
409 void srpc_abort_service(srpc_service_t *sv);
410 int srpc_finish_service(srpc_service_t *sv);
411 int srpc_service_add_buffers(srpc_service_t *sv, int nbuffer);
412 void srpc_service_remove_buffers(srpc_service_t *sv, int nbuffer);
413 void srpc_get_counters(srpc_counters_t *cnt);
414 void srpc_set_counters(const srpc_counters_t *cnt);
415
416 static inline int
417 swi_wi_action(cfs_workitem_t *wi)
418 {
419         swi_workitem_t *swi = container_of(wi, swi_workitem_t, swi_workitem);
420
421         return swi->swi_action(swi);
422 }
423
424 static inline void
425 swi_init_workitem (swi_workitem_t *swi, void *data,
426                    swi_action_t action, short sched_id)
427 {
428         swi->swi_action = action;
429         swi->swi_state  = SWI_STATE_NEWBORN;
430         cfs_wi_init(&swi->swi_workitem, data, swi_wi_action, sched_id);
431 }
432
433 static inline void
434 swi_schedule_workitem(swi_workitem_t *wi)
435 {
436         cfs_wi_schedule(&wi->swi_workitem);
437 }
438
439 static inline void
440 swi_kill_workitem(swi_workitem_t *swi)
441 {
442         cfs_wi_exit(&swi->swi_workitem);
443 }
444
445 #ifndef __KERNEL__
446 static inline int
447 swi_check_events(void)
448 {
449         return cfs_wi_check_events();
450 }
451 #endif
452
453 int sfw_startup(void);
454 int srpc_startup(void);
455 void sfw_shutdown(void);
456 void srpc_shutdown(void);
457
458 static inline void
459 srpc_destroy_client_rpc (srpc_client_rpc_t *rpc)
460 {
461         LASSERT (rpc != NULL);
462         LASSERT (!srpc_event_pending(rpc));
463         LASSERT (cfs_atomic_read(&rpc->crpc_refcount) == 0);
464 #ifndef __KERNEL__
465         LASSERT (rpc->crpc_bulk.bk_pages == NULL);
466 #endif
467
468         if (rpc->crpc_fini == NULL) {
469                 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
470         } else {
471                 (*rpc->crpc_fini) (rpc);
472         }
473
474         return;
475 }
476
477 static inline void
478 srpc_init_client_rpc (srpc_client_rpc_t *rpc, lnet_process_id_t peer,
479                       int service, int nbulkiov, int bulklen,
480                       void (*rpc_done)(srpc_client_rpc_t *),
481                       void (*rpc_fini)(srpc_client_rpc_t *), void *priv)
482 {
483         LASSERT (nbulkiov <= LNET_MAX_IOV);
484
485         memset(rpc, 0, offsetof(srpc_client_rpc_t,
486                                 crpc_bulk.bk_iovs[nbulkiov]));
487
488         CFS_INIT_LIST_HEAD(&rpc->crpc_list);
489         swi_init_workitem(&rpc->crpc_wi, rpc, srpc_send_rpc,
490                           CFS_WI_SCHED_ANY);
491         cfs_spin_lock_init(&rpc->crpc_lock);
492         cfs_atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */
493
494         rpc->crpc_dest         = peer;
495         rpc->crpc_priv         = priv;
496         rpc->crpc_service      = service;
497         rpc->crpc_bulk.bk_len  = bulklen;
498         rpc->crpc_bulk.bk_niov = nbulkiov;
499         rpc->crpc_done         = rpc_done;
500         rpc->crpc_fini         = rpc_fini;
501         LNetInvalidateHandle(&rpc->crpc_reqstmdh);
502         LNetInvalidateHandle(&rpc->crpc_replymdh);
503         LNetInvalidateHandle(&rpc->crpc_bulk.bk_mdh);
504
505         /* no event is expected at this point */
506         rpc->crpc_bulkev.ev_fired  =
507         rpc->crpc_reqstev.ev_fired =
508         rpc->crpc_replyev.ev_fired = 1;
509
510         rpc->crpc_reqstmsg.msg_magic   = SRPC_MSG_MAGIC;
511         rpc->crpc_reqstmsg.msg_version = SRPC_MSG_VERSION;
512         rpc->crpc_reqstmsg.msg_type    = srpc_service2request(service);
513         return;
514 }
515
516 static inline const char *
517 swi_state2str (int state)
518 {
519 #define STATE2STR(x) case x: return #x
520         switch(state) {
521                 default:
522                         LBUG();
523                 STATE2STR(SWI_STATE_NEWBORN);
524                 STATE2STR(SWI_STATE_REPLY_SUBMITTED);
525                 STATE2STR(SWI_STATE_REPLY_SENT);
526                 STATE2STR(SWI_STATE_REQUEST_SUBMITTED);
527                 STATE2STR(SWI_STATE_REQUEST_SENT);
528                 STATE2STR(SWI_STATE_REPLY_RECEIVED);
529                 STATE2STR(SWI_STATE_BULK_STARTED);
530                 STATE2STR(SWI_STATE_DONE);
531         }
532 #undef STATE2STR
533 }
534
535 #define UNUSED(x)       ( (void)(x) )
536
537 #ifndef __KERNEL__
538
539 int stt_poll_interval(void);
540 int sfw_session_removed(void);
541
542 int stt_check_events(void);
543 int srpc_check_event(int timeout);
544
545 int lnet_selftest_init(void);
546 void lnet_selftest_fini(void);
547 int selftest_wait_events(void);
548
549 #else
550
551 #define selftest_wait_events()    cfs_pause(cfs_time_seconds(1))
552
553 #endif
554
555 #define lst_wait_until(cond, lock, fmt, ...)                            \
556 do {                                                                    \
557         int __I = 2;                                                    \
558         while (!(cond)) {                                               \
559                 CDEBUG(IS_PO2(++__I) ? D_WARNING : D_NET,               \
560                        fmt, ## __VA_ARGS__);                            \
561                 cfs_spin_unlock(&(lock));                               \
562                                                                         \
563                 selftest_wait_events();                                 \
564                                                                         \
565                 cfs_spin_lock(&(lock));                                 \
566         }                                                               \
567 } while (0)
568
569 static inline void
570 srpc_wait_service_shutdown (srpc_service_t *sv)
571 {
572         int i = 2;
573
574         cfs_spin_lock(&sv->sv_lock);
575         LASSERT (sv->sv_shuttingdown);
576         cfs_spin_unlock(&sv->sv_lock);
577
578         while (srpc_finish_service(sv) == 0) {
579                 i++;
580                 CDEBUG (((i & -i) == i) ? D_WARNING : D_NET,
581                         "Waiting for %s service to shutdown...\n",
582                         sv->sv_name);
583                 selftest_wait_events();
584         }
585 }
586
587 #endif /* __SELFTEST_SELFTEST_H__ */