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