Whamcloud - gitweb
LU-13903 utils: have liblustreapi support Linux client
[fs/lustre-release.git] / lnet / utils / lnetctl.c
index 5c23c5c..4003acd 100644 (file)
@@ -30,7 +30,7 @@
 #include <limits.h>
 #include <libcfs/util/ioctl.h>
 #include <libcfs/util/parser.h>
-#include <cyaml.h>
+#include "lnetconfig/cyaml.h"
 #include "lnetconfig/liblnetconfig.h"
 
 #define LNET_CONFIGURE         true
@@ -50,6 +50,7 @@ static int jt_show_stats(int argc, char **argv);
 static int jt_show_peer(int argc, char **argv);
 static int jt_show_recovery(int argc, char **argv);
 static int jt_show_global(int argc, char **argv);
+static int jt_show_udsp(int argc, char **argv);
 static int jt_set_tiny(int argc, char **argv);
 static int jt_set_small(int argc, char **argv);
 static int jt_set_large(int argc, char **argv);
@@ -65,6 +66,8 @@ static int jt_set_max_intf(int argc, char **argv);
 static int jt_set_discovery(int argc, char **argv);
 static int jt_set_drop_asym_route(int argc, char **argv);
 static int jt_list_peer(int argc, char **argv);
+static int jt_add_udsp(int argc, char **argv);
+static int jt_del_udsp(int argc, char **argv);
 /*static int jt_show_peer(int argc, char **argv);*/
 static int lnetctl_list_commands(int argc, char **argv);
 static int jt_import(int argc, char **argv);
@@ -83,6 +86,9 @@ static int jt_peers(int argc, char **argv);
 static int jt_set_ni_value(int argc, char **argv);
 static int jt_set_peer_ni_value(int argc, char **argv);
 static int jt_calc_service_id(int argc, char **argv);
