Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3032949pxj; Mon, 17 May 2021 16:04:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyF7WsXHxKyA9mYFi8VuM/H8w0AYLwKLT1lD4LLcHOdB43VSLB5iBBS9WQPbhjYR5z3ShWR X-Received: by 2002:a17:906:6b96:: with SMTP id l22mr2432199ejr.456.1621292652769; Mon, 17 May 2021 16:04:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621292652; cv=none; d=google.com; s=arc-20160816; b=yjQigqaAIKDvC3nFdOyHlJbR8+M6HNNfcZoHCnjc/FCZtD+cop6Ksh2LQoKVC7Vjm+ 1vTeS6jD3izB7Xjv1lzyN/bGcQPoT5Ics56DKOQE6K+ic/IYUSKtAdO+Ir9Ne+Og8QtN B4TGI5LYTLBQW9CLn0ViXMXBG0UMSjO6CgVsuM9A73lNTqCXiF4ZLrrWjICbitGjTyJx TQeWsXRN11lPJFhiPrBjv+oFKEuGzIzRJt5+vZ99UIRjzhVlAwvkld+A4eSbLFrRsmN8 FDGwGo2UY1rgInLIqmxss6uClhwP8Va7JgbbIiJYNMYQhXrra+u3k2JmOWL8+XY9mgf9 g/Og== 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=AdxRVAP3vEGX4KNRcmDO/C9BlwLCfHC4TAtCR8sJaLw=; b=iAOPv9LnLbuUBK1XcjNNyGh31wRk7rcfUVyTBrBBuW5Yh5RYrYp4ju9OVfTnmWat+N 9ab9HNP0Xe0Ux55r3TvaKgZvUquezIBKwwbixB5lQ/MeKciyGe1ebYEuUkAJqUiJH/Zi O/fHzShGemAseMe5V9IWdehYLceroAcDhkQwkJO/NgRXlocyEp8JNNP7fKmthWxseAF8 Kb1Ho2bZGlpxS6EzfY4gynkoPvxmbgdOLm83YkW7PQA5V9QxwVWcmgEZGKt1IC21CN55 t/3Z8tArk0VCftdkN8lM9O2sW4QF5mJAxdgskroOdTJywmpF1Aetf2Ry7mWHpyYEOtgV z/hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x6ZM3bx+; 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 hb18si16037969ejc.159.2021.05.17.16.03.11; Mon, 17 May 2021 16:04:12 -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=x6ZM3bx+; 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 S237188AbhEQOTL (ORCPT + 99 others); Mon, 17 May 2021 10:19:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:46662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238876AbhEQOQr (ORCPT ); Mon, 17 May 2021 10:16:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CCFC361415; Mon, 17 May 2021 14:09:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260592; bh=U4emeyNm6/ZLk4LQWXeu8xQ+maCMCoPMomqWE8L8/1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x6ZM3bx+SDkv8zm/t790dEt+sjT/TX1N4Gw1nT14RMbYxGZcJnyGc92uvB6Ll3Fmw 4hKZSV9VKh7pNn0K12yCzb4atZ95uw5tVqlwLwDFLtVz7ZSJ/f4VrmX3KL3mwLMqiN Mx/7pqL1V8OLwC2MfbuSWQAU+fUmlFsooXShgL/E= 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.12 152/363] NFSv4.2: Always flush out writes in nfs42_proc_fallocate() Date: Mon, 17 May 2021 16:00:18 +0200 Message-Id: <20210517140307.752253403@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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 597005bc8a05..704a5246ccb5 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