X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Fselftest%2Fconsole.c;h=aac83bd231f721fd6e036c4b5fcfb558ded3b17a;hb=ef1d121c2e68e368dae72a5994d3d1fd3b35c2b3;hp=74f77aff308e4da844301eb37560fa3f3de4f03e;hpb=9fb46705ae86aa2c0ac29427f0ff24f923560eb7;p=fs%2Flustre-release.git diff --git a/lnet/selftest/console.c b/lnet/selftest/console.c index 74f77af..aac83bd 100644 --- a/lnet/selftest/console.c +++ b/lnet/selftest/console.c @@ -26,6 +26,8 @@ /* * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2012, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -209,8 +211,14 @@ lstcon_group_alloc(char *name, lstcon_group_t **grpp) grp_ndl_hash[LST_NODE_HASHSIZE])); grp->grp_ref = 1; - if (name != NULL) - strcpy(grp->grp_name, name); + if (name != NULL) { + if (strlen(name) > sizeof(grp->grp_name)-1) { + LIBCFS_FREE(grp, offsetof(lstcon_group_t, + grp_ndl_hash[LST_NODE_HASHSIZE])); + return -E2BIG; + } + strncpy(grp->grp_name, name, sizeof(grp->grp_name)); + } CFS_INIT_LIST_HEAD(&grp->grp_link); CFS_INIT_LIST_HEAD(&grp->grp_ndl_list); @@ -267,21 +275,21 @@ lstcon_group_decref(lstcon_group_t *grp) } static int -lstcon_group_find(char *name, lstcon_group_t **grpp) +lstcon_group_find(const char *name, lstcon_group_t **grpp) { - lstcon_group_t *grp; + lstcon_group_t *grp; - cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list, - lstcon_group_t, grp_link) { - if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0) - continue; + cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list, + lstcon_group_t, grp_link) { + if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0) + continue; - lstcon_group_addref(grp); /* +1 ref for caller */ - *grpp = grp; - return 0; - } + lstcon_group_addref(grp); /* +1 ref for caller */ + *grpp = grp; + return 0; + } - return -ENOENT; + return -ENOENT; } static void @@ -295,7 +303,7 @@ lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create) { int rc; - + rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create); if (rc != 0) return rc; @@ -390,9 +398,9 @@ lstcon_sesrpc_readent(int transop, srpc_msg_t *msg, case LST_TRANS_SESQRY: rep = &msg->msg_body.dbg_reply; - if (cfs_copy_to_user(&ent_up->rpe_priv[0], + if (copy_to_user(&ent_up->rpe_priv[0], &rep->dbg_timeout, sizeof(int)) || - cfs_copy_to_user(&ent_up->rpe_payload[0], + copy_to_user(&ent_up->rpe_payload[0], &rep->dbg_name, LST_NAME_SIZE)) return -EFAULT; @@ -424,7 +432,7 @@ lstcon_group_nodes_add(lstcon_group_t *grp, } for (i = 0 ; i < count; i++) { - if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) { + if (copy_from_user(&id, &ids_up[i], sizeof(id))) { rc = -EFAULT; break; } @@ -493,7 +501,7 @@ lstcon_group_nodes_remove(lstcon_group_t *grp, } for (i = 0; i < count; i++) { - if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) { + if (copy_from_user(&id, &ids_up[i], sizeof(id))) { rc = -EFAULT; goto error; } @@ -738,7 +746,7 @@ lstcon_group_list(int index, int len, char *name_up) cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list, lstcon_group_t, grp_link) { if (index-- == 0) { - return cfs_copy_to_user(name_up, grp->grp_name, len) ? + return copy_to_user(name_up, grp->grp_name, len) ? -EFAULT : 0; } } @@ -768,9 +776,9 @@ lstcon_nodes_getent(cfs_list_t *head, int *index_p, break; nd = ndl->ndl_node; - if (cfs_copy_to_user(&dents_up[count].nde_id, + if (copy_to_user(&dents_up[count].nde_id, &nd->nd_id, sizeof(nd->nd_id)) || - cfs_copy_to_user(&dents_up[count].nde_state, + copy_to_user(&dents_up[count].nde_state, &nd->nd_state, sizeof(nd->nd_state))) return -EFAULT; @@ -825,7 +833,7 @@ lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p, lstcon_ndlink_t, ndl_link) LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp); - rc = cfs_copy_to_user(gents_p, gentp, + rc = copy_to_user(gents_p, gentp, sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0; LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t)); @@ -835,20 +843,20 @@ lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p, return 0; } -int -lstcon_batch_find(char *name, lstcon_batch_t **batpp) +static int +lstcon_batch_find(const char *name, lstcon_batch_t **batpp) { - lstcon_batch_t *bat; - - cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list, - lstcon_batch_t, bat_link) { - if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) { - *batpp = bat; - return 0; - } - } + lstcon_batch_t *bat; + + cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list, + lstcon_batch_t, bat_link) { + if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) { + *batpp = bat; + return 0; + } + } - return -ENOENT; + return -ENOENT; } int @@ -889,7 +897,13 @@ lstcon_batch_add(char *name) return -ENOMEM; } - strcpy(bat->bat_name, name); + if (strlen(name) > sizeof(bat->bat_name)-1) { + LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE); + LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE); + LIBCFS_FREE(bat, sizeof(lstcon_batch_t)); + return -E2BIG; + } + strncpy(bat->bat_name, name, sizeof(bat->bat_name)); bat->bat_hdr.tsb_index = 0; bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie; @@ -922,7 +936,7 @@ lstcon_batch_list(int index, int len, char *name_up) cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list, lstcon_batch_t, bat_link) { if (index-- == 0) { - return cfs_copy_to_user(name_up,bat->bat_name, len) ? + return copy_to_user(name_up, bat->bat_name, len) ? -EFAULT: 0; } } @@ -998,7 +1012,7 @@ lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server, cfs_list_for_each_entry_typed(ndl, srvlst, lstcon_ndlink_t, ndl_link) LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle); - rc = cfs_copy_to_user(ent_up, entp, + rc = copy_to_user(ent_up, entp, sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0; LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t)); @@ -1245,100 +1259,139 @@ again: goto again; } -int -lstcon_test_add(char *name, int type, int loop, int concur, - int dist, int span, char *src_name, char * dst_name, - void *param, int paramlen, int *retp, - cfs_list_t *result_up) +static int +lstcon_verify_batch(const char *name, lstcon_batch_t **batch) { - lstcon_group_t *src_grp = NULL; - lstcon_group_t *dst_grp = NULL; - lstcon_test_t *test = NULL; - lstcon_batch_t *batch; - int rc; + int rc; - rc = lstcon_batch_find(name, &batch); - if (rc != 0) { - CDEBUG(D_NET, "Can't find batch %s\n", name); - return rc; - } + rc = lstcon_batch_find(name, batch); + if (rc != 0) { + CDEBUG(D_NET, "Can't find batch %s\n", name); + return rc; + } - if (batch->bat_state != LST_BATCH_IDLE) { - CDEBUG(D_NET, "Can't change running batch %s\n", name); - return rc; - } + if ((*batch)->bat_state != LST_BATCH_IDLE) { + CDEBUG(D_NET, "Can't change running batch %s\n", name); + return -EINVAL; + } - rc = lstcon_group_find(src_name, &src_grp); - if (rc != 0) { - CDEBUG(D_NET, "Can't find group %s\n", src_name); - goto out; - } + return 0; +} - rc = lstcon_group_find(dst_name, &dst_grp); - if (rc != 0) { - CDEBUG(D_NET, "Can't find group %s\n", dst_name); - goto out; - } +static int +lstcon_verify_group(const char *name, lstcon_group_t **grp) +{ + int rc; + lstcon_ndlink_t *ndl; - if (dst_grp->grp_userland) - *retp = 1; + rc = lstcon_group_find(name, grp); + if (rc != 0) { + CDEBUG(D_NET, "can't find group %s\n", name); + return rc; + } - LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen])); - if (!test) { - CERROR("Can't allocate test descriptor\n"); - rc = -ENOMEM; + cfs_list_for_each_entry_typed(ndl, &(*grp)->grp_ndl_list, + lstcon_ndlink_t, ndl_link) { + if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE) { + return 0; + } + } - goto out; - } + CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name); - memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen])); - test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id; - test->tes_batch = batch; - test->tes_type = type; - test->tes_oneside = 0; /* TODO */ - test->tes_loop = loop; - test->tes_concur = concur; - test->tes_stop_onerr = 1; /* TODO */ - test->tes_span = span; - test->tes_dist = dist; - test->tes_cliidx = 0; /* just used for creating RPC */ - test->tes_src_grp = src_grp; - test->tes_dst_grp = dst_grp; - CFS_INIT_LIST_HEAD(&test->tes_trans_list); + return -EINVAL; +} - if (param != NULL) { - test->tes_paramlen = paramlen; - memcpy(&test->tes_param[0], param, paramlen); - } +int +lstcon_test_add(char *batch_name, int type, int loop, + int concur, int dist, int span, + char *src_name, char *dst_name, + void *param, int paramlen, int *retp, + cfs_list_t *result_up) +{ + lstcon_test_t *test = NULL; + int rc; + lstcon_group_t *src_grp = NULL; + lstcon_group_t *dst_grp = NULL; + lstcon_batch_t *batch = NULL; + + /* + * verify that a batch of the given name exists, and the groups + * that will be part of the batch exist and have at least one + * active node + */ + rc = lstcon_verify_batch(batch_name, &batch); + if (rc != 0) + goto out; - rc = lstcon_test_nodes_add(test, result_up); + rc = lstcon_verify_group(src_name, &src_grp); + if (rc != 0) + goto out; - if (rc != 0) - goto out; + rc = lstcon_verify_group(dst_name, &dst_grp); + if (rc != 0) + goto out; - if (lstcon_trans_stat()->trs_rpc_errno != 0 || - lstcon_trans_stat()->trs_fwk_errno != 0) - CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type, name); + if (dst_grp->grp_userland) + *retp = 1; + + LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen])); + if (!test) { + CERROR("Can't allocate test descriptor\n"); + rc = -ENOMEM; - /* add to test list anyway, so user can check what's going on */ - cfs_list_add_tail(&test->tes_link, &batch->bat_test_list); + goto out; + } - batch->bat_ntest ++; - test->tes_hdr.tsb_index = batch->bat_ntest; + memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen])); + test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id; + test->tes_batch = batch; + test->tes_type = type; + test->tes_oneside = 0; /* TODO */ + test->tes_loop = loop; + test->tes_concur = concur; + test->tes_stop_onerr = 1; /* TODO */ + test->tes_span = span; + test->tes_dist = dist; + test->tes_cliidx = 0; /* just used for creating RPC */ + test->tes_src_grp = src_grp; + test->tes_dst_grp = dst_grp; + CFS_INIT_LIST_HEAD(&test->tes_trans_list); + + if (param != NULL) { + test->tes_paramlen = paramlen; + memcpy(&test->tes_param[0], param, paramlen); + } - /* hold groups so nobody can change them */ - return rc; + rc = lstcon_test_nodes_add(test, result_up); + + if (rc != 0) + goto out; + + if (lstcon_trans_stat()->trs_rpc_errno != 0 || + lstcon_trans_stat()->trs_fwk_errno != 0) + CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type, + batch_name); + + /* add to test list anyway, so user can check what's going on */ + cfs_list_add_tail(&test->tes_link, &batch->bat_test_list); + + batch->bat_ntest++; + test->tes_hdr.tsb_index = batch->bat_ntest; + + /* hold groups so nobody can change them */ + return rc; out: - if (test != NULL) - LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen])); + if (test != NULL) + LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen])); - if (dst_grp != NULL) - lstcon_group_put(dst_grp); + if (dst_grp != NULL) + lstcon_group_put(dst_grp); - if (src_grp != NULL) - lstcon_group_put(src_grp); + if (src_grp != NULL) + lstcon_group_put(src_grp); - return rc; + return rc; } int @@ -1367,7 +1420,7 @@ lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg, transop == LST_TRANS_TSBSRVQRY); /* positive errno, framework error code */ - if (cfs_copy_to_user(&ent_up->rpe_priv[0], + if (copy_to_user(&ent_up->rpe_priv[0], &rep->bar_active, sizeof(rep->bar_active))) return -EFAULT; @@ -1452,9 +1505,9 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg, srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat)); lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat)); - if (cfs_copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) || - cfs_copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) || - cfs_copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat))) + if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) || + copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) || + copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat))) return -EFAULT; return 0; @@ -1522,7 +1575,7 @@ lstcon_nodes_stat(int count, lnet_process_id_t *ids_up, } for (i = 0 ; i < count; i++) { - if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) { + if (copy_from_user(&id, &ids_up[i], sizeof(id))) { rc = -EFAULT; break; } @@ -1634,7 +1687,7 @@ lstcon_nodes_debug(int timeout, } for (i = 0; i < count; i++) { - if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) { + if (copy_from_user(&id, &ids_up[i], sizeof(id))) { rc = -EFAULT; break; } @@ -1721,7 +1774,11 @@ lstcon_session_new(char *name, int key, unsigned feats, console_session.ses_feats_updated = 0; console_session.ses_timeout = (timeout <= 0) ? LST_CONSOLE_TIMEOUT : timeout; - strcpy(console_session.ses_name, name); + + if (strlen(name) > sizeof(console_session.ses_name)-1) + return -E2BIG; + strncpy(console_session.ses_name, name, + sizeof(console_session.ses_name)); rc = lstcon_batch_add(LST_DEFAULT_BATCH); if (rc != 0) @@ -1737,7 +1794,7 @@ lstcon_session_new(char *name, int key, unsigned feats, return rc; } - if (cfs_copy_to_user(sid_up, &console_session.ses_id, + if (copy_to_user(sid_up, &console_session.ses_id, sizeof(lst_sid_t)) == 0) return rc; @@ -1767,14 +1824,14 @@ lstcon_session_info(lst_sid_t *sid_up, int *key_up, unsigned *featp, lstcon_ndlink_t, ndl_link) LST_NODE_STATE_COUNTER(ndl->ndl_node, entp); - if (cfs_copy_to_user(sid_up, &console_session.ses_id, + if (copy_to_user(sid_up, &console_session.ses_id, sizeof(lst_sid_t)) || - cfs_copy_to_user(key_up, &console_session.ses_key, + copy_to_user(key_up, &console_session.ses_key, sizeof(*key_up)) || - cfs_copy_to_user(featp, &console_session.ses_features, + copy_to_user(featp, &console_session.ses_features, sizeof(*featp)) || - cfs_copy_to_user(ndinfo_up, entp, sizeof(*entp)) || - cfs_copy_to_user(name_up, console_session.ses_name, len)) + copy_to_user(ndinfo_up, entp, sizeof(*entp)) || + copy_to_user(name_up, console_session.ses_name, len)) rc = -EFAULT; LIBCFS_FREE(entp, sizeof(*entp));