From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>,
Damien Le Moal <damien.lemoal@opensource.wdc.com>
Cc: dm-devel@redhat.com, linux-block@vger.kernel.org,
linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org
Subject: [PATCH 06/17] nvmet: use blkdev_zone_mgmt_all
Date: Mon, 4 Jul 2022 14:44:49 +0200 [thread overview]
Message-ID: <20220704124500.155247-7-hch@lst.de> (raw)
In-Reply-To: <20220704124500.155247-1-hch@lst.de>
Use blkdev_zone_mgmt_all instead of a copy and pasted version.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/target/zns.c | 104 ++------------------------------------
1 file changed, 3 insertions(+), 101 deletions(-)
diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c
index 82b61acf7a72b..c6f0a775efdee 100644
--- a/drivers/nvme/target/zns.c
+++ b/drivers/nvme/target/zns.c
@@ -337,110 +337,12 @@ static u16 blkdev_zone_mgmt_errno_to_nvme_status(int ret)
}
}
-struct nvmet_zone_mgmt_send_all_data {
- unsigned long *zbitmap;
- struct nvmet_req *req;
-};
-
-static int zmgmt_send_scan_cb(struct blk_zone *z, unsigned i, void *d)
-{
- struct nvmet_zone_mgmt_send_all_data *data = d;
-
- switch (zsa_req_op(data->req->cmd->zms.zsa)) {
- case REQ_OP_ZONE_OPEN:
- switch (z->cond) {
- case BLK_ZONE_COND_CLOSED:
- break;
- default:
- return 0;
- }
- break;
- case REQ_OP_ZONE_CLOSE:
- switch (z->cond) {
- case BLK_ZONE_COND_IMP_OPEN:
- case BLK_ZONE_COND_EXP_OPEN:
- break;
- default:
- return 0;
- }
- break;
- case REQ_OP_ZONE_FINISH:
- switch (z->cond) {
- case BLK_ZONE_COND_IMP_OPEN:
- case BLK_ZONE_COND_EXP_OPEN:
- case BLK_ZONE_COND_CLOSED:
- break;
- default:
- return 0;
- }
- break;
- default:
- return -EINVAL;
- }
-
- set_bit(i, data->zbitmap);
-
- return 0;
-}
-
-static u16 nvmet_bdev_zone_mgmt_emulate_all(struct nvmet_req *req)
-{
- struct block_device *bdev = req->ns->bdev;
- unsigned int nr_zones = blkdev_nr_zones(bdev->bd_disk);
- struct request_queue *q = bdev_get_queue(bdev);
- struct bio *bio = NULL;
- sector_t sector = 0;
- int ret;
- struct nvmet_zone_mgmt_send_all_data d = {
- .req = req,
- };
-
- d.zbitmap = kcalloc_node(BITS_TO_LONGS(nr_zones), sizeof(*(d.zbitmap)),
- GFP_NOIO, q->node);
- if (!d.zbitmap) {
- ret = -ENOMEM;
- goto out;
- }
-
- /* Scan and build bitmap of the eligible zones */
- ret = blkdev_report_zones(bdev, 0, nr_zones, zmgmt_send_scan_cb, &d);
- if (ret != nr_zones) {
- if (ret > 0)
- ret = -EIO;
- goto out;
- } else {
- /* We scanned all the zones */
- ret = 0;
- }
-
- while (sector < get_capacity(bdev->bd_disk)) {
- if (test_bit(blk_queue_zone_no(q, sector), d.zbitmap)) {
- bio = blk_next_bio(bio, bdev, 0,
- zsa_req_op(req->cmd->zms.zsa) | REQ_SYNC,
- GFP_KERNEL);
- bio->bi_iter.bi_sector = sector;
- /* This may take a while, so be nice to others */
- cond_resched();
- }
- sector += blk_queue_zone_sectors(q);
- }
-
- if (bio) {
- ret = submit_bio_wait(bio);
- bio_put(bio);
- }
-
-out:
- kfree(d.zbitmap);
-
- return blkdev_zone_mgmt_errno_to_nvme_status(ret);
-}
-
static u16 nvmet_bdev_execute_zmgmt_send_all(struct nvmet_req *req)
{
+ unsigned int op = zsa_req_op(req->cmd->zms.zsa);
int ret;
- switch (zsa_req_op(req->cmd->zms.zsa)) {
+ switch (op) {
case REQ_OP_ZONE_RESET:
ret = blkdev_zone_mgmt(req->ns->bdev, REQ_OP_ZONE_RESET, 0,
get_capacity(req->ns->bdev->bd_disk),
@@ -451,7 +353,7 @@ static u16 nvmet_bdev_execute_zmgmt_send_all(struct nvmet_req *req)
case REQ_OP_ZONE_OPEN:
case REQ_OP_ZONE_CLOSE:
case REQ_OP_ZONE_FINISH:
- return nvmet_bdev_zone_mgmt_emulate_all(req);
+ return blkdev_zone_mgmt_all(req->ns->bdev, op, GFP_KERNEL);
default:
/* this is needed to quiet compiler warning */
req->error_loc = offsetof(struct nvme_zone_mgmt_send_cmd, zsa);
--
2.30.2
next prev parent reply other threads:[~2022-07-04 12:45 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-04 12:44 clean up zoned device information Christoph Hellwig
2022-07-04 12:44 ` [PATCH 01/17] block: remove a superflous ifdef in blkdev.h Christoph Hellwig
2022-07-04 12:58 ` Johannes Thumshirn
2022-07-04 13:01 ` Christoph Hellwig
2022-07-04 13:04 ` Johannes Thumshirn
2022-07-05 2:26 ` Damien Le Moal
2022-07-05 6:22 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 02/17] block: call blk_queue_free_zone_bitmaps from disk_release Christoph Hellwig
2022-07-04 13:01 ` Johannes Thumshirn
2022-07-05 2:27 ` Damien Le Moal
2022-07-05 6:23 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 03/17] block: use bdev_is_zoned instead of open coding it Christoph Hellwig
2022-07-04 13:13 ` Johannes Thumshirn
2022-07-05 2:28 ` Damien Le Moal
2022-07-05 6:45 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 04/17] block: simplify blk_mq_plug Christoph Hellwig
2022-07-04 13:14 ` Johannes Thumshirn
2022-07-05 2:30 ` Damien Le Moal
2022-07-05 6:25 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 05/17] block: export blkdev_zone_mgmt_all Christoph Hellwig
2022-07-04 13:17 ` Johannes Thumshirn
2022-07-05 2:31 ` Damien Le Moal
2022-07-05 2:39 ` Damien Le Moal
2022-07-05 6:25 ` Chaitanya Kulkarni
2022-07-04 12:44 ` Christoph Hellwig [this message]
2022-07-04 13:18 ` [PATCH 06/17] nvmet: use blkdev_zone_mgmt_all Johannes Thumshirn
2022-07-04 12:44 ` [PATCH 07/17] block: simplify blk_check_zone_append Christoph Hellwig
2022-07-04 13:21 ` Johannes Thumshirn
2022-07-05 2:40 ` Damien Le Moal
2022-07-05 6:27 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 08/17] block: pass a gendisk to blk_queue_set_zoned Christoph Hellwig
2022-07-04 13:22 ` Johannes Thumshirn
2022-07-05 2:41 ` Damien Le Moal
2022-07-05 6:28 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 09/17] block: pass a gendisk to blk_queue_clear_zone_settings Christoph Hellwig
2022-07-04 13:23 ` Johannes Thumshirn
2022-07-05 2:41 ` Damien Le Moal
2022-07-05 6:29 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 10/17] block: pass a gendisk to blk_queue_free_zone_bitmaps Christoph Hellwig
2022-07-04 13:23 ` Johannes Thumshirn
2022-07-05 2:42 ` Damien Le Moal
2022-07-05 6:40 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 11/17] block: remove queue_max_open_zones and queue_max_active_zones Christoph Hellwig
2022-07-04 13:23 ` Johannes Thumshirn
2022-07-05 2:43 ` Damien Le Moal
2022-07-05 6:41 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 12/17] block: pass a gendisk to blk_queue_max_open_zones and blk_queue_max_active_zones Christoph Hellwig
2022-07-04 13:24 ` Johannes Thumshirn
2022-07-05 2:50 ` Damien Le Moal
2022-07-05 6:41 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 13/17] block: replace blkdev_nr_zones with bdev_nr_zones Christoph Hellwig
2022-07-04 13:27 ` Johannes Thumshirn
2022-07-05 2:53 ` Damien Le Moal
2022-07-05 6:42 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 14/17] block: use bdev based helpers in blkdev_zone_mgmt / blkdev_zone_mgmt_all Christoph Hellwig
2022-07-04 13:27 ` Johannes Thumshirn
2022-07-05 2:54 ` Damien Le Moal
2022-07-05 6:43 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 15/17] dm-zoned: cleanup dmz_fixup_devices Christoph Hellwig
2022-07-04 13:28 ` Johannes Thumshirn
2022-07-05 2:54 ` Damien Le Moal
2022-07-05 6:43 ` Chaitanya Kulkarni
2022-07-04 12:44 ` [PATCH 16/17] block: remove blk_queue_zone_sectors Christoph Hellwig
2022-07-04 13:29 ` Johannes Thumshirn
2022-07-05 2:55 ` Damien Le Moal
2022-07-05 6:44 ` Chaitanya Kulkarni
2022-07-04 12:45 ` [PATCH 17/17] block: move zone related fields to struct gendisk Christoph Hellwig
2022-07-04 13:31 ` Johannes Thumshirn
2022-07-05 2:59 ` Damien Le Moal
2022-07-05 6:44 ` Chaitanya Kulkarni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220704124500.155247-7-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=damien.lemoal@opensource.wdc.com \
--cc=dm-devel@redhat.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).