From patchwork Fri Apr 21 03:55:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 9691723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5CF6D6037F for ; Fri, 21 Apr 2017 03:56:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5065228334 for ; Fri, 21 Apr 2017 03:56:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44EF4285E4; Fri, 21 Apr 2017 03:56:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B85E1285E6 for ; Fri, 21 Apr 2017 03:56:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1035034AbdDUD4e (ORCPT ); Thu, 20 Apr 2017 23:56:34 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:22545 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1035033AbdDUD4c (ORCPT ); Thu, 20 Apr 2017 23:56:32 -0400 X-IronPort-AV: E=Sophos;i="5.37,228,1488816000"; d="scan'208";a="12700238" Received: from mail-bl2nam02lp0085.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([207.46.163.85]) by ob1.hgst.iphmx.com with ESMTP; 21 Apr 2017 11:56:31 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=unVIyYoH2vjrhR5awWz2BiWJpPSrF8mIvkQqM7B4SPY=; b=etUzenNskkGi3tJB6OvOcJ/6lmoX5zpIkFE1VpXIckX1HawZFG6Lb5kixBZJKMOo+rg4YCoahIj3okf0wnzkwH/ISzNFLLO0WAMAr8y8N8gtXt8GQn/xZQAJFU0LuEdmd6FPP7q/Mcdvo0i7mGKuOirqUtlISbfSLHflTS9CpMA= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=wdc.com; Received: from washi.fujisawa.hgst.com (199.255.44.173) by SN1PR04MB1983.namprd04.prod.outlook.com (10.166.69.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.10; Fri, 21 Apr 2017 03:56:27 +0000 From: damien.lemoal@wdc.com To: dm-devel@redhat.com, Mike Snitzer , Alasdair Kergon Cc: Hannes Reinecke , Christoph Hellwig , Bart Van Assche , linux-block@vger.kernel.org, Damien Le Moal Subject: [PATCH 06/10] dm: Introduce dm_remap_zone_report() Date: Fri, 21 Apr 2017 12:55:54 +0900 Message-Id: <20170421035558.2657-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170421035558.2657-1-damien.lemoal@wdc.com> References: <20170421035558.2657-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-Originating-IP: [199.255.44.173] X-ClientProxiedBy: MWHPR10CA0052.namprd10.prod.outlook.com (10.169.238.14) To SN1PR04MB1983.namprd04.prod.outlook.com (10.166.69.143) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7a74685c-42b9-4f3c-c0c4-08d4886a63e4 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:SN1PR04MB1983; X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1983; 3:I4JaYUa+TdJmJ3jqlwNzfoHGxHlq+C8SfXcA4xmusp425sUISM620fy73Ml29qOIPWeOLi2XjeGwRTRIaOdCTqeZlKQrZo7+I8EYEUVtZFOvJy/v5EAXKVyzJyFYSGMCCkatLmgEUM3Rii5ruI3FHpPK4JR/FpuwACtS9p7OQ+vP80uFVoheAV3mOM+HBo9qglLJt3FuBj8P96tP4idJrft+HxFSxa2GC01TZjiHvlit7ruSmhOGJ9oe7pHtkw5WhmfHQaUHFtQzIWKaaWfHOgTdpCuZloO+iADh7sxLHNDBnuR2oJIWp7n28aHt1RHdIm7ZjCqSuOEAVLk1tIhuho3dcwK8TxuBTF2eLmV0l4k=; 25:xdsjinlFlCh/lLMXCaoE/012k8nfXIqQDz+Nz1FYoolrF9NWNMMjkVoTx/BQ9/ORAIPKoOpOQUxXJdZl8fnuT3YjdApoNUXt75Bc2YMxCQ8v6YQLdV8gwIOCJQWnGeAtY9YroCYGt/iv9LLzYMl0PCL3wsSeimr2CJe3mFz1xGVQpi+cqLqipYWcb0fGyhEGh0uBk+80DCBX4VrC8pc05TRifzIcHtUztXoznC6lxgJ3T64LOPk10+sGg8YfhjyoskUkspNKkQlJSPSOHPWNdMbvd3/PL6YKOAP0EkfN8T/LUW7XcGkmjg0wWB83brCoSR2JPrTfuGQ4hu3inR4OKDYWLOd7LwN9ZyWJTTbLr9LOF6UKGF5Bt4cNx2wjCgY9TlmbKLQ/mwBxkzbpEOzYlmltWWdbhzole8m2/ary4rrukQOGNjbXxR5E3kOyPkgwG2liC0EyeXY3qIMYTIwtaw== X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1983; 31:B52+kS5EjSOM2ekI8lIIJMm6pskvG1Na2LvM0QpW07M1It932Q5YCi/STA2zsycl7XAhoiC2RQHyQG+cpmT8MTjaaX0OU0EmjcpemqM8UtlHxPCvApDrWQc9S690LYFBEAnN1P1hld1B0cAcQ9sxIUS7A0h0oKEnAJfuQDLUdoZZqm9sgMG9Aj45HNCb+ezGhFDjiYMBgPJmYfamPcG1UeYNy7/tl/NLaKYJ1ynnoEJFBf6tZ3BAHq92uGJq1kyR; 20:4ID1QZv/XfVOAGUkQnI6YaxvmAQTLCoXwNPU7tWB8caMDYUqPK1YFhbLhX6e9VQq+qJvzWxN+RXtQETELhgF3lByoXMNSb4zNXjg1Qsa5qUe863XrOMS+VxebIv6k6d0+8DMzZTBI9Ct0fSZWgi+c4oX8mjCSAlXTXPI0zZBuKEkALVYoBkaFP4D+BEDgAnHCADwaKNSjv7nURPQKIL2HGOcSMAs7cXTzbAUr1NTbfX2vpst6FHVKlL2YfVOekAHwugJMpC01z8dmnahcGNlFsKsE2M1AKulL5QFMsm0++zwYlT4lGvnLQ5HuNECpXIXjRls1fFLfgXnVBEeQJ7A8AsbaSeeOCsl8y6L36KNHR1to6+gaugjZwj71OocM3ckqmg3nG9IOFD3JKOD6so/r8tmPMY5WCXBCIq6gQL6P0pe0nrNsPgAaZQWUJp2RwJz2vJ2+pcksth8GYMtlvbZEFPsczHgI6eMAKu2dS7OLE/aXoCC0m2YAyzpGSFs8j14 WDCIPOUTBOUND: EOP-TRUE X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041248)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123555025)(6072148); SRVR:SN1PR04MB1983; BCL:0; PCL:0; RULEID:; SRVR:SN1PR04MB1983; X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1983; 4:Yf6/+wb7yHFttjc4n/nd0fUpStFc9yL7Cif9qhOWt1pm6kVsr+EKhLXAMC8WcEoaABRjKSsZwcMSOtgLa8h3ovq8Jk0IHmXDMbazWND6XRNqeEFX5yzLcmVNCJyZSDEP3JuAd0bEzHwMFYHJhnB36nl75G8uNx9dWYaL7hz6Odbmb0vcPk5tGn0kgOaZRX5MRNhujsLbZt7GsWmJjBnJJoBVcoO94+AY1jUr8lkf8Jbm7+ocS5Mf3o56cswe8RbYOfWhajjyAxQFILtnACLekeDLenrzxWP7oRE7je7KtC9rbpQf0s0Uyhrpup6LwRo73LtqjdOEamzfX1pjPn2uC4etKfoCFRdFfbpN7RbP5c407U/hkjQKfJi+rYVQoqcrhGGoLdNy0sRKis6yTTjVYuJro7uE13aiiZSeKobkkSAcUhoNqSHzLQiPhvt7hEvgp16Sm4ml2NqQGVjOXDRg2XIyvtwYBzwLf3aEfWFDnwPmgBEiSm8Q5EjOXfHO8594ItE6QRb6DCt6VVKUJ7NzUYE6V508aHDNnS787ZhDTqq3KFZ0ZeApXeokyTaRUDLzcmY2E/10RgPXcEWzvAw50/6/cGJWc3HfK5dfsjIjKAx7VlUdzRWYhwBQ99iW/MdRsCbUaLrlLiB7/0THRYABseKJnNu7y7QyE9rn+XcnQErlkjr8ve5RZLY0OUoS1cHrG87t3VjiaNlrVHndawf/ME+72M+X1x3upUg+ULcmnhk= X-Forefront-PRVS: 02843AA9E0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39400400002)(39850400002)(39450400003)(39840400002)(39860400002)(39410400002)(8676002)(5003940100001)(50466002)(48376002)(3846002)(2906002)(38730400002)(6116002)(36756003)(86362001)(4326008)(50226002)(1076002)(6636002)(2950100002)(6666003)(6486002)(305945005)(6512007)(53936002)(47776003)(66066001)(50986999)(54906002)(189998001)(5660300001)(76176999)(85782001)(7736002)(9686003)(33646002)(25786009)(42186005)(85772001); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR04MB1983; H:washi.fujisawa.hgst.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR04MB1983; 23:l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r7szsaNSs4dyfeuFsBU6KEaxnOYAB3MeSEgEB7te8TXOxhOY8A= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1983; 7:DhHf7JVOCTzgh8wvLVHKDpDTe4ks8YtmTcCpvJ1B8nVmp2I+AJqpUIhNzi0vaEvBbbkervQ7fOLYca5EJgk+3v2t8ve9r9Rh7uAm/Pc8PjMTsGMTSnv1Z9LcECvIL+FTCDV5T3KFVcQ/L1UcR9+4s8wJwBeGqXWrekr8gDYBS6M77yImfaBx8dSlhYrIqaoU1c9MeLti5vArPuNDaBJ8ghIosPiK/VJOfcVOUaZXetFQJY3g/WAMJnu5cO8nWmay6QDWxoV8GjCLAooNFhA4sozRHVPfGElj+MxR59guYZHPXgKIowjxNSDpnzctkiVmWPBYe9PP19BUNU0XYqCxAg==; 20:CULsB3efDmaBs7CScFJP7tWYLpC37mESSpHA134mDP9yYN0DxLM6xeoBJGWDeuYPpynlJAJ5A0Gyxli3vN/3hP+jfHYyy3rye3XiG26PGXEwRZdcusHdmRjij9c6bvJE77bQ6wzeN8eDxB/sZqPQFGgxSN+wWyDKYx4HQo8C7Tw= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2017 03:56:27.0003 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR04MB1983 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Damien Le Moal A target driver support zoned block devices and exposing it as such may receive REQ_OP_ZONE_REPORT request for the user to determine the mapped device zone configuration. To process properly such request, the target driver may need to remap the zone descriptors provided in the report reply. The helper function dm_remap_zone_report() does this generically using only the target start offset and length and the start offset within the target device. dm_remap_zone_report() will remap the start sector of all zones reported. If the report includes sequential zones, the write pointer position of these zones will also be remapped. Signed-off-by: Damien Le Moal --- drivers/md/dm.c | 80 +++++++++++++++++++++++++++++++++++++++++++ include/linux/device-mapper.h | 10 ++++++ 2 files changed, 90 insertions(+) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index cd44928..1f6558e 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -975,6 +975,86 @@ void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors) } EXPORT_SYMBOL_GPL(dm_accept_partial_bio); +#ifdef CONFIG_BLK_DEV_ZONED +/* + * The zone descriptors obtained with a zone report indicate + * zone positions within the target device. The zone descriptors + * must be remapped to match their position within the dm device. + * A target may call dm_remap_zone_report after completion of a + * REQ_OP_ZONE_REPORT bio to remap the zone descriptors obtained + * from the target device mapping to the dm device. + */ +void dm_remap_zone_report(struct dm_target *ti, struct bio *bio, sector_t start) +{ + struct dm_target_io *tio = + container_of(bio, struct dm_target_io, clone); + struct bio *report_bio = tio->io->bio; + struct blk_zone_report_hdr *hdr = NULL; + struct blk_zone *zone; + unsigned int nr_rep = 0; + unsigned int ofst; + struct bio_vec bvec; + struct bvec_iter iter; + void *addr; + + if (bio->bi_error) + return; + + /* + * Remap the start sector of the reported zones. For sequential zones, + * also remap the write pointer position. + */ + bio_for_each_segment(bvec, report_bio, iter) { + + addr = kmap_atomic(bvec.bv_page); + + /* Remember the report header in the first page */ + if (!hdr) { + hdr = addr; + ofst = sizeof(struct blk_zone_report_hdr); + } else { + ofst = 0; + } + + /* Set zones start sector */ + while (hdr->nr_zones && ofst < bvec.bv_len) { + zone = addr + ofst; + if (zone->start >= start + ti->len) { + hdr->nr_zones = 0; + break; + } + zone->start = zone->start + ti->begin - start; + if (zone->type != BLK_ZONE_TYPE_CONVENTIONAL) { + if (zone->cond == BLK_ZONE_COND_FULL) + zone->wp = zone->start + zone->len; + else if (zone->cond == BLK_ZONE_COND_EMPTY) + zone->wp = zone->start; + else + zone->wp = zone->wp + ti->begin - start; + } + ofst += sizeof(struct blk_zone); + hdr->nr_zones--; + nr_rep++; + } + + if (addr != hdr) + kunmap_atomic(addr); + + if (!hdr->nr_zones) + break; + + } + + if (hdr) { + hdr->nr_zones = nr_rep; + kunmap_atomic(hdr); + } + + bio_advance(report_bio, report_bio->bi_iter.bi_size); +} +EXPORT_SYMBOL_GPL(dm_remap_zone_report); +#endif + /* * Flush current->bio_list when the target map method blocks. * This fixes deadlocks in snapshot and possibly in other targets. diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index b3c2408..d21c761 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -433,6 +433,16 @@ struct gendisk *dm_disk(struct mapped_device *md); int dm_suspended(struct dm_target *ti); int dm_noflush_suspending(struct dm_target *ti); void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors); +#ifdef CONFIG_BLK_DEV_ZONED +void dm_remap_zone_report(struct dm_target *ti, struct bio *bio, + sector_t start); +#else +static inline void dm_remap_zone_report(struct dm_target *ti, struct bio *bio, + sector_t start) +{ + bio->bi_error = -ENOTSUPP; +} +#endif union map_info *dm_get_rq_mapinfo(struct request *rq); struct queue_limits *dm_get_queue_limits(struct mapped_device *md);