From patchwork Fri Mar 26 23:57:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 12167909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B006FC433DB for ; Fri, 26 Mar 2021 23:58:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99476619D3 for ; Fri, 26 Mar 2021 23:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229969AbhCZX6W (ORCPT ); Fri, 26 Mar 2021 19:58:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230027AbhCZX5x (ORCPT ); Fri, 26 Mar 2021 19:57:53 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25590C0613AA for ; Fri, 26 Mar 2021 16:57:53 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id b14so10108882lfv.8 for ; Fri, 26 Mar 2021 16:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=T0HNGL9RjbosSy6iahR8KqBCgoS7bcDTI8Uyweu3nC4=; b=a2IoXtMrD63cpObX2DvmUqovLEhbN/zc7AdQC00u7drhU2iCRPCwbqVixsZehW5m9z ODwJMTn13hZQJjxVn5GKY34vDXJP9bnSVN86eMX21E8aSDIKzOyQVG5Q7XnT6J84jzQZ dK29VIsiiw3kVjKKKlL8mOWcOqS5W/HNa5jVmMKBokW8j/EwSwBha0/i5FVmNwQiyCtQ gILnmxlYdSYoT74MQq51yRluXaJ4roevoE/nIlQ4iW5tfKYxUg0nNN614qXhAJbxHOxe znATOSN48GD4dXWoclQP4NeIRlJlo6Y+xMfgmwQiUD+XuGD5dQdLLcsvUamJ/1y+DieF w5Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=T0HNGL9RjbosSy6iahR8KqBCgoS7bcDTI8Uyweu3nC4=; b=BlnZez/OQqPCL4WAdo35z+HAIJ5atinYb3IutS1vZvRHFj10c7BHmAE4N8TLHgD8rx ZjW4beMdbAAr+wT3JyjkbPE9yw1DVX42/491+QQl1DxYh15q2PaiY7paOmkBwN6Addg5 j6Y7u8UYrGJL5Kxh2UE863Lei4N889VFfDRPZLBZKT2nHxKedR86fSQTfJbLMMAY5E71 ht+t2a8aUD56xQgw7UIvHE1J655BUzaIJTQEWMXgOG/bv36SCVvXJKk1z79M9ydDohBn uBBEavSlusY3NNXgUN7o2ZjuwEiUGPoTnCb2v1OQdEM5g8qzUTRfpUt+gPLtFoIDZyK9 WGag== X-Gm-Message-State: AOAM532YZS1khfULQAZ+ZGZRsw5Y11y663+6a6ESfqcldOkVn5QkAl37 QPo+1bRPW3tpgkL4Pz6Ax9iUTrGzR6e/TggZPgN8K0qQIMvE3Q== X-Google-Smtp-Source: ABdhPJwtEtpFhEVtKEzqS1cWIGiyqgEqRDZXUBsUwZNtOfMZ/Pj7rWvJnebWwuQq2TWQI/kgmMRCPEZ0kWLr4pJA09w= X-Received: by 2002:a19:404f:: with SMTP id n76mr9810532lfa.184.1616803071281; Fri, 26 Mar 2021 16:57:51 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Fri, 26 Mar 2021 18:57:40 -0500 Message-ID: Subject: [PATCH][SMB3] Fix file size problems in duplicate extents (reflink) To: CIFS Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org 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 --- fs/cifs/smb2ops.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) From cfc63fc8126a93cbf95379bc4cad79a7b15b6ece Mon Sep 17 00:00:00 2001 From: Steve French Date: Fri, 26 Mar 2021 18:41:55 -0500 Subject: [PATCH] smb3: fix cached file size problems in duplicate extents (reflink) 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 --- fs/cifs/smb2ops.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 3e94f83897e9..f703204fb185 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -2038,6 +2038,7 @@ smb2_duplicate_extents(const unsigned int xid, { 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); @@ -2054,10 +2055,21 @@ smb2_duplicate_extents(const unsigned int xid, 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, -- 2.27.0