From: Mingming Cao <cmm@us.ibm.com>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: tytso@mit.edu, linux-ext4@vger.kernel.org
Subject: Re: [PATCH] ext4: When reading from fallocated blocks make sure we return zero.
Date: Mon, 18 Feb 2008 21:24:12 -0800 [thread overview]
Message-ID: <1203398652.3612.7.camel@localhost.localdomain> (raw)
In-Reply-To: <20080219031914.GA7192@skywalker>
On Tue, 2008-02-19 at 08:49 +0530, Aneesh Kumar K.V wrote:
> On Mon, Feb 18, 2008 at 04:14:34PM -0800, Mingming Cao wrote:
> > On Sat, 2008-02-16 at 08:53 +0530, Aneesh Kumar K.V wrote:
> >
> > How about the following patch?
> >
> > Regards,
> > Mingming
> >
> > ext4: ext4_get_blocks_wrap fix for writing to preallocated
> > From: Mingming Cao <cmm@us.ibm.com>
> >
> > This patch fixed a issue with wrting to a preallocated blocks.
> > A write hit a BUG_ON() in fs/buffer.c saying the buffer is not mapped.
> >
> > On the write path, ext4_get_block_wrap() is called with create=1, but it
> > will pass create=0 down to the underlying ext4ext_get_blocks()
> > to do a look up first. In the preallocation case, ext4_ext_get_blocks()
> > with create = 0, will return number of blocks pre-allocated and buffer
> > head unmapped. ext4_get_blocks_wrap() thinks it succeeds too early, without
> > checking if it needs again call ext4_ext_get_blocks with create = 1
> > which would do proper handling for writing to preallocated blocks:
> > split the extent to initialized and uninitialized one and
> > returns the mapped buffer head.
> >
> > Treating preallocated blocks as holes equally(i.e. ignoring the number of blocks
> > pre-allocated and returns 0) when get_blocks() is called with create = 0 is not enough.
> > ext4_ext_get_blocks() needs to differentiate these two cases for delayed allocation
> > purpose, as for holes it need to do reservation and prepare for later
> > delayed allocation, but for pre-allocated blocks it needs skip that work.
> >
> > It would makes things more clear if we have clear definition of what
> > get_blocks() return value means.
> >
> > Similar to ext4_get_blocks_handle(), the following
> > * return > 0, # of blocks already allocated
> > * if these are pre-allocated blocks and create = 0
> > * buffer head is unmapped
> > * otherwise blocks are mapped.
> > *
> > * return = 0, if plain look up failed (blocks have not been allocated)
> > * buffer head is unmapped
> > *
> > * return < 0, error case.
> >
> > The for the write path, at ext4_ext_get_blocks_wrap(), it could check the
> > buffer_mapped() status for preallocated extent before quit too early.
> >
> > Signed-off-by: Mingming Cao <cmm@us.ibm.com>
>
> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.co>
>
>
>
> I guess we also need to make sure the buffer head have the mapped bit
> set. Something like the patch below.
>
Good point. I modified the patch with clear_buffer_mapped() added at the
begining of the wrapper function.
Mingming
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index bc7081f..69ccda9 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -2294,6 +2294,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
> struct ext4_allocation_request ar;
>
> __clear_bit(BH_New, &bh_result->b_state);
> + __clear_bit(BH_Mapped, &bh_result->b_state);
> ext_debug("blocks %u/%lu requested for inode %u\n",
> iblock, max_blocks, inode->i_ino);
>
prev parent reply other threads:[~2008-02-19 5:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-15 18:16 [PATCH] ext4: When reading from fallocated blocks make sure we return zero Aneesh Kumar K.V
2008-02-15 19:43 ` Mingming Cao
2008-02-16 3:23 ` Aneesh Kumar K.V
2008-02-18 7:45 ` Aneesh Kumar K.V
2008-02-19 0:14 ` Mingming Cao
2008-02-19 3:19 ` Aneesh Kumar K.V
2008-02-19 5:24 ` Mingming Cao [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1203398652.3612.7.camel@localhost.localdomain \
--to=cmm@us.ibm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.