2 * -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
3 * vim:expandtab:shiftwidth=8:tabstop=8:
7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 only,
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License version 2 for more details (a copy is included
17 * in the LICENSE file that accompanied this code).
19 * You should have received a copy of the GNU General Public License
20 * version 2 along with this program; If not, see [sun.com URL with a
23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24 * CA 95054 USA or visit www.sun.com if you need additional information or
30 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
31 * Use is subject to license terms.
34 * This file is part of Lustre, http://www.lustre.org/
35 * Lustre is a trademark of Sun Microsystems, Inc.
37 * lnet/selftest/conctl.c
39 * IOC handle in kernel
41 * Author: Liang Zhen <liangzhen@clusterfs.com>
45 #include <libcfs/libcfs.h>
46 #include <lnet/lib-lnet.h>
47 #include <lnet/lnetst.h>
51 lst_session_new_ioctl(lstio_session_new_args_t *args)
56 if (args->lstio_ses_idp == NULL || /* address for output sid */
57 args->lstio_ses_key == 0 || /* no key is specified */
58 args->lstio_ses_namep == NULL || /* session name */
59 args->lstio_ses_nmlen <= 0 ||
60 args->lstio_ses_nmlen > LST_NAME_SIZE)
63 LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1);
67 if (copy_from_user(name,
68 args->lstio_ses_namep,
69 args->lstio_ses_nmlen)) {
70 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
74 name[args->lstio_ses_nmlen] = 0;
76 rc = lstcon_session_new(name,
78 args->lstio_ses_timeout,
79 args->lstio_ses_force,
82 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
88 lst_session_end_ioctl(lstio_session_end_args_t *args)
90 if (args->lstio_ses_key != console_session.ses_key)
93 return lstcon_session_end();
97 lst_session_info_ioctl(lstio_session_info_args_t *args)
99 /* no checking of key */
101 if (args->lstio_ses_idp == NULL || /* address for ouput sid */
102 args->lstio_ses_keyp == NULL || /* address for ouput key */
103 args->lstio_ses_ndinfo == NULL || /* address for output ndinfo */
104 args->lstio_ses_namep == NULL || /* address for ouput name */
105 args->lstio_ses_nmlen <= 0 ||
106 args->lstio_ses_nmlen > LST_NAME_SIZE)
109 return lstcon_session_info(args->lstio_ses_idp,
110 args->lstio_ses_keyp,
111 args->lstio_ses_ndinfo,
112 args->lstio_ses_namep,
113 args->lstio_ses_nmlen);
117 lst_debug_ioctl(lstio_debug_args_t *args)
123 if (args->lstio_dbg_key != console_session.ses_key)
126 if (args->lstio_dbg_resultp == NULL)
129 if (args->lstio_dbg_namep != NULL && /* name of batch/group */
130 (args->lstio_dbg_nmlen <= 0 ||
131 args->lstio_dbg_nmlen > LST_NAME_SIZE))
134 if (args->lstio_dbg_namep != NULL) {
135 LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1);
139 if (copy_from_user(name, args->lstio_dbg_namep,
140 args->lstio_dbg_nmlen)) {
141 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
146 name[args->lstio_dbg_nmlen] = 0;
151 switch (args->lstio_dbg_type) {
152 case LST_OPC_SESSION:
153 rc = lstcon_session_debug(args->lstio_dbg_timeout,
154 args->lstio_dbg_resultp);
157 case LST_OPC_BATCHSRV:
159 case LST_OPC_BATCHCLI:
163 rc = lstcon_batch_debug(args->lstio_dbg_timeout,
164 name, client, args->lstio_dbg_resultp);
171 rc = lstcon_group_debug(args->lstio_dbg_timeout,
172 name, args->lstio_dbg_resultp);
176 if (args->lstio_dbg_count <= 0 ||
177 args->lstio_dbg_idsp == NULL)
180 rc = lstcon_nodes_debug(args->lstio_dbg_timeout,
181 args->lstio_dbg_count,
182 args->lstio_dbg_idsp,
183 args->lstio_dbg_resultp);
192 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
198 lst_group_add_ioctl(lstio_group_add_args_t *args)
203 if (args->lstio_grp_key != console_session.ses_key)
206 if (args->lstio_grp_namep == NULL||
207 args->lstio_grp_nmlen <= 0 ||
208 args->lstio_grp_nmlen > LST_NAME_SIZE)
211 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
215 if (copy_from_user(name,
216 args->lstio_grp_namep,
217 args->lstio_grp_nmlen)) {
218 LIBCFS_FREE(name, args->lstio_grp_nmlen);
222 name[args->lstio_grp_nmlen] = 0;
224 rc = lstcon_group_add(name);
226 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
232 lst_group_del_ioctl(lstio_group_del_args_t *args)
237 if (args->lstio_grp_key != console_session.ses_key)
240 if (args->lstio_grp_namep == NULL ||
241 args->lstio_grp_nmlen <= 0 ||
242 args->lstio_grp_nmlen > LST_NAME_SIZE)
245 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
249 if (copy_from_user(name,
250 args->lstio_grp_namep,
251 args->lstio_grp_nmlen)) {
252 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
256 name[args->lstio_grp_nmlen] = 0;
258 rc = lstcon_group_del(name);
260 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
266 lst_group_update_ioctl(lstio_group_update_args_t *args)
271 if (args->lstio_grp_key != console_session.ses_key)
274 if (args->lstio_grp_resultp == NULL ||
275 args->lstio_grp_namep == NULL ||
276 args->lstio_grp_nmlen <= 0 ||
277 args->lstio_grp_nmlen > LST_NAME_SIZE)
280 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
284 if (copy_from_user(name,
285 args->lstio_grp_namep,
286 args->lstio_grp_nmlen)) {
287 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
291 name[args->lstio_grp_nmlen] = 0;
293 switch (args->lstio_grp_opc) {
294 case LST_GROUP_CLEAN:
295 rc = lstcon_group_clean(name, args->lstio_grp_args);
298 case LST_GROUP_REFRESH:
299 rc = lstcon_group_refresh(name, args->lstio_grp_resultp);
303 if (args->lstio_grp_count <= 0 ||
304 args->lstio_grp_idsp == NULL) {
308 rc = lstcon_nodes_remove(name, args->lstio_grp_count,
309 args->lstio_grp_idsp,
310 args->lstio_grp_resultp);
318 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
324 lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
329 if (args->lstio_grp_key != console_session.ses_key)
332 if (args->lstio_grp_idsp == NULL || /* array of ids */
333 args->lstio_grp_count <= 0 ||
334 args->lstio_grp_resultp == NULL ||
335 args->lstio_grp_namep == NULL ||
336 args->lstio_grp_nmlen <= 0 ||
337 args->lstio_grp_nmlen > LST_NAME_SIZE)
340 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
344 if (copy_from_user(name, args->lstio_grp_namep,
345 args->lstio_grp_nmlen)) {
346 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
351 name[args->lstio_grp_nmlen] = 0;
353 rc = lstcon_nodes_add(name, args->lstio_grp_count,
354 args->lstio_grp_idsp,
355 args->lstio_grp_resultp);
357 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
363 lst_group_list_ioctl(lstio_group_list_args_t *args)
365 if (args->lstio_grp_key != console_session.ses_key)
368 if (args->lstio_grp_idx < 0 ||
369 args->lstio_grp_namep == NULL ||
370 args->lstio_grp_nmlen <= 0 ||
371 args->lstio_grp_nmlen > LST_NAME_SIZE)
374 return lstcon_group_list(args->lstio_grp_idx,
375 args->lstio_grp_nmlen,
376 args->lstio_grp_namep);
380 lst_group_info_ioctl(lstio_group_info_args_t *args)
387 if (args->lstio_grp_key != console_session.ses_key)
390 if (args->lstio_grp_namep == NULL ||
391 args->lstio_grp_nmlen <= 0 ||
392 args->lstio_grp_nmlen > LST_NAME_SIZE)
395 if (args->lstio_grp_entp == NULL && /* output: group entry */
396 args->lstio_grp_dentsp == NULL) /* output: node entry */
399 if (args->lstio_grp_dentsp != NULL) { /* have node entry */
400 if (args->lstio_grp_idxp == NULL || /* node index */
401 args->lstio_grp_ndentp == NULL) /* # of node entry */
404 if (copy_from_user(&ndent,
405 args->lstio_grp_ndentp, sizeof(ndent)) ||
406 copy_from_user(&index, args->lstio_grp_idxp, sizeof(index)))
409 if (ndent <= 0 || index < 0)
413 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
417 if (copy_from_user(name,
418 args->lstio_grp_namep,
419 args->lstio_grp_nmlen)) {
420 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
424 name[args->lstio_grp_nmlen] = 0;
426 rc = lstcon_group_info(name, args->lstio_grp_entp,
427 &index, &ndent, args->lstio_grp_dentsp);
429 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
434 if (args->lstio_grp_dentsp != NULL &&
435 (copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) ||
436 copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent))))
443 lst_batch_add_ioctl(lstio_batch_add_args_t *args)
448 if (args->lstio_bat_key != console_session.ses_key)
451 if (args->lstio_bat_namep == NULL ||
452 args->lstio_bat_nmlen <= 0 ||
453 args->lstio_bat_nmlen > LST_NAME_SIZE)
456 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
460 if (copy_from_user(name,
461 args->lstio_bat_namep,
462 args->lstio_bat_nmlen)) {
463 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
467 name[args->lstio_bat_nmlen] = 0;
469 rc = lstcon_batch_add(name);
471 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
477 lst_batch_run_ioctl(lstio_batch_run_args_t *args)
482 if (args->lstio_bat_key != console_session.ses_key)
485 if (args->lstio_bat_namep == NULL ||
486 args->lstio_bat_nmlen <= 0 ||
487 args->lstio_bat_nmlen > LST_NAME_SIZE)
490 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
494 if (copy_from_user(name,
495 args->lstio_bat_namep,
496 args->lstio_bat_nmlen)) {
497 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
501 name[args->lstio_bat_nmlen] = 0;
503 rc = lstcon_batch_run(name, args->lstio_bat_timeout,
504 args->lstio_bat_resultp);
506 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
512 lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
517 if (args->lstio_bat_key != console_session.ses_key)
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)
526 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
530 if (copy_from_user(name,
531 args->lstio_bat_namep,
532 args->lstio_bat_nmlen)) {
533 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
537 name[args->lstio_bat_nmlen] = 0;
539 rc = lstcon_batch_stop(name, args->lstio_bat_force,
540 args->lstio_bat_resultp);
542 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
548 lst_batch_query_ioctl(lstio_batch_query_args_t *args)
553 if (args->lstio_bat_key != console_session.ses_key)
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)
562 if (args->lstio_bat_testidx < 0)
565 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
569 if (copy_from_user(name,
570 args->lstio_bat_namep,
571 args->lstio_bat_nmlen)) {
572 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
576 name[args->lstio_bat_nmlen] = 0;
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);
584 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
590 lst_batch_list_ioctl(lstio_batch_list_args_t *args)
592 if (args->lstio_bat_key != console_session.ses_key)
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)
601 return lstcon_batch_list(args->lstio_bat_idx,
602 args->lstio_bat_nmlen,
603 args->lstio_bat_namep);
607 lst_batch_info_ioctl(lstio_batch_info_args_t *args)
614 if (args->lstio_bat_key != console_session.ses_key)
617 if (args->lstio_bat_namep == NULL || /* batch name */
618 args->lstio_bat_nmlen <= 0 ||
619 args->lstio_bat_nmlen > LST_NAME_SIZE)
622 if (args->lstio_bat_entp == NULL && /* output: batch entry */
623 args->lstio_bat_dentsp == NULL) /* output: node entry */
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 */
631 if (copy_from_user(&index, args->lstio_bat_idxp, sizeof(index)) ||
632 copy_from_user(&ndent, args->lstio_bat_ndentp, sizeof(ndent)))
635 if (ndent <= 0 || index < 0)
639 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
643 if (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 (copy_to_user(args->lstio_bat_idxp, &index, sizeof(index)) ||
663 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 (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 (copy_from_user(name,
763 args->lstio_tes_bat_name,
764 args->lstio_tes_bat_nmlen) ||
765 copy_from_user(srcgrp,
766 args->lstio_tes_sgrp_name,
767 args->lstio_tes_sgrp_nmlen) ||
768 copy_from_user(dstgrp,
769 args->lstio_tes_dgrp_name,
770 args->lstio_tes_dgrp_nmlen) ||
771 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 = (copy_to_user(args->lstio_tes_retp, &ret, sizeof(ret))) ?
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 (copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) {
821 LIBCFS_FREE(buf, data->ioc_plen1);
825 mutex_down(&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 (copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat,
906 sizeof(lstcon_trans_stat_t)))
909 mutex_up(&console_session.ses_mutex);
911 LIBCFS_FREE(buf, data->ioc_plen1);
916 EXPORT_SYMBOL(lstcon_ioctl_entry);