From patchwork Thu Sep 15 16:45:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9334281 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 E9D99601C2 for ; Thu, 15 Sep 2016 16:46:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF64C29A79 for ; Thu, 15 Sep 2016 16:46:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D42D429A7C; Thu, 15 Sep 2016 16:46:21 +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 5807329A79 for ; Thu, 15 Sep 2016 16:46:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753665AbcIOQqT (ORCPT ); Thu, 15 Sep 2016 12:46:19 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:35221 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753753AbcIOQqR (ORCPT ); Thu, 15 Sep 2016 12:46:17 -0400 Received: by mail-it0-f65.google.com with SMTP id e20so4992065itc.2 for ; Thu, 15 Sep 2016 09:46:16 -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=Oi/AKlfskaE9Xi74IzuA32FbMgp6U5T7WXoGcLQS5oc=; b=s1gRK6CrpjyH9ytu3bIOKtQLISQX5DTXV+x/gYX4GzuYqy8sOG+oAQplEzQVcTXqyc QxtsFEdAlxvEsGmBE8YjfQh8a9o0hb1d4DHM/hXxEC8FgCvof+S5BTOpmLDDJWoWHTGj QmmVr0bMovdoDp4N/Pl4icIrTX+JulqRfUPGapBXyVZafGH1cRZ3jh2M7S5LSpobmAbm kK5W7PlsWtTb2FUNswKs0/Qxrkpkqa2JmGH0zKpKv26De2rv2zAWdzHZWvtrtpuKfNjB cGIQ1Ps6U2ys4GsYNEl4B18iMEumCtbV6sC487e4NQZBpbIC1OHS1+m0MO0z4c0jYHJV 2uPw== 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=Oi/AKlfskaE9Xi74IzuA32FbMgp6U5T7WXoGcLQS5oc=; b=FcqE8Hh859DnPmMMKPzLTwJMaQscX2yEeW19KV6TBDQ22ZK3ZHC7mJDl7pWa+SfEqr S3M7nFrImsX9eAVEp9VG920vmO6aB0P/T7fYTtmfh65/ITb8zFNX1nUrXvDyFGZXkTkI NZs/MFAvzRKylIHmjVBoZMLrZxctgumSXGWqGVBL6jvhsMRbFnLGLShI1J/vEwgzJFkZ D1xLQuTIskH/Bbvmzw1hnTk3AVZ/bjR1Uoio8aoJCKESNzeWyMumnHf7mDxSX7V0Q+PK MRsxqdwnZpKKmO0Fm11TyjtVp5KCtaB4sXRBx1jGYW0LkHG3k/Bvr2UxMi30L7p/bB3V pnWA== X-Gm-Message-State: AE9vXwP/avSzWAquBMmn4qPhUCuLThYi+cpJ8mxomYJZhWeLDdj68l4Dyn6TgsJi4DoWOA== X-Received: by 10.36.214.193 with SMTP id o184mr571254itg.5.1473957976460; Thu, 15 Sep 2016 09:46:16 -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 y132sm1248687itc.20.2016.09.15.09.46.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Sep 2016 09:46:16 -0700 (PDT) From: Trond Myklebust To: anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org, Oleg Drokin Subject: [PATCH v4 10/20] NFSv4.1: Ensure we always run TEST/FREE_STATEID on locks Date: Thu, 15 Sep 2016 12:45:50 -0400 Message-Id: <1473957960-10001-11-git-send-email-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473957960-10001-10-git-send-email-trond.myklebust@primarydata.com> References: <1473957960-10001-1-git-send-email-trond.myklebust@primarydata.com> <1473957960-10001-2-git-send-email-trond.myklebust@primarydata.com> <1473957960-10001-3-git-send-email-trond.myklebust@primarydata.com> <1473957960-10001-4-git-send-email-trond.myklebust@primarydata.com> <1473957960-10001-5-git-send-email-trond.myklebust@primarydata.com> <1473957960-10001-6-git-send-email-trond.myklebust@primarydata.com> <1473957960-10001-7-git-send-email-trond.myklebust@primarydata.com> <1473957960-10001-8-git-send-email-trond.myklebust@primarydata.com> <1473957960-10001-9-git-send-email-trond.myklebust@primarydata.com> <1473957960-10001-10-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 Right now, we're only running TEST/FREE_STATEID on the locks if the open stateid recovery succeeds. The protocol requires us to always do so. The fix would be to move the call to TEST/FREE_STATEID and do it before we attempt open recovery. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 92 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 3c1b8cb7dd95..33ca6d768bd2 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -2486,6 +2486,45 @@ static void nfs41_check_delegation_stateid(struct nfs4_state *state) } /** + * nfs41_check_expired_locks - possibly free a lock stateid + * + * @state: NFSv4 state for an inode + * + * Returns NFS_OK if recovery for this stateid is now finished. + * Otherwise a negative NFS4ERR value is returned. + */ +static int nfs41_check_expired_locks(struct nfs4_state *state) +{ + int status, ret = NFS_OK; + struct nfs4_lock_state *lsp; + struct nfs_server *server = NFS_SERVER(state->inode); + + if (!test_bit(LK_STATE_IN_USE, &state->flags)) + goto out; + list_for_each_entry(lsp, &state->lock_states, ls_locks) { + if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { + struct rpc_cred *cred = lsp->ls_state->owner->so_cred; + + status = nfs41_test_and_free_expired_stateid(server, + &lsp->ls_stateid, + cred); + trace_nfs4_test_lock_stateid(state, lsp, status); + if (status == -NFS4ERR_EXPIRED || + status == -NFS4ERR_BAD_STATEID) { + clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); + if (!recover_lost_locks) + set_bit(NFS_LOCK_LOST, &lsp->ls_flags); + } else if (status != NFS_OK) { + ret = status; + break; + } + } + }; +out: + return ret; +} + +/** * nfs41_check_open_stateid - possibly free an open stateid * * @state: NFSv4 state for an inode @@ -2522,6 +2561,9 @@ static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st int status; nfs41_check_delegation_stateid(state); + status = nfs41_check_expired_locks(state); + if (status != NFS_OK) + return status; status = nfs41_check_open_stateid(state); if (status != NFS_OK) status = nfs4_open_expired(sp, state); @@ -6125,49 +6167,19 @@ out: } #if defined(CONFIG_NFS_V4_1) -/** - * nfs41_check_expired_locks - possibly free a lock stateid - * - * @state: NFSv4 state for an inode - * - * Returns NFS_OK if recovery for this stateid is now finished. - * Otherwise a negative NFS4ERR value is returned. - */ -static int nfs41_check_expired_locks(struct nfs4_state *state) -{ - int status, ret = NFS_OK; - struct nfs4_lock_state *lsp; - struct nfs_server *server = NFS_SERVER(state->inode); - - list_for_each_entry(lsp, &state->lock_states, ls_locks) { - if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { - struct rpc_cred *cred = lsp->ls_state->owner->so_cred; - - status = nfs41_test_and_free_expired_stateid(server, - &lsp->ls_stateid, - cred); - trace_nfs4_test_lock_stateid(state, lsp, status); - if (status == -NFS4ERR_EXPIRED || - status == -NFS4ERR_BAD_STATEID) - clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); - else if (status != NFS_OK) { - ret = status; - break; - } - } - }; - - return ret; -} - static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) { - int status = NFS_OK; + struct nfs4_lock_state *lsp; + int status; - if (test_bit(LK_STATE_IN_USE, &state->flags)) - status = nfs41_check_expired_locks(state); - if (status != NFS_OK) - status = nfs4_lock_expired(state, request); + status = nfs4_set_lock_state(state, request); + if (status != 0) + return status; + lsp = request->fl_u.nfs4_fl.owner; + if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) || + test_bit(NFS_LOCK_LOST, &lsp->ls_flags)) + return 0; + status = nfs4_lock_expired(state, request); return status; } #endif