Use blkdev_zone_mgmt_all instead of a copy and pasted version. Signed-off-by: Christoph Hellwig <hch@xxxxxx> --- 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