Whamcloud - gitweb
LU-7734 lnet: Update lnetctl usage
[fs/lustre-release.git] / lnet / utils / lnetctl.c
index cbbd33e..2707787 100644 (file)
@@ -135,16 +135,18 @@ command_t set_cmds[] = {
 
 command_t peer_cmds[] = {
        {"add", jt_add_peer_nid, 0, "add a peer NID\n"
-        "\t--key_nid: NID to identify peer. If not provided then the first\n"
-        "\t           NID in the list becomes the key NID of a newly created\n"
-        "\t           peer. \n"
-        "\t--nid: one or more peer NIDs\n"},
+        "\t--prim_nid: Primary NID of the peer. If not provided then the first\n"
+        "\t            NID in the list becomes the Primary NID of a newly created\n"
+        "\t            peer. \n"
+        "\t--nid: one or more peer NIDs\n"
+        "\t--non_mr: create this peer as not Multi-Rail capable\n"},
        {"del", jt_del_peer_nid, 0, "delete a peer NID\n"
-        "\t--key_nid: NID to identify peer.\n"
+        "\t--prim_nid: Primary NID of the peer.\n"
         "\t--nid: list of NIDs to remove. If none provided,\n"
         "\t       peer is deleted\n"},
-       {"show", jt_show_peer, 0, "show peer credits\n"
-        "\t--primary_nid: NID of peer to filter on.\n"},
+       {"show", jt_show_peer, 0, "show peer information\n"
+        "\t--nid: NID of peer to filter on.\n"
+        "\t--verbose: Include  extended  statistics\n"},
        { 0, 0, 0, NULL }
 };
 
@@ -467,7 +469,7 @@ static int jt_add_ni(int argc, char **argv)
        char *ip2net = NULL;
        long int pto = -1, pc = -1, pbc = -1, cre = -1;
        struct cYAML *err_rc = NULL;
-       int rc, opt, num_global_cpts = 0;
+       int rc, opt, cpt_rc = -1;
        struct lnet_dlc_network_descr nw_descr;
        struct cfs_expr_list *global_cpts = NULL;
        struct lnet_ioctl_config_lnd_tunables tunables;
@@ -541,10 +543,9 @@ static int jt_add_ni(int argc, char **argv)
                        }
                        break;
                case 's':
-                       num_global_cpts =
-                               cfs_expr_list_parse(optarg,
-                                                strlen(optarg),
-                                                0, UINT_MAX, &global_cpts);
+                       cpt_rc = cfs_expr_list_parse(optarg,
+                                                    strlen(optarg), 0,
+                                                    UINT_MAX, &global_cpts);
                        break;
                case 'h':
                        print_help(net_cmds, "net", "add");
@@ -563,7 +564,7 @@ static int jt_add_ni(int argc, char **argv)
        }
 
        rc = lustre_lnet_config_ni(&nw_descr,
-                                  (num_global_cpts > 0) ? global_cpts: NULL,
+                                  (cpt_rc == 0) ? global_cpts: NULL,
                                   ip2net, (found) ? &tunables : NULL,
                                   -1, &err_rc);
 
@@ -1002,8 +1003,7 @@ static int jt_import(int argc, char **argv)
                break;
        }
 
-       if (rc != LUSTRE_CFG_RC_NO_ERR)
-               cYAML_print_tree2file(stderr, err_rc);
+       cYAML_print_tree2file(stderr, err_rc);
 
        cYAML_free_tree(err_rc);
 
@@ -1062,6 +1062,18 @@ static int jt_export(int argc, char **argv)
                cYAML_free_tree(err_rc);
        }
 
+       rc = lustre_lnet_show_peer(NULL, 1, -1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               cYAML_free_tree(err_rc);
+       }
+
+       rc = lustre_lnet_show_numa_range(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               cYAML_free_tree(err_rc);
+       }
+
        if (show_rc != NULL) {
                cYAML_print_tree2file(f, show_rc);
                cYAML_free_tree(show_rc);
@@ -1075,18 +1087,18 @@ static int jt_export(int argc, char **argv)
 
 static int jt_add_peer_nid(int argc, char **argv)
 {
-       char *key_nid = NULL;
-       char *nid[LNET_MAX_INTERFACES] = {NULL};
-       int idx = 0;
+       char *prim_nid = NULL;
+       char **nids = NULL, **nids2 = NULL;
+       int size = 0;
        struct cYAML *err_rc = NULL;
-       int rc, opt;
+       int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
        bool non_mr = false;
 
        const char *const short_options = "k:n:mh";
        const struct option long_options[] = {
-               { "key_nid", 1, NULL, 'k' },
+               { "prim_nid", 1, NULL, 'k' },
                { "nid", 1, NULL, 'n' },
-               { "non_mr", 1, NULL, 'm'},
+               { "non_mr", 0, NULL, 'm'},
                { "help", 0, NULL, 'h' },
                { NULL, 0, NULL, 0 },
        };
@@ -1095,29 +1107,19 @@ static int jt_add_peer_nid(int argc, char **argv)
                                  long_options, NULL)) != -1) {
                switch (opt) {
                case 'k':
-                       key_nid = optarg;
+                       prim_nid = optarg;
                        break;
                case 'n':
-                       if (idx >= LNET_MAX_INTERFACES) {
-                               cYAML_build_error(-1, -1, "peer_ni", "add",
-                                                 "too many interfaces",
-                                                 &err_rc);
-                               rc = LUSTRE_CFG_RC_BAD_PARAM;
-                               goto failed;
-                       }
-                       nid[idx] = calloc(strlen(optarg) + 1, 1);
-                       if (nid[idx] == NULL) {
-                               cYAML_build_error(-1, -1, "peer_ni", "add",
-                                                 "out of memory",
-                                                 &err_rc);
-                               rc = LUSTRE_CFG_RC_BAD_PARAM;
+                       size = lustre_lnet_parse_nids(optarg, nids, size,
+                                                     &nids2);
+                       if (nids2 == NULL)
                                goto failed;
-                       }
-                       strncpy(nid[idx], optarg, strlen(optarg));
-                       idx++;
+                       nids = nids2;
+                       rc = LUSTRE_CFG_RC_OUT_OF_MEM;
                        break;
                case 'm':
                        non_mr = true;
+                       break;
                case 'h':
                        print_help(peer_cmds, "peer", "add");
                        return 0;
@@ -1126,14 +1128,13 @@ static int jt_add_peer_nid(int argc, char **argv)
                }
        }
 
