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) 2011, 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/conctl.c
34 * Console framework rpcs
36 * Author: Liang Zhen <liang@whamcloud.com>
40 #include <libcfs/libcfs.h>
41 #include <lnet/lib-lnet.h>
46 void lstcon_rpc_stat_reply(struct lstcon_rpc_trans *, struct srpc_msg *,
47 struct lstcon_node *, struct lstcon_trans_stat *);
50 lstcon_rpc_done(struct srpc_client_rpc *rpc)
52 struct lstcon_rpc *crpc = rpc->crpc_priv;
54 LASSERT(crpc != NULL && rpc == crpc->crp_rpc);
55 LASSERT(crpc->crp_posted && !crpc->crp_finished);
57 spin_lock(&rpc->crpc_lock);
59 if (crpc->crp_trans == NULL) {
60 /* Orphan RPC is not in any transaction,
61 * I'm just a poor body and nobody loves me */
62 spin_unlock(&rpc->crpc_lock);
69 /* not an orphan RPC */
70 crpc->crp_finished = 1;
72 if (crpc->crp_stamp == 0) {
74 LASSERT (crpc->crp_status == 0);
76 crpc->crp_stamp = cfs_time_current();
77 crpc->crp_status = rpc->crpc_status;
80 /* wakeup (transaction)thread if I'm the last RPC in the transaction */
81 if (atomic_dec_and_test(&crpc->crp_trans->tas_remaining))
82 wake_up(&crpc->crp_trans->tas_waitq);
84 spin_unlock(&rpc->crpc_lock);
88 lstcon_rpc_init(struct lstcon_node *nd, int service, unsigned int feats,
89 int bulk_npg, int bulk_len, int embedded,
90 struct lstcon_rpc *crpc)
92 crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
93 feats, bulk_npg, bulk_len,
94 lstcon_rpc_done, (void *)crpc);
95 if (crpc->crp_rpc == NULL)
98 crpc->crp_trans = NULL;
100 crpc->crp_posted = 0;
101 crpc->crp_finished = 0;
102 crpc->crp_unpacked = 0;
103 crpc->crp_status = 0;
105 crpc->crp_embedded = embedded;
106 INIT_LIST_HEAD(&crpc->crp_link);
108 atomic_inc(&console_session.ses_rpc_counter);
114 lstcon_rpc_prep(struct lstcon_node *nd, int service, unsigned int feats,
115 int bulk_npg, int bulk_len, struct lstcon_rpc **crpcpp)
117 struct lstcon_rpc *crpc = NULL;
120 spin_lock(&console_session.ses_rpc_lock);
122 if (!list_empty(&console_session.ses_rpc_freelist)) {
123 crpc = list_entry(console_session.ses_rpc_freelist.next,
124 struct lstcon_rpc, crp_link);
125 list_del_init(&crpc->crp_link);
128 spin_unlock(&console_session.ses_rpc_lock);
131 LIBCFS_ALLOC(crpc, sizeof(*crpc));
136 rc = lstcon_rpc_init(nd, service, feats, bulk_npg, bulk_len, 0, crpc);
142 LIBCFS_FREE(crpc, sizeof(*crpc));
148 lstcon_rpc_put(struct lstcon_rpc *crpc)
150 struct srpc_bulk *bulk = &crpc->crp_rpc->crpc_bulk;
153 LASSERT(list_empty(&crpc->crp_link));
155 for (i = 0; i < bulk->bk_niov; i++) {
156 if (bulk->bk_iovs[i].kiov_page == NULL)
159 __free_page(bulk->bk_iovs[i].kiov_page);
162 srpc_client_rpc_decref(crpc->crp_rpc);
164 if (crpc->crp_embedded) {
165 /* embedded RPC, don't recycle it */
166 memset(crpc, 0, sizeof(*crpc));
167 crpc->crp_embedded = 1;
170 spin_lock(&console_session.ses_rpc_lock);
172 list_add(&crpc->crp_link,
173 &console_session.ses_rpc_freelist);
175 spin_unlock(&console_session.ses_rpc_lock);
178 /* RPC is not alive now */
179 atomic_dec(&console_session.ses_rpc_counter);
183 lstcon_rpc_post(struct lstcon_rpc *crpc)
185 struct lstcon_rpc_trans *trans = crpc->crp_trans;
187 LASSERT (trans != NULL);
189 atomic_inc(&trans->tas_remaining);
190 crpc->crp_posted = 1;
192 sfw_post_rpc(crpc->crp_rpc);
196 lstcon_rpc_trans_name(int transop)
198 if (transop == LST_TRANS_SESNEW)
201 if (transop == LST_TRANS_SESEND)
204 if (transop == LST_TRANS_SESQRY)
207 if (transop == LST_TRANS_SESPING)
210 if (transop == LST_TRANS_TSBCLIADD)
213 if (transop == LST_TRANS_TSBSRVADD)
216 if (transop == LST_TRANS_TSBRUN)
219 if (transop == LST_TRANS_TSBSTOP)
222 if (transop == LST_TRANS_TSBCLIQRY)
225 if (transop == LST_TRANS_TSBSRVQRY)
228 if (transop == LST_TRANS_STATQRY)
235 lstcon_rpc_trans_prep(struct list_head *translist, int transop,
236 struct lstcon_rpc_trans **transpp)
238 struct lstcon_rpc_trans *trans;
240 if (translist != NULL) {
241 list_for_each_entry(trans, translist, tas_link) {
242 /* Can't enqueue two private transaction on
244 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
249 /* create a trans group */
250 LIBCFS_ALLOC(trans, sizeof(*trans));
254 trans->tas_opc = transop;
256 if (translist == NULL)
257 INIT_LIST_HEAD(&trans->tas_olink);
259 list_add_tail(&trans->tas_olink, translist);
261 list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
263 INIT_LIST_HEAD(&trans->tas_rpcs_list);
264 atomic_set(&trans->tas_remaining, 0);
265 init_waitqueue_head(&trans->tas_waitq);
267 spin_lock(&console_session.ses_rpc_lock);
268 trans->tas_features = console_session.ses_features;
269 spin_unlock(&console_session.ses_rpc_lock);
276 lstcon_rpc_trans_addreq(struct lstcon_rpc_trans *trans, struct lstcon_rpc *crpc)
278 list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
279 crpc->crp_trans = trans;
283 lstcon_rpc_trans_abort(struct lstcon_rpc_trans *trans, int error)
285 struct srpc_client_rpc *rpc;
286 struct lstcon_rpc *crpc;
287 struct lstcon_node *nd;
289 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
292 spin_lock(&rpc->crpc_lock);
294 if (!crpc->crp_posted || /* not posted */
295 crpc->crp_stamp != 0) { /* rpc done or aborted already */
296 if (crpc->crp_stamp == 0) {
297 crpc->crp_stamp = cfs_time_current();
298 crpc->crp_status = -EINTR;
300 spin_unlock(&rpc->crpc_lock);
304 crpc->crp_stamp = cfs_time_current();
305 crpc->crp_status = error;
307 spin_unlock(&rpc->crpc_lock);
311 if (error != -ETIMEDOUT)
315 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
318 nd->nd_stamp = crpc->crp_stamp;
319 nd->nd_state = LST_NODE_DOWN;
324 lstcon_rpc_trans_check(struct lstcon_rpc_trans *trans)
326 if (console_session.ses_shutdown &&
327 !list_empty(&trans->tas_olink)) /* Not an end session RPC */
330 return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
334 lstcon_rpc_trans_postwait(struct lstcon_rpc_trans *trans, int timeout)
336 struct lstcon_rpc *crpc;
339 if (list_empty(&trans->tas_rpcs_list))
342 if (timeout < LST_TRANS_MIN_TIMEOUT)
343 timeout = LST_TRANS_MIN_TIMEOUT;
345 CDEBUG(D_NET, "Transaction %s started\n",
346 lstcon_rpc_trans_name(trans->tas_opc));
348 /* post all requests */
349 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
350 LASSERT(!crpc->crp_posted);
352 lstcon_rpc_post(crpc);
355 mutex_unlock(&console_session.ses_mutex);
357 rc = wait_event_interruptible_timeout(trans->tas_waitq,
358 lstcon_rpc_trans_check(trans),
359 cfs_time_seconds(timeout));
361 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
363 mutex_lock(&console_session.ses_mutex);
365 if (console_session.ses_shutdown)
368 if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
369 /* treat short timeout as canceled */
370 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
373 lstcon_rpc_trans_abort(trans, rc);
376 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
377 lstcon_rpc_trans_name(trans->tas_opc), rc);
379 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
385 lstcon_rpc_get_reply(struct lstcon_rpc *crpc, struct srpc_msg **msgpp)
387 struct lstcon_node *nd = crpc->crp_node;
388 struct srpc_client_rpc *rpc = crpc->crp_rpc;
389 struct srpc_generic_reply *rep;
391 LASSERT (nd != NULL && rpc != NULL);
392 LASSERT (crpc->crp_stamp != 0);
394 if (crpc->crp_status != 0) {
396 return crpc->crp_status;
399 *msgpp = &rpc->crpc_replymsg;
400 if (!crpc->crp_unpacked) {
401 sfw_unpack_message(*msgpp);
402 crpc->crp_unpacked = 1;
405 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
408 nd->nd_stamp = crpc->crp_stamp;
409 rep = &(*msgpp)->msg_body.reply;
411 if (rep->sid.ses_nid == LNET_NID_ANY)
412 nd->nd_state = LST_NODE_UNKNOWN;
413 else if (lstcon_session_match(rep->sid))
414 nd->nd_state = LST_NODE_ACTIVE;
416 nd->nd_state = LST_NODE_BUSY;
422 lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans,
423 struct lstcon_trans_stat *stat)
425 struct lstcon_rpc *crpc;
426 struct srpc_msg *rep;
429 LASSERT(stat != NULL);
431 memset(stat, 0, sizeof(*stat));
433 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
434 lstcon_rpc_stat_total(stat, 1);
436 LASSERT(crpc->crp_stamp != 0);
438 error = lstcon_rpc_get_reply(crpc, &rep);
440 lstcon_rpc_stat_failure(stat, 1);
441 if (stat->trs_rpc_errno == 0)
442 stat->trs_rpc_errno = -error;
447 lstcon_rpc_stat_success(stat, 1);
449 lstcon_rpc_stat_reply(trans, rep, crpc->crp_node, stat);
452 if (trans->tas_opc == LST_TRANS_SESNEW && stat->trs_fwk_errno == 0) {
453 stat->trs_fwk_errno =
454 lstcon_session_feats_check(trans->tas_features);
457 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
458 "RPC error(%d), Framework error(%d)\n",
459 lstcon_rpc_trans_name(trans->tas_opc),
460 lstcon_rpc_stat_success(stat, 0),
461 lstcon_rpc_stat_failure(stat, 0),
462 lstcon_rpc_stat_total(stat, 0),
463 stat->trs_rpc_errno, stat->trs_fwk_errno);
469 lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
470 struct list_head __user *head_up,
471 lstcon_rpc_readent_func_t readent)
473 struct list_head tmp;
474 struct list_head __user *next;
475 struct lstcon_rpc_ent *ent;
476 struct srpc_generic_reply *rep;
477 struct lstcon_rpc *crpc;
478 struct srpc_msg *msg;
479 struct lstcon_node *nd;
484 LASSERT(head_up != NULL);
488 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
489 if (copy_from_user(&tmp, next,
490 sizeof(struct list_head)))
493 if (tmp.next == head_up)
498 ent = list_entry(next, struct lstcon_rpc_ent, rpe_link);
500 LASSERT(crpc->crp_stamp != 0);
502 error = lstcon_rpc_get_reply(crpc, &msg);
506 dur = (cfs_duration_t)cfs_time_sub(crpc->crp_stamp,
507 (cfs_time_t)console_session.ses_id.ses_stamp);
508 jiffies_to_timeval(dur, &tv);
510 if (copy_to_user(&ent->rpe_peer,
511 &nd->nd_id, sizeof(struct lnet_process_id)) ||
512 copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
513 copy_to_user(&ent->rpe_state,
514 &nd->nd_state, sizeof(nd->nd_state)) ||
515 copy_to_user(&ent->rpe_rpc_errno, &error,
523 rep = (struct srpc_generic_reply *)&msg->msg_body.reply;
525 if (copy_to_user(&ent->rpe_sid,
526 &rep->sid, sizeof(rep->sid)) ||
527 copy_to_user(&ent->rpe_fwk_errno,
528 &rep->status, sizeof(rep->status)))
534 error = readent(trans->tas_opc, msg, ent);
543 lstcon_rpc_trans_destroy(struct lstcon_rpc_trans *trans)
545 struct srpc_client_rpc *rpc;
546 struct lstcon_rpc *crpc;
547 struct lstcon_rpc *tmp;
550 list_for_each_entry_safe(crpc, tmp, &trans->tas_rpcs_list, crp_link) {
553 spin_lock(&rpc->crpc_lock);
555 /* free it if not posted or finished already */
556 if (!crpc->crp_posted || crpc->crp_finished) {
557 spin_unlock(&rpc->crpc_lock);
559 list_del_init(&crpc->crp_link);
560 lstcon_rpc_put(crpc);
565 /* rpcs can be still not callbacked (even LNetMDUnlink is
566 * called) because huge timeout for inaccessible network,
567 * don't make user wait for them, just abandon them, they
568 * will be recycled in callback */
570 LASSERT(crpc->crp_status != 0);
572 crpc->crp_node = NULL;
573 crpc->crp_trans = NULL;
574 list_del_init(&crpc->crp_link);
577 spin_unlock(&rpc->crpc_lock);
579 atomic_dec(&trans->tas_remaining);
582 LASSERT(atomic_read(&trans->tas_remaining) == 0);
584 list_del(&trans->tas_link);
585 if (!list_empty(&trans->tas_olink))
586 list_del(&trans->tas_olink);
588 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
589 lstcon_rpc_trans_name(trans->tas_opc), count);
591 LIBCFS_FREE(trans, sizeof(*trans));
597 lstcon_sesrpc_prep(struct lstcon_node *nd, int transop,
598 unsigned int feats, struct lstcon_rpc **crpc)
600 struct srpc_mksn_reqst *msrq;
601 struct srpc_rmsn_reqst *rsrq;
605 case LST_TRANS_SESNEW:
606 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
611 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
612 msrq->mksn_sid = console_session.ses_id;
613 msrq->mksn_force = console_session.ses_force;
614 strlcpy(msrq->mksn_name, console_session.ses_name,
615 sizeof(msrq->mksn_name));
618 case LST_TRANS_SESEND:
619 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
624 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
625 rsrq->rmsn_sid = console_session.ses_id;
636 lstcon_dbgrpc_prep(struct lstcon_node *nd, unsigned int feats,
637 struct lstcon_rpc **crpc)
639 struct srpc_debug_reqst *drq;
642 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
646 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
648 drq->dbg_sid = console_session.ses_id;
655 lstcon_batrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
656 struct lstcon_tsb_hdr *tsb, struct lstcon_rpc **crpc)
658 struct lstcon_batch *batch;
659 struct srpc_batch_reqst *brq;
662 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
666 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
668 brq->bar_sid = console_session.ses_id;
669 brq->bar_bid = tsb->tsb_id;
670 brq->bar_testidx = tsb->tsb_index;
671 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
672 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
673 SRPC_BATCH_OPC_QUERY);
675 if (transop != LST_TRANS_TSBRUN &&
676 transop != LST_TRANS_TSBSTOP)
679 LASSERT (tsb->tsb_index == 0);
681 batch = (struct lstcon_batch *)tsb;
682 brq->bar_arg = batch->bat_arg;
688 lstcon_statrpc_prep(struct lstcon_node *nd, unsigned int feats,
689 struct lstcon_rpc **crpc)
691 struct srpc_stat_reqst *srq;
694 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
698 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
700 srq->str_sid = console_session.ses_id;
701 srq->str_type = 0; /* XXX remove it */
706 static struct lnet_process_id_packed *
707 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
709 struct lnet_process_id_packed *pid;
712 i = idx / SFW_ID_PER_PAGE;
716 pid = (struct lnet_process_id_packed *)page_address(kiov[i].kiov_page);
718 return &pid[idx % SFW_ID_PER_PAGE];
722 lstcon_dstnodes_prep(struct lstcon_group *grp, int idx,
723 int dist, int span, int nkiov, lnet_kiov_t *kiov)
725 struct lnet_process_id_packed *pid;
726 struct lstcon_ndlink *ndl;
727 struct lstcon_node *nd;
734 LASSERT (grp->grp_nnode >= 1);
736 if (span > grp->grp_nnode)
739 start = ((idx / dist) * span) % grp->grp_nnode;
740 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
742 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
749 if (i > (end >= start ? end : grp->grp_nnode))
752 pid = lstcon_next_id((i - start), nkiov, kiov);
753 pid->nid = nd->nd_id.nid;
754 pid->pid = nd->nd_id.pid;
758 if (start <= end) /* done */
761 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
762 if (i > grp->grp_nnode + end)
766 pid = lstcon_next_id((i - start), nkiov, kiov);
767 pid->nid = nd->nd_id.nid;
768 pid->pid = nd->nd_id.pid;
776 lstcon_pingrpc_prep(struct lst_test_ping_param *param,
777 struct srpc_test_reqst *req)
779 struct test_ping_req *prq = &req->tsr_u.ping;
781 prq->png_size = param->png_size;
782 prq->png_flags = param->png_flags;
788 lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param,
789 struct srpc_test_reqst *req)
791 struct test_bulk_req *brq = &req->tsr_u.bulk_v0;
793 brq->blk_opc = param->blk_opc;
794 brq->blk_npg = (param->blk_size + PAGE_SIZE - 1) /
796 brq->blk_flags = param->blk_flags;
802 lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
803 struct srpc_test_reqst *req)
805 struct test_bulk_req_v1 *brq = &req->tsr_u.bulk_v1;
807 brq->blk_opc = param->blk_opc;
808 brq->blk_flags = param->blk_flags;
809 brq->blk_len = param->blk_size;
810 brq->blk_offset = is_client ? param->blk_cli_off : param->blk_srv_off;
816 lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
817 struct lstcon_test *test, struct lstcon_rpc **crpc)
819 struct lstcon_group *sgrp = test->tes_src_grp;
820 struct lstcon_group *dgrp = test->tes_dst_grp;
821 struct srpc_test_reqst *trq;
822 struct srpc_bulk *bulk;
828 if (transop == LST_TRANS_TSBCLIADD) {
829 npg = sfw_id_pages(test->tes_span);
830 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
832 sizeof(struct lnet_process_id_packed) * test->tes_span;
835 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
839 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
841 if (transop == LST_TRANS_TSBSRVADD) {
842 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
843 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
844 int nmax = (ndist + nspan - 1) / nspan;
847 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
850 bulk = &(*crpc)->crp_rpc->crpc_bulk;
852 for (i = 0; i < npg; i++) {
857 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
858 PAGE_SIZE : min_t(int, nob, PAGE_SIZE);
861 bulk->bk_iovs[i].kiov_offset = 0;
862 bulk->bk_iovs[i].kiov_len = len;
863 bulk->bk_iovs[i].kiov_page =
864 alloc_page(GFP_KERNEL);
866 if (bulk->bk_iovs[i].kiov_page == NULL) {
867 lstcon_rpc_put(*crpc);
874 LASSERT (transop == LST_TRANS_TSBCLIADD);
876 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
880 npg, &bulk->bk_iovs[0]);
882 lstcon_rpc_put(*crpc);
886 trq->tsr_ndest = test->tes_span;
887 trq->tsr_loop = test->tes_loop;
890 trq->tsr_sid = console_session.ses_id;
891 trq->tsr_bid = test->tes_hdr.tsb_id;
892 trq->tsr_concur = test->tes_concur;
893 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
894 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
896 switch (test->tes_type) {
898 trq->tsr_service = SRPC_SERVICE_PING;
899 rc = lstcon_pingrpc_prep((struct lst_test_ping_param *)
900 &test->tes_param[0], trq);
904 trq->tsr_service = SRPC_SERVICE_BRW;
905 if ((feats & LST_FEAT_BULK_LEN) == 0) {
906 rc = lstcon_bulkrpc_v0_prep((struct lst_test_bulk_param *)
907 &test->tes_param[0], trq);
909 rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
911 trq->tsr_is_client, trq);
924 lstcon_sesnew_stat_reply(struct lstcon_rpc_trans *trans,
925 struct lstcon_node *nd, struct srpc_msg *reply)
927 struct srpc_mksn_reply *mksn_rep = &reply->msg_body.mksn_reply;
928 int status = mksn_rep->mksn_status;
931 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
932 mksn_rep->mksn_status = EPROTO;
936 if (status == EPROTO) {
937 CNETERR("session protocol error from %s: %u\n",
938 libcfs_nid2str(nd->nd_id.nid),
939 reply->msg_ses_feats);
945 if (!trans->tas_feats_updated) {
946 spin_lock(&console_session.ses_rpc_lock);
947 if (!trans->tas_feats_updated) { /* recheck with lock */
948 trans->tas_feats_updated = 1;
949 trans->tas_features = reply->msg_ses_feats;
951 spin_unlock(&console_session.ses_rpc_lock);
954 if (reply->msg_ses_feats != trans->tas_features) {
955 CNETERR("Framework features %x from %s is different with "
956 "features on this transaction: %x\n",
957 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
958 trans->tas_features);
959 status = mksn_rep->mksn_status = EPROTO;
963 /* session timeout on remote node */
964 nd->nd_timeout = mksn_rep->mksn_timeout;
971 lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg,
972 struct lstcon_node *nd, struct lstcon_trans_stat *stat)
974 struct srpc_rmsn_reply *rmsn_rep;
975 struct srpc_debug_reply *dbg_rep;
976 struct srpc_batch_reply *bat_rep;
977 struct srpc_test_reply *test_rep;
978 struct srpc_stat_reply *stat_rep;
981 switch (trans->tas_opc) {
982 case LST_TRANS_SESNEW:
983 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
985 lstcon_sesop_stat_success(stat, 1);
989 lstcon_sesop_stat_failure(stat, 1);
992 case LST_TRANS_SESEND:
993 rmsn_rep = &msg->msg_body.rmsn_reply;
994 /* ESRCH is not an error for end session */
995 if (rmsn_rep->rmsn_status == 0 ||
996 rmsn_rep->rmsn_status == ESRCH) {
997 lstcon_sesop_stat_success(stat, 1);
1001 lstcon_sesop_stat_failure(stat, 1);
1002 rc = rmsn_rep->rmsn_status;
1005 case LST_TRANS_SESQRY:
1006 case LST_TRANS_SESPING:
1007 dbg_rep = &msg->msg_body.dbg_reply;
1009 if (dbg_rep->dbg_status == ESRCH) {
1010 lstcon_sesqry_stat_unknown(stat, 1);
1014 if (lstcon_session_match(dbg_rep->dbg_sid))
1015 lstcon_sesqry_stat_active(stat, 1);
1017 lstcon_sesqry_stat_busy(stat, 1);
1020 case LST_TRANS_TSBRUN:
1021 case LST_TRANS_TSBSTOP:
1022 bat_rep = &msg->msg_body.bat_reply;
1024 if (bat_rep->bar_status == 0) {
1025 lstcon_tsbop_stat_success(stat, 1);
1029 if (bat_rep->bar_status == EPERM &&
1030 trans->tas_opc == LST_TRANS_TSBSTOP) {
1031 lstcon_tsbop_stat_success(stat, 1);
1035 lstcon_tsbop_stat_failure(stat, 1);
1036 rc = bat_rep->bar_status;
1039 case LST_TRANS_TSBCLIQRY:
1040 case LST_TRANS_TSBSRVQRY:
1041 bat_rep = &msg->msg_body.bat_reply;
1043 if (bat_rep->bar_active != 0)
1044 lstcon_tsbqry_stat_run(stat, 1);
1046 lstcon_tsbqry_stat_idle(stat, 1);
1048 if (bat_rep->bar_status == 0)
1051 lstcon_tsbqry_stat_failure(stat, 1);
1052 rc = bat_rep->bar_status;
1055 case LST_TRANS_TSBCLIADD:
1056 case LST_TRANS_TSBSRVADD:
1057 test_rep = &msg->msg_body.tes_reply;
1059 if (test_rep->tsr_status == 0) {
1060 lstcon_tsbop_stat_success(stat, 1);
1064 lstcon_tsbop_stat_failure(stat, 1);
1065 rc = test_rep->tsr_status;
1068 case LST_TRANS_STATQRY:
1069 stat_rep = &msg->msg_body.stat_reply;
1071 if (stat_rep->str_status == 0) {
1072 lstcon_statqry_stat_success(stat, 1);
1076 lstcon_statqry_stat_failure(stat, 1);
1077 rc = stat_rep->str_status;
1084 if (stat->trs_fwk_errno == 0)
1085 stat->trs_fwk_errno = rc;
1091 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1092 struct list_head *translist, int transop,
1093 void *arg, lstcon_rpc_cond_func_t condition,
1094 struct lstcon_rpc_trans **transpp)
1096 struct lstcon_rpc_trans *trans;
1097 struct lstcon_ndlink *ndl;
1098 struct lstcon_node *nd;
1099 struct lstcon_rpc *rpc;
1103 /* Creating session RPG for list of nodes */
1105 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1107 CERROR("Can't create transaction %d: %d\n", transop, rc);
1111 feats = trans->tas_features;
1112 list_for_each_entry(ndl, ndlist, ndl_link) {
1113 rc = condition == NULL ? 1 :
1114 condition(transop, ndl->ndl_node, arg);
1120 CDEBUG(D_NET, "Condition error while creating RPC "
1121 " for transaction %d: %d\n", transop, rc);
1128 case LST_TRANS_SESNEW:
1129 case LST_TRANS_SESEND:
1130 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1132 case LST_TRANS_SESQRY:
1133 case LST_TRANS_SESPING:
1134 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1136 case LST_TRANS_TSBCLIADD:
1137 case LST_TRANS_TSBSRVADD:
1138 rc = lstcon_testrpc_prep(nd, transop, feats,
1139 (struct lstcon_test *)arg,
1142 case LST_TRANS_TSBRUN:
1143 case LST_TRANS_TSBSTOP:
1144 case LST_TRANS_TSBCLIQRY:
1145 case LST_TRANS_TSBSRVQRY:
1146 rc = lstcon_batrpc_prep(nd, transop, feats,
1147 (struct lstcon_tsb_hdr *)arg,
1150 case LST_TRANS_STATQRY:
1151 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1159 CERROR("Failed to create RPC for transaction %s: %d\n",
1160 lstcon_rpc_trans_name(transop), rc);
1164 lstcon_rpc_trans_addreq(trans, rpc);
1172 lstcon_rpc_trans_destroy(trans);
1178 lstcon_rpc_pinger(void *arg)
1180 struct stt_timer *ptimer = arg;
1181 struct lstcon_rpc_trans *trans;
1182 struct lstcon_rpc *crpc;
1183 struct srpc_msg *rep;
1184 struct srpc_debug_reqst *drq;
1185 struct lstcon_ndlink *ndl;
1186 struct lstcon_node *nd;
1191 /* RPC pinger is a special case of transaction,
1192 * it's called by timer at 8 seconds interval.
1194 mutex_lock(&console_session.ses_mutex);
1196 if (console_session.ses_shutdown || console_session.ses_expired) {
1197 mutex_unlock(&console_session.ses_mutex);
1201 if (!console_session.ses_expired &&
1202 ktime_get_real_seconds() - console_session.ses_laststamp >
1203 (time64_t)console_session.ses_timeout)
1204 console_session.ses_expired = 1;
1206 trans = console_session.ses_ping;
1208 LASSERT(trans != NULL);
1210 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1213 if (console_session.ses_expired) {
1214 /* idle console, end session on all nodes */
1215 if (nd->nd_state != LST_NODE_ACTIVE)
1218 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1219 trans->tas_features, &crpc);
1221 CERROR("Out of memory\n");
1225 lstcon_rpc_trans_addreq(trans, crpc);
1226 lstcon_rpc_post(crpc);
1231 crpc = &nd->nd_ping;
1233 if (crpc->crp_rpc != NULL) {
1234 LASSERT(crpc->crp_trans == trans);
1235 LASSERT(!list_empty(&crpc->crp_link));
1237 spin_lock(&crpc->crp_rpc->crpc_lock);
1239 LASSERT(crpc->crp_posted);
1241 if (!crpc->crp_finished) {
1243 spin_unlock(&crpc->crp_rpc->crpc_lock);
1247 spin_unlock(&crpc->crp_rpc->crpc_lock);
1249 lstcon_rpc_get_reply(crpc, &rep);
1251 list_del_init(&crpc->crp_link);
1253 lstcon_rpc_put(crpc);
1256 if (nd->nd_state != LST_NODE_ACTIVE)
1259 intv = cfs_duration_sec(jiffies - nd->nd_stamp);
1260 if (intv < nd->nd_timeout / 2)
1263 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1264 trans->tas_features, 0, 0, 1, crpc);
1266 CERROR("Out of memory\n");
1270 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1272 drq->dbg_sid = console_session.ses_id;
1275 lstcon_rpc_trans_addreq(trans, crpc);
1276 lstcon_rpc_post(crpc);
1281 if (console_session.ses_expired) {
1282 mutex_unlock(&console_session.ses_mutex);
1286 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1288 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1289 stt_add_timer(ptimer);
1291 mutex_unlock(&console_session.ses_mutex);
1295 lstcon_rpc_pinger_start(void)
1297 struct stt_timer *ptimer;
1300 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1301 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1303 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1304 &console_session.ses_ping);
1306 CERROR("Failed to create console pinger\n");
1310 ptimer = &console_session.ses_ping_timer;
1311 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1313 stt_add_timer(ptimer);
1319 lstcon_rpc_pinger_stop(void)
1321 LASSERT (console_session.ses_shutdown);
1323 stt_del_timer(&console_session.ses_ping_timer);
1325 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1326 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1327 lstcon_rpc_trans_destroy(console_session.ses_ping);
1329 memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1331 console_session.ses_ping = NULL;
1335 lstcon_rpc_cleanup_wait(void)
1337 struct lstcon_rpc_trans *trans;
1338 struct lstcon_rpc *crpc;
1339 struct list_head *pacer;
1340 struct list_head zlist;
1342 /* Called with hold of global mutex */
1344 LASSERT(console_session.ses_shutdown);
1346 while (!list_empty(&console_session.ses_trans_list)) {
1347 list_for_each(pacer, &console_session.ses_trans_list) {
1348 trans = list_entry(pacer, struct lstcon_rpc_trans,
1351 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1352 lstcon_rpc_trans_name(trans->tas_opc));
1354 wake_up(&trans->tas_waitq);
1357 mutex_unlock(&console_session.ses_mutex);
1359 CWARN("Session is shutting down, "
1360 "waiting for termination of transactions\n");
1361 set_current_state(TASK_UNINTERRUPTIBLE);
1362 schedule_timeout(cfs_time_seconds(1));
1364 mutex_lock(&console_session.ses_mutex);
1367 spin_lock(&console_session.ses_rpc_lock);
1369 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1370 console_session.ses_rpc_lock,
1371 "Network is not accessable or target is down, "
1372 "waiting for %d console RPCs to being recycled\n",
1373 atomic_read(&console_session.ses_rpc_counter));
1375 list_add(&zlist, &console_session.ses_rpc_freelist);
1376 list_del_init(&console_session.ses_rpc_freelist);
1378 spin_unlock(&console_session.ses_rpc_lock);
1380 while (!list_empty(&zlist)) {
1381 crpc = list_entry(zlist.next, struct lstcon_rpc, crp_link);
1383 list_del(&crpc->crp_link);
1384 LIBCFS_FREE(crpc, sizeof(*crpc));
1389 lstcon_rpc_module_init(void)
1391 INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1392 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1393 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1395 console_session.ses_ping = NULL;
1397 spin_lock_init(&console_session.ses_rpc_lock);
1398 atomic_set(&console_session.ses_rpc_counter, 0);
1399 INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1405 lstcon_rpc_module_fini(void)
1407 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1408 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);