]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/journal/journal-internal.h
journal: use IteratedCache in sd-journal
[thirdparty/systemd.git] / src / journal / journal-internal.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
c2f1db8f 2#pragma once
f39e126e
LP
3
4/***
5 This file is part of systemd.
6
7 Copyright 2011 Lennart Poettering
8
9 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
f39e126e
LP
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 17 Lesser General Public License for more details.
f39e126e 18
5430f7f2 19 You should have received a copy of the GNU Lesser General Public License
f39e126e
LP
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21***/
22
f39e126e
LP
23#include <inttypes.h>
24#include <stdbool.h>
71d35b6b 25#include <sys/types.h>
f39e126e 26
07630cea
LP
27#include "sd-id128.h"
28#include "sd-journal.h"
81527be1 29
07630cea 30#include "hashmap.h"
cbdca852 31#include "journal-def.h"
07630cea 32#include "journal-file.h"
f39e126e 33#include "list.h"
6fe391c5 34#include "set.h"
cbdca852 35
f39e126e 36typedef struct Match Match;
a963990f
LP
37typedef struct Location Location;
38typedef struct Directory Directory;
39
cbdca852
LP
40typedef enum MatchType {
41 MATCH_DISCRETE,
42 MATCH_OR_TERM,
43 MATCH_AND_TERM
44} MatchType;
f39e126e
LP
45
46struct Match {
cbdca852
LP
47 MatchType type;
48 Match *parent;
49 LIST_FIELDS(Match, matches);
50
51 /* For concrete matches */
f39e126e
LP
52 char *data;
53 size_t size;
4fd052ae 54 le64_t le_hash;
f39e126e 55
cbdca852
LP
56 /* For terms */
57 LIST_HEAD(Match, matches);
f39e126e
LP
58};
59
a963990f 60struct Location {
cbdca852 61 LocationType type;
f39e126e 62
68667801
ZJS
63 bool seqnum_set;
64 bool realtime_set;
65 bool monotonic_set;
66 bool xor_hash_set;
67
f39e126e
LP
68 uint64_t seqnum;
69 sd_id128_t seqnum_id;
f39e126e
LP
70
71 uint64_t realtime;
f39e126e
LP
72
73 uint64_t monotonic;
74 sd_id128_t boot_id;
f39e126e
LP
75
76 uint64_t xor_hash;
a963990f
LP
77};
78
79struct Directory {
80 char *path;
81 int wd;
82 bool is_root;
83};
f39e126e
LP
84
85struct sd_journal {
5d1ce257
LP
86 int toplevel_fd;
87
7827b1a1 88 char *path;
89739579 89 char *prefix;
7827b1a1 90
c1f906bd 91 OrderedHashmap *files;
5d4ba7f2 92 IteratedCache *files_cache;
16e9f408 93 MMapCache *mmap;
f39e126e
LP
94
95 Location current_location;
cbdca852 96
f39e126e
LP
97 JournalFile *current_file;
98 uint64_t current_field;
99
cd34b3c6 100 Match *level0, *level1, *level2;
a963990f 101
a65f06bb
ZJS
102 pid_t original_pid;
103
104 int inotify_fd;
a963990f 105 unsigned current_invalidate_counter, last_invalidate_counter;
a65f06bb 106 usec_t last_process_usec;
3c1668da 107
eb86030e 108 /* Iterating through unique fields and their data values */
3c1668da
LP
109 char *unique_field;
110 JournalFile *unique_file;
111 uint64_t unique_offset;
85210bff 112
eb86030e
LP
113 /* Iterating through known fields */
114 JournalFile *fields_file;
115 uint64_t fields_offset;
116 uint64_t fields_hash_table_index;
117 char *fields_buffer;
118 size_t fields_buffer_allocated;
119
a65f06bb
ZJS
120 int flags;
121
eb86030e
LP
122 bool on_network:1;
123 bool no_new_files:1;
5d1ce257 124 bool no_inotify:1;
eb86030e
LP
125 bool unique_file_lost:1; /* File we were iterating over got
126 removed, and there were no more
127 files, so sd_j_enumerate_unique
128 will return a value equal to 0. */
129 bool fields_file_lost:1;
39fd5b08
JS
130 bool has_runtime_files:1;
131 bool has_persistent_files:1;
93b73b06
LP
132
133 size_t data_threshold;
6fe391c5 134
a65f06bb
ZJS
135 Hashmap *directories_by_path;
136 Hashmap *directories_by_wd;
39c155ea 137
5768d259 138 Hashmap *errors;
f39e126e
LP
139};
140
cbdca852 141char *journal_make_match_string(sd_journal *j);
dca6219e 142void journal_print_header(sd_journal *j);
dfb33a97 143
a72b6353
ZJS
144#define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval) \
145 for (sd_journal_restart_data(j); ((retval) = sd_journal_enumerate_data((j), &(data), &(l))) > 0; )