-       rc = lustre_lnet_config_peer_nid(key_nid, nid, !non_mr, -1, &err_rc);
+       rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
+                                        !non_mr, -1, &err_rc);
 
 failed:
-       idx = 0;
-       while (nid[idx] != NULL) {
-               free(nid[idx]);
-               idx++;
-       }
+       for (i = 0; i < size; i++)
+               free(nids[i]);
+       free(nids);
 
        if (rc != LUSTRE_CFG_RC_NO_ERR)
                cYAML_print_tree2file(stderr, err_rc);
@@ -1145,15 +1146,14 @@ failed:
 
 static int jt_del_peer_nid(int argc, char **argv)
 {
-       char *key_nid = NULL;
-       char *nid[LNET_MAX_INTERFACES] = {NULL};
-       int idx = 0;
+       char *prim_nid = NULL;
+       char **nids = NULL, **nids2 = NULL;
        struct cYAML *err_rc = NULL;
-       int rc, opt;
+       int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
 
        const char *const short_options = "k:n:h";
        const struct option long_options[] = {
-               { "key_nid", 1, NULL, 'k' },
+               { "prim_nid", 1, NULL, 'k' },
                { "nid", 1, NULL, 'n' },
                { "help", 0, NULL, 'h' },
                { NULL, 0, NULL, 0 },
@@ -1163,26 +1163,15 @@ static int jt_del_peer_nid(int argc, char **argv)
                                  long_options, NULL)) != -1) {
                switch (opt) {
                case 'k':
-                       key_nid = optarg;
+                       prim_nid = optarg;
                        break;
                case 'n':
-                       if (idx >= LNET_MAX_INTERFACES) {
-                               cYAML_build_error(-1, -1, "peer_ni", "del",
-                                                 "too many interfaces",
-                                                 &err_rc);
-                               rc = LUSTRE_CFG_RC_BAD_PARAM;
-                               goto failed;
-                       }
-                       nid[idx] = calloc(strlen(optarg) + 1, 1);
-                       if (nid[idx] == NULL) {
-                               cYAML_build_error(-1, -1, "peer_ni", "del",
-                                                 "out of memory",
-                                                 &err_rc);
-                               rc = LUSTRE_CFG_RC_BAD_PARAM;
+                       size = lustre_lnet_parse_nids(optarg, nids, size,
+                                                     &nids2);
+                       if (nids2 == NULL)
                                goto failed;
-                       }
-                       strncpy(nid[idx], optarg, strlen(optarg));
-                       idx++;
+                       nids = nids2;
+                       rc = LUSTRE_CFG_RC_OUT_OF_MEM;
                        break;
                case 'h':
                        print_help(peer_cmds, "peer", "del");
@@ -1192,9 +1181,13 @@ static int jt_del_peer_nid(int argc, char **argv)
                }
        }
 
-       rc = lustre_lnet_del_peer_nid(key_nid, nid, -1, &err_rc);
+       rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
 
 failed:
+       for (i = 0; i < size; i++)
+               free(nids[i]);
+       free(nids);
+
        if (rc != LUSTRE_CFG_RC_NO_ERR)
                cYAML_print_tree2file(stderr, err_rc);
 
@@ -1205,13 +1198,15 @@ failed:
 
 static int jt_show_peer(int argc, char **argv)
 {
-       char *key_nid = NULL;
+       char *nid = NULL;
        int rc, opt;
        struct cYAML *err_rc = NULL, *show_rc = NULL;
+       int detail = 0;
 
-       const char *const short_options = "k:vh";
+       const char *const short_options = "n:vh";
        const struct option long_options[] = {
-               { "key_nid", 1, NULL, 'k' },
+               { "nid", 1, NULL, 'n' },
+               { "verbose", 0, NULL, 'v' },
                { "help", 0, NULL, 'h' },
                { NULL, 0, NULL, 0 },
        };
@@ -1219,18 +1214,21 @@ static int jt_show_peer(int argc, char **argv)
        while ((opt = getopt_long(argc, argv, short_options,
                                  long_options, NULL)) != -1) {
                switch (opt) {
-               case 'k':
-                       key_nid = optarg;
+               case 'n':
+                       nid = optarg;
+                       break;
+               case 'v':
+                       detail = 1;
                        break;
                case 'h':
-                       print_help(peer_cmds, "peer", "add");
+                       print_help(peer_cmds, "peer", "show");
                        return 0;
                default:
                        return 0;
                }
        }
 
-       rc = lustre_lnet_show_peer(key_nid, -1, &show_rc, &err_rc);
+       rc = lustre_lnet_show_peer(nid, detail, -1, &show_rc, &err_rc);
 
        if (rc != LUSTRE_CFG_RC_NO_ERR)
                cYAML_print_tree2file(stderr, err_rc);