All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs: fix a dio write regression
@ 2012-08-22 10:11 bo.li.liu
  2012-08-22 15:57 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: bo.li.liu @ 2012-08-22 10:11 UTC (permalink / raw)
  To: linux-btrfs

From: Liu Bo <bo.li.liu@oracle.com>

This bug is introduced by commit 3b8bde746f6f9bd36a9f05f5f3b6e334318176a9
(Btrfs: lock extents as we map them in DIO).

In dio write, we should unlock the section which we didn't do IO on in case that
we fall back to buffered write.  But we need to not only unlock the section
but also cleanup reserved space for the section.

This bug was found while running xfstests 133, with this 133 no longer complains.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/inode.c |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 7131fac..e4ab92b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5993,10 +5993,24 @@ unlock:
 	 * in the case of read we need to unlock only the end area that we
 	 * aren't using if there is any left over space.
 	 */
-	if (lockstart < lockend)
-		clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, lockend,
-				 unlock_bits, 1, 0, &cached_state, GFP_NOFS);
-	else
+	if (lockstart < lockend) {
+		if (create && len < lockend - lockstart) {
+			clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
+					 lockstart + len - 1, unlock_bits, 1, 0,
+					 &cached_state, GFP_NOFS);
+			/*
+			 * Beside unlock, we also need to cleanup reserved space
+			 * for the left range by attaching EXTENT_DO_ACCOUNTING.
+			 */
+			clear_extent_bit(&BTRFS_I(inode)->io_tree,
+					 lockstart + len, lockend, unlock_bits |
+					 EXTENT_DO_ACCOUNTING, 1, 0, NULL,
+					 GFP_NOFS);
+		} else
+			clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
+					 lockend, unlock_bits, 1, 0,
+					 &cached_state, GFP_NOFS);
+	} else
 		free_extent_state(cached_state);
 
 	free_extent_map(em);
-- 
1.7.7.6


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

* Re: [PATCH] Btrfs: fix a dio write regression
  2012-08-22 10:11 [PATCH] Btrfs: fix a dio write regression bo.li.liu
@ 2012-08-22 15:57 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2012-08-22 15:57 UTC (permalink / raw)
  To: bo.li.liu; +Cc: linux-btrfs

Hi,

a few minor style comments,

On Wed, Aug 22, 2012 at 06:11:14PM +0800, bo.li.liu@oracle.com wrote:
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -5993,10 +5993,24 @@ unlock:
>  	 * in the case of read we need to unlock only the end area that we
>  	 * aren't using if there is any left over space.
>  	 */
> -	if (lockstart < lockend)
> -		clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, lockend,
> -				 unlock_bits, 1, 0, &cached_state, GFP_NOFS);
> -	else
> +	if (lockstart < lockend) {
> +		if (create && len < lockend - lockstart) {
> +			clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
> +					 lockstart + len - 1, unlock_bits, 1, 0,
> +					 &cached_state, GFP_NOFS);
> +			/*
> +			 * Beside unlock, we also need to cleanup reserved space
> +			 * for the left range by attaching EXTENT_DO_ACCOUNTING.
> +			 */
> +			clear_extent_bit(&BTRFS_I(inode)->io_tree,
> +					 lockstart + len, lockend, unlock_bits |
> +					 EXTENT_DO_ACCOUNTING, 1, 0, NULL,

I'd prefer to see unlock_bits and the new value on one line

> +					 GFP_NOFS);
> +		} else

add { ... } around this

> +			clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
> +					 lockend, unlock_bits, 1, 0,
> +					 &cached_state, GFP_NOFS);
> +	} else

here too

>  		free_extent_state(cached_state);
>  
>  	free_extent_map(em);

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

end of thread, other threads:[~2012-08-22 15:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-22 10:11 [PATCH] Btrfs: fix a dio write regression bo.li.liu
2012-08-22 15:57 ` David Sterba

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.