Whamcloud - gitweb
LU-56 lnet: Partitioned LNet resources (ME/MD/EQ)
[fs/lustre-release.git] / lnet / selftest / conctl.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  * IOC handle in kernel 
37  *
38  * Author: Liang Zhen <liangzhen@clusterfs.com>
39  */
40 #ifdef __KERNEL__
41
42 #include <libcfs/libcfs.h>
43 #include <lnet/lib-lnet.h>
44 #include <lnet/lnetst.h>
45 #include "console.h"
46
47 int
48 lst_session_new_ioctl(lstio_session_new_args_t *args)
49 {
50         char      *name;
51         int        rc;
52
53         if (args->lstio_ses_idp   == NULL || /* address for output sid */
54             args->lstio_ses_key   == 0 || /* no key is specified */
55             args->lstio_ses_namep == NULL || /* session name */
56             args->lstio_ses_nmlen <= 0 ||
57             args->lstio_ses_nmlen > LST_NAME_SIZE)
58                 return -EINVAL;
59
60         LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1);
61         if (name == NULL)
62                 return -ENOMEM;
63
64         if (cfs_copy_from_user(name,
65                                args->lstio_ses_namep,
66                                args->lstio_ses_nmlen)) {
67                 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
68                 return -EFAULT;
69         }
70
71         name[args->lstio_ses_nmlen] = 0;
72
73         rc = lstcon_session_new(name,
74                              args->lstio_ses_key,
75                              args->lstio_ses_timeout,
76                              args->lstio_ses_force,
77                              args->lstio_ses_idp);
78
79         LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
80
81         return rc;
82 }
83
84 int
85 lst_session_end_ioctl(lstio_session_end_args_t *args)
86 {
87         if (args->lstio_ses_key != console_session.ses_key)
88                 return -EACCES;
89
90         return lstcon_session_end();
91 }
92
93 int
94 lst_session_info_ioctl(lstio_session_info_args_t *args)
95 {
96         /* no checking of key */
97
98         if (args->lstio_ses_idp   == NULL || /* address for ouput sid */
99             args->lstio_ses_keyp  == NULL || /* address for ouput key */
100             args->lstio_ses_ndinfo == NULL || /* address for output ndinfo */
101             args->lstio_ses_namep == NULL || /* address for ouput name */
102             args->lstio_ses_nmlen <= 0 ||
103             args->lstio_ses_nmlen > LST_NAME_SIZE)
104                 return -EINVAL;
105
106         return lstcon_session_info(args->lstio_ses_idp,
107                                    args->lstio_ses_keyp,
108                                    args->lstio_ses_ndinfo,
109                                    args->lstio_ses_namep,
110                                    args->lstio_ses_nmlen);
111 }
112
113 int
114 lst_debug_ioctl(lstio_debug_args_t *args)
115 {
116         char   *name   = NULL;
117         int     client = 1;
118         int     rc;
119
120         if (args->lstio_dbg_key != console_session.ses_key)
121                 return -EACCES;
122
123         if (args->lstio_dbg_resultp == NULL)
124                 return -EINVAL;
125
126         if (args->lstio_dbg_namep != NULL && /* name of batch/group */
127             (args->lstio_dbg_nmlen <= 0 ||
128              args->lstio_dbg_nmlen > LST_NAME_SIZE))
129                 return -EINVAL;
130
131         if (args->lstio_dbg_namep != NULL) {
132                 LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1);
133                 if (name == NULL)
134                         return -ENOMEM;
135
136                 if (cfs_copy_from_user(name, args->lstio_dbg_namep,
137                                        args->lstio_dbg_nmlen)) {
138                         LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
139
140                         return -EFAULT;
141                 }
142
143                 name[args->lstio_dbg_nmlen] = 0;
144         }
145
146         rc = -EINVAL;
147
148         switch (args->lstio_dbg_type) {
149         case LST_OPC_SESSION:
150                 rc = lstcon_session_debug(args->lstio_dbg_timeout,
151                                           args->lstio_dbg_resultp);
152                 break;
153
154         case LST_OPC_BATCHSRV:
155                 client = 0;
156         case LST_OPC_BATCHCLI:
157                 if (name == NULL)
158                         goto out;
159
160                 rc = lstcon_batch_debug(args->lstio_dbg_timeout,
161                                         name, client, args->lstio_dbg_resultp);
162                 break;
163
164         case LST_OPC_GROUP:
165                 if (name == NULL)
166                         goto out;
167
168                 rc = lstcon_group_debug(args->lstio_dbg_timeout,
169                                         name, args->lstio_dbg_resultp);
170                 break;
171
172         case LST_OPC_NODES:
173                 if (args->lstio_dbg_count <= 0 ||
174                     args->lstio_dbg_idsp == NULL)
175                         goto out;
176
177                 rc = lstcon_nodes_debug(args->lstio_dbg_timeout,
178                                         args->lstio_dbg_count,
179                                         args->lstio_dbg_idsp,
180                                         args->lstio_dbg_resultp);
181                 break;
182
183         default:
184                 break;
185         }
186
187 out:
188         if (name != NULL)
189                 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
190
191         return rc;
192 }
193
194 int
195 lst_group_add_ioctl(lstio_group_add_args_t *args)
196 {
197         char           *name;
198         int             rc;
199
200         if (args->lstio_grp_key != console_session.ses_key)
201                 return -EACCES;
202
203         if (args->lstio_grp_namep == NULL||
204             args->lstio_grp_nmlen <= 0 || 
205             args->lstio_grp_nmlen > LST_NAME_SIZE)
206                 return -EINVAL;
207
208         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
209         if (name == NULL)
210                 return -ENOMEM;
211
212         if (cfs_copy_from_user(name,
213                                args->lstio_grp_namep,
214                                args->lstio_grp_nmlen)) {
215                 LIBCFS_FREE(name, args->lstio_grp_nmlen);
216                 return -EFAULT;
217         }
218
219         name[args->lstio_grp_nmlen] = 0;
220
221         rc = lstcon_group_add(name);
222
223         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
224
225         return rc;
226 }
227
228 int
229 lst_group_del_ioctl(lstio_group_del_args_t *args)
230 {
231         int     rc;
232         char   *name;
233
234         if (args->lstio_grp_key != console_session.ses_key)
235                 return -EACCES;
236
237         if (args->lstio_grp_namep == NULL ||
238             args->lstio_grp_nmlen <= 0 ||
239             args->lstio_grp_nmlen > LST_NAME_SIZE)
240                 return -EINVAL;
241
242         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
243         if (name == NULL)
244                 return -ENOMEM;
245
246         if (cfs_copy_from_user(name,
247                                args->lstio_grp_namep,
248                                args->lstio_grp_nmlen)) {
249                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
250                 return -EFAULT;
251         }
252
253         name[args->lstio_grp_nmlen] = 0;
254
255         rc = lstcon_group_del(name);
256
257         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
258
259         return rc;
260 }
261
262 int
263 lst_group_update_ioctl(lstio_group_update_args_t *args)
264 {
265         int     rc;
266         char   *name;
267
268         if (args->lstio_grp_key != console_session.ses_key)
269                 return -EACCES;
270
271         if (args->lstio_grp_resultp == NULL ||
272             args->lstio_grp_namep == NULL ||
273             args->lstio_grp_nmlen <= 0 || 
274             args->lstio_grp_nmlen > LST_NAME_SIZE)
275                 return -EINVAL;
276
277         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
278         if (name == NULL)
279                 return -ENOMEM;
280
281         if (cfs_copy_from_user(name,
282                            args->lstio_grp_namep,
283                            args->lstio_grp_nmlen)) {
284                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
285                 return -EFAULT;
286         }
287
288         name[args->lstio_grp_nmlen] = 0;
289
290         switch (args->lstio_grp_opc) {
291         case LST_GROUP_CLEAN:
292                 rc = lstcon_group_clean(name, args->lstio_grp_args);
293                 break;
294
295         case LST_GROUP_REFRESH:
296                 rc = lstcon_group_refresh(name, args->lstio_grp_resultp);
297                 break;
298
299         case LST_GROUP_RMND:
300                 if (args->lstio_grp_count  <= 0 ||
301                     args->lstio_grp_idsp == NULL) {
302                         rc = -EINVAL;
303                         break;
304                 }
305                 rc = lstcon_nodes_remove(name, args->lstio_grp_count,
306                                          args->lstio_grp_idsp,
307                                          args->lstio_grp_resultp);
308                 break;
309
310         default:
311                 rc = -EINVAL;
312                 break;
313         }
314
315         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
316
317         return rc;
318 }
319
320 int
321 lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
322 {
323         int     rc;
324         char   *name;
325
326         if (args->lstio_grp_key != console_session.ses_key)
327                 return -EACCES;
328
329         if (args->lstio_grp_idsp == NULL || /* array of ids */
330             args->lstio_grp_count <= 0 ||
331             args->lstio_grp_resultp == NULL ||
332             args->lstio_grp_namep == NULL ||
333             args->lstio_grp_nmlen <= 0 || 
334             args->lstio_grp_nmlen > LST_NAME_SIZE)
335                 return -EINVAL;
336
337         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
338         if (name == NULL)
339                 return -ENOMEM;
340
341         if (cfs_copy_from_user(name, args->lstio_grp_namep,
342                                args->lstio_grp_nmlen)) {
343                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
344
345                 return -EFAULT;
346         }
347
348         name[args->lstio_grp_nmlen] = 0;
349
350         rc = lstcon_nodes_add(name, args->lstio_grp_count,
351                               args->lstio_grp_idsp,
352                               args->lstio_grp_resultp);
353
354         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
355
356         return rc;
357 }
358
359 int
360 lst_group_list_ioctl(lstio_group_list_args_t *args)
361 {
362         if (args->lstio_grp_key != console_session.ses_key) 
363                 return -EACCES;
364
365         if (args->lstio_grp_idx   < 0 ||
366             args->lstio_grp_namep == NULL ||
367             args->lstio_grp_nmlen <= 0 ||
368             args->lstio_grp_nmlen > LST_NAME_SIZE)
369                 return -EINVAL;
370
371         return lstcon_group_list(args->lstio_grp_idx,
372                               args->lstio_grp_nmlen,
373                               args->lstio_grp_namep);
374 }
375
376 int
377 lst_group_info_ioctl(lstio_group_info_args_t *args)
378 {
379         char           *name;
380         int             ndent;
381         int             index;
382         int             rc;
383
384         if (args->lstio_grp_key != console_session.ses_key)
385                 return -EACCES;
386
387         if (args->lstio_grp_namep == NULL ||
388             args->lstio_grp_nmlen <= 0 ||
389             args->lstio_grp_nmlen > LST_NAME_SIZE)
390                 return -EINVAL;
391
392         if (args->lstio_grp_entp  == NULL && /* output: group entry */
393             args->lstio_grp_dentsp == NULL)  /* output: node entry */
394                 return -EINVAL;
395
396         if (args->lstio_grp_dentsp != NULL) { /* have node entry */
397                 if (args->lstio_grp_idxp == NULL || /* node index */
398                     args->lstio_grp_ndentp == NULL) /* # of node entry */
399                         return -EINVAL;
400
401                 if (cfs_copy_from_user(&ndent, args->lstio_grp_ndentp,
402                                        sizeof(ndent)) ||
403                     cfs_copy_from_user(&index, args->lstio_grp_idxp,
404                                        sizeof(index)))
405                         return -EFAULT;
406
407                 if (ndent <= 0 || index < 0)
408                         return -EINVAL;
409         }
410
411         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
412         if (name == NULL)
413                 return -ENOMEM;
414
415         if (cfs_copy_from_user(name,
416                                args->lstio_grp_namep,
417                                args->lstio_grp_nmlen)) {
418                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
419                 return -EFAULT;
420         }
421
422         name[args->lstio_grp_nmlen] = 0;
423
424         rc = lstcon_group_info(name, args->lstio_grp_entp,
425                                &index, &ndent, args->lstio_grp_dentsp);
426
427         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
428
429         if (rc != 0) 
430                 return rc;
431
432         if (args->lstio_grp_dentsp != NULL && 
433             (cfs_copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) ||
434              cfs_copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent))))
435                 rc = -EFAULT;
436
437         return 0;
438 }
439
440 int
441 lst_batch_add_ioctl(lstio_batch_add_args_t *args)
442 {
443         int             rc;
444         char           *name;
445
446         if (args->lstio_bat_key != console_session.ses_key)
447                 return -EACCES;
448
449         if (args->lstio_bat_namep == NULL ||
450             args->lstio_bat_nmlen <= 0 ||
451             args->lstio_bat_nmlen > LST_NAME_SIZE)
452                 return -EINVAL;
453
454         LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
455         if (name == NULL)
456                 return -ENOMEM;
457
458         if (cfs_copy_from_user(name,
459                                args->lstio_bat_namep,
460                                args->lstio_bat_nmlen)) {
461                 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
462                 return -EFAULT;
463         }
464
465         name[args->lstio_bat_nmlen] = 0;
466
467         rc = lstcon_batch_add(name);
468
469         LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
470
471         return rc;
472 }
473
474 int
475 lst_batch_run_ioctl(lstio_batch_run_args_t *args)
476 {
477         int             rc;
478         char           *name;
479
480         if (args->lstio_bat_key != console_session.ses_key)
481                 return -EACCES;
482
483         if (args->lstio_bat_namep == NULL ||
484             args->lstio_bat_nmlen <= 0 ||
485             args->lstio_bat_nmlen > LST_NAME_SIZE)
486                 return -EINVAL;
487
488         LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
489         if (name == NULL)
490                 return -ENOMEM;
491
492         if (cfs_copy_from_user(name,
493                                args->lstio_bat_namep,
494                                args->lstio_bat_nmlen)) {
495                 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
496                 return -EFAULT;
497         }
498
499         name[args->lstio_bat_nmlen] = 0;
500
501         rc = lstcon_batch_run(name, args->lstio_bat_timeout,
502                               args->lstio_bat_resultp);
503
504         LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
505
506         return rc;
507 }
508
509 int
510 lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
511 {
512         int             rc;
513         char           *name;
514
515         if (args->lstio_bat_key != console_session.ses_key)
516                 return -EACCES;
517
518         if (args->lstio_bat_resultp == NULL ||
519             args->lstio_bat_namep == NULL ||
520             args->lstio_bat_nmlen <= 0 ||
521             args->lstio_bat_nmlen > LST_NAME_SIZE)
522                 return -EINVAL;
523
524         LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
525         if (name == NULL)
526                 return -ENOMEM;
527
528         if (cfs_copy_from_user(name,
529                                args->lstio_bat_namep,
530                                args->lstio_bat_nmlen)) {
531                 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
532                 return -EFAULT;
533         }
534
535         name[args->lstio_bat_nmlen] = 0;
536
537         rc = lstcon_batch_stop(name, args->lstio_bat_force,
538                                args->lstio_bat_resultp);
539
540         LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
541
542         return rc;
543 }
544
545 int
546 lst_batch_query_ioctl(lstio_batch_query_args_t *args)
547 {
548         char   *name;
549         int     rc;
550
551         if (args->lstio_bat_key != console_session.ses_key)
552                 return -EACCES;
553
554         if (args->lstio_bat_resultp == NULL ||
555             args->lstio_bat_namep == NULL ||
556             args->lstio_bat_nmlen <= 0 ||
557             args->lstio_bat_nmlen > LST_NAME_SIZE)
558                 return -EINVAL;
559
560         if (args->lstio_bat_testidx < 0)
561                 return -EINVAL;
562
563         LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
564         if (name == NULL)
565                 return -ENOMEM;
566
567         if (cfs_copy_from_user(name,
568                                args->lstio_bat_namep,
569                                args->lstio_bat_nmlen)) {
570                 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
571                 return -EFAULT;
572         }
573
574         name[args->lstio_bat_nmlen] = 0;
575
576         rc = lstcon_test_batch_query(name,
577                                      args->lstio_bat_testidx,
578                                      args->lstio_bat_client,
579                                      args->lstio_bat_timeout,
580                                      args->lstio_bat_resultp);
581
582         LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
583
584         return rc;
585 }
586
587 int
588 lst_batch_list_ioctl(lstio_batch_list_args_t *args)
589 {
590         if (args->lstio_bat_key != console_session.ses_key)
591                 return -EACCES;
592
593         if (args->lstio_bat_idx   < 0 ||
594             args->lstio_bat_namep == NULL ||
595             args->lstio_bat_nmlen <= 0 ||
596             args->lstio_bat_nmlen > LST_NAME_SIZE)
597                 return -EINVAL;
598
599         return lstcon_batch_list(args->lstio_bat_idx,
600                               args->lstio_bat_nmlen,
601                               args->lstio_bat_namep);
602 }
603
604 int
605 lst_batch_info_ioctl(lstio_batch_info_args_t *args)
606 {
607         char           *name;
608         int             rc;
609         int             index;
610         int             ndent;
611
612         if (args->lstio_bat_key != console_session.ses_key)
613                 return -EACCES;
614
615         if (args->lstio_bat_namep == NULL || /* batch name */
616             args->lstio_bat_nmlen <= 0 ||
617             args->lstio_bat_nmlen > LST_NAME_SIZE)
618                 return -EINVAL;
619
620         if (args->lstio_bat_entp == NULL && /* output: batch entry */
621             args->lstio_bat_dentsp == NULL) /* output: node entry */
622                 return -EINVAL;
623
624         if (args->lstio_bat_dentsp != NULL) { /* have node entry */
625                 if (args->lstio_bat_idxp == NULL || /* node index */
626                     args->lstio_bat_ndentp == NULL) /* # of node entry */
627                         return -EINVAL;
628
629                 if (cfs_copy_from_user(&index, args->lstio_bat_idxp,
630                                        sizeof(index)) ||
631                     cfs_copy_from_user(&ndent, args->lstio_bat_ndentp,
632                                        sizeof(ndent)))
633                         return -EFAULT;
634
635                 if (ndent <= 0 || index < 0)
636                         return -EINVAL;
637         }
638
639         LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
640         if (name == NULL)
641                 return -ENOMEM;
642
643         if (cfs_copy_from_user(name,
644                                args->lstio_bat_namep, args->lstio_bat_nmlen)) {
645                 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
646                 return -EFAULT;
647         }
648
649         name[args->lstio_bat_nmlen] = 0;
650
651         rc = lstcon_batch_info(name,
652                             args->lstio_bat_entp, args->lstio_bat_server,
653                             args->lstio_bat_testidx, &index, &ndent,
654                             args->lstio_bat_dentsp);
655
656         LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
657
658         if (rc != 0)
659                 return rc;
660
661         if (args->lstio_bat_dentsp != NULL && 
662             (cfs_copy_to_user(args->lstio_bat_idxp, &index, sizeof(index)) ||
663              cfs_copy_to_user(args->lstio_bat_ndentp, &ndent, sizeof(ndent))))
664                 rc = -EFAULT;
665
666         return rc;
667 }
668
669 int
670 lst_stat_query_ioctl(lstio_stat_args_t *args)
671 {
672         int             rc;
673         char           *name;
674
675         /* TODO: not finished */
676         if (args->lstio_sta_key != console_session.ses_key)
677                 return -EACCES;
678
679         if (args->lstio_sta_resultp == NULL ||
680             (args->lstio_sta_namep  == NULL &&
681              args->lstio_sta_idsp   == NULL) ||
682             args->lstio_sta_nmlen <= 0 ||
683             args->lstio_sta_nmlen > LST_NAME_SIZE)
684                 return -EINVAL;
685
686         if (args->lstio_sta_idsp != NULL &&
687             args->lstio_sta_count <= 0)
688                 return -EINVAL;
689
690         LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
691         if (name == NULL)
692                 return -ENOMEM;
693
694         if (cfs_copy_from_user(name, args->lstio_sta_namep,
695                                args->lstio_sta_nmlen)) {
696                 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
697                 return -EFAULT;
698         }
699
700         if (args->lstio_sta_idsp == NULL) {
701                 rc = lstcon_group_stat(name, args->lstio_sta_timeout,
702                                        args->lstio_sta_resultp);
703         } else {
704                 rc = lstcon_nodes_stat(args->lstio_sta_count,
705                                        args->lstio_sta_idsp,
706                                        args->lstio_sta_timeout,
707                                        args->lstio_sta_resultp);
708         }
709
710         LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
711
712         return rc;
713 }
714
715 int lst_test_add_ioctl(lstio_test_args_t *args)
716 {
717         char           *name;
718         char           *srcgrp = NULL;
719         char           *dstgrp = NULL;
720         void           *param = NULL;
721         int             ret = 0;
722         int             rc = -ENOMEM;
723
724         if (args->lstio_tes_resultp == NULL ||
725             args->lstio_tes_retp == NULL ||
726             args->lstio_tes_bat_name == NULL || /* no specified batch */
727             args->lstio_tes_bat_nmlen <= 0 ||
728             args->lstio_tes_bat_nmlen > LST_NAME_SIZE ||
729             args->lstio_tes_sgrp_name == NULL || /* no source group */
730             args->lstio_tes_sgrp_nmlen <= 0 ||
731             args->lstio_tes_sgrp_nmlen > LST_NAME_SIZE ||
732             args->lstio_tes_dgrp_name == NULL || /* no target group */
733             args->lstio_tes_dgrp_nmlen <= 0 ||
734             args->lstio_tes_dgrp_nmlen > LST_NAME_SIZE)
735                 return -EINVAL;
736
737         /* have parameter, check if parameter length is valid */
738         if (args->lstio_tes_param != NULL &&
739             (args->lstio_tes_param_len <= 0 ||
740              args->lstio_tes_param_len > CFS_PAGE_SIZE - sizeof(lstcon_test_t)))
741                 return -EINVAL;
742
743         LIBCFS_ALLOC(name, args->lstio_tes_bat_nmlen + 1);
744         if (name == NULL)
745                 return rc;
746
747         LIBCFS_ALLOC(srcgrp, args->lstio_tes_sgrp_nmlen + 1);
748         if (srcgrp == NULL) 
749                 goto out;
750
751         LIBCFS_ALLOC(dstgrp, args->lstio_tes_dgrp_nmlen + 1);
752          if (dstgrp == NULL)
753                 goto out;
754
755         if (args->lstio_tes_param != NULL) {
756                 LIBCFS_ALLOC(param, args->lstio_tes_param_len);
757                 if (param == NULL) 
758                         goto out;
759         }
760
761         rc = -EFAULT;
762         if (cfs_copy_from_user(name,
763                               args->lstio_tes_bat_name,
764                               args->lstio_tes_bat_nmlen) ||
765             cfs_copy_from_user(srcgrp,
766                               args->lstio_tes_sgrp_name,
767                               args->lstio_tes_sgrp_nmlen) ||
768             cfs_copy_from_user(dstgrp,
769                               args->lstio_tes_dgrp_name,
770                               args->lstio_tes_dgrp_nmlen) ||
771             cfs_copy_from_user(param, args->lstio_tes_param,
772                               args->lstio_tes_param_len))
773                 goto out;
774
775         rc = lstcon_test_add(name,
776                             args->lstio_tes_type,
777                             args->lstio_tes_loop,
778                             args->lstio_tes_concur,
779                             args->lstio_tes_dist, args->lstio_tes_span,
780                             srcgrp, dstgrp, param, args->lstio_tes_param_len,
781                             &ret, args->lstio_tes_resultp);
782
783         if (ret != 0)
784                 rc = (cfs_copy_to_user(args->lstio_tes_retp, &ret,
785                                        sizeof(ret))) ? -EFAULT : 0;
786 out:
787         if (name != NULL)
788                 LIBCFS_FREE(name, args->lstio_tes_bat_nmlen + 1);
789
790         if (srcgrp != NULL)
791                 LIBCFS_FREE(srcgrp, args->lstio_tes_sgrp_nmlen + 1);
792
793         if (dstgrp != NULL)
794                 LIBCFS_FREE(dstgrp, args->lstio_tes_dgrp_nmlen + 1);
795
796         if (param != NULL)
797                 LIBCFS_FREE(param, args->lstio_tes_param_len);
798
799         return rc;
800 }
801
802 int
803 lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
804 {
805         char   *buf;
806         int     opc = data->ioc_u32[0];
807         int     rc;
808
809         if (cmd != IOC_LIBCFS_LNETST)
810                 return -EINVAL;
811
812         if (data->ioc_plen1 > CFS_PAGE_SIZE)
813                 return -EINVAL;
814
815         LIBCFS_ALLOC(buf, data->ioc_plen1);
816         if (buf == NULL)
817                 return -ENOMEM;
818
819         /* copy in parameter */
820         if (cfs_copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) {
821                 LIBCFS_FREE(buf, data->ioc_plen1);
822                 return -EFAULT;
823         }
824
825         cfs_mutex_lock(&console_session.ses_mutex);
826
827         console_session.ses_laststamp = cfs_time_current_sec();
828
829         if (console_session.ses_shutdown) {
830                 rc = -ESHUTDOWN;
831                 goto out;
832         }
833
834         if (console_session.ses_expired)
835                 lstcon_session_end();
836
837         if (opc != LSTIO_SESSION_NEW &&
838             console_session.ses_state == LST_SESSION_NONE) {
839                 CDEBUG(D_NET, "LST no active session\n");
840                 rc = -ESRCH;
841                 goto out;
842         }
843
844         memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t));
845
846         switch (opc) {
847                 case LSTIO_SESSION_NEW:
848                         rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf);
849                         break;
850                 case LSTIO_SESSION_END:
851                         rc = lst_session_end_ioctl((lstio_session_end_args_t *)buf);
852                         break;
853                 case LSTIO_SESSION_INFO:
854                         rc = lst_session_info_ioctl((lstio_session_info_args_t *)buf);
855                         break;
856                 case LSTIO_DEBUG:
857                         rc = lst_debug_ioctl((lstio_debug_args_t *)buf);
858                         break;
859                 case LSTIO_GROUP_ADD:
860                         rc = lst_group_add_ioctl((lstio_group_add_args_t *)buf);
861                         break;
862                 case LSTIO_GROUP_DEL:
863                         rc = lst_group_del_ioctl((lstio_group_del_args_t *)buf);
864                         break;
865                 case LSTIO_GROUP_UPDATE:
866                         rc = lst_group_update_ioctl((lstio_group_update_args_t *)buf);
867                         break;
868                 case LSTIO_NODES_ADD:
869                         rc = lst_nodes_add_ioctl((lstio_group_nodes_args_t *)buf);
870                         break;
871                 case LSTIO_GROUP_LIST:
872                         rc = lst_group_list_ioctl((lstio_group_list_args_t *)buf);
873                         break;
874                 case LSTIO_GROUP_INFO:
875                         rc = lst_group_info_ioctl((lstio_group_info_args_t *)buf);
876                         break;
877                 case LSTIO_BATCH_ADD:
878                         rc = lst_batch_add_ioctl((lstio_batch_add_args_t *)buf);
879                         break;
880                 case LSTIO_BATCH_START:
881                         rc = lst_batch_run_ioctl((lstio_batch_run_args_t *)buf);
882                         break;
883                 case LSTIO_BATCH_STOP:
884                         rc = lst_batch_stop_ioctl((lstio_batch_stop_args_t *)buf);
885                         break;
886                 case LSTIO_BATCH_QUERY:
887                         rc = lst_batch_query_ioctl((lstio_batch_query_args_t *)buf);
888                         break;
889                 case LSTIO_BATCH_LIST:
890                         rc = lst_batch_list_ioctl((lstio_batch_list_args_t *)buf);
891                         break;
892                 case LSTIO_BATCH_INFO:
893                         rc = lst_batch_info_ioctl((lstio_batch_info_args_t *)buf);
894                         break;
895                 case LSTIO_TEST_ADD:
896                         rc = lst_test_add_ioctl((lstio_test_args_t *)buf);
897                         break;
898                 case LSTIO_STAT_QUERY:
899                         rc = lst_stat_query_ioctl((lstio_stat_args_t *)buf);
900                         break;
901                 default:
902                         rc = -EINVAL;
903         }
904
905         if (cfs_copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat,
906                              sizeof(lstcon_trans_stat_t)))
907                 rc = -EFAULT;
908 out:
909         cfs_mutex_unlock(&console_session.ses_mutex);
910
911         LIBCFS_FREE(buf, data->ioc_plen1);
912
913         return rc;
914 }
915
916 EXPORT_SYMBOL(lstcon_ioctl_entry);
917
918 #endif