1
0
mirror of https://github.com/systemd/systemd synced 2026-04-10 09:04:50 +02:00

Compare commits

..

No commits in common. "bb916f350a090bf10a8e71ea26147d4071300d2a" and "733caba3894274a3e53438677bea38a3aa48a458" have entirely different histories.

18 changed files with 64 additions and 104 deletions

View File

@ -161,12 +161,8 @@
<refsect1> <refsect1>
<title>Environment variables</title> <title>Environment variables</title>
<para>If <option>--verbose</option> is used, <varname>$KERNEL_INSTALL_VERBOSE=1</varname> will be set for <para>If <option>--verbose</option> is used, <varname>$KERNEL_INSTALL_VERBOSE=1</varname> will be set for
the plugins. They may output additional logs in this case.</para> the plugins. They may output additional logs in this case.</para>
<para>If <varname>MACHINE_ID=</varname> is set and not empty, it will be used as <replaceable>MACHINE-ID</replaceable>,
overriding any automatic detection attempts. The value must be a valid machine ID (32 hexadecimal characters).</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
@ -218,9 +214,9 @@
</term> </term>
<listitem> <listitem>
<para>The content of this file specifies the machine identification <para>The content of this file specifies the machine identification
<replaceable>MACHINE-ID</replaceable>. If <filename>/etc/machine-id</filename> <replaceable>MACHINE-ID</replaceable>. If <filename>$BOOT/Default</filename> exists,
cannot be read or is temporary (backed by a file on <constant>tmpfs</constant>), or <filename>/etc/machine-id</filename> doesn't, <command>kernel-install</command>
<command>kernel-install</command> will use <literal>Default</literal> instead.</para> will use the literal <literal>Default</literal> as the machine ID instead.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -3,8 +3,8 @@
#include "alloc-util.h" #include "alloc-util.h"
#include "journal-remote.h" #include "journal-remote.h"
static int do_rotate(JournaldFile **f, MMapCache *m, bool compress, bool seal) { static int do_rotate(JournaldFile **f, bool compress, bool seal) {
int r = journald_file_rotate(f, m, compress, UINT64_MAX, seal, NULL); int r = journald_file_rotate(f, compress, UINT64_MAX, seal, NULL);
if (r < 0) { if (r < 0) {
if (*f) if (*f)
log_error_errno(r, "Failed to rotate %s: %m", (*f)->file->path); log_error_errno(r, "Failed to rotate %s: %m", (*f)->file->path);
@ -71,7 +71,7 @@ int writer_write(Writer *w,
if (journal_file_rotate_suggested(w->journal->file, 0, LOG_DEBUG)) { if (journal_file_rotate_suggested(w->journal->file, 0, LOG_DEBUG)) {
log_info("%s: Journal header limits reached or header out-of-date, rotating", log_info("%s: Journal header limits reached or header out-of-date, rotating",
w->journal->file->path); w->journal->file->path);
r = do_rotate(&w->journal, w->mmap, compress, seal); r = do_rotate(&w->journal, compress, seal);
if (r < 0) if (r < 0)
return r; return r;
} }
@ -87,7 +87,7 @@ int writer_write(Writer *w,
return r; 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->file->path);
r = do_rotate(&w->journal, w->mmap, compress, seal); r = do_rotate(&w->journal, compress, seal);
if (r < 0) if (r < 0)
return r; return r;
else else

View File

@ -403,7 +403,6 @@ JournaldFile* journald_file_initiate_close(JournaldFile *f, Set *deferred_closes
int journald_file_rotate( int journald_file_rotate(
JournaldFile **f, JournaldFile **f,
MMapCache *mmap_cache,
bool compress, bool compress,
uint64_t compress_threshold_bytes, uint64_t compress_threshold_bytes,
bool seal, bool seal,
@ -429,7 +428,7 @@ int journald_file_rotate(
compress_threshold_bytes, compress_threshold_bytes,
seal, seal,
NULL, /* metrics */ NULL, /* metrics */
mmap_cache, (*f)->file->mmap,
deferred_closes, deferred_closes,
*f, /* template */ *f, /* template */
&new_file); &new_file);

View File

@ -40,4 +40,4 @@ int journald_file_open_reliably(
JournaldFile **ret); JournaldFile **ret);
JournaldFile* journald_file_initiate_close(JournaldFile *f, Set *deferred_closes); JournaldFile* journald_file_initiate_close(JournaldFile *f, Set *deferred_closes);
int journald_file_rotate(JournaldFile **f, MMapCache *mmap_cache, bool compress, uint64_t compress_threshold_bytes, bool seal, Set *deferred_closes); int journald_file_rotate(JournaldFile **f, bool compress, uint64_t compress_threshold_bytes, bool seal, Set *deferred_closes);

View File

@ -465,7 +465,7 @@ static int do_rotate(
if (!*f) if (!*f)
return -EINVAL; return -EINVAL;
r = journald_file_rotate(f, s->mmap, s->compress.enabled, s->compress.threshold_bytes, seal, s->deferred_closes); r = journald_file_rotate(f, s->compress.enabled, s->compress.threshold_bytes, seal, s->deferred_closes);
if (r < 0) { if (r < 0) {
if (*f) if (*f)
return log_error_errno(r, "Failed to rotate %s: %m", (*f)->file->path); return log_error_errno(r, "Failed to rotate %s: %m", (*f)->file->path);

View File

@ -14,7 +14,6 @@
#include "string-util.h" #include "string-util.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
_cleanup_free_ char *fn = NULL; _cleanup_free_ char *fn = NULL;
char dn[] = "/var/tmp/test-journal-flush.XXXXXX"; char dn[] = "/var/tmp/test-journal-flush.XXXXXX";
JournaldFile *new_journal = NULL; JournaldFile *new_journal = NULL;
@ -22,14 +21,12 @@ int main(int argc, char *argv[]) {
unsigned n = 0; unsigned n = 0;
int r; int r;
m = mmap_cache_new();
assert_se(m != NULL);
assert_se(mkdtemp(dn)); assert_se(mkdtemp(dn));
(void) chattr_path(dn, FS_NOCOW_FL, FS_NOCOW_FL, NULL); (void) chattr_path(dn, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
fn = path_join(dn, "test.journal"); fn = path_join(dn, "test.journal");
r = journald_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, 0, false, NULL, m, NULL, NULL, &new_journal); r = journald_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, 0, false, NULL, NULL, NULL, NULL, &new_journal);
assert_se(r >= 0); assert_se(r >= 0);
if (argc > 1) if (argc > 1)

View File

@ -34,13 +34,8 @@ _noreturn_ static void log_assert_errno(const char *text, int error, const char
} while (false) } while (false)
static JournaldFile *test_open(const char *name) { static JournaldFile *test_open(const char *name) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
JournaldFile *f; JournaldFile *f;
assert_ret(journald_file_open(-1, name, O_RDWR|O_CREAT, 0644, true, UINT64_MAX, false, NULL, NULL, NULL, NULL, &f));
m = mmap_cache_new();
assert_se(m != NULL);
assert_ret(journald_file_open(-1, name, O_RDWR|O_CREAT, 0644, true, UINT64_MAX, false, NULL, m, NULL, NULL, &f));
return f; return f;
} }
@ -203,19 +198,15 @@ static void test_skip(void (*setup)(void)) {
static void test_sequence_numbers(void) { static void test_sequence_numbers(void) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
char t[] = "/var/tmp/journal-seq-XXXXXX"; char t[] = "/var/tmp/journal-seq-XXXXXX";
JournaldFile *one, *two; JournaldFile *one, *two;
uint64_t seqnum = 0; uint64_t seqnum = 0;
sd_id128_t seqnum_id; sd_id128_t seqnum_id;
m = mmap_cache_new();
assert_se(m != NULL);
mkdtemp_chdir_chattr(t); mkdtemp_chdir_chattr(t);
assert_se(journald_file_open(-1, "one.journal", O_RDWR|O_CREAT, 0644, assert_se(journald_file_open(-1, "one.journal", O_RDWR|O_CREAT, 0644,
true, UINT64_MAX, false, NULL, m, NULL, NULL, &one) == 0); true, UINT64_MAX, false, NULL, NULL, NULL, NULL, &one) == 0);
append_number(one, 1, &seqnum); append_number(one, 1, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum); printf("seqnum=%"PRIu64"\n", seqnum);
@ -232,7 +223,7 @@ static void test_sequence_numbers(void) {
memcpy(&seqnum_id, &one->file->header->seqnum_id, sizeof(sd_id128_t)); memcpy(&seqnum_id, &one->file->header->seqnum_id, sizeof(sd_id128_t));
assert_se(journald_file_open(-1, "two.journal", O_RDWR|O_CREAT, 0644, assert_se(journald_file_open(-1, "two.journal", O_RDWR|O_CREAT, 0644,
true, UINT64_MAX, false, NULL, m, NULL, one, &two) == 0); true, UINT64_MAX, false, NULL, NULL, NULL, one, &two) == 0);
assert_se(two->file->header->state == STATE_ONLINE); 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->file_id, one->file->header->file_id));
@ -263,7 +254,7 @@ static void test_sequence_numbers(void) {
seqnum = 0; seqnum = 0;
assert_se(journald_file_open(-1, "two.journal", O_RDWR, 0, assert_se(journald_file_open(-1, "two.journal", O_RDWR, 0,
true, UINT64_MAX, false, NULL, m, NULL, NULL, &two) == 0); true, UINT64_MAX, false, NULL, NULL, NULL, NULL, &two) == 0);
assert_se(sd_id128_equal(two->file->header->seqnum_id, seqnum_id)); assert_se(sd_id128_equal(two->file->header->seqnum_id, seqnum_id));

View File

@ -60,7 +60,6 @@ static void verify_contents(sd_journal *j, unsigned skip) {
} }
static void run_test(void) { static void run_test(void) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
JournaldFile *one, *two, *three; JournaldFile *one, *two, *three;
char t[] = "/var/tmp/journal-stream-XXXXXX"; char t[] = "/var/tmp/journal-stream-XXXXXX";
unsigned i; unsigned i;
@ -70,16 +69,13 @@ static void run_test(void) {
size_t l; size_t l;
dual_timestamp previous_ts = DUAL_TIMESTAMP_NULL; dual_timestamp previous_ts = DUAL_TIMESTAMP_NULL;
m = mmap_cache_new();
assert_se(m != NULL);
assert_se(mkdtemp(t)); assert_se(mkdtemp(t));
assert_se(chdir(t) >= 0); assert_se(chdir(t) >= 0);
(void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL, NULL); (void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
assert_se(journald_file_open(-1, "one.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &one) == 0); assert_se(journald_file_open(-1, "one.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, NULL, NULL, NULL, &one) == 0);
assert_se(journald_file_open(-1, "two.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &two) == 0); assert_se(journald_file_open(-1, "two.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, NULL, NULL, NULL, &two) == 0);
assert_se(journald_file_open(-1, "three.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &three) == 0); assert_se(journald_file_open(-1, "three.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, NULL, NULL, NULL, &three) == 0);
for (i = 0; i < N_ENTRIES; i++) { for (i = 0; i < N_ENTRIES; i++) {
char *p, *q; char *p, *q;

View File

@ -10,7 +10,6 @@
#include "journald-file.h" #include "journald-file.h"
#include "journal-verify.h" #include "journal-verify.h"
#include "log.h" #include "log.h"
#include "mmap-cache.h"
#include "rm-rf.h" #include "rm-rf.h"
#include "terminal-util.h" #include "terminal-util.h"
#include "tests.h" #include "tests.h"
@ -39,14 +38,10 @@ static void bit_toggle(const char *fn, uint64_t p) {
} }
static int raw_verify(const char *fn, const char *verification_key) { static int raw_verify(const char *fn, const char *verification_key) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
JournalFile *f; JournalFile *f;
int r; int r;
m = mmap_cache_new(); r = journal_file_open(-1, fn, O_RDONLY, 0666, true, UINT64_MAX, !!verification_key, NULL, NULL, NULL, &f);
assert_se(m != NULL);
r = journal_file_open(-1, fn, O_RDONLY, 0666, true, UINT64_MAX, !!verification_key, NULL, m, NULL, &f);
if (r < 0) if (r < 0)
return r; return r;
@ -57,7 +52,6 @@ static int raw_verify(const char *fn, const char *verification_key) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
char t[] = "/var/tmp/journal-XXXXXX"; char t[] = "/var/tmp/journal-XXXXXX";
unsigned n; unsigned n;
JournalFile *f; JournalFile *f;
@ -67,9 +61,6 @@ int main(int argc, char *argv[]) {
struct stat st; struct stat st;
uint64_t p; uint64_t p;
m = mmap_cache_new();
assert_se(m != NULL);
/* journald_file_open requires a valid machine id */ /* journald_file_open requires a valid machine id */
if (access("/etc/machine-id", F_OK) != 0) if (access("/etc/machine-id", F_OK) != 0)
return log_tests_skipped("/etc/machine-id not found"); return log_tests_skipped("/etc/machine-id not found");
@ -82,7 +73,7 @@ int main(int argc, char *argv[]) {
log_info("Generating..."); log_info("Generating...");
assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, !!verification_key, NULL, m, NULL, NULL, &df) == 0); assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, !!verification_key, NULL, NULL, NULL, NULL, &df) == 0);
for (n = 0; n < N_ENTRIES; n++) { for (n = 0; n < N_ENTRIES; n++) {
struct iovec iovec; struct iovec iovec;
@ -104,7 +95,7 @@ int main(int argc, char *argv[]) {
log_info("Verifying..."); 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, 0666, true, UINT64_MAX, !!verification_key, NULL, NULL, NULL, &f) == 0);
/* journal_file_print_header(f); */ /* journal_file_print_header(f); */
journal_file_dump(f); journal_file_dump(f);

View File

@ -24,7 +24,6 @@ static void mkdtemp_chdir_chattr(char *path) {
} }
static void test_non_empty(void) { static void test_non_empty(void) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
dual_timestamp ts; dual_timestamp ts;
JournaldFile *f; JournaldFile *f;
struct iovec iovec; struct iovec iovec;
@ -36,12 +35,9 @@ static void test_non_empty(void) {
test_setup_logging(LOG_DEBUG); test_setup_logging(LOG_DEBUG);
m = mmap_cache_new();
assert_se(m != NULL);
mkdtemp_chdir_chattr(t); mkdtemp_chdir_chattr(t);
assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, true, NULL, m, NULL, NULL, &f) == 0); assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, true, NULL, NULL, NULL, NULL, &f) == 0);
assert_se(dual_timestamp_get(&ts)); assert_se(dual_timestamp_get(&ts));
assert_se(sd_id128_randomize(&fake_boot_id) == 0); assert_se(sd_id128_randomize(&fake_boot_id) == 0);
@ -102,8 +98,8 @@ static void test_non_empty(void) {
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->file, 10, DIRECTION_DOWN, &o, NULL) == 0);
journald_file_rotate(&f, m, true, UINT64_MAX, true, NULL); journald_file_rotate(&f, true, UINT64_MAX, true, NULL);
journald_file_rotate(&f, m, true, UINT64_MAX, true, NULL); journald_file_rotate(&f, true, UINT64_MAX, true, NULL);
(void) journald_file_close(f); (void) journald_file_close(f);
@ -121,21 +117,17 @@ static void test_non_empty(void) {
} }
static void test_empty(void) { static void test_empty(void) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
JournaldFile *f1, *f2, *f3, *f4; JournaldFile *f1, *f2, *f3, *f4;
char t[] = "/var/tmp/journal-XXXXXX"; char t[] = "/var/tmp/journal-XXXXXX";
test_setup_logging(LOG_DEBUG); test_setup_logging(LOG_DEBUG);
m = mmap_cache_new();
assert_se(m != NULL);
mkdtemp_chdir_chattr(t); mkdtemp_chdir_chattr(t);
assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, false, UINT64_MAX, false, NULL, m, NULL, NULL, &f1) == 0); assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, false, UINT64_MAX, false, NULL, NULL, NULL, NULL, &f1) == 0);
assert_se(journald_file_open(-1, "test-compress.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, m, NULL, NULL, &f2) == 0); assert_se(journald_file_open(-1, "test-compress.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, false, NULL, NULL, NULL, NULL, &f2) == 0);
assert_se(journald_file_open(-1, "test-seal.journal", O_RDWR|O_CREAT, 0666, false, UINT64_MAX, true, NULL, m, NULL, NULL, &f3) == 0); assert_se(journald_file_open(-1, "test-seal.journal", O_RDWR|O_CREAT, 0666, false, UINT64_MAX, true, NULL, NULL, NULL, NULL, &f3) == 0);
assert_se(journald_file_open(-1, "test-seal-compress.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, true, NULL, m, NULL, NULL, &f4) == 0); assert_se(journald_file_open(-1, "test-seal-compress.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, true, NULL, NULL, NULL, NULL, &f4) == 0);
journal_file_print_header(f1->file); journal_file_print_header(f1->file);
puts(""); puts("");
@ -164,7 +156,6 @@ static void test_empty(void) {
#if HAVE_COMPRESSION #if HAVE_COMPRESSION
static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) { static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
dual_timestamp ts; dual_timestamp ts;
JournaldFile *f; JournaldFile *f;
struct iovec iovec; struct iovec iovec;
@ -179,12 +170,9 @@ static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
test_setup_logging(LOG_DEBUG); test_setup_logging(LOG_DEBUG);
m = mmap_cache_new();
assert_se(m != NULL);
mkdtemp_chdir_chattr(t); mkdtemp_chdir_chattr(t);
assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, compress_threshold, true, NULL, m, NULL, NULL, &f) == 0); assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, compress_threshold, true, NULL, NULL, NULL, NULL, &f) == 0);
dual_timestamp_get(&ts); dual_timestamp_get(&ts);

View File

@ -85,14 +85,20 @@ fi
KERNEL_VERSION="$1" KERNEL_VERSION="$1"
KERNEL_IMAGE="$2" KERNEL_IMAGE="$2"
# Reuse directory created without a machine ID present if it exists.
if [[ -d /efi/Default ]] || [[ -d /boot/Default ]] || [[ -d /boot/efi/Default ]]; then
MACHINE_ID="Default"
elif [[ -f /etc/machine-id ]]; then
read MACHINE_ID < /etc/machine-id
else
MACHINE_ID="Default"
fi
if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
echo "Not enough arguments" >&2 echo "Not enough arguments" >&2
exit 1 exit 1
fi fi
[ -z "$MACHINE_ID" ] && [ -f /etc/machine-id ] && [ "$(stat -fc %T /etc/machine-id)" != "tmpfs" ] && read -r MACHINE_ID < /etc/machine-id
[ -z "$MACHINE_ID" ] && MACHINE_ID="Default"
if [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then if [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
ENTRY_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION" ENTRY_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
elif [[ -d /boot/loader/entries ]] || [[ -d /boot/$MACHINE_ID ]]; then elif [[ -d /boot/loader/entries ]] || [[ -d /boot/$MACHINE_ID ]]; then
@ -107,7 +113,7 @@ else
ENTRY_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION" ENTRY_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
fi fi
export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID" export KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID
ret=0 ret=0

View File

@ -217,13 +217,15 @@ JournalFile* journal_file_close(JournalFile *f) {
if (!f) if (!f)
return NULL; return NULL;
if (f->cache_fd) if (f->mmap && f->cache_fd)
mmap_cache_fd_free(f->cache_fd); mmap_cache_fd_free(f->cache_fd);
if (f->close_fd) if (f->close_fd)
safe_close(f->fd); safe_close(f->fd);
free(f->path); free(f->path);
mmap_cache_unref(f->mmap);
ordered_hashmap_free_free(f->chain_cache); ordered_hashmap_free_free(f->chain_cache);
#if HAVE_COMPRESSION #if HAVE_COMPRESSION
@ -3256,7 +3258,6 @@ int journal_file_open(
assert(ret); assert(ret);
assert(fd >= 0 || fname); assert(fd >= 0 || fname);
assert(mmap_cache);
if (!IN_SET((flags & O_ACCMODE), O_RDONLY, O_RDWR)) if (!IN_SET((flags & O_ACCMODE), O_RDONLY, O_RDWR))
return -EINVAL; return -EINVAL;
@ -3319,6 +3320,16 @@ int journal_file_open(
} }
} }
if (mmap_cache)
f->mmap = mmap_cache_ref(mmap_cache);
else {
f->mmap = mmap_cache_new();
if (!f->mmap) {
r = -ENOMEM;
goto fail;
}
}
if (fname) { if (fname) {
f->path = strdup(fname); f->path = strdup(fname);
if (!f->path) { if (!f->path) {
@ -3360,7 +3371,7 @@ int journal_file_open(
goto fail; goto fail;
} }
f->cache_fd = mmap_cache_add_fd(mmap_cache, f->fd, prot_from_flags(flags)); f->cache_fd = mmap_cache_add_fd(f->mmap, f->fd, prot_from_flags(flags));
if (!f->cache_fd) { if (!f->cache_fd) {
r = -ENOMEM; r = -ENOMEM;
goto fail; goto fail;

View File

@ -92,6 +92,7 @@ typedef struct JournalFile {
uint64_t current_xor_hash; uint64_t current_xor_hash;
JournalMetrics metrics; JournalMetrics metrics;
MMapCache *mmap;
sd_event_source *post_change_timer; sd_event_source *post_change_timer;
usec_t post_change_timer_period; usec_t post_change_timer_period;
@ -231,7 +232,6 @@ void journal_file_dump(JournalFile *f);
void journal_file_print_header(JournalFile *f); void journal_file_print_header(JournalFile *f);
int journal_file_archive(JournalFile *f, char **ret_previous_path); int journal_file_archive(JournalFile *f, char **ret_previous_path);
JournalFile* journal_initiate_close(JournalFile *f, Set *deferred_closes);
int journal_file_dispose(int dir_fd, const char *fname); int journal_file_dispose(int dir_fd, const char *fname);

View File

@ -885,7 +885,6 @@ int journal_file_verify(
unsigned i; unsigned i;
bool found_last = false; bool found_last = false;
const char *tmp_dir = NULL; const char *tmp_dir = NULL;
MMapCache *m;
#if HAVE_GCRYPT #if HAVE_GCRYPT
uint64_t last_tag = 0; uint64_t last_tag = 0;
@ -930,20 +929,19 @@ int journal_file_verify(
goto fail; goto fail;
} }
m = mmap_cache_fd_cache(f->cache_fd); cache_data_fd = mmap_cache_add_fd(f->mmap, data_fd, PROT_READ|PROT_WRITE);
cache_data_fd = mmap_cache_add_fd(m, data_fd, PROT_READ|PROT_WRITE);
if (!cache_data_fd) { if (!cache_data_fd) {
r = log_oom(); r = log_oom();
goto fail; goto fail;
} }
cache_entry_fd = mmap_cache_add_fd(m, entry_fd, PROT_READ|PROT_WRITE); cache_entry_fd = mmap_cache_add_fd(f->mmap, entry_fd, PROT_READ|PROT_WRITE);
if (!cache_entry_fd) { if (!cache_entry_fd) {
r = log_oom(); r = log_oom();
goto fail; goto fail;
} }
cache_entry_array_fd = mmap_cache_add_fd(m, entry_array_fd, PROT_READ|PROT_WRITE); cache_entry_array_fd = mmap_cache_add_fd(f->mmap, entry_array_fd, PROT_READ|PROT_WRITE);
if (!cache_entry_array_fd) { if (!cache_entry_array_fd) {
r = log_oom(); r = log_oom();
goto fail; goto fail;

View File

@ -560,14 +560,14 @@ MMapFileDescriptor* mmap_cache_add_fd(MMapCache *m, int fd, int prot) {
if (!f) if (!f)
return NULL; return NULL;
f->cache = m;
f->fd = fd;
f->prot = prot;
r = hashmap_put(m->fds, FD_TO_PTR(fd), f); r = hashmap_put(m->fds, FD_TO_PTR(fd), f);
if (r < 0) if (r < 0)
return mfree(f); return mfree(f);
f->cache = mmap_cache_ref(m);
f->fd = fd;
f->prot = prot;
return f; return f;
} }
@ -584,16 +584,8 @@ void mmap_cache_fd_free(MMapFileDescriptor *f) {
while (f->windows) while (f->windows)
window_free(f->windows); window_free(f->windows);
if (f->cache) { if (f->cache)
assert_se(hashmap_remove(f->cache->fds, FD_TO_PTR(f->fd))); assert_se(hashmap_remove(f->cache->fds, FD_TO_PTR(f->fd)));
f->cache = mmap_cache_unref(f->cache);
}
free(f); free(f);
} }
MMapCache* mmap_cache_fd_cache(MMapFileDescriptor *f) {
assert(f);
return f->cache;
}

View File

@ -13,7 +13,6 @@ typedef struct MMapFileDescriptor MMapFileDescriptor;
MMapCache* mmap_cache_new(void); MMapCache* mmap_cache_new(void);
MMapCache* mmap_cache_ref(MMapCache *m); MMapCache* mmap_cache_ref(MMapCache *m);
MMapCache* mmap_cache_unref(MMapCache *m); MMapCache* mmap_cache_unref(MMapCache *m);
DEFINE_TRIVIAL_CLEANUP_FUNC(MMapCache*, mmap_cache_unref);
int mmap_cache_fd_get( int mmap_cache_fd_get(
MMapFileDescriptor *f, MMapFileDescriptor *f,
@ -24,7 +23,6 @@ int mmap_cache_fd_get(
struct stat *st, struct stat *st,
void **ret); void **ret);
MMapFileDescriptor * mmap_cache_add_fd(MMapCache *m, int fd, int prot); MMapFileDescriptor * mmap_cache_add_fd(MMapCache *m, int fd, int prot);
MMapCache* mmap_cache_fd_cache(MMapFileDescriptor *f);
void mmap_cache_fd_free(MMapFileDescriptor *f); void mmap_cache_fd_free(MMapFileDescriptor *f);
void mmap_cache_stats_log_debug(MMapCache *m); void mmap_cache_stats_log_debug(MMapCache *m);

View File

@ -681,7 +681,6 @@ static int link_create_stacked_netdev_handler(sd_netlink *rtnl, sd_netlink_messa
if (link->create_stacked_netdev_messages == 0) { if (link->create_stacked_netdev_messages == 0) {
link->stacked_netdevs_created = true; link->stacked_netdevs_created = true;
log_link_debug(link, "Stacked netdevs created."); log_link_debug(link, "Stacked netdevs created.");
link_check_ready(link);
} }
return 0; return 0;

View File

@ -591,10 +591,8 @@ static int link_request_stacked_netdevs(Link *link) {
return r; return r;
} }
if (link->create_stacked_netdev_messages == 0) { if (link->create_stacked_netdev_messages == 0)
link->stacked_netdevs_created = true; link->stacked_netdevs_created = true;
link_check_ready(link);
}
if (link->create_stacked_netdev_after_configured_messages == 0) if (link->create_stacked_netdev_after_configured_messages == 0)
link->stacked_netdevs_after_configured_created = true; link->stacked_netdevs_after_configured_created = true;