[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 37/39] util/log: Rename QemuLogFile to RCUCloseFILE
From: |
Richard Henderson |
Subject: |
[PULL 37/39] util/log: Rename QemuLogFile to RCUCloseFILE |
Date: |
Wed, 20 Apr 2022 11:06:16 -0700 |
s/QemuLogFile/RCUCloseFILE/
s/qemu_logfile_free/rcu_close_file/
Emphasize that this is only a carrier for passing a pointer
to call_rcu for closing, and not the real logfile.
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220417183019.755276-38-richard.henderson@linaro.org>
---
util/log.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/util/log.c b/util/log.c
index 21da961d8d..eb6e85b2f0 100644
--- a/util/log.c
+++ b/util/log.c
@@ -29,15 +29,15 @@
#include "qemu/rcu.h"
-typedef struct QemuLogFile {
+typedef struct RCUCloseFILE {
struct rcu_head rcu;
FILE *fd;
-} QemuLogFile;
+} RCUCloseFILE;
/* Mutex covering the other global_* variables. */
static QemuMutex global_mutex;
static char *global_filename;
-static QemuLogFile *global_file;
+static RCUCloseFILE *global_file;
int qemu_loglevel;
static int log_append = 0;
@@ -52,7 +52,7 @@ bool qemu_log_enabled(void)
/* Returns true if qemu_log() will write somewhere other than stderr. */
bool qemu_log_separate(void)
{
- QemuLogFile *logfile;
+ RCUCloseFILE *logfile;
bool res = false;
rcu_read_lock();
@@ -68,7 +68,7 @@ bool qemu_log_separate(void)
FILE *qemu_log_trylock(void)
{
- QemuLogFile *logfile;
+ RCUCloseFILE *logfile;
rcu_read_lock();
logfile = qatomic_rcu_read(&global_file);
@@ -108,14 +108,12 @@ static void __attribute__((__constructor__)) startup(void)
qemu_mutex_init(&global_mutex);
}
-static void qemu_logfile_free(QemuLogFile *logfile)
+static void rcu_close_file(RCUCloseFILE *r)
{
- g_assert(logfile);
-
- if (logfile->fd != stderr) {
- fclose(logfile->fd);
+ if (r->fd != stderr) {
+ fclose(r->fd);
}
- g_free(logfile);
+ g_free(r);
}
/* enable or disable low levels log */
@@ -124,7 +122,7 @@ static bool qemu_set_log_internal(const char *filename,
bool changed_name,
{
bool need_to_open_file;
bool daemonized;
- QemuLogFile *logfile;
+ RCUCloseFILE *logfile;
QEMU_LOCK_GUARD(&global_mutex);
logfile = global_file;
@@ -178,7 +176,7 @@ static bool qemu_set_log_internal(const char *filename,
bool changed_name,
if (logfile && (!need_to_open_file || changed_name)) {
qatomic_rcu_set(&global_file, NULL);
- call_rcu(logfile, qemu_logfile_free, rcu);
+ call_rcu(logfile, rcu_close_file, rcu);
logfile = NULL;
}
@@ -196,7 +194,7 @@ static bool qemu_set_log_internal(const char *filename,
bool changed_name,
if (daemonized) {
dup2(fileno(fd), STDERR_FILENO);
fclose(fd);
- /* This will skip closing logfile in qemu_logfile_free. */
+ /* This will skip closing logfile in rcu_close_file. */
fd = stderr;
}
} else {
@@ -207,7 +205,7 @@ static bool qemu_set_log_internal(const char *filename,
bool changed_name,
log_append = 1;
- logfile = g_new0(QemuLogFile, 1);
+ logfile = g_new0(RCUCloseFILE, 1);
logfile->fd = fd;
qatomic_rcu_set(&global_file, logfile);
}
--
2.34.1
- [PULL 27/39] util/log: Introduce qemu_set_log_filename_flags, (continued)
- [PULL 27/39] util/log: Introduce qemu_set_log_filename_flags, Richard Henderson, 2022/04/20
- [PULL 26/39] sysemu/os-win32: Test for and use _lock_file/_unlock_file, Richard Henderson, 2022/04/20
- [PULL 29/39] linux-user: Use qemu_set_log_filename_flags, Richard Henderson, 2022/04/20
- [PULL 30/39] softmmu: Use qemu_set_log_filename_flags, Richard Henderson, 2022/04/20
- [PULL 31/39] util/log: Remove qemu_log_close, Richard Henderson, 2022/04/20
- [PULL 32/39] util/log: Rename logfilename to global_filename, Richard Henderson, 2022/04/20
- [PULL 35/39] util/log: Hoist the eval of is_daemonized in qemu_set_log_internal, Richard Henderson, 2022/04/20
- [PULL 28/39] bsd-user: Use qemu_set_log_filename_flags, Richard Henderson, 2022/04/20
- [PULL 33/39] util/log: Rename qemu_logfile to global_file, Richard Henderson, 2022/04/20
- [PULL 36/39] util/log: Combine two logfile closes, Richard Henderson, 2022/04/20
- [PULL 37/39] util/log: Rename QemuLogFile to RCUCloseFILE,
Richard Henderson <=
- [PULL 38/39] util/log: Limit RCUCloseFILE to file closing, Richard Henderson, 2022/04/20
- [PULL 39/39] util/log: Support per-thread log files, Richard Henderson, 2022/04/20
- [PULL 34/39] util/log: Rename qemu_logfile_mutex to global_mutex, Richard Henderson, 2022/04/20
- Re: [PULL 00/39] Logging cleanup and per-thread logfiles, Richard Henderson, 2022/04/20