aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRick Macklem <rmacklem@FreeBSD.org>2021-03-29 21:14:51 +0000
committerRick Macklem <rmacklem@FreeBSD.org>2021-04-12 01:30:00 +0000
commit659d71186597adaf146033f269b3ab101a6bbfd5 (patch)
tree5a9b0d21b56e506eff6c64ab35c854a00a7bc8ec
parent968a4d11b881bba34f1a090f7e46f7e844f6ad3f (diff)
downloadsrc-659d71186597adaf146033f269b3ab101a6bbfd5.tar.gz
src-659d71186597adaf146033f269b3ab101a6bbfd5.zip
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. (cherry picked from commit fdc9b2d50fe905b54afd773a2fc7fb9947508ddf)
-rw-r--r--sys/fs/nfsclient/nfs_clstate.c34
1 files 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;