NFSD: fix deny mode logic in nfs4_upgrade_open
Subsystems (2)
Quoted 18 lines · Pumpkin
If the upgrading deny mode is invalid or conflicts with other client, we should try to resolve it, but the if-condition makes those error handling cannot be executed.
Signed-off-by Pumpkin <[email protected]>---
fs/nfsd/nfs4state.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0
fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5302
Quoted 6 lines
fs/nfsd/nfs4state.c +1
-1@@ -5298,7 +5298,7 @@ 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 != nfs_ok) {if (status != nfserr_share_denied) {
if status == nfs_ok then status will definitely not equal share_denied. So this check is a bit nonsensical as it stands.
Usually I prefer "switch (status)" in situations like this because that avoids this kind of issue and I find it easier to read quickly.
Jeff, you are the original author of this function, and Dai, your commit is the last one to touch this area. Can you guys have a look? The one-liner looks correct, but I might be missing something.
Quoted 5 lines
fs/nfsd/nfs4state.c +0
-0set_deny (open->op_share_deny, stp); fp->fi_share_deny |=Signature · 1 line
2.37.1 (Apple Git-137.1)
--
Chuck Lever
Jeff Layton
maintainerQuoted 27 lines · Chuck Lever III
Quoted 17 lines · Pumpkin
If the upgrading deny mode is invalid or conflicts with other client, we should try to resolve it, but the if-condition makes those error handling cannot be executed.
Signed-off-by Pumpkin <[email protected]>---
fs/nfsd/nfs4state.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5302
Quoted 6 lines
fs/nfsd/nfs4state.c +1
-1@@ -5298,7 +5298,7 @@ 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 != nfs_ok) {if (status != nfserr_share_denied) {if status ==
nfs_okthen status will definitely not equalshare_denied. So this check is a bit nonsensical as it stands.
Quoted 9 lines
Usually I prefer "switch (status)" in situations like this because that avoids this kind of issue and I find it easier to read quickly.
Jeff, you are the original author of this function, and Dai, your commit is the last one to touch this area. Can you guys have a look? The one-liner looks correct, but I might be missing something.
Yeah, that code is clearly broken and it looks like it was done in 3d69427151806 (NFSD: add support for share reservation conflict to courteous server).
I don't believe that one-liner is correct though. If the result is nfs_ok, then we want to set the deny mode here and that won't happen.
Something like this maybe? (completely untested):
---------------8<-------------------
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
Jeff Layton <[email protected]>
[email protected]
reviewerQuoted 35 lines · Jeff Layton
Quoted 25 lines · Chuck Lever III
Quoted 16 lines · Pumpkin
If the upgrading deny mode is invalid or conflicts with other client, we should try to resolve it, but the if-condition makes those error handling cannot be executed.
Signed-off-by Pumpkin <[email protected]>---
fs/nfsd/nfs4state.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5302
Quoted 6 lines
fs/nfsd/nfs4state.c +1
-1@@ -5298,7 +5298,7 @@ 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 != nfs_ok) {if (status != nfserr_share_denied) {if status ==
nfs_okthen status will definitely not equalshare_denied. So this check is a bit nonsensical as it stands.Quoted 9 lines
Usually I prefer "switch (status)" in situations like this because that avoids this kind of issue and I find it easier to read quickly.
Jeff, you are the original author of this function, and Dai, your commit is the last one to touch this area. Can you guys have a look? The one-liner looks correct, but I might be missing something.
Quoted 6 lines
Yeah, that code is clearly broken and it looks like it was done in
3d69427151806(NFSD: add support for share reservation conflict to courteous server).I don't believe that one-liner is correct though. If the result is
nfs_ok, then we want to set the deny mode here and that won't happen.
not sure what I was thinking. The check was totally wrong.
Quoted 26 lines
Something like this maybe? (completely untested):
---------------8<-------------------
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);
LGTM.
Thanks,
-Dai
Quoted 5 lines · 張智諺
Sorry, I thought the set deny mode operation was the error handling of
nfserr_inval, and fixed it with the one-liner wrongly. Thanks your explanation.
Do you happen to have a test case for this issue?
Getting a Tested-by: would be great.
Quoted 84 lines
Jeff Layton <[email protected]> 於 2023年2月3日 週五 上午5:22寫道:
Quoted 27 lines · Chuck Lever III
Quoted 17 lines · Pumpkin
If the upgrading deny mode is invalid or conflicts with other client, we should try to resolve it, but the if-condition makes those error handling cannot be executed.
Signed-off-by Pumpkin <[email protected]>---
fs/nfsd/nfs4state.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5302
Quoted 6 lines
fs/nfsd/nfs4state.c +1
-1@@ -5298,7 +5298,7 @@ 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 != nfs_ok) {if (status != nfserr_share_denied) {if status ==
nfs_okthen status will definitely not equalshare_denied. So this check is a bit nonsensical as it stands.Quoted 9 lines
Usually I prefer "switch (status)" in situations like this because that avoids this kind of issue and I find it easier to read quickly.
Jeff, you are the original author of this function, and Dai, your commit is the last one to touch this area. Can you guys have a look? The one-liner looks correct, but I might be missing something.
Yeah, that code is clearly broken and it looks like it was done in
3d69427151806(NFSD: add support for share reservation conflict to courteous server).I don't believe that one-liner is correct though. If the result is
nfs_ok, then we want to set the deny mode here and that won't happen.Something like this maybe? (completely untested):
---------------8<-------------------
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
Jeff Layton <[email protected]>
--
Chuck Lever
Quoted 74 lines · Jeff Layton
Quoted 27 lines · Chuck Lever III
Quoted 17 lines · Pumpkin
If the upgrading deny mode is invalid or conflicts with other client, we should try to resolve it, but the if-condition makes those error handling cannot be executed.
Signed-off-by Pumpkin <[email protected]>---
fs/nfsd/nfs4state.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5302
Quoted 6 lines
fs/nfsd/nfs4state.c +1
-1@@ -5298,7 +5298,7 @@ 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 != nfs_ok) {if (status != nfserr_share_denied) {if status ==
nfs_okthen status will definitely not equalshare_denied. So this check is a bit nonsensical as it stands.Quoted 9 lines
Usually I prefer "switch (status)" in situations like this because that avoids this kind of issue and I find it easier to read quickly.
Jeff, you are the original author of this function, and Dai, your commit is the last one to touch this area. Can you guys have a look? The one-liner looks correct, but I might be missing something.
Yeah, that code is clearly broken and it looks like it was done in
3d69427151806(NFSD: add support for share reservation conflict to courteous server).I don't believe that one-liner is correct though. If the result is
nfs_ok, then we want to set the deny mode here and that won't happen.Something like this maybe? (completely untested):
---------------8<-------------------
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);
Would pynfs have a case or two that could test this?
Can you post an official version of this patch with Reported-by and Fixes tags?
--
Chuck Lever
[email protected]
reviewerQuoted 73 lines · Chuck Lever III
Quoted 73 lines · Jeff Layton
Quoted 25 lines · Chuck Lever III
Quoted 16 lines · Pumpkin
If the upgrading deny mode is invalid or conflicts with other client, we should try to resolve it, but the if-condition makes those error handling cannot be executed.
Signed-off-by Pumpkin <[email protected]>---
fs/nfsd/nfs4state.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5302
Quoted 6 lines
fs/nfsd/nfs4state.c +1
-1@@ -5298,7 +5298,7 @@ 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 != nfs_ok) {if (status != nfserr_share_denied) {if status ==
nfs_okthen status will definitely not equalshare_denied. So this check is a bit nonsensical as it stands.Quoted 9 lines
Usually I prefer "switch (status)" in situations like this because that avoids this kind of issue and I find it easier to read quickly.
Jeff, you are the original author of this function, and Dai, your commit is the last one to touch this area. Can you guys have a look? The one-liner looks correct, but I might be missing something.
Yeah, that code is clearly broken and it looks like it was done in
3d69427151806(NFSD: add support for share reservation conflict to courteous server).I don't believe that one-liner is correct though. If the result is
nfs_ok, then we want to set the deny mode here and that won't happen.Something like this maybe? (completely untested):
---------------8<-------------------
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 5297
Quoted 7 lines
fs/nfsd/nfs4state.c +5
-0+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);Would pynfs have a case or two that could test this?
pynfs has tests for open upgrade and downgrade but it only tests the upgrade/downgrade functionality without any deny mode and only from 1 client.
We need a test that does open upgrade/downgrade with share deny mode and with 2 clients, one is courtesy client. I will look into creating one.
-Dai
Quoted 10 lines
Can you post an official version of this patch with Reported-by and Fixes tags?
--
Chuck Lever
Jeff Layton
maintainerQuoted 86 lines · Chuck Lever III
Quoted 73 lines · Jeff Layton
Quoted 27 lines · Chuck Lever III
Quoted 17 lines · Pumpkin
If the upgrading deny mode is invalid or conflicts with other client, we should try to resolve it, but the if-condition makes those error handling cannot be executed.
Signed-off-by Pumpkin <[email protected]>---
fs/nfsd/nfs4state.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0fs/nfsd/nfs4state.c nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, · line 5302
Quoted 6 lines
fs/nfsd/nfs4state.c +1
-1@@ -5298,7 +5298,7 @@ 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 != nfs_ok) {if (status != nfserr_share_denied) {if status ==
nfs_okthen status will definitely not equalshare_denied. So this check is a bit nonsensical as it stands.Quoted 9 lines
Usually I prefer "switch (status)" in situations like this because that avoids this kind of issue and I find it easier to read quickly.
Jeff, you are the original author of this function, and Dai, your commit is the last one to touch this area. Can you guys have a look? The one-liner looks correct, but I might be missing something.
Yeah, that code is clearly broken and it looks like it was done in
3d69427151806(NFSD: add support for share reservation conflict to courteous server).I don't believe that one-liner is correct though. If the result is
nfs_ok, then we want to set the deny mode here and that won't happen.Something like this maybe? (completely untested):
---------------8<-------------------
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);Would pynfs have a case or two that could test this?
Quoted 4 lines
Can you post an official version of this patch with Reported-by and Fixes tags?
Sure, but I may not have time to test it out for a bit though.
Signature · 1 line
Jeff Layton <[email protected]>