Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp87625pxh; Tue, 9 Nov 2021 07:43:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlVDwQNZjCIaIS/3ubyca8AltIBSmjRSRwfMyjmVxSBNnTnO9KOtRsBOstW0k7J9btPDqH X-Received: by 2002:a05:6402:12cd:: with SMTP id k13mr10512782edx.218.1636472617125; Tue, 09 Nov 2021 07:43:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636472617; cv=none; d=google.com; s=arc-20160816; b=QsMDVRh5QOJl2mAmEbZ8g23DS3ImlYkbWxkJitzWxhM7e2PGdhHM3ZU+kmNFKf58Lg vBYqRWjBqtczfo01JJzZUQWWMa+3+IQ83u7CDTu/HJ94hO4N4DSWlPwZNbz3HRd3qb0k wemX51Pr9DFXA06LYZI3hzxcE5OrQSSJdjvuEfdAY5y04bPR+bpcu11hx+5e/T/fLnLa UzCgpHVtUsxAoSlERdDCEx88mB3wyUALY+o5DEc09j1xg49HgtTTNScjGhc+u31FXw1+ aDLnlJTefeavCDhyjhayKEHiK+k1+BnytC67rFFtrDye/2DBhJGf041JyQ9mhAGb1imf /50Q== 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 :dkim-signature; bh=nsipimcnsyS/B0mUTKc1w7RvYVd94QXif4VmP6OnJ7M=; b=ITMcsqXpvYoqxxRxjl1jG+eqUbwyNnI2k1II3LNn/mxyNQ2NFsjN0G7TiQxE8U5Bff 49iuLYeMs7VTBMGLfonZQsKPvyIWFoGvQ1nQp4GzY3a+ySt6lbcKZqm6zphKKznx1j4T VQVGAvghqNwjp4uCN94Fjpvs615tqmNoGp9ayvkDlsLJKQoFdnIWBrChvrjl0zvVrhPZ Og7Kjkc/YFIHqBeu751rRcyELTj5Dj7rSYv+ZA7IaeJutga0IH+i0ro2r3JTvOFWDLeA Er9+WCrjeh0R4xa4+1o57RHrr81BKa2xeI23+aQ6x9MBzM2pHeDb5OQMQwyyj/t+mxIz lSSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=SOG3snbC; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 k19si28112904eja.476.2021.11.09.07.43.12; Tue, 09 Nov 2021 07:43:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=SOG3snbC; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244179AbhKIIg3 (ORCPT + 99 others); Tue, 9 Nov 2021 03:36:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244162AbhKIIgU (ORCPT ); Tue, 9 Nov 2021 03:36:20 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24BA8C061764; Tue, 9 Nov 2021 00:33:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=nsipimcnsyS/B0mUTKc1w7RvYVd94QXif4VmP6OnJ7M=; b=SOG3snbCeJFUNnpml/J+nGIFgP 11Rn4mb7f2DlhTGj7RN7VChnDm3Kc7nnt3ugFvyLhPzYC/aVMPav+/ZdZnkkV+C8SGkiSuFBPlmiq +OlDsroYRkp5Z7qJsqAM9LoUeLZdRih0+vjY/R9LbESTRS/PNy3qme0CF0vll5vxbJ5FnNeetrv00 LHf4krhOqEKcByFNJMYS7khd2ax5/pWQRsi+oLDfJlcZ8dz6cjDnoSHusXpAyTUsaiFW7nqLLfAsO qUqyM7FpXzWRPuISCSoM0P5W1S+i4zpKjfv1bi0L3ZBd8jMPV+SnYd3weWCOI+oK+qZxN2yVl739E SR4KAVmg==; Received: from [2001:4bb8:19a:7ee7:fb46:2fe1:8652:d9d4] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mkMZN-000s15-PP; Tue, 09 Nov 2021 08:33:30 +0000 From: Christoph Hellwig To: Dan Williams Cc: Mike Snitzer , Ira Weiny , dm-devel@redhat.com, linux-xfs@vger.kernel.org, nvdimm@lists.linux.dev, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH 09/29] dm-linear: add a linear_dax_pgoff helper Date: Tue, 9 Nov 2021 09:32:49 +0100 Message-Id: <20211109083309.584081-10-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109083309.584081-1-hch@lst.de> References: <20211109083309.584081-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add a helper to perform the entire remapping for DAX accesses. This helper open codes bdev_dax_pgoff given that the alignment checks have already been done by the submitting file system and don't need to be repeated. Signed-off-by: Christoph Hellwig Acked-by: Mike Snitzer --- drivers/md/dm-linear.c | 49 +++++++++++++----------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index 0a260c35aeeed..90de42f6743ac 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c @@ -163,63 +163,44 @@ static int linear_iterate_devices(struct dm_target *ti, } #if IS_ENABLED(CONFIG_FS_DAX) +static struct dax_device *linear_dax_pgoff(struct dm_target *ti, pgoff_t *pgoff) +{ + struct linear_c *lc = ti->private; + sector_t sector = linear_map_sector(ti, *pgoff << PAGE_SECTORS_SHIFT); + + *pgoff = (get_start_sect(lc->dev->bdev) + sector) >> PAGE_SECTORS_SHIFT; + return lc->dev->dax_dev; +} + static long linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff, long nr_pages, void **kaddr, pfn_t *pfn) { - long ret; - struct linear_c *lc = ti->private; - struct block_device *bdev = lc->dev->bdev; - struct dax_device *dax_dev = lc->dev->dax_dev; - sector_t dev_sector, sector = pgoff * PAGE_SECTORS; - - dev_sector = linear_map_sector(ti, sector); - ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages * PAGE_SIZE, &pgoff); - if (ret) - return ret; + struct dax_device *dax_dev = linear_dax_pgoff(ti, &pgoff); + return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn); } static size_t linear_dax_copy_from_iter(struct dm_target *ti, pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i) { - struct linear_c *lc = ti->private; - struct block_device *bdev = lc->dev->bdev; - struct dax_device *dax_dev = lc->dev->dax_dev; - sector_t dev_sector, sector = pgoff * PAGE_SECTORS; + struct dax_device *dax_dev = linear_dax_pgoff(ti, &pgoff); - dev_sector = linear_map_sector(ti, sector); - if (bdev_dax_pgoff(bdev, dev_sector, ALIGN(bytes, PAGE_SIZE), &pgoff)) - return 0; return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i); } static size_t linear_dax_copy_to_iter(struct dm_target *ti, pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i) { - struct linear_c *lc = ti->private; - struct block_device *bdev = lc->dev->bdev; - struct dax_device *dax_dev = lc->dev->dax_dev; - sector_t dev_sector, sector = pgoff * PAGE_SECTORS; + struct dax_device *dax_dev = linear_dax_pgoff(ti, &pgoff); - dev_sector = linear_map_sector(ti, sector); - if (bdev_dax_pgoff(bdev, dev_sector, ALIGN(bytes, PAGE_SIZE), &pgoff)) - return 0; return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i); } static int linear_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff, size_t nr_pages) { - int ret; - struct linear_c *lc = ti->private; - struct block_device *bdev = lc->dev->bdev; - struct dax_device *dax_dev = lc->dev->dax_dev; - sector_t dev_sector, sector = pgoff * PAGE_SECTORS; - - dev_sector = linear_map_sector(ti, sector); - ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages << PAGE_SHIFT, &pgoff); - if (ret) - return ret; + struct dax_device *dax_dev = linear_dax_pgoff(ti, &pgoff); + return dax_zero_page_range(dax_dev, pgoff, nr_pages); } -- 2.30.2