public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext3_getblk should handle HOLE correctly
@ 2006-09-06 17:39 Badari Pulavarty
  2006-09-06 17:42 ` Dave Kleikamp
  2006-09-07 18:45 ` Andrew Morton
  0 siblings, 2 replies; 5+ messages in thread
From: Badari Pulavarty @ 2006-09-06 17:39 UTC (permalink / raw)
  To: akpm; +Cc: lkml, ext4, Will Simoneau, cmm

Hi Andrew,

Its been reported that ext3_getblk() is not doing the right thing
and triggering following WARN():

BUG: warning at fs/ext3/inode.c:1016/ext3_getblk()
 <c01c5140> ext3_getblk+0x98/0x2a6  <c03b2806> md_wakeup_thread
+0x26/0x2a
 <c01c536d> ext3_bread+0x1f/0x88  <c01cedf9> ext3_quota_read+0x136/0x1ae
 <c018b683> v1_read_dqblk+0x61/0xac  <c0188f32> dquot_acquire+0xf6/0x107
 <c01ceaba> ext3_acquire_dquot+0x46/0x68  <c01897d4> dqget+0x155/0x1e7
 <c018a97b> dquot_transfer+0x3e0/0x3e9  <c016fe52> dput+0x23/0x13e
 <c01c7986> ext3_setattr+0xc3/0x240  <c0120f66> current_fs_time
+0x52/0x6a
 <c017320e> notify_change+0x2bd/0x30d  <c0159246> chown_common+0x9c/0xc5
 <c02a222c> strncpy_from_user+0x3b/0x68  <c0167fe6> do_path_lookup
+0xdf/0x266
 <c016841b> __user_walk_fd+0x44/0x5a  <c01592b9> sys_chown+0x4a/0x55
 <c015a43c> vfs_write+0xe7/0x13c  <c01695d4> sys_mkdir+0x1f/0x23
 <c0102a97> syscall_call+0x7/0xb 

Looking at the code, it looks like its not handle HOLE correctly.
It ends up returning -EIO. Here is the patch to fix it.

If we really want to be paranoid, we can allow return values
0 (HOLE), 1 (we asked for one block) and return -EIO for
more than 1 block. But I really don't see a reason for
doing it - all we need is the block# here. (doesn't matter
how many blocks are mapped).

Thanks,
Badari

ext3_get_blocks_handle() returns number of blocks it mapped.
It returns 0 in case of HOLE. ext3_getblk() should handle
HOLE properly (currently its dumping warning stack and
returning -EIO).

Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com>
Acked-by: Mingming Cao <cmm@us.ibm.com>
---
 fs/ext3/inode.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Index: linux-2.6.18-rc5/fs/ext3/inode.c
