]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-file: merge compress/seal bool args into a single flags param
authorLennart Poettering <lennart@poettering.net>
Thu, 24 Mar 2022 13:04:40 +0000 (14:04 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 25 Mar 2022 08:59:09 +0000 (09:59 +0100)
Just some modernization/refactoring.

No change in behaviour, just let's do how we do things these days: use
flags param instead of list of bools.

19 files changed:
src/journal-remote/fuzz-journal-remote.c
src/journal-remote/journal-remote-main.c
src/journal-remote/journal-remote-parse.c
src/journal-remote/journal-remote-parse.h
src/journal-remote/journal-remote-write.c
src/journal-remote/journal-remote-write.h
src/journal-remote/journal-remote.c
src/journal-remote/journal-remote.h
src/journal/journald-server.c
src/journal/managed-journal-file.c
src/journal/managed-journal-file.h
src/journal/test-journal-flush.c
src/journal/test-journal-interleaving.c
src/journal/test-journal-stream.c
src/journal/test-journal-verify.c
src/journal/test-journal.c
src/libsystemd/sd-journal/journal-file.c
src/libsystemd/sd-journal/journal-file.h
src/libsystemd/sd-journal/sd-journal.c

index 1731b94bb8b2714717ab76b0ce282ee2ac9affd4..9206b9940670846e8a61d1e0ffe3f8e4bd0f902d 100644 (file)
@@ -43,7 +43,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 
         /* In */
 
-        r = journal_remote_server_init(&s, name, JOURNAL_WRITE_SPLIT_NONE, false, false);
+        r = journal_remote_server_init(&s, name, JOURNAL_WRITE_SPLIT_NONE, 0);
         if (r < 0) {
                 assert_se(IN_SET(r, -ENOMEM, -EMFILE, -ENFILE));
                 return r;
index beb73f3572c1c89a245edc89fa562dd9e01e19cd..7c3c9ff44ab90efb64358630fe78447bb31b241e 100644 (file)
@@ -223,9 +223,7 @@ static int process_http_upload(
                 finished = true;
 
         for (;;) {
-                r = process_source(source,
-                                   journal_remote_server_global->compress,
-                                   journal_remote_server_global->seal);
+                r = process_source(source, journal_remote_server_global->file_flags);
                 if (r == -EAGAIN)
                         break;
                 if (r < 0) {
@@ -599,7 +597,12 @@ static int create_remoteserver(
 
         int r, n, fd;
 
-        r = journal_remote_server_init(s, arg_output, arg_split_mode, arg_compress, arg_seal);
+        r = journal_remote_server_init(
+                        s,
+                        arg_output,
+                        arg_split_mode,
+                        (arg_compress ? JOURNAL_COMPRESS : 0) |
+                        (arg_seal ? JOURNAL_SEAL : 0));
         if (r < 0)
                 return r;
 
index 2ece329251f84ac281629659ee05318dbbfda7ed..f8d068d6fe1e09e866c807f952cae39ddbe007f1 100644 (file)
@@ -47,7 +47,7 @@ RemoteSource* source_new(int fd, bool passive_fd, char *name, Writer *writer) {
         return source;
 }
 
-int process_source(RemoteSource *source, bool compress, bool seal) {
+int process_source(RemoteSource *source, JournalFileFlags file_flags) {
         int r;
 
         assert(source);
@@ -72,7 +72,7 @@ int process_source(RemoteSource *source, bool compress, bool seal) {
                          &source->importer.iovw,
                          &source->importer.ts,
                          &source->importer.boot_id,
-                         compress, seal);
+                         file_flags);
         if (r == -EBADMSG) {
                 log_warning_errno(r, "Entry is invalid, ignoring.");
                 r = 0;
index a5b51ad4d14563e686b33963404cd0ba7a3288fe..703035b1ecbb43df5828eb4d470443c6cfeeda63 100644 (file)
@@ -17,4 +17,4 @@ typedef struct RemoteSource {
 
 RemoteSource* source_new(int fd, bool passive_fd, char *name, Writer *writer);
 void source_free(RemoteSource *source);
-int process_source(RemoteSource *source, bool compress, bool seal);
+int process_source(RemoteSource *source, JournalFileFlags file_flags);
index 6477bfac2d79732fecb41e3fcea47754582b3390..f4f3b64811de549ce96e6c249015c66fcc62d299 100644 (file)
@@ -3,8 +3,10 @@
 #include "alloc-util.h"
 #include "journal-remote.h"
 
-static int do_rotate(ManagedJournalFile **f, MMapCache *m, bool compress, bool seal) {
-        int r = managed_journal_file_rotate(f, m, compress, UINT64_MAX, seal, NULL);
+static int do_rotate(ManagedJournalFile **f, MMapCache *m, JournalFileFlags file_flags) {
+        int r;
+
+        r = managed_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);
@@ -60,8 +62,7 @@ int writer_write(Writer *w,
                  const struct iovec_wrapper *iovw,
                  const dual_timestamp *ts,
                  const sd_id128_t *boot_id,
-                 bool compress,
-                 bool seal) {
+                 JournalFileFlags file_flags) {
         int r;
 
         assert(w);
@@ -71,7 +72,7 @@ int writer_write(Writer *w,
         if (journal_file_rotate_suggested(w->journal->file, 0, LOG_DEBUG)) {
                 log_info("%s: Journal header limits reached or header out-of-date, rotating",
                          w->journal->file->path);
-                r = do_rotate(&w->journal, w->mmap, compress, seal);
+                r = do_rotate(&w->journal, w->mmap, file_flags);
                 if (r < 0)
                         return r;
         }
@@ -87,7 +88,7 @@ int writer_write(Writer *w,
                 return r;
 
         log_debug_errno(r, "%s: Write failed, rotating: %m", w->journal->file->path);
-        r = do_rotate(&w->journal, w->mmap, compress, seal);
+        r = do_rotate(&w->journal, w->mmap, file_flags);
         if (r < 0)
                 return r;
         else
index 0e375f3489e5429c4c2e1d8c68c893ed95f2d47d..2079214e2349d2f14d7a05b002dc3a6387add9c9 100644 (file)
@@ -29,8 +29,7 @@ int writer_write(Writer *s,
                  const struct iovec_wrapper *iovw,
                  const dual_timestamp *ts,
                  const sd_id128_t *boot_id,
-                 bool compress,
-                 bool seal);
+                 JournalFileFlags file_flags);
 
 typedef enum JournalWriteSplitMode {
         JOURNAL_WRITE_SPLIT_NONE,
index 67a0205bee4f08e956a2019250a18e65227ebc31..d1f394b027ab30e1a6e9f479f4f972a6f9a85ae2 100644 (file)
@@ -61,12 +61,17 @@ static int open_output(RemoteServer *s, Writer *w, const char* host) {
                 assert_not_reached();
         }
 
-        r = managed_journal_file_open_reliably(filename,
-                                        O_RDWR|O_CREAT, 0640,
-                                        s->compress, UINT64_MAX, s->seal,
-                                        &w->metrics,
-                                        w->mmap, NULL,
-                                        NULL, &w->journal);
+        r = managed_journal_file_open_reliably(
+                        filename,
+                        O_RDWR|O_CREAT,
+                        s->file_flags,
+                        0640,
+                        UINT64_MAX,
+                        &w->metrics,
+                        w->mmap,
+                        NULL,
+                        NULL,
+                        &w->journal);
         if (r < 0)
                 return log_error_errno(r, "Failed to open output journal %s: %m", filename);
 
@@ -302,8 +307,7 @@ int journal_remote_server_init(
                 RemoteServer *s,
                 const char *output,
                 JournalWriteSplitMode split_mode,
-                bool compress,
-                bool seal) {
+                JournalFileFlags file_flags) {
 
         int r;
 
@@ -313,8 +317,7 @@ int journal_remote_server_init(
         journal_remote_server_global = s;
 
         s->split_mode = split_mode;
-        s->compress = compress;
-        s->seal = seal;
+        s->file_flags = file_flags;
 
         if (output)
                 s->output = output;
@@ -391,7 +394,7 @@ int journal_remote_handle_raw_source(
         source = s->sources[fd];
         assert(source->importer.fd == fd);
 
-        r = process_source(source, s->compress, s->seal);
+        r = process_source(source, s->file_flags);
         if (journal_importer_eof(&source->importer)) {
                 size_t remaining;
 
index 45176e964da6337e1134f5993ee365f8e1e59a4a..facf1516e0563e7b37f750ca9f988d22384a4949 100644 (file)
@@ -38,8 +38,7 @@ struct RemoteServer {
         const char *output;                    /* either the output file or directory */
 
         JournalWriteSplitMode split_mode;
-        bool compress;
-        bool seal;
+        JournalFileFlags file_flags;
         bool check_trust;
 };
 extern RemoteServer *journal_remote_server_global;
@@ -48,8 +47,7 @@ int journal_remote_server_init(
                 RemoteServer *s,
                 const char *output,
                 JournalWriteSplitMode split_mode,
-                bool compress,
-                bool seal);
+                JournalFileFlags file_flags);
 
 int journal_remote_get_writer(RemoteServer *s, const char *host, Writer **writer);
 
index a7858eedff7307a104fdd69d4e30ced8dc878c56..ed27af28e1118b74ceaabb86a8684fde0d679461 100644 (file)
@@ -260,26 +260,46 @@ static int open_journal(
                 Server *s,
                 bool reliably,
                 const char *fname,
-                int flags,
+                int open_flags,
                 bool seal,
                 JournalMetrics *metrics,
                 ManagedJournalFile **ret) {
 
         _cleanup_(managed_journal_file_closep) ManagedJournalFile *f = NULL;
+        JournalFileFlags file_flags;
         int r;
 
         assert(s);
         assert(fname);
         assert(ret);
 
+        file_flags = (s->compress.enabled ? JOURNAL_COMPRESS : 0) | (seal ? JOURNAL_SEAL : 0);
+
         if (reliably)
-                r = managed_journal_file_open_reliably(fname, flags, 0640, s->compress.enabled,
-                                                s->compress.threshold_bytes, seal, metrics, s->mmap,
-                                                s->deferred_closes, NULL, &f);
+                r = managed_journal_file_open_reliably(
+                                fname,
+                                open_flags,
+                                file_flags,
+                                0640,
+                                s->compress.threshold_bytes,
+                                metrics,
+                                s->mmap,
+                                s->deferred_closes,
+                                NULL,
+                                &f);
         else
-                r = managed_journal_file_open(-1, fname, flags, 0640, s->compress.enabled,
-                                       s->compress.threshold_bytes, seal, metrics, s->mmap,
-                                       s->deferred_closes, NULL, &f);
+                r = managed_journal_file_open(
+                                -1,
+                                fname,
+                                open_flags,
+                                file_flags,
+                                0640,
+                                s->compress.threshold_bytes,
+                                metrics,
+                                s->mmap,
+                                s->deferred_closes,
+                                NULL,
+                                &f);
 
         if (r < 0)
                 return r;
@@ -457,13 +477,19 @@ static int do_rotate(
                 bool seal,
                 uint32_t uid) {
 
+        JournalFileFlags file_flags;
         int r;
+
         assert(s);
 
         if (!*f)
                 return -EINVAL;
 
-        r = managed_journal_file_rotate(f, s->mmap, s->compress.enabled, s->compress.threshold_bytes, seal, s->deferred_closes);
+        file_flags =
+                (s->compress.enabled ? JOURNAL_COMPRESS : 0)|
+                (seal ? JOURNAL_SEAL : 0);
+
+        r = managed_journal_file_rotate(f, s->mmap, file_flags, s->compress.threshold_bytes, s->deferred_closes);
         if (r < 0) {
                 if (*f)
                         return log_error_errno(r, "Failed to rotate %s: %m", (*f)->file->path);
@@ -574,18 +600,19 @@ static int vacuum_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(fd,
-                                       full,
-                                       O_RDWR,
-                                       0640,
-                                       s->compress.enabled,
-                                       s->compress.threshold_bytes,
-                                       s->seal,
-                                       &s->system_storage.metrics,
-                                       s->mmap,
-                                       s->deferred_closes,
-                                       NULL,
-                                       &f);
+                r = managed_journal_file_open(
+                                fd,
+                                full,
+                                O_RDWR,
+                                (s->compress.enabled ? JOURNAL_COMPRESS : 0) |
+                                (s->seal ? JOURNAL_SEAL : 0),
+                                0640,
+                                s->compress.threshold_bytes,
+                                &s->system_storage.metrics,
+                                s->mmap,
+                                s->deferred_closes,
+                                NULL,
+                                &f);
                 if (r < 0) {
                         log_warning_errno(r, "Failed to read journal file %s for rotation, trying to move it out of the way: %m", full);
 
index 03b1d8275e66e7fd458073866d0590194cd395e9..7e89bb30d900ba1bc06f179819e4cc816351049c 100644 (file)
@@ -393,11 +393,10 @@ ManagedJournalFile* managed_journal_file_close(ManagedJournalFile *f) {
 int managed_journal_file_open(
                 int fd,
                 const char *fname,
-                int flags,
+                int open_flags,
+                JournalFileFlags file_flags,
                 mode_t mode,
-                bool compress,
                 uint64_t compress_threshold_bytes,
-                bool seal,
                 JournalMetrics *metrics,
                 MMapCache *mmap_cache,
                 Set *deferred_closes,
@@ -412,7 +411,7 @@ int managed_journal_file_open(
         if (!f)
                 return -ENOMEM;
 
-        r = journal_file_open(fd, fname, flags, mode, compress, compress_threshold_bytes, seal, metrics,
+        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;
@@ -444,9 +443,8 @@ ManagedJournalFile* managed_journal_file_initiate_close(ManagedJournalFile *f, S
 int managed_journal_file_rotate(
                 ManagedJournalFile **f,
                 MMapCache *mmap_cache,
-                bool compress,
+                JournalFileFlags file_flags,
                 uint64_t compress_threshold_bytes,
-                bool seal,
                 Set *deferred_closes) {
 
         _cleanup_free_ char *path = NULL;
@@ -463,11 +461,10 @@ int managed_journal_file_rotate(
         r = managed_journal_file_open(
                         -1,
                         path,
-                        (*f)->file->flags,
+                        (*f)->file->open_flags,
+                        file_flags,
                         (*f)->file->mode,
-                        compress,
                         compress_threshold_bytes,
-                        seal,
                         NULL,            /* metrics */
                         mmap_cache,
                         deferred_closes,
@@ -482,11 +479,10 @@ int managed_journal_file_rotate(
 
 int managed_journal_file_open_reliably(
                 const char *fname,
-                int flags,
+                int open_flags,
+                JournalFileFlags file_flags,
                 mode_t mode,
-                bool compress,
                 uint64_t compress_threshold_bytes,
-                bool seal,
                 JournalMetrics *metrics,
                 MMapCache *mmap_cache,
                 Set *deferred_closes,
@@ -495,7 +491,7 @@ int managed_journal_file_open_reliably(
 
         int r;
 
-        r = managed_journal_file_open(-1, fname, flags, mode, compress, compress_threshold_bytes, seal, metrics,
+        r = managed_journal_file_open(-1, fname, open_flags, file_flags, mode, compress_threshold_bytes, metrics,
                                mmap_cache, deferred_closes, template, ret);
         if (!IN_SET(r,
                     -EBADMSG,           /* Corrupted */
@@ -509,10 +505,10 @@ int managed_journal_file_open_reliably(
                     -ETXTBSY))          /* File is from the future */
                 return r;
 
-        if ((flags & O_ACCMODE) == O_RDONLY)
+        if ((open_flags & O_ACCMODE) == O_RDONLY)
                 return r;
 
-        if (!(flags & O_CREAT))
+        if (!(open_flags & O_CREAT))
                 return r;
 
         if (!endswith(fname, ".journal"))
@@ -525,6 +521,6 @@ int managed_journal_file_open_reliably(
         if (r < 0)
                 return r;
 
-        return managed_journal_file_open(-1, fname, flags, mode, compress, compress_threshold_bytes, seal, metrics,
+        return managed_journal_file_open(-1, fname, open_flags, file_flags, mode, compress_threshold_bytes, metrics,
                                   mmap_cache, deferred_closes, template, ret);
 }
index 6951b000f2c944abf9b20e00dac0ea2b6df91cb1..0ac69a798508d46ccce2eafdf5191cf024839bda 100644 (file)
@@ -10,11 +10,10 @@ typedef struct {
 int managed_journal_file_open(
                 int fd,
                 const char *fname,
-                int flags,
+                int open_flags,
+                JournalFileFlags file_flags,
                 mode_t mode,
-                bool compress,
                 uint64_t compress_threshold_bytes,
-                bool seal,
                 JournalMetrics *metrics,
                 MMapCache *mmap_cache,
                 Set *deferred_closes,
@@ -28,11 +27,10 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(ManagedJournalFile*, managed_journal_file_close);
 
 int managed_journal_file_open_reliably(
                 const char *fname,
-                int flags,
+                int open_flags,
+                JournalFileFlags file_flags,
                 mode_t mode,
-                bool compress,
                 uint64_t compress_threshold_bytes,
-                bool seal,
                 JournalMetrics *metrics,
                 MMapCache *mmap_cache,
                 Set *deferred_closes,
@@ -40,4 +38,4 @@ int managed_journal_file_open_reliably(
                 ManagedJournalFile **ret);
 
 ManagedJournalFile* managed_journal_file_initiate_close(ManagedJournalFile *f, Set *deferred_closes);
-int managed_journal_file_rotate(ManagedJournalFile **f, MMapCache *mmap_cache, bool compress, uint64_t compress_threshold_bytes, bool seal, Set *deferred_closes);
+int managed_journal_file_rotate(ManagedJournalFile **f, MMapCache *mmap_cache, JournalFileFlags file_flags, uint64_t compress_threshold_bytes, Set *deferred_closes);
index 6af819f7339cf069a8221f1b226d9c9abc83db32..06eeb1a57814adee4e970112496340be14da23c3 100644 (file)
@@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {
 
         fn = path_join(dn, "test.journal");
 
-        r = managed_journal_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, 0, false, NULL, m, NULL, NULL, &new_journal);
+        r = managed_journal_file_open(-1, fn, O_CREAT|O_RDWR, 0, 0644, 0, NULL, m, NULL, NULL, &new_journal);
         assert_se(r >= 0);
 
         if (argc > 1)
index bbb83d08240339ab7b011df13aca9e7f585fdf1b..a27ffe5606c88988a8323701e6bf5ed1a3f3460e 100644 (file)
@@ -40,7 +40,7 @@ static ManagedJournalFile *test_open(const char *name) {
         m = mmap_cache_new();
         assert_se(m != NULL);
 
-        assert_ret(managed_journal_file_open(-1, name, O_RDWR|O_CREAT, 0644, true, UINT64_MAX, false, NULL, m, NULL, NULL, &f));
+        assert_ret(managed_journal_file_open(-1, name, O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0644, UINT64_MAX, NULL, m, NULL, NULL, &f));
         return f;
 }
 
@@ -218,8 +218,8 @@ TEST(sequence_numbers) {
 
         mkdtemp_chdir_chattr(t);
 
-        assert_se(managed_journal_file_open(-1, "one.journal", O_RDWR|O_CREAT, 0644,
-                                     true, UINT64_MAX, false, NULL, m, NULL, NULL, &one) == 0);
+        assert_se(managed_journal_file_open(-1, "one.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0644,
+                                            UINT64_MAX, NULL, m, NULL, NULL, &one) == 0);
 
         append_number(one, 1, &seqnum);
         printf("seqnum=%"PRIu64"\n", seqnum);
@@ -235,8 +235,8 @@ TEST(sequence_numbers) {
 
         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, 0644,
-                                     true, UINT64_MAX, false, NULL, m, NULL, one, &two) == 0);
+        assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0644,
+                                            UINT64_MAX, NULL, m, NULL, 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));
@@ -266,8 +266,8 @@ TEST(sequence_numbers) {
         /* restart server */
         seqnum = 0;
 
-        assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR, 0,
-                                     true, UINT64_MAX, false, NULL, m, NULL, NULL, &two) == 0);
+        assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR, JOURNAL_COMPRESS, 0,
+                                            UINT64_MAX, NULL, m, NULL, NULL, &two) == 0);
 
         assert_se(sd_id128_equal(two->file->header->seqnum_id, seqnum_id));
 
index 486a2f41c20df2f54a76b28105ae62d5e87d2b9b..f7bbd4bff977c9887d723c485ffec145f66ac2e1 100644 (file)
@@ -77,9 +77,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, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &one) == 0);
-        assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &two) == 0);
-        assert_se(managed_journal_file_open(-1, "three.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, 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, 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);
 
         for (i = 0; i < N_ENTRIES; i++) {
                 char *p, *q;
index 323e495081df0c9afad3162aca8c9620ea767b92..1b30ebffaf439800cc60d1c41526069d6eb65178 100644 (file)
@@ -46,7 +46,7 @@ static int raw_verify(const char *fn, const char *verification_key) {
         m = mmap_cache_new();
         assert_se(m != NULL);
 
-        r = journal_file_open(-1, fn, O_RDONLY, 0666, true, UINT64_MAX, !!verification_key, NULL, m, NULL, &f);
+        r = journal_file_open(-1, fn, O_RDONLY, JOURNAL_COMPRESS|(verification_key ? JOURNAL_SEAL : 0), 0666, UINT64_MAX, NULL, m, NULL, &f);
         if (r < 0)
                 return r;
 
@@ -82,7 +82,7 @@ int main(int argc, char *argv[]) {
 
         log_info("Generating...");
 
-        assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, !!verification_key, NULL, m, NULL, NULL, &df) == 0);
+        assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS|(verification_key ? JOURNAL_SEAL : 0), 0666, UINT64_MAX, NULL, m, NULL, NULL, &df) == 0);
 
         for (n = 0; n < N_ENTRIES; n++) {
                 struct iovec iovec;
@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
 
         log_info("Verifying...");
 
-        assert_se(journal_file_open(-1, "test.journal", O_RDONLY, 0666, true, UINT64_MAX, !!verification_key, NULL, m, NULL, &f) == 0);
+        assert_se(journal_file_open(-1, "test.journal", O_RDONLY, JOURNAL_COMPRESS|(verification_key ? JOURNAL_SEAL: 0), 0666, UINT64_MAX, NULL, m, NULL, &f) == 0);
         /* journal_file_print_header(f); */
         journal_file_dump(f);
 
index 07c476559c33ad7a2f83c8e214d82ef6f6a201d1..b95e716b9c568cb3f5adf998d8062a09e6fffe5e 100644 (file)
@@ -39,7 +39,7 @@ TEST(non_empty) {
 
         mkdtemp_chdir_chattr(t);
 
-        assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, true, 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, NULL, &f) == 0);
 
         assert_se(dual_timestamp_get(&ts));
         assert_se(sd_id128_randomize(&fake_boot_id) == 0);
@@ -100,8 +100,8 @@ TEST(non_empty) {
 
         assert_se(journal_file_move_to_entry_by_seqnum(f->file, 10, DIRECTION_DOWN, &o, NULL) == 0);
 
-        managed_journal_file_rotate(&f, m, true, UINT64_MAX, true, NULL);
-        managed_journal_file_rotate(&f, m, true, UINT64_MAX, true, NULL);
+        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);
 
         (void) managed_journal_file_close(f);
 
@@ -128,10 +128,10 @@ TEST(empty) {
 
         mkdtemp_chdir_chattr(t);
 
-        assert_se(managed_journal_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, false, UINT64_MAX, false, NULL, m, NULL, NULL, &f1) == 0);
-        assert_se(managed_journal_file_open(-1, "test-compress.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &f2) == 0);
-        assert_se(managed_journal_file_open(-1, "test-seal.journal", O_RDWR|O_CREAT, 0666, false, UINT64_MAX, true, NULL, m, NULL, NULL, &f3) == 0);
-        assert_se(managed_journal_file_open(-1, "test-seal-compress.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, true, 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, 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);
 
         journal_file_print_header(f1->file);
         puts("");
@@ -178,7 +178,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, 0666, true, compress_threshold, true, 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, NULL, &f) == 0);
 
         dual_timestamp_get(&ts);
 
index 27875fb9e71cc4a1976f51b77e9d180afc276581..41a42d7be4366ad22a22f5f12747cff9700ac2c6 100644 (file)
@@ -3314,11 +3314,10 @@ static int journal_file_warn_btrfs(JournalFile *f) {
 int journal_file_open(
                 int fd,
                 const char *fname,
-                int flags,
+                int open_flags,
+                JournalFileFlags file_flags,
                 mode_t mode,
-                bool compress,
                 uint64_t compress_threshold_bytes,
-                bool seal,
                 JournalMetrics *metrics,
                 MMapCache *mmap_cache,
                 JournalFile *template,
@@ -3333,13 +3332,13 @@ int journal_file_open(
         assert(fd >= 0 || fname);
         assert(mmap_cache);
 
-        if (!IN_SET((flags & O_ACCMODE), O_RDONLY, O_RDWR))
+        if (!IN_SET((open_flags & O_ACCMODE), O_RDONLY, O_RDWR))
                 return -EINVAL;
 
-        if ((flags & O_ACCMODE) == O_RDONLY && FLAGS_SET(flags, O_CREAT))
+        if ((open_flags & O_ACCMODE) == O_RDONLY && FLAGS_SET(open_flags, O_CREAT))
                 return -EINVAL;
 
-        if (fname && (flags & O_CREAT) && !endswith(fname, ".journal"))
+        if (fname && (open_flags & O_CREAT) && !endswith(fname, ".journal"))
                 return -EINVAL;
 
         f = new(JournalFile, 1);
@@ -3350,21 +3349,21 @@ int journal_file_open(
                 .fd = fd,
                 .mode = mode,
 
-                .flags = flags,
-                .writable = (flags & O_ACCMODE) != O_RDONLY,
+                .open_flags = open_flags,
+                .writable = (open_flags & O_ACCMODE) != O_RDONLY,
 
 #if HAVE_ZSTD
-                .compress_zstd = compress,
+                .compress_zstd = FLAGS_SET(file_flags, JOURNAL_COMPRESS),
 #elif HAVE_LZ4
-                .compress_lz4 = compress,
+                .compress_lz4 = FLAGS_SET(file_flags, JOURNAL_COMPRESS),
 #elif HAVE_XZ
-                .compress_xz = compress,
+                .compress_xz = FLAGS_SET(file_flags, JOURNAL_COMPRESS),
 #endif
                 .compress_threshold_bytes = compress_threshold_bytes == UINT64_MAX ?
                                             DEFAULT_COMPRESS_THRESHOLD :
                                             MAX(MIN_COMPRESS_THRESHOLD, compress_threshold_bytes),
 #if HAVE_GCRYPT
-                .seal = seal,
+                .seal = FLAGS_SET(file_flags, JOURNAL_SEAL),
 #endif
         };
 
@@ -3424,7 +3423,7 @@ int journal_file_open(
                  * or so, we likely fail quickly than block for long. For regular files O_NONBLOCK has no effect, hence
                  * it doesn't hurt in that case. */
 
-                f->fd = openat_report_new(AT_FDCWD, f->path, f->flags|O_CLOEXEC|O_NONBLOCK, f->mode, &newly_created);
+                f->fd = openat_report_new(AT_FDCWD, f->path, f->open_flags|O_CLOEXEC|O_NONBLOCK, f->mode, &newly_created);
                 if (f->fd < 0) {
                         r = f->fd;
                         goto fail;
@@ -3451,7 +3450,7 @@ int journal_file_open(
                 newly_created = f->last_stat.st_size == 0 && f->writable;
         }
 
-        f->cache_fd = mmap_cache_add_fd(mmap_cache, f->fd, prot_from_flags(flags));
+        f->cache_fd = mmap_cache_add_fd(mmap_cache, f->fd, prot_from_flags(open_flags));
         if (!f->cache_fd) {
                 r = -ENOMEM;
                 goto fail;
index 59509deec9d486d2711d3e4dd2dad0a69cb06daf..7a2c5cdcbeed1026014b6aa1857506d830754d2d 100644 (file)
@@ -62,7 +62,7 @@ typedef struct JournalFile {
 
         mode_t mode;
 
-        int flags;
+        int open_flags;
         bool writable:1;
         bool compress_xz:1;
         bool compress_lz4:1;
@@ -126,14 +126,18 @@ typedef struct JournalFile {
 #endif
 } JournalFile;
 
+typedef enum JournalFileFlags {
+        JOURNAL_COMPRESS = 1 << 0,
+        JOURNAL_SEAL     = 1 << 1,
+} JournalFileFlags;
+
 int journal_file_open(
                 int fd,
                 const char *fname,
-                int flags,
+                int open_flags,
+                JournalFileFlags file_flags,
                 mode_t mode,
-                bool compress,
                 uint64_t compress_threshold_bytes,
-                bool seal,
                 JournalMetrics *metrics,
                 MMapCache *mmap_cache,
                 JournalFile *template,
index 9a886711a99d721e27d6c67789cc882a6d4397d5..e8c66a5e2cc8b4a3786ddbbd64f02d7a4e7e4f3f 100644 (file)
@@ -1337,7 +1337,7 @@ static int add_any_file(
                 goto finish;
         }
 
-        r = journal_file_open(fd, path, O_RDONLY, 0, false, 0, false, NULL, j->mmap, NULL, &f);
+        r = journal_file_open(fd, path, O_RDONLY, 0, 0, 0, NULL, j->mmap, NULL, &f);
         if (r < 0) {
                 log_debug_errno(r, "Failed to open journal file %s: %m", path);
                 goto finish;