Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Mar 2021 22:16:19 GMT
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: fdc9b2d50fe9 - main - nfsv4 client: replace while loops with LIST_FOREACH() loops
Message-ID:  <202103292216.12TMGJx3065446@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=fdc9b2d50fe905b54afd773a2fc7fb9947508ddf

commit fdc9b2d50fe905b54afd773a2fc7fb9947508ddf
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2021-03-29 21:14:51 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2021-03-29 21:14:51 +0000

    nfsv4 client: replace while loops with LIST_FOREACH() loops
    
    This patch replaces a couple of while() loops with LIST_FOREACH() loops.
    While here, declare a couple of variables "bool".
    I think LIST_FOREACH() is preferred and makes the code more readable.
    This also prepares the code for future changes to use a hash table of
    lists for open searches via file handle.
    
    This patch should not result in a semantics change.
    
    MFC after:      2 weeks
---
 sys/fs/nfsclient/nfs_clstate.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c
index 1e4625191bfe..6cb737606525 100644
--- a/sys/fs/nfsclient/nfs_clstate.c
+++ b/sys/fs/nfsclient/nfs_clstate.c
@@ -507,7 +507,8 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode,
 	struct nfsnode *np;
 	struct nfsmount *nmp;
 	u_int8_t own[NFSV4CL_LOCKNAMELEN];
-	int error, done;
+	int error;
+	bool done;
 
 	*lckpp = NULL;
 	/*
@@ -596,9 +597,8 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode,
 	if (op == NULL) {
 		/* If not found, just look for any OpenOwner that will work. */
 		top = NULL;
-		done = 0;
-		owp = LIST_FIRST(&clp->nfsc_owner);
-		while (!done && owp != NULL) {
+		done = false;
+		LIST_FOREACH(owp, &clp->nfsc_owner, nfsow_list) {
 			LIST_FOREACH(op, &owp->nfsow_open, nfso_list) {
 				if (op->nfso_fhlen == fhlen &&
 				    !NFSBCMP(op->nfso_fh, nfhp, fhlen)) {
@@ -607,13 +607,13 @@ nfscl_getstateid(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t mode,
 					    (mode & NFSV4OPEN_ACCESSREAD) != 0)
 						top = op;
 					if ((mode & op->nfso_mode) == mode) {
-						done = 1;
+						done = true;
 						break;
 					}
 				}
 			}
-			if (!done)
-				owp = LIST_NEXT(owp, nfsow_list);
+			if (done)
+				break;
 		}
 		if (!done) {
 			NFSCL_DEBUG(2, "openmode top=%p\n", top);
@@ -653,7 +653,7 @@ nfscl_getopen(struct nfsclownerhead *ohp, u_int8_t *nfhp, int fhlen,
 	struct nfsclowner *owp;
 	struct nfsclopen *op, *rop, *rop2;
 	struct nfscllockowner *lp;
-	int keep_looping;
+	bool keep_looping;
 
 	if (lpp != NULL)
 		*lpp = NULL;
@@ -669,13 +669,11 @@ nfscl_getopen(struct nfsclownerhead *ohp, u_int8_t *nfhp, int fhlen,
 	 */
 	rop = NULL;
 	rop2 = NULL;
-	keep_looping = 1;
+	keep_looping = true;
 	/* Search the client list */
-	owp = LIST_FIRST(ohp);
-	while (owp != NULL && keep_looping != 0) {
+	LIST_FOREACH(owp, ohp, nfsow_list) {
 		/* and look for the correct open */
-		op = LIST_FIRST(&owp->nfsow_open);
-		while (op != NULL && keep_looping != 0) {
+		LIST_FOREACH(op, &owp->nfsow_open, nfso_list) {
 			if (op->nfso_fhlen == fhlen &&
 			    !NFSBCMP(op->nfso_fh, nfhp, fhlen)
 			    && (op->nfso_mode & mode) == mode) {
@@ -688,7 +686,7 @@ nfscl_getopen(struct nfsclownerhead *ohp, u_int8_t *nfhp, int fhlen,
 						    NFSV4CL_LOCKNAMELEN)) {
 							*lpp = lp;
 							rop = op;
-							keep_looping = 0;
+							keep_looping = false;
 							break;
 						}
 					}
@@ -697,14 +695,16 @@ nfscl_getopen(struct nfsclownerhead *ohp, u_int8_t *nfhp, int fhlen,
 				    openown, NFSV4CL_LOCKNAMELEN)) {
 					rop = op;
 					if (lpp == NULL)
-						keep_looping = 0;
+						keep_looping = false;
 				}
 				if (rop2 == NULL)
 					rop2 = op;
 			}
-			op = LIST_NEXT(op, nfso_list);
+			if (!keep_looping)
+				break;
 		}
-		owp = LIST_NEXT(owp, nfsow_list);
+		if (!keep_looping)
+			break;
 	}
 	if (rop == NULL)
 		rop = rop2;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103292216.12TMGJx3065446>