Whamcloud - gitweb
LU-9121 lnet: Delete a selection policy 99/40199/1
authorSonia Sharma <sharmaso@whamcloud.com>
Fri, 29 Mar 2019 10:51:01 +0000 (06:51 -0400)
committerAmir Shehata <ashehata@whamcloud.com>
Thu, 8 Oct 2020 21:28:13 +0000 (14:28 -0700)
This patch adds the function lustre_lnet_del_udsp()
which takes index of the udsp as input and calls
the IOC_LIBCFS_DEL_UDSP ioctl handler to
delete the udsp with that index value.

Change-Id: Ib81c79fd4e76f4e8fbd84709e08cb5d29a059e63
Test-Parameters: trivial testlist=lnet-selftest,sanity-lnet
Signed-off-by: Amir Shehata <ashehata@whamcloud.com>
Signed-off-by: Sonia Sharma <sharmaso@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/34553
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lnet/utils/lnetconfig/liblnetconfig.c
lnet/utils/lnetconfig/liblnetconfig.h
lnet/utils/lnetconfig/liblnetconfig_udsp.c
lnet/utils/lnetctl.c

index a279953..1140513 100644 (file)
@@ -4562,6 +4562,19 @@ static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
                                           show_rc, err_rc);
 }
 
+static int handle_yaml_del_udsp(struct cYAML *tree, struct cYAML **show_rc,
+                               struct cYAML **err_rc)
+{
+       struct cYAML *seq_no, *idx;
+
+       seq_no = cYAML_get_object_item(tree, "seq_no");
+       idx = cYAML_get_object_item(tree, "idx");
+
+       return lustre_lnet_del_udsp(idx ? idx->cy_valueint : -1,
+                                   seq_no ? seq_no->cy_valueint : -1,
+                                   err_rc);
+}
+
 static int handle_yaml_config_udsp(struct cYAML *tree, struct cYAML **show_rc,
                                   struct cYAML **err_rc)
 {
@@ -4848,6 +4861,7 @@ static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
        { .name = "numa",       .cb = handle_yaml_del_numa },
        { .name = "ping",       .cb = handle_yaml_no_op },
        { .name = "discover",   .cb = handle_yaml_no_op },
+       { .name = "udsp",       .cb = handle_yaml_del_udsp },
        { .name = NULL } };
 
 static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
index a8d4b3b..179eecf 100644 (file)
@@ -782,4 +782,13 @@ int lustre_lnet_add_udsp(char *src, char *dst, char *rte, char *type,
                         union lnet_udsp_action *action, int idx,
                         int seq_no, struct cYAML **err_rc);
 
+/* lustre_lnet_del_udsp
+ *     Delete a net selection policy.
+ *     idx - the index to delete
+ *     seq_no - sequence number of the request
+ *     err_rc - [OUT] struct cYAML tree describing the error. Freed by
+ *     caller
+ */
+int lustre_lnet_del_udsp(unsigned int idx, int seq_no, struct cYAML **err_rc);
+
 #endif /* LIB_LNET_CONFIG_API_H */
index 873940e..6193c98 100644 (file)
@@ -592,3 +592,25 @@ out:
        cYAML_build_error(rc, seq_no, ADD_CMD, "udsp", err_str, err_rc);
        return rc;
 }
+
+int lustre_lnet_del_udsp(unsigned int idx, int seq_no, struct cYAML **err_rc)
+{
+       int rc;
+       char err_str[LNET_MAX_STR_LEN];
+       struct lnet_ioctl_udsp udsp_bulk;
+
+       snprintf(err_str, sizeof(err_str), "\"success\"");
+
+       LIBCFS_IOC_INIT_V2(udsp_bulk, iou_hdr);
+       udsp_bulk.iou_idx = idx;
+
+       rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_UDSP, &udsp_bulk);
+       if (rc < 0) {
+               rc = -errno;
+               snprintf(err_str, sizeof(err_str),
+                        "\"cannot del udsp: %s\"", strerror(rc));
+       }
+
+       cYAML_build_error(rc, seq_no, ADD_CMD, "udsp", err_str, err_rc);
+       return rc;
+}
index c1d6a5d..a84afa5 100644 (file)
@@ -66,6 +66,7 @@ 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);
@@ -104,7 +105,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 | help}"},
+       {"udsp", jt_udsp, 0, "udsp {add | del | help}"},
        {"help", Parser_help, 0, "help"},
        {"exit", Parser_quit, 0, "quit"},
        {"quit", Parser_quit, 0, "quit"},
@@ -262,6 +263,8 @@ command_t udsp_cmds[] = {
         "\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"},
        { 0, 0, 0, NULL }
 };
 
@@ -2057,6 +2060,45 @@ static int jt_add_udsp(int argc, char **argv)
        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 */