fat: zero out seek range on _fat_get_block
Subsystems (2)
PATCH v2 3/5 fat: zero out seek range on _fat_get_block
From: Namjae Jeon <[email protected]>
For normal buffered write operations, normally if we try to write to an offset > than file size, it does a cont_expand_zero till that offset. Now, in case of fallocated regions, since the blocks are already allocated. So, make it zero out that buffers for those blocks till the seek'ed offset.
--- fs/fat/cache.c | 3 ++- fs/fat/inode.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-)
fs/fat/cache.c +2 -1
@@ -334,7 +334,8 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,*/ last_block = (MSDOS_I (inode)->i_disksize + (blocksize -1 )) >> blocksize_bits; -if (sector >= last_block) +if (sector >= last_block && +MSDOS_I (inode)->mmu_private ==MSDOS_I (inode)->i_disksize)return 0 ; }
fs/fat/inode.c +13 -2
@@ -61,15 +61,26 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock,struct super_block *sb = inode->i_sb;struct msdos_sb_info *sbi =MSDOS_SB (sb);unsigned long mapped_blocks; -sector_t phys; +sector_t phys, last_block, disk_block;int err, offset; +const unsigned long blocksize = sb->s_blocksize; +const unsigned char blocksize_bits = sb->s_blocksize_bits; err =fat_bmap (inode, iblock, &phys, &mapped_blocks, create);if (err)return err;if (phys) { -map_bh (bh_result, sb, phys); *max_blocks =min (mapped_blocks, *max_blocks); + last_block = (MSDOS_I (inode)->mmu_private + (blocksize -1 )) + >> blocksize_bits; + disk_block = (MSDOS_I (inode)->i_disksize + (blocksize -1 )) + >> blocksize_bits; +if (iblock >= last_block && iblock <= disk_block) { +MSDOS_I (inode)->mmu_private += + *max_blocks << blocksize_bits; +set_buffer_new (bh_result); + } +map_bh (bh_result, sb, phys);return 0 ; }if (!create)
Signature · 1 line
1.7.9.5
OGAWA Hirofumi
maintainerfs/fat/cache.c int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys, · line 339
Quoted 10 lines · Namjae Jeon
fs/fat/cache.c +2
-1@@ -334,7 +334,8 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,*/ last_block = (MSDOS_I (inode)->i_disksize + (blocksize -1 )) >> blocksize_bits; -if (sector >= last_block) +if (sector >= last_block && +MSDOS_I (inode)->mmu_private ==MSDOS_I (inode)->i_disksize)return 0 ;
This is strange check. Why do we want to map even if "sector > ->i_disksize" (when ->mmu_private != ->i_disksize)?
Another point, for ->bmap(), maybe we will need new flag to read beyond ->i_size? Because ->bmap() returns physical address even if > ->i_size.
Quoted 23 lines
fs/fat/inode.c +6
-2@@ -61,15 +61,26 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock,struct super_block *sb = inode->i_sb;struct msdos_sb_info *sbi =MSDOS_SB (sb);unsigned long mapped_blocks; -sector_t phys; +sector_t phys, last_block, disk_block;int err, offset; +const unsigned long blocksize = sb->s_blocksize; +const unsigned char blocksize_bits = sb->s_blocksize_bits; err =fat_bmap (inode, iblock, &phys, &mapped_blocks, create);if (err)return err;if (phys) { -map_bh (bh_result, sb, phys); *max_blocks =min (mapped_blocks, *max_blocks); + last_block = (MSDOS_I (inode)->mmu_private + (blocksize -1 )) + >> blocksize_bits; + disk_block = (MSDOS_I (inode)->i_disksize + (blocksize -1 ))
fs/fat/inode.c static inline int __fat_get_block(struct inode *inode, sector_t iblock, · line 86
Quoted 10 lines
fs/fat/inode.c +7
-0+ >> blocksize_bits; +if (iblock >= last_block && iblock <= disk_block) { +MSDOS_I (inode)->mmu_private += + *max_blocks << blocksize_bits; +set_buffer_new (bh_result); + } +map_bh (bh_result, sb, phys);return 0 ; }if (!create)
Let's give the name for this operation for readability, and make it static function. With this, I think this one much readable.
static void check_fallocate_region()
{
/* code here */
}Signature · 1 line
OGAWA Hirofumi <[email protected]>
2013/12/1, OGAWA Hirofumi <[email protected]>:
Quoted 17 lines
fs/fat/cache.c int fat_bmap(struct inode *inode, sector_t sector, · line 340
Quoted 11 lines · Namjae Jeon
fs/fat/cache.c +2
-1@@ -334,7 +334,8 @@ int fat_bmap(struct inode *inode, sector_t sector,sector_t *phys, */ last_block = (MSDOS_I (inode)->i_disksize + (blocksize -1 )) >> blocksize_bits; -if (sector >= last_block) +if (sector >= last_block && +MSDOS_I (inode)->mmu_private ==MSDOS_I (inode)->i_disksize)return 0 ;This is strange check. Why do we want to map even if "sector > ->i_disksize"
(when ->mmu_private != ->i_disksize)?
Yes, Don't want it. I will fix it.
Quoted 4 lines
Another point, for ->bmap(), maybe we will need new flag to read beyond ->i_size? Because ->bmap() returns physical address even if > ->i_size.
Okay, I will change it as your comment.
Quoted 39 lines
Quoted 34 lines
fs/fat/inode.c +13
-2@@ -61,15 +61,26 @@ static inline int __fat_get_block(struct inode *inode,sector_t iblock, struct super_block *sb = inode->i_sb;struct msdos_sb_info *sbi =MSDOS_SB (sb);unsigned long mapped_blocks; -sector_t phys; +sector_t phys, last_block, disk_block;int err, offset; +const unsigned long blocksize = sb->s_blocksize; +const unsigned char blocksize_bits = sb->s_blocksize_bits; err =fat_bmap (inode, iblock, &phys, &mapped_blocks, create);if (err)return err;if (phys) { -map_bh (bh_result, sb, phys); *max_blocks =min (mapped_blocks, *max_blocks); + last_block = (MSDOS_I (inode)->mmu_private + (blocksize -1 )) + >> blocksize_bits; + disk_block = (MSDOS_I (inode)->i_disksize + (blocksize -1 )) + >> blocksize_bits; +if (iblock >= last_block && iblock <= disk_block) { +MSDOS_I (inode)->mmu_private += + *max_blocks << blocksize_bits; +set_buffer_new (bh_result); + } +map_bh (bh_result, sb, phys);return 0 ; }Quoted 1 line
if (!create)
Let's give the name for this operation for readability, and make it static function. With this, I think this one much readable.
Quoted 4 lines
static void
check_fallocate_region(){ /* code here */ }
Okay, I will make it.
Thanks for review.
Quoted 3 lines
--
OGAWA Hirofumi <[email protected]>