From patchwork Fri Sep 9 18:04:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9324087 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 728AE60752 for ; Fri, 9 Sep 2016 18:04:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 663A229F9A for ; Fri, 9 Sep 2016 18:04:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58A4C29F98; Fri, 9 Sep 2016 18:04:56 +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 E631429F98 for ; Fri, 9 Sep 2016 18:04:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754299AbcIISEy (ORCPT ); Fri, 9 Sep 2016 14:04:54 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:33743 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754264AbcIISEw (ORCPT ); Fri, 9 Sep 2016 14:04:52 -0400 Received: by mail-oi0-f68.google.com with SMTP id y2so7218263oie.0 for ; Fri, 09 Sep 2016 11:04:52 -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=5AcLzucUCTXlssYU4PYQz7Md4Ss9VaYVL0YDtgFs5vA=; b=w/5WN0okNqRyDawudW4uA710N8xLN9777ejicp2OrtuDr1ybN8ydUkg3Y8cK569Hnr rA0qPe/f+E6H1mnh/2zgW1cKk0CJi8TkY/+iKwfucP43HhPV9+rAAa0/e7B44ricl+t6 9/MWw3f6rKxCmMgjwU1XjYj/JkGHJddZcZjZ9LkEFsAaKyQPACvezqndmm9Dan1cIKse rXXKreiVciPI3i5BCEAZ2CEqExDb84fYthfAJTXeRqzYI9ggjEnQoVtkKhs6fsk/t9wL ONLHikOB3jJGB6xMI7mWpWavU6DdR0fr8iNfx2y16cLFeBIMmTf3g+aBjQjgPkWxc+HY 3O2Q== 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=5AcLzucUCTXlssYU4PYQz7Md4Ss9VaYVL0YDtgFs5vA=; b=kTfcsj6uVuWvvYuDK+0SLqyHk8wl5O43lPVu7ebEPONRWEXz0WyArLyENAi+Ac4vTR 0L68L6hbFvG8yw84JQEMlsgClO2jomsU2LQ7i1enTY4tfbF0rjWnGjaN0ix3rsKz4qcc /t/dn31uVdIfRZFLmMTvODta/MB/y3c23XiKgoARLTCzgQ0c4hT2Wu+A5jbOEpJH/Bge cT/kMrWJdGMZVIoNgjO3LKSCXOXIzLYWs6ibh6utxjP2bGnmmmBY1iE3hg+GAuvsaNAw yxVz+Rb1McNYZnnFp502b76SjU+k/lIwEOVKaQq580FcIJpWuNl6m21XUR1F3OCqMoA6 2gjw== X-Gm-Message-State: AE9vXwNa4jLW18GI9GgQrsFYiKr2Y0Ff82Wx133C5AA6reM91hDW/me4NU6fAUgfiLE70w== X-Received: by 10.202.60.138 with SMTP id j132mr7127725oia.90.1473444286889; Fri, 09 Sep 2016 11:04:46 -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 r200sm1925797itc.13.2016.09.09.11.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Sep 2016 11:04:46 -0700 (PDT) From: Trond Myklebust To: linux-nfs@vger.kernel.org Cc: Oleg Drokin Subject: [PATCH v3 04/12] NFSv4.1: Add a helper function to deal with expired stateids Date: Fri, 9 Sep 2016 14:04:05 -0400 Message-Id: <1473444253-12433-5-git-send-email-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473444253-12433-4-git-send-email-trond.myklebust@primarydata.com> References: <1473444253-12433-1-git-send-email-trond.myklebust@primarydata.com> <1473444253-12433-2-git-send-email-trond.myklebust@primarydata.com> <1473444253-12433-3-git-send-email-trond.myklebust@primarydata.com> <1473444253-12433-4-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 9b7ff26b63ff..2fe3445cb7b4 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; }