Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp717871pxj; Thu, 3 Jun 2021 18:21:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzONLtHZ7GbShM+ZLHPzKYkmInnPqVdS4X5VRGo+zwfCpGv67//E+ihja2dO9TC+zohFsIz X-Received: by 2002:aa7:db95:: with SMTP id u21mr2140525edt.152.1622769701781; Thu, 03 Jun 2021 18:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622769701; cv=none; d=google.com; s=arc-20160816; b=ubKQzESS21C0snu0iUxLkyxKmgVicCDkSugL++zBDrlCBH6KWiM/SMX/WHmLzuABLh PTV2EX0ggAxoCtx1VSpsr0HyM0i7lyyka1ceS/BvMHFVa4/NtF6w19AFbx6se+pFOCCK NwMsc8HZiBv3F0cILKfXcAgDU0ID8NXlzd/2vFefRBIhQIQaSUuB7q5dGUWsr5N9bBBz d6nJTXhuELWEWB4yawYREgvpTNuAjZK6todAKXa/iNhiWEw+eNAWROnfIvLvDfvl+wIY VLa18ewmABgfPW/sg9FSfSJZjrTDuSGmwiw1FqFiMTy7JhWJYLuOmiYom49ryQQ0KLra ondw== 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=ZtvkJhnJWaJjjoPhWVhtkMPUNj8B07XI7DGQ7UBKdAE=; b=Hl2D+yNNHKjCuyhjwTPe7utqFxQUbabS7gGRwsbuqW8OeGlu8EItyfbmwVik+aSrMI z6fggRKnnywrRVuX4IGytxnVRo2ir/a5u7B5gyR0nQsQI4YaJ6jK6+YE3jjU1Fdpo+NV XhIioPd+GFE7dXiM++zKknHB+jSXS9NF/a19J503I4+eKm5XCAvEeaw+1+wGwX1OO6iW JKd9a2czBXecmR4G3zJ2gkquNZvIQYHgXbloW2WEack1rkYvCLvDnoEiPyNRTo26q7ny cRKSPMGuq3lAR3Sb/Qk+83dWuUulD8Nwn3SJO7rh+2zfGss6cnePvNlIZ0MR8sEU0qy7 b/Ig== 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 u21si3431606edy.178.2021.06.03.18.21.19; Thu, 03 Jun 2021 18:21:41 -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 S230111AbhFDBVD (ORCPT + 99 others); Thu, 3 Jun 2021 21:21:03 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:12799 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230075AbhFDBU7 (ORCPT ); Thu, 3 Jun 2021 21:20:59 -0400 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3ASN1Snq5yCRqqVPqEvgPXwCzXdLJyesId70hD?= =?us-ascii?q?6qhwISY6TiX+rbHJoB17726MtN9/YhEdcLy7VJVoBEmskKKdgrNhWotKPjOW21?= =?us-ascii?q?dARbsKheCJrgEIWReOktK1vp0AT0ERMrLN5CBB/KTHCReDYqsd6ejC4Ka1nv3f?= =?us-ascii?q?0nsoaQlrbptr5wB/Bh3zKDwMeCB2QYo+CIGH5tdK4x6peXEsZMy9AXUfG8fZod?= =?us-ascii?q?mjruOdXTc2Qw4g9BKVjS6lrJrzEx2j1B8YVD9VhZcOmFK16zDE2g=3D=3D?= X-IronPort-AV: E=Sophos;i="5.83,246,1616428800"; d="scan'208";a="109209814" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Jun 2021 09:19:13 +0800 Received: from G08CNEXMBPEKD06.g08.fujitsu.local (unknown [10.167.33.206]) by cn.fujitsu.com (Postfix) with ESMTP id DCB934C369E0; Fri, 4 Jun 2021 09:19:12 +0800 (CST) Received: from G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) by G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 4 Jun 2021 09:19:09 +0800 Received: from irides.mr.mr.mr (10.167.225.141) by G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 4 Jun 2021 09:19:07 +0800 From: Shiyang Ruan To: , , , , , CC: , , , , , , Subject: [PATCH v4 07/10] dm: Introduce ->rmap() to find bdev offset Date: Fri, 4 Jun 2021 09:18:41 +0800 Message-ID: <20210604011844.1756145-8-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210604011844.1756145-1-ruansy.fnst@fujitsu.com> References: <20210604011844.1756145-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: DCB934C369E0.A20ED 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 Pmem device could be a target of mapped device. In order to find out the global location on a mapped device, we introduce this to translate offset from target device to mapped 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 92db0f5e7f28..f9f9bc765ba7 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; @@ -236,6 +255,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 ff700fb6ce1d..89a893565407 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, @@ -184,6 +188,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.31.1