lst.c

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

C
2,162
字号
        return rc;                }intlst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,                     struct list_head *resultp){               lstio_group_nodes_args_t        args = {                .lstio_grp_key          = session_key,                .lstio_grp_nmlen        = strlen(name),                .lstio_grp_namep        = name,                .lstio_grp_count        = count,                .lstio_grp_idsp         = ids,                .lstio_grp_resultp      = resultp,        };        return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));}intlst_add_group_ioctl (char *name){        lstio_group_add_args_t  args = {                .lstio_grp_key          = session_key,                .lstio_grp_nmlen        = strlen(name),                .lstio_grp_namep        = name,        };        return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));}intjt_lst_add_group(int argc, char **argv){        struct list_head   head;        lnet_process_id_t *ids;        char              *name;        int                count;        int                rc;        int                i;        if (session_key == 0) {                fprintf(stderr,                        "Can't find env LST_SESSION or value is not valid\n");                return -1;        }        if (argc < 3) {                lst_print_usage(argv[0]);                return -1;        }        name = argv[1];        if (strlen(name) >= LST_NAME_SIZE) {                fprintf(stderr, "Name length is limited to %d\n",                        LST_NAME_SIZE - 1);                return -1;        }        rc = lst_add_group_ioctl(name);        if (rc != 0) {                lst_print_error("group", "Failed to add group %s: %s\n",                                name, strerror(errno));                return -1;        }        CFS_INIT_LIST_HEAD(&head);        for (i = 2; i < argc; i++) {                /* parse address list */                rc = lst_parse_nids(argv[i], &count, &ids);                if (rc < 0) {                        fprintf(stderr, "Ignore invalid id list %s\n",                                argv[i]);                        continue;                }                if (count == 0)                        continue;                rc = lst_alloc_rpcent(&head, count, 0);                if (rc != 0) {                        fprintf(stderr, "Out of memory\n");                        break;                }                rc = lst_add_nodes_ioctl(name, count, ids, &head);                free(ids);                if (rc == 0) {                        lst_free_rpcent(&head);                        fprintf(stderr, "%s are added to session\n", argv[i]);                        continue;                }                if (rc == -1) {                        lst_free_rpcent(&head);                        lst_print_error("group", "Failed to add nodes %s: %s\n",                                        argv[i], strerror(errno));                        break;                }                lst_print_transerr(&head, "create session");                lst_free_rpcent(&head);        }        return rc;}intlst_del_group_ioctl (char *name){        lstio_group_del_args_t  args = {                .lstio_grp_key          = session_key,                .lstio_grp_nmlen        = strlen(name),                .lstio_grp_namep        = name,        };        return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));}intjt_lst_del_group(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;        }        if (argc != 2) {                lst_print_usage(argv[0]);                return -1;        }        rc = lst_del_group_ioctl(argv[1]);        if (rc == 0) {                fprintf(stdout, "Group is deleted\n");                return 0;        }        if (rc == -1) {                lst_print_error("group", "Failed to delete group: %s\n",                                strerror(errno));                return rc;        }        fprintf(stderr, "Group is deleted with some errors\n");        if (trans_stat.trs_rpc_errno != 0) {                fprintf(stderr, "[RPC] Failed to send %d end 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 -1;}intlst_update_group_ioctl(int opc, char *name, int clean, int count,                       lnet_process_id_t *ids, struct list_head *resultp){        lstio_group_update_args_t  args = {                .lstio_grp_key          = session_key,                .lstio_grp_opc          = opc,                .lstio_grp_args         = clean,                .lstio_grp_nmlen        = strlen(name),                .lstio_grp_namep        = name,                .lstio_grp_count        = count,                .lstio_grp_idsp         = ids,                .lstio_grp_resultp      = resultp,        };        return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));}intjt_lst_update_group(int argc, char **argv){        struct list_head   head;        lnet_process_id_t *ids = NULL;        char              *str = NULL;        char              *grp = NULL;        int                optidx = 0;        int                count = 0;        int                clean = 0;        int                opc = 0;        int                rc;        int                c;        static struct option update_group_opts[] =        {                {"refresh", no_argument,       0, 'f' },                {"clean",   required_argument, 0, 'c' },                {"remove",  required_argument, 0, 'r' },                {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, "fc:r:",                                update_group_opts, &optidx);                /* Detect the end of the options. */                if (c == -1)                        break;                        switch (c) {                case 'f':                        if (opc != 0) {                                lst_print_usage(argv[0]);                                return -1;                        }                        opc = LST_GROUP_REFRESH;                        break;                case 'r':                        if (opc != 0) {                                lst_print_usage(argv[0]);                                return -1;                        }                        opc = LST_GROUP_RMND;                        str = optarg;                        break;                case 'c':                        clean = lst_node_str2state(optarg);                        if (opc != 0 || clean <= 0) {                                lst_print_usage(argv[0]);                                return -1;                        }                        opc = LST_GROUP_CLEAN;                        break;                default:                        lst_print_usage(argv[0]);                        return -1;                }        }        /* no OPC or group is specified */        if (opc == 0 || optind != argc - 1) {                lst_print_usage(argv[0]);                return -1;        }        grp = argv[optind];        CFS_INIT_LIST_HEAD(&head);        if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {                rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :                                                                LST_OPC_GROUP,                                        opc == LST_GROUP_RMND ? str : grp,                                        &count, &ids);                if (rc != 0) {                        fprintf(stderr, "Can't get count of nodes from %s: %s\n",                                opc == LST_GROUP_RMND ? str : grp,                                strerror(errno));                        return -1;                }                rc = lst_alloc_rpcent(&head, count, 0);                if (rc != 0) {                        fprintf(stderr, "Out of memory\n");                        free(ids);                        return -1;                }        }         rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);        if (ids != NULL)                free(ids);        if (rc == 0) {                lst_free_rpcent(&head);                return 0;        }        if (rc == -1) {                lst_free_rpcent(&head);                lst_print_error("group", "Failed to update group: %s\n",                                strerror(errno));                return rc;        }        lst_print_transerr(&head, "Updating group");        lst_free_rpcent(&head);        return rc;}intlst_list_group_ioctl(int len, char *name, int idx){        lstio_group_list_args_t         args = {                .lstio_grp_key          = session_key,                .lstio_grp_idx          = idx,                .lstio_grp_nmlen        = len,                .lstio_grp_namep        = name,        };        return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));}intlst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,                     int *idx, int *count, lstcon_node_ent_t *dents){        lstio_group_info_args_t         args = {                .lstio_grp_key          = session_key,                .lstio_grp_nmlen        = strlen(name),                .lstio_grp_namep        = name,                .lstio_grp_entp         = gent,                .lstio_grp_idxp         = idx,                .lstio_grp_ndentp       = count,                .lstio_grp_dentsp       = dents,        };        return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));}intlst_list_group_all(void){        char  name[LST_NAME_SIZE];        int   rc;        int   i;        /* no group is specified, list name of all groups */        for (i = 0; ; i++) {                rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);                if (rc == 0) {                        fprintf(stdout, "%d) %s\n", i + 1, name);                        continue;                }                if (errno == ENOENT)                         break;                lst_print_error("group", "Failed to list group: %s\n",                                strerror(errno));                return -1;        }        fprintf(stdout, "Total %d groups\n", i);        return 0;}#define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"intjt_lst_list_group(int argc, char **argv){        lstcon_ndlist_ent_t  gent;        lstcon_node_ent_t   *dents;        int               optidx  = 0;        int               verbose = 0;        int               active  = 0;        int               busy    = 0;        int               down    = 0;        int               unknown = 0;        int               all     = 0;        int               count;        int               index;        int               i;        int               j;        int               c;        int               rc = 0;        static struct option list_group_opts[] =        {                {"active",  no_argument, 0, 'a' },                {"busy",    no_argument, 0, 'b' },                {"down",    no_argument, 0, 'd' },                {"unknown", no_argument, 0, 'u' },                {"all",     no_argument, 0, 'l' },                {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, "abdul",                                list_group_opts, &optidx);                if (c == -1)                        break;                        switch (c) {                case 'a':                        verbose = active = 1;                        all = 0;                        break;                case 'b':                        verbose = busy = 1;                        all = 0;                        break;                case 'd':                        verbose = down = 1;                        all = 0;                        break;                case 'u':                        verbose = unknown = 1;                        all = 0;                        break;                case 'l':                        verbose = all = 1;

⌨️ 快捷键说明

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