mirror of
https://github.com/systemd/systemd.git
synced 2024-12-03 23:33:38 +08:00
Merge pull request #32617 from yuwata/journal-sync
journald: wait for journal files fsync()ed on Synchronize() varlink method
This commit is contained in:
commit
89ad0a7117
@ -91,6 +91,9 @@
|
||||
|
||||
#define FAILED_TO_WRITE_ENTRY_RATELIMIT ((const RateLimit) { .interval = 1 * USEC_PER_SEC, .burst = 1 })
|
||||
|
||||
static int server_schedule_sync(Server *s, int priority);
|
||||
static int server_refresh_idle_timer(Server *s);
|
||||
|
||||
static int server_determine_path_usage(
|
||||
Server *s,
|
||||
const char *path,
|
||||
@ -747,19 +750,19 @@ static void server_rotate_journal(Server *s, JournalFile *f, uid_t uid) {
|
||||
server_process_deferred_closes(s);
|
||||
}
|
||||
|
||||
void server_sync(Server *s) {
|
||||
static void server_sync(Server *s, bool wait) {
|
||||
JournalFile *f;
|
||||
int r;
|
||||
|
||||
if (s->system_journal) {
|
||||
r = journal_file_set_offline(s->system_journal, false);
|
||||
r = journal_file_set_offline(s->system_journal, wait);
|
||||
if (r < 0)
|
||||
log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
|
||||
"Failed to sync system journal, ignoring: %m");
|
||||
}
|
||||
|
||||
ORDERED_HASHMAP_FOREACH(f, s->user_journals) {
|
||||
r = journal_file_set_offline(f, false);
|
||||
r = journal_file_set_offline(f, wait);
|
||||
if (r < 0)
|
||||
log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
|
||||
"Failed to sync user journal, ignoring: %m");
|
||||
@ -1593,7 +1596,7 @@ static void server_full_flush(Server *s) {
|
||||
assert(s);
|
||||
|
||||
(void) server_flush_to_var(s, false);
|
||||
server_sync(s);
|
||||
server_sync(s, /* wait = */ false);
|
||||
server_vacuum(s, false);
|
||||
|
||||
server_space_usage_message(s, NULL);
|
||||
@ -1725,13 +1728,13 @@ fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void server_full_sync(Server *s) {
|
||||
static void server_full_sync(Server *s, bool wait) {
|
||||
const char *fn;
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
|
||||
server_sync(s);
|
||||
server_sync(s, wait);
|
||||
|
||||
/* Let clients know when the most recent sync happened. */
|
||||
fn = strjoina(s->runtime_directory, "/synced");
|
||||
@ -1739,15 +1742,13 @@ static void server_full_sync(Server *s) {
|
||||
if (r < 0)
|
||||
log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
|
||||
"Failed to write %s, ignoring: %m", fn);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int dispatch_sigrtmin1(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
|
||||
Server *s = ASSERT_PTR(userdata);
|
||||
|
||||
log_debug("Received SIGRTMIN1 signal from PID %u, as request to sync.", si->ssi_pid);
|
||||
server_full_sync(s);
|
||||
server_full_sync(s, /* wait = */ false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1934,24 +1935,24 @@ static int server_parse_config_file(Server *s) {
|
||||
static int server_dispatch_sync(sd_event_source *es, usec_t t, void *userdata) {
|
||||
Server *s = ASSERT_PTR(userdata);
|
||||
|
||||
server_sync(s);
|
||||
server_sync(s, /* wait = */ false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int server_schedule_sync(Server *s, int priority) {
|
||||
static int server_schedule_sync(Server *s, int priority) {
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
|
||||
if (priority <= LOG_CRIT) {
|
||||
/* Immediately sync to disk when this is of priority CRIT, ALERT, EMERG */
|
||||
server_sync(s);
|
||||
server_sync(s, /* wait = */ false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!s->event || sd_event_get_state(s->event) == SD_EVENT_FINISHED) {
|
||||
/* Shutting down the server? Let's sync immediately. */
|
||||
server_sync(s);
|
||||
server_sync(s, /* wait = */ false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2170,7 +2171,7 @@ static int synchronize_second_half(sd_event_source *event_source, void *userdata
|
||||
/* This is the "second half" of the Synchronize() varlink method. This function is called as deferred
|
||||
* event source at a low priority to ensure the synchronization completes after all queued log
|
||||
* messages are processed. */
|
||||
server_full_sync(s);
|
||||
server_full_sync(s, /* wait = */ true);
|
||||
|
||||
/* Let's get rid of the event source now, by marking it as non-floating again. It then has no ref
|
||||
* anymore and is immediately destroyed after we return from this function, i.e. from this event
|
||||
@ -2375,7 +2376,7 @@ int server_map_seqnum_file(
|
||||
return 0;
|
||||
}
|
||||
|
||||
void server_unmap_seqnum_file(void *p, size_t size) {
|
||||
static void server_unmap_seqnum_file(void *p, size_t size) {
|
||||
assert(size > 0);
|
||||
|
||||
if (!p)
|
||||
@ -2445,7 +2446,7 @@ int server_start_or_stop_idle_timer(Server *s) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int server_refresh_idle_timer(Server *s) {
|
||||
static int server_refresh_idle_timer(Server *s) {
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
|
@ -232,17 +232,13 @@ int server_new(Server **ret);
|
||||
int server_init(Server *s, const char *namespace);
|
||||
Server* server_free(Server *s);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Server*, server_free);
|
||||
void server_sync(Server *s);
|
||||
void server_vacuum(Server *s, bool verbose);
|
||||
void server_rotate(Server *s);
|
||||
int server_schedule_sync(Server *s, int priority);
|
||||
int server_flush_to_var(Server *s, bool require_flag_file);
|
||||
void server_maybe_append_tags(Server *s);
|
||||
int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata);
|
||||
void server_space_usage_message(Server *s, JournalStorage *storage);
|
||||
|
||||
int server_start_or_stop_idle_timer(Server *s);
|
||||
int server_refresh_idle_timer(Server *s);
|
||||
|
||||
int server_map_seqnum_file(Server *s, const char *fname, size_t size, void **ret);
|
||||
void server_unmap_seqnum_file(void *p, size_t size);
|
||||
|
Loading…
Reference in New Issue
Block a user