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