Whamcloud - gitweb
LU-10391 lnet: change lnet_sock_connect to take sockaddr
[fs/lustre-release.git] / lnet / utils / lnetctl.c
index 00b3bc9..d600730 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
@@ -82,6 +82,7 @@ static int jt_global(int argc, char **argv);
 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);
 
 command_t cmd_list[] = {
        {"lnet", jt_lnet, 0, "lnet {configure | unconfigure} [--all]"},
@@ -99,6 +100,7 @@ command_t cmd_list[] = {
        {"peer", jt_peers, 0, "peer {add | del | show | help}"},
        {"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"},
        {"help", Parser_help, 0, "help"},
        {"exit", Parser_quit, 0, "quit"},
        {"quit", Parser_quit, 0, "quit"},
@@ -118,7 +120,8 @@ command_t route_cmds[] = {
         "\t--net: net name (e.g. tcp0)\n"
         "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"
         "\t--hop: number to final destination (1 < hops < 255)\n"
-        "\t--priority: priority of route (0 - highest prio\n"},
+        "\t--priority: priority of route (0 - highest prio\n"
+        "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"},
        {"del", jt_del_route, 0, "delete a route\n"
         "\t--net: net name (e.g. tcp0)\n"
         "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp)\n"},
@@ -127,6 +130,7 @@ command_t route_cmds[] = {
         "\t--gateway: gateway nid (e.g. 10.1.1.2@tcp) to filter on\n"
         "\t--hop: number to final destination (1 < hops < 255) to filter on\n"
         "\t--priority: priority of route (0 - highest prio to filter on\n"
+        "\t--health_sensitivity: gateway health sensitivity (>= 1)\n"
         "\t--verbose: display detailed output per route\n"},
        { 0, 0, 0, NULL }
 };
@@ -240,6 +244,24 @@ command_t peer_cmds[] = {
        { 0, 0, 0, NULL }
 };
 
+static int jt_calc_service_id(int argc, char **argv)
+{
+       int rc;
+       __u64 service_id;
+
+       rc = lustre_lnet_calc_service_id(&service_id);
+       if (rc != LUSTRE_CFG_RC_NO_ERR)
+               return rc;
+
+       /*
+        * cYAML currently doesn't support printing hex values.
+        * Therefore just print it locally here
+        */
+       printf("service id:\n    value: 0x%llx\n", service_id);
+
+       return rc;
+}
+
 static inline void print_help(const command_t cmds[], const char *cmd_type,
                              const char *pc_name)
 {
@@ -741,7 +763,7 @@ static int jt_unconfig_lnet(int argc, char **argv)
 static int jt_add_route(int argc, char **argv)
 {
        char *network = NULL, *gateway = NULL;
-       long int hop = -1, prio = -1;
+       long int hop = -1, prio = -1, sen = -1;
        struct cYAML *err_rc = NULL;
        int rc, opt;
 
@@ -751,6 +773,7 @@ static int jt_add_route(int argc, char **argv)
        { .name = "gateway",   .has_arg = required_argument, .val = 'g' },
        { .name = "hop-count", .has_arg = required_argument, .val = 'c' },
        { .name = "priority",  .has_arg = required_argument, .val = 'p' },
+       { .name = "health_sensitivity",  .has_arg = required_argument, .val = 's' },
        { .name = NULL } };
 
        rc = check_cmd(route_cmds, "route", "add", 0, argc, argv);
@@ -782,6 +805,15 @@ static int jt_add_route(int argc, char **argv)
                                continue;
                        }
                        break;
+               case 's':
+                       rc = parse_long(optarg, &sen);
+                       if (rc != 0) {
+                               /* ingore option */
+                               sen = -1;
+                               continue;
+                       }
+                       break;
+
                case '?':
                        print_help(route_cmds, "route", "add");
                default:
@@ -789,7 +821,8 @@ static int jt_add_route(int argc, char **argv)
                }
        }
 
