From owner-dev-commits-src-all@freebsd.org Mon Apr 12 01:34:39 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C56885E5554; Mon, 12 Apr 2021 01:34:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FJWW35889z4rVW; Mon, 12 Apr 2021 01:34:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A378265C0; Mon, 12 Apr 2021 01:34:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13C1YdHc072203; Mon, 12 Apr 2021 01:34:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13C1Yd6W072202; Mon, 12 Apr 2021 01:34:39 GMT (envelope-from git) Date: Mon, 12 Apr 2021 01:34:39 GMT Message-Id: <202104120134.13C1Yd6W072202@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: 659d71186597 - stable/13 - nfsv4 client: replace while loops with LIST_FOREACH() loops MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 659d71186597adaf146033f269b3ab101a6bbfd5 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Apr 2021 01:34:39 -0000 The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=659d71186597adaf146033f269b3ab101a6bbfd5 commit 659d71186597adaf146033f269b3ab101a6bbfd5 Author: Rick Macklem AuthorDate: 2021-03-29 21:14:51 +0000 Commit: Rick Macklem CommitDate: 2021-04-12 01:30:00 +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. (cherry picked from commit fdc9b2d50fe905b54afd773a2fc7fb9947508ddf) --- 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;