From patchwork Wed Sep 7 18:01:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9319749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1261D607D3 for ; Wed, 7 Sep 2016 18:02:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 277FA293CF for ; Wed, 7 Sep 2016 18:02:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C5D6293E9; Wed, 7 Sep 2016 18:02:02 +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=-4.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 AA1E9293CF for ; Wed, 7 Sep 2016 18:02:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935283AbcIGSCA (ORCPT ); Wed, 7 Sep 2016 14:02:00 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:35926 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935272AbcIGSB6 (ORCPT ); Wed, 7 Sep 2016 14:01:58 -0400 Received: by mail-it0-f65.google.com with SMTP id i184so2146408itf.3 for ; Wed, 07 Sep 2016 11:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+x2AKsD9sNFegW3YMKd/WiB8IyYnhOggp5soD24CHJM=; b=DIl6v080Qo4uooHo9ySS8wFO8aO1oMmTidXj416WS31WbSCwT06nE/HclHGK27/fEl JOaygaI+NJLgfA6OfE+NZZ7d3k1zJssRbi9+mWojQnmCS22wlKa8H989l5UKRYNFMuGa 1GIcAU12NYAaSSqJkHKCpl0owUG8/DpqfgqSAqBaNYTdOH+2sxIqXHy1A7y/Fm51TkTq 6shBiLif6YJp7v74f7M+PUeciI6boDt0QznbN5QkfGOTUMxNBVWIiYelKm6HWGQqoQPO va7Dck6szXhKRzwmedt6UqTuk4Pjt15KSWRWR5mI/IWOuqsyFXiFguwpP8XZc/h4zh/G V55A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+x2AKsD9sNFegW3YMKd/WiB8IyYnhOggp5soD24CHJM=; b=K7efo//FDy6DZtxIu2k6UVFUobn5IYOXC61qUExAayructLQ1cRBeR7nFYajyh4aUI gJhjnE0vUMZZlqXFzHFf11C2G1AZmDBGhLVSQdTnuUK1K50zGdsymcnNIyzRU1AQdmUa jyxwRVv0oiFG6zShBaciFIv90xBqgneIV9VI7gPjuNNQUHROvOj32jc9xYZBjy79zOwu +GCR6ZWBLBl977g9scgAtOa98/1vxSOmMbatg7xpOI7Xvw86c0vnQNrFsenMfXzQUVR+ TRz5AKfAHPtjqGr71UNnoDQf2w3JvFJfYc+kfBKaLVeVsIvdkdgQEjSy/G1ItG6Ir2ML wRHQ== X-Gm-Message-State: AE9vXwOCpRmD8S6LjRg/VAXoO1v3zng2ljg0CDjsQYqDFQxP/TmsYU8DlDJi/sFCt6KLiA== X-Received: by 10.36.55.146 with SMTP id r140mr8502930itr.73.1473271317533; Wed, 07 Sep 2016 11:01:57 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-49-162-121.hsd1.mi.comcast.net. [68.49.162.121]) by smtp.gmail.com with ESMTPSA id v7sm3626003ita.9.2016.09.07.11.01.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Sep 2016 11:01:57 -0700 (PDT) From: Trond Myklebust To: anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 3/7] NFSv4.1: Add a helper function to deal with expired stateids Date: Wed, 7 Sep 2016 14:01:23 -0400 Message-Id: <1473271287-43478-4-git-send-email-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473271287-43478-3-git-send-email-trond.myklebust@primarydata.com> References: <1473271287-43478-1-git-send-email-trond.myklebust@primarydata.com> <1473271287-43478-2-git-send-email-trond.myklebust@primarydata.com> <1473271287-43478-3-git-send-email-trond.myklebust@primarydata.com> 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 NFSv4.1 and newer, if the server decides to revoke some or all of the protocol state, the client is required to iterate through all the stateids that it holds and call TEST_STATEID to determine which stateids still correspond to valid state, and then call FREE_STATEID on the others. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index f1f5d0f10a6e..9c3e9fa23aa6 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -2405,6 +2405,26 @@ static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st } #if defined(CONFIG_NFS_V4_1) +static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, + nfs4_stateid *stateid, + struct rpc_cred *cred) +{ + int status; + + status = nfs41_test_stateid(server, stateid, cred); + + switch (status) { + case -NFS4ERR_EXPIRED: + case -NFS4ERR_ADMIN_REVOKED: + case -NFS4ERR_DELEG_REVOKED: + /* Ack the revoked state to the server */ + nfs41_free_stateid(server, stateid, cred); + case -NFS4ERR_BAD_STATEID: + return status; + } + return NFS_OK; +} + static void nfs41_check_delegation_stateid(struct nfs4_state *state) { struct nfs_server *server = NFS_SERVER(state->inode); @@ -2429,16 +2449,10 @@ static void nfs41_check_delegation_stateid(struct nfs4_state *state) nfs4_stateid_copy(&stateid, &delegation->stateid); cred = get_rpccred(delegation->cred); rcu_read_unlock(); - status = nfs41_test_stateid(server, &stateid, cred); + status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); trace_nfs4_test_delegation_stateid(state, NULL, status); - - if (status != NFS_OK) { - /* Free the stateid unless the server explicitly - * informs us the stateid is unrecognized. */ - if (status != -NFS4ERR_BAD_STATEID) - nfs41_free_stateid(server, &stateid, cred); + if (status != NFS_OK) nfs_finish_clear_delegation_stateid(state); - } put_rpccred(cred); } @@ -2464,14 +2478,9 @@ static int nfs41_check_open_stateid(struct nfs4_state *state) (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) return -NFS4ERR_BAD_STATEID; - status = nfs41_test_stateid(server, stateid, cred); + status = nfs41_test_and_free_expired_stateid(server, stateid, cred); trace_nfs4_test_open_stateid(state, NULL, status); if (status != NFS_OK) { - /* Free the stateid unless the server explicitly - * informs us the stateid is unrecognized. */ - if (status != -NFS4ERR_BAD_STATEID) - nfs41_free_stateid(server, stateid, cred); - clear_bit(NFS_O_RDONLY_STATE, &state->flags); clear_bit(NFS_O_WRONLY_STATE, &state->flags); clear_bit(NFS_O_RDWR_STATE, &state->flags); @@ -6106,17 +6115,11 @@ static int nfs41_check_expired_locks(struct nfs4_state *state) if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { struct rpc_cred *cred = lsp->ls_state->owner->so_cred; - status = nfs41_test_stateid(server, + status = nfs41_test_and_free_expired_stateid(server, &lsp->ls_stateid, cred); trace_nfs4_test_lock_stateid(state, lsp, status); if (status != NFS_OK) { - /* Free the stateid unless the server - * informs us the stateid is unrecognized. */ - if (status != -NFS4ERR_BAD_STATEID) - nfs41_free_stateid(server, - &lsp->ls_stateid, - cred); clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); ret = status; }