Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp274388pxj; Tue, 18 May 2021 03:07:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoLZ/rCqiTUy+0xsgCG+Dy61ec0ESC9EtPscxAvI6pd1OFx3vPfuwFvA3Ov6aoR8JrXxT3 X-Received: by 2002:a5e:a50c:: with SMTP id 12mr3629069iog.206.1621332470599; Tue, 18 May 2021 03:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621332470; cv=none; d=google.com; s=arc-20160816; b=ODfrqdt6v8mWQHXyb1amo0CkaFDaB1aHsgr7ewm7M5rQft+a12m1JQYG+vQp/Y+P4d jgH0joJVRXqp+t1Q+1tAKL8hC3o1/ONYj9oxkShjYgXGcyPsSl+MiJYItwVEgh68bsc8 A7bDVnsE0Caz9V5e97XBigRFPkWh7naI0b9FfJcgTUpmXwzGpCF6heF3M0gy6Cj3wpav QJu7cLFVPH5iqJJ21fRn01WvN6F63ykhg1V1mGNmSjsTTuoZwoQInCWBoq2OxXi5WCIg tf2oHbNOQf9Qzc4SRG6KluvJ9vHmTnPCvpiRmgDJcbUOiN/KrjXADbLvRQNunehvfRff 0xfw== 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=zwo4C+LG8u1ZPaX/4OixoQsurxmjA2vYGKOY1SxME5Q=; b=LeE2pe3ucLePk8adQMjb79v+CVZhpevOh+Epl+tUqz5N6Zcts93dfSsBIBV2Ew+aaV vrBjLmL4PzsIoBX5lMmr5K4HtOds1ekkb26B5h2Pj0SXnHU12O3J/THsWsvGnXkdvL8S CKBsRAotop1smIpw8n4eXubuB6zwdpL1xuzzvoy9K+l+uj7yTyk76+OSCxEoL8OkGKu2 6s8c9jUvltZYH3pd3Sv5r4ubJmRYftGkEspCPIEVe84JNoMUgCOld653sUzzkpR2f6x2 qNZhF3UiE4mj/QhDWtdBKoJRn9X3Dn0ri5MixD2xIO8jPKxgd4UTXsLIrIiBnezPTztx 1Uyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1w4IrNsz; 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 y10si7069735jak.112.2021.05.18.03.07.25; Tue, 18 May 2021 03:07:50 -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=1w4IrNsz; 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 S241892AbhEQPK6 (ORCPT + 99 others); Mon, 17 May 2021 11:10:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:58730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242180AbhEQPB4 (ORCPT ); Mon, 17 May 2021 11:01:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 619086157F; Mon, 17 May 2021 14:27:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261640; bh=PzD/gdhNJwfVglHlwU8mL86SFUYXfN16H85EldeYMJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1w4IrNsz2B4X+auMzoHf0H+oYCeEgHBlp8gptqy3zgf3xd0kW5YPL7Xfaxhi80/H3 BuIO8LcHTYbtq+ZGnZcFlR38s9oO31CX7l6E96+zffu2xkTOx0Rg9gFszba882r02K ZxShfU7zr9yt/iVw+ffqIUHrusbqQw8viIsAPLdQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , Sasha Levin Subject: [PATCH 5.11 139/329] NFSv4.2: Always flush out writes in nfs42_proc_fallocate() Date: Mon, 17 May 2021 16:00:50 +0200 Message-Id: <20210517140306.813273853@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@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 1edce2d7ecef..7add6332016a 100644 --- a/fs/nfs/nfs42proc.c +++ b/fs/nfs/nfs42proc.c @@ -90,7 +90,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; @@ -99,9 +100,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) { @@ -110,7 +115,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; } @@ -148,16 +153,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