]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
util: Add argconfig seen flag parameter to check if feature NSID set
authorTokunori Ikegami <ikegami.t@gmail.com>
Wed, 1 Mar 2023 14:51:46 +0000 (23:51 +0900)
committerDaniel Wagner <wagi@monom.org>
Tue, 7 Mar 2023 13:32:31 +0000 (14:32 +0100)
To set the flag parameter change options arguments as not const variables.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
nvme.c
nvme.h
plugins/intel/intel-nvme.c
plugins/memblaze/memblaze-nvme.c
plugins/micron/micron-nvme.c
util/argconfig.c
util/argconfig.h

diff --git a/nvme.c b/nvme.c
index c844d2c235f1751522d45458a7827968c2db2b78..f59ca96850fa16a939ce2851d24115e2de447f66 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -408,7 +408,7 @@ static int get_dev(struct nvme_dev **dev, int argc, char **argv, int flags)
 
 int parse_and_open(struct nvme_dev **dev, int argc, char **argv,
                   const char *desc,
-                  const struct argconfig_commandline_options *opts)
+                  struct argconfig_commandline_options *opts)
 {
        int ret;
 
@@ -4700,7 +4700,7 @@ static int get_feature(int argc, char **argv, struct command *cmd,
        if (err)
                goto ret;
 
-       if (!cfg.namespace_id) {
+       if (!opts[1].seen) {
                err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
                if (err < 0) {
                        if (errno != ENOTTY) {
@@ -5878,14 +5878,13 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
        if (err)
                goto ret;
 
-       if (!cfg.namespace_id) {
+       if (!opts[0].seen) {
                err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
                if (err < 0) {
                        if (errno != ENOTTY) {
                                fprintf(stderr, "get-namespace-id: %s\n", nvme_strerror(errno));
                                goto close_dev;
                        }
-
                        cfg.namespace_id = NVME_NSID_ALL;
                }
        }
diff --git a/nvme.h b/nvme.h
index 1938afb934f7e951bc6a06ce675644923b734aaa..d859983e7e08af89a142860678ebc63bd7ca07b9 100644 (file)
--- a/nvme.h
+++ b/nvme.h
@@ -96,7 +96,7 @@ void register_extension(struct plugin *plugin);
  * parse_and_open - parses arguments and opens the NVMe device, populating @dev
  */
 int parse_and_open(struct nvme_dev **dev, int argc, char **argv, const char *desc,
-       const struct argconfig_commandline_options *clo);
+       struct argconfig_commandline_options *clo);
 
 void dev_close(struct nvme_dev *dev);
 
index f660b84409bddfb16e7f07e2086f65dbde13fd17..8a29cf93bd16662b25ce3bccc675cf88c506032c 100644 (file)
@@ -1558,7 +1558,7 @@ static int enable_lat_stats_tracking(int argc, char **argv,
                .disable = false,
        };
 
-       const struct argconfig_commandline_options command_line_options[] = {
+       struct argconfig_commandline_options command_line_options[] = {
                {"enable", 'e', "", CFG_FLAG, &cfg.enable, no_argument, enable_desc},
                {"disable", 'd', "", CFG_FLAG, &cfg.disable, no_argument, disable_desc},
                {NULL}
index 6cc03b616ef717001a15e6f6c4c27a0e785a74c7..7a4633afa4ade84b59f3168acbed187985e80e61 100644 (file)
@@ -1140,7 +1140,7 @@ static int mb_set_lat_stats(int argc, char **argv,
                .disable = false,
        };
 
-       const struct argconfig_commandline_options command_line_options[] = {
+       struct argconfig_commandline_options command_line_options[] = {
                {"enable", 'e', "", CFG_FLAG, &cfg.enable, no_argument, enable_desc},
                {"disable", 'd', "", CFG_FLAG, &cfg.disable, no_argument, disable_desc},
                {NULL}
index 3c0904c40aeae9dd1b350599bd6689d1c94b4dc1..bd5f7d7e698fd690fd0541ab2cfdf50fef2a9734 100644 (file)
@@ -455,7 +455,7 @@ exit_status:
  */
 static int micron_parse_options(struct nvme_dev **dev, int argc, char **argv,
                                const char *desc,
-                               const struct argconfig_commandline_options *opts,
+                               struct argconfig_commandline_options *opts,
                                eDriveModel *modelp)
 {
     int idx = 0;
index 972b8d6fdb3f2a1162a5134a8e806152fa2f269c..2d6b40c045fd82cf1f40df3fc10a4c49afe158b6 100644 (file)
@@ -158,12 +158,12 @@ int argconfig_parse_byte(const char *opt, const char *str, unsigned char *val)
 }
 
 int argconfig_parse(int argc, char *argv[], const char *program_desc,
-                   const struct argconfig_commandline_options *options)
+                   struct argconfig_commandline_options *options)
 {
        char *short_opts;
        char *endptr;
        struct option *long_opts;
-       const struct argconfig_commandline_options *s;
+       struct argconfig_commandline_options *s;
        int c, option_index = 0, short_index = 0, options_count = 0;
        void *value_addr;
        int ret = -EINVAL;
@@ -198,6 +198,7 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc,
                        long_opts[option_index].flag = NULL;
                        long_opts[option_index].val = 0;
                }
+               s->seen = false;
                option_index++;
        }
 
@@ -232,6 +233,7 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc,
                }
 
                s = &options[option_index];
+               s->seen = true;
                value_addr = (void *)(char *)s->default_value;
                if (s->config_type == CFG_STRING) {
                        *((char **)value_addr) = optarg;
index 6ef3b6a194ecb4748722942ec432b99944f26c86..d1c54221e52b7673addb613118363b0de197c697 100644 (file)
@@ -38,6 +38,7 @@
 #include <getopt.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <stdbool.h>
 
 enum argconfig_types {
        CFG_FLAG,
@@ -62,7 +63,7 @@ enum argconfig_types {
 };
 
 #define OPT_ARGS(n) \
-       const struct argconfig_commandline_options n[]
+       struct argconfig_commandline_options n[]
 
 #define OPT_END() { NULL }
 
@@ -109,6 +110,7 @@ struct argconfig_commandline_options {
        void *default_value;
        int argument_type;
        const char *help;
+       bool seen;
 };
 
 #define CFG_MAX_SUBOPTS 500
@@ -119,7 +121,7 @@ void argconfig_append_usage(const char *str);
 void argconfig_print_help(const char *program_desc,
                          const struct argconfig_commandline_options *options);
 int argconfig_parse(int argc, char *argv[], const char *program_desc,
-                   const struct argconfig_commandline_options *options);
+                   struct argconfig_commandline_options *options);
 int argconfig_parse_subopt_string(char *string, char **options,
                                  size_t max_options);
 int argconfig_parse_comma_sep_array(char *string, int *ret,