[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 13/16] Add a mutex to guarantee single writer to qemu_logfile
From: |
Alex Bennée |
Subject: |
[PATCH v1 13/16] Add a mutex to guarantee single writer to qemu_logfile handle. |
Date: |
Mon, 16 Dec 2019 11:07:29 +0000 |
From: Robert Foley <address@hidden>
Also added qemu_logfile_init() for initializing the logfile mutex.
Note that inside qemu_set_log() we needed to add a pair of
qemu_mutex_unlock() calls in order to avoid a double lock in
qemu_log_close(). This unavoidable temporary ugliness will be
cleaned up in a later patch in this series.
Signed-off-by: Robert Foley <address@hidden>
Reviewed-by: Alex Bennée <address@hidden>
Signed-off-by: Alex Bennée <address@hidden>
Message-Id: <address@hidden>
---
util/log.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/util/log.c b/util/log.c
index 417d16ec66e..953a66b5a8d 100644
--- a/util/log.c
+++ b/util/log.c
@@ -24,8 +24,10 @@
#include "qapi/error.h"
#include "qemu/cutils.h"
#include "trace/control.h"
+#include "qemu/thread.h"
static char *logfilename;
+static QemuMutex qemu_logfile_mutex;
FILE *qemu_logfile;
int qemu_loglevel;
static int log_append = 0;
@@ -49,6 +51,11 @@ int qemu_log(const char *fmt, ...)
return ret;
}
+static void __attribute__((__constructor__)) qemu_logfile_init(void)
+{
+ qemu_mutex_init(&qemu_logfile_mutex);
+}
+
static bool log_uses_own_buffers;
/* enable or disable low levels log */
@@ -70,7 +77,9 @@ void qemu_set_log(int log_flags)
if (qemu_loglevel && (!is_daemonized() || logfilename)) {
need_to_open_file = true;
}
+ qemu_mutex_lock(&qemu_logfile_mutex);
if (qemu_logfile && !need_to_open_file) {
+ qemu_mutex_unlock(&qemu_logfile_mutex);
qemu_log_close();
} else if (!qemu_logfile && need_to_open_file) {
if (logfilename) {
@@ -105,6 +114,7 @@ void qemu_set_log(int log_flags)
#endif
log_append = 1;
}
+ qemu_mutex_unlock(&qemu_logfile_mutex);
}
}
@@ -240,12 +250,14 @@ void qemu_log_flush(void)
/* Close the log file */
void qemu_log_close(void)
{
+ qemu_mutex_lock(&qemu_logfile_mutex);
if (qemu_logfile) {
if (qemu_logfile != stderr) {
fclose(qemu_logfile);
}
qemu_logfile = NULL;
}
+ qemu_mutex_unlock(&qemu_logfile_mutex);
}
const QEMULogItem qemu_log_items[] = {
--
2.20.1
- [PATCH v1 04/16] iotests: Provide a function for checking the creation of huge files, (continued)
- [PATCH v1 04/16] iotests: Provide a function for checking the creation of huge files, Alex Bennée, 2019/12/16
- [PATCH v1 05/16] iotests: Skip test 060 if it is not possible to create large files, Alex Bennée, 2019/12/16
- [PATCH v1 06/16] iotests: Skip test 079 if it is not possible to create large files, Alex Bennée, 2019/12/16
- [PATCH v1 07/16] tests/hd-geo-test: Skip test when images can not be created, Alex Bennée, 2019/12/16
- [PATCH v1 08/16] tests/test-util-filemonitor: Skip test on non-x86 Travis containers, Alex Bennée, 2019/12/16
- [PATCH v1 10/16] ci: build out-of-tree, Alex Bennée, 2019/12/16
- [PATCH v1 11/16] Fix double free issue in qemu_set_log_filename()., Alex Bennée, 2019/12/16
- [PATCH v1 09/16] travis.yml: Enable builds on arm64, ppc64le and s390x, Alex Bennée, 2019/12/16
- [PATCH v1 13/16] Add a mutex to guarantee single writer to qemu_logfile handle.,
Alex Bennée <=
- [PATCH v1 16/16] Added tests for close and change of logfile., Alex Bennée, 2019/12/16
- [PATCH v1 12/16] Cleaned up flow of code in qemu_set_log(), to simplify and clarify., Alex Bennée, 2019/12/16
- [PATCH v1 15/16] Add use of RCU for qemu_logfile., Alex Bennée, 2019/12/16
- [PATCH v1 14/16] qemu_log_lock/unlock now preserves the qemu_logfile handle., Alex Bennée, 2019/12/16