Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libsystemd/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ libsystemd_tests += [
'sources' : files('sd-journal/test-journal-append.c'),
'type' : 'manual',
},
{
'sources' : files('sd-journal/test-journal-dump.c'),
'type' : 'manual',
},
{
'sources' : files('sd-journal/test-journal-verify.c'),
'timeout' : 90,
Expand Down
27 changes: 13 additions & 14 deletions src/libsystemd/sd-journal/journal-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
#include "user-util.h"
#include "xattr-util.h"

#define DEFAULT_DATA_HASH_TABLE_SIZE (2047ULL*sizeof(HashItem))
#define DEFAULT_FIELD_HASH_TABLE_SIZE (333ULL*sizeof(HashItem))
#define DEFAULT_DATA_HASH_TABLE_SIZE 2047U
#define DEFAULT_FIELD_HASH_TABLE_SIZE 1023U

#define DEFAULT_COMPRESS_THRESHOLD (512ULL)
#define MIN_COMPRESS_THRESHOLD (8ULL)
#define DEFAULT_COMPRESS_THRESHOLD 512U
#define MIN_COMPRESS_THRESHOLD 8U

/* This is the minimum journal file size */
#define JOURNAL_FILE_SIZE_MIN (512 * U64_KB) /* 512 KiB */
Expand Down Expand Up @@ -1281,23 +1281,22 @@ static int journal_file_setup_data_hash_table(JournalFile *f) {
beyond 75% fill level. Calculate the hash table size for
the maximum file size based on these metrics. */

s = (f->metrics.max_size * 4 / 768 / 3) * sizeof(HashItem);
if (s < DEFAULT_DATA_HASH_TABLE_SIZE)
s = DEFAULT_DATA_HASH_TABLE_SIZE;
s = MAX(f->metrics.max_size * 4 / 768 / 3,
DEFAULT_DATA_HASH_TABLE_SIZE);

log_debug("Reserving %"PRIu64" entries in data hash table.", s / sizeof(HashItem));
log_debug("Reserving %"PRIu64" entries in data hash table.", s);

r = journal_file_append_object(f,
OBJECT_DATA_HASH_TABLE,
offsetof(Object, hash_table.items) + s,
offsetof(Object, hash_table.items) + s * sizeof(HashItem),
&o, &p);
if (r < 0)
return r;

memzero(o->hash_table.items, s);

f->header->data_hash_table_offset = htole64(p + offsetof(Object, hash_table.items));
f->header->data_hash_table_size = htole64(s);
f->header->data_hash_table_size = htole64(s * sizeof(HashItem));

return 0;
}
Expand All @@ -1314,19 +1313,19 @@ static int journal_file_setup_field_hash_table(JournalFile *f) {
* number should grow very slowly only */

s = DEFAULT_FIELD_HASH_TABLE_SIZE;
log_debug("Reserving %"PRIu64" entries in field hash table.", s / sizeof(HashItem));
log_debug("Reserving %"PRIu64" entries in field hash table.", s);

r = journal_file_append_object(f,
OBJECT_FIELD_HASH_TABLE,
offsetof(Object, hash_table.items) + s,
offsetof(Object, hash_table.items) + s * sizeof(HashItem),
&o, &p);
if (r < 0)
return r;

memzero(o->hash_table.items, s);
memzero(o->hash_table.items, s * sizeof(HashItem));

f->header->field_hash_table_offset = htole64(p + offsetof(Object, hash_table.items));
f->header->field_hash_table_size = htole64(s);
f->header->field_hash_table_size = htole64(s * sizeof(HashItem));

return 0;
}
Expand Down
46 changes: 46 additions & 0 deletions src/libsystemd/sd-journal/test-journal-dump.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */

#include "errno-util.h"
#include "journal-file.h"
#include "log.h"
#include "main-func.h"
#include "pager.h"
#include "strv.h"

static int run(int argc, char *argv[]) {
int r = 0;
unsigned n = 0;

_cleanup_(mmap_cache_unrefp) MMapCache *m = mmap_cache_new();
assert_se(m);

pager_open(/* flags= */ 0);

STRV_FOREACH(s, strv_skip(argv, 1)) {
JournalFile *f = NULL;

int k = journal_file_open(
/* fd= */ -EBADF,
*s,
O_RDONLY,
/* file_flags= */ 0,
0666,
/* compress_threshold_bytes= */ UINT64_MAX,
/* metrics= */ NULL,
m,
/* template= */ NULL,
&f);
if (k < 0)
RET_GATHER(r, log_error_errno(k, "Failed to open %s, continuing: %m", *s));

if (n++ > 0)
puts("");

journal_file_print_header(f);
journal_file_close(f);
}

return r;
}

DEFINE_MAIN_FUNCTION(run);
Loading