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