From 0280971faba00c5590f9e49a4c950a9131015786 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 6 Jun 2017 15:45:15 -0700 Subject: [PATCH] scoutfs: add bug on for out of order seg items We've seen some cases where compaction writes a new segment that contains items that aren't sorted. This eventually leads to read being mislead in its binary search of the items in a segment and failing to find the items it was looking for. Signed-off-by: Zach Brown --- kmod/src/seg.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kmod/src/seg.c b/kmod/src/seg.c index 767bab2e..1441d152 100644 --- a/kmod/src/seg.c +++ b/kmod/src/seg.c @@ -565,6 +565,16 @@ void scoutfs_seg_append_item(struct super_block *sb, pos = le32_to_cpu(sblk->nr_items); sblk->nr_items = cpu_to_le32(pos + 1); + /* + * It's very bad data corruption if we write out of order items + * to a segment. It'll mislead the key search during read and + * stop it from finding its items. + */ + if (pos) { + scoutfs_seg_item_ptrs(seg, pos - 1, &item_key, NULL, NULL); + BUG_ON(scoutfs_key_compare(key, &item_key) <= 0); + } + prev = pos_ptr(seg, pos - 1); item = pos_ptr(seg, pos);