Linux-NFS Archive mirror
 help / color / mirror / Atom feed
From: Trond Myklebust <trondmy@kernel.org>
To: Olga Kornievskaia <okorniev@redhat.com>, anna@kernel.org
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH v2 1/1] NFS: fix writeback in presence of errors
Date: Mon, 13 Apr 2026 13:55:34 -0700	[thread overview]
Message-ID: <3f2666aec2649cc8cf2fc0524612b73936b3b17b.camel@kernel.org> (raw)
In-Reply-To: <20260325180050.55186-1-okorniev@redhat.com>

Hi Olga,

On Wed, 2026-03-25 at 14:00 -0400, Olga Kornievskaia wrote:
> After running xfstest generic/751, in certain conditions, can have
> a writeback IO stuck while experiencing one of the two patterns.
> 
> Pattern#1: writeback IO experiences ENOSPC on an offset smaller
> than the filesize. Example,
> write offset=0 len=4096 how=unstable OK
> write offset=8192 len=4096 how=unstable OK
> write offset=12288 len=4096 how=unstable ENOSPC
> write offset=4096 len=4096 how=unstable ENOSPC
> client sends a commit and receives a verifier which is different
> from the last successful write. It marks pages dirty and writeback
> retries. But it again send writes unstable and gets into the same
> pattern, running into the ENOSPC error and sending a commit because
> writes were sent at unstable.
> 
> Pattern#2: an unstable write followed by a short write and ENOSPC.
> write offset=0 len=4096 how=unstable OK
> write offset=4096 len=4096 how=unstable returns OK but count=100
> write offset=4197 len=3996 how=stable returns ENOSPC
> client send a commit and receives a verifier different from
> the last unstable write. The same behaviour is retried in a loop.
> 
> Instead, this patch proposes to identify those conditions and mark
> requests to be done synchronously instead. Previous solution tried
> to mark it in the nfs_page, however that's not persistent thus
> instead mark it in the nfs_open_context.
> 
> Furthermore, the same problem occurs during localio code path so
> recognize that IO needs to be done sync in that case as well.
> 
> Signed-off-by: Olga Kornievskaia <okorniev@redhat.com>
> ---
>  fs/nfs/localio.c       | 10 ++++++++++
>  fs/nfs/pagelist.c      |  3 +++
>  fs/nfs/write.c         |  9 +++++++++
>  include/linux/nfs_fs.h |  1 +
>  4 files changed, 23 insertions(+)
> 
> diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c
> index 4c7d16a99ed6..d4f04534966a 100644
> --- a/fs/nfs/localio.c
> +++ b/fs/nfs/localio.c
> @@ -883,6 +883,13 @@ static void nfs_local_call_write(struct
> work_struct *work)
>  		/* Break on completion, errors, or short writes */
>  		if (nfs_local_pgio_done(iocb, status) || status < 0
> ||
>  		    (size_t)status < iov_iter_count(&iocb-
> >iters[i])) {
> +			if ((size_t)status < iov_iter_count(&iocb-
> >iters[i])) {

Can we please do something to avoid 2 calls to iov_iter_count() here?

> +				struct nfs_lock_context *ctx =
> +					iocb->hdr->req-
> >wb_lock_context;
> +
> +				set_bit(NFS_CONTEXT_WRITE_SYNC,
> +					&ctx->open_context->flags);
> +			}
>  			nfs_local_write_iocb_done(iocb);
>  			break;
>  		}
> @@ -901,6 +908,9 @@ static void nfs_local_do_write(struct
> nfs_local_kiocb *iocb,
>  		__func__, hdr->args.count, hdr->args.offset,
>  		(hdr->args.stable == NFS_UNSTABLE) ?  "unstable" :
> "stable");
>  
> +	if (test_bit(NFS_CONTEXT_WRITE_SYNC,
> +		     &hdr->req->wb_lock_context->open_context-
> >flags))
> +		hdr->args.stable = NFS_FILE_SYNC;
>  	switch (hdr->args.stable) {
>  	default:
>  		break;
> diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
> index a9373de891c9..4a87b2fdb2e6 100644
> --- a/fs/nfs/pagelist.c
> +++ b/fs/nfs/pagelist.c
> @@ -1186,6 +1186,9 @@ static int __nfs_pageio_add_request(struct
> nfs_pageio_descriptor *desc,
>  
>  	nfs_page_group_lock(req);
>  
> +	if (test_bit(NFS_CONTEXT_WRITE_SYNC,
> +		     &req->wb_lock_context->open_context->flags))
> +		desc->pg_ioflags |= FLUSH_STABLE;
>  	subreq = req;
>  	subreq_size = subreq->wb_bytes;
>  	for(;;) {
> diff --git a/fs/nfs/write.c b/fs/nfs/write.c
> index 1ed4b3590b1a..ddae197d2d3f 100644
> --- a/fs/nfs/write.c
> +++ b/fs/nfs/write.c
> @@ -927,9 +927,13 @@ static void nfs_write_completion(struct
> nfs_pgio_header *hdr)
>  			goto remove_req;
>  		}
>  		if (nfs_write_need_commit(hdr)) {
> +			struct nfs_open_context *ctx =
> +				hdr->req->wb_lock_context-
> >open_context;
> +
>  			/* Reset wb_nio, since the write was
> successful. */
>  			req->wb_nio = 0;
>  			memcpy(&req->wb_verf, &hdr->verf.verifier,
> sizeof(req->wb_verf));
> +			clear_bit(NFS_CONTEXT_WRITE_SYNC, &ctx-
> >flags);
>  			nfs_mark_request_commit(req, hdr->lseg,
> &cinfo,
>  				hdr->ds_commit_idx);
>  			goto next;
> @@ -1553,7 +1557,10 @@ static void nfs_writeback_result(struct
> rpc_task *task,
>  
>  	if (resp->count < argp->count) {
>  		static unsigned long    complain;
> +		struct nfs_open_context *ctx =
> +			hdr->req->wb_lock_context->open_context;
>  
> +		set_bit(NFS_CONTEXT_WRITE_SYNC, &ctx->flags);
>  		/* This a short write! */
>  		nfs_inc_stats(hdr->inode, NFSIOS_SHORTWRITE);
>  
> @@ -1837,6 +1844,8 @@ static void nfs_commit_release_pages(struct
> nfs_commit_data *data)
>  		/* We have a mismatch. Write the page again */
>  		dprintk(" mismatch\n");
>  		nfs_mark_request_dirty(req);
> +		set_bit(NFS_CONTEXT_WRITE_SYNC,
> +			&req->wb_lock_context->open_context->flags);
>  		atomic_long_inc(&NFS_I(data->inode)-
> >redirtied_pages);
>  	next:
>  		nfs_unlock_and_release_request(req);
> diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
> index 8dd79a3f3d66..4623262da3c0 100644
> --- a/include/linux/nfs_fs.h
> +++ b/include/linux/nfs_fs.h
> @@ -109,6 +109,7 @@ struct nfs_open_context {
>  #define NFS_CONTEXT_BAD			(2)
>  #define NFS_CONTEXT_UNLOCK	(3)
>  #define NFS_CONTEXT_FILE_OPEN		(4)
> +#define NFS_CONTEXT_WRITE_SYNC		(5)
>  
>  	struct nfs4_threshold	*mdsthreshold;
>  	struct list_head list;

Otherwise, the rest looks good to me.

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trondmy@kernel.org, trond.myklebust@hammerspace.com

      reply	other threads:[~2026-04-13 20:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-25 18:00 [PATCH v2 1/1] NFS: fix writeback in presence of errors Olga Kornievskaia
2026-04-13 20:55 ` Trond Myklebust [this message]

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=3f2666aec2649cc8cf2fc0524612b73936b3b17b.camel@kernel.org \
    --to=trondmy@kernel.org \
    --cc=anna@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=okorniev@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).