===================================================================
--- linux-2.6.18-rc5.orig/fs/ext3/inode.c	2006-08-27 20:41:48.000000000 -0700
+++ linux-2.6.18-rc5/fs/ext3/inode.c	2006-09-05 15:32:57.000000000 -0700
@@ -1009,11 +1009,12 @@ struct buffer_head *ext3_getblk(handle_t
 	buffer_trace_init(&dummy.b_history);
 	err = ext3_get_blocks_handle(handle, inode, block, 1,
 					&dummy, create, 1);
-	if (err == 1) {
+	/*
+	 * ext3_get_blocks_handle() returns number of blocks
+	 * mapped. 0 in case of a HOLE.
+	 */
+	if (err > 0) {
 		err = 0;
-	} else if (err >= 0) {
-		WARN_ON(1);
-		err = -EIO;
 	}
 	*errp = err;
 	if (!err && buffer_mapped(&dummy)) {



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext3_getblk should handle HOLE correctly
  2006-09-06 17:39 [PATCH] ext3_getblk should handle HOLE correctly Badari Pulavarty
@ 2006-09-06 17:42 ` Dave Kleikamp
  2006-09-07 18:45 ` Andrew Morton
  1 sibling, 0 replies; 5+ messages in thread
From: Dave Kleikamp @ 2006-09-06 17:42 UTC (permalink / raw)
  To: Badari Pulavarty; +Cc: akpm, lkml, ext4, Will Simoneau, cmm

On Wed, 2006-09-06 at 10:39 -0700, Badari Pulavarty wrote:

> Index: linux-2.6.18-rc5/fs/ext3/inode.c
> ===================================================================
> --- linux-2.6.18-rc5.orig/fs/ext3/inode.c	2006-08-27 20:41:48.000000000 -0700
> +++ linux-2.6.18-rc5/fs/ext3/inode.c	2006-09-05 15:32:57.000000000 -0700
> @@ -1009,11 +1009,12 @@ struct buffer_head *ext3_getblk(handle_t
>  	buffer_trace_init(&dummy.b_history);
>  	err = ext3_get_blocks_handle(handle, inode, block, 1,
>  					&dummy, create, 1);
> -	if (err == 1) {
> +	/*
> +	 * ext3_get_blocks_handle() returns number of blocks
> +	 * mapped. 0 in case of a HOLE.
> +	 */
> +	if (err > 0) {
>  		err = 0;
> -	} else if (err >= 0) {
> -		WARN_ON(1);
> -		err = -EIO;
>  	}

I'd get rid of the {} too.

>  	*errp = err;
>  	if (!err && buffer_mapped(&dummy)) {

-- 
David Kleikamp
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext3_getblk should handle HOLE correctly
  2006-09-06 17:39 [PATCH] ext3_getblk should handle HOLE correctly Badari Pulavarty
  2006-09-06 17:42 ` Dave Kleikamp
@ 2006-09-07 18:45 ` Andrew Morton
  2006-09-07 19:22   ` Badari Pulavarty
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2006-09-07 18:45 UTC (permalink / raw)
  To: Badari Pulavarty; +Cc: lkml, ext4, Will Simoneau, cmm

On Wed, 06 Sep 2006 10:39:06 -0700
Badari Pulavarty <pbadari@us.ibm.com> wrote:

> Hi Andrew,
> 
> Its been reported that ext3_getblk() is not doing the right thing
> and triggering following WARN():
> 
> BUG: warning at fs/ext3/inode.c:1016/ext3_getblk()
>  <c01c5140> ext3_getblk+0x98/0x2a6  <c03b2806> md_wakeup_thread
> +0x26/0x2a
>  <c01c536d> ext3_bread+0x1f/0x88  <c01cedf9> ext3_quota_read+0x136/0x1ae
>  <c018b683> v1_read_dqblk+0x61/0xac  <c0188f32> dquot_acquire+0xf6/0x107
>  <c01ceaba> ext3_acquire_dquot+0x46/0x68  <c01897d4> dqget+0x155/0x1e7
>  <c018a97b> dquot_transfer+0x3e0/0x3e9  <c016fe52> dput+0x23/0x13e
>  <c01c7986> ext3_setattr+0xc3/0x240  <c0120f66> current_fs_time
> +0x52/0x6a
>  <c017320e> notify_change+0x2bd/0x30d  <c0159246> chown_common+0x9c/0xc5
>  <c02a222c> strncpy_from_user+0x3b/0x68  <c0167fe6> do_path_lookup
> +0xdf/0x266
>  <c016841b> __user_walk_fd+0x44/0x5a  <c01592b9> sys_chown+0x4a/0x55
>  <c015a43c> vfs_write+0xe7/0x13c  <c01695d4> sys_mkdir+0x1f/0x23
>  <c0102a97> syscall_call+0x7/0xb 
> 
> Looking at the code, it looks like its not handle HOLE correctly.
> It ends up returning -EIO.

Strange.  The fs should be spewing these warnings all over the place.  For
some reason this code is hard to trigger.  Why??

> -	if (err == 1) {
> +	/*
> +	 * ext3_get_blocks_handle() returns number of blocks
> +	 * mapped. 0 in case of a HOLE.
> +	 */
> +	if (err > 0) {
>  		err = 0;
> -	} else if (err >= 0) {
> -		WARN_ON(1);
> -		err = -EIO;
>  	}

That removes the warning if ext3_get_blocks_handle() returned a positive
number greater than one.  And it looks like we still need debugging support
in this area.

I reworked it like this:

--- a/fs/ext3/inode.c~ext3_getblk-should-handle-hole-correctly
+++ a/fs/ext3/inode.c
@@ -1010,11 +1010,14 @@ struct buffer_head *ext3_getblk(handle_t
 	buffer_trace_init(&dummy.b_history);
 	err = ext3_get_blocks_handle(handle, inode, block, 1,
 					&dummy, create, 1);
-	if (err == 1) {
+	/*
+	 * ext3_get_blocks_handle() returns number of blocks
+	 * mapped. 0 in case of a HOLE.
+	 */
+	if (err > 0) {
+		if (err > 1)
+			WARN_ON(1);
 		err = 0;
-	} else if (err >= 0) {
-		WARN_ON(1);
-		err = -EIO;
 	}
 	*errp = err;
 	if (!err && buffer_mapped(&dummy)) {
_

ie:

	/*
	 * ext3_get_blocks_handle() returns number of blocks
	 * mapped. 0 in case of a HOLE.
	 */
	if (err > 0) {
		if (err > 1)
			WARN_ON(1);
		err = 0;
	}
	*errp = err;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext3_getblk should handle HOLE correctly
  2006-09-07 18:45 ` Andrew Morton
@ 2006-09-07 19:22   ` Badari Pulavarty
  2006-09-07 19:55     ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Badari Pulavarty @ 2006-09-07 19:22 UTC (permalink / raw)
  To: Andrew Morton; +Cc: lkml, ext4, Will Simoneau, cmm

On Thu, 2006-09-07 at 11:45 -0700, Andrew Morton wrote:
> On Wed, 06 Sep 2006 10:39:06 -0700
> Badari Pulavarty <pbadari@us.ibm.com> wrote:
> 
> > Hi Andrew,
> > 
> > Its been reported that ext3_getblk() is not doing the right thing
> > and triggering following WARN():
> > 
> > BUG: warning at fs/ext3/inode.c:1016/ext3_getblk()
> >  <c01c5140> ext3_getblk+0x98/0x2a6  <c03b2806> md_wakeup_thread
> > +0x26/0x2a
> >  <c01c536d> ext3_bread+0x1f/0x88  <c01cedf9> ext3_quota_read+0x136/0x1ae
> >  <c018b683> v1_read_dqblk+0x61/0xac  <c0188f32> dquot_acquire+0xf6/0x107
> >  <c01ceaba> ext3_acquire_dquot+0x46/0x68  <c01897d4> dqget+0x155/0x1e7
> >  <c018a97b> dquot_transfer+0x3e0/0x3e9  <c016fe52> dput+0x23/0x13e
> >  <c01c7986> ext3_setattr+0xc3/0x240  <c0120f66> current_fs_time
> > +0x52/0x6a
> >  <c017320e> notify_change+0x2bd/0x30d  <c0159246> chown_common+0x9c/0xc5
> >  <c02a222c> strncpy_from_user+0x3b/0x68  <c0167fe6> do_path_lookup
> > +0xdf/0x266
> >  <c016841b> __user_walk_fd+0x44/0x5a  <c01592b9> sys_chown+0x4a/0x55
> >  <c015a43c> vfs_write+0xe7/0x13c  <c01695d4> sys_mkdir+0x1f/0x23
> >  <c0102a97> syscall_call+0x7/0xb 
> > 
> > Looking at the code, it looks like its not handle HOLE correctly.
> > It ends up returning -EIO.
> 
> Strange.  The fs should be spewing these warnings all over the place.  For
> some reason this code is hard to trigger.  Why??

I guess - ext3_getblk() mostly used by ext3_bread() and most callers 
to it would be reading already allocated block.

> 
> > -	if (err == 1) {
> > +	/*
> > +	 * ext3_get_blocks_handle() returns number of blocks
> > +	 * mapped. 0 in case of a HOLE.
> > +	 */
> > +	if (err > 0) {
> >  		err = 0;
> > -	} else if (err >= 0) {
> > -		WARN_ON(1);
> > -		err = -EIO;
> >  	}
> 
> That removes the warning if ext3_get_blocks_handle() returned a positive
> number greater than one.  And it looks like we still need debugging support
> in this area.

I am not sure why we need it ? All we care about is one block. If
ext3_get_blocks_handle() returns more than one (which it shouldn't) -
it still be okay. Whats wrong with that ? Just curious ..

May be we should add a WARN() in ext3_get_blocks_handle() when it
returns more than asked for.

Thanks,
Badari


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext3_getblk should handle HOLE correctly
  2006-09-07 19:22   ` Badari Pulavarty
@ 2006-09-07 19:55     ` Andrew Morton
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2006-09-07 19:55 UTC (permalink / raw)
  To: Badari Pulavarty; +Cc: lkml, ext4, Will Simoneau, cmm

On Thu, 07 Sep 2006 12:22:27 -0700
Badari Pulavarty <pbadari@us.ibm.com> wrote:

> On Thu, 2006-09-07 at 11:45 -0700, Andrew Morton wrote:
> > On Wed, 06 Sep 2006 10:39:06 -0700
> > Badari Pulavarty <pbadari@us.ibm.com> wrote:
> > 
> > > Hi Andrew,
> > > 
> > > Its been reported that ext3_getblk() is not doing the right thing
> > > and triggering following WARN():
> > > 
> > > BUG: warning at fs/ext3/inode.c:1016/ext3_getblk()
> > >  <c01c5140> ext3_getblk+0x98/0x2a6  <c03b2806> md_wakeup_thread
> > > +0x26/0x2a
> > >  <c01c536d> ext3_bread+0x1f/0x88  <c01cedf9> ext3_quota_read+0x136/0x1ae
> > >  <c018b683> v1_read_dqblk+0x61/0xac  <c0188f32> dquot_acquire+0xf6/0x107
> > >  <c01ceaba> ext3_acquire_dquot+0x46/0x68  <c01897d4> dqget+0x155/0x1e7
> > >  <c018a97b> dquot_transfer+0x3e0/0x3e9  <c016fe52> dput+0x23/0x13e
> > >  <c01c7986> ext3_setattr+0xc3/0x240  <c0120f66> current_fs_time
> > > +0x52/0x6a
> > >  <c017320e> notify_change+0x2bd/0x30d  <c0159246> chown_common+0x9c/0xc5
> > >  <c02a222c> strncpy_from_user+0x3b/0x68  <c0167fe6> do_path_lookup
> > > +0xdf/0x266
> > >  <c016841b> __user_walk_fd+0x44/0x5a  <c01592b9> sys_chown+0x4a/0x55
> > >  <c015a43c> vfs_write+0xe7/0x13c  <c01695d4> sys_mkdir+0x1f/0x23
> > >  <c0102a97> syscall_call+0x7/0xb 
> > > 
> > > Looking at the code, it looks like its not handle HOLE correctly.
> > > It ends up returning -EIO.
> > 
> > Strange.  The fs should be spewing these warnings all over the place.  For
> > some reason this code is hard to trigger.  Why??
> 
> I guess - ext3_getblk() mostly used by ext3_bread() and most callers 
> to it would be reading already allocated block.

OK.

> > 
> > > -	if (err == 1) {
> > > +	/*
> > > +	 * ext3_get_blocks_handle() returns number of blocks
> > > +	 * mapped. 0 in case of a HOLE.
> > > +	 */
> > > +	if (err > 0) {
> > >  		err = 0;
> > > -	} else if (err >= 0) {
> > > -		WARN_ON(1);
> > > -		err = -EIO;
> > >  	}
> > 
> > That removes the warning if ext3_get_blocks_handle() returned a positive
> > number greater than one.  And it looks like we still need debugging support
> > in this area.
> 
> I am not sure why we need it ? All we care about is one block. If
> ext3_get_blocks_handle() returns more than one (which it shouldn't) -

The operative part is "which it shouldn't".  This code is fairly fresh, and
ext3 is paranoid.  Once it's all settled down then after a year or so we
might decide that the debugging code is no longer needed.

Then again, we have plenty of five-year-old assertions in there..


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-09-07 19:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-06 17:39 [PATCH] ext3_getblk should handle HOLE correctly Badari Pulavarty
2006-09-06 17:42 ` Dave Kleikamp
2006-09-07 18:45 ` Andrew Morton
2006-09-07 19:22   ` Badari Pulavarty
2006-09-07 19:55     ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox