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