From d309f6247a6628e28931bc781170bf8c8109c6ed Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Fri, 30 Aug 2024 03:24:14 -0400 Subject: [PATCH] LU-18182 lctl: Handle fault when issuing 'lctl net' cmd 'lctl net' command whithout arguments should dump usage message and not fault. After patch: $ lctl net configure LNET usage: net [Network] [-l] -l: Override existing, else it will create new Before patch: $ lctl net Segmentation fault (core dumped) Test-Parameters: trivial testlist=sanity-lnet Signed-off-by: Arshad Hussain Change-Id: I7c885032d8b5493bcadc35062047a3e0a5a1e48f Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56205 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Chris Horn Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/utils/lctl.c | 6 ++++-- lustre/utils/portals.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lustre/utils/lctl.c b/lustre/utils/lctl.c index 6cc06eb..e2715ca 100644 --- a/lustre/utils/lctl.c +++ b/lustre/utils/lctl.c @@ -134,9 +134,11 @@ command_t cmdlist[] = { {"--net", jt_opt_net, 0, "run after selecting network \n" "usage: --net "}, {"network", jt_ptl_network, 0, "configure LNET\n" - "usage: network up|down"}, + "usage: network [Network] [-l]\n" + " -l: Override existing, else it will create new\n"}, {"net", jt_ptl_network, 0, "configure LNET\n" - "usage: net up|down"}, + "usage: net [Network] [-l]\n" + " -l: Override existing, else it will create new\n"}, {"list_nids", jt_ptl_list_nids, 0, "list local NIDs\n" "usage: list_nids [all]"}, {"which_nid", jt_ptl_which_nid, 0, "choose a NID\n" diff --git a/lustre/utils/portals.c b/lustre/utils/portals.c index 2f063fd..691a30b6 100644 --- a/lustre/utils/portals.c +++ b/lustre/utils/portals.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -307,10 +308,8 @@ int jt_ptl_network(int argc, char **argv) const char *msg = NULL; int rc; - if (argc > 3) { - fprintf(stderr, "usage: %s |up|down [-l]\n", argv[0]); - return -1; - } + if (argc > 3 || argc <= 1) + return CMD_HELP; if (!strcmp(argv[1], "unconfigure") || !strcmp(argv[1], "down")) { rc = yaml_lnet_configure(0, &msg); @@ -350,16 +349,19 @@ int jt_ptl_network(int argc, char **argv) errno, strerror(errno)); return -1; } else if (!strcmp(argv[1], "configure") || !strcmp(argv[1], "up")) { - int flags = NLM_F_CREATE; + int flags = NLM_F_CREATE; /* Create, if it does not exist */ if (argc == 3 && argv[2] && !strcmp(argv[2], "-l")) - flags |= NLM_F_REPLACE; + flags |= NLM_F_REPLACE; /* Override existing */ rc = yaml_lnet_configure(flags, &msg); if (rc != -EOPNOTSUPP) { switch (rc) { case 0: - printf("LNET configured\n"); + if (flags & NLM_F_REPLACE) + printf("LNET configured: Overridden existing one\n"); + else + printf("LNET configured: New Created\n"); break; default: fprintf(stderr, "LNET configure error %u: %s\n", -- 1.8.3.1