1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Author: Liang Zhen <liangzhen@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org
12 #include <libcfs/libcfs.h>
13 #include <lnet/lib-lnet.h>
14 #include <lnet/lnetst.h>
18 lst_session_new_ioctl(lstio_session_new_args_t *args)
23 if (args->lstio_ses_idp == NULL || /* address for output sid */
24 args->lstio_ses_key == 0 || /* no key is specified */
25 args->lstio_ses_namep == NULL || /* session name */
26 args->lstio_ses_nmlen <= 0 ||
27 args->lstio_ses_nmlen > LST_NAME_SIZE)
30 LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1);
34 if (copy_from_user(name,
35 args->lstio_ses_namep,
36 args->lstio_ses_nmlen)) {
37 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
41 name[args->lstio_ses_nmlen] = 0;
43 rc = lstcon_session_new(name,
45 args->lstio_ses_timeout,
46 args->lstio_ses_force,
49 LIBCFS_FREE(name, args->lstio_ses_nmlen + 1);
55 lst_session_end_ioctl(lstio_session_end_args_t *args)
57 if (args->lstio_ses_key != console_session.ses_key)
60 return lstcon_session_end();
64 lst_session_info_ioctl(lstio_session_info_args_t *args)
66 /* no checking of key */
68 if (args->lstio_ses_idp == NULL || /* address for ouput sid */
69 args->lstio_ses_keyp == NULL || /* address for ouput key */
70 args->lstio_ses_ndinfo == NULL || /* address for output ndinfo */
71 args->lstio_ses_namep == NULL || /* address for ouput name */
72 args->lstio_ses_nmlen <= 0 ||
73 args->lstio_ses_nmlen > LST_NAME_SIZE)
76 return lstcon_session_info(args->lstio_ses_idp,
78 args->lstio_ses_ndinfo,
79 args->lstio_ses_namep,
80 args->lstio_ses_nmlen);
84 lst_debug_ioctl(lstio_debug_args_t *args)
90 if (args->lstio_dbg_key != console_session.ses_key)
93 if (args->lstio_dbg_resultp == NULL)
96 if (args->lstio_dbg_namep != NULL && /* name of batch/group */
97 (args->lstio_dbg_nmlen <= 0 ||
98 args->lstio_dbg_nmlen > LST_NAME_SIZE))
101 if (args->lstio_dbg_namep != NULL) {
102 LIBCFS_ALLOC(name, args->lstio_dbg_nmlen + 1);
106 if (copy_from_user(name, args->lstio_dbg_namep,
107 args->lstio_dbg_nmlen)) {
108 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
113 name[args->lstio_dbg_nmlen] = 0;
118 switch (args->lstio_dbg_type) {
119 case LST_OPC_SESSION:
120 rc = lstcon_session_debug(args->lstio_dbg_timeout,
121 args->lstio_dbg_resultp);
124 case LST_OPC_BATCHSRV:
126 case LST_OPC_BATCHCLI:
130 rc = lstcon_batch_debug(args->lstio_dbg_timeout,
131 name, client, args->lstio_dbg_resultp);
138 rc = lstcon_group_debug(args->lstio_dbg_timeout,
139 name, args->lstio_dbg_resultp);
143 if (args->lstio_dbg_count <= 0 ||
144 args->lstio_dbg_idsp == NULL)
147 rc = lstcon_nodes_debug(args->lstio_dbg_timeout,
148 args->lstio_dbg_count,
149 args->lstio_dbg_idsp,
150 args->lstio_dbg_resultp);
159 LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1);
165 lst_group_add_ioctl(lstio_group_add_args_t *args)
170 if (args->lstio_grp_key != console_session.ses_key)
173 if (args->lstio_grp_namep == NULL||
174 args->lstio_grp_nmlen <= 0 ||
175 args->lstio_grp_nmlen > LST_NAME_SIZE)
178 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
182 if (copy_from_user(name,
183 args->lstio_grp_namep,
184 args->lstio_grp_nmlen)) {
185 LIBCFS_FREE(name, args->lstio_grp_nmlen);
189 name[args->lstio_grp_nmlen] = 0;
191 rc = lstcon_group_add(name);
193 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
199 lst_group_del_ioctl(lstio_group_del_args_t *args)
204 if (args->lstio_grp_key != console_session.ses_key)
207 if (args->lstio_grp_namep == NULL ||
208 args->lstio_grp_nmlen <= 0 ||
209 args->lstio_grp_nmlen > LST_NAME_SIZE)
212 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
216 if (copy_from_user(name,
217 args->lstio_grp_namep,
218 args->lstio_grp_nmlen)) {
219 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
223 name[args->lstio_grp_nmlen] = 0;
225 rc = lstcon_group_del(name);
227 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
233 lst_group_update_ioctl(lstio_group_update_args_t *args)
238 if (args->lstio_grp_key != console_session.ses_key)
241 if (args->lstio_grp_resultp == NULL ||
242 args->lstio_grp_namep == NULL ||
243 args->lstio_grp_nmlen <= 0 ||
244 args->lstio_grp_nmlen > LST_NAME_SIZE)
247 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
251 if (copy_from_user(name,
252 args->lstio_grp_namep,
253 args->lstio_grp_nmlen)) {
254 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
258 name[args->lstio_grp_nmlen] = 0;
260 switch (args->lstio_grp_opc) {
261 case LST_GROUP_CLEAN:
262 rc = lstcon_group_clean(name, args->lstio_grp_args);
265 case LST_GROUP_REFRESH:
266 rc = lstcon_group_refresh(name, args->lstio_grp_resultp);
270 if (args->lstio_grp_count <= 0 ||
271 args->lstio_grp_idsp == NULL) {
275 rc = lstcon_nodes_remove(name, args->lstio_grp_count,
276 args->lstio_grp_idsp,
277 args->lstio_grp_resultp);
285 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
291 lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
296 if (args->lstio_grp_key != console_session.ses_key)
299 if (args->lstio_grp_idsp == NULL || /* array of ids */
300 args->lstio_grp_count <= 0 ||
301 args->lstio_grp_resultp == NULL ||
302 args->lstio_grp_namep == NULL ||
303 args->lstio_grp_nmlen <= 0 ||
304 args->lstio_grp_nmlen > LST_NAME_SIZE)
307 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
311 if (copy_from_user(name, args->lstio_grp_namep,
312 args->lstio_grp_nmlen)) {
313 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
318 name[args->lstio_grp_nmlen] = 0;
320 rc = lstcon_nodes_add(name, args->lstio_grp_count,
321 args->lstio_grp_idsp,
322 args->lstio_grp_resultp);
324 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
330 lst_group_list_ioctl(lstio_group_list_args_t *args)
332 if (args->lstio_grp_key != console_session.ses_key)
335 if (args->lstio_grp_idx < 0 ||
336 args->lstio_grp_namep == NULL ||
337 args->lstio_grp_nmlen <= 0 ||
338 args->lstio_grp_nmlen > LST_NAME_SIZE)
341 return lstcon_group_list(args->lstio_grp_idx,
342 args->lstio_grp_nmlen,
343 args->lstio_grp_namep);
347 lst_group_info_ioctl(lstio_group_info_args_t *args)
354 if (args->lstio_grp_key != console_session.ses_key)
357 if (args->lstio_grp_namep == NULL ||
358 args->lstio_grp_nmlen <= 0 ||
359 args->lstio_grp_nmlen > LST_NAME_SIZE)
362 if (args->lstio_grp_entp == NULL && /* output: group entry */
363 args->lstio_grp_dentsp == NULL) /* output: node entry */
366 if (args->lstio_grp_dentsp != NULL) { /* have node entry */
367 if (args->lstio_grp_idxp == NULL || /* node index */
368 args->lstio_grp_ndentp == NULL) /* # of node entry */
371 if (copy_from_user(&ndent,
372 args->lstio_grp_ndentp, sizeof(ndent)) ||
373 copy_from_user(&index, args->lstio_grp_idxp, sizeof(index)))
376 if (ndent <= 0 || index < 0)
380 LIBCFS_ALLOC(name, args->lstio_grp_nmlen + 1);
384 if (copy_from_user(name,
385 args->lstio_grp_namep,
386 args->lstio_grp_nmlen)) {
387 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
391 name[args->lstio_grp_nmlen] = 0;
393 rc = lstcon_group_info(name, args->lstio_grp_entp,
394 &index, &ndent, args->lstio_grp_dentsp);
396 LIBCFS_FREE(name, args->lstio_grp_nmlen + 1);
401 if (args->lstio_grp_dentsp != NULL &&
402 (copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) ||
403 copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent))))
410 lst_batch_add_ioctl(lstio_batch_add_args_t *args)
415 if (args->lstio_bat_key != console_session.ses_key)
418 if (args->lstio_bat_namep == NULL ||
419 args->lstio_bat_nmlen <= 0 ||
420 args->lstio_bat_nmlen > LST_NAME_SIZE)
423 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
427 if (copy_from_user(name,
428 args->lstio_bat_namep,
429 args->lstio_bat_nmlen)) {
430 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
434 name[args->lstio_bat_nmlen] = 0;
436 rc = lstcon_batch_add(name);
438 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
444 lst_batch_run_ioctl(lstio_batch_run_args_t *args)
449 if (args->lstio_bat_key != console_session.ses_key)
452 if (args->lstio_bat_namep == NULL ||
453 args->lstio_bat_nmlen <= 0 ||
454 args->lstio_bat_nmlen > LST_NAME_SIZE)
457 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
461 if (copy_from_user(name,
462 args->lstio_bat_namep,
463 args->lstio_bat_nmlen)) {
464 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
468 name[args->lstio_bat_nmlen] = 0;
470 rc = lstcon_batch_run(name, args->lstio_bat_timeout,
471 args->lstio_bat_resultp);
473 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
479 lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
484 if (args->lstio_bat_key != console_session.ses_key)
487 if (args->lstio_bat_resultp == NULL ||
488 args->lstio_bat_namep == NULL ||
489 args->lstio_bat_nmlen <= 0 ||
490 args->lstio_bat_nmlen > LST_NAME_SIZE)
493 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
497 if (copy_from_user(name,
498 args->lstio_bat_namep,
499 args->lstio_bat_nmlen)) {
500 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
504 name[args->lstio_bat_nmlen] = 0;
506 rc = lstcon_batch_stop(name, args->lstio_bat_force,
507 args->lstio_bat_resultp);
509 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
515 lst_batch_query_ioctl(lstio_batch_query_args_t *args)
520 if (args->lstio_bat_key != console_session.ses_key)
523 if (args->lstio_bat_resultp == NULL ||
524 args->lstio_bat_namep == NULL ||
525 args->lstio_bat_nmlen <= 0 ||
526 args->lstio_bat_nmlen > LST_NAME_SIZE)
529 if (args->lstio_bat_testidx < 0)
532 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
536 if (copy_from_user(name,
537 args->lstio_bat_namep,
538 args->lstio_bat_nmlen)) {
539 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
543 name[args->lstio_bat_nmlen] = 0;
545 rc = lstcon_test_batch_query(name,
546 args->lstio_bat_testidx,
547 args->lstio_bat_client,
548 args->lstio_bat_timeout,
549 args->lstio_bat_resultp);
551 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
557 lst_batch_list_ioctl(lstio_batch_list_args_t *args)
559 if (args->lstio_bat_key != console_session.ses_key)
562 if (args->lstio_bat_idx < 0 ||
563 args->lstio_bat_namep == NULL ||
564 args->lstio_bat_nmlen <= 0 ||
565 args->lstio_bat_nmlen > LST_NAME_SIZE)
568 return lstcon_batch_list(args->lstio_bat_idx,
569 args->lstio_bat_nmlen,
570 args->lstio_bat_namep);
574 lst_batch_info_ioctl(lstio_batch_info_args_t *args)
581 if (args->lstio_bat_key != console_session.ses_key)
584 if (args->lstio_bat_namep == NULL || /* batch name */
585 args->lstio_bat_nmlen <= 0 ||
586 args->lstio_bat_nmlen > LST_NAME_SIZE)
589 if (args->lstio_bat_entp == NULL && /* output: batch entry */
590 args->lstio_bat_dentsp == NULL) /* output: node entry */
593 if (args->lstio_bat_dentsp != NULL) { /* have node entry */
594 if (args->lstio_bat_idxp == NULL || /* node index */
595 args->lstio_bat_ndentp == NULL) /* # of node entry */
598 if (copy_from_user(&index, args->lstio_bat_idxp, sizeof(index)) ||
599 copy_from_user(&ndent, args->lstio_bat_ndentp, sizeof(ndent)))
602 if (ndent <= 0 || index < 0)
606 LIBCFS_ALLOC(name, args->lstio_bat_nmlen + 1);
610 if (copy_from_user(name,
611 args->lstio_bat_namep, args->lstio_bat_nmlen)) {
612 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
616 name[args->lstio_bat_nmlen] = 0;
618 rc = lstcon_batch_info(name,
619 args->lstio_bat_entp, args->lstio_bat_server,
620 args->lstio_bat_testidx, &index, &ndent,
621 args->lstio_bat_dentsp);
623 LIBCFS_FREE(name, args->lstio_bat_nmlen + 1);
628 if (args->lstio_bat_dentsp != NULL &&
629 (copy_to_user(args->lstio_bat_idxp, &index, sizeof(index)) ||
630 copy_to_user(args->lstio_bat_ndentp, &ndent, sizeof(ndent))))
637 lst_stat_query_ioctl(lstio_stat_args_t *args)
642 /* TODO: not finished */
643 if (args->lstio_sta_key != console_session.ses_key)
646 if (args->lstio_sta_resultp == NULL ||
647 (args->lstio_sta_namep == NULL &&
648 args->lstio_sta_idsp == NULL) ||
649 args->lstio_sta_nmlen <= 0 ||
650 args->lstio_sta_nmlen > LST_NAME_SIZE)
653 if (args->lstio_sta_idsp != NULL &&
654 args->lstio_sta_count <= 0)
657 LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
661 if (copy_from_user(name, args->lstio_sta_namep,
662 args->lstio_sta_nmlen)) {
663 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
667 if (args->lstio_sta_idsp == NULL) {
668 rc = lstcon_group_stat(name, args->lstio_sta_timeout,
669 args->lstio_sta_resultp);
671 rc = lstcon_nodes_stat(args->lstio_sta_count,
672 args->lstio_sta_idsp,
673 args->lstio_sta_timeout,
674 args->lstio_sta_resultp);
677 LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
682 int lst_test_add_ioctl(lstio_test_args_t *args)
691 if (args->lstio_tes_resultp == NULL ||
692 args->lstio_tes_retp == NULL ||
693 args->lstio_tes_bat_name == NULL || /* no specified batch */
694 args->lstio_tes_bat_nmlen <= 0 ||
695 args->lstio_tes_bat_nmlen > LST_NAME_SIZE ||
696 args->lstio_tes_sgrp_name == NULL || /* no source group */
697 args->lstio_tes_sgrp_nmlen <= 0 ||
698 args->lstio_tes_sgrp_nmlen > LST_NAME_SIZE ||
699 args->lstio_tes_dgrp_name == NULL || /* no target group */
700 args->lstio_tes_dgrp_nmlen <= 0 ||
701 args->lstio_tes_dgrp_nmlen > LST_NAME_SIZE)
704 /* have parameter, check if parameter length is valid */
705 if (args->lstio_tes_param != NULL &&
706 (args->lstio_tes_param_len <= 0 ||
707 args->lstio_tes_param_len > CFS_PAGE_SIZE - sizeof(lstcon_test_t)))
710 LIBCFS_ALLOC(name, args->lstio_tes_bat_nmlen + 1);
714 LIBCFS_ALLOC(srcgrp, args->lstio_tes_sgrp_nmlen + 1);
718 LIBCFS_ALLOC(dstgrp, args->lstio_tes_dgrp_nmlen + 1);
722 if (args->lstio_tes_param != NULL) {
723 LIBCFS_ALLOC(param, args->lstio_tes_param_len);
729 if (copy_from_user(name,
730 args->lstio_tes_bat_name,
731 args->lstio_tes_bat_nmlen) ||
732 copy_from_user(srcgrp,
733 args->lstio_tes_sgrp_name,
734 args->lstio_tes_sgrp_nmlen) ||
735 copy_from_user(dstgrp,
736 args->lstio_tes_dgrp_name,
737 args->lstio_tes_dgrp_nmlen) ||
738 copy_from_user(param, args->lstio_tes_param,
739 args->lstio_tes_param_len))
742 rc = lstcon_test_add(name,
743 args->lstio_tes_type,
744 args->lstio_tes_loop,
745 args->lstio_tes_concur,
746 args->lstio_tes_dist, args->lstio_tes_span,
747 srcgrp, dstgrp, param, args->lstio_tes_param_len,
748 &ret, args->lstio_tes_resultp);
751 rc = (copy_to_user(args->lstio_tes_retp, &ret, sizeof(ret))) ?
755 LIBCFS_FREE(name, args->lstio_tes_bat_nmlen + 1);
758 LIBCFS_FREE(srcgrp, args->lstio_tes_sgrp_nmlen + 1);
761 LIBCFS_FREE(dstgrp, args->lstio_tes_dgrp_nmlen + 1);
764 LIBCFS_FREE(param, args->lstio_tes_param_len);
770 lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
773 int opc = data->ioc_u32[0];
776 if (cmd != IOC_LIBCFS_LNETST)
779 if (data->ioc_plen1 > CFS_PAGE_SIZE)
782 LIBCFS_ALLOC(buf, data->ioc_plen1);
786 /* copy in parameter */
787 if (copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) {
788 LIBCFS_FREE(buf, data->ioc_plen1);
792 mutex_down(&console_session.ses_mutex);
794 console_session.ses_laststamp = cfs_time_current_sec();
796 if (console_session.ses_shutdown) {
801 if (console_session.ses_expired)
802 lstcon_session_end();
804 if (opc != LSTIO_SESSION_NEW &&
805 console_session.ses_state == LST_SESSION_NONE) {
806 CDEBUG(D_NET, "LST no active session\n");
811 memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t));
814 case LSTIO_SESSION_NEW:
815 rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf);
817 case LSTIO_SESSION_END:
818 rc = lst_session_end_ioctl((lstio_session_end_args_t *)buf);
820 case LSTIO_SESSION_INFO:
821 rc = lst_session_info_ioctl((lstio_session_info_args_t *)buf);
824 rc = lst_debug_ioctl((lstio_debug_args_t *)buf);
826 case LSTIO_GROUP_ADD:
827 rc = lst_group_add_ioctl((lstio_group_add_args_t *)buf);
829 case LSTIO_GROUP_DEL:
830 rc = lst_group_del_ioctl((lstio_group_del_args_t *)buf);
832 case LSTIO_GROUP_UPDATE:
833 rc = lst_group_update_ioctl((lstio_group_update_args_t *)buf);
835 case LSTIO_NODES_ADD:
836 rc = lst_nodes_add_ioctl((lstio_group_nodes_args_t *)buf);
838 case LSTIO_GROUP_LIST:
839 rc = lst_group_list_ioctl((lstio_group_list_args_t *)buf);
841 case LSTIO_GROUP_INFO:
842 rc = lst_group_info_ioctl((lstio_group_info_args_t *)buf);
844 case LSTIO_BATCH_ADD:
845 rc = lst_batch_add_ioctl((lstio_batch_add_args_t *)buf);
847 case LSTIO_BATCH_START:
848 rc = lst_batch_run_ioctl((lstio_batch_run_args_t *)buf);
850 case LSTIO_BATCH_STOP:
851 rc = lst_batch_stop_ioctl((lstio_batch_stop_args_t *)buf);
853 case LSTIO_BATCH_QUERY:
854 rc = lst_batch_query_ioctl((lstio_batch_query_args_t *)buf);
856 case LSTIO_BATCH_LIST:
857 rc = lst_batch_list_ioctl((lstio_batch_list_args_t *)buf);
859 case LSTIO_BATCH_INFO:
860 rc = lst_batch_info_ioctl((lstio_batch_info_args_t *)buf);
863 rc = lst_test_add_ioctl((lstio_test_args_t *)buf);
865 case LSTIO_STAT_QUERY:
866 rc = lst_stat_query_ioctl((lstio_stat_args_t *)buf);
872 if (copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat,
873 sizeof(lstcon_trans_stat_t)))
876 mutex_up(&console_session.ses_mutex);
878 LIBCFS_FREE(buf, data->ioc_plen1);
883 EXPORT_SYMBOL(lstcon_ioctl_entry);