Date: Thu, 1 Apr 2021 22:39:56 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: 4e6c2a1ee9af - main - nfsv4 client: factor loop contents out into a separate function Message-ID: <202104012239.131Mduau067177@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=4e6c2a1ee9af05bf42187e8201af1d03a617834f commit 4e6c2a1ee9af05bf42187e8201af1d03a617834f Author: Rick Macklem <rmacklem@FreeBSD.org> AuthorDate: 2021-04-01 22:36:37 +0000 Commit: Rick Macklem <rmacklem@FreeBSD.org> 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104012239.131Mduau067177>