⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.c

📁 lustre 1.6.5 source code
💻 C
📖 第 1 页 / 共 4 页
字号:
        rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;        if (rc != 0) {                /* find a group with same name */                lstcon_group_put(grp);                return rc;        }        rc = lstcon_group_alloc(name, &grp);        if (rc != 0) {                CERROR("Can't allocate descriptor for group %s\n", name);                return -ENOMEM;        }        list_add_tail(&grp->grp_link, &console_session.ses_grp_list);        return rc;}intlstcon_nodes_add(char *name, int count,                 lnet_process_id_t *ids_up, struct list_head *result_up){        lstcon_group_t         *grp;        int                     rc;        LASSERT (count > 0);        LASSERT (ids_up != NULL);        rc = lstcon_group_find(name, &grp);        if (rc != 0) {                CDEBUG(D_NET, "Can't find group %s\n", name);                return rc;        }        if (grp->grp_ref > 2) {                /* referred by other threads or test */                CDEBUG(D_NET, "Group %s is busy\n", name);                lstcon_group_put(grp);                return -EBUSY;        }        rc = lstcon_group_nodes_add(grp, count, ids_up, result_up);        lstcon_group_put(grp);        return rc;}intlstcon_group_del(char *name){        lstcon_rpc_trans_t *trans;        lstcon_group_t     *grp;        int                 rc;        rc = lstcon_group_find(name, &grp);        if (rc != 0) {                CDEBUG(D_NET, "Can't find group: %s\n", name);                return rc;        }        if (grp->grp_ref > 2) {                /* referred by others threads or test */                CDEBUG(D_NET, "Group %s is busy\n", name);                lstcon_group_put(grp);                return -EBUSY;        }        rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,                                     &grp->grp_trans_list, LST_TRANS_SESEND,                                     grp, lstcon_sesrpc_condition, &trans);        if (rc != 0) {                CERROR("Can't create transaction: %d\n", rc);                lstcon_group_put(grp);                return rc;        }        lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);        lstcon_rpc_trans_destroy(trans);        lstcon_group_put(grp);        /* -ref for session, it's destroyed,         * status can't be rolled back, destroy group anway */        lstcon_group_put(grp);        return rc;}intlstcon_group_clean(char *name, int args){        lstcon_group_t *grp = NULL;        int             rc;        rc = lstcon_group_find(name, &grp);        if (rc != 0) {                CDEBUG(D_NET, "Can't find group %s\n", name);                return rc;        }        if (grp->grp_ref > 2) {                /* referred by test */                CDEBUG(D_NET, "Group %s is busy\n", name);                lstcon_group_put(grp);                return -EBUSY;        }        args = (LST_NODE_ACTIVE | LST_NODE_BUSY |                LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;        lstcon_group_drain(grp, args);        lstcon_group_put(grp);        /* release empty group */        if (list_empty(&grp->grp_ndl_list))                lstcon_group_put(grp);        return 0;}intlstcon_nodes_remove(char *name, int count,                    lnet_process_id_t *ids_up, struct list_head *result_up){        lstcon_group_t *grp = NULL;        int             rc;        rc = lstcon_group_find(name, &grp);        if (rc != 0) {                CDEBUG(D_NET, "Can't find group: %s\n", name);                return rc;        }        if (grp->grp_ref > 2) {                /* referred by test */                CDEBUG(D_NET, "Group %s is busy\n", name);                lstcon_group_put(grp);                return -EBUSY;        }        rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);        lstcon_group_put(grp);        /* release empty group */        if (list_empty(&grp->grp_ndl_list))                lstcon_group_put(grp);        return rc;}intlstcon_group_refresh(char *name, struct list_head *result_up){        lstcon_rpc_trans_t      *trans;        lstcon_group_t          *grp;        int                      rc;        rc = lstcon_group_find(name, &grp);        if (rc != 0) {                CDEBUG(D_NET, "Can't find group: %s\n", name);                return rc;        }        if (grp->grp_ref > 2) {                /* referred by test */                CDEBUG(D_NET, "Group %s is busy\n", name);                lstcon_group_put(grp);                return -EBUSY;        }        /* re-invite all inactive nodes int the group */        rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,                                     &grp->grp_trans_list, LST_TRANS_SESNEW,                                     grp, lstcon_sesrpc_condition, &trans);        if (rc != 0) {                /* local error, return */                CDEBUG(D_NET, "Can't create transaction: %d\n", rc);                lstcon_group_put(grp);                return rc;        }        lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);        rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);        lstcon_rpc_trans_destroy(trans);        /* -ref for me */        lstcon_group_put(grp);        return rc;}intlstcon_group_list(int index, int len, char *name_up){        lstcon_group_t *grp;        LASSERT (index >= 0);        LASSERT (name_up != NULL);        list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {                if (index-- == 0) {                        return copy_to_user(name_up, grp->grp_name, len) ?                               -EFAULT : 0;                }        }        return -ENOENT;}static intlstcon_nodes_getent(struct list_head *head, int *index_p,                    int *count_p, lstcon_node_ent_t *dents_up){        lstcon_ndlink_t  *ndl;        lstcon_node_t    *nd;        int               count = 0;        int               index = 0;        LASSERT (index_p != NULL && count_p != NULL);        LASSERT (dents_up != NULL);        LASSERT (*index_p >= 0);        LASSERT (*count_p > 0);        list_for_each_entry(ndl, head, ndl_link) {                if (index++ < *index_p)                        continue;                if (count >= *count_p)                        break;                nd = ndl->ndl_node;                if (copy_to_user(&dents_up[count].nde_id,                                 &nd->nd_id, sizeof(nd->nd_id)) ||                    copy_to_user(&dents_up[count].nde_state,                                 &nd->nd_state, sizeof(nd->nd_state)))                        return -EFAULT;                count ++;        }        if (index <= *index_p)                return -ENOENT;        *count_p = count;        *index_p = index;        return 0;}intlstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,                  int *index_p, int *count_p, lstcon_node_ent_t *dents_up){        lstcon_ndlist_ent_t *gentp;        lstcon_group_t      *grp;        lstcon_ndlink_t     *ndl;        int                  rc;        rc = lstcon_group_find(name, &grp);        if (rc != 0) {                CDEBUG(D_NET, "Can't find group %s\n", name);                return rc;        }        if (dents_up != 0) {                /* verbose query */                rc = lstcon_nodes_getent(&grp->grp_ndl_list,                                         index_p, count_p, dents_up);                lstcon_group_put(grp);                return rc;        }        /* non-verbose query */        LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));        if (gentp == NULL) {                CERROR("Can't allocate ndlist_ent\n");                lstcon_group_put(grp);                return -ENOMEM;        }        memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));        list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)                LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);        rc = copy_to_user(gents_p, gentp,                          sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;        LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));                        lstcon_group_put(grp);        return 0;}intlstcon_batch_find(char *name, lstcon_batch_t **batpp){        lstcon_batch_t   *bat;        list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {                if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {                        *batpp = bat;                        return 0;                }        }        return -ENOENT;}intlstcon_batch_add(char *name){        lstcon_batch_t   *bat;        int               i;        int               rc;        rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;        if (rc != 0) {                CDEBUG(D_NET, "Batch %s already exists\n", name);                return rc;        }        LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));        if (bat == NULL) {                CERROR("Can't allocate descriptor for batch %s\n", name);                return -ENOMEM;        }        LIBCFS_ALLOC(bat->bat_cli_hash,                     sizeof(struct list_head) * LST_NODE_HASHSIZE);        if (bat->bat_cli_hash == NULL) {                CERROR("Can't allocate hash for batch %s\n", name);                LIBCFS_FREE(bat, sizeof(lstcon_batch_t));                return -ENOMEM;        }        LIBCFS_ALLOC(bat->bat_srv_hash,                     sizeof(struct list_head) * LST_NODE_HASHSIZE);        if (bat->bat_srv_hash == NULL) {                CERROR("Can't allocate hash for batch %s\n", name);                LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);                LIBCFS_FREE(bat, sizeof(lstcon_batch_t));                return -ENOMEM;        }        strcpy(bat->bat_name, name);        bat->bat_hdr.tsb_index = 0;        bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;        bat->bat_ntest = 0;        bat->bat_state = LST_BATCH_IDLE;        CFS_INIT_LIST_HEAD(&bat->bat_cli_list);        CFS_INIT_LIST_HEAD(&bat->bat_srv_list);        CFS_INIT_LIST_HEAD(&bat->bat_test_list);        CFS_INIT_LIST_HEAD(&bat->bat_trans_list);        for (i = 0; i < LST_NODE_HASHSIZE; i++) {                CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);                CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);        }        list_add_tail(&bat->bat_link, &console_session.ses_bat_list);        return rc;}intlstcon_batch_list(int index, int len, char *name_up){        lstcon_batch_t    *bat;        LASSERT (name_up != NULL);        LASSERT (index >= 0);        list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {                if (index-- == 0) {                        return copy_to_user(name_up,bat->bat_name, len) ?                               -EFAULT: 0;                }        }        return -ENOENT;}intlstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,                  int testidx, int *index_p, int *ndent_p,                  lstcon_node_ent_t *dents_up){        lstcon_test_batch_ent_t *entp;        struct list_head        *clilst;        struct list_head        *srvlst;        lstcon_test_t           *test = NULL;        lstcon_batch_t          *bat;        lstcon_ndlink_t         *ndl;        int                      rc;        rc = lstcon_batch_find(name, &bat);        if (rc != 0) {                CDEBUG(D_NET, "Can't find batch %s\n", name);                return -ENOENT;        }        if (testidx > 0) {                /* query test, test index start from 1 */                list_for_each_entry(test, &bat->bat_test_list, tes_link) {                        if (testidx-- == 1)                                break;                }                if (testidx > 0) {                        CDEBUG(D_NET, "Can't find specified test in batch\n");                        return -ENOENT;                }        }        clilst = (test == NULL) ? &bat->bat_cli_list :                                  &test->tes_src_grp->grp_ndl_list;        srvlst = (test == NULL) ? &bat->bat_srv_list :                                  &test->tes_dst_grp->grp_ndl_list;        if (dents_up != NULL) {                rc = lstcon_nodes_getent((server ? srvlst: clilst),                                         index_p, ndent_p, dents_up);                return rc;        }        /* non-verbose query */        LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));        if (entp == NULL)                return -ENOMEM;        memset(entp, 0, sizeof(lstcon_test_batch_ent_t));        if (test == NULL) {                entp->u.tbe_batch.bae_ntest = bat->bat_ntest;                entp->u.tbe_batch.bae_state = bat->bat_state;        } else {                entp->u.tbe_test.tse_type   = test->tes_type;                entp->u.tbe_test.tse_loop   = test->tes_loop;                entp->u.tbe_test.tse_concur = test->tes_concur;        }        list_for_each_entry(ndl, clilst, ndl_link)                LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);        list_for_each_entry(ndl, srvlst, ndl_link)                LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);        rc = copy_to_user(ent_up, entp,                          sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;        LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));        return rc;}intlstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg){        switch (transop) {        case LST_TRANS_TSBRUN:                if (nd->nd_state != LST_NODE_ACTIVE)                        return -ENETDOWN;                break;        case LST_TRANS_TSBSTOP:                if (nd->nd_state != LST_NODE_ACTIVE)                        return 0;                break;        case LST_TRANS_TSBCLIQRY:        case LST_TRANS_TSBSRVQRY:                break;        }        return 1;}static intlstcon_batch_op(lstcon_batch_t *bat, int transop, struct list_head *result_up){        lstcon_rpc_trans_t *trans;        int                 rc;        rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -