From patchwork Sat Aug 3 14:58:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11074493 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3F1D912 for ; Sat, 3 Aug 2019 15:00:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C08B5285D8 for ; Sat, 3 Aug 2019 15:00:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B16CC285FF; Sat, 3 Aug 2019 15:00:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E1FB284DC for ; Sat, 3 Aug 2019 15:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727816AbfHCPAf (ORCPT ); Sat, 3 Aug 2019 11:00:35 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:36124 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727535AbfHCPAf (ORCPT ); Sat, 3 Aug 2019 11:00:35 -0400 Received: by mail-io1-f68.google.com with SMTP id o9so55101014iom.3 for ; Sat, 03 Aug 2019 08:00:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=GyNHAH00KqBO+HMY5Y0wF6D7MG+dmxd2DUPH09N1l8o=; b=AE1Uo6wlj1DyTkwHu5FygbLM6VHI1lPuo8Fwad2nz3p2ez5oGfxt8zPal2zaIG4Pa0 RAG9xXbGH/NG+SZ5JWIoaxCrOFaT7ampfUOu6y0kAdtpcmRwtAb6dWhtBlfnZnaZaWy1 h6Iq/8SuhU2JJ6FzS2BMIXPQ2qRmFG7sAMJDNv+xoBIuSzh1NaViJXeveJXxfmh3OLb/ /mTKiuaRdAeaLjSOpMSK+G8OZYzAPWNMgYRlGzZ3PCbZdhI6Vf4qmbKuiELdlYBCm25J 59sgjf0sblD1mTme+XEic0qaDAIAeou3lJab8t4CawOMdium5wU8fLCqPvrXkRTH+316 tIqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=GyNHAH00KqBO+HMY5Y0wF6D7MG+dmxd2DUPH09N1l8o=; b=dfMNvxpfRTImYCnN7/mt1bSfkEBKLINwqW3tJ6jr8Y958t4sxaCDxfX5i8dMEdj5Dp GRmT+JJSl4A7fujnq5djymp5YVso/2a8ebREbCkV3pollpzbE9UCmmUt/NviDMowPtTh 2lPi3dEPo5SLdX9NXqwgT1OToDgtZKxk7DetoHxccoqdsIYSbijcdM4NTlVIFKkpIcnC h3I4Q0B36ETQGGbB9vDfqy+vlWEsTylMsFVO4UQDxrHKI4gFy+gjuBI0GXh46Z5DiB5w EJCAxpUjDUIAJp4JpPx27VKMtEeAuozywikbJn5oJyLv+cmeGr8wCZYVHXUL5acEF+4S Z9cw== X-Gm-Message-State: APjAAAUEJpPxoD7zPcp63pAAkRIyCN9ca6aXw2GMjOJuwvz47TCxsogJ Jit9k2ZJiNRxMY8tcuEerXsAVcQ= X-Google-Smtp-Source: APXvYqw7bzgM+uTFO37ZWxIVx/Nsnsll4DLqv0vd2l9K2nSYpoRJi+0B0EPhwY4b2TZRN0wN+77r+w== X-Received: by 2002:a6b:dc17:: with SMTP id s23mr20361891ioc.56.1564844433914; Sat, 03 Aug 2019 08:00:33 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f20sm60820416ioh.17.2019.08.03.08.00.33 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 03 Aug 2019 08:00:33 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 1/8] NFSv4: Fix a credential refcount leak in nfs41_check_delegation_stateid Date: Sat, 3 Aug 2019 10:58:19 -0400 Message-Id: <20190803145826.15504-1-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is unsafe to dereference delegation outside the rcu lock, and in any case, the refcount is guaranteed held if cred is non-zero. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 39896afc6edf..a6d73609b163 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -2778,8 +2778,7 @@ static void nfs41_check_delegation_stateid(struct nfs4_state *state) if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) nfs_finish_clear_delegation_stateid(state, &stateid); - if (delegation->cred) - put_cred(cred); + put_cred(cred); } /** From patchwork Sat Aug 3 14:58:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11074507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1467912 for ; Sat, 3 Aug 2019 15:00:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 923F0284DC for ; Sat, 3 Aug 2019 15:00:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86627285CB; Sat, 3 Aug 2019 15:00:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E128285B9 for ; Sat, 3 Aug 2019 15:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727830AbfHCPAg (ORCPT ); Sat, 3 Aug 2019 11:00:36 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:36125 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727535AbfHCPAf (ORCPT ); Sat, 3 Aug 2019 11:00:35 -0400 Received: by mail-io1-f66.google.com with SMTP id o9so55101081iom.3 for ; Sat, 03 Aug 2019 08:00:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4/7a3f+prLAMWa+GJyh21FglLHfc4906imLer/C8sQI=; b=L6AtQBOaWTeSGGaZDpD6Sil6ypc0+BeSa1p+k3xxlwppIVa+L4E0cOobz8zCNvvvce 8ITheNqLwboJjDGbO3KrZ5Qf/E9PIMmo/hIzLeNFBHjtOed1GI3gYOAOQpIeVkayZ3iC MTCqAqGKA3MLvS+sO7iMPYDTkgsKqmSqPedA4RjKvlxLakHlorqhPd/FcpBpA8DrRQyk Ep9phSa42rwAaSVcavHIpwcrQXDEeL6ZIROJQZPoZy7KaVUHXtJkV+lXqSoJzJ8rYoOD /4JdbEOfVvRWv68sX/Zb+ee70o7Bhawrdv6NSMmkBdH/EveMz43/D9f1EcHeDepYMNZl KGSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4/7a3f+prLAMWa+GJyh21FglLHfc4906imLer/C8sQI=; b=Jk9qEc1TKcSKLaVocKfT/0eIvdB+ZgIcVdNme9WZ0qw5nYTZddt8IbBsyNVp2w6EB3 Ussd65EIG0URCIfVJQUHnNNsY+sHqbst64SmJ1QODFQ6mwN/RCFh3RXh9/M4hkiCGTwC /lcMSdS0e0HdnqmxvBFy0/Ev5NFQpWcQE7soEmllS6sWKuNOBxdisMxAVD6GrGAtZl62 rCI7/uOfVt4ZacDn2+H+3Rd0if7H1hTXpMfiSxuruf2UXbvY3B4rDmNnswB57E3sE65g kaWPKwSpnZBmFa132HymvqAcH0kV+jVSi5bucqol/GhZevkvDnJtxYht5Dnk0MEIT0Ef NzhQ== X-Gm-Message-State: APjAAAUF+YrefQZkPlJQ3B1eXOX0Upe3zbt4WVKD+OP5l2vMp5nkkqCu dvasOIwoHpfJncZUyfHRQjaySyo= X-Google-Smtp-Source: APXvYqwmFjsZM/lcGNOSLBCk9xh7wqrENCfKgS2oV1PmCpTLX3AjT1TH924Jz0I0FooUQ4mo/bz5ZA== X-Received: by 2002:a02:5a02:: with SMTP id v2mr15231216jaa.124.1564844434553; Sat, 03 Aug 2019 08:00:34 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f20sm60820416ioh.17.2019.08.03.08.00.33 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 03 Aug 2019 08:00:34 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 2/8] NFSv4: Fix delegation state recovery Date: Sat, 3 Aug 2019 10:58:20 -0400 Message-Id: <20190803145826.15504-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190803145826.15504-1-trond.myklebust@hammerspace.com> References: <20190803145826.15504-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 X-Virus-Scanned: ClamAV using ClamSMTP Once we clear the NFS_DELEGATED_STATE flag, we're telling nfs_delegation_claim_opens() that we're done recovering all open state for that stateid, so we really need to ensure that we test for all open modes that are currently cached and recover them before exiting nfs4_open_delegation_recall(). Fixes: 24311f884189d ("NFSv4: Recovery of recalled read delegations...") Signed-off-by: Trond Myklebust Cc: stable@vger.kernel.org # v4.3+ --- fs/nfs/delegation.c | 2 +- fs/nfs/delegation.h | 2 +- fs/nfs/nfs4proc.c | 25 ++++++++++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index 0ff3facf81da..0af854cce8ff 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -153,7 +153,7 @@ static int nfs_delegation_claim_opens(struct inode *inode, /* Block nfs4_proc_unlck */ mutex_lock(&sp->so_delegreturn_mutex); seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); - err = nfs4_open_delegation_recall(ctx, state, stateid, type); + err = nfs4_open_delegation_recall(ctx, state, stateid); if (!err) err = nfs_delegation_claim_locks(state, stateid); if (!err && read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h index 5799777df5ec..9eb87ae4c982 100644 --- a/fs/nfs/delegation.h +++ b/fs/nfs/delegation.h @@ -63,7 +63,7 @@ void nfs_reap_expired_delegations(struct nfs_client *clp); /* NFSv4 delegation-related procedures */ int nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync); -int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid, fmode_t type); +int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid); int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid); bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_stateid *dst, const struct cred **cred); bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode); diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index a6d73609b163..21e3c159bc69 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -2177,12 +2177,10 @@ static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct case -NFS4ERR_BAD_HIGH_SLOT: case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: case -NFS4ERR_DEADSESSION: - set_bit(NFS_DELEGATED_STATE, &state->flags); nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); return -EAGAIN; case -NFS4ERR_STALE_CLIENTID: case -NFS4ERR_STALE_STATEID: - set_bit(NFS_DELEGATED_STATE, &state->flags); /* Don't recall a delegation if it was lost */ nfs4_schedule_lease_recovery(server->nfs_client); return -EAGAIN; @@ -2203,7 +2201,6 @@ static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct return -EAGAIN; case -NFS4ERR_DELAY: case -NFS4ERR_GRACE: - set_bit(NFS_DELEGATED_STATE, &state->flags); ssleep(1); return -EAGAIN; case -ENOMEM: @@ -2219,8 +2216,7 @@ static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct } int nfs4_open_delegation_recall(struct nfs_open_context *ctx, - struct nfs4_state *state, const nfs4_stateid *stateid, - fmode_t type) + struct nfs4_state *state, const nfs4_stateid *stateid) { struct nfs_server *server = NFS_SERVER(state->inode); struct nfs4_opendata *opendata; @@ -2231,20 +2227,23 @@ int nfs4_open_delegation_recall(struct nfs_open_context *ctx, if (IS_ERR(opendata)) return PTR_ERR(opendata); nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); - nfs_state_clear_delegation(state); - switch (type & (FMODE_READ|FMODE_WRITE)) { - case FMODE_READ|FMODE_WRITE: - case FMODE_WRITE: + if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { err = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); if (err) - break; + goto out; + } + if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { err = nfs4_open_recover_helper(opendata, FMODE_WRITE); if (err) - break; - /* Fall through */ - case FMODE_READ: + goto out; + } + if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { err = nfs4_open_recover_helper(opendata, FMODE_READ); + if (err) + goto out; } + nfs_state_clear_delegation(state); +out: nfs4_opendata_put(opendata); return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); } From patchwork Sat Aug 3 14:58:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11074495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1876113B1 for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09B32285D8 for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1E60286C0; Sat, 3 Aug 2019 15:00:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DFBC285CB for ; Sat, 3 Aug 2019 15:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727843AbfHCPAg (ORCPT ); Sat, 3 Aug 2019 11:00:36 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:39566 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727535AbfHCPAg (ORCPT ); Sat, 3 Aug 2019 11:00:36 -0400 Received: by mail-io1-f65.google.com with SMTP id f4so158748637ioh.6 for ; Sat, 03 Aug 2019 08:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=H6RjXIqkymcgD1H8o7IZsZ4Q3k0CSgAlxo5Yg+M1ya8=; b=BFjPu07NDDNfUPvTaDKlXoUA/OcAJ58CbhLHpRriF281I8NjPYpBvUCqEp2S1VM8UN NGm3wvgnG7+PTNxU6pUIH4rIBVsjx5Btsz+hZZ8jV+R7Zbd2bxTXz6wZJZ/g+GTFjrKk 0h2P9M7RPK8qvh/4omWCm+UdmDL8WTgDhPfhy07GY6D17qwinVArxexyUbz6jMnIoRPw AV/7tzuMptV1P9DxqUaLmYtU0Il5Vkki6Wpjlq4BogcNgmYyV0uFaXLhNYwk8QyHCpt2 lHub4PKH91Z3tkI0x73UIvvARB8ni9IU4wzVasAB7kBHvksiiYkf4sKA1FhSKTd2L5Sk yAWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=H6RjXIqkymcgD1H8o7IZsZ4Q3k0CSgAlxo5Yg+M1ya8=; b=WxNBxCVe6vftyW8yMTOWxohdtZqLxMIthPWSdax7tN1Otm3UWIdyzdt1rEEXtebucM 8acUUBKLUHykfbECqPXWwbCT8LwXEWcLGKu2bnnPBwnS4nY1F/hnTdQxi/e3QMLcAmHM ZOkifHkvObTrfZ3/hOloQHXNbP1T0FZrukQzoGxtdJB+d/tblbpMtNPvYdSMWvoq/TJb 8U4NuYq0KukEcpNheTQ6JOm99aKRqBbJrS6G2Aej8mOQNUD/aMAGxAeh9R0sT7nBxj+2 +MxvT9pAbnEIQfcII8MsFLQkf2FJtQrHVAUDvojUkoB9ZW210ZL9b0CTJwHs/VxEpU6s 8Z0w== X-Gm-Message-State: APjAAAUf9Zg/B84pGXzYZfuX7v8c59KL9tgW1/cVp2J/2EnpNFx76lZ7 2fssjQxIFngkrS41uNwzavtPGm4= X-Google-Smtp-Source: APXvYqwY3s8Ga9umuIzZgdClpZIdFguKQEA7Vl2zbtbwx6dN6ALAD1pLAzOSwrqNgkLDm43jWknfkQ== X-Received: by 2002:a02:a417:: with SMTP id c23mr25152268jal.141.1564844435372; Sat, 03 Aug 2019 08:00:35 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f20sm60820416ioh.17.2019.08.03.08.00.34 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 03 Aug 2019 08:00:34 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 3/8] NFSv4: Print an error in the syslog when state is marked as irrecoverable Date: Sat, 3 Aug 2019 10:58:21 -0400 Message-Id: <20190803145826.15504-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190803145826.15504-2-trond.myklebust@hammerspace.com> References: <20190803145826.15504-1-trond.myklebust@hammerspace.com> <20190803145826.15504-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 X-Virus-Scanned: ClamAV using ClamSMTP When error recovery fails due to a fatal error on the server, ensure we log it in the syslog. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4state.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index 9afd051a4876..a71a61e5fe2c 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -1463,7 +1463,7 @@ void nfs_inode_find_state_and_recover(struct inode *inode, nfs4_schedule_state_manager(clp); } -static void nfs4_state_mark_open_context_bad(struct nfs4_state *state) +static void nfs4_state_mark_open_context_bad(struct nfs4_state *state, int err) { struct inode *inode = state->inode; struct nfs_inode *nfsi = NFS_I(inode); @@ -1474,6 +1474,8 @@ static void nfs4_state_mark_open_context_bad(struct nfs4_state *state) if (ctx->state != state) continue; set_bit(NFS_CONTEXT_BAD, &ctx->flags); + pr_warn("NFSv4: state recovery failed for open file %pd2, " + "error = %d\n", ctx->dentry, err); } rcu_read_unlock(); } @@ -1481,7 +1483,7 @@ static void nfs4_state_mark_open_context_bad(struct nfs4_state *state) static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error) { set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags); - nfs4_state_mark_open_context_bad(state); + nfs4_state_mark_open_context_bad(state, error); } From patchwork Sat Aug 3 14:58:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11074497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D8E0186E for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DA0F286E2 for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4202E286DB; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD4EE284DC for ; Sat, 3 Aug 2019 15:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727845AbfHCPAh (ORCPT ); Sat, 3 Aug 2019 11:00:37 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:37510 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727535AbfHCPAh (ORCPT ); Sat, 3 Aug 2019 11:00:37 -0400 Received: by mail-io1-f66.google.com with SMTP id q22so38891096iog.4 for ; Sat, 03 Aug 2019 08:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0pFB+4SQh7Dkgli7Gh6pL88AFg9wW+6p1cHkhZw918E=; b=ravujXrtMqYxtV2qgbAOzi3Pe4ofolJ/ojfovdZ6CSF0ooSAZhrFwwnUckGNi7FbVp h/ffzZEb/yffXJZ46/MDjakIGSp3/HFrE5QQid3EuQKvYRlDnZCC58xKxR+fjIqvlAa0 AvYZmAI/qyFZ6wtBkpvjC29fgnH2X//WXdMcIxtA6BUUDQuigirSWUV9pXUcNGm6pCCd ztPM9TEdyzqG5Kxd5EELABYCYywtTbojqFFMlO/Am6U4RJP+jbfCy7h+BiYpOoJc9gqn EmkcvXN470jgdcp4HrDYGu8IsjelMxn5um9TVa0Fud4w0sQ5RX6dCLYdnoMKjnQW8rhT 4GPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0pFB+4SQh7Dkgli7Gh6pL88AFg9wW+6p1cHkhZw918E=; b=IdGbf6I6ehiB5uAEkK3OiwJ7NzNmoyDDs4aie3FlS09+fu5pgo8rX7qrKfp9RbEO/T Rk8AfWkZCbnnwwr5Eep1CK6/hJY2PN1/ijZ9klrxwuqMJZFoOA/LjlvRcmOYzUrT4I8z smzDpjvWdRZw6+5hc4Fgv8iETpb8v+9Xs/7Un6S3eFhjrh7SFDlrP6UgxWCGkRKXMbvU gd+zBOMTPEWkBRFN24N0cqC9aaIWQiixa6UH8clvihG4WGCADK5/Vw+YYiF8HIi2sLjx vZb8aQpaUfa8zsqmwPe/boziaBkwnITEHfDQ1nJf8cXmBqAy6xV1fdp0QjKxzvARHSiC UhUw== X-Gm-Message-State: APjAAAVHVEON98T0o8zxGiJlFQ8QVgPk7vdf2STJCcbggTvnl9oHsdV1 GYAivWF3UJCfEu2CqYSJBuG71Ro= X-Google-Smtp-Source: APXvYqxBHDWJNmyejRqNN32DYUujsIf55l9fywOgI/vPqhDPok0u6ngvOfHETqcihxLEkrl1PPfAOw== X-Received: by 2002:a5d:94d0:: with SMTP id y16mr90267804ior.123.1564844436022; Sat, 03 Aug 2019 08:00:36 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f20sm60820416ioh.17.2019.08.03.08.00.35 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 03 Aug 2019 08:00:35 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 4/8] NFSv4: When recovering state fails with EAGAIN, retry the same recovery Date: Sat, 3 Aug 2019 10:58:22 -0400 Message-Id: <20190803145826.15504-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190803145826.15504-3-trond.myklebust@hammerspace.com> References: <20190803145826.15504-1-trond.myklebust@hammerspace.com> <20190803145826.15504-2-trond.myklebust@hammerspace.com> <20190803145826.15504-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 X-Virus-Scanned: ClamAV using ClamSMTP If the server returns with EAGAIN when we're trying to recover from a server reboot, we currently delay for 1 second, but then mark the stateid as needing recovery after the grace period has expired. Instead, we should just retry the same recovery process immediately after the 1 second delay. Break out of the loop after 10 retries. Fixes: 35a61606a612 ("NFS: Reduce indentation of the switch statement...") Signed-off-by: Trond Myklebust --- fs/nfs/nfs4state.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index a71a61e5fe2c..d03b9cf42bd0 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -1607,6 +1607,7 @@ static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_st static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs4_state_recovery_ops *ops) { struct nfs4_state *state; + unsigned int loop = 0; int status = 0; /* Note: we rely on the sp->so_states list being ordered @@ -1633,8 +1634,10 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs switch (status) { default: - if (status >= 0) + if (status >= 0) { + loop = 0; break; + } printk(KERN_ERR "NFS: %s: unhandled error %d\n", __func__, status); /* Fall through */ case -ENOENT: @@ -1648,6 +1651,10 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs break; case -EAGAIN: ssleep(1); + if (loop++ < 10) { + set_bit(ops->state_flag_bit, &state->flags); + break; + } /* Fall through */ case -NFS4ERR_ADMIN_REVOKED: case -NFS4ERR_STALE_STATEID: From patchwork Sat Aug 3 14:58:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11074499 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 773FA174A for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 670CD286C0 for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C860285FF; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCDC6285FF for ; Sat, 3 Aug 2019 15:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727535AbfHCPAi (ORCPT ); Sat, 3 Aug 2019 11:00:38 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:38557 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727844AbfHCPAh (ORCPT ); Sat, 3 Aug 2019 11:00:37 -0400 Received: by mail-io1-f68.google.com with SMTP id j6so38880286ioa.5 for ; Sat, 03 Aug 2019 08:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=jP6jSiXxqPOpj4SyG5pF7m+G03jZg20kHJfasyqxaP4=; b=qO55BGTREs1CeT8fmLSmgSP+VM2wKy/vGbHLWYksPzd3Eo6emLOpKJClqrKbCDqtWS 1Yd1tk8WnlHVOYqEjtPrVNKi/FRw2Z5UrBm/RU/lunjTrEe4D8vrxCTU8ClxL8F59KJi TcbLfzlomgIjOkTekQR50Ffm9dIcq4ha1ukpa99rvWRv7nizEQUNXfJCRjqmH1H5SHQ5 yVBpH7240UV943OP6v0VIpkuWaPsBl9h6NTUL46kFLMA8fU5Mp6Fiw4Hv+hK5GvMAGVr zf00ybdfZGnNTDxNMute1U+U0vd6Op/l+QpAtJZpB8a+DWE9tn1sZgrfGCLPidGHp8up 7P6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jP6jSiXxqPOpj4SyG5pF7m+G03jZg20kHJfasyqxaP4=; b=Y2I8Us4qgVzi3za+cvN/op24YpqvRLvfXuzbWlMu4/NA/FBokVgwoNW9KMACw1oH82 oph/h/O1wTBtA2HAeT5CqjRvKDmYml7Q88IyqkyXw1tlOvHiMResGbjvRuEFUsUOZjTi Fp/i9YHf/cQOIXQrlYkHRfT2cx23FMCGFybqL790+XJrdZNZMOLKtBnV4PlanLKoageS GPn1cjNYfnVEmjGRJlEYL68pOwv10dEDSYt+uoIFO99p2dLB04FE0aBNahHH3fl4zT1w 7S2vSTYP1N4cpVZemPqGxvnZd2p6w2eoim12JfFTpVBZrBFv7Z1blG6zUuRyUmHAya+S NAPQ== X-Gm-Message-State: APjAAAX7q4J5gvhBicgTXbn87wDBvT3RQJRCudV4eHdukOGVG53YkOng 9fTLjX/+03/TgMs7OwIqLjDPaEk= X-Google-Smtp-Source: APXvYqyu+mt64j/bcHcPqSA+gAelDKepj7k9wzActFbUTj/fO2QZrzwVV/nxNzzNISSnb3ksRHDRkQ== X-Received: by 2002:a02:22c6:: with SMTP id o189mr52897573jao.35.1564844436681; Sat, 03 Aug 2019 08:00:36 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f20sm60820416ioh.17.2019.08.03.08.00.36 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 03 Aug 2019 08:00:36 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 5/8] NFSv4: Report the error from nfs4_select_rw_stateid() Date: Sat, 3 Aug 2019 10:58:23 -0400 Message-Id: <20190803145826.15504-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190803145826.15504-4-trond.myklebust@hammerspace.com> References: <20190803145826.15504-1-trond.myklebust@hammerspace.com> <20190803145826.15504-2-trond.myklebust@hammerspace.com> <20190803145826.15504-3-trond.myklebust@hammerspace.com> <20190803145826.15504-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 X-Virus-Scanned: ClamAV using ClamSMTP In pnfs_update_layout() ensure that we do report any fatal errors from nfs4_select_rw_stateid(). Fixes: d9aba2b40de6 ("NFSv4: Don't use the zero stateid with layoutget") Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 75bd5b552ba4..4525d5acae38 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1903,12 +1903,6 @@ pnfs_update_layout(struct inode *ino, goto out_unlock; } - if (!nfs4_valid_open_stateid(ctx->state)) { - trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, - PNFS_UPDATE_LAYOUT_INVALID_OPEN); - goto out_unlock; - } - /* * Choose a stateid for the LAYOUTGET. If we don't have a layout * stateid, or it has been invalidated, then we must use the open @@ -1939,6 +1933,7 @@ pnfs_update_layout(struct inode *ino, iomode == IOMODE_RW ? FMODE_WRITE : FMODE_READ, NULL, &stateid, NULL); if (status != 0) { + lseg = ERR_PTR(status); trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, PNFS_UPDATE_LAYOUT_INVALID_OPEN); From patchwork Sat Aug 3 14:58:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11074503 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BAA05912 for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA770284DC for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93E04286C0; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 089D9285CB for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727850AbfHCPAj (ORCPT ); Sat, 3 Aug 2019 11:00:39 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:44331 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727844AbfHCPAi (ORCPT ); Sat, 3 Aug 2019 11:00:38 -0400 Received: by mail-io1-f66.google.com with SMTP id s7so158534403iob.11 for ; Sat, 03 Aug 2019 08:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LlF62m+Gv0rAWCHTfnQLpoe7ZScHzX+jX7oHGPOV2KU=; b=Pne7OWAaTix6S/cswb0pc4AfskzeP+4UfO9f4+FE1NPgtB3JJAhystlgIxlZ8vx3ZC gHwzXOZNwQ5+zJQz6D5F7ok8jROJgRC992DsEDq07IoWagvUM3vvJy7Rm6d3wIWPV/WQ NQ01wPbXUrdoxlRP+7PaGB25LHJtbswsCzyJT8PfLlnw7cKnIP9RoywRUuNR/mTwCh/k ghdEIoudSu2Z/JseDoa201vZd8ZE89RoQYcRk/y3t+bYdyWNKhP8/qtmRdHbFIx4KGfm K3XI1QbZFqcCv33199Itta9r39wUpDDAGEeDt3Cxn27xLobwBOSSWlJ3czI8LuZIZiWK oeAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LlF62m+Gv0rAWCHTfnQLpoe7ZScHzX+jX7oHGPOV2KU=; b=q4JGtTUHWGBLbxbNS8NugnRbWM4HU172F+5j8Lw7y92k2a/2svzWh3xarYc8xso72D 0aBNU4fz3QfpGXv1m+CQgE6I6s+4v+OGnWL6ScVNP0sLNfy9X8mjAScpb+j/lERHfwla xT9QIfpI33z09yxOpjlqchwLVFIzhbSnWXm3OQIx/PzFnvVfRLXrEZ/FLNPfcMF247ct GIoYCYYsUv3AgqFQBWFcx/xV2WWNmNH9Naj7kanSW8sYc3ELnGD9w6bTI0JEvfNGpFC2 BXkfUZHBUpYR+D0mFHw0DfcwbYa2scd3px4JxfQlyetGxBpVODq8QG4+5Lh2KyvmUhRH 830w== X-Gm-Message-State: APjAAAVa4/c6FJasAk29ntNl4VzEmKa950wmeYjYznW8EfpOanLd7Bwu 7j6HEdYwo3sOdhEGDyuKEI8YV58= X-Google-Smtp-Source: APXvYqyawBjdduvTF9ENO1rKeeWc7zSeBubAw4Vh1TSG5RSs3qG+jpA1lw2CEXxHtW6lfY0lLsJBdw== X-Received: by 2002:a6b:e608:: with SMTP id g8mr7838559ioh.88.1564844437317; Sat, 03 Aug 2019 08:00:37 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f20sm60820416ioh.17.2019.08.03.08.00.36 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 03 Aug 2019 08:00:36 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 6/8] NFSv4.1: Fix open stateid recovery Date: Sat, 3 Aug 2019 10:58:24 -0400 Message-Id: <20190803145826.15504-6-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190803145826.15504-5-trond.myklebust@hammerspace.com> References: <20190803145826.15504-1-trond.myklebust@hammerspace.com> <20190803145826.15504-2-trond.myklebust@hammerspace.com> <20190803145826.15504-3-trond.myklebust@hammerspace.com> <20190803145826.15504-4-trond.myklebust@hammerspace.com> <20190803145826.15504-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 X-Virus-Scanned: ClamAV using ClamSMTP The logic for checking in nfs41_check_open_stateid() whether the state is supported by a delegation is inverted. In addition, it makes more sense to perform that check before we check for expired locks. Fixes: 8a64c4ef106d1 ("NFSv4.1: Even if the stateid is OK,...") Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 65 +++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 21e3c159bc69..c9e14ce0b7b2 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1683,6 +1683,14 @@ static void nfs_state_set_open_stateid(struct nfs4_state *state, write_sequnlock(&state->seqlock); } +static void nfs_state_clear_open_state_flags(struct nfs4_state *state) +{ + clear_bit(NFS_O_RDWR_STATE, &state->flags); + clear_bit(NFS_O_WRONLY_STATE, &state->flags); + clear_bit(NFS_O_RDONLY_STATE, &state->flags); + clear_bit(NFS_OPEN_STATE, &state->flags); +} + static void nfs_state_set_delegation(struct nfs4_state *state, const nfs4_stateid *deleg_stateid, fmode_t fmode) @@ -2074,13 +2082,7 @@ static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state * { int ret; - /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ - clear_bit(NFS_O_RDWR_STATE, &state->flags); - clear_bit(NFS_O_WRONLY_STATE, &state->flags); - clear_bit(NFS_O_RDONLY_STATE, &state->flags); /* memory barrier prior to reading state->n_* */ - clear_bit(NFS_DELEGATED_STATE, &state->flags); - clear_bit(NFS_OPEN_STATE, &state->flags); smp_rmb(); ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); if (ret != 0) @@ -2156,6 +2158,8 @@ static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *sta ctx = nfs4_state_find_open_context(state); if (IS_ERR(ctx)) return -EAGAIN; + clear_bit(NFS_DELEGATED_STATE, &state->flags); + nfs_state_clear_open_state_flags(state); ret = nfs4_do_open_reclaim(ctx, state); put_nfs_open_context(ctx); return ret; @@ -2697,6 +2701,7 @@ static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st { /* NFSv4.0 doesn't allow for delegation recovery on open expire */ nfs40_clear_delegation_stateid(state); + nfs_state_clear_open_state_flags(state); return nfs4_open_expired(sp, state); } @@ -2739,13 +2744,13 @@ static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, return -NFS4ERR_EXPIRED; } -static void nfs41_check_delegation_stateid(struct nfs4_state *state) +static int nfs41_check_delegation_stateid(struct nfs4_state *state) { struct nfs_server *server = NFS_SERVER(state->inode); nfs4_stateid stateid; struct nfs_delegation *delegation; const struct cred *cred = NULL; - int status; + int status, ret = NFS_OK; /* Get the delegation credential for use by test/free_stateid */ rcu_read_lock(); @@ -2753,20 +2758,15 @@ static void nfs41_check_delegation_stateid(struct nfs4_state *state) if (delegation == NULL) { rcu_read_unlock(); nfs_state_clear_delegation(state); - return; + return NFS_OK; } nfs4_stateid_copy(&stateid, &delegation->stateid); - if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { - rcu_read_unlock(); - nfs_state_clear_delegation(state); - return; - } if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { rcu_read_unlock(); - return; + return NFS_OK; } if (delegation->cred) @@ -2776,8 +2776,24 @@ static void nfs41_check_delegation_stateid(struct nfs4_state *state) trace_nfs4_test_delegation_stateid(state, NULL, status); if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) nfs_finish_clear_delegation_stateid(state, &stateid); + else + ret = status; put_cred(cred); + return ret; +} + +static void nfs41_delegation_recover_stateid(struct nfs4_state *state) +{ + nfs4_stateid tmp; + + if (test_bit(NFS_DELEGATED_STATE, &state->flags) && + nfs4_copy_delegation_stateid(state->inode, state->state, + &tmp, NULL) && + nfs4_stateid_match_other(&state->stateid, &tmp)) + nfs_state_set_delegation(state, &tmp, state->state); + else + nfs_state_clear_delegation(state); } /** @@ -2847,21 +2863,12 @@ static int nfs41_check_open_stateid(struct nfs4_state *state) const struct cred *cred = state->owner->so_cred; int status; - if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { - if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { - if (nfs4_have_delegation(state->inode, state->state)) - return NFS_OK; - return -NFS4ERR_OPENMODE; - } + if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) return -NFS4ERR_BAD_STATEID; - } status = nfs41_test_and_free_expired_stateid(server, stateid, cred); trace_nfs4_test_open_stateid(state, NULL, status); if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { - clear_bit(NFS_O_RDONLY_STATE, &state->flags); - clear_bit(NFS_O_WRONLY_STATE, &state->flags); - clear_bit(NFS_O_RDWR_STATE, &state->flags); - clear_bit(NFS_OPEN_STATE, &state->flags); + nfs_state_clear_open_state_flags(state); stateid->type = NFS4_INVALID_STATEID_TYPE; return status; } @@ -2874,7 +2881,11 @@ static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st { int status; - nfs41_check_delegation_stateid(state); + status = nfs41_check_delegation_stateid(state); + if (status != NFS_OK) + return status; + nfs41_delegation_recover_stateid(state); + status = nfs41_check_expired_locks(state); if (status != NFS_OK) return status; From patchwork Sat Aug 3 14:58:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11074501 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A333818B7 for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F0F0285D8 for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83710286DB; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 286ED285D8 for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727844AbfHCPAj (ORCPT ); Sat, 3 Aug 2019 11:00:39 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:44334 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727849AbfHCPAj (ORCPT ); Sat, 3 Aug 2019 11:00:39 -0400 Received: by mail-io1-f68.google.com with SMTP id s7so158534444iob.11 for ; Sat, 03 Aug 2019 08:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=m27ZvLzHwiRctmX2AA9qRyAWINQZyTlknWtR5CenV2I=; b=C8iNXGKRtWAGMDxk1MySlBvUEJMsExYjRVZo5RhgXZ/CVfqVdbf6I+VJf0hCD4mVz1 56xBmOl2zidapfxYLzu0SvVAkjdKIs4aT4Y3KQrNNmPjARxBR7khaYePjFSQiICB5TQf h0IGgDAGi5qnMT7XnGq8MYTCueMuFnUEmPjQfsgMDlVmeGt8eoSUKC3h/RaWXsvyTwpT aw80KQIVlzFd4sWgvb5CWMz01rCyVBMEYN1al4rCZsA0bUTvMC73lKX770C3zEyLaHp2 1sscDpWV49Q5ADPxhfZ+xhsDrkwW4a20XAmhu6FTzMig6l1Pk17CiC2eHvVzuhYtCrR8 q6kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m27ZvLzHwiRctmX2AA9qRyAWINQZyTlknWtR5CenV2I=; b=YoQiUWJY+tK5msXOPrf4k2qGz0N1cuKXMnIf7j8NJFduuGJeT5ruvKCK21yPQL+HeV 1B6shcnZPyoROV28ETtbCW3yg97hNdDoNZbKs3wYEl6oYPQLj26XmVppUyLePd2wtUj4 2JA0oKz3UF1KKdWMIBYF8KAEg1DtbfId7TJoljZcBIQO+9BIuhPv29885p3jeQQNk2MC 6Mran7G6dfpc2SfEpBBg34v1ETjzjdu/h6NMCc1GS6NLc7yKPRymn65GKjdCW5zI1BWf XOb8uwUhsovukiVzVY21Cf9DUuLgQlWwpFiE7ojeh9JUOQIV1g20Q86QuS3L/cnXi4uD atWw== X-Gm-Message-State: APjAAAXho3EtX1LdmToyW0/2+3TWaq5o/KPX3nvbU9cHBQMuwtrf7QIm BkGoBA58O7esHnv4AVVv0k1E5DU= X-Google-Smtp-Source: APXvYqwx7Ft0wO+c6oyom9iv2PfRIlovbBkk0hZxmLvYhk4UY1vbOnIE4iHTiUy474qF7eKr384IWg== X-Received: by 2002:a02:8663:: with SMTP id e90mr143203385jai.98.1564844438025; Sat, 03 Aug 2019 08:00:38 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f20sm60820416ioh.17.2019.08.03.08.00.37 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 03 Aug 2019 08:00:37 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 7/8] NFSv4.1: Only reap expired delegations Date: Sat, 3 Aug 2019 10:58:25 -0400 Message-Id: <20190803145826.15504-7-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190803145826.15504-6-trond.myklebust@hammerspace.com> References: <20190803145826.15504-1-trond.myklebust@hammerspace.com> <20190803145826.15504-2-trond.myklebust@hammerspace.com> <20190803145826.15504-3-trond.myklebust@hammerspace.com> <20190803145826.15504-4-trond.myklebust@hammerspace.com> <20190803145826.15504-5-trond.myklebust@hammerspace.com> <20190803145826.15504-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 X-Virus-Scanned: ClamAV using ClamSMTP Fix nfs_reap_expired_delegations() to ensure that we only reap delegations that are actually expired, rather than triggering on random errors. Fixes: 45870d6909d5a ("NFSv4.1: Test delegation stateids when server...") Signed-off-by: Trond Myklebust --- fs/nfs/delegation.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index 0af854cce8ff..071b90a45933 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -1046,6 +1046,22 @@ void nfs_test_expired_all_delegations(struct nfs_client *clp) nfs4_schedule_state_manager(clp); } +static void +nfs_delegation_test_free_expired(struct inode *inode, + nfs4_stateid *stateid, + const struct cred *cred) +{ + struct nfs_server *server = NFS_SERVER(inode); + const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; + int status; + + if (!cred) + return; + status = ops->test_and_free_expired(server, stateid, cred); + if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) + nfs_remove_bad_delegation(inode, stateid); +} + /** * nfs_reap_expired_delegations - reap expired delegations * @clp: nfs_client to process @@ -1057,7 +1073,6 @@ void nfs_test_expired_all_delegations(struct nfs_client *clp) */ void nfs_reap_expired_delegations(struct nfs_client *clp) { - const struct nfs4_minor_version_ops *ops = clp->cl_mvops; struct nfs_delegation *delegation; struct nfs_server *server; struct inode *inode; @@ -1088,11 +1103,7 @@ void nfs_reap_expired_delegations(struct nfs_client *clp) nfs4_stateid_copy(&stateid, &delegation->stateid); clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags); rcu_read_unlock(); - if (cred != NULL && - ops->test_and_free_expired(server, &stateid, cred) < 0) { - nfs_revoke_delegation(inode, &stateid); - nfs_inode_find_state_and_recover(inode, &stateid); - } + nfs_delegation_test_free_expired(inode, &stateid, cred); put_cred(cred); if (nfs4_server_rebooted(clp)) { nfs_inode_mark_test_expired_delegation(server,inode); From patchwork Sat Aug 3 14:58:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11074505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9FEE1920 for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B98B5285D8 for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A613C285FF; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47E9F284DC for ; Sat, 3 Aug 2019 15:00:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727849AbfHCPAk (ORCPT ); Sat, 3 Aug 2019 11:00:40 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:41906 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727851AbfHCPAj (ORCPT ); Sat, 3 Aug 2019 11:00:39 -0400 Received: by mail-io1-f68.google.com with SMTP id j5so154570196ioj.8 for ; Sat, 03 Aug 2019 08:00:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=2RjX4xJ+cxt3dLtKsWxFiNtC9Mhb5keEj/q7VRtZ0X4=; b=oL5F6dl1gqpHBlHo+vU929bXge79R2gvhjoOaLjTarNNzpdTOQYfprUecQJc+y98/0 KMqMusyfvDROr5zV6bz3JPrImbT15eINphXoVKRIwas3ZZz/Sqqm4AnhOyV7TE9czkvD r5FWwJaZXWRKTsymdu/alraZbcpg0NDyIU4G3G95+o+S0gZpicoaluXD9QX/9J2vv3nB oDVx7xicMGgn4irpNTanZ0D6Mo/viwGRHhkBjtV41B7zoXnbG7DTUg093Wunlxh8WOZf nmg9OSl61y+/4oqP1Imgyz0QyeNcMlz6aNR8enMYSzFDuxuuLGrpYWGYCM7FRPjeA+Mj 0yfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2RjX4xJ+cxt3dLtKsWxFiNtC9Mhb5keEj/q7VRtZ0X4=; b=XbGXW7mC07dJRAIhMLWAe3gFNCyIK1Mt3rJ9PsNzpQNJLUpaBkYWwWY1raw9nbRO51 JgKn1v5iavp9nvwQa8IpbkRRBNt+M4sRTN0MDM9fsZef3gzjVTV+BwatawFSHkdDkV4X 6ronjP2KEiLmqCtQE4a43Bvg/Ib9lE/bsSktipeh7G6CancOiWqiOAPz/pfFlNGHpLDm VMYtXoRfvHOIN2rBt7EKxWKsYIhNkoGvdCjAnYxfjnT0jVJSJKg/nN8IB5n5tM9AalH2 EfmN1RS5bD9y5bppu1D1vO7Ftu5yxHnEC9ROAiqc0HGavXbnufRB5mmWu7CFxng7t2Kl 3tcA== X-Gm-Message-State: APjAAAVoMWZEg20Fv7dmAJgPM7FEDMqT5MZUmcpBFM8CzJd+VVupGYIW A7nGLPeWc9DmF80kPuFKM96SCNU= X-Google-Smtp-Source: APXvYqx/6LKWfV9H/Po2QH+yyt84jGztyqbt7YjRrduAJ8mSeyTRo15EfVQJGQjIJJ5z55Pko4YgOg== X-Received: by 2002:a6b:cd86:: with SMTP id d128mr130476671iog.234.1564844438649; Sat, 03 Aug 2019 08:00:38 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f20sm60820416ioh.17.2019.08.03.08.00.38 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 03 Aug 2019 08:00:38 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 8/8] NFSv4: Check the return value of update_open_stateid() Date: Sat, 3 Aug 2019 10:58:26 -0400 Message-Id: <20190803145826.15504-8-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190803145826.15504-7-trond.myklebust@hammerspace.com> References: <20190803145826.15504-1-trond.myklebust@hammerspace.com> <20190803145826.15504-2-trond.myklebust@hammerspace.com> <20190803145826.15504-3-trond.myklebust@hammerspace.com> <20190803145826.15504-4-trond.myklebust@hammerspace.com> <20190803145826.15504-5-trond.myklebust@hammerspace.com> <20190803145826.15504-6-trond.myklebust@hammerspace.com> <20190803145826.15504-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 X-Virus-Scanned: ClamAV using ClamSMTP Ensure that we always check the return value of update_open_stateid() so that we can retry if the update of local state failed. Fixes: e23008ec81ef3 ("NFSv4 reduce attribute requests for open reclaim") Signed-off-by: Trond Myklebust Cc: stable@vger.kernel.org # v3.7+ --- fs/nfs/nfs4proc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index c9e14ce0b7b2..3e0b93f2b61a 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1915,8 +1915,9 @@ _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) if (data->o_res.delegation_type != 0) nfs4_opendata_check_deleg(data, state); update: - update_open_stateid(state, &data->o_res.stateid, NULL, - data->o_arg.fmode); + if (!update_open_stateid(state, &data->o_res.stateid, + NULL, data->o_arg.fmode)) + return ERR_PTR(-EAGAIN); refcount_inc(&state->count); return state; @@ -1981,8 +1982,11 @@ _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) if (data->o_res.delegation_type != 0) nfs4_opendata_check_deleg(data, state); - update_open_stateid(state, &data->o_res.stateid, NULL, - data->o_arg.fmode); + if (!update_open_stateid(state, &data->o_res.stateid, + NULL, data->o_arg.fmode)) { + nfs4_put_open_state(state); + state = ERR_PTR(-EAGAIN); + } out: nfs_release_seqid(data->o_arg.seqid); return state;