Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lnet / selftest / conctl.c
1 /*
2  * -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
3  * vim:expandtab:shiftwidth=8:tabstop=8:
4  *
5  * GPL HEADER START
6  *
7  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 only,
11  * as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License version 2 for more details (a copy is included
17  * in the LICENSE file that accompanied this code).
18  *
19  * You should have received a copy of the GNU General Public License
20  * version 2 along with this program; If not, see [sun.com URL with a
21  * copy of GPLv2].
22  *
23  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24  * CA 95054 USA or visit www.sun.com if you need additional information or
25  * have any questions.
26  *
27  * GPL HEADER END
28  */
29 /*
30  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
31  * Use is subject to license terms.
32  */
33 /*
34  * This file is part of Lustre, http://www.lustre.org/
35  * Lustre is a trademark of Sun Microsystems, Inc.
36  *
37  * lnet/selftest/conctl.c
38  *
39  * IOC handle in kernel 
40  *
41  * Author: Liang Zhen <liangzhen@clusterfs.com>
42  */
43 #ifdef __KERNEL__
44
45 #include <libcfs/libcfs.h>
46 #include <lnet/lib-lnet.h>
47 #include <lnet/lnetst.h>
48 #include "console.h"
49
50 int
51 lst_session_new_ioctl(lstio_session_new_args_t *args) 
52 {
53         char      *name;
54         int        rc;
55
56         if (args->lstio_ses_idp   == NULL || /* address for output sid */
57             args->lstio_ses_key   == 0 || /* no key is specified */
58             args->lstio_ses_namep == NULL || /* session name */
59             args->lstio_ses_nmlen <= 0 ||
60             args->lstio_ses_nmlen > LST_NAME_SIZE)
61                 return -EINVAL;
62        
63         LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1);
64         if (name == NULL)
65                 return -ENOMEM;
66         
67         if (copy_from_user(name,
68                            args->lstio_ses_namep,
69                            args->lstio_ses_nmlen)) {
70                 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
71                 return -EFAULT;
72         }
73         
74         name[args->lstio_ses_nmlen] = 0;
75         
76         rc = lstcon_session_new(name,
77                              args->lstio_ses_key,
78                              args->lstio_ses_timeout,
79                              args->lstio_ses_force,
80                              args->lstio_ses_idp);
81         
82         LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
83
84         return rc;
85 }
86
87 int
88 lst_session_end_ioctl(lstio_session_end_args_t *args)
89 {
90         if (args->lstio_ses_key != console_session.ses_key)
91                 return -EACCES;
92
93         return lstcon_session_end();
94 }
95
96 int
97 lst_session_info_ioctl(lstio_session_info_args_t *args)
98 {
99         /* no checking of key */
100
101         if (args->lstio_ses_idp   == NULL || /* address for ouput sid */
102             args->lstio_ses_keyp  == NULL || /* address for ouput key */
103             args->lstio_ses_ndinfo == NULL || /* address for output ndinfo */
104             args->lstio_ses_namep == NULL || /* address for ouput name */
105             args->lstio_ses_nmlen <= 0 ||
106             args->lstio_ses_nmlen > LST_NAME_SIZE)
107                 return -EINVAL;
108
109         return lstcon_session_info(args->lstio_ses_idp,
110                                    args->lstio_ses_keyp,
111                                    args->lstio_ses_ndinfo,
112                                    args->lstio_ses_namep,
113                                    args->lstio_ses_nmlen);
114 }
115
116 int
117 lst_debug_ioctl(lstio_debug_args_t *args)
118 {
119         char   *name   = NULL;
120         int     client = 1;
121         int     rc;
122
123         if (args->lstio_dbg_key != console_session.ses_key)
124                 return -EACCES;
125
126         if (args->lstio_dbg_resultp == NULL)
127                 return -EINVAL;
128
129         if (args->lstio_dbg_namep != NULL && /* name of batch/group */
130             (args->lstio_dbg_nmlen <= 0 ||
131              args->lstio_dbg_nmlen > LST_NAME_SIZE))
132                 return -EINVAL;
133
134         if (args->lstio_dbg_namep != NULL) {
135                 LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1);
136                 if (name == NULL)
137                         return -ENOMEM;
138
139                 if (copy_from_user(name, args->lstio_dbg_namep,
140                                    args->lstio_dbg_nmlen)) {
141                         LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
142
143                         return -EFAULT;
144                 }
145
146                 name[args->lstio_dbg_nmlen] = 0;
147         }
148
149         rc = -EINVAL;
150
151         switch (args->lstio_dbg_type) {
152         case LST_OPC_SESSION:
153                 rc = lstcon_session_debug(args->lstio_dbg_timeout,
154                                           args->lstio_dbg_resultp);
155                 break;
156
157         case LST_OPC_BATCHSRV:
158                 client = 0;
159         case LST_OPC_BATCHCLI:
160                 if (name == NULL)
161                         goto out;
162
163                 rc = lstcon_batch_debug(args->lstio_dbg_timeout,
164                                         name, client, args->lstio_dbg_resultp);
165                 break;
166
167         case LST_OPC_GROUP:
168                 if (name == NULL)
169                         goto out;
170
171                 rc = lstcon_group_debug(args->lstio_dbg_timeout,
172                                         name, args->lstio_dbg_resultp);
173                 break;
174
175         case LST_OPC_NODES:
176                 if (args->lstio_dbg_count <= 0 ||
177                     args->lstio_dbg_idsp == NULL)
178                         goto out;
179
180                 rc = lstcon_nodes_debug(args->lstio_dbg_timeout,
181                                         args->lstio_dbg_count,
182                                         args->lstio_dbg_idsp,
183                                         args->lstio_dbg_resultp);
184                 break;
185
186         default:
187                 break;
188         }
189
190 out:
191         if (name != NULL)
192                 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
193
194         return rc;
195 }
196
197 int
198 lst_group_add_ioctl(lstio_group_add_args_t *args)
199 {
200         char           *name;
201         int             rc;
202
203         if (args->lstio_grp_key != console_session.ses_key)
204                 return -EACCES;
205
206         if (args->lstio_grp_namep == NULL||
207             args->lstio_grp_nmlen <= 0 || 
208             args->lstio_grp_nmlen > LST_NAME_SIZE)
209                 return -EINVAL;
210
211         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
212         if (name == NULL)
213                 return -ENOMEM;
214
215         if (copy_from_user(name,
216                            args->lstio_grp_namep,
217                            args->lstio_grp_nmlen)) {
218                 LIBCFS_FREE(name, args->lstio_grp_nmlen);
219                 return -EFAULT;
220         }
221
222         name[args->lstio_grp_nmlen] = 0;
223
224         rc = lstcon_group_add(name);
225
226         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
227
228         return rc;
229 }
230
231 int
232 lst_group_del_ioctl(lstio_group_del_args_t *args)
233 {
234         int     rc;
235         char   *name;
236
237         if (args->lstio_grp_key != console_session.ses_key)
238                 return -EACCES;
239         
240         if (args->lstio_grp_namep == NULL ||
241             args->lstio_grp_nmlen <= 0 || 
242             args->lstio_grp_nmlen > LST_NAME_SIZE)
243                 return -EINVAL;
244
245         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
246         if (name == NULL)
247                 return -ENOMEM;
248
249         if (copy_from_user(name,
250                            args->lstio_grp_namep,
251                            args->lstio_grp_nmlen)) {
252                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
253                 return -EFAULT;
254         }
255
256         name[args->lstio_grp_nmlen] = 0;
257
258         rc = lstcon_group_del(name);
259
260         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
261
262         return rc;
263 }
264
265 int
266 lst_group_update_ioctl(lstio_group_update_args_t *args)
267 {
268         int     rc;
269         char   *name;
270
271         if (args->lstio_grp_key != console_session.ses_key)
272                 return -EACCES;
273
274         if (args->lstio_grp_resultp == NULL ||
275             args->lstio_grp_namep == NULL ||
276             args->lstio_grp_nmlen <= 0 || 
277             args->lstio_grp_nmlen > LST_NAME_SIZE)
278                 return -EINVAL;
279
280         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
281         if (name == NULL)
282                 return -ENOMEM;
283
284         if (copy_from_user(name,
285                            args->lstio_grp_namep,
286                            args->lstio_grp_nmlen)) {
287                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
288                 return -EFAULT;
289         }
290
291         name[args->lstio_grp_nmlen] = 0;
292
293         switch (args->lstio_grp_opc) {
294         case LST_GROUP_CLEAN:
295                 rc = lstcon_group_clean(name, args->lstio_grp_args);
296                 break;
297
298         case LST_GROUP_REFRESH:
299                 rc = lstcon_group_refresh(name, args->lstio_grp_resultp);
300                 break;
301
302         case LST_GROUP_RMND:
303                 if (args->lstio_grp_count  <= 0 ||
304                     args->lstio_grp_idsp == NULL) {
305                         rc = -EINVAL;
306                         break;
307                 }
308                 rc = lstcon_nodes_remove(name, args->lstio_grp_count,
309                                          args->lstio_grp_idsp,
310                                          args->lstio_grp_resultp);
311                 break;
312
313         default:
314                 rc = -EINVAL;
315                 break;
316         }
317
318         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
319         
320         return rc;
321 }
322
323 int
324 lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
325 {
326         int     rc;
327         char   *name;
328
329         if (args->lstio_grp_key != console_session.ses_key)
330                 return -EACCES;
331
332         if (args->lstio_grp_idsp == NULL || /* array of ids */
333             args->lstio_grp_count <= 0 ||
334             args->lstio_grp_resultp == NULL ||
335             args->lstio_grp_namep == NULL ||
336             args->lstio_grp_nmlen <= 0 || 
337             args->lstio_grp_nmlen > LST_NAME_SIZE)
338                 return -EINVAL;
339
340         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
341         if (name == NULL)
342                 return -ENOMEM;
343
344         if (copy_from_user(name, args->lstio_grp_namep,
345                            args->lstio_grp_nmlen)) {
346                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
347
348                 return -EFAULT;
349         }
350
351         name[args->lstio_grp_nmlen] = 0;
352
353         rc = lstcon_nodes_add(name, args->lstio_grp_count,
354                               args->lstio_grp_idsp,
355                               args->lstio_grp_resultp);
356
357         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
358
359         return rc;
360 }
361
362 int
363 lst_group_list_ioctl(lstio_group_list_args_t *args)
364 {
365         if (args->lstio_grp_key != console_session.ses_key) 
366                 return -EACCES;
367
368         if (args->lstio_grp_idx   < 0 ||
369             args->lstio_grp_namep == NULL ||
370             args->lstio_grp_nmlen <= 0 ||
371             args->lstio_grp_nmlen > LST_NAME_SIZE)
372                 return -EINVAL;
373
374         return lstcon_group_list(args->lstio_grp_idx,
375                               args->lstio_grp_nmlen,
376                               args->lstio_grp_namep);
377 }
378
379 int
380 lst_group_info_ioctl(lstio_group_info_args_t *args)
381 {
382         char           *name;
383         int             ndent;
384         int             index;
385         int             rc;
386
387         if (args->lstio_grp_key != console_session.ses_key)
388                 return -EACCES;
389
390         if (args->lstio_grp_namep == NULL ||
391             args->lstio_grp_nmlen <= 0 ||
392             args->lstio_grp_nmlen > LST_NAME_SIZE)
393                 return -EINVAL;
394
395         if (args->lstio_grp_entp  == NULL && /* output: group entry */
396             args->lstio_grp_dentsp == NULL)  /* output: node entry */
397                 return -EINVAL;
398
399         if (args->lstio_grp_dentsp != NULL) { /* have node entry */
400                 if (args->lstio_grp_idxp == NULL || /* node index */
401                     args->lstio_grp_ndentp == NULL) /* # of node entry */
402                         return -EINVAL;
403                                 
404                 if (copy_from_user(&ndent,
405                                    args->lstio_grp_ndentp, sizeof(ndent)) ||
406                     copy_from_user(&index, args->lstio_grp_idxp, sizeof(index)))
407                         return -EFAULT;
408
409                 if (ndent <= 0 || index < 0)
410                         return -EINVAL;
411         }
412
413         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
414         if (name == NULL)
415                 return -ENOMEM;
416
417         if (copy_from_user(name,
418                            args->lstio_grp_namep,
419                            args->lstio_grp_nmlen)) {
420                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
421                 return -EFAULT;
422         }
423
424         name[args->lstio_grp_nmlen] = 0;
425
426         rc = lstcon_group_info(name, args->lstio_grp_entp,
427                                &index, &ndent, args->lstio_grp_dentsp);
428
429         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
430
431         if (rc != 0) 
432                 return rc;
433
434         if (args->lstio_grp_dentsp != NULL && 
435             (copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) ||
436              copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent))))
437                 rc = -EFAULT;
438
439         return 0;
440 }
441
442 int
443 lst_batch_add_ioctl(lstio_batch_add_args_t *args)
444 {
445         int             rc;
446         char           *name;
447
448         if (args->lstio_bat_key != console_session.ses_key)
449                 return -EACCES;
450
451         if (args->lstio_bat_namep == NULL ||
452             args->lstio_bat_nmlen <= 0 ||
453             args->lstio_bat_nmlen > LST_NAME_SIZE)
454                 return -EINVAL;
455
456         LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
457         if (name == NULL)
458                 return -ENOMEM;
459
460         if (copy_from_user(name,
461                            args->lstio_bat_namep,
462                            args->lstio_bat_nmlen)) {
463                 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
464                 return -EFAULT;
465         }
466
467         name[args->lstio_bat_nmlen] = 0;
468
469         rc = lstcon_batch_add(name);
470
471         LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
472
473         return rc;
474 }
475
476 int
477 lst_batch_run_ioctl(lstio_batch_run_args_t *args)
478 {
479         int             rc;
480         char           *name;
481
482         if (args->lstio_bat_key != console_session.ses_key)
483                 return -EACCES;
484
485         if (args->lstio_bat_namep == NULL ||
486             args->lstio_bat_nmlen <= 0 ||
487             args->lstio_bat_nmlen > LST_NAME_SIZE)
488                 return -EINVAL;
489
490         LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
491         if (name == NULL)
492                 return -ENOMEM;
493
494         if (copy_from_user(name,
495                            args->lstio_bat_namep,
496                            args->lstio_bat_nmlen)) {
497                 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
498                 return -EFAULT;
499         }
500
501         name[args->lstio_bat_nmlen] = 0;
502
503         rc = lstcon_batch_run(name, args->lstio_bat_timeout,
504                               args->lstio_bat_resultp);
505
506         LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
507
508         return rc;
509 }
510
511 int
512 lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
513 {
514         int             rc;
515         char           *name;
516
517         if (args->lstio_bat_key != console_session.ses_key)
518                 return -EACCES;
519
520         if (args->lstio_bat_resultp == NULL ||
521             args->lstio_bat_namep == NULL ||
522             args->lstio_bat_nmlen <= 0 ||
523             args->lstio_bat_nmlen > LST_NAME_SIZE)
524                 return -EINVAL;
525
526         LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
527         if (name == NULL)
528                 return -ENOMEM;
529
530         if (copy_from_user(name,
531                            args->lstio_bat_namep,
532                            args->lstio_bat_nmlen)) {
533                 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
534                 return -EFAULT;
535         }
536
537         name[args->lstio_bat_nmlen] = 0;
538
539         rc = lstcon_batch_stop(name, args->lstio_bat_force,
540                                args->lstio_bat_resultp);
541
542         LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
543
544         return rc;
545 }
546
547 int
548 lst_batch_query_ioctl(lstio_batch_query_args_t *args)
549 {
550         char   *name;
551         int     rc;
552
553         if (args->lstio_bat_key != console_session.ses_key)
554                 return -EACCES;
555
556         if (args->lstio_bat_resultp == NULL ||
557             args->lstio_bat_namep == NULL ||
558             args->lstio_bat_nmlen <= 0 ||
559             args->lstio_bat_nmlen > LST_NAME_SIZE)
560                 return -EINVAL;
561
562         if (args->lstio_bat_testidx < 0)
563                 return -EINVAL;
564
565         LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
566         if (name == NULL)
567                 return -ENOMEM;
568
569         if (copy_from_user(name,
570                            args->lstio_bat_namep,
571                            args->lstio_bat_nmlen)) {
572                 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
573                 return -EFAULT;
574         }
575
576         name[args->lstio_bat_nmlen] = 0;
577
578         rc = lstcon_test_batch_query(name,
579                                      args->lstio_bat_testidx,
580                                      args->lstio_bat_client,
581                                      args->lstio_bat_timeout,
582                                      args->lstio_bat_resultp);
583
584         LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
585
586         return rc;
587 }
588
589 int
590 lst_batch_list_ioctl(lstio_batch_list_args_t *args)
591 {
592         if (args->lstio_bat_key != console_session.ses_key)
593                 return -EACCES;
594
595         if (args->lstio_bat_idx   < 0 ||
596             args->lstio_bat_namep == NULL ||
597             args->lstio_bat_nmlen <= 0 ||
598             args->lstio_bat_nmlen > LST_NAME_SIZE)
599                 return -EINVAL;
600
601         return lstcon_batch_list(args->lstio_bat_idx,
602                               args->lstio_bat_nmlen,
603                               args->lstio_bat_namep);
604 }
605
606 int
607 lst_batch_info_ioctl(lstio_batch_info_args_t *args)
608 {
609         char           *name;
610         int             rc;
611         int             index;
612         int             ndent;
613
614         if (args->lstio_bat_key != console_session.ses_key)
615                 return -EACCES;
616
617         if (args->lstio_bat_namep == NULL || /* batch name */
618             args->lstio_bat_nmlen <= 0 ||
619             args->lstio_bat_nmlen > LST_NAME_SIZE)
620                 return -EINVAL;
621
622         if (args->lstio_bat_entp == NULL && /* output: batch entry */
623             args->lstio_bat_dentsp == NULL) /* output: node entry */
624                 return -EINVAL;
625
626         if (args->lstio_bat_dentsp != NULL) { /* have node entry */
627                 if (args->lstio_bat_idxp == NULL || /* node index */
628                     args->lstio_bat_ndentp == NULL) /* # of node entry */
629                         return -EINVAL;
630                                 
631                 if (copy_from_user(&index, args->lstio_bat_idxp, sizeof(index)) ||
632                     copy_from_user(&ndent, args->lstio_bat_ndentp, 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 (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             (copy_to_user(args->lstio_bat_idxp, &index, sizeof(index)) ||
663              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 (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 (srcgrp == 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 (copy_from_user(name,
763                            args->lstio_tes_bat_name,
764                            args->lstio_tes_bat_nmlen) ||
765             copy_from_user(srcgrp,
766                            args->lstio_tes_sgrp_name,
767                            args->lstio_tes_sgrp_nmlen) ||
768             copy_from_user(dstgrp,
769                            args->lstio_tes_dgrp_name,
770                            args->lstio_tes_dgrp_nmlen) ||
771             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 = (copy_to_user(args->lstio_tes_retp, &ret, sizeof(ret))) ?
785                      -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 (copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) {
821                 LIBCFS_FREE(buf, data->ioc_plen1);
822                 return -EFAULT;
823         }
824
825         mutex_down(&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 (copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat,
906                          sizeof(lstcon_trans_stat_t)))
907                 rc = -EFAULT;
908 out:
909         mutex_up(&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