X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Fselftest%2Fconctl.c;h=f9e4c0d02ddb198d74aefa4de4564d4b487a579b;hb=5a6aa0e6d1583cc0d4c82ae8c95fb7b9856d6284;hp=68297bd45a39bf4d5877b075468027caf47aa2e1;hpb=1b2547843817b4b7adbeb87ea9b070d9cac35c90;p=fs%2Flustre-release.git diff --git a/lnet/selftest/conctl.c b/lnet/selftest/conctl.c index 68297bd..f9e4c0d 100644 --- a/lnet/selftest/conctl.c +++ b/lnet/selftest/conctl.c @@ -15,11 +15,7 @@ * * You should have received a copy of the GNU General Public License * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * http://www.gnu.org/licenses/gpl-2.0.html * * GPL HEADER END */ @@ -27,7 +23,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, Intel Corporation. + * Copyright (c) 2012, 2014, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -35,19 +31,18 @@ * * lnet/selftest/conctl.c * - * IOC handle in kernel + * IOC handle in kernel * * Author: Liang Zhen */ -#ifdef __KERNEL__ #include #include #include #include "console.h" -int -lst_session_new_ioctl(lstio_session_new_args_t *args) +static int +lst_session_new_ioctl(struct lstio_session_new_args *args) { char *name; int rc; @@ -82,8 +77,8 @@ lst_session_new_ioctl(lstio_session_new_args_t *args) return rc; } -int -lst_session_end_ioctl(lstio_session_end_args_t *args) +static int +lst_session_end_ioctl(struct lstio_session_end_args *args) { if (args->lstio_ses_key != console_session.ses_key) return -EACCES; @@ -91,8 +86,8 @@ lst_session_end_ioctl(lstio_session_end_args_t *args) return lstcon_session_end(); } -int -lst_session_info_ioctl(lstio_session_info_args_t *args) +static int +lst_session_info_ioctl(struct lstio_session_info_args *args) { /* no checking of key */ @@ -113,8 +108,8 @@ lst_session_info_ioctl(lstio_session_info_args_t *args) args->lstio_ses_nmlen); } -int -lst_debug_ioctl(lstio_debug_args_t *args) +static int +lst_debug_ioctl(struct lstio_debug_args *args) { char *name = NULL; int client = 1; @@ -194,8 +189,8 @@ out: return rc; } -int -lst_group_add_ioctl(lstio_group_add_args_t *args) +static int +lst_group_add_ioctl(struct lstio_group_add_args *args) { char *name; int rc; @@ -204,7 +199,7 @@ lst_group_add_ioctl(lstio_group_add_args_t *args) return -EACCES; if (args->lstio_grp_namep == NULL|| - args->lstio_grp_nmlen <= 0 || + args->lstio_grp_nmlen <= 0 || args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; @@ -227,8 +222,8 @@ lst_group_add_ioctl(lstio_group_add_args_t *args) return rc; } -int -lst_group_del_ioctl(lstio_group_del_args_t *args) +static int +lst_group_del_ioctl(struct lstio_group_del_args *args) { int rc; char *name; @@ -260,8 +255,8 @@ lst_group_del_ioctl(lstio_group_del_args_t *args) return rc; } -int -lst_group_update_ioctl(lstio_group_update_args_t *args) +static int +lst_group_update_ioctl(struct lstio_group_update_args *args) { int rc; char *name; @@ -271,7 +266,7 @@ lst_group_update_ioctl(lstio_group_update_args_t *args) if (args->lstio_grp_resultp == NULL || args->lstio_grp_namep == NULL || - args->lstio_grp_nmlen <= 0 || + args->lstio_grp_nmlen <= 0 || args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; @@ -317,8 +312,8 @@ lst_group_update_ioctl(lstio_group_update_args_t *args) return rc; } -int -lst_nodes_add_ioctl(lstio_group_nodes_args_t *args) +static int +lst_nodes_add_ioctl(struct lstio_group_nodes_args *args) { unsigned feats; int rc; @@ -362,10 +357,10 @@ lst_nodes_add_ioctl(lstio_group_nodes_args_t *args) return rc; } -int -lst_group_list_ioctl(lstio_group_list_args_t *args) +static int +lst_group_list_ioctl(struct lstio_group_list_args *args) { - if (args->lstio_grp_key != console_session.ses_key) + if (args->lstio_grp_key != console_session.ses_key) return -EACCES; if (args->lstio_grp_idx < 0 || @@ -379,8 +374,8 @@ lst_group_list_ioctl(lstio_group_list_args_t *args) args->lstio_grp_namep); } -int -lst_group_info_ioctl(lstio_group_info_args_t *args) +static int +lst_group_info_ioctl(struct lstio_group_info_args *args) { char *name; int ndent; @@ -431,19 +426,19 @@ lst_group_info_ioctl(lstio_group_info_args_t *args) LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); - if (rc != 0) + if (rc != 0) return rc; if (args->lstio_grp_dentsp != NULL && (copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) || copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent)))) - rc = -EFAULT; + return -EFAULT; return 0; } -int -lst_batch_add_ioctl(lstio_batch_add_args_t *args) +static int +lst_batch_add_ioctl(struct lstio_batch_add_args *args) { int rc; char *name; @@ -475,8 +470,8 @@ lst_batch_add_ioctl(lstio_batch_add_args_t *args) return rc; } -int -lst_batch_run_ioctl(lstio_batch_run_args_t *args) +static int +lst_batch_run_ioctl(struct lstio_batch_run_args *args) { int rc; char *name; @@ -509,8 +504,8 @@ lst_batch_run_ioctl(lstio_batch_run_args_t *args) return rc; } -int -lst_batch_stop_ioctl(lstio_batch_stop_args_t *args) +static int +lst_batch_stop_ioctl(struct lstio_batch_stop_args *args) { int rc; char *name; @@ -544,8 +539,8 @@ lst_batch_stop_ioctl(lstio_batch_stop_args_t *args) return rc; } -int -lst_batch_query_ioctl(lstio_batch_query_args_t *args) +static int +lst_batch_query_ioctl(struct lstio_batch_query_args *args) { char *name; int rc; @@ -585,8 +580,8 @@ lst_batch_query_ioctl(lstio_batch_query_args_t *args) return rc; } -int -lst_batch_list_ioctl(lstio_batch_list_args_t *args) +static int +lst_batch_list_ioctl(struct lstio_batch_list_args *args) { if (args->lstio_bat_key != console_session.ses_key) return -EACCES; @@ -602,8 +597,8 @@ lst_batch_list_ioctl(lstio_batch_list_args_t *args) args->lstio_bat_namep); } -int -lst_batch_info_ioctl(lstio_batch_info_args_t *args) +static int +lst_batch_info_ioctl(struct lstio_batch_info_args *args) { char *name; int rc; @@ -667,73 +662,74 @@ lst_batch_info_ioctl(lstio_batch_info_args_t *args) return rc; } -int -lst_stat_query_ioctl(lstio_stat_args_t *args) +static int +lst_stat_query_ioctl(struct lstio_stat_args *args) { int rc; - char *name; + char *name = NULL; /* TODO: not finished */ if (args->lstio_sta_key != console_session.ses_key) return -EACCES; - if (args->lstio_sta_resultp == NULL || - (args->lstio_sta_namep == NULL && - args->lstio_sta_idsp == NULL) || - args->lstio_sta_nmlen <= 0 || - args->lstio_sta_nmlen > LST_NAME_SIZE) - return -EINVAL; - - if (args->lstio_sta_idsp != NULL && - args->lstio_sta_count <= 0) - return -EINVAL; - - LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1); - if (name == NULL) - return -ENOMEM; + if (args->lstio_sta_resultp == NULL) + return -EINVAL; - if (copy_from_user(name, args->lstio_sta_namep, - args->lstio_sta_nmlen)) { - LIBCFS_FREE(name, args->lstio_sta_nmlen + 1); - return -EFAULT; - } + if (args->lstio_sta_idsp != NULL) { + if (args->lstio_sta_count <= 0) + return -EINVAL; - if (args->lstio_sta_idsp == NULL) { - rc = lstcon_group_stat(name, args->lstio_sta_timeout, - args->lstio_sta_resultp); - } else { - rc = lstcon_nodes_stat(args->lstio_sta_count, + rc = lstcon_nodes_stat(args->lstio_sta_count, args->lstio_sta_idsp, args->lstio_sta_timeout, args->lstio_sta_resultp); - } + } else if (args->lstio_sta_namep != NULL) { + if (args->lstio_sta_nmlen <= 0 || + args->lstio_sta_nmlen > LST_NAME_SIZE) + return -EINVAL; - LIBCFS_FREE(name, args->lstio_sta_nmlen + 1); + LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1); + if (name == NULL) + return -ENOMEM; - return rc; + rc = copy_from_user(name, args->lstio_sta_namep, + args->lstio_sta_nmlen); + if (rc == 0) + rc = lstcon_group_stat(name, args->lstio_sta_timeout, + args->lstio_sta_resultp); + else + rc = -EFAULT; + + } else { + rc = -EINVAL; + } + + if (name != NULL) + LIBCFS_FREE(name, args->lstio_sta_nmlen + 1); + return rc; } -int lst_test_add_ioctl(lstio_test_args_t *args) +static int lst_test_add_ioctl(struct lstio_test_args *args) { - char *name; - char *srcgrp = NULL; - char *dstgrp = NULL; - void *param = NULL; - int ret = 0; - int rc = -ENOMEM; - - if (args->lstio_tes_resultp == NULL || - args->lstio_tes_retp == NULL || - args->lstio_tes_bat_name == NULL || /* no specified batch */ - args->lstio_tes_bat_nmlen <= 0 || - args->lstio_tes_bat_nmlen > LST_NAME_SIZE || - args->lstio_tes_sgrp_name == NULL || /* no source group */ - args->lstio_tes_sgrp_nmlen <= 0 || - args->lstio_tes_sgrp_nmlen > LST_NAME_SIZE || - args->lstio_tes_dgrp_name == NULL || /* no target group */ - args->lstio_tes_dgrp_nmlen <= 0 || - args->lstio_tes_dgrp_nmlen > LST_NAME_SIZE) - return -EINVAL; + char *batch_name; + char *src_name = NULL; + char *dst_name = NULL; + void *param = NULL; + int ret = 0; + int rc = -ENOMEM; + + if (args->lstio_tes_resultp == NULL || + args->lstio_tes_retp == NULL || + args->lstio_tes_bat_name == NULL || /* no specified batch */ + args->lstio_tes_bat_nmlen <= 0 || + args->lstio_tes_bat_nmlen > LST_NAME_SIZE || + args->lstio_tes_sgrp_name == NULL || /* no source group */ + args->lstio_tes_sgrp_nmlen <= 0 || + args->lstio_tes_sgrp_nmlen > LST_NAME_SIZE || + args->lstio_tes_dgrp_name == NULL || /* no target group */ + args->lstio_tes_dgrp_nmlen <= 0 || + args->lstio_tes_dgrp_nmlen > LST_NAME_SIZE) + return -EINVAL; if (args->lstio_tes_loop == 0 || /* negative is infinite */ args->lstio_tes_concur <= 0 || @@ -745,76 +741,85 @@ int lst_test_add_ioctl(lstio_test_args_t *args) if (args->lstio_tes_param != NULL && (args->lstio_tes_param_len <= 0 || args->lstio_tes_param_len > - PAGE_CACHE_SIZE - sizeof(lstcon_test_t))) + PAGE_SIZE - sizeof(lstcon_test_t))) return -EINVAL; - LIBCFS_ALLOC(name, args->lstio_tes_bat_nmlen + 1); - if (name == NULL) - return rc; + LIBCFS_ALLOC(batch_name, args->lstio_tes_bat_nmlen + 1); + if (batch_name == NULL) + return rc; - LIBCFS_ALLOC(srcgrp, args->lstio_tes_sgrp_nmlen + 1); - if (srcgrp == NULL) - goto out; + LIBCFS_ALLOC(src_name, args->lstio_tes_sgrp_nmlen + 1); + if (src_name == NULL) + goto out; - LIBCFS_ALLOC(dstgrp, args->lstio_tes_dgrp_nmlen + 1); - if (dstgrp == NULL) - goto out; + LIBCFS_ALLOC(dst_name, args->lstio_tes_dgrp_nmlen + 1); + if (dst_name == NULL) + goto out; - if (args->lstio_tes_param != NULL) { - LIBCFS_ALLOC(param, args->lstio_tes_param_len); - if (param == NULL) - goto out; - } + if (args->lstio_tes_param != NULL) { + LIBCFS_ALLOC(param, args->lstio_tes_param_len); + if (param == NULL) + goto out; + if (copy_from_user(param, args->lstio_tes_param, + args->lstio_tes_param_len)) { + rc = -EFAULT; + goto out; + } + } rc = -EFAULT; - if (copy_from_user(name, args->lstio_tes_bat_name, + if (copy_from_user(batch_name, args->lstio_tes_bat_name, args->lstio_tes_bat_nmlen) || - copy_from_user(srcgrp, args->lstio_tes_sgrp_name, + copy_from_user(src_name, args->lstio_tes_sgrp_name, args->lstio_tes_sgrp_nmlen) || - copy_from_user(dstgrp, args->lstio_tes_dgrp_name, - args->lstio_tes_dgrp_nmlen) || - copy_from_user(param, args->lstio_tes_param, - args->lstio_tes_param_len)) + copy_from_user(dst_name, args->lstio_tes_dgrp_name, + args->lstio_tes_dgrp_nmlen)) goto out; - rc = lstcon_test_add(name, - args->lstio_tes_type, - args->lstio_tes_loop, - args->lstio_tes_concur, - args->lstio_tes_dist, args->lstio_tes_span, - srcgrp, dstgrp, param, args->lstio_tes_param_len, - &ret, args->lstio_tes_resultp); + rc = lstcon_test_add(batch_name, + args->lstio_tes_type, + args->lstio_tes_loop, + args->lstio_tes_concur, + args->lstio_tes_dist, args->lstio_tes_span, + src_name, dst_name, param, + args->lstio_tes_param_len, + &ret, args->lstio_tes_resultp); if (ret != 0) rc = (copy_to_user(args->lstio_tes_retp, &ret, sizeof(ret))) ? -EFAULT : 0; out: - if (name != NULL) - LIBCFS_FREE(name, args->lstio_tes_bat_nmlen + 1); + if (batch_name != NULL) + LIBCFS_FREE(batch_name, args->lstio_tes_bat_nmlen + 1); - if (srcgrp != NULL) - LIBCFS_FREE(srcgrp, args->lstio_tes_sgrp_nmlen + 1); + if (src_name != NULL) + LIBCFS_FREE(src_name, args->lstio_tes_sgrp_nmlen + 1); - if (dstgrp != NULL) - LIBCFS_FREE(dstgrp, args->lstio_tes_dgrp_nmlen + 1); + if (dst_name != NULL) + LIBCFS_FREE(dst_name, args->lstio_tes_dgrp_nmlen + 1); - if (param != NULL) - LIBCFS_FREE(param, args->lstio_tes_param_len); + if (param != NULL) + LIBCFS_FREE(param, args->lstio_tes_param_len); - return rc; + return rc; } int -lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data) +lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr) { char *buf; - int opc = data->ioc_u32[0]; + struct libcfs_ioctl_data *data; + int opc; int rc; if (cmd != IOC_LIBCFS_LNETST) return -EINVAL; - if (data->ioc_plen1 > PAGE_CACHE_SIZE) + data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr); + + opc = data->ioc_u32[0]; + + if (data->ioc_plen1 > PAGE_SIZE) return -EINVAL; LIBCFS_ALLOC(buf, data->ioc_plen1); @@ -829,86 +834,86 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data) mutex_lock(&console_session.ses_mutex); - console_session.ses_laststamp = cfs_time_current_sec(); + console_session.ses_laststamp = ktime_get_real_seconds(); - if (console_session.ses_shutdown) { - rc = -ESHUTDOWN; - goto out; - } + if (console_session.ses_shutdown) { + rc = -ESHUTDOWN; + goto out; + } - if (console_session.ses_expired) - lstcon_session_end(); + if (console_session.ses_expired) + lstcon_session_end(); - if (opc != LSTIO_SESSION_NEW && - console_session.ses_state == LST_SESSION_NONE) { - CDEBUG(D_NET, "LST no active session\n"); - rc = -ESRCH; - goto out; - } - - memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t)); + if (opc != LSTIO_SESSION_NEW && + console_session.ses_state == LST_SESSION_NONE) { + CDEBUG(D_NET, "LST no active session\n"); + rc = -ESRCH; + goto out; + } - switch (opc) { - case LSTIO_SESSION_NEW: - rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf); - break; - case LSTIO_SESSION_END: - rc = lst_session_end_ioctl((lstio_session_end_args_t *)buf); - break; - case LSTIO_SESSION_INFO: - rc = lst_session_info_ioctl((lstio_session_info_args_t *)buf); - break; - case LSTIO_DEBUG: - rc = lst_debug_ioctl((lstio_debug_args_t *)buf); - break; - case LSTIO_GROUP_ADD: - rc = lst_group_add_ioctl((lstio_group_add_args_t *)buf); - break; - case LSTIO_GROUP_DEL: - rc = lst_group_del_ioctl((lstio_group_del_args_t *)buf); - break; - case LSTIO_GROUP_UPDATE: - rc = lst_group_update_ioctl((lstio_group_update_args_t *)buf); - break; - case LSTIO_NODES_ADD: - rc = lst_nodes_add_ioctl((lstio_group_nodes_args_t *)buf); - break; - case LSTIO_GROUP_LIST: - rc = lst_group_list_ioctl((lstio_group_list_args_t *)buf); - break; - case LSTIO_GROUP_INFO: - rc = lst_group_info_ioctl((lstio_group_info_args_t *)buf); - break; - case LSTIO_BATCH_ADD: - rc = lst_batch_add_ioctl((lstio_batch_add_args_t *)buf); - break; - case LSTIO_BATCH_START: - rc = lst_batch_run_ioctl((lstio_batch_run_args_t *)buf); - break; - case LSTIO_BATCH_STOP: - rc = lst_batch_stop_ioctl((lstio_batch_stop_args_t *)buf); - break; - case LSTIO_BATCH_QUERY: - rc = lst_batch_query_ioctl((lstio_batch_query_args_t *)buf); - break; - case LSTIO_BATCH_LIST: - rc = lst_batch_list_ioctl((lstio_batch_list_args_t *)buf); - break; - case LSTIO_BATCH_INFO: - rc = lst_batch_info_ioctl((lstio_batch_info_args_t *)buf); - break; - case LSTIO_TEST_ADD: - rc = lst_test_add_ioctl((lstio_test_args_t *)buf); - break; - case LSTIO_STAT_QUERY: - rc = lst_stat_query_ioctl((lstio_stat_args_t *)buf); - break; - default: - rc = -EINVAL; - } + memset(&console_session.ses_trans_stat, 0, sizeof(struct lstcon_trans_stat)); + + switch (opc) { + case LSTIO_SESSION_NEW: + rc = lst_session_new_ioctl((struct lstio_session_new_args *)buf); + break; + case LSTIO_SESSION_END: + rc = lst_session_end_ioctl((struct lstio_session_end_args *)buf); + break; + case LSTIO_SESSION_INFO: + rc = lst_session_info_ioctl((struct lstio_session_info_args *)buf); + break; + case LSTIO_DEBUG: + rc = lst_debug_ioctl((struct lstio_debug_args *)buf); + break; + case LSTIO_GROUP_ADD: + rc = lst_group_add_ioctl((struct lstio_group_add_args *)buf); + break; + case LSTIO_GROUP_DEL: + rc = lst_group_del_ioctl((struct lstio_group_del_args *)buf); + break; + case LSTIO_GROUP_UPDATE: + rc = lst_group_update_ioctl((struct lstio_group_update_args *)buf); + break; + case LSTIO_NODES_ADD: + rc = lst_nodes_add_ioctl((struct lstio_group_nodes_args *)buf); + break; + case LSTIO_GROUP_LIST: + rc = lst_group_list_ioctl((struct lstio_group_list_args *)buf); + break; + case LSTIO_GROUP_INFO: + rc = lst_group_info_ioctl((struct lstio_group_info_args *)buf); + break; + case LSTIO_BATCH_ADD: + rc = lst_batch_add_ioctl((struct lstio_batch_add_args *)buf); + break; + case LSTIO_BATCH_START: + rc = lst_batch_run_ioctl((struct lstio_batch_run_args *)buf); + break; + case LSTIO_BATCH_STOP: + rc = lst_batch_stop_ioctl((struct lstio_batch_stop_args *)buf); + break; + case LSTIO_BATCH_QUERY: + rc = lst_batch_query_ioctl((struct lstio_batch_query_args *)buf); + break; + case LSTIO_BATCH_LIST: + rc = lst_batch_list_ioctl((struct lstio_batch_list_args *)buf); + break; + case LSTIO_BATCH_INFO: + rc = lst_batch_info_ioctl((struct lstio_batch_info_args *)buf); + break; + case LSTIO_TEST_ADD: + rc = lst_test_add_ioctl((struct lstio_test_args *)buf); + break; + case LSTIO_STAT_QUERY: + rc = lst_stat_query_ioctl((struct lstio_stat_args *)buf); + break; + default: + rc = -EINVAL; + } if (copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat, - sizeof(lstcon_trans_stat_t))) + sizeof(struct lstcon_trans_stat))) rc = -EFAULT; out: mutex_unlock(&console_session.ses_mutex); @@ -917,7 +922,3 @@ out: return rc; } - -EXPORT_SYMBOL(lstcon_ioctl_entry); - -#endif