* [PATCH 2/3] btrfs-progs: fix lowmem check's handling of holes
2020-02-04 14:32 [PATCH 0/3][v2] Fix btrfs check handling of missing file extents Josef Bacik
2020-02-04 14:32 ` [PATCH 1/3] btrfs-progs: fix check to catch gaps at the start of the file Josef Bacik
@ 2020-02-04 14:32 ` Josef Bacik
2020-02-04 14:32 ` [PATCH 3/3] btrfs-progs: fix hole error output in fsck Josef Bacik
2 siblings, 0 replies; 4+ messages in thread
From: Josef Bacik @ 2020-02-04 14:32 UTC (permalink / raw)
To: kernel-team, linux-btrfs
Lowmem check had the opposite problem of normal check, it caught gaps
that started at 0, but would still fail with my fixes in place. This is
because lowmem check doesn't take into account the isize of the inode.
Address this by making sure we do not complain about gaps that are after
isize. This makes lowmem pass with my fixes applied, and still fail
without my fixes.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
check/mode-lowmem.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 2f76d634..fd503aa6 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -2029,7 +2029,8 @@ static int check_file_extent_inline(struct btrfs_root *root,
* Return 0 if no error occurred.
*/
static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
- unsigned int nodatasum, u64 *size, u64 *end)
+ unsigned int nodatasum, u64 isize, u64 *size,
+ u64 *end)
{
struct btrfs_file_extent_item *fi;
struct btrfs_key fkey;
@@ -2152,7 +2153,7 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
}
/* Check EXTENT_DATA hole */
- if (!no_holes && *end != fkey.offset) {
+ if (!no_holes && (fkey.offset < isize) && (*end != fkey.offset)) {
if (repair)
ret = punch_extent_hole(root, path, fkey.objectid,
*end, fkey.offset - *end);
@@ -2165,7 +2166,8 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
}
}
- *end = fkey.offset + extent_num_bytes;
+ if (fkey.offset + extent_num_bytes < isize)
+ *end = fkey.offset + extent_num_bytes;
if (!is_hole)
*size += extent_num_bytes;
@@ -2726,7 +2728,7 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path)
root->objectid, inode_id, key.objectid,
key.offset);
}
- ret = check_file_extent(root, path, nodatasum,
+ ret = check_file_extent(root, path, nodatasum, isize,
&extent_size, &extent_end);
err |= ret;
break;
--
2.24.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 3/3] btrfs-progs: fix hole error output in fsck
2020-02-04 14:32 [PATCH 0/3][v2] Fix btrfs check handling of missing file extents Josef Bacik
2020-02-04 14:32 ` [PATCH 1/3] btrfs-progs: fix check to catch gaps at the start of the file Josef Bacik
2020-02-04 14:32 ` [PATCH 2/3] btrfs-progs: fix lowmem check's handling of holes Josef Bacik
@ 2020-02-04 14:32 ` Josef Bacik
2 siblings, 0 replies; 4+ messages in thread
From: Josef Bacik @ 2020-02-04 14:32 UTC (permalink / raw)
To: kernel-team, linux-btrfs
If we don't find holes in our hole rb tree we'll just assume there's a
gap from 0 to the length of the file and print that out. But this
simply isn't correct, we could have a gap between the last extent and
the isize, or 0 and the start of the first extent. Fix the error
message to tell us exactly where the hole is.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
check/main.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/check/main.c b/check/main.c
index 22f4e24c..71b68ff9 100644
--- a/check/main.c
+++ b/check/main.c
@@ -639,10 +639,20 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)
hole->start, hole->len);
node = rb_next(node);
}
- if (!found)
- fprintf(stderr, "\tstart: 0, len: %llu\n",
- round_up(rec->isize,
- root->fs_info->sectorsize));
+ if (!found) {
+ u64 start, len;
+ if (rec->extent_end < rec->isize) {
+ start = rec->extent_end;
+ len = round_up(rec->isize,
+ root->fs_info->sectorsize) -
+ start;
+ } else {
+ start = 0;
+ len = rec->extent_start;
+ }
+ fprintf(stderr, "\tstart: %llu, len: %llu\n", start,
+ len);
+ }
}
/* Print dir item with mismatch hash */
--
2.24.1
^ permalink raw reply related [flat|nested] 4+ messages in thread