linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: fix truncate down when no_holes feature is enabled
@ 2016-11-11 22:27 Liu Bo
  2016-11-22 19:13 ` Chris Mason
  0 siblings, 1 reply; 4+ messages in thread
From: Liu Bo @ 2016-11-11 22:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba, Filipe Manana

For such a file mapping,

[0-4k][hole][8k-12k]

In NO_HOLES mode, we don't have the [hole] extent any more.
Commit c1aa45759e90 ("Btrfs: fix shrinking truncate when the no_holes feature is enabled")
 fixed disk isize not being updated in NO_HOLES mode when data is not flushed.

However, even if data has been flushed, we can still have trouble
in updating disk isize since we updated disk isize to 'start' of
the last evicted extent.

Also add a ASSERT for better catching (for developers only).

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/inode.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 2b790bd..603dd492 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4483,8 +4483,19 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
 		if (found_type > min_type) {
 			del_item = 1;
 		} else {
-			if (item_end < new_size)
+			if (item_end < new_size) {
+				/*
+				 * With NO_HOLES mode, for the following mapping
+				 *
+				 * [0-4k][hole][8k-12k]
+				 *
+				 * if truncating isize down to 6k, it ends up
+				 * isize being 8k.
+				 */
+				if (btrfs_fs_incompat(root->fs_info, NO_HOLES))
+					last_size = new_size;
 				break;
+			}
 			if (found_key.offset >= new_size)
 				del_item = 1;
 			else
@@ -4666,6 +4677,9 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
 			btrfs_abort_transaction(trans, ret);
 	}
 error:
+	if (err == 0)
+		ASSERT(last_size == new_size);
+
 	if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID)
 		btrfs_ordered_update_i_size(inode, last_size, NULL);
 
-- 
2.5.5


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

* Re: [PATCH] Btrfs: fix truncate down when no_holes feature is enabled
  2016-11-11 22:27 [PATCH] Btrfs: fix truncate down when no_holes feature is enabled Liu Bo
@ 2016-11-22 19:13 ` Chris Mason
  2016-11-22 20:08   ` Liu Bo
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Mason @ 2016-11-22 19:13 UTC (permalink / raw)
  To: Liu Bo, linux-btrfs; +Cc: David Sterba, Filipe Manana

On 11/11/2016 05:27 PM, Liu Bo wrote:
> For such a file mapping,
>
> [0-4k][hole][8k-12k]
>
> In NO_HOLES mode, we don't have the [hole] extent any more.
> Commit c1aa45759e90 ("Btrfs: fix shrinking truncate when the no_holes feature is enabled")
>  fixed disk isize not being updated in NO_HOLES mode when data is not flushed.
>
> However, even if data has been flushed, we can still have trouble
> in updating disk isize since we updated disk isize to 'start' of
> the last evicted extent.
>
> Also add a ASSERT for better catching (for developers only).
>
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>

Thanks Liu!

Reviewed-by: Chris Mason <clm@fb.com>

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

* Re: [PATCH] Btrfs: fix truncate down when no_holes feature is enabled
  2016-11-22 19:13 ` Chris Mason
@ 2016-11-22 20:08   ` Liu Bo
  2016-11-23 16:55     ` David Sterba
  0 siblings, 1 reply; 4+ messages in thread
From: Liu Bo @ 2016-11-22 20:08 UTC (permalink / raw)
  To: Chris Mason; +Cc: linux-btrfs, David Sterba, Filipe Manana

On Tue, Nov 22, 2016 at 02:13:21PM -0500, Chris Mason wrote:
> On 11/11/2016 05:27 PM, Liu Bo wrote:
> > For such a file mapping,
> > 
> > [0-4k][hole][8k-12k]
> > 
> > In NO_HOLES mode, we don't have the [hole] extent any more.
> > Commit c1aa45759e90 ("Btrfs: fix shrinking truncate when the no_holes feature is enabled")
> >  fixed disk isize not being updated in NO_HOLES mode when data is not flushed.
> > 
> > However, even if data has been flushed, we can still have trouble
> > in updating disk isize since we updated disk isize to 'start' of
> > the last evicted extent.
> > 
> > Also add a ASSERT for better catching (for developers only).
> > 
> > Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> 
> Thanks Liu!
> 
> Reviewed-by: Chris Mason <clm@fb.com>

The added ASSERT() can cause generic/068 to crash because I didn't
filter out the 'log tree' case, I'm testing a V2 patch.

Thanks,

-liubo

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

* Re: [PATCH] Btrfs: fix truncate down when no_holes feature is enabled
  2016-11-22 20:08   ` Liu Bo
@ 2016-11-23 16:55     ` David Sterba
  0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2016-11-23 16:55 UTC (permalink / raw)
  To: Liu Bo; +Cc: Chris Mason, linux-btrfs, David Sterba, Filipe Manana

On Tue, Nov 22, 2016 at 12:08:47PM -0800, Liu Bo wrote:
> On Tue, Nov 22, 2016 at 02:13:21PM -0500, Chris Mason wrote:
> > On 11/11/2016 05:27 PM, Liu Bo wrote:
> > > For such a file mapping,
> > > 
> > > [0-4k][hole][8k-12k]
> > > 
> > > In NO_HOLES mode, we don't have the [hole] extent any more.
> > > Commit c1aa45759e90 ("Btrfs: fix shrinking truncate when the no_holes feature is enabled")
> > >  fixed disk isize not being updated in NO_HOLES mode when data is not flushed.
> > > 
> > > However, even if data has been flushed, we can still have trouble
> > > in updating disk isize since we updated disk isize to 'start' of
> > > the last evicted extent.
> > > 
> > > Also add a ASSERT for better catching (for developers only).
> > > 
> > > Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> > 
> > Thanks Liu!
> > 
> > Reviewed-by: Chris Mason <clm@fb.com>
> 
> The added ASSERT() can cause generic/068 to crash because I didn't
> filter out the 'log tree' case, I'm testing a V2 patch.

I've hit the assert with btrfs/003, once and not deterministically in a VM.

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

end of thread, other threads:[~2016-11-23 16:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-11 22:27 [PATCH] Btrfs: fix truncate down when no_holes feature is enabled Liu Bo
2016-11-22 19:13 ` Chris Mason
2016-11-22 20:08   ` Liu Bo
2016-11-23 16:55     ` David Sterba

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).