Skip to contentSkip to conversation

NFSv4: Fix a deadlock between nfs4_open_recover_helper() and delegreturn

PATCH New [email protected] 1 participant 1 message Nov 4, 2022

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

PATCH 1/1 NFSv4: Fix a deadlock between nfs4_open_recover_helper() and delegreturn

From: Trond Myklebust <[email protected]>

If we're asked to recover open state while a delegation return is outstanding, then the state manager thread cannot use a cached open, so if the server returns a delegation, we can end up deadlocked behind the pending delegreturn.
To avoid this problem, let's just ask the server not to give us a delegation unless we're explicitly reclaiming one.

Fixes be36e185bd26 ("NFSv4: nfs4_open_recover_helper() must set share access")
---
 fs/nfs/nfs4proc.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
fs/nfs/nfs4proc.c +14 -5
index bd89c7f06952..c002e4b69761 100644
@@ -2131,18 +2131,27 @@ static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context
 }
 
 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata,
-		fmode_t fmode)
+				    fmode_t fmode)
 {
 	struct nfs4_state *newstate;
+	struct nfs_server *server = NFS_SB(opendata->dentry->d_sb);
+	int openflags = 0;
 	int ret;
 
 	if (!nfs4_mode_match_open_stateid(opendata->state, fmode))
 		return 0;
-	opendata->o_arg.open_flags = 0;
+	/*
+	 * If we're not recovering a delegation, then ask for no delegation.
+	 * Otherwise the recovery thread could deadlock with an outstanding
+	 * delegation return.
+	 */
+	if (opendata->o_arg.u.delegation_type == 0)
+		openflags = O_DIRECT;
+
+	opendata->o_arg.open_flags = openflags;
 	opendata->o_arg.fmode = fmode;
-	opendata->o_arg.share_access = nfs4_map_atomic_open_share(
-			NFS_SB(opendata->dentry->d_sb),
-			fmode, 0);
+	opendata->o_arg.share_access =
+		nfs4_map_atomic_open_share(server, fmode, openflags);
 	memset(&opendata->o_res, 0, sizeof(opendata->o_res));
 	memset(&opendata->c_res, 0, sizeof(opendata->c_res));
 	nfs4_init_opendata_res(opendata);
Signature · 1 line
2.38.1