All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: fix off-by-one fsmap error on 1k block filesystems
@ 2017-06-21 18:29 Darrick J. Wong
  2017-06-23  5:01 ` Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Darrick J. Wong @ 2017-06-21 18:29 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-ext4

For 1k-block filesystems, the filesystem starts at block 1, not block 0.
This fact is recorded in s_first_data_block, so use that to bump up the
start_fsb before we start querying the filesystem for its space map.
Without this, ext4/026 fails on 1k block ext4 because various functions
(notably ext4_get_group_no_and_offset) don't know what to do with an
fsblock that is "before" the start of the filesystem and return garbage
results (blockgroup 2^32-1, etc.) that confuse fsmap.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/ext4/fsmap.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c
index b194360..7ec3408 100644
--- a/fs/ext4/fsmap.c
+++ b/fs/ext4/fsmap.c
@@ -480,6 +480,7 @@ static int ext4_getfsmap_datadev(struct super_block *sb,
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	ext4_fsblk_t start_fsb;
 	ext4_fsblk_t end_fsb;
+	ext4_fsblk_t bofs;
 	ext4_fsblk_t eofs;
 	ext4_group_t start_ag;
 	ext4_group_t end_ag;
@@ -487,9 +488,12 @@ static int ext4_getfsmap_datadev(struct super_block *sb,
 	ext4_grpblk_t last_cluster;
 	int error = 0;
 
+	bofs = le32_to_cpu(sbi->s_es->s_first_data_block);
 	eofs = ext4_blocks_count(sbi->s_es);
 	if (keys[0].fmr_physical >= eofs)
 		return 0;
+	else if (keys[0].fmr_physical < bofs)
+		keys[0].fmr_physical = bofs;
 	if (keys[1].fmr_physical >= eofs)
 		keys[1].fmr_physical = eofs - 1;
 	start_fsb = keys[0].fmr_physical;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: fix off-by-one fsmap error on 1k block filesystems
  2017-06-21 18:29 [PATCH] ext4: fix off-by-one fsmap error on 1k block filesystems Darrick J. Wong
@ 2017-06-23  5:01 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2017-06-23  5:01 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-ext4

On Wed, Jun 21, 2017 at 11:29:40AM -0700, Darrick J. Wong wrote:
> For 1k-block filesystems, the filesystem starts at block 1, not block 0.
> This fact is recorded in s_first_data_block, so use that to bump up the
> start_fsb before we start querying the filesystem for its space map.
> Without this, ext4/026 fails on 1k block ext4 because various functions
> (notably ext4_get_group_no_and_offset) don't know what to do with an
> fsblock that is "before" the start of the filesystem and return garbage
> results (blockgroup 2^32-1, etc.) that confuse fsmap.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-06-23  5:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-21 18:29 [PATCH] ext4: fix off-by-one fsmap error on 1k block filesystems Darrick J. Wong
2017-06-23  5:01 ` Theodore Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.