]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journal-internal.h
a649acf634e74d4409da33af209cce716f5a7eaa
[thirdparty/systemd.git] / src / journal / journal-internal.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <inttypes.h>
5 #include <stdbool.h>
6 #include <sys/types.h>
7
8 #include "sd-id128.h"
9 #include "sd-journal.h"
10
11 #include "hashmap.h"
12 #include "journal-def.h"
13 #include "journal-file.h"
14 #include "list.h"
15 #include "set.h"
16
17 typedef struct Match Match;
18 typedef struct Location Location;
19 typedef struct Directory Directory;
20
21 typedef enum MatchType {
22 MATCH_DISCRETE,
23 MATCH_OR_TERM,
24 MATCH_AND_TERM
25 } MatchType;
26
27 struct Match {
28 MatchType type;
29 Match *parent;
30 LIST_FIELDS(Match, matches);
31
32 /* For concrete matches */
33 char *data;
34 size_t size;
35 uint64_t hash; /* old-style jenkins hash. New-style siphash is different per file, hence won't be cached here */
36
37 /* For terms */
38 LIST_HEAD(Match, matches);
39 };
40
41 struct Location {
42 LocationType type;
43
44 bool seqnum_set:1;
45 bool realtime_set:1;
46 bool monotonic_set:1;
47 bool xor_hash_set:1;
48
49 uint64_t seqnum;
50 sd_id128_t seqnum_id;
51
52 uint64_t realtime;
53
54 uint64_t monotonic;
55 sd_id128_t boot_id;
56
57 uint64_t xor_hash;
58 };
59
60 struct Directory {
61 char *path;
62 int wd;
63 bool is_root;
64 unsigned last_seen_generation;
65 };
66
67 struct sd_journal {
68 int toplevel_fd;
69
70 char *path;
71 char *prefix;
72 char *namespace;
73
74 OrderedHashmap *files;
75 IteratedCache *files_cache;
76 MMapCache *mmap;
77
78 Location current_location;
79
80 JournalFile *current_file;
81 uint64_t current_field;
82
83 Match *level0, *level1, *level2;
84
85 pid_t original_pid;
86
87 int inotify_fd;
88 unsigned current_invalidate_counter, last_invalidate_counter;
89 usec_t last_process_usec;
90 unsigned generation;
91
92 /* Iterating through unique fields and their data values */
93 char *unique_field;
94 JournalFile *unique_file;
95 uint64_t unique_offset;
96
97 /* Iterating through known fields */
98 JournalFile *fields_file;
99 uint64_t fields_offset;
100 uint64_t fields_hash_table_index;
101 char *fields_buffer;
102 size_t fields_buffer_allocated;
103
104 int flags;
105
106 bool on_network:1;
107 bool no_new_files:1;
108 bool no_inotify:1;
109 bool unique_file_lost:1; /* File we were iterating over got
110 removed, and there were no more
111 files, so sd_j_enumerate_unique
112 will return a value equal to 0. */
113 bool fields_file_lost:1;
114 bool has_runtime_files:1;
115 bool has_persistent_files:1;
116
117 size_t data_threshold;
118
119 Hashmap *directories_by_path;
120 Hashmap *directories_by_wd;
121
122 Hashmap *errors;
123 };
124
125 char *journal_make_match_string(sd_journal *j);
126 void journal_print_header(sd_journal *j);
127
128 #define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval) \
129 for (sd_journal_restart_data(j); ((retval) = sd_journal_enumerate_data((j), &(data), &(l))) > 0; )