From patchwork Thu Jan 5 12:15:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13089751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23789C54EBD for ; Thu, 5 Jan 2023 12:15:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231365AbjAEMPV (ORCPT ); Thu, 5 Jan 2023 07:15:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232926AbjAEMPS (ORCPT ); Thu, 5 Jan 2023 07:15:18 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D98C458FAA for ; Thu, 5 Jan 2023 04:15:17 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8E22FB81ABD for ; Thu, 5 Jan 2023 12:15:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00D63C433D2; Thu, 5 Jan 2023 12:15:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672920915; bh=RsJimtyejEI6shLrI7EHKX2SRLnEOu+qhk4RqOFVT50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XTZEYQfWcUR+yzNLUkcfLRS7y872q5zO0s9My8usT5lf6M6YN69GNY3MhmQQcBehQ jKH9DnKiTWKplSFzVeZ9FAtms+UhI3KKBOIg/7dITxFW/8MyiYYhIOXIsITJQ0ofvP lkgNg4MgqRH60vTp1Pz0aCuy4Obwqpwhotfj7kBb2UT9jnQCdHqGcYsQ5VY6jq9Gb+ c4VAKj20t1FI/+HgresmDTvlwI0VupOVDiZwVL2E4+9GI1CyRxJpFHgfk/mGbzlEjf +r0Chf/N29xiS6VJNljKKlCVjkmmvwA7SsLO02RwsbA2cRXM8PmBBSE1Qat7K09l/c GuWkdF/UYI8ew== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/4] nfsd: don't open-code clear_and_wake_up_bit Date: Thu, 5 Jan 2023 07:15:09 -0500 Message-Id: <20230105121512.21484-2-jlayton@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230105121512.21484-1-jlayton@kernel.org> References: <20230105121512.21484-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Signed-off-by: Jeff Layton --- fs/nfsd/filecache.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 6674a86e1917..9fff1fa09d08 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -1184,9 +1184,7 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_jukebox; if (status != nfs_ok) nfsd_file_unhash(nf); - clear_bit_unlock(NFSD_FILE_PENDING, &nf->nf_flags); - smp_mb__after_atomic(); - wake_up_bit(&nf->nf_flags, NFSD_FILE_PENDING); + clear_and_wake_up_bit(NFSD_FILE_PENDING, &nf->nf_flags); goto out; } From patchwork Thu Jan 5 12:15:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13089752 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B30C4C53210 for ; Thu, 5 Jan 2023 12:15:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232785AbjAEMPV (ORCPT ); Thu, 5 Jan 2023 07:15:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232101AbjAEMPR (ORCPT ); Thu, 5 Jan 2023 07:15:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D745844C7B for ; Thu, 5 Jan 2023 04:15:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 730A5619BA for ; Thu, 5 Jan 2023 12:15:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 921D8C433F0; Thu, 5 Jan 2023 12:15:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672920915; bh=3p+ngESF8KDQYHCVlyR+gbXAMRqoiukwDM35jBjQZnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fe1qmwYAP1hdESRBr8dQ29fOd+YtMH84NmLg9yst0FgZfZGXpLOBmaIRI4kEaHOa+ 41734WtCToaXafQuTGrSZfYml8yuWE6MtJUAvpeZ4RlKqJ2uQ14IvU5bNaPvbsuEIr BLhfWASGKoxWfzK0vwW1IZDix3/WuSPlW/NACNgrBzdG9So65yEz2mVXCx02TKAABV qvR3V/9otyljh5Qm4FkXVUVmZWDRk9TLuhjbyE0/yU49raI0sYj1JcTP57vNl5i25H 97wuXwZRiu/k5PG2cyClEy7kdqDav/eyMLjIlLCNxFXOPLC2eN2/vHuhBNshpO1WKZ PJweVsMP+LJvw== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/4] nfsd: NFSD_FILE_KEY_INODE only needs to find GC'ed entries Date: Thu, 5 Jan 2023 07:15:10 -0500 Message-Id: <20230105121512.21484-3-jlayton@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230105121512.21484-1-jlayton@kernel.org> References: <20230105121512.21484-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Since v4 files are expected to be long-lived, there's little value in closing them out of the cache when there is conflicting access. Rename NFSD_FILE_KEY_INODE to NFSD_FILE_KEY_INODE_GC, and change the comparator to also match the gc value in the key. Change both of the current users of that key to set the gc value in the key to "true". Also, test_bit returns bool, AFAICT, so I think we're ok to drop the !! from the condition later in the comparator. Signed-off-by: Jeff Layton --- fs/nfsd/filecache.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 9fff1fa09d08..a67b22579c6e 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -78,7 +78,7 @@ static struct rhashtable nfsd_file_rhash_tbl ____cacheline_aligned_in_smp; enum nfsd_file_lookup_type { - NFSD_FILE_KEY_INODE, + NFSD_FILE_KEY_INODE_GC, NFSD_FILE_KEY_FULL, }; @@ -174,7 +174,9 @@ static int nfsd_file_obj_cmpfn(struct rhashtable_compare_arg *arg, const struct nfsd_file *nf = ptr; switch (key->type) { - case NFSD_FILE_KEY_INODE: + case NFSD_FILE_KEY_INODE_GC: + if (test_bit(NFSD_FILE_GC, &nf->nf_flags) != key->gc) + return 1; if (nf->nf_inode != key->inode) return 1; break; @@ -187,7 +189,7 @@ static int nfsd_file_obj_cmpfn(struct rhashtable_compare_arg *arg, return 1; if (!nfsd_match_cred(nf->nf_cred, key->cred)) return 1; - if (!!test_bit(NFSD_FILE_GC, &nf->nf_flags) != key->gc) + if (test_bit(NFSD_FILE_GC, &nf->nf_flags) != key->gc) return 1; if (test_bit(NFSD_FILE_HASHED, &nf->nf_flags) == 0) return 1; @@ -681,8 +683,9 @@ static void nfsd_file_queue_for_close(struct inode *inode, struct list_head *dispose) { struct nfsd_file_lookup_key key = { - .type = NFSD_FILE_KEY_INODE, + .type = NFSD_FILE_KEY_INODE_GC, .inode = inode, + .gc = true, }; struct nfsd_file *nf; @@ -1057,8 +1060,9 @@ bool nfsd_file_is_cached(struct inode *inode) { struct nfsd_file_lookup_key key = { - .type = NFSD_FILE_KEY_INODE, + .type = NFSD_FILE_KEY_INODE_GC, .inode = inode, + .gc = true, }; bool ret = false; From patchwork Thu Jan 5 12:15:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13089749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04B6AC3DA7A for ; Thu, 5 Jan 2023 12:15:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231460AbjAEMPV (ORCPT ); Thu, 5 Jan 2023 07:15:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232785AbjAEMPR (ORCPT ); Thu, 5 Jan 2023 07:15:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10E42559DE for ; Thu, 5 Jan 2023 04:15:17 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A1763619FF for ; Thu, 5 Jan 2023 12:15:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25FB6C433F1; Thu, 5 Jan 2023 12:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672920916; bh=zxF6rfc1pRplAF1s3BDaUNR09oF2RCVgVRRhxBsuoAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g+fgEzRDiSADgugdQclFYP5YAeMlrru+Y4zZhWDiq7E8+yL2ybFmI8bNRXenfCibz HENn8yJSc2TELhFe2SQRMiRUHIhx2bjSj1Z+cMECchZYy7BvrMMyYbKflDLyX3Ny/W riEH2arsStz/1BdnO7YJMWgCLeG4paIV2VXD9No3VUCMiFT9iE5Y+ghsdr28DPLrJo B/ixbZo1S9w8lwtHoVwUTbSam1DAhdIqNzRg7+YJE3i7ghL3WFFEKgz4s7mz2O3JS3 QptxDrhS1/wBZo1bQRgJA7DNzu8MCuWtax2VXARzGfnEHXVTIVHwHPcUVIlZS5okfm 04SlYERMowKzw== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH 3/4] nfsd: don't kill nfsd_files because of lease break error Date: Thu, 5 Jan 2023 07:15:11 -0500 Message-Id: <20230105121512.21484-4-jlayton@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230105121512.21484-1-jlayton@kernel.org> References: <20230105121512.21484-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org An error from break_lease is non-fatal, so we needn't destroy the nfsd_file in that case. Just put the reference like we normally would and return the error. Signed-off-by: Jeff Layton --- fs/nfsd/filecache.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index a67b22579c6e..f0ca9501edb2 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -1113,7 +1113,7 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, nf = nfsd_file_alloc(&key, may_flags); if (!nf) { status = nfserr_jukebox; - goto out_status; + goto out; } ret = rhashtable_lookup_insert_key(&nfsd_file_rhash_tbl, @@ -1122,13 +1122,11 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, if (likely(ret == 0)) goto open_file; - nfsd_file_slab_free(&nf->nf_rcu); - nf = NULL; if (ret == -EEXIST) goto retry; trace_nfsd_file_insert_err(rqstp, key.inode, may_flags, ret); status = nfserr_jukebox; - goto out_status; + goto construction_err; wait_for_construction: wait_on_bit(&nf->nf_flags, NFSD_FILE_PENDING, TASK_UNINTERRUPTIBLE); @@ -1138,28 +1136,24 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, trace_nfsd_file_cons_err(rqstp, key.inode, may_flags, nf); if (!open_retry) { status = nfserr_jukebox; - goto out; + goto construction_err; } open_retry = false; - if (refcount_dec_and_test(&nf->nf_ref)) - nfsd_file_free(nf); goto retry; } - this_cpu_inc(nfsd_file_cache_hits); status = nfserrno(nfsd_open_break_lease(file_inode(nf->nf_file), may_flags)); + if (status != nfs_ok) { + nfsd_file_put(nf); + nf = NULL; + } + out: if (status == nfs_ok) { this_cpu_inc(nfsd_file_acquisitions); *pnf = nf; - } else { - if (refcount_dec_and_test(&nf->nf_ref)) - nfsd_file_free(nf); - nf = NULL; } - -out_status: put_cred(key.cred); trace_nfsd_file_acquire(rqstp, key.inode, may_flags, nf, status); return status; @@ -1189,6 +1183,13 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, if (status != nfs_ok) nfsd_file_unhash(nf); clear_and_wake_up_bit(NFSD_FILE_PENDING, &nf->nf_flags); + if (status == nfs_ok) + goto out; + +construction_err: + if (refcount_dec_and_test(&nf->nf_ref)) + nfsd_file_free(nf); + nf = NULL; goto out; } From patchwork Thu Jan 5 12:15:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13089753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B549C3DA7D for ; Thu, 5 Jan 2023 12:15:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232101AbjAEMPW (ORCPT ); Thu, 5 Jan 2023 07:15:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232987AbjAEMPU (ORCPT ); Thu, 5 Jan 2023 07:15:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4E1444C7B for ; Thu, 5 Jan 2023 04:15:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 50868B81AC6 for ; Thu, 5 Jan 2023 12:15:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE222C433EF; Thu, 5 Jan 2023 12:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672920917; bh=64ox1Dctbnqwo17SUA9JBVAOHUOogbmQ/K52bJnkFSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=peUE5QdY+WenaSEZTbR0mpAQHgjmtEWxkp2O3V9blJAc8ROYvbDCpgWp5RlxZY6tF RXI5JLRWfm9wTACgAw69rF7Q69ZDadWQ/PnzDEVUXCJ+bxy8iuELEqMCF+J+FbjZCK 36NOURRIxG9dfnEwp5TGtDYzxF425GYKHzmRHctewBQDvqaoS0wIV4CGieuEkqY2ui G85hr9q2OPgQsBEpbYSX9s3t8ai+RFBNxP+nM8tS66vNIcgmLrRb9TbkxzEenYf2HB SskWAwMSrPcHOF7UW6GEbF8Q6VAjwwkjs/cvRxo2uUrMz5mS1QRZRKcHRGQM/6OrRw ER8k7aFS6gZNg== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org, David Howells Subject: [PATCH 4/4] nfsd: add some comments to nfsd_file_do_acquire Date: Thu, 5 Jan 2023 07:15:12 -0500 Message-Id: <20230105121512.21484-5-jlayton@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230105121512.21484-1-jlayton@kernel.org> References: <20230105121512.21484-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org David Howells mentioned that he found this bit of code confusing, so sprinkle in some comments to clarify. Reported-by: David Howells Signed-off-by: Jeff Layton --- fs/nfsd/filecache.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index f0ca9501edb2..5724baad09ec 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -1105,6 +1105,11 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, rcu_read_unlock(); if (nf) { + /* + * If the nf is on the LRU then it holds an extra reference + * that must be put if it's removed. It had better not be + * the last one however, since we should hold another. + */ if (nfsd_file_lru_remove(nf)) WARN_ON_ONCE(refcount_dec_and_test(&nf->nf_ref)); goto wait_for_construction;