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, 2017, 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).lcc_errors); \
87 __swab32s(&(lc).lcc_msgs_max); \
88 __swab32s(&(lc).lcc_msgs_alloc); \
89 __swab32s(&(lc).lcc_send_count); \
90 __swab32s(&(lc).lcc_recv_count); \
91 __swab32s(&(lc).lcc_drop_count); \
92 __swab32s(&(lc).lcc_route_count); \
93 __swab64s(&(lc).lcc_send_length); \
94 __swab64s(&(lc).lcc_recv_length); \
95 __swab64s(&(lc).lcc_drop_length); \
96 __swab64s(&(lc).lcc_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 struct sfw_session *fw_session;
115 /* shutdown in progress */
118 struct srpc_server_rpc *fw_active_srpc;
122 static int sfw_stop_batch(struct sfw_batch *tsb, int force);
123 static void sfw_destroy_session(struct sfw_session *sn);
125 static inline struct sfw_test_case *
126 sfw_find_test_case(int id)
128 struct sfw_test_case *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(struct srpc_service *service,
143 struct sfw_test_client_ops *cliops)
145 struct sfw_test_case *tsc;
147 if (sfw_find_test_case(service->sv_id) != NULL) {
148 CERROR ("Failed to register test %s (%d)\n",
149 service->sv_name, service->sv_id);
153 LIBCFS_ALLOC(tsc, sizeof(*tsc));
157 tsc->tsc_cli_ops = cliops;
158 tsc->tsc_srv_service = service;
160 list_add_tail(&tsc->tsc_list, &sfw_data.fw_tests);
165 sfw_add_session_timer (void)
167 struct sfw_session *sn = sfw_data.fw_session;
168 struct stt_timer *timer = &sn->sn_timer;
170 LASSERT (!sfw_data.fw_shuttingdown);
172 if (sn == NULL || sn->sn_timeout == 0)
175 LASSERT (!sn->sn_timer_active);
177 sn->sn_timer_active = 1;
178 timer->stt_expires = ktime_get_real_seconds()+ sn->sn_timeout;
179 stt_add_timer(timer);
183 sfw_del_session_timer (void)
185 struct sfw_session *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 struct sfw_session *sn = sfw_data.fw_session;
207 struct sfw_batch *tsb;
208 struct sfw_test_case *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 struct sfw_session *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(struct sfw_session *sn, struct lst_sid sid,
267 unsigned features, const char *name)
269 struct stt_timer *timer = &sn->sn_timer;
271 memset(sn, 0, sizeof(struct sfw_session));
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 = ktime_get();
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)
309 sfw_client_rpc_fini(struct srpc_client_rpc *rpc)
311 LASSERT(rpc->crpc_bulk.bk_niov == 0);
312 LASSERT(list_empty(&rpc->crpc_list));
313 LASSERT(atomic_read(&rpc->crpc_refcount) == 0);
315 CDEBUG(D_NET, "Outgoing framework RPC done: "
316 "service %d, peer %s, status %s:%d:%d\n",
317 rpc->crpc_service, libcfs_id2str(rpc->crpc_dest),
318 swi_state2str(rpc->crpc_wi.swi_state),
319 rpc->crpc_aborted, rpc->crpc_status);
321 spin_lock(&sfw_data.fw_lock);
323 /* my callers must finish all RPCs before shutting me down */
324 LASSERT(!sfw_data.fw_shuttingdown);
325 list_add(&rpc->crpc_list, &sfw_data.fw_zombie_rpcs);
327 spin_unlock(&sfw_data.fw_lock);
330 static struct sfw_batch *
331 sfw_find_batch(struct lst_bid bid)
333 struct sfw_session *sn = sfw_data.fw_session;
334 struct sfw_batch *bat;
338 list_for_each_entry(bat, &sn->sn_batches, bat_list) {
339 if (bat->bat_id.bat_id == bid.bat_id)
346 static struct sfw_batch *
347 sfw_bid2batch(struct lst_bid bid)
349 struct sfw_session *sn = sfw_data.fw_session;
350 struct sfw_batch *bat;
352 LASSERT (sn != NULL);
354 bat = sfw_find_batch(bid);
358 LIBCFS_ALLOC(bat, sizeof(*bat));
363 bat->bat_session = sn;
365 atomic_set(&bat->bat_nactive, 0);
366 INIT_LIST_HEAD(&bat->bat_tests);
368 list_add_tail(&bat->bat_list, &sn->sn_batches);
373 sfw_get_stats(struct srpc_stat_reqst *request, struct srpc_stat_reply *reply)
375 struct sfw_session *sn = sfw_data.fw_session;
376 struct sfw_counters *cnt = &reply->str_fw;
377 struct sfw_batch *bat;
379 reply->str_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
381 if (request->str_sid.ses_nid == LNET_NID_ANY) {
382 reply->str_status = EINVAL;
386 if (sn == NULL || !sfw_sid_equal(request->str_sid, sn->sn_id)) {
387 reply->str_status = ESRCH;
391 lnet_counters_get_common(&reply->str_lnet);
392 srpc_get_counters(&reply->str_rpc);
394 /* send over the msecs since the session was started
395 - with 32 bits to send, this is ~49 days */
396 cnt->running_ms = ktime_ms_delta(ktime_get(), sn->sn_started);
397 cnt->brw_errors = atomic_read(&sn->sn_brw_errors);
398 cnt->ping_errors = atomic_read(&sn->sn_ping_errors);
399 cnt->zombie_sessions = atomic_read(&sfw_data.fw_nzombies);
401 cnt->active_batches = 0;
402 list_for_each_entry(bat, &sn->sn_batches, bat_list) {
403 if (atomic_read(&bat->bat_nactive) > 0)
404 cnt->active_batches++;
407 reply->str_status = 0;
412 sfw_make_session(struct srpc_mksn_reqst *request, struct srpc_mksn_reply *reply)
414 struct sfw_session *sn = sfw_data.fw_session;
415 struct srpc_msg *msg = container_of(request, struct srpc_msg,
416 msg_body.mksn_reqst);
419 if (request->mksn_sid.ses_nid == LNET_NID_ANY) {
420 reply->mksn_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
421 reply->mksn_status = EINVAL;
426 reply->mksn_status = 0;
427 reply->mksn_sid = sn->sn_id;
428 reply->mksn_timeout = sn->sn_timeout;
430 if (sfw_sid_equal(request->mksn_sid, sn->sn_id)) {
431 atomic_inc(&sn->sn_refcount);
435 if (!request->mksn_force) {
436 reply->mksn_status = EBUSY;
437 cplen = strlcpy(&reply->mksn_name[0], &sn->sn_name[0],
438 sizeof(reply->mksn_name));
439 if (cplen >= sizeof(reply->mksn_name))
445 /* reject the request if it requires unknown features
446 * NB: old version will always accept all features because it's not
447 * aware of struct srpc_msg::msg_ses_feats, it's a defect but it's also
448 * harmless because it will return zero feature to console, and it's
449 * console's responsibility to make sure all nodes in a session have
450 * same feature mask. */
451 if ((msg->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
452 reply->mksn_status = EPROTO;
456 /* brand new or create by force */
457 LIBCFS_ALLOC(sn, sizeof(*sn));
459 CERROR("dropping RPC mksn under memory pressure\n");
463 sfw_init_session(sn, request->mksn_sid,
464 msg->msg_ses_feats, &request->mksn_name[0]);
466 spin_lock(&sfw_data.fw_lock);
468 sfw_deactivate_session();
469 LASSERT(sfw_data.fw_session == NULL);
470 sfw_data.fw_session = sn;
472 spin_unlock(&sfw_data.fw_lock);
474 reply->mksn_status = 0;
475 reply->mksn_sid = sn->sn_id;
476 reply->mksn_timeout = sn->sn_timeout;
481 sfw_remove_session(struct srpc_rmsn_reqst *request,
482 struct srpc_rmsn_reply *reply)
484 struct sfw_session *sn = sfw_data.fw_session;
486 reply->rmsn_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
488 if (request->rmsn_sid.ses_nid == LNET_NID_ANY) {
489 reply->rmsn_status = EINVAL;
493 if (sn == NULL || !sfw_sid_equal(request->rmsn_sid, sn->sn_id)) {
494 reply->rmsn_status = (sn == NULL) ? ESRCH : EBUSY;
498 if (!atomic_dec_and_test(&sn->sn_refcount)) {
499 reply->rmsn_status = 0;
503 spin_lock(&sfw_data.fw_lock);
504 sfw_deactivate_session();
505 spin_unlock(&sfw_data.fw_lock);
507 reply->rmsn_status = 0;
508 reply->rmsn_sid = LST_INVALID_SID;
509 LASSERT(sfw_data.fw_session == NULL);
514 sfw_debug_session(struct srpc_debug_reqst *request,
515 struct srpc_debug_reply *reply)
517 struct sfw_session *sn = sfw_data.fw_session;
520 reply->dbg_status = ESRCH;
521 reply->dbg_sid = LST_INVALID_SID;
525 reply->dbg_status = 0;
526 reply->dbg_sid = sn->sn_id;
527 reply->dbg_timeout = sn->sn_timeout;
528 if (strlcpy(reply->dbg_name, &sn->sn_name[0], sizeof(reply->dbg_name))
529 >= sizeof(reply->dbg_name))
536 sfw_test_rpc_fini(struct srpc_client_rpc *rpc)
538 struct sfw_test_unit *tsu = rpc->crpc_priv;
539 struct sfw_test_instance *tsi = tsu->tsu_instance;
541 /* Called with hold of tsi->tsi_lock */
542 LASSERT(list_empty(&rpc->crpc_list));
543 list_add(&rpc->crpc_list, &tsi->tsi_free_rpcs);
547 sfw_test_buffers(struct sfw_test_instance *tsi)
549 struct sfw_test_case *tsc;
550 struct srpc_service *svc;
553 LASSERT(tsi != NULL);
554 tsc = sfw_find_test_case(tsi->tsi_service);
555 LASSERT(tsc != NULL);
556 svc = tsc->tsc_srv_service;
557 LASSERT(svc != NULL);
559 nbuf = min(svc->sv_wi_total, tsi->tsi_loop) / svc->sv_ncpts;
560 return max(SFW_TEST_WI_MIN, nbuf + SFW_TEST_WI_EXTRA);
564 sfw_load_test(struct sfw_test_instance *tsi)
566 struct sfw_test_case *tsc;
567 struct srpc_service *svc;
571 LASSERT(tsi != NULL);
572 tsc = sfw_find_test_case(tsi->tsi_service);
573 nbuf = sfw_test_buffers(tsi);
574 LASSERT(tsc != NULL);
575 svc = tsc->tsc_srv_service;
577 if (tsi->tsi_is_client) {
578 tsi->tsi_ops = tsc->tsc_cli_ops;
582 rc = srpc_service_add_buffers(svc, nbuf);
584 CWARN("Failed to reserve enough buffers: "
585 "service %s, %d needed: %d\n", svc->sv_name, nbuf, rc);
586 /* NB: this error handler is not strictly correct, because
587 * it may release more buffers than already allocated,
588 * but it doesn't matter because request portal should
589 * be lazy portal and will grow buffers if necessary. */
590 srpc_service_remove_buffers(svc, nbuf);
594 CDEBUG(D_NET, "Reserved %d buffers for test %s\n",
595 nbuf * (srpc_serv_is_framework(svc) ?
596 1 : cfs_cpt_number(cfs_cpt_tab)), svc->sv_name);
601 sfw_unload_test(struct sfw_test_instance *tsi)
603 struct sfw_test_case *tsc;
605 LASSERT(tsi != NULL);
606 tsc = sfw_find_test_case(tsi->tsi_service);
607 LASSERT(tsc != NULL);
609 if (tsi->tsi_is_client)
612 /* shrink buffers, because request portal is lazy portal
613 * which can grow buffers at runtime so we may leave
614 * some buffers behind, but never mind... */
615 srpc_service_remove_buffers(tsc->tsc_srv_service,
616 sfw_test_buffers(tsi));
620 sfw_destroy_test_instance(struct sfw_test_instance *tsi)
622 struct srpc_client_rpc *rpc;
623 struct sfw_test_unit *tsu;
625 if (!tsi->tsi_is_client) goto clean;
627 tsi->tsi_ops->tso_fini(tsi);
629 LASSERT(!tsi->tsi_stopping);
630 LASSERT(list_empty(&tsi->tsi_active_rpcs));
631 LASSERT(!sfw_test_active(tsi));
633 while (!list_empty(&tsi->tsi_units)) {
634 tsu = list_entry(tsi->tsi_units.next,
635 struct sfw_test_unit, tsu_list);
636 list_del(&tsu->tsu_list);
637 LIBCFS_FREE(tsu, sizeof(*tsu));
640 while (!list_empty(&tsi->tsi_free_rpcs)) {
641 rpc = list_entry(tsi->tsi_free_rpcs.next,
642 struct srpc_client_rpc, crpc_list);
643 list_del(&rpc->crpc_list);
644 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
648 sfw_unload_test(tsi);
649 LIBCFS_FREE(tsi, sizeof(*tsi));
653 sfw_destroy_batch(struct sfw_batch *tsb)
655 struct sfw_test_instance *tsi;
657 LASSERT(!sfw_batch_active(tsb));
658 LASSERT(list_empty(&tsb->bat_list));
660 while (!list_empty(&tsb->bat_tests)) {
661 tsi = list_entry(tsb->bat_tests.next,
662 struct sfw_test_instance, tsi_list);
663 list_del_init(&tsi->tsi_list);
664 sfw_destroy_test_instance(tsi);
667 LIBCFS_FREE(tsb, sizeof(*tsb));
671 sfw_destroy_session(struct sfw_session *sn)
673 struct sfw_batch *batch;
675 LASSERT(list_empty(&sn->sn_list));
676 LASSERT(sn != sfw_data.fw_session);
678 while (!list_empty(&sn->sn_batches)) {
679 batch = list_entry(sn->sn_batches.next,
680 struct sfw_batch, bat_list);
681 list_del_init(&batch->bat_list);
682 sfw_destroy_batch(batch);
685 LIBCFS_FREE(sn, sizeof(*sn));
686 atomic_dec(&sfw_data.fw_nzombies);
690 sfw_unpack_addtest_req(struct srpc_msg *msg)
692 struct srpc_test_reqst *req = &msg->msg_body.tes_reqst;
694 LASSERT (msg->msg_type == SRPC_MSG_TEST_REQST);
695 LASSERT (req->tsr_is_client);
697 if (msg->msg_magic == SRPC_MSG_MAGIC)
698 return; /* no flipping needed */
700 LASSERT (msg->msg_magic == __swab32(SRPC_MSG_MAGIC));
702 if (req->tsr_service == SRPC_SERVICE_BRW) {
703 if ((msg->msg_ses_feats & LST_FEAT_BULK_LEN) == 0) {
704 struct test_bulk_req *bulk = &req->tsr_u.bulk_v0;
706 __swab32s(&bulk->blk_opc);
707 __swab32s(&bulk->blk_npg);
708 __swab32s(&bulk->blk_flags);
711 struct test_bulk_req_v1 *bulk = &req->tsr_u.bulk_v1;
713 __swab16s(&bulk->blk_opc);
714 __swab16s(&bulk->blk_flags);
715 __swab32s(&bulk->blk_offset);
716 __swab32s(&bulk->blk_len);
722 if (req->tsr_service == SRPC_SERVICE_PING) {
723 struct test_ping_req *ping = &req->tsr_u.ping;
725 __swab32s(&ping->png_size);
726 __swab32s(&ping->png_flags);
734 sfw_add_test_instance(struct sfw_batch *tsb, struct srpc_server_rpc *rpc)
736 struct srpc_msg *msg = &rpc->srpc_reqstbuf->buf_msg;
737 struct srpc_test_reqst *req = &msg->msg_body.tes_reqst;
738 struct srpc_bulk *bk = rpc->srpc_bulk;
739 int ndest = req->tsr_ndest;
740 struct sfw_test_unit *tsu;
741 struct sfw_test_instance *tsi;
745 LIBCFS_ALLOC(tsi, sizeof(*tsi));
747 CERROR ("Can't allocate test instance for batch: %llu\n",
752 spin_lock_init(&tsi->tsi_lock);
753 atomic_set(&tsi->tsi_nactive, 0);
754 INIT_LIST_HEAD(&tsi->tsi_units);
755 INIT_LIST_HEAD(&tsi->tsi_free_rpcs);
756 INIT_LIST_HEAD(&tsi->tsi_active_rpcs);
758 tsi->tsi_stopping = 0;
759 tsi->tsi_batch = tsb;
760 tsi->tsi_loop = req->tsr_loop;
761 tsi->tsi_concur = req->tsr_concur;
762 tsi->tsi_service = req->tsr_service;
763 tsi->tsi_is_client = !!(req->tsr_is_client);
764 tsi->tsi_stoptsu_onerr = !!(req->tsr_stop_onerr);
766 rc = sfw_load_test(tsi);
768 LIBCFS_FREE(tsi, sizeof(*tsi));
772 LASSERT (!sfw_batch_active(tsb));
774 if (!tsi->tsi_is_client) {
775 /* it's test server, just add it to tsb */
776 list_add_tail(&tsi->tsi_list, &tsb->bat_tests);
780 LASSERT (bk != NULL);
781 LASSERT (bk->bk_niov * SFW_ID_PER_PAGE >= (unsigned int)ndest);
782 LASSERT((unsigned int)bk->bk_len >=
783 sizeof(struct lnet_process_id_packed) * ndest);
785 sfw_unpack_addtest_req(msg);
786 memcpy(&tsi->tsi_u, &req->tsr_u, sizeof(tsi->tsi_u));
788 for (i = 0; i < ndest; i++) {
789 struct lnet_process_id_packed *dests;
790 struct lnet_process_id_packed id;
793 dests = page_address(bk->bk_iovs[i / SFW_ID_PER_PAGE].bv_page);
794 LASSERT (dests != NULL); /* my pages are within KVM always */
795 id = dests[i % SFW_ID_PER_PAGE];
796 if (msg->msg_magic != SRPC_MSG_MAGIC)
799 for (j = 0; j < tsi->tsi_concur; j++) {
800 LIBCFS_ALLOC(tsu, sizeof(*tsu));
803 CERROR ("Can't allocate tsu for %d\n",
808 tsu->tsu_dest.nid = id.nid;
809 tsu->tsu_dest.pid = id.pid;
810 tsu->tsu_instance = tsi;
811 tsu->tsu_private = NULL;
812 list_add_tail(&tsu->tsu_list, &tsi->tsi_units);
816 rc = tsi->tsi_ops->tso_init(tsi);
818 list_add_tail(&tsi->tsi_list, &tsb->bat_tests);
824 sfw_destroy_test_instance(tsi);
829 sfw_test_unit_done(struct sfw_test_unit *tsu)
831 struct sfw_test_instance *tsi = tsu->tsu_instance;
832 struct sfw_batch *tsb = tsi->tsi_batch;
833 struct sfw_session *sn = tsb->bat_session;
835 LASSERT (sfw_test_active(tsi));
837 if (!atomic_dec_and_test(&tsi->tsi_nactive))
840 /* the test instance is done */
841 spin_lock(&tsi->tsi_lock);
843 tsi->tsi_stopping = 0;
845 spin_unlock(&tsi->tsi_lock);
847 spin_lock(&sfw_data.fw_lock);
849 if (!atomic_dec_and_test(&tsb->bat_nactive) ||/* tsb still active */
850 sn == sfw_data.fw_session) { /* sn also active */
851 spin_unlock(&sfw_data.fw_lock);
855 LASSERT(!list_empty(&sn->sn_list)); /* I'm a zombie! */
857 list_for_each_entry(tsb, &sn->sn_batches, bat_list) {
858 if (sfw_batch_active(tsb)) {
859 spin_unlock(&sfw_data.fw_lock);
864 list_del_init(&sn->sn_list);
865 spin_unlock(&sfw_data.fw_lock);
867 sfw_destroy_session(sn);
871 sfw_test_rpc_done(struct srpc_client_rpc *rpc)
873 struct sfw_test_unit *tsu = rpc->crpc_priv;
874 struct sfw_test_instance *tsi = tsu->tsu_instance;
877 tsi->tsi_ops->tso_done_rpc(tsu, rpc);
879 spin_lock(&tsi->tsi_lock);
881 LASSERT(sfw_test_active(tsi));
882 LASSERT(!list_empty(&rpc->crpc_list));
884 list_del_init(&rpc->crpc_list);
886 /* batch is stopping or loop is done or get error */
887 if (tsi->tsi_stopping ||
888 tsu->tsu_loop == 0 ||
889 (rpc->crpc_status != 0 && tsi->tsi_stoptsu_onerr))
892 /* dec ref for poster */
893 srpc_client_rpc_decref(rpc);
895 spin_unlock(&tsi->tsi_lock);
898 swi_schedule_workitem(&tsu->tsu_worker);
902 sfw_test_unit_done(tsu);
906 sfw_create_test_rpc(struct sfw_test_unit *tsu, struct lnet_process_id peer,
907 unsigned features, int nblk, int blklen,
908 struct srpc_client_rpc **rpcpp)
910 struct srpc_client_rpc *rpc = NULL;
911 struct sfw_test_instance *tsi = tsu->tsu_instance;
913 spin_lock(&tsi->tsi_lock);
915 LASSERT (sfw_test_active(tsi));
917 if (!list_empty(&tsi->tsi_free_rpcs)) {
918 /* pick request from buffer */
919 rpc = list_entry(tsi->tsi_free_rpcs.next,
920 struct srpc_client_rpc, crpc_list);
921 LASSERT(nblk == rpc->crpc_bulk.bk_niov);
922 list_del_init(&rpc->crpc_list);
925 spin_unlock(&tsi->tsi_lock);
928 rpc = srpc_create_client_rpc(peer, tsi->tsi_service, nblk,
929 blklen, sfw_test_rpc_done,
930 sfw_test_rpc_fini, tsu);
932 srpc_init_client_rpc(rpc, peer, tsi->tsi_service, nblk,
933 blklen, sfw_test_rpc_done,
934 sfw_test_rpc_fini, tsu);
938 CERROR("Can't create rpc for test %d\n", tsi->tsi_service);
942 rpc->crpc_reqstmsg.msg_ses_feats = features;
949 sfw_run_test(struct swi_workitem *wi)
951 struct sfw_test_unit *tsu = container_of(wi, struct sfw_test_unit, tsu_worker);
952 struct sfw_test_instance *tsi = tsu->tsu_instance;
953 struct srpc_client_rpc *rpc = NULL;
955 LASSERT (wi == &tsu->tsu_worker);
957 if (tsi->tsi_ops->tso_prep_rpc(tsu, tsu->tsu_dest, &rpc) != 0) {
958 LASSERT (rpc == NULL);
962 LASSERT (rpc != NULL);
964 spin_lock(&tsi->tsi_lock);
966 if (tsi->tsi_stopping) {
967 list_add(&rpc->crpc_list, &tsi->tsi_free_rpcs);
968 spin_unlock(&tsi->tsi_lock);
972 if (tsu->tsu_loop > 0)
975 list_add_tail(&rpc->crpc_list, &tsi->tsi_active_rpcs);
976 spin_unlock(&tsi->tsi_lock);
978 spin_lock(&rpc->crpc_lock);
979 rpc->crpc_timeout = rpc_timeout;
981 spin_unlock(&rpc->crpc_lock);
986 * No one can schedule me now since:
987 * - previous RPC, if any, has done and
988 * - no new RPC is initiated.
989 * - my batch is still active; no one can run it again now.
990 * Cancel pending schedules and prevent future schedule attempts:
992 swi_exit_workitem(wi);
993 sfw_test_unit_done(tsu);
998 sfw_run_batch(struct sfw_batch *tsb)
1000 struct swi_workitem *wi;
1001 struct sfw_test_unit *tsu;
1002 struct sfw_test_instance *tsi;
1004 if (sfw_batch_active(tsb)) {
1005 CDEBUG(D_NET, "Batch already active: %llu (%d)\n",
1006 tsb->bat_id.bat_id, atomic_read(&tsb->bat_nactive));
1010 list_for_each_entry(tsi, &tsb->bat_tests, tsi_list) {
1011 if (!tsi->tsi_is_client) /* skip server instances */
1014 LASSERT(!tsi->tsi_stopping);
1015 LASSERT(!sfw_test_active(tsi));
1017 atomic_inc(&tsb->bat_nactive);
1019 list_for_each_entry(tsu, &tsi->tsi_units, tsu_list) {
1020 atomic_inc(&tsi->tsi_nactive);
1021 tsu->tsu_loop = tsi->tsi_loop;
1022 wi = &tsu->tsu_worker;
1023 swi_init_workitem(wi, sfw_run_test,
1024 lst_sched_test[lnet_cpt_of_nid(tsu->tsu_dest.nid, NULL)]);
1025 swi_schedule_workitem(wi);
1033 sfw_stop_batch(struct sfw_batch *tsb, int force)
1035 struct sfw_test_instance *tsi;
1036 struct srpc_client_rpc *rpc;
1038 if (!sfw_batch_active(tsb)) {
1039 CDEBUG(D_NET, "Batch %llu inactive\n", tsb->bat_id.bat_id);
1043 list_for_each_entry(tsi, &tsb->bat_tests, tsi_list) {
1044 spin_lock(&tsi->tsi_lock);
1046 if (!tsi->tsi_is_client ||
1047 !sfw_test_active(tsi) || tsi->tsi_stopping) {
1048 spin_unlock(&tsi->tsi_lock);
1052 tsi->tsi_stopping = 1;
1055 spin_unlock(&tsi->tsi_lock);
1059 /* abort launched rpcs in the test */
1060 list_for_each_entry(rpc, &tsi->tsi_active_rpcs, crpc_list) {
1061 spin_lock(&rpc->crpc_lock);
1063 srpc_abort_rpc(rpc, -EINTR);
1065 spin_unlock(&rpc->crpc_lock);
1068 spin_unlock(&tsi->tsi_lock);
1075 sfw_query_batch(struct sfw_batch *tsb, int testidx,
1076 struct srpc_batch_reply *reply)
1078 struct sfw_test_instance *tsi;
1084 reply->bar_active = atomic_read(&tsb->bat_nactive);
1088 list_for_each_entry(tsi, &tsb->bat_tests, tsi_list) {
1092 reply->bar_active = atomic_read(&tsi->tsi_nactive);
1100 sfw_free_pages(struct srpc_server_rpc *rpc)
1102 srpc_free_bulk(rpc->srpc_bulk);
1103 rpc->srpc_bulk = NULL;
1107 sfw_alloc_pages(struct srpc_server_rpc *rpc, int cpt, int npages, int len,
1110 LASSERT(rpc->srpc_bulk == NULL);
1111 LASSERT(npages > 0 && npages <= LNET_MAX_IOV);
1113 rpc->srpc_bulk = srpc_alloc_bulk(cpt, 0, npages, len, sink);
1114 if (rpc->srpc_bulk == NULL)
1121 sfw_add_test(struct srpc_server_rpc *rpc)
1123 struct sfw_session *sn = sfw_data.fw_session;
1124 struct srpc_test_reply *reply = &rpc->srpc_replymsg.msg_body.tes_reply;
1125 struct srpc_test_reqst *request;
1127 struct sfw_batch *bat;
1129 request = &rpc->srpc_reqstbuf->buf_msg.msg_body.tes_reqst;
1130 reply->tsr_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
1132 if (request->tsr_loop == 0 ||
1133 request->tsr_concur == 0 ||
1134 request->tsr_sid.ses_nid == LNET_NID_ANY ||
1135 request->tsr_ndest > SFW_MAX_NDESTS ||
1136 (request->tsr_is_client && request->tsr_ndest == 0) ||
1137 request->tsr_concur > SFW_MAX_CONCUR ||
1138 request->tsr_service > SRPC_SERVICE_MAX_ID ||
1139 request->tsr_service <= SRPC_FRAMEWORK_SERVICE_MAX_ID) {
1140 reply->tsr_status = EINVAL;
1144 if (sn == NULL || !sfw_sid_equal(request->tsr_sid, sn->sn_id) ||
1145 sfw_find_test_case(request->tsr_service) == NULL) {
1146 reply->tsr_status = ENOENT;
1150 bat = sfw_bid2batch(request->tsr_bid);
1152 CERROR("dropping RPC %s from %s under memory pressure\n",
1153 rpc->srpc_scd->scd_svc->sv_name,
1154 libcfs_id2str(rpc->srpc_peer));
1158 if (sfw_batch_active(bat)) {
1159 reply->tsr_status = EBUSY;
1163 if (request->tsr_is_client && rpc->srpc_bulk == NULL) {
1164 /* rpc will be resumed later in sfw_bulk_ready */
1165 int npg = sfw_id_pages(request->tsr_ndest);
1168 if ((sn->sn_features & LST_FEAT_BULK_LEN) == 0) {
1169 len = npg * PAGE_SIZE;
1172 len = sizeof(struct lnet_process_id_packed) *
1176 return sfw_alloc_pages(rpc, CFS_CPT_ANY, npg, len, 1);
1179 rc = sfw_add_test_instance(bat, rpc);
1180 CDEBUG (rc == 0 ? D_NET : D_WARNING,
1181 "%s test: sv %d %s, loop %d, concur %d, ndest %d\n",
1182 rc == 0 ? "Added" : "Failed to add", request->tsr_service,
1183 request->tsr_is_client ? "client" : "server",
1184 request->tsr_loop, request->tsr_concur, request->tsr_ndest);
1186 reply->tsr_status = (rc < 0) ? -rc : rc;
1191 sfw_control_batch(struct srpc_batch_reqst *request,
1192 struct srpc_batch_reply *reply)
1194 struct sfw_session *sn = sfw_data.fw_session;
1196 struct sfw_batch *bat;
1198 reply->bar_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
1200 if (sn == NULL || !sfw_sid_equal(request->bar_sid, sn->sn_id)) {
1201 reply->bar_status = ESRCH;
1205 bat = sfw_find_batch(request->bar_bid);
1207 reply->bar_status = ENOENT;
1211 switch (request->bar_opc) {
1212 case SRPC_BATCH_OPC_RUN:
1213 rc = sfw_run_batch(bat);
1216 case SRPC_BATCH_OPC_STOP:
1217 rc = sfw_stop_batch(bat, request->bar_arg);
1220 case SRPC_BATCH_OPC_QUERY:
1221 rc = sfw_query_batch(bat, request->bar_testidx, reply);
1225 return -EINVAL; /* drop it */
1228 reply->bar_status = (rc < 0) ? -rc : rc;
1233 sfw_handle_server_rpc(struct srpc_server_rpc *rpc)
1235 struct srpc_service *sv = rpc->srpc_scd->scd_svc;
1236 struct srpc_msg *reply = &rpc->srpc_replymsg;
1237 struct srpc_msg *request = &rpc->srpc_reqstbuf->buf_msg;
1238 unsigned features = LST_FEATS_MASK;
1241 LASSERT(sfw_data.fw_active_srpc == NULL);
1242 LASSERT(sv->sv_id <= SRPC_FRAMEWORK_SERVICE_MAX_ID);
1244 spin_lock(&sfw_data.fw_lock);
1246 if (sfw_data.fw_shuttingdown) {
1247 spin_unlock(&sfw_data.fw_lock);
1251 /* Remove timer to avoid racing with it or expiring active session */
1252 if (sfw_del_session_timer() != 0) {
1253 CERROR("dropping RPC %s from %s: racing with expiry timer\n",
1254 sv->sv_name, libcfs_id2str(rpc->srpc_peer));
1255 spin_unlock(&sfw_data.fw_lock);
1259 sfw_data.fw_active_srpc = rpc;
1260 spin_unlock(&sfw_data.fw_lock);
1262 sfw_unpack_message(request);
1263 LASSERT(request->msg_type == srpc_service2request(sv->sv_id));
1265 /* rpc module should have checked this */
1266 LASSERT(request->msg_version == SRPC_MSG_VERSION);
1268 if (sv->sv_id != SRPC_SERVICE_MAKE_SESSION &&
1269 sv->sv_id != SRPC_SERVICE_DEBUG) {
1270 struct sfw_session *sn = sfw_data.fw_session;
1273 sn->sn_features != request->msg_ses_feats) {
1274 CNETERR("Features of framework RPC don't match "
1275 "features of current session: %x/%x\n",
1276 request->msg_ses_feats, sn->sn_features);
1277 reply->msg_body.reply.status = EPROTO;
1278 reply->msg_body.reply.sid = sn->sn_id;
1282 } else if ((request->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
1283 /* NB: at this point, old version will ignore features and
1284 * create new session anyway, so console should be able
1286 reply->msg_body.reply.status = EPROTO;
1293 case SRPC_SERVICE_TEST:
1294 rc = sfw_add_test(rpc);
1297 case SRPC_SERVICE_BATCH:
1298 rc = sfw_control_batch(&request->msg_body.bat_reqst,
1299 &reply->msg_body.bat_reply);
1302 case SRPC_SERVICE_QUERY_STAT:
1303 rc = sfw_get_stats(&request->msg_body.stat_reqst,
1304 &reply->msg_body.stat_reply);
1307 case SRPC_SERVICE_DEBUG:
1308 rc = sfw_debug_session(&request->msg_body.dbg_reqst,
1309 &reply->msg_body.dbg_reply);
1312 case SRPC_SERVICE_MAKE_SESSION:
1313 rc = sfw_make_session(&request->msg_body.mksn_reqst,
1314 &reply->msg_body.mksn_reply);
1317 case SRPC_SERVICE_REMOVE_SESSION:
1318 rc = sfw_remove_session(&request->msg_body.rmsn_reqst,
1319 &reply->msg_body.rmsn_reply);
1323 if (sfw_data.fw_session != NULL)
1324 features = sfw_data.fw_session->sn_features;
1326 reply->msg_ses_feats = features;
1327 rpc->srpc_done = sfw_server_rpc_done;
1328 spin_lock(&sfw_data.fw_lock);
1330 if (!sfw_data.fw_shuttingdown)
1331 sfw_add_session_timer();
1333 sfw_data.fw_active_srpc = NULL;
1334 spin_unlock(&sfw_data.fw_lock);
1339 sfw_bulk_ready(struct srpc_server_rpc *rpc, int status)
1341 struct srpc_service *sv = rpc->srpc_scd->scd_svc;
1344 LASSERT(rpc->srpc_bulk != NULL);
1345 LASSERT(sv->sv_id == SRPC_SERVICE_TEST);
1346 LASSERT(sfw_data.fw_active_srpc == NULL);
1347 LASSERT(rpc->srpc_reqstbuf->buf_msg.msg_body.tes_reqst.tsr_is_client);
1349 spin_lock(&sfw_data.fw_lock);
1352 CERROR("Bulk transfer failed for RPC: "
1353 "service %s, peer %s, status %d\n",
1354 sv->sv_name, libcfs_id2str(rpc->srpc_peer), status);
1355 spin_unlock(&sfw_data.fw_lock);
1359 if (sfw_data.fw_shuttingdown) {
1360 spin_unlock(&sfw_data.fw_lock);
1364 if (sfw_del_session_timer() != 0) {
1365 CERROR("dropping RPC %s from %s: racing with expiry timer\n",
1366 sv->sv_name, libcfs_id2str(rpc->srpc_peer));
1367 spin_unlock(&sfw_data.fw_lock);
1371 sfw_data.fw_active_srpc = rpc;
1372 spin_unlock(&sfw_data.fw_lock);
1374 rc = sfw_add_test(rpc);
1376 spin_lock(&sfw_data.fw_lock);
1378 if (!sfw_data.fw_shuttingdown)
1379 sfw_add_session_timer();
1381 sfw_data.fw_active_srpc = NULL;
1382 spin_unlock(&sfw_data.fw_lock);
1386 struct srpc_client_rpc *
1387 sfw_create_rpc(struct lnet_process_id peer, int service,
1388 unsigned features, int nbulkiov, int bulklen,
1389 void (*done)(struct srpc_client_rpc *), void *priv)
1391 struct srpc_client_rpc *rpc = NULL;
1393 spin_lock(&sfw_data.fw_lock);
1395 LASSERT (!sfw_data.fw_shuttingdown);
1396 LASSERT (service <= SRPC_FRAMEWORK_SERVICE_MAX_ID);
1398 if (nbulkiov == 0 && !list_empty(&sfw_data.fw_zombie_rpcs)) {
1399 rpc = list_entry(sfw_data.fw_zombie_rpcs.next,
1400 struct srpc_client_rpc, crpc_list);
1401 list_del(&rpc->crpc_list);
1403 srpc_init_client_rpc(rpc, peer, service, 0, 0,
1404 done, sfw_client_rpc_fini, priv);
1407 spin_unlock(&sfw_data.fw_lock);
1410 rpc = srpc_create_client_rpc(peer, service,
1411 nbulkiov, bulklen, done,
1412 nbulkiov != 0 ? NULL :
1413 sfw_client_rpc_fini,
1417 if (rpc != NULL) /* "session" is concept in framework */
1418 rpc->crpc_reqstmsg.msg_ses_feats = features;
1424 sfw_unpack_message(struct srpc_msg *msg)
1426 if (msg->msg_magic == SRPC_MSG_MAGIC)
1427 return; /* no flipping needed */
1429 /* srpc module should guarantee I wouldn't get crap */
1430 LASSERT (msg->msg_magic == __swab32(SRPC_MSG_MAGIC));
1432 if (msg->msg_type == SRPC_MSG_STAT_REQST) {
1433 struct srpc_stat_reqst *req = &msg->msg_body.stat_reqst;
1435 __swab32s(&req->str_type);
1436 __swab64s(&req->str_rpyid);
1437 sfw_unpack_sid(req->str_sid);
1441 if (msg->msg_type == SRPC_MSG_STAT_REPLY) {
1442 struct srpc_stat_reply *rep = &msg->msg_body.stat_reply;
1444 __swab32s(&rep->str_status);
1445 sfw_unpack_sid(rep->str_sid);
1446 sfw_unpack_fw_counters(rep->str_fw);
1447 sfw_unpack_rpc_counters(rep->str_rpc);
1448 sfw_unpack_lnet_counters(rep->str_lnet);
1452 if (msg->msg_type == SRPC_MSG_MKSN_REQST) {
1453 struct srpc_mksn_reqst *req = &msg->msg_body.mksn_reqst;
1455 __swab64s(&req->mksn_rpyid);
1456 __swab32s(&req->mksn_force);
1457 sfw_unpack_sid(req->mksn_sid);
1461 if (msg->msg_type == SRPC_MSG_MKSN_REPLY) {
1462 struct srpc_mksn_reply *rep = &msg->msg_body.mksn_reply;
1464 __swab32s(&rep->mksn_status);
1465 __swab32s(&rep->mksn_timeout);
1466 sfw_unpack_sid(rep->mksn_sid);
1470 if (msg->msg_type == SRPC_MSG_RMSN_REQST) {
1471 struct srpc_rmsn_reqst *req = &msg->msg_body.rmsn_reqst;
1473 __swab64s(&req->rmsn_rpyid);
1474 sfw_unpack_sid(req->rmsn_sid);
1478 if (msg->msg_type == SRPC_MSG_RMSN_REPLY) {
1479 struct srpc_rmsn_reply *rep = &msg->msg_body.rmsn_reply;
1481 __swab32s(&rep->rmsn_status);
1482 sfw_unpack_sid(rep->rmsn_sid);
1486 if (msg->msg_type == SRPC_MSG_DEBUG_REQST) {
1487 struct srpc_debug_reqst *req = &msg->msg_body.dbg_reqst;
1489 __swab64s(&req->dbg_rpyid);
1490 __swab32s(&req->dbg_flags);
1491 sfw_unpack_sid(req->dbg_sid);
1495 if (msg->msg_type == SRPC_MSG_DEBUG_REPLY) {
1496 struct srpc_debug_reply *rep = &msg->msg_body.dbg_reply;
1498 __swab32s(&rep->dbg_nbatch);
1499 __swab32s(&rep->dbg_timeout);
1500 sfw_unpack_sid(rep->dbg_sid);
1504 if (msg->msg_type == SRPC_MSG_BATCH_REQST) {
1505 struct srpc_batch_reqst *req = &msg->msg_body.bat_reqst;
1507 __swab32s(&req->bar_opc);
1508 __swab64s(&req->bar_rpyid);
1509 __swab32s(&req->bar_testidx);
1510 __swab32s(&req->bar_arg);
1511 sfw_unpack_sid(req->bar_sid);
1512 __swab64s(&req->bar_bid.bat_id);
1516 if (msg->msg_type == SRPC_MSG_BATCH_REPLY) {
1517 struct srpc_batch_reply *rep = &msg->msg_body.bat_reply;
1519 __swab32s(&rep->bar_status);
1520 sfw_unpack_sid(rep->bar_sid);
1524 if (msg->msg_type == SRPC_MSG_TEST_REQST) {
1525 struct srpc_test_reqst *req = &msg->msg_body.tes_reqst;
1527 __swab64s(&req->tsr_rpyid);
1528 __swab64s(&req->tsr_bulkid);
1529 __swab32s(&req->tsr_loop);
1530 __swab32s(&req->tsr_ndest);
1531 __swab32s(&req->tsr_concur);
1532 __swab32s(&req->tsr_service);
1533 sfw_unpack_sid(req->tsr_sid);
1534 __swab64s(&req->tsr_bid.bat_id);
1538 if (msg->msg_type == SRPC_MSG_TEST_REPLY) {
1539 struct srpc_test_reply *rep = &msg->msg_body.tes_reply;
1541 __swab32s(&rep->tsr_status);
1542 sfw_unpack_sid(rep->tsr_sid);
1546 if (msg->msg_type == SRPC_MSG_JOIN_REQST) {
1547 struct srpc_join_reqst *req = &msg->msg_body.join_reqst;
1549 __swab64s(&req->join_rpyid);
1550 sfw_unpack_sid(req->join_sid);
1554 if (msg->msg_type == SRPC_MSG_JOIN_REPLY) {
1555 struct srpc_join_reply *rep = &msg->msg_body.join_reply;
1557 __swab32s(&rep->join_status);
1558 __swab32s(&rep->join_timeout);
1559 sfw_unpack_sid(rep->join_sid);
1567 sfw_abort_rpc(struct srpc_client_rpc *rpc)
1569 LASSERT(atomic_read(&rpc->crpc_refcount) > 0);
1570 LASSERT(rpc->crpc_service <= SRPC_FRAMEWORK_SERVICE_MAX_ID);
1572 spin_lock(&rpc->crpc_lock);
1573 srpc_abort_rpc(rpc, -EINTR);
1574 spin_unlock(&rpc->crpc_lock);
1578 sfw_post_rpc(struct srpc_client_rpc *rpc)
1580 spin_lock(&rpc->crpc_lock);
1582 LASSERT(!rpc->crpc_closed);
1583 LASSERT(!rpc->crpc_aborted);
1584 LASSERT(list_empty(&rpc->crpc_list));
1585 LASSERT(!sfw_data.fw_shuttingdown);
1587 rpc->crpc_timeout = rpc_timeout;
1590 spin_unlock(&rpc->crpc_lock);
1593 static struct srpc_service sfw_services[] = {
1594 { .sv_id = SRPC_SERVICE_DEBUG, .sv_name = "debug", },
1595 { .sv_id = SRPC_SERVICE_QUERY_STAT, .sv_name = "query stats", },
1596 { .sv_id = SRPC_SERVICE_MAKE_SESSION, .sv_name = "make session", },
1597 { .sv_id = SRPC_SERVICE_REMOVE_SESSION, .sv_name = "remove session", },
1598 { .sv_id = SRPC_SERVICE_BATCH, .sv_name = "batch service", },
1599 { .sv_id = SRPC_SERVICE_TEST, .sv_name = "test service", },
1608 struct srpc_service *sv;
1609 struct sfw_test_case *tsc;
1612 if (session_timeout < 0) {
1613 CERROR ("Session timeout must be non-negative: %d\n",
1618 if (rpc_timeout < 0) {
1619 CERROR ("RPC timeout must be non-negative: %d\n",
1624 if (session_timeout == 0)
1625 CWARN ("Zero session_timeout specified "
1626 "- test sessions never expire.\n");
1628 if (rpc_timeout == 0)
1629 CWARN ("Zero rpc_timeout specified "
1630 "- test RPC never expire.\n");
1632 memset(&sfw_data, 0, sizeof(struct smoketest_framework));
1634 sfw_data.fw_session = NULL;
1635 sfw_data.fw_active_srpc = NULL;
1636 spin_lock_init(&sfw_data.fw_lock);
1637 atomic_set(&sfw_data.fw_nzombies, 0);
1638 INIT_LIST_HEAD(&sfw_data.fw_tests);
1639 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
1640 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
1642 brw_init_test_client();
1643 brw_init_test_service();
1644 rc = sfw_register_test(&brw_test_service, &brw_test_client);
1647 ping_init_test_client();
1648 ping_init_test_service();
1649 rc = sfw_register_test(&ping_test_service, &ping_test_client);
1653 list_for_each_entry(tsc, &sfw_data.fw_tests, tsc_list) {
1654 sv = tsc->tsc_srv_service;
1656 rc = srpc_add_service(sv);
1657 LASSERT(rc != -EBUSY);
1659 CWARN("Failed to add %s service: %d\n",
1665 for (i = 0; ; i++) {
1666 sv = &sfw_services[i];
1667 if (sv->sv_name == NULL) break;
1669 sv->sv_bulk_ready = NULL;
1670 sv->sv_handler = sfw_handle_server_rpc;
1671 sv->sv_wi_total = SFW_FRWK_WI_MAX;
1672 if (sv->sv_id == SRPC_SERVICE_TEST)
1673 sv->sv_bulk_ready = sfw_bulk_ready;
1675 rc = srpc_add_service(sv);
1676 LASSERT (rc != -EBUSY);
1678 CWARN ("Failed to add %s service: %d\n",
1683 /* about to sfw_shutdown, no need to add buffer */
1684 if (error) continue;
1686 rc = srpc_service_add_buffers(sv, sv->sv_wi_total);
1688 CWARN("Failed to reserve enough buffers: "
1689 "service %s, %d needed: %d\n",
1690 sv->sv_name, sv->sv_wi_total, rc);
1703 struct srpc_service *sv;
1704 struct sfw_test_case *tsc;
1707 spin_lock(&sfw_data.fw_lock);
1709 sfw_data.fw_shuttingdown = 1;
1710 lst_wait_until(sfw_data.fw_active_srpc == NULL, sfw_data.fw_lock,
1711 "waiting for active RPC to finish.\n");
1713 if (sfw_del_session_timer() != 0)
1714 lst_wait_until(sfw_data.fw_session == NULL, sfw_data.fw_lock,
1715 "waiting for session timer to explode.\n");
1717 sfw_deactivate_session();
1718 lst_wait_until(atomic_read(&sfw_data.fw_nzombies) == 0,
1720 "waiting for %d zombie sessions to die.\n",
1721 atomic_read(&sfw_data.fw_nzombies));
1723 spin_unlock(&sfw_data.fw_lock);
1725 for (i = 0; ; i++) {
1726 sv = &sfw_services[i];
1727 if (sv->sv_name == NULL)
1730 srpc_shutdown_service(sv);
1731 srpc_remove_service(sv);
1734 list_for_each_entry(tsc, &sfw_data.fw_tests, tsc_list) {
1735 sv = tsc->tsc_srv_service;
1736 srpc_shutdown_service(sv);
1737 srpc_remove_service(sv);
1740 while (!list_empty(&sfw_data.fw_zombie_rpcs)) {
1741 struct srpc_client_rpc *rpc;
1743 rpc = list_entry(sfw_data.fw_zombie_rpcs.next,
1744 struct srpc_client_rpc, crpc_list);
1745 list_del(&rpc->crpc_list);
1747 LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
1750 for (i = 0; ; i++) {
1751 sv = &sfw_services[i];
1752 if (sv->sv_name == NULL)
1755 srpc_wait_service_shutdown(sv);
1758 while (!list_empty(&sfw_data.fw_tests)) {
1759 tsc = list_entry(sfw_data.fw_tests.next,
1760 struct sfw_test_case, tsc_list);
1762 srpc_wait_service_shutdown(tsc->tsc_srv_service);
1764 list_del(&tsc->tsc_list);
1765 LIBCFS_FREE(tsc, sizeof(*tsc));