Lines Matching +full:suspend +full:- +full:to +full:- +full:disk
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
8 #include "dm-core.h"
9 #include "dm-rq.h"
10 #include "dm-uevent.h"
11 #include "dm-ima.h"
31 #include <linux/blk-crypto.h>
32 #include <linux/blk-crypto-profile.h>
45 * dm_io into one list, and reuse bio->bi_private as the list head. Before
46 * ending this fs bio, we will recover its ->bi_private.
79 * One of these is allocated (on-stack) per original bio.
99 return (char *)bio - DM_TARGET_IO_BIO_OFFSET - data_size; in dm_per_bio_data()
100 return (char *)bio - DM_IO_BIO_OFFSET - data_size; in dm_per_bio_data()
107 if (io->magic == DM_IO_MAGIC) in dm_bio_from_per_bio_data()
109 BUG_ON(io->magic != DM_TIO_MAGIC); in dm_bio_from_per_bio_data()
116 return container_of(bio, struct dm_target_io, clone)->target_bio_nr; in dm_bio_get_target_bio_nr()
120 #define MINOR_ALLOCED ((void *)-1)
142 * Bio-based DM's mempools' reserved IOs set by the user.
197 DM_NUMA_NODE, num_online_nodes() - 1); in dm_get_numa_node()
210 r = -ENOMEM; in local_init()
285 while (i--) in dm_init()
295 while (i--) in dm_exit()
309 return test_bit(DMF_DELETING, &md->flags); in dm_deleting_md()
318 md = bdev->bd_disk->private_data; in dm_blk_open()
322 if (test_bit(DMF_FREEING, &md->flags) || in dm_blk_open()
329 atomic_inc(&md->open_count); in dm_blk_open()
333 return md ? 0 : -ENXIO; in dm_blk_open()
336 static void dm_blk_close(struct gendisk *disk, fmode_t mode) in dm_blk_close() argument
342 md = disk->private_data; in dm_blk_close()
346 if (atomic_dec_and_test(&md->open_count) && in dm_blk_close()
347 (test_bit(DMF_DEFERRED_REMOVE, &md->flags))) in dm_blk_close()
357 return atomic_read(&md->open_count); in dm_open_count()
370 r = -EBUSY; in dm_lock_for_deletion()
372 set_bit(DMF_DEFERRED_REMOVE, &md->flags); in dm_lock_for_deletion()
373 } else if (only_deferred && !test_bit(DMF_DEFERRED_REMOVE, &md->flags)) in dm_lock_for_deletion()
374 r = -EEXIST; in dm_lock_for_deletion()
376 set_bit(DMF_DELETING, &md->flags); in dm_lock_for_deletion()
389 if (test_bit(DMF_DELETING, &md->flags)) in dm_cancel_deferred_remove()
390 r = -EBUSY; in dm_cancel_deferred_remove()
392 clear_bit(DMF_DEFERRED_REMOVE, &md->flags); in dm_cancel_deferred_remove()
406 struct mapped_device *md = bdev->bd_disk->private_data; in dm_blk_getgeo()
419 r = -ENOTTY; in dm_prepare_ioctl()
425 if (map->num_targets != 1) in dm_prepare_ioctl()
429 if (!ti->type->prepare_ioctl) in dm_prepare_ioctl()
433 return -EAGAIN; in dm_prepare_ioctl()
435 r = ti->type->prepare_ioctl(ti, bdev); in dm_prepare_ioctl()
436 if (r == -ENOTCONN && !fatal_signal_pending(current)) { in dm_prepare_ioctl()
453 struct mapped_device *md = bdev->bd_disk->private_data; in dm_blk_ioctl()
467 "%s: sending ioctl %x to DM device without required privilege.", in dm_blk_ioctl()
468 current->comm, cmd); in dm_blk_ioctl()
469 r = -ENOIOCTLCMD; in dm_blk_ioctl()
474 if (!bdev->bd_disk->fops->ioctl) in dm_blk_ioctl()
475 r = -ENOTTY; in dm_blk_ioctl()
477 r = bdev->bd_disk->fops->ioctl(bdev, mode, cmd, arg); in dm_blk_ioctl()
485 return jiffies_to_nsecs(clone_to_tio(bio)->io->start_time); in dm_start_time_ns_from_clone()
491 return ((bio->bi_opf & REQ_PREFLUSH) && bio->bi_iter.bi_size); in bio_is_flush_with_data()
496 struct dm_stats_aux *stats_aux = &io->stats_aux; in dm_io_acct()
497 unsigned long start_time = io->start_time; in dm_io_acct()
498 struct mapped_device *md = io->md; in dm_io_acct()
499 struct bio *bio = io->orig_bio; in dm_io_acct()
511 sectors = io->sectors; in dm_io_acct()
514 bdev_start_io_acct(bio->bi_bdev, sectors, bio_op(bio), in dm_io_acct()
517 bdev_end_io_acct(bio->bi_bdev, bio_op(bio), start_time); in dm_io_acct()
520 unlikely(dm_stats_used(&md->stats))) { in dm_io_acct()
524 sector = bio->bi_iter.bi_sector; in dm_io_acct()
526 sector = bio_end_sector(bio) - io->sector_offset; in dm_io_acct()
528 dm_stats_account_io(&md->stats, bio_data_dir(bio), in dm_io_acct()
553 spin_lock_irqsave(&io->lock, flags); in dm_start_io_acct()
555 spin_unlock_irqrestore(&io->lock, flags); in dm_start_io_acct()
559 spin_unlock_irqrestore(&io->lock, flags); in dm_start_io_acct()
576 clone = bio_alloc_clone(NULL, bio, GFP_NOIO, &md->mempools->io_bs); in alloc_io()
578 tio->flags = 0; in alloc_io()
580 tio->io = NULL; in alloc_io()
583 io->magic = DM_IO_MAGIC; in alloc_io()
584 io->status = BLK_STS_OK; in alloc_io()
587 atomic_set(&io->io_count, 2); in alloc_io()
588 this_cpu_inc(*md->pending_io); in alloc_io()
589 io->orig_bio = bio; in alloc_io()
590 io->md = md; in alloc_io()
591 spin_lock_init(&io->lock); in alloc_io()
592 io->start_time = jiffies; in alloc_io()
593 io->flags = 0; in alloc_io()
596 dm_stats_record_start(&md->stats, &io->stats_aux); in alloc_io()
603 bio_put(&io->tio.clone); in free_io()
609 struct mapped_device *md = ci->io->md; in alloc_tio()
613 if (!ci->io->tio.io) { in alloc_tio()
614 /* the dm_target_io embedded in ci->io is available */ in alloc_tio()
615 tio = &ci->io->tio; in alloc_tio()
617 clone = &tio->clone; in alloc_tio()
619 clone = bio_alloc_clone(NULL, ci->bio, gfp_mask, in alloc_tio()
620 &md->mempools->bs); in alloc_tio()
625 clone->bi_opf &= ~REQ_DM_POLL_LIST; in alloc_tio()
628 tio->flags = 0; /* also clears DM_TIO_INSIDE_DM_IO */ in alloc_tio()
631 tio->magic = DM_TIO_MAGIC; in alloc_tio()
632 tio->io = ci->io; in alloc_tio()
633 tio->ti = ti; in alloc_tio()
634 tio->target_bio_nr = target_bio_nr; in alloc_tio()
635 tio->len_ptr = len; in alloc_tio()
636 tio->old_sector = 0; in alloc_tio()
639 clone->bi_bdev = md->disk->part0; in alloc_tio()
640 if (unlikely(ti->needs_bio_set_dev)) in alloc_tio()
641 bio_set_dev(clone, md->disk->part0); in alloc_tio()
644 clone->bi_iter.bi_size = to_bytes(*len); in alloc_tio()
660 * Add the bio to the list of deferred io.
666 spin_lock_irqsave(&md->deferred_lock, flags); in queue_io()
667 bio_list_add(&md->deferred, bio); in queue_io()
668 spin_unlock_irqrestore(&md->deferred_lock, flags); in queue_io()
669 queue_work(md->wq, &md->work); in queue_io()
674 * function to access the md->map field, and make sure they call
678 int *srcu_idx) __acquires(md->io_barrier) in dm_get_live_table()
680 *srcu_idx = srcu_read_lock(&md->io_barrier); in dm_get_live_table()
682 return srcu_dereference(md->map, &md->io_barrier); in dm_get_live_table()
686 int srcu_idx) __releases(md->io_barrier) in dm_put_live_table()
688 srcu_read_unlock(&md->io_barrier, srcu_idx); in dm_put_live_table()
693 synchronize_srcu(&md->io_barrier); in dm_sync_table()
698 * A fast alternative to dm_get_live_table/dm_put_live_table.
704 return rcu_dereference(md->map); in dm_get_live_table_fast()
730 static char *_dm_claim_ptr = "I belong to device-mapper";
742 BUG_ON(td->dm_dev.bdev); in open_table_device()
744 bdev = blkdev_get_by_dev(dev, td->dm_dev.mode | FMODE_EXCL, _dm_claim_ptr); in open_table_device()
750 blkdev_put(bdev, td->dm_dev.mode | FMODE_EXCL); in open_table_device()
754 td->dm_dev.bdev = bdev; in open_table_device()
755 td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev, &part_off, NULL, NULL); in open_table_device()
764 if (!td->dm_dev.bdev) in close_table_device()
767 bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md)); in close_table_device()
768 blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL); in close_table_device()
769 put_dax(td->dm_dev.dax_dev); in close_table_device()
770 td->dm_dev.bdev = NULL; in close_table_device()
771 td->dm_dev.dax_dev = NULL; in close_table_device()
780 if (td->dm_dev.bdev->bd_dev == dev && td->dm_dev.mode == mode) in find_table_device()
792 mutex_lock(&md->table_devices_lock); in dm_get_table_device()
793 td = find_table_device(&md->table_devices, dev, mode); in dm_get_table_device()
795 td = kmalloc_node(sizeof(*td), GFP_KERNEL, md->numa_node_id); in dm_get_table_device()
797 mutex_unlock(&md->table_devices_lock); in dm_get_table_device()
798 return -ENOMEM; in dm_get_table_device()
801 td->dm_dev.mode = mode; in dm_get_table_device()
802 td->dm_dev.bdev = NULL; in dm_get_table_device()
805 mutex_unlock(&md->table_devices_lock); in dm_get_table_device()
810 format_dev_t(td->dm_dev.name, dev); in dm_get_table_device()
812 refcount_set(&td->count, 1); in dm_get_table_device()
813 list_add(&td->list, &md->table_devices); in dm_get_table_device()
815 refcount_inc(&td->count); in dm_get_table_device()
817 mutex_unlock(&md->table_devices_lock); in dm_get_table_device()
819 *result = &td->dm_dev; in dm_get_table_device()
827 mutex_lock(&md->table_devices_lock); in dm_put_table_device()
828 if (refcount_dec_and_test(&td->count)) { in dm_put_table_device()
830 list_del(&td->list); in dm_put_table_device()
833 mutex_unlock(&md->table_devices_lock); in dm_put_table_device()
844 td->dm_dev.name, refcount_read(&td->count)); in free_table_devices()
854 *geo = md->geometry; in dm_get_geometry()
864 sector_t sz = (sector_t)geo->cylinders * geo->heads * geo->sectors; in dm_set_geometry()
866 if (geo->start > sz) { in dm_set_geometry()
868 return -EINVAL; in dm_set_geometry()
871 md->geometry = *geo; in dm_set_geometry()
878 return test_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __noflush_suspending()
883 struct mapped_device *md = io->md; in dm_requeue_add_io()
886 struct dm_io *next = md->requeue_list; in dm_requeue_add_io()
888 md->requeue_list = io; in dm_requeue_add_io()
889 io->next = next; in dm_requeue_add_io()
891 bio_list_add_head(&md->deferred, io->orig_bio); in dm_requeue_add_io()
898 queue_work(md->wq, &md->requeue_work); in dm_kick_requeue()
900 queue_work(md->wq, &md->work); in dm_kick_requeue()
905 * io->status is updated with error if requeue disallowed.
909 struct bio *bio = io->orig_bio; in dm_handle_requeue()
910 bool handle_requeue = (io->status == BLK_STS_DM_REQUEUE); in dm_handle_requeue()
911 bool handle_polled_eagain = ((io->status == BLK_STS_AGAIN) && in dm_handle_requeue()
912 (bio->bi_opf & REQ_POLLED)); in dm_handle_requeue()
913 struct mapped_device *md = io->md; in dm_handle_requeue()
919 if (bio->bi_opf & REQ_POLLED) { in dm_handle_requeue()
922 * (io->orig_bio may only reflect a subset of the in dm_handle_requeue()
923 * pre-split original) so clear REQ_POLLED. in dm_handle_requeue()
932 spin_lock_irqsave(&md->deferred_lock, flags); in dm_handle_requeue()
940 * noflush suspend was interrupted or this is in dm_handle_requeue()
941 * a write to a zoned target. in dm_handle_requeue()
943 io->status = BLK_STS_IOERR; in dm_handle_requeue()
945 spin_unlock_irqrestore(&md->deferred_lock, flags); in dm_handle_requeue()
956 struct bio *bio = io->orig_bio; in __dm_io_complete()
957 struct mapped_device *md = io->md; in __dm_io_complete()
965 io_error = io->status; in __dm_io_complete()
970 * Must handle target that DM_MAPIO_SUBMITTED only to in __dm_io_complete()
978 this_cpu_dec(*md->pending_io); in __dm_io_complete()
980 /* nudge anyone waiting on suspend queue */ in __dm_io_complete()
981 if (unlikely(wq_has_sleeper(&md->wait))) in __dm_io_complete()
982 wake_up(&md->wait); in __dm_io_complete()
993 bio->bi_opf &= ~REQ_PREFLUSH; in __dm_io_complete()
998 bio->bi_status = io_error; in __dm_io_complete()
1010 /* reuse deferred lock to simplify dm_handle_requeue */ in dm_wq_requeue_work()
1011 spin_lock_irqsave(&md->deferred_lock, flags); in dm_wq_requeue_work()
1012 io = md->requeue_list; in dm_wq_requeue_work()
1013 md->requeue_list = NULL; in dm_wq_requeue_work()
1014 spin_unlock_irqrestore(&md->deferred_lock, flags); in dm_wq_requeue_work()
1017 struct dm_io *next = io->next; in dm_wq_requeue_work()
1019 dm_io_rewind(io, &md->disk->bio_split); in dm_wq_requeue_work()
1021 io->next = NULL; in dm_wq_requeue_work()
1030 * 1) io->orig_bio points to the real original bio, and the part mapped to
1033 * 2) io->orig_bio points to new cloned bio which matches the requeued dm_io.
1041 * we may run into long bio clone chain during suspend and OOM could in dm_io_complete()
1061 if (atomic_dec_and_test(&io->io_count)) in __dm_io_dec_pending()
1069 /* Push-back supersedes any I/O errors */ in dm_io_set_error()
1070 spin_lock_irqsave(&io->lock, flags); in dm_io_set_error()
1071 if (!(io->status == BLK_STS_DM_REQUEUE && in dm_io_set_error()
1072 __noflush_suspending(io->md))) { in dm_io_set_error()
1073 io->status = error; in dm_io_set_error()
1075 spin_unlock_irqrestore(&io->lock, flags); in dm_io_set_error()
1091 limits->max_discard_sectors = 0; in disable_discard()
1099 limits->max_write_zeroes_sectors = 0; in disable_write_zeroes()
1104 return unlikely((bio->bi_opf & REQ_SWAP) != 0) && unlikely(ti->limit_swap_bios); in swap_bios_limit()
1109 blk_status_t error = bio->bi_status; in clone_endio()
1111 struct dm_target *ti = tio->ti; in clone_endio()
1112 dm_endio_fn endio = ti->type->end_io; in clone_endio()
1113 struct dm_io *io = tio->io; in clone_endio()
1114 struct mapped_device *md = io->md; in clone_endio()
1118 !bdev_max_discard_sectors(bio->bi_bdev)) in clone_endio()
1121 !bdev_write_zeroes_sectors(bio->bi_bdev)) in clone_endio()
1126 unlikely(bdev_is_zoned(bio->bi_bdev))) in clone_endio()
1135 * Requeuing writes to a sequential zone of a zoned in clone_endio()
1159 up(&md->swap_bios_semaphore); in clone_endio()
1166 * Return maximum size of I/O possible at the supplied sector up to the current
1172 return ti->len - target_offset; in max_io_len_target_boundary()
1181 * Does the target need to split IO even further? in max_io_len()
1182 * - varied (per target) IO splitting is a tenet of DM; this in max_io_len()
1186 if (!ti->max_io_len) in max_io_len()
1189 min(queue_max_sectors(ti->table->md->queue), in max_io_len()
1190 blk_chunk_sectors_left(target_offset, ti->max_io_len))); in max_io_len()
1198 ti->error = "Maximum size of target IO is too large"; in dm_set_target_max_io_len()
1199 return -EINVAL; in dm_set_target_max_io_len()
1202 ti->max_io_len = (uint32_t) len; in dm_set_target_max_io_len()
1210 __acquires(md->io_barrier) in dm_dax_get_live_target()
1233 long len, ret = -EIO; in dm_dax_direct_access()
1240 if (!ti->type->direct_access) in dm_dax_direct_access()
1246 ret = ti->type->direct_access(ti, pgoff, nr_pages, mode, kaddr, pfn); in dm_dax_direct_access()
1260 int ret = -EIO; in dm_dax_zero_page_range()
1267 if (WARN_ON(!ti->type->dax_zero_page_range)) { in dm_dax_zero_page_range()
1269 * ->zero_page_range() is mandatory dax operation. If we are in dm_dax_zero_page_range()
1274 ret = ti->type->dax_zero_page_range(ti, pgoff, nr_pages); in dm_dax_zero_page_range()
1291 if (!ti || !ti->type->dax_recovery_write) in dm_dax_recovery_write()
1294 ret = ti->type->dax_recovery_write(ti, pgoff, addr, bytes, i); in dm_dax_recovery_write()
1306 * dm_accept_partial_bio informs the dm that the target only wants to process
1311 * +--------------------+---------------+-------+
1313 * +--------------------+---------------+-------+
1315 * <-------------- *tio->len_ptr --------------->
1316 * <----- bio_sectors ----->
1317 * <-- n_sectors -->
1321 * Region 2 is the remaining bio size that the target wants to process.
1322 * (it may be empty if region 1 is non-empty, although there is no reason
1323 * to make it empty)
1324 * The target requires that region 3 is to be sent in the next bio.
1326 * If the target wants to receive multiple copies of the bio (via num_*bios, etc),
1333 struct dm_io *io = tio->io; in dm_accept_partial_bio()
1339 BUG_ON(bio_sectors > *tio->len_ptr); in dm_accept_partial_bio()
1342 *tio->len_ptr -= bio_sectors - n_sectors; in dm_accept_partial_bio()
1343 bio->bi_iter.bi_size = n_sectors << SECTOR_SHIFT; in dm_accept_partial_bio()
1350 io->sectors = n_sectors; in dm_accept_partial_bio()
1351 io->sector_offset = bio_sectors(io->orig_bio); in dm_accept_partial_bio()
1356 * @clone: clone bio that DM core passed to target's .map function
1359 * Targets should use this interface to submit bios they take
1362 * Target should also enable ti->accounts_remapped_io
1367 struct dm_io *io = tio->io; in dm_submit_bio_remap()
1374 * Account io->origin_bio to DM dev on behalf of target in dm_submit_bio_remap()
1379 trace_block_bio_remap(tgt_clone, disk_devt(io->md->disk), in dm_submit_bio_remap()
1380 tio->old_sector); in dm_submit_bio_remap()
1387 mutex_lock(&md->swap_bios_lock); in __set_swap_bios_limit()
1388 while (latch < md->swap_bios) { in __set_swap_bios_limit()
1390 down(&md->swap_bios_semaphore); in __set_swap_bios_limit()
1391 md->swap_bios--; in __set_swap_bios_limit()
1393 while (latch > md->swap_bios) { in __set_swap_bios_limit()
1395 up(&md->swap_bios_semaphore); in __set_swap_bios_limit()
1396 md->swap_bios++; in __set_swap_bios_limit()
1398 mutex_unlock(&md->swap_bios_lock); in __set_swap_bios_limit()
1404 struct dm_target *ti = tio->ti; in __map_bio()
1405 struct dm_io *io = tio->io; in __map_bio()
1406 struct mapped_device *md = io->md; in __map_bio()
1409 clone->bi_end_io = clone_endio; in __map_bio()
1414 tio->old_sector = clone->bi_iter.bi_sector; in __map_bio()
1419 if (unlikely(latch != md->swap_bios)) in __map_bio()
1421 down(&md->swap_bios_semaphore); in __map_bio()
1426 * Check if the IO needs a special mapping due to zone append in __map_bio()
1433 r = ti->type->map(ti, clone); in __map_bio()
1435 r = ti->type->map(ti, clone); in __map_bio()
1440 if (!ti->accounts_remapped_io) in __map_bio()
1450 up(&md->swap_bios_semaphore); in __map_bio()
1465 struct dm_io *io = ci->io; in setup_split_accounting()
1467 if (ci->sector_count > len) { in setup_split_accounting()
1473 io->sectors = len; in setup_split_accounting()
1474 io->sector_offset = bio_sectors(ci->bio); in setup_split_accounting()
1488 mutex_lock(&ci->io->md->table_devices_lock); in alloc_multiple_bios()
1498 mutex_unlock(&ci->io->md->table_devices_lock); in alloc_multiple_bios()
1525 /* dm_accept_partial_bio() is not supported with shared tio->len_ptr */ in __send_duplicate_bios()
1540 struct dm_table *t = ci->map; in __send_empty_flush()
1544 * Use an on-stack bio for this, it's safe since we don't in __send_empty_flush()
1545 * need to reference it after submit. It's just used as in __send_empty_flush()
1548 bio_init(&flush_bio, ci->io->md->disk->part0, NULL, 0, in __send_empty_flush()
1551 ci->bio = &flush_bio; in __send_empty_flush()
1552 ci->sector_count = 0; in __send_empty_flush()
1553 ci->io->tio.clone.bi_iter.bi_size = 0; in __send_empty_flush()
1555 for (unsigned int i = 0; i < t->num_targets; i++) { in __send_empty_flush()
1559 atomic_add(ti->num_flush_bios, &ci->io->io_count); in __send_empty_flush()
1560 bios = __send_duplicate_bios(ci, ti, ti->num_flush_bios, NULL); in __send_empty_flush()
1561 atomic_sub(ti->num_flush_bios - bios, &ci->io->io_count); in __send_empty_flush()
1568 atomic_sub(1, &ci->io->io_count); in __send_empty_flush()
1570 bio_uninit(ci->bio); in __send_empty_flush()
1579 len = min_t(sector_t, ci->sector_count, in __send_changing_extent_only()
1580 max_io_len_target_boundary(ti, dm_target_offset(ti, ci->sector))); in __send_changing_extent_only()
1582 atomic_add(num_bios, &ci->io->io_count); in __send_changing_extent_only()
1588 atomic_sub(num_bios - bios + 1, &ci->io->io_count); in __send_changing_extent_only()
1590 ci->sector += len; in __send_changing_extent_only()
1591 ci->sector_count -= len; in __send_changing_extent_only()
1617 switch (bio_op(ci->bio)) { in __process_abnormal_io()
1619 num_bios = ti->num_discard_bios; in __process_abnormal_io()
1622 num_bios = ti->num_secure_erase_bios; in __process_abnormal_io()
1625 num_bios = ti->num_write_zeroes_bios; in __process_abnormal_io()
1645 * Reuse ->bi_private as dm_io list head for storing all dm_io instances
1646 * associated with this bio, and this bio's bi_private needs to be
1647 * stored in dm_io->data before the reuse.
1649 * bio->bi_private is owned by fs or upper layer, so block layer won't
1655 return (struct dm_io **)&bio->bi_private; in dm_poll_list_head()
1662 if (!(bio->bi_opf & REQ_DM_POLL_LIST)) { in dm_queue_poll_io()
1663 bio->bi_opf |= REQ_DM_POLL_LIST; in dm_queue_poll_io()
1668 io->data = bio->bi_private; in dm_queue_poll_io()
1670 /* tell block layer to poll for completion */ in dm_queue_poll_io()
1671 bio->bi_cookie = ~BLK_QC_T_NONE; in dm_queue_poll_io()
1673 io->next = NULL; in dm_queue_poll_io()
1676 * bio recursed due to split, reuse original poll list, in dm_queue_poll_io()
1677 * and save bio->bi_private too. in dm_queue_poll_io()
1679 io->data = (*head)->data; in dm_queue_poll_io()
1680 io->next = *head; in dm_queue_poll_io()
1687 * Select the correct strategy for processing a non-flush bio.
1695 ti = dm_table_find_target(ci->map, ci->sector); in __split_and_process_bio()
1699 if (unlikely((ci->bio->bi_opf & REQ_NOWAIT) != 0) && in __split_and_process_bio()
1700 unlikely(!dm_target_supports_nowait(ti->type))) in __split_and_process_bio()
1703 if (unlikely(ci->is_abnormal_io)) in __split_and_process_bio()
1710 ci->submit_as_polled = !!(ci->bio->bi_opf & REQ_POLLED); in __split_and_process_bio()
1712 len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count); in __split_and_process_bio()
1717 ci->sector += len; in __split_and_process_bio()
1718 ci->sector_count -= len; in __split_and_process_bio()
1726 ci->map = map; in init_clone_info()
1727 ci->io = alloc_io(md, bio); in init_clone_info()
1728 ci->bio = bio; in init_clone_info()
1729 ci->is_abnormal_io = is_abnormal; in init_clone_info()
1730 ci->submit_as_polled = false; in init_clone_info()
1731 ci->sector = bio->bi_iter.bi_sector; in init_clone_info()
1732 ci->sector_count = bio_sectors(bio); in init_clone_info()
1734 /* Shouldn't happen but sector_count was being set to 0 so... */ in init_clone_info()
1736 WARN_ON_ONCE(op_is_zone_mgmt(bio_op(bio)) && ci->sector_count)) in init_clone_info()
1737 ci->sector_count = 0; in init_clone_info()
1741 * Entry point to split a bio into clones and submit them to the targets.
1763 if (bio->bi_opf & REQ_PREFLUSH) { in dm_split_and_process_bio()
1773 * Remainder must be passed to submit_bio_noacct() so it gets handled in dm_split_and_process_bio()
1776 bio_trim(bio, io->sectors, ci.sector_count); in dm_split_and_process_bio()
1777 trace_block_split(bio, bio->bi_iter.bi_sector); in dm_split_and_process_bio()
1782 * Drop the extra reference count for non-POLLED bio, and hold one in dm_split_and_process_bio()
1786 * in bio->bi_private, so that dm_poll_bio can poll them all. in dm_split_and_process_bio()
1794 atomic_dec(&io->io_count); in dm_split_and_process_bio()
1802 struct mapped_device *md = bio->bi_bdev->bd_disk->private_data; in dm_submit_bio()
1805 blk_opf_t bio_opf = bio->bi_opf; in dm_submit_bio()
1810 if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) || in dm_submit_bio()
1812 if (bio->bi_opf & REQ_NOWAIT) in dm_submit_bio()
1814 else if (bio->bi_opf & REQ_RAHEAD) in dm_submit_bio()
1829 WARN_ON_ONCE(!dm_tio_is_normal(&io->tio)); in dm_poll_dm_io()
1832 if (atomic_read(&io->io_count) > 1) in dm_poll_dm_io()
1833 bio_poll(&io->tio.clone, iob, flags); in dm_poll_dm_io()
1836 return atomic_read(&io->io_count) == 1; in dm_poll_dm_io()
1848 if (!(bio->bi_opf & REQ_DM_POLL_LIST)) in dm_poll_bio()
1857 * submitted via submit_bio_noacct()'s depth-first submission. in dm_poll_bio()
1861 bio->bi_opf &= ~REQ_DM_POLL_LIST; in dm_poll_bio()
1862 bio->bi_private = list->data; in dm_poll_bio()
1864 for (curr = list, next = curr->next; curr; curr = next, next = in dm_poll_bio()
1865 curr ? curr->next : NULL) { in dm_poll_bio()
1873 curr->next = tmp; in dm_poll_bio()
1880 bio->bi_opf |= REQ_DM_POLL_LIST; in dm_poll_bio()
1881 /* Reset bio->bi_private to dm_io list head */ in dm_poll_bio()
1888 /*-----------------------------------------------------------------
1889 * An IDR is used to keep track of allocated minor numbers.
1890 *---------------------------------------------------------------*/
1906 return -EINVAL; in specific_minor()
1916 return r == -ENOSPC ? -EBUSY : r; in specific_minor()
1946 dm_destroy_crypto_profile(q->crypto_profile); in dm_queue_destroy_crypto_profile()
1958 if (md->wq) in cleanup_mapped_device()
1959 destroy_workqueue(md->wq); in cleanup_mapped_device()
1960 dm_free_md_mempools(md->mempools); in cleanup_mapped_device()
1962 if (md->dax_dev) { in cleanup_mapped_device()
1963 dax_remove_host(md->disk); in cleanup_mapped_device()
1964 kill_dax(md->dax_dev); in cleanup_mapped_device()
1965 put_dax(md->dax_dev); in cleanup_mapped_device()
1966 md->dax_dev = NULL; in cleanup_mapped_device()
1970 if (md->disk) { in cleanup_mapped_device()
1972 md->disk->private_data = NULL; in cleanup_mapped_device()
1976 del_gendisk(md->disk); in cleanup_mapped_device()
1978 dm_queue_destroy_crypto_profile(md->queue); in cleanup_mapped_device()
1979 put_disk(md->disk); in cleanup_mapped_device()
1982 if (md->pending_io) { in cleanup_mapped_device()
1983 free_percpu(md->pending_io); in cleanup_mapped_device()
1984 md->pending_io = NULL; in cleanup_mapped_device()
1987 cleanup_srcu_struct(&md->io_barrier); in cleanup_mapped_device()
1989 mutex_destroy(&md->suspend_lock); in cleanup_mapped_device()
1990 mutex_destroy(&md->type_lock); in cleanup_mapped_device()
1991 mutex_destroy(&md->table_devices_lock); in cleanup_mapped_device()
1992 mutex_destroy(&md->swap_bios_lock); in cleanup_mapped_device()
2008 DMERR("unable to allocate device, out of memory."); in alloc_dev()
2023 r = init_srcu_struct(&md->io_barrier); in alloc_dev()
2027 md->numa_node_id = numa_node_id; in alloc_dev()
2028 md->init_tio_pdu = false; in alloc_dev()
2029 md->type = DM_TYPE_NONE; in alloc_dev()
2030 mutex_init(&md->suspend_lock); in alloc_dev()
2031 mutex_init(&md->type_lock); in alloc_dev()
2032 mutex_init(&md->table_devices_lock); in alloc_dev()
2033 spin_lock_init(&md->deferred_lock); in alloc_dev()
2034 atomic_set(&md->holders, 1); in alloc_dev()
2035 atomic_set(&md->open_count, 0); in alloc_dev()
2036 atomic_set(&md->event_nr, 0); in alloc_dev()
2037 atomic_set(&md->uevent_seq, 0); in alloc_dev()
2038 INIT_LIST_HEAD(&md->uevent_list); in alloc_dev()
2039 INIT_LIST_HEAD(&md->table_devices); in alloc_dev()
2040 spin_lock_init(&md->uevent_lock); in alloc_dev()
2043 * default to bio-based until DM table is loaded and md->type in alloc_dev()
2044 * established. If request-based table is loaded: blk-mq will in alloc_dev()
2047 md->disk = blk_alloc_disk(md->numa_node_id); in alloc_dev()
2048 if (!md->disk) in alloc_dev()
2050 md->queue = md->disk->queue; in alloc_dev()
2052 init_waitqueue_head(&md->wait); in alloc_dev()
2053 INIT_WORK(&md->work, dm_wq_work); in alloc_dev()
2054 INIT_WORK(&md->requeue_work, dm_wq_requeue_work); in alloc_dev()
2055 init_waitqueue_head(&md->eventq); in alloc_dev()
2056 init_completion(&md->kobj_holder.completion); in alloc_dev()
2058 md->requeue_list = NULL; in alloc_dev()
2059 md->swap_bios = get_swap_bios(); in alloc_dev()
2060 sema_init(&md->swap_bios_semaphore, md->swap_bios); in alloc_dev()
2061 mutex_init(&md->swap_bios_lock); in alloc_dev()
2063 md->disk->major = _major; in alloc_dev()
2064 md->disk->first_minor = minor; in alloc_dev()
2065 md->disk->minors = 1; in alloc_dev()
2066 md->disk->flags |= GENHD_FL_NO_PART; in alloc_dev()
2067 md->disk->fops = &dm_blk_dops; in alloc_dev()
2068 md->disk->private_data = md; in alloc_dev()
2069 sprintf(md->disk->disk_name, "dm-%d", minor); in alloc_dev()
2072 md->dax_dev = alloc_dax(md, &dm_dax_ops); in alloc_dev()
2073 if (IS_ERR(md->dax_dev)) { in alloc_dev()
2074 md->dax_dev = NULL; in alloc_dev()
2077 set_dax_nocache(md->dax_dev); in alloc_dev()
2078 set_dax_nomc(md->dax_dev); in alloc_dev()
2079 if (dax_add_host(md->dax_dev, md->disk)) in alloc_dev()
2083 format_dev_t(md->name, MKDEV(_major, minor)); in alloc_dev()
2085 md->wq = alloc_workqueue("kdmflush/%s", WQ_MEM_RECLAIM, 0, md->name); in alloc_dev()
2086 if (!md->wq) in alloc_dev()
2089 md->pending_io = alloc_percpu(unsigned long); in alloc_dev()
2090 if (!md->pending_io) in alloc_dev()
2093 dm_stats_init(&md->stats); in alloc_dev()
2119 int minor = MINOR(disk_devt(md->disk)); in free_dev()
2125 free_table_devices(&md->table_devices); in free_dev()
2126 dm_stats_cleanup(&md->stats); in free_dev()
2134 * Bind a table to the device.
2142 spin_lock_irqsave(&md->uevent_lock, flags); in event_callback()
2143 list_splice_init(&md->uevent_list, &uevents); in event_callback()
2144 spin_unlock_irqrestore(&md->uevent_lock, flags); in event_callback()
2146 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj); in event_callback()
2148 atomic_inc(&md->event_nr); in event_callback()
2149 wake_up(&md->eventq); in event_callback()
2163 lockdep_assert_held(&md->suspend_lock); in __bind()
2171 memset(&md->geometry, 0, sizeof(md->geometry)); in __bind()
2173 if (!get_capacity(md->disk)) in __bind()
2174 set_capacity(md->disk, size); in __bind()
2176 set_capacity_and_notify(md->disk, size); in __bind()
2182 * Leverage the fact that request-based DM targets are in __bind()
2183 * immutable singletons - used to optimize dm_mq_queue_rq. in __bind()
2185 md->immutable_target = dm_table_get_immutable_target(t); in __bind()
2188 * There is no need to reload with request-based dm because the in __bind()
2191 * Note for future: If you are to reload bioset, prep-ed in __bind()
2192 * requests in the queue may refer to bio from the old bioset, in __bind()
2193 * so you must walk through the queue to unprep. in __bind()
2195 if (!md->mempools) { in __bind()
2196 md->mempools = t->mempools; in __bind()
2197 t->mempools = NULL; in __bind()
2205 dm_free_md_mempools(md->mempools); in __bind()
2206 md->mempools = t->mempools; in __bind()
2207 t->mempools = NULL; in __bind()
2210 ret = dm_table_set_restrictions(t, md->queue, limits); in __bind()
2216 old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __bind()
2217 rcu_assign_pointer(md->map, (void *)t); in __bind()
2218 md->immutable_target_type = dm_table_get_immutable_target_type(t); in __bind()
2227 * Returns unbound table for the caller to free.
2231 struct dm_table *map = rcu_dereference_protected(md->map, 1); in __unbind()
2237 RCU_INIT_POINTER(md->map, NULL); in __unbind()
2252 return -ENXIO; in dm_create()
2261 * Functions to manage md->type.
2262 * All are required to hold md->type_lock.
2266 mutex_lock(&md->type_lock); in dm_lock_md_type()
2271 mutex_unlock(&md->type_lock); in dm_unlock_md_type()
2276 BUG_ON(!mutex_is_locked(&md->type_lock)); in dm_set_md_type()
2277 md->type = type; in dm_set_md_type()
2282 return md->type; in dm_get_md_type()
2287 return md->immutable_target_type; in dm_get_immutable_target_type()
2296 BUG_ON(!atomic_read(&md->holders)); in dm_get_queue_limits()
2297 return &md->queue->limits; in dm_get_queue_limits()
2312 md->disk->fops = &dm_rq_blk_dops; in dm_setup_md_queue()
2315 DMERR("Cannot initialize queue for request-based dm mapped device"); in dm_setup_md_queue()
2332 r = dm_table_set_restrictions(t, md->queue, &limits); in dm_setup_md_queue()
2336 r = add_disk(md->disk); in dm_setup_md_queue()
2342 del_gendisk(md->disk); in dm_setup_md_queue()
2345 md->type = type; in dm_setup_md_queue()
2361 test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { in dm_get_md()
2375 return md->interface_ptr; in dm_get_mdptr()
2380 md->interface_ptr = ptr; in dm_set_mdptr()
2385 atomic_inc(&md->holders); in dm_get()
2386 BUG_ON(test_bit(DMF_FREEING, &md->flags)); in dm_get()
2392 if (test_bit(DMF_FREEING, &md->flags)) { in dm_hold()
2394 return -EBUSY; in dm_hold()
2404 return md->name; in dm_device_name()
2417 set_bit(DMF_FREEING, &md->flags); in __dm_destroy()
2420 blk_mark_disk_dead(md->disk); in __dm_destroy()
2424 * do not race with internal suspend. in __dm_destroy()
2426 mutex_lock(&md->suspend_lock); in __dm_destroy()
2430 set_bit(DMF_SUSPENDED, &md->flags); in __dm_destroy()
2431 set_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_destroy()
2436 mutex_unlock(&md->suspend_lock); in __dm_destroy()
2439 * Rare, but there may be I/O requests still going to complete, in __dm_destroy()
2440 * for example. Wait for all references to disappear. in __dm_destroy()
2445 while (atomic_read(&md->holders)) in __dm_destroy()
2447 else if (atomic_read(&md->holders)) in __dm_destroy()
2449 dm_device_name(md), atomic_read(&md->holders)); in __dm_destroy()
2467 atomic_dec(&md->holders); in dm_put()
2477 sum += *per_cpu_ptr(md->pending_io, cpu); in dm_in_flight_bios()
2488 prepare_to_wait(&md->wait, &wait, task_state); in dm_wait_for_bios_completion()
2494 r = -EINTR; in dm_wait_for_bios_completion()
2500 finish_wait(&md->wait, &wait); in dm_wait_for_bios_completion()
2511 if (!queue_is_mq(md->queue)) in dm_wait_for_completion()
2515 if (!blk_mq_queue_inflight(md->queue)) in dm_wait_for_completion()
2519 r = -EINTR; in dm_wait_for_completion()
2537 while (!test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) { in dm_wq_work()
2538 spin_lock_irq(&md->deferred_lock); in dm_wq_work()
2539 bio = bio_list_pop(&md->deferred); in dm_wq_work()
2540 spin_unlock_irq(&md->deferred_lock); in dm_wq_work()
2551 clear_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in dm_queue_flush()
2553 queue_work(md->wq, &md->work); in dm_queue_flush()
2557 * Swap in a new table, returning the old one for the caller to destroy.
2561 struct dm_table *live_map = NULL, *map = ERR_PTR(-EINVAL); in dm_swap_table()
2565 mutex_lock(&md->suspend_lock); in dm_swap_table()
2580 limits = md->queue->limits; in dm_swap_table()
2596 mutex_unlock(&md->suspend_lock); in dm_swap_table()
2601 * Functions to lock and unlock any filesystem running on the
2608 WARN_ON(test_bit(DMF_FROZEN, &md->flags)); in lock_fs()
2610 r = freeze_bdev(md->disk->part0); in lock_fs()
2612 set_bit(DMF_FROZEN, &md->flags); in lock_fs()
2618 if (!test_bit(DMF_FROZEN, &md->flags)) in unlock_fs()
2620 thaw_bdev(md->disk->part0); in unlock_fs()
2621 clear_bit(DMF_FROZEN, &md->flags); in unlock_fs()
2630 * now. There is no request-processing activity. All new requests
2631 * are being added to md->deferred list.
2641 lockdep_assert_held(&md->suspend_lock); in __dm_suspend()
2648 set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __dm_suspend()
2659 * Flush I/O to the device. in __dm_suspend()
2662 * (lock_fs() flushes I/Os and waits for them to complete.) in __dm_suspend()
2674 * to target drivers i.e. no one may be executing in __dm_suspend()
2677 * To get all processes out of dm_split_and_process_bio in dm_submit_bio, in __dm_suspend()
2678 * we take the write lock. To prevent any process from reentering in __dm_suspend()
2681 * flush_workqueue(md->wq). in __dm_suspend()
2683 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in __dm_suspend()
2685 synchronize_srcu(&md->io_barrier); in __dm_suspend()
2688 * Stop md->queue before flushing md->wq in case request-based in __dm_suspend()
2689 * dm defers requests to md->wq from md->queue. in __dm_suspend()
2692 dm_stop_queue(md->queue); in __dm_suspend()
2694 flush_workqueue(md->wq); in __dm_suspend()
2698 * We call dm_wait_for_completion to wait for all existing requests in __dm_suspend()
2699 * to finish. in __dm_suspend()
2703 set_bit(dmf_suspended_flag, &md->flags); in __dm_suspend()
2706 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __dm_suspend()
2708 synchronize_srcu(&md->io_barrier); in __dm_suspend()
2715 dm_start_queue(md->queue); in __dm_suspend()
2726 * We need to be able to change a mapping table under a mounted
2727 * filesystem. For example we might want to move some data in
2729 * dm_bind_table, dm_suspend must be called to flush any in
2733 * Suspend mechanism in request-based dm.
2737 * 3. Wait for all in-flight I/Os to be completed or requeued.
2739 * To abort suspend, start the request_queue.
2747 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING); in dm_suspend()
2750 r = -EINVAL; in dm_suspend()
2756 mutex_unlock(&md->suspend_lock); in dm_suspend()
2757 r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE); in dm_suspend()
2763 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in dm_suspend()
2769 set_bit(DMF_POST_SUSPENDING, &md->flags); in dm_suspend()
2771 clear_bit(DMF_POST_SUSPENDING, &md->flags); in dm_suspend()
2774 mutex_unlock(&md->suspend_lock); in dm_suspend()
2791 * Request-based dm is queueing the deferred I/Os in its request_queue. in __dm_resume()
2794 dm_start_queue(md->queue); in __dm_resume()
2807 r = -EINVAL; in dm_resume()
2808 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING); in dm_resume()
2815 mutex_unlock(&md->suspend_lock); in dm_resume()
2816 r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE); in dm_resume()
2822 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in dm_resume()
2830 clear_bit(DMF_SUSPENDED, &md->flags); in dm_resume()
2832 mutex_unlock(&md->suspend_lock); in dm_resume()
2838 * Internal suspend/resume works like userspace-driven suspend. It waits
2839 * until all bios finish and prevents issuing new bios to the target drivers.
2847 lockdep_assert_held(&md->suspend_lock); in __dm_internal_suspend()
2849 if (md->internal_suspend_count++) in __dm_internal_suspend()
2850 return; /* nested internal suspend */ in __dm_internal_suspend()
2853 set_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in __dm_internal_suspend()
2854 return; /* nest suspend */ in __dm_internal_suspend()
2857 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __dm_internal_suspend()
2860 * Using TASK_UNINTERRUPTIBLE because only NOFLUSH internal suspend is in __dm_internal_suspend()
2861 * supported. Properly supporting a TASK_INTERRUPTIBLE internal suspend in __dm_internal_suspend()
2862 * would require changing .presuspend to return an error -- avoid this in __dm_internal_suspend()
2863 * until there is a need for more elaborate variants of internal suspend. in __dm_internal_suspend()
2868 set_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_internal_suspend()
2870 clear_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_internal_suspend()
2875 BUG_ON(!md->internal_suspend_count); in __dm_internal_resume()
2877 if (--md->internal_suspend_count) in __dm_internal_resume()
2878 return; /* resume from nested internal suspend */ in __dm_internal_resume()
2881 goto done; /* resume from nested suspend */ in __dm_internal_resume()
2884 * NOTE: existing callers don't need to call dm_table_resume_targets in __dm_internal_resume()
2885 * (which may fail -- so best to avoid it for now by passing NULL map) in __dm_internal_resume()
2890 clear_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in __dm_internal_resume()
2892 wake_up_bit(&md->flags, DMF_SUSPENDED_INTERNALLY); in __dm_internal_resume()
2897 mutex_lock(&md->suspend_lock); in dm_internal_suspend_noflush()
2899 mutex_unlock(&md->suspend_lock); in dm_internal_suspend_noflush()
2905 mutex_lock(&md->suspend_lock); in dm_internal_resume()
2907 mutex_unlock(&md->suspend_lock); in dm_internal_resume()
2912 * Fast variants of internal suspend/resume hold md->suspend_lock,
2913 * which prevents interaction with userspace-driven suspend.
2918 mutex_lock(&md->suspend_lock); in dm_internal_suspend_fast()
2922 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in dm_internal_suspend_fast()
2923 synchronize_srcu(&md->io_barrier); in dm_internal_suspend_fast()
2924 flush_workqueue(md->wq); in dm_internal_suspend_fast()
2937 mutex_unlock(&md->suspend_lock); in dm_internal_resume_fast()
2941 /*-----------------------------------------------------------------
2943 *---------------------------------------------------------------*/
2955 r = kobject_uevent(&disk_to_dev(md->disk)->kobj, action); in dm_kobject_uevent()
2959 r = kobject_uevent_env(&disk_to_dev(md->disk)->kobj, in dm_kobject_uevent()
2970 return atomic_add_return(1, &md->uevent_seq); in dm_next_uevent_seq()
2975 return atomic_read(&md->event_nr); in dm_get_event_nr()
2980 return wait_event_interruptible(md->eventq, in dm_wait_event()
2981 (event_nr != atomic_read(&md->event_nr))); in dm_wait_event()
2988 spin_lock_irqsave(&md->uevent_lock, flags); in dm_uevent_add()
2989 list_add(elist, &md->uevent_list); in dm_uevent_add()
2990 spin_unlock_irqrestore(&md->uevent_lock, flags); in dm_uevent_add()
2999 return md->disk; in dm_disk()
3005 return &md->kobj_holder.kobj; in dm_kobject()
3015 if (test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { in dm_get_from_kobject()
3028 return test_bit(DMF_SUSPENDED, &md->flags); in dm_suspended_md()
3033 return test_bit(DMF_POST_SUSPENDING, &md->flags); in dm_post_suspending_md()
3038 return test_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in dm_suspended_internally_md()
3043 return test_bit(DMF_DEFERRED_REMOVE, &md->flags); in dm_test_deferred_remove_flag()
3048 return dm_suspended_md(ti->table->md); in dm_suspended()
3054 return dm_post_suspending_md(ti->table->md); in dm_post_suspending()
3060 return __noflush_suspending(ti->table->md); in dm_noflush_suspending()
3069 bioset_exit(&pools->bs); in dm_free_md_mempools()
3070 bioset_exit(&pools->io_bs); in dm_free_md_mempools()
3088 struct mapped_device *md = bdev->bd_disk->private_data; in dm_call_pr()
3091 int ret = -ENOTTY, srcu_idx; in dm_call_pr()
3098 if (table->num_targets != 1) in dm_call_pr()
3103 ret = -EAGAIN; in dm_call_pr()
3107 ret = -EINVAL; in dm_call_pr()
3108 if (!ti->type->iterate_devices) in dm_call_pr()
3111 ti->type->iterate_devices(ti, fn, pr); in dm_call_pr()
3119 * For register / unregister we need to manually call out to every path.
3125 const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops; in __dm_pr_register()
3128 if (!ops || !ops->pr_register) { in __dm_pr_register()
3129 pr->ret = -EOPNOTSUPP; in __dm_pr_register()
3130 return -1; in __dm_pr_register()
3133 ret = ops->pr_register(dev->bdev, pr->old_key, pr->new_key, pr->flags); in __dm_pr_register()
3137 if (!pr->ret) in __dm_pr_register()
3138 pr->ret = ret; in __dm_pr_register()
3140 if (pr->fail_early) in __dm_pr_register()
3141 return -1; in __dm_pr_register()
3160 /* Didn't even get to register a path */ in dm_pr_register()
3171 /* unregister all paths if we failed to register any path */ in dm_pr_register()
3185 const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops; in __dm_pr_reserve()
3187 if (!ops || !ops->pr_reserve) { in __dm_pr_reserve()
3188 pr->ret = -EOPNOTSUPP; in __dm_pr_reserve()
3189 return -1; in __dm_pr_reserve()
3192 pr->ret = ops->pr_reserve(dev->bdev, pr->old_key, pr->type, pr->flags); in __dm_pr_reserve()
3193 if (!pr->ret) in __dm_pr_reserve()
3194 return -1; in __dm_pr_reserve()
3219 * If there is a non-All Registrants type of reservation, the release must be
3222 * try each path to make sure we got the correct path.
3228 const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops; in __dm_pr_release()
3230 if (!ops || !ops->pr_release) { in __dm_pr_release()
3231 pr->ret = -EOPNOTSUPP; in __dm_pr_release()
3232 return -1; in __dm_pr_release()
3235 pr->ret = ops->pr_release(dev->bdev, pr->old_key, pr->type); in __dm_pr_release()
3236 if (pr->ret) in __dm_pr_release()
3237 return -1; in __dm_pr_release()
3262 const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops; in __dm_pr_preempt()
3264 if (!ops || !ops->pr_preempt) { in __dm_pr_preempt()
3265 pr->ret = -EOPNOTSUPP; in __dm_pr_preempt()
3266 return -1; in __dm_pr_preempt()
3269 pr->ret = ops->pr_preempt(dev->bdev, pr->old_key, pr->new_key, pr->type, in __dm_pr_preempt()
3270 pr->abort); in __dm_pr_preempt()
3271 if (!pr->ret) in __dm_pr_preempt()
3272 return -1; in __dm_pr_preempt()
3297 struct mapped_device *md = bdev->bd_disk->private_data; in dm_pr_clear()
3305 ops = bdev->bd_disk->fops->pr_ops; in dm_pr_clear()
3306 if (ops && ops->pr_clear) in dm_pr_clear()
3307 r = ops->pr_clear(bdev, key); in dm_pr_clear()
3309 r = -EOPNOTSUPP; in dm_pr_clear()
3360 MODULE_PARM_DESC(reserved_bio_based_ios, "Reserved IOs in bio-based mempools");
3369 MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");