Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4620562pxb; Mon, 27 Sep 2021 23:25:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsD2Yd4r3t8j5r97no4FZpzbLSwYS5OlXvupk0bUH3ZGJf7vePP/9Hos/z+HC1P8aViU1R X-Received: by 2002:a63:7b54:: with SMTP id k20mr3090396pgn.137.1632810310695; Mon, 27 Sep 2021 23:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632810310; cv=none; d=google.com; s=arc-20160816; b=Flutr0OKI4U9fAMj6Cbld805THJbcWLboPddBJPHG9Jqrf6ObUyEQwb4nTTTr2NXos Hq/iF5cPBeQCgVgjfcHFZM0odcTzTH61GZxLc41ZTiYxWDkq/03njdAc4qZx29nAplaj uP5LVms5mtZDtjbKlFq+9Tct3WQteRpq5KJqzzgN6b4GvVC4lZ+njNx/65CEWKoQ5Hly qAPfM/kRe1alo9/MD/8He6fcxCx0HHGKp4W7nnQDK6tIxFWgzz4sDPlMNbTqV/t0uEyX 1gT9LxOToYL8JCvZJhEz4UtgkCkBmPeL/+RuwKCIWEq8YgEVKpa/fjjklLYmMrxCRYw+ XoJg== 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:ironport-data; bh=ZpM0cfpARufXqFX2xMtPTXRikVuRLFDRi2xQ8vUp8cA=; b=OZSmDuOni76pLExK4Hgq4iLtJXVr56xy02r9EDETzRMhyLcbCfvBmUApuDwrY/MmyH WkpCOE/BvQirNR6T2E4iRDiOJLtxb51N8y9+JlhL/5O7JwOPD15mGTxXIokv2aEQXdjT 8PR3DE+RlSM2UECnXB8ZzqjbXt+d7XB7dL9eLmuRybxwD7M43ZB4tR1LqsV2dX5Y02Gc mCYE8dzcpIHJ/zzlT0wcqTAP+v6DfJGMrsnNnIm28se8vcrqhsaK6luf7SFtC8o/U5Bk lu0orX0PPeAyMEFpTKgI5gfBx0wHd4YOORMYQxJBRnVsSQkTe0wswTL29ePQkQXevd1A 0VRw== 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 2si24597687pgo.95.2021.09.27.23.24.58; Mon, 27 Sep 2021 23:25:10 -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 S239043AbhI1GZh (ORCPT + 99 others); Tue, 28 Sep 2021 02:25:37 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:6283 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239053AbhI1GZc (ORCPT ); Tue, 28 Sep 2021 02:25:32 -0400 IronPort-Data: =?us-ascii?q?A9a23=3AzxInbKIOS5sSqRVzFE+RwZQlxSXFcZb7ZxGrkP8?= =?us-ascii?q?bfHC60zkl1GFVyDEbWjuFa6mOajTwKo8nPo6/pkIHuJPQxoNqS1BcGVNFFSwT8?= =?us-ascii?q?ZWfbTi6wuYcBwvLd4ubChsPA/w2MrEsF+hpCC+BzvuRGuK59yAkhPvYHuOU5NP?= =?us-ascii?q?sYUideyc1EU/Ntjozw4bVsqYw6TSIK1vlVeHa+qUzC3f5s9JACV/43orYwP9ZU?= =?us-ascii?q?FsejxtD1rA2TagjUFYzDBD5BrpHTU26ByOQroW5goeHq+j/ILGRpgs1/j8mDJW?= =?us-ascii?q?rj7T6blYXBLXVOGBiiFIPA+773EcE/Xd0j87XN9JFAatToy+UltZq2ZNDs4esY?= =?us-ascii?q?Qk0PKzQg/lbWB5de817FfQfpeeWfynu6qR/yGWDKRMA2c5GAEgoPIEw9PxwBGZ?= =?us-ascii?q?U//0EbjsKa3irmOOyxKOTS+9inM0vIcDneoQFtRlIwTjfS/RgXpHHR6TD4MRw3?= =?us-ascii?q?TEsi8QIFvHbD+IVayVoahvoYBBVPFoTTpUkk4+AnHjjfiZYqHqRpKwq8y7Sxgk?= =?us-ascii?q?327/oWPLTZNCLQMB9mkeDunmA+2X/HwFcONGBoRKF+XKEgvTT2y/2MKoIG7q8+?= =?us-ascii?q?uF7hnWI23ceThEbPXO/oP+kmguwQN5SNUEQ0jQhoLJ090GxSNT5GRqirxasuh8?= =?us-ascii?q?aRsoVEOAg7gyJ4rTb7hzfBWUeSDNFLts8u6ceQT0sy0/Mj93yLSJgvafTSn+H8?= =?us-ascii?q?LqQ6zSoNkA9M24YYgcWQA0E/Z/noYcunlTIVNklDa3dszFfMVkc2BjT9G5n2ep?= =?us-ascii?q?V1pVNis2GEZn8q2rEjvD0osQdu207hl6Y0z4=3D?= IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AunpnqKNbIuqYKcBcTv2jsMiBIKoaSvp037BL?= =?us-ascii?q?7TEUdfUxSKGlfq+V8sjzqiWftN98YhAdcLO7Scy9qBHnhP1ICOAqVN/MYOCMgh?= =?us-ascii?q?rLEGgN1+vf6gylMyj/28oY7q14bpV5YeeaMXFKyer8/ym0euxN/OW6?= X-IronPort-AV: E=Sophos;i="5.85,328,1624291200"; d="scan'208";a="115096993" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 28 Sep 2021 14:23:51 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 8836C4D0DC83; Tue, 28 Sep 2021 14:23:50 +0800 (CST) Received: from G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 28 Sep 2021 14:23:44 +0800 Received: from G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.85) by G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 28 Sep 2021 14:23:43 +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; Tue, 28 Sep 2021 14:23:42 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , , Ritesh Harjani Subject: [PATCH v10 5/8] fsdax: Add dax_iomap_cow_copy() for dax_iomap_zero Date: Tue, 28 Sep 2021 14:23:08 +0800 Message-ID: <20210928062311.4012070-6-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210928062311.4012070-1-ruansy.fnst@fujitsu.com> References: <20210928062311.4012070-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: 8836C4D0DC83.AED86 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 CoW operation for not aligned case in dax_iomap_zero(). Signed-off-by: Shiyang Ruan Reviewed-by: Ritesh Harjani Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/dax.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index debe459680f2..5379de8ad0c7 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1212,6 +1212,7 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf, s64 dax_iomap_zero(const struct iomap_iter *iter, loff_t pos, u64 length) { const struct iomap *iomap = &iter->iomap; + const struct iomap *srcmap = &iter->srcmap; sector_t sector = iomap_sector(iomap, pos & PAGE_MASK); pgoff_t pgoff; long rc, id; @@ -1230,21 +1231,27 @@ s64 dax_iomap_zero(const struct iomap_iter *iter, loff_t pos, u64 length) id = dax_read_lock(); - if (page_aligned) + if (page_aligned) { rc = dax_zero_page_range(iomap->dax_dev, pgoff, 1); - else - rc = dax_direct_access(iomap->dax_dev, pgoff, 1, &kaddr, NULL); - if (rc < 0) { - dax_read_unlock(id); - return rc; + goto out; } - if (!page_aligned) { - memset(kaddr + offset, 0, size); + rc = dax_direct_access(iomap->dax_dev, pgoff, 1, &kaddr, NULL); + if (rc < 0) + goto out; + memset(kaddr + offset, 0, size); + if (srcmap->addr != IOMAP_HOLE && srcmap->addr != iomap->addr) { + rc = dax_iomap_cow_copy(pos, size, PAGE_SIZE, srcmap, + kaddr); + if (rc < 0) + goto out; + dax_flush(iomap->dax_dev, kaddr, PAGE_SIZE); + } else 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, -- 2.33.0