1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2017 Western Digital Corporation or its affiliates.
5 * This file is released under the GPL.
10 #include <linux/module.h>
12 #define DM_MSG_PREFIX "zoned"
14 #define DMZ_MIN_BIOS 8192
20 struct dmz_target *target;
27 * Chunk work descriptor.
29 struct dm_chunk_work {
30 struct work_struct work;
32 struct dmz_target *target;
34 struct bio_list bio_list;
45 /* Zoned block device information */
48 /* For metadata handling */
49 struct dmz_metadata *metadata;
52 struct dmz_reclaim *reclaim;
55 struct radix_tree_root chunk_rxtree;
56 struct workqueue_struct *chunk_wq;
57 struct mutex chunk_lock;
59 /* For cloned BIOs to zones */
60 struct bio_set bio_set;
63 spinlock_t flush_lock;
64 struct bio_list flush_list;
65 struct delayed_work flush_work;
66 struct workqueue_struct *flush_wq;
70 * Flush intervals (seconds).
72 #define DMZ_FLUSH_PERIOD (10 * HZ)
75 * Target BIO completion.
77 static inline void dmz_bio_endio(struct bio *bio, blk_status_t status)
79 struct dmz_bioctx *bioctx = dm_per_bio_data(bio, sizeof(struct dmz_bioctx));
81 if (status != BLK_STS_OK && bio->bi_status == BLK_STS_OK)
82 bio->bi_status = status;
84 if (refcount_dec_and_test(&bioctx->ref)) {
85 struct dm_zone *zone = bioctx->zone;
88 if (bio->bi_status != BLK_STS_OK &&
89 bio_op(bio) == REQ_OP_WRITE &&
91 set_bit(DMZ_SEQ_WRITE_ERR, &zone->flags);
92 dmz_deactivate_zone(zone);
99 * Completion callback for an internally cloned target BIO. This terminates the
100 * target BIO when there are no more references to its context.
102 static void dmz_clone_endio(struct bio *clone)
104 struct dmz_bioctx *bioctx = clone->bi_private;
105 blk_status_t status = clone->bi_status;
108 dmz_bio_endio(bioctx->bio, status);
112 * Issue a clone of a target BIO. The clone may only partially process the
113 * original target BIO.
115 static int dmz_submit_bio(struct dmz_target *dmz, struct dm_zone *zone,
116 struct bio *bio, sector_t chunk_block,
117 unsigned int nr_blocks)
119 struct dmz_bioctx *bioctx = dm_per_bio_data(bio, sizeof(struct dmz_bioctx));
122 clone = bio_clone_fast(bio, GFP_NOIO, &dmz->bio_set);
126 bio_set_dev(clone, dmz->dev->bdev);
127 clone->bi_iter.bi_sector =
128 dmz_start_sect(dmz->metadata, zone) + dmz_blk2sect(chunk_block);
129 clone->bi_iter.bi_size = dmz_blk2sect(nr_blocks) << SECTOR_SHIFT;
130 clone->bi_end_io = dmz_clone_endio;
131 clone->bi_private = bioctx;
133 bio_advance(bio, clone->bi_iter.bi_size);
135 refcount_inc(&bioctx->ref);
136 generic_make_request(clone);
138 if (bio_op(bio) == REQ_OP_WRITE && dmz_is_seq(zone))
139 zone->wp_block += nr_blocks;
145 * Zero out pages of discarded blocks accessed by a read BIO.
147 static void dmz_handle_read_zero(struct dmz_target *dmz, struct bio *bio,
148 sector_t chunk_block, unsigned int nr_blocks)
150 unsigned int size = nr_blocks << DMZ_BLOCK_SHIFT;
152 /* Clear nr_blocks */
153 swap(bio->bi_iter.bi_size, size);
155 swap(bio->bi_iter.bi_size, size);
157 bio_advance(bio, size);
161 * Process a read BIO.
163 static int dmz_handle_read(struct dmz_target *dmz, struct dm_zone *zone,
166 sector_t chunk_block = dmz_chunk_block(dmz->dev, dmz_bio_block(bio));
167 unsigned int nr_blocks = dmz_bio_blocks(bio);
168 sector_t end_block = chunk_block + nr_blocks;
169 struct dm_zone *rzone, *bzone;
172 /* Read into unmapped chunks need only zeroing the BIO buffer */
178 dmz_dev_debug(dmz->dev, "READ chunk %llu -> %s zone %u, block %llu, %u blocks",
179 (unsigned long long)dmz_bio_chunk(dmz->dev, bio),
180 (dmz_is_rnd(zone) ? "RND" : "SEQ"),
181 dmz_id(dmz->metadata, zone),
182 (unsigned long long)chunk_block, nr_blocks);
184 /* Check block validity to determine the read location */
186 while (chunk_block < end_block) {
188 if (dmz_is_rnd(zone) || chunk_block < zone->wp_block) {
189 /* Test block validity in the data zone */
190 ret = dmz_block_valid(dmz->metadata, zone, chunk_block);
194 /* Read data zone blocks */
201 * No valid blocks found in the data zone.
202 * Check the buffer zone, if there is one.
204 if (!nr_blocks && bzone) {
205 ret = dmz_block_valid(dmz->metadata, bzone, chunk_block);
209 /* Read buffer zone blocks */
216 /* Valid blocks found: read them */
217 nr_blocks = min_t(unsigned int, nr_blocks, end_block - chunk_block);
218 ret = dmz_submit_bio(dmz, rzone, bio, chunk_block, nr_blocks);
221 chunk_block += nr_blocks;
223 /* No valid block: zeroout the current BIO block */
224 dmz_handle_read_zero(dmz, bio, chunk_block, 1);
233 * Write blocks directly in a data zone, at the write pointer.
234 * If a buffer zone is assigned, invalidate the blocks written
237 static int dmz_handle_direct_write(struct dmz_target *dmz,
238 struct dm_zone *zone, struct bio *bio,
239 sector_t chunk_block,
240 unsigned int nr_blocks)
242 struct dmz_metadata *zmd = dmz->metadata;
243 struct dm_zone *bzone = zone->bzone;
246 if (dmz_is_readonly(zone))
250 ret = dmz_submit_bio(dmz, zone, bio, chunk_block, nr_blocks);
255 * Validate the blocks in the data zone and invalidate
256 * in the buffer zone, if there is one.
258 ret = dmz_validate_blocks(zmd, zone, chunk_block, nr_blocks);
259 if (ret == 0 && bzone)
260 ret = dmz_invalidate_blocks(zmd, bzone, chunk_block, nr_blocks);
266 * Write blocks in the buffer zone of @zone.
267 * If no buffer zone is assigned yet, get one.
268 * Called with @zone write locked.
270 static int dmz_handle_buffered_write(struct dmz_target *dmz,
271 struct dm_zone *zone, struct bio *bio,
272 sector_t chunk_block,
273 unsigned int nr_blocks)
275 struct dmz_metadata *zmd = dmz->metadata;
276 struct dm_zone *bzone;
279 /* Get the buffer zone. One will be allocated if needed */
280 bzone = dmz_get_chunk_buffer(zmd, zone);
282 return PTR_ERR(bzone);
284 if (dmz_is_readonly(bzone))
288 ret = dmz_submit_bio(dmz, bzone, bio, chunk_block, nr_blocks);
293 * Validate the blocks in the buffer zone
294 * and invalidate in the data zone.
296 ret = dmz_validate_blocks(zmd, bzone, chunk_block, nr_blocks);
297 if (ret == 0 && chunk_block < zone->wp_block)
298 ret = dmz_invalidate_blocks(zmd, zone, chunk_block, nr_blocks);
304 * Process a write BIO.
306 static int dmz_handle_write(struct dmz_target *dmz, struct dm_zone *zone,
309 sector_t chunk_block = dmz_chunk_block(dmz->dev, dmz_bio_block(bio));
310 unsigned int nr_blocks = dmz_bio_blocks(bio);
315 dmz_dev_debug(dmz->dev, "WRITE chunk %llu -> %s zone %u, block %llu, %u blocks",
316 (unsigned long long)dmz_bio_chunk(dmz->dev, bio),
317 (dmz_is_rnd(zone) ? "RND" : "SEQ"),
318 dmz_id(dmz->metadata, zone),
319 (unsigned long long)chunk_block, nr_blocks);
321 if (dmz_is_rnd(zone) || chunk_block == zone->wp_block) {
323 * zone is a random zone or it is a sequential zone
324 * and the BIO is aligned to the zone write pointer:
325 * direct write the zone.
327 return dmz_handle_direct_write(dmz, zone, bio, chunk_block, nr_blocks);
331 * This is an unaligned write in a sequential zone:
332 * use buffered write.
334 return dmz_handle_buffered_write(dmz, zone, bio, chunk_block, nr_blocks);
338 * Process a discard BIO.
340 static int dmz_handle_discard(struct dmz_target *dmz, struct dm_zone *zone,
343 struct dmz_metadata *zmd = dmz->metadata;
344 sector_t block = dmz_bio_block(bio);
345 unsigned int nr_blocks = dmz_bio_blocks(bio);
346 sector_t chunk_block = dmz_chunk_block(dmz->dev, block);
349 /* For unmapped chunks, there is nothing to do */
353 if (dmz_is_readonly(zone))
356 dmz_dev_debug(dmz->dev, "DISCARD chunk %llu -> zone %u, block %llu, %u blocks",
357 (unsigned long long)dmz_bio_chunk(dmz->dev, bio),
359 (unsigned long long)chunk_block, nr_blocks);
362 * Invalidate blocks in the data zone and its
363 * buffer zone if one is mapped.
365 if (dmz_is_rnd(zone) || chunk_block < zone->wp_block)
366 ret = dmz_invalidate_blocks(zmd, zone, chunk_block, nr_blocks);
367 if (ret == 0 && zone->bzone)
368 ret = dmz_invalidate_blocks(zmd, zone->bzone,
369 chunk_block, nr_blocks);
376 static void dmz_handle_bio(struct dmz_target *dmz, struct dm_chunk_work *cw,
379 struct dmz_bioctx *bioctx = dm_per_bio_data(bio, sizeof(struct dmz_bioctx));
380 struct dmz_metadata *zmd = dmz->metadata;
381 struct dm_zone *zone;
385 * Write may trigger a zone allocation. So make sure the
386 * allocation can succeed.
388 if (bio_op(bio) == REQ_OP_WRITE)
389 dmz_schedule_reclaim(dmz->reclaim);
391 dmz_lock_metadata(zmd);
393 if (dmz->dev->flags & DMZ_BDEV_DYING) {
399 * Get the data zone mapping the chunk. There may be no
400 * mapping for read and discard. If a mapping is obtained,
401 + the zone returned will be set to active state.
403 zone = dmz_get_chunk_mapping(zmd, dmz_bio_chunk(dmz->dev, bio),
410 /* Process the BIO */
412 dmz_activate_zone(zone);
416 switch (bio_op(bio)) {
418 ret = dmz_handle_read(dmz, zone, bio);
421 ret = dmz_handle_write(dmz, zone, bio);
424 case REQ_OP_WRITE_ZEROES:
425 ret = dmz_handle_discard(dmz, zone, bio);
428 dmz_dev_err(dmz->dev, "Unsupported BIO operation 0x%x",
434 * Release the chunk mapping. This will check that the mapping
435 * is still valid, that is, that the zone used still has valid blocks.
438 dmz_put_chunk_mapping(zmd, zone);
440 dmz_bio_endio(bio, errno_to_blk_status(ret));
442 dmz_unlock_metadata(zmd);
446 * Increment a chunk reference counter.
448 static inline void dmz_get_chunk_work(struct dm_chunk_work *cw)
450 refcount_inc(&cw->refcount);
454 * Decrement a chunk work reference count and
455 * free it if it becomes 0.
457 static void dmz_put_chunk_work(struct dm_chunk_work *cw)
459 if (refcount_dec_and_test(&cw->refcount)) {
460 WARN_ON(!bio_list_empty(&cw->bio_list));
461 radix_tree_delete(&cw->target->chunk_rxtree, cw->chunk);
467 * Chunk BIO work function.
469 static void dmz_chunk_work(struct work_struct *work)
471 struct dm_chunk_work *cw = container_of(work, struct dm_chunk_work, work);
472 struct dmz_target *dmz = cw->target;
475 mutex_lock(&dmz->chunk_lock);
477 /* Process the chunk BIOs */
478 while ((bio = bio_list_pop(&cw->bio_list))) {
479 mutex_unlock(&dmz->chunk_lock);
480 dmz_handle_bio(dmz, cw, bio);
481 mutex_lock(&dmz->chunk_lock);
482 dmz_put_chunk_work(cw);
485 /* Queueing the work incremented the work refcount */
486 dmz_put_chunk_work(cw);
488 mutex_unlock(&dmz->chunk_lock);
494 static void dmz_flush_work(struct work_struct *work)
496 struct dmz_target *dmz = container_of(work, struct dmz_target, flush_work.work);
500 /* Flush dirty metadata blocks */
501 ret = dmz_flush_metadata(dmz->metadata);
503 dmz_dev_debug(dmz->dev, "Metadata flush failed, rc=%d\n", ret);
505 /* Process queued flush requests */
507 spin_lock(&dmz->flush_lock);
508 bio = bio_list_pop(&dmz->flush_list);
509 spin_unlock(&dmz->flush_lock);
514 dmz_bio_endio(bio, errno_to_blk_status(ret));
517 queue_delayed_work(dmz->flush_wq, &dmz->flush_work, DMZ_FLUSH_PERIOD);
521 * Get a chunk work and start it to process a new BIO.
522 * If the BIO chunk has no work yet, create one.
524 static int dmz_queue_chunk_work(struct dmz_target *dmz, struct bio *bio)
526 unsigned int chunk = dmz_bio_chunk(dmz->dev, bio);
527 struct dm_chunk_work *cw;
530 mutex_lock(&dmz->chunk_lock);
532 /* Get the BIO chunk work. If one is not active yet, create one */
533 cw = radix_tree_lookup(&dmz->chunk_rxtree, chunk);
536 /* Create a new chunk work */
537 cw = kmalloc(sizeof(struct dm_chunk_work), GFP_NOIO);
543 INIT_WORK(&cw->work, dmz_chunk_work);
544 refcount_set(&cw->refcount, 0);
547 bio_list_init(&cw->bio_list);
549 ret = radix_tree_insert(&dmz->chunk_rxtree, chunk, cw);
556 bio_list_add(&cw->bio_list, bio);
557 dmz_get_chunk_work(cw);
559 dmz_reclaim_bio_acc(dmz->reclaim);
560 if (queue_work(dmz->chunk_wq, &cw->work))
561 dmz_get_chunk_work(cw);
563 mutex_unlock(&dmz->chunk_lock);
568 * Check the backing device availability. If it's on the way out,
569 * start failing I/O. Reclaim and metadata components also call this
570 * function to cleanly abort operation in the event of such failure.
572 bool dmz_bdev_is_dying(struct dmz_dev *dmz_dev)
574 struct gendisk *disk;
576 if (!(dmz_dev->flags & DMZ_BDEV_DYING)) {
577 disk = dmz_dev->bdev->bd_disk;
578 if (blk_queue_dying(bdev_get_queue(dmz_dev->bdev))) {
579 dmz_dev_warn(dmz_dev, "Backing device queue dying");
580 dmz_dev->flags |= DMZ_BDEV_DYING;
581 } else if (disk->fops->check_events) {
582 if (disk->fops->check_events(disk, 0) &
583 DISK_EVENT_MEDIA_CHANGE) {
584 dmz_dev_warn(dmz_dev, "Backing device offline");
585 dmz_dev->flags |= DMZ_BDEV_DYING;
590 return dmz_dev->flags & DMZ_BDEV_DYING;
596 static int dmz_map(struct dm_target *ti, struct bio *bio)
598 struct dmz_target *dmz = ti->private;
599 struct dmz_dev *dev = dmz->dev;
600 struct dmz_bioctx *bioctx = dm_per_bio_data(bio, sizeof(struct dmz_bioctx));
601 sector_t sector = bio->bi_iter.bi_sector;
602 unsigned int nr_sectors = bio_sectors(bio);
603 sector_t chunk_sector;
606 if (dmz_bdev_is_dying(dmz->dev))
607 return DM_MAPIO_KILL;
609 dmz_dev_debug(dev, "BIO op %d sector %llu + %u => chunk %llu, block %llu, %u blocks",
610 bio_op(bio), (unsigned long long)sector, nr_sectors,
611 (unsigned long long)dmz_bio_chunk(dmz->dev, bio),
612 (unsigned long long)dmz_chunk_block(dmz->dev, dmz_bio_block(bio)),
613 (unsigned int)dmz_bio_blocks(bio));
615 bio_set_dev(bio, dev->bdev);
617 if (!nr_sectors && bio_op(bio) != REQ_OP_WRITE)
618 return DM_MAPIO_REMAPPED;
620 /* The BIO should be block aligned */
621 if ((nr_sectors & DMZ_BLOCK_SECTORS_MASK) || (sector & DMZ_BLOCK_SECTORS_MASK))
622 return DM_MAPIO_KILL;
624 /* Initialize the BIO context */
625 bioctx->target = dmz;
628 refcount_set(&bioctx->ref, 1);
630 /* Set the BIO pending in the flush list */
631 if (!nr_sectors && bio_op(bio) == REQ_OP_WRITE) {
632 spin_lock(&dmz->flush_lock);
633 bio_list_add(&dmz->flush_list, bio);
634 spin_unlock(&dmz->flush_lock);
635 mod_delayed_work(dmz->flush_wq, &dmz->flush_work, 0);
636 return DM_MAPIO_SUBMITTED;
639 /* Split zone BIOs to fit entirely into a zone */
640 chunk_sector = sector & (dev->zone_nr_sectors - 1);
641 if (chunk_sector + nr_sectors > dev->zone_nr_sectors)
642 dm_accept_partial_bio(bio, dev->zone_nr_sectors - chunk_sector);
644 /* Now ready to handle this BIO */
645 ret = dmz_queue_chunk_work(dmz, bio);
647 dmz_dev_debug(dmz->dev,
648 "BIO op %d, can't process chunk %llu, err %i\n",
649 bio_op(bio), (u64)dmz_bio_chunk(dmz->dev, bio),
651 return DM_MAPIO_REQUEUE;
654 return DM_MAPIO_SUBMITTED;
658 * Get zoned device information.
660 static int dmz_get_zoned_device(struct dm_target *ti, char *path)
662 struct dmz_target *dmz = ti->private;
663 struct request_queue *q;
665 sector_t aligned_capacity;
668 /* Get the target device */
669 ret = dm_get_device(ti, path, dm_table_get_mode(ti->table), &dmz->ddev);
671 ti->error = "Get target device failed";
676 dev = kzalloc(sizeof(struct dmz_dev), GFP_KERNEL);
682 dev->bdev = dmz->ddev->bdev;
683 (void)bdevname(dev->bdev, dev->name);
685 if (bdev_zoned_model(dev->bdev) == BLK_ZONED_NONE) {
686 ti->error = "Not a zoned block device";
691 q = bdev_get_queue(dev->bdev);
692 dev->capacity = i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT;
693 aligned_capacity = dev->capacity &
694 ~((sector_t)blk_queue_zone_sectors(q) - 1);
696 ((ti->len != dev->capacity) && (ti->len != aligned_capacity))) {
697 ti->error = "Partial mapping not supported";
702 dev->zone_nr_sectors = blk_queue_zone_sectors(q);
703 dev->zone_nr_sectors_shift = ilog2(dev->zone_nr_sectors);
705 dev->zone_nr_blocks = dmz_sect2blk(dev->zone_nr_sectors);
706 dev->zone_nr_blocks_shift = ilog2(dev->zone_nr_blocks);
708 dev->nr_zones = blkdev_nr_zones(dev->bdev);
714 dm_put_device(ti, dmz->ddev);
721 * Cleanup zoned device information.
723 static void dmz_put_zoned_device(struct dm_target *ti)
725 struct dmz_target *dmz = ti->private;
727 dm_put_device(ti, dmz->ddev);
735 static int dmz_ctr(struct dm_target *ti, unsigned int argc, char **argv)
737 struct dmz_target *dmz;
741 /* Check arguments */
743 ti->error = "Invalid argument count";
747 /* Allocate and initialize the target descriptor */
748 dmz = kzalloc(sizeof(struct dmz_target), GFP_KERNEL);
750 ti->error = "Unable to allocate the zoned target descriptor";
755 /* Get the target zoned block device */
756 ret = dmz_get_zoned_device(ti, argv[0]);
762 /* Initialize metadata */
764 ret = dmz_ctr_metadata(dev, &dmz->metadata);
766 ti->error = "Metadata initialization failed";
770 /* Set target (no write same support) */
771 ti->max_io_len = dev->zone_nr_sectors << 9;
772 ti->num_flush_bios = 1;
773 ti->num_discard_bios = 1;
774 ti->num_write_zeroes_bios = 1;
775 ti->per_io_data_size = sizeof(struct dmz_bioctx);
776 ti->flush_supported = true;
777 ti->discards_supported = true;
779 /* The exposed capacity is the number of chunks that can be mapped */
780 ti->len = (sector_t)dmz_nr_chunks(dmz->metadata) << dev->zone_nr_sectors_shift;
783 ret = bioset_init(&dmz->bio_set, DMZ_MIN_BIOS, 0, 0);
785 ti->error = "Create BIO set failed";
790 mutex_init(&dmz->chunk_lock);
791 INIT_RADIX_TREE(&dmz->chunk_rxtree, GFP_NOIO);
792 dmz->chunk_wq = alloc_workqueue("dmz_cwq_%s", WQ_MEM_RECLAIM | WQ_UNBOUND,
794 if (!dmz->chunk_wq) {
795 ti->error = "Create chunk workqueue failed";
801 spin_lock_init(&dmz->flush_lock);
802 bio_list_init(&dmz->flush_list);
803 INIT_DELAYED_WORK(&dmz->flush_work, dmz_flush_work);
804 dmz->flush_wq = alloc_ordered_workqueue("dmz_fwq_%s", WQ_MEM_RECLAIM,
806 if (!dmz->flush_wq) {
807 ti->error = "Create flush workqueue failed";
811 mod_delayed_work(dmz->flush_wq, &dmz->flush_work, DMZ_FLUSH_PERIOD);
813 /* Initialize reclaim */
814 ret = dmz_ctr_reclaim(dev, dmz->metadata, &dmz->reclaim);
816 ti->error = "Zone reclaim initialization failed";
820 dmz_dev_info(dev, "Target device: %llu 512-byte logical sectors (%llu blocks)",
821 (unsigned long long)ti->len,
822 (unsigned long long)dmz_sect2blk(ti->len));
826 destroy_workqueue(dmz->flush_wq);
828 destroy_workqueue(dmz->chunk_wq);
830 mutex_destroy(&dmz->chunk_lock);
831 bioset_exit(&dmz->bio_set);
833 dmz_dtr_metadata(dmz->metadata);
835 dmz_put_zoned_device(ti);
845 static void dmz_dtr(struct dm_target *ti)
847 struct dmz_target *dmz = ti->private;
849 flush_workqueue(dmz->chunk_wq);
850 destroy_workqueue(dmz->chunk_wq);
852 dmz_dtr_reclaim(dmz->reclaim);
854 cancel_delayed_work_sync(&dmz->flush_work);
855 destroy_workqueue(dmz->flush_wq);
857 (void) dmz_flush_metadata(dmz->metadata);
859 dmz_dtr_metadata(dmz->metadata);
861 bioset_exit(&dmz->bio_set);
863 dmz_put_zoned_device(ti);
865 mutex_destroy(&dmz->chunk_lock);
871 * Setup target request queue limits.
873 static void dmz_io_hints(struct dm_target *ti, struct queue_limits *limits)
875 struct dmz_target *dmz = ti->private;
876 unsigned int chunk_sectors = dmz->dev->zone_nr_sectors;
878 limits->logical_block_size = DMZ_BLOCK_SIZE;
879 limits->physical_block_size = DMZ_BLOCK_SIZE;
881 blk_limits_io_min(limits, DMZ_BLOCK_SIZE);
882 blk_limits_io_opt(limits, DMZ_BLOCK_SIZE);
884 limits->discard_alignment = DMZ_BLOCK_SIZE;
885 limits->discard_granularity = DMZ_BLOCK_SIZE;
886 limits->max_discard_sectors = chunk_sectors;
887 limits->max_hw_discard_sectors = chunk_sectors;
888 limits->max_write_zeroes_sectors = chunk_sectors;
890 /* FS hint to try to align to the device zone size */
891 limits->chunk_sectors = chunk_sectors;
892 limits->max_sectors = chunk_sectors;
894 /* We are exposing a drive-managed zoned block device */
895 limits->zoned = BLK_ZONED_NONE;
899 * Pass on ioctl to the backend device.
901 static int dmz_prepare_ioctl(struct dm_target *ti, struct block_device **bdev)
903 struct dmz_target *dmz = ti->private;
905 if (dmz_bdev_is_dying(dmz->dev))
908 *bdev = dmz->dev->bdev;
914 * Stop works on suspend.
916 static void dmz_suspend(struct dm_target *ti)
918 struct dmz_target *dmz = ti->private;
920 flush_workqueue(dmz->chunk_wq);
921 dmz_suspend_reclaim(dmz->reclaim);
922 cancel_delayed_work_sync(&dmz->flush_work);
926 * Restart works on resume or if suspend failed.
928 static void dmz_resume(struct dm_target *ti)
930 struct dmz_target *dmz = ti->private;
932 queue_delayed_work(dmz->flush_wq, &dmz->flush_work, DMZ_FLUSH_PERIOD);
933 dmz_resume_reclaim(dmz->reclaim);
936 static int dmz_iterate_devices(struct dm_target *ti,
937 iterate_devices_callout_fn fn, void *data)
939 struct dmz_target *dmz = ti->private;
940 struct dmz_dev *dev = dmz->dev;
941 sector_t capacity = dev->capacity & ~(dev->zone_nr_sectors - 1);
943 return fn(ti, dmz->ddev, 0, capacity, data);
946 static struct target_type dmz_type = {
948 .version = {1, 0, 0},
949 .features = DM_TARGET_SINGLETON | DM_TARGET_ZONED_HM,
950 .module = THIS_MODULE,
954 .io_hints = dmz_io_hints,
955 .prepare_ioctl = dmz_prepare_ioctl,
956 .postsuspend = dmz_suspend,
957 .resume = dmz_resume,
958 .iterate_devices = dmz_iterate_devices,
961 static int __init dmz_init(void)
963 return dm_register_target(&dmz_type);
966 static void __exit dmz_exit(void)
968 dm_unregister_target(&dmz_type);
971 module_init(dmz_init);
972 module_exit(dmz_exit);
974 MODULE_DESCRIPTION(DM_NAME " target for zoned block devices");
975 MODULE_AUTHOR("Damien Le Moal <damien.lemoal@wdc.com>");
976 MODULE_LICENSE("GPL");