X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lnet%2Fselftest%2Fconctl.c;h=901b6e2ad7ce0cfa4d4f10ed72d67a7ae14ca453;hp=7cb1378eece0ecda29f600f1f2ef9d356da9e641;hb=54320d7f52e6dd2b32e64997e2f7ae1ff1060f6f;hpb=776615e6825e2c90c2635c8b55e7bb02da33726c diff --git a/lnet/selftest/conctl.c b/lnet/selftest/conctl.c index 7cb1378..901b6e2 100644 --- a/lnet/selftest/conctl.c +++ b/lnet/selftest/conctl.c @@ -1,11 +1,41 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: +/* + * GPL HEADER START * - * Author: Liang Zhen + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). + * + * 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. + * + * GPL HEADER END + */ +/* + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. * - * This file is part of Lustre, http://www.lustre.org + * lnet/selftest/conctl.c * * IOC handle in kernel + * + * Author: Liang Zhen */ #ifdef __KERNEL__ @@ -15,7 +45,7 @@ #include "console.h" int -lst_session_new_ioctl(lstio_session_new_args_t *args) +lst_session_new_ioctl(lstio_session_new_args_t *args) { char *name; int rc; @@ -26,26 +56,26 @@ lst_session_new_ioctl(lstio_session_new_args_t *args) args->lstio_ses_nmlen <= 0 || args->lstio_ses_nmlen > LST_NAME_SIZE) return -EINVAL; - + LIBCFS_ALLOC(name, args->lstio_ses_nmlen + 1); if (name == NULL) return -ENOMEM; - - if (copy_from_user(name, - args->lstio_ses_namep, - args->lstio_ses_nmlen)) { + + if (cfs_copy_from_user(name, + args->lstio_ses_namep, + args->lstio_ses_nmlen)) { LIBCFS_FREE(name, args->lstio_ses_nmlen + 1); return -EFAULT; } - + name[args->lstio_ses_nmlen] = 0; - + rc = lstcon_session_new(name, args->lstio_ses_key, args->lstio_ses_timeout, args->lstio_ses_force, args->lstio_ses_idp); - + LIBCFS_FREE(name, args->lstio_ses_nmlen + 1); return rc; @@ -103,8 +133,8 @@ lst_debug_ioctl(lstio_debug_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, args->lstio_dbg_namep, - args->lstio_dbg_nmlen)) { + if (cfs_copy_from_user(name, args->lstio_dbg_namep, + args->lstio_dbg_nmlen)) { LIBCFS_FREE(name, args->lstio_dbg_nmlen + 1); return -EFAULT; @@ -179,9 +209,9 @@ lst_group_add_ioctl(lstio_group_add_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, - args->lstio_grp_namep, - args->lstio_grp_nmlen)) { + if (cfs_copy_from_user(name, + args->lstio_grp_namep, + args->lstio_grp_nmlen)) { LIBCFS_FREE(name, args->lstio_grp_nmlen); return -EFAULT; } @@ -203,9 +233,9 @@ lst_group_del_ioctl(lstio_group_del_args_t *args) if (args->lstio_grp_key != console_session.ses_key) 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; @@ -213,9 +243,9 @@ lst_group_del_ioctl(lstio_group_del_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, - args->lstio_grp_namep, - args->lstio_grp_nmlen)) { + if (cfs_copy_from_user(name, + args->lstio_grp_namep, + args->lstio_grp_nmlen)) { LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return -EFAULT; } @@ -248,7 +278,7 @@ lst_group_update_ioctl(lstio_group_update_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, + if (cfs_copy_from_user(name, args->lstio_grp_namep, args->lstio_grp_nmlen)) { LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); @@ -283,7 +313,7 @@ lst_group_update_ioctl(lstio_group_update_args_t *args) } LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); - + return rc; } @@ -308,8 +338,8 @@ lst_nodes_add_ioctl(lstio_group_nodes_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, args->lstio_grp_namep, - args->lstio_grp_nmlen)) { + if (cfs_copy_from_user(name, args->lstio_grp_namep, + args->lstio_grp_nmlen)) { LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return -EFAULT; @@ -367,10 +397,11 @@ lst_group_info_ioctl(lstio_group_info_args_t *args) if (args->lstio_grp_idxp == NULL || /* node index */ args->lstio_grp_ndentp == NULL) /* # of node entry */ return -EINVAL; - - if (copy_from_user(&ndent, - args->lstio_grp_ndentp, sizeof(ndent)) || - copy_from_user(&index, args->lstio_grp_idxp, sizeof(index))) + + if (cfs_copy_from_user(&ndent, args->lstio_grp_ndentp, + sizeof(ndent)) || + cfs_copy_from_user(&index, args->lstio_grp_idxp, + sizeof(index))) return -EFAULT; if (ndent <= 0 || index < 0) @@ -381,9 +412,9 @@ lst_group_info_ioctl(lstio_group_info_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, - args->lstio_grp_namep, - args->lstio_grp_nmlen)) { + if (cfs_copy_from_user(name, + args->lstio_grp_namep, + args->lstio_grp_nmlen)) { LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); return -EFAULT; } @@ -399,8 +430,8 @@ lst_group_info_ioctl(lstio_group_info_args_t *args) 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)))) + (cfs_copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) || + cfs_copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent)))) rc = -EFAULT; return 0; @@ -424,9 +455,9 @@ lst_batch_add_ioctl(lstio_batch_add_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, - args->lstio_bat_namep, - args->lstio_bat_nmlen)) { + if (cfs_copy_from_user(name, + args->lstio_bat_namep, + args->lstio_bat_nmlen)) { LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); return -EFAULT; } @@ -458,9 +489,9 @@ lst_batch_run_ioctl(lstio_batch_run_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, - args->lstio_bat_namep, - args->lstio_bat_nmlen)) { + if (cfs_copy_from_user(name, + args->lstio_bat_namep, + args->lstio_bat_nmlen)) { LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); return -EFAULT; } @@ -494,9 +525,9 @@ lst_batch_stop_ioctl(lstio_batch_stop_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, - args->lstio_bat_namep, - args->lstio_bat_nmlen)) { + if (cfs_copy_from_user(name, + args->lstio_bat_namep, + args->lstio_bat_nmlen)) { LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); return -EFAULT; } @@ -533,9 +564,9 @@ lst_batch_query_ioctl(lstio_batch_query_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, - args->lstio_bat_namep, - args->lstio_bat_nmlen)) { + if (cfs_copy_from_user(name, + args->lstio_bat_namep, + args->lstio_bat_nmlen)) { LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); return -EFAULT; } @@ -594,9 +625,11 @@ lst_batch_info_ioctl(lstio_batch_info_args_t *args) if (args->lstio_bat_idxp == NULL || /* node index */ args->lstio_bat_ndentp == NULL) /* # of node entry */ return -EINVAL; - - if (copy_from_user(&index, args->lstio_bat_idxp, sizeof(index)) || - copy_from_user(&ndent, args->lstio_bat_ndentp, sizeof(ndent))) + + if (cfs_copy_from_user(&index, args->lstio_bat_idxp, + sizeof(index)) || + cfs_copy_from_user(&ndent, args->lstio_bat_ndentp, + sizeof(ndent))) return -EFAULT; if (ndent <= 0 || index < 0) @@ -607,8 +640,8 @@ lst_batch_info_ioctl(lstio_batch_info_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, - args->lstio_bat_namep, args->lstio_bat_nmlen)) { + if (cfs_copy_from_user(name, + args->lstio_bat_namep, args->lstio_bat_nmlen)) { LIBCFS_FREE(name, args->lstio_bat_nmlen + 1); return -EFAULT; } @@ -626,8 +659,8 @@ lst_batch_info_ioctl(lstio_batch_info_args_t *args) return rc; if (args->lstio_bat_dentsp != NULL && - (copy_to_user(args->lstio_bat_idxp, &index, sizeof(index)) || - copy_to_user(args->lstio_bat_ndentp, &ndent, sizeof(ndent)))) + (cfs_copy_to_user(args->lstio_bat_idxp, &index, sizeof(index)) || + cfs_copy_to_user(args->lstio_bat_ndentp, &ndent, sizeof(ndent)))) rc = -EFAULT; return rc; @@ -658,8 +691,8 @@ lst_stat_query_ioctl(lstio_stat_args_t *args) if (name == NULL) return -ENOMEM; - if (copy_from_user(name, args->lstio_sta_namep, - args->lstio_sta_nmlen)) { + if (cfs_copy_from_user(name, args->lstio_sta_namep, + args->lstio_sta_nmlen)) { LIBCFS_FREE(name, args->lstio_sta_nmlen + 1); return -EFAULT; } @@ -685,9 +718,11 @@ int lst_test_add_ioctl(lstio_test_args_t *args) 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 || @@ -714,7 +749,7 @@ int lst_test_add_ioctl(lstio_test_args_t *args) goto out; LIBCFS_ALLOC(dstgrp, args->lstio_tes_dgrp_nmlen + 1); - if (srcgrp == NULL) + if (dstgrp == NULL) goto out; if (args->lstio_tes_param != NULL) { @@ -724,17 +759,17 @@ int lst_test_add_ioctl(lstio_test_args_t *args) } rc = -EFAULT; - if (copy_from_user(name, - args->lstio_tes_bat_name, - args->lstio_tes_bat_nmlen) || - copy_from_user(srcgrp, - 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)) + if (cfs_copy_from_user(name, + args->lstio_tes_bat_name, + args->lstio_tes_bat_nmlen) || + cfs_copy_from_user(srcgrp, + args->lstio_tes_sgrp_name, + args->lstio_tes_sgrp_nmlen) || + cfs_copy_from_user(dstgrp, + args->lstio_tes_dgrp_name, + args->lstio_tes_dgrp_nmlen) || + cfs_copy_from_user(param, args->lstio_tes_param, + args->lstio_tes_param_len)) goto out; rc = lstcon_test_add(name, @@ -743,7 +778,11 @@ int lst_test_add_ioctl(lstio_test_args_t *args) args->lstio_tes_concur, args->lstio_tes_dist, args->lstio_tes_span, srcgrp, dstgrp, param, args->lstio_tes_param_len, - args->lstio_tes_resultp); + &ret, args->lstio_tes_resultp); + + if (ret != 0) + rc = (cfs_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); @@ -778,12 +817,12 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data) return -ENOMEM; /* copy in parameter */ - if (copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) { + if (cfs_copy_from_user(buf, data->ioc_pbuf1, data->ioc_plen1)) { LIBCFS_FREE(buf, data->ioc_plen1); return -EFAULT; } - mutex_down(&console_session.ses_mutex); + cfs_mutex_lock(&console_session.ses_mutex); console_session.ses_laststamp = cfs_time_current_sec(); @@ -803,7 +842,7 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data) } memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t)); - + switch (opc) { case LSTIO_SESSION_NEW: rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf); @@ -863,11 +902,11 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data) rc = -EINVAL; } - if (copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat, - sizeof(lstcon_trans_stat_t))) + if (cfs_copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat, + sizeof(lstcon_trans_stat_t))) rc = -EFAULT; out: - mutex_up(&console_session.ses_mutex); + cfs_mutex_unlock(&console_session.ses_mutex); LIBCFS_FREE(buf, data->ioc_plen1);