Whamcloud - gitweb
LU-9120 lnet: remove obsolete health functions
[fs/lustre-release.git] / lnet / utils / lnetctl.c
index cfd16fe..e14d43e 100644 (file)
@@ -18,7 +18,7 @@
  *
  * LGPL HEADER END
  *
- * Copyright (c) 2014, 2016, Intel Corporation.
+ * Copyright (c) 2014, 2017, Intel Corporation.
  *
  * Author:
  *   Amir Shehata <amir.shehata@intel.com>
@@ -183,11 +183,13 @@ command_t peer_cmds[] = {
         "\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"},
+        "\t--non_mr: create this peer as not Multi-Rail capable\n"
+        "\t--ip2nets: specify a range of nids per peer"},
        {"del", jt_del_peer_nid, 0, "delete a peer NID\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"},
+        "\t       peer is deleted\n"
+        "\t--ip2nets: specify a range of nids per peer"},
        {"show", jt_show_peer, 0, "show peer information\n"
         "\t--nid: NID of peer to filter on.\n"
         "\t--verbose: display detailed output per peer."
@@ -843,7 +845,7 @@ static int jt_show_route(int argc, char **argv)
        }
 
        rc = lustre_lnet_show_route(network, gateway, hop, prio, detail, -1,
-                                   &show_rc, &err_rc);
+                                   &show_rc, &err_rc, false);
 
        if (rc != LUSTRE_CFG_RC_NO_ERR)
                cYAML_print_tree2file(stderr, err_rc);
@@ -893,7 +895,8 @@ static int jt_show_net(int argc, char **argv)
                }
        }
 
-       rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc);
+       rc = lustre_lnet_show_net(network, (int) detail, -1, &show_rc, &err_rc,
+                                 false);
 
        if (rc != LUSTRE_CFG_RC_NO_ERR)
                cYAML_print_tree2file(stderr, err_rc);
@@ -915,7 +918,7 @@ static int jt_show_routing(int argc, char **argv)
        if (rc)
                return rc;
 
-       rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
+       rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, false);
 
        if (rc != LUSTRE_CFG_RC_NO_ERR)
                cYAML_print_tree2file(stderr, err_rc);
@@ -1165,32 +1168,44 @@ static int jt_export(int argc, char **argv)
        int rc;
        FILE *f = NULL;
        int opt;
+       bool backup = false;
+       char *file = NULL;
 
-       const char *const short_options = "h";
+       const char *const short_options = "bh";
        static const struct option long_options[] = {
+               { .name = "backup", .has_arg = no_argument, .val = 'b' },
                { .name = "help", .has_arg = no_argument, .val = 'h' },
                { .name = NULL } };
 
        while ((opt = getopt_long(argc, argv, short_options,
                                   long_options, NULL)) != -1) {
                switch (opt) {
+               case 'b':
+                       backup = true;
+                       break;
                case 'h':
+               default:
                        printf("export > FILE.yaml : export configuration\n"
+                              "\t--backup: export only what's necessary for reconfig\n"
                               "\t--help: display this help\n");
                        return 0;
-               default:
-                       return 0;
                }
        }
 
-       if (argc >= 2) {
-               f = fopen(argv[1], "w");
+       if (backup && argc >= 3)
+               file = argv[2];
+       else if (!backup && argc >= 2)
+               file = argv[1];
+       else
+               f = stdout;
+
+       if (file) {
+               f = fopen(file, "w");
                if (f == NULL)
                        return -1;
-       } else
-               f = stdout;
+       }
 
-       rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc);
+       rc = lustre_lnet_show_net(NULL, 2, -1, &show_rc, &err_rc, backup);
        if (rc != LUSTRE_CFG_RC_NO_ERR) {
                cYAML_print_tree2file(stderr, err_rc);
                cYAML_free_tree(err_rc);
@@ -1198,21 +1213,21 @@ static int jt_export(int argc, char **argv)
        }
 
        rc = lustre_lnet_show_route(NULL, NULL, -1, -1, 1, -1, &show_rc,
-                                   &err_rc);
+                                   &err_rc, backup);
        if (rc != LUSTRE_CFG_RC_NO_ERR) {
                cYAML_print_tree2file(stderr, err_rc);
                cYAML_free_tree(err_rc);
                err_rc = NULL;
        }
 
