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