Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1348490pxf; Fri, 19 Mar 2021 05:24:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkl9kfwpSf8jcbAuiSr+nuTlJyEs3Yg5WVXF048bwjnerYZxV1dF8cVWGnXwiHsxkKl7Ti X-Received: by 2002:a17:906:5450:: with SMTP id d16mr4079574ejp.274.1616156680434; Fri, 19 Mar 2021 05:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616156680; cv=none; d=google.com; s=arc-20160816; b=ZJRMaaRpqsAVn8Watl5J+CkkASFWTzRXl0HXlorOvLE6v87Aqj9HOWH1NtXhFc98oh JwTWs775pKwCVO8XITpKk4Y8/gJy6bFvv5XBRl0lNpicNR1EiGxAi14BtWo+6cPfHW/g +BBifLPNbe03X916RvUYXYRV77NwUq9ro7ZJdnTnqYviLzmqgGnlBkXq2FFKSjMtSgle M8lBsltx/r/iv01wMyeVQfiCR2mQkGeXD+itj5aWN1x0K/Y5DYaUb9NxlbR+TqOFjKLW qB5ISLqtFe0qXt3d6DpZJzpmDxtBVKJrr3pHSpftnII/sd2MB20HKtxo1ID60IjFVHLr MDHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/X8v1m0tPo3JTJu4OsaOwnfK/zzOw1HZ3uULl+aUftY=; b=hpYeXgfQVUxlvLZc9QoxFZ6b63BTlwoKgMekOCwMwJRD84LvUSTef9YismIQen5QxD DVE/N4iaIwMDavEVNGMUq0Gg3MKGwb8PvnCZOVRWNbA9ZY9BVIWppJy56vMZmLuXfsE+ V3foPsml4IS3o4kodDJrie0IjmO+o49SGek/Th1E/kQKVnbWDVp9iXm+rh4qgllRdp8A e4qLPgRqi+cO0z4XAYqbKf7sJRAs4+AO/56K3BK1V4QnnxBd6JyDU8OmJX6dTNbc+Ksy D/Cy2KFScf1SVlLnCuJtyve7Axjn6ZaGvDde5YyMrQgd7kijdzC9S08C1Smu2M9pPAAI YdiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wf9v077u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id di21si3863746edb.524.2021.03.19.05.24.18; Fri, 19 Mar 2021 05:24:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=wf9v077u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbhCSMU0 (ORCPT + 99 others); Fri, 19 Mar 2021 08:20:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:57728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbhCSMT5 (ORCPT ); Fri, 19 Mar 2021 08:19:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D958C64F6C; Fri, 19 Mar 2021 12:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616156397; bh=tA2R1Xyov1vbbxO8oGGXj5HDDCZK3v8CM/aY/QGS8Y4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wf9v077u7OHaqEcGN3c2okCb2kcfugeJlakzZK8vXt/rcEUPIIcgXAy2cHe7xSoGr 5nGQc0ExBvcYubmRq2ZrDnIIX8LfDnUm9zTjtH16NZLnjjWVefhx2PP6utFsZks3bL hj2fYspcdD9Efus1L4CwvskW+qnYRkvKMggS9Otw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Timo Rothenpieler , "J. Bruce Fields" , Chuck Lever Subject: [PATCH 5.10 11/13] Revert "nfsd4: a clients own opens neednt prevent delegations" Date: Fri, 19 Mar 2021 13:19:08 +0100 Message-Id: <20210319121745.473563900@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210319121745.112612545@linuxfoundation.org> References: <20210319121745.112612545@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: J. Bruce Fields commit 6ee65a773096ab3f39d9b00311ac983be5bdeb7c upstream. 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 Signed-off-by: Chuck Lever Signed-off-by: Greg Kroah-Hartman --- fs/locks.c | 3 -- fs/nfsd/nfs4state.c | 54 +++++++++++++--------------------------------------- 2 files changed, 14 insertions(+), 43 deletions(-) --- a/fs/locks.c +++ b/fs/locks.c @@ -1808,9 +1808,6 @@ check_conflicting_open(struct file *filp 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; --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4945,32 +4945,6 @@ static struct file_lock *nfs4_alloc_init 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) @@ -4990,12 +4964,9 @@ nfs4_set_delegation(struct nfs4_client * 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); @@ -5025,19 +4996,11 @@ nfs4_set_delegation(struct nfs4_client * 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); @@ -5119,6 +5082,17 @@ nfs4_open_delegation(struct svc_fh *fh, 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;