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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Console framework rpcs
40 * Author: Liang Zhen <liang@whamcloud.com>
45 #include <libcfs/libcfs.h>
46 #include <lnet/lib-lnet.h>
51 void lstcon_rpc_stat_reply(lstcon_rpc_trans_t *, srpc_msg_t *,
52 lstcon_node_t *, lstcon_trans_stat_t *);
55 lstcon_rpc_done(srpc_client_rpc_t *rpc)
57 lstcon_rpc_t *crpc = (lstcon_rpc_t *)rpc->crpc_priv;
59 LASSERT(crpc != NULL && rpc == crpc->crp_rpc);
60 LASSERT(crpc->crp_posted && !crpc->crp_finished);
62 spin_lock(&rpc->crpc_lock);
64 if (crpc->crp_trans == NULL) {
65 /* Orphan RPC is not in any transaction,
66 * I'm just a poor body and nobody loves me */
67 spin_unlock(&rpc->crpc_lock);
74 /* not an orphan RPC */
75 crpc->crp_finished = 1;
77 if (crpc->crp_stamp == 0) {
79 LASSERT (crpc->crp_status == 0);
81 crpc->crp_stamp = cfs_time_current();
82 crpc->crp_status = rpc->crpc_status;
85 /* wakeup (transaction)thread if I'm the last RPC in the transaction */
86 if (atomic_dec_and_test(&crpc->crp_trans->tas_remaining))
87 wake_up(&crpc->crp_trans->tas_waitq);
89 spin_unlock(&rpc->crpc_lock);
93 lstcon_rpc_init(lstcon_node_t *nd, int service, unsigned feats,
94 int bulk_npg, int bulk_len, int embedded, lstcon_rpc_t *crpc)
96 crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
97 feats, bulk_npg, bulk_len,
98 lstcon_rpc_done, (void *)crpc);
99 if (crpc->crp_rpc == NULL)
102 crpc->crp_trans = NULL;
104 crpc->crp_posted = 0;
105 crpc->crp_finished = 0;
106 crpc->crp_unpacked = 0;
107 crpc->crp_status = 0;
109 crpc->crp_embedded = embedded;
110 INIT_LIST_HEAD(&crpc->crp_link);
112 atomic_inc(&console_session.ses_rpc_counter);
118 lstcon_rpc_prep(lstcon_node_t *nd, int service, unsigned feats,
119 int bulk_npg, int bulk_len, lstcon_rpc_t **crpcpp)
121 lstcon_rpc_t *crpc = NULL;
124 spin_lock(&console_session.ses_rpc_lock);
126 if (!list_empty(&console_session.ses_rpc_freelist)) {
127 crpc = list_entry(console_session.ses_rpc_freelist.next,
128 lstcon_rpc_t, crp_link);
129 list_del_init(&crpc->crp_link);
132 spin_unlock(&console_session.ses_rpc_lock);
135 LIBCFS_ALLOC(crpc, sizeof(*crpc));
140 rc = lstcon_rpc_init(nd, service, feats, bulk_npg, bulk_len, 0, crpc);
146 LIBCFS_FREE(crpc, sizeof(*crpc));
152 lstcon_rpc_put(lstcon_rpc_t *crpc)
154 srpc_bulk_t *bulk = &crpc->crp_rpc->crpc_bulk;
157 LASSERT(list_empty(&crpc->crp_link));
159 for (i = 0; i < bulk->bk_niov; i++) {
160 if (bulk->bk_iovs[i].kiov_page == NULL)
163 __free_page(bulk->bk_iovs[i].kiov_page);
166 srpc_client_rpc_decref(crpc->crp_rpc);
168 if (crpc->crp_embedded) {
169 /* embedded RPC, don't recycle it */
170 memset(crpc, 0, sizeof(*crpc));
171 crpc->crp_embedded = 1;
174 spin_lock(&console_session.ses_rpc_lock);
176 list_add(&crpc->crp_link,
177 &console_session.ses_rpc_freelist);
179 spin_unlock(&console_session.ses_rpc_lock);
182 /* RPC is not alive now */
183 atomic_dec(&console_session.ses_rpc_counter);
187 lstcon_rpc_post(lstcon_rpc_t *crpc)
189 lstcon_rpc_trans_t *trans = crpc->crp_trans;
191 LASSERT (trans != NULL);
193 atomic_inc(&trans->tas_remaining);
194 crpc->crp_posted = 1;
196 sfw_post_rpc(crpc->crp_rpc);
200 lstcon_rpc_trans_name(int transop)
202 if (transop == LST_TRANS_SESNEW)
205 if (transop == LST_TRANS_SESEND)
208 if (transop == LST_TRANS_SESQRY)
211 if (transop == LST_TRANS_SESPING)
214 if (transop == LST_TRANS_TSBCLIADD)
217 if (transop == LST_TRANS_TSBSRVADD)
220 if (transop == LST_TRANS_TSBRUN)
223 if (transop == LST_TRANS_TSBSTOP)
226 if (transop == LST_TRANS_TSBCLIQRY)
229 if (transop == LST_TRANS_TSBSRVQRY)
232 if (transop == LST_TRANS_STATQRY)
239 lstcon_rpc_trans_prep(struct list_head *translist, int transop,
240 lstcon_rpc_trans_t **transpp)
242 lstcon_rpc_trans_t *trans;
244 if (translist != NULL) {
245 list_for_each_entry(trans, translist, tas_link) {
246 /* Can't enqueue two private transaction on
248 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
253 /* create a trans group */
254 LIBCFS_ALLOC(trans, sizeof(*trans));
258 trans->tas_opc = transop;
260 if (translist == NULL)
261 INIT_LIST_HEAD(&trans->tas_olink);
263 list_add_tail(&trans->tas_olink, translist);
265 list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
267 INIT_LIST_HEAD(&trans->tas_rpcs_list);
268 atomic_set(&trans->tas_remaining, 0);
269 init_waitqueue_head(&trans->tas_waitq);
271 spin_lock(&console_session.ses_rpc_lock);
272 trans->tas_features = console_session.ses_features;
273 spin_unlock(&console_session.ses_rpc_lock);
280 lstcon_rpc_trans_addreq(lstcon_rpc_trans_t *trans, lstcon_rpc_t *crpc)
282 list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
283 crpc->crp_trans = trans;
287 lstcon_rpc_trans_abort(lstcon_rpc_trans_t *trans, int error)
289 srpc_client_rpc_t *rpc;
293 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
296 spin_lock(&rpc->crpc_lock);
298 if (!crpc->crp_posted || /* not posted */
299 crpc->crp_stamp != 0) { /* rpc done or aborted already */
300 if (crpc->crp_stamp == 0) {
301 crpc->crp_stamp = cfs_time_current();
302 crpc->crp_status = -EINTR;
304 spin_unlock(&rpc->crpc_lock);
308 crpc->crp_stamp = cfs_time_current();
309 crpc->crp_status = error;
311 spin_unlock(&rpc->crpc_lock);
315 if (error != -ETIMEDOUT)
319 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
322 nd->nd_stamp = crpc->crp_stamp;
323 nd->nd_state = LST_NODE_DOWN;
328 lstcon_rpc_trans_check(lstcon_rpc_trans_t *trans)
330 if (console_session.ses_shutdown &&
331 !list_empty(&trans->tas_olink)) /* Not an end session RPC */
334 return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
338 lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
343 if (list_empty(&trans->tas_rpcs_list))
346 if (timeout < LST_TRANS_MIN_TIMEOUT)
347 timeout = LST_TRANS_MIN_TIMEOUT;
349 CDEBUG(D_NET, "Transaction %s started\n",
350 lstcon_rpc_trans_name(trans->tas_opc));
352 /* post all requests */
353 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
354 LASSERT(!crpc->crp_posted);
356 lstcon_rpc_post(crpc);
359 mutex_unlock(&console_session.ses_mutex);
361 rc = wait_event_interruptible_timeout(trans->tas_waitq,
362 lstcon_rpc_trans_check(trans),
363 cfs_time_seconds(timeout));
365 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
367 mutex_lock(&console_session.ses_mutex);
369 if (console_session.ses_shutdown)
372 if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
373 /* treat short timeout as canceled */
374 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
377 lstcon_rpc_trans_abort(trans, rc);
380 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
381 lstcon_rpc_trans_name(trans->tas_opc), rc);
383 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
389 lstcon_rpc_get_reply(lstcon_rpc_t *crpc, srpc_msg_t **msgpp)
391 lstcon_node_t *nd = crpc->crp_node;
392 srpc_client_rpc_t *rpc = crpc->crp_rpc;
393 srpc_generic_reply_t *rep;
395 LASSERT (nd != NULL && rpc != NULL);
396 LASSERT (crpc->crp_stamp != 0);
398 if (crpc->crp_status != 0) {
400 return crpc->crp_status;
403 *msgpp = &rpc->crpc_replymsg;
404 if (!crpc->crp_unpacked) {
405 sfw_unpack_message(*msgpp);
406 crpc->crp_unpacked = 1;
409 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
412 nd->nd_stamp = crpc->crp_stamp;
413 rep = &(*msgpp)->msg_body.reply;
415 if (rep->sid.ses_nid == LNET_NID_ANY)
416 nd->nd_state = LST_NODE_UNKNOWN;
417 else if (lstcon_session_match(rep->sid))
418 nd->nd_state = LST_NODE_ACTIVE;
420 nd->nd_state = LST_NODE_BUSY;
426 lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
432 LASSERT(stat != NULL);
434 memset(stat, 0, sizeof(*stat));
436 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
437 lstcon_rpc_stat_total(stat, 1);
439 LASSERT(crpc->crp_stamp != 0);
441 error = lstcon_rpc_get_reply(crpc, &rep);
443 lstcon_rpc_stat_failure(stat, 1);
444 if (stat->trs_rpc_errno == 0)
445 stat->trs_rpc_errno = -error;
450 lstcon_rpc_stat_success(stat, 1);
452 lstcon_rpc_stat_reply(trans, rep, crpc->crp_node, stat);
455 if (trans->tas_opc == LST_TRANS_SESNEW && stat->trs_fwk_errno == 0) {
456 stat->trs_fwk_errno =
457 lstcon_session_feats_check(trans->tas_features);
460 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
461 "RPC error(%d), Framework error(%d)\n",
462 lstcon_rpc_trans_name(trans->tas_opc),
463 lstcon_rpc_stat_success(stat, 0),
464 lstcon_rpc_stat_failure(stat, 0),
465 lstcon_rpc_stat_total(stat, 0),
466 stat->trs_rpc_errno, stat->trs_fwk_errno);
472 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
473 struct list_head __user *head_up,
474 lstcon_rpc_readent_func_t readent)
476 struct list_head tmp;
477 struct list_head __user *next;
478 lstcon_rpc_ent_t *ent;
479 srpc_generic_reply_t *rep;
487 LASSERT(head_up != NULL);
491 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
492 if (copy_from_user(&tmp, next,
493 sizeof(struct list_head)))
496 if (tmp.next == head_up)
501 ent = list_entry(next, lstcon_rpc_ent_t, rpe_link);
503 LASSERT(crpc->crp_stamp != 0);
505 error = lstcon_rpc_get_reply(crpc, &msg);
509 dur = (cfs_duration_t)cfs_time_sub(crpc->crp_stamp,
510 (cfs_time_t)console_session.ses_id.ses_stamp);
511 cfs_duration_usec(dur, &tv);
513 if (copy_to_user(&ent->rpe_peer,
514 &nd->nd_id, sizeof(lnet_process_id_t)) ||
515 copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
516 copy_to_user(&ent->rpe_state,
517 &nd->nd_state, sizeof(nd->nd_state)) ||
518 copy_to_user(&ent->rpe_rpc_errno, &error,
526 rep = (srpc_generic_reply_t *)&msg->msg_body.reply;
528 if (copy_to_user(&ent->rpe_sid,
529 &rep->sid, sizeof(lst_sid_t)) ||
530 copy_to_user(&ent->rpe_fwk_errno,
531 &rep->status, sizeof(rep->status)))
537 error = readent(trans->tas_opc, msg, ent);
546 lstcon_rpc_trans_destroy(lstcon_rpc_trans_t *trans)
548 srpc_client_rpc_t *rpc;
553 list_for_each_entry_safe(crpc, tmp, &trans->tas_rpcs_list, crp_link) {
556 spin_lock(&rpc->crpc_lock);
558 /* free it if not posted or finished already */
559 if (!crpc->crp_posted || crpc->crp_finished) {
560 spin_unlock(&rpc->crpc_lock);
562 list_del_init(&crpc->crp_link);
563 lstcon_rpc_put(crpc);
568 /* rpcs can be still not callbacked (even LNetMDUnlink is
569 * called) because huge timeout for inaccessible network,
570 * don't make user wait for them, just abandon them, they
571 * will be recycled in callback */
573 LASSERT(crpc->crp_status != 0);
575 crpc->crp_node = NULL;
576 crpc->crp_trans = NULL;
577 list_del_init(&crpc->crp_link);
580 spin_unlock(&rpc->crpc_lock);
582 atomic_dec(&trans->tas_remaining);
585 LASSERT(atomic_read(&trans->tas_remaining) == 0);
587 list_del(&trans->tas_link);
588 if (!list_empty(&trans->tas_olink))
589 list_del(&trans->tas_olink);
591 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
592 lstcon_rpc_trans_name(trans->tas_opc), count);
594 LIBCFS_FREE(trans, sizeof(*trans));
600 lstcon_sesrpc_prep(lstcon_node_t *nd, int transop,
601 unsigned feats, lstcon_rpc_t **crpc)
603 srpc_mksn_reqst_t *msrq;
604 srpc_rmsn_reqst_t *rsrq;
608 case LST_TRANS_SESNEW:
609 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
614 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
615 msrq->mksn_sid = console_session.ses_id;
616 msrq->mksn_force = console_session.ses_force;
617 strlcpy(msrq->mksn_name, console_session.ses_name,
618 sizeof(msrq->mksn_name));
621 case LST_TRANS_SESEND:
622 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
627 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
628 rsrq->rmsn_sid = console_session.ses_id;
639 lstcon_dbgrpc_prep(lstcon_node_t *nd, unsigned feats, lstcon_rpc_t **crpc)
641 srpc_debug_reqst_t *drq;
644 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
648 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
650 drq->dbg_sid = console_session.ses_id;
657 lstcon_batrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
658 lstcon_tsb_hdr_t *tsb, lstcon_rpc_t **crpc)
660 lstcon_batch_t *batch;
661 srpc_batch_reqst_t *brq;
664 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
668 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
670 brq->bar_sid = console_session.ses_id;
671 brq->bar_bid = tsb->tsb_id;
672 brq->bar_testidx = tsb->tsb_index;
673 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
674 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
675 SRPC_BATCH_OPC_QUERY);
677 if (transop != LST_TRANS_TSBRUN &&
678 transop != LST_TRANS_TSBSTOP)
681 LASSERT (tsb->tsb_index == 0);
683 batch = (lstcon_batch_t *)tsb;
684 brq->bar_arg = batch->bat_arg;
690 lstcon_statrpc_prep(lstcon_node_t *nd, unsigned feats, lstcon_rpc_t **crpc)
692 srpc_stat_reqst_t *srq;
695 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
699 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
701 srq->str_sid = console_session.ses_id;
702 srq->str_type = 0; /* XXX remove it */
707 static lnet_process_id_packed_t *
708 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
710 lnet_process_id_packed_t *pid;
713 i = idx / SFW_ID_PER_PAGE;
717 pid = (lnet_process_id_packed_t *)page_address(kiov[i].kiov_page);
719 return &pid[idx % SFW_ID_PER_PAGE];
723 lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
724 int dist, int span, int nkiov, lnet_kiov_t *kiov)
726 lnet_process_id_packed_t *pid;
727 lstcon_ndlink_t *ndl;
735 LASSERT (grp->grp_nnode >= 1);
737 if (span > grp->grp_nnode)
740 start = ((idx / dist) * span) % grp->grp_nnode;
741 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
743 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
750 if (i > (end >= start ? end : grp->grp_nnode))
753 pid = lstcon_next_id((i - start), nkiov, kiov);
754 pid->nid = nd->nd_id.nid;
755 pid->pid = nd->nd_id.pid;
759 if (start <= end) /* done */
762 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
763 if (i > grp->grp_nnode + end)
767 pid = lstcon_next_id((i - start), nkiov, kiov);
768 pid->nid = nd->nd_id.nid;
769 pid->pid = nd->nd_id.pid;
777 lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req)
779 test_ping_req_t *prq = &req->tsr_u.ping;
781 prq->png_size = param->png_size;
782 prq->png_flags = param->png_flags;
788 lstcon_bulkrpc_v0_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
790 test_bulk_req_t *brq = &req->tsr_u.bulk_v0;
792 brq->blk_opc = param->blk_opc;
793 brq->blk_npg = (param->blk_size + PAGE_CACHE_SIZE - 1) /
795 brq->blk_flags = param->blk_flags;
801 lstcon_bulkrpc_v1_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
803 test_bulk_req_v1_t *brq = &req->tsr_u.bulk_v1;
805 brq->blk_opc = param->blk_opc;
806 brq->blk_flags = param->blk_flags;
807 brq->blk_len = param->blk_size;
808 brq->blk_offset = 0; /* reserved */
814 lstcon_testrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
815 lstcon_test_t *test, lstcon_rpc_t **crpc)
817 lstcon_group_t *sgrp = test->tes_src_grp;
818 lstcon_group_t *dgrp = test->tes_dst_grp;
819 srpc_test_reqst_t *trq;
826 if (transop == LST_TRANS_TSBCLIADD) {
827 npg = sfw_id_pages(test->tes_span);
828 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
829 npg * PAGE_CACHE_SIZE :
830 sizeof(lnet_process_id_packed_t) * test->tes_span;
833 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
837 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
839 if (transop == LST_TRANS_TSBSRVADD) {
840 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
841 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
842 int nmax = (ndist + nspan - 1) / nspan;
845 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
848 bulk = &(*crpc)->crp_rpc->crpc_bulk;
850 for (i = 0; i < npg; i++) {
855 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
856 PAGE_CACHE_SIZE : min_t(int, nob, PAGE_CACHE_SIZE);
859 bulk->bk_iovs[i].kiov_offset = 0;
860 bulk->bk_iovs[i].kiov_len = len;
861 bulk->bk_iovs[i].kiov_page =
862 alloc_page(GFP_IOFS);
864 if (bulk->bk_iovs[i].kiov_page == NULL) {
865 lstcon_rpc_put(*crpc);
872 LASSERT (transop == LST_TRANS_TSBCLIADD);
874 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
878 npg, &bulk->bk_iovs[0]);
880 lstcon_rpc_put(*crpc);
884 trq->tsr_ndest = test->tes_span;
885 trq->tsr_loop = test->tes_loop;
888 trq->tsr_sid = console_session.ses_id;
889 trq->tsr_bid = test->tes_hdr.tsb_id;
890 trq->tsr_concur = test->tes_concur;
891 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
892 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
894 switch (test->tes_type) {
896 trq->tsr_service = SRPC_SERVICE_PING;
897 rc = lstcon_pingrpc_prep((lst_test_ping_param_t *)
898 &test->tes_param[0], trq);
902 trq->tsr_service = SRPC_SERVICE_BRW;
903 if ((feats & LST_FEAT_BULK_LEN) == 0) {
904 rc = lstcon_bulkrpc_v0_prep((lst_test_bulk_param_t *)
905 &test->tes_param[0], trq);
907 rc = lstcon_bulkrpc_v1_prep((lst_test_bulk_param_t *)
908 &test->tes_param[0], trq);
921 lstcon_sesnew_stat_reply(lstcon_rpc_trans_t *trans,
922 lstcon_node_t *nd, srpc_msg_t *reply)
924 srpc_mksn_reply_t *mksn_rep = &reply->msg_body.mksn_reply;
925 int status = mksn_rep->mksn_status;
928 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
929 mksn_rep->mksn_status = EPROTO;
933 if (status == EPROTO) {
934 CNETERR("session protocol error from %s: %u\n",
935 libcfs_nid2str(nd->nd_id.nid),
936 reply->msg_ses_feats);
942 if (!trans->tas_feats_updated) {
943 spin_lock(&console_session.ses_rpc_lock);
944 if (!trans->tas_feats_updated) { /* recheck with lock */
945 trans->tas_feats_updated = 1;
946 trans->tas_features = reply->msg_ses_feats;
948 spin_unlock(&console_session.ses_rpc_lock);
951 if (reply->msg_ses_feats != trans->tas_features) {
952 CNETERR("Framework features %x from %s is different with "
953 "features on this transaction: %x\n",
954 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
955 trans->tas_features);
956 status = mksn_rep->mksn_status = EPROTO;
960 /* session timeout on remote node */
961 nd->nd_timeout = mksn_rep->mksn_timeout;
968 lstcon_rpc_stat_reply(lstcon_rpc_trans_t *trans, srpc_msg_t *msg,
969 lstcon_node_t *nd, lstcon_trans_stat_t *stat)
971 srpc_rmsn_reply_t *rmsn_rep;
972 srpc_debug_reply_t *dbg_rep;
973 srpc_batch_reply_t *bat_rep;
974 srpc_test_reply_t *test_rep;
975 srpc_stat_reply_t *stat_rep;
978 switch (trans->tas_opc) {
979 case LST_TRANS_SESNEW:
980 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
982 lstcon_sesop_stat_success(stat, 1);
986 lstcon_sesop_stat_failure(stat, 1);
989 case LST_TRANS_SESEND:
990 rmsn_rep = &msg->msg_body.rmsn_reply;
991 /* ESRCH is not an error for end session */
992 if (rmsn_rep->rmsn_status == 0 ||
993 rmsn_rep->rmsn_status == ESRCH) {
994 lstcon_sesop_stat_success(stat, 1);
998 lstcon_sesop_stat_failure(stat, 1);
999 rc = rmsn_rep->rmsn_status;
1002 case LST_TRANS_SESQRY:
1003 case LST_TRANS_SESPING:
1004 dbg_rep = &msg->msg_body.dbg_reply;
1006 if (dbg_rep->dbg_status == ESRCH) {
1007 lstcon_sesqry_stat_unknown(stat, 1);
1011 if (lstcon_session_match(dbg_rep->dbg_sid))
1012 lstcon_sesqry_stat_active(stat, 1);
1014 lstcon_sesqry_stat_busy(stat, 1);
1017 case LST_TRANS_TSBRUN:
1018 case LST_TRANS_TSBSTOP:
1019 bat_rep = &msg->msg_body.bat_reply;
1021 if (bat_rep->bar_status == 0) {
1022 lstcon_tsbop_stat_success(stat, 1);
1026 if (bat_rep->bar_status == EPERM &&
1027 trans->tas_opc == LST_TRANS_TSBSTOP) {
1028 lstcon_tsbop_stat_success(stat, 1);
1032 lstcon_tsbop_stat_failure(stat, 1);
1033 rc = bat_rep->bar_status;
1036 case LST_TRANS_TSBCLIQRY:
1037 case LST_TRANS_TSBSRVQRY:
1038 bat_rep = &msg->msg_body.bat_reply;
1040 if (bat_rep->bar_active != 0)
1041 lstcon_tsbqry_stat_run(stat, 1);
1043 lstcon_tsbqry_stat_idle(stat, 1);
1045 if (bat_rep->bar_status == 0)
1048 lstcon_tsbqry_stat_failure(stat, 1);
1049 rc = bat_rep->bar_status;
1052 case LST_TRANS_TSBCLIADD:
1053 case LST_TRANS_TSBSRVADD:
1054 test_rep = &msg->msg_body.tes_reply;
1056 if (test_rep->tsr_status == 0) {
1057 lstcon_tsbop_stat_success(stat, 1);
1061 lstcon_tsbop_stat_failure(stat, 1);
1062 rc = test_rep->tsr_status;
1065 case LST_TRANS_STATQRY:
1066 stat_rep = &msg->msg_body.stat_reply;
1068 if (stat_rep->str_status == 0) {
1069 lstcon_statqry_stat_success(stat, 1);
1073 lstcon_statqry_stat_failure(stat, 1);
1074 rc = stat_rep->str_status;
1081 if (stat->trs_fwk_errno == 0)
1082 stat->trs_fwk_errno = rc;
1088 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1089 struct list_head *translist, int transop,
1090 void *arg, lstcon_rpc_cond_func_t condition,
1091 lstcon_rpc_trans_t **transpp)
1093 lstcon_rpc_trans_t *trans;
1094 lstcon_ndlink_t *ndl;
1100 /* Creating session RPG for list of nodes */
1102 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1104 CERROR("Can't create transaction %d: %d\n", transop, rc);
1108 feats = trans->tas_features;
1109 list_for_each_entry(ndl, ndlist, ndl_link) {
1110 rc = condition == NULL ? 1 :
1111 condition(transop, ndl->ndl_node, arg);
1117 CDEBUG(D_NET, "Condition error while creating RPC "
1118 " for transaction %d: %d\n", transop, rc);
1125 case LST_TRANS_SESNEW:
1126 case LST_TRANS_SESEND:
1127 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1129 case LST_TRANS_SESQRY:
1130 case LST_TRANS_SESPING:
1131 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1133 case LST_TRANS_TSBCLIADD:
1134 case LST_TRANS_TSBSRVADD:
1135 rc = lstcon_testrpc_prep(nd, transop, feats,
1136 (lstcon_test_t *)arg, &rpc);
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 (lstcon_tsb_hdr_t *)arg, &rpc);
1145 case LST_TRANS_STATQRY:
1146 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1154 CERROR("Failed to create RPC for transaction %s: %d\n",
1155 lstcon_rpc_trans_name(transop), rc);
1159 lstcon_rpc_trans_addreq(trans, rpc);
1167 lstcon_rpc_trans_destroy(trans);
1173 lstcon_rpc_pinger(void *arg)
1175 stt_timer_t *ptimer = (stt_timer_t *)arg;
1176 lstcon_rpc_trans_t *trans;
1179 srpc_debug_reqst_t *drq;
1180 lstcon_ndlink_t *ndl;
1186 /* RPC pinger is a special case of transaction,
1187 * it's called by timer at 8 seconds interval.
1189 mutex_lock(&console_session.ses_mutex);
1191 if (console_session.ses_shutdown || console_session.ses_expired) {
1192 mutex_unlock(&console_session.ses_mutex);
1196 if (!console_session.ses_expired &&
1197 cfs_time_current_sec() - console_session.ses_laststamp >
1198 (time_t)console_session.ses_timeout)
1199 console_session.ses_expired = 1;
1201 trans = console_session.ses_ping;
1203 LASSERT(trans != NULL);
1205 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1208 if (console_session.ses_expired) {
1209 /* idle console, end session on all nodes */
1210 if (nd->nd_state != LST_NODE_ACTIVE)
1213 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1214 trans->tas_features, &crpc);
1216 CERROR("Out of memory\n");
1220 lstcon_rpc_trans_addreq(trans, crpc);
1221 lstcon_rpc_post(crpc);
1226 crpc = &nd->nd_ping;
1228 if (crpc->crp_rpc != NULL) {
1229 LASSERT(crpc->crp_trans == trans);
1230 LASSERT(!list_empty(&crpc->crp_link));
1232 spin_lock(&crpc->crp_rpc->crpc_lock);
1234 LASSERT(crpc->crp_posted);
1236 if (!crpc->crp_finished) {
1238 spin_unlock(&crpc->crp_rpc->crpc_lock);
1242 spin_unlock(&crpc->crp_rpc->crpc_lock);
1244 lstcon_rpc_get_reply(crpc, &rep);
1246 list_del_init(&crpc->crp_link);
1248 lstcon_rpc_put(crpc);
1251 if (nd->nd_state != LST_NODE_ACTIVE)
1254 intv = cfs_duration_sec(cfs_time_sub(cfs_time_current(),
1256 if (intv < (time_t)nd->nd_timeout / 2)
1259 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1260 trans->tas_features, 0, 0, 1, crpc);
1262 CERROR("Out of memory\n");
1266 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1268 drq->dbg_sid = console_session.ses_id;
1271 lstcon_rpc_trans_addreq(trans, crpc);
1272 lstcon_rpc_post(crpc);
1277 if (console_session.ses_expired) {
1278 mutex_unlock(&console_session.ses_mutex);
1282 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1284 ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
1285 stt_add_timer(ptimer);
1287 mutex_unlock(&console_session.ses_mutex);
1291 lstcon_rpc_pinger_start(void)
1293 stt_timer_t *ptimer;
1296 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1297 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1299 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1300 &console_session.ses_ping);
1302 CERROR("Failed to create console pinger\n");
1306 ptimer = &console_session.ses_ping_timer;
1307 ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
1309 stt_add_timer(ptimer);
1315 lstcon_rpc_pinger_stop(void)
1317 LASSERT (console_session.ses_shutdown);
1319 stt_del_timer(&console_session.ses_ping_timer);
1321 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1322 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1323 lstcon_rpc_trans_destroy(console_session.ses_ping);
1325 memset(lstcon_trans_stat(), 0, sizeof(lstcon_trans_stat_t));
1327 console_session.ses_ping = NULL;
1331 lstcon_rpc_cleanup_wait(void)
1333 lstcon_rpc_trans_t *trans;
1335 struct list_head *pacer;
1336 struct list_head zlist;
1338 /* Called with hold of global mutex */
1340 LASSERT(console_session.ses_shutdown);
1342 while (!list_empty(&console_session.ses_trans_list)) {
1343 list_for_each(pacer, &console_session.ses_trans_list) {
1344 trans = list_entry(pacer, lstcon_rpc_trans_t,
1347 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1348 lstcon_rpc_trans_name(trans->tas_opc));
1350 wake_up(&trans->tas_waitq);
1353 mutex_unlock(&console_session.ses_mutex);
1355 CWARN("Session is shutting down, "
1356 "waiting for termination of transactions\n");
1357 cfs_pause(cfs_time_seconds(1));
1359 mutex_lock(&console_session.ses_mutex);
1362 spin_lock(&console_session.ses_rpc_lock);
1364 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1365 console_session.ses_rpc_lock,
1366 "Network is not accessable or target is down, "
1367 "waiting for %d console RPCs to being recycled\n",
1368 atomic_read(&console_session.ses_rpc_counter));
1370 list_add(&zlist, &console_session.ses_rpc_freelist);
1371 list_del_init(&console_session.ses_rpc_freelist);
1373 spin_unlock(&console_session.ses_rpc_lock);
1375 while (!list_empty(&zlist)) {
1376 crpc = list_entry(zlist.next, lstcon_rpc_t, crp_link);
1378 list_del(&crpc->crp_link);
1379 LIBCFS_FREE(crpc, sizeof(lstcon_rpc_t));
1384 lstcon_rpc_module_init(void)
1386 INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1387 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1388 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1390 console_session.ses_ping = NULL;
1392 spin_lock_init(&console_session.ses_rpc_lock);
1393 atomic_set(&console_session.ses_rpc_counter, 0);
1394 INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1400 lstcon_rpc_module_fini(void)
1402 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1403 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);