+static int jt_set_response_tracking(int argc, char **argv);
+static int jt_set_recovery_limit(int argc, char **argv);
+static int jt_udsp(int argc, char **argv);
 
 command_t cmd_list[] = {
        {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
@@ -91,7 +97,10 @@ command_t cmd_list[] = {
        {"routing", jt_routing, 0, "routing {show | help}"},
        {"set", jt_set, 0, "set {tiny_buffers | small_buffers | large_buffers"
                           " | routing | numa_range | max_interfaces"
-                          " | discovery}"},
+                          " | discovery | drop_asym_route | retry_count"
+                          " | transaction_timeout | health_sensitivity"
+                          " | recovery_interval | router_sensitivity"
+                          " | response_tracking | recovery_limit}"},
        {"import", jt_import, 0, "import FILE.yaml"},
        {"export", jt_export, 0, "export FILE.yaml"},
        {"stats", jt_stats, 0, "stats {show | help}"},
@@ -101,6 +110,7 @@ command_t cmd_list[] = {
        {"ping", jt_ping, 0, "ping nid,[nid,...]"},
        {"discover", jt_discover, 0, "discover nid[,nid,...]"},
        {"service-id", jt_calc_service_id, 0, "Calculate IB Lustre service ID\n"},
+       {"udsp", jt_udsp, 0, "udsp {add | del | help}"},
        {"help", Parser_help, 0, "help"},
        {"exit", Parser_quit, 0, "quit"},
        {"quit", Parser_quit, 0, "quit"},
@@ -216,14 +226,24 @@ command_t set_cmds[] = {
        {"router_sensitivity", jt_set_rtr_sensitivity, 0, "router sensitivity %\n"
         "\t100 - router interfaces need to be fully healthy to be used\n"
         "\t<100 - router interfaces can be used even if not healthy\n"},
+       {"response_tracking", jt_set_response_tracking, 0,
+        "Set the behavior of response tracking\n"
+        "\t0 - Only LNet pings and discovery pushes utilize response tracking\n"
+        "\t1 - GETs are eligible for response tracking\n"
+        "\t2 - PUTs are eligible for response tracking\n"
+        "\t3 - Both PUTs and GETs are eligible for response tracking (default)\n"
+        "\tNote: Regardless of the value of the response_tracking parameter LNet\n"
+        "\t      pings and discovery pushes always utilize response tracking\n"},
+       {"recovery_limit", jt_set_recovery_limit, 0,
+        "Set how long LNet will attempt to recover unhealthy interfaces.\n"
+        "\t0 - Recover indefinitely (default)\n"
+        "\t>0 - Recover for the specified number of seconds.\n"},
        { 0, 0, 0, NULL }
 };
 
 command_t peer_cmds[] = {
        {"add", jt_add_peer_nid, 0, "add a peer NID\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--prim_nid: Primary NID of the peer.\n"
         "\t--nid: one or more peer NIDs\n"
         "\t--non_mr: create this peer as not Multi-Rail capable\n"
         "\t--ip2nets: specify a range of nids per peer"},
@@ -244,6 +264,21 @@ command_t peer_cmds[] = {
        { 0, 0, 0, NULL }
 };
 
+command_t udsp_cmds[] = {
+       {"add", jt_add_udsp, 0, "add a udsp\n"
+        "\t--src: ip2nets syntax specifying the local NID to match\n"
+        "\t--dst: ip2nets syntax specifying the remote NID to match\n"
+        "\t--rte: ip2nets syntax specifying the router NID to match\n"
+        "\t--priority: priority value (0 - highest priority)\n"
+        "\t--idx: index of where to insert the rule.\n"
+        "\t       By default, appends to the end of the rule list.\n"},
+       {"del", jt_del_udsp, 0, "delete a udsp\n"
+       "\t--idx: index of the Policy.\n"},
+       {"show", jt_show_udsp, 0, "show udsps\n"
+        "\t --idx: index of the policy to show.\n"},
+       { 0, 0, 0, NULL }
+};
+
 static int jt_calc_service_id(int argc, char **argv)
 {
        int rc;
@@ -257,7 +292,7 @@ static int jt_calc_service_id(int argc, char **argv)
         * cYAML currently doesn't support printing hex values.
         * Therefore just print it locally here
         */
-       printf("service id:\n    value: 0x%llx\n", service_id);
+       printf("service id:\n    value: 0x%jx\n", (uintmax_t)service_id);
 
        return rc;
 }
@@ -336,6 +371,64 @@ out:
        return rc;
 }
 
+static int jt_set_response_tracking(int argc, char **argv)
+{
+       long int value;
+       int rc;
+       struct cYAML *err_rc = NULL;
+
+       rc = check_cmd(set_cmds, "set", "response_tracking", 2, argc, argv);
+       if (rc)
+               return rc;
+
+       rc = parse_long(argv[1], &value);
+       if (rc != 0) {
+               cYAML_build_error(-1, -1, "parser", "set",
+                                 "cannot parse response_tracking value",
+                                 &err_rc);
+               cYAML_print_tree2file(stderr, err_rc);
+               cYAML_free_tree(err_rc);
+               return -1;
+       }
+
+       rc = lustre_lnet_config_response_tracking(value, -1, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR)
+               cYAML_print_tree2file(stderr, err_rc);
+
+       cYAML_free_tree(err_rc);
+
+       return rc;
+}
+
+static int jt_set_recovery_limit(int argc, char **argv)
+{
+       long int value;
+       int rc;
+       struct cYAML *err_rc = NULL;
+
+       rc = check_cmd(set_cmds, "set", "recovery_limit", 2, argc, argv);
+       if (rc)
+               return rc;
+
+       rc = parse_long(argv[1], &value);
+       if (rc != 0) {
+               cYAML_build_error(-1, -1, "parser", "set",
+                                 "cannot parse recovery_limit value",
+                                 &err_rc);
+               cYAML_print_tree2file(stderr, err_rc);
+               cYAML_free_tree(err_rc);
+               return -1;
+       }
+
+       rc = lustre_lnet_config_recovery_limit(value, -1, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR)
+               cYAML_print_tree2file(stderr, err_rc);
+
+       cYAML_free_tree(err_rc);
+
+       return rc;
+}
+
 static int jt_set_max_intf(int argc, char **argv)
 {
        long int value;
@@ -1307,6 +1400,48 @@ static int jt_show_stats(int argc, char **argv)
        return rc;
 }
 
+static int jt_show_udsp(int argc, char **argv)
+{
+       int idx = -1;
+       int rc, opt;
+       struct cYAML *err_rc = NULL, *show_rc = NULL;
+
+       const char *const short_options = "i:";
+       static const struct option long_options[] = {
+               { .name = "idx", .has_arg = required_argument, .val = 'i' },
+               { .name = NULL }
+       };
+
+       rc = check_cmd(udsp_cmds, "udsp", "show", 0, argc, argv);
+       if (rc)
+               return rc;
+
+       while ((opt = getopt_long(argc, argv, short_options,
+                                  long_options, NULL)) != -1) {
+               switch (opt) {
+               case 'i':
+                       idx = atoi(optarg);
+                       break;
+               case '?':
+                       print_help(net_cmds, "net", "show");
+               default:
+                       return 0;
+               }
+       }
+
+       rc = lustre_lnet_show_udsp(idx, -1, &show_rc, &err_rc);
+
+       if (rc != LUSTRE_CFG_RC_NO_ERR)
+               cYAML_print_tree2file(stderr, err_rc);
+       else if (show_rc)
+               cYAML_print_tree(show_rc);
+
+       cYAML_free_tree(err_rc);
+       cYAML_free_tree(show_rc);
+
+       return rc;
+}
+
 static int jt_show_global(int argc, char **argv)
 {
        int rc;
@@ -1370,6 +1505,24 @@ static int jt_show_global(int argc, char **argv)
                goto out;
        }
 
+       rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               goto out;
+       }
+
+       rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               goto out;
+       }
+
+       rc = lustre_lnet_show_recovery_limit(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               goto out;
+       }
+
        if (show_rc)
                cYAML_print_tree(show_rc);
 
@@ -1479,6 +1632,17 @@ static int jt_set(int argc, char **argv)
        return Parser_execarg(argc - 1, &argv[1], set_cmds);
 }
 
