From patchwork Sun Mar 1 23:21:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11414565 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3485E1800 for ; Sun, 1 Mar 2020 23:25:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A74F246B6 for ; Sun, 1 Mar 2020 23:25:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QE0WmNou" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726562AbgCAXZQ (ORCPT ); Sun, 1 Mar 2020 18:25:16 -0500 Received: from mail-yw1-f66.google.com ([209.85.161.66]:43717 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726050AbgCAXZP (ORCPT ); Sun, 1 Mar 2020 18:25:15 -0500 Received: by mail-yw1-f66.google.com with SMTP id u78so4672586ywf.10 for ; Sun, 01 Mar 2020 15:25:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M8qHIALFHS4iOjubUfvsPbpUxxXoz9pieckInQwWYAE=; b=QE0WmNou4KnCXTxVLUPn9MNuDB4tijkKa2lvz+Tq6z5bHlR0/TcHGaI5/fl9Ep/ovW eKIfltMH7zjsp+NxsZfdwv0VbZxPUuOA5X030QXF6DCQaWHpYVEe0ooKPBKlf9HieN+0 fa4dAoELTdZL8y+CgSVYJz0BBkhIk9QmFGE+w02nf6F/wsWAj3qpyXxsXMOAk47qQrJE wwPiinkQsNPZpRKdhux2nGMQKm+F/d0/v1MnCcw+5GPjVQ2ZRxx6AKrMDaVhxGTg9w9q 1NQONnvylr9zbfEzIY67P9PmqC/WitlXTSz31sjO4mLIZEpEBcN0xgXI5s2CbDYhrnWT OGfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M8qHIALFHS4iOjubUfvsPbpUxxXoz9pieckInQwWYAE=; b=e/gSlWq10jagLfhbFXcW4t77kQstGXEcDife5Ykt0EVaxCoammvrX87gs6fF81JBsf qrLLGoSIGec9Xl/VY/WmLRhRucZk0N+jFdnho5g9Md0xlwH7R5UZDbetl9Fn/8bPnRcv uG6T9VRPGvZ0sQzt/mVGUJqH6e3rO3x1MDSsgT5qbXDETJ7Tdtszl/vgIcl+c0GCRhHz SpcQC6Qt25Q1OlgS7ZXY0JMSEgW8J5AIw6SHWkOJHz8LffcOGHYWy7wk4fZ00wYpj6D8 NcQRPv0VtthbwV7rNilLAc1xRphBv4EdvLyhPPtXBD+Iv0lF5W3gj9FNFj7qbTmrcnkq a15Q== X-Gm-Message-State: APjAAAV6jfbrPvyQU8XlmYIBot5pPeSWtefSB9/MiSbmjz3E7ktHIrC5 qKbwMDe6AxXauUokNm3zMg== X-Google-Smtp-Source: APXvYqxYJ+KvmGuy1EzzRlirRT0IHnLcWD6oMVw4NXXJz7OCwnraRIL0yR7xnU9VDx7gOWAn1aG/uQ== X-Received: by 2002:a81:5303:: with SMTP id h3mr14594643ywb.267.1583105114827; Sun, 01 Mar 2020 15:25:14 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u4sm7167301ywu.26.2020.03.01.15.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 15:25:14 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/8] nfsd: Don't add locks to closed or closing open stateids Date: Sun, 1 Mar 2020 18:21:38 -0500 Message-Id: <20200301232145.1465430-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200301232145.1465430-1-trond.myklebust@hammerspace.com> References: <20200301232145.1465430-1-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org In NFSv4, the lock stateids are tied to the lockowner, and the open stateid, so that the action of closing the file also results in either an automatic loss of the locks, or an error of the form NFS4ERR_LOCKS_HELD. In practice this means we must not add new locks to the open stateid after the close process has been invoked. In fact doing so, can result in the following panic: kernel BUG at lib/list_debug.c:51! invalid opcode: 0000 [#1] SMP NOPTI CPU: 2 PID: 1085 Comm: nfsd Not tainted 5.6.0-rc3+ #2 Hardware name: VMware, Inc. VMware7,1/440BX Desktop Reference Platform, BIOS VMW71.00V.14410784.B64.1908150010 08/15/2019 RIP: 0010:__list_del_entry_valid.cold+0x31/0x55 Code: 1a 3d 9b e8 74 10 c2 ff 0f 0b 48 c7 c7 f0 1a 3d 9b e8 66 10 c2 ff 0f 0b 48 89 f2 48 89 fe 48 c7 c7 b0 1a 3d 9b e8 52 10 c2 ff <0f> 0b 48 89 fe 4c 89 c2 48 c7 c7 78 1a 3d 9b e8 3e 10 c2 ff 0f 0b RSP: 0018:ffffb296c1d47d90 EFLAGS: 00010246 RAX: 0000000000000054 RBX: ffff8ba032456ec8 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffff8ba039e99cc8 RDI: ffff8ba039e99cc8 RBP: ffff8ba032456e60 R08: 0000000000000781 R09: 0000000000000003 R10: 0000000000000000 R11: 0000000000000001 R12: ffff8ba009a4abe0 R13: ffff8ba032456e8c R14: 0000000000000000 R15: ffff8ba00adb01d8 FS: 0000000000000000(0000) GS:ffff8ba039e80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fb213f0b008 CR3: 00000001347de006 CR4: 00000000003606e0 Call Trace: release_lock_stateid+0x2b/0x80 [nfsd] nfsd4_free_stateid+0x1e9/0x210 [nfsd] nfsd4_proc_compound+0x414/0x700 [nfsd] ? nfs4svc_decode_compoundargs+0x407/0x4c0 [nfsd] nfsd_dispatch+0xc1/0x200 [nfsd] svc_process_common+0x476/0x6f0 [sunrpc] ? svc_sock_secure_port+0x12/0x30 [sunrpc] ? svc_recv+0x313/0x9c0 [sunrpc] ? nfsd_svc+0x2d0/0x2d0 [nfsd] svc_process+0xd4/0x110 [sunrpc] nfsd+0xe3/0x140 [nfsd] kthread+0xf9/0x130 ? nfsd_destroy+0x50/0x50 [nfsd] ? kthread_park+0x90/0x90 ret_from_fork+0x1f/0x40 The fix is to ensure that lock creation tests for whether or not the open stateid is unhashed, and to fail if that is the case. Fixes: 659aefb68eca ("nfsd: Ensure we don't recognise lock stateids after freeing them") Signed-off-by: Trond Myklebust --- fs/nfsd/nfs4state.c | 73 ++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 65cfe9ab47be..1ba4514be18d 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -494,6 +494,8 @@ find_any_file(struct nfs4_file *f) { struct nfsd_file *ret; + if (!f) + return NULL; spin_lock(&f->fi_lock); ret = __nfs4_get_fd(f, O_RDWR); if (!ret) { @@ -1309,6 +1311,12 @@ static void nfs4_put_stateowner(struct nfs4_stateowner *sop) nfs4_free_stateowner(sop); } +static bool +nfs4_ol_stateid_unhashed(const struct nfs4_ol_stateid *stp) +{ + return list_empty(&stp->st_perfile); +} + static bool unhash_ol_stateid(struct nfs4_ol_stateid *stp) { struct nfs4_file *fp = stp->st_stid.sc_file; @@ -1379,9 +1387,11 @@ static bool unhash_lock_stateid(struct nfs4_ol_stateid *stp) { lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); + if (!unhash_ol_stateid(stp)) + return false; list_del_init(&stp->st_locks); nfs4_unhash_stid(&stp->st_stid); - return unhash_ol_stateid(stp); + return true; } static void release_lock_stateid(struct nfs4_ol_stateid *stp) @@ -1446,13 +1456,12 @@ static void release_open_stateid_locks(struct nfs4_ol_stateid *open_stp, static bool unhash_open_stateid(struct nfs4_ol_stateid *stp, struct list_head *reaplist) { - bool unhashed; - lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); - unhashed = unhash_ol_stateid(stp); + if (!unhash_ol_stateid(stp)) + return false; release_open_stateid_locks(stp, reaplist); - return unhashed; + return true; } static void release_open_stateid(struct nfs4_ol_stateid *stp) @@ -6393,21 +6402,21 @@ alloc_init_lock_stateowner(unsigned int strhashval, struct nfs4_client *clp, } static struct nfs4_ol_stateid * -find_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp) +find_lock_stateid(const struct nfs4_lockowner *lo, + const struct nfs4_ol_stateid *ost) { struct nfs4_ol_stateid *lst; - struct nfs4_client *clp = lo->lo_owner.so_client; - lockdep_assert_held(&clp->cl_lock); + lockdep_assert_held(&ost->st_stid.sc_client->cl_lock); - list_for_each_entry(lst, &lo->lo_owner.so_stateids, st_perstateowner) { - if (lst->st_stid.sc_type != NFS4_LOCK_STID) - continue; - if (lst->st_stid.sc_file == fp) { - refcount_inc(&lst->st_stid.sc_count); - return lst; + /* If ost is not hashed, ost->st_locks will not be valid */ + if (!nfs4_ol_stateid_unhashed(ost)) + list_for_each_entry(lst, &ost->st_locks, st_locks) { + if (lst->st_stateowner == &lo->lo_owner) { + refcount_inc(&lst->st_stid.sc_count); + return lst; + } } - } return NULL; } @@ -6423,11 +6432,11 @@ init_lock_stateid(struct nfs4_ol_stateid *stp, struct nfs4_lockowner *lo, mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); retry: spin_lock(&clp->cl_lock); - spin_lock(&fp->fi_lock); - retstp = find_lock_stateid(lo, fp); + if (nfs4_ol_stateid_unhashed(open_stp)) + goto out_close; + retstp = find_lock_stateid(lo, open_stp); if (retstp) - goto out_unlock; - + goto out_found; refcount_inc(&stp->st_stid.sc_count); stp->st_stid.sc_type = NFS4_LOCK_STID; stp->st_stateowner = nfs4_get_stateowner(&lo->lo_owner); @@ -6436,22 +6445,26 @@ init_lock_stateid(struct nfs4_ol_stateid *stp, struct nfs4_lockowner *lo, stp->st_access_bmap = 0; stp->st_deny_bmap = open_stp->st_deny_bmap; stp->st_openstp = open_stp; + spin_lock(&fp->fi_lock); list_add(&stp->st_locks, &open_stp->st_locks); list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids); list_add(&stp->st_perfile, &fp->fi_stateids); -out_unlock: spin_unlock(&fp->fi_lock); spin_unlock(&clp->cl_lock); - if (retstp) { - if (nfsd4_lock_ol_stateid(retstp) != nfs_ok) { - nfs4_put_stid(&retstp->st_stid); - goto retry; - } - /* To keep mutex tracking happy */ - mutex_unlock(&stp->st_mutex); - stp = retstp; - } return stp; +out_found: + spin_unlock(&clp->cl_lock); + if (nfsd4_lock_ol_stateid(retstp) != nfs_ok) { + nfs4_put_stid(&retstp->st_stid); + goto retry; + } + /* To keep mutex tracking happy */ + mutex_unlock(&stp->st_mutex); + return retstp; +out_close: + spin_unlock(&clp->cl_lock); + mutex_unlock(&stp->st_mutex); + return NULL; } static struct nfs4_ol_stateid * @@ -6466,7 +6479,7 @@ find_or_create_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fi, *new = false; spin_lock(&clp->cl_lock); - lst = find_lock_stateid(lo, fi); + lst = find_lock_stateid(lo, ost); spin_unlock(&clp->cl_lock); if (lst != NULL) { if (nfsd4_lock_ol_stateid(lst) == nfs_ok) From patchwork Sun Mar 1 23:21:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11414569 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D985092A for ; Sun, 1 Mar 2020 23:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B929624699 for ; Sun, 1 Mar 2020 23:25:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H26CeLc0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726592AbgCAXZR (ORCPT ); Sun, 1 Mar 2020 18:25:17 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:43719 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726050AbgCAXZQ (ORCPT ); Sun, 1 Mar 2020 18:25:16 -0500 Received: by mail-yw1-f67.google.com with SMTP id u78so4672619ywf.10 for ; Sun, 01 Mar 2020 15:25:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ds3vP0pr/vApQsOppNkATvBSjNkIOcY6j7wOViIDBOE=; b=H26CeLc0sUsga0syMXZMYXJ92gaZFBIxooXue+sTXJvM5DSd8YLkpmU3qvU2nxU+2e KHwfdmv1EMPdfYMUUX78a0kDxkuHI6XOtNlzJz8ZotM3FcDtMSk9d+JDI4HPj2b6mMpI eBh2+P9wWHo/iTyZ0Cglmn2ZT8C7eTp1SluvLL0O+iiopipTfpXcUlWFYgiKbm02CIu0 M1vrMhalgdRaZ8TA/f1XEVL+KBUb6MEtRIJ+Q/XaF4pMwwz4j+Hd/2RKtrp9Kyr5zPyd KSA+xqRFcnnMMDsKUlVtTvRJkatg9FeIV6LUA55qiKmLKhNx84BA/oikh9X1pvig/N+D yw+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ds3vP0pr/vApQsOppNkATvBSjNkIOcY6j7wOViIDBOE=; b=PskLJIqy/IcBsElVCaPclJwWKbJxsh1BsSu9tIxhUZonxmZeb5/7qXFlqwmovewfRf o2UG8b9yFFPfQWV+v7l3SRwDlgdIzFoOZGBqPFBPsg2jWZFcXoGJVQw89QFlo1Y+0Bf8 DhsAe6KcmwgBv5wVOGzZ+a2RkHAAbhkgTOJzFbup5G6IBimliR3VFn6LV0chVNM/59nD OTRqzgKx/6FDAeE38LnELYFDfA5F6X39A/wBWGxI7zoG4NTblaoxkX6lQexN4ztnz1sF uvwkRJqvyoXVpeP7O/MCbjZKogXo6mTXJUq94XWrhc1IgUJXVxpTQxB8aJHegNG0Iqty 5r4A== X-Gm-Message-State: APjAAAUt7pHqNkBJiB5GM7qwfoZkDjTFVCYdhf0K/5Est7hfm9wsKTub J55MygE6odkXepaTYZfPnQ== X-Google-Smtp-Source: APXvYqzl39T8JSRAq1wQN06caINNSaqI71oUCCi5AFECRHz0e/06XWd7l5PeIKI7RpeqkWjEvjKAug== X-Received: by 2002:a0d:ebc9:: with SMTP id u192mr14379842ywe.360.1583105115924; Sun, 01 Mar 2020 15:25:15 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u4sm7167301ywu.26.2020.03.01.15.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 15:25:15 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/8] nfsd: Add tracing to nfsd_set_fh_dentry() Date: Sun, 1 Mar 2020 18:21:39 -0500 Message-Id: <20200301232145.1465430-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200301232145.1465430-2-trond.myklebust@hammerspace.com> References: <20200301232145.1465430-1-trond.myklebust@hammerspace.com> <20200301232145.1465430-2-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add tracing to allow us to figure out where any stale filehandle issues may be originating from. Signed-off-by: Trond Myklebust --- fs/nfsd/nfsfh.c | 13 ++++++++++--- fs/nfsd/trace.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c index b319080288c3..37bc8f5f4514 100644 --- a/fs/nfsd/nfsfh.c +++ b/fs/nfsd/nfsfh.c @@ -14,6 +14,7 @@ #include "nfsd.h" #include "vfs.h" #include "auth.h" +#include "trace.h" #define NFSDDBG_FACILITY NFSDDBG_FH @@ -209,11 +210,14 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp) } error = nfserr_stale; - if (PTR_ERR(exp) == -ENOENT) - return error; + if (IS_ERR(exp)) { + trace_nfsd_set_fh_dentry_badexport(rqstp, fhp, PTR_ERR(exp)); + + if (PTR_ERR(exp) == -ENOENT) + return error; - if (IS_ERR(exp)) return nfserrno(PTR_ERR(exp)); + } if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) { /* Elevate privileges so that the lack of 'r' or 'x' @@ -267,6 +271,9 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp) dentry = exportfs_decode_fh(exp->ex_path.mnt, fid, data_left, fileid_type, nfsd_acceptable, exp); + if (IS_ERR_OR_NULL(dentry)) + trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp, + dentry ? PTR_ERR(dentry) : -ESTALE); } if (dentry == NULL) goto out; diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h index 06dd0d337049..9abd1591a841 100644 --- a/fs/nfsd/trace.h +++ b/fs/nfsd/trace.h @@ -50,6 +50,36 @@ TRACE_EVENT(nfsd_compound_status, __get_str(name), __entry->status) ) +DECLARE_EVENT_CLASS(nfsd_fh_err_class, + TP_PROTO(struct svc_rqst *rqstp, + struct svc_fh *fhp, + int status), + TP_ARGS(rqstp, fhp, status), + TP_STRUCT__entry( + __field(u32, xid) + __field(u32, fh_hash) + __field(int, status) + ), + TP_fast_assign( + __entry->xid = be32_to_cpu(rqstp->rq_xid); + __entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle); + __entry->status = status; + ), + TP_printk("xid=0x%08x fh_hash=0x%08x status=%d", + __entry->xid, __entry->fh_hash, + __entry->status) +) + +#define DEFINE_NFSD_FH_ERR_EVENT(name) \ +DEFINE_EVENT(nfsd_fh_err_class, nfsd_##name, \ + TP_PROTO(struct svc_rqst *rqstp, \ + struct svc_fh *fhp, \ + int status), \ + TP_ARGS(rqstp, fhp, status)) + +DEFINE_NFSD_FH_ERR_EVENT(set_fh_dentry_badexport); +DEFINE_NFSD_FH_ERR_EVENT(set_fh_dentry_badhandle); + DECLARE_EVENT_CLASS(nfsd_io_class, TP_PROTO(struct svc_rqst *rqstp, struct svc_fh *fhp, From patchwork Sun Mar 1 23:21:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11414571 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E71D1800 for ; Sun, 1 Mar 2020 23:25:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E292324699 for ; Sun, 1 Mar 2020 23:25:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g84hdTyV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbgCAXZS (ORCPT ); Sun, 1 Mar 2020 18:25:18 -0500 Received: from mail-yw1-f66.google.com ([209.85.161.66]:42398 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726050AbgCAXZS (ORCPT ); Sun, 1 Mar 2020 18:25:18 -0500 Received: by mail-yw1-f66.google.com with SMTP id n127so9454620ywd.9 for ; Sun, 01 Mar 2020 15:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p9LwGjWOmssh6gQXkXnUBTSYCwZetwFOik6mpoK+NvY=; b=g84hdTyVdEJdVrU7A+7QU8J9vLzWRX/p9A61pNRmvPJC5uWZ0ezkw5eoDSUyzTtqdc nn8qqOw5Kps1A5AntdAANlByv/AEItj9F0niXS7fczW10JvTawYJxYYvlRYslTHX4reb 2gcyGo0j7+C9SFoIgfjJlrFxMguY/e4GR0+n5yxcu9sA4AU3oRyPYqp3GV/bdTE2wCGB maGH3B2x5oOaIyDvqxnAsrhulJDu0VuGKApaDa0xF+Ii4S43C+dmXMLHM//GfTrUqlgR w7/zRynPuW0qE5NqtrcfQtIARcrGADJCrSUG+i7ndvipnk+8du+oVQz5HXK/MOp7EXBx bwnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p9LwGjWOmssh6gQXkXnUBTSYCwZetwFOik6mpoK+NvY=; b=hRD86ScRjWL3eJHFSmtFld9D2dkAN7gJeYHQqzz1yAdfUxWFsZ6lqQHWPyUoBY1C23 uwN3VtbMVNhEEeWRbOsBWKkfjGDDpnDBXoVMqpYOpY9fYJFiPVf0rECWOi4HfIMe1eG+ HwYPcymw054RGHT5N5TOQ5gdBGDQJNjHvbnYvqdfUyrvqdJvSOROzr85HpORlyNGE36/ BsT5OPh/naQ9kHZShbFjQ3pkKyk/VM77MCasZ5Nq4NPElS867NOG+6+Nb0fokuiHcBwS PkDYiw4/223PX6bWJRiA9rRNQoI2G2LHjglt7mXAys/zYG7bolgPfRDn8pBt7fjlgceO hOtA== X-Gm-Message-State: APjAAAVdsIHua+BMWw1mYcj0Ju92WbFNsXhShooFqfrtQNtxrCP97Za/ jP3ly92oS1lqpmVmyUodFEVnxYUgVA== X-Google-Smtp-Source: APXvYqyviRdG8PiOkecFwVw0wHEbrxJ10k3QXNOGBOoROx8w7C7arjH4IkCO7hlIKVg5pkPzQ3oJ6g== X-Received: by 2002:a81:4603:: with SMTP id t3mr14219487ywa.97.1583105116864; Sun, 01 Mar 2020 15:25:16 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u4sm7167301ywu.26.2020.03.01.15.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 15:25:16 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 3/8] nfsd: Add tracepoints for exp_find_key() and exp_get_by_name() Date: Sun, 1 Mar 2020 18:21:40 -0500 Message-Id: <20200301232145.1465430-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200301232145.1465430-3-trond.myklebust@hammerspace.com> References: <20200301232145.1465430-1-trond.myklebust@hammerspace.com> <20200301232145.1465430-2-trond.myklebust@hammerspace.com> <20200301232145.1465430-3-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add tracepoints for upcalls. Signed-off-by: Trond Myklebust --- fs/nfsd/export.c | 9 +++++++-- fs/nfsd/trace.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c index 15422c951fd1..e867db0bb380 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c @@ -23,6 +23,7 @@ #include "netns.h" #include "pnfs.h" #include "filecache.h" +#include "trace.h" #define NFSDDBG_FACILITY NFSDDBG_EXPORT @@ -832,8 +833,10 @@ exp_find_key(struct cache_detail *cd, struct auth_domain *clp, int fsid_type, if (ek == NULL) return ERR_PTR(-ENOMEM); err = cache_check(cd, &ek->h, reqp); - if (err) + if (err) { + trace_nfsd_exp_find_key(&key, err); return ERR_PTR(err); + } return ek; } @@ -855,8 +858,10 @@ exp_get_by_name(struct cache_detail *cd, struct auth_domain *clp, if (exp == NULL) return ERR_PTR(-ENOMEM); err = cache_check(cd, &exp->h, reqp); - if (err) + if (err) { + trace_nfsd_exp_get_by_name(&key, err); return ERR_PTR(err); + } return exp; } diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h index 9abd1591a841..3b9277d7b5f2 100644 --- a/fs/nfsd/trace.h +++ b/fs/nfsd/trace.h @@ -9,6 +9,7 @@ #define _NFSD_TRACE_H #include +#include "export.h" #include "nfsfh.h" TRACE_EVENT(nfsd_compound, @@ -80,6 +81,51 @@ DEFINE_EVENT(nfsd_fh_err_class, nfsd_##name, \ DEFINE_NFSD_FH_ERR_EVENT(set_fh_dentry_badexport); DEFINE_NFSD_FH_ERR_EVENT(set_fh_dentry_badhandle); +TRACE_EVENT(nfsd_exp_find_key, + TP_PROTO(const struct svc_expkey *key, + int status), + TP_ARGS(key, status), + TP_STRUCT__entry( + __field(int, fsidtype) + __array(u32, fsid, 6) + __string(auth_domain, key->ek_client->name) + __field(int, status) + ), + TP_fast_assign( + __entry->fsidtype = key->ek_fsidtype; + memcpy(__entry->fsid, key->ek_fsid, 4*6); + __assign_str(auth_domain, key->ek_client->name); + __entry->status = status; + ), + TP_printk("fsid=%x::%s domain=%s status=%d", + __entry->fsidtype, + __print_array(__entry->fsid, 6, 4), + __get_str(auth_domain), + __entry->status + ) +); + +TRACE_EVENT(nfsd_exp_get_by_name, + TP_PROTO(const struct svc_export *key, + int status), + TP_ARGS(key, status), + TP_STRUCT__entry( + __string(path, key->ex_path.dentry->d_name.name) + __string(auth_domain, key->ex_client->name) + __field(int, status) + ), + TP_fast_assign( + __assign_str(path, key->ex_path.dentry->d_name.name); + __assign_str(auth_domain, key->ex_client->name); + __entry->status = status; + ), + TP_printk("path=%s domain=%s status=%d", + __get_str(path), + __get_str(auth_domain), + __entry->status + ) +); + DECLARE_EVENT_CLASS(nfsd_io_class, TP_PROTO(struct svc_rqst *rqstp, struct svc_fh *fhp, From patchwork Sun Mar 1 23:21:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11414575 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75BA514BC for ; Sun, 1 Mar 2020 23:25:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 545C424699 for ; Sun, 1 Mar 2020 23:25:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NoeH/02s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726050AbgCAXZU (ORCPT ); Sun, 1 Mar 2020 18:25:20 -0500 Received: from mail-yw1-f66.google.com ([209.85.161.66]:46908 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbgCAXZU (ORCPT ); Sun, 1 Mar 2020 18:25:20 -0500 Received: by mail-yw1-f66.google.com with SMTP id n1so8945711ywe.13 for ; Sun, 01 Mar 2020 15:25:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1ro0Ba+6pk8IfNjZpm7XGUiBmJP7EtwT3otvd3Y4S3I=; b=NoeH/02sDCGzAReFr1cjK4kn/EJb8GMs+Xm5vue9MYAGufNOJWb4H7TM/3mtfwHD15 1DOYdcWczakuTsMC/cCzyYv+4f4bzIoLclQ1QDkjQISjAVXk7JNXx27TW3lmefFp4RzL OHcmBHrB3D3EsFDRNy3taDVX7lKnXgBvn5iz9e0igjrvCeG+5CWWxvY8+PfGkG18hGc7 uGX+ZlhZiZ8nrq4ObsmVqEnnjmt/8ZVdmnL9yqUyduPEpoKKcHdxgwHk6VYGZtt7jgUh Ys0s179EhmpGngBIpqTMoH27PsYiU4ZOTXO9P5lvEJPXFbQrecU0lv8DKGG/P46zrVbk wqig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1ro0Ba+6pk8IfNjZpm7XGUiBmJP7EtwT3otvd3Y4S3I=; b=TU7bNqugo3zLtF3k5H8/StltIrsYIMiXvWYskvWhXrZYhbSOeOztYVNx02jkcJxbAG Pgn9oT+pyH10yG1MXEWlBGlwzzkjA0iRHie4rCeUpLTzv+iqw/jBko5nnVm9XsS1sx2M aEeovLxIgK8dNr38zzHPsszpeaPKuJu/RQi21J11aG526gAHdMnwCt3EzKp+rRccUsNl pB6BxWN/LAOtEHom59iPa+D95Zx5snAhy/vY5omvXx3uTLyOkarl30BAbK+Z9no5Jqhk WuxN7pH+fkAxwbKDN7ya99V9AHTZGK4zqsUhs7pEGivof+WJetUkaUmuW3Ttzw5K32js wNrw== X-Gm-Message-State: APjAAAU6p+frrblW3fPu3HrlXiYCQVjd5JLBHlukOYawvmkEst7ifff4 0qbgH5rfF5g7JBT+fUWITTUiKoUH8A== X-Google-Smtp-Source: APXvYqyQBXvbCa4hwZJKeGPaDQa696fXp+pdMGRn2SDQzeGVYqAenGiNmF2mTyKVW/yslQ16Iyy1bQ== X-Received: by 2002:a0d:e657:: with SMTP id p84mr14169217ywe.444.1583105117840; Sun, 01 Mar 2020 15:25:17 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u4sm7167301ywu.26.2020.03.01.15.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 15:25:17 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 4/8] nfsd: Add tracepoints for update of the expkey and export cache entries Date: Sun, 1 Mar 2020 18:21:41 -0500 Message-Id: <20200301232145.1465430-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200301232145.1465430-4-trond.myklebust@hammerspace.com> References: <20200301232145.1465430-1-trond.myklebust@hammerspace.com> <20200301232145.1465430-2-trond.myklebust@hammerspace.com> <20200301232145.1465430-3-trond.myklebust@hammerspace.com> <20200301232145.1465430-4-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Signed-off-by: Trond Myklebust --- fs/nfsd/export.c | 24 +++++++++++++++--------- fs/nfsd/trace.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c index e867db0bb380..6e6cbeb7ac2b 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c @@ -141,7 +141,9 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen) if (len == 0) { set_bit(CACHE_NEGATIVE, &key.h.flags); ek = svc_expkey_update(cd, &key, ek); - if (!ek) + if (ek) + trace_nfsd_expkey_update(ek, NULL); + else err = -ENOMEM; } else { err = kern_path(buf, 0, &key.ek_path); @@ -151,7 +153,9 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen) dprintk("Found the path %s\n", buf); ek = svc_expkey_update(cd, &key, ek); - if (!ek) + if (ek) + trace_nfsd_expkey_update(ek, buf); + else err = -ENOMEM; path_put(&key.ek_path); } @@ -644,15 +648,17 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen) } expp = svc_export_lookup(&exp); - if (expp) - expp = svc_export_update(&exp, expp); - else - err = -ENOMEM; - cache_flush(); - if (expp == NULL) + if (!expp) { err = -ENOMEM; - else + goto out4; + } + expp = svc_export_update(&exp, expp); + if (expp) { + trace_nfsd_export_update(expp); + cache_flush(); exp_put(expp); + } else + err = -ENOMEM; out4: nfsd4_fslocs_free(&exp.ex_fslocs); kfree(exp.ex_uuid); diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h index 3b9277d7b5f2..78c574251c60 100644 --- a/fs/nfsd/trace.h +++ b/fs/nfsd/trace.h @@ -105,6 +105,32 @@ TRACE_EVENT(nfsd_exp_find_key, ) ); +TRACE_EVENT(nfsd_expkey_update, + TP_PROTO(const struct svc_expkey *key, const char *exp_path), + TP_ARGS(key, exp_path), + TP_STRUCT__entry( + __field(int, fsidtype) + __array(u32, fsid, 6) + __string(auth_domain, key->ek_client->name) + __string(path, exp_path) + __field(bool, cache) + ), + TP_fast_assign( + __entry->fsidtype = key->ek_fsidtype; + memcpy(__entry->fsid, key->ek_fsid, 4*6); + __assign_str(auth_domain, key->ek_client->name); + __assign_str(path, exp_path); + __entry->cache = !test_bit(CACHE_NEGATIVE, &key->h.flags); + ), + TP_printk("fsid=%x::%s domain=%s path=%s cache=%s", + __entry->fsidtype, + __print_array(__entry->fsid, 6, 4), + __get_str(auth_domain), + __get_str(path), + __entry->cache ? "pos" : "neg" + ) +); + TRACE_EVENT(nfsd_exp_get_by_name, TP_PROTO(const struct svc_export *key, int status), @@ -126,6 +152,26 @@ TRACE_EVENT(nfsd_exp_get_by_name, ) ); +TRACE_EVENT(nfsd_export_update, + TP_PROTO(const struct svc_export *key), + TP_ARGS(key), + TP_STRUCT__entry( + __string(path, key->ex_path.dentry->d_name.name) + __string(auth_domain, key->ex_client->name) + __field(bool, cache) + ), + TP_fast_assign( + __assign_str(path, key->ex_path.dentry->d_name.name); + __assign_str(auth_domain, key->ex_client->name); + __entry->cache = !test_bit(CACHE_NEGATIVE, &key->h.flags); + ), + TP_printk("path=%s domain=%s cache=%s", + __get_str(path), + __get_str(auth_domain), + __entry->cache ? "pos" : "neg" + ) +); + DECLARE_EVENT_CLASS(nfsd_io_class, TP_PROTO(struct svc_rqst *rqstp, struct svc_fh *fhp, From patchwork Sun Mar 1 23:21:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11414573 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B0AA184C for ; Sun, 1 Mar 2020 23:25:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 17F4A24699 for ; Sun, 1 Mar 2020 23:25:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N5nGwHCg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726658AbgCAXZU (ORCPT ); Sun, 1 Mar 2020 18:25:20 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:33268 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726050AbgCAXZT (ORCPT ); Sun, 1 Mar 2020 18:25:19 -0500 Received: by mail-yw1-f67.google.com with SMTP id j186so9530099ywe.0 for ; Sun, 01 Mar 2020 15:25:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D5JlzuuzfYDgx4k/u4CJVEMHAcaOTaT7l+Jq/zZhDmI=; b=N5nGwHCg/le3P4RQXh6rkare/7x0JlLHWCNSz9EcMW3NTWN2bgyIuq6/EfG1mQ+GPf SV3p/3eatjtDXoz9jTxcl0EJ0A4bUDVDQAHhSM0HNlEWKo+vQFCPQDhxnOAoWp7QtT84 BmMx9mPOMOEwsDpvYGcbGzbssiRozjKBmJtwZzaGeICJBD74F9VccPPCQotxkk1bSaj1 YCL0SCaIj/HBNZbURFwouC4OowWJ5Wqd98LGmhX70ziM77kOgh8Tr3tpZfD9itWe0QmL MntR29pUui7MlTeB5ieo1ZfZemybrOZ2OMyGDNwnLTZxIlvZRNuEgX18+SrP89LWkUgi 1IRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D5JlzuuzfYDgx4k/u4CJVEMHAcaOTaT7l+Jq/zZhDmI=; b=mO2mrTa4UH0rBGg1+1/7B+SBIF6TXjaUesgEXhLh9XjlhHkATfxkCh8iVtTYGT7KnE 6+r6nsR3zN4LOxO31Pw1YDaYZmAoYteGoffY3wXrgifqUukv8jPLnKfB09zEXC1xZLTI +5xJdDsNXf7mejF9er106k3GeWlcnR6nqoeoDuqzL0GigB3NmBxEfFqy7ekotc6SADa3 1ubrbp1Ufr/zJb+N/X+0IH1tgK71KgqeQlRF9bvG/VwSmdj95MJicC2qPGN8Ga1FoHaZ t9ztqv3kq0mGSBh2QpzMNWLkWLEV8pGuUL7LbzNYjEm5FBX7R5Xj1xWHonpHTmgNAgny lmdQ== X-Gm-Message-State: ANhLgQ1CGDhhBnysRhfV54fpitX0X4XYIecdWsi81xN2yoeKTzwoHgAm 2/oYHMb1i/iYd2QsUpJROg== X-Google-Smtp-Source: ADFU+vv+BO5XOnejQA0TEhLRaNI+5gaX9u0dSkdqclykQHgUHjkL8ckzdMp7cvuwHWz+1rRFKbX0Cg== X-Received: by 2002:a25:bc87:: with SMTP id e7mr3682868ybk.412.1583105118824; Sun, 01 Mar 2020 15:25:18 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u4sm7167301ywu.26.2020.03.01.15.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 15:25:18 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 5/8] nfsd: export upcalls must not return ESTALE when mountd is down Date: Sun, 1 Mar 2020 18:21:42 -0500 Message-Id: <20200301232145.1465430-6-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200301232145.1465430-5-trond.myklebust@hammerspace.com> References: <20200301232145.1465430-1-trond.myklebust@hammerspace.com> <20200301232145.1465430-2-trond.myklebust@hammerspace.com> <20200301232145.1465430-3-trond.myklebust@hammerspace.com> <20200301232145.1465430-4-trond.myklebust@hammerspace.com> <20200301232145.1465430-5-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org If the rpc.mountd daemon goes down, then that should not cause all exports to start failing with ESTALE errors. Let's explicitly distinguish between the cache upcall cases that need to time out, and those that do not. Signed-off-by: Trond Myklebust --- fs/nfs/dns_resolve.c | 11 ++++--- fs/nfsd/export.c | 12 +++++++ fs/nfsd/nfs4idmap.c | 14 ++++++++ include/linux/sunrpc/cache.h | 3 ++ net/sunrpc/auth_gss/svcauth_gss.c | 12 +++++++ net/sunrpc/cache.c | 53 +++++++++++++++---------------- net/sunrpc/svcauth_unix.c | 12 +++++++ 7 files changed, 85 insertions(+), 32 deletions(-) diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c index 89bd5581f317..963800037609 100644 --- a/fs/nfs/dns_resolve.c +++ b/fs/nfs/dns_resolve.c @@ -152,12 +152,13 @@ static int nfs_dns_upcall(struct cache_detail *cd, struct cache_head *ch) { struct nfs_dns_ent *key = container_of(ch, struct nfs_dns_ent, h); - int ret; - ret = nfs_cache_upcall(cd, key->hostname); - if (ret) - ret = sunrpc_cache_pipe_upcall(cd, ch); - return ret; + if (test_and_set_bit(CACHE_PENDING, &ch->flags)) + return 0; + if (!nfs_cache_upcall(cd, key->hostname)) + return 0; + clear_bit(CACHE_PENDING, &ch->flags); + return sunrpc_cache_pipe_upcall_timeout(cd, ch); } static int nfs_dns_match(struct cache_head *ca, diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c index 6e6cbeb7ac2b..cb777fe82988 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c @@ -51,6 +51,11 @@ static void expkey_put(struct kref *ref) kfree_rcu(key, ek_rcu); } +static int expkey_upcall(struct cache_detail *cd, struct cache_head *h) +{ + return sunrpc_cache_pipe_upcall(cd, h); +} + static void expkey_request(struct cache_detail *cd, struct cache_head *h, char **bpp, int *blen) @@ -254,6 +259,7 @@ static const struct cache_detail svc_expkey_cache_template = { .hash_size = EXPKEY_HASHMAX, .name = "nfsd.fh", .cache_put = expkey_put, + .cache_upcall = expkey_upcall, .cache_request = expkey_request, .cache_parse = expkey_parse, .cache_show = expkey_show, @@ -335,6 +341,11 @@ static void svc_export_put(struct kref *ref) kfree_rcu(exp, ex_rcu); } +static int svc_export_upcall(struct cache_detail *cd, struct cache_head *h) +{ + return sunrpc_cache_pipe_upcall(cd, h); +} + static void svc_export_request(struct cache_detail *cd, struct cache_head *h, char **bpp, int *blen) @@ -774,6 +785,7 @@ static const struct cache_detail svc_export_cache_template = { .hash_size = EXPORT_HASHMAX, .name = "nfsd.export", .cache_put = svc_export_put, + .cache_upcall = svc_export_upcall, .cache_request = svc_export_request, .cache_parse = svc_export_parse, .cache_show = svc_export_show, diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c index d1f285245af8..9460be8a8321 100644 --- a/fs/nfsd/nfs4idmap.c +++ b/fs/nfsd/nfs4idmap.c @@ -122,6 +122,12 @@ idtoname_hash(struct ent *ent) return hash; } +static int +idtoname_upcall(struct cache_detail *cd, struct cache_head *h) +{ + return sunrpc_cache_pipe_upcall_timeout(cd, h); +} + static void idtoname_request(struct cache_detail *cd, struct cache_head *ch, char **bpp, int *blen) @@ -184,6 +190,7 @@ static const struct cache_detail idtoname_cache_template = { .hash_size = ENT_HASHMAX, .name = "nfs4.idtoname", .cache_put = ent_put, + .cache_upcall = idtoname_upcall, .cache_request = idtoname_request, .cache_parse = idtoname_parse, .cache_show = idtoname_show, @@ -295,6 +302,12 @@ nametoid_hash(struct ent *ent) return hash_str(ent->name, ENT_HASHBITS); } +static int +nametoid_upcall(struct cache_detail *cd, struct cache_head *h) +{ + return sunrpc_cache_pipe_upcall_timeout(cd, h); +} + static void nametoid_request(struct cache_detail *cd, struct cache_head *ch, char **bpp, int *blen) @@ -347,6 +360,7 @@ static const struct cache_detail nametoid_cache_template = { .hash_size = ENT_HASHMAX, .name = "nfs4.nametoid", .cache_put = ent_put, + .cache_upcall = nametoid_upcall, .cache_request = nametoid_request, .cache_parse = nametoid_parse, .cache_show = nametoid_show, diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h index 0f64de7caa39..656882a50991 100644 --- a/include/linux/sunrpc/cache.h +++ b/include/linux/sunrpc/cache.h @@ -179,6 +179,9 @@ sunrpc_cache_update(struct cache_detail *detail, extern int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h); +extern int +sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail, + struct cache_head *h); extern void cache_clean_deferred(void *owner); diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 65b67b257302..6d698bf1c16e 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -184,6 +184,11 @@ static struct cache_head *rsi_alloc(void) return NULL; } +static int rsi_upcall(struct cache_detail *cd, struct cache_head *h) +{ + return sunrpc_cache_pipe_upcall_timeout(cd, h); +} + static void rsi_request(struct cache_detail *cd, struct cache_head *h, char **bpp, int *blen) @@ -282,6 +287,7 @@ static const struct cache_detail rsi_cache_template = { .hash_size = RSI_HASHMAX, .name = "auth.rpcsec.init", .cache_put = rsi_put, + .cache_upcall = rsi_upcall, .cache_request = rsi_request, .cache_parse = rsi_parse, .match = rsi_match, @@ -428,6 +434,11 @@ rsc_alloc(void) return NULL; } +static int rsc_upcall(struct cache_detail *cd, struct cache_head *h) +{ + return -EINVAL; +} + static int rsc_parse(struct cache_detail *cd, char *mesg, int mlen) { @@ -554,6 +565,7 @@ static const struct cache_detail rsc_cache_template = { .hash_size = RSC_HASHMAX, .name = "auth.rpcsec.context", .cache_put = rsc_put, + .cache_upcall = rsc_upcall, .cache_parse = rsc_parse, .match = rsc_match, .init = rsc_init, diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index bd843a81afa0..5e14513603cb 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -38,7 +38,6 @@ static bool cache_defer_req(struct cache_req *req, struct cache_head *item); static void cache_revisit_request(struct cache_head *item); -static bool cache_listeners_exist(struct cache_detail *detail); static void cache_init(struct cache_head *h, struct cache_detail *detail) { @@ -224,13 +223,6 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail, } EXPORT_SYMBOL_GPL(sunrpc_cache_update); -static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h) -{ - if (cd->cache_upcall) - return cd->cache_upcall(cd, h); - return sunrpc_cache_pipe_upcall(cd, h); -} - static inline int cache_is_valid(struct cache_head *h) { if (!test_bit(CACHE_VALID, &h->flags)) @@ -303,17 +295,14 @@ int cache_check(struct cache_detail *detail, (h->expiry_time != 0 && age > refresh_age/2)) { dprintk("RPC: Want update, refage=%lld, age=%lld\n", refresh_age, age); - if (!test_and_set_bit(CACHE_PENDING, &h->flags)) { - switch (cache_make_upcall(detail, h)) { - case -EINVAL: - rv = try_to_negate_entry(detail, h); - break; - case -EAGAIN: - cache_fresh_unlocked(h, detail); - break; - } - } else if (!cache_listeners_exist(detail)) + switch (detail->cache_upcall(detail, h)) { + case -EINVAL: rv = try_to_negate_entry(detail, h); + break; + case -EAGAIN: + cache_fresh_unlocked(h, detail); + break; + } } if (rv == -EAGAIN) { @@ -1195,20 +1184,12 @@ static bool cache_listeners_exist(struct cache_detail *detail) * * Each request is at most one page long. */ -int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h) +static int cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h) { - char *buf; struct cache_request *crq; int ret = 0; - if (!detail->cache_request) - return -EINVAL; - - if (!cache_listeners_exist(detail)) { - warn_no_listener(detail); - return -EINVAL; - } if (test_bit(CACHE_CLEANED, &h->flags)) /* Too late to make an upcall */ return -EAGAIN; @@ -1242,8 +1223,26 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h) } return ret; } + +int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h) +{ + if (test_and_set_bit(CACHE_PENDING, &h->flags)) + return 0; + return cache_pipe_upcall(detail, h); +} EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall); +int sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail, + struct cache_head *h) +{ + if (!cache_listeners_exist(detail)) { + warn_no_listener(detail); + return -EINVAL; + } + return sunrpc_cache_pipe_upcall(detail, h); +} +EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall_timeout); + /* * parse a message from user-space and pass it * to an appropriate cache diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index 04aa80a2d752..6c8f802c4261 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -148,6 +148,11 @@ static struct cache_head *ip_map_alloc(void) return NULL; } +static int ip_map_upcall(struct cache_detail *cd, struct cache_head *h) +{ + return sunrpc_cache_pipe_upcall(cd, h); +} + static void ip_map_request(struct cache_detail *cd, struct cache_head *h, char **bpp, int *blen) @@ -467,6 +472,11 @@ static struct cache_head *unix_gid_alloc(void) return NULL; } +static int unix_gid_upcall(struct cache_detail *cd, struct cache_head *h) +{ + return sunrpc_cache_pipe_upcall_timeout(cd, h); +} + static void unix_gid_request(struct cache_detail *cd, struct cache_head *h, char **bpp, int *blen) @@ -584,6 +594,7 @@ static const struct cache_detail unix_gid_cache_template = { .hash_size = GID_HASHMAX, .name = "auth.unix.gid", .cache_put = unix_gid_put, + .cache_upcall = unix_gid_upcall, .cache_request = unix_gid_request, .cache_parse = unix_gid_parse, .cache_show = unix_gid_show, @@ -881,6 +892,7 @@ static const struct cache_detail ip_map_cache_template = { .hash_size = IP_HASHMAX, .name = "auth.unix.ip", .cache_put = ip_map_put, + .cache_upcall = ip_map_upcall, .cache_request = ip_map_request, .cache_parse = ip_map_parse, .cache_show = ip_map_show, From patchwork Sun Mar 1 23:21:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11414579 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46E1D1800 for ; Sun, 1 Mar 2020 23:25:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 26D07246A1 for ; Sun, 1 Mar 2020 23:25:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vZfAfthe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726627AbgCAXZW (ORCPT ); Sun, 1 Mar 2020 18:25:22 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:38997 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726673AbgCAXZW (ORCPT ); Sun, 1 Mar 2020 18:25:22 -0500 Received: by mail-yw1-f68.google.com with SMTP id x184so9482034ywd.6 for ; Sun, 01 Mar 2020 15:25:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MWEyLw6EQcAivJXsLlZHcdf1lKHYi989/KDUlTy90nY=; b=vZfAftheEIXvNSdnKIAErv4k0Yl+Wx0I72g/Oknhfk1AUHGxdLY1D65sIdyly40zYC qDo+oFwkKgqpmgmST1Q6wBkqMd15JBKOEbFBCXaBGoyNtnBExl0YizpXrvIMod+YCWhA O6N/eVUhT/pYcZ+GLgOyFTEvZJXfVVn9Fe9a1eoKFY+81IkhY0MsGQoeFeA7a2QOXY8F ab5Fu2faFQx6xAEf5kLtWt/LmQDNAlns/DGQXEWzwyh1HFYVva+yD3/ASMIXVZ550hKl daAC3ghJi3jYEdTLORXeiuBwn9n4+GVDeUU+PesmysAoHQNqLkswGwP93fN6RrKpfZRT xSuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MWEyLw6EQcAivJXsLlZHcdf1lKHYi989/KDUlTy90nY=; b=Y01GMO3ElMZa3WuQ0cP7FmnsjkFtEa0xXsdCnoh6kvv6WUJa6LAvGbZXrwRdpdWIsV ZR1lBjsBNSaBMawofP/SLaAq95cWzAnuVfNv1Dwf2FU0IX7Xvsdqz139vBeAXU9q1Bmq nKCkctHTnSOnvlLql01qg1SmNFw5QO2PPveBnLFljR+PwhnoGS1Tu6b0t7rib8B9F0yl 6mQc/7s2QMTAMK7egl93cOpn04GCcryqozb2YWYND3/dTR20f7sxrwZ+yJ0KqxJWZYIr I7fpTLbVDdwiNgGNXfxkBHbITpOerq+04inqgsjqNNOHy12slL3kF1VQmS5VK/dZnPqU Fbww== X-Gm-Message-State: ANhLgQ26KiH4Oto8+w8iH75aznoQZ87UkzaVB/Im0oupg7prqt0seIZU C6w+1JSERbvpeWsjdBNavkrJRcdPvw== X-Google-Smtp-Source: ADFU+vuvLVuZ2QwBr1SZwXr8GAWg0c27CJRIDro2QQnPH/M7voIgDlp17vR7i0p84iEJXik0mZVC2Q== X-Received: by 2002:a05:6902:693:: with SMTP id i19mr389340ybt.297.1583105119633; Sun, 01 Mar 2020 15:25:19 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u4sm7167301ywu.26.2020.03.01.15.25.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 15:25:19 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 6/8] SUNRPC/cache: Allow garbage collection of invalid cache entries Date: Sun, 1 Mar 2020 18:21:43 -0500 Message-Id: <20200301232145.1465430-7-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200301232145.1465430-6-trond.myklebust@hammerspace.com> References: <20200301232145.1465430-1-trond.myklebust@hammerspace.com> <20200301232145.1465430-2-trond.myklebust@hammerspace.com> <20200301232145.1465430-3-trond.myklebust@hammerspace.com> <20200301232145.1465430-4-trond.myklebust@hammerspace.com> <20200301232145.1465430-5-trond.myklebust@hammerspace.com> <20200301232145.1465430-6-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org If the cache entry never gets initialised, we want the garbage collector to be able to evict it. Otherwise if the upcall daemon fails to initialise the entry, we end up never expiring it. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/cache.h | 3 --- net/sunrpc/cache.c | 36 +++++++++++++++++++----------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h index 656882a50991..532cdbda43da 100644 --- a/include/linux/sunrpc/cache.h +++ b/include/linux/sunrpc/cache.h @@ -209,9 +209,6 @@ static inline void cache_put(struct cache_head *h, struct cache_detail *cd) static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h) { - if (!test_bit(CACHE_VALID, &h->flags)) - return false; - return (h->expiry_time < seconds_since_boot()) || (detail->flush_time >= h->last_refresh); } diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 5e14513603cb..b7ddb2affb7e 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -64,13 +64,14 @@ static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail, rcu_read_lock(); hlist_for_each_entry_rcu(tmp, head, cache_list) { - if (detail->match(tmp, key)) { - if (cache_is_expired(detail, tmp)) - continue; - tmp = cache_get_rcu(tmp); - rcu_read_unlock(); - return tmp; - } + if (!detail->match(tmp, key)) + continue; + if (test_bit(CACHE_VALID, &tmp->flags) && + cache_is_expired(detail, tmp)) + continue; + tmp = cache_get_rcu(tmp); + rcu_read_unlock(); + return tmp; } rcu_read_unlock(); return NULL; @@ -113,17 +114,18 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, /* check if entry appeared while we slept */ hlist_for_each_entry_rcu(tmp, head, cache_list) { - if (detail->match(tmp, key)) { - if (cache_is_expired(detail, tmp)) { - sunrpc_begin_cache_remove_entry(tmp, detail); - freeme = tmp; - break; - } - cache_get(tmp); - spin_unlock(&detail->hash_lock); - cache_put(new, detail); - return tmp; + if (!detail->match(tmp, key)) + continue; + if (test_bit(CACHE_VALID, &tmp->flags) && + cache_is_expired(detail, tmp)) { + sunrpc_begin_cache_remove_entry(tmp, detail); + freeme = tmp; + break; } + cache_get(tmp); + spin_unlock(&detail->hash_lock); + cache_put(new, detail); + return tmp; } hlist_add_head_rcu(&new->cache_list, head); From patchwork Sun Mar 1 23:21:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11414577 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7DE114BC for ; Sun, 1 Mar 2020 23:25:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE9EC246A1 for ; Sun, 1 Mar 2020 23:25:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ev5dcINe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbgCAXZW (ORCPT ); Sun, 1 Mar 2020 18:25:22 -0500 Received: from mail-yw1-f65.google.com ([209.85.161.65]:45243 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbgCAXZV (ORCPT ); Sun, 1 Mar 2020 18:25:21 -0500 Received: by mail-yw1-f65.google.com with SMTP id d206so9424891ywa.12 for ; Sun, 01 Mar 2020 15:25:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DYn9xC5a+w1YWiCL5VqG8RJ0SsGR3kzp0QX7T7SK8Rw=; b=Ev5dcINewLEt38Pu1V2O+x8XhtJH02RZ7qa+qdhBveW+G1JYTC7Wk9d9x9cvqrIwRg F4GfTfq4TDnUBZ6O73X1GHIppTCT7RFcRDKAq2iK7IIwA2DYPgm3FPks1cg0RvWfU0dV XTP1NX5366rYxLvJoReRYL5h+VKN0SfpkaKnzH2UwesWvZWsUfjqotn8UyrF/YQgh3S6 WjWKyYeT5noiEyqPFYtZcBiTsPqc9jGnp+4Q1q3lw7cK2N3Cpn2RIkB6Mq8lYTMKGjCU ANb86mzZ3NXz4CwE5Rac4g8s60xUfy9QuW3e8WRMd/CgLckKXwybEQYVR5exh7XSgEUB NHMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DYn9xC5a+w1YWiCL5VqG8RJ0SsGR3kzp0QX7T7SK8Rw=; b=cifecMcq1sGZsM7+j1Rudq6A0Pla618TiYT8HHr1rw/VxkUrxuu3npqj1/3RZ54S0v U1umlCzJNIAxGv78XSm1JbwdjZU9i3W5PVw6LAUk9sPMzlfmmxFK5yj7odQvdbEX/N1n MKXHiLyE2Mxd0j31fcaua2c4+zvZ/FdInucbYaLzCnbCs6ApjiH6iL9/uKzL0Bhrp3dr eFMfQEwlqGJANmOO4Vrmt5cL/SHOLU8UFU9HnGhpcjY9TtH1xkdt1rZzl4+Yk85XTCRm G0PMFJdT9ZBeaUU/QhxlXoJULDYEAGDspOZseMM9goYet068rdMHooTE0eGt8NgkbY3o P+4A== X-Gm-Message-State: ANhLgQ2IGFl7jSKl/PiKm4SNjv49kSZis3JQWi+rb2x31dLApZ5CJUAI dmSJhsKPNdQhFoQj7RPOYiuhaWSSTg== X-Google-Smtp-Source: ADFU+vtKhjV8uisotK9qpm4il76KPLKpYk52NLx481hFnOFOjHnMGh7njUvh72ZBz/KEe8e0Fg7lmw== X-Received: by 2002:a81:5251:: with SMTP id g78mr3131755ywb.5.1583105120552; Sun, 01 Mar 2020 15:25:20 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u4sm7167301ywu.26.2020.03.01.15.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 15:25:20 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 7/8] sunrpc: Add tracing for cache events Date: Sun, 1 Mar 2020 18:21:44 -0500 Message-Id: <20200301232145.1465430-8-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200301232145.1465430-7-trond.myklebust@hammerspace.com> References: <20200301232145.1465430-1-trond.myklebust@hammerspace.com> <20200301232145.1465430-2-trond.myklebust@hammerspace.com> <20200301232145.1465430-3-trond.myklebust@hammerspace.com> <20200301232145.1465430-4-trond.myklebust@hammerspace.com> <20200301232145.1465430-5-trond.myklebust@hammerspace.com> <20200301232145.1465430-6-trond.myklebust@hammerspace.com> <20200301232145.1465430-7-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add basic tracing for debugging the sunrpc cache events. Signed-off-by: Trond Myklebust --- include/trace/events/sunrpc.h | 33 +++++++++++++++++++++++++++++++++ net/sunrpc/cache.c | 35 ++++++++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/include/trace/events/sunrpc.h b/include/trace/events/sunrpc.h index ee993575d2fa..236d42539c7b 100644 --- a/include/trace/events/sunrpc.h +++ b/include/trace/events/sunrpc.h @@ -1292,6 +1292,39 @@ DECLARE_EVENT_CLASS(svc_deferred_event, DEFINE_SVC_DEFERRED_EVENT(drop); DEFINE_SVC_DEFERRED_EVENT(revisit); +DECLARE_EVENT_CLASS(cache_event, + TP_PROTO( + const struct cache_detail *cd, + const struct cache_head *h + ), + + TP_ARGS(cd, h), + + TP_STRUCT__entry( + __field(const struct cache_head *, h) + __string(name, cd->name) + ), + + TP_fast_assign( + __entry->h = h; + __assign_str(name, cd->name); + ), + + TP_printk("cache=%s entry=%p", __get_str(name), __entry->h) +); +#define DEFINE_CACHE_EVENT(name) \ + DEFINE_EVENT(cache_event, name, \ + TP_PROTO( \ + const struct cache_detail *cd, \ + const struct cache_head *h \ + ), \ + TP_ARGS(cd, h)) +DEFINE_CACHE_EVENT(cache_entry_expired); +DEFINE_CACHE_EVENT(cache_entry_upcall); +DEFINE_CACHE_EVENT(cache_entry_update); +DEFINE_CACHE_EVENT(cache_entry_make_negative); +DEFINE_CACHE_EVENT(cache_entry_no_listener); + #endif /* _TRACE_SUNRPC_H */ #include diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index b7ddb2affb7e..559a61644037 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "netns.h" #define RPCDBG_FACILITY RPCDBG_CACHE @@ -119,6 +120,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, if (test_bit(CACHE_VALID, &tmp->flags) && cache_is_expired(detail, tmp)) { sunrpc_begin_cache_remove_entry(tmp, detail); + trace_cache_entry_expired(detail, tmp); freeme = tmp; break; } @@ -175,6 +177,24 @@ static void cache_fresh_unlocked(struct cache_head *head, } } +static void cache_make_negative(struct cache_detail *detail, + struct cache_head *h) +{ + set_bit(CACHE_NEGATIVE, &h->flags); + trace_cache_entry_make_negative(detail, h); +} + +static void cache_entry_update(struct cache_detail *detail, + struct cache_head *h, + struct cache_head *new) +{ + if (!test_bit(CACHE_NEGATIVE, &new->flags)) { + detail->update(h, new); + trace_cache_entry_update(detail, h); + } else + cache_make_negative(detail, h); +} + struct cache_head *sunrpc_cache_update(struct cache_detail *detail, struct cache_head *new, struct cache_head *old, int hash) { @@ -187,10 +207,7 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail, if (!test_bit(CACHE_VALID, &old->flags)) { spin_lock(&detail->hash_lock); if (!test_bit(CACHE_VALID, &old->flags)) { - if (test_bit(CACHE_NEGATIVE, &new->flags)) - set_bit(CACHE_NEGATIVE, &old->flags); - else - detail->update(old, new); + cache_entry_update(detail, old, new); cache_fresh_locked(old, new->expiry_time, detail); spin_unlock(&detail->hash_lock); cache_fresh_unlocked(old, detail); @@ -208,10 +225,7 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail, detail->init(tmp, old); spin_lock(&detail->hash_lock); - if (test_bit(CACHE_NEGATIVE, &new->flags)) - set_bit(CACHE_NEGATIVE, &tmp->flags); - else - detail->update(tmp, new); + cache_entry_update(detail, tmp, new); hlist_add_head(&tmp->cache_list, &detail->hash_table[hash]); detail->entries++; cache_get(tmp); @@ -253,7 +267,7 @@ static int try_to_negate_entry(struct cache_detail *detail, struct cache_head *h spin_lock(&detail->hash_lock); rv = cache_is_valid(h); if (rv == -EAGAIN) { - set_bit(CACHE_NEGATIVE, &h->flags); + cache_make_negative(detail, h); cache_fresh_locked(h, seconds_since_boot()+CACHE_NEW_EXPIRY, detail); rv = -ENOENT; @@ -459,6 +473,7 @@ static int cache_clean(void) continue; sunrpc_begin_cache_remove_entry(ch, current_detail); + trace_cache_entry_expired(current_detail, ch); rv = 1; break; } @@ -1214,6 +1229,7 @@ static int cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h) if (test_bit(CACHE_PENDING, &h->flags)) { crq->item = cache_get(h); list_add_tail(&crq->q.list, &detail->queue); + trace_cache_entry_upcall(detail, h); } else /* Lost a race, no longer PENDING, so don't enqueue */ ret = -EAGAIN; @@ -1239,6 +1255,7 @@ int sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail, { if (!cache_listeners_exist(detail)) { warn_no_listener(detail); + trace_cache_entry_no_listener(detail, h); return -EINVAL; } return sunrpc_cache_pipe_upcall(detail, h); From patchwork Sun Mar 1 23:21:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11414581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0ED4392A for ; Sun, 1 Mar 2020 23:25:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E3193246A1 for ; Sun, 1 Mar 2020 23:25:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RuZZD6G0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726673AbgCAXZX (ORCPT ); Sun, 1 Mar 2020 18:25:23 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:33271 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726682AbgCAXZW (ORCPT ); Sun, 1 Mar 2020 18:25:22 -0500 Received: by mail-yw1-f67.google.com with SMTP id j186so9530226ywe.0 for ; Sun, 01 Mar 2020 15:25:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U14Uy4stoVVLCX7z3eAHr/J7no/Y5EZ7ZoEpafZVGbk=; b=RuZZD6G0ydqhvfQDgzlWyAL3zjtZ60VfWDcCOPMuuHw7jw14D2d2wA4zcUsUjNg2DR MMecdQW74NTkV0GaX7/FfNaw3tqFvFix1rNClaUlovL57pbtxH9BYLHiC35c3gTpArNU Fy6JCyvVe/GYrfWX0yNiuW6gHA+gSW+2e+En3gqQ7iyxPM6Bmzt6azjv0nHFD5lh5iy0 nVX09fNLtKkMkvxg0fjELXh0y6bs3lDbf6lysTinIr0o9rTwsDlwAAQVd4JPPmX5EvMc WDYu251PGoxhYN//CI+LRa9fRfSzCKu8MhpErcbfisNfbqbeRQ2UIB4JnpctAvH8kiWP 2otQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U14Uy4stoVVLCX7z3eAHr/J7no/Y5EZ7ZoEpafZVGbk=; b=c/MFvCb6znjTpNX5TBm/aZhyhoP/rfSwCRorq9RUTUS9i830OlUxmOs+D8dxuE5UWB q9bqjyTeF+/fujOWFY6Yj+WRVVoFzrtyD9HKX9GKGJ3AQIDNwt6+R7fp0N/9XQbMz4fE AKSAH/JKn+uNbytP3rfesO02V7qtAyrhM5gPSCGItImXiNkp2Fms8OwQqE5rUpVeOal9 dIm93Sbdctsgg5oV+TTmQ/HULi8VcAFdQNfaAKVrhRCQQVngfkt8n/C+AeyhZhmgsFnE m6W59+/0b7Jr3EJP6hV/P0hIgtRliq2S9+n0vY8vM8GliGEa7ChpFJMkbm/kWjJWS1EV /p3Q== X-Gm-Message-State: APjAAAWF9cekg3oMwTuJxr894/ewlgsmFbS6/lgkmaWX0sJgiN7uiQGn z7T5QjzUmaMkDj3y3AY90w== X-Google-Smtp-Source: APXvYqzGYnnf6TQShe/Q82d/fM3T8RYzOVDQb6SgJP6valb5CRt+NUN6GPw20aj45Vf5m+WCVCIKpA== X-Received: by 2002:a25:8804:: with SMTP id c4mr14255517ybl.387.1583105121539; Sun, 01 Mar 2020 15:25:21 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u4sm7167301ywu.26.2020.03.01.15.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 15:25:21 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 8/8] sunrpc: Drop the connection when the server drops a request Date: Sun, 1 Mar 2020 18:21:45 -0500 Message-Id: <20200301232145.1465430-9-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200301232145.1465430-8-trond.myklebust@hammerspace.com> References: <20200301232145.1465430-1-trond.myklebust@hammerspace.com> <20200301232145.1465430-2-trond.myklebust@hammerspace.com> <20200301232145.1465430-3-trond.myklebust@hammerspace.com> <20200301232145.1465430-4-trond.myklebust@hammerspace.com> <20200301232145.1465430-5-trond.myklebust@hammerspace.com> <20200301232145.1465430-6-trond.myklebust@hammerspace.com> <20200301232145.1465430-7-trond.myklebust@hammerspace.com> <20200301232145.1465430-8-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org If a server wants to drop a request, then it should also drop the connection, in order to let the client know. Signed-off-by: Trond Myklebust --- net/sunrpc/svc_xprt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c index de3c077733a7..83a527e56c87 100644 --- a/net/sunrpc/svc_xprt.c +++ b/net/sunrpc/svc_xprt.c @@ -873,6 +873,13 @@ int svc_recv(struct svc_rqst *rqstp, long timeout) } EXPORT_SYMBOL_GPL(svc_recv); +static void svc_drop_connection(struct svc_xprt *xprt) +{ + if (test_bit(XPT_TEMP, &xprt->xpt_flags) && + !test_and_set_bit(XPT_CLOSE, &xprt->xpt_flags)) + svc_xprt_enqueue(xprt); +} + /* * Drop request */ @@ -880,6 +887,8 @@ void svc_drop(struct svc_rqst *rqstp) { trace_svc_drop(rqstp); dprintk("svc: xprt %p dropped request\n", rqstp->rq_xprt); + /* Close the connection when dropping a request */ + svc_drop_connection(rqstp->rq_xprt); svc_xprt_release(rqstp); } EXPORT_SYMBOL_GPL(svc_drop); @@ -1148,6 +1157,7 @@ static void svc_revisit(struct cache_deferred_req *dreq, int too_many) if (too_many || test_bit(XPT_DEAD, &xprt->xpt_flags)) { spin_unlock(&xprt->xpt_lock); dprintk("revisit canceled\n"); + svc_drop_connection(xprt); svc_xprt_put(xprt); trace_svc_drop_deferred(dr); kfree(dr);