nfsd: fix courtesy client with deny mode handling in nfs4_upgrade_open
Subsystems (2)
Jeff Layton
maintainerPATCH 1/1 nfsd: fix courtesy client with deny mode handling in nfs4_upgrade_open
The nested if statements here make no sense, as you can never reach "else" branch in the nested statement. Fix the error handling for when there is a courtesy client that holds a conflicting deny mode.
--- fs/nfsd/nfs4state.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
fs/nfsd/nfs4state.c +11 -10
@@ -5282,16 +5282,17 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp,/* test and set deny mode */ spin_lock (&fp->fi_lock); status =nfs4_file_check_deny (fp, open->op_share_deny); -if (status == nfs_ok) { -if (status != nfserr_share_denied) { -set_deny (open->op_share_deny, stp); - fp->fi_share_deny |= - (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); - }else { -if (nfs4_resolve_deny_conflicts_locked (fp, false, - stp, open->op_share_deny, false)) - status = nfserr_jukebox; - } +switch (status) { +case nfs_ok: +set_deny (open->op_share_deny, stp); + fp->fi_share_deny |= + (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); +break ; +case nfserr_share_denied: +if (nfs4_resolve_deny_conflicts_locked (fp, false, + stp, open->op_share_deny, false)) + status = nfserr_jukebox; +break ; }spin_unlock (&fp->fi_lock);
Signature · 1 line
2.39.1
Quoted 12 lines · Jeff Layton
The nested if statements here make no sense, as you can never reach "else" branch in the nested statement. Fix the error handling for when there is a courtesy client that holds a conflicting deny mode.
Fixes 3d69427151806 (NFSD: add support for share reservation conflict to courteous server)Reported-by 張智諺 <[email protected]>Cc Dai Ngo <[email protected]>Signed-off-by Jeff Layton <[email protected]>
Jeff, perfecto. Thank you!
Dai, reply-all with your Reviewed-by and my tooling will pick that up automatically when I apply this to the nfsd tree. Thanks!
Anyone else is also welcome to send a R-b or T-b.
Quoted 39 lines
---
fs/nfsd/nfs4state.c| 21 +++++++++++----------1 file changed, 11 insertions(+), 10 deletions(-)fs/nfsd/nfs4state.c +11
-10@@ -5282,16 +5282,17 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp,/* test and set deny mode */ spin_lock (&fp->fi_lock); status =nfs4_file_check_deny (fp, open->op_share_deny); -if (status == nfs_ok) { -if (status != nfserr_share_denied) { -set_deny (open->op_share_deny, stp); - fp->fi_share_deny |= - (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); - }else { -if (nfs4_resolve_deny_conflicts_locked (fp, false, - stp, open->op_share_deny, false)) - status = nfserr_jukebox; - } +switch (status) { +case nfs_ok: +set_deny (open->op_share_deny, stp); + fp->fi_share_deny |= + (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); +break ; +case nfserr_share_denied: +if (nfs4_resolve_deny_conflicts_locked (fp, false, + stp, open->op_share_deny, false)) + status = nfserr_jukebox; +break ; }spin_unlock (&fp->fi_lock);Signature · 1 line
2.39.1
--
Chuck Lever
Quoted 33 lines · Jeff Layton
The nested if statements here make no sense, as you can never reach "else" branch in the nested statement. Fix the error handling for when there is a courtesy client that holds a conflicting deny mode.
Fixes 3d69427151806 (NFSD: add support for share reservation conflict to courteous server)Reported-by 張智諺 <[email protected]>Cc Dai Ngo <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4state.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)fs/nfsd/nfs4state.c +3
-10@@ -5282,16 +5282,17 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp,/* test and set deny mode */ spin_lock (&fp->fi_lock); status =nfs4_file_check_deny (fp, open->op_share_deny); -if (status == nfs_ok) { -if (status != nfserr_share_denied) { -set_deny (open->op_share_deny, stp); - fp->fi_share_deny |= - (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); - }else { -if (nfs4_resolve_deny_conflicts_locked (fp, false, - stp, open->op_share_deny, false)) - status = nfserr_jukebox; - } +switch (status) { +case nfs_ok: +set_deny (open->op_share_deny, stp);
fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5297
Quoted 10 lines
fs/nfsd/nfs4state.c +8
-0+ fp->fi_share_deny |= + (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); +break ; +case nfserr_share_denied: +if (nfs4_resolve_deny_conflicts_locked (fp, false, + stp, open->op_share_deny, false)) + status = nfserr_jukebox; +break ; }spin_unlock (&fp->fi_lock);
Quoted 1 line
Chuck Lever III
AppliedQuoted 43 lines · Dai Ngo
Quoted 37 lines · Jeff Layton
The nested if statements here make no sense, as you can never reach "else" branch in the nested statement. Fix the error handling for when there is a courtesy client that holds a conflicting deny mode.
Fixes 3d69427151806 (NFSD: add support for share reservation conflict to courteous server)Reported-by 張智諺 <[email protected]>Cc Dai Ngo <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4state.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)fs/nfsd/nfs4state.c +7
-10@@ -5282,16 +5282,17 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp,/* test and set deny mode */ spin_lock (&fp->fi_lock); status =nfs4_file_check_deny (fp, open->op_share_deny); -if (status == nfs_ok) { -if (status != nfserr_share_denied) { -set_deny (open->op_share_deny, stp); - fp->fi_share_deny |= - (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); - }else { -if (nfs4_resolve_deny_conflicts_locked (fp, false, - stp, open->op_share_deny, false)) - status = nfserr_jukebox; - } +switch (status) { +case nfs_ok: +set_deny (open->op_share_deny, stp); + fp->fi_share_deny |= + (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); +break ; +case nfserr_share_denied:
Quoted 8 lines
fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5297
Quoted 6 lines
fs/nfsd/nfs4state.c +4
-0+if (nfs4_resolve_deny_conflicts_locked (fp, false, + stp, open->op_share_deny, false)) + status = nfserr_jukebox; +break ; }spin_unlock (&fp->fi_lock);Reviewed-by Dai Ngo <[email protected]>
Thanks! Applied to nfsd-next.
--
Chuck Lever
[email protected]
reviewerHi Jeff, Chuck,
Quoted 29 lines · Jeff Layton
The nested if statements here make no sense, as you can never reach "else" branch in the nested statement. Fix the error handling for when there is a courtesy client that holds a conflicting deny mode.
Fixes 3d69427151806 (NFSD: add support for share reservation conflict to courteous server)Reported-by 張智諺 <[email protected]>Cc Dai Ngo <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/nfsd/nfs4state.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)fs/nfsd/nfs4state.c +0
-9@@ -5282,16 +5282,17 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp,/* test and set deny mode */ spin_lock (&fp->fi_lock); status =nfs4_file_check_deny (fp, open->op_share_deny); -if (status == nfs_ok) { -if (status != nfserr_share_denied) { -set_deny (open->op_share_deny, stp); - fp->fi_share_deny |= - (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); - }else { -if (nfs4_resolve_deny_conflicts_locked (fp, false, - stp, open->op_share_deny, false)) - status = nfserr_jukebox;
fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5293
Quoted 10 lines
fs/nfsd/nfs4state.c +9
-1- } +switch (status) { +case nfs_ok: +set_deny (open->op_share_deny, stp); + fp->fi_share_deny |= + (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); +break ; +case nfserr_share_denied: +if (nfs4_resolve_deny_conflicts_locked (fp, false, + stp, open->op_share_deny, false))
While trying to write a pynfs test case to exercise this code path, I realize that we don't need to call nfs4_resolve_deny_conflicts_locked here since this is an open upgrade so it must comes from the same client hence there is no conflict to resolve. Same behavior as OPEN_DOWNGRADE.
-Dai
Quoted 5 lines
fs/nfsd/nfs4state.c +2
-0+ status = nfserr_jukebox; +break ; }spin_unlock (&fp->fi_lock);
[email protected]
reviewerQuoted 40 lines · On 2/15/23 3:05 PM, [email protected] wrote:
Hi Jeff, Chuck,
Quoted 37 lines · Jeff Layton
The nested if statements here make no sense, as you can never reach "else" branch in the nested statement. Fix the error handling for when there is a courtesy client that holds a conflicting deny mode.
Fixes 3d69427151806 (NFSD: add support for share reservation conflict to courteous server)Reported-by 張智諺 <[email protected]>Cc Dai Ngo <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/nfs4state.c| 21 +++++++++++----------1 file changed, 11 insertions(+), 10 deletions(-)fs/nfsd/nfs4state.c +6
-10@@ -5282,16 +5282,17 @@ nfs4_upgrade_open(struct svc_rqst *rqstp,struct nfs4_file *fp, /* test and set deny mode */ spin_lock(&fp->fi_lock); status = nfs4_file_check_deny(fp, open->op_share_deny); - if (status == nfs_ok) { - if (status != nfserr_share_denied) { - set_deny(open->op_share_deny, stp); - fp->fi_share_deny |= - (open->op_share_deny & NFS4_SHARE_DENY_BOTH); - } else { - if (nfs4_resolve_deny_conflicts_locked(fp, false, - stp, open->op_share_deny, false)) - status = nfserr_jukebox; - } + switch (status) { + case nfs_ok: + set_deny(open->op_share_deny, stp); + fp->fi_share_deny |= + (open->op_share_deny & NFS4_SHARE_DENY_BOTH); + break;
Quoted 8 lines
fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5293
Quoted 3 lines
fs/nfsd/nfs4state.c +3
-0+ case nfserr_share_denied: + if (nfs4_resolve_deny_conflicts_locked(fp, false, + stp, open->op_share_deny, false))While trying to write a pynfs test case to exercise this code path, I realize that we don't need to call
nfs4_resolve_deny_conflicts_lockedhere since this is an open upgrade so it must comes from the same client hence there is no conflict to resolve. Same behavior asOPEN_DOWNGRADE.
never mind, I found the scenario where this code path is executed:
Client1 opens fileX with WRITE, DENY_NONE
Client2 opens fileX with READ, DENY_NONE
Client2 opens fileX with READ, DENY_WRITE
-Dai
Quoted 7 lines
-Dai
Quoted 4 lines
fs/nfsd/nfs4state.c +2
-0+ status = nfserr_jukebox; + break; } spin_unlock(&fp->fi_lock);