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