+static int jt_udsp(int argc, char **argv)
+{
+       int rc;
+
+       rc = check_cmd(udsp_cmds, "udsp", NULL, 2, argc, argv);
+       if (rc)
+               return rc;
+
+       return Parser_execarg(argc - 1, &argv[1], udsp_cmds);
+}
+
 static int jt_import(int argc, char **argv)
 {
        char *file = NULL;
@@ -1663,6 +1827,63 @@ static int jt_export(int argc, char **argv)
                err_rc = NULL;
        }
 
+       rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               err_rc = NULL;
+       }
+
+       rc = lustre_lnet_show_transaction_to(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               err_rc = NULL;
+       }
+
+       rc = lustre_lnet_show_hsensitivity(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               err_rc = NULL;
+       }
+
+       rc = lustre_lnet_show_recov_intrv(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               err_rc = NULL;
+       }
+
+       rc = lustre_lnet_show_rtr_sensitivity(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               err_rc = NULL;
+       }
+
+       rc = lustre_lnet_show_lnd_timeout(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               err_rc = NULL;
+       }
+
+       rc = lustre_lnet_show_response_tracking(-1, &show_rc, &err_rc);
+       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_recovery_limit(-1, &show_rc, &err_rc);
+       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_udsp(-1, -1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               cYAML_free_tree(err_rc);
+               err_rc = NULL;
+       }
+
        if (show_rc != NULL) {
                cYAML_print_tree2file(f, show_rc);
                cYAML_free_tree(show_rc);
@@ -1676,13 +1897,11 @@ static int jt_export(int argc, char **argv)
 
 static int jt_peer_nid_common(int argc, char **argv, int cmd)
 {
-       int rc = LUSTRE_CFG_RC_NO_ERR, opt, num_nids, num_nidstrs, i;
+       int rc = LUSTRE_CFG_RC_NO_ERR, opt;
        bool is_mr = true;
        char *prim_nid = NULL, *nidstr = NULL;
        char err_str[LNET_MAX_STR_LEN] = "Error";
-       char *nidstrarray[LNET_MAX_STR_LEN];
        struct cYAML *err_rc = NULL;
-       lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
 
        const char *const short_opts = "k:mn:";
        const struct option long_opts[] = {
@@ -1709,7 +1928,7 @@ static int jt_peer_nid_common(int argc, char **argv, int cmd)
                                rc = LUSTRE_CFG_RC_BAD_PARAM;
                                snprintf(err_str, LNET_MAX_STR_LEN,
                                         "Unrecognized option '-%c'", opt);
-                               goto out;
+                               goto build_error;
                        }
                        is_mr = false;
                        break;
@@ -1721,63 +1940,19 @@ static int jt_peer_nid_common(int argc, char **argv, int cmd)
                }
        }
 
-       if (!(nidstr || prim_nid)) {
-               rc = LUSTRE_CFG_RC_BAD_PARAM;
-               snprintf(err_str, LNET_MAX_STR_LEN,
-                        "--prim_nid or --nid (or both) must be specified");
-               goto out;
-       }
-
-       if (!nidstr) {
-               /* We were only provided a primary nid */
-               num_nids = 0;
-               if (cmd == LNETCTL_ADD_CMD)
-                       rc = lustre_lnet_config_peer_nidlist(prim_nid,
-                                                            lnet_nidlist,
-                                                            num_nids, is_mr,
-                                                            -1, &err_rc);
-               else
-                       rc = lustre_lnet_del_peer_nidlist(prim_nid,
-                                                         lnet_nidlist,
-                                                         num_nids, -1,
-                                                         &err_rc);
-
-               goto out;
-       }
-
-       rc = tokenize_nidstr(nidstr, &nidstrarray[0], err_str);
-       if (rc <= 0)
+       rc = lustre_lnet_modify_peer(prim_nid, nidstr, is_mr, cmd,
+                                    -1, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR)
                goto out;
 
