Skip to contentSkip to conversation

nfsd: fix courtesy client with deny mode handling in nfs4_upgrade_open

PATCH Applied Jeff Layton 3 participants 6 messages Feb 3, 2023 – Feb 16, 2023

Subsystems (2)
lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

PATCH 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.

Fixes 3d69427151806 (NFSD: add support for share reservation conflict to courteous server)
Cc Dai Ngo <[email protected]>
---
 fs/nfsd/nfs4state.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
fs/nfsd/nfs4state.c +11 -10
index c39e43742dd6..af22dfdc6fcc 100644
@@ -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
#1 lore raw
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)
Cc Dai Ngo <[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
index c39e43742dd6..af22dfdc6fcc 100644
@@ -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

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Jeff Layton
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)
Cc Dai Ngo <[email protected]>
---
  fs/nfsd/nfs4state.c | 21 +++++++++++----------
  1 file changed, 11 insertions(+), 10 deletions(-)
fs/nfsd/nfs4state.c +3 -10
index c39e43742dd6..af22dfdc6fcc 100644
@@ -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
#3 lore raw
Quoted 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)
Cc Dai Ngo <[email protected]>
---
 fs/nfsd/nfs4state.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
fs/nfsd/nfs4state.c +7 -10
index c39e43742dd6..af22dfdc6fcc 100644
@@ -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);

Thanks! Applied to nfsd-next.

--
Chuck Lever

#4 lore raw
In reply to Jeff Layton

Hi 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)
Cc Dai Ngo <[email protected]>
---
  fs/nfsd/nfs4state.c | 21 +++++++++++----------
  1 file changed, 11 insertions(+), 10 deletions(-)
fs/nfsd/nfs4state.c +0 -9
index c39e43742dd6..af22dfdc6fcc 100644
@@ -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);
 
#5 lore raw
Quoted 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)
Cc Dai Ngo <[email protected]>

---
  fs/nfsd/nfs4state.c | 21 +++++++++++----------

  1 file changed, 11 insertions(+), 10 deletions(-)
fs/nfsd/nfs4state.c +6 -10
index c39e43742dd6..af22dfdc6fcc 100644
@@ -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_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.

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);