Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3390904pxb; Mon, 25 Jan 2021 15:05:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUVigFem6mfCetSFKFR0vxjacXH3/dd4RmiRE7ce9yummbmGrp/LqdPryjLzNNagZ9IWua X-Received: by 2002:a05:6402:184b:: with SMTP id v11mr2353471edy.47.1611615944236; Mon, 25 Jan 2021 15:05:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611615944; cv=none; d=google.com; s=arc-20160816; b=zJ4S3iYv1OfFDdOFt2p1KxyuDm5Mm9FcpL/HeoA90BvywWGoSZ7omWd8Qe7tmsiD13 U5qRTmZGslRPCavNCfI91L+V+6jtuw5n3wLdOOQ9AcVefcP78HJfHT9W9bcMXP4P966o K2HWGWobwqjdu+owf8IEx50rz7rizRDQZf/bDWUXaX/yKX77bMvT7fXga9IiceiyTPs2 cO2l7Rmt0ZGIEP4lTJEuFA/uF5tHdzG6LeyVjv+AFM1TJiw4hxEO8rClZoIdEjXZ+oxl DDb7SMYPiJMUA3aVXUw6yL/w4tpq9Px4Pcomhld+QUpW3DF0q7Tin0Ee5uRbOfmzZkdb fLXg== 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=oJAgQ9cHFLL7vf90dnJZZC3eEu7rXoxF7bBOk5wTrR8=; b=q0WnIMtLc+IKpBN2xNAje0CeZmyE1x84paBOcWrxQL5isRMfEoNUjcerAMql2Yd6H6 mSRfafzzierU5wNfItw8VrtfEwKzX5uNpfOeB5xIONWKCCFXrDZFt3aBGOx1z+oEwMSd nJxoWON6cNuqeItL3gnO+04UOKjva2qjRCQSLTIE9JlTotpuOWhPa9FjGgwJAgarBGcu J4o6jBbB2cUXQGpjwSz5pnMCXercZk+/lSMDBzOD4iz7igWEQ4HcNUAfI7sIj6FtRw4i lX3A0oAEsBRIyf7YEW2MspjNz21LRepVHCmH7EFCpEX545bPj8/F04Me46CER4q9nq1Q 9xqA== 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 s9si6367680ejc.752.2021.01.25.15.05.19; Mon, 25 Jan 2021 15:05:44 -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 S1732651AbhAYXDc (ORCPT + 99 others); Mon, 25 Jan 2021 18:03:32 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:41443 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732659AbhAYW4n (ORCPT ); Mon, 25 Jan 2021 17:56:43 -0500 X-IronPort-AV: E=Sophos;i="5.79,374,1602518400"; d="scan'208";a="103820573" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Jan 2021 06:55:38 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id A142F4CE6031; Tue, 26 Jan 2021 06:55:38 +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; Tue, 26 Jan 2021 06:55:37 +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; Tue, 26 Jan 2021 06:55:36 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , , , Subject: [PATCH v2 07/10] dm: Introduce ->rmap() to find bdev offset Date: Tue, 26 Jan 2021 06:55:23 +0800 Message-ID: <20210125225526.1048877-8-ruansy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210125225526.1048877-1-ruansy.fnst@cn.fujitsu.com> References: <20210125225526.1048877-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: A142F4CE6031.A9CC7 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 Pmem device could be a target of mapped device. In order to obtain superblock on the mapped device, we introduce this to translate offset from target device to md device. Currently, we implement it on linear target, which is easy to do the translation. Other targets will be supported in the future. However, some targets may not support it because of the non-linear mapping. Signed-off-by: Shiyang Ruan --- drivers/md/dm-linear.c | 20 ++++++++++++++++++++ include/linux/device-mapper.h | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index 00774b5d7668..90fdb4700afd 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c @@ -5,6 +5,7 @@ */ #include "dm.h" +#include "dm-core.h" #include #include #include @@ -119,6 +120,24 @@ static void linear_status(struct dm_target *ti, status_type_t type, } } +static int linear_rmap(struct dm_target *ti, sector_t offset, + rmap_callout_fn fn, void *data) +{ + struct linear_c *lc = (struct linear_c *) ti->private; + struct mapped_device *md = ti->table->md; + struct block_device *bdev; + sector_t disk_sect = offset - dm_target_offset(ti, lc->start); + int rc = -ENODEV; + + bdev = bdget_disk_sector(md->disk, offset); + if (!bdev) + return rc; + + rc = fn(ti, bdev, disk_sect, data); + bdput(bdev); + return rc; +} + static int linear_prepare_ioctl(struct dm_target *ti, struct block_device **bdev) { struct linear_c *lc = (struct linear_c *) ti->private; @@ -238,6 +257,7 @@ static struct target_type linear_target = { .ctr = linear_ctr, .dtr = linear_dtr, .map = linear_map, + .rmap = linear_rmap, .status = linear_status, .prepare_ioctl = linear_prepare_ioctl, .iterate_devices = linear_iterate_devices, diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 61a66fb8ebb3..c5cd1009a08d 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -58,6 +58,10 @@ typedef void (*dm_dtr_fn) (struct dm_target *ti); * = 2: The target wants to push back the io */ typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio); +typedef int (*rmap_callout_fn) (struct dm_target *ti, struct block_device *bdev, + sector_t sect, void *data); +typedef int (*dm_rmap_fn) (struct dm_target *ti, sector_t offset, + rmap_callout_fn fn, void *data); typedef int (*dm_clone_and_map_request_fn) (struct dm_target *ti, struct request *rq, union map_info *map_context, @@ -175,6 +179,7 @@ struct target_type { dm_ctr_fn ctr; dm_dtr_fn dtr; dm_map_fn map; + dm_rmap_fn rmap; dm_clone_and_map_request_fn clone_and_map_rq; dm_release_clone_request_fn release_clone_rq; dm_endio_fn end_io; -- 2.30.0