From patchwork Wed Sep 7 18:01:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9319751 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 C07B3607D3 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 D5C77293CF for ; Wed, 7 Sep 2016 18:02:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAD72293E9; 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 4D7C4293CF for ; Wed, 7 Sep 2016 18:02:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935330AbcIGSCA (ORCPT ); Wed, 7 Sep 2016 14:02:00 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:33053 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933182AbcIGSB7 (ORCPT ); Wed, 7 Sep 2016 14:01:59 -0400 Received: by mail-it0-f68.google.com with SMTP id g185so2144987ith.0 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=A4IhNJuyhhoBQehEGGMwuw2dt4SVm5ZwiRN03UuANw8=; b=JRAF9AOj/PpnnAdsadNvPNMOfA0CYR1i+VIs3rqbM/JXw7rzGm8Z2JVWfgrnzZVj9b /qFd/b17tPLM5fMZwEXl4bYStDFcccbvmWYtJ1RPLgO0FCdG1bEe6vnX2lPaIW30meE9 iD4S8b0ZREdtz2qNlspFdjOcuRWSryCpBtCIyCIeu1Ra7kJk8jlvvP2u/ZsOr62hrO/W h99mkx2pQ+P8OJNWY/zkj1/zB/j/ODTLtwRQJoUw0RDazhD2LQLRrOTW87f76Kqe5Adn vfw5ksElgswOAMbzsruFZXKZ+ADTxM+pp6dMB7J68HhEuqYU3BDhYtY2jBsH+UrxxkOh l3dA== 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=A4IhNJuyhhoBQehEGGMwuw2dt4SVm5ZwiRN03UuANw8=; b=PCs1ig7hHquU0gq0Cco3EbBWJ9e4T5XHm8JLy6f9gbdmRjOpJ+89Pp0QLvdMCVNL1O PWvzskifvdvCZ4HmwCCHBiCQbkRNbvuf1cSQgwbMM1WV+OpBP4wPvpOp43yVFvW/jIEy pTMd7HNVRsVwbHd5FRferH0RLMberEDuuodYknaHSKsnPthvG2EEmrHhsLMIfgoZ3ZsV oWZCqJGmhyUHTB47L4DKPRSQGMSWs82yDCeh+JMl7Q+C3Zm6nAeQoREX4D04pAzcVNaH rQJgoHlxHLnVw1NQ0je/jJrUUSlIJ4kk3pT/ZpRgO3jfmnfNuEZSQe33czPGamS47hKR MgQQ== X-Gm-Message-State: AE9vXwMphUESujAn6ty3myOSTb15NSwotobwDaR5DkxhC7zC8iyPwGd9oB3RquQcNxNfYw== X-Received: by 10.36.237.6 with SMTP id r6mr8076779ith.62.1473271318399; Wed, 07 Sep 2016 11:01:58 -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.57 (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 4/7] NFSv4.x: Allow callers of nfs_remove_bad_delegation() to specify a stateid Date: Wed, 7 Sep 2016 14:01:24 -0400 Message-Id: <1473271287-43478-5-git-send-email-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473271287-43478-4-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> <1473271287-43478-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 Allow the callers of nfs_remove_bad_delegation() to specify the stateid that needs to be marked as bad. Signed-off-by: Trond Myklebust --- fs/nfs/delegation.c | 30 +++++++++++++++++++++++------- fs/nfs/delegation.h | 2 +- fs/nfs/flexfilelayout/flexfilelayout.c | 2 +- fs/nfs/nfs4proc.c | 14 ++++++++------ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index 322c2585bc34..76dc11ecdedd 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -642,23 +642,39 @@ static void nfs_client_mark_return_unused_delegation_types(struct nfs_client *cl rcu_read_unlock(); } -static void nfs_revoke_delegation(struct inode *inode) +static void nfs_mark_delegation_revoked(struct nfs_server *server, + struct nfs_delegation *delegation) +{ + set_bit(NFS_DELEGATION_REVOKED, &delegation->flags); + nfs_mark_return_delegation(server, delegation); +} + +static bool nfs_revoke_delegation(struct inode *inode, + const nfs4_stateid *stateid) { struct nfs_delegation *delegation; + bool ret = false; + rcu_read_lock(); delegation = rcu_dereference(NFS_I(inode)->delegation); - if (delegation != NULL) { - set_bit(NFS_DELEGATION_REVOKED, &delegation->flags); - nfs_mark_return_delegation(NFS_SERVER(inode), delegation); - } + if (delegation == NULL) + goto out; + if (stateid && !nfs4_stateid_match(stateid, &delegation->stateid)) + goto out; + nfs_mark_delegation_revoked(NFS_SERVER(inode), delegation); + ret = true; +out: rcu_read_unlock(); + return ret; } -void nfs_remove_bad_delegation(struct inode *inode) +void nfs_remove_bad_delegation(struct inode *inode, + const nfs4_stateid *stateid) { struct nfs_delegation *delegation; - nfs_revoke_delegation(inode); + if (!nfs_revoke_delegation(inode, stateid)) + return; delegation = nfs_inode_detach_delegation(inode); if (delegation) { nfs_inode_find_state_and_recover(inode, &delegation->stateid); diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h index 64724d252a79..d40827af5913 100644 --- a/fs/nfs/delegation.h +++ b/fs/nfs/delegation.h @@ -47,7 +47,7 @@ void nfs_expire_unused_delegation_types(struct nfs_client *clp, fmode_t flags); void nfs_expire_unreferenced_delegations(struct nfs_client *clp); int nfs_client_return_marked_delegations(struct nfs_client *clp); int nfs_delegations_present(struct nfs_client *clp); -void nfs_remove_bad_delegation(struct inode *inode); +void nfs_remove_bad_delegation(struct inode *inode, const nfs4_stateid *stateid); void nfs_delegation_mark_reclaim(struct nfs_client *clp); void nfs_delegation_reap_unclaimed(struct nfs_client *clp); diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index 51b51369704c..98ace127bf86 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -1080,7 +1080,7 @@ static int ff_layout_async_handle_error_v4(struct rpc_task *task, case -NFS4ERR_BAD_STATEID: if (state == NULL) break; - nfs_remove_bad_delegation(state->inode); + nfs_remove_bad_delegation(state->inode, NULL); case -NFS4ERR_OPENMODE: if (state == NULL) break; diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 9c3e9fa23aa6..9d007a0555a7 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -2382,9 +2382,10 @@ static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *sta return ret; } -static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) +static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, + const nfs4_stateid *stateid) { - nfs_remove_bad_delegation(state->inode); + nfs_remove_bad_delegation(state->inode, stateid); write_seqlock(&state->seqlock); nfs4_stateid_copy(&state->stateid, &state->open_stateid); write_sequnlock(&state->seqlock); @@ -2394,7 +2395,7 @@ static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state) static void nfs40_clear_delegation_stateid(struct nfs4_state *state) { if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) - nfs_finish_clear_delegation_stateid(state); + nfs_finish_clear_delegation_stateid(state, NULL); } static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) @@ -2440,19 +2441,20 @@ static void nfs41_check_delegation_stateid(struct nfs4_state *state) rcu_read_unlock(); return; } + + nfs4_stateid_copy(&stateid, &delegation->stateid); if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { rcu_read_unlock(); - nfs_finish_clear_delegation_stateid(state); + nfs_finish_clear_delegation_stateid(state, &stateid); return; } - nfs4_stateid_copy(&stateid, &delegation->stateid); cred = get_rpccred(delegation->cred); rcu_read_unlock(); status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); trace_nfs4_test_delegation_stateid(state, NULL, status); if (status != NFS_OK) - nfs_finish_clear_delegation_stateid(state); + nfs_finish_clear_delegation_stateid(state, &stateid); put_rpccred(cred); }