Whamcloud - gitweb
LU-18182 lctl: Handle fault when issuing 'lctl net' cmd 05/56205/3
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Fri, 30 Aug 2024 07:24:14 +0000 (03:24 -0400)
committerOleg Drokin <green@whamcloud.com>
Sun, 8 Sep 2024 16:05:50 +0000 (16:05 +0000)
'lctl net' command whithout arguments should dump
usage message and not fault.

After patch:
$ lctl net
configure LNET
usage: net [Network] <up|down> [-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 <arshad.hussain@aeoncomputing.com>
Change-Id: I7c885032d8b5493bcadc35062047a3e0a5a1e48f
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56205
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/utils/lctl.c
lustre/utils/portals.c

index 6cc06eb..e2715ca 100644 (file)
@@ -134,9 +134,11 @@ command_t cmdlist[] = {
        {"--net", jt_opt_net, 0, "run <command> after selecting network <net>\n"
         "usage: --net <tcp/o2ib/...> <command>"},
        {"network", jt_ptl_network, 0, "configure LNET\n"
-        "usage: network up|down"},
+        "usage: network [Network] <up|down> [-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] <up|down> [-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"
index 2f063fd..691a30b 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/types.h>
 
 #include <libcfs/util/ioctl.h>
+#include <libcfs/util/parser.h>
 #include <linux/lnet/libcfs_debug.h>
 #include <linux/lnet/lnet-dlc.h>
 #include <linux/lnet/lnetctl.h>
@@ -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 <net>|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",