From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev,
Trond Myklebust <trond.myklebust@hammerspace.com>,
Jeff Layton <jlayton@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.12 50/55] NFS: Avoid flushing data while holding directory locks in nfs_rename()
Date: Mon, 2 Jun 2025 15:48:07 +0200 [thread overview]
Message-ID: <20250602134240.247985573@linuxfoundation.org> (raw)
In-Reply-To: <20250602134238.271281478@linuxfoundation.org>
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <trond.myklebust@hammerspace.com>
[ Upstream commit dcd21b609d4abc7303f8683bce4f35d78d7d6830 ]
The Linux client assumes that all filehandles are non-volatile for
renames within the same directory (otherwise sillyrename cannot work).
However, the existence of the Linux 'subtree_check' export option has
meant that nfs_rename() has always assumed it needs to flush writes
before attempting to rename.
Since NFSv4 does allow the client to query whether or not the server
exhibits this behaviour, and since knfsd does actually set the
appropriate flag when 'subtree_check' is enabled on an export, it
should be OK to optimise away the write flushing behaviour in the cases
where it is clearly not needed.
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/nfs/client.c | 2 ++
fs/nfs/dir.c | 15 ++++++++++++++-
include/linux/nfs_fs_sb.h | 12 +++++++++---
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 03ecc77656151..4503758e9594b 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -1096,6 +1096,8 @@ struct nfs_server *nfs_create_server(struct fs_context *fc)
if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
server->namelen = NFS2_MAXNAMLEN;
}
+ /* Linux 'subtree_check' borkenness mandates this setting */
+ server->fh_expire_type = NFS_FH_VOL_RENAME;
if (!(fattr->valid & NFS_ATTR_FATTR)) {
error = ctx->nfs_mod->rpc_ops->getattr(server, ctx->mntfh,
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 492cffd9d3d84..f9f4a92f63e92 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -2690,6 +2690,18 @@ nfs_unblock_rename(struct rpc_task *task, struct nfs_renamedata *data)
unblock_revalidate(new_dentry);
}
+static bool nfs_rename_is_unsafe_cross_dir(struct dentry *old_dentry,
+ struct dentry *new_dentry)
+{
+ struct nfs_server *server = NFS_SB(old_dentry->d_sb);
+
+ if (old_dentry->d_parent != new_dentry->d_parent)
+ return false;
+ if (server->fh_expire_type & NFS_FH_RENAME_UNSAFE)
+ return !(server->fh_expire_type & NFS_FH_NOEXPIRE_WITH_OPEN);
+ return true;
+}
+
/*
* RENAME
* FIXME: Some nfsds, like the Linux user space nfsd, may generate a
@@ -2777,7 +2789,8 @@ int nfs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
}
- if (S_ISREG(old_inode->i_mode))
+ if (S_ISREG(old_inode->i_mode) &&
+ nfs_rename_is_unsafe_cross_dir(old_dentry, new_dentry))
nfs_sync_inode(old_inode);
task = nfs_async_rename(old_dir, new_dir, old_dentry, new_dentry,
must_unblock ? nfs_unblock_rename : NULL);
diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h
index 81ab18658d72d..2cff5cafbaa78 100644
--- a/include/linux/nfs_fs_sb.h
+++ b/include/linux/nfs_fs_sb.h
@@ -211,6 +211,15 @@ struct nfs_server {
char *fscache_uniq; /* Uniquifier (or NULL) */
#endif
+ /* The following #defines numerically match the NFSv4 equivalents */
+#define NFS_FH_NOEXPIRE_WITH_OPEN (0x1)
+#define NFS_FH_VOLATILE_ANY (0x2)
+#define NFS_FH_VOL_MIGRATION (0x4)
+#define NFS_FH_VOL_RENAME (0x8)
+#define NFS_FH_RENAME_UNSAFE (NFS_FH_VOLATILE_ANY | NFS_FH_VOL_RENAME)
+ u32 fh_expire_type; /* V4 bitmask representing file
+ handle volatility type for
+ this filesystem */
u32 pnfs_blksize; /* layout_blksize attr */
#if IS_ENABLED(CONFIG_NFS_V4)
u32 attr_bitmask[3];/* V4 bitmask representing the set
@@ -234,9 +243,6 @@ struct nfs_server {
u32 acl_bitmask; /* V4 bitmask representing the ACEs
that are supported on this
filesystem */
- u32 fh_expire_type; /* V4 bitmask representing file
- handle volatility type for
- this filesystem */
struct pnfs_layoutdriver_type *pnfs_curr_ld; /* Active layout driver */
struct rpc_wait_queue roc_rpcwaitq;
void *pnfs_ld_data; /* per mount point data */
--
2.39.5
next prev parent reply other threads:[~2025-06-02 14:02 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-02 13:47 [PATCH 6.12 00/55] 6.12.32-rc1 review Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 01/55] can: kvaser_pciefd: Force IRQ edge in case of nested IRQ Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 02/55] arm64: dts: qcom: ipq9574: Add missing properties for cryptobam Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 03/55] arm64: dts: qcom: sa8775p: Remove extra entries from the iommus property Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 04/55] arm64: dts: qcom: sa8775p: Remove cdsp compute-cb@10 Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 05/55] arm64: dts: qcom: sm8350: Fix typo in pil_camera_mem node Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 06/55] arm64: dts: qcom: sm8450: Add missing properties for cryptobam Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 07/55] arm64: dts: qcom: sm8550: " Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 08/55] arm64: dts: qcom: sm8650: " Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 09/55] arm64: dts: qcom: x1e80100-asus-vivobook-s15: Fix vreg_l2j_1p2 voltage Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 10/55] arm64: dts: qcom: x1e80100-lenovo-yoga-slim7x: " Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 11/55] arm64: dts: qcom: x1e80100-qcp: " Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 12/55] arm64: dts: qcom: x1e80100-qcp: mark l12b and l15b always-on Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 13/55] arm64: dts: qcom: x1e80100-yoga-slim7x: " Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 14/55] arm64: dts: qcom: x1e80100: Fix video thermal zone Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 15/55] arm64: dts: ti: k3-am62-main: Set eMMC clock parent to default Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 16/55] arm64: dts: ti: k3-am62a-main: " Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 17/55] arm64: dts: ti: k3-am62p-j722s-common-main: " Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 18/55] arm64: dts: ti: k3-am62x: Remove clock-names property from IMX219 overlay Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 19/55] arm64: dts: ti: k3-am62x: Rename I2C switch to I2C mux in " Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 20/55] arm64: dts: ti: k3-am62x: Rename I2C switch to I2C mux in OV5640 overlay Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 21/55] arm64: dts: ti: k3-am65-main: Add missing taps to sdhci0 Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 22/55] arm64: dts: ti: k3-am68-sk: Fix regulator hierarchy Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 23/55] arm64: dts: ti: k3-j721e-sk: Add DT nodes for power regulators Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 24/55] arm64: dts: ti: k3-j721e-sk: Remove clock-names property from IMX219 overlay Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 25/55] arm64: dts: ti: k3-j721e-sk: Add requiried voltage supplies for IMX219 Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 26/55] arm64: dts: ti: k3-j722s-evm: Enable "serdes_wiz0" and "serdes_wiz1" Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 27/55] arm64: dts: ti: k3-j722s-main: Disable " Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 28/55] arm64: dts: ti: k3-j784s4-j742s2-main-common: Fix length of serdes_ln_ctrl Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 29/55] net_sched: hfsc: Address reentrant enqueue adding class to eltree twice Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 30/55] perf/arm-cmn: Fix REQ2/SNP2 mixup Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 31/55] perf/arm-cmn: Initialise cmn->cpu earlier Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 32/55] perf/arm-cmn: Add CMN S3 ACPI binding Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 33/55] coredump: fix error handling for replace_fd() Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 34/55] coredump: hand a pidfd to the usermode coredump helper Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 35/55] dmaengine: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 36/55] HID: quirks: Add ADATA XPG alpha wireless mouse support Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 37/55] nfs: dont share pNFS DS connections between net namespaces Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 38/55] platform/x86: thinkpad_acpi: Support also NEC Lavie X1475JAS Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 39/55] um: let make clean properly clean underlying SUBARCH as well Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 40/55] gpio: virtuser: fix potential out-of-bound write Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 41/55] drm/amd/display: fix link_set_dpms_off multi-display MST corner case Greg Kroah-Hartman
2025-06-02 13:47 ` [PATCH 6.12 42/55] drm/amd/display: check stream id dml21 wrapper to get plane_id Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 43/55] phy: starfive: jh7110-usb: Fix USB 2.0 host occasional detection failure Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 44/55] phy: phy-rockchip-samsung-hdptx: Fix PHY PLL output 50.25MHz error Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 45/55] spi: spi-sun4i: fix early activation Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 46/55] nvme-pci: add NVME_QUIRK_NO_DEEPEST_PS quirk for SOLIDIGM P44 Pro Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 47/55] drm/xe/xe2hpg: Add Wa_22021007897 Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 48/55] drm/xe: Save the gt pointer in lrc and drop the tile Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 49/55] char: tpm: tpm-buf: Add sanity check fallback in read helpers Greg Kroah-Hartman
2025-06-02 13:48 ` Greg Kroah-Hartman [this message]
2025-06-02 13:48 ` [PATCH 6.12 51/55] platform/x86: fujitsu-laptop: Support Lifebook S2110 hotkeys Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 52/55] ALSA: hda/realtek - restore auto-mute mode for Dell Chrome platform Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 53/55] platform/x86: thinkpad_acpi: Ignore battery threshold change event notification Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 54/55] net: ethernet: ti: am65-cpsw: Lower random mac address error print to info Greg Kroah-Hartman
2025-06-02 13:48 ` [PATCH 6.12 55/55] ksmbd: use list_first_entry_or_null for opinfo_get_list() Greg Kroah-Hartman
2025-06-02 17:42 ` [PATCH 6.12 00/55] 6.12.32-rc1 review Florian Fainelli
2025-06-02 17:57 ` Peter Schneider
2025-06-03 6:10 ` Harshit Mogalapalli
2025-06-03 7:36 ` Ron Economos
2025-06-03 9:43 ` Mark Brown
2025-06-03 11:32 ` Naresh Kamboju
2025-06-03 13:51 ` Brett Mastbergen
2025-06-03 17:10 ` Shuah Khan
2025-06-03 20:33 ` Hardik Garg
2025-06-04 9:41 ` Jon Hunter
2025-06-04 9:57 ` Jon Hunter
2025-06-04 10:19 ` Greg Kroah-Hartman
2025-06-04 10:22 ` Jon Hunter
2025-06-04 10:36 ` Greg Kroah-Hartman
2025-06-04 9:58 ` Greg Kroah-Hartman
2025-06-04 10:20 ` Jon Hunter
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=20250602134240.247985573@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=jlayton@kernel.org \
--cc=patches@lists.linux.dev \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=trond.myklebust@hammerspace.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