Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796306230; b=pp1HGkVAAa973/zRsUwZgr1oHVsWscGeUc8vqjys/uAttcyM8F0DPRmzciahD2JTPyx3 aLkiW4cyIfgL4JrRR4BcbNRtKJI4JF9ihvyEA8UuftUh+B9T1leqDm9gedp47faFljsde rCWo6gRkk9OG3TsyIith1g70bnDl0o409OndcVYRUZN86u1EZWdxrpim2bF8jOkVkZvT0 zKB4z6jyJ0fLP2IBaTuPkkA99cAM2y189LWa6B0Kok3ni1/FvAbAsE5oROSxQFUkf2BXr PUyXR1mEiSZ8QkXoYHOfmG2dtcWQFJG6KY+Tg0UMEifoKIAQAwxdQWuwKUgc25CJ1nA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796306230; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=lD00AUZcXkU23QZ6ZFEievVgDsgzVLXgwRweB29cubI=; b=wxiSzRQnuqX6NgETWxhxZmHcbOZHOBhjR4pfQZkxw571gN6Kff++nw72cpeaLXxXQ5kd TCzXVomRQ+xyn+sgs2FlpgL/L+TIPv0zwYJdsiopx04k7PLkjaA3ak8sLyjvXsAer7iSY hvzBGJ1DFxd1/Kj8mUxy8KPl/lfsz4vlrRsuoDkQLl95sHvMsAiox50LvBztjtHweQWnV PndmUsWZOzXyoKKuSa9uGW5d4yNL5w/eD0M/zEQHtMSU/Befl2Immx88sswt6IAlYL1rJ fDEC3g5z6oE0BxgWcdY6OBOQRev4p88N/osGSqNeQGt+/VlEqFqJBDq46IlEBSWTUKQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=hammerspace.com; spf=pass smtp.mailfrom=hammerspace.com; dkim=pass header.d=hammerspace.com header.i=@hammerspace.com header.a=rsa-sha256 header.s=google header.b=TNIqInfP; arc=none smtp.remote-ip=209.85.167.169 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 884FD606A332 for ; Thu, 3 Dec 2026 13:57:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 884FD606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hammerspace.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hammerspace.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hammerspace.com header.i=@hammerspace.com header.a=rsa-sha256 header.s=google header.b=TNIqInfP Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-57297329b3eso7243400b6e.0 for ; Thu, 03 Dec 2026 05:57:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hammerspace.com; s=google; t=1796306229; x=1796911029; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lD00AUZcXkU23QZ6ZFEievVgDsgzVLXgwRweB29cubI=; b=TNIqInfPGO4KOiuUcFhwnNsHjOCmg10tEi4Vbed/G0YR6kinFMfqeOvcmLNsmzZcVM GoOCqgup7iqMDGOTDFF/OdDakGubCACkndxI1jvE7p5nt9eWChEpxB2DA7uS24XICr3S W73ZnWmFuG2j3mT60Y7lZPWLhDQ9gazmPHXZaSkRF1K/A1CB8DfOT7kjltGd6D8vyY8A DCPcrYCPVu7UcDIhnZJ7inXSp51Nt3mzNN9rXQY9voHyDIKkhwto+WJ1v5cy0zBSjzH3 YZwrsNM+xYY5qI/Fxa/csOOvpABEuqWABNme0ywvhOCh3K7y4zXH00ibEaCC6qJJqLFi dxWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796306229; x=1796911029; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=lD00AUZcXkU23QZ6ZFEievVgDsgzVLXgwRweB29cubI=; b=PtcTn9ukxlf9MtPgoXQOPD3WvREWLu17ouPiXVTxnKu6zzX03xFcu3kut9A4KjD+6d 6uP2NqMRvLz8wZdGTnzfV0aUx4hO+owoaiEROMQaWRemak1NUJyFJ3F7Blyrq4iX3N64 r9b1LN4Q4RgE3xCPs2m8GayOU7AWia0nkYFgD8mZEW7rXCRKGwKS+U12NdXaU6VHCHi4 RUFNwGV1RtMgP5IaAe1UZaKpzeV9ElK0hqvXjk/G8oyzhWqjUH+fFpRqFbpjAa7S58Kp HD4qzh/9JiNkV0FpIj9pVtzzLOf6aUDzk1z4vZukA9Mw99UzCK3gKtaXwqYpcKG/k1Bl xyFw== X-Forwarded-Encrypted: i=1; AL+hErE9T4faTxBssFdb9/OWDs2iERcqrbJVnnmUEPwOgslJuT/fcUPEBnRLLpyha5eSsDnNpjEcqCbytFM=@vger.kernel.org X-Gm-Message-State: APuU4Z/7BwQuMmLq9nXwAtsQjla25osewSorSXrZhUT/hOrJXsYtKo9c 3PWFmiO6qQ29VzXcEH6SbjL8P6RF0h9JUTMxHFpjnEuJy1g3wUM7eShyRLZD9+Fj5Ck= X-Gm-Gg: AZFdTZcejdbmwpurjDMrVfmJZe+xr6Q564ulRhzgfL048QTM3uTIbH3S0vopC3nI26P hgECZJAjDX401DMUd3RfDBAZ4UI+YSu7hxPRugDHGdCextfLkVzNF7VpfkMn/TgvBcRIZcim8ez A3zM/PH9pwtUmPZA5FNForVsQ2gQ+T16C6BK+ulLZI+Zwgk2iccOs6Lb3gs9WGI22kUsgbFEpZJ swc74bQzrHdOq9gxBa+7+4tV3I55AjisgEFwLVhL3k7yQ95vkQ7DRU8GeQbze/H97pvhT0TaSvQ zambAqzrugH2E334wnMWsKBAJ0KirLVma0eU9BtOs4RL/Gcn/s3+XgxLfYVp3HLu3954Xl9TTyW izExqfKFbqgBri2DKEOkmeFf4yoHuuO4LUAmbL7P3+EmMfa/FY51ssCPGu0wfls8C21OiOMMQAj xEhtYlmdPrFI47byPVI9y2tQ4w4s6PJ1Vnjx9U3GEWHodUNXKwJAZB2a14MHOAatKPCdaT4wUKr gzA8maYVmdLyphUs0o8+/PlE6Ex6xX4BXDF1BSzTDet2vwAgRPtmCM6mpAt9zYlX3gfOXpw5mHN PHnKOEBPPUtZKbW/ad+ITWDJ3F99wvQAJ4vK0e29t8vAyx5Na2CRshrlyCMQ0EqemxEruauz X-Received: by 2002:a05:6808:c3d2:b0:4e9:3412:14ac with SMTP id 5614622812f47-57a0af3421bmr46581711b6e.33.1796306229421; Thu, 03 Dec 2026 05:57:09 -0800 (PST) Received: from bcodding.csb.hammerspace.com ([66.97.168.37]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57a350548ffsm30973955b6e.11.2026.12.03.05.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:57:09 -0800 (PST) From: Benjamin Coddington To: Trond Myklebust , Anna Schumaker , Mike Snitzer Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v4 01/11] NFS: resend O_DIRECT write requests that error cleanup gets with -EAGAIN Date: Thu, 3 Dec 2026 08:56:56 -0500 Message-ID: <800dceb7f4876ff11c2424da73bc05fc1ce95b58.1796306148.git.bcodding@hammerspace.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Benjamin Coddington A layout driver's pg_init can fail a descriptor with -EAGAIN while it still holds queued requests; flexfiles does this when the mirror count changes. nfs_pageio_error_cleanup() hands those requests to error_cleanup, and for O_DIRECT writes nfs_write_sync_pgio_error() just unlocks and releases them. nfs_direct_write_schedule_iovec() treats -EAGAIN as soft and defers only the request it was adding, so the queued requests, already counted in requested_bytes, are never written and no error is reported. Pass the descriptor's nfs_direct_req to error_cleanup. On -EAGAIN, put the O_DIRECT write requests on the commit list and set NFS_ODIRECT_RESCHED_WRITES so the write completion resends them. Move that code out of nfs_direct_write_reschedule_io() into nfs_direct_write_requeue() and use it in both places. This also changes the other -EAGAIN cleanups of O_DIRECT write requests: the requests queued in nfs_direct_write_reschedule()'s descriptor, a mirror copy cleaned up by nfs_pageio_cleanup_request(), and the pages left over when nfs_pageio_resend() fails with -EAGAIN are all requeued rather than released. Fixes: 954998b60caa ("NFS: Fix error handling for O_DIRECT write scheduling") Cc: stable@vger.kernel.org # v6.6+ Signed-off-by: Benjamin Coddington --- fs/nfs/direct.c | 48 +++++++++++++++++++++++++---------------- fs/nfs/pagelist.c | 7 +++--- fs/nfs/read.c | 3 ++- fs/nfs/write.c | 5 +++-- include/linux/nfs_xdr.h | 3 ++- 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index a3c6e8f4ea06..c771bb1b0730 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -330,7 +330,8 @@ static void nfs_direct_read_completion(struct nfs_pgio_header *hdr) hdr->release(hdr); } -static void nfs_read_sync_pgio_error(struct list_head *head, int error) +static void nfs_read_sync_pgio_error(struct list_head *head, int error, + struct nfs_direct_req *dreq) { nfs_release_request_list(head); } @@ -818,39 +819,50 @@ static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) hdr->release(hdr); } -static void nfs_write_sync_pgio_error(struct list_head *head, int error) +static void nfs_direct_write_requeue(struct nfs_direct_req *dreq, + struct list_head *head) { + struct nfs_commit_info cinfo; struct nfs_page *req; + nfs_init_cinfo_from_dreq(&cinfo, dreq); + spin_lock(&dreq->lock); + if (dreq->error == 0) + dreq->flags = NFS_ODIRECT_RESCHED_WRITES; + spin_unlock(&dreq->lock); while (!list_empty(head)) { req = nfs_list_entry(head->next); nfs_list_remove_request(req); - nfs_unlock_and_release_request(req); + nfs_unlock_request(req); + nfs_mark_request_commit(req, NULL, &cinfo, 0); } } -static void nfs_direct_write_reschedule_io(struct nfs_pgio_header *hdr) +static void nfs_write_sync_pgio_error(struct list_head *head, int error, + struct nfs_direct_req *dreq) { - struct nfs_direct_req *dreq = hdr->dreq; struct nfs_page *req; - struct nfs_commit_info cinfo; - - trace_nfs_direct_write_reschedule_io(dreq); - nfs_init_cinfo_from_dreq(&cinfo, dreq); - spin_lock(&dreq->lock); - if (dreq->error == 0) - dreq->flags = NFS_ODIRECT_RESCHED_WRITES; - set_bit(NFS_IOHDR_REDO, &hdr->flags); - spin_unlock(&dreq->lock); - while (!list_empty(&hdr->pages)) { - req = nfs_list_entry(hdr->pages.next); + /* -EAGAIN: requests already counted by the caller must be resent */ + if (error == -EAGAIN) { + nfs_direct_write_requeue(dreq, head); + return; + } + while (!list_empty(head)) { + req = nfs_list_entry(head->next); nfs_list_remove_request(req); - nfs_unlock_request(req); - nfs_mark_request_commit(req, NULL, &cinfo, 0); + nfs_unlock_and_release_request(req); } } +static void nfs_direct_write_reschedule_io(struct nfs_pgio_header *hdr) +{ + trace_nfs_direct_write_reschedule_io(hdr->dreq); + + set_bit(NFS_IOHDR_REDO, &hdr->flags); + nfs_direct_write_requeue(hdr->dreq, &hdr->pages); +} + static const struct nfs_pgio_completion_ops nfs_direct_write_completion_ops = { .error_cleanup = nfs_write_sync_pgio_error, .init_hdr = nfs_direct_pgio_init, diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index c76c32a33be5..0bb18acaf872 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -1209,7 +1209,8 @@ nfs_pageio_cleanup_request(struct nfs_pageio_descriptor *desc, LIST_HEAD(head); nfs_list_move_request(req, &head); - desc->pg_completion_ops->error_cleanup(&head, desc->pg_error); + desc->pg_completion_ops->error_cleanup(&head, desc->pg_error, + desc->pg_dreq); } /** @@ -1340,7 +1341,7 @@ static void nfs_pageio_error_cleanup(struct nfs_pageio_descriptor *desc) for (midx = 0; midx < desc->pg_mirror_count; midx++) { mirror = nfs_pgio_get_mirror(desc, midx); desc->pg_completion_ops->error_cleanup(&mirror->pg_list, - desc->pg_error); + desc->pg_error, desc->pg_dreq); } } @@ -1443,7 +1444,7 @@ int nfs_pageio_resend(struct nfs_pageio_descriptor *desc, nfs_pageio_complete(desc); if (!list_empty(&pages)) { int err = desc->pg_error < 0 ? desc->pg_error : -EIO; - hdr->completion_ops->error_cleanup(&pages, err); + hdr->completion_ops->error_cleanup(&pages, err, hdr->dreq); nfs_set_pgio_error(hdr, err, hdr->io_start); return err; } diff --git a/fs/nfs/read.c b/fs/nfs/read.c index 1fdca07761f6..ad9e948f4cb1 100644 --- a/fs/nfs/read.c +++ b/fs/nfs/read.c @@ -220,7 +220,8 @@ static void nfs_initiate_read(struct nfs_pgio_header *hdr, } static void -nfs_async_read_error(struct list_head *head, int error) +nfs_async_read_error(struct list_head *head, int error, + struct nfs_direct_req *dreq) { struct nfs_page *req; diff --git a/fs/nfs/write.c b/fs/nfs/write.c index af8735d0d67f..7967487e026c 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -1378,7 +1378,8 @@ static void nfs_redirty_request(struct nfs_page *req) nfs_release_request(req); } -static void nfs_async_write_error(struct list_head *head, int error) +static void nfs_async_write_error(struct list_head *head, int error, + struct nfs_direct_req *dreq) { struct nfs_page *req; @@ -1394,7 +1395,7 @@ static void nfs_async_write_error(struct list_head *head, int error) static void nfs_async_write_reschedule_io(struct nfs_pgio_header *hdr) { - nfs_async_write_error(&hdr->pages, 0); + nfs_async_write_error(&hdr->pages, 0, NULL); } static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops = { diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h index c0e29b4dfa62..fce0e773bd7b 100644 --- a/include/linux/nfs_xdr.h +++ b/include/linux/nfs_xdr.h @@ -1742,7 +1742,8 @@ struct nfs_commit_data { }; struct nfs_pgio_completion_ops { - void (*error_cleanup)(struct list_head *head, int); + void (*error_cleanup)(struct list_head *head, int error, + struct nfs_direct_req *dreq); void (*init_hdr)(struct nfs_pgio_header *hdr); void (*completion)(struct nfs_pgio_header *hdr); void (*reschedule_io)(struct nfs_pgio_header *hdr); -- 2.53.0