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

Message ID 20241107205145.2424871-4-david.marchand@redhat.com (mailing list archive)
State Superseded, 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. 7, 2024, 8:51 p.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 d3b40e81d8..8563ef1156 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -392,8 +392,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);
@@ -574,8 +574,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 40d750ed0d..9ac52ea500 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -610,8 +610,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);
@@ -950,8 +950,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 a77e590a72..69d367fb8e 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -120,8 +120,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);
@@ -252,7 +252,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.");