[v32,03/12] eal: introduce log options parser

Message ID 20241108085710.2943741-4-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series Log library enhancements |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

David Marchand Nov. 8, 2024, 8:57 a.m. UTC
Rename existing log level option parser and add a little helper tracking
all options related to logs.
This will make it easier to add more log options in the next commits.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_options.c | 26 ++++++++++++++++++--------
 lib/eal/common/eal_options.h        |  3 ++-
 lib/eal/freebsd/eal.c               |  8 ++++----
 lib/eal/linux/eal.c                 |  8 ++++----
 lib/eal/windows/eal.c               |  7 ++++---
 5 files changed, 32 insertions(+), 20 deletions(-)
  

Patch

diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c
index 17c378f0c7..ab6cf8bebf 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -1640,9 +1640,20 @@  eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out)
 	return -1;
 }
 
-/* Parse the arguments for --log-level only */
+bool
+eal_option_is_log(int opt)
+{
+	switch (opt) {
+	case OPT_LOG_LEVEL_NUM:
+		return true;
+	default:
+		return false;
+	}
+}
+
+/* Parse all arguments looking for log related ones */
 int
-eal_log_level_parse(int argc, char * const argv[])
+eal_parse_log_options(int argc, char * const argv[])
 {
 	struct internal_config *internal_conf = eal_get_internal_configuration();
 	int option_index, opt;
@@ -1661,12 +1672,11 @@  eal_log_level_parse(int argc, char * const argv[])
 	while ((opt = getopt_long(argc, argv, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		switch (opt) {
-		case OPT_LOG_LEVEL_NUM:
-			if (eal_parse_common_option(opt, optarg, internal_conf) < 0)
-				return -1;
-			break;
-		}
+		if (!eal_option_is_log(opt))
+			continue;
+
+		if (eal_parse_common_option(opt, optarg, internal_conf) < 0)
+			return -1;
 	}
 
 	/* restore getopt lib */
diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h
index f3f2e104f6..06ba023c5a 100644
--- a/lib/eal/common/eal_options.h
+++ b/lib/eal/common/eal_options.h
@@ -96,7 +96,8 @@  enum {
 extern const char eal_short_options[];
 extern const struct option eal_long_options[];
 
-int eal_log_level_parse(int argc, char * const argv[]);
+bool eal_option_is_log(int opt);
+int eal_parse_log_options(int argc, char * const argv[]);
 int eal_parse_common_option(int opt, const char *argv,
 			    struct internal_config *conf);
 int eal_option_device_parse(void);
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 89dfc540f2..16b1c67cca 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -393,8 +393,8 @@  eal_parse_args(int argc, char **argv)
 			goto out;
 		}
 
-		/* eal_log_level_parse() already handled this option */
-		if (opt == OPT_LOG_LEVEL_NUM)
+		/* eal_parse_log_options() already handled this option */
+		if (eal_option_is_log(opt))
 			continue;
 
 		ret = eal_parse_common_option(opt, optarg, internal_conf);
@@ -575,8 +575,8 @@  rte_eal_init(int argc, char **argv)
 	/* clone argv to report out later in telemetry */
 	eal_save_args(argc, argv);
 
-	/* set log level as early as possible */
-	eal_log_level_parse(argc, argv);
+	/* parse log options as early as possible */
+	eal_parse_log_options(argc, argv);
 
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index f82a398d4b..49a88cfbd5 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -611,8 +611,8 @@  eal_parse_args(int argc, char **argv)
 			goto out;
 		}
 
-		/* eal_log_level_parse() already handled this option */
-		if (opt == OPT_LOG_LEVEL_NUM)
+		/* eal_parse_log_options() already handled this option */
+		if (eal_option_is_log(opt))
 			continue;
 
 		ret = eal_parse_common_option(opt, optarg, internal_conf);
@@ -951,8 +951,8 @@  rte_eal_init(int argc, char **argv)
 
 	eal_reset_internal_config(internal_conf);
 
-	/* set log level as early as possible */
-	eal_log_level_parse(argc, argv);
+	/* parse log options as early as possible */
+	eal_parse_log_options(argc, argv);
 
 	/* clone argv to report out later in telemetry */
 	eal_save_args(argc, argv);
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index 25e69a429b..f77053eb7e 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -121,8 +121,8 @@  eal_parse_args(int argc, char **argv)
 			return -1;
 		}
 
-		/* eal_log_level_parse() already handled this option */
-		if (opt == OPT_LOG_LEVEL_NUM)
+		/* eal_parse_log_options() already handled this option */
+		if (eal_option_is_log(opt))
 			continue;
 
 		ret = eal_parse_common_option(opt, optarg, internal_conf);
@@ -254,7 +254,8 @@  rte_eal_init(int argc, char **argv)
 
 	eal_log_init(NULL, 0);
 
-	eal_log_level_parse(argc, argv);
+	/* parse log options as early as possible */
+	eal_parse_log_options(argc, argv);
 
 	if (eal_create_cpu_map() < 0) {
 		rte_eal_init_alert("Cannot discover CPU and NUMA.");