From: "Alex Bennée" <alex.bennee@linaro.org>
To: Robert Foley <robert.foley@linaro.org>
Cc: peter.puhov@linaro.org, qemu-devel@nongnu.org
Subject: Re: [PATCH 1/4] Add a mutex to guarantee single writer to qemu_logfile handle.
Date: Thu, 07 Nov 2019 16:53:41 +0000 [thread overview]
Message-ID: <87o8xnhbl6.fsf@linaro.org> (raw)
In-Reply-To: <20191107142613.2379-2-robert.foley@linaro.org>
Robert Foley <robert.foley@linaro.org> writes:
> This is being added in preparation for using RCU with the logfile handle.
> Also added qemu_logfile_init() for initializing the logfile mutex.
>
> Signed-off-by: Robert Foley <robert.foley@linaro.org>
> ---
> util/log.c | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/util/log.c b/util/log.c
> index 1ca13059ee..dff2f98c8c 100644
> --- a/util/log.c
> +++ b/util/log.c
> @@ -24,8 +24,11 @@
> #include "qapi/error.h"
> #include "qemu/cutils.h"
> #include "trace/control.h"
> +#include "qemu/thread.h"
>
> static char *logfilename;
> +static bool qemu_logfile_initialized;
> +static QemuMutex qemu_logfile_mutex;
> FILE *qemu_logfile;
> int qemu_loglevel;
> static int log_append = 0;
> @@ -49,6 +52,14 @@ int qemu_log(const char *fmt, ...)
> return ret;
> }
>
> +static void qemu_logfile_init(void)
> +{
> + if (!qemu_logfile_initialized) {
> + qemu_mutex_init(&qemu_logfile_mutex);
> + qemu_logfile_initialized = true;
> + }
> +}
> +
> static bool log_uses_own_buffers;
>
> /* enable or disable low levels log */
> @@ -58,6 +69,12 @@ void qemu_set_log(int log_flags)
> #ifdef CONFIG_TRACE_LOG
> qemu_loglevel |= LOG_TRACE;
> #endif
> +
> + /* Is there a better place to call this to init the logfile subsystem? */
> + if (!qemu_logfile_initialized) {
> + qemu_logfile_init();
> + }
It wouldn't be the worst thing in the world to expose:
qemu_logfile_init()
and make vl.c and main.c call it before the setup. Then you can drop the
flag or even just g_assert(qemu_log_mutex_initialised) in qemu_set_log
and qemu_set_logfile.
In fact you could just use:
static void __attribute__((__constructor__)) qemu_logfile_init(void)
and make the compiler do it for you.
> + qemu_mutex_lock(&qemu_logfile_mutex);
> if (!qemu_logfile &&
> (is_daemonized() ? logfilename != NULL : qemu_loglevel)) {
> if (logfilename) {
> @@ -93,6 +110,7 @@ void qemu_set_log(int log_flags)
> log_append = 1;
> }
> }
> + qemu_mutex_unlock(&qemu_logfile_mutex);
> if (qemu_logfile &&
> (is_daemonized() ? logfilename == NULL : !qemu_loglevel)) {
> qemu_log_close();
> @@ -114,6 +132,11 @@ void qemu_set_log_filename(const char *filename, Error **errp)
> char *pidstr;
> g_free(logfilename);
>
> + /* Is there a better place to call this to init the logfile subsystem? */
> + if (!qemu_logfile_initialized) {
> + qemu_logfile_init();
> + }
> +
> pidstr = strstr(filename, "%");
> if (pidstr) {
> /* We only accept one %d, no other format strings */
--
Alex Bennée
next prev parent reply other threads:[~2019-11-07 17:06 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-07 14:26 [PATCH 0/4] Make the qemu_logfile handle thread safe Robert Foley
2019-11-07 14:26 ` [PATCH 1/4] Add a mutex to guarantee single writer to qemu_logfile handle Robert Foley
2019-11-07 16:53 ` Alex Bennée [this message]
2019-11-07 21:54 ` Robert Foley
2019-11-07 14:26 ` [PATCH 2/4] Add use of RCU for qemu_logfile Robert Foley
2019-11-07 16:23 ` Alex Bennée
2019-11-07 21:13 ` Robert Foley
2019-11-07 14:26 ` [PATCH 3/4] qemu_log_lock/unlock now preserves the qemu_logfile handle Robert Foley
2019-11-07 16:25 ` Alex Bennée
2019-11-07 21:22 ` Robert Foley
2019-11-07 14:26 ` [PATCH 4/4] Added tests for close and change of logfile Robert Foley
2019-11-07 16:32 ` Alex Bennée
2019-11-07 17:26 ` Alex Bennée
2019-11-07 19:38 ` Robert Foley
2019-11-07 20:12 ` Alex Bennée
2019-11-07 22:11 ` Robert Foley
2019-11-07 21:33 ` Robert Foley
2019-11-07 14:46 ` [PATCH 0/4] Make the qemu_logfile handle thread safe no-reply
2019-11-07 16:35 ` Alex Bennée
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=87o8xnhbl6.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=peter.puhov@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=robert.foley@linaro.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;
as well as URLs for NNTP newsgroup(s).