lst.c

来自「lustre 1.6.5 source code」· C语言 代码 · 共 2,162 行 · 第 1/5 页

C
2,162
字号
}int lst_info_batch_ioctl(char *batch, int test, int server,                        lstcon_test_batch_ent_t *entp, int *idxp,                        int *ndentp, lstcon_node_ent_t *dentsp);int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,                         int *idx, int *count, lstcon_node_ent_t *dents);int lst_query_batch_ioctl(char *batch, int test, int server,                          int timeout, struct list_head *head);intlst_ioctl(unsigned int opc, void *buf, int len){        struct libcfs_ioctl_data data;        int    rc;        LIBCFS_IOC_INIT (data);        data.ioc_u32[0]  = opc;        data.ioc_plen1   = len;        data.ioc_pbuf1   = (char *)buf;        data.ioc_plen2   = sizeof(trans_stat);        data.ioc_pbuf2   = (char *)&trans_stat;        memset(&trans_stat, 0, sizeof(trans_stat));        rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);        /* local error, no valid RPC result */        if (rc != 0)                return -1;        /* RPC error */        if (trans_stat.trs_rpc_errno != 0)                return -2;        /* Framework error */        if (trans_stat.trs_fwk_errno != 0)                return -3;        return 0;}intlst_new_session_ioctl (char *name, int timeout, int force, lst_sid_t *sid){	lstio_session_new_args_t        args = {                .lstio_ses_key          = session_key,                .lstio_ses_timeout      = timeout,                .lstio_ses_force        = force,                .lstio_ses_idp          = sid,                .lstio_ses_namep        = name,                .lstio_ses_nmlen        = strlen(name),        };        return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));}intjt_lst_new_session(int argc,  char **argv){        char  buf[LST_NAME_SIZE];        char *name;        int   optidx  = 0;        int   timeout = 300;        int   force   = 0;        int   c;        int   rc;        static struct option session_opts[] =        {                {"timeout", required_argument,  0, 't' },                {"force",   no_argument,        0, 'f' },                {0,         0,                  0,  0  }        };        if (session_key == 0) {                fprintf(stderr,                        "Can't find env LST_SESSION or value is not valid\n");                return -1;        }        while (1) {                c = getopt_long(argc, argv, "ft:",                                session_opts, &optidx);                if (c == -1)                        break;                        switch (c) {                case 'f':                        force = 1;                        break;                case 't':                        timeout = atoi(optarg);                        break;                default:                        lst_print_usage(argv[0]);                        return -1;                }        }        if (timeout <= 0) {                fprintf(stderr, "Invalid timeout value\n");                return -1;        }        if (optind == argc - 1) {                name = argv[optind ++];                if (strlen(name) >= LST_NAME_SIZE) {                        fprintf(stderr, "Name size is limited to %d\n",                                LST_NAME_SIZE - 1);                        return -1;                }        } else if (optind == argc) {                char           user[LST_NAME_SIZE];                char           host[LST_NAME_SIZE];                struct passwd *pw = getpwuid(getuid());                if (pw == NULL)                        snprintf(user, sizeof(user), "%d", (int)getuid());                else                        snprintf(user, sizeof(user), "%s", pw->pw_name);                rc = gethostname(host, sizeof(host));                if (rc != 0)                        snprintf(host, sizeof(host), "unknown_host");                snprintf(buf, LST_NAME_SIZE, "%s@%s", user, host);                name = buf;        } else {                 lst_print_usage(argv[0]);                return -1;        }        rc = lst_new_session_ioctl(name, timeout, force, &session_id);        if (rc != 0) {                lst_print_error("session", "Failed to create session: %s\n",                                strerror(errno));                return rc;        }        fprintf(stdout, "SESSION: %s TIMEOUT: %d FORCE: %s\n",                name, timeout, force ? "Yes": "No");        return rc;}intlst_session_info_ioctl(char *name, int len, int *key,                       lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo){        lstio_session_info_args_t args = {                .lstio_ses_keyp         = key,                .lstio_ses_idp          = sid,                .lstio_ses_ndinfo       = ndinfo,                .lstio_ses_nmlen        = len,                .lstio_ses_namep        = name,        };        return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));}intjt_lst_show_session(int argc, char **argv){        lstcon_ndlist_ent_t ndinfo;        lst_sid_t           sid;        char                name[LST_NAME_SIZE];        int                 key;        int                 rc;        rc = lst_session_info_ioctl(name, LST_NAME_SIZE, &key, &sid, &ndinfo);        if (rc != 0) {                lst_print_error("session", "Failed to show session: %s\n",                                strerror(errno));                return -1;        }        fprintf(stdout, "%s ID: %Lu@%s, KEY: %d NODES: %d\n",                name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),                key, ndinfo.nle_nnode);        return 0;}intlst_end_session_ioctl(void){        lstio_session_end_args_t args = {                .lstio_ses_key           = session_key,        };        return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));}intjt_lst_end_session(int argc, char **argv){        int             rc;        if (session_key == 0) {                fprintf(stderr,                        "Can't find env LST_SESSION or value is not valid\n");                return -1;        }        rc = lst_end_session_ioctl();        if (rc == 0) {                fprintf(stdout, "session is ended\n");                return 0;        }        if (rc == -1) {                lst_print_error("session", "Failed to end session: %s\n",                                strerror(errno));                return rc;        }        if (trans_stat.trs_rpc_errno != 0) {                fprintf(stderr,                        "[RPC] Failed to send %d session RPCs: %s\n",                        lstcon_rpc_stat_failure(&trans_stat, 0),                        strerror(trans_stat.trs_rpc_errno));        }        if (trans_stat.trs_fwk_errno != 0) {                fprintf(stderr,                        "[FWK] Failed to end session on %d nodes: %s\n",                        lstcon_sesop_stat_failure(&trans_stat, 0),                        strerror(trans_stat.trs_fwk_errno));        }        return rc;}intlst_ping_ioctl(char *str, int type, int timeout,                int count, lnet_process_id_t *ids, struct list_head *head){        lstio_debug_args_t args = {                .lstio_dbg_key          = session_key,                .lstio_dbg_type         = type,                .lstio_dbg_flags        = 0,                .lstio_dbg_timeout      = timeout,                .lstio_dbg_nmlen        = (str == NULL) ? 0: strlen(str),                .lstio_dbg_namep        = str,                .lstio_dbg_count        = count,                .lstio_dbg_idsp         = ids,                .lstio_dbg_resultp      = head,        };        return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));}intlst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp){        char                    buf[LST_NAME_SIZE];        lstcon_test_batch_ent_t ent;        lstcon_ndlist_ent_t    *entp = &ent.tbe_cli_nle;        lst_sid_t               sid;        int                     key;        int                     rc;        switch (type) {        case LST_OPC_SESSION:                rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,                                            &key, &sid, entp);                break;        case LST_OPC_BATCHSRV:                entp = &ent.tbe_srv_nle;        case LST_OPC_BATCHCLI:                rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);                break;                        case LST_OPC_GROUP:                rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);                break;        case LST_OPC_NODES:                rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;                break;        default:                rc = -1;                break;        }        if (rc == 0)                 *countp = entp->nle_nnode;        return rc;}intjt_lst_ping(int argc,  char **argv){        struct list_head   head;        lnet_process_id_t *ids = NULL;        lstcon_rpc_ent_t  *ent = NULL;        char              *str = NULL;        int                optidx  = 0;        int                server  = 0;        int                timeout = 5;        int                count   = 0;        int                type    = 0;        int                rc      = 0;        int                c;        static struct option ping_opts[] =        {                {"session", no_argument,       0, 's' },                {"server",  no_argument,       0, 'v' },                {"batch",   required_argument, 0, 'b' },                {"group",   required_argument, 0, 'g' },                {"nodes",   required_argument, 0, 'n' },                {"timeout", required_argument, 0, 't' },                {0,         0,                 0,  0  }        };        if (session_key == 0) {                fprintf(stderr,                        "Can't find env LST_SESSION or value is not valid\n");                return -1;        }        while (1) {                c = getopt_long(argc, argv, "g:b:n:t:sv",                                ping_opts, &optidx);                if (c == -1)                        break;                        switch (c) {                case 's':                        type = LST_OPC_SESSION;                        break;                case 'g':                        type = LST_OPC_GROUP;                        str = optarg;                        break;                case 'b':                        type = LST_OPC_BATCHCLI;                        str = optarg;                        break;                case 'n':                        type = LST_OPC_NODES;                        str = optarg;                        break;                case 't':                        timeout = atoi(optarg);                        break;                case 'v':                        server = 1;                        break;                default:                        lst_print_usage(argv[0]);                        return -1;                }        }        if (type == 0 || timeout <= 0 || optind != argc) {                lst_print_usage(argv[0]);                return -1;        }        if (type == LST_OPC_BATCHCLI && server)                type = LST_OPC_BATCHSRV;        rc = lst_get_node_count(type, str, &count, &ids);        if (rc < 0) {                fprintf(stderr, "Failed to get count of nodes from %s: %s\n",                        (str == NULL) ? "session" : str, strerror(errno));                return -1;        }        CFS_INIT_LIST_HEAD(&head);        rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);        if (rc != 0) {                fprintf(stderr, "Out of memory\n");                goto out;        }        if (count == 0) {                fprintf(stdout, "Target %s is empty\n",                        (str == NULL) ? "session" : str);                goto out;        }        rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);        if (rc == -1) { /* local failure */                lst_print_error("debug", "Failed to ping %s: %s\n",                                (str == NULL) ? "session" : str,                                strerror(errno));                rc = -1;                goto out;        }        /* ignore RPC errors and framwork errors */        list_for_each_entry(ent, &head, rpe_link) {                fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",                        libcfs_id2str(ent->rpe_peer),                        lst_node_state2str(ent->rpe_state),                        (ent->rpe_state == LST_NODE_ACTIVE ||                         ent->rpe_state == LST_NODE_BUSY)?                                 (ent->rpe_rpc_errno == 0 ?                                         &ent->rpe_payload[0] : "Unknown") :                                 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));        }out:        lst_free_rpcent(&head);        if (ids != NULL)                free(ids);

⌨️ 快捷键说明

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