From patchwork Tue Oct 17 14:46:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 10012213 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 9110160567 for ; Tue, 17 Oct 2017 14:46:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 961F828932 for ; Tue, 17 Oct 2017 14:46:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B14228938; Tue, 17 Oct 2017 14:46:19 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 31A0D28932 for ; Tue, 17 Oct 2017 14:46:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932493AbdJQOqR (ORCPT ); Tue, 17 Oct 2017 10:46:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52412 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936049AbdJQOqQ (ORCPT ); Tue, 17 Oct 2017 10:46:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 524AC4ACA5; Tue, 17 Oct 2017 14:46:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 524AC4ACA5 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=bcodding@redhat.com Received: from bcodding.csb (ovpn-120-157.rdu2.redhat.com [10.10.120.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 152C27800D; Tue, 17 Oct 2017 14:46:16 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id 74ECD10C3115; Tue, 17 Oct 2017 10:46:15 -0400 (EDT) From: Benjamin Coddington To: Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 3/3] NFSv4.1: Detect and retry after OPEN and CLOSE/DOWNGRADE race Date: Tue, 17 Oct 2017 10:46:15 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 17 Oct 2017 14:46:16 +0000 (UTC) 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 client issues two simultaneous OPEN calls, and the response to the first OPEN call (sequence id 1) is delayed before updating the nfs4_state, then the client's nfs4_state can transition through a complete lifecycle of OPEN (state sequence id 2), and CLOSE (state sequence id 3). When the first OPEN is finally processed, the nfs4_state is incorrectly transitioned back to NFS_OPEN_STATE for the first OPEN (sequence id 1). Subsequent calls to LOCK or CLOSE will receive NFS4ERR_BAD_STATEID, and trigger state recovery. Fix this by passing back the result of need_update_open_stateid() to the open() path, with the result to try again if the OPEN's stateid should not be updated. Signed-off-by: Benjamin Coddington --- fs/nfs/nfs4proc.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 40e431ea1bdc..632136bfd3b3 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1352,9 +1352,9 @@ static void nfs_test_and_clear_all_open_stateid(struct nfs4_state *state) static bool nfs_need_update_open_stateid(struct nfs4_state *state, const nfs4_stateid *stateid, nfs4_stateid *freeme) { - if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) - return true; if (!nfs4_stateid_match_other(stateid, &state->open_stateid)) { + if (test_and_set_bit(NFS_OPEN_STATE, &state->flags) == 0) + return true; nfs4_stateid_copy(freeme, &state->open_stateid); nfs_test_and_clear_all_open_stateid(state); return true; @@ -1468,7 +1468,8 @@ static int update_open_stateid(struct nfs4_state *state, ret = 1; } - if (open_stateid) { + if (open_stateid && + nfs_need_update_open_stateid(state, open_stateid, &freeme)) { switch (fmode) { case FMODE_READ: set_bit(NFS_O_RDONLY_STATE, &state->flags); @@ -1479,11 +1480,10 @@ static int update_open_stateid(struct nfs4_state *state, case FMODE_READ|FMODE_WRITE: set_bit(NFS_O_RDWR_STATE, &state->flags); } - if (nfs_need_update_open_stateid(state, open_stateid, &freeme)) { - if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) - nfs4_stateid_copy(&state->stateid, open_stateid); - nfs4_stateid_copy(&state->open_stateid, open_stateid); - } + + if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) + nfs4_stateid_copy(&state->stateid, open_stateid); + nfs4_stateid_copy(&state->open_stateid, open_stateid); ret = 1; } @@ -1675,8 +1675,12 @@ _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) goto err_put_inode; if (data->o_res.delegation_type != 0) nfs4_opendata_check_deleg(data, state); - update_open_stateid(state, &data->o_res.stateid, NULL, - data->o_arg.fmode); + ret = -EAGAIN; + if (!update_open_stateid(state, &data->o_res.stateid, NULL, + data->o_arg.fmode)) { + nfs4_put_open_state(state); + goto err_put_inode; + } iput(inode); out: nfs_release_seqid(data->o_arg.seqid);