Whamcloud - gitweb
LU-6210 utils: Use C99 struct initializers in lnetctl 23/28423/4
authorSteve Guminski <stephenx.guminski@intel.com>
Mon, 7 Aug 2017 14:55:35 +0000 (10:55 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Sun, 10 Sep 2017 04:55:11 +0000 (04:55 +0000)
This patch makes no functional changes.  The option struct
initializers in lnetctl are updated to C99 syntax.  The short and
long options are renamed to short_opts and long_opts for consistency.

C89 positional initializers require values to be placed in the
correct order. This will cause errors if the fields of the struct
definition are reordered or fields are added or removed. C99 named
initializers avoid this problem, and also automatically clear any
values that are not explicitly set.

Test-Parameters: trivial
Signed-off-by: Steve Guminski <stephenx.guminski@intel.com>
Change-Id: I1c1483a57aea918dce84afd0c7e94e31324c189e
Reviewed-on: https://review.whamcloud.com/28423
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lnet/utils/lnetctl.c

index cfd16fe..237955c 100644 (file)
@@ -1260,20 +1260,19 @@ static int jt_add_peer_nid(int argc, char **argv)
        int rc = LUSTRE_CFG_RC_NO_ERR, opt, i;
        bool non_mr = false;
 
-       const char *const short_options = "k:n:m";
-       const struct option long_options[] = {
-               { "prim_nid", 1, NULL, 'k' },
-               { "nid", 1, NULL, 'n' },
-               { "non_mr", 0, NULL, 'm'},
-               { NULL, 0, NULL, 0 },
-       };
+       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 = NULL } };
 
        rc = check_cmd(peer_cmds, "peer", "add", 2, argc, argv);
        if (rc)
                return rc;
 
-       while ((opt = getopt_long(argc, argv, short_options,
-                                 long_options, NULL)) != -1) {
+       while ((opt = getopt_long(argc, argv, short_opts,
+                                 long_opts, NULL)) != -1) {
                switch (opt) {
                case 'k':
                        prim_nid = optarg;
@@ -1320,19 +1319,18 @@ static int jt_del_peer_nid(int argc, char **argv)
        struct cYAML *err_rc = NULL;
        int rc = LUSTRE_CFG_RC_NO_ERR, opt, i, size = 0;
 
-       const char *const short_options = "k:n:";
-       const struct option long_options[] = {
-               { "prim_nid", 1, NULL, 'k' },
-               { "nid", 1, NULL, 'n' },
-               { NULL, 0, NULL, 0 },
-       };
+       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 = NULL } };
 
        rc = check_cmd(peer_cmds, "peer", "del", 2, argc, argv);
        if (rc)
                return rc;
 
-       while ((opt = getopt_long(argc, argv, short_options,
-                                 long_options, NULL)) != -1) {
+       while ((opt = getopt_long(argc, argv, short_opts,
+                                 long_opts, NULL)) != -1) {
                switch (opt) {
                case 'k':
                        prim_nid = optarg;
@@ -1374,20 +1372,19 @@ static int jt_show_peer(int argc, char **argv)
        struct cYAML *err_rc = NULL, *show_rc = NULL;
        long int detail = 0;
 
-       const char *const short_options = "n:v::h";
-       const struct option long_options[] = {
-               { "nid", 1, NULL, 'n' },
-               { "verbose", 2, NULL, 'v' },
-               { "help", 0, NULL, 'h' },
-               { NULL, 0, NULL, 0 },
-       };
+       const char *const short_opts = "hn:v::";
+       const struct option long_opts[] = {
+       { .name = "help",       .has_arg = no_argument,         .val = 'h' },
+       { .name = "nid",        .has_arg = required_argument,   .val = 'n' },
+       { .name = "verbose",    .has_arg = optional_argument,   .val = 'v' },
+       { .name = NULL } };
 
        rc = check_cmd(peer_cmds, "peer", "show", 1, argc, argv);
        if (rc)
                return rc;
 
-       while ((opt = getopt_long(argc, argv, short_options,
-                                 long_options, NULL)) != -1) {
+       while ((opt = getopt_long(argc, argv, short_opts,
+                                 long_opts, NULL)) != -1) {
                switch (opt) {
                case 'n':
                        nid = optarg;
@@ -1448,12 +1445,11 @@ static int jt_ping(int argc, char **argv)
        int timeout = 1000;
        int rc = 0, opt;
 
-       const char *const short_options = "t:h";
+       const char *const short_options = "ht:";
        const struct option long_options[] = {
-               { "timeout", 1, NULL, 't' },
-               { "help", 0, NULL, 'h' },
-               { NULL, 0, NULL, 0 },
-       };
+       { .name = "help",       .has_arg = no_argument,         .val = 'h' },
+       { .name = "timeout",    .has_arg = required_argument,   .val = 't' },
+       { .name = NULL } };
 
        while ((opt = getopt_long(argc, argv, short_options,
                                  long_options, NULL)) != -1) {
@@ -1495,10 +1491,9 @@ static int jt_discover(int argc, char **argv)
 
        const char *const short_options = "fh";
        const struct option long_options[] = {
-               { "force", 0, NULL, 'f' },
-               { "help", 0, NULL, 'h' },
-               { NULL, 0, NULL, 0 },
-       };
+               { .name = "force",      .has_arg = no_argument, .val = 'f' },
+               { .name = "help",       .has_arg = no_argument, .val = 'h' },
+               { .name = NULL } };
 
        while ((opt = getopt_long(argc, argv, short_options,
                                  long_options, NULL)) != -1) {