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_ns == 0) {
74 LASSERT(crpc->crp_status == 0);
76 crpc->crp_stamp_ns = ktime_get_ns();
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 memset(crpc, 0, sizeof(*crpc));
94 crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
95 feats, bulk_npg, bulk_len,
96 lstcon_rpc_done, (void *)crpc);
97 if (crpc->crp_rpc == NULL)
101 crpc->crp_embedded = embedded;
102 INIT_LIST_HEAD(&crpc->crp_link);
104 atomic_inc(&console_session.ses_rpc_counter);
110 lstcon_rpc_prep(struct lstcon_node *nd, int service, unsigned int feats,
111 int bulk_npg, int bulk_len, struct lstcon_rpc **crpcpp)
113 struct lstcon_rpc *crpc = NULL;
116 spin_lock(&console_session.ses_rpc_lock);
118 if (!list_empty(&console_session.ses_rpc_freelist)) {
119 crpc = list_entry(console_session.ses_rpc_freelist.next,
120 struct lstcon_rpc, crp_link);
121 list_del_init(&crpc->crp_link);
124 spin_unlock(&console_session.ses_rpc_lock);
127 LIBCFS_ALLOC(crpc, sizeof(*crpc));
132 rc = lstcon_rpc_init(nd, service, feats, bulk_npg, bulk_len, 0, crpc);
138 LIBCFS_FREE(crpc, sizeof(*crpc));
144 lstcon_rpc_put(struct lstcon_rpc *crpc)
146 struct srpc_bulk *bulk = &crpc->crp_rpc->crpc_bulk;
149 LASSERT(list_empty(&crpc->crp_link));
151 for (i = 0; i < bulk->bk_niov; i++) {
152 if (bulk->bk_iovs[i].kiov_page == NULL)
155 __free_page(bulk->bk_iovs[i].kiov_page);
158 srpc_client_rpc_decref(crpc->crp_rpc);
160 if (crpc->crp_embedded) {
161 /* embedded RPC, don't recycle it */
162 memset(crpc, 0, sizeof(*crpc));
163 crpc->crp_embedded = 1;
166 spin_lock(&console_session.ses_rpc_lock);
168 list_add(&crpc->crp_link,
169 &console_session.ses_rpc_freelist);
171 spin_unlock(&console_session.ses_rpc_lock);
174 /* RPC is not alive now */
175 atomic_dec(&console_session.ses_rpc_counter);
179 lstcon_rpc_post(struct lstcon_rpc *crpc)
181 struct lstcon_rpc_trans *trans = crpc->crp_trans;
183 LASSERT (trans != NULL);
185 atomic_inc(&trans->tas_remaining);
186 crpc->crp_posted = 1;
188 sfw_post_rpc(crpc->crp_rpc);
192 lstcon_rpc_trans_name(int transop)
194 if (transop == LST_TRANS_SESNEW)
197 if (transop == LST_TRANS_SESEND)
200 if (transop == LST_TRANS_SESQRY)
203 if (transop == LST_TRANS_SESPING)
206 if (transop == LST_TRANS_TSBCLIADD)
209 if (transop == LST_TRANS_TSBSRVADD)
212 if (transop == LST_TRANS_TSBRUN)
215 if (transop == LST_TRANS_TSBSTOP)
218 if (transop == LST_TRANS_TSBCLIQRY)
221 if (transop == LST_TRANS_TSBSRVQRY)
224 if (transop == LST_TRANS_STATQRY)
231 lstcon_rpc_trans_prep(struct list_head *translist, int transop,
232 struct lstcon_rpc_trans **transpp)
234 struct lstcon_rpc_trans *trans;
236 if (translist != NULL) {
237 list_for_each_entry(trans, translist, tas_link) {
238 /* Can't enqueue two private transaction on
240 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
245 /* create a trans group */
246 LIBCFS_ALLOC(trans, sizeof(*trans));
250 trans->tas_opc = transop;
252 if (translist == NULL)
253 INIT_LIST_HEAD(&trans->tas_olink);
255 list_add_tail(&trans->tas_olink, translist);
257 list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
259 INIT_LIST_HEAD(&trans->tas_rpcs_list);
260 atomic_set(&trans->tas_remaining, 0);
261 init_waitqueue_head(&trans->tas_waitq);
263 spin_lock(&console_session.ses_rpc_lock);
264 trans->tas_features = console_session.ses_features;
265 spin_unlock(&console_session.ses_rpc_lock);
272 lstcon_rpc_trans_addreq(struct lstcon_rpc_trans *trans, struct lstcon_rpc *crpc)
274 list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
275 crpc->crp_trans = trans;
279 lstcon_rpc_trans_abort(struct lstcon_rpc_trans *trans, int error)
281 struct srpc_client_rpc *rpc;
282 struct lstcon_rpc *crpc;
283 struct lstcon_node *nd;
285 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
288 spin_lock(&rpc->crpc_lock);
290 if (!crpc->crp_posted || /* not posted */
291 crpc->crp_stamp_ns != 0) { /* rpc done or aborted already */
292 if (crpc->crp_stamp_ns == 0) {
293 crpc->crp_stamp_ns = ktime_get_ns();
294 crpc->crp_status = -EINTR;
296 spin_unlock(&rpc->crpc_lock);
300 crpc->crp_stamp_ns = ktime_get_ns();
301 crpc->crp_status = error;
303 spin_unlock(&rpc->crpc_lock);
307 if (error != -ETIMEDOUT)
311 if (ktime_to_ns(nd->nd_stamp) > crpc->crp_stamp_ns)
314 nd->nd_stamp = ktime_set(0, crpc->crp_stamp_ns);
315 nd->nd_state = LST_NODE_DOWN;
320 lstcon_rpc_trans_check(struct lstcon_rpc_trans *trans)
322 if (console_session.ses_shutdown &&
323 !list_empty(&trans->tas_olink)) /* Not an end session RPC */
326 return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
330 lstcon_rpc_trans_postwait(struct lstcon_rpc_trans *trans, int timeout)
332 struct lstcon_rpc *crpc;
335 if (list_empty(&trans->tas_rpcs_list))
338 if (timeout < LST_TRANS_MIN_TIMEOUT)
339 timeout = LST_TRANS_MIN_TIMEOUT;
341 CDEBUG(D_NET, "Transaction %s started\n",
342 lstcon_rpc_trans_name(trans->tas_opc));
344 /* post all requests */
345 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
346 LASSERT(!crpc->crp_posted);
348 lstcon_rpc_post(crpc);
351 mutex_unlock(&console_session.ses_mutex);
353 rc = wait_event_interruptible_timeout(trans->tas_waitq,
354 lstcon_rpc_trans_check(trans),
355 cfs_time_seconds(timeout));
357 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
359 mutex_lock(&console_session.ses_mutex);
361 if (console_session.ses_shutdown)
364 if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
365 /* treat short timeout as canceled */
366 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
369 lstcon_rpc_trans_abort(trans, rc);
372 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
373 lstcon_rpc_trans_name(trans->tas_opc), rc);
375 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
381 lstcon_rpc_get_reply(struct lstcon_rpc *crpc, struct srpc_msg **msgpp)
383 struct lstcon_node *nd = crpc->crp_node;
384 struct srpc_client_rpc *rpc = crpc->crp_rpc;
385 struct srpc_generic_reply *rep;
387 LASSERT(nd != NULL && rpc != NULL);
388 LASSERT(crpc->crp_stamp_ns != 0);
390 if (crpc->crp_status != 0) {
392 return crpc->crp_status;
395 *msgpp = &rpc->crpc_replymsg;
396 if (!crpc->crp_unpacked) {
397 sfw_unpack_message(*msgpp);
398 crpc->crp_unpacked = 1;
401 if (ktime_to_ns(nd->nd_stamp) > crpc->crp_stamp_ns)
404 nd->nd_stamp = ktime_set(0, crpc->crp_stamp_ns);
405 rep = &(*msgpp)->msg_body.reply;
407 if (rep->sid.ses_nid == LNET_NID_ANY)
408 nd->nd_state = LST_NODE_UNKNOWN;
409 else if (lstcon_session_match(rep->sid))
410 nd->nd_state = LST_NODE_ACTIVE;
412 nd->nd_state = LST_NODE_BUSY;
418 lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans,
419 struct lstcon_trans_stat *stat)
421 struct lstcon_rpc *crpc;
422 struct srpc_msg *rep;
425 LASSERT(stat != NULL);
427 memset(stat, 0, sizeof(*stat));
429 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
430 lstcon_rpc_stat_total(stat, 1);
432 LASSERT(crpc->crp_stamp_ns != 0);
434 error = lstcon_rpc_get_reply(crpc, &rep);
436 lstcon_rpc_stat_failure(stat, 1);
437 if (stat->trs_rpc_errno == 0)
438 stat->trs_rpc_errno = -error;
443 lstcon_rpc_stat_success(stat, 1);
445 lstcon_rpc_stat_reply(trans, rep, crpc->crp_node, stat);
448 if (trans->tas_opc == LST_TRANS_SESNEW && stat->trs_fwk_errno == 0) {
449 stat->trs_fwk_errno =
450 lstcon_session_feats_check(trans->tas_features);
453 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
454 "RPC error(%d), Framework error(%d)\n",
455 lstcon_rpc_trans_name(trans->tas_opc),
456 lstcon_rpc_stat_success(stat, 0),
457 lstcon_rpc_stat_failure(stat, 0),
458 lstcon_rpc_stat_total(stat, 0),
459 stat->trs_rpc_errno, stat->trs_fwk_errno);
465 lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
466 struct list_head __user *head_up,
467 lstcon_rpc_readent_func_t readent)
469 struct list_head tmp;
470 struct list_head __user *next;
471 struct lstcon_rpc_ent *ent;
472 struct srpc_generic_reply *rep;
473 struct lstcon_rpc *crpc;
474 struct srpc_msg *msg;
475 struct lstcon_node *nd;
480 LASSERT(head_up != NULL);
484 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
485 if (copy_from_user(&tmp, next,
486 sizeof(struct list_head)))
489 if (tmp.next == head_up)
494 ent = list_entry(next, struct lstcon_rpc_ent, rpe_link);
496 LASSERT(crpc->crp_stamp_ns != 0);
498 error = lstcon_rpc_get_reply(crpc, &msg);
502 dur = crpc->crp_stamp_ns -
503 console_session.ses_id.ses_stamp * NSEC_PER_MSEC;
504 tv = ns_to_timeval(dur);
506 if (copy_to_user(&ent->rpe_peer,
507 &nd->nd_id, sizeof(struct lnet_process_id)) ||
508 copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
509 copy_to_user(&ent->rpe_state,
510 &nd->nd_state, sizeof(nd->nd_state)) ||
511 copy_to_user(&ent->rpe_rpc_errno, &error,
519 rep = (struct srpc_generic_reply *)&msg->msg_body.reply;
521 if (copy_to_user(&ent->rpe_sid,
522 &rep->sid, sizeof(rep->sid)) ||
523 copy_to_user(&ent->rpe_fwk_errno,
524 &rep->status, sizeof(rep->status)))
530 error = readent(trans->tas_opc, msg, ent);
539 lstcon_rpc_trans_destroy(struct lstcon_rpc_trans *trans)
541 struct srpc_client_rpc *rpc;
542 struct lstcon_rpc *crpc;
543 struct lstcon_rpc *tmp;
546 list_for_each_entry_safe(crpc, tmp, &trans->tas_rpcs_list, crp_link) {
549 spin_lock(&rpc->crpc_lock);
551 /* free it if not posted or finished already */
552 if (!crpc->crp_posted || crpc->crp_finished) {
553 spin_unlock(&rpc->crpc_lock);
555 list_del_init(&crpc->crp_link);
556 lstcon_rpc_put(crpc);
561 /* rpcs can be still not callbacked (even LNetMDUnlink is
562 * called) because huge timeout for inaccessible network,
563 * don't make user wait for them, just abandon them, they
564 * will be recycled in callback */
566 LASSERT(crpc->crp_status != 0);
568 crpc->crp_node = NULL;
569 crpc->crp_trans = NULL;
570 list_del_init(&crpc->crp_link);
573 spin_unlock(&rpc->crpc_lock);
575 atomic_dec(&trans->tas_remaining);
578 LASSERT(atomic_read(&trans->tas_remaining) == 0);
580 list_del(&trans->tas_link);
581 if (!list_empty(&trans->tas_olink))
582 list_del(&trans->tas_olink);
584 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
585 lstcon_rpc_trans_name(trans->tas_opc), count);
587 LIBCFS_FREE(trans, sizeof(*trans));
593 lstcon_sesrpc_prep(struct lstcon_node *nd, int transop,
594 unsigned int feats, struct lstcon_rpc **crpc)
596 struct srpc_mksn_reqst *msrq;
597 struct srpc_rmsn_reqst *rsrq;
601 case LST_TRANS_SESNEW:
602 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
607 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
608 msrq->mksn_sid = console_session.ses_id;
609 msrq->mksn_force = console_session.ses_force;
610 strlcpy(msrq->mksn_name, console_session.ses_name,
611 sizeof(msrq->mksn_name));
614 case LST_TRANS_SESEND:
615 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
620 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
621 rsrq->rmsn_sid = console_session.ses_id;
632 lstcon_dbgrpc_prep(struct lstcon_node *nd, unsigned int feats,
633 struct lstcon_rpc **crpc)
635 struct srpc_debug_reqst *drq;
638 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
642 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
644 drq->dbg_sid = console_session.ses_id;
651 lstcon_batrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
652 struct lstcon_tsb_hdr *tsb, struct lstcon_rpc **crpc)
654 struct lstcon_batch *batch;
655 struct srpc_batch_reqst *brq;
658 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
662 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
664 brq->bar_sid = console_session.ses_id;
665 brq->bar_bid = tsb->tsb_id;
666 brq->bar_testidx = tsb->tsb_index;
667 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
668 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
669 SRPC_BATCH_OPC_QUERY);
671 if (transop != LST_TRANS_TSBRUN &&
672 transop != LST_TRANS_TSBSTOP)
675 LASSERT (tsb->tsb_index == 0);
677 batch = (struct lstcon_batch *)tsb;
678 brq->bar_arg = batch->bat_arg;
684 lstcon_statrpc_prep(struct lstcon_node *nd, unsigned int feats,
685 struct lstcon_rpc **crpc)
687 struct srpc_stat_reqst *srq;
690 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
694 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
696 srq->str_sid = console_session.ses_id;
697 srq->str_type = 0; /* XXX remove it */
702 static struct lnet_process_id_packed *
703 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
705 struct lnet_process_id_packed *pid;
708 i = idx / SFW_ID_PER_PAGE;
712 pid = (struct lnet_process_id_packed *)page_address(kiov[i].kiov_page);
714 return &pid[idx % SFW_ID_PER_PAGE];
718 lstcon_dstnodes_prep(struct lstcon_group *grp, int idx,
719 int dist, int span, int nkiov, lnet_kiov_t *kiov)
721 struct lnet_process_id_packed *pid;
722 struct lstcon_ndlink *ndl;
723 struct lstcon_node *nd;
730 LASSERT (grp->grp_nnode >= 1);
732 if (span > grp->grp_nnode)
735 start = ((idx / dist) * span) % grp->grp_nnode;
736 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
738 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
745 if (i > (end >= start ? end : grp->grp_nnode))
748 pid = lstcon_next_id((i - start), nkiov, kiov);
749 pid->nid = nd->nd_id.nid;
750 pid->pid = nd->nd_id.pid;
754 if (start <= end) /* done */
757 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
758 if (i > grp->grp_nnode + end)
762 pid = lstcon_next_id((i - start), nkiov, kiov);
763 pid->nid = nd->nd_id.nid;
764 pid->pid = nd->nd_id.pid;
772 lstcon_pingrpc_prep(struct lst_test_ping_param *param,
773 struct srpc_test_reqst *req)
775 struct test_ping_req *prq = &req->tsr_u.ping;
777 prq->png_size = param->png_size;
778 prq->png_flags = param->png_flags;
784 lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param,
785 struct srpc_test_reqst *req)
787 struct test_bulk_req *brq = &req->tsr_u.bulk_v0;
789 brq->blk_opc = param->blk_opc;
790 brq->blk_npg = (param->blk_size + PAGE_SIZE - 1) /
792 brq->blk_flags = param->blk_flags;
798 lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
799 struct srpc_test_reqst *req)
801 struct test_bulk_req_v1 *brq = &req->tsr_u.bulk_v1;
803 brq->blk_opc = param->blk_opc;
804 brq->blk_flags = param->blk_flags;
805 brq->blk_len = param->blk_size;
806 brq->blk_offset = is_client ? param->blk_cli_off : param->blk_srv_off;
812 lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
813 struct lstcon_test *test, struct lstcon_rpc **crpc)
815 struct lstcon_group *sgrp = test->tes_src_grp;
816 struct lstcon_group *dgrp = test->tes_dst_grp;
817 struct srpc_test_reqst *trq;
818 struct srpc_bulk *bulk;
824 if (transop == LST_TRANS_TSBCLIADD) {
825 npg = sfw_id_pages(test->tes_span);
826 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
828 sizeof(struct lnet_process_id_packed) * test->tes_span;
831 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
835 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
837 if (transop == LST_TRANS_TSBSRVADD) {
838 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
839 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
840 int nmax = (ndist + nspan - 1) / nspan;
843 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
846 bulk = &(*crpc)->crp_rpc->crpc_bulk;
848 for (i = 0; i < npg; i++) {
853 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
854 PAGE_SIZE : min_t(int, nob, PAGE_SIZE);
857 bulk->bk_iovs[i].kiov_offset = 0;
858 bulk->bk_iovs[i].kiov_len = len;
859 bulk->bk_iovs[i].kiov_page =
860 alloc_page(GFP_KERNEL);
862 if (bulk->bk_iovs[i].kiov_page == NULL) {
863 lstcon_rpc_put(*crpc);
870 LASSERT (transop == LST_TRANS_TSBCLIADD);
872 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
876 npg, &bulk->bk_iovs[0]);
878 lstcon_rpc_put(*crpc);
882 trq->tsr_ndest = test->tes_span;
883 trq->tsr_loop = test->tes_loop;
886 trq->tsr_sid = console_session.ses_id;
887 trq->tsr_bid = test->tes_hdr.tsb_id;
888 trq->tsr_concur = test->tes_concur;
889 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
890 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
892 switch (test->tes_type) {
894 trq->tsr_service = SRPC_SERVICE_PING;
895 rc = lstcon_pingrpc_prep((struct lst_test_ping_param *)
896 &test->tes_param[0], trq);
900 trq->tsr_service = SRPC_SERVICE_BRW;
901 if ((feats & LST_FEAT_BULK_LEN) == 0) {
902 rc = lstcon_bulkrpc_v0_prep((struct lst_test_bulk_param *)
903 &test->tes_param[0], trq);
905 rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
907 trq->tsr_is_client, trq);
920 lstcon_sesnew_stat_reply(struct lstcon_rpc_trans *trans,
921 struct lstcon_node *nd, struct srpc_msg *reply)
923 struct srpc_mksn_reply *mksn_rep = &reply->msg_body.mksn_reply;
924 int status = mksn_rep->mksn_status;
927 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
928 mksn_rep->mksn_status = EPROTO;
932 if (status == EPROTO) {
933 CNETERR("session protocol error from %s: %u\n",
934 libcfs_nid2str(nd->nd_id.nid),
935 reply->msg_ses_feats);
941 if (!trans->tas_feats_updated) {
942 spin_lock(&console_session.ses_rpc_lock);
943 if (!trans->tas_feats_updated) { /* recheck with lock */
944 trans->tas_feats_updated = 1;
945 trans->tas_features = reply->msg_ses_feats;
947 spin_unlock(&console_session.ses_rpc_lock);
950 if (reply->msg_ses_feats != trans->tas_features) {
951 CNETERR("Framework features %x from %s is different with "
952 "features on this transaction: %x\n",
953 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
954 trans->tas_features);
955 status = mksn_rep->mksn_status = EPROTO;
959 /* session timeout on remote node */
960 nd->nd_timeout = mksn_rep->mksn_timeout;
967 lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg,
968 struct lstcon_node *nd, struct lstcon_trans_stat *stat)
970 struct srpc_rmsn_reply *rmsn_rep;
971 struct srpc_debug_reply *dbg_rep;
972 struct srpc_batch_reply *bat_rep;
973 struct srpc_test_reply *test_rep;
974 struct srpc_stat_reply *stat_rep;
977 switch (trans->tas_opc) {
978 case LST_TRANS_SESNEW:
979 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
981 lstcon_sesop_stat_success(stat, 1);
985 lstcon_sesop_stat_failure(stat, 1);
988 case LST_TRANS_SESEND:
989 rmsn_rep = &msg->msg_body.rmsn_reply;
990 /* ESRCH is not an error for end session */
991 if (rmsn_rep->rmsn_status == 0 ||
992 rmsn_rep->rmsn_status == ESRCH) {
993 lstcon_sesop_stat_success(stat, 1);
997 lstcon_sesop_stat_failure(stat, 1);
998 rc = rmsn_rep->rmsn_status;
1001 case LST_TRANS_SESQRY:
1002 case LST_TRANS_SESPING:
1003 dbg_rep = &msg->msg_body.dbg_reply;
1005 if (dbg_rep->dbg_status == ESRCH) {
1006 lstcon_sesqry_stat_unknown(stat, 1);
1010 if (lstcon_session_match(dbg_rep->dbg_sid))
1011 lstcon_sesqry_stat_active(stat, 1);
1013 lstcon_sesqry_stat_busy(stat, 1);
1016 case LST_TRANS_TSBRUN:
1017 case LST_TRANS_TSBSTOP:
1018 bat_rep = &msg->msg_body.bat_reply;
1020 if (bat_rep->bar_status == 0) {
1021 lstcon_tsbop_stat_success(stat, 1);
1025 if (bat_rep->bar_status == EPERM &&
1026 trans->tas_opc == LST_TRANS_TSBSTOP) {
1027 lstcon_tsbop_stat_success(stat, 1);
1031 lstcon_tsbop_stat_failure(stat, 1);
1032 rc = bat_rep->bar_status;
1035 case LST_TRANS_TSBCLIQRY:
1036 case LST_TRANS_TSBSRVQRY:
1037 bat_rep = &msg->msg_body.bat_reply;
1039 if (bat_rep->bar_active != 0)
1040 lstcon_tsbqry_stat_run(stat, 1);
1042 lstcon_tsbqry_stat_idle(stat, 1);
1044 if (bat_rep->bar_status == 0)
1047 lstcon_tsbqry_stat_failure(stat, 1);
1048 rc = bat_rep->bar_status;
1051 case LST_TRANS_TSBCLIADD:
1052 case LST_TRANS_TSBSRVADD:
1053 test_rep = &msg->msg_body.tes_reply;
1055 if (test_rep->tsr_status == 0) {
1056 lstcon_tsbop_stat_success(stat, 1);
1060 lstcon_tsbop_stat_failure(stat, 1);
1061 rc = test_rep->tsr_status;
1064 case LST_TRANS_STATQRY:
1065 stat_rep = &msg->msg_body.stat_reply;
1067 if (stat_rep->str_status == 0) {
1068 lstcon_statqry_stat_success(stat, 1);
1072 lstcon_statqry_stat_failure(stat, 1);
1073 rc = stat_rep->str_status;
1080 if (stat->trs_fwk_errno == 0)
1081 stat->trs_fwk_errno = rc;
1087 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1088 struct list_head *translist, int transop,
1089 void *arg, lstcon_rpc_cond_func_t condition,
1090 struct lstcon_rpc_trans **transpp)
1092 struct lstcon_rpc_trans *trans;
1093 struct lstcon_ndlink *ndl;
1094 struct lstcon_node *nd;
1095 struct lstcon_rpc *rpc;
1099 /* Creating session RPG for list of nodes */
1101 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1103 CERROR("Can't create transaction %d: %d\n", transop, rc);
1107 feats = trans->tas_features;
1108 list_for_each_entry(ndl, ndlist, ndl_link) {
1109 rc = condition == NULL ? 1 :
1110 condition(transop, ndl->ndl_node, arg);
1116 CDEBUG(D_NET, "Condition error while creating RPC "
1117 " for transaction %d: %d\n", transop, rc);
1124 case LST_TRANS_SESNEW:
1125 case LST_TRANS_SESEND:
1126 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1128 case LST_TRANS_SESQRY:
1129 case LST_TRANS_SESPING:
1130 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1132 case LST_TRANS_TSBCLIADD:
1133 case LST_TRANS_TSBSRVADD:
1134 rc = lstcon_testrpc_prep(nd, transop, feats,
1135 (struct lstcon_test *)arg,
1138 case LST_TRANS_TSBRUN:
1139 case LST_TRANS_TSBSTOP:
1140 case LST_TRANS_TSBCLIQRY:
1141 case LST_TRANS_TSBSRVQRY:
1142 rc = lstcon_batrpc_prep(nd, transop, feats,
1143 (struct lstcon_tsb_hdr *)arg,
1146 case LST_TRANS_STATQRY:
1147 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1155 CERROR("Failed to create RPC for transaction %s: %d\n",
1156 lstcon_rpc_trans_name(transop), rc);
1160 lstcon_rpc_trans_addreq(trans, rpc);
1168 lstcon_rpc_trans_destroy(trans);
1174 lstcon_rpc_pinger(void *arg)
1176 struct stt_timer *ptimer = arg;
1177 struct lstcon_rpc_trans *trans;
1178 struct lstcon_rpc *crpc;
1179 struct srpc_msg *rep;
1180 struct srpc_debug_reqst *drq;
1181 struct lstcon_ndlink *ndl;
1182 struct lstcon_node *nd;
1187 /* RPC pinger is a special case of transaction,
1188 * it's called by timer at 8 seconds interval.
1190 mutex_lock(&console_session.ses_mutex);
1192 if (console_session.ses_shutdown || console_session.ses_expired) {
1193 mutex_unlock(&console_session.ses_mutex);
1197 if (!console_session.ses_expired &&
1198 ktime_get_real_seconds() - console_session.ses_laststamp >
1199 (time64_t)console_session.ses_timeout)
1200 console_session.ses_expired = 1;
1202 trans = console_session.ses_ping;
1204 LASSERT(trans != NULL);
1206 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1209 if (console_session.ses_expired) {
1210 /* idle console, end session on all nodes */
1211 if (nd->nd_state != LST_NODE_ACTIVE)
1214 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1215 trans->tas_features, &crpc);
1217 CERROR("Out of memory\n");
1221 lstcon_rpc_trans_addreq(trans, crpc);
1222 lstcon_rpc_post(crpc);
1227 crpc = &nd->nd_ping;
1229 if (crpc->crp_rpc != NULL) {
1230 LASSERT(crpc->crp_trans == trans);
1231 LASSERT(!list_empty(&crpc->crp_link));
1233 spin_lock(&crpc->crp_rpc->crpc_lock);
1235 LASSERT(crpc->crp_posted);
1237 if (!crpc->crp_finished) {
1239 spin_unlock(&crpc->crp_rpc->crpc_lock);
1243 spin_unlock(&crpc->crp_rpc->crpc_lock);
1245 lstcon_rpc_get_reply(crpc, &rep);
1247 list_del_init(&crpc->crp_link);
1249 lstcon_rpc_put(crpc);
1252 if (nd->nd_state != LST_NODE_ACTIVE)
1255 intv = div_u64(ktime_ms_delta(ktime_get(), nd->nd_stamp),
1257 if (intv < nd->nd_timeout / 2)
1260 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1261 trans->tas_features, 0, 0, 1, crpc);
1263 CERROR("Out of memory\n");
1267 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1269 drq->dbg_sid = console_session.ses_id;
1272 lstcon_rpc_trans_addreq(trans, crpc);
1273 lstcon_rpc_post(crpc);
1278 if (console_session.ses_expired) {
1279 mutex_unlock(&console_session.ses_mutex);
1283 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1285 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1286 stt_add_timer(ptimer);
1288 mutex_unlock(&console_session.ses_mutex);
1292 lstcon_rpc_pinger_start(void)
1294 struct stt_timer *ptimer;
1297 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1298 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1300 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1301 &console_session.ses_ping);
1303 CERROR("Failed to create console pinger\n");
1307 ptimer = &console_session.ses_ping_timer;
1308 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1310 stt_add_timer(ptimer);
1316 lstcon_rpc_pinger_stop(void)
1318 LASSERT (console_session.ses_shutdown);
1320 stt_del_timer(&console_session.ses_ping_timer);
1322 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1323 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1324 lstcon_rpc_trans_destroy(console_session.ses_ping);
1326 memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1328 console_session.ses_ping = NULL;
1332 lstcon_rpc_cleanup_wait(void)
1334 struct lstcon_rpc_trans *trans;
1335 struct lstcon_rpc *crpc;
1336 struct list_head *pacer;
1337 struct list_head zlist;
1339 /* Called with hold of global mutex */
1341 LASSERT(console_session.ses_shutdown);
1343 while (!list_empty(&console_session.ses_trans_list)) {
1344 list_for_each(pacer, &console_session.ses_trans_list) {
1345 trans = list_entry(pacer, struct lstcon_rpc_trans,
1348 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1349 lstcon_rpc_trans_name(trans->tas_opc));
1351 wake_up(&trans->tas_waitq);
1354 mutex_unlock(&console_session.ses_mutex);
1356 CWARN("Session is shutting down, "
1357 "waiting for termination of transactions\n");
1358 set_current_state(TASK_UNINTERRUPTIBLE);
1359 schedule_timeout(cfs_time_seconds(1));
1361 mutex_lock(&console_session.ses_mutex);
1364 spin_lock(&console_session.ses_rpc_lock);
1366 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1367 console_session.ses_rpc_lock,
1368 "Network is not accessable or target is down, "
1369 "waiting for %d console RPCs to being recycled\n",
1370 atomic_read(&console_session.ses_rpc_counter));
1372 list_add(&zlist, &console_session.ses_rpc_freelist);
1373 list_del_init(&console_session.ses_rpc_freelist);
1375 spin_unlock(&console_session.ses_rpc_lock);
1377 while (!list_empty(&zlist)) {
1378 crpc = list_entry(zlist.next, struct lstcon_rpc, crp_link);
1380 list_del(&crpc->crp_link);
1381 LIBCFS_FREE(crpc, sizeof(*crpc));
1386 lstcon_rpc_module_init(void)
1388 INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1389 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1390 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1392 console_session.ses_ping = NULL;
1394 spin_lock_init(&console_session.ses_rpc_lock);
1395 atomic_set(&console_session.ses_rpc_counter, 0);
1396 INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1402 lstcon_rpc_module_fini(void)
1404 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1405 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);