From patchwork Tue May 25 21:24:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12280223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 867D5C4707F for ; Tue, 25 May 2021 21:25:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7081B6138C for ; Tue, 25 May 2021 21:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229976AbhEYV0p (ORCPT ); Tue, 25 May 2021 17:26:45 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36441 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232769AbhEYV0n (ORCPT ); Tue, 25 May 2021 17:26:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621977913; x=1653513913; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=nT50xLpTVaUfz/iFvC58nOvFcskAeykP4XiHqrg6BYc=; b=AVciql1xolgsuhbZefhuINRA9UsZm8S/W7Dw3rRnRRuXyaEnRLE5ME42 YyU+L4ANk1TSjTx7t2OFwqc3lSTGQ+GoffhlyaNORfLweuqspHJddsqFh Sqm/upGWpiGiUHE768u/YfdmFsRf3LACcR61FzNaNrzW/scApUFCdZ00q W9fX8WacCgPgd2bDSbC0PsLS6zM5N5ZiTtW3LpUF0zj1HKlRoYb/pUizw xx0S7tv7y6HzkhFkpRILAzcR0oZ6M3YaKsJsXgBRwihu6b2UwTIQWuaWT jaP7PHwrqQKubAEwW98aThsioIW8mlc1MM36PZ4bU6D7r4wB6PvIqCtlH g==; IronPort-SDR: BdvODX2bm1vmNdq63o5lWOP9rKWvSp7X69+3PwiBmG3cKPgz/KjBZi3Q9OyuhSxPOEG3Vff9UA 6649B+HSNFN5Vc95uW5Pyuw6lY99OzyyfURcpHV0w/39NFpf5iHG1hF4K/seigBCp4oVG4+Kw8 XubBUfBYcqE7oAglN8Fwfp6gBE1K0rvZGp5JqDl6DEd/sUALvZ9xkzoY6ahZ5M4scp8wgHN7Er WM31Ap+nd2YC9g+ITQNPcZC35AchUd5nDAsg5UTxoYah94phVZdHd1eIkHyhYvTUIcumtbvfom 3rk= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717533" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:12 +0800 IronPort-SDR: q3OB0VnTgV4jiCRqR+hG+bOiSTPzsltpssU6FtUqo8vLuNGpYaAPYV8Ix+w5wHQJGSlkfRKzzH OVgO+icH09CFBIPu3SxWZ7d8VaFXcXWj/HjJ4gO7iUuKM6ZNY/uWcZZyXOQmA27vZx7ugQGAr3 pFOcf2dAtqQJk6HTIMVbVVL2SNa97Q/sLHD5lVf8WGnl3i/IJss2k/dUmBdpH+swev/rmf3pUE jAQhZ1vTxYXzjRSBVNBHbWohr2Ppz1MUM3rPmMPGPshK/iZgob+hoZgc2wO7DMuAkWS96fb2Zv jYCMp/rtd6iujrQqDLyGajFG Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:40 -0700 IronPort-SDR: 8cS/GDNZrClTdleFDrLru3OBcppNA7XH7h94rIzbghBh8hgaS9NSlzHJgUaL3pm3ATTWbe1+zn pmvnWYsQkP7IZZRFh/C/o5nyuWZjXYqOUcsITS+vUCzX9aJeMlMeexFIn98C0dSE/K/Rn6dKMX sVtGzAJopMZ7A1qBwEGoVP3MWE+W3Nf8h+iL90djMtsIK2yBBeqqoz/v9Ens5YRUCSnfvsHLlI S149d8GcGZeACDv+pfWQF/XPnnxbiNJ/HOQIN3wLvEz9dLPyvvOTYrgOC/N4Sa5/qaHuO/N4nS lZQ= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:12 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 07/11] dm: Introduce dm_report_zones() Date: Wed, 26 May 2021 06:24:57 +0900 Message-Id: <20210525212501.226888-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org To simplify the implementation of the report_zones operation of a zoned target, introduce the function dm_report_zones() to set a target mapping start sector in struct dm_report_zones_args and call blkdev_report_zones(). This new function is exported and the report zones callback function dm_report_zones_cb() is not. dm-linear, dm-flakey and dm-crypt are modified to use dm_report_zones(). Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Reviewed-by: Himanshu Madhani --- drivers/md/dm-crypt.c | 7 +++---- drivers/md/dm-flakey.c | 7 +++---- drivers/md/dm-linear.c | 7 +++---- drivers/md/dm-zone.c | 23 ++++++++++++++++++++--- include/linux/device-mapper.h | 3 ++- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index b0ab080f2567..f410ceee51d7 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -3138,11 +3138,10 @@ static int crypt_report_zones(struct dm_target *ti, struct dm_report_zones_args *args, unsigned int nr_zones) { struct crypt_config *cc = ti->private; - sector_t sector = cc->start + dm_target_offset(ti, args->next_sector); - args->start = cc->start; - return blkdev_report_zones(cc->dev->bdev, sector, nr_zones, - dm_report_zones_cb, args); + return dm_report_zones(cc->dev->bdev, cc->start, + cc->start + dm_target_offset(ti, args->next_sector), + args, nr_zones); } #else #define crypt_report_zones NULL diff --git a/drivers/md/dm-flakey.c b/drivers/md/dm-flakey.c index b7fee9936f05..5877220c01ed 100644 --- a/drivers/md/dm-flakey.c +++ b/drivers/md/dm-flakey.c @@ -463,11 +463,10 @@ static int flakey_report_zones(struct dm_target *ti, struct dm_report_zones_args *args, unsigned int nr_zones) { struct flakey_c *fc = ti->private; - sector_t sector = flakey_map_sector(ti, args->next_sector); - args->start = fc->start; - return blkdev_report_zones(fc->dev->bdev, sector, nr_zones, - dm_report_zones_cb, args); + return dm_report_zones(fc->dev->bdev, fc->start, + flakey_map_sector(ti, args->next_sector), + args, nr_zones); } #else #define flakey_report_zones NULL diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index 92db0f5e7f28..c91f1e2e2f65 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c @@ -140,11 +140,10 @@ static int linear_report_zones(struct dm_target *ti, struct dm_report_zones_args *args, unsigned int nr_zones) { struct linear_c *lc = ti->private; - sector_t sector = linear_map_sector(ti, args->next_sector); - args->start = lc->start; - return blkdev_report_zones(lc->dev->bdev, sector, nr_zones, - dm_report_zones_cb, args); + return dm_report_zones(lc->dev->bdev, lc->start, + linear_map_sector(ti, args->next_sector), + args, nr_zones); } #else #define linear_report_zones NULL diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c index 3243c42b7951..b42474043249 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -56,7 +56,8 @@ int dm_blk_report_zones(struct gendisk *disk, sector_t sector, return ret; } -int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data) +static int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, + void *data) { struct dm_report_zones_args *args = data; sector_t sector_diff = args->tgt->begin - args->start; @@ -84,7 +85,24 @@ int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data) args->next_sector = zone->start + zone->len; return args->orig_cb(zone, args->zone_idx++, args->orig_data); } -EXPORT_SYMBOL_GPL(dm_report_zones_cb); + +/* + * Helper for drivers of zoned targets to implement struct target_type + * report_zones operation. + */ +int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector, + struct dm_report_zones_args *args, unsigned int nr_zones) +{ + /* + * Set the target mapping start sector first so that + * dm_report_zones_cb() can correctly remap zone information. + */ + args->start = start; + + return blkdev_report_zones(bdev, sector, nr_zones, + dm_report_zones_cb, args); +} +EXPORT_SYMBOL_GPL(dm_report_zones); void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) { @@ -99,4 +117,3 @@ void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) WARN_ON_ONCE(queue_is_mq(q)); q->nr_zones = blkdev_nr_zones(t->md->disk); } - diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index ff700fb6ce1d..caea0a079d2d 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -478,7 +478,8 @@ struct dm_report_zones_args { /* must be filled by ->report_zones before calling dm_report_zones_cb */ sector_t start; }; -int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data); +int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector, + struct dm_report_zones_args *args, unsigned int nr_zones); #endif /* CONFIG_BLK_DEV_ZONED */ /*