Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796055091; b=5JonzUGOhTDy1ak1ir8HToSzCB5Jp5BLMLr17DBDQJEdTz/cgD8y0M5WOtahmBdLKhIB CeTdzzHNnS6Vj55goUqdu2hjeWKoB7XEmvbv44hyBpuFqq3+0KW7NR9liAxyLKQrP5JFl YeBFwxXqP6dON7MoDb9bhX4kXSqblUPH9Ipb58CmaQyGOEGwFVkFkMaLjIQBpFDuIBJKX wekJlLMSi0uRlQca5fMu2WZZTdgjJQ+2B3BD5lDHUzPJrDMAxxRRzXd3Fcbc584CK2k9X slFdwP1dirlQm6t6fa+R1RRLSSLGyOEpYOSDJtj1hSKUnzFJZVBmEat3VCIdQyxTZ2g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796055091; 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=nFOi4zwW3bfVYVdXZoXjRSngjxlUbfQ5Itz8e16Cpmw=; b=jDJOrP9KPF85SMwCmTLCU/psqLjL7xvbIhAGYTx8r+wmOkUOKKuszdhQJvl24YDf8nK0 2tR6cG1vkzunmT32t+RtMMj+mLOLu6V1AqZ26hlreMwErp5zS4buFQoqSdXAtQ0eOpaWL I3lV4hCTyt5fms8cTTtIHMv+E4O3I7a0x709RkLuhxNOncwqb4Fe03w5LpWOdPcO9XNS3 V7nkJyqPKQ4P7yEKdri4Iz5eDyurgmauHr/Sz3rP6FmySrs5tr0haUEKfihSPGAc0W2cV nnoyZBMzCs7ROCf6mRfzfHwg7aaNNfaUy8u3/8oDBqURlLQwICni/5s4E/pJzDVlG0w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=lists.scylladb.com; spf=pass smtp.mailfrom=scylladb.com; dkim=pass header.d=lists.scylladb.com header.i=@lists.scylladb.com header.a=rsa-sha256 header.s=google header.b=oWfcWy3z; arc=none smtp.remote-ip=209.85.218.51 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 C7FC0606A325 for ; Mon, 30 Nov 2026 16:11:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C7FC0606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lists.scylladb.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=scylladb.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.scylladb.com header.i=@lists.scylladb.com header.a=rsa-sha256 header.s=google header.b=oWfcWy3z Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-c51a14bd405so726662066b.2 for ; Mon, 30 Nov 2026 08:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.scylladb.com; s=google; t=1796055089; x=1796659889; 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=nFOi4zwW3bfVYVdXZoXjRSngjxlUbfQ5Itz8e16Cpmw=; b=oWfcWy3z4BOJWwDoHMYb/8jpqCmQEpgSatwuSE6acam8oid3DHpplY98ifnLqpxFcY v3D4VgKXP+ZdN0tuuO8Ts+lsm0TGWeyptFfhyzwdbF9jhD4oTcOTm2tYdElkye6AKn0H jYeelB7oMPVgCxWCHovSG8uqxeMCHEcqcQk8L7jG7UD0+1/ofd0lx1/f46PDHPvPGkCP 1qf4ityHM4s3tJ2fclFuL4Q9gUg4ej1lNRqOQvPrF5be4490yr9G7MaE5F+jRUfz9E9q G+ofp9t9hi0egSYjlpgBFuzyuj9eB80S6JMFWfi2MZpge+plBfcY1Ql2bSzJxbQMAjdT JFQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796055089; x=1796659889; 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=nFOi4zwW3bfVYVdXZoXjRSngjxlUbfQ5Itz8e16Cpmw=; b=LF7MPhO9KoOOkdszz9ps4xsybTGxDZV0YNVvHfH6E2cu61Y9DYGI2kd5Hpd7ecimPJ Ia8XHbJobcEQm3d7Ez5ZzOLLDAr1ubNX3PMOxN0dRctBR1H9P/du089I++Cr8BnGoRzK IRSgOMMC0kYOvhC8nZEEgwYFl0+fkZRQPPwYy73UYvhkUj08QuzOAg0WNHXu4SaJ8Ztc UyZA6pYDq/C5sZPInk6asn7tL2jongiP7vsj+mcWd8+CSTnqvQThRPvFYsRySlJTWFhS zPttANhx83edgvoW2StsZghgAhCkIwxaXcLbyuXPaDQID8p2iCU5+pJ8ekGuIfBxYWqx AV6w== X-Forwarded-Encrypted: i=1; AL+hErG/fnElieaHPwEP3u4zEpNealPJVYIOfY3qUL/Ef7dWQO1L6K7Ra0P6RnPqt2Kle2pqgzYMhpevRA==@vger.kernel.org X-Gm-Message-State: APuU4Z/d/tdnRPN/DaSZn5ZzBEvbeP3eSX7l5iKeL4bgF67ZdLiXKIM1 mp81hlMIZQupRqg3iMrpUclhrbH9q9KPCjex+OveXUzGKXzr7TTja5atu1NJrHsVWqU= X-Gm-Gg: AZFdTZdnmGMwuC/wXSAHqLXIXIC/XwyCe5skPTn5p/vSSMXyZ1OlZQH6rlv0yUvk8gt 9pr8ssbOaj8DCGA1p5BMWLaBanoRr1trcq2EJDJ69nu4TTutjDGeZbG9wxOmsbcRkhXNjtskHAn njYMRQOzLFqr1BeApGxRVzr8RfO7N4/62Ylg4A4ILlIuooVC9SKJnYtQO6hmYOHfbVtSKOSWrob 9lkayGXmoG0/lxwgGtQbl/gm/YRZwxgvFPeYf54si/15hR+M6POBSMZbqGsWW0PSeKAwxOP76cm nkqRIWjewaDGxSBo6X3nigPirjVK6rWGB/S12QuH5q5nxmzwmV8bamANKyJGikVNJTBTddBeMvF /5JOiTCOUBlXlZCRyboGn37KV7292hQDSieaJlIJ8JY8gHegktc0zzyQogyF10XCX9Ff/21Fol7 WnFfJbFrCucbaGIn9AOEFsRc/jLAn0VdhUiZqFKe0a2VnoHtMbjG7nstnnt7E8yZ17w7pbuFGpf B5Aa3hhnHLPtVFrct83gfa4l/JIqRcc7NtAxo5mCuMy3pr9gNjAPucBWDob/z6mZmyoCXGlebxa E23u4I2zJ7ZzitGqQ7ZWazpV3ijJys7NsKymJq3TKqgXuOkbRJEoxxPvEQ== X-Received: by 2002:a17:906:7ac6:b0:c40:4965:72bd with SMTP id a640c23a62f3a-c513a9ae10cmr1961138766b.19.1796055089078; Mon, 30 Nov 2026 08:11:29 -0800 (PST) Received: from avi.scylladb.com ([2a09:bac6:3ac2:1137::1b7:18]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4abbd84e661sm61188151f8f.18.2026.11.30.08.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 08:11:28 -0800 (PST) From: Avi Kivity To: linux-nfs@vger.kernel.org, io-uring@vger.kernel.org Cc: Avi Kivity Subject: [PATCH v1 4/5] nfs: advertise FMODE_NOWAIT on writable files Date: Mon, 30 Nov 2026 18:09:45 +0200 Message-ID: <20261130161103.1972677-5-avi@lists.scylladb.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261130161103.1972677-1-avi@lists.scylladb.com> References: <20261130161103.1972677-1-avi@lists.scylladb.com> X-Mailing-List: io-uring@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: Avi Kivity FMODE_NOWAIT was only set on read-only files, and only by nfs_file_open() - nfs4_file_open() never set it at all, so on NFSv4 mounts even read-only files did not get it. io_uring gates REQ_F_SUPPORT_NOWAIT on this flag, so every read and write on an O_DIRECT NFS file was punted to an io-wq worker before the request ever reached NFS. Now that nfs_file_direct_write() honours IOCB_NOWAIT, set the flag regardless of the access mode from all three open paths: nfs_file_open(), nfs4_file_open(), and nfs_atomic_open(). The last one matters because on NFSv4 a file opened with O_CREAT goes through ->atomic_open() and never reaches nfs4_file_open(); without it every newly created file would still lack the flag. The buffered write path returns -EAGAIN instead of warning; move that check below the O_DIRECT dispatch so direct writes are not caught by it. pNFS is excluded. pnfs_update_layout() is reached from ->pg_init() in the submission loop and blocks - on NFS_LAYOUT_DRAIN, on a pending layoutreturn, and on the LAYOUTGET RPC itself - so claiming NOWAIT there would only move the stall into the io_uring submitter. Making that path non-blocking needs a nowait flag plumbed through pnfs_update_layout() and the layout drivers, which is left for later. Assisted-by: Claude:claude-opus-5 Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Avi Kivity --- fs/nfs/dir.c | 4 ++++ fs/nfs/file.c | 24 ++++++++++++++++-------- fs/nfs/nfs4file.c | 3 +++ fs/nfs/pnfs.h | 5 +++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 49437037f948d..a3089cbdc1cf2 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -42,10 +42,11 @@ #include "delegation.h" #include "iostat.h" #include "internal.h" #include "fscache.h" +#include "pnfs.h" #include "nfstrace.h" /* #define NFS_DEBUG_VERBOSE 1 */ @@ -2209,10 +2210,13 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry, break; } goto out; } file->f_mode |= FMODE_CAN_ODIRECT; + /* See the FMODE_NOWAIT comment in nfs_file_open() */ + if (!pnfs_enabled_sb(NFS_SERVER(dir))) + file->f_mode |= FMODE_NOWAIT; if (test_bit(NFS_CONTEXT_O_DIRECT, &ctx->flags)) { file->f_flags |= O_DIRECT; open_flags |= O_DIRECT; } diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 38f830a6467c9..8e119b55577d9 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -71,12 +71,22 @@ nfs_file_open(struct inode *inode, struct file *filp) return res; res = nfs_open(inode, filp); if (res == 0) { filp->f_mode |= FMODE_CAN_ODIRECT; - /* flag NOWAIT on read-only files only */ - if (!(filp->f_mode & FMODE_WRITE)) + /* + * Both nfs_file_read() and nfs_file_write() honour IOCB_NOWAIT: + * the O_DIRECT paths make a genuine non-blocking attempt, and + * the buffered paths report -EAGAIN. Without FMODE_NOWAIT + * io_uring punts every request on a writable file to an io-wq + * worker before it ever reaches us. + * + * pNFS is excluded: issuing an I/O for which no layout segment + * is cached requires a synchronous LAYOUTGET, and there is no + * way to ask for that without blocking yet. + */ + if (!pnfs_enabled_sb(NFS_SERVER(inode))) filp->f_mode |= FMODE_NOWAIT; } return res; } @@ -743,23 +753,21 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) errseq_t since; int error; trace_nfs_file_write(iocb, from); - /* - * FMODE_NOWAIT is not set for writable files - */ - if (WARN_ON_ONCE(iocb->ki_flags & IOCB_NOWAIT)) - return -EAGAIN; - result = nfs_key_timeout_notify(file, inode); if (result) return result; if (iocb->ki_flags & IOCB_DIRECT) return nfs_file_direct_write(iocb, from, false); + /* NOWAIT is only supported on direct writes */ + if (iocb->ki_flags & IOCB_NOWAIT) + return -EAGAIN; + dprintk("NFS: write(%pD2, %zu@%Ld)\n", file, iov_iter_count(from), (long long) iocb->ki_pos); if (IS_SWAPFILE(inode)) goto out_swapfile; diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 9a434f5dda8d3..1cbb4160377c3 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -89,10 +89,13 @@ nfs4_file_open(struct inode *inode, struct file *filp) nfs_file_set_open_context(filp, ctx); nfs_fscache_open_file(inode, filp); err = 0; filp->f_mode |= FMODE_CAN_ODIRECT; + /* See the FMODE_NOWAIT comment in nfs_file_open() */ + if (!pnfs_enabled_sb(NFS_SERVER(inode))) + filp->f_mode |= FMODE_NOWAIT; if (test_bit(NFS_CONTEXT_O_DIRECT, &ctx->flags)) filp->f_flags |= O_DIRECT; out_put_ctx: put_nfs_open_context(ctx); diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h index ce98fe5264acd..13b4ee7c6febb 100644 --- a/fs/nfs/pnfs.h +++ b/fs/nfs/pnfs.h @@ -908,10 +908,15 @@ static inline void set_pnfs_layoutdriver(struct nfs_server *s, static inline void unset_pnfs_layoutdriver(struct nfs_server *s) { } +static inline int pnfs_enabled_sb(struct nfs_server *nfss) +{ + return 0; +} + static inline int pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how, struct nfs_commit_info *cinfo) { return PNFS_NOT_ATTEMPTED; -- 2.56.1