Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3037955pxj; Mon, 17 May 2021 16:10:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpp2cwh5ZmqtYwdhE+UZEr52N9zJBHNh+sxp7bTG+4asej5wK2vANThuz1zDNaY0lF8gt3 X-Received: by 2002:a02:a10f:: with SMTP id f15mr2370297jag.124.1621293037848; Mon, 17 May 2021 16:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621293037; cv=none; d=google.com; s=arc-20160816; b=oNqjrAw8nDlpsAktehsh05KGOnmK197WFUYLizN753aPvCC5e69OohDd69698KrL7F Zqf6ZSzAIpd/Cz6vAYMwduDIzzwvHMvRmwXlAgGLnJk3yvfFBIq4nEFscWu5AFMS86qJ JYJIwJuJ/pxiOBhpPjxFYAl+66+Nd0D5m09725pX2RsR6Lmc7a3SoebuBf8ph32ROsz5 VDJe4Wo5zLC+0XFyNMuR8I+ZH+7ivZuCvklDF8oIe13DaDyGUt2YWMqpz0ceN13eZ7tG 8pHqPwVoldfEnAS3r55jkQlz2Kw0GB61hDaxrStznyW8MUcJZcvQIuzVdFb7LXULwckv IuYg== 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=CGlN+tWPgbyIases9gJP5O+oahJKGOPn8aNiYI54M4k=; b=npoyLBn/xX2iAnwoxNJV9Td5+GqZyHN4uGrSc0+5t4XYcG9m2ioXjBrCQDFYGJdiBa /cgLclfMu3a7iZVIub6qfoddhEY1UHlQL3FhFiFB+A0jTS5Sm9syOihkZGlzaPJTCZyU bu5Ea7EXuRaiNj3Ok8eKpCzmbhkfKD879jdYob7ikQuqIDwxd4cRkEGcTZQLlFzt7v0T YB3sWVIIXMP/EM2J8CNZGJ93U+EjB78t22IRTqCz/hLCsxfybN3dp3+ft1Q5rr9baX43 9TA3oeV7026LETsF4Z8+3eF1+hOGEV82G8AZcBBDYIIcQvd++rnRCKIbNdl5kJv7wVck 9j3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AYSmlsEx; 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 k21si3674090jad.9.2021.05.17.16.10.17; Mon, 17 May 2021 16:10:37 -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=AYSmlsEx; 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 S238773AbhEQOV3 (ORCPT + 99 others); Mon, 17 May 2021 10:21:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:33820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236996AbhEQOSH (ORCPT ); Mon, 17 May 2021 10:18:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2715761360; Mon, 17 May 2021 14:10:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260618; bh=tk0iYPFDw5h/n0cZ+mlXZmyCzH8dxrX7cPlTfjNce7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AYSmlsExGMM47A6aYm7NVcUigom4LzwzuIwkddHcHREiY3g9Qntpm/APK/N/Dgra1 4WwGSqM/+bsxzGNG5alyRlIrUPljMWjXHTWAhsdU4+8z5XrxZ4AL98bACMuq8uHMnt sxAQgMh30pGW7xJ2UAKLIgM39zLtRYaF2KNBktAE= 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 163/363] NFSv42: Copy offload should update the file size when appropriate Date: Mon, 17 May 2021 16:00:29 +0200 Message-Id: <20210517140308.114834232@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 94d202d5ca39d0eb757d16ef2624b013fb64f64d ] If the result of a copy offload or clone operation is to grow the destination file size, then we should update it. The reason is that when a client holds a delegation, it is authoritative for the file size. Fixes: 16abd2a0c124 ("NFSv4.2: fix client's attribute cache management for copy_file_range") Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/nfs42proc.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c index 8d64eb953347..3875120ef3ef 100644 --- a/fs/nfs/nfs42proc.c +++ b/fs/nfs/nfs42proc.c @@ -269,6 +269,33 @@ out: return status; } +/** + * nfs42_copy_dest_done - perform inode cache updates after clone/copy offload + * @inode: pointer to destination inode + * @pos: destination offset + * @len: copy length + * + * Punch a hole in the inode page cache, so that the NFS client will + * know to retrieve new data. + * Update the file size if necessary, and then mark the inode as having + * invalid cached values for change attribute, ctime, mtime and space used. + */ +static void nfs42_copy_dest_done(struct inode *inode, loff_t pos, loff_t len) +{ + loff_t newsize = pos + len; + loff_t end = newsize - 1; + + truncate_pagecache_range(inode, pos, end); + spin_lock(&inode->i_lock); + if (newsize > i_size_read(inode)) + i_size_write(inode, newsize); + nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | + NFS_INO_INVALID_CTIME | + NFS_INO_INVALID_MTIME | + NFS_INO_INVALID_BLOCKS); + spin_unlock(&inode->i_lock); +} + static ssize_t _nfs42_proc_copy(struct file *src, struct nfs_lock_context *src_lock, struct file *dst, @@ -362,14 +389,8 @@ static ssize_t _nfs42_proc_copy(struct file *src, goto out; } - truncate_pagecache_range(dst_inode, pos_dst, - pos_dst + res->write_res.count); - spin_lock(&dst_inode->i_lock); - nfs_set_cache_invalid( - dst_inode, NFS_INO_REVAL_PAGECACHE | NFS_INO_REVAL_FORCED | - NFS_INO_INVALID_SIZE | NFS_INO_INVALID_ATTR | - NFS_INO_INVALID_DATA); - spin_unlock(&dst_inode->i_lock); + nfs42_copy_dest_done(dst_inode, pos_dst, res->write_res.count); + spin_lock(&src_inode->i_lock); nfs_set_cache_invalid(src_inode, NFS_INO_REVAL_PAGECACHE | NFS_INO_REVAL_FORCED | @@ -1055,8 +1076,10 @@ static int _nfs42_proc_clone(struct rpc_message *msg, struct file *src_f, status = nfs4_call_sync(server->client, server, msg, &args.seq_args, &res.seq_res, 0); - if (status == 0) + if (status == 0) { + nfs42_copy_dest_done(dst_inode, dst_offset, count); status = nfs_post_op_update_inode(dst_inode, res.dst_fattr); + } kfree(res.dst_fattr); return status; -- 2.30.2