From bbb3a875717f159c4a99eccebf0c28f30459da4f Mon Sep 17 00:00:00 2001 From: Sonia Sharma Date: Fri, 29 Mar 2019 06:51:01 -0400 Subject: [PATCH] LU-9121 lnet: Delete a selection policy 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 Signed-off-by: Sonia Sharma Reviewed-on: https://review.whamcloud.com/34553 Reviewed-by: Serguei Smirnov Reviewed-by: Sebastien Buisson Tested-by: jenkins Tested-by: Maloo --- lnet/utils/lnetconfig/liblnetconfig.c | 14 ++++++++++ lnet/utils/lnetconfig/liblnetconfig.h | 9 ++++++ lnet/utils/lnetconfig/liblnetconfig_udsp.c | 22 +++++++++++++++ lnet/utils/lnetctl.c | 44 +++++++++++++++++++++++++++++- 4 files changed, 88 insertions(+), 1 deletion(-) diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index 1c253c5..22bb91a 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -4534,6 +4534,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) { @@ -4836,6 +4849,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[] = { diff --git a/lnet/utils/lnetconfig/liblnetconfig.h b/lnet/utils/lnetconfig/liblnetconfig.h index b3d5b0f..3f4ab15 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.h +++ b/lnet/utils/lnetconfig/liblnetconfig.h @@ -786,4 +786,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 */ diff --git a/lnet/utils/lnetconfig/liblnetconfig_udsp.c b/lnet/utils/lnetconfig/liblnetconfig_udsp.c index 873940e..6193c98 100644 --- a/lnet/utils/lnetconfig/liblnetconfig_udsp.c +++ b/lnet/utils/lnetconfig/liblnetconfig_udsp.c @@ -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; +} diff --git a/lnet/utils/lnetctl.c b/lnet/utils/lnetctl.c index 631c18e..97515e1 100644 --- a/lnet/utils/lnetctl.c +++ b/lnet/utils/lnetctl.c @@ -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); @@ -108,7 +109,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"}, @@ -270,6 +271,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 } }; @@ -2143,6 +2146,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 */ -- 1.8.3.1