Commit b8632c0e authored by Marek Vavruša's avatar Marek Vavruša

journal: disallow duplicates (invalidates old duplicate entries)

parent 59e8cd6b
......@@ -647,12 +647,13 @@ int journal_map(journal_t *journal, uint64_t id, char **dst, size_t size, bool r
/* Check if entry exists. */
journal_node_t *n = NULL;
int ret = journal_fetch(journal, id, journal_cmp_eq, &n);
if (ret != KNOT_EOK) {
/* Return error if read only. */
if (rdonly) {
/* Return if read-only, invalidate if rewritten to avoid duplicates. */
if (rdonly) {
if (ret != KNOT_EOK) {
return ret;
}
} else {
/* Prepare journal write. */
ret = journal_write_in(journal, &n, id, size);
if (ret != KNOT_EOK) {
......@@ -675,11 +676,6 @@ int journal_map(journal_t *journal, uint64_t id, char **dst, size_t size, bool r
}
size -= wb;
}
} else {
/* Entry resizing is not really supported now. */
if (n->len < size) {
return KNOT_ESPACE;
}
}
/* Align offset to page size (required). */
......@@ -965,6 +961,12 @@ static int journal_walk(const char *fn, uint32_t from, uint32_t to,
}
while (n != 0 && n != journal_end(journal)) {
/* Skip invalid nodes. */
if (!(n->flags & JOURNAL_VALID)) {
++n;
continue;
}
/* Check for history end. */
if (to == found_to) {
break;
......
......@@ -146,9 +146,9 @@ int main(int argc, char *argv[])
}
is_int(KNOT_EOK, ret, "journal: sustained mmap r/w");
/* Overfill */
/* Overfill (yields ESPACE/EBUSY) */
ret = journal_map(journal, chk_key, &mptr, fsize, false);
is_int(KNOT_ESPACE, ret, "journal: overfill");
ok(ret != KNOT_EOK, "journal: overfill");
/* Fillup */
unsigned iterations = 10;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment