From 8135b18c7636b46dc36ca370c2a858130e6cb3be Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Mon, 14 Aug 2017 20:59:15 -0700 Subject: [PATCH] scoutfs: start truncate from first block Truncation updates extents that intersect with the input range. It starts with the first block in the range and iterates until it has searched for all the extents that could cover the range. Extents are stored in items at their final block location so that we can use _next to find intersections. Truncation was searching for the next extent after the full extent that it was still searching for. That means it was starting the search at the last block in the extent, not the first. It would miss all the extents that didn't overlap with the last block it was searching for. This fixed by searching from a temporary single block extent at the start of the search range. Signed-off-by: Zach Brown --- kmod/src/data.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kmod/src/data.c b/kmod/src/data.c index dad28b6c..661cff5b 100644 --- a/kmod/src/data.c +++ b/kmod/src/data.c @@ -530,6 +530,7 @@ int scoutfs_data_truncate_items(struct super_block *sb, u64 ino, u64 iblock, struct scoutfs_key_buf last; struct scoutfs_key_buf key; struct native_extent found; + struct native_extent first; struct native_extent rng; struct native_extent ext; struct native_extent ofl; @@ -554,7 +555,9 @@ int scoutfs_data_truncate_items(struct super_block *sb, u64 ino, u64 iblock, while (rng.blocks) { /* find the next extent that could include our first block */ - init_extent_key(&key, key_bytes, &rng, ino, + first = rng; + first.blocks = 1; + init_extent_key(&key, key_bytes, &first, ino, SCOUTFS_FILE_EXTENT_TYPE); ret = scoutfs_item_next_same(sb, &key, &last, NULL, NULL);