linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: Mingming Cao <cmm@us.ibm.com>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
	tytso@mit.edu, linux-ext4@vger.kernel.org
Subject: Re: [RFC PATCH] mark buffer_head mapping preallocate area as new during write_begin with delayed allocation
Date: Mon, 27 Apr 2009 22:03:32 -0500	[thread overview]
Message-ID: <49F67204.5000108@redhat.com> (raw)
In-Reply-To: <1240873494.6775.8.camel@mingming-laptop>

Mingming Cao wrote:
> 在 2009-04-28二的 00:35 +0530,Aneesh Kumar K.V写道:
>> We need to mark the  buffer_head mapping prealloc space
>> as new during write_begin. Otherwise we don't zero out the
>> page cache content properly for a partial write. This will
>> cause file corruption with preallocation.
>>
> 
>> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
>>
>> ---
>>  fs/ext4/inode.c |    2 ++
>>  1 files changed, 2 insertions(+), 0 deletions(-)
>>
>> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
>> index c6bd6ce..c7251ec 100644
>> --- a/fs/ext4/inode.c
>> +++ b/fs/ext4/inode.c
>> @@ -2323,6 +2323,8 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
>>  		set_buffer_delay(bh_result);
>>  	} else if (ret > 0) {
>>  		bh_result->b_size = (ret << inode->i_blkbits);
>> +		if (buffer_unwritten(bh_result))
>> +			set_buffer_new(bh_result);
>>  		ret = 0;
>>  	}
>>
> 
> Thanks Aneesh.
> 
> Just to share with list, I have seen garbage content show up on a
> preallocated but later partially written blocks. This only happens with
> delayed allocation. The test simply preallocate 2blocks to a new file,
> then write a few bytes to the beginning of file(less than a block), and
> od shows the first block the written content followed by garbage filled
> to the end of the first block.
> 
> After examing the code, we did set the buffer as new for nondelalloc, as
> the create flag passed to ext4_ext_get_blocks() is 1, while for delalloc
> case, ext4_get_blocks_prep() calling ext4_ext_get_block() with create
> =0, which leads to the code path that forget to set the bh as new if the
> block is preallocated.
> 
> This patch is mostly correct except forget to set the bh_result->bdev,
> which caused the fs blow out.

Yep, I saw the oops too.

> The updated patch fixed the problem for me.
> 
> Signed-off-by: Mingming Cao <cmm@us.ibm.com>
> 
> Index: linux-2.6.28-rc6/fs/ext4/inode.c
> ===================================================================
> --- linux-2.6.28-rc6.orig/fs/ext4/inode.c	2009-03-12 10:21:05.000000000 -0700
> +++ linux-2.6.28-rc6/fs/ext4/inode.c	2009-04-27 14:35:21.000000000 -0700
> @@ -2177,7 +2177,10 @@ static int ext4_da_get_block_prep(struct
>  		set_buffer_new(bh_result);
>  		set_buffer_delay(bh_result);
>  	} else if (ret > 0) {
> +		if (buffer_unwritten(bh_result))
> +			set_buffer_new(bh_result);
>  		bh_result->b_size = (ret << inode->i_blkbits);
> +		bh_result->b_bdev = inode->i_sb->s_bdev;
>  		ret = 0;
>  	}

It may be just me, but I'd like to sort out why we now need to set
b_bdev here just because we set it as new, and it wasn't necessary
before...?  If it's obvious I'm not yet seeing it :)

-Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2009-04-28  3:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-27 19:05 [RFC PATCH] mark buffer_head mapping preallocate area as new during write_begin with delayed allocation Aneesh Kumar K.V
2009-04-27 19:30 ` Eric Sandeen
2009-04-27 23:04 ` Mingming Cao
2009-04-28  3:03   ` Eric Sandeen [this message]
2009-04-28  4:20   ` Aneesh Kumar K.V
2009-04-28  9:31     ` Aneesh Kumar K.V
2009-04-28 12:48       ` Theodore Tso
2009-04-28 16:35         ` Aneesh Kumar K.V
2009-04-28 17:00           ` Theodore Tso
2009-04-28 18:57             ` Aneesh Kumar K.V
2009-04-28 19:35               ` Eric Sandeen
2009-04-29 11:57                 ` Jan Kara
2009-04-29 14:08                   ` Eric Sandeen
2009-04-29 18:13                     ` Jan Kara
2009-04-29  1:38             ` Mingming
2009-04-28 16:37         ` Eric Sandeen

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=49F67204.5000108@redhat.com \
    --to=sandeen@redhat.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=cmm@us.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 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).