1 Star 0 Fork 98

Mingtai/systemd_1

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-journal-Deduplicate-entry-items-before-they-are-stor.patch 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
From 71976e91c5a887585b9fb8a162116824b141eecf Mon Sep 17 00:00:00 2001
From: Daan De Meyer <daan.j.demeyer@gmail.com>
Date: Fri, 12 Nov 2021 14:32:40 +0000
Subject: [PATCH] journal: Deduplicate entry items before they are stored in
the entry object
If the iovec contains the same data more than once, we'll end up with
duplicate offsets in the items array. Let's make sure we remove any
duplicates before we store the items in an entry object.
(cherry picked from commit 5ec9fbae64bef896368f744a875dd0437a4c42f2)
Conflict:NA
Reference:https://github.com/systemd/systemd/commit/71976e91c5a887585b9fb8a162116824b141eecf
---
src/libsystemd/sd-journal/journal-file.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c
index ae19c1c1f2..a8029c2868 100644
--- a/src/libsystemd/sd-journal/journal-file.c
+++ b/src/libsystemd/sd-journal/journal-file.c
@@ -2082,6 +2082,21 @@ static int entry_item_cmp(const EntryItem *a, const EntryItem *b) {
return CMP(le64toh(a->object_offset), le64toh(b->object_offset));
}
+static size_t remove_duplicate_entry_items(EntryItem items[], size_t n) {
+
+ /* This function relies on the items array being sorted. */
+ size_t j = 1;
+
+ if (n <= 1)
+ return n;
+
+ for (size_t i = 1; i < n; i++)
+ if (items[i].object_offset != items[j - 1].object_offset)
+ items[j++] = items[i];
+
+ return j;
+}
+
int journal_file_append_entry(
JournalFile *f,
const dual_timestamp *ts,
@@ -2151,6 +2166,7 @@ int journal_file_append_entry(
/* Order by the position on disk, in order to improve seek
* times for rotating media. */
typesafe_qsort(items, n_iovec, entry_item_cmp);
+ n_iovec = remove_duplicate_entry_items(items, n_iovec);
r = journal_file_append_entry_internal(f, ts, boot_id, xor_hash, items, n_iovec, seqnum, ret, ret_offset);
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangmingtaip/systemd_1.git
git@gitee.com:yangmingtaip/systemd_1.git
yangmingtaip
systemd_1
systemd_1
master

搜索帮助