Skip to content

Commit

Permalink
journal-vacuum: count size of all journal files
Browse files Browse the repository at this point in the history
Currently, active journal files are excluded, which means that vacuuming
may not remove anything even if *MaxUse= has been exceeded.

(cherry picked from commit 9ea46af4f2368b41d57705bac09774778126507f)

Resolves: #2180380
  • Loading branch information
dtardon authored and systemd-rhel-bot committed Jun 14, 2023
1 parent 3590a9c commit 947296a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/journal/journal-vacuum.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ int journal_directory_vacuum(
if (!S_ISREG(st.st_mode))
continue;

size = 512UL * (uint64_t) st.st_blocks;

q = strlen(de->d_name);

if (endswith(de->d_name, ".journal")) {
Expand All @@ -188,13 +190,15 @@ int journal_directory_vacuum(

if (q < 1 + 32 + 1 + 16 + 1 + 16 + 8) {
n_active_files++;
sum += size;
continue;
}

if (de->d_name[q-8-16-1] != '-' ||
de->d_name[q-8-16-1-16-1] != '-' ||
de->d_name[q-8-16-1-16-1-32-1] != '@') {
n_active_files++;
sum += size;
continue;
}

Expand All @@ -207,11 +211,13 @@ int journal_directory_vacuum(
de->d_name[q-8-16-1-16-1] = 0;
if (sd_id128_from_string(de->d_name + q-8-16-1-16-1-32, &seqnum_id) < 0) {
n_active_files++;
sum += size;
continue;
}

if (sscanf(de->d_name + q-8-16-1-16, "%16llx-%16llx.journal", &seqnum, &realtime) != 2) {
n_active_files++;
sum += size;
continue;
}

Expand All @@ -224,12 +230,14 @@ int journal_directory_vacuum(

if (q < 1 + 16 + 1 + 16 + 8 + 1) {
n_active_files++;
sum += size;
continue;
}

if (de->d_name[q-1-8-16-1] != '-' ||
de->d_name[q-1-8-16-1-16-1] != '@') {
n_active_files++;
sum += size;
continue;
}

Expand All @@ -241,6 +249,7 @@ int journal_directory_vacuum(

if (sscanf(de->d_name + q-1-8-16-1-16, "%16llx-%16llx.journal~", &realtime, &tmp) != 2) {
n_active_files++;
sum += size;
continue;
}

Expand All @@ -251,8 +260,6 @@ int journal_directory_vacuum(
continue;
}

size = 512UL * (uint64_t) st.st_blocks;

r = journal_file_empty(dirfd(d), p);
if (r < 0) {
log_debug_errno(r, "Failed check if %s is empty, ignoring: %m", p);
Expand Down

0 comments on commit 947296a

Please sign in to comment.