Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3427831pxf; Mon, 29 Mar 2021 01:48:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+SlH3Vxt75EdY666F7oBrNp/DkTkfwXfJpiHXiAfJfX1elrlsvVPVvg0yOCbPLe0Kzelt X-Received: by 2002:a17:906:7806:: with SMTP id u6mr25650718ejm.130.1617007737937; Mon, 29 Mar 2021 01:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617007737; cv=none; d=google.com; s=arc-20160816; b=SeYQE7Plu3wiP3ZhOyxMXW25ukdiEvLobTTeZ+JALjVJTgVypfi1lUY05w+lO4ysHD zC/Pq+bgF20ncySiMksZqJDwAxNp7eEY8AvjCBhTOZI8V4P3vJSPl5TY43ocCJGRdN+3 WAKnD1THHd9Ufx1xhLZSNguD6PN18FpuwGvQ04f86bKJzYL0l63rVWC9FAKoXuE2zxkD r+OeFOMtxS5iBSJ2y0u2SsxfKuzh8eMCowqghz7EH2LohLZmsOuuV4pWNuTGHmeVI7ik 0VDI4na8tJJi9psPSkgUSapxF3qpx9SVxvbZk6+bF+FKklL+ofmyDU9KaqFwVOa2kQDC 8w4w== 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=oMTQDRKPQIZufjwTBNi1ZLO4GHWune46xfLwsIDSrsg=; b=ejA/eAD2MiZnvVFn0lDixziLi5p5UCFLDq6U+PTwMB9hopGrYytftYDnNiDo1vEHcg VoUHeZ1gcn/EON4HKHZ6obw+tYjRp0xI6csq1ZBGAgWanniEL8MapFjmOKvC4YbwSWdc QVptGNyoA5unUDQAfVmGVR/jo6FfEzZfB5owUWfr3wKn6pJcMiJRPAU5GZrLUIyyP6Nw gbmr2JKhhX+1AUvBkZLAQQpIRK7BaU8J+hpn7apVVoahjsLIXZ5IUyRN3PJScSEdbGda rcYtmv1QIrKQNHgSp2DEuby9EXnvSJOzuoAOAIO6vaO+0j1RcsIpuJGhZHoAtGwLb+TG WW4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Yz7GbyD3; 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 t16si12719837edc.448.2021.03.29.01.48.35; Mon, 29 Mar 2021 01:48:57 -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=Yz7GbyD3; 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 S235699AbhC2Ira (ORCPT + 99 others); Mon, 29 Mar 2021 04:47:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:41790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233709AbhC2I0V (ORCPT ); Mon, 29 Mar 2021 04:26:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 00C1E6191F; Mon, 29 Mar 2021 08:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006340; bh=UPQIX7PxWlx38E8Y1XTqAIo+xV4fACP3vQf7ThL01fw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yz7GbyD3dUhVEdWHXeYHm8AOSBUJox4gZJS8Uh7WywTb/dFNirrsV98R7tlbhJFkb do2g7RMrEJ6eFvkzBf5F2bzAl66QxtHFZkfgPbb0N23IQYbzkwYtAsDr0ZFiuyQMu5 iXVcGYVNnbBkKJ2I6L6/o/0wHDl6pq5uHFA+GBHI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve French Subject: [PATCH 5.10 205/221] smb3: fix cached file size problems in duplicate extents (reflink) Date: Mon, 29 Mar 2021 09:58:56 +0200 Message-Id: <20210329075635.956192163@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@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: Steve French commit cfc63fc8126a93cbf95379bc4cad79a7b15b6ece upstream. There were two problems (one of which could cause data corruption) that were noticed with duplicate extents (ie reflink) when debugging why various xfstests were being incorrectly skipped (e.g. generic/138, generic/140, generic/142). First, we were not updating the file size locally in the cache when extending a file due to reflink (it would refresh after actimeo expires) but xfstest was checking the size immediately which was still 0 so caused the test to be skipped. Second, we were setting the target file size (which could shrink the file) in all cases to the end of the reflinked range rather than only setting the target file size when reflink would extend the file. CC: Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/smb2ops.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1980,6 +1980,7 @@ smb2_duplicate_extents(const unsigned in { int rc; unsigned int ret_data_len; + struct inode *inode; struct duplicate_extents_to_file dup_ext_buf; struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); @@ -1996,10 +1997,21 @@ smb2_duplicate_extents(const unsigned in cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n", src_off, dest_off, len); - rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); - if (rc) - goto duplicate_extents_out; + inode = d_inode(trgtfile->dentry); + if (inode->i_size < dest_off + len) { + rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); + if (rc) + goto duplicate_extents_out; + /* + * Although also could set plausible allocation size (i_blocks) + * here in addition to setting the file size, in reflink + * it is likely that the target file is sparse. Its allocation + * size will be queried on next revalidate, but it is important + * to make sure that file's cached size is updated immediately + */ + cifs_setsize(inode, dest_off + len); + } rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, trgtfile->fid.volatile_fid, FSCTL_DUPLICATE_EXTENTS_TO_FILE,