From patchwork Thu Apr 9 16:53:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11482003 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE0B4112C for ; Thu, 9 Apr 2020 16:54:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F9C920769 for ; Thu, 9 Apr 2020 16:54:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="P2/zFD0X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727356AbgDIQyA (ORCPT ); Thu, 9 Apr 2020 12:54:00 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24703 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726574AbgDIQx6 (ORCPT ); Thu, 9 Apr 2020 12:53:58 -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=1586451239; x=1617987239; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iOKpbr1Ka1cFGP35Fa6ZTxHG0mbfjgFm55pfw0HfVbo=; b=P2/zFD0XRhKEHw2DhdA1ySHhuykUn/Ggwr7k/gXPT3C9zK7BNjgmk+MY YgHqTTiuwvsXdEeeGhOvNiqf3esqBmNtCyk5yyThZaFGMYMfUAmsi+wYY PGl/SnCCum3z3aPrrbPonh/RtzU0Ifg6BvBqFn1KSwOtEw3uJ4uEwhBsk d94JRjOx0cVM94/R2fNCeQ26kuhdnCW4915IBaeGaY9h3Pa7fUYjSuDmX MrYgwBFXJ6Clawq4X+9aiDtFHmXhsZJYK7BpA5qq2kWBabdkSuEy7vSsO QIFheExhU/GS7lVHMVSzUfN5j8AeGsK4kTJkdpCgtg/LRoh+lbRUJ8DEZ w==; IronPort-SDR: iJkOb4ytwAaMAZ7e8LPuQg+2ksngj1pprsZkRGC6S2CMCOU5R9WevybjgIpyrKWOqOXRDOaCPk 760bhhXq4CQZ+CAi8QJJYOCxvy8hBaP9wZEFpGubu8XcvY3EZM0DmH/d9b4o5hSdw9WJpvsj33 a15laxfKXc64jKFU+EMaY8QbkR95ICh4u8J8BMhyw6Ts/t0FvN7juPJ/zb8o8qi1Y9MrleEme0 vHv/PoxBzl9k32X3i+CD89sRjVOyNpC3Puus6zP/wM/pyuTtmcxrMoFfgX9Aw/vZjN4pB/ACzj 33U= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="136423680" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 00:53:58 +0800 IronPort-SDR: r/oUsgegiTSuR34SZs+7bM010dbkAG1hey2nAz2UbCcykImeY4d3jAOYu4UWz8P1grJ4BTs4J3 9rAo0rZSm3vg7YoGbDVob9bormSWiN/49shStiQh8SPiZ2W6bLHAvw+/mWBmQzLq6g9E4Bl794 cT8p+PWP+8ojOkkqnvEKt1FUdukQy3uu0qO/UP0UneQIrlzMLYhDfWOZdqou6dNSciRtMxodRP xewG07cfyvdLuwthxn6I5f3klezl4zwNDPlVPbshqOUdTsrTjuDA3J4vIUlTaOFFVE/SR5iwZn EsO2jXTHHhmGqCou5rhNlT1Z Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 09:44:37 -0700 IronPort-SDR: dUIaPq6/IiqFECkhaVWoIem7bAFfhsBVnKQAfuAtSF6kAmP1YC8fedu+jHy1xukLrxEPWityHU zBQfcsOH/v0M/oEEG38W9ooHZrGt7ACmY7EAoBjlJyJHZOAZw9p/eLMaNo5uWn5DTQEBYcqD1T C24+hm1PrlRtPkIjBMc1W+Af2U3DyRIjORRt670Li5zzZtQboCr0Rp6z0qec8YMxfIFtdvLAFG zGYGmSlfvtsCTevfIP7FhYf3cBdsW8CHDy2r6qAaSNXNXFBldYDjBmR+96RlVDDFzu4ZlXDcuk PS8= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 09:53:57 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v5 01/10] block: provide fallbacks for blk_queue_zone_is_seq and blk_queue_zone_no Date: Fri, 10 Apr 2020 01:53:43 +0900 Message-Id: <20200409165352.2126-2-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200409165352.2126-1-johannes.thumshirn@wdc.com> References: <20200409165352.2126-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org blk_queue_zone_is_seq() and blk_queue_zone_no() have not been called with CONFIG_BLK_DEV_ZONED disabled until now. The introduction of REQ_OP_ZONE_APPEND will change this, so we need to provide noop fallbacks for the !CONFIG_BLK_DEV_ZONED case. Signed-off-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig --- include/linux/blkdev.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index f629d40c645c..25b63f714619 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -729,6 +729,16 @@ static inline unsigned int blk_queue_nr_zones(struct request_queue *q) { return 0; } +static inline bool blk_queue_zone_is_seq(struct request_queue *q, + sector_t sector) +{ + return false; +} +static inline unsigned int blk_queue_zone_no(struct request_queue *q, + sector_t sector) +{ + return 0; +} #endif /* CONFIG_BLK_DEV_ZONED */ static inline bool rq_is_sync(struct request *rq) From patchwork Thu Apr 9 16:53:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11482007 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D85A17D4 for ; Thu, 9 Apr 2020 16:54:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1555E20769 for ; Thu, 9 Apr 2020 16:54:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nKF6bzme" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727461AbgDIQyA (ORCPT ); Thu, 9 Apr 2020 12:54:00 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24703 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727235AbgDIQyA (ORCPT ); Thu, 9 Apr 2020 12:54:00 -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=1586451240; x=1617987240; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vAO2UxWgIo/N3O/CCwYSSyzR+tIlfSM1uEVc2K+9RKg=; b=nKF6bzmeNfKP7ev7Aky/bhBQNSkzqeImQK2GpQHMD9pQOz5OZ962czWj zFlht0U2csdP1F/xllFu1kfVzsMLTyOUWh0ZJFXz9hG25cL8mckI4ZAwu icgyeAe/4Wa17C1dEw2HspKdButAo/Ud88erlR8NpV4HwVIpc4FXUrdd8 zM4EJgJFJCO7k00tkn4ojJJ1s6gFZX0Bjtp202v15tj5RzrOBRwNzFOfH cUlwLycTODscsqFW0XaSwMz9PJKdXP3Uc/WYhRdzCT0TgJQsEgJuct0v5 Ei8xNZf9BBwYLRtYzNIo2sY6qm6Hl+QjIV8h+IVDRpfw3lVQy/U0fP16n g==; IronPort-SDR: 7Q5VSZndslkkLIMx+HGSPYvyIVhifKL+yfo9Np7VK9BykEAASpIDkhPOvRCDk37aWkha0yOV13 XePnvRBa/jEDRpqr0W07hJTOhz/n9wQ9nunlp0uYnCPwFadc0CopBjS5NmyCeLVpkwZqgJerwl 8P8rgayRT46+S/zODsgrXHW15UYIr2WpVj+BOs1K01hogRBP7w2JDXrgXmuvO4OQju40ExQnHY xhVEsk/xdEFrqfGRCRa9bMkZvANt6iSOy2gPzhUNBrW3dimUhVbL9LEx+scDRQMkrM6QJkiHI4 I3Y= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="136423682" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 00:54:00 +0800 IronPort-SDR: V1GaOGT8D4GFbfnUVpnxp0Mi8UCHM/a5qdwRQUTv3TMhncvVUBUZjlRuoXKl1hCrLZSnmx05nD TerQ+liF8VgE1k6NVjyofZhZ8fNFP7OgmSrD97K4ebFzRuPANtuGb+rF/sTnk5LEk77B/sV25o +u47hcFMHOBhUYySZLGpuhOPfb+xljyCayOFNRPr/ZdCUrL2Sj53qPnqc9Of/2bj+s+zZenkKB or+k6VixRw+Zm7lqsYCoCGdTbZnRwVO6+1Sib2h3bSD+YdLZWhPG1rNKQtqd1OPo+hvsBklF8d eHuSxtlpnP7WV0CUmcwEuceF Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 09:44:39 -0700 IronPort-SDR: 2wE+jqrME+00wdphR5HXRA4dDAhJcTh4SzNnaifBOIHSljndofEQTtE5O1Ysw7iFfxeB+pqvPj vOWAJwdNSjHlvSJ5ZbgmLe6k6NH4e/6gJyXhA2LVePY2OsbMQkWtpWAjE5SuQX4VkIAysnR4UH UguOkB8RjkSVoSsRRyzwQfPoaglCdlTxPWjJ8Dxs8pEBLmlpQyXfWUhSB3127zFmJNOfWa0Tm5 j6gh/I8W8EWCdqHK+P7oZ3+Rprg87Y8f5BLYON10kA6a0cLAdIZL0KVy3Z7FljOXCbU7ajX6xl /2o= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 09:53:59 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Johannes Thumshirn Subject: [PATCH v5 02/10] block: Introduce REQ_OP_ZONE_APPEND Date: Fri, 10 Apr 2020 01:53:44 +0900 Message-Id: <20200409165352.2126-3-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200409165352.2126-1-johannes.thumshirn@wdc.com> References: <20200409165352.2126-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Keith Busch Define REQ_OP_ZONE_APPEND to append-write sectors to a zone of a zoned block device. This is a no-merge write operation. A zone append write BIO must: * Target a zoned block device * Have a sector position indicating the start sector of the target zone * The target zone must be a sequential write zone * The BIO must not cross a zone boundary * The BIO size must not be split to ensure that a single range of LBAs is written with a single command. Implement these checks in generic_make_request_checks() using the helper function blk_check_zone_append(). To avoid write append BIO splitting, introduce the new max_zone_append_sectors queue limit attribute and ensure that a BIO size is always lower than this limit. Export this new limit through sysfs and check these limits in bio_full(). Also when a LLDD can't dispatch a request to a specific zone, it will return BLK_STS_ZONE_RESOURCE indicating this request needs to be delayed, e.g. because the zone it will be dispatched to is still write-locked. If this happens set the request aside in a local list to continue trying dispatching requests such as READ requests or a WRITE/ZONE_APPEND requests targetting other zones. This way we can still keep a high queue depth without starving other requests even if one request can't be served due to zone write-locking. Finally, make sure that the bio sector position indicates the actual write position as indicated by the device on completion. Signed-off-by: Keith Busch [ jth: added zone-append specific add_page and merge_page helpers ] Signed-off-by: Johannes Thumshirn --- Changes to v4: - fix page merging for zone-append bios - remove unneeded variable --- block/bio.c | 70 +++++++++++++++++++++++++++++++++++++-- block/blk-core.c | 52 +++++++++++++++++++++++++++++ block/blk-mq.c | 27 +++++++++++++++ block/blk-settings.c | 23 +++++++++++++ block/blk-sysfs.c | 13 ++++++++ drivers/scsi/scsi_lib.c | 1 + include/linux/blk_types.h | 14 ++++++++ include/linux/blkdev.h | 11 ++++++ 8 files changed, 209 insertions(+), 2 deletions(-) diff --git a/block/bio.c b/block/bio.c index 94d697217887..689f31357d30 100644 --- a/block/bio.c +++ b/block/bio.c @@ -679,6 +679,54 @@ struct bio *bio_clone_fast(struct bio *bio, gfp_t gfp_mask, struct bio_set *bs) } EXPORT_SYMBOL(bio_clone_fast); +static bool bio_try_merge_zone_append_page(struct bio *bio, struct page *page, + unsigned int len, unsigned int off, + bool *same_page) +{ + struct request_queue *q = bio->bi_disk->queue; + struct bio_vec *bv; + unsigned long mask = queue_segment_boundary(q); + phys_addr_t addr1, addr2; + + if (bio->bi_vcnt < 1) + return false; + + bv = &bio->bi_io_vec[bio->bi_vcnt - 1]; + + addr1 = page_to_phys(bv->bv_page) + bv->bv_offset; + addr2 = page_to_phys(page) + off + len - 1; + + if ((addr1 | mask) != (addr2 | mask)) + return false; + if (bv->bv_len + len > queue_max_segment_size(q)) + return false; + return __bio_try_merge_page(bio, page, len, off, same_page); +} + +static int bio_add_append_page(struct bio *bio, struct page *page, unsigned len, + size_t offset) +{ + struct request_queue *q = bio->bi_disk->queue; + unsigned int max_append_sectors = queue_max_zone_append_sectors(q); + bool same_page = false; + + if (WARN_ON_ONCE(!max_append_sectors)) + return 0; + + if (((bio->bi_iter.bi_size + len) >> 9) > max_append_sectors) + return 0; + + if (bio_try_merge_zone_append_page(bio, page, len, offset, &same_page)) + return len; + + if (bio->bi_vcnt >= queue_max_segments(q)) + return 0; + + __bio_add_page(bio, page, len, offset); + + return len; +} + static inline bool page_is_mergeable(const struct bio_vec *bv, struct page *page, unsigned int len, unsigned int off, bool *same_page) @@ -944,8 +992,22 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) struct page *page = pages[i]; len = min_t(size_t, PAGE_SIZE - offset, left); - - if (__bio_try_merge_page(bio, page, len, offset, &same_page)) { + if (bio_op(bio) == REQ_OP_ZONE_APPEND) { + int ret; + + if (bio_try_merge_zone_append_page(bio, page, len, + offset, + &same_page)) { + if (same_page) + put_page(page); + } else { + ret = bio_add_append_page(bio, page, len, + offset); + if (ret != len) + return -EINVAL; + } + } else if (__bio_try_merge_page(bio, page, len, offset, + &same_page)) { if (same_page) put_page(page); } else { @@ -1895,6 +1957,10 @@ struct bio *bio_split(struct bio *bio, int sectors, BUG_ON(sectors <= 0); BUG_ON(sectors >= bio_sectors(bio)); + /* Zone append commands cannot be split */ + if (WARN_ON_ONCE(bio_op(bio) == REQ_OP_ZONE_APPEND)) + return NULL; + split = bio_clone_fast(bio, gfp, bs); if (!split) return NULL; diff --git a/block/blk-core.c b/block/blk-core.c index 60dc9552ef8d..57127092d816 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -135,6 +135,7 @@ static const char *const blk_op_name[] = { REQ_OP_NAME(ZONE_OPEN), REQ_OP_NAME(ZONE_CLOSE), REQ_OP_NAME(ZONE_FINISH), + REQ_OP_NAME(ZONE_APPEND), REQ_OP_NAME(WRITE_SAME), REQ_OP_NAME(WRITE_ZEROES), REQ_OP_NAME(SCSI_IN), @@ -240,6 +241,17 @@ static void req_bio_endio(struct request *rq, struct bio *bio, bio_advance(bio, nbytes); + if (req_op(rq) == REQ_OP_ZONE_APPEND && error == BLK_STS_OK) { + /* + * Partial zone append completions cannot be supported as the + * BIO fragments may end up not being written sequentially. + */ + if (bio->bi_iter.bi_size) + bio->bi_status = BLK_STS_IOERR; + else + bio->bi_iter.bi_sector = rq->__sector; + } + /* don't actually finish bio if it's part of flush sequence */ if (bio->bi_iter.bi_size == 0 && !(rq->rq_flags & RQF_FLUSH_SEQ)) bio_endio(bio); @@ -865,6 +877,41 @@ static inline int blk_partition_remap(struct bio *bio) return ret; } +/* + * Check write append to a zoned block device. + */ +static inline blk_status_t blk_check_zone_append(struct request_queue *q, + struct bio *bio) +{ + sector_t pos = bio->bi_iter.bi_sector; + int nr_sectors = bio_sectors(bio); + + /* Only applicable to zoned block devices */ + if (!blk_queue_is_zoned(q)) + return BLK_STS_NOTSUPP; + + /* The bio sector must point to the start of a sequential zone */ + if (pos & (blk_queue_zone_sectors(q) - 1) || + !blk_queue_zone_is_seq(q, pos)) + return BLK_STS_IOERR; + + /* + * Not allowed to cross zone boundaries. Otherwise, the BIO will be + * split and could result in non-contiguous sectors being written in + * different zones. + */ + if (blk_queue_zone_no(q, pos) != blk_queue_zone_no(q, pos + nr_sectors)) + return BLK_STS_IOERR; + + /* Make sure the BIO is small enough and will not get split */ + if (nr_sectors > q->limits.max_zone_append_sectors) + return BLK_STS_IOERR; + + bio->bi_opf |= REQ_NOMERGE; + + return BLK_STS_OK; +} + static noinline_for_stack bool generic_make_request_checks(struct bio *bio) { @@ -937,6 +984,11 @@ generic_make_request_checks(struct bio *bio) if (!q->limits.max_write_same_sectors) goto not_supported; break; + case REQ_OP_ZONE_APPEND: + status = blk_check_zone_append(q, bio); + if (status != BLK_STS_OK) + goto end_io; + break; case REQ_OP_ZONE_RESET: case REQ_OP_ZONE_OPEN: case REQ_OP_ZONE_CLOSE: diff --git a/block/blk-mq.c b/block/blk-mq.c index d92088dec6c3..ce60a071660f 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1178,6 +1178,19 @@ static void blk_mq_update_dispatch_busy(struct blk_mq_hw_ctx *hctx, bool busy) #define BLK_MQ_RESOURCE_DELAY 3 /* ms units */ +static void blk_mq_handle_zone_resource(struct request *rq, + struct list_head *zone_list) +{ + /* + * If we end up here it is because we cannot dispatch a request to a + * specific zone due to LLD level zone-write locking or other zone + * related resource not being available. In this case, set the request + * aside in zone_list for retrying it later. + */ + list_add(&rq->queuelist, zone_list); + __blk_mq_requeue_request(rq); +} + /* * Returns true if we did some work AND can potentially do more. */ @@ -1189,6 +1202,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, bool no_tag = false; int errors, queued; blk_status_t ret = BLK_STS_OK; + LIST_HEAD(zone_list); if (list_empty(list)) return false; @@ -1257,6 +1271,16 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, list_add(&rq->queuelist, list); __blk_mq_requeue_request(rq); break; + } else if (ret == BLK_STS_ZONE_RESOURCE) { + /* + * Move the request to zone_list and keep going through + * the dispatch list to find more requests the drive can + * accept. + */ + blk_mq_handle_zone_resource(rq, &zone_list); + if (list_empty(list)) + break; + continue; } if (unlikely(ret != BLK_STS_OK)) { @@ -1268,6 +1292,9 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, queued++; } while (!list_empty(list)); + if (!list_empty(&zone_list)) + list_splice_tail_init(&zone_list, list); + hctx->dispatched[queued_to_index(queued)]++; /* diff --git a/block/blk-settings.c b/block/blk-settings.c index c8eda2e7b91e..5388965841df 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -48,6 +48,7 @@ void blk_set_default_limits(struct queue_limits *lim) lim->chunk_sectors = 0; lim->max_write_same_sectors = 0; lim->max_write_zeroes_sectors = 0; + lim->max_zone_append_sectors = 0; lim->max_discard_sectors = 0; lim->max_hw_discard_sectors = 0; lim->discard_granularity = 0; @@ -83,6 +84,7 @@ void blk_set_stacking_limits(struct queue_limits *lim) lim->max_dev_sectors = UINT_MAX; lim->max_write_same_sectors = UINT_MAX; lim->max_write_zeroes_sectors = UINT_MAX; + lim->max_zone_append_sectors = UINT_MAX; } EXPORT_SYMBOL(blk_set_stacking_limits); @@ -257,6 +259,25 @@ void blk_queue_max_write_zeroes_sectors(struct request_queue *q, } EXPORT_SYMBOL(blk_queue_max_write_zeroes_sectors); +/** + * blk_queue_max_zone_append_sectors - set max sectors for a single zone append + * @q: the request queue for the device + * @max_zone_append_sectors: maximum number of sectors to write per command + **/ +void blk_queue_max_zone_append_sectors(struct request_queue *q, + unsigned int max_zone_append_sectors) +{ + unsigned int max_sectors; + + max_sectors = min(q->limits.max_hw_sectors, max_zone_append_sectors); + if (max_sectors) + max_sectors = min_not_zero(q->limits.chunk_sectors, + max_sectors); + + q->limits.max_zone_append_sectors = max_sectors; +} +EXPORT_SYMBOL_GPL(blk_queue_max_zone_append_sectors); + /** * blk_queue_max_segments - set max hw segments for a request for this queue * @q: the request queue for the device @@ -506,6 +527,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, b->max_write_same_sectors); t->max_write_zeroes_sectors = min(t->max_write_zeroes_sectors, b->max_write_zeroes_sectors); + t->max_zone_append_sectors = min(t->max_zone_append_sectors, + b->max_zone_append_sectors); t->bounce_pfn = min_not_zero(t->bounce_pfn, b->bounce_pfn); t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask, diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index fca9b158f4a0..02643e149d5e 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -218,6 +218,13 @@ static ssize_t queue_write_zeroes_max_show(struct request_queue *q, char *page) (unsigned long long)q->limits.max_write_zeroes_sectors << 9); } +static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page) +{ + unsigned long long max_sectors = q->limits.max_zone_append_sectors; + + return sprintf(page, "%llu\n", max_sectors << SECTOR_SHIFT); +} + static ssize_t queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) { @@ -639,6 +646,11 @@ static struct queue_sysfs_entry queue_write_zeroes_max_entry = { .show = queue_write_zeroes_max_show, }; +static struct queue_sysfs_entry queue_zone_append_max_entry = { + .attr = {.name = "zone_append_max_bytes", .mode = 0444 }, + .show = queue_zone_append_max_show, +}; + static struct queue_sysfs_entry queue_nonrot_entry = { .attr = {.name = "rotational", .mode = 0644 }, .show = queue_show_nonrot, @@ -749,6 +761,7 @@ static struct attribute *queue_attrs[] = { &queue_discard_zeroes_data_entry.attr, &queue_write_same_max_entry.attr, &queue_write_zeroes_max_entry.attr, + &queue_zone_append_max_entry.attr, &queue_nonrot_entry.attr, &queue_zoned_entry.attr, &queue_nr_zones_entry.attr, diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 610ee41fa54c..ea327f320b7f 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1706,6 +1706,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, case BLK_STS_OK: break; case BLK_STS_RESOURCE: + case BLK_STS_ZONE_RESOURCE: if (atomic_read(&sdev->device_busy) || scsi_device_blocked(sdev)) ret = BLK_STS_DEV_RESOURCE; diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 70254ae11769..824ec2d89954 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -63,6 +63,18 @@ typedef u8 __bitwise blk_status_t; */ #define BLK_STS_DEV_RESOURCE ((__force blk_status_t)13) +/* + * BLK_STS_ZONE_RESOURCE is returned from the driver to the block layer if zone + * related resources are unavailable, but the driver can guarantee the queue + * will be rerun in the future once the resources become available again. + * + * This is different from BLK_STS_DEV_RESOURCE in that it explicitly references + * a zone specific resource and IO to a different zone on the same device could + * still be served. Examples of that are zones that are write-locked, but a read + * to the same zone could be served. + */ +#define BLK_STS_ZONE_RESOURCE ((__force blk_status_t)14) + /** * blk_path_error - returns true if error may be path related * @error: status the request was completed with @@ -296,6 +308,8 @@ enum req_opf { REQ_OP_ZONE_CLOSE = 11, /* Transition a zone to full */ REQ_OP_ZONE_FINISH = 12, + /* write data at the current zone write pointer */ + REQ_OP_ZONE_APPEND = 13, /* SCSI passthrough using struct scsi_request */ REQ_OP_SCSI_IN = 32, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 25b63f714619..36111b10d514 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -336,6 +336,7 @@ struct queue_limits { unsigned int max_hw_discard_sectors; unsigned int max_write_same_sectors; unsigned int max_write_zeroes_sectors; + unsigned int max_zone_append_sectors; unsigned int discard_granularity; unsigned int discard_alignment; @@ -757,6 +758,9 @@ static inline bool rq_mergeable(struct request *rq) if (req_op(rq) == REQ_OP_WRITE_ZEROES) return false; + if (req_op(rq) == REQ_OP_ZONE_APPEND) + return false; + if (rq->cmd_flags & REQ_NOMERGE_FLAGS) return false; if (rq->rq_flags & RQF_NOMERGE_FLAGS) @@ -1088,6 +1092,8 @@ extern void blk_queue_max_write_same_sectors(struct request_queue *q, extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q, unsigned int max_write_same_sectors); extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); +extern void blk_queue_max_zone_append_sectors(struct request_queue *q, + unsigned int max_zone_append_sectors); extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); extern void blk_queue_alignment_offset(struct request_queue *q, unsigned int alignment); @@ -1301,6 +1307,11 @@ static inline unsigned int queue_max_segment_size(const struct request_queue *q) return q->limits.max_segment_size; } +static inline unsigned int queue_max_zone_append_sectors(const struct request_queue *q) +{ + return q->limits.max_zone_append_sectors; +} + static inline unsigned queue_logical_block_size(const struct request_queue *q) { int retval = 512; From patchwork Thu Apr 9 16:53:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11482017 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60B3217D4 for ; Thu, 9 Apr 2020 16:54:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 416D820769 for ; Thu, 9 Apr 2020 16:54:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="OO4BZROV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727593AbgDIQyD (ORCPT ); Thu, 9 Apr 2020 12:54:03 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24715 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727235AbgDIQyC (ORCPT ); Thu, 9 Apr 2020 12:54:02 -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=1586451242; x=1617987242; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Kvkqhedaxckecfp14XwRLXhYwHCzNuCrujz+QWt/cdU=; b=OO4BZROVvRNcUnABBTd1IjXOs7Q6IaH7MJoUx6NIXUTJdcBN1CK2RZd7 Sru2EUneMZ5GaiiEYhKerwUN3U7/AVAMiM+MQXLFX7C+hr7rMKJbZaNDw iBf72ghselhK5Lp+4R7TEdqonQOQu6eXunKAjescBmYVVC9g4y/8Mn8ql z3EB+mD2nWivbRoAJUBL84LF7xJ2k8yNQudT12WCXlLP3Ezr8evKwl+SV CFzBVHVNBC8yaQxwtJC1PzWlRja11+3vWUtvclaikxDDQL1W5rmuYwtYI iBKAefgpzoSHTKjFJGPs4kDOw5Dw3Hfk20DLkjcMJH/TTTsgMWxaKBusE Q==; IronPort-SDR: LHWTyCrSGUM+RV/6Vm6YQeV4fxxzoIoEWZ8DI3UG2VFLNnGowWlU/tAp1BTh/qAwRT9OVBib5T h6QSLuYY3lCDiRzpB3I/MM4KVdP6QPQ2eynocUCH9vGV1Ya+GG6c6OXxGfdHUvvO8H7wjqrsla 02VfONDMxPzA3r1ZqbODW+UqnntmsPtHdh+ipm53ss41RaUGj/12lO2TFYY4HLDhXLjSePgFSV 6rCFqKiCTS5agqmXDwuCRrszkOQOSoCIHJCcjcFuqPogMEJoRJCH0MxGpiPbvp+xPOBwV0iILN 9Sc= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="136423686" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 00:54:02 +0800 IronPort-SDR: aTHeFwOAkuBh8w/ohZstRT3VKliw8CPlZbw26ErdGxI0TB9bUAK6O31Y9cHPfQ6sDqOtCoASjC N4r4bjGK1s+r7W01IPY1rfLFuGH4wKNUpUatLTzqb2UsTsVTS9fWGLbw7v5LF8hmf1X1I4WpsK GcEdPVbqEscIP/8e6uRIh4HkJ6u27nmr8JrOIuHz6g7YHL1e6l9P0n/lReyRXkUjQu24WH6Rmv Tgs3GVtai9MbFg+i1F0o4ODb6JosOLhHA7R9GqY+1QnMrjybsr0Fp/8c41IqVAeacZe792N92o oo1/F01Ow7hJXX1sG1ENeFwG Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 09:44:40 -0700 IronPort-SDR: w/CnDXvbqBJ6S6wBeXOgCIFQDvwqB6LtLe6hFAbeZ/GPS3VFMkpirXCqkqq5bYxe8+KCa7y6f8 SMjANsO5TV4H5txf3HxEGgpaqBwmR0GvZTsPHBFpXNuAmp8J9lcF9355CZCovNmreUgHyxl46H dJhboJqu2YSQgnsmUwHbNrmt72FzPbNaSRhDdngfaC5izfthJW8qFrhwVd4JOZJrbTGZSffwJt Mu+iV+jVpaBUEFq/XryXH/sXz4ez8VJOWhmRBWgDO7SKIkU9/RNRIOH1ZiodgWFIZeCRT0aRJl 8a0= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 09:54:01 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v5 03/10] block: introduce blk_req_zone_write_trylock Date: Fri, 10 Apr 2020 01:53:45 +0900 Message-Id: <20200409165352.2126-4-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200409165352.2126-1-johannes.thumshirn@wdc.com> References: <20200409165352.2126-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Introduce blk_req_zone_write_trylock(), which either grabs the write-lock for a sequential zone or returns false, if the zone is already locked. Signed-off-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig --- block/blk-zoned.c | 14 ++++++++++++++ include/linux/blkdev.h | 1 + 2 files changed, 15 insertions(+) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 05741c6f618b..00b025b8b7c0 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -50,6 +50,20 @@ bool blk_req_needs_zone_write_lock(struct request *rq) } EXPORT_SYMBOL_GPL(blk_req_needs_zone_write_lock); +bool blk_req_zone_write_trylock(struct request *rq) +{ + unsigned int zno = blk_rq_zone_no(rq); + + if (test_and_set_bit(zno, rq->q->seq_zones_wlock)) + return false; + + WARN_ON_ONCE(rq->rq_flags & RQF_ZONE_WRITE_LOCKED); + rq->rq_flags |= RQF_ZONE_WRITE_LOCKED; + + return true; +} +EXPORT_SYMBOL_GPL(blk_req_zone_write_trylock); + void __blk_req_zone_write_lock(struct request *rq) { if (WARN_ON_ONCE(test_and_set_bit(blk_rq_zone_no(rq), diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 36111b10d514..e591b22ace03 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1746,6 +1746,7 @@ extern int bdev_write_page(struct block_device *, sector_t, struct page *, #ifdef CONFIG_BLK_DEV_ZONED bool blk_req_needs_zone_write_lock(struct request *rq); +bool blk_req_zone_write_trylock(struct request *rq); void __blk_req_zone_write_lock(struct request *rq); void __blk_req_zone_write_unlock(struct request *rq); From patchwork Thu Apr 9 16:53:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11482021 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 337E5112C for ; Thu, 9 Apr 2020 16:54:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0BA2C20768 for ; Thu, 9 Apr 2020 16:54:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="TLKgEHIK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727719AbgDIQyE (ORCPT ); Thu, 9 Apr 2020 12:54:04 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24715 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727235AbgDIQyD (ORCPT ); Thu, 9 Apr 2020 12:54:03 -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=1586451244; x=1617987244; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tmksEDboe4ywDTGLgmwOeM5+BOGLe3IzaNWoQ4/NHho=; b=TLKgEHIKGUdVzU4YSTG8Wk2dK/A1QXgkux0ulsnL7p/p8LM3aAtbOxDp OlbnOhnsjTsZASeb5Q5iQWdofCMY+xFitNVqSx1bfpeNn+L22arqV+ltx 8QaX+mAbpqt+mFc7i5BJZnQgRi+ScOejf7CO3YMulzuMllc23vG9qknNX z6sz3Eap2755wFTAXwKblrAMV+bUuQTrNjz/uZeA/IIMszDU9l3pz4fFV 2lwDt+O0DJe5Uvz9yXYX57RUehASRXjF52mIWAeUz8l+6eJ+BRSw6tOZW w4GoQFv+Y7V08fYB3490Q8c5qQZ22ppYmuMceedTzXV6DReIh6RKuZyrd Q==; IronPort-SDR: TZirsWmHGCcuCGDoj5OFR35AafJS0vZWlN8UIBYrZcrE6qvw1ccRDz3+hYzTyFYFzuO4tojN8h SR2Rc8hQFlVyhG1vC8kuVfWSy4pK9Sgp9jD/NK+Mv2VlDTPwWsZ/eNwF698ZgBKdkkcFejUoT0 /xw446VHCP563S3Hvw4BOw8ZgpR0X7yMzvIJynyYfisrzTHXrZ7oW/4gqeHIErXDdotCfnwjPQ XhJODxQBCSFe67Bfj0WARUJ18hy1m9ReH+pCORhSuO4L5Ajp74t5y5w5xuT6xOYzMW07SXkEg1 uu0= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="136423690" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 00:54:04 +0800 IronPort-SDR: K1jl0uT5hGMULBkUXY0Bqc54GOh6aw0sDkjwFqhvh8vmfj/M0cYhzuHLcEfNXSYZKWydflEfmw T11mQejKrFWROuUjzlQ1U3WqCOgsvvEq+6SIiwb8s6cJsseChhqcffmvFWe4Qi6BE5M8g9WXzn NMf/ABKKqWgTfnhgXaigl4bdGgZ8+w/5yhsN3AOBpVHVDEyV7W/LOQg5AnMqUP/T8MYRopr2/j SeTb4PR9lDuK9lV3/x06v4s8ncWIJsdbT8MOWu9Je74/galm7LlDfEMbjcEOPbBHC69GLP6rmM hlU9Q9CVdM6ByLZQsBJmwZD5 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 09:44:42 -0700 IronPort-SDR: Ha6lzkHwhM0BaEUUAY089ZiFimgoH32MQnUX2l0jeICoxR7PEgWC8iwb6ifLxOOwH8qg/NT/Wu TwYLYqviTFepIoCReTuO8YT7CugOPDF1OpfMfrJFe2oTKOI07OzMkwXz3JuNIhhvJUOFD4+qNV 6SPhLur+hLiN/NwVCjbtrXdVhrysBR1PeRnfMRqPoR395zIrQjwS4Rs7DT30jcWnYGeUiVI6B7 zePw/hjeHDIodPE6w6MXG1hYvU17ymAlW6+WUyImkhAMk1nbka3nogRcY38JudBgA8gKmZrNnS 8ss= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 09:54:02 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Damien Le Moal , Johannes Thumshirn Subject: [PATCH v5 04/10] block: Modify revalidate zones Date: Fri, 10 Apr 2020 01:53:46 +0900 Message-Id: <20200409165352.2126-5-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200409165352.2126-1-johannes.thumshirn@wdc.com> References: <20200409165352.2126-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Damien Le Moal Modify the interface of blk_revalidate_disk_zones() to add an optional revalidation callback function that a driver can use to extend checks and processing done during zone revalidation. The callback, if defined, is executed time after all zones are inspected and with the queue frozen. blk_revalidate_disk_zones() is renamed as __blk_revalidate_disk_zones() and blk_revalidate_disk_zones() implemented as an inline function calling __blk_revalidate_disk_zones() without no revalidation callback specified, resulting in an unchanged behavior for all callers of blk_revalidate_disk_zones(). Signed-off-by: Damien Le Moal Signed-off-by: Johannes Thumshirn --- block/blk-zoned.c | 19 ++++++++++++++----- include/linux/blkdev.h | 10 +++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 00b025b8b7c0..6c37fec6859b 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -437,20 +437,27 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, } /** - * blk_revalidate_disk_zones - (re)allocate and initialize zone bitmaps - * @disk: Target disk + * __blk_revalidate_disk_zones - (re)allocate and initialize zone bitmaps + * @disk: Target disk + * @revalidate_cb: LLD callback + * @revalidate_data: LLD callback argument * * Helper function for low-level device drivers to (re) allocate and initialize * a disk request queue zone bitmaps. This functions should normally be called * within the disk ->revalidate method for blk-mq based drivers. For BIO based * drivers only q->nr_zones needs to be updated so that the sysfs exposed value * is correct. + * If the @revalidate_cb callback function is not NULL, the callback will be + * executed with the device request queue frozen after all zones have been + * checked. */ -int blk_revalidate_disk_zones(struct gendisk *disk) +int __blk_revalidate_disk_zones(struct gendisk *disk, + revalidate_zones_cb revalidate_cb, + void *revalidate_data) { struct request_queue *q = disk->queue; struct blk_revalidate_zone_args args = { - .disk = disk, + .disk = disk, }; unsigned int noio_flag; int ret; @@ -480,6 +487,8 @@ int blk_revalidate_disk_zones(struct gendisk *disk) q->nr_zones = args.nr_zones; swap(q->seq_zones_wlock, args.seq_zones_wlock); swap(q->conv_zones_bitmap, args.conv_zones_bitmap); + if (revalidate_cb) + revalidate_cb(disk, revalidate_data); ret = 0; } else { pr_warn("%s: failed to revalidate zones\n", disk->disk_name); @@ -491,4 +500,4 @@ int blk_revalidate_disk_zones(struct gendisk *disk) kfree(args.conv_zones_bitmap); return ret; } -EXPORT_SYMBOL_GPL(blk_revalidate_disk_zones); +EXPORT_SYMBOL_GPL(__blk_revalidate_disk_zones); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index e591b22ace03..a730cacda0f7 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -353,6 +353,8 @@ struct queue_limits { typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx, void *data); +typedef void (*revalidate_zones_cb)(struct gendisk *disk, void *data); + #ifdef CONFIG_BLK_DEV_ZONED #define BLK_ALL_ZONES ((unsigned int)-1) @@ -362,7 +364,13 @@ unsigned int blkdev_nr_zones(struct gendisk *disk); extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, sector_t sectors, sector_t nr_sectors, gfp_t gfp_mask); -extern int blk_revalidate_disk_zones(struct gendisk *disk); +int __blk_revalidate_disk_zones(struct gendisk *disk, + revalidate_zones_cb revalidate_cb, + void *revalidate_data); +static inline int blk_revalidate_disk_zones(struct gendisk *disk) +{ + return __blk_revalidate_disk_zones(disk, NULL, NULL); +} extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg); From patchwork Thu Apr 9 16:53:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11482027 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17F6914B4 for ; Thu, 9 Apr 2020 16:54:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ECFB820771 for ; Thu, 9 Apr 2020 16:54:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="hsNvvNHT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727796AbgDIQyG (ORCPT ); Thu, 9 Apr 2020 12:54:06 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24715 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727235AbgDIQyF (ORCPT ); Thu, 9 Apr 2020 12:54:05 -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=1586451246; x=1617987246; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=af+TpmrNaP6opwMEPh6jKrw6Bxfh1IsevFX/PW8xfPo=; b=hsNvvNHTjsovPfvo3hCiHTDRiN58mmI6xa1IVm5PmsY0Y554GSsxLRrU a5bpZAE8A63a+Z2CL7HqCv1Hf5BgQQod3ZJPGroRykWzEcGkljgDxyom5 xYe8tRCkjgDHTd7uDKTbJXEnlAAkSkzPuwreRNdE+iyQkJACtObkt7Y2J YqJ9W3q9X/v96+fPkoZrbFVx6ZkfW66lpPxNyYexojqpupDuhXYpuQgnj wYLN+JNE5JqZ/XvCgAkkm2DGdbBe5kechpWUL31G9myWqLrglEFZUUFeY NETVDO/IquJ+c5qmnHANam6rcD8KUe3iezov37kcvPz+zkGTYgaKjJH3f w==; IronPort-SDR: SGoCgbltRKsC32MsHKc6VlUJLj78Itsn6c38gKapAqhtHleDBIGOauzn85VTdX1N+tFqeCLlIg Ux7unujbsuShrE2Q3XlfNbs8Qf3xT+bYca4cpry58Ft4PVHgeu96RCUTr0Rjc1jWMSdC73biqw yfUmy0bSPF5deEat8YbTMkFNxxtXLnQ5uLI5ivwS7R4ZVxY3tvB89VjBfKDF+2rsEIq1tnuGgb l7McOz2bftcKVu6JEqZJumHBeTnlwkvjq2aWhf0eo8Qr/Fir9JkVwxhXwTZm4dl9u46K1DF4Bk zK0= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="136423695" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 00:54:06 +0800 IronPort-SDR: 6+39GUFAAH12uu+VXz/DSKRR3pYUblPtY9sLWsQFyS4x1SEnemhNMyePwNzOwpFuGGAz5V6ylD +Klk3Qy/8VBRu0WM4l25VhIkH99UqoOeU2QWSUXbg6mXlDzuKVOIROsXDcFXfzQsdE4Nn1uHiK aHYxsEHIl00bDM6efb75oJehRyOsLhC8L2TU3XBGj7ZnQCC6nfhgWd3YbmS3RqR2mzvwQ+tW5B RlRR0JlmD5TaiXcFdGyIdHgUXXmp+9VcMAu5wmunTc9iE3jNP/l44b5WVGjBe+rw2iUGunvZj2 2hpR0KVNVHAfyxY+DgiWBk1s Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 09:44:44 -0700 IronPort-SDR: +nAtLtmGjeh9fwyAgaXidtrGP5Yf+uR8XGp8p49fIAOKF4Eb9wD/Lo9d1wRe9y3VjHbY3umxIj 9AokJG83wV4AWOdifM4Xs+33cX4OQK5WbX/N3olSaSWBf68bxD7uyHXK+pVBqNuxxvskWZ6ZLI C6n75DZRH5nz5dnGhIy9JlMdTe+d4WWSQOj904KsWpmOfUdcBKK3h9WQYMHOKJu2LSlbWGylmd mt4As2mJPRw3o9rzWz90IyI1cyQRYRqd94MHEfp2lE5MODhwFQW5XnqHjp6KN10NxSwusugQ+1 GSk= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 09:54:04 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v5 05/10] scsi: sd_zbc: factor out sanity checks for zoned commands Date: Fri, 10 Apr 2020 01:53:47 +0900 Message-Id: <20200409165352.2126-6-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200409165352.2126-1-johannes.thumshirn@wdc.com> References: <20200409165352.2126-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Factor sanity checks for zoned commands from sd_zbc_setup_zone_mgmt_cmnd(). This will help with the introduction of an emulated ZONE_APPEND command. Signed-off-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig --- drivers/scsi/sd_zbc.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index f45c22b09726..ee156fbf3780 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -209,6 +209,26 @@ int sd_zbc_report_zones(struct gendisk *disk, sector_t sector, return ret; } +static blk_status_t sd_zbc_cmnd_checks(struct scsi_cmnd *cmd) +{ + struct request *rq = cmd->request; + struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); + sector_t sector = blk_rq_pos(rq); + + if (!sd_is_zoned(sdkp)) + /* Not a zoned device */ + return BLK_STS_IOERR; + + if (sdkp->device->changed) + return BLK_STS_IOERR; + + if (sector & (sd_zbc_zone_sectors(sdkp) - 1)) + /* Unaligned request */ + return BLK_STS_IOERR; + + return BLK_STS_OK; +} + /** * sd_zbc_setup_zone_mgmt_cmnd - Prepare a zone ZBC_OUT command. The operations * can be RESET WRITE POINTER, OPEN, CLOSE or FINISH. @@ -223,20 +243,14 @@ blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd, unsigned char op, bool all) { struct request *rq = cmd->request; - struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); sector_t sector = blk_rq_pos(rq); + struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); sector_t block = sectors_to_logical(sdkp->device, sector); + blk_status_t ret; - if (!sd_is_zoned(sdkp)) - /* Not a zoned device */ - return BLK_STS_IOERR; - - if (sdkp->device->changed) - return BLK_STS_IOERR; - - if (sector & (sd_zbc_zone_sectors(sdkp) - 1)) - /* Unaligned request */ - return BLK_STS_IOERR; + ret = sd_zbc_cmnd_checks(cmd); + if (ret != BLK_STS_OK) + return ret; cmd->cmd_len = 16; memset(cmd->cmnd, 0, cmd->cmd_len); From patchwork Thu Apr 9 16:53:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11482047 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9EFE3112C for ; Thu, 9 Apr 2020 16:54:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8049C20771 for ; Thu, 9 Apr 2020 16:54:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="iJLQiagG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727824AbgDIQyK (ORCPT ); Thu, 9 Apr 2020 12:54:10 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24715 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727235AbgDIQyH (ORCPT ); Thu, 9 Apr 2020 12:54:07 -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=1586451247; x=1617987247; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q++7tLiMOyjklktmG5UM9qExxC1QYLaiR3sPHhtXviQ=; b=iJLQiagGiYDY5NYzRSfWltaFaj9UmEfVL58I3l2kZ3AKyx+8YTlSGxIh jyafYE189o+FhiKjyKPgna8h9dYeVaAltJnSjHD/pDu5AEU8YRrlk9Db3 A/DiFM3oKmYIgCYCA+0V7g+y1zO2WnUiCAd5DTuEaj/ChKhFBJLZJPLvD AqXzXesaARtsaZIGV4u/HQUrVff+D5LmNkZso/1MA6DfrUqh0DpbqP9uD b0qdVkQapvyGIaGLAPsRHaEfKgzq82hykmnsAS1FpmBt84tHKFdf0Trx7 UCn3ylb0f5vmQ4CdXJQ9x+bX4I/VwUTexLII/0fsc+EQMwnheuDqaaoRQ Q==; IronPort-SDR: HXPaPfkK95IBcn6lbT98CIrqVtLGfKXa0/iXI+S08PcfqJ0Dy/n6wOM3GMj4zuD2yKCV9lL0xv LzkgN9L4264gZhPF1J73TrUNM+CzZeFVph2hq/QlNYTT6kLp6xTkmySKZfnVeTomxN5aUvGwue eN4Y3K0iQZRw62MoZkOw1HNjaktXRiDSB4+qDmlG90fwTDfLliUqvl/9s8qrnrlyLM0lUc7oL6 AQk1uKRy0/sidFkbUFp2MvKoo4SJlHSaTxEjzJ4ODARiM0UaW8OoMDPlECO4Kp46r3NOr5R5xi oK4= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="136423697" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 00:54:07 +0800 IronPort-SDR: Fau621jWYy6tQZ7S25GWwtivGduaB8ZHT3i9AhgIdDOkBVU2emVvyQ+s3wPi/tLYuJaUoEXQEV XVhte+26SNYRnwId/HG66MydHFCzEm6ET2zuemrPE9UTkykv63aFjgWmy2aOKIEUlsVyvvIG66 44YK7Rsq+fiDK8KPqds/hKg0F5Tsgc9U9tFHhcLEl97Ig4HBog7N/SUxTj8pr45Waf8MhAuNaa 6zkkH0sbZ8WeGC2EmjkZPN8gDDcy/A25SBF7YXI7LoaVHFbJviY2hc8cjtsfgSvuGxPjvWTaIH HS1KDqSxEUImH20I5QXdrbxn Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 09:44:46 -0700 IronPort-SDR: oeDJliF9+Gc5BrpOJzUUaj+cFpnU6A2fmoukfsV4u746HazOKY4LIbyIk6CW4GEAV0Irfz9M9c Eche1Dn4C4/sBkgNa9sYfR77o403hL9EfEcEyQnhlwoxompSuMI6OLUgdmmKJXkSm5Df0aIgKV uC8pL6ubm7PnEySMqdITeKxiAUSObR5EWJbKpaKeFNpI8OHnhoYUfp9BJU0bXHHhitvYFmfAHH FU7UyRV38Wwcdxie5LACm7TW5dgFYu/xWIGbsXRk+6xvNX0xKnRAIgGjSe6Ca8PgHVBTMB/zUW d8I= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 09:54:06 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Johannes Thumshirn Subject: [PATCH v5 06/10] scsi: export scsi_mq_free_sgtables Date: Fri, 10 Apr 2020 01:53:48 +0900 Message-Id: <20200409165352.2126-7-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200409165352.2126-1-johannes.thumshirn@wdc.com> References: <20200409165352.2126-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org scsi_mq_free_sgtables is used to free the sg_tables, uninitialize the command and delete it from the command list. Export this function so it can be used from modular code to free the memory allocated by scsi_init_io() if the caller of scsi_init_io() needs to do error recovery. While we're at it, rename scsi_mq_free_sgtables() to scsi_free_sgtables(). Signed-off-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig Reviewed-by: Bart Van Assche --- Changes to v4: - Export scsi_mq_free_sgtables() instead of scsi_mq_uninit_cmnd() --- drivers/scsi/scsi_lib.c | 7 ++++--- include/scsi/scsi_cmnd.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index ea327f320b7f..b6b3ccd366da 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -548,7 +548,7 @@ static void scsi_uninit_cmd(struct scsi_cmnd *cmd) } } -static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd) +void scsi_free_sgtables(struct scsi_cmnd *cmd) { if (cmd->sdb.table.nents) sg_free_table_chained(&cmd->sdb.table, @@ -557,10 +557,11 @@ static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd) sg_free_table_chained(&cmd->prot_sdb->table, SCSI_INLINE_PROT_SG_CNT); } +EXPORT_SYMBOL_GPL(scsi_free_sgtables); static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd) { - scsi_mq_free_sgtables(cmd); + scsi_free_sgtables(cmd); scsi_uninit_cmd(cmd); scsi_del_cmd_from_list(cmd); } @@ -1060,7 +1061,7 @@ blk_status_t scsi_init_io(struct scsi_cmnd *cmd) return BLK_STS_OK; out_free_sgtables: - scsi_mq_free_sgtables(cmd); + scsi_free_sgtables(cmd); return ret; } EXPORT_SYMBOL(scsi_init_io); diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index a2849bb9cd19..a6383ced6156 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -167,6 +167,7 @@ extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count, extern void scsi_kunmap_atomic_sg(void *virt); extern blk_status_t scsi_init_io(struct scsi_cmnd *cmd); +extern void scsi_free_sgtables(struct scsi_cmnd *cmd); #ifdef CONFIG_SCSI_DMA extern int scsi_dma_map(struct scsi_cmnd *cmd); From patchwork Thu Apr 9 16:53:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11482035 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E8C717D4 for ; Thu, 9 Apr 2020 16:54:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D237E20769 for ; Thu, 9 Apr 2020 16:54:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="KSUdKd68" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727865AbgDIQyK (ORCPT ); Thu, 9 Apr 2020 12:54:10 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24726 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727805AbgDIQyJ (ORCPT ); Thu, 9 Apr 2020 12:54:09 -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=1586451249; x=1617987249; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qIvWO0GqOHIB6x27skdRFKVK2VQiM5tZJhbZ0U64gxQ=; b=KSUdKd68VbGErNPtPV+YNGRYJhiOuK92pRfpFHe0CFFKC13FVtpSzFv0 n+uJ4brgYDKLebFA312VNC/CZKsR8zK7t7SL6iqfWHaWIw1Oz3hq1Qfr5 pUMKwOPZRv2c9hMJE0tENOhLDzSX4kviwAak4XaJWJPFnyWTcAVJ3uh26 R7L5jamAZkDKtAk3uGlQpxW9eHOpa6JbIKviHhni7g+cxeVihOAIGlnUM y2WpPfuDnHnFvM9deKc8NOBmAbo6s13aemtn1NvlChSvgp9nnw9yzxnsY XXTqNevatIoM+dKx2fZo0uq/XpHd5sBt/H+IMLsbxbwxq+00xSCELlDJL g==; IronPort-SDR: EarXTEFxWJC+0r6LhRkxSnkwz+iv8w+2qtWZbrVYAAC7E40PZsqvzfSiV1ku8ZO3z5NbFcvSYG a/HRMiceyqOVqH4GWmy02wsMYl+lqSxJn3MYA/LVaqO5yxI5MmP1PsSLIokfbK9W7n3QmvF1/J I9L5TFw0UoHrYmtOLUeZd9n2QJqEJa+rmynGkvITNK/nuHVNtx4CIl/jrnd/I6RinD0TRz0pAQ Ub9IjaDiXpR91QUEPea/kyZyEaRy0RvZ+lfFLc3dNj3wboVdmI6Dzy1AWbLX4CrfvgOLfRWP/A V44= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="136423699" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 00:54:09 +0800 IronPort-SDR: vdCiNezYKjsCwzqW4qe/yc9yfK8EjPfc916ncXyAPMmBMAWkOupffIsYxnSx7vZMJBmuproGYE hZQnO2fwRGmBI5cljcYWiwCm+2p75NhW8axTvLXIrC6ro86minf7xnsunvjo6Wngrxn4A/sPBX r6pdvWU2u5S48hnPVW6vOzTZ3S8IXKxu2xRbVtCHBru0aj+NYTWefeZAPuTny4W2M30yPqDrwX 1xxuXS9pWFUI/w6VRzay5/w8GgEHK05lzPL9znJ/kO8yuB1aAbGIVtjeElNvAnuGLI2ee71wHs kJXm/bxz0tMft6dAMZ5aqBOT Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 09:44:47 -0700 IronPort-SDR: YGgozoajRJnDj93LHFq1H8jLHyDxoeHMlehfvLygRq7qHX1QTWB8MMMQhfOwQodvWfu2mh4YAf X7sVK5UwI/0qhy05yTcH3w3H12KoFjJIoRxsKRqDTjMabLHkYsVv2b0nlCIz1opFf49DI48Gv2 6qDjUfy9x3XSBqNz2HFgTrIHMU0Ge+7PjfVflAQMe9l1z73gmHMFPe2ZcgkY3tdgQI+j8H/wIt N9cphoUG/j66pzXVmQWj9q981C2YDSWredZ4hCTD4LNNmzq4Co0X2xu9eJOElJoxJgFyhmCix8 6u4= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 09:54:08 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Johannes Thumshirn Subject: [PATCH v5 07/10] scsi: sd_zbc: emulate ZONE_APPEND commands Date: Fri, 10 Apr 2020 01:53:49 +0900 Message-Id: <20200409165352.2126-8-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200409165352.2126-1-johannes.thumshirn@wdc.com> References: <20200409165352.2126-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Emulate ZONE_APPEND for SCSI disks using a regular WRITE(16) with a start LBA set to the target zone write pointer position. In order to always know the write pointer position of a sequential write zone, the queue flag QUEUE_FLAG_ZONE_WP_OFST is set to get an initialized write pointer offset array attached to the device request queue. The values of the cache are maintained in sync with the device as follows: 1) the write pointer offset of a zone is reset to 0 when a REQ_OP_ZONE_RESET command completes. 2) the write pointer offset of a zone is set to the zone size when a REQ_OP_ZONE_FINISH command completes. 3) the write pointer offset of a zone is incremented by the number of 512B sectors written when a write or a zone append command completes 4) the write pointer offset of all zones is reset to 0 when a REQ_OP_ZONE_RESET_ALL command completes. Since the block layer does not write lock zones for zone append commands, to ensure a sequential ordering of the write commands used for the emulation, the target zone of a zone append command is locked when the function sd_zbc_prepare_zone_append() is called from sd_setup_read_write_cmnd(). If the zone write lock cannot be obtained (e.g. a zone append is in-flight or a regular write has already locked the zone), the zone append command dispatching is delayed by returning BLK_STS_ZONE_RESOURCE. To avoid the need for write locking all zones for REQ_OP_ZONE_RESET_ALL requests, use a spinlock to protect accesses and modifications of the zone write pointer offsets. This spinlock is initialized from sd_probe() using the new function sd_zbc_init(). Co-developed-by: Damien Le Moal Signed-off-by: Johannes Thumshirn --- Changes to v4: - fix brace nit - fix write-locking rules - revalidate zone reworked --- drivers/scsi/sd.c | 26 +++- drivers/scsi/sd.h | 40 ++++- drivers/scsi/sd_zbc.c | 344 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 391 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 2710a0e5ae6d..05a7abd4295d 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1206,6 +1206,14 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) } } + if (req_op(rq) == REQ_OP_ZONE_APPEND) { + ret = sd_zbc_prepare_zone_append(cmd, &lba, nr_blocks); + if (ret) { + scsi_free_sgtables(cmd); + return ret; + } + } + fua = rq->cmd_flags & REQ_FUA ? 0x8 : 0; dix = scsi_prot_sg_count(cmd); dif = scsi_host_dif_capable(cmd->device->host, sdkp->protection_type); @@ -1287,6 +1295,7 @@ static blk_status_t sd_init_command(struct scsi_cmnd *cmd) return sd_setup_flush_cmnd(cmd); case REQ_OP_READ: case REQ_OP_WRITE: + case REQ_OP_ZONE_APPEND: return sd_setup_read_write_cmnd(cmd); case REQ_OP_ZONE_RESET: return sd_zbc_setup_zone_mgmt_cmnd(cmd, ZO_RESET_WRITE_POINTER, @@ -2055,7 +2064,7 @@ static int sd_done(struct scsi_cmnd *SCpnt) out: if (sd_is_zoned(sdkp)) - sd_zbc_complete(SCpnt, good_bytes, &sshdr); + good_bytes = sd_zbc_complete(SCpnt, good_bytes, &sshdr); SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt, "sd_done: completed %d of %d bytes\n", @@ -3371,6 +3380,10 @@ static int sd_probe(struct device *dev) sdkp->first_scan = 1; sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS; + error = sd_zbc_init_disk(sdkp); + if (error) + goto out_free_index; + sd_revalidate_disk(gd); gd->flags = GENHD_FL_EXT_DEVT; @@ -3408,6 +3421,7 @@ static int sd_probe(struct device *dev) out_put: put_disk(gd); out_free: + sd_zbc_release_disk(sdkp); kfree(sdkp); out: scsi_autopm_put_device(sdp); @@ -3484,6 +3498,8 @@ static void scsi_disk_release(struct device *dev) put_disk(disk); put_device(&sdkp->device->sdev_gendev); + sd_zbc_release_disk(sdkp); + kfree(sdkp); } @@ -3664,19 +3680,19 @@ static int __init init_sd(void) if (!sd_page_pool) { printk(KERN_ERR "sd: can't init discard page pool\n"); err = -ENOMEM; - goto err_out_ppool; + goto err_out_cdb_pool; } err = scsi_register_driver(&sd_template.gendrv); if (err) - goto err_out_driver; + goto err_out_ppool; return 0; -err_out_driver: +err_out_ppool: mempool_destroy(sd_page_pool); -err_out_ppool: +err_out_cdb_pool: mempool_destroy(sd_cdb_pool); err_out_cache: diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 50fff0bf8c8e..f7a4d6fcac6b 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -79,6 +79,12 @@ struct scsi_disk { u32 zones_optimal_open; u32 zones_optimal_nonseq; u32 zones_max_open; + u32 *zones_wp_ofst; + spinlock_t zones_wp_ofst_lock; + u32 *rev_wp_ofst; + struct mutex rev_mutex; + struct work_struct zone_wp_ofst_work; + char *zone_wp_update_buf; #endif atomic_t openers; sector_t capacity; /* size in logical blocks */ @@ -207,17 +213,32 @@ static inline int sd_is_zoned(struct scsi_disk *sdkp) #ifdef CONFIG_BLK_DEV_ZONED +int sd_zbc_init_disk(struct scsi_disk *sdkp); +void sd_zbc_release_disk(struct scsi_disk *sdkp); extern int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buffer); extern void sd_zbc_print_zones(struct scsi_disk *sdkp); blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd, unsigned char op, bool all); -extern void sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes, - struct scsi_sense_hdr *sshdr); +unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes, + struct scsi_sense_hdr *sshdr); int sd_zbc_report_zones(struct gendisk *disk, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data); +blk_status_t sd_zbc_prepare_zone_append(struct scsi_cmnd *cmd, sector_t *lba, + unsigned int nr_blocks); + #else /* CONFIG_BLK_DEV_ZONED */ +static inline int sd_zbc_init(void) +{ + return 0; +} + +static inline void sd_zbc_exit(void) {} + +static inline void sd_zbc_init_disk(struct scsi_disk *sdkp) {} +static inline void sd_zbc_release_disk(struct scsi_disk *sdkp) {} + static inline int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) { @@ -233,9 +254,18 @@ static inline blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd, return BLK_STS_TARGET; } -static inline void sd_zbc_complete(struct scsi_cmnd *cmd, - unsigned int good_bytes, - struct scsi_sense_hdr *sshdr) {} +static inline unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, + unsigned int good_bytes, struct scsi_sense_hdr *sshdr) +{ + return 0; +} + +static inline blk_status_t sd_zbc_prepare_zone_append(struct scsi_cmnd *cmd, + sector_t *lba, + unsigned int nr_blocks) +{ + return BLK_STS_TARGET; +} #define sd_zbc_report_zones NULL diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index ee156fbf3780..53cfe998a3f6 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -19,11 +20,36 @@ #include "sd.h" +static unsigned int sd_zbc_get_zone_wp_ofst(struct blk_zone *zone) +{ + if (zone->type == ZBC_ZONE_TYPE_CONV) + return 0; + + switch (zone->cond) { + case BLK_ZONE_COND_IMP_OPEN: + case BLK_ZONE_COND_EXP_OPEN: + case BLK_ZONE_COND_CLOSED: + return zone->wp - zone->start; + case BLK_ZONE_COND_FULL: + return zone->len; + case BLK_ZONE_COND_EMPTY: + case BLK_ZONE_COND_OFFLINE: + case BLK_ZONE_COND_READONLY: + default: + /* + * Offline and read-only zones do not have a valid + * write pointer. Use 0 as for an empty zone. + */ + return 0; + } +} + static int sd_zbc_parse_report(struct scsi_disk *sdkp, u8 *buf, unsigned int idx, report_zones_cb cb, void *data) { struct scsi_device *sdp = sdkp->device; struct blk_zone zone = { 0 }; + int ret; zone.type = buf[0] & 0x0f; zone.cond = (buf[1] >> 4) & 0xf; @@ -39,7 +65,14 @@ static int sd_zbc_parse_report(struct scsi_disk *sdkp, u8 *buf, zone.cond == ZBC_ZONE_COND_FULL) zone.wp = zone.start + zone.len; - return cb(&zone, idx, data); + ret = cb(&zone, idx, data); + if (ret) + return ret; + + if (sdkp->rev_wp_ofst) + sdkp->rev_wp_ofst[idx] = sd_zbc_get_zone_wp_ofst(&zone); + + return 0; } /** @@ -229,6 +262,134 @@ static blk_status_t sd_zbc_cmnd_checks(struct scsi_cmnd *cmd) return BLK_STS_OK; } +#define SD_ZBC_INVALID_WP_OFST (~0u) +#define SD_ZBC_UPDATING_WP_OFST (SD_ZBC_INVALID_WP_OFST - 1) + +static int sd_zbc_update_wp_ofst_cb(struct blk_zone *zone, unsigned int idx, + void *data) +{ + struct scsi_disk *sdkp = data; + + lockdep_assert_held(&sdkp->zones_wp_ofst_lock); + + sdkp->zones_wp_ofst[idx] = sd_zbc_get_zone_wp_ofst(zone); + + return 0; +} + +static void sd_zbc_update_wp_ofst_workfn(struct work_struct *work) +{ + struct scsi_disk *sdkp; + unsigned int zno; + int ret; + + sdkp = container_of(work, struct scsi_disk, zone_wp_ofst_work); + + spin_lock_bh(&sdkp->zones_wp_ofst_lock); + for (zno = 0; zno < sdkp->nr_zones; zno++) { + if (sdkp->zones_wp_ofst[zno] != SD_ZBC_UPDATING_WP_OFST) + continue; + + spin_unlock_bh(&sdkp->zones_wp_ofst_lock); + ret = sd_zbc_do_report_zones(sdkp, sdkp->zone_wp_update_buf, + SD_BUF_SIZE, + zno * sdkp->zone_blocks, true); + spin_lock_bh(&sdkp->zones_wp_ofst_lock); + if (!ret) + sd_zbc_parse_report(sdkp, sdkp->zone_wp_update_buf + 64, + zno, sd_zbc_update_wp_ofst_cb, + sdkp); + } + spin_unlock_bh(&sdkp->zones_wp_ofst_lock); + + scsi_device_put(sdkp->device); +} + +static blk_status_t sd_zbc_update_wp_ofst(struct scsi_disk *sdkp, + unsigned int zno) +{ + /* + * We are about to schedule work to update a zone write pointer offset, + * which will cause the zone append command to be requeued. So make + * sure that the scsi device does not go away while the work is + * being processed. + */ + if (scsi_device_get(sdkp->device)) + return BLK_STS_IOERR; + + sdkp->zones_wp_ofst[zno] = SD_ZBC_UPDATING_WP_OFST; + + schedule_work(&sdkp->zone_wp_ofst_work); + + return BLK_STS_RESOURCE; +} + +/** + * sd_zbc_prepare_zone_append() - Prepare an emulated ZONE_APPEND command. + * @cmd: the command to setup + * @lba: the LBA to patch + * @nr_blocks: the number of LBAs to be written + * + * Called from sd_setup_read_write_cmnd() for REQ_OP_ZONE_APPEND. + * @sd_zbc_prepare_zone_append() handles the necessary zone wrote locking and + * patching of the lba for an emulated ZONE_APPEND command. + * + * In case the cached write pointer offset is %SD_ZBC_INVALID_WP_OFST it will + * schedule a REPORT ZONES command and return BLK_STS_IOERR. + */ +blk_status_t sd_zbc_prepare_zone_append(struct scsi_cmnd *cmd, sector_t *lba, + unsigned int nr_blocks) +{ + struct request *rq = cmd->request; + struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); + unsigned int wp_ofst, zno = blk_rq_zone_no(rq); + blk_status_t ret; + + ret = sd_zbc_cmnd_checks(cmd); + if (ret != BLK_STS_OK) + return ret; + + if (!blk_rq_zone_is_seq(rq)) + return BLK_STS_IOERR; + + /* Unlock of the write lock will happen in sd_zbc_complete() */ + if (!blk_req_zone_write_trylock(rq)) + return BLK_STS_ZONE_RESOURCE; + + spin_lock_bh(&sdkp->zones_wp_ofst_lock); + + wp_ofst = sdkp->zones_wp_ofst[zno]; + if (wp_ofst == SD_ZBC_UPDATING_WP_OFST) { + /* Write pointer offset update in progress: ask for a requeue */ + ret = BLK_STS_RESOURCE; + goto err; + } + + if (wp_ofst == SD_ZBC_INVALID_WP_OFST) { + /* Invalid write pointer offset: trigger an update from disk */ + ret = sd_zbc_update_wp_ofst(sdkp, zno); + goto err; + } + + wp_ofst = sectors_to_logical(sdkp->device, wp_ofst); + if (wp_ofst + nr_blocks > sdkp->zone_blocks) { + ret = BLK_STS_IOERR; + goto err; + } + + /* Set the LBA for the write command used to emulate zone append */ + *lba += wp_ofst; + + spin_unlock_bh(&sdkp->zones_wp_ofst_lock); + + return BLK_STS_OK; + +err: + spin_unlock_bh(&sdkp->zones_wp_ofst_lock); + blk_req_zone_write_unlock(rq); + return ret; +} + /** * sd_zbc_setup_zone_mgmt_cmnd - Prepare a zone ZBC_OUT command. The operations * can be RESET WRITE POINTER, OPEN, CLOSE or FINISH. @@ -269,16 +430,104 @@ blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd, return BLK_STS_OK; } +static bool sd_zbc_need_zone_wp_update(struct request *rq) +{ + switch (req_op(rq)) { + case REQ_OP_ZONE_APPEND: + case REQ_OP_ZONE_FINISH: + case REQ_OP_ZONE_RESET: + case REQ_OP_ZONE_RESET_ALL: + return true; + case REQ_OP_WRITE: + case REQ_OP_WRITE_ZEROES: + case REQ_OP_WRITE_SAME: + return blk_rq_zone_is_seq(rq); + default: + return false; + } +} + +/** + * sd_zbc_zone_wp_update - Update cached zone write pointer upon cmd completion + * @cmd: Completed command + * @good_bytes: Command reply bytes + * + * Called from sd_zbc_complete() to handle the update of the cached zone write + * pointer value in case an update is needed. + */ +static unsigned int sd_zbc_zone_wp_update(struct scsi_cmnd *cmd, + unsigned int good_bytes) +{ + int result = cmd->result; + struct request *rq = cmd->request; + struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); + unsigned int zno = blk_rq_zone_no(rq); + enum req_opf op = req_op(rq); + + /* + * If we got an error for a command that needs updating the write + * pointer offset cache, we must mark the zone wp offset entry as + * invalid to force an update from disk the next time a zone append + * command is issued. + */ + spin_lock_bh(&sdkp->zones_wp_ofst_lock); + + if (result && op != REQ_OP_ZONE_RESET_ALL) { + if (op == REQ_OP_ZONE_APPEND) { + /* Force complete completion (no retry) */ + good_bytes = 0; + scsi_set_resid(cmd, blk_rq_bytes(rq)); + } + + /* + * Force an update of the zone write pointer offset on + * the next zone append access. + */ + if (sdkp->zones_wp_ofst[zno] != SD_ZBC_UPDATING_WP_OFST) + sdkp->zones_wp_ofst[zno] = SD_ZBC_INVALID_WP_OFST; + goto unlock_wp_ofst; + } + + switch (op) { + case REQ_OP_ZONE_APPEND: + rq->__sector += sdkp->zones_wp_ofst[zno]; + /* fallthrough */ + case REQ_OP_WRITE_ZEROES: + case REQ_OP_WRITE_SAME: + case REQ_OP_WRITE: + if (sdkp->zones_wp_ofst[zno] < sd_zbc_zone_sectors(sdkp)) + sdkp->zones_wp_ofst[zno] += good_bytes >> SECTOR_SHIFT; + break; + case REQ_OP_ZONE_RESET: + sdkp->zones_wp_ofst[zno] = 0; + break; + case REQ_OP_ZONE_FINISH: + sdkp->zones_wp_ofst[zno] = sd_zbc_zone_sectors(sdkp); + break; + case REQ_OP_ZONE_RESET_ALL: + memset(sdkp->zones_wp_ofst, 0, + sdkp->nr_zones * sizeof(unsigned int)); + break; + default: + break; + } + +unlock_wp_ofst: + spin_unlock_bh(&sdkp->zones_wp_ofst_lock); + + return good_bytes; +} + /** * sd_zbc_complete - ZBC command post processing. * @cmd: Completed command * @good_bytes: Command reply bytes * @sshdr: command sense header * - * Called from sd_done(). Process report zones reply and handle reset zone - * and write commands errors. + * Called from sd_done() to handle zone commands errors and updates to the + * device queue zone write pointer offset cahce. */ -void sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes, +unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes, struct scsi_sense_hdr *sshdr) { int result = cmd->result; @@ -294,7 +543,18 @@ void sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes, * so be quiet about the error. */ rq->rq_flags |= RQF_QUIET; + goto unlock_zone; } + + if (sd_zbc_need_zone_wp_update(rq)) + good_bytes = sd_zbc_zone_wp_update(cmd, good_bytes); + + +unlock_zone: + if (req_op(rq) == REQ_OP_ZONE_APPEND) + blk_req_zone_write_unlock(rq); + + return good_bytes; } /** @@ -396,11 +656,48 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf, return 0; } +static void sd_zbc_revalidate_zones_cb(struct gendisk *disk, void *data) +{ + struct scsi_disk *sdkp = scsi_disk(disk); + + swap(sdkp->zones_wp_ofst, sdkp->rev_wp_ofst); +} + +static int sd_zbc_revalidate_zones(struct scsi_disk *sdkp, + unsigned int nr_zones) +{ + int ret; + + /* + * Make sure revalidate zones are serialized to ensure exclusive + * updates of the temporary array sdkp->rev_wp_ofst. + */ + mutex_lock(&sdkp->rev_mutex); + + sdkp->rev_wp_ofst = kvcalloc(nr_zones, sizeof(u32), GFP_NOIO); + if (!sdkp->rev_wp_ofst) { + ret = -ENOMEM; + goto unlock; + } + + ret = __blk_revalidate_disk_zones(sdkp->disk, + sd_zbc_revalidate_zones_cb, NULL); + kvfree(sdkp->rev_wp_ofst); + sdkp->rev_wp_ofst = NULL; + +unlock: + mutex_unlock(&sdkp->rev_mutex); + + return ret; +} + int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) { struct gendisk *disk = sdkp->disk; + struct request_queue *q = disk->queue; unsigned int nr_zones; u32 zone_blocks = 0; + u32 max_append; int ret; if (!sd_is_zoned(sdkp)) @@ -420,10 +717,14 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) if (ret != 0) goto err; + max_append = min_t(u32, logical_to_sectors(sdkp->device, zone_blocks), + q->limits.max_segments << (PAGE_SHIFT - 9)); + max_append = min_t(u32, max_append, queue_max_hw_sectors(q)); + /* The drive satisfies the kernel restrictions: set it up */ - blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, sdkp->disk->queue); - blk_queue_required_elevator_features(sdkp->disk->queue, - ELEVATOR_F_ZBD_SEQ_WRITE); + blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); + blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE); + blk_queue_max_zone_append_sectors(q, max_append); nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks); /* READ16/WRITE16 is mandatory for ZBC disks */ @@ -443,8 +744,8 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) if (sdkp->zone_blocks != zone_blocks || sdkp->nr_zones != nr_zones || - disk->queue->nr_zones != nr_zones) { - ret = blk_revalidate_disk_zones(disk); + q->nr_zones != nr_zones) { + ret = sd_zbc_revalidate_zones(sdkp, nr_zones); if (ret != 0) goto err; sdkp->zone_blocks = zone_blocks; @@ -475,3 +776,28 @@ void sd_zbc_print_zones(struct scsi_disk *sdkp) sdkp->nr_zones, sdkp->zone_blocks); } + +int sd_zbc_init_disk(struct scsi_disk *sdkp) +{ + if (!sd_is_zoned(sdkp)) + return 0; + + sdkp->zones_wp_ofst = NULL; + spin_lock_init(&sdkp->zones_wp_ofst_lock); + sdkp->rev_wp_ofst = NULL; + mutex_init(&sdkp->rev_mutex); + INIT_WORK(&sdkp->zone_wp_ofst_work, sd_zbc_update_wp_ofst_workfn); + sdkp->zone_wp_update_buf = kzalloc(SD_BUF_SIZE, GFP_KERNEL); + if (!sdkp->zone_wp_update_buf) + return -ENOMEM; + + return 0; +} + +void sd_zbc_release_disk(struct scsi_disk *sdkp) +{ + kvfree(sdkp->zones_wp_ofst); + sdkp->zones_wp_ofst = NULL; + kfree(sdkp->zone_wp_update_buf); + sdkp->zone_wp_update_buf = NULL; +} From patchwork Thu Apr 9 16:53:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11482043 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5DFE014B4 for ; Thu, 9 Apr 2020 16:54:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F768208FE for ; Thu, 9 Apr 2020 16:54:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Q20SdBk4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727883AbgDIQyL (ORCPT ); Thu, 9 Apr 2020 12:54:11 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24729 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727833AbgDIQyL (ORCPT ); Thu, 9 Apr 2020 12:54:11 -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=1586451251; x=1617987251; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m2H27AoyUGGLJggOB8uvDrziXzXN6LJ8DBjwSQ16qmI=; b=Q20SdBk4jpmaIKPfX1ICGCnPCua9NTDTxNNECHSuWT36mUSjLMnSb79n l1Wc1VoUoqb98CcVT0pWPm261wka8hL4ubDaGu19ve6j2esMUIcgl4uns JYZu1YEvDP5zMMb6g+Y8t99RW9xCDsowvx/sA9re+NJuqhn9QmipaXhGy eNuRfouAripObrjM47e7rFAicNlAAH7EOzcQL1pZhVxDDO/rwDwTshsK1 RV1hTR9MiozMrz+0kPcKS5SS57Ngd8+Q7hRfqXw3ssEzPJy10MXbc71/+ s8c+aR7JIohRy2GY/TqTf5rhJkGSe6NAyCTGJJHlJ+LNnJE1QW7dprBw2 g==; IronPort-SDR: zM1fCOD9dnRO3UprufNMoahnReA4gLhdcuA5rMLAzH1pjuv500d6B1iEisuXuXJAQX2MEOcumx iGIr7AmvKA8+Y/uwjqZh1hSP5gLu+A3z2NtVJ/b2tm73dBcscbe3tf8IEVhykyHiZq/xbHSeOs 3cXWuDF+eJMY8a6XH9g3SsX+H/RNAaiaZ/8gbmKj9nH1rfptzHa5bUkgEqAcZ44YJEY3GJPZLt us5HisYWRvigCHn7NnLt5ZvnO6b6GofIt9OI5C2vy38341qlqKlD20epwLM8MUOuClaBKRdvxo /IM= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="136423701" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 00:54:11 +0800 IronPort-SDR: qvZoN5aKpXNgvAdscjuduLUZcLFw+wJGZATcyKeex54xI5lcwyAmUDYIQ0r8Z21/R/y0UmhxFS q0hD+4SYj/JRQtWO7YrW41RGp4cdgWMPcqXChbv/nsfGa8gmbhq23TKOkYL5TE5N2xXo1J8eq8 zpCfuuhOhJCN+nTBqZ9gItC7Za4YdHOO/r9l8wAJzXpG3hky2gRJmbMMiD4SyDjnRvDmTLOhlW EwAreL/ANcGI/+NOxdYg2UtwWO0YnnNeN6s2TXJOm+tdChXU5wvBuD0TF5w/K99Zh1wyhn6cd9 G32nTfuzUv9nPS/gcyd2YtpT Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 09:44:49 -0700 IronPort-SDR: 5pX8gF8H4vB3FMyhSxzOcaqEhHy3IdhGh1UbbO9QqTwt3KALxUz1DKq63lPwt7XIQP4IYCjjMM /ynGbEXHHteuX2TMbkdF3lee5PP6D5e2XSsYRUB+wn3i61HGjqmDbwuFqSeecxkZDpgtxi/T3h lkqg/NiaOcKr1eRmwbTmbsoZQinvTNYLE4fOlLB29lzY1vrw9dfq4rnk0DHoBpvKo5sNK/reYe GZl+iOVBIB+dIX0Zbnqj7uSTBHESFJ9TOkJPjMq3YrJyRsIlwCJwJ8fe0U4dH0AKI5smmirE2v mBo= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 09:54:09 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Damien Le Moal , Christoph Hellwig , Johannes Thumshirn Subject: [PATCH v5 08/10] null_blk: Support REQ_OP_ZONE_APPEND Date: Fri, 10 Apr 2020 01:53:50 +0900 Message-Id: <20200409165352.2126-9-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200409165352.2126-1-johannes.thumshirn@wdc.com> References: <20200409165352.2126-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Damien Le Moal Support REQ_OP_ZONE_APPEND requests for null_blk devices with zoned mode enabled. Use the internally tracked zone write pointer position as the actual write position and return it using the command request __sector field in the case of an mq device and using the command BIO sector in the case of a BIO device. Reviewed-by: Christoph Hellwig Signed-off-by: Damien Le Moal Signed-off-by: Johannes Thumshirn --- drivers/block/null_blk_zoned.c | 39 +++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c index c60b19432a2e..b664be0bbb5e 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -67,13 +67,22 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) int null_register_zoned_dev(struct nullb *nullb) { + struct nullb_device *dev = nullb->dev; struct request_queue *q = nullb->q; - if (queue_is_mq(q)) - return blk_revalidate_disk_zones(nullb->disk); + if (queue_is_mq(q)) { + int ret = blk_revalidate_disk_zones(nullb->disk); + + if (ret) + return ret; + } else { + blk_queue_chunk_sectors(q, dev->zone_size_sects); + q->nr_zones = blkdev_nr_zones(nullb->disk); + } - blk_queue_chunk_sectors(q, nullb->dev->zone_size_sects); - q->nr_zones = blkdev_nr_zones(nullb->disk); + blk_queue_max_zone_append_sectors(q, + min_t(sector_t, q->limits.max_hw_sectors, + dev->zone_size_sects)); return 0; } @@ -133,7 +142,7 @@ size_t null_zone_valid_read_len(struct nullb *nullb, } static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, - unsigned int nr_sectors) + unsigned int nr_sectors, bool append) { struct nullb_device *dev = cmd->nq->dev; unsigned int zno = null_zone_no(dev, sector); @@ -151,9 +160,21 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, case BLK_ZONE_COND_IMP_OPEN: case BLK_ZONE_COND_EXP_OPEN: case BLK_ZONE_COND_CLOSED: - /* Writes must be at the write pointer position */ - if (sector != zone->wp) + /* + * Regular writes must be at the write pointer position. + * Zone append writes are automatically issued at the write + * pointer and the position returned using the request or BIO + * sector. + */ + if (append) { + sector = zone->wp; + if (cmd->bio) + cmd->bio->bi_iter.bi_sector = sector; + else + cmd->rq->__sector = sector; + } else if (sector != zone->wp) { return BLK_STS_IOERR; + } if (zone->cond != BLK_ZONE_COND_EXP_OPEN) zone->cond = BLK_ZONE_COND_IMP_OPEN; @@ -232,7 +253,9 @@ blk_status_t null_handle_zoned(struct nullb_cmd *cmd, enum req_opf op, { switch (op) { case REQ_OP_WRITE: - return null_zone_write(cmd, sector, nr_sectors); + return null_zone_write(cmd, sector, nr_sectors, false); + case REQ_OP_ZONE_APPEND: + return null_zone_write(cmd, sector, nr_sectors, true); case REQ_OP_ZONE_RESET: case REQ_OP_ZONE_RESET_ALL: case REQ_OP_ZONE_OPEN: From patchwork Thu Apr 9 16:53:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11482053 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AC1217D4 for ; Thu, 9 Apr 2020 16:54:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 576AB20753 for ; Thu, 9 Apr 2020 16:54:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="pJUC/xHp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728079AbgDIQyP (ORCPT ); Thu, 9 Apr 2020 12:54:15 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24729 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727833AbgDIQyM (ORCPT ); Thu, 9 Apr 2020 12:54:12 -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=1586451253; x=1617987253; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/sRG9rMebxTyOpqZFaCW5QMmTu1k57daJpfK2lPqV/s=; b=pJUC/xHpcA/zW+qNMNfcAnpBYYy09YhIaX9gXBabQm3cKPz5Dc9cBE6v 42LRdRPeAjI+8ymOrnaZmwFIoFU/qPu0k3mOLzcrECNRnN5bzjhHV826l Fn/sXo4UtLKwrUHxQBsMYqIDFKoewqYjiLijEaG82DuUT9ggfXXom/Tnr aSSun8UMB2DCHUpQv85EBj+IP5eyhtQFsIzNOgv623ppC4UYVfG3MP29b aShOkIsXfRzqfCGSa/fD1vojV30BKIOBj68GyojgyO8KY4saTONhkUOhG 9v9Pjrna4N84H9w73PzxrUUlYUiKlff7Me9/qmUjhDhJLV0JcXIuv4UeE Q==; IronPort-SDR: JpJzgSpXMOnlBRGxOlnI2pjAkP4Gr3ztYQtS9GQ5u+IKl8qs58SAGLdd8tTlHAVbNiS1vWVQy5 xfrz14mUboOv0DihoNcbscH0tjiW9iQs1PUvAbV9oT7SI2uUfJM4vtJp51weNiD3+3w/C2SSCo 3KzaToR8LBl22eGehkr2ikfzJT9C9IuhjH53uOwTPRRcZ55CnlwxXmxdnkcBm4xzFrjtRFdgxH qc4oFiNEk8yWR29nEgT+tMTcGEqa58ngp+sjcHbgvsvtm1q+L46ADkQZBYyYXzhsOEWTsFwp3I uKQ= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="136423704" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 00:54:12 +0800 IronPort-SDR: Ysbjm7qAmDkeleE6S0UKxmDUf1V1fRbfXcd++0JhIboOIbivGRgmjsstU2tkvTyh2+jFEYH3z1 wSO0deiuJH7sILaT8YLJ6yf+3O2k+9YV0OkTV45oDKM2xt1b3SbVRQxUKZ5PTdpJ0bPhvNbJrR gCQfPBXuP5FzqsHSlAxDYMXNmIaksPB/fh/sUi8ua/bVFetBrDltnmMGY3KUrT3kS1r/4L18fh f8CzzLwXyrNsgYnOlxyIGzD33eLBRvWGtNmhnAsChrkXoSa+281Rqoj+G1v2fjeOzf2fmJVlv6 C/krBgJqitnfdEhKtBS/4tOM Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 09:44:51 -0700 IronPort-SDR: UBm2dceu86+lz/v4VdnpD6uza7DWaf+8fpqQvoDbkFJ1hfxOv63LEO/+YtKHrT19g66e3vj/h6 g0Ozg029H6TaiPi3EJN3TdKe85GKGUi1TIwaClgrzbkgT0IbJKedmLvX7HHhhZ4NM65SxzUGEv xoT7h6qR9a4rTP0u9EY5awEiKBsX6dQTrA+ovckynLS8CAPET+nUf7Gpj4+Upmp1tDl0vFvsJ0 iJV94j3XgxUqV5vdREn24AKngyCg+cq9eC+lmur+znCoa9lCdVs5clAelb+7iTQk40KSvXYiOc n3g= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 09:54:11 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Johannes Thumshirn Subject: [PATCH v5 09/10] block: export bio_release_pages and bio_iov_iter_get_pages Date: Fri, 10 Apr 2020 01:53:51 +0900 Message-Id: <20200409165352.2126-10-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200409165352.2126-1-johannes.thumshirn@wdc.com> References: <20200409165352.2126-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Export bio_release_pages and bio_iov_iter_get_pages, so they can be used from modular code. Signed-off-by: Johannes Thumshirn --- Changes to v3: - Use EXPORT_SYMBOL_GPL --- block/bio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/bio.c b/block/bio.c index 689f31357d30..4029a48f3828 100644 --- a/block/bio.c +++ b/block/bio.c @@ -934,6 +934,7 @@ void bio_release_pages(struct bio *bio, bool mark_dirty) put_page(bvec->bv_page); } } +EXPORT_SYMBOL_GPL(bio_release_pages); static int __bio_iov_bvec_add_pages(struct bio *bio, struct iov_iter *iter) { @@ -1061,6 +1062,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) bio_set_flag(bio, BIO_NO_PAGE_REF); return bio->bi_vcnt ? 0 : ret; } +EXPORT_SYMBOL_GPL(bio_iov_iter_get_pages); static void submit_bio_wait_endio(struct bio *bio) { From patchwork Thu Apr 9 16:53:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11482059 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65E5414B4 for ; Thu, 9 Apr 2020 16:54:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 462EE20769 for ; Thu, 9 Apr 2020 16:54:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="iQ3glxeB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728137AbgDIQyQ (ORCPT ); Thu, 9 Apr 2020 12:54:16 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:24729 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727878AbgDIQyO (ORCPT ); Thu, 9 Apr 2020 12:54:14 -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=1586451254; x=1617987254; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DntH3FOL+F2qJ4JB8bNfeHvJeRnIrbJq4X8RpN63JaA=; b=iQ3glxeBXBKjcW6mGQomEUPIYeZO2ch0KO1sF4Ao+0km+/oVVDjmpOKE VzTtp/QPVXIglru5IWlP1JoDt3Hbxd0kSD/3RmvDv0BYBqcSBTWSgxM4s +nL7Nyw9DhD7Iv196PbxE7Qae8aKYr+ZNnwRRJ6RdRFXRhZcht+/YchSm NG+ycskdXhZMgd0QvvUoM33wZWfzvIshpyNDz3Xp8FEv7JH74YPzKxDkK qHVrfxBF2EnI0SsnVsUod4/vqfUc7+hfCjpC/JEc+GvfLsNjoSa9VcsqY aFnSr8BEsEYRMvbbHXIfU1R2qoTkrwqwdFEds3aPaJROYhUdjjFONLOWO g==; IronPort-SDR: P+jja9En4szPyF6RN278XRQ/3w4o8kHMb1GzNf2Joxo/cgPlzA7rXEx4RSXcYBtGl+6jqFdm7y Q8SNGphGe67cpo9FAbg3LNGcKncRqdyjdGdZu3wjMURx0kW80IIZtvF4AyvobJPA+Iz0CNhBm0 Yk7eDRYqQU9w4hfPkIdBrQ2LnpjuuFvVpB9abfgu1MiVbkyHOFqkttaAp5vQlnNb6BBMT81OXJ 21fV2tv0flo1KK/X+2WJjS4fE50p+yXoYUo4bjHo/mOMUhsuq+RiXcMgEnTzx/1Is0APVz2qzz O4U= X-IronPort-AV: E=Sophos;i="5.72,363,1580745600"; d="scan'208";a="136423706" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Apr 2020 00:54:14 +0800 IronPort-SDR: Y0yjE/uAPjs6U72F80v9dnwuR/3KWTrmwzf+rdT2m7V8BR9+Rn22zk3gcnatEaKzh6owKvvN/7 R+3ykxQ7Moex5X16l1igEEIQeTrUa0l2gryB9ngV37AxhdZaDvmKa3B6IDdl3HbthGV8gd9DPl Y+uaw8MkxDz69LsntnnGXA6nNQd2q998ai3uvUp8/bjACqGq6lHGRO2PKeqVYBB4mgQCVha66N KJSnrC7nIbhQfNY2sNxlwyk4eXIB/W9mdAfbQsL++yBsQUFDUmarVbNB+SIt4Pg40pBg/YExv4 iTkZ/BoTfdqcbB9WmJst9Zmo Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 09:44:53 -0700 IronPort-SDR: NHV6vZzxltP47OwkQ54VnvpTBjp3Czrekz+QikxdevLcZD+4Y/14HslBI9Sr7yygh+shbWRiKM 2DybP7Fa3yXVaxkPuxzK/6E3lzRHULeK3tiGzNXm3KBSdvhFqPYf9Wf9Ao7+jKHtyxdNNRn5FS oGRWEv+c15SUXOJW1EHr2Uk5WoSCV9d/XOtOj/vBmc5mWAZmWU/l9zHhnJDZYOwHuTHunG2TvB 506WS0SSvTSQWWr13MnDLSenZ0PLuM29C9hCORENr6kI2b0oexODDjbJQXwpxjOvUUuIL7wlPa GPw= WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Apr 2020 09:54:13 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Johannes Thumshirn Subject: [PATCH v5 10/10] zonefs: use REQ_OP_ZONE_APPEND for sync DIO Date: Fri, 10 Apr 2020 01:53:52 +0900 Message-Id: <20200409165352.2126-11-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200409165352.2126-1-johannes.thumshirn@wdc.com> References: <20200409165352.2126-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Synchronous direct I/O to a sequential write only zone can be issued using the new REQ_OP_ZONE_APPEND request operation. As dispatching multiple BIOs can potentially result in reordering, we cannot support asynchronous IO via this interface. We also can only dispatch up to queue_max_zone_append_sectors() via the new zone-append method and have to return a short write back to user-space in case an IO larger than queue_max_zone_append_sectors() has been issued. Signed-off-by: Johannes Thumshirn --- fs/zonefs/super.c | 80 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index 3ce9829a6936..0bf7009f50a2 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "zonefs.h" @@ -596,6 +597,61 @@ static const struct iomap_dio_ops zonefs_write_dio_ops = { .end_io = zonefs_file_write_dio_end_io, }; +static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from) +{ + struct inode *inode = file_inode(iocb->ki_filp); + struct zonefs_inode_info *zi = ZONEFS_I(inode); + struct block_device *bdev = inode->i_sb->s_bdev; + unsigned int max; + struct bio *bio; + ssize_t size; + int nr_pages; + ssize_t ret; + + nr_pages = iov_iter_npages(from, BIO_MAX_PAGES); + if (!nr_pages) + return 0; + + max = queue_max_zone_append_sectors(bdev_get_queue(bdev)); + max = ALIGN_DOWN(max << SECTOR_SHIFT, inode->i_sb->s_blocksize); + iov_iter_truncate(from, max); + + bio = bio_alloc_bioset(GFP_NOFS, nr_pages, &fs_bio_set); + if (!bio) + return -ENOMEM; + + bio_set_dev(bio, bdev); + bio->bi_iter.bi_sector = zi->i_zsector; + bio->bi_write_hint = iocb->ki_hint; + bio->bi_ioprio = iocb->ki_ioprio; + bio->bi_opf = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE; + if (iocb->ki_flags & IOCB_DSYNC) + bio->bi_opf |= REQ_FUA; + + ret = bio_iov_iter_get_pages(bio, from); + if (unlikely(ret)) { + bio_io_error(bio); + return ret; + } + size = bio->bi_iter.bi_size; + task_io_account_write(ret); + + if (iocb->ki_flags & IOCB_HIPRI) + bio_set_polled(bio, iocb); + + ret = submit_bio_wait(bio); + + bio_put(bio); + + zonefs_file_write_dio_end_io(iocb, size, ret, 0); + if (ret >= 0) { + iocb->ki_pos += size; + return size; + } + + return ret; +} + /* * Handle direct writes. For sequential zone files, this is the only possible * write path. For these files, check that the user is issuing writes @@ -611,6 +667,8 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from) struct inode *inode = file_inode(iocb->ki_filp); struct zonefs_inode_info *zi = ZONEFS_I(inode); struct super_block *sb = inode->i_sb; + bool sync = is_sync_kiocb(iocb); + bool append = false; size_t count; ssize_t ret; @@ -619,7 +677,7 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from) * as this can cause write reordering (e.g. the first aio gets EAGAIN * on the inode lock but the second goes through but is now unaligned). */ - if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && !is_sync_kiocb(iocb) && + if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && !sync && (iocb->ki_flags & IOCB_NOWAIT)) return -EOPNOTSUPP; @@ -643,16 +701,22 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from) } /* Enforce sequential writes (append only) in sequential zones */ - mutex_lock(&zi->i_truncate_mutex); - if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && iocb->ki_pos != zi->i_wpoffset) { + if (zi->i_ztype == ZONEFS_ZTYPE_SEQ) { + mutex_lock(&zi->i_truncate_mutex); + if (iocb->ki_pos != zi->i_wpoffset) { + mutex_unlock(&zi->i_truncate_mutex); + ret = -EINVAL; + goto inode_unlock; + } mutex_unlock(&zi->i_truncate_mutex); - ret = -EINVAL; - goto inode_unlock; + append = sync; } - mutex_unlock(&zi->i_truncate_mutex); - ret = iomap_dio_rw(iocb, from, &zonefs_iomap_ops, - &zonefs_write_dio_ops, is_sync_kiocb(iocb)); + if (append) + ret = zonefs_file_dio_append(iocb, from); + else + ret = iomap_dio_rw(iocb, from, &zonefs_iomap_ops, + &zonefs_write_dio_ops, sync); if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && (ret > 0 || ret == -EIOCBQUEUED)) { if (ret > 0)