4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lnet/selftest/conctl.c
36 * IOC handle in kernel
38 * Author: Liang Zhen <liangzhen@clusterfs.com>
42 #include <libcfs/libcfs.h>
43 #include <lnet/lib-lnet.h>
44 #include <lnet/lnetst.h>
48 lst_session_new_ioctl(lstio_session_new_args_t *args)
53 if (args->lstio_ses_idp == NULL || /* address for output sid */
54 args->lstio_ses_key == 0 || /* no key is specified */
55 args->lstio_ses_namep == NULL || /* session name */
56 args->lstio_ses_nmlen <= 0 ||
57 args->lstio_ses_nmlen > LST_NAME_SIZE)
60 LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1);
64 if (cfs_copy_from_user(name,
65 args->lstio_ses_namep,
66 args->lstio_ses_nmlen)) {
67 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
71 name[args->lstio_ses_nmlen] = 0;
73 rc = lstcon_session_new(name,
75 args->lstio_ses_timeout,
76 args->lstio_ses_force,
79 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
85 lst_session_end_ioctl(lstio_session_end_args_t *args)
87 if (args->lstio_ses_key != console_session.ses_key)
90 return lstcon_session_end();
94 lst_session_info_ioctl(lstio_session_info_args_t *args)
96 /* no checking of key */
98 if (args->lstio_ses_idp == NULL || /* address for ouput sid */
99 args->lstio_ses_keyp == NULL || /* address for ouput key */
100 args->lstio_ses_ndinfo == NULL || /* address for output ndinfo */
101 args->lstio_ses_namep == NULL || /* address for ouput name */
102 args->lstio_ses_nmlen <= 0 ||
103 args->lstio_ses_nmlen > LST_NAME_SIZE)
106 return lstcon_session_info(args->lstio_ses_idp,
107 args->lstio_ses_keyp,
108 args->lstio_ses_ndinfo,
109 args->lstio_ses_namep,
110 args->lstio_ses_nmlen);
114 lst_debug_ioctl(lstio_debug_args_t *args)
120 if (args->lstio_dbg_key != console_session.ses_key)
123 if (args->lstio_dbg_resultp == NULL)
126 if (args->lstio_dbg_namep != NULL && /* name of batch/group */
127 (args->lstio_dbg_nmlen <= 0 ||
128 args->lstio_dbg_nmlen > LST_NAME_SIZE))
131 if (args->lstio_dbg_namep != NULL) {
132 LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1);
136 if (cfs_copy_from_user(name, args->lstio_dbg_namep,
137 args->lstio_dbg_nmlen)) {
138 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
143 name[args->lstio_dbg_nmlen] = 0;
148 switch (args->lstio_dbg_type) {
149 case LST_OPC_SESSION:
150 rc = lstcon_session_debug(args->lstio_dbg_timeout,
151 args->lstio_dbg_resultp);
154 case LST_OPC_BATCHSRV:
156 case LST_OPC_BATCHCLI:
160 rc = lstcon_batch_debug(args->lstio_dbg_timeout,
161 name, client, args->lstio_dbg_resultp);
168 rc = lstcon_group_debug(args->lstio_dbg_timeout,
169 name, args->lstio_dbg_resultp);
173 if (args->lstio_dbg_count <= 0 ||
174 args->lstio_dbg_idsp == NULL)
177 rc = lstcon_nodes_debug(args->lstio_dbg_timeout,
178 args->lstio_dbg_count,
179 args->lstio_dbg_idsp,
180 args->lstio_dbg_resultp);
189 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
195 lst_group_add_ioctl(lstio_group_add_args_t *args)
200 if (args->lstio_grp_key != console_session.ses_key)
203 if (args->lstio_grp_namep == NULL||
204 args->lstio_grp_nmlen <= 0 ||
205 args->lstio_grp_nmlen > LST_NAME_SIZE)
208 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
212 if (cfs_copy_from_user(name,
213 args->lstio_grp_namep,
214 args->lstio_grp_nmlen)) {
215 LIBCFS_FREE(name, args->lstio_grp_nmlen);
219 name[args->lstio_grp_nmlen] = 0;
221 rc = lstcon_group_add(name);
223 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
229 lst_group_del_ioctl(lstio_group_del_args_t *args)
234 if (args->lstio_grp_key != console_session.ses_key)
237 if (args->lstio_grp_namep == NULL ||
238 args->lstio_grp_nmlen <= 0 ||
239 args->lstio_grp_nmlen > LST_NAME_SIZE)
242 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
246 if (cfs_copy_from_user(name,
247 args->lstio_grp_namep,
248 args->lstio_grp_nmlen)) {
249 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
253 name[args->lstio_grp_nmlen] = 0;
255 rc = lstcon_group_del(name);
257 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
263 lst_group_update_ioctl(lstio_group_update_args_t *args)
268 if (args->lstio_grp_key != console_session.ses_key)
271 if (args->lstio_grp_resultp == NULL ||
272 args->lstio_grp_namep == NULL ||
273 args->lstio_grp_nmlen <= 0 ||
274 args->lstio_grp_nmlen > LST_NAME_SIZE)
277 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
281 if (cfs_copy_from_user(name,
282 args->lstio_grp_namep,
283 args->lstio_grp_nmlen)) {
284 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
288 name[args->lstio_grp_nmlen] = 0;
290 switch (args->lstio_grp_opc) {
291 case LST_GROUP_CLEAN:
292 rc = lstcon_group_clean(name, args->lstio_grp_args);
295 case LST_GROUP_REFRESH:
296 rc = lstcon_group_refresh(name, args->lstio_grp_resultp);
300 if (args->lstio_grp_count <= 0 ||
301 args->lstio_grp_idsp == NULL) {
305 rc = lstcon_nodes_remove(name, args->lstio_grp_count,
306 args->lstio_grp_idsp,
307 args->lstio_grp_resultp);
315 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
321 lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
326 if (args->lstio_grp_key != console_session.ses_key)
329 if (args->lstio_grp_idsp == NULL || /* array of ids */
330 args->lstio_grp_count <= 0 ||
331 args->lstio_grp_resultp == NULL ||
332 args->lstio_grp_namep == NULL ||
333 args->lstio_grp_nmlen <= 0 ||
334 args->lstio_grp_nmlen > LST_NAME_SIZE)
337 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
341 if (cfs_copy_from_user(name, args->lstio_grp_namep,
342 args->lstio_grp_nmlen)) {
343 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
348 name[args->lstio_grp_nmlen] = 0;
350 rc = lstcon_nodes_add(name, args->lstio_grp_count,
351 args->lstio_grp_idsp,
352 args->lstio_grp_resultp);
354 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
360 lst_group_list_ioctl(lstio_group_list_args_t *args)
362 if (args->lstio_grp_key != console_session.ses_key)
365 if (args->lstio_grp_idx < 0 ||
366 args->lstio_grp_namep == NULL ||
367 args->lstio_grp_nmlen <= 0 ||
368 args->lstio_grp_nmlen > LST_NAME_SIZE)
371 return lstcon_group_list(args->lstio_grp_idx,
372 args->lstio_grp_nmlen,
373 args->lstio_grp_namep);
377 lst_group_info_ioctl(lstio_group_info_args_t *args)
384 if (args->lstio_grp_key != console_session.ses_key)
387 if (args->lstio_grp_namep == NULL ||
388 args->lstio_grp_nmlen <= 0 ||
389 args->lstio_grp_nmlen > LST_NAME_SIZE)
392 if (args->lstio_grp_entp == NULL && /* output: group entry */
393 args->lstio_grp_dentsp == NULL) /* output: node entry */
396 if (args->lstio_grp_dentsp != NULL) { /* have node entry */
397 if (args->lstio_grp_idxp == NULL || /* node index */
398 args->lstio_grp_ndentp == NULL) /* # of node entry */
401 if (cfs_copy_from_user(&ndent, args->lstio_grp_ndentp,
403 cfs_copy_from_user(&index, args->lstio_grp_idxp,
407 if (ndent <= 0 || index < 0)
411 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
415 if (cfs_copy_from_user(name,
416 args->lstio_grp_namep,
417 args->lstio_grp_nmlen)) {
418 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
422 name[args->lstio_grp_nmlen] = 0;
424 rc = lstcon_group_info(name, args->lstio_grp_entp,
425 &index, &ndent, args->lstio_grp_dentsp);
427 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
432 if (args->lstio_grp_dentsp != NULL &&
433 (cfs_copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) ||
434 cfs_copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent))))
441 lst_batch_add_ioctl(lstio_batch_add_args_t *args)
446 if (args->lstio_bat_key != console_session.ses_key)
449 if (args->lstio_bat_namep == NULL ||
450 args->lstio_bat_nmlen <= 0 ||
451 args->lstio_bat_nmlen > LST_NAME_SIZE)
454 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
458 if (cfs_copy_from_user(name,
459 args->lstio_bat_namep,
460 args->lstio_bat_nmlen)) {
461 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
465 name[args->lstio_bat_nmlen] = 0;
467 rc = lstcon_batch_add(name);
469 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
475 lst_batch_run_ioctl(lstio_batch_run_args_t *args)
480 if (args->lstio_bat_key != console_session.ses_key)
483 if (args->lstio_bat_namep == NULL ||
484 args->lstio_bat_nmlen <= 0 ||
485 args->lstio_bat_nmlen > LST_NAME_SIZE)
488 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
492 if (cfs_copy_from_user(name,
493 args->lstio_bat_namep,
494 args->lstio_bat_nmlen)) {
495 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
499 name[args->lstio_bat_nmlen] = 0;
501 rc = lstcon_batch_run(name, args->lstio_bat_timeout,
502 args->lstio_bat_resultp);
504 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
510 lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
515 if (args->lstio_bat_key != console_session.ses_key)
518 if (args->lstio_bat_resultp == NULL ||
519 args->lstio_bat_namep == NULL ||
520 args->lstio_bat_nmlen <= 0 ||
521 args->lstio_bat_nmlen > LST_NAME_SIZE)
524 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
528 if (cfs_copy_from_user(name,
529 args->lstio_bat_namep,
530 args->lstio_bat_nmlen)) {
531 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
535 name[args->lstio_bat_nmlen] = 0;
537 rc = lstcon_batch_stop(name, args->lstio_bat_force,
538 args->lstio_bat_resultp);
540 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
546 lst_batch_query_ioctl(lstio_batch_query_args_t *args)
551 if (args->lstio_bat_key != console_session.ses_key)
554 if (args->lstio_bat_resultp == NULL ||
555 args->lstio_bat_namep == NULL ||
556 args->lstio_bat_nmlen <= 0 ||
557 args->lstio_bat_nmlen > LST_NAME_SIZE)
560 if (args->lstio_bat_testidx < 0)
563 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
567 if (cfs_copy_from_user(name,
568 args->lstio_bat_namep,
569 args->lstio_bat_nmlen)) {
570 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
574 name[args->lstio_bat_nmlen] = 0;
576 rc = lstcon_test_batch_query(name,
577 args->lstio_bat_testidx,
578 args->lstio_bat_client,
579 args->lstio_bat_timeout,
580 args->lstio_bat_resultp);
582 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
588 lst_batch_list_ioctl(lstio_batch_list_args_t *args)
590 if (args->lstio_bat_key != console_session.ses_key)
593 if (args->lstio_bat_idx < 0 ||
594 args->lstio_bat_namep == NULL ||
595 args->lstio_bat_nmlen <= 0 ||
596 args->lstio_bat_nmlen > LST_NAME_SIZE)
599 return lstcon_batch_list(args->lstio_bat_idx,
600 args->lstio_bat_nmlen,
601 args->lstio_bat_namep);
605 lst_batch_info_ioctl(lstio_batch_info_args_t *args)
612 if (args->lstio_bat_key != console_session.ses_key)
615 if (args->lstio_bat_namep == NULL || /* batch name */
616 args->lstio_bat_nmlen <= 0 ||
617 args->lstio_bat_nmlen > LST_NAME_SIZE)
620 if (args->lstio_bat_entp == NULL && /* output: batch entry */
621 args->lstio_bat_dentsp == NULL) /* output: node entry */
624 if (args->lstio_bat_dentsp != NULL) { /* have node entry */
625 if (args->lstio_bat_idxp == NULL || /* node index */
626 args->lstio_bat_ndentp == NULL) /* # of node entry */
629 if (cfs_copy_from_user(&index, args->lstio_bat_idxp,
631 cfs_copy_from_user(&ndent, args->lstio_bat_ndentp,
635 if (ndent <= 0 || index < 0)
639 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
643 if (cfs_copy_from_user(name,
644 args->lstio_bat_namep, args->lstio_bat_nmlen)) {
645 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
649 name[args->lstio_bat_nmlen] = 0;
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);
656 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
661 if (args->lstio_bat_dentsp != NULL &&
662 (cfs_copy_to_user(args->lstio_bat_idxp, &index, sizeof(index)) ||
663 cfs_copy_to_user(args->lstio_bat_ndentp, &ndent, sizeof(ndent))))
670 lst_stat_query_ioctl(lstio_stat_args_t *args)
675 /* TODO: not finished */
676 if (args->lstio_sta_key != console_session.ses_key)
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)
686 if (args->lstio_sta_idsp != NULL &&
687 args->lstio_sta_count <= 0)
690 LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
694 if (cfs_copy_from_user(name, args->lstio_sta_namep,
695 args->lstio_sta_nmlen)) {
696 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
700 if (args->lstio_sta_idsp == NULL) {
701 rc = lstcon_group_stat(name, args->lstio_sta_timeout,
702 args->lstio_sta_resultp);
704 rc = lstcon_nodes_stat(args->lstio_sta_count,
705 args->lstio_sta_idsp,
706 args->lstio_sta_timeout,
707 args->lstio_sta_resultp);
710 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
715 int lst_test_add_ioctl(lstio_test_args_t *args)
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)
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)))
743 LIBCFS_ALLOC(name, args->lstio_tes_bat_nmlen + 1);
747 LIBCFS_ALLOC(srcgrp, args->lstio_tes_sgrp_nmlen + 1);
751 LIBCFS_ALLOC(dstgrp, args->lstio_tes_dgrp_nmlen + 1);
755 if (args->lstio_tes_param != NULL) {
756 LIBCFS_ALLOC(param, args->lstio_tes_param_len);
762 if (cfs_copy_from_user(name,
763 args->lstio_tes_bat_name,
764 args->lstio_tes_bat_nmlen) ||
765 cfs_copy_from_user(srcgrp,
766 args->lstio_tes_sgrp_name,
767 args->lstio_tes_sgrp_nmlen) ||
768 cfs_copy_from_user(dstgrp,
769 args->lstio_tes_dgrp_name,
770 args->lstio_tes_dgrp_nmlen) ||
771 cfs_copy_from_user(param, args->lstio_tes_param,
772 args->lstio_tes_param_len))
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);
784 rc = (cfs_copy_to_user(args->lstio_tes_retp, &ret,
785 sizeof(ret))) ? -EFAULT : 0;
788 LIBCFS_FREE(name, args->lstio_tes_bat_nmlen + 1);
791 LIBCFS_FREE(srcgrp, args->lstio_tes_sgrp_nmlen + 1);
794 LIBCFS_FREE(dstgrp, args->lstio_tes_dgrp_nmlen + 1);
797 LIBCFS_FREE(param, args->lstio_tes_param_len);
803 lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
806 int opc = data->ioc_u32[0];
809 if (cmd != IOC_LIBCFS_LNETST)
812 if (data->ioc_plen1 > CFS_PAGE_SIZE)
815 LIBCFS_ALLOC(buf, data->ioc_plen1);
819 /* copy in parameter */
820 if (cfs_copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) {
821 LIBCFS_FREE(buf, data->ioc_plen1);
825 cfs_mutex_lock(&console_session.ses_mutex);
827 console_session.ses_laststamp = cfs_time_current_sec();
829 if (console_session.ses_shutdown) {
834 if (console_session.ses_expired)
835 lstcon_session_end();
837 if (opc != LSTIO_SESSION_NEW &&
838 console_session.ses_state == LST_SESSION_NONE) {
839 CDEBUG(D_NET, "LST no active session\n");
844 memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t));
847 case LSTIO_SESSION_NEW:
848 rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf);
850 case LSTIO_SESSION_END:
851 rc = lst_session_end_ioctl((lstio_session_end_args_t *)buf);
853 case LSTIO_SESSION_INFO:
854 rc = lst_session_info_ioctl((lstio_session_info_args_t *)buf);
857 rc = lst_debug_ioctl((lstio_debug_args_t *)buf);
859 case LSTIO_GROUP_ADD:
860 rc = lst_group_add_ioctl((lstio_group_add_args_t *)buf);
862 case LSTIO_GROUP_DEL:
863 rc = lst_group_del_ioctl((lstio_group_del_args_t *)buf);
865 case LSTIO_GROUP_UPDATE:
866 rc = lst_group_update_ioctl((lstio_group_update_args_t *)buf);
868 case LSTIO_NODES_ADD:
869 rc = lst_nodes_add_ioctl((lstio_group_nodes_args_t *)buf);
871 case LSTIO_GROUP_LIST:
872 rc = lst_group_list_ioctl((lstio_group_list_args_t *)buf);
874 case LSTIO_GROUP_INFO:
875 rc = lst_group_info_ioctl((lstio_group_info_args_t *)buf);
877 case LSTIO_BATCH_ADD:
878 rc = lst_batch_add_ioctl((lstio_batch_add_args_t *)buf);
880 case LSTIO_BATCH_START:
881 rc = lst_batch_run_ioctl((lstio_batch_run_args_t *)buf);
883 case LSTIO_BATCH_STOP:
884 rc = lst_batch_stop_ioctl((lstio_batch_stop_args_t *)buf);
886 case LSTIO_BATCH_QUERY:
887 rc = lst_batch_query_ioctl((lstio_batch_query_args_t *)buf);
889 case LSTIO_BATCH_LIST:
890 rc = lst_batch_list_ioctl((lstio_batch_list_args_t *)buf);
892 case LSTIO_BATCH_INFO:
893 rc = lst_batch_info_ioctl((lstio_batch_info_args_t *)buf);
896 rc = lst_test_add_ioctl((lstio_test_args_t *)buf);
898 case LSTIO_STAT_QUERY:
899 rc = lst_stat_query_ioctl((lstio_stat_args_t *)buf);
905 if (cfs_copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat,
906 sizeof(lstcon_trans_stat_t)))
909 cfs_mutex_unlock(&console_session.ses_mutex);
911 LIBCFS_FREE(buf, data->ioc_plen1);
916 EXPORT_SYMBOL(lstcon_ioctl_entry);