Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp557698pxj; Thu, 20 May 2021 16:10:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygxGkkTdjeEhaxhISTpZHB7eubDKUCezIyAXD+R3ot07oXEiO4KIkJi2xdLMGYH7SwdOm2 X-Received: by 2002:aa7:dd41:: with SMTP id o1mr7270987edw.361.1621552246186; Thu, 20 May 2021 16:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621552246; cv=none; d=google.com; s=arc-20160816; b=Lo0qGQ2snvloqvPImkPaO+i0nLkPoB8QBSkADhC51MYroXN7D/8VWXJPl3QiHQmebY CbZ8+XWd9BrMVn1TkJmf63FKjka9BfHZICp/qrA/laBxqli12UKC6XWJfBpuY1OmTh3q hZ5QZkktnUjZ31RTaK8sVqTFkIthgh3aeYl+UeaVOp/zWxM08rlUADVoM6yMJtf+dbDQ TpZq7vwLkfrjF1lOORV3sEcRvYc91bQWCCl11fErOB23Oz+V1UXUhm07zD8mz9ddpiAf WpjfD18p9Ysy7k3z/AlJpL139WZUTu2HUF4FosRzRrlOXoJ+fyvzbJz7rwG4GXhM3NaD glSg== 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=idkBSgEl+UuwwxJdLxzm7KmlG4Phmc0W5DBTQnNjB5k=; b=fYuDjoIm+FCeUpQTttJLXozkEl6r1UGC2RaYW617ywWdY5qLhzUfa+Y/F9jomHnJ7L runuyNQIOfkZEjZd2AINmwB15DLaOcJ/AzSTHFlIqrXxip1ee7+WV7f4nKIS0WGzNmAN k4dotsCHBjVTNOKnSI0ROF8RGG+jR0lcgQceA0Yy4kdNWDEVxN+SWbUlyB5Az1tZo0YP vJGuvwdXC0T7G8fJwFv6iPF6iNyl7aC/QNmScgKYZKkmUjKGwlakzFn22/vKlrLnZBfY tq6LKK+RMp9QUZ2UZmtN1O2sFXuHbds4+RHpqCUsDmWcyJhD1l0wqqK7IOaf5KRemQdQ CHWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lnfPjEtp; 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 a15si1712911edr.48.2021.05.20.16.10.21; Thu, 20 May 2021 16:10:46 -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=lnfPjEtp; 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 S241170AbhETLWY (ORCPT + 99 others); Thu, 20 May 2021 07:22:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:57204 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238908AbhETLB7 (ORCPT ); Thu, 20 May 2021 07:01:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CA1FE61D11; Thu, 20 May 2021 10:03:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505038; bh=luXZQP9Rz2/4d6Wl+X/ZCEKV/DqB17C0PCwyfQdo5ng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lnfPjEtp4/7hpP2tXtctmHCvBr81fKuBbFNaiJz0OjuZnmXvgot5akXMITqGFV4tU 3+bz7WfrkhHrqxjyNcF8FQxelHMFHmBrdTjJrQwtRuaMCvswWnAEBaP+WjY8tudauh NSsEcg91PK2+B5xRcysPSjld93IOtWf74eCC2rT8= 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.9 195/240] NFSv4.2: Always flush out writes in nfs42_proc_fallocate() Date: Thu, 20 May 2021 11:23:07 +0200 Message-Id: <20210520092115.210265542@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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 5cda392028ce..7e9fb1119bcf 100644 --- a/fs/nfs/nfs42proc.c +++ b/fs/nfs/nfs42proc.c @@ -56,7 +56,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; @@ -65,9 +66,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) { @@ -76,7 +81,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; } @@ -114,16 +119,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