4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lnet/selftest/framework.c
34 * Author: Isaac Huang <isaac@clusterfs.com>
35 * Author: Liang Zhen <liangzhen@clusterfs.com>
38 #define DEBUG_SUBSYSTEM S_LNET
42 struct lst_sid LST_INVALID_SID = { .ses_nid = LNET_NID_ANY, .ses_stamp = -1};
44 static int session_timeout = 100;
45 module_param(session_timeout, int, 0444);
46 MODULE_PARM_DESC(session_timeout, "test session timeout in seconds (100 by default, 0 == never)");
48 static int rpc_timeout = 64;
49 module_param(rpc_timeout, int, 0644);
50 MODULE_PARM_DESC(rpc_timeout, "rpc timeout in seconds (64 by default, 0 == never)");
52 #define sfw_unpack_id(id) \
54 __swab64s(&(id).nid); \
55 __swab32s(&(id).pid); \
58 #define sfw_unpack_sid(sid) \
60 __swab64s(&(sid).ses_nid); \
61 __swab64s(&(sid).ses_stamp); \
64 #define sfw_unpack_fw_counters(fc) \
66 __swab32s(&(fc).running_ms); \
67 __swab32s(&(fc).active_batches); \
68 __swab32s(&(fc).zombie_sessions); \
69 __swab32s(&(fc).brw_errors); \
70 __swab32s(&(fc).ping_errors); \
73 #define sfw_unpack_rpc_counters(rc) \
75 __swab32s(&(rc).errors); \
76 __swab32s(&(rc).rpcs_sent); \
77 __swab32s(&(rc).rpcs_rcvd); \
78 __swab32s(&(rc).rpcs_dropped); \
79 __swab32s(&(rc).rpcs_expired); \
80 __swab64s(&(rc).bulk_get); \
81 __swab64s(&(rc).bulk_put); \
84 #define sfw_unpack_lnet_counters(lc) \
86 __swab32s(&(lc).errors); \
87 __swab32s(&(lc).msgs_max); \
88 __swab32s(&(lc).msgs_alloc); \
89 __swab32s(&(lc).send_count); \
90 __swab32s(&(lc).recv_count); \
91 __swab32s(&(lc).drop_count); \
92 __swab32s(&(lc).route_count); \
93 __swab64s(&(lc).send_length); \
94 __swab64s(&(lc).recv_length); \
95 __swab64s(&(lc).drop_length); \
96 __swab64s(&(lc).route_length); \
99 #define sfw_test_active(t) (atomic_read(&(t)->tsi_nactive) != 0)
100 #define sfw_batch_active(b) (atomic_read(&(b)->bat_nactive) != 0)
102 static struct smoketest_framework {
103 /* RPCs to be recycled */
104 struct list_head fw_zombie_rpcs;
105 /* stopping sessions */
106 struct list_head fw_zombie_sessions;
107 /* registered test cases */
108 struct list_head fw_tests;
109 /* # zombie sessions */
110 atomic_t fw_nzombies;
114 sfw_session_t *fw_session;
115 /* shutdown in progress */
118 srpc_server_rpc_t *fw_active_srpc;
122 int sfw_stop_batch (sfw_batch_t *tsb, int force);
123 void sfw_destroy_session (sfw_session_t *sn);
125 static inline sfw_test_case_t *
126 sfw_find_test_case(int id)
128 sfw_test_case_t *tsc;
130 LASSERT(id <= SRPC_SERVICE_MAX_ID);
131 LASSERT(id > SRPC_FRAMEWORK_SERVICE_MAX_ID);
133 list_for_each_entry(tsc, &sfw_data.fw_tests, tsc_list) {
134 if (tsc->tsc_srv_service->sv_id == id)
142 sfw_register_test (srpc_service_t *service, sfw_test_client_ops_t *cliops)
144 sfw_test_case_t *tsc;
146 if (sfw_find_test_case(service->sv_id) != NULL) {
147 CERROR ("Failed to register test %s (%d)\n",
148 service->sv_name, service->sv_id);
152 LIBCFS_ALLOC(tsc, sizeof(sfw_test_case_t));
156 tsc->tsc_cli_ops = cliops;
157 tsc->tsc_srv_service = service;
159 list_add_tail(&tsc->tsc_list, &sfw_data.fw_tests);
164 sfw_add_session_timer (void)
166 sfw_session_t *sn = sfw_data.fw_session;
167 stt_timer_t *timer = &sn->sn_timer;
169 LASSERT (!sfw_data.fw_shuttingdown);
171 if (sn == NULL || sn->sn_timeout == 0)
174 LASSERT (!sn->sn_timer_active);
176 sn->sn_timer_active = 1;
177 timer->stt_expires = ktime_get_real_seconds()+ sn->sn_timeout;
178 stt_add_timer(timer);
183 sfw_del_session_timer (void)
185 sfw_session_t *sn = sfw_data.fw_session;
187 if (sn == NULL || !sn->sn_timer_active)
190 LASSERT (sn->sn_timeout != 0);
192 if (stt_del_timer(&sn->sn_timer)) { /* timer defused */
193 sn->sn_timer_active = 0;
197 return EBUSY; /* racing with sfw_session_expired() */
200 /* called with sfw_data.fw_lock held */
202 sfw_deactivate_session (void)
203 __must_hold(&sfw_data.fw_lock)
205 sfw_session_t *sn = sfw_data.fw_session;
208 sfw_test_case_t *tsc;
210 if (sn == NULL) return;
212 LASSERT(!sn->sn_timer_active);
214 sfw_data.fw_session = NULL;
215 atomic_inc(&sfw_data.fw_nzombies);
216 list_add(&sn->sn_list, &sfw_data.fw_zombie_sessions);
218 spin_unlock(&sfw_data.fw_lock);
220 list_for_each_entry(tsc, &sfw_data.fw_tests, tsc_list) {
221 srpc_abort_service(tsc->tsc_srv_service);
224 spin_lock(&sfw_data.fw_lock);
226 list_for_each_entry(tsb, &sn->sn_batches, bat_list) {
227 if (sfw_batch_active(tsb)) {
229 sfw_stop_batch(tsb, 1);
234 return; /* wait for active batches to stop */
236 list_del_init(&sn->sn_list);
237 spin_unlock(&sfw_data.fw_lock);
239 sfw_destroy_session(sn);
241 spin_lock(&sfw_data.fw_lock);
246 sfw_session_expired (void *data)
248 sfw_session_t *sn = data;
250 spin_lock(&sfw_data.fw_lock);
252 LASSERT (sn->sn_timer_active);
253 LASSERT (sn == sfw_data.fw_session);
255 CWARN ("Session expired! sid: %s-%llu, name: %s\n",
256 libcfs_nid2str(sn->sn_id.ses_nid),
257 sn->sn_id.ses_stamp, &sn->sn_name[0]);
259 sn->sn_timer_active = 0;
260 sfw_deactivate_session();
262 spin_unlock(&sfw_data.fw_lock);
266 sfw_init_session(sfw_session_t *sn, struct lst_sid sid,
267 unsigned features, const char *name)
269 stt_timer_t *timer = &sn->sn_timer;
271 memset(sn, 0, sizeof(sfw_session_t));
272 INIT_LIST_HEAD(&sn->sn_list);
273 INIT_LIST_HEAD(&sn->sn_batches);
274 atomic_set(&sn->sn_refcount, 1); /* +1 for caller */
275 atomic_set(&sn->sn_brw_errors, 0);
276 atomic_set(&sn->sn_ping_errors, 0);
277 strlcpy(&sn->sn_name[0], name, sizeof(sn->sn_name));
279 sn->sn_timer_active = 0;
281 sn->sn_features = features;
282 sn->sn_timeout = session_timeout;
283 sn->sn_started = cfs_time_current();
285 timer->stt_data = sn;
286 timer->stt_func = sfw_session_expired;
287 INIT_LIST_HEAD(&timer->stt_list);
290 /* completion handler for incoming framework RPCs */
292 sfw_server_rpc_done(struct srpc_server_rpc *rpc)
294 struct srpc_service *sv = rpc->srpc_scd->scd_svc;
295 int status = rpc->srpc_status;
298 "Incoming framework RPC done: "
299 "service %s, peer %s, status %s:%d\n",
300 sv->sv_name, libcfs_id2str(rpc->srpc_peer),
301 swi_state2str(rpc->srpc_wi.swi_state),
304 if (rpc->srpc_bulk != NULL)
310 sfw_client_rpc_fini (srpc_client_rpc_t *rpc)
312 LASSERT(rpc->crpc_bulk.bk_niov == 0);
313 LASSERT(list_empty(&rpc->crpc_list));
314 LASSERT(atomic_read(&rpc->crpc_refcount) == 0);
316 CDEBUG(D_NET, "Outgoing framework RPC done: "
317 "service %d, peer %s, status %s:%d:%d\n",
318 rpc->crpc_service, libcfs_id2str(rpc->crpc_dest),
319 swi_state2str(rpc->crpc_wi.swi_state),
320 rpc->crpc_aborted, rpc->crpc_status);
322 spin_lock(&sfw_data.fw_lock);
324 /* my callers must finish all RPCs before shutting me down */
325 LASSERT(!sfw_data.fw_shuttingdown);
326 list_add(&rpc->crpc_list, &sfw_data.fw_zombie_rpcs);
328 spin_unlock(&sfw_data.fw_lock);
332 sfw_find_batch(struct lst_bid bid)
334 sfw_session_t *sn = sfw_data.fw_session;
339 list_for_each_entry(bat, &sn->sn_batches, bat_list) {
340 if (bat->bat_id.bat_id == bid.bat_id)
348 sfw_bid2batch(struct lst_bid bid)
350 sfw_session_t *sn = sfw_data.fw_session;
353 LASSERT (sn != NULL);
355 bat = sfw_find_batch(bid);
359 LIBCFS_ALLOC(bat, sizeof(sfw_batch_t));
364 bat->bat_session = sn;
366 atomic_set(&bat->bat_nactive, 0);
367 INIT_LIST_HEAD(&bat->bat_tests);
369 list_add_tail(&bat->bat_list, &sn->sn_batches);
374 sfw_get_stats (srpc_stat_reqst_t *request, srpc_stat_reply_t *reply)
376 sfw_session_t *sn = sfw_data.fw_session;
377 struct sfw_counters *cnt = &reply->str_fw;
381 reply->str_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
383 if (request->str_sid.ses_nid == LNET_NID_ANY) {
384 reply->str_status = EINVAL;
388 if (sn == NULL || !sfw_sid_equal(request->str_sid, sn->sn_id)) {
389 reply->str_status = ESRCH;
393 lnet_counters_get(&reply->str_lnet);
394 srpc_get_counters(&reply->str_rpc);
396 /* send over the msecs since the session was started
397 - with 32 bits to send, this is ~49 days */
398 cfs_duration_usec(cfs_time_sub(cfs_time_current(),
399 sn->sn_started), &tv);
401 cnt->running_ms = (__u32)(tv.tv_sec * 1000 + tv.tv_usec / 1000);
402 cnt->brw_errors = atomic_read(&sn->sn_brw_errors);
403 cnt->ping_errors = atomic_read(&sn->sn_ping_errors);
404 cnt->zombie_sessions = atomic_read(&sfw_data.fw_nzombies);
406 cnt->active_batches = 0;
407 list_for_each_entry(bat, &sn->sn_batches, bat_list) {
408 if (atomic_read(&bat->bat_nactive) > 0)
409 cnt->active_batches++;
412 reply->str_status = 0;
417 sfw_make_session(srpc_mksn_reqst_t *request, srpc_mksn_reply_t *reply)
419 sfw_session_t *sn = sfw_data.fw_session;
420 srpc_msg_t *msg = container_of(request, srpc_msg_t,
421 msg_body.mksn_reqst);
424 if (request->mksn_sid.ses_nid == LNET_NID_ANY) {
425 reply->mksn_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
426 reply->mksn_status = EINVAL;
431 reply->mksn_status = 0;
432 reply->mksn_sid = sn->sn_id;
433 reply->mksn_timeout = sn->sn_timeout;
435 if (sfw_sid_equal(request->mksn_sid, sn->sn_id)) {
436 atomic_inc(&sn->sn_refcount);
440 if (!request->mksn_force) {
441 reply->mksn_status = EBUSY;
442 cplen = strlcpy(&reply->mksn_name[0], &sn->sn_name[0],
443 sizeof(reply->mksn_name));
444 if (cplen >= sizeof(reply->mksn_name))
450 /* reject the request if it requires unknown features
451 * NB: old version will always accept all features because it's not
452 * aware of srpc_msg_t::msg_ses_feats, it's a defect but it's also
453 * harmless because it will return zero feature to console, and it's
454 * console's responsibility to make sure all nodes in a session have
455 * same feature mask. */
456 if ((msg->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
457 reply->mksn_status = EPROTO;
461 /* brand new or create by force */
462 LIBCFS_ALLOC(sn, sizeof(sfw_session_t));
464 CERROR("dropping RPC mksn under memory pressure\n");
468 sfw_init_session(sn, request->mksn_sid,
469 msg->msg_ses_feats, &request->mksn_name[0]);
471 spin_lock(&sfw_data.fw_lock);
473 sfw_deactivate_session();
474 LASSERT(sfw_data.fw_session == NULL);
475 sfw_data.fw_session = sn;
477 spin_unlock(&sfw_data.fw_lock);
479 reply->mksn_status = 0;
480 reply->mksn_sid = sn->sn_id;
481 reply->mksn_timeout = sn->sn_timeout;
486 sfw_remove_session (srpc_rmsn_reqst_t *request, srpc_rmsn_reply_t *reply)
488 sfw_session_t *sn = sfw_data.fw_session;
490 reply->rmsn_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
492 if (request->rmsn_sid.ses_nid == LNET_NID_ANY) {
493 reply->rmsn_status = EINVAL;
497 if (sn == NULL || !sfw_sid_equal(request->rmsn_sid, sn->sn_id)) {
498 reply->rmsn_status = (sn == NULL) ? ESRCH : EBUSY;
502 if (!atomic_dec_and_test(&sn->sn_refcount)) {
503 reply->rmsn_status = 0;
507 spin_lock(&sfw_data.fw_lock);
508 sfw_deactivate_session();
509 spin_unlock(&sfw_data.fw_lock);
511 reply->rmsn_status = 0;
512 reply->rmsn_sid = LST_INVALID_SID;
513 LASSERT(sfw_data.fw_session == NULL);
518 sfw_debug_session (srpc_debug_reqst_t *request, srpc_debug_reply_t *reply)
520 sfw_session_t *sn = sfw_data.fw_session;
523 reply->dbg_status = ESRCH;
524 reply->dbg_sid = LST_INVALID_SID;
528 reply->dbg_status = 0;
529 reply->dbg_sid = sn->sn_id;
530 reply->dbg_timeout = sn->sn_timeout;
531 if (strlcpy(reply->dbg_name, &sn->sn_name[0], sizeof(reply->dbg_name))
532 >= sizeof(reply->dbg_name))
539 sfw_test_rpc_fini (srpc_client_rpc_t *rpc)
541 sfw_test_unit_t *tsu = rpc->crpc_priv;
542 sfw_test_instance_t *tsi = tsu->tsu_instance;
544 /* Called with hold of tsi->tsi_lock */
545 LASSERT(list_empty(&rpc->crpc_list));
546 list_add(&rpc->crpc_list, &tsi->tsi_free_rpcs);
550 sfw_test_buffers(sfw_test_instance_t *tsi)
552 struct sfw_test_case *tsc;
553 struct srpc_service *svc;
556 LASSERT(tsi != NULL);
557 tsc = sfw_find_test_case(tsi->tsi_service);
558 LASSERT(tsc != NULL);
559 svc = tsc->tsc_srv_service;
560 LASSERT(svc != NULL);
562 nbuf = min(svc->sv_wi_total, tsi->tsi_loop) / svc->sv_ncpts;
563 return max(SFW_TEST_WI_MIN, nbuf + SFW_TEST_WI_EXTRA);
567 sfw_load_test(struct sfw_test_instance *tsi)
569 struct sfw_test_case *tsc;
570 struct srpc_service *svc;
574 LASSERT(tsi != NULL);
575 tsc = sfw_find_test_case(tsi->tsi_service);
576 nbuf = sfw_test_buffers(tsi);
577 LASSERT(tsc != NULL);
578 svc = tsc->tsc_srv_service;
580 if (tsi->tsi_is_client) {
581 tsi->tsi_ops = tsc->tsc_cli_ops;
585 rc = srpc_service_add_buffers(svc, nbuf);
587 CWARN("Failed to reserve enough buffers: "
588 "service %s, %d needed: %d\n", svc->sv_name, nbuf, rc);
589 /* NB: this error handler is not strictly correct, because
590 * it may release more buffers than already allocated,
591 * but it doesn't matter because request portal should
592 * be lazy portal and will grow buffers if necessary. */
593 srpc_service_remove_buffers(svc, nbuf);
597 CDEBUG(D_NET, "Reserved %d buffers for test %s\n",
598 nbuf * (srpc_serv_is_framework(svc) ?
599 1 : cfs_cpt_number(cfs_cpt_table)), svc->sv_name);
604 sfw_unload_test(struct sfw_test_instance *tsi)
606 struct sfw_test_case *tsc;
608 LASSERT(tsi != NULL);
609 tsc = sfw_find_test_case(tsi->tsi_service);
610 LASSERT(tsc != NULL);
612 if (tsi->tsi_is_client)
615 /* shrink buffers, because request portal is lazy portal
616 * which can grow buffers at runtime so we may leave
617 * some buffers behind, but never mind... */
618 srpc_service_remove_buffers(tsc->tsc_srv_service,
619 sfw_test_buffers(tsi));
624 sfw_destroy_test_instance (sfw_test_instance_t *tsi)
626 srpc_client_rpc_t *rpc;
627 sfw_test_unit_t *tsu;
629 if (!tsi->tsi_is_client) goto clean;
631 tsi->tsi_ops->tso_fini(tsi);
633 LASSERT(!tsi->tsi_stopping);
634 LASSERT(list_empty(&tsi->tsi_active_rpcs));
635 LASSERT(!sfw_test_active(tsi));
637 while (!list_empty(&tsi->tsi_units)) {
638 tsu = list_entry(tsi->tsi_units.next,
639 sfw_test_unit_t, tsu_list);
640 list_del(&tsu->tsu_list);
641 LIBCFS_FREE(tsu, sizeof(*tsu));
644 while (!list_empty(&tsi->tsi_free_rpcs)) {
645 rpc = list_entry(tsi->tsi_free_rpcs.next,
646 srpc_client_rpc_t, crpc_list);
647 list_del(&rpc->crpc_list);
648 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
652 sfw_unload_test(tsi);
653 LIBCFS_FREE(tsi, sizeof(*tsi));
658 sfw_destroy_batch (sfw_batch_t *tsb)
660 sfw_test_instance_t *tsi;
662 LASSERT(!sfw_batch_active(tsb));
663 LASSERT(list_empty(&tsb->bat_list));
665 while (!list_empty(&tsb->bat_tests)) {
666 tsi = list_entry(tsb->bat_tests.next,
667 sfw_test_instance_t, tsi_list);
668 list_del_init(&tsi->tsi_list);
669 sfw_destroy_test_instance(tsi);
672 LIBCFS_FREE(tsb, sizeof(sfw_batch_t));
677 sfw_destroy_session (sfw_session_t *sn)
681 LASSERT(list_empty(&sn->sn_list));
682 LASSERT(sn != sfw_data.fw_session);
684 while (!list_empty(&sn->sn_batches)) {
685 batch = list_entry(sn->sn_batches.next,
686 sfw_batch_t, bat_list);
687 list_del_init(&batch->bat_list);
688 sfw_destroy_batch(batch);
691 LIBCFS_FREE(sn, sizeof(*sn));
692 atomic_dec(&sfw_data.fw_nzombies);
697 sfw_unpack_addtest_req(srpc_msg_t *msg)
699 srpc_test_reqst_t *req = &msg->msg_body.tes_reqst;
701 LASSERT (msg->msg_type == SRPC_MSG_TEST_REQST);
702 LASSERT (req->tsr_is_client);
704 if (msg->msg_magic == SRPC_MSG_MAGIC)
705 return; /* no flipping needed */
707 LASSERT (msg->msg_magic == __swab32(SRPC_MSG_MAGIC));
709 if (req->tsr_service == SRPC_SERVICE_BRW) {
710 if ((msg->msg_ses_feats & LST_FEAT_BULK_LEN) == 0) {
711 test_bulk_req_t *bulk = &req->tsr_u.bulk_v0;
713 __swab32s(&bulk->blk_opc);
714 __swab32s(&bulk->blk_npg);
715 __swab32s(&bulk->blk_flags);
718 test_bulk_req_v1_t *bulk = &req->tsr_u.bulk_v1;
720 __swab16s(&bulk->blk_opc);
721 __swab16s(&bulk->blk_flags);
722 __swab32s(&bulk->blk_offset);
723 __swab32s(&bulk->blk_len);
729 if (req->tsr_service == SRPC_SERVICE_PING) {
730 test_ping_req_t *ping = &req->tsr_u.ping;
732 __swab32s(&ping->png_size);
733 __swab32s(&ping->png_flags);
742 sfw_add_test_instance (sfw_batch_t *tsb, srpc_server_rpc_t *rpc)
744 srpc_msg_t *msg = &rpc->srpc_reqstbuf->buf_msg;
745 srpc_test_reqst_t *req = &msg->msg_body.tes_reqst;
746 srpc_bulk_t *bk = rpc->srpc_bulk;
747 int ndest = req->tsr_ndest;
748 sfw_test_unit_t *tsu;
749 sfw_test_instance_t *tsi;
753 LIBCFS_ALLOC(tsi, sizeof(*tsi));
755 CERROR ("Can't allocate test instance for batch: %llu\n",
760 spin_lock_init(&tsi->tsi_lock);
761 atomic_set(&tsi->tsi_nactive, 0);
762 INIT_LIST_HEAD(&tsi->tsi_units);
763 INIT_LIST_HEAD(&tsi->tsi_free_rpcs);
764 INIT_LIST_HEAD(&tsi->tsi_active_rpcs);
766 tsi->tsi_stopping = 0;
767 tsi->tsi_batch = tsb;
768 tsi->tsi_loop = req->tsr_loop;
769 tsi->tsi_concur = req->tsr_concur;
770 tsi->tsi_service = req->tsr_service;
771 tsi->tsi_is_client = !!(req->tsr_is_client);
772 tsi->tsi_stoptsu_onerr = !!(req->tsr_stop_onerr);
774 rc = sfw_load_test(tsi);
776 LIBCFS_FREE(tsi, sizeof(*tsi));
780 LASSERT (!sfw_batch_active(tsb));
782 if (!tsi->tsi_is_client) {
783 /* it's test server, just add it to tsb */
784 list_add_tail(&tsi->tsi_list, &tsb->bat_tests);
788 LASSERT (bk != NULL);
789 LASSERT (bk->bk_niov * SFW_ID_PER_PAGE >= (unsigned int)ndest);
790 LASSERT((unsigned int)bk->bk_len >=
791 sizeof(struct lnet_process_id_packed) * ndest);
793 sfw_unpack_addtest_req(msg);
794 memcpy(&tsi->tsi_u, &req->tsr_u, sizeof(tsi->tsi_u));
796 for (i = 0; i < ndest; i++) {
797 struct lnet_process_id_packed *dests;
798 struct lnet_process_id_packed id;
801 dests = page_address(bk->bk_iovs[i / SFW_ID_PER_PAGE].kiov_page);
802 LASSERT (dests != NULL); /* my pages are within KVM always */
803 id = dests[i % SFW_ID_PER_PAGE];
804 if (msg->msg_magic != SRPC_MSG_MAGIC)
807 for (j = 0; j < tsi->tsi_concur; j++) {
808 LIBCFS_ALLOC(tsu, sizeof(sfw_test_unit_t));
811 CERROR ("Can't allocate tsu for %d\n",
816 tsu->tsu_dest.nid = id.nid;
817 tsu->tsu_dest.pid = id.pid;
818 tsu->tsu_instance = tsi;
819 tsu->tsu_private = NULL;
820 list_add_tail(&tsu->tsu_list, &tsi->tsi_units);
824 rc = tsi->tsi_ops->tso_init(tsi);
826 list_add_tail(&tsi->tsi_list, &tsb->bat_tests);
832 sfw_destroy_test_instance(tsi);
837 sfw_test_unit_done (sfw_test_unit_t *tsu)
839 sfw_test_instance_t *tsi = tsu->tsu_instance;
840 sfw_batch_t *tsb = tsi->tsi_batch;
841 sfw_session_t *sn = tsb->bat_session;
843 LASSERT (sfw_test_active(tsi));
845 if (!atomic_dec_and_test(&tsi->tsi_nactive))
848 /* the test instance is done */
849 spin_lock(&tsi->tsi_lock);
851 tsi->tsi_stopping = 0;
853 spin_unlock(&tsi->tsi_lock);
855 spin_lock(&sfw_data.fw_lock);
857 if (!atomic_dec_and_test(&tsb->bat_nactive) ||/* tsb still active */
858 sn == sfw_data.fw_session) { /* sn also active */
859 spin_unlock(&sfw_data.fw_lock);
863 LASSERT(!list_empty(&sn->sn_list)); /* I'm a zombie! */
865 list_for_each_entry(tsb, &sn->sn_batches, bat_list) {
866 if (sfw_batch_active(tsb)) {
867 spin_unlock(&sfw_data.fw_lock);
872 list_del_init(&sn->sn_list);
873 spin_unlock(&sfw_data.fw_lock);
875 sfw_destroy_session(sn);
880 sfw_test_rpc_done (srpc_client_rpc_t *rpc)
882 sfw_test_unit_t *tsu = rpc->crpc_priv;
883 sfw_test_instance_t *tsi = tsu->tsu_instance;
886 tsi->tsi_ops->tso_done_rpc(tsu, rpc);
888 spin_lock(&tsi->tsi_lock);
890 LASSERT(sfw_test_active(tsi));
891 LASSERT(!list_empty(&rpc->crpc_list));
893 list_del_init(&rpc->crpc_list);
895 /* batch is stopping or loop is done or get error */
896 if (tsi->tsi_stopping ||
897 tsu->tsu_loop == 0 ||
898 (rpc->crpc_status != 0 && tsi->tsi_stoptsu_onerr))
901 /* dec ref for poster */
902 srpc_client_rpc_decref(rpc);
904 spin_unlock(&tsi->tsi_lock);
907 swi_schedule_workitem(&tsu->tsu_worker);
911 sfw_test_unit_done(tsu);
916 sfw_create_test_rpc(sfw_test_unit_t *tsu, struct lnet_process_id peer,
917 unsigned features, int nblk, int blklen,
918 srpc_client_rpc_t **rpcpp)
920 srpc_client_rpc_t *rpc = NULL;
921 sfw_test_instance_t *tsi = tsu->tsu_instance;
923 spin_lock(&tsi->tsi_lock);
925 LASSERT (sfw_test_active(tsi));
927 if (!list_empty(&tsi->tsi_free_rpcs)) {
928 /* pick request from buffer */
929 rpc = list_entry(tsi->tsi_free_rpcs.next,
930 srpc_client_rpc_t, crpc_list);
931 LASSERT(nblk == rpc->crpc_bulk.bk_niov);
932 list_del_init(&rpc->crpc_list);
935 spin_unlock(&tsi->tsi_lock);
938 rpc = srpc_create_client_rpc(peer, tsi->tsi_service, nblk,
939 blklen, sfw_test_rpc_done,
940 sfw_test_rpc_fini, tsu);
942 srpc_init_client_rpc(rpc, peer, tsi->tsi_service, nblk,
943 blklen, sfw_test_rpc_done,
944 sfw_test_rpc_fini, tsu);
948 CERROR("Can't create rpc for test %d\n", tsi->tsi_service);
952 rpc->crpc_reqstmsg.msg_ses_feats = features;
959 sfw_run_test (swi_workitem_t *wi)
961 sfw_test_unit_t *tsu = wi->swi_workitem.wi_data;
962 sfw_test_instance_t *tsi = tsu->tsu_instance;
963 srpc_client_rpc_t *rpc = NULL;
965 LASSERT (wi == &tsu->tsu_worker);
967 if (tsi->tsi_ops->tso_prep_rpc(tsu, tsu->tsu_dest, &rpc) != 0) {
968 LASSERT (rpc == NULL);
972 LASSERT (rpc != NULL);
974 spin_lock(&tsi->tsi_lock);
976 if (tsi->tsi_stopping) {
977 list_add(&rpc->crpc_list, &tsi->tsi_free_rpcs);
978 spin_unlock(&tsi->tsi_lock);
982 if (tsu->tsu_loop > 0)
985 list_add_tail(&rpc->crpc_list, &tsi->tsi_active_rpcs);
986 spin_unlock(&tsi->tsi_lock);
988 spin_lock(&rpc->crpc_lock);
989 rpc->crpc_timeout = rpc_timeout;
991 spin_unlock(&rpc->crpc_lock);
996 * No one can schedule me now since:
997 * - previous RPC, if any, has done and
998 * - no new RPC is initiated.
999 * - my batch is still active; no one can run it again now.
1000 * Cancel pending schedules and prevent future schedule attempts:
1002 swi_exit_workitem(wi);
1003 sfw_test_unit_done(tsu);
1008 sfw_run_batch (sfw_batch_t *tsb)
1011 sfw_test_unit_t *tsu;
1012 sfw_test_instance_t *tsi;
1014 if (sfw_batch_active(tsb)) {
1015 CDEBUG(D_NET, "Batch already active: %llu (%d)\n",
1016 tsb->bat_id.bat_id, atomic_read(&tsb->bat_nactive));
1020 list_for_each_entry(tsi, &tsb->bat_tests, tsi_list) {
1021 if (!tsi->tsi_is_client) /* skip server instances */
1024 LASSERT(!tsi->tsi_stopping);
1025 LASSERT(!sfw_test_active(tsi));
1027 atomic_inc(&tsb->bat_nactive);
1029 list_for_each_entry(tsu, &tsi->tsi_units, tsu_list) {
1030 atomic_inc(&tsi->tsi_nactive);
1031 tsu->tsu_loop = tsi->tsi_loop;
1032 wi = &tsu->tsu_worker;
1033 swi_init_workitem(wi, tsu, sfw_run_test,
1035 lnet_cpt_of_nid(tsu->tsu_dest.nid,
1037 swi_schedule_workitem(wi);
1045 sfw_stop_batch (sfw_batch_t *tsb, int force)
1047 sfw_test_instance_t *tsi;
1048 srpc_client_rpc_t *rpc;
1050 if (!sfw_batch_active(tsb)) {
1051 CDEBUG(D_NET, "Batch %llu inactive\n", tsb->bat_id.bat_id);
1055 list_for_each_entry(tsi, &tsb->bat_tests, tsi_list) {
1056 spin_lock(&tsi->tsi_lock);
1058 if (!tsi->tsi_is_client ||
1059 !sfw_test_active(tsi) || tsi->tsi_stopping) {
1060 spin_unlock(&tsi->tsi_lock);
1064 tsi->tsi_stopping = 1;
1067 spin_unlock(&tsi->tsi_lock);
1071 /* abort launched rpcs in the test */
1072 list_for_each_entry(rpc, &tsi->tsi_active_rpcs, crpc_list) {
1073 spin_lock(&rpc->crpc_lock);
1075 srpc_abort_rpc(rpc, -EINTR);
1077 spin_unlock(&rpc->crpc_lock);
1080 spin_unlock(&tsi->tsi_lock);
1087 sfw_query_batch (sfw_batch_t *tsb, int testidx, srpc_batch_reply_t *reply)
1089 sfw_test_instance_t *tsi;
1095 reply->bar_active = atomic_read(&tsb->bat_nactive);
1099 list_for_each_entry(tsi, &tsb->bat_tests, tsi_list) {
1103 reply->bar_active = atomic_read(&tsi->tsi_nactive);
1111 sfw_free_pages (srpc_server_rpc_t *rpc)
1113 srpc_free_bulk(rpc->srpc_bulk);
1114 rpc->srpc_bulk = NULL;
1118 sfw_alloc_pages(struct srpc_server_rpc *rpc, int cpt, int npages, int len,
1121 LASSERT(rpc->srpc_bulk == NULL);
1122 LASSERT(npages > 0 && npages <= LNET_MAX_IOV);
1124 rpc->srpc_bulk = srpc_alloc_bulk(cpt, 0, npages, len, sink);
1125 if (rpc->srpc_bulk == NULL)
1132 sfw_add_test (srpc_server_rpc_t *rpc)
1134 sfw_session_t *sn = sfw_data.fw_session;
1135 srpc_test_reply_t *reply = &rpc->srpc_replymsg.msg_body.tes_reply;
1136 srpc_test_reqst_t *request;
1140 request = &rpc->srpc_reqstbuf->buf_msg.msg_body.tes_reqst;
1141 reply->tsr_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
1143 if (request->tsr_loop == 0 ||
1144 request->tsr_concur == 0 ||
1145 request->tsr_sid.ses_nid == LNET_NID_ANY ||
1146 request->tsr_ndest > SFW_MAX_NDESTS ||
1147 (request->tsr_is_client && request->tsr_ndest == 0) ||
1148 request->tsr_concur > SFW_MAX_CONCUR ||
1149 request->tsr_service > SRPC_SERVICE_MAX_ID ||
1150 request->tsr_service <= SRPC_FRAMEWORK_SERVICE_MAX_ID) {
1151 reply->tsr_status = EINVAL;
1155 if (sn == NULL || !sfw_sid_equal(request->tsr_sid, sn->sn_id) ||
1156 sfw_find_test_case(request->tsr_service) == NULL) {
1157 reply->tsr_status = ENOENT;
1161 bat = sfw_bid2batch(request->tsr_bid);
1163 CERROR("dropping RPC %s from %s under memory pressure\n",
1164 rpc->srpc_scd->scd_svc->sv_name,
1165 libcfs_id2str(rpc->srpc_peer));
1169 if (sfw_batch_active(bat)) {
1170 reply->tsr_status = EBUSY;
1174 if (request->tsr_is_client && rpc->srpc_bulk == NULL) {
1175 /* rpc will be resumed later in sfw_bulk_ready */
1176 int npg = sfw_id_pages(request->tsr_ndest);
1179 if ((sn->sn_features & LST_FEAT_BULK_LEN) == 0) {
1180 len = npg * PAGE_SIZE;
1183 len = sizeof(struct lnet_process_id_packed) *
1187 return sfw_alloc_pages(rpc, CFS_CPT_ANY, npg, len, 1);
1190 rc = sfw_add_test_instance(bat, rpc);
1191 CDEBUG (rc == 0 ? D_NET : D_WARNING,
1192 "%s test: sv %d %s, loop %d, concur %d, ndest %d\n",
1193 rc == 0 ? "Added" : "Failed to add", request->tsr_service,
1194 request->tsr_is_client ? "client" : "server",
1195 request->tsr_loop, request->tsr_concur, request->tsr_ndest);
1197 reply->tsr_status = (rc < 0) ? -rc : rc;
1202 sfw_control_batch (srpc_batch_reqst_t *request, srpc_batch_reply_t *reply)
1204 sfw_session_t *sn = sfw_data.fw_session;
1208 reply->bar_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
1210 if (sn == NULL || !sfw_sid_equal(request->bar_sid, sn->sn_id)) {
1211 reply->bar_status = ESRCH;
1215 bat = sfw_find_batch(request->bar_bid);
1217 reply->bar_status = ENOENT;
1221 switch (request->bar_opc) {
1222 case SRPC_BATCH_OPC_RUN:
1223 rc = sfw_run_batch(bat);
1226 case SRPC_BATCH_OPC_STOP:
1227 rc = sfw_stop_batch(bat, request->bar_arg);
1230 case SRPC_BATCH_OPC_QUERY:
1231 rc = sfw_query_batch(bat, request->bar_testidx, reply);
1235 return -EINVAL; /* drop it */
1238 reply->bar_status = (rc < 0) ? -rc : rc;
1243 sfw_handle_server_rpc(struct srpc_server_rpc *rpc)
1245 struct srpc_service *sv = rpc->srpc_scd->scd_svc;
1246 srpc_msg_t *reply = &rpc->srpc_replymsg;
1247 srpc_msg_t *request = &rpc->srpc_reqstbuf->buf_msg;
1248 unsigned features = LST_FEATS_MASK;
1251 LASSERT(sfw_data.fw_active_srpc == NULL);
1252 LASSERT(sv->sv_id <= SRPC_FRAMEWORK_SERVICE_MAX_ID);
1254 spin_lock(&sfw_data.fw_lock);
1256 if (sfw_data.fw_shuttingdown) {
1257 spin_unlock(&sfw_data.fw_lock);
1261 /* Remove timer to avoid racing with it or expiring active session */
1262 if (sfw_del_session_timer() != 0) {
1263 CERROR("dropping RPC %s from %s: racing with expiry timer\n",
1264 sv->sv_name, libcfs_id2str(rpc->srpc_peer));
1265 spin_unlock(&sfw_data.fw_lock);
1269 sfw_data.fw_active_srpc = rpc;
1270 spin_unlock(&sfw_data.fw_lock);
1272 sfw_unpack_message(request);
1273 LASSERT(request->msg_type == srpc_service2request(sv->sv_id));
1275 /* rpc module should have checked this */
1276 LASSERT(request->msg_version == SRPC_MSG_VERSION);
1278 if (sv->sv_id != SRPC_SERVICE_MAKE_SESSION &&
1279 sv->sv_id != SRPC_SERVICE_DEBUG) {
1280 sfw_session_t *sn = sfw_data.fw_session;
1283 sn->sn_features != request->msg_ses_feats) {
1284 CNETERR("Features of framework RPC don't match "
1285 "features of current session: %x/%x\n",
1286 request->msg_ses_feats, sn->sn_features);
1287 reply->msg_body.reply.status = EPROTO;
1288 reply->msg_body.reply.sid = sn->sn_id;
1292 } else if ((request->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
1293 /* NB: at this point, old version will ignore features and
1294 * create new session anyway, so console should be able
1296 reply->msg_body.reply.status = EPROTO;
1303 case SRPC_SERVICE_TEST:
1304 rc = sfw_add_test(rpc);
1307 case SRPC_SERVICE_BATCH:
1308 rc = sfw_control_batch(&request->msg_body.bat_reqst,
1309 &reply->msg_body.bat_reply);
1312 case SRPC_SERVICE_QUERY_STAT:
1313 rc = sfw_get_stats(&request->msg_body.stat_reqst,
1314 &reply->msg_body.stat_reply);
1317 case SRPC_SERVICE_DEBUG:
1318 rc = sfw_debug_session(&request->msg_body.dbg_reqst,
1319 &reply->msg_body.dbg_reply);
1322 case SRPC_SERVICE_MAKE_SESSION:
1323 rc = sfw_make_session(&request->msg_body.mksn_reqst,
1324 &reply->msg_body.mksn_reply);
1327 case SRPC_SERVICE_REMOVE_SESSION:
1328 rc = sfw_remove_session(&request->msg_body.rmsn_reqst,
1329 &reply->msg_body.rmsn_reply);
1333 if (sfw_data.fw_session != NULL)
1334 features = sfw_data.fw_session->sn_features;
1336 reply->msg_ses_feats = features;
1337 rpc->srpc_done = sfw_server_rpc_done;
1338 spin_lock(&sfw_data.fw_lock);
1340 if (!sfw_data.fw_shuttingdown)
1341 sfw_add_session_timer();
1343 sfw_data.fw_active_srpc = NULL;
1344 spin_unlock(&sfw_data.fw_lock);
1349 sfw_bulk_ready(struct srpc_server_rpc *rpc, int status)
1351 struct srpc_service *sv = rpc->srpc_scd->scd_svc;
1354 LASSERT(rpc->srpc_bulk != NULL);
1355 LASSERT(sv->sv_id == SRPC_SERVICE_TEST);
1356 LASSERT(sfw_data.fw_active_srpc == NULL);
1357 LASSERT(rpc->srpc_reqstbuf->buf_msg.msg_body.tes_reqst.tsr_is_client);
1359 spin_lock(&sfw_data.fw_lock);
1362 CERROR("Bulk transfer failed for RPC: "
1363 "service %s, peer %s, status %d\n",
1364 sv->sv_name, libcfs_id2str(rpc->srpc_peer), status);
1365 spin_unlock(&sfw_data.fw_lock);
1369 if (sfw_data.fw_shuttingdown) {
1370 spin_unlock(&sfw_data.fw_lock);
1374 if (sfw_del_session_timer() != 0) {
1375 CERROR("dropping RPC %s from %s: racing with expiry timer\n",
1376 sv->sv_name, libcfs_id2str(rpc->srpc_peer));
1377 spin_unlock(&sfw_data.fw_lock);
1381 sfw_data.fw_active_srpc = rpc;
1382 spin_unlock(&sfw_data.fw_lock);
1384 rc = sfw_add_test(rpc);
1386 spin_lock(&sfw_data.fw_lock);
1388 if (!sfw_data.fw_shuttingdown)
1389 sfw_add_session_timer();
1391 sfw_data.fw_active_srpc = NULL;
1392 spin_unlock(&sfw_data.fw_lock);
1397 sfw_create_rpc(struct lnet_process_id peer, int service,
1398 unsigned features, int nbulkiov, int bulklen,
1399 void (*done)(srpc_client_rpc_t *), void *priv)
1401 srpc_client_rpc_t *rpc = NULL;
1403 spin_lock(&sfw_data.fw_lock);
1405 LASSERT (!sfw_data.fw_shuttingdown);
1406 LASSERT (service <= SRPC_FRAMEWORK_SERVICE_MAX_ID);
1408 if (nbulkiov == 0 && !list_empty(&sfw_data.fw_zombie_rpcs)) {
1409 rpc = list_entry(sfw_data.fw_zombie_rpcs.next,
1410 srpc_client_rpc_t, crpc_list);
1411 list_del(&rpc->crpc_list);
1413 srpc_init_client_rpc(rpc, peer, service, 0, 0,
1414 done, sfw_client_rpc_fini, priv);
1417 spin_unlock(&sfw_data.fw_lock);
1420 rpc = srpc_create_client_rpc(peer, service,
1421 nbulkiov, bulklen, done,
1422 nbulkiov != 0 ? NULL :
1423 sfw_client_rpc_fini,
1427 if (rpc != NULL) /* "session" is concept in framework */
1428 rpc->crpc_reqstmsg.msg_ses_feats = features;
1434 sfw_unpack_message (srpc_msg_t *msg)
1436 if (msg->msg_magic == SRPC_MSG_MAGIC)
1437 return; /* no flipping needed */
1439 /* srpc module should guarantee I wouldn't get crap */
1440 LASSERT (msg->msg_magic == __swab32(SRPC_MSG_MAGIC));
1442 if (msg->msg_type == SRPC_MSG_STAT_REQST) {
1443 srpc_stat_reqst_t *req = &msg->msg_body.stat_reqst;
1445 __swab32s(&req->str_type);
1446 __swab64s(&req->str_rpyid);
1447 sfw_unpack_sid(req->str_sid);
1451 if (msg->msg_type == SRPC_MSG_STAT_REPLY) {
1452 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1454 __swab32s(&rep->str_status);
1455 sfw_unpack_sid(rep->str_sid);
1456 sfw_unpack_fw_counters(rep->str_fw);
1457 sfw_unpack_rpc_counters(rep->str_rpc);
1458 sfw_unpack_lnet_counters(rep->str_lnet);
1462 if (msg->msg_type == SRPC_MSG_MKSN_REQST) {
1463 srpc_mksn_reqst_t *req = &msg->msg_body.mksn_reqst;
1465 __swab64s(&req->mksn_rpyid);
1466 __swab32s(&req->mksn_force);
1467 sfw_unpack_sid(req->mksn_sid);
1471 if (msg->msg_type == SRPC_MSG_MKSN_REPLY) {
1472 srpc_mksn_reply_t *rep = &msg->msg_body.mksn_reply;
1474 __swab32s(&rep->mksn_status);
1475 __swab32s(&rep->mksn_timeout);
1476 sfw_unpack_sid(rep->mksn_sid);
1480 if (msg->msg_type == SRPC_MSG_RMSN_REQST) {
1481 srpc_rmsn_reqst_t *req = &msg->msg_body.rmsn_reqst;
1483 __swab64s(&req->rmsn_rpyid);
1484 sfw_unpack_sid(req->rmsn_sid);
1488 if (msg->msg_type == SRPC_MSG_RMSN_REPLY) {
1489 srpc_rmsn_reply_t *rep = &msg->msg_body.rmsn_reply;
1491 __swab32s(&rep->rmsn_status);
1492 sfw_unpack_sid(rep->rmsn_sid);
1496 if (msg->msg_type == SRPC_MSG_DEBUG_REQST) {
1497 srpc_debug_reqst_t *req = &msg->msg_body.dbg_reqst;
1499 __swab64s(&req->dbg_rpyid);
1500 __swab32s(&req->dbg_flags);
1501 sfw_unpack_sid(req->dbg_sid);
1505 if (msg->msg_type == SRPC_MSG_DEBUG_REPLY) {
1506 srpc_debug_reply_t *rep = &msg->msg_body.dbg_reply;
1508 __swab32s(&rep->dbg_nbatch);
1509 __swab32s(&rep->dbg_timeout);
1510 sfw_unpack_sid(rep->dbg_sid);
1514 if (msg->msg_type == SRPC_MSG_BATCH_REQST) {
1515 srpc_batch_reqst_t *req = &msg->msg_body.bat_reqst;
1517 __swab32s(&req->bar_opc);
1518 __swab64s(&req->bar_rpyid);
1519 __swab32s(&req->bar_testidx);
1520 __swab32s(&req->bar_arg);
1521 sfw_unpack_sid(req->bar_sid);
1522 __swab64s(&req->bar_bid.bat_id);
1526 if (msg->msg_type == SRPC_MSG_BATCH_REPLY) {
1527 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1529 __swab32s(&rep->bar_status);
1530 sfw_unpack_sid(rep->bar_sid);
1534 if (msg->msg_type == SRPC_MSG_TEST_REQST) {
1535 srpc_test_reqst_t *req = &msg->msg_body.tes_reqst;
1537 __swab64s(&req->tsr_rpyid);
1538 __swab64s(&req->tsr_bulkid);
1539 __swab32s(&req->tsr_loop);
1540 __swab32s(&req->tsr_ndest);
1541 __swab32s(&req->tsr_concur);
1542 __swab32s(&req->tsr_service);
1543 sfw_unpack_sid(req->tsr_sid);
1544 __swab64s(&req->tsr_bid.bat_id);
1548 if (msg->msg_type == SRPC_MSG_TEST_REPLY) {
1549 srpc_test_reply_t *rep = &msg->msg_body.tes_reply;
1551 __swab32s(&rep->tsr_status);
1552 sfw_unpack_sid(rep->tsr_sid);
1556 if (msg->msg_type == SRPC_MSG_JOIN_REQST) {
1557 srpc_join_reqst_t *req = &msg->msg_body.join_reqst;
1559 __swab64s(&req->join_rpyid);
1560 sfw_unpack_sid(req->join_sid);
1564 if (msg->msg_type == SRPC_MSG_JOIN_REPLY) {
1565 srpc_join_reply_t *rep = &msg->msg_body.join_reply;
1567 __swab32s(&rep->join_status);
1568 __swab32s(&rep->join_timeout);
1569 sfw_unpack_sid(rep->join_sid);
1578 sfw_abort_rpc (srpc_client_rpc_t *rpc)
1580 LASSERT(atomic_read(&rpc->crpc_refcount) > 0);
1581 LASSERT(rpc->crpc_service <= SRPC_FRAMEWORK_SERVICE_MAX_ID);
1583 spin_lock(&rpc->crpc_lock);
1584 srpc_abort_rpc(rpc, -EINTR);
1585 spin_unlock(&rpc->crpc_lock);
1590 sfw_post_rpc (srpc_client_rpc_t *rpc)
1592 spin_lock(&rpc->crpc_lock);
1594 LASSERT(!rpc->crpc_closed);
1595 LASSERT(!rpc->crpc_aborted);
1596 LASSERT(list_empty(&rpc->crpc_list));
1597 LASSERT(!sfw_data.fw_shuttingdown);
1599 rpc->crpc_timeout = rpc_timeout;
1602 spin_unlock(&rpc->crpc_lock);
1606 static srpc_service_t sfw_services[] =
1609 /* sv_id */ SRPC_SERVICE_DEBUG,
1610 /* sv_name */ "debug",
1614 /* sv_id */ SRPC_SERVICE_QUERY_STAT,
1615 /* sv_name */ "query stats",
1619 /* sv_id */ SRPC_SERVICE_MAKE_SESSION,
1620 /* sv_name */ "make session",
1624 /* sv_id */ SRPC_SERVICE_REMOVE_SESSION,
1625 /* sv_name */ "remove session",
1629 /* sv_id */ SRPC_SERVICE_BATCH,
1630 /* sv_name */ "batch service",
1634 /* sv_id */ SRPC_SERVICE_TEST,
1635 /* sv_name */ "test service",
1652 sfw_test_case_t *tsc;
1655 if (session_timeout < 0) {
1656 CERROR ("Session timeout must be non-negative: %d\n",
1661 if (rpc_timeout < 0) {
1662 CERROR ("RPC timeout must be non-negative: %d\n",
1667 if (session_timeout == 0)
1668 CWARN ("Zero session_timeout specified "
1669 "- test sessions never expire.\n");
1671 if (rpc_timeout == 0)
1672 CWARN ("Zero rpc_timeout specified "
1673 "- test RPC never expire.\n");
1675 memset(&sfw_data, 0, sizeof(struct smoketest_framework));
1677 sfw_data.fw_session = NULL;
1678 sfw_data.fw_active_srpc = NULL;
1679 spin_lock_init(&sfw_data.fw_lock);
1680 atomic_set(&sfw_data.fw_nzombies, 0);
1681 INIT_LIST_HEAD(&sfw_data.fw_tests);
1682 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
1683 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
1685 brw_init_test_client();
1686 brw_init_test_service();
1687 rc = sfw_register_test(&brw_test_service, &brw_test_client);
1690 ping_init_test_client();
1691 ping_init_test_service();
1692 rc = sfw_register_test(&ping_test_service, &ping_test_client);
1696 list_for_each_entry(tsc, &sfw_data.fw_tests, tsc_list) {
1697 sv = tsc->tsc_srv_service;
1699 rc = srpc_add_service(sv);
1700 LASSERT(rc != -EBUSY);
1702 CWARN("Failed to add %s service: %d\n",
1708 for (i = 0; ; i++) {
1709 sv = &sfw_services[i];
1710 if (sv->sv_name == NULL) break;
1712 sv->sv_bulk_ready = NULL;
1713 sv->sv_handler = sfw_handle_server_rpc;
1714 sv->sv_wi_total = SFW_FRWK_WI_MAX;
1715 if (sv->sv_id == SRPC_SERVICE_TEST)
1716 sv->sv_bulk_ready = sfw_bulk_ready;
1718 rc = srpc_add_service(sv);
1719 LASSERT (rc != -EBUSY);
1721 CWARN ("Failed to add %s service: %d\n",
1726 /* about to sfw_shutdown, no need to add buffer */
1727 if (error) continue;
1729 rc = srpc_service_add_buffers(sv, sv->sv_wi_total);
1731 CWARN("Failed to reserve enough buffers: "
1732 "service %s, %d needed: %d\n",
1733 sv->sv_name, sv->sv_wi_total, rc);
1747 sfw_test_case_t *tsc;
1750 spin_lock(&sfw_data.fw_lock);
1752 sfw_data.fw_shuttingdown = 1;
1753 lst_wait_until(sfw_data.fw_active_srpc == NULL, sfw_data.fw_lock,
1754 "waiting for active RPC to finish.\n");
1756 if (sfw_del_session_timer() != 0)
1757 lst_wait_until(sfw_data.fw_session == NULL, sfw_data.fw_lock,
1758 "waiting for session timer to explode.\n");
1760 sfw_deactivate_session();
1761 lst_wait_until(atomic_read(&sfw_data.fw_nzombies) == 0,
1763 "waiting for %d zombie sessions to die.\n",
1764 atomic_read(&sfw_data.fw_nzombies));
1766 spin_unlock(&sfw_data.fw_lock);
1768 for (i = 0; ; i++) {
1769 sv = &sfw_services[i];
1770 if (sv->sv_name == NULL)
1773 srpc_shutdown_service(sv);
1774 srpc_remove_service(sv);
1777 list_for_each_entry(tsc, &sfw_data.fw_tests, tsc_list) {
1778 sv = tsc->tsc_srv_service;
1779 srpc_shutdown_service(sv);
1780 srpc_remove_service(sv);
1783 while (!list_empty(&sfw_data.fw_zombie_rpcs)) {
1784 srpc_client_rpc_t *rpc;
1786 rpc = list_entry(sfw_data.fw_zombie_rpcs.next,
1787 srpc_client_rpc_t, crpc_list);
1788 list_del(&rpc->crpc_list);
1790 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
1793 for (i = 0; ; i++) {
1794 sv = &sfw_services[i];
1795 if (sv->sv_name == NULL)
1798 srpc_wait_service_shutdown(sv);
1801 while (!list_empty(&sfw_data.fw_tests)) {
1802 tsc = list_entry(sfw_data.fw_tests.next,
1803 sfw_test_case_t, tsc_list);
1805 srpc_wait_service_shutdown(tsc->tsc_srv_service);
1807 list_del(&tsc->tsc_list);
1808 LIBCFS_FREE(tsc, sizeof(*tsc));