-       num_nidstrs = rc;
-
-       for (i = 0; i < num_nidstrs; i++) {
-               rc = lustre_lnet_parse_nidstr(nidstrarray[i], lnet_nidlist,
-                                             LNET_MAX_NIDS_PER_PEER, err_str);
-               if (rc < 0)
-                       goto out;
-
-               num_nids = rc;
-
-               if (cmd == LNETCTL_ADD_CMD)
-                       rc = lustre_lnet_config_peer_nidlist(prim_nid,
-                                                            lnet_nidlist,
-                                                            num_nids, is_mr,
-                                                            -1, &err_rc);
-               else
-                       rc = lustre_lnet_del_peer_nidlist(prim_nid,
-                                                         lnet_nidlist,
-                                                         num_nids, -1,
-                                                         &err_rc);
-       }
+build_error:
+       cYAML_build_error(rc, -1, "peer",
+                         cmd == LNETCTL_ADD_CMD ? "add" : "del",
+                         err_str, &err_rc);
 
 out:
-       if (rc != LUSTRE_CFG_RC_NO_ERR) {
-               cYAML_build_error(rc, -1, "peer",
-                                 cmd == LNETCTL_ADD_CMD ? "add" : "del",
-                                 err_str, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR)
                cYAML_print_tree2file(stderr, err_rc);
-       }
 
        cYAML_free_tree(err_rc);
 
@@ -1959,6 +2134,109 @@ static int jt_discover(int argc, char **argv)
        return rc;
 }
 
+static int jt_add_udsp(int argc, char **argv)
+{
+       char *src = NULL, *dst = NULL, *rte = NULL;
+       struct cYAML *err_rc = NULL;
+       union lnet_udsp_action udsp_action;
+       long int idx = -1, priority = -1;
+       int opt, rc = 0;
+       char *action_type = "pref";
+
+       const char *const short_options = "s:d:r:p:i:";
+       static const struct option long_options[] = {
+       { .name = "src",         .has_arg = required_argument, .val = 's' },
+       { .name = "dst",         .has_arg = required_argument, .val = 'd' },
+       { .name = "rte",         .has_arg = required_argument, .val = 'r' },
+       { .name = "priority",    .has_arg = required_argument, .val = 'p' },
+       { .name = "idx",         .has_arg = required_argument, .val = 'i' },
+       { .name = NULL } };
+
+       rc = check_cmd(udsp_cmds, "udsp", "add", 0, argc, argv);
+       if (rc)
+               return rc;
+
+       while ((opt = getopt_long(argc, argv, short_options,
+                                 long_options, NULL)) != -1) {
+               switch (opt) {
+               case 's':
+                       src = optarg;
+                       break;
+               case 'd':
+                       dst = optarg;
+                       break;
+               case 'r':
+                       rte = optarg;
+                       break;
+               case 'p':
+                       rc = parse_long(optarg, &priority);
+                       if (rc != 0)
+                               priority = -1;
+                       action_type = "priority";
+                       udsp_action.udsp_priority = priority;
+                       break;
+               case 'i':
+                       rc = parse_long(optarg, &idx);
+                       if (rc != 0)
+                               idx = 0;
+                       break;
+               case '?':
+                       print_help(udsp_cmds, "udsp", "add");
+               default:
+                       return 0;
+               }
+       }
+
+       rc = lustre_lnet_add_udsp(src, dst, rte, action_type, &udsp_action,
+                                 idx, -1, &err_rc);
+
+       if (rc != LUSTRE_CFG_RC_NO_ERR)
+               cYAML_print_tree2file(stderr, err_rc);
+
+       cYAML_free_tree(err_rc);
+
+       return rc;
+}
+
+static int jt_del_udsp(int argc, char **argv)
+{
+       struct cYAML *err_rc = NULL;
+       long int idx = 0;
+       int opt, rc = 0;
+
+       const char *const short_options = "i:";
+       static const struct option long_options[] = {
+       { .name = "idx",        .has_arg = required_argument, .val = 'i' },
+       { .name = NULL } };
+
+       rc = check_cmd(udsp_cmds, "udsp", "del", 0, argc, argv);
+       if (rc)
+               return rc;
+
+       while ((opt = getopt_long(argc, argv, short_options,
+                                 long_options, NULL)) != -1) {
+               switch (opt) {
+               case 'i':
+                       rc = parse_long(optarg, &idx);
+                       if (rc != 0)
+                               idx = 0;
+                       break;
+               case '?':
+                       print_help(udsp_cmds, "udsp", "add");
+               default:
+                       return 0;
+               }
+       }
+
+       rc = lustre_lnet_del_udsp(idx, -1, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR)
+               cYAML_print_tree2file(stderr, err_rc);
+
+       cYAML_free_tree(err_rc);
+
+       return rc;
+}
+
 static int lnetctl_list_commands(int argc, char **argv)
 {
        char buffer[81] = ""; /* 80 printable chars + terminating NUL */