Skip to contentSkip to conversation

NFSv4/flexfiles: couple back with NFSv3

PATCH In review Roberto Bergantinos Corpas 2 participants 2 messages Nov 4 – Nov 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFSv4/flexfiles: couple back with NFSv3

Commit 7a375cafc14e ("NFSv4/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS on fatal DS connect errors") uncovered an unexpected issue, EPROTONOSUPPORT from a missing nfsv3 module during pNFS flexfiles I/O operation turned a harmless WARN + fallback to MDS into a forever retry op.

Flexfiles is decoupled from NFSv3 after commit a68c6fbb638a ("nfs41:
drop dependency between flexfiles layout driver and NFSv3 modules"), so we trusted on legacy symbol_request(nfs3_set_ds_client) -> request_module at runtime to load NFSv3 module in case it's not loaded.

However this approach has some problematic scenarios, an unprivileged container may be denied by SELinux policy to load nfsv3 module, leading to writeback hang, other scenario is boot hang on NFSv4 root mounted hosts, where we get deadlocked trying to fetch from the filesystem the usermode helpers necessary for request_module to proceed.

So, couple back NFSv3 with flexfiles to make sure both are loaded on i.e. mount time, and remove the scaffolding associated with symbol_request() mechanism now that we have a hard dependency on the code with nfs3_set_ds_client.

Fixes 7a375cafc14e ("NFSv4/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS on fatal DS connect errors")
Assisted-by Claude Opus 4.6 <[email protected]>
---
 fs/nfs/Kconfig     |  2 +-
 fs/nfs/nfs4super.c |  3 ---
 fs/nfs/pnfs.h      |  5 -----
 fs/nfs/pnfs_nfs.c  | 34 ++--------------------------------
 4 files changed, 3 insertions(+), 41 deletions(-)
fs/nfs/Kconfig +1 -1
index fd430718d02b..b693f573c2ba 100644
@@ -143,7 +143,7 @@ config PNFS_SCSI_LAYOUT
 
 config PNFS_FLEXFILE_LAYOUT
 	tristate
-	depends on NFS_V4
+	depends on NFS_V4 && NFS_V3
 	default NFS_V4
 
 config NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
fs/nfs/nfs4super.c +0 -3
index 9c5895b551a1..f142e29a816c 100644
@@ -297,9 +297,6 @@ static int __init init_nfs_v4(void)
 
 static void __exit exit_nfs_v4(void)
 {
-	/* Not called in the _init(), conditionally loaded */
-	nfs4_pnfs_v3_ds_connect_unload();
-
 	unregister_nfs_version(&nfs_v4);
 #ifdef CONFIG_NFS_V4_2
 	nfs4_xattr_cache_exit();
fs/nfs/pnfs.h +0 -5
index 2774d4adf4c3..e5a8547e050e 100644
@@ -504,7 +504,6 @@ void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds *ds);
 struct nfs4_pnfs_ds *nfs4_pnfs_ds_add(const struct net *net,
 				      struct list_head *dsaddrs,
 				      u32 version, gfp_t gfp_flags);
-void nfs4_pnfs_v3_ds_connect_unload(void);
 int nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds,
 			  struct nfs4_deviceid_node *devid, unsigned int timeo,
 			  unsigned int retrans, unsigned int nconnect,
@@ -972,10 +971,6 @@ static inline struct nfs4_threshold *pnfs_mdsthreshold_alloc(void)
 	return NULL;
 }
 
-static inline void nfs4_pnfs_v3_ds_connect_unload(void)
-{
-}
-
 static inline bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst,
 		struct pnfs_layout_range *dst_range,
 		struct inode *inode)
fs/nfs/pnfs_nfs.c +2 -32
index 7adb6f941cf2..7775ee6d087c 100644
@@ -838,33 +838,6 @@ static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds *ds)
 	clear_and_wake_up_bit(NFS4DS_CONNECTING, &ds->ds_state);
 }
 
