Merge char-misc-next into staging-next
[linux-2.6-block.git] / drivers / staging / lustre / lnet / selftest / conctl.c
CommitLineData
d7e09d03
PT
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26/*
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2012, Intel Corporation.
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
9fdaf8c0
GKH
43#include "../../include/linux/libcfs/libcfs.h"
44#include "../../include/linux/lnet/lib-lnet.h"
45#include "../../include/linux/lnet/lnetst.h"
d7e09d03
PT
46#include "console.h"
47
8d94b6d2 48static int
d7e09d03
PT
49lst_session_new_ioctl(lstio_session_new_args_t *args)
50{
74d68011
MS
51 char *name;
52 int rc;
d7e09d03 53
06ace26e 54 if (!args->lstio_ses_idp || /* address for output sid */
5fd88337 55 !args->lstio_ses_key || /* no key is specified */
06ace26e 56 !args->lstio_ses_namep || /* session name */
d7e09d03
PT
57 args->lstio_ses_nmlen <= 0 ||
58 args->lstio_ses_nmlen > LST_NAME_SIZE)
59 return -EINVAL;
60
61 LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1);
06ace26e 62 if (!name)
d7e09d03
PT
63 return -ENOMEM;
64
c314c319
JS
65 if (copy_from_user(name, args->lstio_ses_namep,
66 args->lstio_ses_nmlen)) {
d7e09d03
PT
67 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
68 return -EFAULT;
69 }
70
71 name[args->lstio_ses_nmlen] = 0;
72
73 rc = lstcon_session_new(name,
74 args->lstio_ses_key,
75 args->lstio_ses_feats,
76 args->lstio_ses_force,
77 args->lstio_ses_timeout,
78 args->lstio_ses_idp);
79
80 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
81 return rc;
82}
83
8d94b6d2 84static int
d7e09d03
PT
85lst_session_end_ioctl(lstio_session_end_args_t *args)
86{
87 if (args->lstio_ses_key != console_session.ses_key)
88 return -EACCES;
89
90 return lstcon_session_end();
91}
92
8d94b6d2 93static int
d7e09d03
PT
94lst_session_info_ioctl(lstio_session_info_args_t *args)
95{
96 /* no checking of key */
97
06ace26e
JS
98 if (!args->lstio_ses_idp || /* address for output sid */
99 !args->lstio_ses_keyp || /* address for output key */
100 !args->lstio_ses_featp || /* address for output features */
101 !args->lstio_ses_ndinfo || /* address for output ndinfo */
102 !args->lstio_ses_namep || /* address for output name */
74d68011 103 args->lstio_ses_nmlen <= 0 ||
d7e09d03
PT
104 args->lstio_ses_nmlen > LST_NAME_SIZE)
105 return -EINVAL;
106
107 return lstcon_session_info(args->lstio_ses_idp,
108 args->lstio_ses_keyp,
109 args->lstio_ses_featp,
110 args->lstio_ses_ndinfo,
111 args->lstio_ses_namep,
112 args->lstio_ses_nmlen);
113}
114
8d94b6d2 115static int
d7e09d03
PT
116lst_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
06ace26e 125 if (!args->lstio_dbg_resultp)
d7e09d03
PT
126 return -EINVAL;
127
06ace26e 128 if (args->lstio_dbg_namep && /* name of batch/group */
d7e09d03
PT
129 (args->lstio_dbg_nmlen <= 0 ||
130 args->lstio_dbg_nmlen > LST_NAME_SIZE))
131 return -EINVAL;
132
06ace26e 133 if (args->lstio_dbg_namep) {
d7e09d03 134 LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1);
06ace26e 135 if (!name)
d7e09d03
PT
136 return -ENOMEM;
137
138 if (copy_from_user(name, args->lstio_dbg_namep,
c314c319 139 args->lstio_dbg_nmlen)) {
d7e09d03
PT
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:
06ace26e 159 if (!name)
d7e09d03
PT
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:
06ace26e 167 if (!name)
d7e09d03
PT
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 ||
06ace26e 176 !args->lstio_dbg_idsp)
d7e09d03
PT
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
189out:
06ace26e 190 if (name)
d7e09d03
PT
191 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
192
193 return rc;
194}
195
8d94b6d2 196static int
d7e09d03
PT
197lst_group_add_ioctl(lstio_group_add_args_t *args)
198{
74d68011
MS
199 char *name;
200 int rc;
d7e09d03
PT
201
202 if (args->lstio_grp_key != console_session.ses_key)
203 return -EACCES;
204
06ace26e 205 if (!args->lstio_grp_namep ||
d7e09d03
PT
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);
06ace26e 211 if (!name)
d7e09d03
PT
212 return -ENOMEM;
213
c314c319
JS
214 if (copy_from_user(name, args->lstio_grp_namep,
215 args->lstio_grp_nmlen)) {
d7e09d03
PT
216 LIBCFS_FREE(name, args->lstio_grp_nmlen);
217 return -EFAULT;
218 }
219
220 name[args->lstio_grp_nmlen] = 0;
221
222 rc = lstcon_group_add(name);
223
224 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
225
226 return rc;
227}
228
8d94b6d2 229static int
d7e09d03
PT
230lst_group_del_ioctl(lstio_group_del_args_t *args)
231{
232 int rc;
233 char *name;
234
235 if (args->lstio_grp_key != console_session.ses_key)
236 return -EACCES;
237
06ace26e 238 if (!args->lstio_grp_namep ||
d7e09d03
PT
239 args->lstio_grp_nmlen <= 0 ||
240 args->lstio_grp_nmlen > LST_NAME_SIZE)
241 return -EINVAL;
242
243 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
06ace26e 244 if (!name)
d7e09d03
PT
245 return -ENOMEM;
246
c314c319
JS
247 if (copy_from_user(name, args->lstio_grp_namep,
248 args->lstio_grp_nmlen)) {
d7e09d03
PT
249 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
250 return -EFAULT;
251 }
252
253 name[args->lstio_grp_nmlen] = 0;
254
255 rc = lstcon_group_del(name);
256
257 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
258
259 return rc;
260}
261
8d94b6d2 262static int
d7e09d03
PT
263lst_group_update_ioctl(lstio_group_update_args_t *args)
264{
265 int rc;
266 char *name;
267
268 if (args->lstio_grp_key != console_session.ses_key)
269 return -EACCES;
270
06ace26e
JS
271 if (!args->lstio_grp_resultp ||
272 !args->lstio_grp_namep ||
d7e09d03
PT
273 args->lstio_grp_nmlen <= 0 ||
274 args->lstio_grp_nmlen > LST_NAME_SIZE)
275 return -EINVAL;
276
277 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
06ace26e 278 if (!name)
d7e09d03
PT
279 return -ENOMEM;
280
281 if (copy_from_user(name,
282 args->lstio_grp_namep,
283 args->lstio_grp_nmlen)) {
284 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
285 return -EFAULT;
286 }
287
288 name[args->lstio_grp_nmlen] = 0;
289
290 switch (args->lstio_grp_opc) {
291 case LST_GROUP_CLEAN:
292 rc = lstcon_group_clean(name, args->lstio_grp_args);
293 break;
294
295 case LST_GROUP_REFRESH:
296 rc = lstcon_group_refresh(name, args->lstio_grp_resultp);
297 break;
298
299 case LST_GROUP_RMND:
300 if (args->lstio_grp_count <= 0 ||
06ace26e 301 !args->lstio_grp_idsp) {
d7e09d03
PT
302 rc = -EINVAL;
303 break;
304 }
305 rc = lstcon_nodes_remove(name, args->lstio_grp_count,
306 args->lstio_grp_idsp,
307 args->lstio_grp_resultp);
308 break;
309
310 default:
311 rc = -EINVAL;
312 break;
313 }
314
315 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
316
317 return rc;
318}
319
8d94b6d2 320static int
d7e09d03
PT
321lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
322{
323 unsigned feats;
74d68011
MS
324 int rc;
325 char *name;
d7e09d03
PT
326
327 if (args->lstio_grp_key != console_session.ses_key)
328 return -EACCES;
329
06ace26e 330 if (!args->lstio_grp_idsp || /* array of ids */
d7e09d03 331 args->lstio_grp_count <= 0 ||
06ace26e
JS
332 !args->lstio_grp_resultp ||
333 !args->lstio_grp_featp ||
334 !args->lstio_grp_namep ||
d7e09d03
PT
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);
06ace26e 340 if (!name)
d7e09d03
PT
341 return -ENOMEM;
342
343 if (copy_from_user(name, args->lstio_grp_namep,
c314c319 344 args->lstio_grp_nmlen)) {
d7e09d03
PT
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, &feats,
354 args->lstio_grp_resultp);
355
356 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
5fd88337 357 if (!rc &&
d7e09d03
PT
358 copy_to_user(args->lstio_grp_featp, &feats, sizeof(feats))) {
359 return -EINVAL;
360 }
361
362 return rc;
363}
364
8d94b6d2 365static int
d7e09d03
PT
366lst_group_list_ioctl(lstio_group_list_args_t *args)
367{
368 if (args->lstio_grp_key != console_session.ses_key)
369 return -EACCES;
370
371 if (args->lstio_grp_idx < 0 ||
06ace26e 372 !args->lstio_grp_namep ||
d7e09d03
PT
373 args->lstio_grp_nmlen <= 0 ||
374 args->lstio_grp_nmlen > LST_NAME_SIZE)
375 return -EINVAL;
376
377 return lstcon_group_list(args->lstio_grp_idx,
378 args->lstio_grp_nmlen,
379 args->lstio_grp_namep);
380}
381
8d94b6d2 382static int
d7e09d03
PT
383lst_group_info_ioctl(lstio_group_info_args_t *args)
384{
74d68011
MS
385 char *name;
386 int ndent;
387 int index;
388 int rc;
d7e09d03
PT
389
390 if (args->lstio_grp_key != console_session.ses_key)
391 return -EACCES;
392
06ace26e 393 if (!args->lstio_grp_namep ||
d7e09d03
PT
394 args->lstio_grp_nmlen <= 0 ||
395 args->lstio_grp_nmlen > LST_NAME_SIZE)
396 return -EINVAL;
397
06ace26e
JS
398 if (!args->lstio_grp_entp && /* output: group entry */
399 !args->lstio_grp_dentsp) /* output: node entry */
d7e09d03
PT
400 return -EINVAL;
401
06ace26e
JS
402 if (args->lstio_grp_dentsp) { /* have node entry */
403 if (!args->lstio_grp_idxp || /* node index */
404 !args->lstio_grp_ndentp) /* # of node entry */
d7e09d03
PT
405 return -EINVAL;
406
407 if (copy_from_user(&ndent, args->lstio_grp_ndentp,
c314c319 408 sizeof(ndent)) ||
d7e09d03 409 copy_from_user(&index, args->lstio_grp_idxp,
c314c319 410 sizeof(index)))
d7e09d03
PT
411 return -EFAULT;
412
413 if (ndent <= 0 || index < 0)
414 return -EINVAL;
415 }
416
417 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
06ace26e 418 if (!name)
d7e09d03
PT
419 return -ENOMEM;
420
c314c319
JS
421 if (copy_from_user(name, args->lstio_grp_namep,
422 args->lstio_grp_nmlen)) {
d7e09d03
PT
423 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
424 return -EFAULT;
425 }
426
427 name[args->lstio_grp_nmlen] = 0;
428
429 rc = lstcon_group_info(name, args->lstio_grp_entp,
430 &index, &ndent, args->lstio_grp_dentsp);
431
432 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
433
5fd88337 434 if (rc)
d7e09d03
PT
435 return rc;
436
06ace26e 437 if (args->lstio_grp_dentsp &&
d7e09d03
PT
438 (copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) ||
439 copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent))))
2a96be0d 440 return -EFAULT;
d7e09d03
PT
441
442 return 0;
443}
444
8d94b6d2 445static int
d7e09d03
PT
446lst_batch_add_ioctl(lstio_batch_add_args_t *args)
447{
74d68011
MS
448 int rc;
449 char *name;
d7e09d03
PT
450
451 if (args->lstio_bat_key != console_session.ses_key)
452 return -EACCES;
453
06ace26e 454 if (!args->lstio_bat_namep ||
d7e09d03
PT
455 args->lstio_bat_nmlen <= 0 ||
456 args->lstio_bat_nmlen > LST_NAME_SIZE)
457 return -EINVAL;
458
459 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
06ace26e 460 if (!name)
d7e09d03
PT
461 return -ENOMEM;
462
c314c319
JS
463 if (copy_from_user(name, args->lstio_bat_namep,
464 args->lstio_bat_nmlen)) {
d7e09d03
PT
465 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
466 return -EFAULT;
467 }
468
469 name[args->lstio_bat_nmlen] = 0;
470
471 rc = lstcon_batch_add(name);
472
473 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
474
475 return rc;
476}
477
8d94b6d2 478static int
d7e09d03
PT
479lst_batch_run_ioctl(lstio_batch_run_args_t *args)
480{
74d68011
MS
481 int rc;
482 char *name;
d7e09d03
PT
483
484 if (args->lstio_bat_key != console_session.ses_key)
485 return -EACCES;
486
06ace26e 487 if (!args->lstio_bat_namep ||
d7e09d03
PT
488 args->lstio_bat_nmlen <= 0 ||
489 args->lstio_bat_nmlen > LST_NAME_SIZE)
490 return -EINVAL;
491
492 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
06ace26e 493 if (!name)
d7e09d03
PT
494 return -ENOMEM;
495
c314c319
JS
496 if (copy_from_user(name, args->lstio_bat_namep,
497 args->lstio_bat_nmlen)) {
d7e09d03
PT
498 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
499 return -EFAULT;
500 }
501
502 name[args->lstio_bat_nmlen] = 0;
503
504 rc = lstcon_batch_run(name, args->lstio_bat_timeout,
505 args->lstio_bat_resultp);
506
507 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
508
509 return rc;
510}
511
8d94b6d2 512static int
d7e09d03
PT
513lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
514{
74d68011
MS
515 int rc;
516 char *name;
d7e09d03
PT
517
518 if (args->lstio_bat_key != console_session.ses_key)
519 return -EACCES;
520
06ace26e
JS
521 if (!args->lstio_bat_resultp ||
522 !args->lstio_bat_namep ||
d7e09d03
PT
523 args->lstio_bat_nmlen <= 0 ||
524 args->lstio_bat_nmlen > LST_NAME_SIZE)
525 return -EINVAL;
526
527 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
06ace26e 528 if (!name)
d7e09d03
PT
529 return -ENOMEM;
530
c314c319
JS
531 if (copy_from_user(name, args->lstio_bat_namep,
532 args->lstio_bat_nmlen)) {
d7e09d03
PT
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
8d94b6d2 547static int
d7e09d03
PT
548lst_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
06ace26e
JS
556 if (!args->lstio_bat_resultp ||
557 !args->lstio_bat_namep ||
d7e09d03
PT
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);
06ace26e 566 if (!name)
d7e09d03
PT
567 return -ENOMEM;
568
c314c319
JS
569 if (copy_from_user(name, args->lstio_bat_namep,
570 args->lstio_bat_nmlen)) {
d7e09d03
PT
571 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
572 return -EFAULT;
573 }
574
575 name[args->lstio_bat_nmlen] = 0;
576
577 rc = lstcon_test_batch_query(name,
578 args->lstio_bat_testidx,
579 args->lstio_bat_client,
580 args->lstio_bat_timeout,
581 args->lstio_bat_resultp);
582
583 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
584
585 return rc;
586}
587
8d94b6d2 588static int
d7e09d03
PT
589lst_batch_list_ioctl(lstio_batch_list_args_t *args)
590{
591 if (args->lstio_bat_key != console_session.ses_key)
592 return -EACCES;
593
594 if (args->lstio_bat_idx < 0 ||
06ace26e 595 !args->lstio_bat_namep ||
d7e09d03
PT
596 args->lstio_bat_nmlen <= 0 ||
597 args->lstio_bat_nmlen > LST_NAME_SIZE)
598 return -EINVAL;
599
600 return lstcon_batch_list(args->lstio_bat_idx,
601 args->lstio_bat_nmlen,
602 args->lstio_bat_namep);
603}
604
8d94b6d2 605static int
d7e09d03
PT
606lst_batch_info_ioctl(lstio_batch_info_args_t *args)
607{
74d68011
MS
608 char *name;
609 int rc;
610 int index;
611 int ndent;
d7e09d03
PT
612
613 if (args->lstio_bat_key != console_session.ses_key)
614 return -EACCES;
615
06ace26e 616 if (!args->lstio_bat_namep || /* batch name */
d7e09d03
PT
617 args->lstio_bat_nmlen <= 0 ||
618 args->lstio_bat_nmlen > LST_NAME_SIZE)
619 return -EINVAL;
620
06ace26e
JS
621 if (!args->lstio_bat_entp && /* output: batch entry */
622 !args->lstio_bat_dentsp) /* output: node entry */
d7e09d03
PT
623 return -EINVAL;
624
06ace26e
JS
625 if (args->lstio_bat_dentsp) { /* have node entry */
626 if (!args->lstio_bat_idxp || /* node index */
627 !args->lstio_bat_ndentp) /* # of node entry */
d7e09d03
PT
628 return -EINVAL;
629
630 if (copy_from_user(&index, args->lstio_bat_idxp,
c314c319 631 sizeof(index)) ||
d7e09d03 632 copy_from_user(&ndent, args->lstio_bat_ndentp,
c314c319 633 sizeof(ndent)))
d7e09d03
PT
634 return -EFAULT;
635
636 if (ndent <= 0 || index < 0)
637 return -EINVAL;
638 }
639
640 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
06ace26e 641 if (!name)
d7e09d03
PT
642 return -ENOMEM;
643
c314c319
JS
644 if (copy_from_user(name, args->lstio_bat_namep,
645 args->lstio_bat_nmlen)) {
d7e09d03
PT
646 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
647 return -EFAULT;
648 }
649
650 name[args->lstio_bat_nmlen] = 0;
651
c314c319
JS
652 rc = lstcon_batch_info(name, args->lstio_bat_entp,
653 args->lstio_bat_server, args->lstio_bat_testidx,
654 &index, &ndent, args->lstio_bat_dentsp);
d7e09d03
PT
655
656 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
657
5fd88337 658 if (rc)
d7e09d03
PT
659 return rc;
660
06ace26e 661 if (args->lstio_bat_dentsp &&
d7e09d03
PT
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
8d94b6d2 669static int
d7e09d03
PT
670lst_stat_query_ioctl(lstio_stat_args_t *args)
671{
74d68011
MS
672 int rc;
673 char *name;
d7e09d03
PT
674
675 /* TODO: not finished */
676 if (args->lstio_sta_key != console_session.ses_key)
677 return -EACCES;
678
06ace26e
JS
679 if (!args->lstio_sta_resultp ||
680 (!args->lstio_sta_namep && !args->lstio_sta_idsp) ||
d7e09d03
PT
681 args->lstio_sta_nmlen <= 0 ||
682 args->lstio_sta_nmlen > LST_NAME_SIZE)
683 return -EINVAL;
684
06ace26e 685 if (args->lstio_sta_idsp &&
d7e09d03
PT
686 args->lstio_sta_count <= 0)
687 return -EINVAL;
688
689 LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
06ace26e 690 if (!name)
d7e09d03
PT
691 return -ENOMEM;
692
693 if (copy_from_user(name, args->lstio_sta_namep,
c314c319 694 args->lstio_sta_nmlen)) {
d7e09d03
PT
695 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
696 return -EFAULT;
697 }
698
06ace26e 699 if (!args->lstio_sta_idsp) {
d7e09d03
PT
700 rc = lstcon_group_stat(name, args->lstio_sta_timeout,
701 args->lstio_sta_resultp);
702 } else {
703 rc = lstcon_nodes_stat(args->lstio_sta_count,
704 args->lstio_sta_idsp,
705 args->lstio_sta_timeout,
706 args->lstio_sta_resultp);
707 }
708
709 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
710
711 return rc;
712}
713
f3731cdb 714static int lst_test_add_ioctl(lstio_test_args_t *args)
d7e09d03 715{
d75e265b
AS
716 char *batch_name;
717 char *src_name = NULL;
718 char *dst_name = NULL;
719 void *param = NULL;
720 int ret = 0;
721 int rc = -ENOMEM;
d7e09d03 722
06ace26e
JS
723 if (!args->lstio_tes_resultp ||
724 !args->lstio_tes_retp ||
725 !args->lstio_tes_bat_name || /* no specified batch */
d7e09d03
PT
726 args->lstio_tes_bat_nmlen <= 0 ||
727 args->lstio_tes_bat_nmlen > LST_NAME_SIZE ||
06ace26e 728 !args->lstio_tes_sgrp_name || /* no source group */
d7e09d03
PT
729 args->lstio_tes_sgrp_nmlen <= 0 ||
730 args->lstio_tes_sgrp_nmlen > LST_NAME_SIZE ||
06ace26e 731 !args->lstio_tes_dgrp_name || /* no target group */
d7e09d03
PT
732 args->lstio_tes_dgrp_nmlen <= 0 ||
733 args->lstio_tes_dgrp_nmlen > LST_NAME_SIZE)
734 return -EINVAL;
735
5fd88337 736 if (!args->lstio_tes_loop || /* negative is infinite */
d7e09d03
PT
737 args->lstio_tes_concur <= 0 ||
738 args->lstio_tes_dist <= 0 ||
739 args->lstio_tes_span <= 0)
740 return -EINVAL;
741
742 /* have parameter, check if parameter length is valid */
06ace26e 743 if (args->lstio_tes_param &&
d7e09d03
PT
744 (args->lstio_tes_param_len <= 0 ||
745 args->lstio_tes_param_len > PAGE_CACHE_SIZE - sizeof(lstcon_test_t)))
746 return -EINVAL;
747
d75e265b 748 LIBCFS_ALLOC(batch_name, args->lstio_tes_bat_nmlen + 1);
06ace26e 749 if (!batch_name)
d7e09d03
PT
750 return rc;
751
d75e265b 752 LIBCFS_ALLOC(src_name, args->lstio_tes_sgrp_nmlen + 1);
06ace26e 753 if (!src_name)
d7e09d03
PT
754 goto out;
755
d75e265b 756 LIBCFS_ALLOC(dst_name, args->lstio_tes_dgrp_nmlen + 1);
06ace26e 757 if (!dst_name)
d7e09d03
PT
758 goto out;
759
06ace26e 760 if (args->lstio_tes_param) {
d7e09d03 761 LIBCFS_ALLOC(param, args->lstio_tes_param_len);
06ace26e 762 if (!param)
d7e09d03
PT
763 goto out;
764 }
765
766 rc = -EFAULT;
d75e265b
AS
767 if (copy_from_user(batch_name, args->lstio_tes_bat_name,
768 args->lstio_tes_bat_nmlen) ||
769 copy_from_user(src_name, args->lstio_tes_sgrp_name,
770 args->lstio_tes_sgrp_nmlen) ||
771 copy_from_user(dst_name, args->lstio_tes_dgrp_name,
772 args->lstio_tes_dgrp_nmlen) ||
d7e09d03 773 copy_from_user(param, args->lstio_tes_param,
c314c319 774 args->lstio_tes_param_len))
d7e09d03
PT
775 goto out;
776
c314c319
JS
777 rc = lstcon_test_add(batch_name, args->lstio_tes_type,
778 args->lstio_tes_loop, args->lstio_tes_concur,
779 args->lstio_tes_dist, args->lstio_tes_span,
780 src_name, dst_name, param,
781 args->lstio_tes_param_len,
782 &ret, args->lstio_tes_resultp);
d7e09d03 783
5fd88337 784 if (ret)
d7e09d03 785 rc = (copy_to_user(args->lstio_tes_retp, &ret,
c314c319 786 sizeof(ret))) ? -EFAULT : 0;
d7e09d03 787out:
06ace26e 788 if (batch_name)
d75e265b 789 LIBCFS_FREE(batch_name, args->lstio_tes_bat_nmlen + 1);
d7e09d03 790
06ace26e 791 if (src_name)
d75e265b 792 LIBCFS_FREE(src_name, args->lstio_tes_sgrp_nmlen + 1);
d7e09d03 793
06ace26e 794 if (dst_name)
d75e265b 795 LIBCFS_FREE(dst_name, args->lstio_tes_dgrp_nmlen + 1);
d7e09d03 796
06ace26e 797 if (param)
d7e09d03
PT
798 LIBCFS_FREE(param, args->lstio_tes_param_len);
799
800 return rc;
801}
802
803int
804lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
805{
806 char *buf;
807 int opc = data->ioc_u32[0];
808 int rc;
809
810 if (cmd != IOC_LIBCFS_LNETST)
811 return -EINVAL;
812
813 if (data->ioc_plen1 > PAGE_CACHE_SIZE)
814 return -EINVAL;
815
816 LIBCFS_ALLOC(buf, data->ioc_plen1);
06ace26e 817 if (!buf)
d7e09d03
PT
818 return -ENOMEM;
819
820 /* copy in parameter */
821 if (copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) {
822 LIBCFS_FREE(buf, data->ioc_plen1);
823 return -EFAULT;
824 }
825
826 mutex_lock(&console_session.ses_mutex);
827
d9f79e6b 828 console_session.ses_laststamp = ktime_get_real_seconds();
d7e09d03
PT
829
830 if (console_session.ses_shutdown) {
831 rc = -ESHUTDOWN;
832 goto out;
833 }
834
835 if (console_session.ses_expired)
836 lstcon_session_end();
837
838 if (opc != LSTIO_SESSION_NEW &&
839 console_session.ses_state == LST_SESSION_NONE) {
840 CDEBUG(D_NET, "LST no active session\n");
841 rc = -ESRCH;
842 goto out;
843 }
844
845 memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t));
846
847 switch (opc) {
a18dd470
TG
848 case LSTIO_SESSION_NEW:
849 rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf);
850 break;
851 case LSTIO_SESSION_END:
852 rc = lst_session_end_ioctl((lstio_session_end_args_t *)buf);
853 break;
854 case LSTIO_SESSION_INFO:
855 rc = lst_session_info_ioctl((lstio_session_info_args_t *)buf);
856 break;
857 case LSTIO_DEBUG:
858 rc = lst_debug_ioctl((lstio_debug_args_t *)buf);
859 break;
860 case LSTIO_GROUP_ADD:
861 rc = lst_group_add_ioctl((lstio_group_add_args_t *)buf);
862 break;
863 case LSTIO_GROUP_DEL:
864 rc = lst_group_del_ioctl((lstio_group_del_args_t *)buf);
865 break;
866 case LSTIO_GROUP_UPDATE:
867 rc = lst_group_update_ioctl((lstio_group_update_args_t *)buf);
868 break;
869 case LSTIO_NODES_ADD:
870 rc = lst_nodes_add_ioctl((lstio_group_nodes_args_t *)buf);
871 break;
872 case LSTIO_GROUP_LIST:
873 rc = lst_group_list_ioctl((lstio_group_list_args_t *)buf);
874 break;
875 case LSTIO_GROUP_INFO:
876 rc = lst_group_info_ioctl((lstio_group_info_args_t *)buf);
877 break;
878 case LSTIO_BATCH_ADD:
879 rc = lst_batch_add_ioctl((lstio_batch_add_args_t *)buf);
880 break;
881 case LSTIO_BATCH_START:
882 rc = lst_batch_run_ioctl((lstio_batch_run_args_t *)buf);
883 break;
884 case LSTIO_BATCH_STOP:
885 rc = lst_batch_stop_ioctl((lstio_batch_stop_args_t *)buf);
886 break;
887 case LSTIO_BATCH_QUERY:
888 rc = lst_batch_query_ioctl((lstio_batch_query_args_t *)buf);
889 break;
890 case LSTIO_BATCH_LIST:
891 rc = lst_batch_list_ioctl((lstio_batch_list_args_t *)buf);
892 break;
893 case LSTIO_BATCH_INFO:
894 rc = lst_batch_info_ioctl((lstio_batch_info_args_t *)buf);
895 break;
896 case LSTIO_TEST_ADD:
897 rc = lst_test_add_ioctl((lstio_test_args_t *)buf);
898 break;
899 case LSTIO_STAT_QUERY:
900 rc = lst_stat_query_ioctl((lstio_stat_args_t *)buf);
901 break;
902 default:
903 rc = -EINVAL;
d7e09d03
PT
904 }
905
906 if (copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat,
c314c319 907 sizeof(lstcon_trans_stat_t)))
d7e09d03
PT
908 rc = -EFAULT;
909out:
910 mutex_unlock(&console_session.ses_mutex);
911
912 LIBCFS_FREE(buf, data->ioc_plen1);
913
914 return rc;
915}