Whamcloud - gitweb
56a6bde3389541add2c1c0a1fc23409438178846
[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_ns == 0) {
73                 /* not aborted */
74                 LASSERT(crpc->crp_status == 0);
75
76                 crpc->crp_stamp_ns = ktime_get_ns();
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         memset(crpc, 0, sizeof(*crpc));
93
94         crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
95                                        feats, bulk_npg, bulk_len,
96                                        lstcon_rpc_done, (void *)crpc);
97         if (crpc->crp_rpc == NULL)
98                 return -ENOMEM;
99
100         crpc->crp_node     = nd;
101         crpc->crp_embedded = embedded;
102         INIT_LIST_HEAD(&crpc->crp_link);
103
104         atomic_inc(&console_session.ses_rpc_counter);
105
106         return 0;
107 }
108
109 static int
110 lstcon_rpc_prep(struct lstcon_node *nd, int service, unsigned int feats,
111                 int bulk_npg, int bulk_len, struct lstcon_rpc **crpcpp)
112 {
113         struct lstcon_rpc *crpc = NULL;
114         int rc;
115
116         spin_lock(&console_session.ses_rpc_lock);
117
118         if (!list_empty(&console_session.ses_rpc_freelist)) {
119                 crpc = list_entry(console_session.ses_rpc_freelist.next,
120                                   struct lstcon_rpc, crp_link);
121                 list_del_init(&crpc->crp_link);
122         }
123
124         spin_unlock(&console_session.ses_rpc_lock);
125
126         if (crpc == NULL) {
127                 LIBCFS_ALLOC(crpc, sizeof(*crpc));
128                 if (crpc == NULL)
129                         return -ENOMEM;
130         }
131
132         rc = lstcon_rpc_init(nd, service, feats, bulk_npg, bulk_len, 0, crpc);
133         if (rc == 0) {
134                 *crpcpp = crpc;
135                 return 0;
136         }
137
138         LIBCFS_FREE(crpc, sizeof(*crpc));
139
140         return rc;
141 }
142
143 void
144 lstcon_rpc_put(struct lstcon_rpc *crpc)
145 {
146         struct srpc_bulk *bulk = &crpc->crp_rpc->crpc_bulk;
147         int i;
148
149         LASSERT(list_empty(&crpc->crp_link));
150
151         for (i = 0; i < bulk->bk_niov; i++) {
152                 if (bulk->bk_iovs[i].kiov_page == NULL)
153                         continue;
154
155                 __free_page(bulk->bk_iovs[i].kiov_page);
156         }
157
158         srpc_client_rpc_decref(crpc->crp_rpc);
159
160         if (crpc->crp_embedded) {
161                 /* embedded RPC, don't recycle it */
162                 memset(crpc, 0, sizeof(*crpc));
163                 crpc->crp_embedded = 1;
164
165         } else {
166                 spin_lock(&console_session.ses_rpc_lock);
167
168                 list_add(&crpc->crp_link,
169                          &console_session.ses_rpc_freelist);
170
171                 spin_unlock(&console_session.ses_rpc_lock);
172         }
173
174         /* RPC is not alive now */
175         atomic_dec(&console_session.ses_rpc_counter);
176 }
177
178 static void
179 lstcon_rpc_post(struct lstcon_rpc *crpc)
180 {
181         struct lstcon_rpc_trans *trans = crpc->crp_trans;
182
183         LASSERT (trans != NULL);
184
185         atomic_inc(&trans->tas_remaining);
186         crpc->crp_posted = 1;
187
188         sfw_post_rpc(crpc->crp_rpc);
189 }
190
191 static char *
192 lstcon_rpc_trans_name(int transop)
193 {
194         if (transop == LST_TRANS_SESNEW)
195                 return "SESNEW";
196
197         if (transop == LST_TRANS_SESEND)
198                 return "SESEND";
199
200         if (transop == LST_TRANS_SESQRY)
201                 return "SESQRY";
202
203         if (transop == LST_TRANS_SESPING)
204                 return "SESPING";
205
206         if (transop == LST_TRANS_TSBCLIADD)
207                 return "TSBCLIADD";
208
209         if (transop == LST_TRANS_TSBSRVADD)
210                 return "TSBSRVADD";
211
212         if (transop == LST_TRANS_TSBRUN)
213                 return "TSBRUN";
214
215         if (transop == LST_TRANS_TSBSTOP)
216                 return "TSBSTOP";
217
218         if (transop == LST_TRANS_TSBCLIQRY)
219                 return "TSBCLIQRY";
220
221         if (transop == LST_TRANS_TSBSRVQRY)
222                 return "TSBSRVQRY";
223
224         if (transop == LST_TRANS_STATQRY)
225                 return "STATQRY";
226
227         return "Unknown";
228 }
229
230 int
231 lstcon_rpc_trans_prep(struct list_head *translist, int transop,
232                       struct lstcon_rpc_trans **transpp)
233 {
234         struct lstcon_rpc_trans *trans;
235
236         if (translist != NULL) {
237                 list_for_each_entry(trans, translist, tas_link) {
238                         /* Can't enqueue two private transaction on
239                          * the same object */
240                         if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
241                                 return -EPERM;
242                 }
243         }
244
245         /* create a trans group */
246         LIBCFS_ALLOC(trans, sizeof(*trans));
247         if (trans == NULL)
248                 return -ENOMEM;
249
250         trans->tas_opc = transop;
251
252         if (translist == NULL)
253                 INIT_LIST_HEAD(&trans->tas_olink);
254         else
255                 list_add_tail(&trans->tas_olink, translist);
256
257         list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
258
259         INIT_LIST_HEAD(&trans->tas_rpcs_list);
260         atomic_set(&trans->tas_remaining, 0);
261         init_waitqueue_head(&trans->tas_waitq);
262
263         spin_lock(&console_session.ses_rpc_lock);
264         trans->tas_features = console_session.ses_features;
265         spin_unlock(&console_session.ses_rpc_lock);
266
267         *transpp = trans;
268         return 0;
269 }
270
271 void
272 lstcon_rpc_trans_addreq(struct lstcon_rpc_trans *trans, struct lstcon_rpc *crpc)
273 {
274         list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
275         crpc->crp_trans = trans;
276 }
277
278 void
279 lstcon_rpc_trans_abort(struct lstcon_rpc_trans *trans, int error)
280 {
281         struct srpc_client_rpc *rpc;
282         struct lstcon_rpc *crpc;
283         struct lstcon_node *nd;
284
285         list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
286                 rpc = crpc->crp_rpc;
287
288                 spin_lock(&rpc->crpc_lock);
289
290                 if (!crpc->crp_posted || /* not posted */
291                     crpc->crp_stamp_ns != 0) { /* rpc done or aborted already */
292                         if (crpc->crp_stamp_ns == 0) {
293                                 crpc->crp_stamp_ns = ktime_get_ns();
294                                 crpc->crp_status = -EINTR;
295                         }
296                         spin_unlock(&rpc->crpc_lock);
297                         continue;
298                 }
299
300                 crpc->crp_stamp_ns  = ktime_get_ns();
301                 crpc->crp_status = error;
302
303                 spin_unlock(&rpc->crpc_lock);
304
305                 sfw_abort_rpc(rpc);
306
307                 if (error != -ETIMEDOUT)
308                         continue;
309
310                 nd = crpc->crp_node;
311                 if (ktime_to_ns(nd->nd_stamp) > crpc->crp_stamp_ns)
312                         continue;
313
314                 nd->nd_stamp = ktime_set(0, crpc->crp_stamp_ns);
315                 nd->nd_state = LST_NODE_DOWN;
316         }
317 }
318
319 static int
320 lstcon_rpc_trans_check(struct lstcon_rpc_trans *trans)
321 {
322         if (console_session.ses_shutdown &&
323             !list_empty(&trans->tas_olink)) /* Not an end session RPC */
324                 return 1;
325
326         return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
327 }
328
329 int
330 lstcon_rpc_trans_postwait(struct lstcon_rpc_trans *trans, int timeout)
331 {
332         struct lstcon_rpc *crpc;
333         int rc;
334
335         if (list_empty(&trans->tas_rpcs_list))
336                 return 0;
337
338         if (timeout < LST_TRANS_MIN_TIMEOUT)
339                 timeout = LST_TRANS_MIN_TIMEOUT;
340
341         CDEBUG(D_NET, "Transaction %s started\n",
342         lstcon_rpc_trans_name(trans->tas_opc));
343
344         /* post all requests */
345         list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
346                 LASSERT(!crpc->crp_posted);
347
348                 lstcon_rpc_post(crpc);
349         }
350
351         mutex_unlock(&console_session.ses_mutex);
352
353         rc = wait_event_interruptible_timeout(trans->tas_waitq,
354                                               lstcon_rpc_trans_check(trans),
355                                               cfs_time_seconds(timeout));
356
357         rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
358
359         mutex_lock(&console_session.ses_mutex);
360
361         if (console_session.ses_shutdown)
362                 rc = -ESHUTDOWN;
363
364         if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
365                 /* treat short timeout as canceled */
366                 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
367                         rc = -EINTR;
368
369                 lstcon_rpc_trans_abort(trans, rc);
370         }
371
372         CDEBUG(D_NET, "Transaction %s stopped: %d\n",
373                lstcon_rpc_trans_name(trans->tas_opc), rc);
374
375         lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
376
377         return rc;
378 }
379
380 static int
381 lstcon_rpc_get_reply(struct lstcon_rpc *crpc, struct srpc_msg **msgpp)
382 {
383         struct lstcon_node *nd = crpc->crp_node;
384         struct srpc_client_rpc *rpc = crpc->crp_rpc;
385         struct srpc_generic_reply *rep;
386
387         LASSERT(nd != NULL && rpc != NULL);
388         LASSERT(crpc->crp_stamp_ns != 0);
389
390         if (crpc->crp_status != 0) {
391                 *msgpp = NULL;
392                 return crpc->crp_status;
393         }
394
395         *msgpp = &rpc->crpc_replymsg;
396         if (!crpc->crp_unpacked) {
397                 sfw_unpack_message(*msgpp);
398                 crpc->crp_unpacked = 1;
399         }
400
401         if (ktime_to_ns(nd->nd_stamp) > crpc->crp_stamp_ns)
402                 return 0;
403
404         nd->nd_stamp = ktime_set(0, crpc->crp_stamp_ns);
405         rep = &(*msgpp)->msg_body.reply;
406
407         if (rep->sid.ses_nid == LNET_NID_ANY)
408                 nd->nd_state = LST_NODE_UNKNOWN;
409         else if (lstcon_session_match(rep->sid))
410                 nd->nd_state = LST_NODE_ACTIVE;
411         else
412                 nd->nd_state = LST_NODE_BUSY;
413
414         return 0;
415 }
416
417 void
418 lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans,
419                       struct lstcon_trans_stat *stat)
420 {
421         struct lstcon_rpc *crpc;
422         struct srpc_msg *rep;
423         int error;
424
425         LASSERT(stat != NULL);
426
427         memset(stat, 0, sizeof(*stat));
428
429         list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
430                 lstcon_rpc_stat_total(stat, 1);
431
432                 LASSERT(crpc->crp_stamp_ns != 0);
433
434                 error = lstcon_rpc_get_reply(crpc, &rep);
435                 if (error != 0) {
436                         lstcon_rpc_stat_failure(stat, 1);
437                         if (stat->trs_rpc_errno == 0)
438                                 stat->trs_rpc_errno = -error;
439
440                         continue;
441                 }
442
443                 lstcon_rpc_stat_success(stat, 1);
444
445                 lstcon_rpc_stat_reply(trans, rep, crpc->crp_node, stat);
446         }
447
448         if (trans->tas_opc == LST_TRANS_SESNEW && stat->trs_fwk_errno == 0) {
449                 stat->trs_fwk_errno =
450                       lstcon_session_feats_check(trans->tas_features);
451         }
452
453         CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
454                       "RPC error(%d), Framework error(%d)\n",
455                lstcon_rpc_trans_name(trans->tas_opc),
456                lstcon_rpc_stat_success(stat, 0),
457                lstcon_rpc_stat_failure(stat, 0),
458                lstcon_rpc_stat_total(stat, 0),
459                stat->trs_rpc_errno, stat->trs_fwk_errno);
460
461         return;
462 }
463
464 int
465 lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
466                              struct list_head __user *head_up,
467                              lstcon_rpc_readent_func_t readent)
468 {
469         struct list_head tmp;
470         struct list_head __user *next;
471         struct lstcon_rpc_ent *ent;
472         struct srpc_generic_reply *rep;
473         struct lstcon_rpc *crpc;
474         struct srpc_msg *msg;
475         struct lstcon_node *nd;
476         struct timeval tv;
477         int error;
478         s64 dur;
479
480         LASSERT(head_up != NULL);
481
482         next = head_up;
483
484         list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
485                 if (copy_from_user(&tmp, next,
486                                    sizeof(struct list_head)))
487                         return -EFAULT;
488
489                 if (tmp.next == head_up)
490                         return 0;
491
492                 next = tmp.next;
493
494                 ent = list_entry(next, struct lstcon_rpc_ent, rpe_link);
495
496                 LASSERT(crpc->crp_stamp_ns != 0);
497
498                 error = lstcon_rpc_get_reply(crpc, &msg);
499
500                 nd = crpc->crp_node;
501
502                 dur = crpc->crp_stamp_ns -
503                       console_session.ses_id.ses_stamp * NSEC_PER_MSEC;
504                 tv = ns_to_timeval(dur);
505
506                 if (copy_to_user(&ent->rpe_peer,
507                                  &nd->nd_id, sizeof(struct lnet_process_id)) ||
508                     copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
509                     copy_to_user(&ent->rpe_state,
510                                  &nd->nd_state, sizeof(nd->nd_state)) ||
511                     copy_to_user(&ent->rpe_rpc_errno, &error,
512                                      sizeof(error)))
513                         return -EFAULT;
514
515                 if (error != 0)
516                         continue;
517
518                 /* RPC is done */
519                 rep = (struct srpc_generic_reply *)&msg->msg_body.reply;
520
521                 if (copy_to_user(&ent->rpe_sid,
522                                  &rep->sid, sizeof(rep->sid)) ||
523                     copy_to_user(&ent->rpe_fwk_errno,
524                                  &rep->status, sizeof(rep->status)))
525                         return -EFAULT;
526
527                 if (readent == NULL)
528                         continue;
529
530                 error = readent(trans->tas_opc, msg, ent);
531                 if (error != 0)
532                         return error;
533         }
534
535         return 0;
536 }
537
538 void
539 lstcon_rpc_trans_destroy(struct lstcon_rpc_trans *trans)
540 {
541         struct srpc_client_rpc *rpc;
542         struct lstcon_rpc *crpc;
543         struct lstcon_rpc *tmp;
544         int count = 0;
545
546         list_for_each_entry_safe(crpc, tmp, &trans->tas_rpcs_list, crp_link) {
547                 rpc = crpc->crp_rpc;
548
549                 spin_lock(&rpc->crpc_lock);
550
551                 /* free it if not posted or finished already */
552                 if (!crpc->crp_posted || crpc->crp_finished) {
553                         spin_unlock(&rpc->crpc_lock);
554
555                         list_del_init(&crpc->crp_link);
556                         lstcon_rpc_put(crpc);
557
558                         continue;
559                 }
560
561                 /* rpcs can be still not callbacked (even LNetMDUnlink is
562                  * called) because huge timeout for inaccessible network,
563                  * don't make user wait for them, just abandon them, they
564                  * will be recycled in callback */
565
566                 LASSERT(crpc->crp_status != 0);
567
568                 crpc->crp_node  = NULL;
569                 crpc->crp_trans = NULL;
570                 list_del_init(&crpc->crp_link);
571                 count++;
572
573                 spin_unlock(&rpc->crpc_lock);
574
575                 atomic_dec(&trans->tas_remaining);
576         }
577
578         LASSERT(atomic_read(&trans->tas_remaining) == 0);
579
580         list_del(&trans->tas_link);
581         if (!list_empty(&trans->tas_olink))
582                 list_del(&trans->tas_olink);
583
584         CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
585                lstcon_rpc_trans_name(trans->tas_opc), count);
586
587         LIBCFS_FREE(trans, sizeof(*trans));
588
589         return;
590 }
591
592 int
593 lstcon_sesrpc_prep(struct lstcon_node *nd, int transop,
594                    unsigned int feats, struct lstcon_rpc **crpc)
595 {
596         struct srpc_mksn_reqst *msrq;
597         struct srpc_rmsn_reqst *rsrq;
598         int rc;
599
600         switch (transop) {
601         case LST_TRANS_SESNEW:
602                 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
603                                      feats, 0, 0, crpc);
604                 if (rc != 0)
605                         return rc;
606
607                 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
608                 msrq->mksn_sid     = console_session.ses_id;
609                 msrq->mksn_force   = console_session.ses_force;
610                 strlcpy(msrq->mksn_name, console_session.ses_name,
611                         sizeof(msrq->mksn_name));
612                 break;
613
614         case LST_TRANS_SESEND:
615                 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
616                                      feats, 0, 0, crpc);
617                 if (rc != 0)
618                         return rc;
619
620                 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
621                 rsrq->rmsn_sid = console_session.ses_id;
622                 break;
623
624         default:
625                 LBUG();
626         }
627
628         return 0;
629 }
630
631 int
632 lstcon_dbgrpc_prep(struct lstcon_node *nd, unsigned int feats,
633                    struct lstcon_rpc **crpc)
634 {
635         struct srpc_debug_reqst *drq;
636         int rc;
637
638         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
639         if (rc != 0)
640                 return rc;
641
642         drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
643
644         drq->dbg_sid   = console_session.ses_id;
645         drq->dbg_flags = 0;
646
647         return rc;
648 }
649
650 int
651 lstcon_batrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
652                    struct lstcon_tsb_hdr *tsb, struct lstcon_rpc **crpc)
653 {
654         struct lstcon_batch *batch;
655         struct srpc_batch_reqst *brq;
656         int rc;
657
658         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
659         if (rc != 0)
660                 return rc;
661
662         brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
663
664         brq->bar_sid     = console_session.ses_id;
665         brq->bar_bid     = tsb->tsb_id;
666         brq->bar_testidx = tsb->tsb_index;
667         brq->bar_opc     = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
668                            (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
669                             SRPC_BATCH_OPC_QUERY);
670
671         if (transop != LST_TRANS_TSBRUN &&
672             transop != LST_TRANS_TSBSTOP)
673                 return 0;
674
675         LASSERT (tsb->tsb_index == 0);
676
677         batch = (struct lstcon_batch *)tsb;
678         brq->bar_arg = batch->bat_arg;
679
680         return 0;
681 }
682
683 int
684 lstcon_statrpc_prep(struct lstcon_node *nd, unsigned int feats,
685                     struct lstcon_rpc **crpc)
686 {
687         struct srpc_stat_reqst *srq;
688         int rc;
689
690         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
691         if (rc != 0)
692                 return rc;
693
694         srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
695
696         srq->str_sid  = console_session.ses_id;
697         srq->str_type = 0; /* XXX remove it */
698
699         return 0;
700 }
701
702 static struct lnet_process_id_packed *
703 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
704 {
705         struct lnet_process_id_packed *pid;
706         int                       i;
707
708         i = idx / SFW_ID_PER_PAGE;
709
710         LASSERT (i < nkiov);
711
712         pid = (struct lnet_process_id_packed *)page_address(kiov[i].kiov_page);
713
714         return &pid[idx % SFW_ID_PER_PAGE];
715 }
716
717 static int
718 lstcon_dstnodes_prep(struct lstcon_group *grp, int idx,
719                      int dist, int span, int nkiov, lnet_kiov_t *kiov)
720 {
721         struct lnet_process_id_packed *pid;
722         struct lstcon_ndlink *ndl;
723         struct lstcon_node *nd;
724         int start;
725         int end;
726         int i = 0;
727
728         LASSERT (dist >= 1);
729         LASSERT (span >= 1);
730         LASSERT (grp->grp_nnode >= 1);
731
732         if (span > grp->grp_nnode)
733                 return -EINVAL;
734
735         start = ((idx / dist) * span) % grp->grp_nnode;
736         end   = ((idx / dist) * span + span - 1) % grp->grp_nnode;
737
738         list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
739                 nd = ndl->ndl_node;
740                 if (i < start) {
741                         i++;
742                         continue;
743                 }
744
745                 if (i > (end >= start ? end : grp->grp_nnode))
746                         break;
747
748                 pid = lstcon_next_id((i - start), nkiov, kiov);
749                 pid->nid = nd->nd_id.nid;
750                 pid->pid = nd->nd_id.pid;
751                 i++;
752         }
753
754         if (start <= end)       /* done */
755                 return 0;
756
757         list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
758                 if (i > grp->grp_nnode + end)
759                         break;
760
761                 nd = ndl->ndl_node;
762                 pid = lstcon_next_id((i - start), nkiov, kiov);
763                 pid->nid = nd->nd_id.nid;
764                 pid->pid = nd->nd_id.pid;
765                 i++;
766         }
767
768         return 0;
769 }
770
771 static int
772 lstcon_pingrpc_prep(struct lst_test_ping_param *param,
773                     struct srpc_test_reqst *req)
774 {
775         struct test_ping_req *prq = &req->tsr_u.ping;
776
777         prq->png_size   = param->png_size;
778         prq->png_flags  = param->png_flags;
779         /* TODO dest */
780         return 0;
781 }
782
783 static int
784 lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param,
785                        struct srpc_test_reqst *req)
786 {
787         struct test_bulk_req *brq = &req->tsr_u.bulk_v0;
788
789         brq->blk_opc    = param->blk_opc;
790         brq->blk_npg    = (param->blk_size + PAGE_SIZE - 1) /
791                            PAGE_SIZE;
792         brq->blk_flags  = param->blk_flags;
793
794         return 0;
795 }
796
797 static int
798 lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
799                        struct srpc_test_reqst *req)
800 {
801         struct test_bulk_req_v1 *brq = &req->tsr_u.bulk_v1;
802
803         brq->blk_opc    = param->blk_opc;
804         brq->blk_flags  = param->blk_flags;
805         brq->blk_len    = param->blk_size;
806         brq->blk_offset = is_client ? param->blk_cli_off : param->blk_srv_off;
807
808         return 0;
809 }
810
811 int
812 lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
813                     struct lstcon_test *test, struct lstcon_rpc **crpc)
814 {
815         struct lstcon_group *sgrp = test->tes_src_grp;
816         struct lstcon_group *dgrp = test->tes_dst_grp;
817         struct srpc_test_reqst *trq;
818         struct srpc_bulk *bulk;
819         int i;
820         int npg = 0;
821         int nob = 0;
822         int rc = 0;
823
824         if (transop == LST_TRANS_TSBCLIADD) {
825                 npg = sfw_id_pages(test->tes_span);
826                 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
827                       npg * PAGE_SIZE :
828                       sizeof(struct lnet_process_id_packed) * test->tes_span;
829         }
830
831         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
832         if (rc != 0)
833                 return rc;
834
835         trq  = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
836
837         if (transop == LST_TRANS_TSBSRVADD) {
838                 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
839                 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
840                 int nmax = (ndist + nspan - 1) / nspan;
841
842                 trq->tsr_ndest = 0;
843                 trq->tsr_loop  = nmax * test->tes_dist * test->tes_concur;
844
845         } else {
846                 bulk = &(*crpc)->crp_rpc->crpc_bulk;
847
848                 for (i = 0; i < npg; i++) {
849                         int     len;
850
851                         LASSERT(nob > 0);
852
853                         len = (feats & LST_FEAT_BULK_LEN) == 0 ?
854                               PAGE_SIZE : min_t(int, nob, PAGE_SIZE);
855                         nob -= len;
856
857                         bulk->bk_iovs[i].kiov_offset = 0;
858                         bulk->bk_iovs[i].kiov_len    = len;
859                         bulk->bk_iovs[i].kiov_page   =
860                                 alloc_page(GFP_KERNEL);
861
862                         if (bulk->bk_iovs[i].kiov_page == NULL) {
863                                 lstcon_rpc_put(*crpc);
864                                 return -ENOMEM;
865                         }
866                 }
867
868                 bulk->bk_sink = 0;
869
870                 LASSERT (transop == LST_TRANS_TSBCLIADD);
871
872                 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
873                                           test->tes_cliidx++,
874                                           test->tes_dist,
875                                           test->tes_span,
876                                           npg, &bulk->bk_iovs[0]);
877                 if (rc != 0) {
878                         lstcon_rpc_put(*crpc);
879                         return rc;
880                 }
881
882                 trq->tsr_ndest = test->tes_span;
883                 trq->tsr_loop  = test->tes_loop;
884         }
885
886         trq->tsr_sid        = console_session.ses_id;
887         trq->tsr_bid        = test->tes_hdr.tsb_id;
888         trq->tsr_concur     = test->tes_concur;
889         trq->tsr_is_client  = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
890         trq->tsr_stop_onerr = !!test->tes_stop_onerr;
891
892         switch (test->tes_type) {
893         case LST_TEST_PING:
894                 trq->tsr_service = SRPC_SERVICE_PING;
895                 rc = lstcon_pingrpc_prep((struct lst_test_ping_param *)
896                                          &test->tes_param[0], trq);
897                 break;
898
899         case LST_TEST_BULK:
900                 trq->tsr_service = SRPC_SERVICE_BRW;
901                 if ((feats & LST_FEAT_BULK_LEN) == 0) {
902                         rc = lstcon_bulkrpc_v0_prep((struct lst_test_bulk_param *)
903                                                     &test->tes_param[0], trq);
904                 } else {
905                         rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
906                                                     &test->tes_param[0],
907                                                     trq->tsr_is_client, trq);
908                 }
909
910                 break;
911         default:
912                 LBUG();
913                 break;
914         }
915
916         return rc;
917 }
918
919 static int
920 lstcon_sesnew_stat_reply(struct lstcon_rpc_trans *trans,
921                          struct lstcon_node *nd, struct srpc_msg *reply)
922 {
923         struct srpc_mksn_reply *mksn_rep = &reply->msg_body.mksn_reply;
924         int status = mksn_rep->mksn_status;
925
926         if (status == 0 &&
927             (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
928                 mksn_rep->mksn_status = EPROTO;
929                 status = EPROTO;
930         }
931
932         if (status == EPROTO) {
933                 CNETERR("session protocol error from %s: %u\n",
934                         libcfs_nid2str(nd->nd_id.nid),
935                         reply->msg_ses_feats);
936         }
937
938         if (status != 0)
939                 return status;
940
941         if (!trans->tas_feats_updated) {
942                 spin_lock(&console_session.ses_rpc_lock);
943                 if (!trans->tas_feats_updated) { /* recheck with lock */
944                         trans->tas_feats_updated = 1;
945                         trans->tas_features = reply->msg_ses_feats;
946                 }
947                 spin_unlock(&console_session.ses_rpc_lock);
948         }
949
950         if (reply->msg_ses_feats != trans->tas_features) {
951                 CNETERR("Framework features %x from %s is different with "
952                         "features on this transaction: %x\n",
953                          reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
954                          trans->tas_features);
955                 status = mksn_rep->mksn_status = EPROTO;
956         }
957
958         if (status == 0) {
959                 /* session timeout on remote node */
960                 nd->nd_timeout = mksn_rep->mksn_timeout;
961         }
962
963         return status;
964 }
965
966 void
967 lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg,
968                       struct lstcon_node *nd, struct lstcon_trans_stat *stat)
969 {
970         struct srpc_rmsn_reply *rmsn_rep;
971         struct srpc_debug_reply *dbg_rep;
972         struct srpc_batch_reply *bat_rep;
973         struct srpc_test_reply *test_rep;
974         struct srpc_stat_reply *stat_rep;
975         int rc = 0;
976
977         switch (trans->tas_opc) {
978         case LST_TRANS_SESNEW:
979                 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
980                 if (rc == 0) {
981                         lstcon_sesop_stat_success(stat, 1);
982                         return;
983                 }
984
985                 lstcon_sesop_stat_failure(stat, 1);
986                 break;
987
988         case LST_TRANS_SESEND:
989                 rmsn_rep = &msg->msg_body.rmsn_reply;
990                 /* ESRCH is not an error for end session */
991                 if (rmsn_rep->rmsn_status == 0 ||
992                     rmsn_rep->rmsn_status == ESRCH) {
993                         lstcon_sesop_stat_success(stat, 1);
994                         return;
995                 }
996
997                 lstcon_sesop_stat_failure(stat, 1);
998                 rc = rmsn_rep->rmsn_status;
999                 break;
1000
1001         case LST_TRANS_SESQRY:
1002         case LST_TRANS_SESPING:
1003                 dbg_rep = &msg->msg_body.dbg_reply;
1004
1005                 if (dbg_rep->dbg_status == ESRCH) {
1006                         lstcon_sesqry_stat_unknown(stat, 1);
1007                         return;
1008                 }
1009
1010                 if (lstcon_session_match(dbg_rep->dbg_sid))
1011                         lstcon_sesqry_stat_active(stat, 1);
1012                 else
1013                         lstcon_sesqry_stat_busy(stat, 1);
1014                 return;
1015
1016         case LST_TRANS_TSBRUN:
1017         case LST_TRANS_TSBSTOP:
1018                 bat_rep = &msg->msg_body.bat_reply;
1019
1020                 if (bat_rep->bar_status == 0) {
1021                         lstcon_tsbop_stat_success(stat, 1);
1022                         return;
1023                 }
1024
1025                 if (bat_rep->bar_status == EPERM &&
1026                     trans->tas_opc == LST_TRANS_TSBSTOP) {
1027                         lstcon_tsbop_stat_success(stat, 1);
1028                         return;
1029                 }
1030
1031                 lstcon_tsbop_stat_failure(stat, 1);
1032                 rc = bat_rep->bar_status;
1033                 break;
1034
1035         case LST_TRANS_TSBCLIQRY:
1036         case LST_TRANS_TSBSRVQRY:
1037                 bat_rep = &msg->msg_body.bat_reply;
1038
1039                 if (bat_rep->bar_active != 0)
1040                         lstcon_tsbqry_stat_run(stat, 1);
1041                 else
1042                         lstcon_tsbqry_stat_idle(stat, 1);
1043
1044                 if (bat_rep->bar_status == 0)
1045                         return;
1046
1047                 lstcon_tsbqry_stat_failure(stat, 1);
1048                 rc = bat_rep->bar_status;
1049                 break;
1050
1051         case LST_TRANS_TSBCLIADD:
1052         case LST_TRANS_TSBSRVADD:
1053                 test_rep = &msg->msg_body.tes_reply;
1054
1055                 if (test_rep->tsr_status == 0) {
1056                         lstcon_tsbop_stat_success(stat, 1);
1057                         return;
1058                 }
1059
1060                 lstcon_tsbop_stat_failure(stat, 1);
1061                 rc = test_rep->tsr_status;
1062                 break;
1063
1064         case LST_TRANS_STATQRY:
1065                 stat_rep = &msg->msg_body.stat_reply;
1066
1067                 if (stat_rep->str_status == 0) {
1068                         lstcon_statqry_stat_success(stat, 1);
1069                         return;
1070                 }
1071
1072                 lstcon_statqry_stat_failure(stat, 1);
1073                 rc = stat_rep->str_status;
1074                 break;
1075
1076         default:
1077                 LBUG();
1078         }
1079
1080         if (stat->trs_fwk_errno == 0)
1081                 stat->trs_fwk_errno = rc;
1082
1083         return;
1084 }
1085
1086 int
1087 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1088                         struct list_head *translist, int transop,
1089                         void *arg, lstcon_rpc_cond_func_t condition,
1090                         struct lstcon_rpc_trans **transpp)
1091 {
1092         struct lstcon_rpc_trans *trans;
1093         struct lstcon_ndlink *ndl;
1094         struct lstcon_node *nd;
1095         struct lstcon_rpc *rpc;
1096         unsigned int feats;
1097         int rc;
1098
1099         /* Creating session RPG for list of nodes */
1100
1101         rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1102         if (rc != 0) {
1103                 CERROR("Can't create transaction %d: %d\n", transop, rc);
1104                 return rc;
1105         }
1106
1107         feats = trans->tas_features;
1108         list_for_each_entry(ndl, ndlist, ndl_link) {
1109                 rc = condition == NULL ? 1 :
1110                      condition(transop, ndl->ndl_node, arg);
1111
1112                 if (rc == 0)
1113                         continue;
1114
1115                 if (rc < 0) {
1116                         CDEBUG(D_NET, "Condition error while creating RPC "
1117                                       " for transaction %d: %d\n", transop, rc);
1118                         break;
1119                 }
1120
1121                 nd = ndl->ndl_node;
1122
1123                 switch (transop) {
1124                 case LST_TRANS_SESNEW:
1125                 case LST_TRANS_SESEND:
1126                         rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1127                         break;
1128                 case LST_TRANS_SESQRY:
1129                 case LST_TRANS_SESPING:
1130                         rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1131                         break;
1132                 case LST_TRANS_TSBCLIADD:
1133                 case LST_TRANS_TSBSRVADD:
1134                         rc = lstcon_testrpc_prep(nd, transop, feats,
1135                                                  (struct lstcon_test *)arg,
1136                                                  &rpc);
1137                         break;
1138                 case LST_TRANS_TSBRUN:
1139                 case LST_TRANS_TSBSTOP:
1140                 case LST_TRANS_TSBCLIQRY:
1141                 case LST_TRANS_TSBSRVQRY:
1142                         rc = lstcon_batrpc_prep(nd, transop, feats,
1143                                                 (struct lstcon_tsb_hdr *)arg,
1144                                                 &rpc);
1145                         break;
1146                 case LST_TRANS_STATQRY:
1147                         rc = lstcon_statrpc_prep(nd, feats, &rpc);
1148                         break;
1149                 default:
1150                         rc = -EINVAL;
1151                         break;
1152                 }
1153
1154                 if (rc != 0) {
1155                         CERROR("Failed to create RPC for transaction %s: %d\n",
1156                                lstcon_rpc_trans_name(transop), rc);
1157                         break;
1158                 }
1159
1160                 lstcon_rpc_trans_addreq(trans, rpc);
1161         }
1162
1163         if (rc == 0) {
1164                 *transpp = trans;
1165                 return 0;
1166         }
1167
1168         lstcon_rpc_trans_destroy(trans);
1169
1170         return rc;
1171 }
1172
1173 static void
1174 lstcon_rpc_pinger(void *arg)
1175 {
1176         struct stt_timer *ptimer = arg;
1177         struct lstcon_rpc_trans *trans;
1178         struct lstcon_rpc *crpc;
1179         struct srpc_msg *rep;
1180         struct srpc_debug_reqst *drq;
1181         struct lstcon_ndlink *ndl;
1182         struct lstcon_node *nd;
1183         int intv;
1184         int count = 0;
1185         int rc;
1186
1187         /* RPC pinger is a special case of transaction,
1188          * it's called by timer at 8 seconds interval.
1189          */
1190         mutex_lock(&console_session.ses_mutex);
1191
1192         if (console_session.ses_shutdown || console_session.ses_expired) {
1193                 mutex_unlock(&console_session.ses_mutex);
1194                 return;
1195         }
1196
1197         if (!console_session.ses_expired &&
1198             ktime_get_real_seconds() - console_session.ses_laststamp >
1199             (time64_t)console_session.ses_timeout)
1200                 console_session.ses_expired = 1;
1201
1202         trans = console_session.ses_ping;
1203
1204         LASSERT(trans != NULL);
1205
1206         list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1207                 nd = ndl->ndl_node;
1208
1209                 if (console_session.ses_expired) {
1210                         /* idle console, end session on all nodes */
1211                         if (nd->nd_state != LST_NODE_ACTIVE)
1212                                 continue;
1213
1214                         rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1215                                                 trans->tas_features, &crpc);
1216                         if (rc != 0) {
1217                                 CERROR("Out of memory\n");
1218                                 break;
1219                         }
1220
1221                         lstcon_rpc_trans_addreq(trans, crpc);
1222                         lstcon_rpc_post(crpc);
1223
1224                         continue;
1225                 }
1226
1227                 crpc = &nd->nd_ping;
1228
1229                 if (crpc->crp_rpc != NULL) {
1230                         LASSERT(crpc->crp_trans == trans);
1231                         LASSERT(!list_empty(&crpc->crp_link));
1232
1233                         spin_lock(&crpc->crp_rpc->crpc_lock);
1234
1235                         LASSERT(crpc->crp_posted);
1236
1237                         if (!crpc->crp_finished) {
1238                                 /* in flight */
1239                                 spin_unlock(&crpc->crp_rpc->crpc_lock);
1240                                 continue;
1241                         }
1242
1243                         spin_unlock(&crpc->crp_rpc->crpc_lock);
1244
1245                         lstcon_rpc_get_reply(crpc, &rep);
1246
1247                         list_del_init(&crpc->crp_link);
1248
1249                         lstcon_rpc_put(crpc);
1250                 }
1251
1252                 if (nd->nd_state != LST_NODE_ACTIVE)
1253                         continue;
1254
1255                 intv = ktime_ms_delta(ktime_get(), nd->nd_stamp) / MSEC_PER_SEC;
1256                 if (intv < nd->nd_timeout / 2)
1257                         continue;
1258
1259                 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1260                                      trans->tas_features, 0, 0, 1, crpc);
1261                 if (rc != 0) {
1262                         CERROR("Out of memory\n");
1263                         break;
1264                 }
1265
1266                 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1267
1268                 drq->dbg_sid   = console_session.ses_id;
1269                 drq->dbg_flags = 0;
1270
1271                 lstcon_rpc_trans_addreq(trans, crpc);
1272                 lstcon_rpc_post(crpc);
1273
1274                 count++;
1275         }
1276
1277         if (console_session.ses_expired) {
1278                 mutex_unlock(&console_session.ses_mutex);
1279                 return;
1280         }
1281
1282         CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1283
1284         ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1285         stt_add_timer(ptimer);
1286
1287         mutex_unlock(&console_session.ses_mutex);
1288 }
1289
1290 int
1291 lstcon_rpc_pinger_start(void)
1292 {
1293         struct stt_timer *ptimer;
1294         int rc;
1295
1296         LASSERT(list_empty(&console_session.ses_rpc_freelist));
1297         LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1298
1299         rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1300                                    &console_session.ses_ping);
1301         if (rc != 0) {
1302                 CERROR("Failed to create console pinger\n");
1303                 return rc;
1304         }
1305
1306         ptimer = &console_session.ses_ping_timer;
1307         ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1308
1309         stt_add_timer(ptimer);
1310
1311         return 0;
1312 }
1313
1314 void
1315 lstcon_rpc_pinger_stop(void)
1316 {
1317         LASSERT (console_session.ses_shutdown);
1318
1319         stt_del_timer(&console_session.ses_ping_timer);
1320
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);
1324
1325         memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1326
1327         console_session.ses_ping = NULL;
1328 }
1329
1330 void
1331 lstcon_rpc_cleanup_wait(void)
1332 {
1333         struct lstcon_rpc_trans *trans;
1334         struct lstcon_rpc *crpc;
1335         struct list_head *pacer;
1336         struct list_head zlist;
1337
1338         /* Called with hold of global mutex */
1339
1340         LASSERT(console_session.ses_shutdown);
1341
1342         while (!list_empty(&console_session.ses_trans_list)) {
1343                 list_for_each(pacer, &console_session.ses_trans_list) {
1344                         trans = list_entry(pacer, struct lstcon_rpc_trans,
1345                                            tas_link);
1346
1347                         CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1348                                lstcon_rpc_trans_name(trans->tas_opc));
1349
1350                         wake_up(&trans->tas_waitq);
1351                 }
1352
1353                 mutex_unlock(&console_session.ses_mutex);
1354
1355                 CWARN("Session is shutting down, "
1356                       "waiting for termination of transactions\n");
1357                 set_current_state(TASK_UNINTERRUPTIBLE);
1358                 schedule_timeout(cfs_time_seconds(1));
1359
1360                 mutex_lock(&console_session.ses_mutex);
1361         }
1362
1363         spin_lock(&console_session.ses_rpc_lock);
1364
1365         lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1366                        console_session.ses_rpc_lock,
1367                        "Network is not accessable or target is down, "
1368                        "waiting for %d console RPCs to being recycled\n",
1369                        atomic_read(&console_session.ses_rpc_counter));
1370
1371         list_add(&zlist, &console_session.ses_rpc_freelist);
1372         list_del_init(&console_session.ses_rpc_freelist);
1373
1374         spin_unlock(&console_session.ses_rpc_lock);
1375
1376         while (!list_empty(&zlist)) {
1377                 crpc = list_entry(zlist.next, struct lstcon_rpc, crp_link);
1378
1379                 list_del(&crpc->crp_link);
1380                 LIBCFS_FREE(crpc, sizeof(*crpc));
1381         }
1382 }
1383
1384 int
1385 lstcon_rpc_module_init(void)
1386 {
1387         INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1388         console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1389         console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1390
1391         console_session.ses_ping = NULL;
1392
1393         spin_lock_init(&console_session.ses_rpc_lock);
1394         atomic_set(&console_session.ses_rpc_counter, 0);
1395         INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1396
1397         return 0;
1398 }
1399
1400 void
1401 lstcon_rpc_module_fini(void)
1402 {
1403         LASSERT(list_empty(&console_session.ses_rpc_freelist));
1404         LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1405 }
1406