Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp460410pxj; Thu, 20 May 2021 13:29:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLLf0mZeE/sCjnWKq75Y2UN657UKo96GYfkT5ghV5sWT0ZLelNPNnrG+rbHiS/dZLvmg3J X-Received: by 2002:a02:5289:: with SMTP id d131mr8465297jab.121.1621542547974; Thu, 20 May 2021 13:29:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621542547; cv=none; d=google.com; s=arc-20160816; b=ioQUSAHJxc9XV97DLtSHu58uXcBQCgVsk3Bve0gXuITLHlrOGQnJWgRMi+o7idcAVG /QF12HXtkpLOY0pSt+8EwDQ1yQBIs7LXGwQ4VuthDvyEkiRGrA8QXbmM4TBspwD0rltg vbV5jb5nNVy0Jmrc2vBzcUwA+PHExJAIYM5i8UZnx9GkSKsdDELBQpGma8lk5To2IYf8 HgfrntLF50kRWmnNc3QV9KU0+qBbat/HWymUasvDSxEt1ogKEJscqlmrOR4s8fI3fGrC i2LAFJHc/XOwyBnH9NVFi76h3AaDu2Hfw9wvTUCdjUpHYJjZkUvFq1BdpiioBdBTEQpM zDsw== 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=mAtfvWBpKBiwKGTTRZnpGD8diFBnpCOgNWhF4v7jHP8=; b=rhLEFdTCx9t5bDYyV5k4LXMuyr1ILGiWhNDW3t/Zg2c2zJjUOX8QaSYPND5IUvIwZf hARiATWvNBAWQ19m08bjj6fo89kDsBf3Z8v/kyZN57fOHU+hjXV7SnI7KOrGXybdzASH qCHyzzMcRqytwqA8AD4IACw7mY50NezJw4FJkqfAwKQy8R5lZCqUICXttb2nVHPHdND7 UQNDMawCf50xHqV6xUz9PMZ57Q3CBuwN+mStdUN+UiuH1dW+8fi3IDEQ5UGKKBt/7iSe Wxq6ukH0V13x2ihHWU11LI01uGYkFSUY/APZH/3Tvp2T0KsqOp4Wm68VgNAEo1iJPEjP HUCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oW1ZXdHo; 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 h11si3559118ila.129.2021.05.20.13.28.55; Thu, 20 May 2021 13:29:07 -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=oW1ZXdHo; 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 S238742AbhETKxX (ORCPT + 99 others); Thu, 20 May 2021 06:53:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:39842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237360AbhETKhu (ORCPT ); Thu, 20 May 2021 06:37:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 194966135C; Thu, 20 May 2021 09:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504477; bh=F9UfUe/Ra93WaKN7aBfDR0M930Ya3gI29+VUSSWwJak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oW1ZXdHoHlzZAe+CujupXhFdommki6BB0R4eucIVBaug+bGmagKDB+XXg5OnHpPKe 8Cnxy/bFnOyrDx7RuNHhkoI1d922FEP4M8imZYN4ucPD0mh+hnUvhWQJua8jMzBd8k KQrEFiCI5e0OMwfClUvbC57DpEvupe2gGs9NaaFY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , Sasha Levin Subject: [PATCH 4.14 263/323] NFSv4.2: Always flush out writes in nfs42_proc_fallocate() Date: Thu, 20 May 2021 11:22:35 +0200 Message-Id: <20210520092129.233298425@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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: Trond Myklebust [ Upstream commit 99f23783224355e7022ceea9b8d9f62c0fd01bd8 ] Whether we're allocating or delallocating space, we should flush out the pending writes in order to avoid races with attribute updates. Fixes: 1e564d3dbd68 ("NFSv4.2: Fix a race in nfs42_proc_deallocate()") Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/nfs42proc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c index 9c374441f660..1c4361aed415 100644 --- a/fs/nfs/nfs42proc.c +++ b/fs/nfs/nfs42proc.c @@ -58,7 +58,8 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, loff_t offset, loff_t len) { - struct nfs_server *server = NFS_SERVER(file_inode(filep)); + struct inode *inode = file_inode(filep); + struct nfs_server *server = NFS_SERVER(inode); struct nfs4_exception exception = { }; struct nfs_lock_context *lock; int err; @@ -67,9 +68,13 @@ static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, if (IS_ERR(lock)) return PTR_ERR(lock); - exception.inode = file_inode(filep); + exception.inode = inode; exception.state = lock->open_context->state; + err = nfs_sync_inode(inode); + if (err) + goto out; + do { err = _nfs42_proc_fallocate(msg, filep, lock, offset, len); if (err == -ENOTSUPP) { @@ -78,7 +83,7 @@ static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, } err = nfs4_handle_exception(server, err, &exception); } while (exception.retry); - +out: nfs_put_lock_context(lock); return err; } @@ -116,16 +121,13 @@ int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len) return -EOPNOTSUPP; inode_lock(inode); - err = nfs_sync_inode(inode); - if (err) - goto out_unlock; err = nfs42_proc_fallocate(&msg, filep, offset, len); if (err == 0) truncate_pagecache_range(inode, offset, (offset + len) -1); if (err == -EOPNOTSUPP) NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE; -out_unlock: + inode_unlock(inode); return err; } -- 2.30.2