Whamcloud - gitweb
LU-9859 libcfs: always range-check libcfs_debug_mb setting.
[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].bv_page == NULL)
153                         continue;
154
155                 __free_page(bulk->bk_iovs[i].bv_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
462 int
463 lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
464                              struct list_head __user *head_up,
465                              lstcon_rpc_readent_func_t readent)
466 {
467         struct list_head tmp;
468         struct list_head __user *next;
469         struct lstcon_rpc_ent *ent;
470         struct srpc_generic_reply *rep;
471         struct lstcon_rpc *crpc;
472         struct srpc_msg *msg;
473         struct lstcon_node *nd;
474         struct timeval tv;
475         int error;
476         s64 dur;
477
478         LASSERT(head_up != NULL);
479
480         next = head_up;
481
482         list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
483                 if (copy_from_user(&tmp, next,
484                                    sizeof(struct list_head)))
485                         return -EFAULT;
486
487                 if (tmp.next == head_up)
488                         return 0;
489
490                 next = tmp.next;
491
492                 ent = list_entry(next, struct lstcon_rpc_ent, rpe_link);
493
494                 LASSERT(crpc->crp_stamp_ns != 0);
495
496                 error = lstcon_rpc_get_reply(crpc, &msg);
497
498                 nd = crpc->crp_node;
499
500                 dur = crpc->crp_stamp_ns -
501                       console_session.ses_id.ses_stamp * NSEC_PER_MSEC;
502                 tv = ns_to_timeval(dur);
503
504                 if (copy_to_user(&ent->rpe_peer,
505                                  &nd->nd_id, sizeof(struct lnet_process_id)) ||
506                     copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
507                     copy_to_user(&ent->rpe_state,
508                                  &nd->nd_state, sizeof(nd->nd_state)) ||
509                     copy_to_user(&ent->rpe_rpc_errno, &error,
510                                      sizeof(error)))
511                         return -EFAULT;
512
513                 if (error != 0)
514                         continue;
515
516                 /* RPC is done */
517                 rep = (struct srpc_generic_reply *)&msg->msg_body.reply;
518
519                 if (copy_to_user(&ent->rpe_sid,
520                                  &rep->sid, sizeof(rep->sid)) ||
521                     copy_to_user(&ent->rpe_fwk_errno,
522                                  &rep->status, sizeof(rep->status)))
523                         return -EFAULT;
524
525                 if (readent == NULL)
526                         continue;
527
528                 error = readent(trans->tas_opc, msg, ent);
529                 if (error != 0)
530                         return error;
531         }
532
533         return 0;
534 }
535
536 void
537 lstcon_rpc_trans_destroy(struct lstcon_rpc_trans *trans)
538 {
539         struct srpc_client_rpc *rpc;
540         struct lstcon_rpc *crpc;
541         struct lstcon_rpc *tmp;
542         int count = 0;
543
544         list_for_each_entry_safe(crpc, tmp, &trans->tas_rpcs_list, crp_link) {
545                 rpc = crpc->crp_rpc;
546
547                 spin_lock(&rpc->crpc_lock);
548
549                 /* free it if not posted or finished already */
550                 if (!crpc->crp_posted || crpc->crp_finished) {
551                         spin_unlock(&rpc->crpc_lock);
552
553                         list_del_init(&crpc->crp_link);
554                         lstcon_rpc_put(crpc);
555
556                         continue;
557                 }
558
559                 /* rpcs can be still not callbacked (even LNetMDUnlink is
560                  * called) because huge timeout for inaccessible network,
561                  * don't make user wait for them, just abandon them, they
562                  * will be recycled in callback */
563
564                 LASSERT(crpc->crp_status != 0);
565
566                 crpc->crp_node  = NULL;
567                 crpc->crp_trans = NULL;
568                 list_del_init(&crpc->crp_link);
569                 count++;
570
571                 spin_unlock(&rpc->crpc_lock);
572
573                 atomic_dec(&trans->tas_remaining);
574         }
575
576         LASSERT(atomic_read(&trans->tas_remaining) == 0);
577
578         list_del(&trans->tas_link);
579         if (!list_empty(&trans->tas_olink))
580                 list_del(&trans->tas_olink);
581
582         CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
583                lstcon_rpc_trans_name(trans->tas_opc), count);
584
585         LIBCFS_FREE(trans, sizeof(*trans));
586 }
587
588 int
589 lstcon_sesrpc_prep(struct lstcon_node *nd, int transop,
590                    unsigned int feats, struct lstcon_rpc **crpc)
591 {
592         struct srpc_mksn_reqst *msrq;
593         struct srpc_rmsn_reqst *rsrq;
594         int rc;
595
596         switch (transop) {
597         case LST_TRANS_SESNEW:
598                 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
599                                      feats, 0, 0, crpc);
600                 if (rc != 0)
601                         return rc;
602
603                 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
604                 msrq->mksn_sid     = console_session.ses_id;
605                 msrq->mksn_force   = console_session.ses_force;
606                 strlcpy(msrq->mksn_name, console_session.ses_name,
607                         sizeof(msrq->mksn_name));
608                 break;
609
610         case LST_TRANS_SESEND:
611                 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
612                                      feats, 0, 0, crpc);
613                 if (rc != 0)
614                         return rc;
615
616                 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
617                 rsrq->rmsn_sid = console_session.ses_id;
618                 break;
619
620         default:
621                 LBUG();
622         }
623
624         return 0;
625 }
626
627 int
628 lstcon_dbgrpc_prep(struct lstcon_node *nd, unsigned int feats,
629                    struct lstcon_rpc **crpc)
630 {
631         struct srpc_debug_reqst *drq;
632         int rc;
633
634         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
635         if (rc != 0)
636                 return rc;
637
638         drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
639
640         drq->dbg_sid   = console_session.ses_id;
641         drq->dbg_flags = 0;
642
643         return rc;
644 }
645
646 int
647 lstcon_batrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
648                    struct lstcon_tsb_hdr *tsb, struct lstcon_rpc **crpc)
649 {
650         struct lstcon_batch *batch;
651         struct srpc_batch_reqst *brq;
652         int rc;
653
654         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
655         if (rc != 0)
656                 return rc;
657
658         brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
659
660         brq->bar_sid     = console_session.ses_id;
661         brq->bar_bid     = tsb->tsb_id;
662         brq->bar_testidx = tsb->tsb_index;
663         brq->bar_opc     = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
664                            (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
665                             SRPC_BATCH_OPC_QUERY);
666
667         if (transop != LST_TRANS_TSBRUN &&
668             transop != LST_TRANS_TSBSTOP)
669                 return 0;
670
671         LASSERT (tsb->tsb_index == 0);
672
673         batch = (struct lstcon_batch *)tsb;
674         brq->bar_arg = batch->bat_arg;
675
676         return 0;
677 }
678
679 int
680 lstcon_statrpc_prep(struct lstcon_node *nd, unsigned int feats,
681                     struct lstcon_rpc **crpc)
682 {
683         struct srpc_stat_reqst *srq;
684         int rc;
685
686         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
687         if (rc != 0)
688                 return rc;
689
690         srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
691
692         srq->str_sid  = console_session.ses_id;
693         srq->str_type = 0; /* XXX remove it */
694
695         return 0;
696 }
697
698 static struct lnet_process_id_packed *
699 lstcon_next_id(int idx, int nkiov, struct bio_vec *kiov)
700 {
701         struct lnet_process_id_packed *pid;
702         int                       i;
703
704         i = idx / SFW_ID_PER_PAGE;
705
706         LASSERT (i < nkiov);
707
708         pid = (struct lnet_process_id_packed *)page_address(kiov[i].bv_page);
709
710         return &pid[idx % SFW_ID_PER_PAGE];
711 }
712
713 static int
714 lstcon_dstnodes_prep(struct lstcon_group *grp, int idx,
715                      int dist, int span, int nkiov, struct bio_vec *kiov)
716 {
717         struct lnet_process_id_packed *pid;
718         struct lstcon_ndlink *ndl;
719         struct lstcon_node *nd;
720         int start;
721         int end;
722         int i = 0;
723
724         LASSERT (dist >= 1);
725         LASSERT (span >= 1);
726         LASSERT (grp->grp_nnode >= 1);
727
728         if (span > grp->grp_nnode)
729                 return -EINVAL;
730
731         start = ((idx / dist) * span) % grp->grp_nnode;
732         end   = ((idx / dist) * span + span - 1) % grp->grp_nnode;
733
734         list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
735                 nd = ndl->ndl_node;
736                 if (i < start) {
737                         i++;
738                         continue;
739                 }
740
741                 if (i > (end >= start ? end : grp->grp_nnode))
742                         break;
743
744                 pid = lstcon_next_id((i - start), nkiov, kiov);
745                 pid->nid = nd->nd_id.nid;
746                 pid->pid = nd->nd_id.pid;
747                 i++;
748         }
749
750         if (start <= end)       /* done */
751                 return 0;
752
753         list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
754                 if (i > grp->grp_nnode + end)
755                         break;
756
757                 nd = ndl->ndl_node;
758                 pid = lstcon_next_id((i - start), nkiov, kiov);
759                 pid->nid = nd->nd_id.nid;
760                 pid->pid = nd->nd_id.pid;
761                 i++;
762         }
763
764         return 0;
765 }
766
767 static int
768 lstcon_pingrpc_prep(struct lst_test_ping_param *param,
769                     struct srpc_test_reqst *req)
770 {
771         struct test_ping_req *prq = &req->tsr_u.ping;
772
773         prq->png_size   = param->png_size;
774         prq->png_flags  = param->png_flags;
775         /* TODO dest */
776         return 0;
777 }
778
779 static int
780 lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param,
781                        struct srpc_test_reqst *req)
782 {
783         struct test_bulk_req *brq = &req->tsr_u.bulk_v0;
784
785         brq->blk_opc    = param->blk_opc;
786         brq->blk_npg    = (param->blk_size + PAGE_SIZE - 1) /
787                            PAGE_SIZE;
788         brq->blk_flags  = param->blk_flags;
789
790         return 0;
791 }
792
793 static int
794 lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
795                        struct srpc_test_reqst *req)
796 {
797         struct test_bulk_req_v1 *brq = &req->tsr_u.bulk_v1;
798
799         brq->blk_opc    = param->blk_opc;
800         brq->blk_flags  = param->blk_flags;
801         brq->blk_len    = param->blk_size;
802         brq->blk_offset = is_client ? param->blk_cli_off : param->blk_srv_off;
803
804         return 0;
805 }
806
807 int
808 lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
809                     struct lstcon_test *test, struct lstcon_rpc **crpc)
810 {
811         struct lstcon_group *sgrp = test->tes_src_grp;
812         struct lstcon_group *dgrp = test->tes_dst_grp;
813         struct srpc_test_reqst *trq;
814         struct srpc_bulk *bulk;
815         int i;
816         int npg = 0;
817         int nob = 0;
818         int rc = 0;
819
820         if (transop == LST_TRANS_TSBCLIADD) {
821                 npg = sfw_id_pages(test->tes_span);
822                 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
823                       npg * PAGE_SIZE :
824                       sizeof(struct lnet_process_id_packed) * test->tes_span;
825         }
826
827         rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
828         if (rc != 0)
829                 return rc;
830
831         trq  = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
832
833         if (transop == LST_TRANS_TSBSRVADD) {
834                 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
835                 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
836                 int nmax = (ndist + nspan - 1) / nspan;
837
838                 trq->tsr_ndest = 0;
839                 trq->tsr_loop  = nmax * test->tes_dist * test->tes_concur;
840
841         } else {
842                 bulk = &(*crpc)->crp_rpc->crpc_bulk;
843
844                 for (i = 0; i < npg; i++) {
845                         int     len;
846
847                         LASSERT(nob > 0);
848
849                         len = (feats & LST_FEAT_BULK_LEN) == 0 ?
850                               PAGE_SIZE : min_t(int, nob, PAGE_SIZE);
851                         nob -= len;
852
853                         bulk->bk_iovs[i].bv_offset = 0;
854                         bulk->bk_iovs[i].bv_len    = len;
855                         bulk->bk_iovs[i].bv_page   =
856                                 alloc_page(GFP_KERNEL);
857
858                         if (bulk->bk_iovs[i].bv_page == NULL) {
859                                 lstcon_rpc_put(*crpc);
860                                 return -ENOMEM;
861                         }
862                 }
863
864                 bulk->bk_sink = 0;
865
866                 LASSERT (transop == LST_TRANS_TSBCLIADD);
867
868                 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
869                                           test->tes_cliidx++,
870                                           test->tes_dist,
871                                           test->tes_span,
872                                           npg, &bulk->bk_iovs[0]);
873                 if (rc != 0) {
874                         lstcon_rpc_put(*crpc);
875                         return rc;
876                 }
877
878                 trq->tsr_ndest = test->tes_span;
879                 trq->tsr_loop  = test->tes_loop;
880         }
881
882         trq->tsr_sid        = console_session.ses_id;
883         trq->tsr_bid        = test->tes_hdr.tsb_id;
884         trq->tsr_concur     = test->tes_concur;
885         trq->tsr_is_client  = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
886         trq->tsr_stop_onerr = !!test->tes_stop_onerr;
887
888         switch (test->tes_type) {
889         case LST_TEST_PING:
890                 trq->tsr_service = SRPC_SERVICE_PING;
891                 rc = lstcon_pingrpc_prep((struct lst_test_ping_param *)
892                                          &test->tes_param[0], trq);
893                 break;
894
895         case LST_TEST_BULK:
896                 trq->tsr_service = SRPC_SERVICE_BRW;
897                 if ((feats & LST_FEAT_BULK_LEN) == 0) {
898                         rc = lstcon_bulkrpc_v0_prep((struct lst_test_bulk_param *)
899                                                     &test->tes_param[0], trq);
900                 } else {
901                         rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
902                                                     &test->tes_param[0],
903                                                     trq->tsr_is_client, trq);
904                 }
905
906                 break;
907         default:
908                 LBUG();
909                 break;
910         }
911
912         return rc;
913 }
914
915 static int
916 lstcon_sesnew_stat_reply(struct lstcon_rpc_trans *trans,
917                          struct lstcon_node *nd, struct srpc_msg *reply)
918 {
919         struct srpc_mksn_reply *mksn_rep = &reply->msg_body.mksn_reply;
920         int status = mksn_rep->mksn_status;
921
922         if (status == 0 &&
923             (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
924                 mksn_rep->mksn_status = EPROTO;
925                 status = EPROTO;
926         }
927
928         if (status == EPROTO) {
929                 CNETERR("session protocol error from %s: %u\n",
930                         libcfs_nid2str(nd->nd_id.nid),
931                         reply->msg_ses_feats);
932         }
933
934         if (status != 0)
935                 return status;
936
937         if (!trans->tas_feats_updated) {
938                 spin_lock(&console_session.ses_rpc_lock);
939                 if (!trans->tas_feats_updated) { /* recheck with lock */
940                         trans->tas_feats_updated = 1;
941                         trans->tas_features = reply->msg_ses_feats;
942                 }
943                 spin_unlock(&console_session.ses_rpc_lock);
944         }
945
946         if (reply->msg_ses_feats != trans->tas_features) {
947                 CNETERR("Framework features %x from %s is different with "
948                         "features on this transaction: %x\n",
949                          reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
950                          trans->tas_features);
951                 status = mksn_rep->mksn_status = EPROTO;
952         }
953
954         if (status == 0) {
955                 /* session timeout on remote node */
956                 nd->nd_timeout = mksn_rep->mksn_timeout;
957         }
958
959         return status;
960 }
961
962 void
963 lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg,
964                       struct lstcon_node *nd, struct lstcon_trans_stat *stat)
965 {
966         struct srpc_rmsn_reply *rmsn_rep;
967         struct srpc_debug_reply *dbg_rep;
968         struct srpc_batch_reply *bat_rep;
969         struct srpc_test_reply *test_rep;
970         struct srpc_stat_reply *stat_rep;
971         int rc = 0;
972
973         switch (trans->tas_opc) {
974         case LST_TRANS_SESNEW:
975                 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
976                 if (rc == 0) {
977                         lstcon_sesop_stat_success(stat, 1);
978                         return;
979                 }
980
981                 lstcon_sesop_stat_failure(stat, 1);
982                 break;
983
984         case LST_TRANS_SESEND:
985                 rmsn_rep = &msg->msg_body.rmsn_reply;
986                 /* ESRCH is not an error for end session */
987                 if (rmsn_rep->rmsn_status == 0 ||
988                     rmsn_rep->rmsn_status == ESRCH) {
989                         lstcon_sesop_stat_success(stat, 1);
990                         return;
991                 }
992
993                 lstcon_sesop_stat_failure(stat, 1);
994                 rc = rmsn_rep->rmsn_status;
995                 break;
996
997         case LST_TRANS_SESQRY:
998         case LST_TRANS_SESPING:
999                 dbg_rep = &msg->msg_body.dbg_reply;
1000
1001                 if (dbg_rep->dbg_status == ESRCH) {
1002                         lstcon_sesqry_stat_unknown(stat, 1);
1003                         return;
1004                 }
1005
1006                 if (lstcon_session_match(dbg_rep->dbg_sid))
1007                         lstcon_sesqry_stat_active(stat, 1);
1008                 else
1009                         lstcon_sesqry_stat_busy(stat, 1);
1010                 return;
1011
1012         case LST_TRANS_TSBRUN:
1013         case LST_TRANS_TSBSTOP:
1014                 bat_rep = &msg->msg_body.bat_reply;
1015
1016                 if (bat_rep->bar_status == 0) {
1017                         lstcon_tsbop_stat_success(stat, 1);
1018                         return;
1019                 }
1020
1021                 if (bat_rep->bar_status == EPERM &&
1022                     trans->tas_opc == LST_TRANS_TSBSTOP) {
1023                         lstcon_tsbop_stat_success(stat, 1);
1024                         return;
1025                 }
1026
1027                 lstcon_tsbop_stat_failure(stat, 1);
1028                 rc = bat_rep->bar_status;
1029                 break;
1030
1031         case LST_TRANS_TSBCLIQRY:
1032         case LST_TRANS_TSBSRVQRY:
1033                 bat_rep = &msg->msg_body.bat_reply;
1034
1035                 if (bat_rep->bar_active != 0)
1036                         lstcon_tsbqry_stat_run(stat, 1);
1037                 else
1038                         lstcon_tsbqry_stat_idle(stat, 1);
1039
1040                 if (bat_rep->bar_status == 0)
1041                         return;
1042
1043                 lstcon_tsbqry_stat_failure(stat, 1);
1044                 rc = bat_rep->bar_status;
1045                 break;
1046
1047         case LST_TRANS_TSBCLIADD:
1048         case LST_TRANS_TSBSRVADD:
1049                 test_rep = &msg->msg_body.tes_reply;
1050
1051                 if (test_rep->tsr_status == 0) {
1052                         lstcon_tsbop_stat_success(stat, 1);
1053                         return;
1054                 }
1055
1056                 lstcon_tsbop_stat_failure(stat, 1);
1057                 rc = test_rep->tsr_status;
1058                 break;
1059
1060         case LST_TRANS_STATQRY:
1061                 stat_rep = &msg->msg_body.stat_reply;
1062
1063                 if (stat_rep->str_status == 0) {
1064                         lstcon_statqry_stat_success(stat, 1);
1065                         return;
1066                 }
1067
1068                 lstcon_statqry_stat_failure(stat, 1);
1069                 rc = stat_rep->str_status;
1070                 break;
1071
1072         default:
1073                 LBUG();
1074         }
1075
1076         if (stat->trs_fwk_errno == 0)
1077                 stat->trs_fwk_errno = rc;
1078 }
1079
1080 int
1081 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1082                         struct list_head *translist, int transop,
1083                         void *arg, lstcon_rpc_cond_func_t condition,
1084                         struct lstcon_rpc_trans **transpp)
1085 {
1086         struct lstcon_rpc_trans *trans;
1087         struct lstcon_ndlink *ndl;
1088         struct lstcon_node *nd;
1089         struct lstcon_rpc *rpc;
1090         unsigned int feats;
1091         int rc;
1092
1093         /* Creating session RPG for list of nodes */
1094
1095         rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1096         if (rc != 0) {
1097                 CERROR("Can't create transaction %d: %d\n", transop, rc);
1098                 return rc;
1099         }
1100
1101         feats = trans->tas_features;
1102         list_for_each_entry(ndl, ndlist, ndl_link) {
1103                 rc = condition == NULL ? 1 :
1104                      condition(transop, ndl->ndl_node, arg);
1105
1106                 if (rc == 0)
1107                         continue;
1108
1109                 if (rc < 0) {
1110                         CDEBUG(D_NET, "Condition error while creating RPC "
1111                                       " for transaction %d: %d\n", transop, rc);
1112                         break;
1113                 }
1114
1115                 nd = ndl->ndl_node;
1116
1117                 switch (transop) {
1118                 case LST_TRANS_SESNEW:
1119                 case LST_TRANS_SESEND:
1120                         rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1121                         break;
1122                 case LST_TRANS_SESQRY:
1123                 case LST_TRANS_SESPING:
1124                         rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1125                         break;
1126                 case LST_TRANS_TSBCLIADD:
1127                 case LST_TRANS_TSBSRVADD:
1128                         rc = lstcon_testrpc_prep(nd, transop, feats,
1129                                                  (struct lstcon_test *)arg,
1130                                                  &rpc);
1131                         break;
1132                 case LST_TRANS_TSBRUN:
1133                 case LST_TRANS_TSBSTOP:
1134                 case LST_TRANS_TSBCLIQRY:
1135                 case LST_TRANS_TSBSRVQRY:
1136                         rc = lstcon_batrpc_prep(nd, transop, feats,
1137                                                 (struct lstcon_tsb_hdr *)arg,
1138                                                 &rpc);
1139                         break;
1140                 case LST_TRANS_STATQRY:
1141                         rc = lstcon_statrpc_prep(nd, feats, &rpc);
1142                         break;
1143                 default:
1144                         rc = -EINVAL;
1145                         break;
1146                 }
1147
1148                 if (rc != 0) {
1149                         CERROR("Failed to create RPC for transaction %s: %d\n",
1150                                lstcon_rpc_trans_name(transop), rc);
1151                         break;
1152                 }
1153
1154                 lstcon_rpc_trans_addreq(trans, rpc);
1155         }
1156
1157         if (rc == 0) {
1158                 *transpp = trans;
1159                 return 0;
1160         }
1161
1162         lstcon_rpc_trans_destroy(trans);
1163
1164         return rc;
1165 }
1166
1167 static void
1168 lstcon_rpc_pinger(void *arg)
1169 {
1170         struct stt_timer *ptimer = arg;
1171         struct lstcon_rpc_trans *trans;
1172         struct lstcon_rpc *crpc;
1173         struct srpc_msg *rep;
1174         struct srpc_debug_reqst *drq;
1175         struct lstcon_ndlink *ndl;
1176         struct lstcon_node *nd;
1177         int intv;
1178         int count = 0;
1179         int rc;
1180
1181         /* RPC pinger is a special case of transaction,
1182          * it's called by timer at 8 seconds interval.
1183          */
1184         mutex_lock(&console_session.ses_mutex);
1185
1186         if (console_session.ses_shutdown || console_session.ses_expired) {
1187                 mutex_unlock(&console_session.ses_mutex);
1188                 return;
1189         }
1190
1191         if (!console_session.ses_expired &&
1192             ktime_get_real_seconds() - console_session.ses_laststamp >
1193             (time64_t)console_session.ses_timeout)
1194                 console_session.ses_expired = 1;
1195
1196         trans = console_session.ses_ping;
1197
1198         LASSERT(trans != NULL);
1199
1200         list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1201                 nd = ndl->ndl_node;
1202
1203                 if (console_session.ses_expired) {
1204                         /* idle console, end session on all nodes */
1205                         if (nd->nd_state != LST_NODE_ACTIVE)
1206                                 continue;
1207
1208                         rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1209                                                 trans->tas_features, &crpc);
1210                         if (rc != 0) {
1211                                 CERROR("Out of memory\n");
1212                                 break;
1213                         }
1214
1215                         lstcon_rpc_trans_addreq(trans, crpc);
1216                         lstcon_rpc_post(crpc);
1217
1218                         continue;
1219                 }
1220
1221                 crpc = &nd->nd_ping;
1222
1223                 if (crpc->crp_rpc != NULL) {
1224                         LASSERT(crpc->crp_trans == trans);
1225                         LASSERT(!list_empty(&crpc->crp_link));
1226
1227                         spin_lock(&crpc->crp_rpc->crpc_lock);
1228
1229                         LASSERT(crpc->crp_posted);
1230
1231                         if (!crpc->crp_finished) {
1232                                 /* in flight */
1233                                 spin_unlock(&crpc->crp_rpc->crpc_lock);
1234                                 continue;
1235                         }
1236
1237                         spin_unlock(&crpc->crp_rpc->crpc_lock);
1238
1239                         lstcon_rpc_get_reply(crpc, &rep);
1240
1241                         list_del_init(&crpc->crp_link);
1242
1243                         lstcon_rpc_put(crpc);
1244                 }
1245
1246                 if (nd->nd_state != LST_NODE_ACTIVE)
1247                         continue;
1248
1249                 intv = div_u64(ktime_ms_delta(ktime_get(), nd->nd_stamp),
1250                                MSEC_PER_SEC);
1251                 if (intv < nd->nd_timeout / 2)
1252                         continue;
1253
1254                 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1255                                      trans->tas_features, 0, 0, 1, crpc);
1256                 if (rc != 0) {
1257                         CERROR("Out of memory\n");
1258                         break;
1259                 }
1260
1261                 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1262
1263                 drq->dbg_sid   = console_session.ses_id;
1264                 drq->dbg_flags = 0;
1265
1266                 lstcon_rpc_trans_addreq(trans, crpc);
1267                 lstcon_rpc_post(crpc);
1268
1269                 count++;
1270         }
1271
1272         if (console_session.ses_expired) {
1273                 mutex_unlock(&console_session.ses_mutex);
1274                 return;
1275         }
1276
1277         CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1278
1279         ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1280         stt_add_timer(ptimer);
1281
1282         mutex_unlock(&console_session.ses_mutex);
1283 }
1284
1285 int
1286 lstcon_rpc_pinger_start(void)
1287 {
1288         struct stt_timer *ptimer;
1289         int rc;
1290
1291         LASSERT(list_empty(&console_session.ses_rpc_freelist));
1292         LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1293
1294         rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1295                                    &console_session.ses_ping);
1296         if (rc != 0) {
1297                 CERROR("Failed to create console pinger\n");
1298                 return rc;
1299         }
1300
1301         ptimer = &console_session.ses_ping_timer;
1302         ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1303
1304         stt_add_timer(ptimer);
1305
1306         return 0;
1307 }
1308
1309 void
1310 lstcon_rpc_pinger_stop(void)
1311 {
1312         LASSERT (console_session.ses_shutdown);
1313
1314         stt_del_timer(&console_session.ses_ping_timer);
1315
1316         lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1317         lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1318         lstcon_rpc_trans_destroy(console_session.ses_ping);
1319
1320         memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1321
1322         console_session.ses_ping = NULL;
1323 }
1324
1325 void
1326 lstcon_rpc_cleanup_wait(void)
1327 {
1328         struct lstcon_rpc_trans *trans;
1329         struct lstcon_rpc *crpc;
1330         struct list_head *pacer;
1331         LIST_HEAD(zlist);
1332
1333         /* Called with hold of global mutex */
1334
1335         LASSERT(console_session.ses_shutdown);
1336
1337         while (!list_empty(&console_session.ses_trans_list)) {
1338                 list_for_each(pacer, &console_session.ses_trans_list) {
1339                         trans = list_entry(pacer, struct lstcon_rpc_trans,
1340                                            tas_link);
1341
1342                         CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1343                                lstcon_rpc_trans_name(trans->tas_opc));
1344
1345                         wake_up(&trans->tas_waitq);
1346                 }
1347
1348                 mutex_unlock(&console_session.ses_mutex);
1349
1350                 CWARN("Session is shutting down, "
1351                       "waiting for termination of transactions\n");
1352                 schedule_timeout_uninterruptible(cfs_time_seconds(1));
1353
1354                 mutex_lock(&console_session.ses_mutex);
1355         }
1356
1357         spin_lock(&console_session.ses_rpc_lock);
1358
1359         lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1360                        console_session.ses_rpc_lock,
1361                        "Network is not accessable or target is down, "
1362                        "waiting for %d console RPCs to being recycled\n",
1363                        atomic_read(&console_session.ses_rpc_counter));
1364
1365         list_splice_init(&console_session.ses_rpc_freelist, &zlist);
1366
1367         spin_unlock(&console_session.ses_rpc_lock);
1368
1369         while (!list_empty(&zlist)) {
1370                 crpc = list_entry(zlist.next, struct lstcon_rpc, crp_link);
1371
1372                 list_del(&crpc->crp_link);
1373                 LIBCFS_FREE(crpc, sizeof(*crpc));
1374         }
1375 }
1376
1377 int
1378 lstcon_rpc_module_init(void)
1379 {
1380         INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1381         console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1382         console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1383
1384         console_session.ses_ping = NULL;
1385
1386         spin_lock_init(&console_session.ses_rpc_lock);
1387         atomic_set(&console_session.ses_rpc_counter, 0);
1388         INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1389
1390         return 0;
1391 }
1392
1393 void
1394 lstcon_rpc_module_fini(void)
1395 {
1396         LASSERT(list_empty(&console_session.ses_rpc_freelist));
1397         LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1398 }
1399