From patchwork Mon May 1 17:53:10 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: 9706763 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 C2F8D602B5 for ; Mon, 1 May 2017 17:53:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8070208C2 for ; Mon, 1 May 2017 17:53:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACBBD2808F; Mon, 1 May 2017 17:53:57 +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 35621208C2 for ; Mon, 1 May 2017 17:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750731AbdEARx4 (ORCPT ); Mon, 1 May 2017 13:53:56 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:42560 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750703AbdEARxz (ORCPT ); Mon, 1 May 2017 13:53:55 -0400 X-IronPort-AV: E=Sophos;i="5.37,401,1488816000"; d="scan'208";a="14501930" Received: from mail-bl2nam02lp0087.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([207.46.163.87]) by ob1.hgst.iphmx.com with ESMTP; 02 May 2017 01:53:55 +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=22C1YpFunsVOinUM/AZDs8MYCQMM2KQXz4T63P9d3yQ=; b=REU7u1mcmGjgkFKN53JwXVs4QSBEzkYJhOErZ55kJMO8S54HmnrSN1omO3xsFMYjQMsIj5kJiW3vMGH9lRG8KL7WHGvaeMgLDx6Sd3xh7jR4EH1bCgn+XAuahIwxjzJ13UZfoTn01YN2uI8O6GYpYsIrUCZ101e8TYGWBCtSl2c= 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 BL2PR04MB1971.namprd04.prod.outlook.com (10.167.97.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1047.13; Mon, 1 May 2017 17:53:50 +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 v2 06/10] dm: Introduce dm_remap_zone_report() Date: Tue, 2 May 2017 02:53:10 +0900 Message-Id: <20170501175314.10922-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170501175314.10922-1-damien.lemoal@wdc.com> References: <20170501175314.10922-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-Originating-IP: [199.255.44.173] X-ClientProxiedBy: BN6PR1301CA0002.namprd13.prod.outlook.com (10.174.84.143) To BL2PR04MB1971.namprd04.prod.outlook.com (10.167.97.143) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f82d4c7a-0f26-4f31-2042-08d490bb0786 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201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Hrj1mJ4R7/GXKPCY78dM0yC78CCq+KUVwbJTL24uLD/iB+WSJKCaFTop50blwc2IhdysX2O/z3pmWNdEu7Lwo6RciJNkJ+IWNuakc6mQ3cTNTj8ZXjMXnl/P; 20:gVavowr+rZWtSbyrZssC2wkXVw1C1QoENIeCFZjSzZhtEzxwn1EzpksfGq93oNLhDkZu+OCZoHQelegRecqaFI/dEm8PJGi5PbG17YM5G7hqUqO3f3wv1hVn+vw5TOFfYRTd6StaiYq6CZIp3QpM1ikO93Y2Aen20oF39E4t0HFflwMS3whC3jnpGzPak/F/LrkVEABpBoWY9pBU9CE1TWG4KQGwA3JTdmgNzzRt/XTS+TD4e4j6jj2Xc4XD29jdCUpM0mRPGpuVBPXhJaYLVoEcYwhnBXVHCHBlmHHNpDAkNWHEBn1LTTcLN7Te0gx5nHgc8swcoElu/gu6t1BZORA92sEMMvirpI07nj1vjY1c5pGnSXzmCElDDrFCKMvlS3GyfxvXvGPlJn8aCAGOWypmtCIcF+lVQq9uTxo7sBaXdusOCkafGLh4MTv8Mzu/CNtbmcpUY/oLMIiGTgFpDv6H/MBmxqVxQYH5XGq8xIFP0QatNJoJ6bYQscHm2A3Q 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)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123555025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(20161123562025)(6072148); SRVR:BL2PR04MB1971; BCL:0; PCL:0; RULEID:; SRVR:BL2PR04MB1971; X-Microsoft-Exchange-Diagnostics: 1; BL2PR04MB1971; 4:fRExMsmi52vjZBv1xKZhh1zHfZXt2ec22ig3MW2pVtEcBPGKmlIP5496dDRhnQjESIwg8+pLuvlqE+IW3ZUh2ZACmoZXJlWV7ZzlvUiRLYlErp+lLovN7S9JcER15wh65XeZOU1yj6QYf/UAeD7D611DQuy8PCAoWYchz6TupJmqmhWohYFLivihmRRqVcbAZlg9II7wLAdrA7p7kBpgqRGmhEvrtIKn3JkCtVhhySjfIY8M2xJR0AKM7QCV2PoNJYbH80l1WoFYZu8Pe7gy20qI6dSIv12kEqobgswp/YVtmLSs2lnUwTF4QXFq/+hkzfQ9+ga9mg99QAr1dleWZksA7giv0dFYEAjatWSnLdORhcq+wT9IHkDLnSjzrYkrQ1O9w/F1Mshoz2yvtsPsS/4dvJbJkmTs529OhB7uW9TuYMOUOjQeg6ENWjpwxyLvxM848v30K/qaVeYwA64ZaP9Zltx75cfjk+lzykUu2A2wAJz/jtY2bnKWABQdqhAT36BEfKE8YohQG0LQRaUtoJltJoX6gYQKiN1Nyy6rsICLnmGe+DhRjZwe6EHdH5SXFv03Qae/mlPlCVBBMHmpP046XYxfU4eimXbCj7R9m3g3fBV+aGbQS3BFgYS2JSyOJnZpsxFjZsr+pvA6zjZ+hSdiMvkftsqlSdN7+Oio2awuUaBnqnCAs35DeDWWWcPKL/YpWefZRCBZbZLT+XCb/uWEsZT0mRwRKQ68jnix8pk= X-Forefront-PRVS: 02945962BD X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39450400003)(39840400002)(39860400002)(39400400002)(39410400002)(39850400002)(2950100002)(47776003)(50226002)(85782001)(25786009)(42186005)(7736002)(5660300001)(6636002)(305945005)(81166006)(6116002)(3846002)(8676002)(33646002)(54906002)(6666003)(53936002)(6486002)(9686003)(189998001)(6512007)(86362001)(1076002)(50466002)(2906002)(38730400002)(48376002)(4326008)(36756003)(76176999)(508600001)(50986999)(85772001); DIR:OUT; SFP:1102; SCL:1; SRVR:BL2PR04MB1971; H:washi.fujisawa.hgst.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BL2PR04MB1971; 23:ghKvmzQxo+F9NZ7jEuPI45KkoCz5kJben1f4dF28y?= =?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iagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BL2PR04MB1971; 7:ttOZ6mFleO9ydnGv6XeRuYxXV8ke7jovuQ1t1LVtCwvwC8MlYtYEOVI0eKy748tmHh5K3VE9MZUBDv36rfhEtL1LUqdDMlm+ihas+ka/SAPhvXYrS6CZGXNCP5fQyEkj5PoT+B2WfvbHZx4a1YHaUYUudvTfXcmGgo1uFsXMCuFgra2JilTmbLerTVKCjlQUQGpPbnEGuK0mp9e+Ki8is9BFjOuCtN8JMarU22Eb0R+eHtYkMEzSSg7otWqEC+EbRGb+EIZ6dZS+2B2FLP7DaC4ydJEVvlWY7qQgAjpd9sNGb9sV3i2A/mqIZbE7SXj8Hte1Z/0S7QOYjIs7owOW7g==; 20:2dj1wlEL8qPDqTMq8aDEdjZgiqViksGOwgsBxUwzXw4TP9BmP7UsU4nGex6qL1l010ag5+GUTQ4OY2/vkFKYTBmXQneTDQ12x7ubCIgbQOAxJU/zbqnp9A33A+2pKJBeJncvh/VuR0JogqafL3nOvFdPrLq7P1LrRtlj1HaGkEo= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2017 17:53:50.4190 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR04MB1971 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 Reviewed-by: Hannes Reinecke --- 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);