Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3139746pxj; Mon, 10 May 2021 20:11:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoA+GWP7Kd2viiF6KzHMoPu+nfRP+k0p6rnuhbT++sMjIy0SFk2hPoTo+YzeX4adAV/5ke X-Received: by 2002:a92:de05:: with SMTP id x5mr24450793ilm.156.1620702679472; Mon, 10 May 2021 20:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620702679; cv=none; d=google.com; s=arc-20160816; b=opUcYKiKPML43VuFapm+iNLOa1blcl6hUs22HUzjEpWXPfuXPqaiBomrbRd5NPHyj3 sl1wQBwOXoTwTpr8dknavV/sxEI1ZIzwtZs/mGI87ErLjA5i8iP292tJWYDPxO0OyBym FDBUjc6Ql5F1Ycz+I2ezNBLgkSGWFnaiLP7oNeu2uyuQxLa4QlW01sV+m1SSSCoQ0aa9 MHhO+nnnYSzp41dUielQtL58LN9cBvg89qzaDmJOSF25fhA8uOov3DRvydRfOZ5Katqq wLZ23SLRNEtkgfCIhnhL21+rhFh2EDEiBL5+WijAP/KHrujKdtoTtIPb6xXleZaUUNBs tuhw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-hdrordr; bh=BhegSMU5MBTC2TWa3GMWwFecLt48vmMEtHZZ3Y0VLh8=; b=gRM/9xWJvRUoPdcmUL/J4691MiODmXSgRPODZDQGWfK5aFsvRAhAtFy5To9yp9JZTu x33+WnnzEVxHgSl9E5LtBGq3t+v5N1yJPA0ek873HVvsWJC98TiGjRp0uglBWxtzZAR8 vq9wy45FLTlet0BowdlCWpvj+X3YWBNz9kHrgzmZgZ8YhJz5bKwwqPOns32HYzaPm/WZ pDd1zD5NjGFcb8CrQeHJocuycVIjGPID3Y3jxklUJ0x9rht0qjoa7fsGdXfrLX3GStXd 07AFGzC8zeQ8yvzsyTpKF8W0m/ou/ackmK/0TimqYJSpMRdqiVfAhM/UfCHvUzwlLVye Kz2w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y24si12300957ior.40.2021.05.10.20.11.07; Mon, 10 May 2021 20:11:19 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbhEKDLO (ORCPT + 99 others); Mon, 10 May 2021 23:11:14 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:41058 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230011AbhEKDLO (ORCPT ); Mon, 10 May 2021 23:11:14 -0400 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3Ah6/KB6w18dSo8UouYdzgKrPwyr1zdoMgy1kn?= =?us-ascii?q?xilNoRw8SK2lfqeV7Y0mPH7P+U4ssR4b6LO90cW7Lk80sKQFhbX5Xo3SOjUO2l?= =?us-ascii?q?HYTr2KhLGKq1aLdkHDH6xmpMBdmsNFaOEYY2IVsS+D2njcLz8/+qj6zImYwffZ?= =?us-ascii?q?02x2TRxnL4Vp7wJCAA6dFUFsLTM2f6YRJd6N4NZdvTq8dTAyZsS/PHMMWO/OvJ?= =?us-ascii?q?nlj5TjCCR2eiIP2U2fiy+y8r7mH1y91hcaaTlGxrAv6izkvmXCl96ej80=3D?= X-IronPort-AV: E=Sophos;i="5.82,290,1613404800"; d="scan'208";a="108110547" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 11 May 2021 11:10:05 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id 04FF54D0BA7A; Tue, 11 May 2021 11:10:01 +0800 (CST) Received: from G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 11 May 2021 11:09:52 +0800 Received: from irides.mr.mr.mr (10.167.225.141) by G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 11 May 2021 11:09:49 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , Ritesh Harjani Subject: [PATCH v5 3/7] fsdax: Add dax_iomap_cow_copy() for dax_iomap_zero Date: Tue, 11 May 2021 11:09:29 +0800 Message-ID: <20210511030933.3080921-4-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511030933.3080921-1-ruansy.fnst@fujitsu.com> References: <20210511030933.3080921-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: 04FF54D0BA7A.A2DDA X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@fujitsu.com X-Spam-Status: No Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Punch hole on a reflinked file needs dax_copy_edge() too. Otherwise, data in not aligned area will be not correct. So, add the srcmap to dax_iomap_zero() and replace memset() as dax_copy_edge(). Signed-off-by: Shiyang Ruan Reviewed-by: Ritesh Harjani --- fs/dax.c | 25 +++++++++++++++---------- fs/iomap/buffered-io.c | 2 +- include/linux/dax.h | 3 ++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index ef0e564e7904..ee9d28a79bfb 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1186,7 +1186,8 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf, } #endif /* CONFIG_FS_DAX_PMD */ -s64 dax_iomap_zero(loff_t pos, u64 length, struct iomap *iomap) +s64 dax_iomap_zero(loff_t pos, u64 length, struct iomap *iomap, + struct iomap *srcmap) { sector_t sector = iomap_sector(iomap, pos & PAGE_MASK); pgoff_t pgoff; @@ -1208,19 +1209,23 @@ s64 dax_iomap_zero(loff_t pos, u64 length, struct iomap *iomap) if (page_aligned) rc = dax_zero_page_range(iomap->dax_dev, pgoff, 1); - else + else { rc = dax_direct_access(iomap->dax_dev, pgoff, 1, &kaddr, NULL); - if (rc < 0) { - dax_read_unlock(id); - return rc; - } - - if (!page_aligned) { - memset(kaddr + offset, 0, size); + if (rc < 0) + goto out; + if (iomap->addr != srcmap->addr) { + rc = dax_iomap_cow_copy(offset, size, PAGE_SIZE, srcmap, + kaddr); + if (rc < 0) + goto out; + } else + memset(kaddr + offset, 0, size); dax_flush(iomap->dax_dev, kaddr + offset, size); } + +out: dax_read_unlock(id); - return size; + return rc < 0 ? rc : size; } static loff_t diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index f2cd2034a87b..2734955ea67f 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -933,7 +933,7 @@ static loff_t iomap_zero_range_actor(struct inode *inode, loff_t pos, s64 bytes; if (IS_DAX(inode)) - bytes = dax_iomap_zero(pos, length, iomap); + bytes = dax_iomap_zero(pos, length, iomap, srcmap); else bytes = iomap_zero(inode, pos, length, iomap, srcmap); if (bytes < 0) diff --git a/include/linux/dax.h b/include/linux/dax.h index b52f084aa643..3275e01ed33d 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -237,7 +237,8 @@ vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index); int dax_invalidate_mapping_entry_sync(struct address_space *mapping, pgoff_t index); -s64 dax_iomap_zero(loff_t pos, u64 length, struct iomap *iomap); +s64 dax_iomap_zero(loff_t pos, u64 length, struct iomap *iomap, + struct iomap *srcmap); static inline bool dax_mapping(struct address_space *mapping) { return mapping->host && IS_DAX(mapping->host); -- 2.31.1