Whamcloud - gitweb
LU-9019 target: migrate to 64 bit time
[fs/lustre-release.git] / lnet / selftest / conrpc.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lnet/selftest/conctl.c
33  *
34  * Console framework rpcs
35  *
36  * Author: Liang Zhen <liang@whamcloud.com>
37  */
38
39
40 #include <libcfs/libcfs.h>
41 #include <lnet/lib-lnet.h>
42 #include "timer.h"
43 #include "conrpc.h"
44 #include "console.h"
45
46 void lstcon_rpc_stat_reply(struct lstcon_rpc_trans *, struct srpc_msg *,
47                            struct lstcon_node *, struct lstcon_trans_stat *);
48
49 static void
50 lstcon_rpc_done(struct srpc_client_rpc *rpc)
51 {
52         struct lstcon_rpc *crpc = rpc->crpc_priv;
53
54         LASSERT(crpc != NULL && rpc == crpc->crp_rpc);
55         LASSERT(crpc->crp_posted && !crpc->crp_finished);
56
57         spin_lock(&rpc->crpc_lock);
58
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);
63
64                 /* release it */
65                 lstcon_rpc_put(crpc);
66                 return;
67         }
68
69         /* not an orphan RPC */
70         crpc->crp_finished = 1;
71
72         if (crpc->crp_stamp == 0) {
73                 /* not aborted */
74                 LASSERT (crpc->crp_status == 0);
75
76                 crpc->crp_stamp  = cfs_time_current();
77                 crpc->crp_status = rpc->crpc_status;
78         }
79
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);
83
84         spin_unlock(&rpc->crpc_lock);
85 }
86
87 static int
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)
91 {
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)
96                 return -ENOMEM;
97
98         crpc->crp_trans    = NULL;
99         crpc->crp_node     = nd;
100         crpc->crp_posted   = 0;
101         crpc->crp_finished = 0;
102         crpc->crp_unpacked = 0;
103         crpc->crp_status   = 0;
104         crpc->crp_stamp    = 0;
105         crpc->crp_embedded = embedded;
106         INIT_LIST_HEAD(&crpc->crp_link);
107
108         atomic_inc(&console_session.ses_rpc_counter);
109
110         return 0;
111 }
112
113 static int
114 lstcon_rpc_prep(struct lstcon_node *nd, int service, unsigned int feats,
115                 int bulk_npg, int bulk_len, struct lstcon_rpc **crpcpp)
116 {
117         struct lstcon_rpc *crpc = NULL;
118         int rc;
119
120         spin_lock(&console_session.ses_rpc_lock);
121
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);
126         }
127
128         spin_unlock(&console_session.ses_rpc_lock);
129
130         if (crpc == NULL) {
131                 LIBCFS_ALLOC(crpc, sizeof(*crpc));
132                 if (crpc == NULL)
133                         return -ENOMEM;
134         }
135
136         rc = lstcon_rpc_init(nd, service, feats, bulk_npg, bulk_len, 0, crpc);
137         if (rc == 0) {
138                 *crpcpp = crpc;
139                 return 0;
140         }
141
142         LIBCFS_FREE(crpc, sizeof(*crpc));
143
144         return rc;
145 }
146
147 void
148 lstcon_rpc_put(struct lstcon_rpc *crpc)
149 {
150         struct srpc_bulk *bulk = &crpc->crp_rpc->crpc_bulk;
151         int i;
152
153         LASSERT(list_empty(&crpc->crp_link));
154
155         for (i = 0; i < bulk->bk_niov; i++) {
156                 if (bulk->bk_iovs[i].kiov_page == NULL)
157                         continue;
158
159                 __free_page(bulk->bk_iovs[i].kiov_page);
160         }
161
162         srpc_client_rpc_decref(crpc->crp_rpc);
163
164         if (crpc->crp_embedded) {
165                 /* embedded RPC, don't recycle it */
166                 memset(crpc, 0, sizeof(*crpc));
167                 crpc->crp_embedded = 1;
168
169         } else {
170                 spin_lock(&console_session.ses_rpc_lock);
171
172                 list_add(&crpc->crp_link,
173                          &console_session.ses_rpc_freelist);
174
175                 spin_unlock(&console_session.ses_rpc_lock);
176         }
177
178         /* RPC is not alive now */
179         atomic_dec(&console_session.ses_rpc_counter);
180 }
181
182 static void
183 lstcon_rpc_post(struct lstcon_rpc *crpc)
184 {
185         struct lstcon_rpc_trans *trans = crpc->crp_trans;
186
187         LASSERT (trans != NULL);
188
189         atomic_inc(&trans->tas_remaining);
190         crpc->crp_posted = 1;
191
192         sfw_post_rpc(crpc->crp_rpc);
193 }
194
195 static char *
196 lstcon_rpc_trans_name(int transop)
197 {
198         if (transop == LST_TRANS_SESNEW)
199                 return "SESNEW";
200
201         if (transop == LST_TRANS_SESEND)
202                 return "SESEND";
203
204         if (transop == LST_TRANS_SESQRY)
205                 return "SESQRY";
206
207         if (transop == LST_TRANS_SESPING)
208                 return "SESPING";
209
210         if (transop == LST_TRANS_TSBCLIADD)
211                 return "TSBCLIADD";
212
213         if (transop == LST_TRANS_TSBSRVADD)
214                 return "TSBSRVADD";
215
216         if (transop == LST_TRANS_TSBRUN)
217                 return "TSBRUN";
218
219         if (transop == LST_TRANS_TSBSTOP)
220                 return "TSBSTOP";
221
222         if (transop == LST_TRANS_TSBCLIQRY)
223                 return "TSBCLIQRY";
224
225         if (transop == LST_TRANS_TSBSRVQRY)
226                 return "TSBSRVQRY";
227
228         if (transop == LST_TRANS_STATQRY)
229                 return "STATQRY";
230
231         return "Unknown";
232 }
233
234 int
235 lstcon_rpc_trans_prep(struct list_head *translist, int transop,
236                       struct lstcon_rpc_trans **transpp)
237 {
238         struct lstcon_rpc_trans *trans;
239
240         if (translist != NULL) {
241                 list_for_each_entry(trans, translist, tas_link) {
242                         /* Can't enqueue two private transaction on
243                          * the same object */
244                         if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
245                                 return -EPERM;
246                 }
247         }
248
249         /* create a trans group */
250         LIBCFS_ALLOC(trans, sizeof(*trans));
251         if (trans == NULL)
252                 return -ENOMEM;
253
254         trans->tas_opc = transop;
255
256         if (translist == NULL)
257                 INIT_LIST_HEAD(&trans->tas_olink);
258         else
259                 list_add_tail(&trans->tas_olink, translist);
260
261         list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
262
263         INIT_LIST_HEAD(&trans->tas_rpcs_list);
264         atomic_set(&trans->tas_remaining, 0);
265         init_waitqueue_head(&trans->tas_waitq);
266
267         spin_lock(&console_session.ses_rpc_lock);
268         trans->tas_features = console_session.ses_features;
269         spin_unlock(&console_session.ses_rpc_lock);
270
271         *transpp = trans;
272         return 0;
273 }
274
275 void
276 lstcon_rpc_trans_addreq(struct lstcon_rpc_trans *trans, struct lstcon_rpc *crpc)
277 {
278         list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
279         crpc->crp_trans = trans;
280 }
281
282 void
283 lstcon_rpc_trans_abort(struct lstcon_rpc_trans *trans, int error)
284 {
285         struct srpc_client_rpc *rpc;
286         struct lstcon_rpc *crpc;
287         struct lstcon_node *nd;
288
289         list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
290                 rpc = crpc->crp_rpc;
291
292                 spin_lock(&rpc->crpc_lock);
293
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;
299                         }
300                         spin_unlock(&rpc->crpc_lock);
301                         continue;
302                 }
303
304                 crpc->crp_stamp  = cfs_time_current();
305                 crpc->crp_status = error;
306
307                 spin_unlock(&rpc->crpc_lock);
308
309                 sfw_abort_rpc(rpc);
310
311                 if (error != -ETIMEDOUT)
312                         continue;
313
314                 nd = crpc->crp_node;
315                 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
316                         continue;
317
318                 nd->nd_stamp = crpc->crp_stamp;
319                 nd->nd_state = LST_NODE_DOWN;
320         }
321 }
322
323 static int
324 lstcon_rpc_trans_check(struct lstcon_rpc_trans *trans)
325 {
326         if (console_session.ses_shutdown &&
327             !list_empty(&trans->tas_olink)) /* Not an end session RPC */
328                 return 1;
329
330         return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
331 }
332
333 int
334 lstcon_rpc_trans_postwait(struct lstcon_rpc_trans *trans, int timeout)
335 {
336         struct lstcon_rpc *crpc;
337         int rc;
338
339         if (list_empty(&trans->tas_rpcs_list))
340                 return 0;
341
342         if (timeout < LST_TRANS_MIN_TIMEOUT)
343                 timeout = LST_TRANS_MIN_TIMEOUT;
344
345         CDEBUG(D_NET, "Transaction %s started\n",
346         lstcon_rpc_trans_name(trans->tas_opc));
347
348         /* post all requests */
349         list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
350                 LASSERT(!crpc->crp_posted);
351
352                 lstcon_rpc_post(crpc);
353         }
354
355         mutex_unlock(&console_session.ses_mutex);
356
357         rc = wait_event_interruptible_timeout(trans->tas_waitq,
358                                               lstcon_rpc_trans_check(trans),
359                                               cfs_time_seconds(timeout));
360
361         rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
362
363         mutex_lock(&console_session.ses_mutex);
364
365         if (console_session.ses_shutdown)
366                 rc = -ESHUTDOWN;
367
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)
371                         rc = -EINTR;
372
373                 lstcon_rpc_trans_abort(trans, rc);
374         }
375
376         CDEBUG(D_NET, "Transaction %s stopped: %d\n",
377                lstcon_rpc_trans_name(trans->tas_opc), rc);
378
379         lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
380
381         return rc;
382 }
383
384 static int
385 lstcon_rpc_get_reply(struct lstcon_rpc *crpc, struct srpc_msg **msgpp)
386 {
387         struct lstcon_node *nd = crpc->crp_node;
388         struct srpc_client_rpc *rpc = crpc->crp_rpc;
389         struct srpc_generic_reply *rep;
390
391         LASSERT (nd != NULL && rpc != NULL);
392         LASSERT (crpc->crp_stamp != 0);
393
394         if (crpc->crp_status != 0) {
395                 *msgpp = NULL;
396                 return crpc->crp_status;
397         }
398
399         *msgpp = &rpc->crpc_replymsg;
400         if (!crpc->crp_unpacked) {
401                 sfw_unpack_message(*msgpp);
402                 crpc->crp_unpacked = 1;
403         }
404
405         if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
406                 return 0;
407
408         nd->nd_stamp = crpc->crp_stamp;
409         rep = &(*msgpp)->msg_body.reply;
410
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;
415         else
416                 nd->nd_state = LST_NODE_BUSY;
417
418         return 0;
419 }
420
421 void
422 lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans,
423                       struct lstcon_trans_stat *stat)
424 {
425         struct lstcon_rpc *crpc;
426         struct srpc_msg *rep;
427         int error;
428
429         LASSERT(stat != NULL);
430
431         memset(stat, 0, sizeof(*stat));
432
433         list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
434                 lstcon_rpc_stat_total(stat, 1);
435
436                 LASSERT(crpc->crp_stamp != 0);
437
438                 error = lstcon_rpc_get_reply(crpc, &rep);
439                 if (error != 0) {
440                         lstcon_rpc_stat_failure(stat, 1);
441                         if (stat->trs_rpc_errno == 0)
442                                 stat->trs_rpc_errno = -error;
443
444                         continue;
445                 }
446
447                 lstcon_rpc_stat_success(stat, 1);
448
449                 lstcon_rpc_stat_reply(trans, rep, crpc->crp_node, stat);
450         }
451
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);
455         }
456
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);
464
465         return;
466 }
467
468 int
469 lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
470                              struct list_head __user *head_up,
471                              lstcon_rpc_readent_func_t readent)
472 {
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;
480         cfs_duration_t dur;
481         struct timeval tv;
482         int error;
483
484         LASSERT(head_up != NULL);
485
486         next = head_up;
487
488         list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
489                 if (copy_from_user(&tmp, next,
490                                    sizeof(struct list_head)))
491                         return -EFAULT;
492
493                 if (tmp.next == head_up)
494                         return 0;
495
496                 next = tmp.next;
497
498                 ent = list_entry(next, struct lstcon_rpc_ent, rpe_link);
499
500                 LASSERT(crpc->crp_stamp != 0);
501
502                 error = lstcon_rpc_get_reply(crpc, &msg);
503
504                 nd = crpc->crp_node;
505
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);
509
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,
516                                      sizeof(error)))
517                         return -EFAULT;
518
519                 if (error != 0)
520                         continue;
521
522                 /* RPC is done */
523                 rep = (struct srpc_generic_reply *)&msg->msg_body.reply;
524
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)))
529                         return -EFAULT;
530
531                 if (readent == NULL)
532                         continue;
533
534                 error = readent(trans->tas_opc, msg, ent);
535                 if (error != 0)
536                         return error;
537         }
538
539         return 0;
540 }
541
542 void
543 lstcon_rpc_trans_destroy(struct lstcon_rpc_trans *trans)
544 {
545         struct srpc_client_rpc *rpc;
546         struct lstcon_rpc *crpc;
547         struct lstcon_rpc *tmp;
548         int count = 0;
549
550         list_for_each_entry_safe(crpc, tmp, &trans->tas_rpcs_list, crp_link) {
551                 rpc = crpc->crp_rpc;
552
553                 spin_lock(&rpc->crpc_lock);
554
555                 /* free it if not posted or finished already */
556                 if (!crpc->crp_posted || crpc->crp_finished) {
557                         spin_unlock(&rpc->crpc_lock);
558
559                         list_del_init(&crpc->crp_link);
560                         lstcon_rpc_put(crpc);
561
562                         continue;
563                 }
564
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 */
569
570                 LASSERT(crpc->crp_status != 0);
571
572                 crpc->crp_node  = NULL;
573                 crpc->crp_trans = NULL;
574                 list_del_init(&crpc->crp_link);
575                 count++;
576
577                 spin_unlock(&rpc->crpc_lock);
578
579                 atomic_dec(&trans->tas_remaining);
580         }
581
582         LASSERT(atomic_read(&trans->tas_remaining) == 0);
583
584         list_del(&trans->tas_link);
585         if (!list_empty(&trans->tas_olink))
586                 list_del(&trans->tas_olink);
587
588         CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
589                lstcon_rpc_trans_name(trans->tas_opc), count);
590
591         LIBCFS_FREE(trans, sizeof(*trans));
592
593         return;
594 }
595
596 int
597 lstcon_sesrpc_prep(struct lstcon_node *nd, int transop,
598                    unsigned int feats, struct lstcon_rpc **crpc)
599 {
600         struct srpc_mksn_reqst *msrq;
601         struct srpc_rmsn_reqst *rsrq;
602         int rc;
603
604         switch (transop) {
605         case LST_TRANS_SESNEW:
606                 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
607                                      feats, 0, 0, crpc);
608                 if (rc != 0)
609                         return rc;
610
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));
616                 break;
617
618         case LST_TRANS_SESEND:
619                 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
620                                      feats, 0, 0, crpc);
621                 if (rc != 0)
622                         return rc;
623
624                 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
625                 rsrq->rmsn_sid = console_session.ses_id;
626                 break;
627
628         default:
629                 LBUG();
630         }
631
632         return 0;
633 }
634
635 int
636 lstcon_dbgrpc_prep(struct lstcon_node *nd, unsigned int feats,
637                    struct lstcon_rpc **crpc)
638 {
639         struct srpc_debug_reqst *drq;
640         int rc;
641
642         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
643         if (rc != 0)
644                 return rc;
645
646         drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
647
648         drq->dbg_sid   = console_session.ses_id;
649         drq->dbg_flags = 0;
650
651         return rc;
652 }
653
654 int
655 lstcon_batrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
656                    struct lstcon_tsb_hdr *tsb, struct lstcon_rpc **crpc)
657 {
658         struct lstcon_batch *batch;
659         struct srpc_batch_reqst *brq;
660         int rc;
661
662         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
663         if (rc != 0)
664                 return rc;
665
666         brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
667
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);
674
675         if (transop != LST_TRANS_TSBRUN &&
676             transop != LST_TRANS_TSBSTOP)
677                 return 0;
678
679         LASSERT (tsb->tsb_index == 0);
680
681         batch = (struct lstcon_batch *)tsb;
682         brq->bar_arg = batch->bat_arg;
683
684         return 0;
685 }
686
687 int
688 lstcon_statrpc_prep(struct lstcon_node *nd, unsigned int feats,
689                     struct lstcon_rpc **crpc)
690 {
691         struct srpc_stat_reqst *srq;
692         int rc;
693
694         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
695         if (rc != 0)
696                 return rc;
697
698         srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
699
700         srq->str_sid  = console_session.ses_id;
701         srq->str_type = 0; /* XXX remove it */
702
703         return 0;
704 }
705
706 static struct lnet_process_id_packed *
707 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
708 {
709         struct lnet_process_id_packed *pid;
710         int                       i;
711
712         i = idx / SFW_ID_PER_PAGE;
713
714         LASSERT (i < nkiov);
715
716         pid = (struct lnet_process_id_packed *)page_address(kiov[i].kiov_page);
717
718         return &pid[idx % SFW_ID_PER_PAGE];
719 }
720
721 static int
722 lstcon_dstnodes_prep(struct lstcon_group *grp, int idx,
723                      int dist, int span, int nkiov, lnet_kiov_t *kiov)
724 {
725         struct lnet_process_id_packed *pid;
726         struct lstcon_ndlink *ndl;
727         struct lstcon_node *nd;
728         int start;
729         int end;
730         int i = 0;
731
732         LASSERT (dist >= 1);
733         LASSERT (span >= 1);
734         LASSERT (grp->grp_nnode >= 1);
735
736         if (span > grp->grp_nnode)
737                 return -EINVAL;
738
739         start = ((idx / dist) * span) % grp->grp_nnode;
740         end   = ((idx / dist) * span + span - 1) % grp->grp_nnode;
741
742         list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
743                 nd = ndl->ndl_node;
744                 if (i < start) {
745                         i++;
746                         continue;
747                 }
748
749                 if (i > (end >= start ? end : grp->grp_nnode))
750                         break;
751
752                 pid = lstcon_next_id((i - start), nkiov, kiov);
753                 pid->nid = nd->nd_id.nid;
754                 pid->pid = nd->nd_id.pid;
755                 i++;
756         }
757
758         if (start <= end)       /* done */
759                 return 0;
760
761         list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
762                 if (i > grp->grp_nnode + end)
763                         break;
764
765                 nd = ndl->ndl_node;
766                 pid = lstcon_next_id((i - start), nkiov, kiov);
767                 pid->nid = nd->nd_id.nid;
768                 pid->pid = nd->nd_id.pid;
769                 i++;
770         }
771
772         return 0;
773 }
774
775 static int
776 lstcon_pingrpc_prep(struct lst_test_ping_param *param,
777                     struct srpc_test_reqst *req)
778 {
779         struct test_ping_req *prq = &req->tsr_u.ping;
780
781         prq->png_size   = param->png_size;
782         prq->png_flags  = param->png_flags;
783         /* TODO dest */
784         return 0;
785 }
786
787 static int
788 lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param,
789                        struct srpc_test_reqst *req)
790 {
791         struct test_bulk_req *brq = &req->tsr_u.bulk_v0;
792
793         brq->blk_opc    = param->blk_opc;
794         brq->blk_npg    = (param->blk_size + PAGE_SIZE - 1) /
795                            PAGE_SIZE;
796         brq->blk_flags  = param->blk_flags;
797
798         return 0;
799 }
800
801 static int
802 lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
803                        struct srpc_test_reqst *req)
804 {
805         struct test_bulk_req_v1 *brq = &req->tsr_u.bulk_v1;
806
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;
811
812         return 0;
813 }
814
815 int
816 lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
817                     struct lstcon_test *test, struct lstcon_rpc **crpc)
818 {
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;
823         int i;
824         int npg = 0;
825         int nob = 0;
826         int rc = 0;
827
828         if (transop == LST_TRANS_TSBCLIADD) {
829                 npg = sfw_id_pages(test->tes_span);
830                 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
831                       npg * PAGE_SIZE :
832                       sizeof(struct lnet_process_id_packed) * test->tes_span;
833         }
834
835         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
836         if (rc != 0)
837                 return rc;
838
839         trq  = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
840
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;
845
846                 trq->tsr_ndest = 0;
847                 trq->tsr_loop  = nmax * test->tes_dist * test->tes_concur;
848
849         } else {
850                 bulk = &(*crpc)->crp_rpc->crpc_bulk;
851
852                 for (i = 0; i < npg; i++) {
853                         int     len;
854
855                         LASSERT(nob > 0);
856
857                         len = (feats & LST_FEAT_BULK_LEN) == 0 ?
858                               PAGE_SIZE : min_t(int, nob, PAGE_SIZE);
859                         nob -= len;
860
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);
865
866                         if (bulk->bk_iovs[i].kiov_page == NULL) {
867                                 lstcon_rpc_put(*crpc);
868                                 return -ENOMEM;
869                         }
870                 }
871
872                 bulk->bk_sink = 0;
873
874                 LASSERT (transop == LST_TRANS_TSBCLIADD);
875
876                 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
877                                           test->tes_cliidx++,
878                                           test->tes_dist,
879                                           test->tes_span,
880                                           npg, &bulk->bk_iovs[0]);
881                 if (rc != 0) {
882                         lstcon_rpc_put(*crpc);
883                         return rc;
884                 }
885
886                 trq->tsr_ndest = test->tes_span;
887                 trq->tsr_loop  = test->tes_loop;
888         }
889
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;
895
896         switch (test->tes_type) {
897         case LST_TEST_PING:
898                 trq->tsr_service = SRPC_SERVICE_PING;
899                 rc = lstcon_pingrpc_prep((struct lst_test_ping_param *)
900                                          &test->tes_param[0], trq);
901                 break;
902
903         case LST_TEST_BULK:
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);
908                 } else {
909                         rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
910                                                     &test->tes_param[0],
911                                                     trq->tsr_is_client, trq);
912                 }
913
914                 break;
915         default:
916                 LBUG();
917                 break;
918         }
919
920         return rc;
921 }
922
923 static int
924 lstcon_sesnew_stat_reply(struct lstcon_rpc_trans *trans,
925                          struct lstcon_node *nd, struct srpc_msg *reply)
926 {
927         struct srpc_mksn_reply *mksn_rep = &reply->msg_body.mksn_reply;
928         int status = mksn_rep->mksn_status;
929
930         if (status == 0 &&
931             (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
932                 mksn_rep->mksn_status = EPROTO;
933                 status = EPROTO;
934         }
935
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);
940         }
941
942         if (status != 0)
943                 return status;
944
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;
950                 }
951                 spin_unlock(&console_session.ses_rpc_lock);
952         }
953
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;
960         }
961
962         if (status == 0) {
963                 /* session timeout on remote node */
964                 nd->nd_timeout = mksn_rep->mksn_timeout;
965         }
966
967         return status;
968 }
969
970 void
971 lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg,
972                       struct lstcon_node *nd, struct lstcon_trans_stat *stat)
973 {
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;
979         int rc = 0;
980
981         switch (trans->tas_opc) {
982         case LST_TRANS_SESNEW:
983                 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
984                 if (rc == 0) {
985                         lstcon_sesop_stat_success(stat, 1);
986                         return;
987                 }
988
989                 lstcon_sesop_stat_failure(stat, 1);
990                 break;
991
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);
998                         return;
999                 }
1000
1001                 lstcon_sesop_stat_failure(stat, 1);
1002                 rc = rmsn_rep->rmsn_status;
1003                 break;
1004
1005         case LST_TRANS_SESQRY:
1006         case LST_TRANS_SESPING:
1007                 dbg_rep = &msg->msg_body.dbg_reply;
1008
1009                 if (dbg_rep->dbg_status == ESRCH) {
1010                         lstcon_sesqry_stat_unknown(stat, 1);
1011                         return;
1012                 }
1013
1014                 if (lstcon_session_match(dbg_rep->dbg_sid))
1015                         lstcon_sesqry_stat_active(stat, 1);
1016                 else
1017                         lstcon_sesqry_stat_busy(stat, 1);
1018                 return;
1019
1020         case LST_TRANS_TSBRUN:
1021         case LST_TRANS_TSBSTOP:
1022                 bat_rep = &msg->msg_body.bat_reply;
1023
1024                 if (bat_rep->bar_status == 0) {
1025                         lstcon_tsbop_stat_success(stat, 1);
1026                         return;
1027                 }
1028
1029                 if (bat_rep->bar_status == EPERM &&
1030                     trans->tas_opc == LST_TRANS_TSBSTOP) {
1031                         lstcon_tsbop_stat_success(stat, 1);
1032                         return;
1033                 }
1034
1035                 lstcon_tsbop_stat_failure(stat, 1);
1036                 rc = bat_rep->bar_status;
1037                 break;
1038
1039         case LST_TRANS_TSBCLIQRY:
1040         case LST_TRANS_TSBSRVQRY:
1041                 bat_rep = &msg->msg_body.bat_reply;
1042
1043                 if (bat_rep->bar_active != 0)
1044                         lstcon_tsbqry_stat_run(stat, 1);
1045                 else
1046                         lstcon_tsbqry_stat_idle(stat, 1);
1047
1048                 if (bat_rep->bar_status == 0)
1049                         return;
1050
1051                 lstcon_tsbqry_stat_failure(stat, 1);
1052                 rc = bat_rep->bar_status;
1053                 break;
1054
1055         case LST_TRANS_TSBCLIADD:
1056         case LST_TRANS_TSBSRVADD:
1057                 test_rep = &msg->msg_body.tes_reply;
1058
1059                 if (test_rep->tsr_status == 0) {
1060                         lstcon_tsbop_stat_success(stat, 1);
1061                         return;
1062                 }
1063
1064                 lstcon_tsbop_stat_failure(stat, 1);
1065                 rc = test_rep->tsr_status;
1066                 break;
1067
1068         case LST_TRANS_STATQRY:
1069                 stat_rep = &msg->msg_body.stat_reply;
1070
1071                 if (stat_rep->str_status == 0) {
1072                         lstcon_statqry_stat_success(stat, 1);
1073                         return;
1074                 }
1075
1076                 lstcon_statqry_stat_failure(stat, 1);
1077                 rc = stat_rep->str_status;
1078                 break;
1079
1080         default:
1081                 LBUG();
1082         }
1083
1084         if (stat->trs_fwk_errno == 0)
1085                 stat->trs_fwk_errno = rc;
1086
1087         return;
1088 }
1089
1090 int
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)
1095 {
1096         struct lstcon_rpc_trans *trans;
1097         struct lstcon_ndlink *ndl;
1098         struct lstcon_node *nd;
1099         struct lstcon_rpc *rpc;
1100         unsigned int feats;
1101         int rc;
1102
1103         /* Creating session RPG for list of nodes */
1104
1105         rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1106         if (rc != 0) {
1107                 CERROR("Can't create transaction %d: %d\n", transop, rc);
1108                 return rc;
1109         }
1110
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);
1115
1116                 if (rc == 0)
1117                         continue;
1118
1119                 if (rc < 0) {
1120                         CDEBUG(D_NET, "Condition error while creating RPC "
1121                                       " for transaction %d: %d\n", transop, rc);
1122                         break;
1123                 }
1124
1125                 nd = ndl->ndl_node;
1126
1127                 switch (transop) {
1128                 case LST_TRANS_SESNEW:
1129                 case LST_TRANS_SESEND:
1130                         rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1131                         break;
1132                 case LST_TRANS_SESQRY:
1133                 case LST_TRANS_SESPING:
1134                         rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1135                         break;
1136                 case LST_TRANS_TSBCLIADD:
1137                 case LST_TRANS_TSBSRVADD:
1138                         rc = lstcon_testrpc_prep(nd, transop, feats,
1139                                                  (struct lstcon_test *)arg,
1140                                                  &rpc);
1141                         break;
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,
1148                                                 &rpc);
1149                         break;
1150                 case LST_TRANS_STATQRY:
1151                         rc = lstcon_statrpc_prep(nd, feats, &rpc);
1152                         break;
1153                 default:
1154                         rc = -EINVAL;
1155                         break;
1156                 }
1157
1158                 if (rc != 0) {
1159                         CERROR("Failed to create RPC for transaction %s: %d\n",
1160                                lstcon_rpc_trans_name(transop), rc);
1161                         break;
1162                 }
1163
1164                 lstcon_rpc_trans_addreq(trans, rpc);
1165         }
1166
1167         if (rc == 0) {
1168                 *transpp = trans;
1169                 return 0;
1170         }
1171
1172         lstcon_rpc_trans_destroy(trans);
1173
1174         return rc;
1175 }
1176
1177 static void
1178 lstcon_rpc_pinger(void *arg)
1179 {
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;
1187         int intv;
1188         int count = 0;
1189         int rc;
1190
1191         /* RPC pinger is a special case of transaction,
1192          * it's called by timer at 8 seconds interval.
1193          */
1194         mutex_lock(&console_session.ses_mutex);
1195
1196         if (console_session.ses_shutdown || console_session.ses_expired) {
1197                 mutex_unlock(&console_session.ses_mutex);
1198                 return;
1199         }
1200
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;
1205
1206         trans = console_session.ses_ping;
1207
1208         LASSERT(trans != NULL);
1209
1210         list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1211                 nd = ndl->ndl_node;
1212
1213                 if (console_session.ses_expired) {
1214                         /* idle console, end session on all nodes */
1215                         if (nd->nd_state != LST_NODE_ACTIVE)
1216                                 continue;
1217
1218                         rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1219                                                 trans->tas_features, &crpc);
1220                         if (rc != 0) {
1221                                 CERROR("Out of memory\n");
1222                                 break;
1223                         }
1224
1225                         lstcon_rpc_trans_addreq(trans, crpc);
1226                         lstcon_rpc_post(crpc);
1227
1228                         continue;
1229                 }
1230
1231                 crpc = &nd->nd_ping;
1232
1233                 if (crpc->crp_rpc != NULL) {
1234                         LASSERT(crpc->crp_trans == trans);
1235                         LASSERT(!list_empty(&crpc->crp_link));
1236
1237                         spin_lock(&crpc->crp_rpc->crpc_lock);
1238
1239                         LASSERT(crpc->crp_posted);
1240
1241                         if (!crpc->crp_finished) {
1242                                 /* in flight */
1243                                 spin_unlock(&crpc->crp_rpc->crpc_lock);
1244                                 continue;
1245                         }
1246
1247                         spin_unlock(&crpc->crp_rpc->crpc_lock);
1248
1249                         lstcon_rpc_get_reply(crpc, &rep);
1250
1251                         list_del_init(&crpc->crp_link);
1252
1253                         lstcon_rpc_put(crpc);
1254                 }
1255
1256                 if (nd->nd_state != LST_NODE_ACTIVE)
1257                         continue;
1258
1259                 intv = cfs_duration_sec(jiffies - nd->nd_stamp);
1260                 if (intv < nd->nd_timeout / 2)
1261                         continue;
1262
1263                 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1264                                      trans->tas_features, 0, 0, 1, crpc);
1265                 if (rc != 0) {
1266                         CERROR("Out of memory\n");
1267                         break;
1268                 }
1269
1270                 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1271
1272                 drq->dbg_sid   = console_session.ses_id;
1273                 drq->dbg_flags = 0;
1274
1275                 lstcon_rpc_trans_addreq(trans, crpc);
1276                 lstcon_rpc_post(crpc);
1277
1278                 count++;
1279         }
1280
1281         if (console_session.ses_expired) {
1282                 mutex_unlock(&console_session.ses_mutex);
1283                 return;
1284         }
1285
1286         CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1287
1288         ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1289         stt_add_timer(ptimer);
1290
1291         mutex_unlock(&console_session.ses_mutex);
1292 }
1293
1294 int
1295 lstcon_rpc_pinger_start(void)
1296 {
1297         struct stt_timer *ptimer;
1298         int rc;
1299
1300         LASSERT(list_empty(&console_session.ses_rpc_freelist));
1301         LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1302
1303         rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1304                                    &console_session.ses_ping);
1305         if (rc != 0) {
1306                 CERROR("Failed to create console pinger\n");
1307                 return rc;
1308         }
1309
1310         ptimer = &console_session.ses_ping_timer;
1311         ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1312
1313         stt_add_timer(ptimer);
1314
1315         return 0;
1316 }
1317
1318 void
1319 lstcon_rpc_pinger_stop(void)
1320 {
1321         LASSERT (console_session.ses_shutdown);
1322
1323         stt_del_timer(&console_session.ses_ping_timer);
1324
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);
1328
1329         memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1330
1331         console_session.ses_ping = NULL;
1332 }
1333
1334 void
1335 lstcon_rpc_cleanup_wait(void)
1336 {
1337         struct lstcon_rpc_trans *trans;
1338         struct lstcon_rpc *crpc;
1339         struct list_head *pacer;
1340         struct list_head zlist;
1341
1342         /* Called with hold of global mutex */
1343
1344         LASSERT(console_session.ses_shutdown);
1345
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,
1349                                            tas_link);
1350
1351                         CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1352                                lstcon_rpc_trans_name(trans->tas_opc));
1353
1354                         wake_up(&trans->tas_waitq);
1355                 }
1356
1357                 mutex_unlock(&console_session.ses_mutex);
1358
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));
1363
1364                 mutex_lock(&console_session.ses_mutex);
1365         }
1366
1367         spin_lock(&console_session.ses_rpc_lock);
1368
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));
1374
1375         list_add(&zlist, &console_session.ses_rpc_freelist);
1376         list_del_init(&console_session.ses_rpc_freelist);
1377
1378         spin_unlock(&console_session.ses_rpc_lock);
1379
1380         while (!list_empty(&zlist)) {
1381                 crpc = list_entry(zlist.next, struct lstcon_rpc, crp_link);
1382
1383                 list_del(&crpc->crp_link);
1384                 LIBCFS_FREE(crpc, sizeof(*crpc));
1385         }
1386 }
1387
1388 int
1389 lstcon_rpc_module_init(void)
1390 {
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;
1394
1395         console_session.ses_ping = NULL;
1396
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);
1400
1401         return 0;
1402 }
1403
1404 void
1405 lstcon_rpc_module_fini(void)
1406 {
1407         LASSERT(list_empty(&console_session.ses_rpc_freelist));
1408         LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1409 }
1410