ext4: Fix ext4_bmap to flush the data to the disk with delalloc
PATCH 1/1 ext4: Fix ext4_bmap to flush the data to the disk with delalloc
With delalloc we don't do block allocation in the write_begin/write_end. So when using bmap we first need to flush data to the disk so that blocks get allocated and then call generic_block_bmap.
--- fs/ext4/inode.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
fs/ext4/inode.c +11 -0
@@ -1833,6 +1833,17 @@ sector_t ext4_bmap(struct address_space *mapping, sector_t block)journal_t *journal;int err; +if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY ) && +test_opt (inode->i_sb,DELALLOC )) { +/* +* With delalloc we want to sync the file +* so that we can make sure we allocate +* blocks for file +*/ +filemap_fdatawrite (mapping); +filemap_fdatawait (mapping); + } +if (EXT4_I (inode)->i_state &EXT4_STATE_JDATA ) {/* * This is a REALLY heavyweight approach, but the use of
Signature · 1 line
1.5.6.rc2.15.g457bb.dirty
Quoted 17 lines · Aneesh Kumar K.V
With delalloc we don't do block allocation in the write_begin/write_end. So when using bmap we first need to flush data to the disk so that blocks get allocated and then call
generic_block_bmap.Signed-off-by Aneesh Kumar K.V <[email protected]>--- fs/ext4/inode.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)fs/ext4/inode.c +0
-0@@ -1833,6 +1833,17 @@ sector_t ext4_bmap(struct address_space *mapping, sector_t block)journal_t *journal;int err;
fs/ext4/inode.c sector_t ext4_bmap(struct address_space *mapping, sector_t block) · line 1845
Quoted 10 lines
fs/ext4/inode.c +10
-0+if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY ) && +test_opt (inode->i_sb,DELALLOC )) { +/* +* With delalloc we want to sync the file +* so that we can make sure we allocate +* blocks for file +*/ +filemap_fdatawrite (mapping); +filemap_fdatawait (mapping); + }
This seems fine.
I wonder, does it make any sense at all to only do the flushing if the block we wish to map is actually in a delalloc state at the moment?
-Eric
Quoted 4 lines
fs/ext4/inode.c +1
-0+if (EXT4_I (inode)->i_state &EXT4_STATE_JDATA ) {/* * This is a REALLY heavyweight approach, but the use of
Quoted 31 lines · Eric Sandeen
Quoted 17 lines · Aneesh Kumar K.V
With delalloc we don't do block allocation in the write_begin/write_end. So when using bmap we first need to flush data to the disk so that blocks get allocated and then call
generic_block_bmap.Signed-off-by Aneesh Kumar K.V <[email protected]>--- fs/ext4/inode.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)fs/ext4/inode.c +0
-0@@ -1833,6 +1833,17 @@ sector_t ext4_bmap(struct address_space *mapping, sector_t block)journal_t *journal;int err;fs/ext4/inode.c sector_t ext4_bmap(struct address_space *mapping, sector_t block) · line 1845
Quoted 10 lines
fs/ext4/inode.c +10
-0+if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY ) && +test_opt (inode->i_sb,DELALLOC )) { +/* +* With delalloc we want to sync the file +* so that we can make sure we allocate +* blocks for file +*/ +filemap_fdatawrite (mapping); +filemap_fdatawait (mapping); + }This seems fine.
Quoted 3 lines
I wonder, does it make any sense at all to only do the flushing if the block we wish to map is actually in a delalloc state at the moment?
I am not sure it is worth the complexity considering bmap is not a frequently used API. Initially I was even thinking should i be doing it only for delalloc. That test seems to be a simple one to put.
-aneesh
Quoted 18 lines · Aneesh Kumar K.V
With delalloc we don't do block allocation in the write_begin/write_end. So when using bmap we first need to flush data to the disk so that blocks get allocated and then call
generic_block_bmap.Signed-off-by Aneesh Kumar K.V <[email protected]>--- fs/ext4/inode.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)fs/ext4/inode.c +1
-0@@ -1833,6 +1833,17 @@ sector_t ext4_bmap(struct address_space *mapping, sector_t block)journal_t *journal;int err; + if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) &&
fs/ext4/inode.c sector_t ext4_bmap(struct address_space *mapping, sector_t block) · line 1846
Quoted 10 lines
fs/ext4/inode.c +10
-0+ test_opt(inode->i_sb, DELALLOC)) { +/* +* With delalloc we want to sync the file +* so that we can make sure we allocate +* blocks for file +*/ +filemap_fdatawrite (mapping); +filemap_fdatawait (mapping); + } +
I would use filemap_write_and_wait(), it is essentially the same as above two functions, but with a little extra checking.
Mingming
Quoted 3 lines
fs/ext4/inode.c +0
-0if (EXT4_I (inode)->i_state &EXT4_STATE_JDATA ) {/* * This is a REALLY heavyweight approach, but the use of
Quoted 19 lines · Mingming
Quoted 17 lines · Aneesh Kumar K.V
With delalloc we don't do block allocation in the write_begin/write_end. So when using bmap we first need to flush data to the disk so that blocks get allocated and then call
generic_block_bmap.Signed-off-by Aneesh Kumar K.V <[email protected]>--- fs/ext4/inode.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)fs/ext4/inode.c +0
-0@@ -1833,6 +1833,17 @@ sector_t ext4_bmap(struct address_space *mapping, sector_t block)journal_t *journal;int err;
Quoted 15 lines
fs/ext4/inode.c sector_t ext4_bmap(struct address_space *mapping, sector_t block) · line 1846
Quoted 11 lines
fs/ext4/inode.c +11
-0+if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY ) && +test_opt (inode->i_sb,DELALLOC )) { +/* +* With delalloc we want to sync the file +* so that we can make sure we allocate +* blocks for file +*/ +filemap_fdatawrite (mapping); +filemap_fdatawait (mapping); + } +I would use
filemap_write_and_wait(), it is essentially the same as above two functions, but with a little extra checking.
Updated patch below
ext4: Fix ext4_bmap to flush the data to the disk with delalloc
From: Aneesh Kumar K.V <[email protected]>
With delalloc we don't do block allocation in the write_begin/write_end. So when using bmap we first need to flush data to the disk so that blocks get allocated and then call generic_block_bmap.
---
fs/ext4/inode.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
fs/ext4/inode.c +10 -0
@@ -1833,6 +1833,16 @@ sector_t ext4_bmap(struct address_space *mapping, sector_t block)journal_t *journal;int err; +if (mapping_tagged (mapping,PAGECACHE_TAG_DIRTY ) && +test_opt (inode->i_sb,DELALLOC )) { +/* +* With delalloc we want to sync the file +* so that we can make sure we allocate +* blocks for file +*/ +filemap_write_and_wait (mapping); + } +if (EXT4_I (inode)->i_state &EXT4_STATE_JDATA ) {/* * This is a REALLY heavyweight approach, but the use of