X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lnet%2Fselftest%2Fconctl.c;h=9c2f39f90f5e542753f31d298df6eff0eb4f04ad;hp=8b0a1e34c0f563a25f3932341c6d891589476864;hb=ad173173fe6b67e41c2c232a15c5eb6939836871;hpb=6869932b552ac705f411de3362f01bd50c1f6f7d diff --git a/lnet/selftest/conctl.c b/lnet/selftest/conctl.c index 8b0a1e3..9c2f39f 100644 --- a/lnet/selftest/conctl.c +++ b/lnet/selftest/conctl.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -26,7 +24,7 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. */ /* @@ -47,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; @@ -58,29 +56,29 @@ 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; + rc = lstcon_session_new(name, + args->lstio_ses_key, + args->lstio_ses_feats, + args->lstio_ses_force, + args->lstio_ses_timeout, + args->lstio_ses_idp); + + LIBCFS_FREE(name, args->lstio_ses_nmlen + 1); + return rc; } int @@ -99,6 +97,7 @@ lst_session_info_ioctl(lstio_session_info_args_t *args) if (args->lstio_ses_idp == NULL || /* address for ouput sid */ args->lstio_ses_keyp == NULL || /* address for ouput key */ + args->lstio_ses_featp == NULL || /* address for ouput features */ args->lstio_ses_ndinfo == NULL || /* address for output ndinfo */ args->lstio_ses_namep == NULL || /* address for ouput name */ args->lstio_ses_nmlen <= 0 || @@ -107,6 +106,7 @@ lst_session_info_ioctl(lstio_session_info_args_t *args) return lstcon_session_info(args->lstio_ses_idp, args->lstio_ses_keyp, + args->lstio_ses_featp, args->lstio_ses_ndinfo, args->lstio_ses_namep, args->lstio_ses_nmlen); @@ -135,8 +135,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; @@ -211,9 +211,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; } @@ -235,9 +235,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; @@ -245,9 +245,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; } @@ -280,7 +280,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); @@ -315,13 +315,14 @@ lst_group_update_ioctl(lstio_group_update_args_t *args) } LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); - + return rc; } int lst_nodes_add_ioctl(lstio_group_nodes_args_t *args) { + unsigned feats; int rc; char *name; @@ -331,8 +332,9 @@ lst_nodes_add_ioctl(lstio_group_nodes_args_t *args) if (args->lstio_grp_idsp == NULL || /* array of ids */ args->lstio_grp_count <= 0 || args->lstio_grp_resultp == NULL || - args->lstio_grp_namep == NULL || - args->lstio_grp_nmlen <= 0 || + args->lstio_grp_featp == NULL || + args->lstio_grp_namep == NULL || + args->lstio_grp_nmlen <= 0 || args->lstio_grp_nmlen > LST_NAME_SIZE) return -EINVAL; @@ -340,8 +342,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; @@ -350,10 +352,14 @@ lst_nodes_add_ioctl(lstio_group_nodes_args_t *args) name[args->lstio_grp_nmlen] = 0; rc = lstcon_nodes_add(name, args->lstio_grp_count, - args->lstio_grp_idsp, - args->lstio_grp_resultp); + args->lstio_grp_idsp, &feats, + args->lstio_grp_resultp); - LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); + LIBCFS_FREE(name, args->lstio_grp_nmlen + 1); + if (rc == 0 && + cfs_copy_to_user(args->lstio_grp_featp, &feats, sizeof(feats))) { + return -EINVAL; + } return rc; } @@ -399,10 +405,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) @@ -413,9 +420,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; } @@ -431,8 +438,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; @@ -456,9 +463,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; } @@ -490,9 +497,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; } @@ -526,9 +533,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; } @@ -565,9 +572,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; } @@ -626,9 +633,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) @@ -639,8 +648,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; } @@ -658,8 +667,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; @@ -690,8 +699,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; } @@ -733,6 +742,12 @@ int lst_test_add_ioctl(lstio_test_args_t *args) args->lstio_tes_dgrp_nmlen > LST_NAME_SIZE) return -EINVAL; + if (args->lstio_tes_loop == 0 || /* negative is infinite */ + args->lstio_tes_concur <= 0 || + args->lstio_tes_dist <= 0 || + args->lstio_tes_span <= 0) + return -EINVAL; + /* have parameter, check if parameter length is valid */ if (args->lstio_tes_param != NULL && (args->lstio_tes_param_len <= 0 || @@ -748,7 +763,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) { @@ -758,17 +773,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, @@ -780,8 +795,8 @@ int lst_test_add_ioctl(lstio_test_args_t *args) &ret, args->lstio_tes_resultp); if (ret != 0) - rc = (copy_to_user(args->lstio_tes_retp, &ret, sizeof(ret))) ? - -EFAULT : 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); @@ -816,12 +831,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(); @@ -841,7 +856,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); @@ -901,11 +916,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);