mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
Merge pull request #22857 from poettering/journal-file-flags
journal: add flags param to journal_file_open(), replacing bools
This commit is contained in:
commit
e5531be27b
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
@ -57,11 +59,10 @@ static Writer* writer_free(Writer *w) {
|
||||
DEFINE_TRIVIAL_REF_UNREF_FUNC(Writer, writer, writer_free);
|
||||
|
||||
int writer_write(Writer *w,
|
||||
struct iovec_wrapper *iovw,
|
||||
dual_timestamp *ts,
|
||||
sd_id128_t *boot_id,
|
||||
bool compress,
|
||||
bool seal) {
|
||||
const struct iovec_wrapper *iovw,
|
||||
const dual_timestamp *ts,
|
||||
const sd_id128_t *boot_id,
|
||||
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
|
||||
|
@ -26,11 +26,10 @@ Writer* writer_unref(Writer *w);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Writer*, writer_unref);
|
||||
|
||||
int writer_write(Writer *s,
|
||||
struct iovec_wrapper *iovw,
|
||||
dual_timestamp *ts,
|
||||
sd_id128_t *boot_id,
|
||||
bool compress,
|
||||
bool seal);
|
||||
const struct iovec_wrapper *iovw,
|
||||
const dual_timestamp *ts,
|
||||
const sd_id128_t *boot_id,
|
||||
JournalFileFlags file_flags);
|
||||
|
||||
typedef enum JournalWriteSplitMode {
|
||||
JOURNAL_WRITE_SPLIT_NONE,
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "time-util.h"
|
||||
|
||||
typedef struct JournalMetrics {
|
||||
/* For all these: -1 means "pick automatically", and 0 means "no limit enforced" */
|
||||
/* For all these: UINT64_MAX means "pick automatically", and 0 means "no limit enforced" */
|
||||
uint64_t max_size; /* how large journal files grow at max */
|
||||
uint64_t min_size; /* how large journal files grow at least */
|
||||
uint64_t max_use; /* how much disk space to use in total at max, keep_free permitting */
|
||||
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user