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