Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp372741pxf; Thu, 8 Apr 2021 05:06:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwg0rnQGc5jSWYLteZeLHEtLxYaUrreL4qUtwP7PHWdeHoJCCMB0jBeuFSX40NhIaYsTmGu X-Received: by 2002:a17:906:b202:: with SMTP id p2mr9915069ejz.244.1617883594248; Thu, 08 Apr 2021 05:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617883594; cv=none; d=google.com; s=arc-20160816; b=p2PohqV5F39V1W7NT37C//CuwcUv5ZqoNTQiLRcPRcuRSmTSTskdp6LXOccpH8Q5Eo fIxq6bg9MJNZT9TA3T9jgdQLsO1eSGFEuybXcTZsRO7V5q/T/bMW0j730NOq+0A+4azr M8ZM0XSvdNXJN4lx82C5c+osSFntVvW4v4dCvdPwt9NH90v373ACg6q6edI2cwurWDDM ra2w/K3iY0fBSNehBmZnIt7EUH9VfLvxEEEXmoaZEiTWP4GXC/nrU3b7qw7bi9j7ConH J8Nqt8X81DFV95CSlzlFnToy7NGzzHiawfSWIVEtVg2IcE7jfC4XkL1wN0aOQjKWJ9nC sJ2Q== 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=z5KibUpfmeEoPuY5a41lXVEsFD6cRBJsAqnwn0rMOJw=; b=dVvOyciS/o1A79VYlA9ggzkEfXVQRf43moHbTC5Z49xF0j+CmNYnTYpgBLjKPDGLJ/ yB/FiAIohpkFWoHkjwTvtAyQbQBuBJgCucd1d2R7njvCZRKm1QkCYOQHEpG0WYL0P/1m UwQfGpYDKJuEU6hiXR1Me+0EQYjp01IPH8DEeE3cN9bGTDVdcejnyAf8KfXdDACZp3Zi 3RJE/PMZ0Cq6sU8iFjM8KZk/9pgepwkN2g/Dq7fhj8zgqTTwoSu9VviqPbL/eMODczU8 ttNPvEy8A5NQsr2FbuWP6sI0L+X/acsYOxn62htEqZxcUummWuQQ4zGxwohsvXuThaRH 5YSg== 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 ce25si12701332ejb.93.2021.04.08.05.06.11; Thu, 08 Apr 2021 05:06:34 -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 S231489AbhDHMFT (ORCPT + 99 others); Thu, 8 Apr 2021 08:05:19 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:24855 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231395AbhDHMFS (ORCPT ); Thu, 8 Apr 2021 08:05:18 -0400 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AWRPeqa/y1cKUU1EwtMxuk+A4I+orLtY04lQ7?= =?us-ascii?q?vn1ZYxpTb8CeioSSjO0WvCWE7Ao5dVMBvZS7OKeGSW7B7pId2+QsFJqrQQWOgg?= =?us-ascii?q?WVBa5v4YboyzfjXw3Sn9Q26Y5OaK57YeeQMXFfreLXpDa1CMwhxt7vytHMuc77?= =?us-ascii?q?w212RQ9nL4FMhj0JaTqzKUF9SAlYCZdRLvP1ifZvnSaqengcc62Adxs4dtXEzu?= =?us-ascii?q?eqqLvWJTYCBzMCrDKFlC6U7tfBeCSw71MzVCxuzN4ZnVT4rw=3D=3D?= X-IronPort-AV: E=Sophos;i="5.82,206,1613404800"; d="scan'208";a="106797286" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 08 Apr 2021 20:05:04 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 3BCC14D0B8A9; Thu, 8 Apr 2021 20:04:59 +0800 (CST) Received: from G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.200) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 8 Apr 2021 20:04:49 +0800 Received: from irides.mr.mr.mr (10.167.225.141) by G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 8 Apr 2021 20:04:48 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , , , Ritesh Harjani Subject: [PATCH v4 3/7] fsdax: Add dax_iomap_cow_copy() for dax_iomap_zero Date: Thu, 8 Apr 2021 20:04:28 +0800 Message-ID: <20210408120432.1063608-4-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210408120432.1063608-1-ruansy.fnst@fujitsu.com> References: <20210408120432.1063608-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: 3BCC14D0B8A9.A4AFC 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 e6c1354b27a8..fcd1e932716e 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 414769a6ad11..67936e9967b8 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.0