From: Jean-Philippe Brucker <jean-philippe@linaro.org>
To: Alexandru Elisei <alexandru.elisei@arm.com>
Cc: will@kernel.org, julien.thierry.kdev@gmail.com,
Suzuki.Poulose@arm.com, andre.przywara@arm.com, maz@kernel.org,
oliver.upton@linux.dev, jean-philippe.brucker@arm.com,
apatel@ventanamicro.com, kvm@vger.kernel.org
Subject: Re: [PATCH RESEND kvmtool 4/4] Add --loglevel argument for the run command
Date: Tue, 4 Jul 2023 10:53:04 +0100 [thread overview]
Message-ID: <20230704095304.GE3214657@myrica> (raw)
In-Reply-To: <20230630133134.65284-5-alexandru.elisei@arm.com>
On Fri, Jun 30, 2023 at 02:31:34PM +0100, Alexandru Elisei wrote:
> Add --loglevel command line argument, with the possible values of 'error',
> 'warning', 'info' or 'debug' to control what messages kvmtool displays. The
> argument functions similarly to the Linux kernel parameter, when lower
> verbosity levels hide all message with a higher verbosity (for example,
> 'warning' hides info and debug messages, allows warning and error
> messsages).
>
> The default level is 'info', to match the current behaviour. --debug has
> been kept as a legacy option, which might be removed in the future.
>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---
> builtin-run.c | 32 ++++++++++++++++++++++++++++----
> include/kvm/util.h | 9 +++++++--
> util/util.c | 9 +++++++++
> 3 files changed, 44 insertions(+), 6 deletions(-)
>
> diff --git a/builtin-run.c b/builtin-run.c
> index 79d031777c26..2e4378819f00 100644
> --- a/builtin-run.c
> +++ b/builtin-run.c
> @@ -58,8 +58,7 @@
> __thread struct kvm_cpu *current_kvm_cpu;
>
> static int kvm_run_wrapper;
> -
> -bool do_debug_print = false;
> +int loglevel = LOGLEVEL_INFO;
>
> static const char * const run_usage[] = {
> "lkvm run [<options>] [<kernel image>]",
> @@ -146,6 +145,27 @@ static int mem_parser(const struct option *opt, const char *arg, int unset)
> return 0;
> }
>
> +static int loglevel_parser(const struct option *opt, const char *arg, int unset)
> +{
> + if (strcmp(opt->long_name, "debug") == 0) {
> + loglevel = LOGLEVEL_DEBUG;
> + return 0;
> + }
> +
> + if (strcmp(arg, "debug") == 0)
> + loglevel = LOGLEVEL_DEBUG;
> + else if (strcmp(arg, "info") == 0)
> + loglevel = LOGLEVEL_INFO;
> + else if (strcmp(arg, "warning") == 0)
> + loglevel = LOGLEVEL_WARNING;
> + else if (strcmp(arg, "error") == 0)
> + loglevel = LOGLEVEL_ERROR;
> + else
> + die("Unknown loglevel: %s", arg);
> +
> + return 0;
> +}
> +
> #ifndef OPT_ARCH_RUN
> #define OPT_ARCH_RUN(...)
> #endif
> @@ -215,6 +235,8 @@ static int mem_parser(const struct option *opt, const char *arg, int unset)
> VIRTIO_TRANS_OPT_HELP_SHORT, \
> "Type of virtio transport", \
> virtio_transport_parser, NULL), \
> + OPT_CALLBACK('\0', "loglevel", NULL, "[error|warning|info|debug]",\
> + "Set the verbosity level", loglevel_parser, NULL),\
> \
> OPT_GROUP("Kernel options:"), \
> OPT_STRING('k', "kernel", &(cfg)->kernel_filename, "kernel", \
> @@ -241,8 +263,10 @@ static int mem_parser(const struct option *opt, const char *arg, int unset)
> vfio_device_parser, kvm), \
> \
> OPT_GROUP("Debug options:"), \
> - OPT_BOOLEAN('\0', "debug", &do_debug_print, \
> - "Enable debug messages"), \
> + OPT_CALLBACK_NOOPT('\0', "debug", kvm, NULL, \
> + "Enable debug messages (deprecated, use " \
> + "--loglevel=debug instead)", \
> + loglevel_parser, NULL), \
> OPT_BOOLEAN('\0', "debug-single-step", &(cfg)->single_step, \
> "Enable single stepping"), \
> OPT_BOOLEAN('\0', "debug-ioport", &(cfg)->ioport_debug, \
> diff --git a/include/kvm/util.h b/include/kvm/util.h
> index 6920ce2630ad..e9d63c184752 100644
> --- a/include/kvm/util.h
> +++ b/include/kvm/util.h
> @@ -32,7 +32,10 @@
> #endif
> #endif
>
> -extern bool do_debug_print;
> +#define LOGLEVEL_ERROR 0
> +#define LOGLEVEL_WARNING 1
> +#define LOGLEVEL_INFO 2
> +#define LOGLEVEL_DEBUG 3
>
> #define PROT_RW (PROT_READ|PROT_WRITE)
> #define MAP_ANON_NORESERVE (MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE)
> @@ -45,9 +48,11 @@ extern void pr_info(const char *err, ...) __attribute__((format (printf, 1, 2)))
> extern void __pr_debug(const char *err, ...) __attribute__((format (printf, 1, 2)));
> extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
>
> +extern int loglevel;
> +
> #define pr_debug(fmt, ...) \
> do { \
> - if (do_debug_print) \
> + if (loglevel >= LOGLEVEL_DEBUG) \
> __pr_debug("(%s) %s:%d: " fmt, __FILE__, \
> __func__, __LINE__, ##__VA_ARGS__); \
> } while (0)
> diff --git a/util/util.c b/util/util.c
> index e3b36f67f899..962e8d4edb21 100644
> --- a/util/util.c
> +++ b/util/util.c
> @@ -56,6 +56,9 @@ void pr_err(const char *err, ...)
> {
> va_list params;
>
> + if (loglevel < LOGLEVEL_ERROR)
> + return;
> +
> va_start(params, err);
> error_builtin(err, params);
> va_end(params);
> @@ -65,6 +68,9 @@ void pr_warning(const char *warn, ...)
> {
> va_list params;
>
> + if (loglevel < LOGLEVEL_WARNING)
> + return;
> +
> va_start(params, warn);
> warn_builtin(warn, params);
> va_end(params);
> @@ -74,6 +80,9 @@ void pr_info(const char *info, ...)
> {
> va_list params;
>
> + if (loglevel < LOGLEVEL_INFO)
> + return;
> +
> va_start(params, info);
> info_builtin(info, params);
> va_end(params);
> --
> 2.41.0
>
prev parent reply other threads:[~2023-07-04 9:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-30 13:31 [PATCH RESEND kvmtool 0/4] Add --loglevel argument Alexandru Elisei
2023-06-30 13:31 ` [PATCH RESEND kvmtool 1/4] util: Make pr_err() return void Alexandru Elisei
2023-07-04 9:37 ` Jean-Philippe Brucker
2023-07-07 13:10 ` Alexandru Elisei
2023-06-30 13:31 ` [PATCH RESEND kvmtool 2/4] Replace printf/fprintf with pr_* macros Alexandru Elisei
2023-07-04 9:46 ` Jean-Philippe Brucker
2023-07-07 13:29 ` Alexandru Elisei
2023-07-07 14:21 ` Jean-Philippe Brucker
2023-06-30 13:31 ` [PATCH RESEND kvmtool 3/4] util: Use __pr_debug() instead of pr_info() to print debug messages Alexandru Elisei
2023-07-04 9:50 ` Jean-Philippe Brucker
2023-07-07 13:35 ` Alexandru Elisei
2023-06-30 13:31 ` [PATCH RESEND kvmtool 4/4] Add --loglevel argument for the run command Alexandru Elisei
2023-07-04 9:53 ` Jean-Philippe Brucker [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230704095304.GE3214657@myrica \
--to=jean-philippe@linaro.org \
--cc=Suzuki.Poulose@arm.com \
--cc=alexandru.elisei@arm.com \
--cc=andre.przywara@arm.com \
--cc=apatel@ventanamicro.com \
--cc=jean-philippe.brucker@arm.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox