linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 3/6] fat: zero out seek range on _fat_get_block
@ 2014-03-02 14:09 Namjae Jeon
  2014-03-18 14:59 ` OGAWA Hirofumi
  0 siblings, 1 reply; 3+ messages in thread
From: Namjae Jeon @ 2014-03-02 14:09 UTC (permalink / raw)
  To: hirofumi, akpm
  Cc: linux-fsdevel, linux-kernel, Namjae Jeon, Namjae Jeon, Amit Sahrawat

From: Namjae Jeon <namjae.jeon@samsung.com>

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.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com>
---
 fs/fat/inode.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index ca222ef..a594dae 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -54,6 +54,25 @@ static int fat_add_cluster(struct inode *inode)
 	return err;
 }
 
+static void check_fallocated_region(struct inode *inode, sector_t iblock,
+		unsigned long *max_blocks, struct buffer_head *bh_result)
+{
+	struct super_block *sb = inode->i_sb;
+	sector_t last_block, disk_block;
+	const unsigned long blocksize = sb->s_blocksize;
+	const unsigned char blocksize_bits = sb->s_blocksize_bits;
+
+	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);
+	}
+
+}
+
 static inline int __fat_get_block(struct inode *inode, sector_t iblock,
 				  unsigned long *max_blocks,
 				  struct buffer_head *bh_result, int create)
@@ -68,8 +87,11 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock,
 	if (err)
 		return err;
 	if (phys) {
-		map_bh(bh_result, sb, phys);
 		*max_blocks = min(mapped_blocks, *max_blocks);
+		if (create)
+			check_fallocated_region(inode, iblock, max_blocks,
+				bh_result);
+		map_bh(bh_result, sb, phys);
 		return 0;
 	}
 	if (!create)
-- 
1.7.11-rc0



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

* Re: [PATCH v4 3/6] fat: zero out seek range on _fat_get_block
  2014-03-02 14:09 [PATCH v4 3/6] fat: zero out seek range on _fat_get_block Namjae Jeon
@ 2014-03-18 14:59 ` OGAWA Hirofumi
  2014-03-19  9:40   ` Namjae Jeon
  0 siblings, 1 reply; 3+ messages in thread
From: OGAWA Hirofumi @ 2014-03-18 14:59 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: akpm, linux-fsdevel, linux-kernel, Namjae Jeon, Amit Sahrawat

Namjae Jeon <linkinjeon@gmail.com> writes:

> +static void check_fallocated_region(struct inode *inode, sector_t iblock,
> +		unsigned long *max_blocks, struct buffer_head *bh_result)
> +{
> +	struct super_block *sb = inode->i_sb;
> +	sector_t last_block, disk_block;
> +	const unsigned long blocksize = sb->s_blocksize;
> +	const unsigned char blocksize_bits = sb->s_blocksize_bits;
> +
> +	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) {

Maybe off-by-one error. If iblock == disk_block, phys should not be set
by fat_bmap()?
-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

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

* Re: [PATCH v4 3/6] fat: zero out seek range on _fat_get_block
  2014-03-18 14:59 ` OGAWA Hirofumi
@ 2014-03-19  9:40   ` Namjae Jeon
  0 siblings, 0 replies; 3+ messages in thread
From: Namjae Jeon @ 2014-03-19  9:40 UTC (permalink / raw)
  To: OGAWA Hirofumi
  Cc: akpm, linux-fsdevel, linux-kernel, Namjae Jeon, Amit Sahrawat

2014-03-18 23:59 GMT+09:00, OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>:
> Namjae Jeon <linkinjeon@gmail.com> writes:
>
>> +static void check_fallocated_region(struct inode *inode, sector_t
>> iblock,
>> +		unsigned long *max_blocks, struct buffer_head *bh_result)
>> +{
>> +	struct super_block *sb = inode->i_sb;
>> +	sector_t last_block, disk_block;
>> +	const unsigned long blocksize = sb->s_blocksize;
>> +	const unsigned char blocksize_bits = sb->s_blocksize_bits;
>> +
>> +	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) {
>
Hi OGAWA.
> Maybe off-by-one error. If iblock == disk_block, phys should not be set
> by fat_bmap()?
Yes, right, iblock == disk_block case is not needed in this condition
because fat_bmap don't set to phys when iblock==diskblock.(phys will
be 0)
So I will change it like this.

if (iblock >= last_block && iblock < disk_block) {

And I will fix your review comments in other patches.

Thanks for review!
> --
> OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
>

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

end of thread, other threads:[~2014-03-19  9:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-02 14:09 [PATCH v4 3/6] fat: zero out seek range on _fat_get_block Namjae Jeon
2014-03-18 14:59 ` OGAWA Hirofumi
2014-03-19  9:40   ` Namjae Jeon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).