Skip to content

Commit 30ca22c

Browse files
ploprestiJoel Becker
authored andcommitted
ext3/ext4: Factor out disk addressability check
As part of adding support for OCFS2 to mount huge volumes, we need to check that the sector_t and page cache of the system are capable of addressing the entire volume. An identical check already appears in ext3 and ext4. This patch moves the addressability check into its own function in fs/libfs.c and modifies ext3 and ext4 to invoke it. [Edited to -EINVAL instead of BUG_ON() for bad blocksize_bits -- Joel] Signed-off-by: Patrick LoPresti <lopresti@gmail.com> Cc: linux-ext4@vger.kernel.org Acked-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Joel Becker <joel.becker@oracle.com>
1 parent 729963a commit 30ca22c

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎fs/ext3/super.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,8 +1849,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
18491849
goto failed_mount;
18501850
}
18511851

1852-
if (le32_to_cpu(es->s_blocks_count) >
1853-
(sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
1852+
if (generic_check_addressable(sb->s_blocksize_bits,
1853+
le32_to_cpu(es->s_blocks_count))) {
18541854
ext3_msg(sb, KERN_ERR,
18551855
"error: filesystem is too large to mount safely");
18561856
if (sizeof(sector_t) < 8)

‎fs/ext4/super.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,15 +2831,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
28312831
* Test whether we have more sectors than will fit in sector_t,
28322832
* and whether the max offset is addressable by the page cache.
28332833
*/
2834-
if ((ext4_blocks_count(es) >
2835-
(sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) ||
2836-
(ext4_blocks_count(es) >
2837-
(pgoff_t)(~0ULL) >> (PAGE_CACHE_SHIFT - sb->s_blocksize_bits))) {
2834+
ret = generic_check_addressable(sb->s_blocksize_bits,
2835+
ext4_blocks_count(es));
2836+
if (ret) {
28382837
ext4_msg(sb, KERN_ERR, "filesystem"
28392838
" too large to mount safely on this system");
28402839
if (sizeof(sector_t) < 8)
28412840
ext4_msg(sb, KERN_WARNING, "CONFIG_LBDAF not enabled");
2842-
ret = -EFBIG;
28432841
goto failed_mount;
28442842
}
28452843

‎fs/libfs.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,35 @@ int generic_file_fsync(struct file *file, int datasync)
913913
}
914914
EXPORT_SYMBOL(generic_file_fsync);
915915

916+
/**
917+
* generic_check_addressable - Check addressability of file system
918+
* @blocksize_bits: log of file system block size
919+
* @num_blocks: number of blocks in file system
920+
*
921+
* Determine whether a file system with @num_blocks blocks (and a
922+
* block size of 2**@blocksize_bits) is addressable by the sector_t
923+
* and page cache of the system. Return 0 if so and -EFBIG otherwise.
924+
*/
925+
int generic_check_addressable(unsigned blocksize_bits, u64 num_blocks)
926+
{
927+
u64 last_fs_block = num_blocks - 1;
928+
929+
if (unlikely(num_blocks == 0))
930+
return 0;
931+
932+
if ((blocksize_bits < 9) || (blocksize_bits > PAGE_CACHE_SHIFT))
933+
return -EINVAL;
934+
935+
if ((last_fs_block >
936+
(sector_t)(~0ULL) >> (blocksize_bits - 9)) ||
937+
(last_fs_block >
938+
(pgoff_t)(~0ULL) >> (PAGE_CACHE_SHIFT - blocksize_bits))) {
939+
return -EFBIG;
940+
}
941+
return 0;
942+
}
943+
EXPORT_SYMBOL(generic_check_addressable);
944+
916945
/*
917946
* No-op implementation of ->fsync for in-memory filesystems.
918947
*/

‎include/linux/fs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,8 @@ extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
23742374

23752375
extern int generic_file_fsync(struct file *, int);
23762376

2377+
extern int generic_check_addressable(unsigned, u64);
2378+
23772379
#ifdef CONFIG_MIGRATION
23782380
extern int buffer_migrate_page(struct address_space *,
23792381
struct page *, struct page *);

0 commit comments

Comments
 (0)