-       rc = lustre_lnet_config_route(network, gateway, hop, prio, -1, &err_rc);
+       rc = lustre_lnet_config_route(network, gateway, hop, prio, sen, -1,
+                                     &err_rc);
 
        if (rc != LUSTRE_CFG_RC_NO_ERR)
                cYAML_print_tree2file(stderr, err_rc);
@@ -1641,22 +1674,21 @@ static int jt_export(int argc, char **argv)
        return 0;
 }
 
-static int jt_add_peer_nid(int argc, char **argv)
+static int jt_peer_nid_common(int argc, char **argv, int cmd)
 {
-       char *prim_nid = NULL;
-       char **nids = NULL, **nids2 = NULL;
-       int size = 0;
+       int rc = LUSTRE_CFG_RC_NO_ERR, opt, num_nids, num_nidstrs, i;
+       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;
-       int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
-       bool non_mr = false;
-       bool ip2nets = false, nid_list = false, prim_nid_present = false;
+       lnet_nid_t lnet_nidlist[LNET_MAX_NIDS_PER_PEER];
 
        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);
@@ -1667,161 +1699,99 @@ static int jt_add_peer_nid(int argc, char **argv)
                                  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)
-                               goto failed;
-                       nids = nids2;
-                       rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+                       nidstr = optarg;
                        break;
                case 'm':
-                       non_mr = true;
+                       if (cmd == LNETCTL_DEL_CMD) {
+                               rc = LUSTRE_CFG_RC_BAD_PARAM;
+                               snprintf(err_str, LNET_MAX_STR_LEN,
+                                        "Unrecognized option '-%c'", opt);
+                               goto out;
+                       }
+                       is_mr = false;
                        break;
                case '?':
-                       print_help(peer_cmds, "peer", "add");
+                       print_help(peer_cmds, "peer",
+                                  cmd == LNETCTL_ADD_CMD ? "add" : "del");
                default:
                        return 0;
                }
        }
 
-       for (; optind < argc; optind++) {
-               size = lustre_lnet_parse_nids(argv[optind], nids, size,
-                                               &nids2);
-               if (nids2 == NULL)
-                       goto failed;
-               nids = nids2;
+       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;
        }
 
-       rc = lustre_lnet_config_peer_nid(prim_nid, nids, size,
-                                        !non_mr, ip2nets, -1, &err_rc);
+       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);
 
-failed:
-       if (nids) {
-               /* free the array of nids */
-               for (i = 0; i < size; i++)
-                       free(nids[i]);
-               free(nids);
+               goto out;
        }
 
-       if (rc != LUSTRE_CFG_RC_NO_ERR)
+       rc = tokenize_nidstr(nidstr, &nidstrarray[0], err_str);
+       if (rc <= 0)
+               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);
+       }
+
+out:
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_build_error(rc, -1, "peer",
+                                 cmd == LNETCTL_ADD_CMD ? "add" : "del",
+                                 err_str, &err_rc);
                cYAML_print_tree2file(stderr, err_rc);
+       }
 
        cYAML_free_tree(err_rc);
 
        return rc;
 }
 
-static int jt_del_peer_nid(int argc, char **argv)
+static int jt_add_peer_nid(int argc, char **argv)
 {
-       char *prim_nid = NULL;
-       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_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_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)
-                               goto failed;
-                       nids = nids2;
-                       rc = LUSTRE_CFG_RC_OUT_OF_MEM;
-                       break;
-               case '?':
-                       print_help(peer_cmds, "peer", "del");
-               default:
-                       return 0;
-               }
-       }
-
-       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) {
-               for (i = 0; i < size; i++)
-                       free(nids[i]);
-               free(nids);
-       }
-
-       if (rc != LUSTRE_CFG_RC_NO_ERR)
-               cYAML_print_tree2file(stderr, err_rc);
-
-       cYAML_free_tree(err_rc);
+       return jt_peer_nid_common(argc, argv, LNETCTL_ADD_CMD);
+}
 
-       return rc;
+static int jt_del_peer_nid(int argc, char **argv)
+{
+       return jt_peer_nid_common(argc, argv, LNETCTL_DEL_CMD);
 }
 
 static int jt_show_peer(int argc, char **argv)