Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3433202pxb; Sun, 7 Feb 2021 09:12:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMQs86r2MD+u1X4rq7ojha4i+Tig8TLXgUl9r1f81aTZNACiVl8u8x0Pm/WSBBACOwlrAX X-Received: by 2002:a17:906:5857:: with SMTP id h23mr12977922ejs.465.1612717977734; Sun, 07 Feb 2021 09:12:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612717977; cv=none; d=google.com; s=arc-20160816; b=Zdhwel5th2c4BrZMAD0Vu1PcHBCTDTQBIXjCijLyHxrcCjAUEA8iyp2WC1T4SB6iAl F1+/9RRGF4rQG64FQCaUm4AzREasUm346zENEUnkSVjnvLAqtGFZbJauOKt/iQmrbAAA LxwDpFOjKScZkwlWgquthH2UILcOEf22t4L/ApJb6qN2ALijwwh5vgNVDCZSNyYGiRyL MVrI1Dt1olHtGEVklWsAv3jdgfeddWv//VhfS4kULde73iJoZnVm8JX8cjvN1KGh3vbi ZtRGcbm9duUgMnKjyEFcEMkEqk6r3ity5ZzTlau03FnxwT3n8hOBbByjKZVFA0mt2kAN dG5Q== 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; bh=ZXtZXyt7ibbgwycrh3v/QJGtReWuSsvOKxNjrqQhUkE=; b=yKIR91IaDLzL0XmJN1Cdj+PA9nexGBBFC0ccENxgrV5VEQYV55NaBoctru82ArBqT+ wQ4n9WEbECpOQYdtcTN+rmXqrCPFF0bf3vPk3oC9bmB2s6Z7jDrN8qdHJCOKyOHSB7/W 5usREA8XhpgHuH9wpoy63uYL56zI0IEqDmLO+m3REFwidBrfiNLNPZ6Ob2ZONNVEVTK0 fvEUZuQt+LWbHWNrHQA/Z1VVsWgYn/dYnBsgy51L96hN8zKzaINZmKSz1Cs+ClmlXyiz Eeq+tcr40tdldFbdTYCk/jQoCG+Z1xYAHQqLNX2L/cZiDi81sTENvnDAXA41nMSRO2qu d+MA== 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 4si3225265edc.221.2021.02.07.09.12.34; Sun, 07 Feb 2021 09:12:57 -0800 (PST) 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 S229770AbhBGRKm (ORCPT + 99 others); Sun, 7 Feb 2021 12:10:42 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:52559 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229720AbhBGRKi (ORCPT ); Sun, 7 Feb 2021 12:10:38 -0500 X-IronPort-AV: E=Sophos;i="5.81,160,1610380800"; d="scan'208";a="104299368" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 08 Feb 2021 01:09:32 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id 641D84CE6F77; Mon, 8 Feb 2021 01:09:30 +0800 (CST) Received: from G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.200) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 8 Feb 2021 01:09:32 +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; Mon, 8 Feb 2021 01:09:31 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , , , , Goldwyn Rodrigues Subject: [PATCH 2/7] fsdax: Introduce dax_copy_edges() for CoW Date: Mon, 8 Feb 2021 01:09:19 +0800 Message-ID: <20210207170924.2933035-3-ruansy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207170924.2933035-1-ruansy.fnst@cn.fujitsu.com> References: <20210207170924.2933035-1-ruansy.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: 641D84CE6F77.ACBBD X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@cn.fujitsu.com X-Spam-Status: No Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dax_copy_edges() is a helper functions performs a copy from one part of the device to another for data not page aligned. Signed-off-by: Goldwyn Rodrigues Signed-off-by: Shiyang Ruan --- fs/dax.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/fs/dax.c b/fs/dax.c index b012b2db7ba2..ea4e8a434900 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1038,6 +1038,47 @@ static int dax_iomap_direct_access(struct iomap *iomap, loff_t pos, size_t size, return rc; } +/* + * Copies the part of the pages not included in the write, but required for CoW + * because offset/offset+length are not page aligned. + */ +static int dax_copy_edges(loff_t pos, loff_t length, struct iomap *srcmap, + void *daddr, bool pmd) +{ + size_t page_size = pmd ? PMD_SIZE : PAGE_SIZE; + loff_t offset = pos & (page_size - 1); + size_t size = ALIGN(offset + length, page_size); + loff_t end = pos + length; + loff_t pg_end = round_up(end, page_size); + void *saddr = 0; + int ret = 0; + + ret = dax_iomap_direct_access(srcmap, pos, size, &saddr, NULL); + if (ret) + return ret; + /* + * Copy the first part of the page + * Note: we pass offset as length + */ + if (offset) { + if (saddr) + ret = copy_mc_to_kernel(daddr, saddr, offset); + else + memset(daddr, 0, offset); + } + + /* Copy the last part of the range */ + if (end < pg_end) { + if (saddr) + ret = copy_mc_to_kernel(daddr + offset + length, + saddr + offset + length, pg_end - end); + else + memset(daddr + offset + length, 0, pg_end - end); + } + + return ret; +} + /* * The user has performed a load from a hole in the file. Allocating a new * page in the file would cause excessive storage usage for workloads with -- 2.30.0