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