]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal-remote/journal-remote-write.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Zbigniew Jędrzejewski-Szmek
6 #include "alloc-util.h"
7 #include "journal-remote.h"
9 static int do_rotate(JournalFile
**f
, bool compress
, bool seal
) {
10 int r
= journal_file_rotate(f
, compress
, (uint64_t) -1, seal
, NULL
);
13 log_error_errno(r
, "Failed to rotate %s: %m", (*f
)->path
);
15 log_error_errno(r
, "Failed to create rotated journal: %m");
21 Writer
* writer_new(RemoteServer
*server
) {
28 memset(&w
->metrics
, 0xFF, sizeof(w
->metrics
));
30 w
->mmap
= mmap_cache_new();
40 Writer
* writer_free(Writer
*w
) {
45 log_debug("Closing journal file %s.", w
->journal
->path
);
46 journal_file_close(w
->journal
);
49 if (w
->server
&& w
->hashmap_key
)
50 hashmap_remove(w
->server
->writers
, w
->hashmap_key
);
55 mmap_cache_unref(w
->mmap
);
60 Writer
* writer_unref(Writer
*w
) {
61 if (w
&& (-- w
->n_ref
<= 0))
67 Writer
* writer_ref(Writer
*w
) {
69 assert_se(++ w
->n_ref
>= 2);
74 int writer_write(Writer
*w
,
75 struct iovec_wrapper
*iovw
,
83 assert(iovw
->count
> 0);
85 if (journal_file_rotate_suggested(w
->journal
, 0)) {
86 log_info("%s: Journal header limits reached or header out-of-date, rotating",
88 r
= do_rotate(&w
->journal
, compress
, seal
);
93 r
= journal_file_append_entry(w
->journal
, ts
, NULL
,
94 iovw
->iovec
, iovw
->count
,
95 &w
->seqnum
, NULL
, NULL
);
98 w
->server
->event_count
+= 1;
100 } else if (r
== -EBADMSG
)
103 log_debug_errno(r
, "%s: Write failed, rotating: %m", w
->journal
->path
);
104 r
= do_rotate(&w
->journal
, compress
, seal
);
108 log_debug("%s: Successfully rotated journal", w
->journal
->path
);
110 log_debug("Retrying write.");
111 r
= journal_file_append_entry(w
->journal
, ts
, NULL
,
112 iovw
->iovec
, iovw
->count
,
113 &w
->seqnum
, NULL
, NULL
);
118 w
->server
->event_count
+= 1;