public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Zorro Lang <zlang@redhat.com>
Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org
Subject: Re: [PATCH v1.1 8/8] xfs: test for premature ENOSPC with large cow delalloc extents
Date: Thu, 7 Mar 2024 15:17:48 -0800	[thread overview]
Message-ID: <20240307231748.GE1927156@frogsfrogsfrogs> (raw)
In-Reply-To: <20240302205056.saexqlexlmwpfy4e@dell-per750-06-vm-08.rhts.eng.pek2.redhat.com>

On Sun, Mar 03, 2024 at 04:50:56AM +0800, Zorro Lang wrote:
> On Fri, Mar 01, 2024 at 09:52:02AM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > On a higly fragmented filesystem a Direct IO write can fail with -ENOSPC error
> > even though the filesystem has sufficient number of free blocks.
> > 
> > This occurs if the file offset range on which the write operation is being
> > performed has a delalloc extent in the cow fork and this delalloc extent
> > begins much before the Direct IO range.
> > 
> > In such a scenario, xfs_reflink_allocate_cow() invokes xfs_bmapi_write() to
> > allocate the blocks mapped by the delalloc extent. The extent thus allocated
> > may not cover the beginning of file offset range on which the Direct IO write
> > was issued. Hence xfs_reflink_allocate_cow() ends up returning -ENOSPC.
> > 
> > This test addresses this issue.
> > 
> > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> > ---
> > v1.1: address some missing bits and remove extraneous code
> > ---
> >  common/rc          |   14 ++++++++
> >  tests/xfs/1923     |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  tests/xfs/1923.out |    8 +++++
> >  3 files changed, 108 insertions(+)
> >  create mode 100755 tests/xfs/1923
> >  create mode 100644 tests/xfs/1923.out
> > 
> > diff --git a/common/rc b/common/rc
> > index 30c44dddd9..d3a2a0718b 100644
> > --- a/common/rc
> > +++ b/common/rc
> > @@ -1873,6 +1873,20 @@ _require_scratch_delalloc()
> >  	_scratch_unmount
> >  }
> >  
> > +# Require test fs supports delay allocation.
> > +_require_test_delalloc()
> > +{
> > +	_require_command "$FILEFRAG_PROG" filefrag
> > +
> > +	rm -f $TEST_DIR/testy
> > +	$XFS_IO_PROG -f -c 'pwrite 0 64k' $TEST_DIR/testy &> /dev/null
> > +	$FILEFRAG_PROG -v $TEST_DIR/testy 2>&1 | grep -q delalloc
> > +	res=$?
> > +	rm -f $TEST_DIR/testy
> > +	test $res -eq 0 || \
> > +		_notrun "test requires delayed allocation buffered writes"
> > +}
> > +
> >  # this test needs a test partition - check we're ok & mount it
> >  #
> >  _require_test()
> > diff --git a/tests/xfs/1923 b/tests/xfs/1923
> > new file mode 100755
> > index 0000000000..7068fda64c
> > --- /dev/null
> > +++ b/tests/xfs/1923
> > @@ -0,0 +1,86 @@
> > +#! /bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +# Copyright (c) 2022-2024 Oracle.  All Rights Reserved.
> > +#
> > +# FS QA Test No. 1923
> > +#
> > +# This is a regression test for "xfs: Fix false ENOSPC when performing direct
> > +# write on a delalloc extent in cow fork".  If there is a lot of free space but
> > +# it is very fragmented, it's possible that a very large delalloc reservation
> > +# could be created in the CoW fork by a buffered write.  If a directio write
> > +# tries to convert the delalloc reservation to a real extent, it's possible
> > +# that the allocation will succeed but fail to convert even the first block of
> > +# the directio write range.  In this case, XFS will return ENOSPC even though
> > +# all it needed to do was to keep converting until the allocator returns ENOSPC
> > +# or the first block of the direct write got some space.
> > +#
> > +. ./common/preamble
> > +_begin_fstest auto quick clone
> > +
> > +_cleanup()
> > +{
> > +	cd /
> > +	rm -f $file1 $file2 $fragmentedfile
> > +}
> > +
> > +# Import common functions.
> > +. ./common/reflink
> > +. ./common/inject
> > +
> > +# real QA test starts here
> > +_fixed_by_kernel_commit d62113303d69 \
> > +	"xfs: Fix false ENOSPC when performing direct write on a delalloc extent in cow fork"
> > +
> > +# Modify as appropriate.
> > +_supported_fs xfs
> > +_require_test_program "punch-alternating"
> > +_require_test_reflink
> > +_require_xfs_io_error_injection "bmap_alloc_minlen_extent"
> > +_require_test_delalloc
> > +
> > +file1=$TEST_DIR/file1.$seq
> > +file2=$TEST_DIR/file2.$seq
> > +fragmentedfile=$TEST_DIR/fragmentedfile.$seq
> > +
> > +rm -f $file1 $file2 $fragmentedfile
> > +
> > +# COW operates on pages, so we must not perform operations in units smaller
> > +# than a page.
> > +blksz=$(_get_file_block_size $TEST_DIR)
> > +pagesz=$(_get_page_size)
> > +if (( $blksz < $pagesz )); then
> > +	blksz=$pagesz
> > +fi
> > +
> > +echo "Create source file"
> > +$XFS_IO_PROG -f -c "pwrite 0 $((blksz * 256))" $file1 >> $seqres.full
> > +
> > +sync
> > +
> > +echo "Create Reflinked file"
> > +_cp_reflink $file1 $file2 >> $seqres.full
> > +
> > +echo "Set cowextsize"
> > +$XFS_IO_PROG -c "cowextsize $((blksz * 128))" -c stat $file1 >> $seqres.full
> > +
> > +echo "Fragment FS"
> > +$XFS_IO_PROG -f -c "pwrite 0 $((blksz * 512))" $fragmentedfile >> $seqres.full
> > +sync
> > +$here/src/punch-alternating $fragmentedfile
> > +
> > +echo "Allocate block sized extent from now onwards"
> > +_test_inject_error bmap_alloc_minlen_extent 1
> > +
> > +echo "Create big delalloc extent in CoW fork"
> > +$XFS_IO_PROG -c "pwrite 0 $blksz" $file1 >> $seqres.full
> > +
> > +sync
> > +
> > +$XFS_IO_PROG -c 'bmap -elpv' -c 'bmap -celpv' $file1 >> $seqres.full
> 
> The "-c" option might get:
> 
>   $ xfs_io -c "bmap -celpv" testfile 
>   xfs_io: xfsctl(XFS_IOC_GETBMAPX) iflags=0x28 ["testfile"]: Invalid argument
> 
> It will break the golden image, can we redirect stderr to $seqres.full,
> as it's just for debug? If you agree, I can help to change that by adding
> "2>&1" at the end. Or you hope to deal with it by other method?

