Btrfs: remove BUG_ON()'s in btrfs_map_block
PATCH 1/1 Btrfs: remove BUG_ON()'s in btrfs_map_block
btrfs_map_block can go horribly wrong in the face of fs corruption, lets agree to not be assholes and panic at any possible chance things are all fucked up.
--- fs/btrfs/volumes.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +20 -2
@@ -5278,7 +5278,18 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, stripe_nr =div64_u64 (stripe_nr, stripe_len); stripe_offset = stripe_nr * stripe_len; -BUG_ON (offset < stripe_offset); +if (offset < stripe_offset) { +btrfs_crit (fs_info,"stripe math has gone wrong, " +"stripe_offset=%llu, offset=%llu, start=%llu, " +"logical=%llu, stripe_len=%llu\n" , + (unsigned long long )stripe_offset, + (unsigned long long )offset, + (unsigned long long )em->start, + (unsigned long long )logical, + (unsigned long long )stripe_len); +free_extent_map (em); +return -EINVAL ; + }/* stripe_offset is the offset of this block in its stripe*/ stripe_offset = offset - stripe_offset;
@@ -5519,7 +5530,14 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, &stripe_index); mirror_num = stripe_index +1 ; } -BUG_ON (stripe_index >= map->num_stripes); +if (stripe_index >= map->num_stripes) { +btrfs_crit (fs_info,"stripe index math went horribly wrong, " +"got stripe_index=%lu, num_stripes=%lu\n" , + (unsigned long )stripe_index, + (unsigned long )map->num_stripes); + ret = -EINVAL ; + goto out; + } num_alloc_stripes = num_stripes;if (dev_replace_is_ongoing) {
Signature · 6 lines
2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-
Quoted 13 lines · Josef Bacik
btrfs_map_blockcan go horribly wrong in the face of fs corruption, lets agree to not be assholes and panic at any possible chance things are all fucked up.Signed-off-by Josef Bacik <[email protected]>--- fs/btrfs/volumes.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)fs/btrfs/volumes.c +0
-0
fs/btrfs/volumes.c static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, · line 5286
Quoted 10 lines
fs/btrfs/volumes.c +4
-1@@ -5278,7 +5278,18 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, stripe_nr =div64_u64 (stripe_nr, stripe_len); stripe_offset = stripe_nr * stripe_len; -BUG_ON (offset < stripe_offset); +if (offset < stripe_offset) { + btrfs_crit(fs_info, "stripe math has gone wrong, " + "stripe_offset=%llu, offset=%llu, start=%llu, " + "logical=%llu, stripe_len=%llu\n",
btrfs_crit adds \n suffix by its own.
Quoted 12 lines
fs/btrfs/volumes.c +8
-0+ (unsigned long long )stripe_offset, + (unsigned long long )offset, + (unsigned long long )em->start, + (unsigned long long )logical, + (unsigned long long)stripe_len); +free_extent_map (em); +return -EINVAL ; + }/*
stripe_offsetis the offset of this block in its stripe*/stripe_offset= offset -stripe_offset;
fs/btrfs/volumes.c static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, · line 5536
Quoted 8 lines
fs/btrfs/volumes.c +3
-1@@ -5519,7 +5530,14 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, &stripe_index); mirror_num = stripe_index +1 ; } -BUG_ON (stripe_index >= map->num_stripes); +if (stripe_index >= map->num_stripes) { + btrfs_crit(fs_info, "stripe index math went horribly wrong, " + "got stripe_index=%lu, num_stripes=%lu\n",
-same-
Thanks, Anand
Quoted 9 lines
fs/btrfs/volumes.c +5
-0+ (unsigned long )stripe_index, + (unsigned long)map->num_stripes); + ret = -EINVAL ; + goto out; + } num_alloc_stripes = num_stripes;if (dev_replace_is_ongoing) {
Quoted 9 lines · Anand Jain
fs/btrfs/volumes.c static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
Quoted 7 lines
fs/btrfs/volumes.c +4
-1-BUG_ON (offset < stripe_offset); +if (offset < stripe_offset) { + btrfs_crit(fs_info, "stripe math has gone wrong, " + "stripe_offset=%llu, offset=%llu, start=%llu, " + "logical=%llu, stripe_len=%llu\n",
btrfs_critadds \n suffix by its own.
Right,
Quoted 6 lines
fs/btrfs/volumes.c static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, · line 5289
Quoted 6 lines
fs/btrfs/volumes.c +5
-0+ (unsigned long long )stripe_offset, + (unsigned long long )offset, + (unsigned long long )em->start, + (unsigned long long )logical, + (unsigned long long)stripe_len);
and we don't have to cast u64 to ULL anymore.
Quoted 14 lines
Quoted 13 lines
fs/btrfs/volumes.c +5
-1+free_extent_map (em); +return -EINVAL ; + }/* stripe_offset is the offset of this block in its stripe*/ stripe_offset = offset - stripe_offset;@@ -5519,7 +5530,14 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, &stripe_index); mirror_num = stripe_index +1 ; } -BUG_ON (stripe_index >= map->num_stripes); +if (stripe_index >= map->num_stripes) { + btrfs_crit(fs_info, "stripe index math went horribly wrong, "
Quoted 8 lines
fs/btrfs/volumes.c static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, · line 5535
Quoted 1 line
fs/btrfs/volumes.c +1
-0+ "got stripe_index=%lu, num_stripes=%lu\n",-same-
Thanks, Anand
fs/btrfs/volumes.c static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, · line 5537
Quoted 2 lines
fs/btrfs/volumes.c +2
-0+ (unsigned long )stripe_index, + (unsigned long)map->num_stripes);
typecasts dropped and format string updated.
Fixed and added to for-next.