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