-static struct nfs_client *(*get_v3_ds_connect)(
-			struct nfs_server *mds_srv,
-			const struct sockaddr_storage *ds_addr,
-			int ds_addrlen,
-			int ds_proto,
-			unsigned int ds_timeo,
-			unsigned int ds_retrans,
-			unsigned int ds_nconnect);
-
-static bool load_v3_ds_connect(void)
-{
-	if (!get_v3_ds_connect) {
-		get_v3_ds_connect = symbol_request(nfs3_set_ds_client);
-		WARN_ON_ONCE(!get_v3_ds_connect);
-	}
-
-	return(get_v3_ds_connect != NULL);
-}
-
-void nfs4_pnfs_v3_ds_connect_unload(void)
-{
-	if (get_v3_ds_connect) {
-		symbol_put(nfs3_set_ds_client);
-		get_v3_ds_connect = NULL;
-	}
-}
-
 static int _nfs4_pnfs_v3_ds_connect(struct nfs_server *mds_srv,
 				 struct nfs4_pnfs_ds *ds,
 				 unsigned int timeo,
@@ -881,9 +854,6 @@ static int _nfs4_pnfs_v3_ds_connect(struct nfs_server *mds_srv,
 
 	dprintk("--> %s DS %s\n", __func__, ds->ds_remotestr);
 
-	if (!load_v3_ds_connect())
-		return -EPROTONOSUPPORT;
-
 	list_for_each_entry(da, &ds->ds_addrs, da_node) {
 		dprintk("%s: DS %s: trying address %s\n",
 			__func__, ds->ds_remotestr, da->da_remotestr);
@@ -920,8 +890,8 @@ static int _nfs4_pnfs_v3_ds_connect(struct nfs_server *mds_srv,
 		    xprtsec_policy != RPC_XPRTSEC_NONE)
 			ds_proto = XPRT_TRANSPORT_TCP_TLS;
 
-		clp = get_v3_ds_connect(mds_srv, &da->da_addr, da->da_addrlen,
-					ds_proto, timeo, retrans, nconnect);
+		clp = nfs3_set_ds_client(mds_srv, &da->da_addr, da->da_addrlen,
+					 ds_proto, timeo, retrans, nconnect);
 		if (IS_ERR(clp))
 			continue;
 		clp->cl_rpcclient->cl_softerr = 0;
Signature · 1 line
2.55.0
#1 lore raw

----- Original Message -----

Quoted 50 lines

From: "Roberto Bergantinos Corpas" <[email protected]>
To: "Trond Myklebust" <[email protected]>, "Anna Schumaker" <[email protected]>
Cc: "linux-nfs" <[email protected]>, "Mike Snitzer" <[email protected]>, "Benjamin Coddington" <[email protected]>, "Antonio Alvarez Feijoo" <[email protected]>, "Tigran Mkrtchyan" <[email protected]>
Sent: Wednesday, 4 November, 2026 12:25:05
Subject: [PATCH] NFSv4/flexfiles: couple back with NFSv3

Commit 7a375cafc14e ("NFSv4/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS on fatal DS connect errors") uncovered an unexpected issue, EPROTONOSUPPORT from a missing nfsv3 module during pNFS flexfiles I/O operation turned a harmless WARN + fallback to MDS into a forever retry op.

Flexfiles is decoupled from NFSv3 after commit a68c6fbb638a ("nfs41:
drop dependency between flexfiles layout driver and NFSv3 modules"), so we trusted on legacy symbol_request(nfs3_set_ds_client) -> request_module at runtime to load NFSv3 module in case it's not loaded.

However this approach has some problematic scenarios, an unprivileged container may be denied by SELinux policy to load nfsv3 module, leading to writeback hang, other scenario is boot hang on NFSv4 root mounted hosts, where we get deadlocked trying to fetch from the filesystem the usermode helpers necessary for request_module to proceed.

So, couple back NFSv3 with flexfiles to make sure both are loaded on i.e. mount time, and remove the scaffolding associated with symbol_request() mechanism now that we have a hard dependency on the code with nfs3_set_ds_client.

Fixes 7a375cafc14e ("NFSv4/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS on fatal DS

connect errors")

---

fs/nfs/Kconfig     |  2 +-
fs/nfs/nfs4super.c |  3 ---
fs/nfs/pnfs.h      |  5 -----
fs/nfs/pnfs_nfs.c  | 34 ++--------------------------------
4 files changed, 3 insertions(+), 41 deletions(-)
fs/nfs/Kconfig +0 -0
index fd430718d02b..b693f573c2ba 100644
@@ -143,7 +143,7 @@ config PNFS_SCSI_LAYOUT
 

config PNFS_FLEXFILE_LAYOUT
tristate

fs/nfs/Kconfig config PNFS_SCSI_LAYOUT · line 146

Quoted 2 lines
fs/nfs/Kconfig +1 -1
-	depends on NFS_V4
+	depends on NFS_V4 && NFS_V3

or maybe

select NFS_V3

To enforce nfs3 to be built, if flexfiles layout type is selected.

Tigran.

Quoted 104 lines

default NFS_V4

config NFS_V4_1_IMPLEMENTATION_ID_DOMAIN

fs/nfs/nfs4super.c +0 -3
index 9c5895b551a1..f142e29a816c 100644
@@ -297,9 +297,6 @@ static int __init init_nfs_v4(void)
 
 static void __exit exit_nfs_v4(void)
 {
-	/* Not called in the _init(), conditionally loaded */
-	nfs4_pnfs_v3_ds_connect_unload();
-
 	unregister_nfs_version(&nfs_v4);
 #ifdef CONFIG_NFS_V4_2
 	nfs4_xattr_cache_exit();
fs/nfs/pnfs.h +0 -5
index 2774d4adf4c3..e5a8547e050e 100644
@@ -504,7 +504,6 @@ void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds *ds);
 struct nfs4_pnfs_ds *nfs4_pnfs_ds_add(const struct net *net,
 				      struct list_head *dsaddrs,
 				      u32 version, gfp_t gfp_flags);
-void nfs4_pnfs_v3_ds_connect_unload(void);
 int nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds,
 			  struct nfs4_deviceid_node *devid, unsigned int timeo,
 			  unsigned int retrans, unsigned int nconnect,
@@ -972,10 +971,6 @@ static inline struct nfs4_threshold
 *pnfs_mdsthreshold_alloc(void)
 	return NULL;
 }
 
-static inline void nfs4_pnfs_v3_ds_connect_unload(void)
-{
-}
-
 static inline bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst,
 		struct pnfs_layout_range *dst_range,

struct inode *inode)

fs/nfs/pnfs_nfs.c +0 -30
index 7adb6f941cf2..7775ee6d087c 100644
@@ -838,33 +838,6 @@ static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds *ds)
 	clear_and_wake_up_bit(NFS4DS_CONNECTING, &ds->ds_state);
 }
 
-static struct nfs_client *(*get_v3_ds_connect)(
-			struct nfs_server *mds_srv,
-			const struct sockaddr_storage *ds_addr,
-			int ds_addrlen,
-			int ds_proto,
-			unsigned int ds_timeo,
-			unsigned int ds_retrans,
-			unsigned int ds_nconnect);
-
-static bool load_v3_ds_connect(void)
-{
-	if (!get_v3_ds_connect) {
-		get_v3_ds_connect = symbol_request(nfs3_set_ds_client);
-		WARN_ON_ONCE(!get_v3_ds_connect);
-	}
-
-	return(get_v3_ds_connect != NULL);
-}
-
-void nfs4_pnfs_v3_ds_connect_unload(void)
-{
-	if (get_v3_ds_connect) {
-		symbol_put(nfs3_set_ds_client);
-		get_v3_ds_connect = NULL;
-	}
-}
-
 static int _nfs4_pnfs_v3_ds_connect(struct nfs_server *mds_srv,
 				 struct nfs4_pnfs_ds *ds,
 				 unsigned int timeo,
@@ -881,9 +854,6 @@ static int _nfs4_pnfs_v3_ds_connect(struct nfs_server
 *mds_srv,
 
 	dprintk("--> %s DS %s\n", __func__, ds->ds_remotestr);
 
-	if (!load_v3_ds_connect())
-		return -EPROTONOSUPPORT;
-
 	list_for_each_entry(da, &ds->ds_addrs, da_node) {
 		dprintk("%s: DS %s: trying address %s\n",
			__func__, ds->ds_remotestr, da->da_remotestr);
fs/nfs/pnfs_nfs.c +2 -2
@@ -920,8 +890,8 @@ static int _nfs4_pnfs_v3_ds_connect(struct nfs_server
 *mds_srv,
 		    xprtsec_policy != RPC_XPRTSEC_NONE)
 			ds_proto = XPRT_TRANSPORT_TCP_TLS;
 
-		clp = get_v3_ds_connect(mds_srv, &da->da_addr, da->da_addrlen,
-					ds_proto, timeo, retrans, nconnect);
+		clp = nfs3_set_ds_client(mds_srv, &da->da_addr, da->da_addrlen,
+					 ds_proto, timeo, retrans, nconnect);
 		if (IS_ERR(clp))
 			continue;
		clp->cl_rpcclient->cl_softerr = 0;

--
2.55.0