Whamcloud - gitweb
LU-16011 lnet: use preallocate bulk for server
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lnet/selftest/selftest.h
32  *
33  * Author: Isaac Huang <isaac@clusterfs.com>
34  */
35 #ifndef __SELFTEST_SELFTEST_H__
36 #define __SELFTEST_SELFTEST_H__
37
38 #define LNET_ONLY
39
40 #include <libcfs/libcfs.h>
41 #include <lnet/api.h>
42 #include <lnet/lib-lnet.h>
43 #include <lnet/lib-types.h>
44 #include <uapi/linux/lnet/lnetst.h>
45
46 #include "rpc.h"
47 #include "timer.h"
48
49 #ifndef MADE_WITHOUT_COMPROMISE
50 #define MADE_WITHOUT_COMPROMISE
51 #endif
52
53
54 #define SWI_STATE_NEWBORN                  0
55 #define SWI_STATE_REPLY_SUBMITTED          1
56 #define SWI_STATE_REPLY_SENT               2
57 #define SWI_STATE_REQUEST_SUBMITTED        3
58 #define SWI_STATE_REQUEST_SENT             4
59 #define SWI_STATE_REPLY_RECEIVED           5
60 #define SWI_STATE_BULK_STARTED             6
61 #define SWI_STATE_DONE                     10
62
63 /* forward refs */
64 struct srpc_service;
65 struct srpc_service_cd;
66 struct sfw_test_unit;
67 struct sfw_test_instance;
68
69 /* services below SRPC_FRAMEWORK_SERVICE_MAX_ID are framework
70  * services, e.g. create/modify session.
71  */
72 #define SRPC_SERVICE_DEBUG              0
73 #define SRPC_SERVICE_MAKE_SESSION       1
74 #define SRPC_SERVICE_REMOVE_SESSION     2
75 #define SRPC_SERVICE_BATCH              3
76 #define SRPC_SERVICE_TEST               4
77 #define SRPC_SERVICE_QUERY_STAT         5
78 #define SRPC_SERVICE_JOIN               6
79 #define SRPC_FRAMEWORK_SERVICE_MAX_ID   10
80 /* other services start from SRPC_FRAMEWORK_SERVICE_MAX_ID+1 */
81 #define SRPC_SERVICE_BRW                11
82 #define SRPC_SERVICE_PING               12
83 #define SRPC_SERVICE_MAX_ID             12
84
85 #define SRPC_REQUEST_PORTAL             50
86 /* a lazy portal for framework RPC requests */
87 #define SRPC_FRAMEWORK_REQUEST_PORTAL   51
88 /* all reply/bulk RDMAs go to this portal */
89 #define SRPC_RDMA_PORTAL                52
90
91 static inline enum srpc_msg_type
92 srpc_service2request (int service)
93 {
94         switch (service) {
95         default:
96                 LBUG ();
97         case SRPC_SERVICE_DEBUG:
98                 return SRPC_MSG_DEBUG_REQST;
99
100         case SRPC_SERVICE_MAKE_SESSION:
101                 return SRPC_MSG_MKSN_REQST;
102
103         case SRPC_SERVICE_REMOVE_SESSION:
104                 return SRPC_MSG_RMSN_REQST;
105
106         case SRPC_SERVICE_BATCH:
107                 return SRPC_MSG_BATCH_REQST;
108
109         case SRPC_SERVICE_TEST:
110                 return SRPC_MSG_TEST_REQST;
111
112         case SRPC_SERVICE_QUERY_STAT:
113                 return SRPC_MSG_STAT_REQST;
114
115         case SRPC_SERVICE_BRW:
116                 return SRPC_MSG_BRW_REQST;
117
118         case SRPC_SERVICE_PING:
119                 return SRPC_MSG_PING_REQST;
120
121         case SRPC_SERVICE_JOIN:
122                 return SRPC_MSG_JOIN_REQST;
123         }
124 }
125
126 static inline enum srpc_msg_type
127 srpc_service2reply (int service)
128 {
129         return srpc_service2request(service) + 1;
130 }
131
132 enum srpc_event_type {
133         SRPC_BULK_REQ_RCVD   = 1, /* passive bulk request(PUT sink/GET source) received */
134         SRPC_BULK_PUT_SENT   = 2, /* active bulk PUT sent (source) */
135         SRPC_BULK_GET_RPLD   = 3, /* active bulk GET replied (sink) */
136         SRPC_REPLY_RCVD      = 4, /* incoming reply received */
137         SRPC_REPLY_SENT      = 5, /* outgoing reply sent */
138         SRPC_REQUEST_RCVD    = 6, /* incoming request received */
139         SRPC_REQUEST_SENT    = 7, /* outgoing request sent */
140 };
141
142 /* RPC event */
143 struct srpc_event {
144         enum srpc_event_type    ev_type;   /* what's up */
145         enum lnet_event_kind    ev_lnet;   /* LNet event type */
146         int               ev_fired;  /* LNet event fired? */
147         int               ev_status; /* LNet event status */
148         void             *ev_data;   /* owning server/client RPC */
149 };
150
151 /* bulk descriptor */
152 struct srpc_bulk {
153         int                     bk_len;  /* len of bulk data */
154         struct lnet_handle_md   bk_mdh;
155         int                     bk_sink; /* sink/source */
156         int                     bk_niov; /* # iov in bk_iovs */
157         struct bio_vec          bk_iovs[0];
158 };
159
160 /* message buffer descriptor */
161 struct srpc_buffer {
162         struct list_head        buf_list; /* chain on srpc_service::*_msgq */
163         struct srpc_msg         buf_msg;
164         struct lnet_handle_md   buf_mdh;
165         lnet_nid_t              buf_self;
166         struct lnet_process_id  buf_peer;
167 };
168
169 struct swi_workitem;
170 typedef int (*swi_action_t)(struct swi_workitem *);
171
172 struct swi_workitem {
173         struct cfs_wi_sched     *swi_sched;
174         struct cfs_workitem     swi_workitem;
175         swi_action_t         swi_action;
176         int                  swi_state;
177 };
178
179 /* server-side state of a RPC */
180 struct srpc_server_rpc {
181         /* chain on srpc_service::*_rpcq */
182         struct list_head        srpc_list;
183         struct srpc_service_cd *srpc_scd;
184         struct swi_workitem     srpc_wi;
185         struct srpc_event       srpc_ev;        /* bulk/reply event */
186         lnet_nid_t              srpc_self;
187         struct lnet_process_id  srpc_peer;
188         struct srpc_msg         srpc_replymsg;
189         struct lnet_handle_md   srpc_replymdh;
190         struct srpc_buffer     *srpc_reqstbuf;
191         struct srpc_bulk       *srpc_bulk;
192
193         unsigned int    srpc_aborted; /* being given up */
194         int             srpc_status;
195         void            (*srpc_done)(struct srpc_server_rpc *);
196 };
197
198 /* client-side state of a RPC */
199 struct srpc_client_rpc {
200         struct list_head        crpc_list;      /* chain on user's lists */
201         spinlock_t              crpc_lock;      /* serialize */
202         int                     crpc_service;
203         atomic_t                crpc_refcount;
204         /* # seconds to wait for reply */
205         int                     crpc_timeout;
206         struct stt_timer        crpc_timer;
207         struct swi_workitem     crpc_wi;
208         struct lnet_process_id  crpc_dest;
209
210         void               (*crpc_done)(struct srpc_client_rpc *);
211         void               (*crpc_fini)(struct srpc_client_rpc *);
212         int                  crpc_status;    /* completion status */
213         void                *crpc_priv;      /* caller data */
214
215         /* state flags */
216         unsigned int         crpc_aborted:1; /* being given up */
217         unsigned int         crpc_closed:1;  /* completed */
218
219         /* RPC events */
220         struct srpc_event       crpc_bulkev;    /* bulk event */
221         struct srpc_event       crpc_reqstev;   /* request event */
222         struct srpc_event       crpc_replyev;   /* reply event */
223
224         /* bulk, request(reqst), and reply exchanged on wire */
225         struct srpc_msg         crpc_reqstmsg;
226         struct srpc_msg         crpc_replymsg;
227         struct lnet_handle_md   crpc_reqstmdh;
228         struct lnet_handle_md   crpc_replymdh;
229         struct srpc_bulk        crpc_bulk;
230 };
231
232 #define srpc_client_rpc_size(rpc)                                       \
233 offsetof(struct srpc_client_rpc, crpc_bulk.bk_iovs[(rpc)->crpc_bulk.bk_niov])
234
235 #define srpc_client_rpc_addref(rpc)                                     \
236 do {                                                                    \
237         CDEBUG(D_NET, "RPC[%p] -> %s (%d)++\n",                         \
238                (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
239                atomic_read(&(rpc)->crpc_refcount));                 \
240         LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0);            \
241         atomic_inc(&(rpc)->crpc_refcount);                          \
242 } while (0)
243
244 #define srpc_client_rpc_decref(rpc)                                     \
245 do {                                                                    \
246         CDEBUG(D_NET, "RPC[%p] -> %s (%d)--\n",                         \
247                (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
248                atomic_read(&(rpc)->crpc_refcount));                 \
249         LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0);            \
250         if (atomic_dec_and_test(&(rpc)->crpc_refcount))             \
251                 srpc_destroy_client_rpc(rpc);                           \
252 } while (0)
253
254 #define srpc_event_pending(rpc)   ((rpc)->crpc_bulkev.ev_fired == 0 ||  \
255                                    (rpc)->crpc_reqstev.ev_fired == 0 || \
256                                    (rpc)->crpc_replyev.ev_fired == 0)
257
258 /* CPU partition data of srpc service */
259 struct srpc_service_cd {
260         /** serialize */
261         spinlock_t              scd_lock;
262         /** backref to service */
263         struct srpc_service     *scd_svc;
264         /** event buffer */
265         struct srpc_event       scd_ev;
266         /** free RPC descriptors */
267         struct list_head        scd_rpc_free;
268         /** in-flight RPCs */
269         struct list_head        scd_rpc_active;
270         /** workitem for posting buffer */
271         struct swi_workitem     scd_buf_wi;
272         /** CPT id */
273         int                     scd_cpt;
274         /** error code for scd_buf_wi */
275         int                     scd_buf_err;
276         /** timestamp for scd_buf_err */
277         time64_t                scd_buf_err_stamp;
278         /** total # request buffers */
279         int                     scd_buf_total;
280         /** # posted request buffers */
281         int                     scd_buf_nposted;
282         /** in progress of buffer posting */
283         int                     scd_buf_posting;
284         /** allocate more buffers if scd_buf_nposted < scd_buf_low */
285         int                     scd_buf_low;
286         /** increase/decrease some buffers */
287         int                     scd_buf_adjust;
288         /** posted message buffers */
289         struct list_head        scd_buf_posted;
290         /** blocked for RPC descriptor */
291         struct list_head        scd_buf_blocked;
292 };
293
294 /* number of server workitems (mini-thread) for testing service */
295 #define SFW_TEST_WI_MIN         256
296 #define SFW_TEST_WI_MAX         2048
297 /* extra buffers for tolerating buggy peers, or unbalanced number
298  * of peers between partitions  */
299 #define SFW_TEST_WI_EXTRA       64
300
301 /* number of server workitems (mini-thread) for framework service */
302 #define SFW_FRWK_WI_MIN         16
303 #define SFW_FRWK_WI_MAX         256
304
305 struct srpc_service {
306         int                     sv_id;          /* service id */
307         const char              *sv_name;       /* human readable name */
308         int                     sv_wi_total;    /* total server workitems */
309         int                     sv_shuttingdown;
310         int                     sv_ncpts;
311         /* percpt data for srpc_service */
312         struct srpc_service_cd  **sv_cpt_data;
313         /* Service callbacks:
314          * - sv_handler: process incoming RPC request
315          * - sv_bulk_ready: notify bulk data
316          */
317         int              (*sv_handler)(struct srpc_server_rpc *);
318         int              (*sv_bulk_ready)(struct srpc_server_rpc *, int);
319
320         /** Service side srpc constructor/destructor.
321          *  used for the bulk preallocation as usual.
322          */
323         int              (*sv_srpc_init)(struct srpc_server_rpc *, int);
324         void             (*sv_srpc_fini)(struct srpc_server_rpc *);
325 };
326
327 struct sfw_session {
328         /* chain on fw_zombie_sessions */
329         struct list_head        sn_list;
330         struct lst_sid          sn_id;          /* unique identifier */
331         /* # seconds' inactivity to expire */
332         unsigned int            sn_timeout;
333         int                     sn_timer_active;
334         unsigned int            sn_features;
335         struct stt_timer        sn_timer;
336         struct list_head        sn_batches;     /* list of batches */
337         char                    sn_name[LST_NAME_SIZE];
338         atomic_t                sn_refcount;
339         atomic_t                sn_brw_errors;
340         atomic_t                sn_ping_errors;
341         ktime_t                 sn_started;
342 };
343
344 #define sfw_sid_equal(sid0, sid1)     ((sid0).ses_nid == (sid1).ses_nid && \
345                                        (sid0).ses_stamp == (sid1).ses_stamp)
346
347 struct sfw_batch {
348         struct list_head        bat_list;       /* chain on sn_batches */
349         struct lst_bid          bat_id;         /* batch id */
350         int                     bat_error;      /* error code of batch */
351         struct sfw_session      *bat_session;   /* batch's session */
352         atomic_t                bat_nactive;    /* # of active tests */
353         struct list_head        bat_tests;      /* test instances */
354 };
355
356 struct sfw_test_client_ops {
357         int  (*tso_init)(struct sfw_test_instance *tsi); /* intailize test client */
358         void (*tso_fini)(struct sfw_test_instance *tsi); /* finalize test client */
359         int  (*tso_prep_rpc)(struct sfw_test_unit *tsu,
360                              struct lnet_process_id dest,
361                              struct srpc_client_rpc **rpc); /* prep a tests rpc */
362         void (*tso_done_rpc)(struct sfw_test_unit *tsu,
363                              struct srpc_client_rpc *rpc);  /* done a test rpc */
364 };
365
366 struct sfw_test_instance {
367         struct list_head        tsi_list;       /* chain on batch */
368         int                     tsi_service;    /* test type */
369         struct sfw_batch        *tsi_batch;     /* batch */
370         struct sfw_test_client_ops      *tsi_ops;       /* test client operations */
371
372         /* public parameter for all test units */
373         unsigned int            tsi_is_client:1;     /* is test client */
374         unsigned int            tsi_stoptsu_onerr:1; /* stop tsu on error */
375         int                     tsi_concur;          /* concurrency */
376         int                     tsi_loop;            /* loop count */
377
378         /* status of test instance */
379         spinlock_t              tsi_lock;       /* serialize */
380         unsigned int            tsi_stopping:1; /* test is stopping */
381         atomic_t                tsi_nactive;    /* # of active test unit */
382         struct list_head        tsi_units;      /* test units */
383         struct list_head        tsi_free_rpcs;  /* free rpcs */
384         struct list_head        tsi_active_rpcs;/* active rpcs */
385
386         union {
387                 struct test_ping_req    ping;     /* ping parameter */
388                 struct test_bulk_req    bulk_v0;  /* bulk parameter */
389                 struct test_bulk_req_v1 bulk_v1;  /* bulk v1 parameter */
390         } tsi_u;
391 };
392
393 /* XXX: trailing (PAGE_SIZE % sizeof(struct lnet_process_id)) bytes at
394  * the end of pages are not used */
395 #define SFW_MAX_CONCUR     LST_MAX_CONCUR
396 #define SFW_ID_PER_PAGE    (PAGE_SIZE / sizeof(struct lnet_process_id_packed))
397 #define SFW_MAX_NDESTS     (LNET_MAX_IOV * SFW_ID_PER_PAGE)
398 #define sfw_id_pages(n)    (((n) + SFW_ID_PER_PAGE - 1) / SFW_ID_PER_PAGE)
399
400 struct sfw_test_unit {
401         struct list_head        tsu_list;       /* chain on lst_test_instance */
402         struct lnet_process_id  tsu_dest;       /* id of dest node */
403         int                     tsu_loop;       /* loop count of the test */
404         struct sfw_test_instance *tsu_instance; /* pointer to test instance */
405         void                    *tsu_private;   /* private data */
406         struct swi_workitem      tsu_worker;    /* workitem of the test unit */
407 };
408
409 struct sfw_test_case {
410         struct list_head                tsc_list;               /* chain on fw_tests */
411         struct srpc_service             *tsc_srv_service;       /* test service */
412         struct sfw_test_client_ops      *tsc_cli_ops;           /* ops of test client */
413 };
414
415 struct srpc_client_rpc *
416 sfw_create_rpc(struct lnet_process_id peer, int service,
417                unsigned features, int nbulkiov, int bulklen,
418                void (*done)(struct srpc_client_rpc *), void *priv);
419 int sfw_create_test_rpc(struct sfw_test_unit *tsu,
420                         struct lnet_process_id peer, unsigned int features,
421                         int nblk, int blklen, struct srpc_client_rpc **rpc);
422 void sfw_abort_rpc(struct srpc_client_rpc *rpc);
423 void sfw_post_rpc(struct srpc_client_rpc *rpc);
424 void sfw_client_rpc_done(struct srpc_client_rpc *rpc);
425 void sfw_unpack_message(struct srpc_msg *msg);
426 void sfw_add_bulk_page(struct srpc_bulk *bk, struct page *pg, int i);
427 int sfw_alloc_pages(struct srpc_server_rpc *rpc, int cpt, int npages, int len,
428                     int sink);
429 int sfw_make_session(struct srpc_mksn_reqst *request,
430                      struct srpc_mksn_reply *reply);
431
432 struct srpc_client_rpc *
433 srpc_create_client_rpc(struct lnet_process_id peer, int service,
434                        int nbulkiov, int bulklen,
435                        void (*rpc_done)(struct srpc_client_rpc *),
436                        void (*rpc_fini)(struct srpc_client_rpc *), void *priv);
437 void srpc_post_rpc(struct srpc_client_rpc *rpc);
438 void srpc_abort_rpc(struct srpc_client_rpc *rpc, int why);
439 void srpc_free_bulk(struct srpc_bulk *bk);
440 struct srpc_bulk *srpc_alloc_bulk(int cpt, unsigned int bulk_npg);
441 void srpc_init_bulk(struct srpc_bulk *bk, unsigned int off,
442                     unsigned int bulk_npg, unsigned int bulk_len, int sink);
443
444 int srpc_send_rpc(struct swi_workitem *wi);
445 int srpc_send_reply(struct srpc_server_rpc *rpc);
446 int srpc_add_service(struct srpc_service *sv);
447 int srpc_remove_service(struct srpc_service *sv);
448 void srpc_shutdown_service(struct srpc_service *sv);
449 void srpc_abort_service(struct srpc_service *sv);
450 int srpc_finish_service(struct srpc_service *sv);
451 int srpc_service_add_buffers(struct srpc_service *sv, int nbuffer);
452 void srpc_service_remove_buffers(struct srpc_service *sv, int nbuffer);
453 void srpc_get_counters(struct srpc_counters *cnt);
454
455 extern struct cfs_wi_sched *lst_sched_serial;
456 extern struct cfs_wi_sched **lst_sched_test;
457
458 static inline int
459 srpc_serv_is_framework(struct srpc_service *svc)
460 {
461         return svc->sv_id < SRPC_FRAMEWORK_SERVICE_MAX_ID;
462 }
463
464 static inline int
465 swi_wi_action(struct cfs_workitem *wi)
466 {
467         struct swi_workitem *swi;
468
469         swi = container_of(wi, struct swi_workitem, swi_workitem);
470         return swi->swi_action(swi);
471 }
472
473 static inline void
474 swi_init_workitem(struct swi_workitem *swi,
475                   swi_action_t action, struct cfs_wi_sched *sched)
476 {
477         swi->swi_sched  = sched;
478         swi->swi_action = action;
479         swi->swi_state  = SWI_STATE_NEWBORN;
480         cfs_wi_init(&swi->swi_workitem, swi_wi_action);
481 }
482
483 static inline void
484 swi_schedule_workitem(struct swi_workitem *wi)
485 {
486         cfs_wi_schedule(wi->swi_sched, &wi->swi_workitem);
487 }
488
489 static inline void
490 swi_exit_workitem(struct swi_workitem *swi)
491 {
492         cfs_wi_exit(swi->swi_sched, &swi->swi_workitem);
493 }
494
495 static inline int
496 swi_deschedule_workitem(struct swi_workitem *swi)
497 {
498         return cfs_wi_deschedule(swi->swi_sched, &swi->swi_workitem);
499 }
500
501 int sfw_startup(void);
502 int srpc_startup(void);
503 void sfw_shutdown(void);
504 void srpc_shutdown(void);
505
506 static inline void
507 srpc_destroy_client_rpc(struct srpc_client_rpc *rpc)
508 {
509         LASSERT (rpc != NULL);
510         LASSERT (!srpc_event_pending(rpc));
511         LASSERT (atomic_read(&rpc->crpc_refcount) == 0);
512
513         if (rpc->crpc_fini == NULL) {
514                 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
515         } else {
516                 (*rpc->crpc_fini) (rpc);
517         }
518 }
519
520 static inline void
521 srpc_init_client_rpc(struct srpc_client_rpc *rpc, struct lnet_process_id peer,
522                      int service, int nbulkiov, int bulklen,
523                      void (*rpc_done)(struct srpc_client_rpc *),
524                      void (*rpc_fini)(struct srpc_client_rpc *), void *priv)
525 {
526         LASSERT(nbulkiov <= LNET_MAX_IOV);
527
528         memset(rpc, 0, offsetof(struct srpc_client_rpc,
529                                 crpc_bulk.bk_iovs[nbulkiov]));
530
531         INIT_LIST_HEAD(&rpc->crpc_list);
532         swi_init_workitem(&rpc->crpc_wi, srpc_send_rpc,
533                           lst_sched_test[lnet_cpt_of_nid(peer.nid, NULL)]);
534         spin_lock_init(&rpc->crpc_lock);
535         atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */
536
537         rpc->crpc_dest         = peer;
538         rpc->crpc_priv         = priv;
539         rpc->crpc_service      = service;
540         rpc->crpc_bulk.bk_len  = bulklen;
541         rpc->crpc_bulk.bk_niov = nbulkiov;
542         rpc->crpc_done         = rpc_done;
543         rpc->crpc_fini         = rpc_fini;
544         LNetInvalidateMDHandle(&rpc->crpc_reqstmdh);
545         LNetInvalidateMDHandle(&rpc->crpc_replymdh);
546         LNetInvalidateMDHandle(&rpc->crpc_bulk.bk_mdh);
547
548         /* no event is expected at this point */
549         rpc->crpc_bulkev.ev_fired  =
550         rpc->crpc_reqstev.ev_fired =
551         rpc->crpc_replyev.ev_fired = 1;
552
553         rpc->crpc_reqstmsg.msg_magic   = SRPC_MSG_MAGIC;
554         rpc->crpc_reqstmsg.msg_version = SRPC_MSG_VERSION;
555         rpc->crpc_reqstmsg.msg_type    = srpc_service2request(service);
556 }
557
558 static inline const char *
559 swi_state2str (int state)
560 {
561 #define STATE2STR(x) case x: return #x
562         switch(state) {
563                 default:
564                         LBUG();
565                 STATE2STR(SWI_STATE_NEWBORN);
566                 STATE2STR(SWI_STATE_REPLY_SUBMITTED);
567                 STATE2STR(SWI_STATE_REPLY_SENT);
568                 STATE2STR(SWI_STATE_REQUEST_SUBMITTED);
569                 STATE2STR(SWI_STATE_REQUEST_SENT);
570                 STATE2STR(SWI_STATE_REPLY_RECEIVED);
571                 STATE2STR(SWI_STATE_BULK_STARTED);
572                 STATE2STR(SWI_STATE_DONE);
573         }
574 #undef STATE2STR
575 }
576
577 #define lst_wait_until(cond, lock, fmt, ...)                            \
578 do {                                                                    \
579         int __I = 2;                                                    \
580         while (!(cond)) {                                               \
581                 CDEBUG(is_power_of_2(++__I) ? D_WARNING : D_NET,        \
582                        fmt, ## __VA_ARGS__);                            \
583                 spin_unlock(&(lock));                                   \
584                                                                         \
585                 schedule_timeout_uninterruptible(                       \
586                         cfs_time_seconds(1) / 10);                      \
587                                                                         \
588                 spin_lock(&(lock));                                     \
589         }                                                               \
590 } while (0)
591
592 static inline void
593 srpc_wait_service_shutdown(struct srpc_service *sv)
594 {
595         int i = 2;
596
597         LASSERT(sv->sv_shuttingdown);
598
599         while (srpc_finish_service(sv) == 0) {
600                 i++;
601                 CDEBUG(((i & -i) == i) ? D_WARNING : D_NET,
602                        "Waiting for %s service to shutdown...\n",
603                        sv->sv_name);
604                 schedule_timeout_uninterruptible(cfs_time_seconds(1) / 10);
605         }
606 }
607
608 extern struct sfw_test_client_ops ping_test_client;
609 extern struct srpc_service ping_test_service;
610 void ping_init_test_client(void);
611 void ping_init_test_service(void);
612
613 extern struct sfw_test_client_ops brw_test_client;
614 extern struct srpc_service brw_test_service;
615 void brw_init_test_service(void);
616
617 #endif /* __SELFTEST_SELFTEST_H__ */