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