Whamcloud - gitweb
LU-184 Keep orphan on failover umount
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lnet/selftest/conctl.c
37  *
38  * IOC handle in kernel 
39  *
40  * Author: Liang Zhen <liangzhen@clusterfs.com>
41  */
42 #ifdef __KERNEL__
43
44 #include <libcfs/libcfs.h>
45 #include <lnet/lib-lnet.h>
46 #include <lnet/lnetst.h>
47 #include "console.h"
48
49 int
50 lst_session_new_ioctl(lstio_session_new_args_t *args)
51 {
52         char      *name;
53         int        rc;
54
55         if (args->lstio_ses_idp   == NULL || /* address for output sid */
56             args->lstio_ses_key   == 0 || /* no key is specified */
57             args->lstio_ses_namep == NULL || /* session name */
58             args->lstio_ses_nmlen <= 0 ||
59             args->lstio_ses_nmlen > LST_NAME_SIZE)
60                 return -EINVAL;
61
62         LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1);
63         if (name == NULL)
64                 return -ENOMEM;
65
66         if (cfs_copy_from_user(name,
67                                args->lstio_ses_namep,
68                                args->lstio_ses_nmlen)) {
69                 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
70                 return -EFAULT;
71         }
72
73         name[args->lstio_ses_nmlen] = 0;
74
75         rc = lstcon_session_new(name,
76                              args->lstio_ses_key,
77                              args->lstio_ses_timeout,
78                              args->lstio_ses_force,
79                              args->lstio_ses_idp);
80
81         LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
82
83         return rc;
84 }
85
86 int
87 lst_session_end_ioctl(lstio_session_end_args_t *args)
88 {
89         if (args->lstio_ses_key != console_session.ses_key)
90                 return -EACCES;
91
92         return lstcon_session_end();
93 }
94
95 int
96 lst_session_info_ioctl(lstio_session_info_args_t *args)
97 {
98         /* no checking of key */
99
100         if (args->lstio_ses_idp   == NULL || /* address for ouput sid */
101             args->lstio_ses_keyp  == NULL || /* address for ouput key */
102             args->lstio_ses_ndinfo == NULL || /* address for output ndinfo */
103             args->lstio_ses_namep == NULL || /* address for ouput name */
104             args->lstio_ses_nmlen <= 0 ||
105             args->lstio_ses_nmlen > LST_NAME_SIZE)
106                 return -EINVAL;
107
108         return lstcon_session_info(args->lstio_ses_idp,
109                                    args->lstio_ses_keyp,
110                                    args->lstio_ses_ndinfo,
111                                    args->lstio_ses_namep,
112                                    args->lstio_ses_nmlen);
113 }
114
115 int
116 lst_debug_ioctl(lstio_debug_args_t *args)
117 {
118         char   *name   = NULL;
119         int     client = 1;
120         int     rc;
121
122         if (args->lstio_dbg_key != console_session.ses_key)
123                 return -EACCES;
124
125         if (args->lstio_dbg_resultp == NULL)
126                 return -EINVAL;
127
128         if (args->lstio_dbg_namep != NULL && /* name of batch/group */
129             (args->lstio_dbg_nmlen <= 0 ||
130              args->lstio_dbg_nmlen > LST_NAME_SIZE))
131                 return -EINVAL;
132
133         if (args->lstio_dbg_namep != NULL) {
134                 LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1);
135                 if (name == NULL)
136                         return -ENOMEM;
137
138                 if (cfs_copy_from_user(name, args->lstio_dbg_namep,
139                                        args->lstio_dbg_nmlen)) {
140                         LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
141
142                         return -EFAULT;
143                 }
144
145                 name[args->lstio_dbg_nmlen] = 0;
146         }
147
148         rc = -EINVAL;
149
150         switch (args->lstio_dbg_type) {
151         case LST_OPC_SESSION:
152                 rc = lstcon_session_debug(args->lstio_dbg_timeout,
153                                           args->lstio_dbg_resultp);
154                 break;
155
156         case LST_OPC_BATCHSRV:
157                 client = 0;
158         case LST_OPC_BATCHCLI:
159                 if (name == NULL)
160                         goto out;
161
162                 rc = lstcon_batch_debug(args->lstio_dbg_timeout,
163                                         name, client, args->lstio_dbg_resultp);
164                 break;
165
166         case LST_OPC_GROUP:
167                 if (name == NULL)
168                         goto out;
169
170                 rc = lstcon_group_debug(args->lstio_dbg_timeout,
171                                         name, args->lstio_dbg_resultp);
172                 break;
173
174         case LST_OPC_NODES:
175                 if (args->lstio_dbg_count <= 0 ||
176                     args->lstio_dbg_idsp == NULL)
177                         goto out;
178
179                 rc = lstcon_nodes_debug(args->lstio_dbg_timeout,
180                                         args->lstio_dbg_count,
181                                         args->lstio_dbg_idsp,
182                                         args->lstio_dbg_resultp);
183                 break;
184
185         default:
186                 break;
187         }
188
189 out:
190         if (name != NULL)
191                 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
192
193         return rc;
194 }
195
196 int
197 lst_group_add_ioctl(lstio_group_add_args_t *args)
198 {
199         char           *name;
200         int             rc;
201
202         if (args->lstio_grp_key != console_session.ses_key)
203                 return -EACCES;
204
205         if (args->lstio_grp_namep == NULL||
206             args->lstio_grp_nmlen <= 0 || 
207             args->lstio_grp_nmlen > LST_NAME_SIZE)
208                 return -EINVAL;
209
210         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
211         if (name == NULL)
212                 return -ENOMEM;
213
214         if (cfs_copy_from_user(name,
215                                args->lstio_grp_namep,
216                                args->lstio_grp_nmlen)) {
217                 LIBCFS_FREE(name, args->lstio_grp_nmlen);
218                 return -EFAULT;
219         }
220
221         name[args->lstio_grp_nmlen] = 0;
222
223         rc = lstcon_group_add(name);
224
225         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
226
227         return rc;
228 }
229
230 int
231 lst_group_del_ioctl(lstio_group_del_args_t *args)
232 {
233         int     rc;
234         char   *name;
235
236         if (args->lstio_grp_key != console_session.ses_key)
237                 return -EACCES;
238
239         if (args->lstio_grp_namep == NULL ||
240             args->lstio_grp_nmlen <= 0 ||
241             args->lstio_grp_nmlen > LST_NAME_SIZE)
242                 return -EINVAL;
243
244         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
245         if (name == NULL)
246                 return -ENOMEM;
247
248         if (cfs_copy_from_user(name,
249                                args->lstio_grp_namep,
250                                args->lstio_grp_nmlen)) {
251                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
252                 return -EFAULT;
253         }
254
255         name[args->lstio_grp_nmlen] = 0;
256
257         rc = lstcon_group_del(name);
258
259         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
260
261         return rc;
262 }
263
264 int
265 lst_group_update_ioctl(lstio_group_update_args_t *args)
266 {
267         int     rc;
268         char   *name;
269
270         if (args->lstio_grp_key != console_session.ses_key)
271                 return -EACCES;
272
273         if (args->lstio_grp_resultp == NULL ||
274             args->lstio_grp_namep == NULL ||
275             args->lstio_grp_nmlen <= 0 || 
276             args->lstio_grp_nmlen > LST_NAME_SIZE)
277                 return -EINVAL;
278
279         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
280         if (name == NULL)
281                 return -ENOMEM;
282
283         if (cfs_copy_from_user(name,
284                            args->lstio_grp_namep,
285                            args->lstio_grp_nmlen)) {
286                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
287                 return -EFAULT;
288         }
289
290         name[args->lstio_grp_nmlen] = 0;
291
292         switch (args->lstio_grp_opc) {
293         case LST_GROUP_CLEAN:
294                 rc = lstcon_group_clean(name, args->lstio_grp_args);
295                 break;
296
297         case LST_GROUP_REFRESH:
298                 rc = lstcon_group_refresh(name, args->lstio_grp_resultp);
299                 break;
300
301         case LST_GROUP_RMND:
302                 if (args->lstio_grp_count  <= 0 ||
303                     args->lstio_grp_idsp == NULL) {
304                         rc = -EINVAL;
305                         break;
306                 }
307                 rc = lstcon_nodes_remove(name, args->lstio_grp_count,
308                                          args->lstio_grp_idsp,
309                                          args->lstio_grp_resultp);
310                 break;
311
312         default:
313                 rc = -EINVAL;
314                 break;
315         }
316
317         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
318
319         return rc;
320 }
321
322 int
323 lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
324 {
325         int     rc;
326         char   *name;
327
328         if (args->lstio_grp_key != console_session.ses_key)
329                 return -EACCES;
330
331         if (args->lstio_grp_idsp == NULL || /* array of ids */
332             args->lstio_grp_count <= 0 ||
333             args->lstio_grp_resultp == NULL ||
334             args->lstio_grp_namep == NULL ||
335             args->lstio_grp_nmlen <= 0 || 
336             args->lstio_grp_nmlen > LST_NAME_SIZE)
337                 return -EINVAL;
338
339         LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
340         if (name == NULL)
341                 return -ENOMEM;
342
343         if (cfs_copy_from_user(name, args->lstio_grp_namep,
344                                args->lstio_grp_nmlen)) {
345                 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
346
347                 return -EFAULT;
348         }
349
350         name[args->lstio_grp_nmlen] = 0;
351
352         rc = lstcon_nodes_add(name, args->lstio_grp_count,
353                               args->lstio_grp_idsp,
354                               args->lstio_grp_resultp);
355
356         LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
357
358         return rc;
359 }
360
361 int
362 lst_group_list_ioctl(lstio_group_list_args_t *args)
363 {
364         if (args->lstio_grp_key != console_session.ses_key) 
365                 return -EACCES;
366
367         if (args->lstio_grp_idx   < 0 ||
368             args->lstio_grp_namep == NULL ||
369             args->lstio_grp_nmlen <= 0 ||
370             args->lstio_grp_nmlen > LST_NAME_SIZE)
371                 return -EINVAL;
372
373         return lstcon_group_list(args->lstio_grp_idx,
374                               args->lstio_grp_nmlen,
375                               args->lstio_grp_namep);
376 }
377
378 int
379 lst_group_info_ioctl(lstio_group_info_args_t *args)
380 {
381         char           *name;
382         int             ndent;
383         int             index;
384         int             rc;
385
386         if (args->lstio_grp_key != console_session.ses_key)
387                 return -EACCES;
388
389         if (args->lstio_grp_namep == NULL ||
390             args->lstio_grp_nmlen <= 0 ||
391             args->lstio_grp_nmlen > LST_NAME_SIZE)
392                 return -EINVAL;
393
394         if (args->lstio_grp_entp  == NULL && /* output: group entry */
395             args->lstio_grp_dentsp == NULL)  /* output: node entry */
396                 return -EINVAL;
397
398         if (args->lstio_grp_dentsp != NULL) { /* have node entry */
399                 if (args->lstio_grp_idxp == NULL || /* node index */
400                     args->lstio_grp_ndentp == NULL) /* # of node entry */
401                         return -EINVAL;
402
403                 if (cfs_copy_from_user(&ndent, args->lstio_grp_ndentp,
404                                        sizeof(ndent)) ||
405                     cfs_copy_from_user(&index, args->lstio_grp_idxp,
406                                        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 (cfs_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             (cfs_copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) ||
436              cfs_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 (cfs_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 (cfs_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 (cfs_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 (cfs_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 (cfs_copy_from_user(&index, args->lstio_bat_idxp,
632                                        sizeof(index)) ||
633                     cfs_copy_from_user(&ndent, args->lstio_bat_ndentp,
634                                        sizeof(ndent)))
635                         return -EFAULT;
636
637                 if (ndent <= 0 || index < 0)
638                         return -EINVAL;
639         }
640
641         LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
642         if (name == NULL)
643                 return -ENOMEM;
644
645         if (cfs_copy_from_user(name,
646                                args->lstio_bat_namep, args->lstio_bat_nmlen)) {
647                 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
648                 return -EFAULT;
649         }
650
651         name[args->lstio_bat_nmlen] = 0;
652
653         rc = lstcon_batch_info(name,
654                             args->lstio_bat_entp, args->lstio_bat_server,
655                             args->lstio_bat_testidx, &index, &ndent,
656                             args->lstio_bat_dentsp);
657
658         LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
659
660         if (rc != 0)
661                 return rc;
662
663         if (args->lstio_bat_dentsp != NULL && 
664             (cfs_copy_to_user(args->lstio_bat_idxp, &index, sizeof(index)) ||
665              cfs_copy_to_user(args->lstio_bat_ndentp, &ndent, sizeof(ndent))))
666                 rc = -EFAULT;
667
668         return rc;
669 }
670
671 int
672 lst_stat_query_ioctl(lstio_stat_args_t *args)
673 {
674         int             rc;
675         char           *name;
676
677         /* TODO: not finished */
678         if (args->lstio_sta_key != console_session.ses_key)
679                 return -EACCES;
680
681         if (args->lstio_sta_resultp == NULL ||
682             (args->lstio_sta_namep  == NULL &&
683              args->lstio_sta_idsp   == NULL) ||
684             args->lstio_sta_nmlen <= 0 ||
685             args->lstio_sta_nmlen > LST_NAME_SIZE)
686                 return -EINVAL;
687
688         if (args->lstio_sta_idsp != NULL &&
689             args->lstio_sta_count <= 0)
690                 return -EINVAL;
691
692         LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
693         if (name == NULL)
694                 return -ENOMEM;
695
696         if (cfs_copy_from_user(name, args->lstio_sta_namep,
697                                args->lstio_sta_nmlen)) {
698                 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
699                 return -EFAULT;
700         }
701
702         if (args->lstio_sta_idsp == NULL) {
703                 rc = lstcon_group_stat(name, args->lstio_sta_timeout,
704                                        args->lstio_sta_resultp);
705         } else {
706                 rc = lstcon_nodes_stat(args->lstio_sta_count,
707                                        args->lstio_sta_idsp,
708                                        args->lstio_sta_timeout,
709                                        args->lstio_sta_resultp);
710         }
711
712         LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
713
714         return rc;
715 }
716
717 int lst_test_add_ioctl(lstio_test_args_t *args)
718 {
719         char           *name;
720         char           *srcgrp = NULL;
721         char           *dstgrp = NULL;
722         void           *param = NULL;
723         int             ret = 0;
724         int             rc = -ENOMEM;
725
726         if (args->lstio_tes_resultp == NULL ||
727             args->lstio_tes_retp == NULL ||
728             args->lstio_tes_bat_name == NULL || /* no specified batch */
729             args->lstio_tes_bat_nmlen <= 0 ||
730             args->lstio_tes_bat_nmlen > LST_NAME_SIZE ||
731             args->lstio_tes_sgrp_name == NULL || /* no source group */
732             args->lstio_tes_sgrp_nmlen <= 0 ||
733             args->lstio_tes_sgrp_nmlen > LST_NAME_SIZE ||
734             args->lstio_tes_dgrp_name == NULL || /* no target group */
735             args->lstio_tes_dgrp_nmlen <= 0 ||
736             args->lstio_tes_dgrp_nmlen > LST_NAME_SIZE)
737                 return -EINVAL;
738
739         /* have parameter, check if parameter length is valid */
740         if (args->lstio_tes_param != NULL &&
741             (args->lstio_tes_param_len <= 0 ||
742              args->lstio_tes_param_len > CFS_PAGE_SIZE - sizeof(lstcon_test_t)))
743                 return -EINVAL;
744
745         LIBCFS_ALLOC(name, args->lstio_tes_bat_nmlen + 1);
746         if (name == NULL)
747                 return rc;
748
749         LIBCFS_ALLOC(srcgrp, args->lstio_tes_sgrp_nmlen + 1);
750         if (srcgrp == NULL) 
751                 goto out;
752
753         LIBCFS_ALLOC(dstgrp, args->lstio_tes_dgrp_nmlen + 1);
754         if (srcgrp == NULL) 
755                 goto out;
756
757         if (args->lstio_tes_param != NULL) {
758                 LIBCFS_ALLOC(param, args->lstio_tes_param_len);
759                 if (param == NULL) 
760                         goto out;
761         }
762
763         rc = -EFAULT;
764         if (cfs_copy_from_user(name,
765                               args->lstio_tes_bat_name,
766                               args->lstio_tes_bat_nmlen) ||
767             cfs_copy_from_user(srcgrp,
768                               args->lstio_tes_sgrp_name,
769                               args->lstio_tes_sgrp_nmlen) ||
770             cfs_copy_from_user(dstgrp,
771                               args->lstio_tes_dgrp_name,
772                               args->lstio_tes_dgrp_nmlen) ||
773             cfs_copy_from_user(param, args->lstio_tes_param,
774                               args->lstio_tes_param_len))
775                 goto out;
776
777         rc = lstcon_test_add(name,
778                             args->lstio_tes_type,
779                             args->lstio_tes_loop,
780                             args->lstio_tes_concur,
781                             args->lstio_tes_dist, args->lstio_tes_span,
782                             srcgrp, dstgrp, param, args->lstio_tes_param_len,
783                             &ret, args->lstio_tes_resultp);
784
785         if (ret != 0)
786                 rc = (cfs_copy_to_user(args->lstio_tes_retp, &ret,
787                                        sizeof(ret))) ? -EFAULT : 0;
788 out:
789         if (name != NULL)
790                 LIBCFS_FREE(name, args->lstio_tes_bat_nmlen + 1);
791
792         if (srcgrp != NULL)
793                 LIBCFS_FREE(srcgrp, args->lstio_tes_sgrp_nmlen + 1);
794
795         if (dstgrp != NULL)
796                 LIBCFS_FREE(dstgrp, args->lstio_tes_dgrp_nmlen + 1);
797
798         if (param != NULL)
799                 LIBCFS_FREE(param, args->lstio_tes_param_len);
800
801         return rc;
802 }
803
804 int
805 lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
806 {
807         char   *buf;
808         int     opc = data->ioc_u32[0];
809         int     rc;
810
811         if (cmd != IOC_LIBCFS_LNETST)
812                 return -EINVAL;
813
814         if (data->ioc_plen1 > CFS_PAGE_SIZE)
815                 return -EINVAL;
816
817         LIBCFS_ALLOC(buf, data->ioc_plen1);
818         if (buf == NULL)
819                 return -ENOMEM;
820
821         /* copy in parameter */
822         if (cfs_copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) {
823                 LIBCFS_FREE(buf, data->ioc_plen1);
824                 return -EFAULT;
825         }
826
827         cfs_mutex_down(&console_session.ses_mutex);
828
829         console_session.ses_laststamp = cfs_time_current_sec();
830
831         if (console_session.ses_shutdown) {
832                 rc = -ESHUTDOWN;
833                 goto out;
834         }
835
836         if (console_session.ses_expired)
837                 lstcon_session_end();
838
839         if (opc != LSTIO_SESSION_NEW &&
840             console_session.ses_state == LST_SESSION_NONE) {
841                 CDEBUG(D_NET, "LST no active session\n");
842                 rc = -ESRCH;
843                 goto out;
844         }
845
846         memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t));
847
848         switch (opc) {
849                 case LSTIO_SESSION_NEW:
850                         rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf);
851                         break;
852                 case LSTIO_SESSION_END:
853                         rc = lst_session_end_ioctl((lstio_session_end_args_t *)buf);
854                         break;
855                 case LSTIO_SESSION_INFO:
856                         rc = lst_session_info_ioctl((lstio_session_info_args_t *)buf);
857                         break;
858                 case LSTIO_DEBUG:
859                         rc = lst_debug_ioctl((lstio_debug_args_t *)buf);
860                         break;
861                 case LSTIO_GROUP_ADD:
862                         rc = lst_group_add_ioctl((lstio_group_add_args_t *)buf);
863                         break;
864                 case LSTIO_GROUP_DEL:
865                         rc = lst_group_del_ioctl((lstio_group_del_args_t *)buf);
866                         break;
867                 case LSTIO_GROUP_UPDATE:
868                         rc = lst_group_update_ioctl((lstio_group_update_args_t *)buf);
869                         break;
870                 case LSTIO_NODES_ADD:
871                         rc = lst_nodes_add_ioctl((lstio_group_nodes_args_t *)buf);
872                         break;
873                 case LSTIO_GROUP_LIST:
874                         rc = lst_group_list_ioctl((lstio_group_list_args_t *)buf);
875                         break;
876                 case LSTIO_GROUP_INFO:
877                         rc = lst_group_info_ioctl((lstio_group_info_args_t *)buf);
878                         break;
879                 case LSTIO_BATCH_ADD:
880                         rc = lst_batch_add_ioctl((lstio_batch_add_args_t *)buf);
881                         break;
882                 case LSTIO_BATCH_START:
883                         rc = lst_batch_run_ioctl((lstio_batch_run_args_t *)buf);
884                         break;
885                 case LSTIO_BATCH_STOP:
886                         rc = lst_batch_stop_ioctl((lstio_batch_stop_args_t *)buf);
887                         break;
888                 case LSTIO_BATCH_QUERY:
889                         rc = lst_batch_query_ioctl((lstio_batch_query_args_t *)buf);
890                         break;
891                 case LSTIO_BATCH_LIST:
892                         rc = lst_batch_list_ioctl((lstio_batch_list_args_t *)buf);
893                         break;
894                 case LSTIO_BATCH_INFO:
895                         rc = lst_batch_info_ioctl((lstio_batch_info_args_t *)buf);
896                         break;
897                 case LSTIO_TEST_ADD:
898                         rc = lst_test_add_ioctl((lstio_test_args_t *)buf);
899                         break;
900                 case LSTIO_STAT_QUERY:
901                         rc = lst_stat_query_ioctl((lstio_stat_args_t *)buf);
902                         break;
903                 default:
904                         rc = -EINVAL;
905         }
906
907         if (cfs_copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat,
908                              sizeof(lstcon_trans_stat_t)))
909                 rc = -EFAULT;
910 out:
911         cfs_mutex_up(&console_session.ses_mutex);
912
913         LIBCFS_FREE(buf, data->ioc_plen1);
914
915         return rc;
916 }
917
918 EXPORT_SYMBOL(lstcon_ioctl_entry);
919
920 #endif