From patchwork Mon Nov 6 15:27:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10043707 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 2B03E60247 for ; Mon, 6 Nov 2017 15:27:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 139C329EA2 for ; Mon, 6 Nov 2017 15:27:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08BF329EA6; Mon, 6 Nov 2017 15:27:48 +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 97B5E29EA2 for ; Mon, 6 Nov 2017 15:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753706AbdKFP1q (ORCPT ); Mon, 6 Nov 2017 10:27:46 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:45795 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751992AbdKFP1p (ORCPT ); Mon, 6 Nov 2017 10:27:45 -0500 Received: by mail-it0-f67.google.com with SMTP id n195so5743157itg.0 for ; Mon, 06 Nov 2017 07:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3zlJ2lu8aGal9L+HwHTZpYmz9guKn5ZsoTshzya5iuY=; b=Th+vNptKDN7a91SqFu7tdhlPJRiur+CiYeVzyMT/KaLj92C2fqslw07CMpUTwZyk6x 3uOjTjBa9icZurrrz6crR/8Z1wjuseZP4mepw157CFHepB5JxACf0MrgVvzicryoObOp bpBWObBaXpUJnAjBNYwzFLjF7cp8hjS4AjNjXgxvFkIgmrrcHg4b7df2hR27sEqbcYjR GrjwgNNqUOCmpqozRnu2h8EXORwo9575zNzmYtQvkY82z+HRFxxjfedu5Jzv9csmbq7G A0wscWzSW5+HuvcDEEnEV+ZmUXf4jzC9F2+Vu2kIfF97uaS709sMGf8fMy8oqCC+FLjs aDKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=3zlJ2lu8aGal9L+HwHTZpYmz9guKn5ZsoTshzya5iuY=; b=BdR+bEnZgpzjWdsb1slEJZcANwPdDV02LBcLPxTmRInDAr6p4ooP9XH+wcihNBlbhc UMpcieWKmkJm1zzzfZNze2YU/oPTsP7z/M82CZvOCvbxZYyBq8MMc2bYpAMs+qcihoIg 9Bc1S/bMiVjmTBX4YeCMDKAnuIEI4j+sOkjCz+aF52VCvvr1qTP8RsBuMjAPRhnen3BJ IAqjU+vilx3Jxq/iMBboHk4zxnyAUxbWtyJtFUXvXYnaAehwtiqaLn4YDHJIKhwD4uS5 xftU/CtCuogdj6xWXSaTJ4+fBwWswyWGRMxNfnicVGJ1TDTj1lGECQJoEpZKXThBsUdB hpZQ== X-Gm-Message-State: AJaThX4GwsT0/EGI4Sq2f23WKpvvcWIMNZUW8ecvOeoN0PKNuq04QSMK 5b7s0MuB+w4rbx/xiM3rPjiBS9Q= X-Google-Smtp-Source: ABhQp+Q+KwfIpX7DHAPVHVLLK7tUDvL6/RZwFHyot7riz3+l8tPeruXBHKWq/aatw1w4WLjFUEg+NA== X-Received: by 10.36.65.84 with SMTP id x81mr9883334ita.61.1509982064840; Mon, 06 Nov 2017 07:27:44 -0800 (PST) Received: from localhost.localdomain (c-68-49-162-121.hsd1.mi.comcast.net. [68.49.162.121]) by smtp.gmail.com with ESMTPSA id p10sm5807007ioe.19.2017.11.06.07.27.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Nov 2017 07:27:43 -0800 (PST) From: Trond Myklebust To: Benjamin Coddington , Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH v7 06/10] NFSv4: Don't try to CLOSE if the stateid 'other' field has changed Date: Mon, 6 Nov 2017 10:27:22 -0500 Message-Id: <20171106152726.13755-7-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171106152726.13755-6-trond.myklebust@primarydata.com> References: <20171106152726.13755-1-trond.myklebust@primarydata.com> <20171106152726.13755-2-trond.myklebust@primarydata.com> <20171106152726.13755-3-trond.myklebust@primarydata.com> <20171106152726.13755-4-trond.myklebust@primarydata.com> <20171106152726.13755-5-trond.myklebust@primarydata.com> <20171106152726.13755-6-trond.myklebust@primarydata.com> MIME-Version: 1.0 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 If the stateid is no longer recognised on the server, either due to a restart, or due to a competing CLOSE call, then we do not have to retry. Any open contexts that triggered a reopen of the file, will also act as triggers for any CLOSE for the updated stateids. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4_fs.h | 2 ++ fs/nfs/nfs4proc.c | 14 ++++---------- fs/nfs/nfs4state.c | 9 +++++++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index 84c3adc6bf96..cdab6e8dbacc 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -463,6 +463,8 @@ extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t, struct rpc_cred **); extern bool nfs4_refresh_open_stateid(nfs4_stateid *dst, struct nfs4_state *state); +extern bool nfs4_copy_open_stateid(nfs4_stateid *dst, + struct nfs4_state *state); extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask); extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task); diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 153e34c5b6e9..fe4a855dc965 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -3214,14 +3214,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data) task->tk_msg.rpc_cred); /* Fallthrough */ case -NFS4ERR_BAD_STATEID: - if (!nfs4_stateid_match(&calldata->arg.stateid, - &state->open_stateid)) { - rpc_restart_call_prepare(task); - goto out_release; - } - if (calldata->arg.fmode == 0) - break; - /* Fallthrough */ + break; default: if (nfs4_async_handle_error(task, server, state, NULL) == -EAGAIN) { rpc_restart_call_prepare(task); @@ -3253,7 +3246,6 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); - nfs4_stateid_copy(&calldata->arg.stateid, &state->open_stateid); /* Calculate the change in open mode */ calldata->arg.fmode = 0; if (state->n_rdwr == 0) { @@ -3271,7 +3263,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; if (!nfs4_valid_open_stateid(state) || - test_bit(NFS_OPEN_STATE, &state->flags) == 0) + !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) call_close = 0; spin_unlock(&state->owner->so_lock); @@ -3365,6 +3357,8 @@ int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait) calldata->inode = state->inode; calldata->state = state; calldata->arg.fh = NFS_FH(state->inode); + if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) + goto out_free_calldata; /* Serialization for the sequence id */ alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index ccf3b4e03997..4a6f77880992 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -1002,18 +1002,23 @@ bool nfs4_refresh_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) return ret; } -static void nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) +bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) { + bool ret; const nfs4_stateid *src; int seq; do { + ret = false; src = &zero_stateid; seq = read_seqbegin(&state->seqlock); - if (test_bit(NFS_OPEN_STATE, &state->flags)) + if (test_bit(NFS_OPEN_STATE, &state->flags)) { src = &state->open_stateid; + ret = true; + } nfs4_stateid_copy(dst, src); } while (read_seqretry(&state->seqlock, seq)); + return ret; } /*