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(lstcon_rpc_trans_t *, srpc_msg_t *,
47 lstcon_node_t *, struct lstcon_trans_stat *);
50 lstcon_rpc_done(srpc_client_rpc_t *rpc)
52 lstcon_rpc_t *crpc = (lstcon_rpc_t *)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(lstcon_node_t *nd, int service, unsigned feats,
89 int bulk_npg, int bulk_len, int embedded, lstcon_rpc_t *crpc)
91 crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
92 feats, bulk_npg, bulk_len,
93 lstcon_rpc_done, (void *)crpc);
94 if (crpc->crp_rpc == NULL)
97 crpc->crp_trans = NULL;
100 crpc->crp_finished = 0;
101 crpc->crp_unpacked = 0;
102 crpc->crp_status = 0;
104 crpc->crp_embedded = embedded;
105 INIT_LIST_HEAD(&crpc->crp_link);
107 atomic_inc(&console_session.ses_rpc_counter);
113 lstcon_rpc_prep(lstcon_node_t *nd, int service, unsigned feats,
114 int bulk_npg, int bulk_len, lstcon_rpc_t **crpcpp)
116 lstcon_rpc_t *crpc = NULL;
119 spin_lock(&console_session.ses_rpc_lock);
121 if (!list_empty(&console_session.ses_rpc_freelist)) {
122 crpc = list_entry(console_session.ses_rpc_freelist.next,
123 lstcon_rpc_t, crp_link);
124 list_del_init(&crpc->crp_link);
127 spin_unlock(&console_session.ses_rpc_lock);
130 LIBCFS_ALLOC(crpc, sizeof(*crpc));
135 rc = lstcon_rpc_init(nd, service, feats, bulk_npg, bulk_len, 0, crpc);
141 LIBCFS_FREE(crpc, sizeof(*crpc));
147 lstcon_rpc_put(lstcon_rpc_t *crpc)
149 srpc_bulk_t *bulk = &crpc->crp_rpc->crpc_bulk;
152 LASSERT(list_empty(&crpc->crp_link));
154 for (i = 0; i < bulk->bk_niov; i++) {
155 if (bulk->bk_iovs[i].kiov_page == NULL)
158 __free_page(bulk->bk_iovs[i].kiov_page);
161 srpc_client_rpc_decref(crpc->crp_rpc);
163 if (crpc->crp_embedded) {
164 /* embedded RPC, don't recycle it */
165 memset(crpc, 0, sizeof(*crpc));
166 crpc->crp_embedded = 1;
169 spin_lock(&console_session.ses_rpc_lock);
171 list_add(&crpc->crp_link,
172 &console_session.ses_rpc_freelist);
174 spin_unlock(&console_session.ses_rpc_lock);
177 /* RPC is not alive now */
178 atomic_dec(&console_session.ses_rpc_counter);
182 lstcon_rpc_post(lstcon_rpc_t *crpc)
184 lstcon_rpc_trans_t *trans = crpc->crp_trans;
186 LASSERT (trans != NULL);
188 atomic_inc(&trans->tas_remaining);
189 crpc->crp_posted = 1;
191 sfw_post_rpc(crpc->crp_rpc);
195 lstcon_rpc_trans_name(int transop)
197 if (transop == LST_TRANS_SESNEW)
200 if (transop == LST_TRANS_SESEND)
203 if (transop == LST_TRANS_SESQRY)
206 if (transop == LST_TRANS_SESPING)
209 if (transop == LST_TRANS_TSBCLIADD)
212 if (transop == LST_TRANS_TSBSRVADD)
215 if (transop == LST_TRANS_TSBRUN)
218 if (transop == LST_TRANS_TSBSTOP)
221 if (transop == LST_TRANS_TSBCLIQRY)
224 if (transop == LST_TRANS_TSBSRVQRY)
227 if (transop == LST_TRANS_STATQRY)
234 lstcon_rpc_trans_prep(struct list_head *translist, int transop,
235 lstcon_rpc_trans_t **transpp)
237 lstcon_rpc_trans_t *trans;
239 if (translist != NULL) {
240 list_for_each_entry(trans, translist, tas_link) {
241 /* Can't enqueue two private transaction on
243 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
248 /* create a trans group */
249 LIBCFS_ALLOC(trans, sizeof(*trans));
253 trans->tas_opc = transop;
255 if (translist == NULL)
256 INIT_LIST_HEAD(&trans->tas_olink);
258 list_add_tail(&trans->tas_olink, translist);
260 list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
262 INIT_LIST_HEAD(&trans->tas_rpcs_list);
263 atomic_set(&trans->tas_remaining, 0);
264 init_waitqueue_head(&trans->tas_waitq);
266 spin_lock(&console_session.ses_rpc_lock);
267 trans->tas_features = console_session.ses_features;
268 spin_unlock(&console_session.ses_rpc_lock);
275 lstcon_rpc_trans_addreq(lstcon_rpc_trans_t *trans, lstcon_rpc_t *crpc)
277 list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
278 crpc->crp_trans = trans;
282 lstcon_rpc_trans_abort(lstcon_rpc_trans_t *trans, int error)
284 srpc_client_rpc_t *rpc;
288 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
291 spin_lock(&rpc->crpc_lock);
293 if (!crpc->crp_posted || /* not posted */
294 crpc->crp_stamp != 0) { /* rpc done or aborted already */
295 if (crpc->crp_stamp == 0) {
296 crpc->crp_stamp = cfs_time_current();
297 crpc->crp_status = -EINTR;
299 spin_unlock(&rpc->crpc_lock);
303 crpc->crp_stamp = cfs_time_current();
304 crpc->crp_status = error;
306 spin_unlock(&rpc->crpc_lock);
310 if (error != -ETIMEDOUT)
314 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
317 nd->nd_stamp = crpc->crp_stamp;
318 nd->nd_state = LST_NODE_DOWN;
323 lstcon_rpc_trans_check(lstcon_rpc_trans_t *trans)
325 if (console_session.ses_shutdown &&
326 !list_empty(&trans->tas_olink)) /* Not an end session RPC */
329 return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
333 lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
338 if (list_empty(&trans->tas_rpcs_list))
341 if (timeout < LST_TRANS_MIN_TIMEOUT)
342 timeout = LST_TRANS_MIN_TIMEOUT;
344 CDEBUG(D_NET, "Transaction %s started\n",
345 lstcon_rpc_trans_name(trans->tas_opc));
347 /* post all requests */
348 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
349 LASSERT(!crpc->crp_posted);
351 lstcon_rpc_post(crpc);
354 mutex_unlock(&console_session.ses_mutex);
356 rc = wait_event_interruptible_timeout(trans->tas_waitq,
357 lstcon_rpc_trans_check(trans),
358 cfs_time_seconds(timeout));
360 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
362 mutex_lock(&console_session.ses_mutex);
364 if (console_session.ses_shutdown)
367 if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
368 /* treat short timeout as canceled */
369 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
372 lstcon_rpc_trans_abort(trans, rc);
375 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
376 lstcon_rpc_trans_name(trans->tas_opc), rc);
378 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
384 lstcon_rpc_get_reply(lstcon_rpc_t *crpc, srpc_msg_t **msgpp)
386 lstcon_node_t *nd = crpc->crp_node;
387 srpc_client_rpc_t *rpc = crpc->crp_rpc;
388 srpc_generic_reply_t *rep;
390 LASSERT (nd != NULL && rpc != NULL);
391 LASSERT (crpc->crp_stamp != 0);
393 if (crpc->crp_status != 0) {
395 return crpc->crp_status;
398 *msgpp = &rpc->crpc_replymsg;
399 if (!crpc->crp_unpacked) {
400 sfw_unpack_message(*msgpp);
401 crpc->crp_unpacked = 1;
404 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
407 nd->nd_stamp = crpc->crp_stamp;
408 rep = &(*msgpp)->msg_body.reply;
410 if (rep->sid.ses_nid == LNET_NID_ANY)
411 nd->nd_state = LST_NODE_UNKNOWN;
412 else if (lstcon_session_match(rep->sid))
413 nd->nd_state = LST_NODE_ACTIVE;
415 nd->nd_state = LST_NODE_BUSY;
421 lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, struct lstcon_trans_stat *stat)
427 LASSERT(stat != NULL);
429 memset(stat, 0, sizeof(*stat));
431 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
432 lstcon_rpc_stat_total(stat, 1);
434 LASSERT(crpc->crp_stamp != 0);
436 error = lstcon_rpc_get_reply(crpc, &rep);
438 lstcon_rpc_stat_failure(stat, 1);
439 if (stat->trs_rpc_errno == 0)
440 stat->trs_rpc_errno = -error;
445 lstcon_rpc_stat_success(stat, 1);
447 lstcon_rpc_stat_reply(trans, rep, crpc->crp_node, stat);
450 if (trans->tas_opc == LST_TRANS_SESNEW && stat->trs_fwk_errno == 0) {
451 stat->trs_fwk_errno =
452 lstcon_session_feats_check(trans->tas_features);
455 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
456 "RPC error(%d), Framework error(%d)\n",
457 lstcon_rpc_trans_name(trans->tas_opc),
458 lstcon_rpc_stat_success(stat, 0),
459 lstcon_rpc_stat_failure(stat, 0),
460 lstcon_rpc_stat_total(stat, 0),
461 stat->trs_rpc_errno, stat->trs_fwk_errno);
467 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
468 struct list_head __user *head_up,
469 lstcon_rpc_readent_func_t readent)
471 struct list_head tmp;
472 struct list_head __user *next;
473 struct lstcon_rpc_ent *ent;
474 srpc_generic_reply_t *rep;
482 LASSERT(head_up != NULL);
486 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
487 if (copy_from_user(&tmp, next,
488 sizeof(struct list_head)))
491 if (tmp.next == head_up)
496 ent = list_entry(next, struct lstcon_rpc_ent, rpe_link);
498 LASSERT(crpc->crp_stamp != 0);
500 error = lstcon_rpc_get_reply(crpc, &msg);
504 dur = (cfs_duration_t)cfs_time_sub(crpc->crp_stamp,
505 (cfs_time_t)console_session.ses_id.ses_stamp);
506 cfs_duration_usec(dur, &tv);
508 if (copy_to_user(&ent->rpe_peer,
509 &nd->nd_id, sizeof(lnet_process_id_t)) ||
510 copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
511 copy_to_user(&ent->rpe_state,
512 &nd->nd_state, sizeof(nd->nd_state)) ||
513 copy_to_user(&ent->rpe_rpc_errno, &error,
521 rep = (srpc_generic_reply_t *)&msg->msg_body.reply;
523 if (copy_to_user(&ent->rpe_sid,
524 &rep->sid, sizeof(rep->sid)) ||
525 copy_to_user(&ent->rpe_fwk_errno,
526 &rep->status, sizeof(rep->status)))
532 error = readent(trans->tas_opc, msg, ent);
541 lstcon_rpc_trans_destroy(lstcon_rpc_trans_t *trans)
543 srpc_client_rpc_t *rpc;
548 list_for_each_entry_safe(crpc, tmp, &trans->tas_rpcs_list, crp_link) {
551 spin_lock(&rpc->crpc_lock);
553 /* free it if not posted or finished already */
554 if (!crpc->crp_posted || crpc->crp_finished) {
555 spin_unlock(&rpc->crpc_lock);
557 list_del_init(&crpc->crp_link);
558 lstcon_rpc_put(crpc);
563 /* rpcs can be still not callbacked (even LNetMDUnlink is
564 * called) because huge timeout for inaccessible network,
565 * don't make user wait for them, just abandon them, they
566 * will be recycled in callback */
568 LASSERT(crpc->crp_status != 0);
570 crpc->crp_node = NULL;
571 crpc->crp_trans = NULL;
572 list_del_init(&crpc->crp_link);
575 spin_unlock(&rpc->crpc_lock);
577 atomic_dec(&trans->tas_remaining);
580 LASSERT(atomic_read(&trans->tas_remaining) == 0);
582 list_del(&trans->tas_link);
583 if (!list_empty(&trans->tas_olink))
584 list_del(&trans->tas_olink);
586 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
587 lstcon_rpc_trans_name(trans->tas_opc), count);
589 LIBCFS_FREE(trans, sizeof(*trans));
595 lstcon_sesrpc_prep(lstcon_node_t *nd, int transop,
596 unsigned feats, lstcon_rpc_t **crpc)
598 srpc_mksn_reqst_t *msrq;
599 srpc_rmsn_reqst_t *rsrq;
603 case LST_TRANS_SESNEW:
604 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
609 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
610 msrq->mksn_sid = console_session.ses_id;
611 msrq->mksn_force = console_session.ses_force;
612 strlcpy(msrq->mksn_name, console_session.ses_name,
613 sizeof(msrq->mksn_name));
616 case LST_TRANS_SESEND:
617 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
622 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
623 rsrq->rmsn_sid = console_session.ses_id;
634 lstcon_dbgrpc_prep(lstcon_node_t *nd, unsigned feats, lstcon_rpc_t **crpc)
636 srpc_debug_reqst_t *drq;
639 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
643 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
645 drq->dbg_sid = console_session.ses_id;
652 lstcon_batrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
653 lstcon_tsb_hdr_t *tsb, lstcon_rpc_t **crpc)
655 lstcon_batch_t *batch;
656 srpc_batch_reqst_t *brq;
659 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
663 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
665 brq->bar_sid = console_session.ses_id;
666 brq->bar_bid = tsb->tsb_id;
667 brq->bar_testidx = tsb->tsb_index;
668 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
669 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
670 SRPC_BATCH_OPC_QUERY);
672 if (transop != LST_TRANS_TSBRUN &&
673 transop != LST_TRANS_TSBSTOP)
676 LASSERT (tsb->tsb_index == 0);
678 batch = (lstcon_batch_t *)tsb;
679 brq->bar_arg = batch->bat_arg;
685 lstcon_statrpc_prep(lstcon_node_t *nd, unsigned feats, lstcon_rpc_t **crpc)
687 srpc_stat_reqst_t *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(lstcon_group_t *grp, int idx,
719 int dist, int span, int nkiov, lnet_kiov_t *kiov)
721 struct lnet_process_id_packed *pid;
722 lstcon_ndlink_t *ndl;
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, srpc_test_reqst_t *req)
774 test_ping_req_t *prq = &req->tsr_u.ping;
776 prq->png_size = param->png_size;
777 prq->png_flags = param->png_flags;
783 lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param, srpc_test_reqst_t *req)
785 test_bulk_req_t *brq = &req->tsr_u.bulk_v0;
787 brq->blk_opc = param->blk_opc;
788 brq->blk_npg = (param->blk_size + PAGE_SIZE - 1) /
790 brq->blk_flags = param->blk_flags;
796 lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
797 srpc_test_reqst_t *req)
799 test_bulk_req_v1_t *brq = &req->tsr_u.bulk_v1;
801 brq->blk_opc = param->blk_opc;
802 brq->blk_flags = param->blk_flags;
803 brq->blk_len = param->blk_size;
804 brq->blk_offset = is_client ? param->blk_cli_off : param->blk_srv_off;
810 lstcon_testrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
811 lstcon_test_t *test, lstcon_rpc_t **crpc)
813 lstcon_group_t *sgrp = test->tes_src_grp;
814 lstcon_group_t *dgrp = test->tes_dst_grp;
815 srpc_test_reqst_t *trq;
822 if (transop == LST_TRANS_TSBCLIADD) {
823 npg = sfw_id_pages(test->tes_span);
824 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
826 sizeof(struct lnet_process_id_packed) * test->tes_span;
829 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
833 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
835 if (transop == LST_TRANS_TSBSRVADD) {
836 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
837 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
838 int nmax = (ndist + nspan - 1) / nspan;
841 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
844 bulk = &(*crpc)->crp_rpc->crpc_bulk;
846 for (i = 0; i < npg; i++) {
851 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
852 PAGE_SIZE : min_t(int, nob, PAGE_SIZE);
855 bulk->bk_iovs[i].kiov_offset = 0;
856 bulk->bk_iovs[i].kiov_len = len;
857 bulk->bk_iovs[i].kiov_page =
858 alloc_page(GFP_KERNEL);
860 if (bulk->bk_iovs[i].kiov_page == NULL) {
861 lstcon_rpc_put(*crpc);
868 LASSERT (transop == LST_TRANS_TSBCLIADD);
870 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
874 npg, &bulk->bk_iovs[0]);
876 lstcon_rpc_put(*crpc);
880 trq->tsr_ndest = test->tes_span;
881 trq->tsr_loop = test->tes_loop;
884 trq->tsr_sid = console_session.ses_id;
885 trq->tsr_bid = test->tes_hdr.tsb_id;
886 trq->tsr_concur = test->tes_concur;
887 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
888 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
890 switch (test->tes_type) {
892 trq->tsr_service = SRPC_SERVICE_PING;
893 rc = lstcon_pingrpc_prep((struct lst_test_ping_param *)
894 &test->tes_param[0], trq);
898 trq->tsr_service = SRPC_SERVICE_BRW;
899 if ((feats & LST_FEAT_BULK_LEN) == 0) {
900 rc = lstcon_bulkrpc_v0_prep((struct lst_test_bulk_param *)
901 &test->tes_param[0], trq);
903 rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
905 trq->tsr_is_client, trq);
918 lstcon_sesnew_stat_reply(lstcon_rpc_trans_t *trans,
919 lstcon_node_t *nd, srpc_msg_t *reply)
921 srpc_mksn_reply_t *mksn_rep = &reply->msg_body.mksn_reply;
922 int status = mksn_rep->mksn_status;
925 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
926 mksn_rep->mksn_status = EPROTO;
930 if (status == EPROTO) {
931 CNETERR("session protocol error from %s: %u\n",
932 libcfs_nid2str(nd->nd_id.nid),
933 reply->msg_ses_feats);
939 if (!trans->tas_feats_updated) {
940 spin_lock(&console_session.ses_rpc_lock);
941 if (!trans->tas_feats_updated) { /* recheck with lock */
942 trans->tas_feats_updated = 1;
943 trans->tas_features = reply->msg_ses_feats;
945 spin_unlock(&console_session.ses_rpc_lock);
948 if (reply->msg_ses_feats != trans->tas_features) {
949 CNETERR("Framework features %x from %s is different with "
950 "features on this transaction: %x\n",
951 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
952 trans->tas_features);
953 status = mksn_rep->mksn_status = EPROTO;
957 /* session timeout on remote node */
958 nd->nd_timeout = mksn_rep->mksn_timeout;
965 lstcon_rpc_stat_reply(lstcon_rpc_trans_t *trans, srpc_msg_t *msg,
966 lstcon_node_t *nd, struct lstcon_trans_stat *stat)
968 srpc_rmsn_reply_t *rmsn_rep;
969 srpc_debug_reply_t *dbg_rep;
970 srpc_batch_reply_t *bat_rep;
971 srpc_test_reply_t *test_rep;
972 srpc_stat_reply_t *stat_rep;
975 switch (trans->tas_opc) {
976 case LST_TRANS_SESNEW:
977 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
979 lstcon_sesop_stat_success(stat, 1);
983 lstcon_sesop_stat_failure(stat, 1);
986 case LST_TRANS_SESEND:
987 rmsn_rep = &msg->msg_body.rmsn_reply;
988 /* ESRCH is not an error for end session */
989 if (rmsn_rep->rmsn_status == 0 ||
990 rmsn_rep->rmsn_status == ESRCH) {
991 lstcon_sesop_stat_success(stat, 1);
995 lstcon_sesop_stat_failure(stat, 1);
996 rc = rmsn_rep->rmsn_status;
999 case LST_TRANS_SESQRY:
1000 case LST_TRANS_SESPING:
1001 dbg_rep = &msg->msg_body.dbg_reply;
1003 if (dbg_rep->dbg_status == ESRCH) {
1004 lstcon_sesqry_stat_unknown(stat, 1);
1008 if (lstcon_session_match(dbg_rep->dbg_sid))
1009 lstcon_sesqry_stat_active(stat, 1);
1011 lstcon_sesqry_stat_busy(stat, 1);
1014 case LST_TRANS_TSBRUN:
1015 case LST_TRANS_TSBSTOP:
1016 bat_rep = &msg->msg_body.bat_reply;
1018 if (bat_rep->bar_status == 0) {
1019 lstcon_tsbop_stat_success(stat, 1);
1023 if (bat_rep->bar_status == EPERM &&
1024 trans->tas_opc == LST_TRANS_TSBSTOP) {
1025 lstcon_tsbop_stat_success(stat, 1);
1029 lstcon_tsbop_stat_failure(stat, 1);
1030 rc = bat_rep->bar_status;
1033 case LST_TRANS_TSBCLIQRY:
1034 case LST_TRANS_TSBSRVQRY:
1035 bat_rep = &msg->msg_body.bat_reply;
1037 if (bat_rep->bar_active != 0)
1038 lstcon_tsbqry_stat_run(stat, 1);
1040 lstcon_tsbqry_stat_idle(stat, 1);
1042 if (bat_rep->bar_status == 0)
1045 lstcon_tsbqry_stat_failure(stat, 1);
1046 rc = bat_rep->bar_status;
1049 case LST_TRANS_TSBCLIADD:
1050 case LST_TRANS_TSBSRVADD:
1051 test_rep = &msg->msg_body.tes_reply;
1053 if (test_rep->tsr_status == 0) {
1054 lstcon_tsbop_stat_success(stat, 1);
1058 lstcon_tsbop_stat_failure(stat, 1);
1059 rc = test_rep->tsr_status;
1062 case LST_TRANS_STATQRY:
1063 stat_rep = &msg->msg_body.stat_reply;
1065 if (stat_rep->str_status == 0) {
1066 lstcon_statqry_stat_success(stat, 1);
1070 lstcon_statqry_stat_failure(stat, 1);
1071 rc = stat_rep->str_status;
1078 if (stat->trs_fwk_errno == 0)
1079 stat->trs_fwk_errno = rc;
1085 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1086 struct list_head *translist, int transop,
1087 void *arg, lstcon_rpc_cond_func_t condition,
1088 lstcon_rpc_trans_t **transpp)
1090 lstcon_rpc_trans_t *trans;
1091 lstcon_ndlink_t *ndl;
1097 /* Creating session RPG for list of nodes */
1099 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1101 CERROR("Can't create transaction %d: %d\n", transop, rc);
1105 feats = trans->tas_features;
1106 list_for_each_entry(ndl, ndlist, ndl_link) {
1107 rc = condition == NULL ? 1 :
1108 condition(transop, ndl->ndl_node, arg);
1114 CDEBUG(D_NET, "Condition error while creating RPC "
1115 " for transaction %d: %d\n", transop, rc);
1122 case LST_TRANS_SESNEW:
1123 case LST_TRANS_SESEND:
1124 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1126 case LST_TRANS_SESQRY:
1127 case LST_TRANS_SESPING:
1128 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1130 case LST_TRANS_TSBCLIADD:
1131 case LST_TRANS_TSBSRVADD:
1132 rc = lstcon_testrpc_prep(nd, transop, feats,
1133 (lstcon_test_t *)arg, &rpc);
1135 case LST_TRANS_TSBRUN:
1136 case LST_TRANS_TSBSTOP:
1137 case LST_TRANS_TSBCLIQRY:
1138 case LST_TRANS_TSBSRVQRY:
1139 rc = lstcon_batrpc_prep(nd, transop, feats,
1140 (lstcon_tsb_hdr_t *)arg, &rpc);
1142 case LST_TRANS_STATQRY:
1143 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1151 CERROR("Failed to create RPC for transaction %s: %d\n",
1152 lstcon_rpc_trans_name(transop), rc);
1156 lstcon_rpc_trans_addreq(trans, rpc);
1164 lstcon_rpc_trans_destroy(trans);
1170 lstcon_rpc_pinger(void *arg)
1172 stt_timer_t *ptimer = (stt_timer_t *)arg;
1173 lstcon_rpc_trans_t *trans;
1176 srpc_debug_reqst_t *drq;
1177 lstcon_ndlink_t *ndl;
1183 /* RPC pinger is a special case of transaction,
1184 * it's called by timer at 8 seconds interval.
1186 mutex_lock(&console_session.ses_mutex);
1188 if (console_session.ses_shutdown || console_session.ses_expired) {
1189 mutex_unlock(&console_session.ses_mutex);
1193 if (!console_session.ses_expired &&
1194 ktime_get_real_seconds() - console_session.ses_laststamp >
1195 (time64_t)console_session.ses_timeout)
1196 console_session.ses_expired = 1;
1198 trans = console_session.ses_ping;
1200 LASSERT(trans != NULL);
1202 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1205 if (console_session.ses_expired) {
1206 /* idle console, end session on all nodes */
1207 if (nd->nd_state != LST_NODE_ACTIVE)
1210 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1211 trans->tas_features, &crpc);
1213 CERROR("Out of memory\n");
1217 lstcon_rpc_trans_addreq(trans, crpc);
1218 lstcon_rpc_post(crpc);
1223 crpc = &nd->nd_ping;
1225 if (crpc->crp_rpc != NULL) {
1226 LASSERT(crpc->crp_trans == trans);
1227 LASSERT(!list_empty(&crpc->crp_link));
1229 spin_lock(&crpc->crp_rpc->crpc_lock);
1231 LASSERT(crpc->crp_posted);
1233 if (!crpc->crp_finished) {
1235 spin_unlock(&crpc->crp_rpc->crpc_lock);
1239 spin_unlock(&crpc->crp_rpc->crpc_lock);
1241 lstcon_rpc_get_reply(crpc, &rep);
1243 list_del_init(&crpc->crp_link);
1245 lstcon_rpc_put(crpc);
1248 if (nd->nd_state != LST_NODE_ACTIVE)
1251 intv = cfs_duration_sec(jiffies - nd->nd_stamp);
1252 if (intv < nd->nd_timeout / 2)
1255 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1256 trans->tas_features, 0, 0, 1, crpc);
1258 CERROR("Out of memory\n");
1262 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1264 drq->dbg_sid = console_session.ses_id;
1267 lstcon_rpc_trans_addreq(trans, crpc);
1268 lstcon_rpc_post(crpc);
1273 if (console_session.ses_expired) {
1274 mutex_unlock(&console_session.ses_mutex);
1278 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1280 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1281 stt_add_timer(ptimer);
1283 mutex_unlock(&console_session.ses_mutex);
1287 lstcon_rpc_pinger_start(void)
1289 stt_timer_t *ptimer;
1292 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1293 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1295 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1296 &console_session.ses_ping);
1298 CERROR("Failed to create console pinger\n");
1302 ptimer = &console_session.ses_ping_timer;
1303 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1305 stt_add_timer(ptimer);
1311 lstcon_rpc_pinger_stop(void)
1313 LASSERT (console_session.ses_shutdown);
1315 stt_del_timer(&console_session.ses_ping_timer);
1317 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1318 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1319 lstcon_rpc_trans_destroy(console_session.ses_ping);
1321 memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1323 console_session.ses_ping = NULL;
1327 lstcon_rpc_cleanup_wait(void)
1329 lstcon_rpc_trans_t *trans;
1331 struct list_head *pacer;
1332 struct list_head zlist;
1334 /* Called with hold of global mutex */
1336 LASSERT(console_session.ses_shutdown);
1338 while (!list_empty(&console_session.ses_trans_list)) {
1339 list_for_each(pacer, &console_session.ses_trans_list) {
1340 trans = list_entry(pacer, lstcon_rpc_trans_t,
1343 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1344 lstcon_rpc_trans_name(trans->tas_opc));
1346 wake_up(&trans->tas_waitq);
1349 mutex_unlock(&console_session.ses_mutex);
1351 CWARN("Session is shutting down, "
1352 "waiting for termination of transactions\n");
1353 set_current_state(TASK_UNINTERRUPTIBLE);
1354 schedule_timeout(cfs_time_seconds(1));
1356 mutex_lock(&console_session.ses_mutex);
1359 spin_lock(&console_session.ses_rpc_lock);
1361 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1362 console_session.ses_rpc_lock,
1363 "Network is not accessable or target is down, "
1364 "waiting for %d console RPCs to being recycled\n",
1365 atomic_read(&console_session.ses_rpc_counter));
1367 list_add(&zlist, &console_session.ses_rpc_freelist);
1368 list_del_init(&console_session.ses_rpc_freelist);
1370 spin_unlock(&console_session.ses_rpc_lock);
1372 while (!list_empty(&zlist)) {
1373 crpc = list_entry(zlist.next, lstcon_rpc_t, crp_link);
1375 list_del(&crpc->crp_link);
1376 LIBCFS_FREE(crpc, sizeof(lstcon_rpc_t));
1381 lstcon_rpc_module_init(void)
1383 INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1384 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1385 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1387 console_session.ses_ping = NULL;
1389 spin_lock_init(&console_session.ses_rpc_lock);
1390 atomic_set(&console_session.ses_rpc_counter, 0);
1391 INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1397 lstcon_rpc_module_fini(void)
1399 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1400 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);