-       rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc);
+       rc = lustre_lnet_show_routing(-1, &show_rc, &err_rc, backup);
        if (rc != LUSTRE_CFG_RC_NO_ERR) {
                cYAML_print_tree2file(stderr, err_rc);
                cYAML_free_tree(err_rc);
                err_rc = NULL;
        }
 
-       rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc);
+       rc = lustre_lnet_show_peer(NULL, 2, -1, &show_rc, &err_rc, backup);
        if (rc != LUSTRE_CFG_RC_NO_ERR) {
                cYAML_print_tree2file(stderr, err_rc);
                cYAML_free_tree(err_rc);
@@ -1259,26 +1274,50 @@ static int jt_add_peer_nid(int argc, char **argv)
        struct cYAML *err_rc = NULL;
        int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
        bool non_mr = false;
-
-       const char *const short_options = "k:n:m";
-       const struct option long_options[] = {
-               { "prim_nid", 1, NULL, 'k' },
-               { "nid", 1, NULL, 'n' },
-               { "non_mr", 0, NULL, 'm'},
-               { NULL, 0, NULL, 0 },
-       };
+       bool ip2nets = false, nid_list = false, prim_nid_present = false;
+
+       const char *const short_opts = "k:mn:";
+       const struct option long_opts[] = {
+       { .name = "prim_nid",   .has_arg = required_argument,   .val = 'k' },
+       { .name = "non_mr",     .has_arg = no_argument,         .val = 'm' },
+       { .name = "nid",        .has_arg = required_argument,   .val = 'n' },
+       { .name = "ip2nets",    .has_arg = required_argument,   .val = 'i' },
+       { .name = NULL } };
 
        rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
        if (rc)
                return rc;
 
-       while ((opt = getopt_long(argc, argv, short_options,
-                                 long_options, NULL)) != -1) {
+       while ((opt = getopt_long(argc, argv, short_opts,
+                                 long_opts, NULL)) != -1) {
                switch (opt) {
                case 'k':
+                       prim_nid_present = true;
+                       if (ip2nets) {
+                               cYAML_build_error(-1, -1, "peer", "add",
+                                               "ip2nets can not be specified"
+                                               " along side prim_nid parameter.",
+                                               &err_rc);
+                               goto failed;
+                       }
                        prim_nid = optarg;
                        break;
+               case 'i':
                case 'n':
+                       if (opt == 'i')
+                               ip2nets = true;
+
+                       if (opt == 'n')
+                               nid_list = true;
+
+                       if (ip2nets && (nid_list || prim_nid_present)) {
+                               cYAML_build_error(-1, -1, "peer", "add",
+                                               "ip2nets can not be specified"
+                                               " along side nid or prim_nid"
+                                               " parameters", &err_rc);
+                               goto failed;
+                       }
+
                        size = lustre_lnet_parse_nids(optarg, nids, size,
                                                      &nids2);
                        if (nids2 == NULL)
@@ -1294,8 +1333,16 @@ static int jt_add_peer_nid(int argc, char **argv)
                }
        }
 
+       for (; optind < argc; optind++) {
+               size = lustre_lnet_parse_nids(argv[optind], nids, size,
+                                               &nids2);
+               if (nids2 == NULL)
+                       goto failed;
+               nids = nids2;
+       }
+
        rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
-                                        !non_mr, -1, &err_rc);
+                                        !non_mr, ip2nets, -1, &err_rc);
 
 failed:
        if (nids) {
@@ -1319,25 +1366,48 @@ static int jt_del_peer_nid(int argc, char **argv)
        char **nids = NULL, **nids2 = NULL;
        struct cYAML *err_rc = NULL;
        int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
+       bool ip2nets = false, nid_list = false, prim_nid_present = false;
 
-       const char *const short_options = "k:n:";
-       const struct option long_options[] = {
-               { "prim_nid", 1, NULL, 'k' },
-               { "nid", 1, NULL, 'n' },
-               { NULL, 0, NULL, 0 },
-       };
+       const char *const short_opts = "k:n:";
+       const struct option long_opts[] = {
+       { .name = "prim_nid",   .has_arg = required_argument,   .val = 'k' },
+       { .name = "nid",        .has_arg = required_argument,   .val = 'n' },
+       { .name = "ip2nets",    .has_arg = required_argument,   .val = 'i' },
+       { .name = NULL } };
 
        rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
        if (rc)
                return rc;
 
-       while ((opt = getopt_long(argc, argv, short_options,
-                                 long_options, NULL)) != -1) {
+       while ((opt = getopt_long(argc, argv, short_opts,
+                                 long_opts, NULL)) != -1) {
                switch (opt) {
                case 'k':
+                       prim_nid_present = true;
+                       if (ip2nets) {
+                               cYAML_build_error(-1, -1, "peer", "add",
+                                               "ip2nets can not be specified"
+                                               " along side prim_nid parameter.",
+                                               &err_rc);
+                               goto failed;
+                       }
                        prim_nid = optarg;
                        break;
+               case 'i':
                case 'n':
+                       if (opt == 'i')
+                               ip2nets = true;
+
+                       if (opt == 'n')
+                               nid_list = true;
+
+                       if (ip2nets && (nid_list || prim_nid_present)) {
+                               cYAML_build_error(-1, -1, "peer", "add",
+                                               "ip2nets can not be specified"
+                                               " along side nid or prim_nid"
+                                               " parameters", &err_rc);
+                               goto failed;
+                       }
                        size = lustre_lnet_parse_nids(optarg, nids, size,
                                                      &nids2);
                        if (nids2 == NULL)
@@ -1350,7 +1420,15 @@ static int jt_del_peer_nid(int argc, char **argv)
                }
        }
 
-       rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, -1, &err_rc);
+       for (; optind < argc; optind++) {
+               size = lustre_lnet_parse_nids(argv[optind], nids, size,
+                                               &nids2);
+               if (nids2 == NULL)
+                       goto failed;
+               nids = nids2;
+       }
+
+       rc = lustre_lnet_del_peer_nid(prim_nid, nids, size, ip2nets, -1, &err_rc);
 
 failed:
        if (nids) {
@@ -1374,20 +1452,19 @@ static int jt_show_peer(int argc, char **argv)
        struct cYAML *err_rc = NULL, *show_rc = NULL;
        long int detail = 0;
 
-       const char *const short_options = "n:v::h";
-       const struct option long_options[] = {
-               { "nid", 1, NULL, 'n' },
-               { "verbose", 2, NULL, 'v' },
-               { "help", 0, NULL, 'h' },
-               { NULL, 0, NULL, 0 },
-       };
+       const char *const short_opts = "hn:v::";
+       const struct option long_opts[] = {
+       { .name = "help",       .has_arg = no_argument,         .val = 'h' },
+       { .name = "nid",        .has_arg = required_argument,   .val = 'n' },
+       { .name = "verbose",    .has_arg = optional_argument,   .val = 'v' },
+       { .name = NULL } };
 
        rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
        if (rc)
                return rc;
 
-       while ((opt = getopt_long(argc, argv, short_options,
-                                 long_options, NULL)) != -1) {
+       while ((opt = getopt_long(argc, argv, short_opts,
+                                 long_opts, NULL)) != -1) {
                switch (opt) {
                case 'n':
                        nid = optarg;
@@ -1406,7 +1483,8 @@ static int jt_show_peer(int argc, char **argv)
                }
        }
 
-       rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc);
+       rc = lustre_lnet_show_peer(nid, (int) detail, -1, &show_rc, &err_rc,
+                                  false);
 
        if (rc != LUSTRE_CFG_RC_NO_ERR)
                cYAML_print_tree2file(stderr, err_rc);
@@ -1448,12 +1526,11 @@ static int jt_ping(int argc, char **argv)
        int timeout = 1000;
        int rc = 0, opt;
 
-       const char *const short_options = "t:h";
+       const char *const short_options = "ht:";
        const struct option long_options[] = {
-               { "timeout", 1, NULL, 't' },
-               { "help", 0, NULL, 'h' },
-               { NULL, 0, NULL, 0 },
-       };
+       { .name = "help",       .has_arg = no_argument,         .val = 'h' },
+       { .name = "timeout",    .has_arg = required_argument,   .val = 't' },
+       { .name = NULL } };
 
        while ((opt = getopt_long(argc, argv, short_options,
                                  long_options, NULL)) != -1) {
@@ -1495,10 +1572,9 @@ static int jt_discover(int argc, char **argv)
 
        const char *const short_options = "fh";
        const struct option long_options[] = {
-               { "force", 0, NULL, 'f' },
-               { "help", 0, NULL, 'h' },
-               { NULL, 0, NULL, 0 },
-       };
+               { .name = "force",      .has_arg = no_argument, .val = 'f' },
+               { .name = "help",       .has_arg = no_argument, .val = 'h' },
+               { .name = NULL } };
 
        while ((opt = getopt_long(argc, argv, short_options,
                                  long_options, NULL)) != -1) {