Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1851863pxb; Mon, 8 Mar 2021 07:53:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2Cud00OkLIAYJ+3pZsnj7P8QWC4Q9RouvbBg41WYNTQL21d/qkUnsgTD4UQd3xHT91mXk X-Received: by 2002:a17:906:2c44:: with SMTP id f4mr3488258ejh.508.1615218837973; Mon, 08 Mar 2021 07:53:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615218837; cv=none; d=google.com; s=arc-20160816; b=s+Mf8JuZ55CZXOnRoguHiqejcK+wKH4C2yK+m7E8gfoGNVjCsdj5rZV79D1qX8RHMZ HisdjJQqBOdWD/wS45WLF0EUgv79IUQmDXkRCqflydTzZeyCiRT9eA3nlRuv9YUr+NUH k2PpqKf6oHVeOOK3klLk7pfwhbPX5sd35ZYzHKnTS9yxz3P3xNLcxcUNgggFpZ7+aqvH CMw2+yfOg+Uju1m+oAHsvZqc5aqa2LI3DwQbrGiDNgwL69nogXrx7eT0rd10lRH8Ag2j +8rgkCOTgS3Op0PJ/ltMm43+AiZU9PTPrHWXKbvyTQNMT292mMmNwtkRiNR7e7u2Vz4y QefA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=S7t/9AyIqSMCz/QZkxiMpvUUWEWQQwRvlN5H/lRWnqI=; b=O07RCM2p4UHbraqvZyTROe9sSvdcX9dq/VRTp6wIIjA8V9Q8eqDsQTz4qrT5MubaKM HnJVlK9Ajq55FXuK9x1iEleRAL3eVa4dcp/B9wnyuSY0l826CXs1GPfFj9YRwXynmLJP rgGqlOhMypgUTc/DXWn9Et4Rm0Rwj259UPESn/m0z2jerDEiTMtRpzMF/hrgqZVec7Ul MK+nyHEtJfRF1d7lRhBUHtenjPxuPZDud62o9aYJ4zgRPHZtkUSWKI/wVwKMXHvTQ9LD vIF4XFIXVGB3UdjNR5RNmRHbFYnfUQkO+ON+B4yXRrNIFpIQK/qteliAXUTr4WHkHs8u Cnmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b=XBxjJPRu; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v5si8218955edi.550.2021.03.08.07.53.35; Mon, 08 Mar 2021 07:53:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b=XBxjJPRu; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229737AbhCHPxB (ORCPT + 99 others); Mon, 8 Mar 2021 10:53:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229627AbhCHPwa (ORCPT ); Mon, 8 Mar 2021 10:52:30 -0500 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D232C06174A for ; Mon, 8 Mar 2021 07:52:30 -0800 (PST) Received: by fieldses.org (Postfix, from userid 2815) id F115323D8; Mon, 8 Mar 2021 10:52:29 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org F115323D8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1615218749; bh=S7t/9AyIqSMCz/QZkxiMpvUUWEWQQwRvlN5H/lRWnqI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XBxjJPRusyAByLAqlnYSFjvAVILdsH66tPrj+//ebMDbFCqA2jkiI/Q6o2sCGaW/L DpHyhwTKAqyDZZdbupSHxkfDG03JyzsAeLJDp5464zDTycZf/8Bd/18VoeGikFnUBq sn8eV2gdlOztPxjf7uF5YkmT6pgF0kqg6XW3EYKg= Date: Mon, 8 Mar 2021 10:52:29 -0500 From: "J. Bruce Fields" To: Chuck Lever Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/2] Revert "nfsd4: a client's own opens needn't prevent delegations" Message-ID: <20210308155229.GD7284@fieldses.org> References: <20210308155151.GC7284@fieldses.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210308155151.GC7284@fieldses.org> User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: "J. Bruce Fields" This reverts commit 94415b06eb8aed13481646026dc995f04a3a534a. That commit claimed to allow a client to get a read delegation when it was the only writer. Actually it allowed a client to get a read delegation when *any* client has a write open! The main problem is that it's depending on nfs4_clnt_odstate structures that are actually only maintained for pnfs exports. This causes clients to miss writes performed by other clients, even when there have been intervening closes and opens, violating close-to-open cache consistency. We can do this a different way, but first we should just revert this. I've added pynfs 4.1 test DELEG19 to test for this, as I should have done originally! Cc: stable@vger.kernel.org Reported-by: Timo Rothenpieler Signed-off-by: J. Bruce Fields --- fs/locks.c | 3 --- fs/nfsd/nfs4state.c | 54 ++++++++++++--------------------------------- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 99ca97e81b7a..6125d2de39b8 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1808,9 +1808,6 @@ check_conflicting_open(struct file *filp, const long arg, int flags) if (flags & FL_LAYOUT) return 0; - if (flags & FL_DELEG) - /* We leave these checks to the caller. */ - return 0; if (arg == F_RDLCK) return inode_is_open_for_write(inode) ? -EAGAIN : 0; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 408e2c4db926..27983a50435e 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4940,32 +4940,6 @@ static struct file_lock *nfs4_alloc_init_lease(struct nfs4_delegation *dp, return fl; } -static int nfsd4_check_conflicting_opens(struct nfs4_client *clp, - struct nfs4_file *fp) -{ - struct nfs4_clnt_odstate *co; - struct file *f = fp->fi_deleg_file->nf_file; - struct inode *ino = locks_inode(f); - int writes = atomic_read(&ino->i_writecount); - - if (fp->fi_fds[O_WRONLY]) - writes--; - if (fp->fi_fds[O_RDWR]) - writes--; - WARN_ON_ONCE(writes < 0); - if (writes > 0) - return -EAGAIN; - spin_lock(&fp->fi_lock); - list_for_each_entry(co, &fp->fi_clnt_odstate, co_perfile) { - if (co->co_client != clp) { - spin_unlock(&fp->fi_lock); - return -EAGAIN; - } - } - spin_unlock(&fp->fi_lock); - return 0; -} - static struct nfs4_delegation * nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh, struct nfs4_file *fp, struct nfs4_clnt_odstate *odstate) @@ -4985,12 +4959,9 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh, nf = find_readable_file(fp); if (!nf) { - /* - * We probably could attempt another open and get a read - * delegation, but for now, don't bother until the - * client actually sends us one. - */ - return ERR_PTR(-EAGAIN); + /* We should always have a readable file here */ + WARN_ON_ONCE(1); + return ERR_PTR(-EBADF); } spin_lock(&state_lock); spin_lock(&fp->fi_lock); @@ -5020,19 +4991,11 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh, if (!fl) goto out_clnt_odstate; - status = nfsd4_check_conflicting_opens(clp, fp); - if (status) { - locks_free_lock(fl); - goto out_clnt_odstate; - } status = vfs_setlease(fp->fi_deleg_file->nf_file, fl->fl_type, &fl, NULL); if (fl) locks_free_lock(fl); if (status) goto out_clnt_odstate; - status = nfsd4_check_conflicting_opens(clp, fp); - if (status) - goto out_clnt_odstate; spin_lock(&state_lock); spin_lock(&fp->fi_lock); @@ -5114,6 +5077,17 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, goto out_no_deleg; if (!cb_up || !(oo->oo_flags & NFS4_OO_CONFIRMED)) goto out_no_deleg; + /* + * Also, if the file was opened for write or + * create, there's a good chance the client's + * about to write to it, resulting in an + * immediate recall (since we don't support + * write delegations): + */ + if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) + goto out_no_deleg; + if (open->op_create == NFS4_OPEN_CREATE) + goto out_no_deleg; break; default: goto out_no_deleg; -- 2.29.2