diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-09-30 08:15:28 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-10-02 03:52:45 +0200 |
commit | 5f6b79b73b7eeff1b47eff0f2351542de3980c4b (patch) | |
tree | fe20e4a4fd9a680a8ee3dbbccc82cd1afc8aef61 /src | |
parent | journald: do not close all files stored in Server.deferred_closes (diff) | |
download | systemd-5f6b79b73b7eeff1b47eff0f2351542de3980c4b.tar.xz systemd-5f6b79b73b7eeff1b47eff0f2351542de3980c4b.zip |
journald: split-out closing journal files from managed_journal_file_open()
No functional change, just refactoring and preparation for later
commits.
Diffstat (limited to 'src')
-rw-r--r-- | src/journal-remote/journal-remote.c | 1 | ||||
-rw-r--r-- | src/journal/journald-server.c | 5 | ||||
-rw-r--r-- | src/journal/managed-journal-file.c | 12 | ||||
-rw-r--r-- | src/journal/managed-journal-file.h | 2 | ||||
-rw-r--r-- | src/journal/test-journal-append.c | 2 | ||||
-rw-r--r-- | src/journal/test-journal-flush.c | 2 | ||||
-rw-r--r-- | src/journal/test-journal-interleaving.c | 10 | ||||
-rw-r--r-- | src/journal/test-journal-stream.c | 8 | ||||
-rw-r--r-- | src/journal/test-journal-verify.c | 3 | ||||
-rw-r--r-- | src/journal/test-journal.c | 14 |
10 files changed, 24 insertions, 35 deletions
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index 5b845a520f..29da82e65a 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -88,7 +88,6 @@ static int open_output(RemoteServer *s, Writer *w, const char* host) { &w->metrics, w->mmap, NULL, - NULL, &w->journal); if (r < 0) return log_error_errno(r, "Failed to open output journal %s: %m", filename); diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 8b60369b49..83857d0116 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -276,6 +276,8 @@ static int server_open_journal( (seal ? JOURNAL_SEAL : 0) | JOURNAL_STRICT_ORDER; + set_clear_with_destructor(s->deferred_closes, managed_journal_file_close); + if (reliably) r = managed_journal_file_open_reliably( fname, @@ -285,7 +287,6 @@ static int server_open_journal( s->compress.threshold_bytes, metrics, s->mmap, - s->deferred_closes, /* template= */ NULL, &f); else @@ -298,7 +299,6 @@ static int server_open_journal( s->compress.threshold_bytes, metrics, s->mmap, - s->deferred_closes, /* template= */ NULL, &f); if (r < 0) @@ -655,7 +655,6 @@ static int server_archive_offline_user_journals(Server *s) { s->compress.threshold_bytes, &s->system_storage.metrics, s->mmap, - /* deferred_closes= */ NULL, /* template= */ NULL, &f); if (r < 0) { diff --git a/src/journal/managed-journal-file.c b/src/journal/managed-journal-file.c index 9b1fe30747..aa616988b4 100644 --- a/src/journal/managed-journal-file.c +++ b/src/journal/managed-journal-file.c @@ -421,15 +421,12 @@ int managed_journal_file_open( uint64_t compress_threshold_bytes, JournalMetrics *metrics, MMapCache *mmap_cache, - Set *deferred_closes, ManagedJournalFile *template, ManagedJournalFile **ret) { _cleanup_free_ ManagedJournalFile *f = NULL; int r; - set_clear_with_destructor(deferred_closes, managed_journal_file_close); - f = new0(ManagedJournalFile, 1); if (!f) return -ENOMEM; @@ -489,6 +486,8 @@ int managed_journal_file_rotate( if (r < 0) return r; + set_clear_with_destructor(deferred_closes, managed_journal_file_close); + r = managed_journal_file_open( /* fd= */ -1, path, @@ -498,7 +497,6 @@ int managed_journal_file_rotate( compress_threshold_bytes, /* metrics= */ NULL, mmap_cache, - deferred_closes, /* template= */ *f, &new_file); @@ -516,7 +514,6 @@ int managed_journal_file_open_reliably( uint64_t compress_threshold_bytes, JournalMetrics *metrics, MMapCache *mmap_cache, - Set *deferred_closes, ManagedJournalFile *template, ManagedJournalFile **ret) { @@ -532,7 +529,6 @@ int managed_journal_file_open_reliably( compress_threshold_bytes, metrics, mmap_cache, - deferred_closes, template, ret); if (!IN_SET(r, @@ -565,7 +561,7 @@ int managed_journal_file_open_reliably( r = managed_journal_file_open(-1, fname, (open_flags & ~(O_ACCMODE|O_CREAT|O_EXCL)) | O_RDONLY, file_flags, 0, compress_threshold_bytes, NULL, - mmap_cache, deferred_closes, NULL, &old_file); + mmap_cache, NULL, &old_file); if (r < 0) log_debug_errno(r, "Failed to continue sequence from file %s, ignoring: %m", fname); else @@ -577,5 +573,5 @@ int managed_journal_file_open_reliably( return r; return managed_journal_file_open(-1, fname, open_flags, file_flags, mode, compress_threshold_bytes, metrics, - mmap_cache, deferred_closes, template, ret); + mmap_cache, template, ret); } diff --git a/src/journal/managed-journal-file.h b/src/journal/managed-journal-file.h index 0ac69a7985..2fd1e2d6b4 100644 --- a/src/journal/managed-journal-file.h +++ b/src/journal/managed-journal-file.h @@ -16,7 +16,6 @@ int managed_journal_file_open( uint64_t compress_threshold_bytes, JournalMetrics *metrics, MMapCache *mmap_cache, - Set *deferred_closes, ManagedJournalFile *template, ManagedJournalFile **ret); @@ -33,7 +32,6 @@ int managed_journal_file_open_reliably( uint64_t compress_threshold_bytes, JournalMetrics *metrics, MMapCache *mmap_cache, - Set *deferred_closes, ManagedJournalFile *template, ManagedJournalFile **ret); diff --git a/src/journal/test-journal-append.c b/src/journal/test-journal-append.c index 84fa4d5d54..95b6fc1ee5 100644 --- a/src/journal/test-journal-append.c +++ b/src/journal/test-journal-append.c @@ -70,7 +70,6 @@ static int journal_corrupt_and_append(uint64_t start_offset, uint64_t step) { /* compress_threshold_bytes= */ UINT64_MAX, /* metrics= */ NULL, mmap_cache, - /* deferred_closes= */ NULL, /* template= */ NULL, &mj); if (r < 0) @@ -124,7 +123,6 @@ static int journal_corrupt_and_append(uint64_t start_offset, uint64_t step) { /* compress_threshold_bytes= */ UINT64_MAX, /* metrics= */ NULL, mmap_cache, - /* deferred_closes= */ NULL, /* template= */ NULL, &mj); if (r < 0) { diff --git a/src/journal/test-journal-flush.c b/src/journal/test-journal-flush.c index f2fe0e51c0..677d37edc1 100644 --- a/src/journal/test-journal-flush.c +++ b/src/journal/test-journal-flush.c @@ -30,7 +30,7 @@ static void test_journal_flush(int argc, char *argv[]) { assert_se(fn = path_join(dn, "test.journal")); - r = managed_journal_file_open(-1, fn, O_CREAT|O_RDWR, 0, 0644, 0, NULL, m, NULL, NULL, &new_journal); + r = managed_journal_file_open(-1, fn, O_CREAT|O_RDWR, 0, 0644, 0, NULL, m, NULL, &new_journal); assert_se(r >= 0); if (argc > 1) diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c index dfd4497cfd..32427b8b62 100644 --- a/src/journal/test-journal-interleaving.c +++ b/src/journal/test-journal-interleaving.c @@ -42,7 +42,7 @@ static ManagedJournalFile *test_open_internal(const char *name, JournalFileFlags m = mmap_cache_new(); assert_se(m != NULL); - assert_ret(managed_journal_file_open(-1, name, O_RDWR|O_CREAT, flags, 0644, UINT64_MAX, NULL, m, NULL, NULL, &f)); + assert_ret(managed_journal_file_open(-1, name, O_RDWR|O_CREAT, flags, 0644, UINT64_MAX, NULL, m, NULL, &f)); return f; } @@ -459,7 +459,7 @@ static void test_sequence_numbers_one(void) { mkdtemp_chdir_chattr(t); assert_se(managed_journal_file_open(-1, "one.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0644, - UINT64_MAX, NULL, m, NULL, NULL, &one) == 0); + UINT64_MAX, NULL, m, NULL, &one) == 0); append_number(one, 1, NULL, &seqnum); printf("seqnum=%"PRIu64"\n", seqnum); @@ -476,7 +476,7 @@ static void test_sequence_numbers_one(void) { memcpy(&seqnum_id, &one->file->header->seqnum_id, sizeof(sd_id128_t)); assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0644, - UINT64_MAX, NULL, m, NULL, one, &two) == 0); + UINT64_MAX, NULL, m, one, &two) == 0); assert_se(two->file->header->state == STATE_ONLINE); assert_se(!sd_id128_equal(two->file->header->file_id, one->file->header->file_id)); @@ -513,7 +513,7 @@ static void test_sequence_numbers_one(void) { seqnum = 0; assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR, JOURNAL_COMPRESS, 0, - UINT64_MAX, NULL, m, NULL, NULL, &two) == 0); + UINT64_MAX, NULL, m, NULL, &two) == 0); assert_se(sd_id128_equal(two->file->header->seqnum_id, seqnum_id)); @@ -547,7 +547,7 @@ TEST(sequence_numbers) { } static int intro(void) { - /* managed_journal_file_open requires a valid machine id */ + /* managed_journal_file_open() requires a valid machine id */ if (access("/etc/machine-id", F_OK) != 0) return log_tests_skipped("/etc/machine-id not found"); diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c index 940625a084..1220a29e20 100644 --- a/src/journal/test-journal-stream.c +++ b/src/journal/test-journal-stream.c @@ -76,9 +76,9 @@ static void run_test(void) { assert_se(chdir(t) >= 0); (void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL, NULL); - assert_se(managed_journal_file_open(-1, "one.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, NULL, &one) == 0); - assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, NULL, &two) == 0); - assert_se(managed_journal_file_open(-1, "three.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, NULL, &three) == 0); + assert_se(managed_journal_file_open(-1, "one.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, &one) == 0); + assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, &two) == 0); + assert_se(managed_journal_file_open(-1, "three.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, &three) == 0); for (i = 0; i < N_ENTRIES; i++) { char *p, *q; @@ -177,7 +177,7 @@ static void run_test(void) { int main(int argc, char *argv[]) { - /* managed_journal_file_open requires a valid machine id */ + /* managed_journal_file_open() requires a valid machine id */ if (access("/etc/machine-id", F_OK) != 0) return log_tests_skipped("/etc/machine-id not found"); diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c index 97cc0b1514..9a7fa2a734 100644 --- a/src/journal/test-journal-verify.c +++ b/src/journal/test-journal-verify.c @@ -79,7 +79,7 @@ static int run_test(const char *verification_key, ssize_t max_iterations) { m = mmap_cache_new(); assert_se(m != NULL); - /* managed_journal_file_open requires a valid machine id */ + /* managed_journal_file_open() requires a valid machine id */ if (sd_id128_get_machine(NULL) < 0) return log_tests_skipped("No valid machine ID found"); @@ -100,7 +100,6 @@ static int run_test(const char *verification_key, ssize_t max_iterations) { /* compress_threshold_bytes= */ UINT64_MAX, /* metrics= */ NULL, m, - /* deferred_closes= */ NULL, /* template= */ NULL, &df) == 0); diff --git a/src/journal/test-journal.c b/src/journal/test-journal.c index b227b9be6c..92c5b66fe5 100644 --- a/src/journal/test-journal.c +++ b/src/journal/test-journal.c @@ -39,7 +39,7 @@ static void test_non_empty_one(void) { mkdtemp_chdir_chattr(t); - assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS|JOURNAL_SEAL, 0666, UINT64_MAX, NULL, m, NULL, NULL, &f) == 0); + assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS|JOURNAL_SEAL, 0666, UINT64_MAX, NULL, m, NULL, &f) == 0); assert_se(dual_timestamp_get(&ts)); assert_se(sd_id128_randomize(&fake_boot_id) == 0); @@ -136,10 +136,10 @@ static void test_empty_one(void) { mkdtemp_chdir_chattr(t); - assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0, 0666, UINT64_MAX, NULL, m, NULL, NULL, &f1) == 0); - assert_se(managed_journal_file_open(-1, "test-compress.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, NULL, &f2) == 0); - assert_se(managed_journal_file_open(-1, "test-seal.journal", O_RDWR|O_CREAT, JOURNAL_SEAL, 0666, UINT64_MAX, NULL, m, NULL, NULL, &f3) == 0); - assert_se(managed_journal_file_open(-1, "test-seal-compress.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS|JOURNAL_SEAL, 0666, UINT64_MAX, NULL, m, NULL, NULL, &f4) == 0); + assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0, 0666, UINT64_MAX, NULL, m, NULL, &f1) == 0); + assert_se(managed_journal_file_open(-1, "test-compress.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, &f2) == 0); + assert_se(managed_journal_file_open(-1, "test-seal.journal", O_RDWR|O_CREAT, JOURNAL_SEAL, 0666, UINT64_MAX, NULL, m, NULL, &f3) == 0); + assert_se(managed_journal_file_open(-1, "test-seal-compress.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS|JOURNAL_SEAL, 0666, UINT64_MAX, NULL, m, NULL, &f4) == 0); journal_file_print_header(f1->file); puts(""); @@ -194,7 +194,7 @@ static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) { mkdtemp_chdir_chattr(t); - assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS|JOURNAL_SEAL, 0666, compress_threshold, NULL, m, NULL, NULL, &f) == 0); + assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS|JOURNAL_SEAL, 0666, compress_threshold, NULL, m, NULL, &f) == 0); dual_timestamp_get(&ts); @@ -270,7 +270,7 @@ TEST(min_compress_size) { static int intro(void) { arg_keep = saved_argc > 1; - /* managed_journal_file_open requires a valid machine id */ + /* managed_journal_file_open() requires a valid machine id */ if (access("/etc/machine-id", F_OK) != 0) return log_tests_skipped("/etc/machine-id not found"); |