Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp54256pxb; Sun, 15 Aug 2021 23:05:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRh3eAqxyWC4GFolGExXNdf96/TSs+sVgCDWo36pVkH1vVNOTR0G82+ezpWy+AX56rttuK X-Received: by 2002:a92:c80e:: with SMTP id v14mr9375993iln.57.1629093939171; Sun, 15 Aug 2021 23:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629093939; cv=none; d=google.com; s=arc-20160816; b=e3ELL3YXczahMJ5W4SSuDDgireViPuuvr/ie2ZLDj4jy0BjZOFAE69/k0MtZiRkNLx wxfa1RIT3gzZKuvNhdUdCDAr12iHHixzjqvNL4LF+/ZLRaNIyGzZhwJ0qOFvwZl5TC/L FprOOhoQr4QNepAYp7juft4YYmanxy9Um7bA6bG5mmgTxM0L60NJEjN9QbtV1+Hww4c8 qQvzx1Tq09G6da0Rz5EnFqDxmAwMtdoqAJMo1505RD2MRAEpjsy5d6pXI/t6u5I9RjnL +EL6JTR8eaOe7+D0n0hqU3PRnfa+gt7ZzPhd6e8FrROad10A4hpTl8tl5Bgmj0nL/pQ9 d65g== 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=+s1VuPJh6bj8P+rvVbNbCUI1b+1YvCnFrp8UkW6TdIA=; b=tAiRZEf33t9MPe8370eLq9MIDe+acv3/Dowj8YSStXKq4865DeFqXSiyEXAwWycSlO SA+gpdg3aWgv3L0EGLr/UzRWxLm8jZUZr+n/h+dV0Wxg8f8BGP9IwduJy4F9sG5tHUs+ dbP5O9V9EoAQ3DO6x14+Di0xYXNMh/Mkmry2NHRmvEI8Q9wZRZSQLQQr6MeZ6aIN/nB/ JEqH1CoU4wbklpBpZDQgYhPK6nGyeM4Lzcvoev/u3zRpu6JfNuMWy3rbMH8TkoHOjl5J jGVD0Y+3vmL1sgJ0wTFobaEwyc8W5tcBZVHvywWBpiyyDvyYnmifBIZ96dQ19hGZZjCl sVIg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i13si12266895ilm.90.2021.08.15.23.05.28; Sun, 15 Aug 2021 23:05:39 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229623AbhHPGFD (ORCPT + 99 others); Mon, 16 Aug 2021 02:05:03 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:38862 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233376AbhHPGFB (ORCPT ); Mon, 16 Aug 2021 02:05:01 -0400 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AZ6rcZa82sk4fShoPMLduk+DkI+orL9Y04lQ7?= =?us-ascii?q?vn2ZKCYlFvBw8vrCoB1173HJYUkqMk3I9ergBEDiewK4yXcW2/hzAV7KZmCP11?= =?us-ascii?q?dAR7sSj7cKrQeBJwTOssZZ1YpFN5N1EcDMCzFB5vrS0U2VFMkBzbC8nJyVuQ?= =?us-ascii?q?=3D=3D?= X-IronPort-AV: E=Sophos;i="5.84,324,1620662400"; d="scan'208";a="112944860" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Aug 2021 14:04:29 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id 82D764D0D4BF; Mon, 16 Aug 2021 14:04:28 +0800 (CST) Received: from G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.85) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 16 Aug 2021 14:04:25 +0800 Received: from irides.mr.mr.mr (10.167.225.141) by G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.23 via Frontend Transport; Mon, 16 Aug 2021 14:04:21 +0800 From: Shiyang Ruan To: , , CC: , , , , , , , , , Ritesh Harjani Subject: [PATCH v7 4/8] fsdax: Add dax_iomap_cow_copy() for dax_iomap_zero Date: Mon, 16 Aug 2021 14:03:55 +0800 Message-ID: <20210816060359.1442450-5-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210816060359.1442450-1-ruansy.fnst@fujitsu.com> References: <20210816060359.1442450-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: 82D764D0D4BF.A3AC4 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_iomap_cow_copy() too. Otherwise, data in not aligned area will be not correct. So, add the srcmap to dax_iomap_zero() and replace memset() as dax_iomap_cow_copy(). Signed-off-by: Shiyang Ruan Reviewed-by: Ritesh Harjani Reviewed-by: Darrick J. Wong --- fs/dax.c | 25 +++++++++++++++---------- fs/iomap/buffered-io.c | 4 ++-- include/linux/dax.h | 3 ++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index e49ba68cc7e4..91ceb518f66a 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1198,7 +1198,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, const struct iomap *iomap, + const struct iomap *srcmap) { sector_t sector = iomap_sector(iomap, pos & PAGE_MASK); pgoff_t pgoff; @@ -1220,19 +1221,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(pos, 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 dax_iomap_iter(const struct iomap_iter *iomi, diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 71b4806266d7..6e8d40877d01 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -889,7 +889,7 @@ static s64 __iomap_zero_iter(struct iomap_iter *iter, loff_t pos, u64 length) static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) { - struct iomap *iomap = &iter->iomap; + const struct iomap *iomap = &iter->iomap; const struct iomap *srcmap = iomap_iter_srcmap(iter); loff_t pos = iter->pos; loff_t length = iomap_length(iter); @@ -903,7 +903,7 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) s64 bytes; if (IS_DAX(iter->inode)) - bytes = dax_iomap_zero(pos, length, iomap); + bytes = dax_iomap_zero(pos, length, iomap, srcmap); else bytes = __iomap_zero_iter(iter, pos, length); if (bytes < 0) diff --git a/include/linux/dax.h b/include/linux/dax.h index b52f084aa643..c63559605369 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, const struct iomap *iomap, + const struct iomap *srcmap); static inline bool dax_mapping(struct address_space *mapping) { return mapping->host && IS_DAX(mapping->host); -- 2.32.0