All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mingming Cao <cmm@us.ibm.com>
To: Aneesh Kumar <aneesh.kumar@gmail.com>
Cc: linux-ext4 <linux-ext4@vger.kernel.org>
Subject: Re: Gentoo with ext4-patch-queue snapshots
Date: Thu, 03 Jul 2008 10:38:40 -0700	[thread overview]
Message-ID: <1215106720.6880.5.camel@mingming-laptop> (raw)
In-Reply-To: <cc723f590807030707j5ec31f0p5db26bf8529c61ef@mail.gmail.com>


在 2008-07-03四的 19:37 +0530,Aneesh Kumar写道:
> [sending via gmail  ]
> 
> On Thu, Jul 03, 2008 at 05:03:25PM +0530, Aneesh Kumar K.V wrote:
> > On Wed, Jul 02, 2008 at 10:19:54AM -0700, Mingming Cao wrote:
> > >
> > > On Tue, 2008-07-01 at 17:50 +0000, Gary Hawco wrote:
> > > > Mingming,
> > > >
> > > > Can you post that patch somewhere for download? I access my email using
> > > > Windows Vista, not in linux, so it would be very laborious to hand copy
> > > > this patch and recreate it in linux.
> > > >
> > > Patch attached.
> > >
> > > > Updated the 2.6.26-rc8 kernel with the latest snapshot from today at
> > > > 1833hrs GMT. All hell broke loose in Gentoo, The new kernel wouldn't allow
> > > > the system to remount read/write on boot.  But it worked fine in Slackware.
> > > > Gentoo with the experimental openrc-0.2.5 and baselayout2 apparently does
> > > > not like ext4.
> > > >
> > >
> >
> > I think we need to protect i_disksize update with i_data_sem. Otherwise
> > a parallel writepages and write_end can cause issues. I guess that is
> > what Gary is finding. I also did some cleanup for the patch
> >
> 
> better one moving ext4_truncate i_disksize update under i_data_sem.
> ext4_ext_truncate is already doing this.
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index fcaafe4..05e9790 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -1893,18 +1893,29 @@ static int ext4_da_write_begin(struct file
> *file, struct address_space *mapping,
>  /*
>   * Check if we should update i_disksize
>   * when write to the end of file but not require block allocation
> + * We check only the buffer head mapping the offset.
> + * ex: File with blocksize 1K page size 4K
> + * block 1 and 2 are holes, block 3 is mapped and half filled
> + * seek to block 1 and write ( marked the buffer delay )
> + * seek to block 3 and extent the end of file with end of file still
> + * falling within block 3. Here the writepages won't update the i_disksize
> + * properly because it allocate only block 1. So we need to update
> + * i_disksize in write_end checking only the offset
> + *
>   */

Okay, Iwill add this comment

> -static int ext4_da_should_update_i_disksize(struct page *page,
> -					 unsigned long offset)
> +static int ext4_da_should_update_i_disksize(struct address_space *mapping,
> +					struct page *page, unsigned long offset)
>  {
> -	struct buffer_head *bh;
> -	unsigned int idx;
>  	int i;
> +	unsigned int idx;
> +	struct buffer_head *bh;
> +	struct inode *inode = mapping->host;
> +	unsigned blocksize = inode->i_sb->s_blocksize;
> 
We could use page->mapping->host to get the inode pointer, so no need to
pass the mapping pointer. But I am fine with this.

>  	bh = page_buffers(page);
> -	idx = offset/bh->b_size;
> +	idx = (offset + blocksize - 1)/blocksize;
> 
> -	for (i=0; i < idx; i++)
> +	for (i = 1; i < idx; i++)
>  		bh = bh->b_this_page;
> 
Ack

>  	if (!buffer_mapped(bh) || (buffer_delay(bh)))
> @@ -1934,15 +1945,20 @@ static int ext4_da_write_end(struct file *file,
> 
>  	new_i_size = pos + copied;
>  	if (new_i_size > EXT4_I(inode)->i_disksize)
> -		if (ext4_da_should_update_i_disksize(page, end)) {
> +		if (ext4_da_should_update_i_disksize(mapping, page, end)) {
>  			/*
>  			 * Updating i_disksize when extending file without
>  			 * need block allocation
>  			 */
> -			if (ext4_should_order_data(inode))
> -				ret = ext4_jbd2_file_inode(handle, inode);
> +			down_write(&EXT4_I(inode)->i_data_sem);
> +			if (new_i_size > EXT4_I(inode)->i_disksize) {
> +				if (ext4_should_order_data(inode))
> +					ret = ext4_jbd2_file_inode(handle,
> +									inode);
> 
> -			EXT4_I(inode)->i_disksize = new_i_size;
> +				EXT4_I(inode)->i_disksize = new_i_size;
> +			}
> +			up_write(&EXT4_I(inode)->i_data_sem);
>  		}
>  	ret2 = generic_write_end(file, mapping, pos, len, copied,
>  							page, fsdata);
> @@ -2987,6 +3003,11 @@ void ext4_truncate(struct inode *inode)
>  	 */
>  	if (ext4_orphan_add(handle, inode))
>  		goto out_stop;
> +	/*
> +	 * From here we block out all ext4_get_block() callers who want to
> +	 * modify the block allocation tree.
> +	 */
> +	down_write(&ei->i_data_sem);
> 
>  	/*
>  	 * The orphan list entry will now protect us from any crash which
> @@ -2997,12 +3018,6 @@ void ext4_truncate(struct inode *inode)
>  	 */
>  	ei->i_disksize = inode->i_size;
> 
> -	/*
> -	 * From here we block out all ext4_get_block() callers who want to
> -	 * modify the block allocation tree.
> -	 */
> -	down_write(&ei->i_data_sem);
> -
>  	if (n == 1) {		/* direct blocks */
>  		ext4_free_data(handle, inode, NULL, i_data+offsets[0],
>  			       i_data + EXT4_NDIR_BLOCKS);
> 

Ack.

I will merge the update to the parent patch, thanx

Mingming
> -aneesh
> --
> 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

--
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:[~2008-07-03 17:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-25 13:53 Segmentation Faults with 062508 ext4-patch-queue snapshot Gary Hawco
2008-06-26  4:14 ` Eric Sandeen
2008-06-26 22:12   ` Segmentation Faults with both 062608 snapshots Gary Hawco
2008-07-01  2:32     ` Theodore Tso
2008-07-01  0:00       ` More ext4dev snapshot weirdness Gary Hawco
2008-07-01 16:02         ` Theodore Tso
2008-07-01 10:54           ` delalloc filesystem corruption Gary Hawco
2008-07-01 23:00             ` Mingming Cao
2008-07-01 17:50               ` Gentoo with ext4-patch-queue snapshots Gary Hawco
2008-07-02 17:19                 ` Mingming Cao
2008-07-02 20:33                   ` Mingming Cao
2008-07-03 14:07                     ` Aneesh Kumar
2008-07-03 17:38                       ` 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=1215106720.6880.5.camel@mingming-laptop \
    --to=cmm@us.ibm.com \
    --cc=aneesh.kumar@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    /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.