From owner-dev-commits-src-main@freebsd.org Thu Apr 1 22:39:56 2021 Return-Path: Delivered-To: dev-commits-src-main@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 538285B9706; Thu, 1 Apr 2021 22:39:56 +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 4FBJ641xtwz3CCV; Thu, 1 Apr 2021 22:39:56 +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 3592315330; Thu, 1 Apr 2021 22:39:56 +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 131Mduom067178; Thu, 1 Apr 2021 22:39:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 131Mduau067177; Thu, 1 Apr 2021 22:39:56 GMT (envelope-from git) Date: Thu, 1 Apr 2021 22:39:56 GMT Message-Id: <202104012239.131Mduau067177@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: 4e6c2a1ee9af - main - nfsv4 client: factor loop contents out into a separate function 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/main X-Git-Reftype: branch X-Git-Commit: 4e6c2a1ee9af05bf42187e8201af1d03a617834f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2021 22:39:56 -0000 The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=4e6c2a1ee9af05bf42187e8201af1d03a617834f commit 4e6c2a1ee9af05bf42187e8201af1d03a617834f Author: Rick Macklem AuthorDate: 2021-04-01 22:36:37 +0000 Commit: Rick Macklem CommitDate: 2021-04-01 22:36:37 +0000 nfsv4 client: factor loop contents out into a separate function Commit fdc9b2d50fe9 replaced a couple of while loops with LIST_FOREACH() loops. This patch factors the body of that loop out into a separate function called nfscl_checkown(). This 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 | 63 +++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c index 6cb737606525..e310deff6cf9 100644 --- a/sys/fs/nfsclient/nfs_clstate.c +++ b/sys/fs/nfsclient/nfs_clstate.c @@ -102,6 +102,9 @@ static int nfscl_delegcnt = 0; static int nfscl_layoutcnt = 0; static int nfscl_getopen(struct nfsclownerhead *, u_int8_t *, int, u_int8_t *, u_int8_t *, u_int32_t, struct nfscllockowner **, struct nfsclopen **); +static bool nfscl_checkown(struct nfsclowner *, struct nfsclopen *, uint8_t *, + uint8_t *, struct nfscllockowner **, struct nfsclopen **, + struct nfsclopen **); static void nfscl_clrelease(struct nfsclclient *); static void nfscl_cleanclient(struct nfsclclient *); static void nfscl_expireclient(struct nfsclclient *, struct nfsmount *, @@ -652,7 +655,6 @@ nfscl_getopen(struct nfsclownerhead *ohp, u_int8_t *nfhp, int fhlen, { struct nfsclowner *owp; struct nfsclopen *op, *rop, *rop2; - struct nfscllockowner *lp; bool keep_looping; if (lpp != NULL) @@ -676,30 +678,9 @@ nfscl_getopen(struct nfsclownerhead *ohp, u_int8_t *nfhp, int fhlen, LIST_FOREACH(op, &owp->nfsow_open, nfso_list) { if (op->nfso_fhlen == fhlen && !NFSBCMP(op->nfso_fh, nfhp, fhlen) - && (op->nfso_mode & mode) == mode) { - if (lpp != NULL) { - /* Now look for a matching lockowner. */ - LIST_FOREACH(lp, &op->nfso_lock, - nfsl_list) { - if (!NFSBCMP(lp->nfsl_owner, - lockown, - NFSV4CL_LOCKNAMELEN)) { - *lpp = lp; - rop = op; - keep_looping = false; - break; - } - } - } - if (rop == NULL && !NFSBCMP(owp->nfsow_owner, - openown, NFSV4CL_LOCKNAMELEN)) { - rop = op; - if (lpp == NULL) - keep_looping = false; - } - if (rop2 == NULL) - rop2 = op; - } + && (op->nfso_mode & mode) == mode) + keep_looping = nfscl_checkown(owp, op, openown, + lockown, lpp, &rop, &rop2); if (!keep_looping) break; } @@ -714,6 +695,38 @@ nfscl_getopen(struct nfsclownerhead *ohp, u_int8_t *nfhp, int fhlen, return (0); } +/* Check for an owner match. */ +static bool +nfscl_checkown(struct nfsclowner *owp, struct nfsclopen *op, uint8_t *openown, + uint8_t *lockown, struct nfscllockowner **lpp, struct nfsclopen **ropp, + struct nfsclopen **ropp2) +{ + struct nfscllockowner *lp; + bool keep_looping; + + keep_looping = true; + if (lpp != NULL) { + /* Now look for a matching lockowner. */ + LIST_FOREACH(lp, &op->nfso_lock, nfsl_list) { + if (!NFSBCMP(lp->nfsl_owner, lockown, + NFSV4CL_LOCKNAMELEN)) { + *lpp = lp; + *ropp = op; + return (false); + } + } + } + if (*ropp == NULL && !NFSBCMP(owp->nfsow_owner, openown, + NFSV4CL_LOCKNAMELEN)) { + *ropp = op; + if (lpp == NULL) + keep_looping = false; + } + if (*ropp2 == NULL) + *ropp2 = op; + return (keep_looping); +} + /* * Release use of an open owner. Called when open operations are done * with the open owner.