summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-09-30 08:46:16 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-10-02 03:52:45 +0200
commit45c0ecba2d502acb85405bf1330f1a466fc0cc3b (patch)
tree3d70a92e24cdeec01661c71b031d3fad4bf126ba
parentjournald: split-out closing journal files from managed_journal_file_open() (diff)
downloadsystemd-45c0ecba2d502acb85405bf1330f1a466fc0cc3b.tar.xz
systemd-45c0ecba2d502acb85405bf1330f1a466fc0cc3b.zip
journald: drop ManagedJournalFile
The ManagedJournalFile object is a trivial wrapper of JournalFile. Let's drop it, and also drop 'managed_' prefix from the functions.
-rw-r--r--src/journal-remote/journal-remote-write.c22
-rw-r--r--src/journal-remote/journal-remote-write.h2
-rw-r--r--src/journal-remote/journal-remote.c4
-rw-r--r--src/journal/journald-server.c114
-rw-r--r--src/journal/journald-server.h4
-rw-r--r--src/journal/journald.c2
-rw-r--r--src/journal/managed-journal-file.c196
-rw-r--r--src/journal/managed-journal-file.h35
-rw-r--r--src/journal/test-journal-append.c63
-rw-r--r--src/journal/test-journal-flush.c8
-rw-r--r--src/journal/test-journal-interleaving.c68
-rw-r--r--src/journal/test-journal-stream.c22
-rw-r--r--src/journal/test-journal-verify.c10
-rw-r--r--src/journal/test-journal.c98
14 files changed, 298 insertions, 350 deletions
diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c
index 158d015d89..f972b1fd47 100644
--- a/src/journal-remote/journal-remote-write.c
+++ b/src/journal-remote/journal-remote-write.c
@@ -7,13 +7,13 @@
#include "path-util.h"
#include "stat-util.h"
-static int do_rotate(ManagedJournalFile **f, MMapCache *m, JournalFileFlags file_flags) {
+static int do_rotate(JournalFile **f, MMapCache *m, JournalFileFlags file_flags) {
int r;
- r = managed_journal_file_rotate(f, m, file_flags, UINT64_MAX, NULL);
+ r = journal_file_rotate(f, m, file_flags, UINT64_MAX, NULL);
if (r < 0) {
if (*f)
- log_error_errno(r, "Failed to rotate %s: %m", (*f)->file->path);
+ log_error_errno(r, "Failed to rotate %s: %m", (*f)->path);
else
log_error_errno(r, "Failed to create rotated journal: %m");
}
@@ -61,8 +61,8 @@ static Writer* writer_free(Writer *w) {
return NULL;
if (w->journal) {
- log_debug("Closing journal file %s.", w->journal->file->path);
- managed_journal_file_close(w->journal);
+ log_debug("Closing journal file %s.", w->journal->path);
+ journal_file_offline_close(w->journal);
}
if (w->server && w->hashmap_key)
@@ -90,9 +90,9 @@ int writer_write(Writer *w,
assert(w);
assert(!iovw_isempty(iovw));
- if (journal_file_rotate_suggested(w->journal->file, 0, LOG_DEBUG)) {
+ if (journal_file_rotate_suggested(w->journal, 0, LOG_DEBUG)) {
log_info("%s: Journal header limits reached or header out-of-date, rotating",
- w->journal->file->path);
+ w->journal->path);
r = do_rotate(&w->journal, w->mmap, file_flags);
if (r < 0)
return r;
@@ -102,7 +102,7 @@ int writer_write(Writer *w,
}
r = journal_file_append_entry(
- w->journal->file,
+ w->journal,
ts,
boot_id,
iovw->iovec,
@@ -118,19 +118,19 @@ int writer_write(Writer *w,
} else if (r == -EBADMSG)
return r;
- log_debug_errno(r, "%s: Write failed, rotating: %m", w->journal->file->path);
+ log_debug_errno(r, "%s: Write failed, rotating: %m", w->journal->path);
r = do_rotate(&w->journal, w->mmap, file_flags);
if (r < 0)
return r;
else
- log_debug("%s: Successfully rotated journal", w->journal->file->path);
+ log_debug("%s: Successfully rotated journal", w->journal->path);
r = journal_directory_vacuum(w->output, w->metrics.max_use, w->metrics.n_max_files, 0, NULL, /* verbose = */ true);
if (r < 0)
return r;
log_debug("Retrying write.");
r = journal_file_append_entry(
- w->journal->file,
+ w->journal,
ts,
boot_id,
iovw->iovec, iovw->count,
diff --git a/src/journal-remote/journal-remote-write.h b/src/journal-remote/journal-remote-write.h
index 55513d9bf7..65ec2a599a 100644
--- a/src/journal-remote/journal-remote-write.h
+++ b/src/journal-remote/journal-remote-write.h
@@ -7,7 +7,7 @@
typedef struct RemoteServer RemoteServer;
typedef struct Writer {
- ManagedJournalFile *journal;
+ JournalFile *journal;
JournalMetrics metrics;
char *output; /* directory where we write, for vacuuming */
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index 29da82e65a..16f74ef066 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -79,7 +79,7 @@ static int open_output(RemoteServer *s, Writer *w, const char* host) {
assert_not_reached();
}
- r = managed_journal_file_open_reliably(
+ r = journal_file_open_reliably(
filename,
O_RDWR|O_CREAT,
s->file_flags,
@@ -92,7 +92,7 @@ static int open_output(RemoteServer *s, Writer *w, const char* host) {
if (r < 0)
return log_error_errno(r, "Failed to open output journal %s: %m", filename);
- log_debug("Opened output file %s", w->journal->file->path);
+ log_debug("Opened output file %s", w->journal->path);
return 0;
}
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 83857d0116..3b07a4bf0d 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -238,7 +238,7 @@ void server_space_usage_message(Server *s, JournalStorage *storage) {
NULL);
}
-static void server_add_acls(ManagedJournalFile *f, uid_t uid) {
+static void server_add_acls(JournalFile *f, uid_t uid) {
assert(f);
#if HAVE_ACL
@@ -247,10 +247,10 @@ static void server_add_acls(ManagedJournalFile *f, uid_t uid) {
if (uid_for_system_journal(uid))
return;
- r = fd_add_uid_acl_permission(f->file->fd, uid, ACL_READ);
+ r = fd_add_uid_acl_permission(f->fd, uid, ACL_READ);
if (r < 0)
log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
- "Failed to set ACL on %s, ignoring: %m", f->file->path);
+ "Failed to set ACL on %s, ignoring: %m", f->path);
#endif
}
@@ -261,9 +261,9 @@ static int server_open_journal(
int open_flags,
bool seal,
JournalMetrics *metrics,
- ManagedJournalFile **ret) {
+ JournalFile **ret) {
- _cleanup_(managed_journal_file_closep) ManagedJournalFile *f = NULL;
+ _cleanup_(journal_file_offline_closep) JournalFile *f = NULL;
JournalFileFlags file_flags;
int r;
@@ -276,10 +276,10 @@ static int server_open_journal(
(seal ? JOURNAL_SEAL : 0) |
JOURNAL_STRICT_ORDER;
- set_clear_with_destructor(s->deferred_closes, managed_journal_file_close);
+ set_clear_with_destructor(s->deferred_closes, journal_file_offline_close);
if (reliably)
- r = managed_journal_file_open_reliably(
+ r = journal_file_open_reliably(
fname,
open_flags,
file_flags,
@@ -290,7 +290,7 @@ static int server_open_journal(
/* template= */ NULL,
&f);
else
- r = managed_journal_file_open(
+ r = journal_file_open(
/* fd= */ -1,
fname,
open_flags,
@@ -304,7 +304,7 @@ static int server_open_journal(
if (r < 0)
return r;
- r = journal_file_enable_post_change_timer(f->file, s->event, POST_CHANGE_TIMER_INTERVAL_USEC);
+ r = journal_file_enable_post_change_timer(f, s->event, POST_CHANGE_TIMER_INTERVAL_USEC);
if (r < 0)
return r;
@@ -434,8 +434,8 @@ static int server_system_journal_open(
return r;
}
-static int server_find_user_journal(Server *s, uid_t uid, ManagedJournalFile **ret) {
- _cleanup_(managed_journal_file_closep) ManagedJournalFile *f = NULL;
+static int server_find_user_journal(Server *s, uid_t uid, JournalFile **ret) {
+ _cleanup_(journal_file_offline_closep) JournalFile *f = NULL;
_cleanup_free_ char *p = NULL;
int r;
@@ -450,10 +450,10 @@ static int server_find_user_journal(Server *s, uid_t uid, ManagedJournalFile **r
/* Too many open? Then let's close one (or more) */
while (ordered_hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
- ManagedJournalFile *first;
+ JournalFile *first;
assert_se(first = ordered_hashmap_steal_first(s->user_journals));
- (void) managed_journal_file_close(first);
+ (void) journal_file_offline_close(first);
}
r = server_open_journal(
@@ -478,7 +478,7 @@ found:
return 0;
}
-static ManagedJournalFile* server_find_journal(Server *s, uid_t uid) {
+static JournalFile* server_find_journal(Server *s, uid_t uid) {
int r;
assert(s);
@@ -507,7 +507,7 @@ static ManagedJournalFile* server_find_journal(Server *s, uid_t uid) {
return NULL;
if (!uid_for_system_journal(uid)) {
- ManagedJournalFile *f = NULL;
+ JournalFile *f = NULL;
r = server_find_user_journal(s, uid, &f);
if (r >= 0)
@@ -521,7 +521,7 @@ static ManagedJournalFile* server_find_journal(Server *s, uid_t uid) {
static int server_do_rotate(
Server *s,
- ManagedJournalFile **f,
+ JournalFile **f,
const char* name,
bool seal,
uint32_t uid) {
@@ -539,11 +539,11 @@ static int server_do_rotate(
(seal ? JOURNAL_SEAL : 0) |
JOURNAL_STRICT_ORDER;
- r = managed_journal_file_rotate(f, s->mmap, file_flags, s->compress.threshold_bytes, s->deferred_closes);
+ r = journal_file_rotate(f, s->mmap, file_flags, s->compress.threshold_bytes, s->deferred_closes);
if (r < 0) {
if (*f)
return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
- "Failed to rotate %s: %m", (*f)->file->path);
+ "Failed to rotate %s: %m", (*f)->path);
else
return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT,
"Failed to create new %s journal: %m", name);
@@ -554,15 +554,15 @@ static int server_do_rotate(
}
static void server_process_deferred_closes(Server *s) {
- ManagedJournalFile *f;
+ JournalFile *f;
/* Perform any deferred closes which aren't still offlining. */
SET_FOREACH(f, s->deferred_closes) {
- if (managed_journal_file_is_offlining(f))
+ if (journal_file_is_offlining(f))
continue;
(void) set_remove(s->deferred_closes, f);
- (void) managed_journal_file_close(f);
+ (void) journal_file_offline_close(f);
}
}
@@ -578,10 +578,10 @@ static void server_vacuum_deferred_closes(Server *s) {
/* And now, let's close some more until we reach the limit again. */
while (set_size(s->deferred_closes) >= DEFERRED_CLOSES_MAX) {
- ManagedJournalFile *f;
+ JournalFile *f;
assert_se(f = set_steal_first(s->deferred_closes));
- managed_journal_file_close(f);
+ journal_file_offline_close(f);
}
}
@@ -604,7 +604,7 @@ static int server_archive_offline_user_journals(Server *s) {
_cleanup_free_ char *full = NULL;
_cleanup_close_ int fd = -EBADF;
struct dirent *de;
- ManagedJournalFile *f;
+ JournalFile *f;
uid_t uid;
errno = 0;
@@ -645,7 +645,7 @@ static int server_archive_offline_user_journals(Server *s) {
server_vacuum_deferred_closes(s);
/* Open the file briefly, so that we can archive it */
- r = managed_journal_file_open(
+ r = journal_file_open(
fd,
full,
O_RDWR,
@@ -673,20 +673,20 @@ static int server_archive_offline_user_journals(Server *s) {
continue;
}
- TAKE_FD(fd); /* Donated to managed_journal_file_open() */
+ TAKE_FD(fd); /* Donated to journal_file_open() */
- r = journal_file_archive(f->file, NULL);
+ r = journal_file_archive(f, NULL);
if (r < 0)
log_debug_errno(r, "Failed to archive journal file '%s', ignoring: %m", full);
- managed_journal_file_initiate_close(TAKE_PTR(f), s->deferred_closes);
+ journal_file_initiate_close(TAKE_PTR(f), s->deferred_closes);
}
return 0;
}
void server_rotate(Server *s) {
- ManagedJournalFile *f;
+ JournalFile *f;
void *k;
int r;
@@ -715,18 +715,18 @@ void server_rotate(Server *s) {
}
void server_sync(Server *s) {
- ManagedJournalFile *f;
+ JournalFile *f;
int r;
if (s->system_journal) {
- r = managed_journal_file_set_offline(s->system_journal, false);
+ r = journal_file_set_offline(s->system_journal, false);
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 = managed_journal_file_set_offline(f, false);
+ r = journal_file_set_offline(f, false);
if (r < 0)
log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
"Failed to sync user journal, ignoring: %m");
@@ -900,7 +900,7 @@ static void server_write_to_journal(
bool vacuumed = false, rotate = false;
struct dual_timestamp ts;
- ManagedJournalFile *f;
+ JournalFile *f;
int r;
assert(s);
@@ -927,9 +927,9 @@ static void server_write_to_journal(
if (!f)
return;
- if (journal_file_rotate_suggested(f->file, s->max_file_usec, LOG_DEBUG)) {
+ if (journal_file_rotate_suggested(f, s->max_file_usec, LOG_DEBUG)) {
log_debug("%s: Journal header limits reached or header out-of-date, rotating.",
- f->file->path);
+ f->path);
rotate = true;
}
}
@@ -947,7 +947,7 @@ static void server_write_to_journal(
s->last_realtime_clock = ts.realtime;
r = journal_file_append_entry(
- f->file,
+ f,
&ts,
/* boot_id= */ NULL,
iovec, n,
@@ -960,9 +960,9 @@ static void server_write_to_journal(
return;
}
- log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->file->path, n, IOVEC_TOTAL_SIZE(iovec, n));
+ log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->path, n, IOVEC_TOTAL_SIZE(iovec, n));
- if (!shall_try_append_again(f->file, r))
+ if (!shall_try_append_again(f, r))
return;
if (vacuumed) {
log_ratelimit_warning_errno(r, JOURNAL_LOG_RATELIMIT,
@@ -979,7 +979,7 @@ static void server_write_to_journal(
log_debug_errno(r, "Retrying write.");
r = journal_file_append_entry(
- f->file,
+ f,
&ts,
/* boot_id= */ NULL,
iovec, n,
@@ -990,7 +990,7 @@ static void server_write_to_journal(
if (r < 0)
log_ratelimit_error_errno(r, FAILED_TO_WRITE_ENTRY_RATELIMIT,
"Failed to write entry to %s (%zu items, %zu bytes) despite vacuuming, ignoring: %m",
- f->file->path, n, IOVEC_TOTAL_SIZE(iovec, n));
+ f->path, n, IOVEC_TOTAL_SIZE(iovec, n));
else
server_schedule_sync(s, priority);
}
@@ -1300,7 +1300,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
r = journal_file_copy_entry(
f,
- s->system_journal->file,
+ s->system_journal,
o,
f->current_offset,
&s->seqnum->seqnum,
@@ -1308,7 +1308,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
if (r >= 0)
continue;
- if (!shall_try_append_again(s->system_journal->file, r)) {
+ if (!shall_try_append_again(s->system_journal, r)) {
log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT, "Can't write entry: %m");
goto finish;
}
@@ -1328,7 +1328,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
log_debug("Retrying write.");
r = journal_file_copy_entry(
f,
- s->system_journal->file,
+ s->system_journal,
o,
f->current_offset,
&s->seqnum->seqnum,
@@ -1343,9 +1343,9 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
finish:
if (s->system_journal)
- journal_file_post_change(s->system_journal->file);
+ journal_file_post_change(s->system_journal);
- s->runtime_journal = managed_journal_file_close(s->runtime_journal);
+ s->runtime_journal = journal_file_offline_close(s->runtime_journal);
if (r >= 0)
(void) rm_rf(s->runtime_storage.path, REMOVE_ROOT);
@@ -1386,9 +1386,9 @@ static int server_relinquish_var(Server *s) {
(void) server_system_journal_open(s, /* flush_requested */ false, /* relinquish_requested=*/ true);
- s->system_journal = managed_journal_file_close(s->system_journal);
- ordered_hashmap_clear_with_destructor(s->user_journals, managed_journal_file_close);
- set_clear_with_destructor(s->deferred_closes, managed_journal_file_close);
+ s->system_journal = journal_file_offline_close(s->system_journal);
+ ordered_hashmap_clear_with_destructor(s->user_journals, journal_file_offline_close);
+ set_clear_with_destructor(s->deferred_closes, journal_file_offline_close);
fn = strjoina(s->runtime_directory, "/flushed");
if (unlink(fn) < 0 && errno != ENOENT)
@@ -2405,12 +2405,12 @@ static int server_memory_pressure(sd_event_source *es, void *userdata) {
/* Let's also close all user files (but keep the system/runtime one open) */
for (;;) {
- ManagedJournalFile *first = ordered_hashmap_steal_first(s->user_journals);
+ JournalFile *first = ordered_hashmap_steal_first(s->user_journals);
if (!first)
break;
- (void) managed_journal_file_close(first);
+ (void) journal_file_offline_close(first);
}
sd_event_trim_memory();
@@ -2713,16 +2713,16 @@ int server_init(Server *s, const char *namespace) {
void server_maybe_append_tags(Server *s) {
#if HAVE_GCRYPT
- ManagedJournalFile *f;
+ JournalFile *f;
usec_t n;
n = now(CLOCK_REALTIME);
if (s->system_journal)
- journal_file_maybe_append_tag(s->system_journal->file, n);
+ journal_file_maybe_append_tag(s->system_journal, n);
ORDERED_HASHMAP_FOREACH(f, s->user_journals)
- journal_file_maybe_append_tag(f->file, n);
+ journal_file_maybe_append_tag(f, n);
#endif
}
@@ -2732,17 +2732,17 @@ void server_done(Server *s) {
free(s->namespace);
free(s->namespace_field);
- set_free_with_destructor(s->deferred_closes, managed_journal_file_close);
+ set_free_with_destructor(s->deferred_closes, journal_file_offline_close);
while (s->stdout_streams)
stdout_stream_free(s->stdout_streams);
client_context_flush_all(s);
- (void) managed_journal_file_close(s->system_journal);
- (void) managed_journal_file_close(s->runtime_journal);
+ (void) journal_file_offline_close(s->system_journal);
+ (void) journal_file_offline_close(s->runtime_journal);
- ordered_hashmap_free_with_destructor(s->user_journals, managed_journal_file_close);
+ ordered_hashmap_free_with_destructor(s->user_journals, journal_file_offline_close);
varlink_server_unref(s->varlink_server);
diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
index e03cfc04c9..4e9a67c306 100644
--- a/src/journal/journald-server.h
+++ b/src/journal/journald-server.h
@@ -98,8 +98,8 @@ struct Server {
sd_event_source *idle_event_source;
struct sigrtmin18_info sigrtmin18_info;
- ManagedJournalFile *runtime_journal;
- ManagedJournalFile *system_journal;
+ JournalFile *runtime_journal;
+ JournalFile *system_journal;
OrderedHashmap *user_journals;
SeqnumData *seqnum;
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 3d4044295e..94aad05de9 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -102,7 +102,7 @@ int main(int argc, char *argv[]) {
if (server.system_journal) {
usec_t u;
- if (journal_file_next_evolve_usec(server.system_journal->file, &u)) {
+ if (journal_file_next_evolve_usec(server.system_journal, &u)) {
if (n >= u)
t = 0;
else
diff --git a/src/journal/managed-journal-file.c b/src/journal/managed-journal-file.c
index aa616988b4..34f3497621 100644
--- a/src/journal/managed-journal-file.c
+++ b/src/journal/managed-journal-file.c
@@ -19,7 +19,7 @@
#define PAYLOAD_BUFFER_SIZE (16U * 1024U)
#define MINIMUM_HOLE_SIZE (1U * 1024U * 1024U / 2U)
-static int managed_journal_file_truncate(JournalFile *f) {
+static int journal_file_truncate(JournalFile *f) {
uint64_t p;
int r;
@@ -37,7 +37,7 @@ static int managed_journal_file_truncate(JournalFile *f) {
return journal_file_fstat(f);
}
-static int managed_journal_file_entry_array_punch_hole(JournalFile *f, uint64_t p, uint64_t n_entries) {
+static int journal_file_entry_array_punch_hole(JournalFile *f, uint64_t p, uint64_t n_entries) {
Object o;
uint64_t offset, sz, n_items = 0, n_unused;
int r;
@@ -103,13 +103,13 @@ static int managed_journal_file_entry_array_punch_hole(JournalFile *f, uint64_t
return 0;
}
-static int managed_journal_file_punch_holes(JournalFile *f) {
+static int journal_file_punch_holes(JournalFile *f) {
HashItem items[PAYLOAD_BUFFER_SIZE / sizeof(HashItem)];
uint64_t p, sz;
ssize_t n = SSIZE_MAX;
int r;
- r = managed_journal_file_entry_array_punch_hole(
+ r = journal_file_entry_array_punch_hole(
f, le64toh(f->header->entry_array_offset), le64toh(f->header->n_entries));
if (r < 0)
return r;
@@ -141,7 +141,7 @@ static int managed_journal_file_punch_holes(JournalFile *f) {
if (le64toh(o.data.n_entries) == 0)
continue;
- r = managed_journal_file_entry_array_punch_hole(
+ r = journal_file_entry_array_punch_hole(
f, le64toh(o.data.entry_array_offset), le64toh(o.data.n_entries) - 1);
if (r == -EOPNOTSUPP)
return -EOPNOTSUPP;
@@ -157,18 +157,18 @@ static int managed_journal_file_punch_holes(JournalFile *f) {
/* This may be called from a separate thread to prevent blocking the caller for the duration of fsync().
* As a result we use atomic operations on f->offline_state for inter-thread communications with
* journal_file_set_offline() and journal_file_set_online(). */
-static void managed_journal_file_set_offline_internal(ManagedJournalFile *f) {
+static void journal_file_set_offline_internal(JournalFile *f) {
int r;
assert(f);
- assert(f->file->fd >= 0);
- assert(f->file->header);
+ assert(f->fd >= 0);
+ assert(f->header);
for (;;) {
- switch (f->file->offline_state) {
+ switch (f->offline_state) {
case OFFLINE_CANCEL: {
OfflineState tmp_state = OFFLINE_CANCEL;
- if (!__atomic_compare_exchange_n(&f->file->offline_state, &tmp_state, OFFLINE_DONE,
+ if (!__atomic_compare_exchange_n(&f->offline_state, &tmp_state, OFFLINE_DONE,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
continue;
}
@@ -176,7 +176,7 @@ static void managed_journal_file_set_offline_internal(ManagedJournalFile *f) {
case OFFLINE_AGAIN_FROM_SYNCING: {
OfflineState tmp_state = OFFLINE_AGAIN_FROM_SYNCING;
- if (!__atomic_compare_exchange_n(&f->file->offline_state, &tmp_state, OFFLINE_SYNCING,
+ if (!__atomic_compare_exchange_n(&f->offline_state, &tmp_state, OFFLINE_SYNCING,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
continue;
}
@@ -184,29 +184,29 @@ static void managed_journal_file_set_offline_internal(ManagedJournalFile *f) {
case OFFLINE_AGAIN_FROM_OFFLINING: {
OfflineState tmp_state = OFFLINE_AGAIN_FROM_OFFLINING;
- if (!__atomic_compare_exchange_n(&f->file->offline_state, &tmp_state, OFFLINE_SYNCING,
+ if (!__atomic_compare_exchange_n(&f->offline_state, &tmp_state, OFFLINE_SYNCING,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
continue;
}
break;
case OFFLINE_SYNCING:
- if (f->file->archive) {
- (void) managed_journal_file_truncate(f->file);
- (void) managed_journal_file_punch_holes(f->file);
+ if (f->archive) {
+ (void) journal_file_truncate(f);
+ (void) journal_file_punch_holes(f);
}
- (void) fsync(f->file->fd);
+ (void) fsync(f->fd);
{
OfflineState tmp_state = OFFLINE_SYNCING;
- if (!__atomic_compare_exchange_n(&f->file->offline_state, &tmp_state, OFFLINE_OFFLINING,
+ if (!__atomic_compare_exchange_n(&f->offline_state, &tmp_state, OFFLINE_OFFLINING,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
continue;
}
- f->file->header->state = f->file->archive ? STATE_ARCHIVED : STATE_OFFLINE;
- (void) fsync(f->file->fd);
+ f->header->state = f->archive ? STATE_ARCHIVED : STATE_OFFLINE;
+ (void) fsync(f->fd);
/* If we've archived the journal file, first try to re-enable COW on the file. If the
* FS_NOCOW_FL flag was never set or we successfully removed it, continue. If we fail
@@ -215,20 +215,20 @@ static void managed_journal_file_set_offline_internal(ManagedJournalFile *f) {
* be removed after data has been written to a file. The only way to remove it is to
* copy all data to a new file without the NOCOW flag set. */
- if (f->file->archive) {
- r = chattr_fd(f->file->fd, 0, FS_NOCOW_FL, NULL);
+ if (f->archive) {
+ r = chattr_fd(f->fd, 0, FS_NOCOW_FL, NULL);
if (r >= 0)
continue;
- log_debug_errno(r, "Failed to re-enable copy-on-write for %s: %m, rewriting file", f->file->path);
+ log_debug_errno(r, "Failed to re-enable copy-on-write for %s: %m, rewriting file", f->path);
- r = copy_file_atomic_full(FORMAT_PROC_FD_PATH(f->file->fd), f->file->path, f->file->mode,
+ r = copy_file_atomic_full(FORMAT_PROC_FD_PATH(f->fd), f->path, f->mode,
0,
FS_NOCOW_FL,
COPY_REPLACE | COPY_FSYNC | COPY_HOLES | COPY_ALL_XATTRS,
NULL, NULL);
if (r < 0) {
- log_debug_errno(r, "Failed to rewrite %s: %m", f->file->path);
+ log_debug_errno(r, "Failed to rewrite %s: %m", f->path);
continue;
}
}
@@ -237,7 +237,7 @@ static void managed_journal_file_set_offline_internal(ManagedJournalFile *f) {
case OFFLINE_OFFLINING: {
OfflineState tmp_state = OFFLINE_OFFLINING;
- if (!__atomic_compare_exchange_n(&f->file->offline_state, &tmp_state, OFFLINE_DONE,
+ if (!__atomic_compare_exchange_n(&f->offline_state, &tmp_state, OFFLINE_DONE,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
continue;
}
@@ -252,27 +252,27 @@ static void managed_journal_file_set_offline_internal(ManagedJournalFile *f) {
}
}
-static void * managed_journal_file_set_offline_thread(void *arg) {
- ManagedJournalFile *f = arg;
+static void * journal_file_set_offline_thread(void *arg) {
+ JournalFile *f = arg;
(void) pthread_setname_np(pthread_self(), "journal-offline");
- managed_journal_file_set_offline_internal(f);
+ journal_file_set_offline_internal(f);
return NULL;
}
/* Trigger a restart if the offline thread is mid-flight in a restartable state. */
-static bool managed_journal_file_set_offline_try_restart(ManagedJournalFile *f) {
+static bool journal_file_set_offline_try_restart(JournalFile *f) {
for (;;) {
- switch (f->file->offline_state) {
+ switch (f->offline_state) {
case OFFLINE_AGAIN_FROM_SYNCING:
case OFFLINE_AGAIN_FROM_OFFLINING:
return true;
case OFFLINE_CANCEL: {
OfflineState tmp_state = OFFLINE_CANCEL;
- if (!__atomic_compare_exchange_n(&f->file->offline_state, &tmp_state, OFFLINE_AGAIN_FROM_SYNCING,
+ if (!__atomic_compare_exchange_n(&f->offline_state, &tmp_state, OFFLINE_AGAIN_FROM_SYNCING,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
continue;
}
@@ -280,7 +280,7 @@ static bool managed_journal_file_set_offline_try_restart(ManagedJournalFile *f)
case OFFLINE_SYNCING: {
OfflineState tmp_state = OFFLINE_SYNCING;
- if (!__atomic_compare_exchange_n(&f->file->offline_state, &tmp_state, OFFLINE_AGAIN_FROM_SYNCING,
+ if (!__atomic_compare_exchange_n(&f->offline_state, &tmp_state, OFFLINE_AGAIN_FROM_SYNCING,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
continue;
}
@@ -288,7 +288,7 @@ static bool managed_journal_file_set_offline_try_restart(ManagedJournalFile *f)
case OFFLINE_OFFLINING: {
OfflineState tmp_state = OFFLINE_OFFLINING;
- if (!__atomic_compare_exchange_n(&f->file->offline_state, &tmp_state, OFFLINE_AGAIN_FROM_OFFLINING,
+ if (!__atomic_compare_exchange_n(&f->offline_state, &tmp_state, OFFLINE_AGAIN_FROM_OFFLINING,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
continue;
}
@@ -310,32 +310,32 @@ static bool managed_journal_file_set_offline_try_restart(ManagedJournalFile *f)
* and joined, or if none exists the offline is simply performed in this
* context without involving another thread.
*/
-int managed_journal_file_set_offline(ManagedJournalFile *f, bool wait) {
+int journal_file_set_offline(JournalFile *f, bool wait) {
int target_state;
bool restarted;
int r;
assert(f);
- if (!journal_file_writable(f->file))
+ if (!journal_file_writable(f))
return -EPERM;
- if (f->file->fd < 0 || !f->file->header)
+ if (f->fd < 0 || !f->header)
return -EINVAL;
- target_state = f->file->archive ? STATE_ARCHIVED : STATE_OFFLINE;
+ target_state = f->archive ? STATE_ARCHIVED : STATE_OFFLINE;
/* An offlining journal is implicitly online and may modify f->header->state,
* we must also join any potentially lingering offline thread when already in
* the desired offline state.
*/
- if (!managed_journal_file_is_offlining(f) && f->file->header->state == target_state)
- return journal_file_set_offline_thread_join(f->file);
+ if (!journal_file_is_offlining(f) && f->header->state == target_state)
+ return journal_file_set_offline_thread_join(f);
/* Restart an in-flight offline thread and wait if needed, or join a lingering done one. */
- restarted = managed_journal_file_set_offline_try_restart(f);
+ restarted = journal_file_set_offline_try_restart(f);
if ((restarted && wait) || !restarted) {
- r = journal_file_set_offline_thread_join(f->file);
+ r = journal_file_set_offline_thread_join(f);
if (r < 0)
return r;
}
@@ -344,10 +344,10 @@ int managed_journal_file_set_offline(ManagedJournalFile *f, bool wait) {
return 0;
/* Initiate a new offline. */
- f->file->offline_state = OFFLINE_SYNCING;
+ f->offline_state = OFFLINE_SYNCING;
if (wait) /* Without using a thread if waiting. */
- managed_journal_file_set_offline_internal(f);
+ journal_file_set_offline_internal(f);
else {
sigset_t ss, saved_ss;
int k;
@@ -361,11 +361,11 @@ int managed_journal_file_set_offline(ManagedJournalFile *f, bool wait) {
if (r > 0)
return -r;
- r = pthread_create(&f->file->offline_thread, NULL, managed_journal_file_set_offline_thread, f);
+ r = pthread_create(&f->offline_thread, NULL, journal_file_set_offline_thread, f);
k = pthread_sigmask(SIG_SETMASK, &saved_ss, NULL);
if (r > 0) {
- f->file->offline_state = OFFLINE_JOINED;
+ f->offline_state = OFFLINE_JOINED;
return -r;
}
if (k > 0)
@@ -375,82 +375,42 @@ int managed_journal_file_set_offline(ManagedJournalFile *f, bool wait) {
return 0;
}
-bool managed_journal_file_is_offlining(ManagedJournalFile *f) {
+bool journal_file_is_offlining(JournalFile *f) {
assert(f);
__atomic_thread_fence(__ATOMIC_SEQ_CST);
- if (IN_SET(f->file->offline_state, OFFLINE_DONE, OFFLINE_JOINED))
+ if (IN_SET(f->offline_state, OFFLINE_DONE, OFFLINE_JOINED))
return false;
return true;
}
-ManagedJournalFile* managed_journal_file_close(ManagedJournalFile *f) {
+JournalFile* journal_file_offline_close(JournalFile *f) {
if (!f)
return NULL;
#if HAVE_GCRYPT
/* Write the final tag */
- if (JOURNAL_HEADER_SEALED(f->file->header) && journal_file_writable(f->file)) {
+ if (JOURNAL_HEADER_SEALED(f->header) && journal_file_writable(f)) {
int r;
- r = journal_file_append_tag(f->file);
+ r = journal_file_append_tag(f);
if (r < 0)
log_error_errno(r, "Failed to append tag when closing journal: %m");
}
#endif
- if (sd_event_source_get_enabled(f->file->post_change_timer, NULL) > 0)
- journal_file_post_change(f->file);
- sd_event_source_disable_unref(f->file->post_change_timer);
+ if (sd_event_source_get_enabled(f->post_change_timer, NULL) > 0)
+ journal_file_post_change(f);
+ sd_event_source_disable_unref(f->post_change_timer);
- managed_journal_file_set_offline(f, true);
+ journal_file_set_offline(f, true);
- journal_file_close(f->file);
-
- return mfree(f);
-}
-
-int managed_journal_file_open(
- int fd,
- const char *fname,
- int open_flags,
- JournalFileFlags file_flags,
- mode_t mode,
- uint64_t compress_threshold_bytes,
- JournalMetrics *metrics,
- MMapCache *mmap_cache,
- ManagedJournalFile *template,
- ManagedJournalFile **ret) {
-
- _cleanup_free_ ManagedJournalFile *f = NULL;
- int r;
-
- f = new0(ManagedJournalFile, 1);
- if (!f)
- return -ENOMEM;
-
- r = journal_file_open(
- fd,
- fname,
- open_flags,
- file_flags,
- mode,
- compress_threshold_bytes,
- metrics,
- mmap_cache,
- template ? template->file : NULL,
- &f->file);
- if (r < 0)
- return r;
-
- *ret = TAKE_PTR(f);
-
- return 0;
+ return journal_file_close(f);
}
-ManagedJournalFile* managed_journal_file_initiate_close(ManagedJournalFile *f, Set *deferred_closes) {
+JournalFile* journal_file_initiate_close(JournalFile *f, Set *deferred_closes) {
int r;
assert(f);
@@ -460,53 +420,53 @@ ManagedJournalFile* managed_journal_file_initiate_close(ManagedJournalFile *f, S
if (r < 0)
log_debug_errno(r, "Failed to add file to deferred close set, closing immediately.");
else {
- (void) managed_journal_file_set_offline(f, false);
+ (void) journal_file_set_offline(f, false);
return NULL;
}
}
- return managed_journal_file_close(f);
+ return journal_file_offline_close(f);
}
-int managed_journal_file_rotate(
- ManagedJournalFile **f,
+int journal_file_rotate(
+ JournalFile **f,
MMapCache *mmap_cache,
JournalFileFlags file_flags,
uint64_t compress_threshold_bytes,
Set *deferred_closes) {
_cleanup_free_ char *path = NULL;
- ManagedJournalFile *new_file = NULL;
+ JournalFile *new_file = NULL;
int r;
assert(f);
assert(*f);
- r = journal_file_archive((*f)->file, &path);
+ r = journal_file_archive(*f, &path);
if (r < 0)
return r;
- set_clear_with_destructor(deferred_closes, managed_journal_file_close);
+ set_clear_with_destructor(deferred_closes, journal_file_offline_close);
- r = managed_journal_file_open(
+ r = journal_file_open(
/* fd= */ -1,
path,
- (*f)->file->open_flags,
+ (*f)->open_flags,
file_flags,
- (*f)->file->mode,
+ (*f)->mode,
compress_threshold_bytes,
/* metrics= */ NULL,
mmap_cache,
/* template= */ *f,
&new_file);
- managed_journal_file_initiate_close(*f, deferred_closes);
+ journal_file_initiate_close(*f, deferred_closes);
*f = new_file;
return r;
}
-int managed_journal_file_open_reliably(
+int journal_file_open_reliably(
const char *fname,
int open_flags,
JournalFileFlags file_flags,
@@ -514,13 +474,13 @@ int managed_journal_file_open_reliably(
uint64_t compress_threshold_bytes,
JournalMetrics *metrics,
MMapCache *mmap_cache,
- ManagedJournalFile *template,
- ManagedJournalFile **ret) {
+ JournalFile *template,
+ JournalFile **ret) {
- _cleanup_(managed_journal_file_closep) ManagedJournalFile *old_file = NULL;
+ _cleanup_(journal_file_offline_closep) JournalFile *old_file = NULL;
int r;
- r = managed_journal_file_open(
+ r = journal_file_open(
/* fd= */ -1,
fname,
open_flags,
@@ -558,10 +518,10 @@ int managed_journal_file_open_reliably(
if (!template) {
/* The file is corrupted and no template is specified. Try opening it read-only as the
* template before rotating to inherit its sequence number and ID. */
- 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, NULL, &old_file);
+ r = journal_file_open(-1, fname,
+ (open_flags & ~(O_ACCMODE|O_CREAT|O_EXCL)) | O_RDONLY,
+ file_flags, 0, compress_threshold_bytes, NULL,
+ mmap_cache, NULL, &old_file);
if (r < 0)
log_debug_errno(r, "Failed to continue sequence from file %s, ignoring: %m", fname);
else
@@ -572,6 +532,6 @@ int managed_journal_file_open_reliably(
if (r < 0)
return r;
- return managed_journal_file_open(-1, fname, open_flags, file_flags, mode, compress_threshold_bytes, metrics,
- mmap_cache, template, ret);
+ return journal_file_open(-1, fname, open_flags, file_flags, mode, compress_threshold_bytes, metrics,
+ mmap_cache, template, ret);
}
diff --git a/src/journal/managed-journal-file.h b/src/journal/managed-journal-file.h
index 2fd1e2d6b4..cbe29c762e 100644
--- a/src/journal/managed-journal-file.h
+++ b/src/journal/managed-journal-file.h
@@ -3,12 +3,12 @@
#include "journal-file.h"
-typedef struct {
- JournalFile *file;
-} ManagedJournalFile;
+int journal_file_set_offline(JournalFile *f, bool wait);
+bool journal_file_is_offlining(JournalFile *f);
+JournalFile* journal_file_offline_close(JournalFile *f);
+DEFINE_TRIVIAL_CLEANUP_FUNC(JournalFile*, journal_file_offline_close);
-int managed_journal_file_open(
- int fd,
+int journal_file_open_reliably(
const char *fname,
int open_flags,
JournalFileFlags file_flags,
@@ -16,24 +16,13 @@ int managed_journal_file_open(
uint64_t compress_threshold_bytes,
JournalMetrics *metrics,
MMapCache *mmap_cache,
- ManagedJournalFile *template,
- ManagedJournalFile **ret);
+ JournalFile *template,
+ JournalFile **ret);
-int managed_journal_file_set_offline(ManagedJournalFile *f, bool wait);
-bool managed_journal_file_is_offlining(ManagedJournalFile *f);
-ManagedJournalFile* managed_journal_file_close(ManagedJournalFile *f);
-DEFINE_TRIVIAL_CLEANUP_FUNC(ManagedJournalFile*, managed_journal_file_close);
-
-int managed_journal_file_open_reliably(
- const char *fname,
- int open_flags,
+JournalFile* journal_file_initiate_close(JournalFile *f, Set *deferred_closes);
+int journal_file_rotate(
+ JournalFile **f,
+ MMapCache *mmap_cache,
JournalFileFlags file_flags,
- mode_t mode,
uint64_t compress_threshold_bytes,
- JournalMetrics *metrics,
- MMapCache *mmap_cache,
- ManagedJournalFile *template,
- ManagedJournalFile **ret);
-
-ManagedJournalFile* managed_journal_file_initiate_close(ManagedJournalFile *f, Set *deferred_closes);
-int managed_journal_file_rotate(ManagedJournalFile **f, MMapCache *mmap_cache, JournalFileFlags file_flags, uint64_t compress_threshold_bytes, Set *deferred_closes);
+ Set *deferred_closes);
diff --git a/src/journal/test-journal-append.c b/src/journal/test-journal-append.c
index 95b6fc1ee5..f382b1bd14 100644
--- a/src/journal/test-journal-append.c
+++ b/src/journal/test-journal-append.c
@@ -20,7 +20,7 @@
#include "tests.h"
#include "tmpfile-util.h"
-static int journal_append_message(ManagedJournalFile *mj, const char *message) {
+static int journal_append_message(JournalFile *mj, const char *message) {
struct iovec iovec;
struct dual_timestamp ts;
@@ -30,7 +30,7 @@ static int journal_append_message(ManagedJournalFile *mj, const char *message) {
dual_timestamp_get(&ts);
iovec = IOVEC_MAKE_STRING(message);
return journal_file_append_entry(
- mj->file,
+ mj,
&ts,
/* boot_id= */ NULL,
&iovec,
@@ -44,14 +44,14 @@ static int journal_append_message(ManagedJournalFile *mj, const char *message) {
static int journal_corrupt_and_append(uint64_t start_offset, uint64_t step) {
_cleanup_(mmap_cache_unrefp) MMapCache *mmap_cache = NULL;
_cleanup_(rm_rf_physical_and_freep) char *tempdir = NULL;
- _cleanup_(managed_journal_file_closep) ManagedJournalFile *mj = NULL;
+ _cleanup_(journal_file_offline_closep) JournalFile *mj = NULL;
uint64_t start, end;
int r;
mmap_cache = mmap_cache_new();
assert_se(mmap_cache);
- /* managed_journal_file_open() requires a valid machine id */
+ /* journal_file_open() requires a valid machine id */
if (sd_id128_get_machine(NULL) < 0)
return log_tests_skipped("No valid machine ID found");
@@ -61,22 +61,21 @@ static int journal_corrupt_and_append(uint64_t start_offset, uint64_t step) {
log_debug("Opening journal %s/system.journal", tempdir);
- r = managed_journal_file_open(
- /* fd= */ -1,
- "system.journal",
- O_RDWR|O_CREAT,
- JOURNAL_COMPRESS,
- 0644,
- /* compress_threshold_bytes= */ UINT64_MAX,
- /* metrics= */ NULL,
- mmap_cache,
- /* template= */ NULL,
- &mj);
+ r = journal_file_open(
+ /* fd= */ -1,
+ "system.journal",
+ O_RDWR|O_CREAT,
+ JOURNAL_COMPRESS,
+ 0644,
+ /* compress_threshold_bytes= */ UINT64_MAX,
+ /* metrics= */ NULL,
+ mmap_cache,
+ /* template= */ NULL,
+ &mj);
if (r < 0)
return log_error_errno(r, "Failed to open the journal: %m");
assert_se(mj);
- assert_se(mj->file);
/* Add a couple of initial messages */
for (int i = 0; i < 10; i++) {
@@ -88,8 +87,8 @@ static int journal_corrupt_and_append(uint64_t start_offset, uint64_t step) {
return log_error_errno(r, "Failed to write to the journal: %m");
}
- start = start_offset == UINT64_MAX ? random_u64() % mj->file->last_stat.st_size : start_offset;
- end = (uint64_t) mj->file->last_stat.st_size;
+ start = start_offset == UINT64_MAX ? random_u64() % mj->last_stat.st_size : start_offset;
+ end = (uint64_t) mj->last_stat.st_size;
/* Print the initial offset at which we start flipping bits, which can be
* later used to reproduce a potential fail */
@@ -105,26 +104,26 @@ static int journal_corrupt_and_append(uint64_t start_offset, uint64_t step) {
uint8_t b;
/* Flip a bit in the journal file */
- r = pread(mj->file->fd, &b, 1, offset);
+ r = pread(mj->fd, &b, 1, offset);
assert_se(r == 1);
b |= 0x1;
- r = pwrite(mj->file->fd, &b, 1, offset);
+ r = pwrite(mj->fd, &b, 1, offset);
assert_se(r == 1);
/* Close and reopen the journal to flush all caches and remap
* the corrupted journal */
- mj = managed_journal_file_close(mj);
- r = managed_journal_file_open(
- /* fd= */ -1,
- "system.journal",
- O_RDWR|O_CREAT,
- JOURNAL_COMPRESS,
- 0644,
- /* compress_threshold_bytes= */ UINT64_MAX,
- /* metrics= */ NULL,
- mmap_cache,
- /* template= */ NULL,
- &mj);
+ mj = journal_file_offline_close(mj);
+ r = journal_file_open(
+ /* fd= */ -1,
+ "system.journal",
+ O_RDWR|O_CREAT,
+ JOURNAL_COMPRESS,
+ 0644,
+ /* compress_threshold_bytes= */ UINT64_MAX,
+ /* metrics= */ NULL,
+ mmap_cache,
+ /* template= */ NULL,
+ &mj);
if (r < 0) {
/* The corrupted journal might get rejected during reopening
* if it's corrupted enough (especially its header), so
diff --git a/src/journal/test-journal-flush.c b/src/journal/test-journal-flush.c
index 677d37edc1..53ba72bbd2 100644
--- a/src/journal/test-journal-flush.c
+++ b/src/journal/test-journal-flush.c
@@ -19,7 +19,7 @@ static void test_journal_flush(int argc, char *argv[]) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
_cleanup_free_ char *fn = NULL;
_cleanup_(rm_rf_physical_and_freep) char *dn = NULL;
- ManagedJournalFile *new_journal = NULL;
+ JournalFile *new_journal = NULL;
sd_journal *j = NULL;
unsigned n = 0;
int r;
@@ -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, &new_journal);
+ r = journal_file_open(-1, fn, O_CREAT|O_RDWR, 0, 0644, 0, NULL, m, NULL, &new_journal);
assert_se(r >= 0);
if (argc > 1)
@@ -53,7 +53,7 @@ static void test_journal_flush(int argc, char *argv[]) {
log_error_errno(r, "journal_file_move_to_object failed: %m");
assert_se(r >= 0);
- r = journal_file_copy_entry(f, new_journal->file, o, f->current_offset, NULL, NULL);
+ r = journal_file_copy_entry(f, new_journal, o, f->current_offset, NULL, NULL);
if (r < 0)
log_warning_errno(r, "journal_file_copy_entry failed: %m");
assert_se(r >= 0 ||
@@ -68,7 +68,7 @@ static void test_journal_flush(int argc, char *argv[]) {
sd_journal_close(j);
- (void) managed_journal_file_close(new_journal);
+ (void) journal_file_offline_close(new_journal);
}
int main(int argc, char *argv[]) {
diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c
index 32427b8b62..81073465bf 100644
--- a/src/journal/test-journal-interleaving.c
+++ b/src/journal/test-journal-interleaving.c
@@ -35,30 +35,30 @@ _noreturn_ static void log_assert_errno(const char *text, int error, const char
log_assert_errno(#expr, -_r_, PROJECT_FILE, __LINE__, __func__); \
} while (false)
-static ManagedJournalFile *test_open_internal(const char *name, JournalFileFlags flags) {
+static JournalFile *test_open_internal(const char *name, JournalFileFlags flags) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
- ManagedJournalFile *f;
+ JournalFile *f;
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, &f));
+ assert_ret(journal_file_open(-1, name, O_RDWR|O_CREAT, flags, 0644, UINT64_MAX, NULL, m, NULL, &f));
return f;
}
-static ManagedJournalFile *test_open(const char *name) {
+static JournalFile *test_open(const char *name) {
return test_open_internal(name, JOURNAL_COMPRESS);
}
-static ManagedJournalFile *test_open_strict(const char *name) {
+static JournalFile *test_open_strict(const char *name) {
return test_open_internal(name, JOURNAL_COMPRESS | JOURNAL_STRICT_ORDER);
}
-static void test_close(ManagedJournalFile *f) {
- (void) managed_journal_file_close(f);
+static void test_close(JournalFile *f) {
+ (void) journal_file_offline_close(f);
}
-static void append_number(ManagedJournalFile *f, int n, const sd_id128_t *boot_id, uint64_t *seqnum) {
+static void append_number(JournalFile *f, int n, const sd_id128_t *boot_id, uint64_t *seqnum) {
_cleanup_free_ char *p = NULL, *q = NULL;
dual_timestamp ts;
struct iovec iovec[2];
@@ -82,10 +82,10 @@ static void append_number(ManagedJournalFile *f, int n, const sd_id128_t *boot_i
iovec[n_iov++] = IOVEC_MAKE_STRING(q);
}
- assert_ret(journal_file_append_entry(f->file, &ts, boot_id, iovec, n_iov, seqnum, NULL, NULL, NULL));
+ assert_ret(journal_file_append_entry(f, &ts, boot_id, iovec, n_iov, seqnum, NULL, NULL, NULL));
}
-static void append_unreferenced_data(ManagedJournalFile *f, const sd_id128_t *boot_id) {
+static void append_unreferenced_data(JournalFile *f, const sd_id128_t *boot_id) {
_cleanup_free_ char *q = NULL;
dual_timestamp ts;
struct iovec iovec;
@@ -98,7 +98,7 @@ static void append_unreferenced_data(ManagedJournalFile *f, const sd_id128_t *bo
assert_se(q = strjoin("_BOOT_ID=", SD_ID128_TO_STRING(*boot_id)));
iovec = IOVEC_MAKE_STRING(q);
- assert_se(journal_file_append_entry(f->file, &ts, boot_id, &iovec, 1, NULL, NULL, NULL, NULL) == -EREMCHG);
+ assert_se(journal_file_append_entry(f, &ts, boot_id, &iovec, 1, NULL, NULL, NULL, NULL) == -EREMCHG);
}
static void test_check_number(sd_journal *j, int n) {
@@ -146,7 +146,7 @@ static void test_check_numbers_up(sd_journal *j, int count) {
}
static void setup_sequential(void) {
- ManagedJournalFile *f1, *f2, *f3;
+ JournalFile *f1, *f2, *f3;
sd_id128_t id;
f1 = test_open("one.journal");
@@ -173,7 +173,7 @@ static void setup_sequential(void) {
}
static void setup_interleaved(void) {
- ManagedJournalFile *f1, *f2, *f3;
+ JournalFile *f1, *f2, *f3;
sd_id128_t id;
f1 = test_open("one.journal");
@@ -196,7 +196,7 @@ static void setup_interleaved(void) {
}
static void setup_unreferenced_data(void) {
- ManagedJournalFile *f1, *f2, *f3;
+ JournalFile *f1, *f2, *f3;
sd_id128_t id;
/* For issue #29275. */
@@ -449,7 +449,7 @@ TEST(boot_id) {
static void test_sequence_numbers_one(void) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
char t[] = "/var/tmp/journal-seq-XXXXXX";
- ManagedJournalFile *one, *two;
+ JournalFile *one, *two;
uint64_t seqnum = 0;
sd_id128_t seqnum_id;
@@ -458,8 +458,8 @@ 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, &one) == 0);
+ assert_se(journal_file_open(-1, "one.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0644,
+ UINT64_MAX, NULL, m, NULL, &one) == 0);
append_number(one, 1, NULL, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum);
@@ -468,21 +468,21 @@ static void test_sequence_numbers_one(void) {
printf("seqnum=%"PRIu64"\n", seqnum);
assert_se(seqnum == 2);
- assert_se(one->file->header->state == STATE_ONLINE);
- assert_se(!sd_id128_equal(one->file->header->file_id, one->file->header->machine_id));
- assert_se(!sd_id128_equal(one->file->header->file_id, one->file->header->tail_entry_boot_id));
- assert_se(sd_id128_equal(one->file->header->file_id, one->file->header->seqnum_id));
+ assert_se(one->header->state == STATE_ONLINE);
+ assert_se(!sd_id128_equal(one->header->file_id, one->header->machine_id));
+ assert_se(!sd_id128_equal(one->header->file_id, one->header->tail_entry_boot_id));
+ assert_se(sd_id128_equal(one->header->file_id, one->header->seqnum_id));
- memcpy(&seqnum_id, &one->file->header->seqnum_id, sizeof(sd_id128_t));
+ memcpy(&seqnum_id, &one->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, one, &two) == 0);
+ assert_se(journal_file_open(-1, "two.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0644,
+ 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));
- assert_se(sd_id128_equal(two->file->header->machine_id, one->file->header->machine_id));
- assert_se(sd_id128_is_null(two->file->header->tail_entry_boot_id)); /* Not written yet. */
- assert_se(sd_id128_equal(two->file->header->seqnum_id, one->file->header->seqnum_id));
+ assert_se(two->header->state == STATE_ONLINE);
+ assert_se(!sd_id128_equal(two->header->file_id, one->header->file_id));
+ assert_se(sd_id128_equal(two->header->machine_id, one->header->machine_id));
+ assert_se(sd_id128_is_null(two->header->tail_entry_boot_id)); /* Not written yet. */
+ assert_se(sd_id128_equal(two->header->seqnum_id, one->header->seqnum_id));
append_number(two, 3, NULL, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum);
@@ -492,7 +492,7 @@ static void test_sequence_numbers_one(void) {
assert_se(seqnum == 4);
/* Verify tail_entry_boot_id. */
- assert_se(sd_id128_equal(two->file->header->tail_entry_boot_id, one->file->header->tail_entry_boot_id));
+ assert_se(sd_id128_equal(two->header->tail_entry_boot_id, one->header->tail_entry_boot_id));
test_close(two);
@@ -512,10 +512,10 @@ static void test_sequence_numbers_one(void) {
/* restart server */
seqnum = 0;
- assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR, JOURNAL_COMPRESS, 0,
- UINT64_MAX, NULL, m, NULL, &two) == 0);
+ assert_se(journal_file_open(-1, "two.journal", O_RDWR, JOURNAL_COMPRESS, 0,
+ UINT64_MAX, NULL, m, NULL, &two) == 0);
- assert_se(sd_id128_equal(two->file->header->seqnum_id, seqnum_id));
+ assert_se(sd_id128_equal(two->header->seqnum_id, seqnum_id));
append_number(two, 7, NULL, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum);
@@ -547,7 +547,7 @@ TEST(sequence_numbers) {
}
static int intro(void) {
- /* managed_journal_file_open() requires a valid machine id */
+ /* 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 1220a29e20..7de173f5f3 100644
--- a/src/journal/test-journal-stream.c
+++ b/src/journal/test-journal-stream.c
@@ -60,7 +60,7 @@ static void verify_contents(sd_journal *j, unsigned skip) {
static void run_test(void) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
- ManagedJournalFile *one, *two, *three;
+ JournalFile *one, *two, *three;
char t[] = "/var/tmp/journal-stream-XXXXXX";
unsigned i;
_cleanup_(sd_journal_closep) sd_journal *j = NULL;
@@ -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, &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);
+ assert_se(journal_file_open(-1, "one.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, &one) == 0);
+ assert_se(journal_file_open(-1, "two.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, &two) == 0);
+ assert_se(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;
@@ -103,21 +103,21 @@ static void run_test(void) {
iovec[1] = IOVEC_MAKE(q, strlen(q));
if (i % 10 == 0)
- assert_se(journal_file_append_entry(three->file, &ts, NULL, iovec, 2, NULL, NULL, NULL, NULL) == 0);
+ assert_se(journal_file_append_entry(three, &ts, NULL, iovec, 2, NULL, NULL, NULL, NULL) == 0);
else {
if (i % 3 == 0)
- assert_se(journal_file_append_entry(two->file, &ts, NULL, iovec, 2, NULL, NULL, NULL, NULL) == 0);
+ assert_se(journal_file_append_entry(two, &ts, NULL, iovec, 2, NULL, NULL, NULL, NULL) == 0);
- assert_se(journal_file_append_entry(one->file, &ts, NULL, iovec, 2, NULL, NULL, NULL, NULL) == 0);
+ assert_se(journal_file_append_entry(one, &ts, NULL, iovec, 2, NULL, NULL, NULL, NULL) == 0);
}
free(p);
free(q);
}
- (void) managed_journal_file_close(one);
- (void) managed_journal_file_close(two);
- (void) managed_journal_file_close(three);
+ (void) journal_file_offline_close(one);
+ (void) journal_file_offline_close(two);
+ (void) journal_file_offline_close(three);
assert_se(sd_journal_open_directory(&j, t, 0) >= 0);
@@ -177,7 +177,7 @@ static void run_test(void) {
int main(int argc, char *argv[]) {
- /* managed_journal_file_open() requires a valid machine id */
+ /* 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 9a7fa2a734..8a77f919c5 100644
--- a/src/journal/test-journal-verify.c
+++ b/src/journal/test-journal-verify.c
@@ -71,7 +71,7 @@ static int run_test(const char *verification_key, ssize_t max_iterations) {
char t[] = "/var/tmp/journal-XXXXXX";
struct stat st;
JournalFile *f;
- ManagedJournalFile *df;
+ JournalFile *df;
usec_t from = 0, to = 0, total = 0;
uint64_t start, end;
int r;
@@ -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 */
+ /* journal_file_open() requires a valid machine id */
if (sd_id128_get_machine(NULL) < 0)
return log_tests_skipped("No valid machine ID found");
@@ -91,7 +91,7 @@ static int run_test(const char *verification_key, ssize_t max_iterations) {
log_info("Generating a test journal");
- assert_se(managed_journal_file_open(
+ assert_se(journal_file_open(
/* fd= */ -1,
"test.journal",
O_RDWR|O_CREAT,
@@ -112,7 +112,7 @@ static int run_test(const char *verification_key, ssize_t max_iterations) {
assert_se(asprintf(&test, "RANDOM=%li", random() % RANDOM_RANGE));
iovec = IOVEC_MAKE_STRING(test);
assert_se(journal_file_append_entry(
- df->file,
+ df,
&ts,
/* boot_id= */ NULL,
&iovec,
@@ -123,7 +123,7 @@ static int run_test(const char *verification_key, ssize_t max_iterations) {
/* ret_offset= */ NULL) == 0);
}
- (void) managed_journal_file_close(df);
+ (void) journal_file_offline_close(df);
log_info("Verifying with key: %s", strna(verification_key));
diff --git a/src/journal/test-journal.c b/src/journal/test-journal.c
index 92c5b66fe5..e89d982a78 100644
--- a/src/journal/test-journal.c
+++ b/src/journal/test-journal.c
@@ -26,7 +26,7 @@ static void mkdtemp_chdir_chattr(char *path) {
static void test_non_empty_one(void) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
dual_timestamp ts;
- ManagedJournalFile *f;
+ JournalFile *f;
struct iovec iovec;
static const char test[] = "TEST1=1", test2[] = "TEST2=2";
Object *o, *d;
@@ -39,71 +39,71 @@ 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, &f) == 0);
+ assert_se(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);
iovec = IOVEC_MAKE_STRING(test);
- assert_se(journal_file_append_entry(f->file, &ts, NULL, &iovec, 1, NULL, NULL, NULL, NULL) == 0);
+ assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL, NULL) == 0);
iovec = IOVEC_MAKE_STRING(test2);
- assert_se(journal_file_append_entry(f->file, &ts, NULL, &iovec, 1, NULL, NULL, NULL, NULL) == 0);
+ assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL, NULL) == 0);
iovec = IOVEC_MAKE_STRING(test);
- assert_se(journal_file_append_entry(f->file, &ts, &fake_boot_id, &iovec, 1, NULL, NULL, NULL, NULL) == 0);
+ assert_se(journal_file_append_entry(f, &ts, &fake_boot_id, &iovec, 1, NULL, NULL, NULL, NULL) == 0);
#if HAVE_GCRYPT
- journal_file_append_tag(f->file);
+ journal_file_append_tag(f);
#endif
- journal_file_dump(f->file);
+ journal_file_dump(f);
- assert_se(journal_file_next_entry(f->file, 0, DIRECTION_DOWN, &o, &p) == 1);
+ assert_se(journal_file_next_entry(f, 0, DIRECTION_DOWN, &o, &p) == 1);
assert_se(le64toh(o->entry.seqnum) == 1);
- assert_se(journal_file_next_entry(f->file, p, DIRECTION_DOWN, &o, &p) == 1);
+ assert_se(journal_file_next_entry(f, p, DIRECTION_DOWN, &o, &p) == 1);
assert_se(le64toh(o->entry.seqnum) == 2);
- assert_se(journal_file_next_entry(f->file, p, DIRECTION_DOWN, &o, &p) == 1);
+ assert_se(journal_file_next_entry(f, p, DIRECTION_DOWN, &o, &p) == 1);
assert_se(le64toh(o->entry.seqnum) == 3);
assert_se(sd_id128_equal(o->entry.boot_id, fake_boot_id));
- assert_se(journal_file_next_entry(f->file, p, DIRECTION_DOWN, &o, &p) == 0);
+ assert_se(journal_file_next_entry(f, p, DIRECTION_DOWN, &o, &p) == 0);
- assert_se(journal_file_next_entry(f->file, 0, DIRECTION_DOWN, &o, &p) == 1);
+ assert_se(journal_file_next_entry(f, 0, DIRECTION_DOWN, &o, &p) == 1);
assert_se(le64toh(o->entry.seqnum) == 1);
- assert_se(journal_file_find_data_object(f->file, test, strlen(test), &d, NULL) == 1);
- assert_se(journal_file_move_to_entry_for_data(f->file, d, DIRECTION_DOWN, &o, NULL) == 1);
+ assert_se(journal_file_find_data_object(f, test, strlen(test), &d, NULL) == 1);
+ assert_se(journal_file_move_to_entry_for_data(f, d, DIRECTION_DOWN, &o, NULL) == 1);
assert_se(le64toh(o->entry.seqnum) == 1);
- assert_se(journal_file_move_to_entry_for_data(f->file, d, DIRECTION_UP, &o, NULL) == 1);
+ assert_se(journal_file_move_to_entry_for_data(f, d, DIRECTION_UP, &o, NULL) == 1);
assert_se(le64toh(o->entry.seqnum) == 3);
- assert_se(journal_file_find_data_object(f->file, test2, strlen(test2), &d, NULL) == 1);
- assert_se(journal_file_move_to_entry_for_data(f->file, d, DIRECTION_UP, &o, NULL) == 1);
+ assert_se(journal_file_find_data_object(f, test2, strlen(test2), &d, NULL) == 1);
+ assert_se(journal_file_move_to_entry_for_data(f, d, DIRECTION_UP, &o, NULL) == 1);
assert_se(le64toh(o->entry.seqnum) == 2);
- assert_se(journal_file_move_to_entry_for_data(f->file, d, DIRECTION_DOWN, &o, NULL) == 1);
+ assert_se(journal_file_move_to_entry_for_data(f, d, DIRECTION_DOWN, &o, NULL) == 1);
assert_se(le64toh(o->entry.seqnum) == 2);
- assert_se(journal_file_find_data_object(f->file, "quux", 4, &d, NULL) == 0);
+ assert_se(journal_file_find_data_object(f, "quux", 4, &d, NULL) == 0);
- assert_se(journal_file_move_to_entry_by_seqnum(f->file, 1, DIRECTION_DOWN, &o, NULL) == 1);
+ assert_se(journal_file_move_to_entry_by_seqnum(f, 1, DIRECTION_DOWN, &o, NULL) == 1);
assert_se(le64toh(o->entry.seqnum) == 1);
- assert_se(journal_file_move_to_entry_by_seqnum(f->file, 3, DIRECTION_DOWN, &o, NULL) == 1);
+ assert_se(journal_file_move_to_entry_by_seqnum(f, 3, DIRECTION_DOWN, &o, NULL) == 1);
assert_se(le64toh(o->entry.seqnum) == 3);
- assert_se(journal_file_move_to_entry_by_seqnum(f->file, 2, DIRECTION_DOWN, &o, NULL) == 1);
+ assert_se(journal_file_move_to_entry_by_seqnum(f, 2, DIRECTION_DOWN, &o, NULL) == 1);
assert_se(le64toh(o->entry.seqnum) == 2);
- assert_se(journal_file_move_to_entry_by_seqnum(f->file, 10, DIRECTION_DOWN, &o, NULL) == 0);
+ assert_se(journal_file_move_to_entry_by_seqnum(f, 10, DIRECTION_DOWN, &o, NULL) == 0);
- managed_journal_file_rotate(&f, m, JOURNAL_SEAL|JOURNAL_COMPRESS, UINT64_MAX, NULL);
- managed_journal_file_rotate(&f, m, JOURNAL_SEAL|JOURNAL_COMPRESS, UINT64_MAX, NULL);
+ journal_file_rotate(&f, m, JOURNAL_SEAL|JOURNAL_COMPRESS, UINT64_MAX, NULL);
+ journal_file_rotate(&f, m, JOURNAL_SEAL|JOURNAL_COMPRESS, UINT64_MAX, NULL);
- (void) managed_journal_file_close(f);
+ (void) journal_file_offline_close(f);
log_info("Done...");
@@ -128,7 +128,7 @@ TEST(non_empty) {
static void test_empty_one(void) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
- ManagedJournalFile *f1, *f2, *f3, *f4;
+ JournalFile *f1, *f2, *f3, *f4;
char t[] = "/var/tmp/journal-XXXXXX";
m = mmap_cache_new();
@@ -136,18 +136,18 @@ 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, &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);
+ assert_se(journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0, 0666, UINT64_MAX, NULL, m, NULL, &f1) == 0);
+ assert_se(journal_file_open(-1, "test-compress.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, &f2) == 0);
+ assert_se(journal_file_open(-1, "test-seal.journal", O_RDWR|O_CREAT, JOURNAL_SEAL, 0666, UINT64_MAX, NULL, m, NULL, &f3) == 0);
+ assert_se(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);
+ journal_file_print_header(f1);
puts("");
- journal_file_print_header(f2->file);
+ journal_file_print_header(f2);
puts("");
- journal_file_print_header(f3->file);
+ journal_file_print_header(f3);
puts("");
- journal_file_print_header(f4->file);
+ journal_file_print_header(f4);
puts("");
log_info("Done...");
@@ -160,10 +160,10 @@ static void test_empty_one(void) {
assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
}
- (void) managed_journal_file_close(f1);
- (void) managed_journal_file_close(f2);
- (void) managed_journal_file_close(f3);
- (void) managed_journal_file_close(f4);
+ (void) journal_file_offline_close(f1);
+ (void) journal_file_offline_close(f2);
+ (void) journal_file_offline_close(f3);
+ (void) journal_file_offline_close(f4);
}
TEST(empty) {
@@ -178,7 +178,7 @@ TEST(empty) {
static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
dual_timestamp ts;
- ManagedJournalFile *f;
+ JournalFile *f;
struct iovec iovec;
Object *o;
uint64_t p;
@@ -194,34 +194,34 @@ 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, &f) == 0);
+ assert_se(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);
iovec = IOVEC_MAKE(data, data_size);
- assert_se(journal_file_append_entry(f->file, &ts, NULL, &iovec, 1, NULL, NULL, NULL, NULL) == 0);
+ assert_se(journal_file_append_entry(f, &ts, NULL, &iovec, 1, NULL, NULL, NULL, NULL) == 0);
#if HAVE_GCRYPT
- journal_file_append_tag(f->file);
+ journal_file_append_tag(f);
#endif
- journal_file_dump(f->file);
+ journal_file_dump(f);
/* We have to partially reimplement some of the dump logic, because the normal next_entry does the
* decompression for us. */
- p = le64toh(f->file->header->header_size);
+ p = le64toh(f->header->header_size);
for (;;) {
- r = journal_file_move_to_object(f->file, OBJECT_UNUSED, p, &o);
+ r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &o);
assert_se(r == 0);
if (o->object.type == OBJECT_DATA)
break;
- assert_se(p < le64toh(f->file->header->tail_object_offset));
+ assert_se(p < le64toh(f->header->tail_object_offset));
p = p + ALIGN64(le64toh(o->object.size));
}
is_compressed = COMPRESSION_FROM_OBJECT(o) != COMPRESSION_NONE;
- (void) managed_journal_file_close(f);
+ (void) journal_file_offline_close(f);
log_info("Done...");
@@ -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 */
+ /* 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");