From patchwork Tue Sep 20 16:55:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9342117 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 037FE607D0 for ; Tue, 20 Sep 2016 16:56:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E949429495 for ; Tue, 20 Sep 2016 16:56:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDEEC2996E; Tue, 20 Sep 2016 16:56:27 +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=-6.3 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 795E829495 for ; Tue, 20 Sep 2016 16:56:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755532AbcITQ40 (ORCPT ); Tue, 20 Sep 2016 12:56:26 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:36026 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753999AbcITQ4Z (ORCPT ); Tue, 20 Sep 2016 12:56:25 -0400 Received: by mail-qk0-f194.google.com with SMTP id z143so1432168qka.3 for ; Tue, 20 Sep 2016 09:56:25 -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=N9/iISd+kD2FDYpBm/Nq5fw9So5cnmqF1/ztCimOJRY=; b=psUfdS42vly6BKPyC/K6AjU1rmuXcrMJz0VvIjNx6FxpTBYjy07lVyGATkkAREMsV6 U5aiHx/M3FtcStPBKuQek+2QlQzBfjA6hErJU0BewXFBtLCC5t7Msp8Gjs1H3p0H1eku 9Q2r4A0ZXNwz6RFfEzh9VDoTZQPOcsNxVc4yy9qtgPAfC0p2E8DC+59ud0ZDtXlfK0Kr BExIz0ztTvrLuGyHYGmtsgZmA0/3smSFqaDQXqSi7cITug9GLNfA08N+yEsClN+iKie3 DL2TWlVC51j0ZFw4dFQciJi7qA8AXyjtJCy2DrhuhOYSLcZG236/WNTn5gt8LNa/XZRu zpKQ== 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=N9/iISd+kD2FDYpBm/Nq5fw9So5cnmqF1/ztCimOJRY=; b=SsxT3EZUMfkCy4dTiXFOphSDrZcz4rwr1D+sWqPsLcvjS00Zj3JtgB79NLZJPMceVb PMhSkRXeWoOxKxoRyS49h3Xfga//4L4ugcPyKqW9eOEpmvSp4/IINkYuPdaEkB6uRWQp ODfPjwhYpjZGhSKH1Pp9P2IzQSpQSerVg5vyjhA2lhWOQQgwMf70ia1R0Zm/Sy63J6SG jU9O8gfMrXQeZ/mHyQKnCKQ5LegTzeBTOqfv5zbqY6RG3EFkFnyPEvvLb8Cjc6ZP35C4 0rllOs3Uob131JUwpDmuDKD8kx+V4z2TIWHwFeSZxSIB1BZA8sf64KLvXFYyUApvSKE9 0AVQ== X-Gm-Message-State: AE9vXwNq55YQzmhZLANQoZBog4RL+rHVfK+jIHy7uZ262XrGoWsHcIKiwVMqlrc6Ui4KBA== X-Received: by 10.55.73.6 with SMTP id w6mr38362280qka.59.1474390584847; Tue, 20 Sep 2016 09:56:24 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (50-108-86-94.adr01.mskg.mi.frontiernet.net. [50.108.86.94]) by smtp.gmail.com with ESMTPSA id i4sm16537202qte.40.2016.09.20.09.56.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Sep 2016 09:56:24 -0700 (PDT) From: Trond Myklebust To: anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org, Oleg Drokin Subject: [PATCH v6 07/29] NFSv4.1: Add a helper function to deal with expired stateids Date: Tue, 20 Sep 2016 12:55:49 -0400 Message-Id: <1474390571-17106-8-git-send-email-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474390571-17106-7-git-send-email-trond.myklebust@primarydata.com> References: <1474390571-17106-1-git-send-email-trond.myklebust@primarydata.com> <1474390571-17106-2-git-send-email-trond.myklebust@primarydata.com> <1474390571-17106-3-git-send-email-trond.myklebust@primarydata.com> <1474390571-17106-4-git-send-email-trond.myklebust@primarydata.com> <1474390571-17106-5-git-send-email-trond.myklebust@primarydata.com> <1474390571-17106-6-git-send-email-trond.myklebust@primarydata.com> <1474390571-17106-7-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 2b569d5fb3e2..0ade81441ac2 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -2408,6 +2408,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); @@ -2432,16 +2452,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); } @@ -2467,14 +2481,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); @@ -6109,17 +6118,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; }