1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * IOC handle in kernel
40 * Author: Liang Zhen <liangzhen@clusterfs.com>
44 #include <libcfs/libcfs.h>
45 #include <lnet/lib-lnet.h>
46 #include <lnet/lnetst.h>
50 lst_session_new_ioctl(lstio_session_new_args_t *args)
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)
62 LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1);
66 if (copy_from_user(name,
67 args->lstio_ses_namep,
68 args->lstio_ses_nmlen)) {
69 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
73 name[args->lstio_ses_nmlen] = 0;
75 rc = lstcon_session_new(name,
77 args->lstio_ses_timeout,
78 args->lstio_ses_force,
81 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
87 lst_session_end_ioctl(lstio_session_end_args_t *args)
89 if (args->lstio_ses_key != console_session.ses_key)
92 return lstcon_session_end();
96 lst_session_info_ioctl(lstio_session_info_args_t *args)
98 /* no checking of key */
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)
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);
116 lst_debug_ioctl(lstio_debug_args_t *args)
122 if (args->lstio_dbg_key != console_session.ses_key)
125 if (args->lstio_dbg_resultp == NULL)
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))
133 if (args->lstio_dbg_namep != NULL) {
134 LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1);
138 if (copy_from_user(name, args->lstio_dbg_namep,
139 args->lstio_dbg_nmlen)) {
140 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
145 name[args->lstio_dbg_nmlen] = 0;
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);
156 case LST_OPC_BATCHSRV:
158 case LST_OPC_BATCHCLI:
162 rc = lstcon_batch_debug(args->lstio_dbg_timeout,
163 name, client, args->lstio_dbg_resultp);
170 rc = lstcon_group_debug(args->lstio_dbg_timeout,
171 name, args->lstio_dbg_resultp);
175 if (args->lstio_dbg_count <= 0 ||
176 args->lstio_dbg_idsp == NULL)
179 rc = lstcon_nodes_debug(args->lstio_dbg_timeout,
180 args->lstio_dbg_count,
181 args->lstio_dbg_idsp,
182 args->lstio_dbg_resultp);
191 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
197 lst_group_add_ioctl(lstio_group_add_args_t *args)
202 if (args->lstio_grp_key != console_session.ses_key)
205 if (args->lstio_grp_namep == NULL||
206 args->lstio_grp_nmlen <= 0 ||
207 args->lstio_grp_nmlen > LST_NAME_SIZE)
210 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
214 if (copy_from_user(name,
215 args->lstio_grp_namep,
216 args->lstio_grp_nmlen)) {
217 LIBCFS_FREE(name, args->lstio_grp_nmlen);
221 name[args->lstio_grp_nmlen] = 0;
223 rc = lstcon_group_add(name);
225 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
231 lst_group_del_ioctl(lstio_group_del_args_t *args)
236 if (args->lstio_grp_key != console_session.ses_key)
239 if (args->lstio_grp_namep == NULL ||
240 args->lstio_grp_nmlen <= 0 ||
241 args->lstio_grp_nmlen > LST_NAME_SIZE)
244 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
248 if (copy_from_user(name,
249 args->lstio_grp_namep,
250 args->lstio_grp_nmlen)) {
251 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
255 name[args->lstio_grp_nmlen] = 0;
257 rc = lstcon_group_del(name);
259 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
265 lst_group_update_ioctl(lstio_group_update_args_t *args)
270 if (args->lstio_grp_key != console_session.ses_key)
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)
279 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
283 if (copy_from_user(name,
284 args->lstio_grp_namep,
285 args->lstio_grp_nmlen)) {
286 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
290 name[args->lstio_grp_nmlen] = 0;
292 switch (args->lstio_grp_opc) {
293 case LST_GROUP_CLEAN:
294 rc = lstcon_group_clean(name, args->lstio_grp_args);
297 case LST_GROUP_REFRESH:
298 rc = lstcon_group_refresh(name, args->lstio_grp_resultp);
302 if (args->lstio_grp_count <= 0 ||
303 args->lstio_grp_idsp == NULL) {
307 rc = lstcon_nodes_remove(name, args->lstio_grp_count,
308 args->lstio_grp_idsp,
309 args->lstio_grp_resultp);
317 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
323 lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
328 if (args->lstio_grp_key != console_session.ses_key)
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)
339 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
343 if (copy_from_user(name, args->lstio_grp_namep,
344 args->lstio_grp_nmlen)) {
345 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
350 name[args->lstio_grp_nmlen] = 0;
352 rc = lstcon_nodes_add(name, args->lstio_grp_count,
353 args->lstio_grp_idsp,
354 args->lstio_grp_resultp);
356 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
362 lst_group_list_ioctl(lstio_group_list_args_t *args)
364 if (args->lstio_grp_key != console_session.ses_key)
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)
373 return lstcon_group_list(args->lstio_grp_idx,
374 args->lstio_grp_nmlen,
375 args->lstio_grp_namep);
379 lst_group_info_ioctl(lstio_group_info_args_t *args)
386 if (args->lstio_grp_key != console_session.ses_key)
389 if (args->lstio_grp_namep == NULL ||
390 args->lstio_grp_nmlen <= 0 ||
391 args->lstio_grp_nmlen > LST_NAME_SIZE)
394 if (args->lstio_grp_entp == NULL && /* output: group entry */
395 args->lstio_grp_dentsp == NULL) /* output: node entry */
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 */
403 if (copy_from_user(&ndent,
404 args->lstio_grp_ndentp, sizeof(ndent)) ||
405 copy_from_user(&index, args->lstio_grp_idxp, sizeof(index)))
408 if (ndent <= 0 || index < 0)
412 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
416 if (copy_from_user(name,
417 args->lstio_grp_namep,
418 args->lstio_grp_nmlen)) {
419 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
423 name[args->lstio_grp_nmlen] = 0;
425 rc = lstcon_group_info(name, args->lstio_grp_entp,
426 &index, &ndent, args->lstio_grp_dentsp);
428 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
433 if (args->lstio_grp_dentsp != NULL &&
434 (copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) ||
435 copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent))))
442 lst_batch_add_ioctl(lstio_batch_add_args_t *args)
447 if (args->lstio_bat_key != console_session.ses_key)
450 if (args->lstio_bat_namep == NULL ||
451 args->lstio_bat_nmlen <= 0 ||
452 args->lstio_bat_nmlen > LST_NAME_SIZE)
455 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
459 if (copy_from_user(name,
460 args->lstio_bat_namep,
461 args->lstio_bat_nmlen)) {
462 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
466 name[args->lstio_bat_nmlen] = 0;
468 rc = lstcon_batch_add(name);
470 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
476 lst_batch_run_ioctl(lstio_batch_run_args_t *args)
481 if (args->lstio_bat_key != console_session.ses_key)
484 if (args->lstio_bat_namep == NULL ||
485 args->lstio_bat_nmlen <= 0 ||
486 args->lstio_bat_nmlen > LST_NAME_SIZE)
489 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
493 if (copy_from_user(name,
494 args->lstio_bat_namep,
495 args->lstio_bat_nmlen)) {
496 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
500 name[args->lstio_bat_nmlen] = 0;
502 rc = lstcon_batch_run(name, args->lstio_bat_timeout,
503 args->lstio_bat_resultp);
505 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
511 lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
516 if (args->lstio_bat_key != console_session.ses_key)
519 if (args->lstio_bat_resultp == NULL ||
520 args->lstio_bat_namep == NULL ||
521 args->lstio_bat_nmlen <= 0 ||
522 args->lstio_bat_nmlen > LST_NAME_SIZE)
525 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
529 if (copy_from_user(name,
530 args->lstio_bat_namep,
531 args->lstio_bat_nmlen)) {
532 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
536 name[args->lstio_bat_nmlen] = 0;
538 rc = lstcon_batch_stop(name, args->lstio_bat_force,
539 args->lstio_bat_resultp);
541 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
547 lst_batch_query_ioctl(lstio_batch_query_args_t *args)
552 if (args->lstio_bat_key != console_session.ses_key)
555 if (args->lstio_bat_resultp == NULL ||
556 args->lstio_bat_namep == NULL ||
557 args->lstio_bat_nmlen <= 0 ||
558 args->lstio_bat_nmlen > LST_NAME_SIZE)
561 if (args->lstio_bat_testidx < 0)
564 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
568 if (copy_from_user(name,
569 args->lstio_bat_namep,
570 args->lstio_bat_nmlen)) {
571 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
575 name[args->lstio_bat_nmlen] = 0;
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);
583 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
589 lst_batch_list_ioctl(lstio_batch_list_args_t *args)
591 if (args->lstio_bat_key != console_session.ses_key)
594 if (args->lstio_bat_idx < 0 ||
595 args->lstio_bat_namep == NULL ||
596 args->lstio_bat_nmlen <= 0 ||
597 args->lstio_bat_nmlen > LST_NAME_SIZE)
600 return lstcon_batch_list(args->lstio_bat_idx,
601 args->lstio_bat_nmlen,
602 args->lstio_bat_namep);
606 lst_batch_info_ioctl(lstio_batch_info_args_t *args)
613 if (args->lstio_bat_key != console_session.ses_key)
616 if (args->lstio_bat_namep == NULL || /* batch name */
617 args->lstio_bat_nmlen <= 0 ||
618 args->lstio_bat_nmlen > LST_NAME_SIZE)
621 if (args->lstio_bat_entp == NULL && /* output: batch entry */
622 args->lstio_bat_dentsp == NULL) /* output: node entry */
625 if (args->lstio_bat_dentsp != NULL) { /* have node entry */
626 if (args->lstio_bat_idxp == NULL || /* node index */
627 args->lstio_bat_ndentp == NULL) /* # of node entry */
630 if (copy_from_user(&index, args->lstio_bat_idxp, sizeof(index)) ||
631 copy_from_user(&ndent, args->lstio_bat_ndentp, sizeof(ndent)))
634 if (ndent <= 0 || index < 0)
638 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
642 if (copy_from_user(name,
643 args->lstio_bat_namep, args->lstio_bat_nmlen)) {
644 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
648 name[args->lstio_bat_nmlen] = 0;
650 rc = lstcon_batch_info(name,
651 args->lstio_bat_entp, args->lstio_bat_server,
652 args->lstio_bat_testidx, &index, &ndent,
653 args->lstio_bat_dentsp);
655 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
660 if (args->lstio_bat_dentsp != NULL &&
661 (copy_to_user(args->lstio_bat_idxp, &index, sizeof(index)) ||
662 copy_to_user(args->lstio_bat_ndentp, &ndent, sizeof(ndent))))
669 lst_stat_query_ioctl(lstio_stat_args_t *args)
674 /* TODO: not finished */
675 if (args->lstio_sta_key != console_session.ses_key)
678 if (args->lstio_sta_resultp == NULL ||
679 (args->lstio_sta_namep == NULL &&
680 args->lstio_sta_idsp == NULL) ||
681 args->lstio_sta_nmlen <= 0 ||
682 args->lstio_sta_nmlen > LST_NAME_SIZE)
685 if (args->lstio_sta_idsp != NULL &&
686 args->lstio_sta_count <= 0)
689 LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
693 if (copy_from_user(name, args->lstio_sta_namep,
694 args->lstio_sta_nmlen)) {
695 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
699 if (args->lstio_sta_idsp == NULL) {
700 rc = lstcon_group_stat(name, args->lstio_sta_timeout,
701 args->lstio_sta_resultp);
703 rc = lstcon_nodes_stat(args->lstio_sta_count,
704 args->lstio_sta_idsp,
705 args->lstio_sta_timeout,
706 args->lstio_sta_resultp);
709 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
714 int lst_test_add_ioctl(lstio_test_args_t *args)
723 if (args->lstio_tes_resultp == NULL ||
724 args->lstio_tes_retp == NULL ||
725 args->lstio_tes_bat_name == NULL || /* no specified batch */
726 args->lstio_tes_bat_nmlen <= 0 ||
727 args->lstio_tes_bat_nmlen > LST_NAME_SIZE ||
728 args->lstio_tes_sgrp_name == NULL || /* no source group */
729 args->lstio_tes_sgrp_nmlen <= 0 ||
730 args->lstio_tes_sgrp_nmlen > LST_NAME_SIZE ||
731 args->lstio_tes_dgrp_name == NULL || /* no target group */
732 args->lstio_tes_dgrp_nmlen <= 0 ||
733 args->lstio_tes_dgrp_nmlen > LST_NAME_SIZE)
736 /* have parameter, check if parameter length is valid */
737 if (args->lstio_tes_param != NULL &&
738 (args->lstio_tes_param_len <= 0 ||
739 args->lstio_tes_param_len > CFS_PAGE_SIZE - sizeof(lstcon_test_t)))
742 LIBCFS_ALLOC(name, args->lstio_tes_bat_nmlen + 1);
746 LIBCFS_ALLOC(srcgrp, args->lstio_tes_sgrp_nmlen + 1);
750 LIBCFS_ALLOC(dstgrp, args->lstio_tes_dgrp_nmlen + 1);
754 if (args->lstio_tes_param != NULL) {
755 LIBCFS_ALLOC(param, args->lstio_tes_param_len);
761 if (copy_from_user(name,
762 args->lstio_tes_bat_name,
763 args->lstio_tes_bat_nmlen) ||
764 copy_from_user(srcgrp,
765 args->lstio_tes_sgrp_name,
766 args->lstio_tes_sgrp_nmlen) ||
767 copy_from_user(dstgrp,
768 args->lstio_tes_dgrp_name,
769 args->lstio_tes_dgrp_nmlen) ||
770 copy_from_user(param, args->lstio_tes_param,
771 args->lstio_tes_param_len))
774 rc = lstcon_test_add(name,
775 args->lstio_tes_type,
776 args->lstio_tes_loop,
777 args->lstio_tes_concur,
778 args->lstio_tes_dist, args->lstio_tes_span,
779 srcgrp, dstgrp, param, args->lstio_tes_param_len,
780 &ret, args->lstio_tes_resultp);
783 rc = (copy_to_user(args->lstio_tes_retp, &ret, sizeof(ret))) ?
787 LIBCFS_FREE(name, args->lstio_tes_bat_nmlen + 1);
790 LIBCFS_FREE(srcgrp, args->lstio_tes_sgrp_nmlen + 1);
793 LIBCFS_FREE(dstgrp, args->lstio_tes_dgrp_nmlen + 1);
796 LIBCFS_FREE(param, args->lstio_tes_param_len);
802 lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
805 int opc = data->ioc_u32[0];
808 if (cmd != IOC_LIBCFS_LNETST)
811 if (data->ioc_plen1 > CFS_PAGE_SIZE)
814 LIBCFS_ALLOC(buf, data->ioc_plen1);
818 /* copy in parameter */
819 if (copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) {
820 LIBCFS_FREE(buf, data->ioc_plen1);
824 mutex_down(&console_session.ses_mutex);
826 console_session.ses_laststamp = cfs_time_current_sec();
828 if (console_session.ses_shutdown) {
833 if (console_session.ses_expired)
834 lstcon_session_end();
836 if (opc != LSTIO_SESSION_NEW &&
837 console_session.ses_state == LST_SESSION_NONE) {
838 CDEBUG(D_NET, "LST no active session\n");
843 memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t));
846 case LSTIO_SESSION_NEW:
847 rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf);
849 case LSTIO_SESSION_END:
850 rc = lst_session_end_ioctl((lstio_session_end_args_t *)buf);
852 case LSTIO_SESSION_INFO:
853 rc = lst_session_info_ioctl((lstio_session_info_args_t *)buf);
856 rc = lst_debug_ioctl((lstio_debug_args_t *)buf);
858 case LSTIO_GROUP_ADD:
859 rc = lst_group_add_ioctl((lstio_group_add_args_t *)buf);
861 case LSTIO_GROUP_DEL:
862 rc = lst_group_del_ioctl((lstio_group_del_args_t *)buf);
864 case LSTIO_GROUP_UPDATE:
865 rc = lst_group_update_ioctl((lstio_group_update_args_t *)buf);
867 case LSTIO_NODES_ADD:
868 rc = lst_nodes_add_ioctl((lstio_group_nodes_args_t *)buf);
870 case LSTIO_GROUP_LIST:
871 rc = lst_group_list_ioctl((lstio_group_list_args_t *)buf);
873 case LSTIO_GROUP_INFO:
874 rc = lst_group_info_ioctl((lstio_group_info_args_t *)buf);
876 case LSTIO_BATCH_ADD:
877 rc = lst_batch_add_ioctl((lstio_batch_add_args_t *)buf);
879 case LSTIO_BATCH_START:
880 rc = lst_batch_run_ioctl((lstio_batch_run_args_t *)buf);
882 case LSTIO_BATCH_STOP:
883 rc = lst_batch_stop_ioctl((lstio_batch_stop_args_t *)buf);
885 case LSTIO_BATCH_QUERY:
886 rc = lst_batch_query_ioctl((lstio_batch_query_args_t *)buf);
888 case LSTIO_BATCH_LIST:
889 rc = lst_batch_list_ioctl((lstio_batch_list_args_t *)buf);
891 case LSTIO_BATCH_INFO:
892 rc = lst_batch_info_ioctl((lstio_batch_info_args_t *)buf);
895 rc = lst_test_add_ioctl((lstio_test_args_t *)buf);
897 case LSTIO_STAT_QUERY:
898 rc = lst_stat_query_ioctl((lstio_stat_args_t *)buf);
904 if (copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat,
905 sizeof(lstcon_trans_stat_t)))
908 mutex_up(&console_session.ses_mutex);
910 LIBCFS_FREE(buf, data->ioc_plen1);
915 EXPORT_SYMBOL(lstcon_ioctl_entry);