Whamcloud - gitweb
LU-2446 build: Update Whamcloud copyright messages for Intel
[fs/lustre-release.git] / lnet / selftest / console.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 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * lnet/selftest/conctl.c
35  *
36  * Infrastructure of LST console
37  *
38  * Author: Liang Zhen <liangzhen@clusterfs.com>
39  */
40
41 #ifdef __KERNEL__
42
43 #include <libcfs/libcfs.h>
44 #include <lnet/lib-lnet.h>
45 #include "console.h"
46 #include "conrpc.h"
47
48 #define LST_NODE_STATE_COUNTER(nd, p)                   \
49 do {                                                    \
50         if ((nd)->nd_state == LST_NODE_ACTIVE)          \
51                 (p)->nle_nactive ++;                    \
52         else if ((nd)->nd_state == LST_NODE_BUSY)       \
53                 (p)->nle_nbusy ++;                      \
54         else if ((nd)->nd_state == LST_NODE_DOWN)       \
55                 (p)->nle_ndown ++;                      \
56         else                                            \
57                 (p)->nle_nunknown ++;                   \
58         (p)->nle_nnode ++;                              \
59 } while (0)
60
61 lstcon_session_t        console_session;
62
63 void
64 lstcon_node_get(lstcon_node_t *nd)
65 {
66         LASSERT (nd->nd_ref >= 1);
67
68         nd->nd_ref++;
69 }
70
71 static int
72 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
73 {
74         lstcon_ndlink_t *ndl;
75         unsigned int     idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
76
77         LASSERT (id.nid != LNET_NID_ANY);
78
79         cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_hash[idx],
80                                       lstcon_ndlink_t, ndl_hlink) {
81                 if (ndl->ndl_node->nd_id.nid != id.nid ||
82                     ndl->ndl_node->nd_id.pid != id.pid)
83                         continue;
84
85                 lstcon_node_get(ndl->ndl_node);
86                 *ndpp = ndl->ndl_node;
87                 return 0;
88         }
89         
90         if (!create)
91                 return -ENOENT;
92
93         LIBCFS_ALLOC(*ndpp, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
94         if (*ndpp == NULL)
95                 return -ENOMEM;
96
97         ndl = (lstcon_ndlink_t *)(*ndpp + 1);
98
99         ndl->ndl_node = *ndpp;
100
101         ndl->ndl_node->nd_ref   = 1;
102         ndl->ndl_node->nd_id    = id;
103         ndl->ndl_node->nd_stamp = cfs_time_current();
104         ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
105         ndl->ndl_node->nd_timeout = 0;
106         memset(&ndl->ndl_node->nd_ping, 0, sizeof(lstcon_rpc_t));
107
108         /* queued in global hash & list, no refcount is taken by
109          * global hash & list, if caller release his refcount,
110          * node will be released */
111         cfs_list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
112         cfs_list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
113
114         return 0;
115 }
116
117 void
118 lstcon_node_put(lstcon_node_t *nd)
119 {
120         lstcon_ndlink_t  *ndl;
121
122         LASSERT (nd->nd_ref > 0);
123
124         if (--nd->nd_ref > 0)
125                 return;
126
127         ndl = (lstcon_ndlink_t *)(nd + 1);
128
129         LASSERT (!cfs_list_empty(&ndl->ndl_link));
130         LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
131
132         /* remove from session */
133         cfs_list_del(&ndl->ndl_link);
134         cfs_list_del(&ndl->ndl_hlink);
135
136         LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
137 }
138
139 static int
140 lstcon_ndlink_find(cfs_list_t *hash,
141                    lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
142 {
143         unsigned int     idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
144         lstcon_ndlink_t *ndl;
145         lstcon_node_t   *nd;
146         int              rc;
147
148         if (id.nid == LNET_NID_ANY)
149                 return -EINVAL;
150
151         /* search in hash */
152         cfs_list_for_each_entry_typed(ndl, &hash[idx],
153                                       lstcon_ndlink_t, ndl_hlink) {
154                 if (ndl->ndl_node->nd_id.nid != id.nid ||
155                     ndl->ndl_node->nd_id.pid != id.pid)
156                         continue;
157
158                 *ndlpp = ndl;
159                 return 0;
160         }
161
162         if (create == 0)
163                 return -ENOENT;
164
165         /* find or create in session hash */
166         rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
167         if (rc != 0)
168                 return rc;
169
170         LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
171         if (ndl == NULL) {
172                 lstcon_node_put(nd);
173                 return -ENOMEM;
174         }
175         
176         *ndlpp = ndl;
177
178         ndl->ndl_node = nd;
179         CFS_INIT_LIST_HEAD(&ndl->ndl_link);
180         cfs_list_add_tail(&ndl->ndl_hlink, &hash[idx]);
181
182         return  0;
183 }
184
185 static void
186 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
187 {
188         LASSERT (cfs_list_empty(&ndl->ndl_link));
189         LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
190
191         cfs_list_del(&ndl->ndl_hlink); /* delete from hash */
192         lstcon_node_put(ndl->ndl_node);
193
194         LIBCFS_FREE(ndl, sizeof(*ndl));
195 }
196
197 static int
198 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
199 {
200         lstcon_group_t *grp;
201         int             i;
202
203         LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
204                                    grp_ndl_hash[LST_NODE_HASHSIZE]));
205         if (grp == NULL)
206                 return -ENOMEM;
207
208         memset(grp, 0, offsetof(lstcon_group_t,
209                                 grp_ndl_hash[LST_NODE_HASHSIZE]));
210
211         grp->grp_ref = 1;
212         if (name != NULL)
213                 strcpy(grp->grp_name, name);
214
215         CFS_INIT_LIST_HEAD(&grp->grp_link);
216         CFS_INIT_LIST_HEAD(&grp->grp_ndl_list);
217         CFS_INIT_LIST_HEAD(&grp->grp_trans_list);
218
219         for (i = 0; i < LST_NODE_HASHSIZE; i++)
220                 CFS_INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
221
222         *grpp = grp;
223
224         return 0;
225 }
226
227 static void
228 lstcon_group_addref(lstcon_group_t *grp)
229 {
230         grp->grp_ref ++;
231 }
232
233 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
234
235 static void
236 lstcon_group_drain(lstcon_group_t *grp, int keep)
237 {
238         lstcon_ndlink_t *ndl;
239         lstcon_ndlink_t *tmp;
240
241         cfs_list_for_each_entry_safe_typed(ndl, tmp, &grp->grp_ndl_list,
242                                            lstcon_ndlink_t, ndl_link) {
243                 if ((ndl->ndl_node->nd_state & keep) == 0)
244                         lstcon_group_ndlink_release(grp, ndl);
245         }
246 }
247
248 static void
249 lstcon_group_decref(lstcon_group_t *grp)
250 {
251         int     i;
252
253         if (--grp->grp_ref > 0)
254                 return;
255
256         if (!cfs_list_empty(&grp->grp_link))
257                 cfs_list_del(&grp->grp_link);
258
259         lstcon_group_drain(grp, 0);
260
261         for (i = 0; i < LST_NODE_HASHSIZE; i++) {
262                 LASSERT (cfs_list_empty(&grp->grp_ndl_hash[i]));
263         }
264
265         LIBCFS_FREE(grp, offsetof(lstcon_group_t,
266                                   grp_ndl_hash[LST_NODE_HASHSIZE]));
267 }
268
269 static int
270 lstcon_group_find(char *name, lstcon_group_t **grpp)
271 {
272         lstcon_group_t   *grp;
273
274         cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
275                                       lstcon_group_t, grp_link) {
276                 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
277                         continue;
278
279                 lstcon_group_addref(grp);  /* +1 ref for caller */
280                 *grpp = grp;
281                 return 0;
282         }
283
284         return -ENOENT;
285 }
286
287 static void
288 lstcon_group_put(lstcon_group_t *grp)
289 {
290         lstcon_group_decref(grp);
291 }
292
293 static int
294 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
295                          lstcon_ndlink_t **ndlpp, int create)
296 {
297         int     rc;
298         
299         rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
300         if (rc != 0)
301                 return rc;
302
303         if (!cfs_list_empty(&(*ndlpp)->ndl_link))
304                 return 0;
305
306         cfs_list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
307         grp->grp_nnode ++;
308
309         return 0;
310 }
311
312 static void
313 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
314 {
315         cfs_list_del_init(&ndl->ndl_link);
316         lstcon_ndlink_release(ndl);
317         grp->grp_nnode --;
318 }
319
320 static void
321 lstcon_group_ndlink_move(lstcon_group_t *old,
322                          lstcon_group_t *new, lstcon_ndlink_t *ndl)
323 {
324         unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
325                            LST_NODE_HASHSIZE;
326
327         cfs_list_del(&ndl->ndl_hlink);
328         cfs_list_del(&ndl->ndl_link);
329         old->grp_nnode --;
330
331         cfs_list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
332         cfs_list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
333         new->grp_nnode ++;
334
335         return;
336 }
337
338 static void
339 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
340 {
341         lstcon_ndlink_t *ndl;
342
343         while (!cfs_list_empty(&old->grp_ndl_list)) {
344                 ndl = cfs_list_entry(old->grp_ndl_list.next,
345                                      lstcon_ndlink_t, ndl_link);
346                 lstcon_group_ndlink_move(old, new, ndl);
347         }
348 }
349
350 int
351 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
352 {
353         lstcon_group_t *grp = (lstcon_group_t *)arg;
354
355         switch (transop) {
356         case LST_TRANS_SESNEW:
357                 if (nd->nd_state == LST_NODE_ACTIVE)
358                         return 0;
359                 break;
360
361         case LST_TRANS_SESEND:
362                 if (nd->nd_state != LST_NODE_ACTIVE)
363                         return 0;
364
365                 if (grp != NULL && nd->nd_ref > 1)
366                         return 0;
367                 break;
368
369         case LST_TRANS_SESQRY:
370                 break;
371
372         default:
373                 LBUG();
374         }
375
376         return 1;
377 }
378
379 int
380 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
381                       lstcon_rpc_ent_t *ent_up)
382 {
383         srpc_debug_reply_t *rep;
384
385         switch (transop) {
386         case LST_TRANS_SESNEW:
387         case LST_TRANS_SESEND:
388                 return 0;
389
390         case LST_TRANS_SESQRY:
391                 rep = &msg->msg_body.dbg_reply;
392
393                 if (cfs_copy_to_user(&ent_up->rpe_priv[0],
394                                      &rep->dbg_timeout, sizeof(int)) ||
395                     cfs_copy_to_user(&ent_up->rpe_payload[0],
396                                      &rep->dbg_name, LST_NAME_SIZE))
397                         return -EFAULT;
398
399                 return 0;
400
401         default:
402                 LBUG();
403         }
404
405         return 0;
406 }
407
408 static int
409 lstcon_group_nodes_add(lstcon_group_t *grp,
410                        int count, lnet_process_id_t *ids_up,
411                        unsigned *featp, cfs_list_t *result_up)
412 {
413         lstcon_rpc_trans_t      *trans;
414         lstcon_ndlink_t         *ndl;
415         lstcon_group_t          *tmp;
416         lnet_process_id_t        id;
417         int                      i;
418         int                      rc;
419
420         rc = lstcon_group_alloc(NULL, &tmp);
421         if (rc != 0) {
422                 CERROR("Out of memory\n");
423                 return -ENOMEM;
424         }
425
426         for (i = 0 ; i < count; i++) {
427                 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
428                         rc = -EFAULT;
429                         break;
430                 }
431
432                 /* skip if it's in this group already */
433                 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
434                 if (rc == 0)
435                         continue;
436
437                 /* add to tmp group */
438                 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
439                 if (rc != 0) {
440                         CERROR("Can't create ndlink, out of memory\n");
441                         break;
442                 }
443         }
444
445         if (rc != 0) {
446                 lstcon_group_put(tmp);
447                 return rc;
448         }
449
450         rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
451                                      &tmp->grp_trans_list, LST_TRANS_SESNEW,
452                                      tmp, lstcon_sesrpc_condition, &trans);
453         if (rc != 0) {
454                 CERROR("Can't create transaction: %d\n", rc);
455                 lstcon_group_put(tmp);
456                 return rc;
457         }
458
459         /* post all RPCs */
460         lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
461
462         rc = lstcon_rpc_trans_interpreter(trans, result_up,
463                                           lstcon_sesrpc_readent);
464         *featp = trans->tas_features;
465
466         /* destroy all RPGs */
467         lstcon_rpc_trans_destroy(trans);
468
469         lstcon_group_move(tmp, grp);
470         lstcon_group_put(tmp);
471
472         return rc;
473 }
474
475 static int
476 lstcon_group_nodes_remove(lstcon_group_t *grp,
477                           int count, lnet_process_id_t *ids_up,
478                           cfs_list_t *result_up)
479 {
480         lstcon_rpc_trans_t     *trans;
481         lstcon_ndlink_t        *ndl;
482         lstcon_group_t         *tmp;
483         lnet_process_id_t       id;
484         int                     rc;
485         int                     i;
486
487         /* End session and remove node from the group */
488
489         rc = lstcon_group_alloc(NULL, &tmp);
490         if (rc != 0) {
491                 CERROR("Out of memory\n");
492                 return -ENOMEM;
493         }
494
495         for (i = 0; i < count; i++) {
496                 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
497                         rc = -EFAULT;
498                         goto error;
499                 }
500                 
501                 /* move node to tmp group */
502                 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
503                         lstcon_group_ndlink_move(grp, tmp, ndl);
504         }
505
506         rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
507                                      &tmp->grp_trans_list, LST_TRANS_SESEND,
508                                      tmp, lstcon_sesrpc_condition, &trans);
509         if (rc != 0) {
510                 CERROR("Can't create transaction: %d\n", rc);
511                 goto error;
512         }
513
514         lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
515
516         rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
517
518         lstcon_rpc_trans_destroy(trans);
519         /* release nodes anyway, because we can't rollback status */
520         lstcon_group_put(tmp);
521
522         return rc;
523 error:
524         lstcon_group_move(tmp, grp);
525         lstcon_group_put(tmp);
526
527         return rc;
528 }
529
530 int
531 lstcon_group_add(char *name)
532 {
533         lstcon_group_t *grp;
534         int             rc;
535
536         rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
537         if (rc != 0) {
538                 /* find a group with same name */
539                 lstcon_group_put(grp);
540                 return rc;
541         }
542
543         rc = lstcon_group_alloc(name, &grp);
544         if (rc != 0) {
545                 CERROR("Can't allocate descriptor for group %s\n", name);
546                 return -ENOMEM;
547         }
548
549         cfs_list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
550
551         return rc;
552 }
553
554 int
555 lstcon_nodes_add(char *name, int count, lnet_process_id_t *ids_up,
556                  unsigned *featp, cfs_list_t *result_up)
557 {
558         lstcon_group_t         *grp;
559         int                     rc;
560
561         LASSERT (count > 0);
562         LASSERT (ids_up != NULL);
563
564         rc = lstcon_group_find(name, &grp);
565         if (rc != 0) {
566                 CDEBUG(D_NET, "Can't find group %s\n", name);
567                 return rc;
568         }
569
570         if (grp->grp_ref > 2) {
571                 /* referred by other threads or test */
572                 CDEBUG(D_NET, "Group %s is busy\n", name);
573                 lstcon_group_put(grp);
574
575                 return -EBUSY;
576         }
577
578         rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
579
580         lstcon_group_put(grp);
581
582         return rc;
583 }
584
585 int
586 lstcon_group_del(char *name)
587 {
588         lstcon_rpc_trans_t *trans;
589         lstcon_group_t     *grp;
590         int                 rc;
591
592         rc = lstcon_group_find(name, &grp);
593         if (rc != 0) {
594                 CDEBUG(D_NET, "Can't find group: %s\n", name);
595                 return rc;
596         }
597
598         if (grp->grp_ref > 2) {
599                 /* referred by others threads or test */
600                 CDEBUG(D_NET, "Group %s is busy\n", name);
601                 lstcon_group_put(grp);
602                 return -EBUSY;
603         }
604
605         rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
606                                      &grp->grp_trans_list, LST_TRANS_SESEND,
607                                      grp, lstcon_sesrpc_condition, &trans);
608         if (rc != 0) {
609                 CERROR("Can't create transaction: %d\n", rc);
610                 lstcon_group_put(grp);
611                 return rc;
612         }
613
614         lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
615
616         lstcon_rpc_trans_destroy(trans);
617
618         lstcon_group_put(grp);
619         /* -ref for session, it's destroyed,
620          * status can't be rolled back, destroy group anway */
621         lstcon_group_put(grp);
622
623         return rc;
624 }
625
626 int
627 lstcon_group_clean(char *name, int args)
628 {
629         lstcon_group_t *grp = NULL;
630         int             rc;
631
632         rc = lstcon_group_find(name, &grp);
633         if (rc != 0) {
634                 CDEBUG(D_NET, "Can't find group %s\n", name);
635                 return rc;
636         }
637
638         if (grp->grp_ref > 2) {
639                 /* referred by test */
640                 CDEBUG(D_NET, "Group %s is busy\n", name);
641                 lstcon_group_put(grp);
642                 return -EBUSY;
643         }
644
645         args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
646                 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
647
648         lstcon_group_drain(grp, args);
649
650         lstcon_group_put(grp);
651         /* release empty group */
652         if (cfs_list_empty(&grp->grp_ndl_list))
653                 lstcon_group_put(grp);
654
655         return 0;
656 }
657
658 int
659 lstcon_nodes_remove(char *name, int count,
660                     lnet_process_id_t *ids_up, cfs_list_t *result_up)
661 {
662         lstcon_group_t *grp = NULL;
663         int             rc;
664
665         rc = lstcon_group_find(name, &grp);
666         if (rc != 0) {
667                 CDEBUG(D_NET, "Can't find group: %s\n", name);
668                 return rc;
669         }
670
671         if (grp->grp_ref > 2) {
672                 /* referred by test */
673                 CDEBUG(D_NET, "Group %s is busy\n", name);
674                 lstcon_group_put(grp);
675                 return -EBUSY;
676         }
677
678         rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
679
680         lstcon_group_put(grp);
681         /* release empty group */
682         if (cfs_list_empty(&grp->grp_ndl_list))
683                 lstcon_group_put(grp);
684
685         return rc;
686 }
687
688 int
689 lstcon_group_refresh(char *name, cfs_list_t *result_up)
690 {
691         lstcon_rpc_trans_t      *trans;
692         lstcon_group_t          *grp;
693         int                      rc;
694
695         rc = lstcon_group_find(name, &grp);
696         if (rc != 0) {
697                 CDEBUG(D_NET, "Can't find group: %s\n", name);
698                 return rc;
699         }
700
701         if (grp->grp_ref > 2) {
702                 /* referred by test */
703                 CDEBUG(D_NET, "Group %s is busy\n", name);
704                 lstcon_group_put(grp);
705                 return -EBUSY;
706         }
707
708         /* re-invite all inactive nodes int the group */
709         rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
710                                      &grp->grp_trans_list, LST_TRANS_SESNEW,
711                                      grp, lstcon_sesrpc_condition, &trans);
712         if (rc != 0) {
713                 /* local error, return */
714                 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
715                 lstcon_group_put(grp);
716                 return rc;
717         }
718
719         lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
720
721         rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
722
723         lstcon_rpc_trans_destroy(trans);
724         /* -ref for me */
725         lstcon_group_put(grp);
726
727         return rc;
728 }
729
730 int
731 lstcon_group_list(int index, int len, char *name_up)
732 {
733         lstcon_group_t *grp;
734
735         LASSERT (index >= 0);
736         LASSERT (name_up != NULL);
737
738         cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
739                                       lstcon_group_t, grp_link) {
740                 if (index-- == 0) {
741                         return cfs_copy_to_user(name_up, grp->grp_name, len) ?
742                                -EFAULT : 0;
743                 }
744         }
745
746         return -ENOENT;
747 }
748
749 static int
750 lstcon_nodes_getent(cfs_list_t *head, int *index_p,
751                     int *count_p, lstcon_node_ent_t *dents_up)
752 {
753         lstcon_ndlink_t  *ndl;
754         lstcon_node_t    *nd;
755         int               count = 0;
756         int               index = 0;
757
758         LASSERT (index_p != NULL && count_p != NULL);
759         LASSERT (dents_up != NULL);
760         LASSERT (*index_p >= 0);
761         LASSERT (*count_p > 0);
762
763         cfs_list_for_each_entry_typed(ndl, head, lstcon_ndlink_t, ndl_link) {
764                 if (index++ < *index_p)
765                         continue;
766
767                 if (count >= *count_p)
768                         break;
769
770                 nd = ndl->ndl_node;
771                 if (cfs_copy_to_user(&dents_up[count].nde_id,
772                                      &nd->nd_id, sizeof(nd->nd_id)) ||
773                     cfs_copy_to_user(&dents_up[count].nde_state,
774                                      &nd->nd_state, sizeof(nd->nd_state)))
775                         return -EFAULT;
776
777                 count ++;
778         }
779
780         if (index <= *index_p)
781                 return -ENOENT;
782
783         *count_p = count;
784         *index_p = index;
785
786         return 0;
787 }
788
789 int
790 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
791                   int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
792 {
793         lstcon_ndlist_ent_t *gentp;
794         lstcon_group_t      *grp;
795         lstcon_ndlink_t     *ndl;
796         int                  rc;
797
798         rc = lstcon_group_find(name, &grp);
799         if (rc != 0) {
800                 CDEBUG(D_NET, "Can't find group %s\n", name);
801                 return rc;
802         }
803
804         if (dents_up != 0) {
805                 /* verbose query */
806                 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
807                                          index_p, count_p, dents_up);
808                 lstcon_group_put(grp);
809
810                 return rc;
811         }
812
813         /* non-verbose query */
814         LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
815         if (gentp == NULL) {
816                 CERROR("Can't allocate ndlist_ent\n");
817                 lstcon_group_put(grp);
818
819                 return -ENOMEM;
820         }
821
822         memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
823
824         cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
825                                       lstcon_ndlink_t, ndl_link)
826                 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
827
828         rc = cfs_copy_to_user(gents_p, gentp,
829                               sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
830
831         LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
832
833         lstcon_group_put(grp);
834
835         return 0;
836 }
837
838 int
839 lstcon_batch_find(char *name, lstcon_batch_t **batpp)
840 {
841         lstcon_batch_t   *bat;
842
843         cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
844                                       lstcon_batch_t, bat_link) {
845                 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
846                         *batpp = bat;
847                         return 0;
848                 }
849         }
850
851         return -ENOENT;
852 }
853
854 int
855 lstcon_batch_add(char *name)
856 {
857         lstcon_batch_t   *bat;
858         int               i;
859         int               rc;
860
861         rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
862         if (rc != 0) {
863                 CDEBUG(D_NET, "Batch %s already exists\n", name);
864                 return rc;
865         }
866
867         LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
868         if (bat == NULL) {
869                 CERROR("Can't allocate descriptor for batch %s\n", name);
870                 return -ENOMEM;
871         }
872
873         LIBCFS_ALLOC(bat->bat_cli_hash,
874                      sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
875         if (bat->bat_cli_hash == NULL) {
876                 CERROR("Can't allocate hash for batch %s\n", name);
877                 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
878
879                 return -ENOMEM;
880         }
881
882         LIBCFS_ALLOC(bat->bat_srv_hash,
883                      sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
884         if (bat->bat_srv_hash == NULL) {
885                 CERROR("Can't allocate hash for batch %s\n", name);
886                 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
887                 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
888
889                 return -ENOMEM;
890         }
891
892         strcpy(bat->bat_name, name);
893         bat->bat_hdr.tsb_index = 0;
894         bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
895
896         bat->bat_ntest = 0;
897         bat->bat_state = LST_BATCH_IDLE;
898
899         CFS_INIT_LIST_HEAD(&bat->bat_cli_list);
900         CFS_INIT_LIST_HEAD(&bat->bat_srv_list);
901         CFS_INIT_LIST_HEAD(&bat->bat_test_list);
902         CFS_INIT_LIST_HEAD(&bat->bat_trans_list);
903
904         for (i = 0; i < LST_NODE_HASHSIZE; i++) {
905                 CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
906                 CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
907         }
908
909         cfs_list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
910
911         return rc;
912 }
913
914 int
915 lstcon_batch_list(int index, int len, char *name_up)
916 {
917         lstcon_batch_t    *bat;
918
919         LASSERT (name_up != NULL);
920         LASSERT (index >= 0);
921
922         cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
923                                       lstcon_batch_t, bat_link) {
924                 if (index-- == 0) {
925                         return cfs_copy_to_user(name_up,bat->bat_name, len) ?
926                                -EFAULT: 0;
927                 }
928         }
929
930         return -ENOENT;
931 }
932
933 int
934 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
935                   int testidx, int *index_p, int *ndent_p,
936                   lstcon_node_ent_t *dents_up)
937 {
938         lstcon_test_batch_ent_t *entp;
939         cfs_list_t              *clilst;
940         cfs_list_t              *srvlst;
941         lstcon_test_t           *test = NULL;
942         lstcon_batch_t          *bat;
943         lstcon_ndlink_t         *ndl;
944         int                      rc;
945
946         rc = lstcon_batch_find(name, &bat);
947         if (rc != 0) {
948                 CDEBUG(D_NET, "Can't find batch %s\n", name);
949                 return -ENOENT;
950         }
951
952         if (testidx > 0) {
953                 /* query test, test index start from 1 */
954                 cfs_list_for_each_entry_typed(test, &bat->bat_test_list,
955                                               lstcon_test_t, tes_link) {
956                         if (testidx-- == 1)
957                                 break;
958                 }
959
960                 if (testidx > 0) {
961                         CDEBUG(D_NET, "Can't find specified test in batch\n");
962                         return -ENOENT;
963                 }
964         }
965
966         clilst = (test == NULL) ? &bat->bat_cli_list :
967                                   &test->tes_src_grp->grp_ndl_list;
968         srvlst = (test == NULL) ? &bat->bat_srv_list :
969                                   &test->tes_dst_grp->grp_ndl_list;
970
971         if (dents_up != NULL) {
972                 rc = lstcon_nodes_getent((server ? srvlst: clilst),
973                                          index_p, ndent_p, dents_up);
974                 return rc;
975         }
976
977         /* non-verbose query */
978         LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
979         if (entp == NULL)
980                 return -ENOMEM;
981
982         memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
983
984         if (test == NULL) {
985                 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
986                 entp->u.tbe_batch.bae_state = bat->bat_state;
987
988         } else {
989
990                 entp->u.tbe_test.tse_type   = test->tes_type;
991                 entp->u.tbe_test.tse_loop   = test->tes_loop;
992                 entp->u.tbe_test.tse_concur = test->tes_concur;
993         }
994
995         cfs_list_for_each_entry_typed(ndl, clilst, lstcon_ndlink_t, ndl_link)
996                 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
997
998         cfs_list_for_each_entry_typed(ndl, srvlst, lstcon_ndlink_t, ndl_link)
999                 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
1000
1001         rc = cfs_copy_to_user(ent_up, entp,
1002                               sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
1003
1004         LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1005
1006         return rc;
1007 }
1008
1009 int
1010 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1011 {
1012         switch (transop) {
1013         case LST_TRANS_TSBRUN:
1014                 if (nd->nd_state != LST_NODE_ACTIVE)
1015                         return -ENETDOWN;
1016                 break;
1017
1018         case LST_TRANS_TSBSTOP:
1019                 if (nd->nd_state != LST_NODE_ACTIVE)
1020                         return 0;
1021                 break;
1022
1023         case LST_TRANS_TSBCLIQRY:
1024         case LST_TRANS_TSBSRVQRY:
1025                 break;
1026         }
1027
1028         return 1;
1029 }
1030
1031 static int
1032 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1033                 cfs_list_t *result_up)
1034 {
1035         lstcon_rpc_trans_t *trans;
1036         int                 rc;
1037
1038         rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1039                                      &bat->bat_trans_list, transop,
1040                                      bat, lstcon_batrpc_condition, &trans);
1041         if (rc != 0) {
1042                 CERROR("Can't create transaction: %d\n", rc);
1043                 return rc;
1044         }
1045
1046         lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1047
1048         rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1049
1050         lstcon_rpc_trans_destroy(trans);
1051
1052         return rc;
1053 }
1054
1055 int
1056 lstcon_batch_run(char *name, int timeout, cfs_list_t *result_up)
1057 {
1058         lstcon_batch_t *bat;
1059         int             rc;
1060
1061         if (lstcon_batch_find(name, &bat) != 0) {
1062                 CDEBUG(D_NET, "Can't find batch %s\n", name);
1063                 return -ENOENT;
1064         }
1065
1066         bat->bat_arg = timeout;
1067
1068         rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1069
1070         /* mark batch as running if it's started in any node */
1071         if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1072                 bat->bat_state = LST_BATCH_RUNNING;
1073
1074         return rc;
1075 }
1076
1077 int
1078 lstcon_batch_stop(char *name, int force, cfs_list_t *result_up)
1079 {
1080         lstcon_batch_t *bat;
1081         int             rc;
1082
1083         if (lstcon_batch_find(name, &bat) != 0) {
1084                 CDEBUG(D_NET, "Can't find batch %s\n", name);
1085                 return -ENOENT;
1086         }
1087
1088         bat->bat_arg = force;
1089
1090         rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1091         
1092         /* mark batch as stopped if all RPCs finished */
1093         if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1094                 bat->bat_state = LST_BATCH_IDLE;
1095
1096         return rc;
1097 }
1098
1099 static void
1100 lstcon_batch_destroy(lstcon_batch_t *bat)
1101 {
1102         lstcon_ndlink_t    *ndl;
1103         lstcon_test_t      *test;
1104         int                 i;
1105
1106         cfs_list_del(&bat->bat_link);
1107
1108         while (!cfs_list_empty(&bat->bat_test_list)) {
1109                 test = cfs_list_entry(bat->bat_test_list.next,
1110                                       lstcon_test_t, tes_link);
1111                 LASSERT (cfs_list_empty(&test->tes_trans_list));
1112
1113                 cfs_list_del(&test->tes_link);
1114
1115                 lstcon_group_put(test->tes_src_grp);
1116                 lstcon_group_put(test->tes_dst_grp);
1117
1118                 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1119                                            tes_param[test->tes_paramlen]));
1120         }
1121
1122         LASSERT (cfs_list_empty(&bat->bat_trans_list));
1123
1124         while (!cfs_list_empty(&bat->bat_cli_list)) {
1125                 ndl = cfs_list_entry(bat->bat_cli_list.next,
1126                                      lstcon_ndlink_t, ndl_link);
1127                 cfs_list_del_init(&ndl->ndl_link);
1128
1129                 lstcon_ndlink_release(ndl);
1130         }
1131
1132         while (!cfs_list_empty(&bat->bat_srv_list)) {
1133                 ndl = cfs_list_entry(bat->bat_srv_list.next,
1134                                      lstcon_ndlink_t, ndl_link);
1135                 cfs_list_del_init(&ndl->ndl_link);
1136
1137                 lstcon_ndlink_release(ndl);
1138         }
1139
1140         for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1141                 LASSERT (cfs_list_empty(&bat->bat_cli_hash[i]));
1142                 LASSERT (cfs_list_empty(&bat->bat_srv_hash[i]));
1143         }
1144
1145         LIBCFS_FREE(bat->bat_cli_hash,
1146                     sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
1147         LIBCFS_FREE(bat->bat_srv_hash,
1148                     sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
1149         LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1150 }
1151
1152 int
1153 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1154 {
1155         lstcon_test_t    *test;
1156         lstcon_batch_t   *batch;
1157         lstcon_ndlink_t  *ndl;
1158         cfs_list_t       *hash;
1159         cfs_list_t       *head;
1160
1161         test = (lstcon_test_t *)arg;
1162         LASSERT (test != NULL);
1163
1164         batch = test->tes_batch;
1165         LASSERT (batch != NULL);
1166
1167         if (test->tes_oneside &&
1168             transop == LST_TRANS_TSBSRVADD)
1169                 return 0;
1170
1171         if (nd->nd_state != LST_NODE_ACTIVE)
1172                 return -ENETDOWN;
1173
1174         if (transop == LST_TRANS_TSBCLIADD) {
1175                 hash = batch->bat_cli_hash;
1176                 head = &batch->bat_cli_list;
1177         
1178         } else {
1179                 LASSERT (transop == LST_TRANS_TSBSRVADD);
1180
1181                 hash = batch->bat_srv_hash;
1182                 head = &batch->bat_srv_list;
1183         }
1184
1185         LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1186
1187         if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1188                 return -ENOMEM;
1189
1190         if (cfs_list_empty(&ndl->ndl_link))
1191                 cfs_list_add_tail(&ndl->ndl_link, head);
1192
1193         return 1;
1194 }
1195
1196 static int
1197 lstcon_test_nodes_add(lstcon_test_t *test, cfs_list_t *result_up)
1198 {
1199         lstcon_rpc_trans_t     *trans;
1200         lstcon_group_t         *grp;
1201         int                     transop;
1202         int                     rc;
1203
1204         LASSERT (test->tes_src_grp != NULL);
1205         LASSERT (test->tes_dst_grp != NULL);
1206
1207         transop = LST_TRANS_TSBSRVADD;
1208         grp  = test->tes_dst_grp;
1209 again:
1210         rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1211                                      &test->tes_trans_list, transop,
1212                                      test, lstcon_testrpc_condition, &trans);
1213         if (rc != 0) {
1214                 CERROR("Can't create transaction: %d\n", rc);
1215                 return rc;
1216         }
1217
1218         lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1219
1220         if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1221             lstcon_trans_stat()->trs_fwk_errno != 0) {
1222                 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1223
1224                 lstcon_rpc_trans_destroy(trans);
1225                 /* return if any error */
1226                 CDEBUG(D_NET, "Failed to add test %s, "
1227                               "RPC error %d, framework error %d\n",
1228                        transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1229                        lstcon_trans_stat()->trs_rpc_errno,
1230                        lstcon_trans_stat()->trs_fwk_errno);
1231
1232                 return rc;
1233         }
1234
1235         lstcon_rpc_trans_destroy(trans);
1236
1237         if (transop == LST_TRANS_TSBCLIADD)
1238                 return rc;
1239
1240         transop = LST_TRANS_TSBCLIADD;
1241         grp = test->tes_src_grp;
1242         test->tes_cliidx = 0;
1243
1244         /* requests to test clients */
1245         goto again;
1246 }
1247
1248 int
1249 lstcon_test_add(char *name, int type, int loop, int concur,
1250                 int dist, int span, char *src_name, char * dst_name,
1251                 void *param, int paramlen, int *retp,
1252                 cfs_list_t *result_up)
1253 {
1254         lstcon_group_t  *src_grp = NULL;
1255         lstcon_group_t  *dst_grp = NULL;
1256         lstcon_test_t   *test    = NULL;
1257         lstcon_batch_t  *batch;
1258         int              rc;
1259
1260         rc = lstcon_batch_find(name, &batch);
1261         if (rc != 0) {
1262                 CDEBUG(D_NET, "Can't find batch %s\n", name);
1263                 return rc;
1264         }
1265
1266         if (batch->bat_state != LST_BATCH_IDLE) {
1267                 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1268                 return rc;
1269         }
1270
1271         rc = lstcon_group_find(src_name, &src_grp);
1272         if (rc != 0) {
1273                 CDEBUG(D_NET, "Can't find group %s\n", src_name);
1274                 goto out;
1275         }
1276
1277         rc = lstcon_group_find(dst_name, &dst_grp);
1278         if (rc != 0) {
1279                 CDEBUG(D_NET, "Can't find group %s\n", dst_name);
1280                 goto out;
1281         }
1282
1283         if (dst_grp->grp_userland)
1284                 *retp = 1;
1285
1286         LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1287         if (!test) {
1288                 CERROR("Can't allocate test descriptor\n");
1289                 rc = -ENOMEM;
1290
1291                 goto out;
1292         }
1293
1294         memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1295         test->tes_hdr.tsb_id    = batch->bat_hdr.tsb_id;
1296         test->tes_batch         = batch;
1297         test->tes_type          = type;
1298         test->tes_oneside       = 0; /* TODO */
1299         test->tes_loop          = loop;
1300         test->tes_concur        = concur;
1301         test->tes_stop_onerr    = 1; /* TODO */
1302         test->tes_span          = span;
1303         test->tes_dist          = dist;
1304         test->tes_cliidx        = 0; /* just used for creating RPC */
1305         test->tes_src_grp       = src_grp;
1306         test->tes_dst_grp       = dst_grp;
1307         CFS_INIT_LIST_HEAD(&test->tes_trans_list);
1308
1309         if (param != NULL) {
1310                 test->tes_paramlen = paramlen;
1311                 memcpy(&test->tes_param[0], param, paramlen);
1312         }
1313
1314         rc = lstcon_test_nodes_add(test, result_up);
1315
1316         if (rc != 0)
1317                 goto out;
1318
1319         if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1320             lstcon_trans_stat()->trs_fwk_errno != 0)
1321                 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type, name);
1322
1323         /* add to test list anyway, so user can check what's going on */
1324         cfs_list_add_tail(&test->tes_link, &batch->bat_test_list);
1325
1326         batch->bat_ntest ++;
1327         test->tes_hdr.tsb_index = batch->bat_ntest;
1328
1329         /*  hold groups so nobody can change them */
1330         return rc;
1331 out:
1332         if (test != NULL)
1333                 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1334
1335         if (dst_grp != NULL)
1336                 lstcon_group_put(dst_grp);
1337
1338         if (src_grp != NULL)
1339                 lstcon_group_put(src_grp);
1340
1341         return rc;
1342 }
1343
1344 int
1345 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1346 {
1347         lstcon_test_t *test;
1348
1349         cfs_list_for_each_entry_typed(test, &batch->bat_test_list,
1350                                       lstcon_test_t, tes_link) {
1351                 if (idx == test->tes_hdr.tsb_index) {
1352                         *testpp = test;
1353                         return 0;
1354                 }
1355         }
1356
1357         return -ENOENT;
1358 }
1359
1360 int
1361 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1362                       lstcon_rpc_ent_t *ent_up)
1363 {
1364         srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1365
1366         LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1367                  transop == LST_TRANS_TSBSRVQRY);
1368
1369         /* positive errno, framework error code */
1370         if (cfs_copy_to_user(&ent_up->rpe_priv[0],
1371                              &rep->bar_active, sizeof(rep->bar_active)))
1372                 return -EFAULT;
1373
1374         return 0;
1375 }
1376
1377 int
1378 lstcon_test_batch_query(char *name, int testidx, int client,
1379                         int timeout, cfs_list_t *result_up)
1380 {
1381         lstcon_rpc_trans_t *trans;
1382         cfs_list_t         *translist;
1383         cfs_list_t         *ndlist;
1384         lstcon_tsb_hdr_t   *hdr;
1385         lstcon_batch_t     *batch;
1386         lstcon_test_t      *test = NULL;
1387         int                 transop;
1388         int                 rc;
1389
1390         rc = lstcon_batch_find(name, &batch);
1391         if (rc != 0) {
1392                 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1393                 return rc;
1394         }
1395
1396         if (testidx == 0) {
1397                 translist = &batch->bat_trans_list;
1398                 ndlist    = &batch->bat_cli_list;
1399                 hdr       = &batch->bat_hdr;
1400
1401         } else {
1402                 /* query specified test only */
1403                 rc = lstcon_test_find(batch, testidx, &test);
1404                 if (rc != 0) {
1405                         CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1406                         return rc;
1407                 }
1408         
1409                 translist = &test->tes_trans_list;
1410                 ndlist    = &test->tes_src_grp->grp_ndl_list;
1411                 hdr       = &test->tes_hdr;
1412         } 
1413
1414         transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1415
1416         rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1417                                      lstcon_batrpc_condition, &trans);
1418         if (rc != 0) {
1419                 CERROR("Can't create transaction: %d\n", rc);
1420                 return rc;
1421         }
1422
1423         lstcon_rpc_trans_postwait(trans, timeout);
1424
1425         if (testidx == 0 && /* query a batch, not a test */
1426             lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1427             lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1428                 /* all RPCs finished, and no active test */
1429                 batch->bat_state = LST_BATCH_IDLE;
1430         }
1431
1432         rc = lstcon_rpc_trans_interpreter(trans, result_up,
1433                                           lstcon_tsbrpc_readent);
1434         lstcon_rpc_trans_destroy(trans);
1435
1436         return rc;
1437 }
1438
1439 int
1440 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1441                        lstcon_rpc_ent_t *ent_up)
1442 {
1443         srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1444         sfw_counters_t    *sfwk_stat;
1445         srpc_counters_t   *srpc_stat;
1446         lnet_counters_t   *lnet_stat;
1447         
1448         if (rep->str_status != 0)
1449                 return 0;
1450
1451         sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1452         srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1453         lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1454
1455         if (cfs_copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1456             cfs_copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1457             cfs_copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1458                 return -EFAULT;
1459
1460         return 0;
1461 }
1462
1463 int
1464 lstcon_ndlist_stat(cfs_list_t *ndlist,
1465                    int timeout, cfs_list_t *result_up)
1466 {
1467         cfs_list_t          head;
1468         lstcon_rpc_trans_t *trans;
1469         int                 rc;
1470
1471         CFS_INIT_LIST_HEAD(&head);
1472
1473         rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1474                                      LST_TRANS_STATQRY, NULL, NULL, &trans);
1475         if (rc != 0) {
1476                 CERROR("Can't create transaction: %d\n", rc);
1477                 return rc;
1478         }
1479
1480         lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1481
1482         rc = lstcon_rpc_trans_interpreter(trans, result_up,
1483                                           lstcon_statrpc_readent);
1484         lstcon_rpc_trans_destroy(trans);
1485
1486         return rc;
1487 }
1488
1489 int
1490 lstcon_group_stat(char *grp_name, int timeout, cfs_list_t *result_up)
1491 {
1492         lstcon_group_t     *grp;
1493         int                 rc;
1494
1495         rc = lstcon_group_find(grp_name, &grp);
1496         if (rc != 0) {
1497                 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1498                 return rc;
1499         }
1500
1501         rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1502
1503         lstcon_group_put(grp);
1504
1505         return rc;
1506 }
1507
1508 int
1509 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1510                   int timeout, cfs_list_t *result_up)
1511 {
1512         lstcon_ndlink_t         *ndl;
1513         lstcon_group_t          *tmp;
1514         lnet_process_id_t        id;
1515         int                      i;
1516         int                      rc;
1517
1518         rc = lstcon_group_alloc(NULL, &tmp);
1519         if (rc != 0) {
1520                 CERROR("Out of memory\n");
1521                 return -ENOMEM;
1522         }
1523
1524         for (i = 0 ; i < count; i++) {
1525                 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
1526                         rc = -EFAULT;
1527                         break;
1528                 }
1529
1530                 /* add to tmp group */
1531                 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1532                 if (rc != 0) {
1533                         CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1534                                "Failed to find or create %s: %d\n",
1535                                libcfs_id2str(id), rc);
1536                         break;
1537                 }
1538         }
1539
1540         if (rc != 0) {
1541                 lstcon_group_put(tmp);
1542                 return rc;
1543         }
1544
1545         rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1546
1547         lstcon_group_put(tmp);
1548
1549         return rc;
1550 }
1551
1552 int
1553 lstcon_debug_ndlist(cfs_list_t *ndlist,
1554                     cfs_list_t *translist,
1555                     int timeout, cfs_list_t *result_up)
1556 {
1557         lstcon_rpc_trans_t *trans;
1558         int                 rc;
1559
1560         rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1561                                      NULL, lstcon_sesrpc_condition, &trans);
1562         if (rc != 0) {
1563                 CERROR("Can't create transaction: %d\n", rc);
1564                 return rc;
1565         }
1566
1567         lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1568
1569         rc = lstcon_rpc_trans_interpreter(trans, result_up,
1570                                           lstcon_sesrpc_readent);
1571         lstcon_rpc_trans_destroy(trans);
1572
1573         return rc;
1574 }
1575
1576 int
1577 lstcon_session_debug(int timeout, cfs_list_t *result_up)
1578 {
1579         return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1580                                    NULL, timeout, result_up);
1581 }
1582
1583 int
1584 lstcon_batch_debug(int timeout, char *name,
1585                    int client, cfs_list_t *result_up)
1586 {
1587         lstcon_batch_t *bat;
1588         int             rc;
1589
1590         rc = lstcon_batch_find(name, &bat);
1591         if (rc != 0)
1592                 return -ENOENT;
1593
1594         rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1595                                           &bat->bat_srv_list,
1596                                  NULL, timeout, result_up);
1597
1598         return rc;
1599 }
1600
1601 int
1602 lstcon_group_debug(int timeout, char *name,
1603                    cfs_list_t *result_up)
1604 {
1605         lstcon_group_t *grp;
1606         int             rc;
1607
1608         rc = lstcon_group_find(name, &grp);
1609         if (rc != 0)
1610                 return -ENOENT;
1611
1612         rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1613                                  timeout, result_up);
1614         lstcon_group_put(grp);
1615
1616         return rc;
1617 }
1618
1619 int
1620 lstcon_nodes_debug(int timeout,
1621                    int count, lnet_process_id_t *ids_up, 
1622                    cfs_list_t *result_up)
1623 {
1624         lnet_process_id_t  id;
1625         lstcon_ndlink_t   *ndl;
1626         lstcon_group_t    *grp;
1627         int                i;
1628         int                rc;
1629
1630         rc = lstcon_group_alloc(NULL, &grp);
1631         if (rc != 0) {
1632                 CDEBUG(D_NET, "Out of memory\n");
1633                 return rc;
1634         }
1635
1636         for (i = 0; i < count; i++) {
1637                 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
1638                         rc = -EFAULT;
1639                         break;
1640                 }
1641
1642                 /* node is added to tmp group */
1643                 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1644                 if (rc != 0) {
1645                         CERROR("Can't create node link\n");
1646                         break;
1647                 }
1648         }
1649
1650         if (rc != 0) {
1651                 lstcon_group_put(grp);
1652                 return rc;
1653         }
1654
1655         rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1656                                  timeout, result_up);
1657
1658         lstcon_group_put(grp);
1659
1660         return rc;
1661 }
1662
1663 int
1664 lstcon_session_match(lst_sid_t sid)
1665 {
1666         return (console_session.ses_id.ses_nid   == sid.ses_nid &&
1667                 console_session.ses_id.ses_stamp == sid.ses_stamp) ?  1: 0;
1668 }
1669
1670 static void
1671 lstcon_new_session_id(lst_sid_t *sid)
1672 {
1673         lnet_process_id_t      id;
1674
1675         LASSERT (console_session.ses_state == LST_SESSION_NONE);
1676
1677         LNetGetId(1, &id);
1678         sid->ses_nid   = id.nid;
1679         sid->ses_stamp = cfs_time_current();
1680 }
1681
1682 extern srpc_service_t lstcon_acceptor_service;
1683
1684 int
1685 lstcon_session_new(char *name, int key, unsigned feats,
1686                    int timeout, int force, lst_sid_t *sid_up)
1687 {
1688         int     rc = 0;
1689         int     i;
1690
1691         if (console_session.ses_state != LST_SESSION_NONE) {
1692                 /* session exists */
1693                 if (!force) {
1694                         CNETERR("Session %s already exists\n",
1695                                 console_session.ses_name);
1696                         return -EEXIST;
1697                 }
1698
1699                 rc = lstcon_session_end();
1700
1701                 /* lstcon_session_end() only return local error */
1702                 if  (rc != 0)
1703                         return rc;
1704         }
1705
1706         if ((feats & ~LST_FEATS_MASK) != 0) {
1707                 CNETERR("Unknown session features %x\n",
1708                         (feats & ~LST_FEATS_MASK));
1709                 return -EINVAL;
1710         }
1711
1712         for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1713                 LASSERT(cfs_list_empty(&console_session.ses_ndl_hash[i]));
1714
1715         lstcon_new_session_id(&console_session.ses_id);
1716
1717         console_session.ses_key     = key;
1718         console_session.ses_state   = LST_SESSION_ACTIVE;
1719         console_session.ses_force   = !!force;
1720         console_session.ses_features = feats;
1721         console_session.ses_feats_updated = 0;
1722         console_session.ses_timeout = (timeout <= 0) ?
1723                                       LST_CONSOLE_TIMEOUT : timeout;
1724         strcpy(console_session.ses_name, name);
1725
1726         rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1727         if (rc != 0)
1728                 return rc;
1729
1730         rc = lstcon_rpc_pinger_start();
1731         if (rc != 0) {
1732                 lstcon_batch_t *bat = NULL;
1733
1734                 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1735                 lstcon_batch_destroy(bat);
1736
1737                 return rc;
1738         }
1739
1740         if (cfs_copy_to_user(sid_up, &console_session.ses_id,
1741                              sizeof(lst_sid_t)) == 0)
1742                 return rc;
1743
1744         lstcon_session_end();
1745
1746         return -EFAULT;
1747 }
1748
1749 int
1750 lstcon_session_info(lst_sid_t *sid_up, int *key_up, unsigned *featp,
1751                     lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1752 {
1753         lstcon_ndlist_ent_t *entp;
1754         lstcon_ndlink_t     *ndl;
1755         int                  rc = 0;
1756
1757         if (console_session.ses_state != LST_SESSION_ACTIVE)
1758                 return -ESRCH;
1759
1760         LIBCFS_ALLOC(entp, sizeof(*entp));
1761         if (entp == NULL)
1762                 return -ENOMEM;
1763
1764         memset(entp, 0, sizeof(*entp));
1765
1766         cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_list,
1767                                       lstcon_ndlink_t, ndl_link)
1768                 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1769
1770         if (cfs_copy_to_user(sid_up, &console_session.ses_id,
1771                              sizeof(lst_sid_t)) ||
1772             cfs_copy_to_user(key_up, &console_session.ses_key,
1773                              sizeof(*key_up)) ||
1774             cfs_copy_to_user(featp, &console_session.ses_features,
1775                              sizeof(*featp)) ||
1776             cfs_copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1777             cfs_copy_to_user(name_up, console_session.ses_name, len))
1778                 rc = -EFAULT;
1779
1780         LIBCFS_FREE(entp, sizeof(*entp));
1781
1782         return rc;
1783 }
1784
1785 int
1786 lstcon_session_end()
1787 {
1788         lstcon_rpc_trans_t *trans;
1789         lstcon_group_t     *grp;
1790         lstcon_batch_t     *bat;
1791         int                 rc = 0;
1792
1793         LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1794
1795         rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list, 
1796                                      NULL, LST_TRANS_SESEND, NULL,
1797                                      lstcon_sesrpc_condition, &trans);
1798         if (rc != 0) {
1799                 CERROR("Can't create transaction: %d\n", rc);
1800                 return rc;
1801         }
1802
1803         console_session.ses_shutdown = 1;
1804
1805         lstcon_rpc_pinger_stop();
1806
1807         lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1808
1809         lstcon_rpc_trans_destroy(trans);
1810         /* User can do nothing even rpc failed, so go on */
1811
1812         /* waiting for orphan rpcs to die */
1813         lstcon_rpc_cleanup_wait();
1814
1815         console_session.ses_id    = LST_INVALID_SID;
1816         console_session.ses_state = LST_SESSION_NONE;
1817         console_session.ses_key   = 0;
1818         console_session.ses_force = 0;
1819         console_session.ses_feats_updated = 0;
1820
1821         /* destroy all batches */
1822         while (!cfs_list_empty(&console_session.ses_bat_list)) {
1823                 bat = cfs_list_entry(console_session.ses_bat_list.next,
1824                                      lstcon_batch_t, bat_link);
1825
1826                 lstcon_batch_destroy(bat);
1827         }
1828
1829         /* destroy all groups */
1830         while (!cfs_list_empty(&console_session.ses_grp_list)) {
1831                 grp = cfs_list_entry(console_session.ses_grp_list.next,
1832                                      lstcon_group_t, grp_link);
1833                 LASSERT (grp->grp_ref == 1);
1834
1835                 lstcon_group_put(grp);
1836         }
1837
1838         /* all nodes should be released */
1839         LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
1840
1841         console_session.ses_shutdown = 0;
1842         console_session.ses_expired  = 0;
1843
1844         return rc;
1845 }
1846
1847 int
1848 lstcon_session_feats_check(unsigned feats)
1849 {
1850         int rc = 0;
1851
1852         if ((feats & ~LST_FEATS_MASK) != 0) {
1853                 CERROR("Can't support these features: %x\n",
1854                        (feats & ~LST_FEATS_MASK));
1855                 return -EPROTO;
1856         }
1857
1858         spin_lock(&console_session.ses_rpc_lock);
1859
1860         if (!console_session.ses_feats_updated) {
1861                 console_session.ses_feats_updated = 1;
1862                 console_session.ses_features = feats;
1863         }
1864
1865         if (console_session.ses_features != feats)
1866                 rc = -EPROTO;
1867
1868         spin_unlock(&console_session.ses_rpc_lock);
1869
1870         if (rc != 0) {
1871                 CERROR("remote features %x do not match with "
1872                        "session features %x of console\n",
1873                        feats, console_session.ses_features);
1874         }
1875
1876         return rc;
1877 }
1878
1879 static int
1880 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1881 {
1882         srpc_msg_t        *rep  = &rpc->srpc_replymsg;
1883         srpc_msg_t        *req  = &rpc->srpc_reqstbuf->buf_msg;
1884         srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1885         srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1886         lstcon_group_t    *grp  = NULL;
1887         lstcon_ndlink_t   *ndl;
1888         int                rc   = 0;
1889
1890         sfw_unpack_message(req);
1891
1892         mutex_lock(&console_session.ses_mutex);
1893
1894         jrep->join_sid = console_session.ses_id;
1895
1896         if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1897                 jrep->join_status = ESRCH;
1898                 goto out;
1899         }
1900
1901         if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1902                 jrep->join_status = EPROTO;
1903                 goto out;
1904         }
1905
1906         if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1907              !lstcon_session_match(jreq->join_sid)) {
1908                 jrep->join_status = EBUSY;
1909                 goto out;
1910         }
1911
1912         if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1913                 rc = lstcon_group_alloc(jreq->join_group, &grp);
1914                 if (rc != 0) {
1915                         CERROR("Out of memory\n");
1916                         goto out;
1917                 }
1918
1919                 cfs_list_add_tail(&grp->grp_link,
1920                                   &console_session.ses_grp_list);
1921                 lstcon_group_addref(grp);
1922         }
1923
1924         if (grp->grp_ref > 2) {
1925                 /* Group in using */
1926                 jrep->join_status = EBUSY;
1927                 goto out;
1928         }
1929
1930         rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1931         if (rc == 0) {
1932                 jrep->join_status = EEXIST;
1933                 goto out;
1934         }
1935
1936         rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1937         if (rc != 0) {
1938                 CERROR("Out of memory\n");
1939                 goto out;
1940         }
1941
1942         ndl->ndl_node->nd_state   = LST_NODE_ACTIVE;
1943         ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1944
1945         if (grp->grp_userland == 0)
1946                 grp->grp_userland = 1;
1947
1948         strcpy(jrep->join_session, console_session.ses_name);
1949         jrep->join_timeout = console_session.ses_timeout;
1950         jrep->join_status  = 0;
1951
1952 out:
1953         rep->msg_ses_feats = console_session.ses_features;
1954         if (grp != NULL)
1955                 lstcon_group_put(grp);
1956
1957         mutex_unlock(&console_session.ses_mutex);
1958
1959         return rc;
1960 }
1961
1962 srpc_service_t lstcon_acceptor_service;
1963 void lstcon_init_acceptor_service(void)
1964 {
1965         /* initialize selftest console acceptor service table */
1966         lstcon_acceptor_service.sv_name    = "join session";
1967         lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1968         lstcon_acceptor_service.sv_id      = SRPC_SERVICE_JOIN;
1969         lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
1970 }
1971
1972 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1973
1974 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1975
1976 /* initialize console */
1977 int
1978 lstcon_console_init(void)
1979 {
1980         int     i;
1981         int     rc;
1982
1983         memset(&console_session, 0, sizeof(lstcon_session_t));
1984
1985         console_session.ses_id              = LST_INVALID_SID;
1986         console_session.ses_state           = LST_SESSION_NONE;
1987         console_session.ses_timeout         = 0;
1988         console_session.ses_force           = 0;
1989         console_session.ses_expired         = 0;
1990         console_session.ses_feats_updated   = 0;
1991         console_session.ses_features        = LST_FEATS_MASK;
1992         console_session.ses_laststamp       = cfs_time_current_sec();
1993
1994         mutex_init(&console_session.ses_mutex);
1995
1996         CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
1997         CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
1998         CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
1999         CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
2000
2001         LIBCFS_ALLOC(console_session.ses_ndl_hash,
2002                      sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2003         if (console_session.ses_ndl_hash == NULL)
2004                 return -ENOMEM;
2005
2006         for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2007                 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2008
2009
2010         /* initialize acceptor service table */
2011         lstcon_init_acceptor_service();
2012
2013         rc = srpc_add_service(&lstcon_acceptor_service);
2014         LASSERT (rc != -EBUSY);
2015         if (rc != 0) {
2016                 LIBCFS_FREE(console_session.ses_ndl_hash,
2017                             sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2018                 return rc;
2019         }
2020
2021         rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2022                                       lstcon_acceptor_service.sv_wi_total);
2023         if (rc != 0) {
2024                 rc = -ENOMEM;
2025                 goto out;
2026         }
2027
2028         rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2029
2030         if (rc == 0) {
2031                 lstcon_rpc_module_init();
2032                 return 0;
2033         }
2034
2035 out:
2036         srpc_shutdown_service(&lstcon_acceptor_service);
2037         srpc_remove_service(&lstcon_acceptor_service);
2038
2039         LIBCFS_FREE(console_session.ses_ndl_hash,
2040                     sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2041
2042         srpc_wait_service_shutdown(&lstcon_acceptor_service);
2043
2044         return rc;
2045 }
2046
2047 int
2048 lstcon_console_fini(void)
2049 {
2050         int     i;
2051
2052         libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2053
2054         mutex_lock(&console_session.ses_mutex);
2055
2056         srpc_shutdown_service(&lstcon_acceptor_service);
2057         srpc_remove_service(&lstcon_acceptor_service);
2058
2059         if (console_session.ses_state != LST_SESSION_NONE)
2060                 lstcon_session_end();
2061
2062         lstcon_rpc_module_fini();
2063
2064         mutex_unlock(&console_session.ses_mutex);
2065
2066         LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
2067         LASSERT (cfs_list_empty(&console_session.ses_grp_list));
2068         LASSERT (cfs_list_empty(&console_session.ses_bat_list));
2069         LASSERT (cfs_list_empty(&console_session.ses_trans_list));
2070
2071         for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2072                 LASSERT (cfs_list_empty(&console_session.ses_ndl_hash[i]));
2073         }
2074
2075         LIBCFS_FREE(console_session.ses_ndl_hash,
2076                     sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2077
2078         srpc_wait_service_shutdown(&lstcon_acceptor_service);
2079
2080         return 0;
2081 }
2082
2083 #endif