mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
journal: Stop comparing hash values from entry items against data objects
These checks don't achieve anything of value. Assuming they were added to check for corruption, they don't actually achieve this goal since other parts of the data object can still get corrupted and we wouldn't notice unless we'd recalculate the hash every time. In theory, we could use the entry item hash to avoid a random access lookup for the data object hash in the journal file in the future to speed up searching, but for finding all entry objects containing a specific data objects, we already have entry arrays per data object to get fast access to this information. This means that duplicating the hashes in the entry item doesn't result in any added value. In this commit, we remove the checks so that in future commits we can remove the hashes from the journal file format in the new compact mode.
This commit is contained in:
@@ -3565,21 +3565,16 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
|
||||
|
||||
for (uint64_t i = 0; i < n; i++) {
|
||||
uint64_t l, h;
|
||||
le64_t le_hash;
|
||||
size_t t;
|
||||
void *data;
|
||||
Object *u;
|
||||
|
||||
q = le64toh(o->entry.items[i].object_offset);
|
||||
le_hash = o->entry.items[i].hash;
|
||||
|
||||
r = journal_file_move_to_object(from, OBJECT_DATA, q, &o);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (le_hash != o->data.hash)
|
||||
return -EBADMSG;
|
||||
|
||||
l = le64toh(READ_NOW(o->object.size));
|
||||
if (l < offsetof(Object, data.payload))
|
||||
return -EBADMSG;
|
||||
|
||||
@@ -645,11 +645,10 @@ static int verify_entry(
|
||||
|
||||
n = journal_file_entry_n_items(o);
|
||||
for (i = 0; i < n; i++) {
|
||||
uint64_t q, h;
|
||||
uint64_t q;
|
||||
Object *u;
|
||||
|
||||
q = le64toh(o->entry.items[i].object_offset);
|
||||
h = le64toh(o->entry.items[i].hash);
|
||||
|
||||
if (!contains_uint64(cache_data_fd, n_data, q)) {
|
||||
error(p, "Invalid data object of entry");
|
||||
@@ -660,12 +659,7 @@ static int verify_entry(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (le64toh(u->data.hash) != h) {
|
||||
error(p, "Hash mismatch for data object of entry");
|
||||
return -EBADMSG;
|
||||
}
|
||||
|
||||
r = data_object_in_hash_table(f, h, q);
|
||||
r = data_object_in_hash_table(f, le64toh(u->data.hash), q);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0) {
|
||||
|
||||
@@ -2303,12 +2303,10 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
|
||||
for (i = 0; i < n; i++) {
|
||||
Object *d;
|
||||
uint64_t p, l;
|
||||
le64_t le_hash;
|
||||
size_t t;
|
||||
int compression;
|
||||
|
||||
p = le64toh(o->entry.items[i].object_offset);
|
||||
le_hash = o->entry.items[i].hash;
|
||||
r = journal_file_move_to_object(f, OBJECT_DATA, p, &d);
|
||||
if (IN_SET(r, -EADDRNOTAVAIL, -EBADMSG)) {
|
||||
log_debug_errno(r, "Entry item %"PRIu64" data object is bad, skipping over it: %m", i);
|
||||
@@ -2317,11 +2315,6 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (le_hash != d->data.hash) {
|
||||
log_debug("Entry item %"PRIu64" hash is bad, skipping over it.", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
l = le64toh(d->object.size) - offsetof(Object, data.payload);
|
||||
|
||||
compression = d->object.flags & OBJECT_COMPRESSION_MASK;
|
||||
@@ -2450,10 +2443,8 @@ _public_ int sd_journal_enumerate_data(sd_journal *j, const void **data, size_t
|
||||
|
||||
for (uint64_t n = journal_file_entry_n_items(o); j->current_field < n; j->current_field++) {
|
||||
uint64_t p;
|
||||
le64_t le_hash;
|
||||
|
||||
p = le64toh(o->entry.items[j->current_field].object_offset);
|
||||
le_hash = o->entry.items[j->current_field].hash;
|
||||
r = journal_file_move_to_object(f, OBJECT_DATA, p, &o);
|
||||
if (IN_SET(r, -EADDRNOTAVAIL, -EBADMSG)) {
|
||||
log_debug_errno(r, "Entry item %"PRIu64" data object is bad, skipping over it: %m", j->current_field);
|
||||
@@ -2462,11 +2453,6 @@ _public_ int sd_journal_enumerate_data(sd_journal *j, const void **data, size_t
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (le_hash != o->data.hash) {
|
||||
log_debug("Entry item %"PRIu64" hash is bad, skipping over it.", j->current_field);
|
||||
continue;
|
||||
}
|
||||
|
||||
r = return_data(j, f, o, data, size);
|
||||
if (r == -EBADMSG) {
|
||||
log_debug("Entry item %"PRIu64" data payload is bad, skipping over it.", j->current_field);
|
||||
|
||||
Reference in New Issue
Block a user