1 ext4: create EXT4_MAX_BLOCKS() macro
3 From: Fabian Frederick <fabf@skynet.be>
5 Create a macro to calculate length + offset -> maximum blocks
6 This adds more readability.
8 Signed-off-by: Fabian Frederick <fabf@skynet.be>
9 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 fs/ext4/ext4.h | 3 +++
12 fs/ext4/extents.c | 15 +++------------
13 fs/ext4/file.c | 3 +--
14 3 files changed, 7 insertions(+), 14 deletions(-)
16 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
17 index ea31931..6e98f3f 100644
20 @@ -262,6 +262,9 @@ struct ext4_io_submit {
23 #define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits)))
24 +#define EXT4_MAX_BLOCKS(size, offset, blkbits) \
25 + ((EXT4_BLOCK_ALIGN(size + offset, blkbits) >> blkbits) - (offset >> \
28 /* Translate a block number to a cluster number */
29 #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits)
30 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
31 index 4f1cca8..ac54907 100644
32 --- a/fs/ext4/extents.c
33 +++ b/fs/ext4/extents.c
34 @@ -4960,13 +4960,8 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
36 trace_ext4_fallocate_enter(inode, offset, len, mode);
37 lblk = offset >> blkbits;
39 - * We can't just convert len to max_blocks because
40 - * If blocksize = 4096 offset = 3072 and len = 2048
42 - max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits)
45 + max_blocks = EXT4_MAX_BLOCKS(len, offset, blkbits);
46 flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT;
47 if (mode & FALLOC_FL_KEEP_SIZE)
48 flags |= EXT4_GET_BLOCKS_KEEP_SIZE;
49 @@ -5029,12 +5024,8 @@ int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
50 unsigned int credits, blkbits = inode->i_blkbits;
52 map.m_lblk = offset >> blkbits;
54 - * We can't just convert len to max_blocks because
55 - * If blocksize = 4096 offset = 3072 and len = 2048
57 - max_blocks = ((EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) -
59 + max_blocks = EXT4_MAX_BLOCKS(len, offset, blkbits);
62 * This is somewhat ugly but the idea is clear: When transaction is
63 * reserved, everything goes into it. Otherwise we rather start several
64 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
65 index 261ac37..34acda7 100644
68 @@ -144,8 +144,7 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
71 map.m_lblk = pos >> blkbits;
72 - map.m_len = (EXT4_BLOCK_ALIGN(pos + length, blkbits) >> blkbits)
74 + map.m_len = EXT4_MAX_BLOCKS(length, pos, blkbits);
77 err = ext4_map_blocks(NULL, inode, &map, 0);