Skip to content

Commit 39f897f

Browse files
NeilBrowntrondmypd
authored andcommitted
NFSv4: When returning a delegation, don't reclaim an incompatible open mode.
It is possible to have an active open with one mode, and a delegation for the same file with a different mode. In particular, a WR_ONLY open and an RD_ONLY delegation. This happens if a WR_ONLY open is followed by a RD_ONLY open which provides a delegation, but is then close. When returning the delegation, we currently try to claim opens for every open type (n_rdwr, n_rdonly, n_wronly). As there is no harm in claiming an open for a mode that we already have, this is often simplest. However if the delegation only provides a subset of the modes that we currently have open, this will produce an error from the server. So when claiming open modes prior to returning a delegation, skip the open request if the mode is not covered by the delegation - the open_stateid must already cover that mode, so there is nothing to do. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent 6c5a0d8 commit 39f897f

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

fs/nfs/nfs4proc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,13 @@ static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmod
15471547
struct nfs4_state *newstate;
15481548
int ret;
15491549

1550+
if ((opendata->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR ||
1551+
opendata->o_arg.claim == NFS4_OPEN_CLAIM_DELEG_CUR_FH) &&
1552+
(opendata->o_arg.u.delegation_type & fmode) != fmode)
1553+
/* This mode can't have been delegated, so we must have
1554+
* a valid open_stateid to cover it - not need to reclaim.
1555+
*/
1556+
return 0;
15501557
opendata->o_arg.open_flags = 0;
15511558
opendata->o_arg.fmode = fmode;
15521559
opendata->o_arg.share_access = nfs4_map_atomic_open_share(

0 commit comments

Comments
 (0)