add patch find-the-group-descriptors-on-a-1k-bigalloc,meta_bg-fs
[ext4-patch-queue.git] / find-the-group-descriptors-on-a-1k-bigalloc,meta_bg-fs
blobfc4ad064b0813e2e3fb8a006fcccdac444a10794
1 ext4: find the group descriptors on a 1k-block bigalloc,meta_bg filesystem
3 From: "Darrick J. Wong" <darrick.wong@oracle.com>
5 On a filesystem with a 1k block size, the group descriptors live in
6 block 2, not block 1.  If the filesystem has bigalloc,meta_bg set,
7 however, the calculation of the group descriptor table location does
8 not take this into account and returns the wrong block number.  Fix
9 the calculation to return the correct value for this case.
11 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
12 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
13 ---
14  fs/ext4/super.c |   10 ++++++++++
15  1 file changed, 10 insertions(+)
17 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
18 index 7f52a54..d968c64 100644
19 --- a/fs/ext4/super.c
20 +++ b/fs/ext4/super.c
21 @@ -2420,6 +2420,16 @@ static ext4_fsblk_t descriptor_loc(struct super_block *sb,
22         if (ext4_bg_has_super(sb, bg))
23                 has_super = 1;
25 +       /*
26 +        * If we have a meta_bg fs with 1k blocks, group 0's GDT is at
27 +        * block 2, not 1.  If s_first_data_block == 0 (bigalloc is enabled
28 +        * on modern mke2fs or blksize > 1k on older mke2fs) then we must
29 +        * compensate.
30 +        */
31 +       if (sb->s_blocksize == 1024 && nr == 0 &&
32 +           le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) == 0)
33 +               has_super++;
35         return (has_super + ext4_group_first_block_no(sb, bg));
36  }