From patchwork Fri Nov 3 16:53:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10040731 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 554826032D for ; Fri, 3 Nov 2017 16:54:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46A11296F2 for ; Fri, 3 Nov 2017 16:54:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B69B296ED; Fri, 3 Nov 2017 16:54:09 +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 C5B56296ED for ; Fri, 3 Nov 2017 16:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754374AbdKCQyH (ORCPT ); Fri, 3 Nov 2017 12:54:07 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:56673 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756120AbdKCQyG (ORCPT ); Fri, 3 Nov 2017 12:54:06 -0400 Received: by mail-io0-f194.google.com with SMTP id m81so7558246ioi.13 for ; Fri, 03 Nov 2017 09:54:06 -0700 (PDT) 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=hx+hAVn1Bho9D5j4HO96scWAqso7+fZ4f2+vjDPmGW4=; b=Qe06+zlD8fOESxgEZBOnHyS8G8NNo6GgwJ3+KhsDNc+2VG6Td4m+HeLkQO2QHW8zAQ wP5itW0bNFSU/Z+yl8iViTP75Zh2sJArVokhcV6F3h5T44/FkjPmyEXFqg/TLP8E0U2v CwgQGS42a1A1J2cOdJ1dyves4zOyvL/RkVAqgqQOhQjtzkBmbvpXfgufB8bAvU/Tkazy nQJ6ekytn4voaTgv40/8UMLGcVFWzB6xF39aMNiEMPBDJ3sVW27txB6spCoqTHrKI/WA AeYfzAg5a9LzIeYxRgPh8J7wLRLkoZnj4juA9lmcza3nrVJWBlaY2j3LosnRwL4sQbZu whTA== 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=hx+hAVn1Bho9D5j4HO96scWAqso7+fZ4f2+vjDPmGW4=; b=CLXWK8F9LmxgdRFn+l4BxzEoYPIzLKvOeM1/b71yqFUtS8ByA24mhwa83DHi65Sgra p1fGaAUBgP6ahAP2Kd5dLnbf4XBe1Qgp3vJomeu1Ct2JgJ0pzDw9gFHNNsyTx+NqvpAo cX/YAjuuMCPZpt+s2dBPZ/h8JgsPh2c4rjgFhLJMzyRdcBsXeTd2uosBkh3bXVPbR75X MACp/OB3yzKT0p8MpW1IzrZItU84GRosghpH4SRtqLLzTCDMUzUsF4FZYNYRzjejC6SY 1F9BAVY0Rbdv3OM641kVnmPvYo5H2PDQWI/CHP23Ejy6yF/oeg83x4lEWFdYoVUdUDRb +QTA== X-Gm-Message-State: AJaThX54wTz2XPoLdsE7jxG+g2mymE44ovmTfQT3wa2T8xJuCVNgg+eo T0979BPkJxHTC4B7HAHDBg== X-Google-Smtp-Source: ABhQp+TY51WVTYFnsjB/YikKIRuaSO8EVHM6CgMdn8/LkC7pHuoY8OujK9174WTTgobtFOREvSKEcg== X-Received: by 10.107.107.22 with SMTP id g22mr10115840ioc.77.1509728045477; Fri, 03 Nov 2017 09:54:05 -0700 (PDT) Received: from localhost.localdomain (c-68-49-162-121.hsd1.mi.comcast.net. [68.49.162.121]) by smtp.gmail.com with ESMTPSA id j63sm2939862ioe.25.2017.11.03.09.54.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Nov 2017 09:54:04 -0700 (PDT) From: Trond Myklebust To: Benjamin Coddington , Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH v6 06/10] NFSv4: Don't try to CLOSE if the stateid 'other' field has changed Date: Fri, 3 Nov 2017 12:53:50 -0400 Message-Id: <20171103165354.15997-7-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171103165354.15997-6-trond.myklebust@primarydata.com> References: <20171103165354.15997-1-trond.myklebust@primarydata.com> <20171103165354.15997-2-trond.myklebust@primarydata.com> <20171103165354.15997-3-trond.myklebust@primarydata.com> <20171103165354.15997-4-trond.myklebust@primarydata.com> <20171103165354.15997-5-trond.myklebust@primarydata.com> <20171103165354.15997-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 752b18e88266..d5d52f32e301 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; } /*