Re: [PATCH] btrfs: refactor how we prepare pages for btrfs_buffered_write()

David Sterba
2020-08-13T11:23:21Z

On Thu, Aug 13, 2020 at 07:16:48PM +0800, Qu Wenruo wrote:
> > @@ -1763,11 +1771,9 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
> > nrptrs = 1;
> >
> > if (copied == 0) {
> > - force_page_uptodate = true;
>
> This is here to prevent the following problem:
>
> One page is completely covered by write range, but the write range
> inside the page is split into two iov.
>
> In that case, if the later part failed to be copied, we will hit a short
> write.
> Originally we will set force_page_uptodate, then falls back to nrptrs =
> 1; with force_page_uptodate = true;
>
> Then in the next loop, we will force to read that full page to avoid
> garbage in the partial written page.
>
> This is indeed super rare, thus all my fstests run haven't triggered it.
> But in theory, as long as we have differnt iovs supported, it should
> still be possible.

I wouldn't count on fstests to trigger corner cases, for that we need
long running stress tests. Good that you can identify the rare cases
while the patch is still in development, catching such bugs later is
much harder.