X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Fselftest%2Fconsole.c;h=d58cc9c27faff858af671b323de2e64407e310b3;hb=6d7dfe53923c4a39efa165198b7dbb43045b50dd;hp=04c1a386c676d05464b2cbd3a977003c9c51eddd;hpb=08aa217ce49aba1ded52e0f7adb8a607035123fd;p=fs%2Flustre-release.git diff --git a/lnet/selftest/console.c b/lnet/selftest/console.c index 04c1a38..d58cc9c 100644 --- a/lnet/selftest/console.c +++ b/lnet/selftest/console.c @@ -269,21 +269,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 @@ -297,7 +297,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; @@ -392,9 +392,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; @@ -426,7 +426,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; } @@ -495,7 +495,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; } @@ -740,7 +740,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; } } @@ -770,9 +770,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; @@ -827,7 +827,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)); @@ -837,20 +837,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 @@ -924,7 +924,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; } } @@ -1000,7 +1000,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)); @@ -1247,100 +1247,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; - /* add to test list anyway, so user can check what's going on */ - cfs_list_add_tail(&test->tes_link, &batch->bat_test_list); + LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen])); + if (!test) { + CERROR("Can't allocate test descriptor\n"); + rc = -ENOMEM; - batch->bat_ntest ++; - test->tes_hdr.tsb_index = batch->bat_ntest; + goto out; + } - /* hold groups so nobody can change them */ - return rc; + 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); + } + + 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 @@ -1369,7 +1408,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; @@ -1454,9 +1493,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; @@ -1524,7 +1563,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; } @@ -1636,7 +1675,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; } @@ -1739,7 +1778,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; @@ -1769,14 +1808,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));