ext4: Mark the unwritten buffer_head mapped during write_begin
PATCH 1/1 ext4: Mark the unwritten buffer_head mapped during write_begin
This avoid multiple get_block calls during write. Now that we have unwritten buffer marked as mapped, we need to make sure writepages will handle unwritten buffer_heads also.
With this patch we have the below:
ext4_ext_get_block returns unmapped, unwritten, buffer head when called with create = 0 for prealloc space. This make sure we handle the read path and non delalloc case correctly. Even though the buffer head is marked unmapped we have valid b_blocknr and b_bdev values in the buffer_head.
ext4_da_get_block_prep called for block resrevation will now return mapped, unwritten, new buffer_head for prealloc space. This make sure we don't do multiple get_block calls for write to same offset. Also marking it new make sure sub-block zeroing of buffered writes happen correctly.
--- fs/ext4/extents.c | 6 ++- fs/ext4/inode.c | 81 ++++++++++++++++++++++++++++++++-------------------- 2 files changed, 54 insertions(+), 33 deletions(-)
fs/ext4/extents.c +4 -2
@@ -2865,6 +2865,8 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,if (create ==EXT4_CREATE_UNINITIALIZED_EXT ) goto out;if (!create) { +if (allocated > max_blocks) + allocated = max_blocks;/* * We have blocks reserved already. We * return allocated blocks so that delalloc
@@ -2872,9 +2874,9 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,* the buffer head will be unmapped so that * a read from the block returns 0s. */ -if (allocated > max_blocks) - allocated = max_blocks;set_buffer_unwritten (bh_result); + bh_result->b_bdev = inode->i_sb->s_bdev; + bh_result->b_blocknr = newblock; goto out2; }
fs/ext4/inode.c +49 -29
125 lines not on this page · raw message
Theodore Tso
maintainerQuoted 11 lines · Aneesh Kumar K.V
This avoid multiple
get_blockcalls during write. Now that we have unwritten buffer marked as mapped, we need to make sure writepages will handle unwrittenbuffer_headsalso.With this patch we have the below:
ext4_ext_get_blockreturns unmapped, unwritten, buffer head when called with create = 0 for prealloc space. This make sure we handle the read path and non delalloc case correctly. Even though the buffer head is marked unmapped we have validb_blocknrandb_bdevvalues in thebuffer_head.
Quoted 4 lines
ext4_da_get_block_prepcalled for block resrevation will now return mapped, unwritten, newbuffer_headfor prealloc space. This make sure we don't do multipleget_blockcalls for write to same offset. Also marking it new make sure sub-block zeroing of buffered writes happen correctly.
Can you clarify this patch description. Is this only about avoiding multiple calls to get_block_*(), or does this also fix some potential filesystem corruption bugs? And how does this fit in with the other patches you've submitted?
Thanks,
- Ted
PATCH 1/1 ext4: Mark the unwritten buffer_head mapped during write_begin
In reply to Aneesh Kumar K.VUpdated to apply cleanly after applying the version 5 of fake block number patches
-aneesh
ext4: Mark the unwritten buffer_head as mapped during write_begin
From: Aneesh Kumar K.V <[email protected]>
This avoids multiple get_block calls during write. Now that we have unwritten buffer marked as mapped, we need to make sure writepages will handle unwritten buffer_heads also.
With this patch we have the below:
ext4_ext_get()_block returns unmapped, unwritten, buffer head when called with create = 0 for prealloc space. This makes sure we handle the read path and non-delayed allocation case correctly. Even though the buffer head is marked unmapped we have valid b_blocknr and b_bdev values in the buffer_head.
ext4_da_get_block_prep called for block resrevation will now return mapped, unwritten, new buffer_head for prealloc space. This make sure we don't do multiple get_block calls for write to same offset. Also marking it new make sure sub-block zeroing of buffered writes happen correctly.
--- fs/ext4/extents.c | 4 +-- fs/ext4/inode.c | 79 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 31 deletions(-)
fs/ext4/extents.c +2 -2
@@ -2865,6 +2865,8 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,if (create ==EXT4_CREATE_UNINITIALIZED_EXT ) goto out;if (!create) { +if (allocated > max_blocks) + allocated = max_blocks;/* * We have blocks reserved already. We * return allocated blocks so that delalloc
@@ -2872,8 +2874,6 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,* the buffer head will be unmapped so that * a read from the block returns 0s. */ -if (allocated > max_blocks) - allocated = max_blocks;set_buffer_unwritten (bh_result); bh_result->b_bdev = inode->i_sb->s_bdev; bh_result->b_blocknr = newblock;
fs/ext4/inode.c +49 -27
123 lines not on this page · raw message