That's fine, I don't need the stderr output.  "&>> $seqres.full" works
just as well.

--D

> Thanks,
> Zorro
> 
> 
> > +
> > +echo "Direct I/O write at offset 3FSB"
> > +$XFS_IO_PROG -d -c "pwrite $((blksz * 3)) $((blksz * 2))" $file1 >> $seqres.full
> > +
> > +# success, all done
> > +status=0
> > +exit
> > diff --git a/tests/xfs/1923.out b/tests/xfs/1923.out
> > new file mode 100644
> > index 0000000000..a0553cf3ee
> > --- /dev/null
> > +++ b/tests/xfs/1923.out
> > @@ -0,0 +1,8 @@
> > +QA output created by 1923
> > +Create source file
> > +Create Reflinked file
> > +Set cowextsize
> > +Fragment FS
> > +Allocate block sized extent from now onwards
> > +Create big delalloc extent in CoW fork
> > +Direct I/O write at offset 3FSB
> > 
> 
> 

  reply	other threads:[~2024-03-07 23:17 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27  2:00 [PATCHSET] fstests: random fixes for v2024.02.09 Darrick J. Wong
2024-02-27  2:00 ` [PATCH 1/8] generic/604: try to make race occur reliably Darrick J. Wong
2024-02-27  4:04   ` Zorro Lang
2024-02-27  4:27     ` Darrick J. Wong
2024-02-27  4:40   ` [PATCH v1.1 " Darrick J. Wong
2024-02-27  5:15     ` Zorro Lang
2024-02-27 14:52     ` Christoph Hellwig
2024-03-02 11:44       ` Zorro Lang
2024-02-27  2:01 ` [PATCH 2/8] xfs/155: fail the test if xfs_repair hangs for too long Darrick J. Wong
2024-02-27  4:16   ` Zorro Lang
2024-02-27  4:41   ` [PATCH v1.1 " Darrick J. Wong
2024-02-27  5:14     ` Zorro Lang
2024-02-27 14:52     ` Christoph Hellwig
2024-02-27  2:01 ` [PATCH 3/8] generic/192: fix spurious timeout Darrick J. Wong
2024-02-27  4:23   ` Zorro Lang
2024-02-27  4:29     ` Darrick J. Wong
2024-02-27 14:53   ` Christoph Hellwig
2024-02-27  2:01 ` [PATCH 4/8] generic/491: increase test timeout Darrick J. Wong
2024-02-27  4:28   ` Zorro Lang
2024-02-27 14:53   ` Christoph Hellwig
2024-02-27  2:01 ` [PATCH 5/8] xfs/599: reduce the amount of attrs created here Darrick J. Wong
2024-02-27  4:33   ` Zorro Lang
2024-02-27  2:02 ` [PATCH 6/8] xfs/122: update test to pick up rtword/suminfo ondisk unions Darrick J. Wong
2024-02-27  5:10   ` Zorro Lang
2024-02-27 14:54   ` Christoph Hellwig
2024-02-28  1:27     ` Darrick J. Wong
2024-02-28 15:39       ` Christoph Hellwig
2024-02-29 17:48         ` Darrick J. Wong
2024-02-29 19:42           ` Christoph Hellwig
2024-03-01 13:18             ` Zorro Lang
2024-03-01 17:50               ` Darrick J. Wong
2024-03-02  4:55                 ` Zorro Lang
2024-03-07 23:24                   ` Darrick J. Wong
2024-02-27  2:02 ` [PATCH 7/8] xfs/43[4-6]: make module reloading optional Darrick J. Wong
2024-02-27  5:31   ` Zorro Lang
2024-02-28  1:28     ` Darrick J. Wong
2024-03-01 17:51   ` [PATCH v1.1 " Darrick J. Wong
2024-03-02 12:04     ` Zorro Lang
2024-02-27  2:02 ` [PATCH 8/8] xfs: test for premature ENOSPC with large cow delalloc extents Darrick J. Wong
2024-02-27  6:00   ` Zorro Lang
2024-02-28  1:36     ` Darrick J. Wong
2024-03-01 17:52   ` [PATCH v1.1 " Darrick J. Wong
2024-03-02 20:50     ` Zorro Lang
2024-03-07 23:17       ` Darrick J. Wong [this message]
2024-03-07 23:22   ` [PATCH v1.2 " Darrick J. Wong
2024-03-10  9:17     ` Zorro Lang
2024-03-10 16:26       ` Darrick J. Wong
2024-03-11 13:40         ` Zorro Lang
2024-03-11 15:04           ` Darrick J. Wong
2024-03-03 13:34 ` [PATCHSET] fstests: random fixes for v2024.02.09 Zorro Lang
2024-03-07 23:18   ` Darrick J. Wong

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=20240307231748.GE1927156@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=fstests@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=zlang@redhat.com \
    /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