Lines Matching +full:suspend +full:- +full:to +full:- +full:disk
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
9 #include "dm-core.h"
10 #include "dm-rq.h"
11 #include "dm-uevent.h"
12 #include "dm-ima.h"
32 #include <linux/blk-crypto.h>
33 #include <linux/blk-crypto-profile.h>
46 * dm_io into one list, and reuse bio->bi_private as the list head. Before
47 * ending this fs bio, we will recover its ->bi_private.
80 * One of these is allocated (on-stack) per original bio.
100 return (char *)bio - DM_TARGET_IO_BIO_OFFSET - data_size; in dm_per_bio_data()
101 return (char *)bio - DM_IO_BIO_OFFSET - data_size; in dm_per_bio_data()
109 if (io->magic == DM_IO_MAGIC) in dm_bio_from_per_bio_data()
111 BUG_ON(io->magic != DM_TIO_MAGIC); in dm_bio_from_per_bio_data()
118 return container_of(bio, struct dm_target_io, clone)->target_bio_nr; in dm_bio_get_target_bio_nr()
122 #define MINOR_ALLOCED ((void *)-1)
145 * Bio-based DM's mempools' reserved IOs set by the user.
199 DM_NUMA_NODE, num_online_nodes() - 1); in dm_get_numa_node()
212 r = -ENOMEM; in local_init()
286 while (i--) in dm_init()
296 while (i--) in dm_exit()
310 return test_bit(DMF_DELETING, &md->flags); in dm_deleting_md()
313 static int dm_blk_open(struct gendisk *disk, blk_mode_t mode) in dm_blk_open() argument
319 md = disk->private_data; in dm_blk_open()
323 if (test_bit(DMF_FREEING, &md->flags) || in dm_blk_open()
330 atomic_inc(&md->open_count); in dm_blk_open()
334 return md ? 0 : -ENXIO; in dm_blk_open()
337 static void dm_blk_close(struct gendisk *disk) in dm_blk_close() argument
343 md = disk->private_data; in dm_blk_close()
347 if (atomic_dec_and_test(&md->open_count) && in dm_blk_close()
348 (test_bit(DMF_DEFERRED_REMOVE, &md->flags))) in dm_blk_close()
358 return atomic_read(&md->open_count); in dm_open_count()
371 r = -EBUSY; in dm_lock_for_deletion()
373 set_bit(DMF_DEFERRED_REMOVE, &md->flags); in dm_lock_for_deletion()
374 } else if (only_deferred && !test_bit(DMF_DEFERRED_REMOVE, &md->flags)) in dm_lock_for_deletion()
375 r = -EEXIST; in dm_lock_for_deletion()
377 set_bit(DMF_DELETING, &md->flags); in dm_lock_for_deletion()
390 if (test_bit(DMF_DELETING, &md->flags)) in dm_cancel_deferred_remove()
391 r = -EBUSY; in dm_cancel_deferred_remove()
393 clear_bit(DMF_DEFERRED_REMOVE, &md->flags); in dm_cancel_deferred_remove()
407 struct mapped_device *md = bdev->bd_disk->private_data; in dm_blk_getgeo()
420 r = -ENOTTY; in dm_prepare_ioctl()
426 if (map->num_targets != 1) in dm_prepare_ioctl()
430 if (!ti->type->prepare_ioctl) in dm_prepare_ioctl()
434 return -EAGAIN; in dm_prepare_ioctl()
436 r = ti->type->prepare_ioctl(ti, bdev); in dm_prepare_ioctl()
437 if (r == -ENOTCONN && !fatal_signal_pending(current)) { in dm_prepare_ioctl()
454 struct mapped_device *md = bdev->bd_disk->private_data; in dm_blk_ioctl()
468 "%s: sending ioctl %x to DM device without required privilege.", in dm_blk_ioctl()
469 current->comm, cmd); in dm_blk_ioctl()
470 r = -ENOIOCTLCMD; in dm_blk_ioctl()
475 if (!bdev->bd_disk->fops->ioctl) in dm_blk_ioctl()
476 r = -ENOTTY; in dm_blk_ioctl()
478 r = bdev->bd_disk->fops->ioctl(bdev, mode, cmd, arg); in dm_blk_ioctl()
486 return jiffies_to_nsecs(clone_to_tio(bio)->io->start_time); in dm_start_time_ns_from_clone()
492 return ((bio->bi_opf & REQ_PREFLUSH) && bio->bi_iter.bi_size); in bio_is_flush_with_data()
504 return io->sectors; in dm_io_sectors()
510 struct bio *bio = io->orig_bio; in dm_io_acct()
514 bdev_start_io_acct(bio->bi_bdev, bio_op(bio), in dm_io_acct()
515 io->start_time); in dm_io_acct()
517 bdev_end_io_acct(bio->bi_bdev, bio_op(bio), in dm_io_acct()
519 io->start_time); in dm_io_acct()
523 unlikely(dm_stats_used(&io->md->stats))) { in dm_io_acct()
527 sector = bio_end_sector(bio) - io->sector_offset; in dm_io_acct()
529 sector = bio->bi_iter.bi_sector; in dm_io_acct()
531 dm_stats_account_io(&io->md->stats, bio_data_dir(bio), in dm_io_acct()
533 end, io->start_time, &io->stats_aux); in dm_io_acct()
556 spin_lock_irqsave(&io->lock, flags); in dm_start_io_acct()
558 spin_unlock_irqrestore(&io->lock, flags); in dm_start_io_acct()
562 spin_unlock_irqrestore(&io->lock, flags); in dm_start_io_acct()
579 clone = bio_alloc_clone(NULL, bio, gfp_mask, &md->mempools->io_bs); in alloc_io()
583 tio->flags = 0; in alloc_io()
585 tio->io = NULL; in alloc_io()
588 io->magic = DM_IO_MAGIC; in alloc_io()
589 io->status = BLK_STS_OK; in alloc_io()
592 atomic_set(&io->io_count, 2); in alloc_io()
593 this_cpu_inc(*md->pending_io); in alloc_io()
594 io->orig_bio = bio; in alloc_io()
595 io->md = md; in alloc_io()
596 spin_lock_init(&io->lock); in alloc_io()
597 io->start_time = jiffies; in alloc_io()
598 io->flags = 0; in alloc_io()
599 if (blk_queue_io_stat(md->queue)) in alloc_io()
603 unlikely(dm_stats_used(&md->stats))) in alloc_io()
604 dm_stats_record_start(&md->stats, &io->stats_aux); in alloc_io()
611 bio_put(&io->tio.clone); in free_io()
617 struct mapped_device *md = ci->io->md; in alloc_tio()
621 if (!ci->io->tio.io) { in alloc_tio()
622 /* the dm_target_io embedded in ci->io is available */ in alloc_tio()
623 tio = &ci->io->tio; in alloc_tio()
625 clone = &tio->clone; in alloc_tio()
627 clone = bio_alloc_clone(NULL, ci->bio, gfp_mask, in alloc_tio()
628 &md->mempools->bs); in alloc_tio()
633 clone->bi_opf &= ~REQ_DM_POLL_LIST; in alloc_tio()
636 tio->flags = 0; /* also clears DM_TIO_INSIDE_DM_IO */ in alloc_tio()
639 tio->magic = DM_TIO_MAGIC; in alloc_tio()
640 tio->io = ci->io; in alloc_tio()
641 tio->ti = ti; in alloc_tio()
642 tio->target_bio_nr = target_bio_nr; in alloc_tio()
643 tio->len_ptr = len; in alloc_tio()
644 tio->old_sector = 0; in alloc_tio()
647 clone->bi_bdev = md->disk->part0; in alloc_tio()
648 if (unlikely(ti->needs_bio_set_dev)) in alloc_tio()
649 bio_set_dev(clone, md->disk->part0); in alloc_tio()
652 clone->bi_iter.bi_size = to_bytes(*len); in alloc_tio()
668 * Add the bio to the list of deferred io.
674 spin_lock_irqsave(&md->deferred_lock, flags); in queue_io()
675 bio_list_add(&md->deferred, bio); in queue_io()
676 spin_unlock_irqrestore(&md->deferred_lock, flags); in queue_io()
677 queue_work(md->wq, &md->work); in queue_io()
682 * function to access the md->map field, and make sure they call
686 int *srcu_idx) __acquires(md->io_barrier) in dm_get_live_table()
688 *srcu_idx = srcu_read_lock(&md->io_barrier); in dm_get_live_table()
690 return srcu_dereference(md->map, &md->io_barrier); in dm_get_live_table()
694 int srcu_idx) __releases(md->io_barrier) in dm_put_live_table()
696 srcu_read_unlock(&md->io_barrier, srcu_idx); in dm_put_live_table()
701 synchronize_srcu(&md->io_barrier); in dm_sync_table()
706 * A fast alternative to dm_get_live_table/dm_put_live_table.
712 return rcu_dereference(md->map); in dm_get_live_table_fast()
720 static char *_dm_claim_ptr = "I belong to device-mapper";
733 td = kmalloc_node(sizeof(*td), GFP_KERNEL, md->numa_node_id); in open_table_device()
735 return ERR_PTR(-ENOMEM); in open_table_device()
736 refcount_set(&td->count, 1); in open_table_device()
745 * We can be called before the dm disk is added. In that case we can't in open_table_device()
749 if (md->disk->slave_dir) { in open_table_device()
750 r = bd_link_disk_holder(bdev_handle->bdev, md->disk); in open_table_device()
755 td->dm_dev.mode = mode; in open_table_device()
756 td->dm_dev.bdev = bdev_handle->bdev; in open_table_device()
757 td->dm_dev.bdev_handle = bdev_handle; in open_table_device()
758 td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev_handle->bdev, &part_off, in open_table_device()
760 format_dev_t(td->dm_dev.name, dev); in open_table_device()
761 list_add(&td->list, &md->table_devices); in open_table_device()
776 if (md->disk->slave_dir) in close_table_device()
777 bd_unlink_disk_holder(td->dm_dev.bdev, md->disk); in close_table_device()
778 bdev_release(td->dm_dev.bdev_handle); in close_table_device()
779 put_dax(td->dm_dev.dax_dev); in close_table_device()
780 list_del(&td->list); in close_table_device()
790 if (td->dm_dev.bdev->bd_dev == dev && td->dm_dev.mode == mode) in find_table_device()
801 mutex_lock(&md->table_devices_lock); in dm_get_table_device()
802 td = find_table_device(&md->table_devices, dev, mode); in dm_get_table_device()
806 mutex_unlock(&md->table_devices_lock); in dm_get_table_device()
810 refcount_inc(&td->count); in dm_get_table_device()
812 mutex_unlock(&md->table_devices_lock); in dm_get_table_device()
814 *result = &td->dm_dev; in dm_get_table_device()
822 mutex_lock(&md->table_devices_lock); in dm_put_table_device()
823 if (refcount_dec_and_test(&td->count)) in dm_put_table_device()
825 mutex_unlock(&md->table_devices_lock); in dm_put_table_device()
833 *geo = md->geometry; in dm_get_geometry()
843 sector_t sz = (sector_t)geo->cylinders * geo->heads * geo->sectors; in dm_set_geometry()
845 if (geo->start > sz) { in dm_set_geometry()
847 return -EINVAL; in dm_set_geometry()
850 md->geometry = *geo; in dm_set_geometry()
857 return test_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __noflush_suspending()
862 struct mapped_device *md = io->md; in dm_requeue_add_io()
865 struct dm_io *next = md->requeue_list; in dm_requeue_add_io()
867 md->requeue_list = io; in dm_requeue_add_io()
868 io->next = next; in dm_requeue_add_io()
870 bio_list_add_head(&md->deferred, io->orig_bio); in dm_requeue_add_io()
877 queue_work(md->wq, &md->requeue_work); in dm_kick_requeue()
879 queue_work(md->wq, &md->work); in dm_kick_requeue()
884 * io->status is updated with error if requeue disallowed.
888 struct bio *bio = io->orig_bio; in dm_handle_requeue()
889 bool handle_requeue = (io->status == BLK_STS_DM_REQUEUE); in dm_handle_requeue()
890 bool handle_polled_eagain = ((io->status == BLK_STS_AGAIN) && in dm_handle_requeue()
891 (bio->bi_opf & REQ_POLLED)); in dm_handle_requeue()
892 struct mapped_device *md = io->md; in dm_handle_requeue()
898 if (bio->bi_opf & REQ_POLLED) { in dm_handle_requeue()
901 * (io->orig_bio may only reflect a subset of the in dm_handle_requeue()
902 * pre-split original) so clear REQ_POLLED. in dm_handle_requeue()
911 spin_lock_irqsave(&md->deferred_lock, flags); in dm_handle_requeue()
919 * noflush suspend was interrupted or this is in dm_handle_requeue()
920 * a write to a zoned target. in dm_handle_requeue()
922 io->status = BLK_STS_IOERR; in dm_handle_requeue()
924 spin_unlock_irqrestore(&md->deferred_lock, flags); in dm_handle_requeue()
935 struct bio *bio = io->orig_bio; in __dm_io_complete()
936 struct mapped_device *md = io->md; in __dm_io_complete()
944 io_error = io->status; in __dm_io_complete()
949 * Must handle target that DM_MAPIO_SUBMITTED only to in __dm_io_complete()
957 this_cpu_dec(*md->pending_io); in __dm_io_complete()
959 /* nudge anyone waiting on suspend queue */ in __dm_io_complete()
960 if (unlikely(wq_has_sleeper(&md->wait))) in __dm_io_complete()
961 wake_up(&md->wait); in __dm_io_complete()
972 bio->bi_opf &= ~REQ_PREFLUSH; in __dm_io_complete()
977 bio->bi_status = io_error; in __dm_io_complete()
989 /* reuse deferred lock to simplify dm_handle_requeue */ in dm_wq_requeue_work()
990 spin_lock_irqsave(&md->deferred_lock, flags); in dm_wq_requeue_work()
991 io = md->requeue_list; in dm_wq_requeue_work()
992 md->requeue_list = NULL; in dm_wq_requeue_work()
993 spin_unlock_irqrestore(&md->deferred_lock, flags); in dm_wq_requeue_work()
996 struct dm_io *next = io->next; in dm_wq_requeue_work()
998 dm_io_rewind(io, &md->disk->bio_split); in dm_wq_requeue_work()
1000 io->next = NULL; in dm_wq_requeue_work()
1010 * 1) io->orig_bio points to the real original bio, and the part mapped to
1013 * 2) io->orig_bio points to new cloned bio which matches the requeued dm_io.
1021 * we may run into long bio clone chain during suspend and OOM could in dm_io_complete()
1041 if (atomic_dec_and_test(&io->io_count)) in __dm_io_dec_pending()
1049 /* Push-back supersedes any I/O errors */ in dm_io_set_error()
1050 spin_lock_irqsave(&io->lock, flags); in dm_io_set_error()
1051 if (!(io->status == BLK_STS_DM_REQUEUE && in dm_io_set_error()
1052 __noflush_suspending(io->md))) { in dm_io_set_error()
1053 io->status = error; in dm_io_set_error()
1055 spin_unlock_irqrestore(&io->lock, flags); in dm_io_set_error()
1068 * count on 'md'. But _not_ imposing verification to avoid atomic_read(),
1072 return &md->queue->limits; in dm_get_queue_limits()
1080 limits->max_discard_sectors = 0; in disable_discard()
1088 limits->max_write_zeroes_sectors = 0; in disable_write_zeroes()
1093 return unlikely((bio->bi_opf & REQ_SWAP) != 0) && unlikely(ti->limit_swap_bios); in swap_bios_limit()
1098 blk_status_t error = bio->bi_status; in clone_endio()
1100 struct dm_target *ti = tio->ti; in clone_endio()
1101 dm_endio_fn endio = ti->type->end_io; in clone_endio()
1102 struct dm_io *io = tio->io; in clone_endio()
1103 struct mapped_device *md = io->md; in clone_endio()
1107 !bdev_max_discard_sectors(bio->bi_bdev)) in clone_endio()
1110 !bdev_write_zeroes_sectors(bio->bi_bdev)) in clone_endio()
1115 unlikely(bdev_is_zoned(bio->bi_bdev))) in clone_endio()
1125 * Requeuing writes to a sequential zone of a zoned in clone_endio()
1149 up(&md->swap_bios_semaphore); in clone_endio()
1156 * Return maximum size of I/O possible at the supplied sector up to the current
1162 return ti->len - target_offset; in max_io_len_target_boundary()
1173 * Does the target need to split IO even further? in __max_io_len()
1174 * - varied (per target) IO splitting is a tenet of DM; this in __max_io_len()
1181 min(max_sectors ? : queue_max_sectors(ti->table->md->queue), in __max_io_len()
1187 return __max_io_len(ti, sector, ti->max_io_len, 0); in max_io_len()
1195 ti->error = "Maximum size of target IO is too large"; in dm_set_target_max_io_len()
1196 return -EINVAL; in dm_set_target_max_io_len()
1199 ti->max_io_len = (uint32_t) len; in dm_set_target_max_io_len()
1207 __acquires(md->io_barrier) in dm_dax_get_live_target()
1230 long len, ret = -EIO; in dm_dax_direct_access()
1237 if (!ti->type->direct_access) in dm_dax_direct_access()
1243 ret = ti->type->direct_access(ti, pgoff, nr_pages, mode, kaddr, pfn); in dm_dax_direct_access()
1257 int ret = -EIO; in dm_dax_zero_page_range()
1264 if (WARN_ON(!ti->type->dax_zero_page_range)) { in dm_dax_zero_page_range()
1266 * ->zero_page_range() is mandatory dax operation. If we are in dm_dax_zero_page_range()
1271 ret = ti->type->dax_zero_page_range(ti, pgoff, nr_pages); in dm_dax_zero_page_range()
1288 if (!ti || !ti->type->dax_recovery_write) in dm_dax_recovery_write()
1291 ret = ti->type->dax_recovery_write(ti, pgoff, addr, bytes, i); in dm_dax_recovery_write()
1303 * dm_accept_partial_bio informs the dm that the target only wants to process
1308 * +--------------------+---------------+-------+
1310 * +--------------------+---------------+-------+
1312 * <-------------- *tio->len_ptr --------------->
1313 * <----- bio_sectors ----->
1314 * <-- n_sectors -->
1318 * Region 2 is the remaining bio size that the target wants to process.
1319 * (it may be empty if region 1 is non-empty, although there is no reason
1320 * to make it empty)
1321 * The target requires that region 3 is to be sent in the next bio.
1323 * If the target wants to receive multiple copies of the bio (via num_*bios, etc),
1330 struct dm_io *io = tio->io; in dm_accept_partial_bio()
1336 BUG_ON(bio_sectors > *tio->len_ptr); in dm_accept_partial_bio()
1339 *tio->len_ptr -= bio_sectors - n_sectors; in dm_accept_partial_bio()
1340 bio->bi_iter.bi_size = n_sectors << SECTOR_SHIFT; in dm_accept_partial_bio()
1347 io->sectors = n_sectors; in dm_accept_partial_bio()
1348 io->sector_offset = bio_sectors(io->orig_bio); in dm_accept_partial_bio()
1353 * @clone: clone bio that DM core passed to target's .map function
1356 * Targets should use this interface to submit bios they take
1359 * Target should also enable ti->accounts_remapped_io
1364 struct dm_io *io = tio->io; in dm_submit_bio_remap()
1371 * Account io->origin_bio to DM dev on behalf of target in dm_submit_bio_remap()
1376 trace_block_bio_remap(tgt_clone, disk_devt(io->md->disk), in dm_submit_bio_remap()
1377 tio->old_sector); in dm_submit_bio_remap()
1384 mutex_lock(&md->swap_bios_lock); in __set_swap_bios_limit()
1385 while (latch < md->swap_bios) { in __set_swap_bios_limit()
1387 down(&md->swap_bios_semaphore); in __set_swap_bios_limit()
1388 md->swap_bios--; in __set_swap_bios_limit()
1390 while (latch > md->swap_bios) { in __set_swap_bios_limit()
1392 up(&md->swap_bios_semaphore); in __set_swap_bios_limit()
1393 md->swap_bios++; in __set_swap_bios_limit()
1395 mutex_unlock(&md->swap_bios_lock); in __set_swap_bios_limit()
1401 struct dm_target *ti = tio->ti; in __map_bio()
1402 struct dm_io *io = tio->io; in __map_bio()
1403 struct mapped_device *md = io->md; in __map_bio()
1406 clone->bi_end_io = clone_endio; in __map_bio()
1411 tio->old_sector = clone->bi_iter.bi_sector; in __map_bio()
1417 if (unlikely(latch != md->swap_bios)) in __map_bio()
1419 down(&md->swap_bios_semaphore); in __map_bio()
1424 * Check if the IO needs a special mapping due to zone append in __map_bio()
1434 if (likely(ti->type->map == linear_map)) in __map_bio()
1436 else if (ti->type->map == stripe_map) in __map_bio()
1439 r = ti->type->map(ti, clone); in __map_bio()
1445 if (!ti->accounts_remapped_io) in __map_bio()
1455 up(&md->swap_bios_semaphore); in __map_bio()
1470 struct dm_io *io = ci->io; in setup_split_accounting()
1472 if (ci->sector_count > len) { in setup_split_accounting()
1478 io->sectors = len; in setup_split_accounting()
1479 io->sector_offset = bio_sectors(ci->bio); in setup_split_accounting()
1494 mutex_lock(&ci->io->md->table_devices_lock); in alloc_multiple_bios()
1504 mutex_unlock(&ci->io->md->table_devices_lock); in alloc_multiple_bios()
1524 /* dm_accept_partial_bio() is not supported with shared tio->len_ptr */ in __send_duplicate_bios()
1529 * Using alloc_multiple_bios(), even if num_bios is 1, to consistently in __send_duplicate_bios()
1545 struct dm_table *t = ci->map; in __send_empty_flush()
1549 * Use an on-stack bio for this, it's safe since we don't in __send_empty_flush()
1550 * need to reference it after submit. It's just used as in __send_empty_flush()
1553 bio_init(&flush_bio, ci->io->md->disk->part0, NULL, 0, in __send_empty_flush()
1556 ci->bio = &flush_bio; in __send_empty_flush()
1557 ci->sector_count = 0; in __send_empty_flush()
1558 ci->io->tio.clone.bi_iter.bi_size = 0; in __send_empty_flush()
1560 for (unsigned int i = 0; i < t->num_targets; i++) { in __send_empty_flush()
1564 if (unlikely(ti->num_flush_bios == 0)) in __send_empty_flush()
1567 atomic_add(ti->num_flush_bios, &ci->io->io_count); in __send_empty_flush()
1568 bios = __send_duplicate_bios(ci, ti, ti->num_flush_bios, in __send_empty_flush()
1570 atomic_sub(ti->num_flush_bios - bios, &ci->io->io_count); in __send_empty_flush()
1577 atomic_sub(1, &ci->io->io_count); in __send_empty_flush()
1579 bio_uninit(ci->bio); in __send_empty_flush()
1588 len = min_t(sector_t, ci->sector_count, in __send_abnormal_io()
1589 __max_io_len(ti, ci->sector, max_granularity, max_sectors)); in __send_abnormal_io()
1591 atomic_add(num_bios, &ci->io->io_count); in __send_abnormal_io()
1597 atomic_sub(num_bios - bios + 1, &ci->io->io_count); in __send_abnormal_io()
1599 ci->sector += len; in __send_abnormal_io()
1600 ci->sector_count -= len; in __send_abnormal_io()
1627 struct queue_limits *limits = dm_get_queue_limits(ti->table->md); in __process_abnormal_io()
1629 switch (bio_op(ci->bio)) { in __process_abnormal_io()
1631 num_bios = ti->num_discard_bios; in __process_abnormal_io()
1632 max_sectors = limits->max_discard_sectors; in __process_abnormal_io()
1633 if (ti->max_discard_granularity) in __process_abnormal_io()
1637 num_bios = ti->num_secure_erase_bios; in __process_abnormal_io()
1638 max_sectors = limits->max_secure_erase_sectors; in __process_abnormal_io()
1639 if (ti->max_secure_erase_granularity) in __process_abnormal_io()
1643 num_bios = ti->num_write_zeroes_bios; in __process_abnormal_io()
1644 max_sectors = limits->max_write_zeroes_sectors; in __process_abnormal_io()
1645 if (ti->max_write_zeroes_granularity) in __process_abnormal_io()
1667 * Reuse ->bi_private as dm_io list head for storing all dm_io instances
1668 * associated with this bio, and this bio's bi_private needs to be
1669 * stored in dm_io->data before the reuse.
1671 * bio->bi_private is owned by fs or upper layer, so block layer won't
1677 return (struct dm_io **)&bio->bi_private; in dm_poll_list_head()
1684 if (!(bio->bi_opf & REQ_DM_POLL_LIST)) { in dm_queue_poll_io()
1685 bio->bi_opf |= REQ_DM_POLL_LIST; in dm_queue_poll_io()
1690 io->data = bio->bi_private; in dm_queue_poll_io()
1692 /* tell block layer to poll for completion */ in dm_queue_poll_io()
1693 bio->bi_cookie = ~BLK_QC_T_NONE; in dm_queue_poll_io()
1695 io->next = NULL; in dm_queue_poll_io()
1698 * bio recursed due to split, reuse original poll list, in dm_queue_poll_io()
1699 * and save bio->bi_private too. in dm_queue_poll_io()
1701 io->data = (*head)->data; in dm_queue_poll_io()
1702 io->next = *head; in dm_queue_poll_io()
1709 * Select the correct strategy for processing a non-flush bio.
1717 ti = dm_table_find_target(ci->map, ci->sector); in __split_and_process_bio()
1721 if (unlikely(ci->is_abnormal_io)) in __split_and_process_bio()
1728 ci->submit_as_polled = !!(ci->bio->bi_opf & REQ_POLLED); in __split_and_process_bio()
1730 len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count); in __split_and_process_bio()
1733 if (unlikely(ci->bio->bi_opf & REQ_NOWAIT)) { in __split_and_process_bio()
1734 if (unlikely(!dm_target_supports_nowait(ti->type))) in __split_and_process_bio()
1745 ci->sector += len; in __split_and_process_bio()
1746 ci->sector_count -= len; in __split_and_process_bio()
1754 ci->map = map; in init_clone_info()
1755 ci->io = io; in init_clone_info()
1756 ci->bio = bio; in init_clone_info()
1757 ci->is_abnormal_io = is_abnormal; in init_clone_info()
1758 ci->submit_as_polled = false; in init_clone_info()
1759 ci->sector = bio->bi_iter.bi_sector; in init_clone_info()
1760 ci->sector_count = bio_sectors(bio); in init_clone_info()
1762 /* Shouldn't happen but sector_count was being set to 0 so... */ in init_clone_info()
1764 WARN_ON_ONCE(op_is_zone_mgmt(bio_op(bio)) && ci->sector_count)) in init_clone_info()
1765 ci->sector_count = 0; in init_clone_info()
1769 * Entry point to split a bio into clones and submit them to the targets.
1791 if (unlikely(bio->bi_opf & REQ_NOWAIT) && !is_abnormal) { in dm_split_and_process_bio()
1794 /* Unable to do anything without dm_io. */ in dm_split_and_process_bio()
1803 if (bio->bi_opf & REQ_PREFLUSH) { in dm_split_and_process_bio()
1813 * Remainder must be passed to submit_bio_noacct() so it gets handled in dm_split_and_process_bio()
1816 bio_trim(bio, io->sectors, ci.sector_count); in dm_split_and_process_bio()
1817 trace_block_split(bio, bio->bi_iter.bi_sector); in dm_split_and_process_bio()
1822 * Drop the extra reference count for non-POLLED bio, and hold one in dm_split_and_process_bio()
1826 * in bio->bi_private, so that dm_poll_bio can poll them all. in dm_split_and_process_bio()
1834 atomic_dec(&io->io_count); in dm_split_and_process_bio()
1842 struct mapped_device *md = bio->bi_bdev->bd_disk->private_data; in dm_submit_bio()
1849 if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) || in dm_submit_bio()
1851 if (bio->bi_opf & REQ_NOWAIT) in dm_submit_bio()
1853 else if (bio->bi_opf & REQ_RAHEAD) in dm_submit_bio()
1868 WARN_ON_ONCE(!dm_tio_is_normal(&io->tio)); in dm_poll_dm_io()
1871 if (atomic_read(&io->io_count) > 1) in dm_poll_dm_io()
1872 bio_poll(&io->tio.clone, iob, flags); in dm_poll_dm_io()
1875 return atomic_read(&io->io_count) == 1; in dm_poll_dm_io()
1887 if (!(bio->bi_opf & REQ_DM_POLL_LIST)) in dm_poll_bio()
1896 * submitted via submit_bio_noacct()'s depth-first submission. in dm_poll_bio()
1900 bio->bi_opf &= ~REQ_DM_POLL_LIST; in dm_poll_bio()
1901 bio->bi_private = list->data; in dm_poll_bio()
1903 for (curr = list, next = curr->next; curr; curr = next, next = in dm_poll_bio()
1904 curr ? curr->next : NULL) { in dm_poll_bio()
1912 curr->next = tmp; in dm_poll_bio()
1919 bio->bi_opf |= REQ_DM_POLL_LIST; in dm_poll_bio()
1920 /* Reset bio->bi_private to dm_io list head */ in dm_poll_bio()
1928 *---------------------------------------------------------------
1929 * An IDR is used to keep track of allocated minor numbers.
1930 *---------------------------------------------------------------
1947 return -EINVAL; in specific_minor()
1957 return r == -ENOSPC ? -EBUSY : r; in specific_minor()
1987 dm_destroy_crypto_profile(q->crypto_profile); in dm_queue_destroy_crypto_profile()
1999 if (md->wq) in cleanup_mapped_device()
2000 destroy_workqueue(md->wq); in cleanup_mapped_device()
2001 dm_free_md_mempools(md->mempools); in cleanup_mapped_device()
2003 if (md->dax_dev) { in cleanup_mapped_device()
2004 dax_remove_host(md->disk); in cleanup_mapped_device()
2005 kill_dax(md->dax_dev); in cleanup_mapped_device()
2006 put_dax(md->dax_dev); in cleanup_mapped_device()
2007 md->dax_dev = NULL; in cleanup_mapped_device()
2011 if (md->disk) { in cleanup_mapped_device()
2013 md->disk->private_data = NULL; in cleanup_mapped_device()
2019 list_for_each_entry(td, &md->table_devices, list) { in cleanup_mapped_device()
2020 bd_unlink_disk_holder(td->dm_dev.bdev, in cleanup_mapped_device()
2021 md->disk); in cleanup_mapped_device()
2025 * Hold lock to make sure del_gendisk() won't concurrent in cleanup_mapped_device()
2028 mutex_lock(&md->table_devices_lock); in cleanup_mapped_device()
2029 del_gendisk(md->disk); in cleanup_mapped_device()
2030 mutex_unlock(&md->table_devices_lock); in cleanup_mapped_device()
2032 dm_queue_destroy_crypto_profile(md->queue); in cleanup_mapped_device()
2033 put_disk(md->disk); in cleanup_mapped_device()
2036 if (md->pending_io) { in cleanup_mapped_device()
2037 free_percpu(md->pending_io); in cleanup_mapped_device()
2038 md->pending_io = NULL; in cleanup_mapped_device()
2041 cleanup_srcu_struct(&md->io_barrier); in cleanup_mapped_device()
2043 mutex_destroy(&md->suspend_lock); in cleanup_mapped_device()
2044 mutex_destroy(&md->type_lock); in cleanup_mapped_device()
2045 mutex_destroy(&md->table_devices_lock); in cleanup_mapped_device()
2046 mutex_destroy(&md->swap_bios_lock); in cleanup_mapped_device()
2062 DMERR("unable to allocate device, out of memory."); in alloc_dev()
2077 r = init_srcu_struct(&md->io_barrier); in alloc_dev()
2081 md->numa_node_id = numa_node_id; in alloc_dev()
2082 md->init_tio_pdu = false; in alloc_dev()
2083 md->type = DM_TYPE_NONE; in alloc_dev()
2084 mutex_init(&md->suspend_lock); in alloc_dev()
2085 mutex_init(&md->type_lock); in alloc_dev()
2086 mutex_init(&md->table_devices_lock); in alloc_dev()
2087 spin_lock_init(&md->deferred_lock); in alloc_dev()
2088 atomic_set(&md->holders, 1); in alloc_dev()
2089 atomic_set(&md->open_count, 0); in alloc_dev()
2090 atomic_set(&md->event_nr, 0); in alloc_dev()
2091 atomic_set(&md->uevent_seq, 0); in alloc_dev()
2092 INIT_LIST_HEAD(&md->uevent_list); in alloc_dev()
2093 INIT_LIST_HEAD(&md->table_devices); in alloc_dev()
2094 spin_lock_init(&md->uevent_lock); in alloc_dev()
2097 * default to bio-based until DM table is loaded and md->type in alloc_dev()
2098 * established. If request-based table is loaded: blk-mq will in alloc_dev()
2101 md->disk = blk_alloc_disk(md->numa_node_id); in alloc_dev()
2102 if (!md->disk) in alloc_dev()
2104 md->queue = md->disk->queue; in alloc_dev()
2106 init_waitqueue_head(&md->wait); in alloc_dev()
2107 INIT_WORK(&md->work, dm_wq_work); in alloc_dev()
2108 INIT_WORK(&md->requeue_work, dm_wq_requeue_work); in alloc_dev()
2109 init_waitqueue_head(&md->eventq); in alloc_dev()
2110 init_completion(&md->kobj_holder.completion); in alloc_dev()
2112 md->requeue_list = NULL; in alloc_dev()
2113 md->swap_bios = get_swap_bios(); in alloc_dev()
2114 sema_init(&md->swap_bios_semaphore, md->swap_bios); in alloc_dev()
2115 mutex_init(&md->swap_bios_lock); in alloc_dev()
2117 md->disk->major = _major; in alloc_dev()
2118 md->disk->first_minor = minor; in alloc_dev()
2119 md->disk->minors = 1; in alloc_dev()
2120 md->disk->flags |= GENHD_FL_NO_PART; in alloc_dev()
2121 md->disk->fops = &dm_blk_dops; in alloc_dev()
2122 md->disk->private_data = md; in alloc_dev()
2123 sprintf(md->disk->disk_name, "dm-%d", minor); in alloc_dev()
2126 md->dax_dev = alloc_dax(md, &dm_dax_ops); in alloc_dev()
2127 if (IS_ERR(md->dax_dev)) { in alloc_dev()
2128 md->dax_dev = NULL; in alloc_dev()
2131 set_dax_nocache(md->dax_dev); in alloc_dev()
2132 set_dax_nomc(md->dax_dev); in alloc_dev()
2133 if (dax_add_host(md->dax_dev, md->disk)) in alloc_dev()
2137 format_dev_t(md->name, MKDEV(_major, minor)); in alloc_dev()
2139 md->wq = alloc_workqueue("kdmflush/%s", WQ_MEM_RECLAIM, 0, md->name); in alloc_dev()
2140 if (!md->wq) in alloc_dev()
2143 md->pending_io = alloc_percpu(unsigned long); in alloc_dev()
2144 if (!md->pending_io) in alloc_dev()
2147 r = dm_stats_init(&md->stats); in alloc_dev()
2175 int minor = MINOR(disk_devt(md->disk)); in free_dev()
2181 WARN_ON_ONCE(!list_empty(&md->table_devices)); in free_dev()
2182 dm_stats_cleanup(&md->stats); in free_dev()
2190 * Bind a table to the device.
2198 spin_lock_irqsave(&md->uevent_lock, flags); in event_callback()
2199 list_splice_init(&md->uevent_list, &uevents); in event_callback()
2200 spin_unlock_irqrestore(&md->uevent_lock, flags); in event_callback()
2202 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj); in event_callback()
2204 atomic_inc(&md->event_nr); in event_callback()
2205 wake_up(&md->eventq); in event_callback()
2219 lockdep_assert_held(&md->suspend_lock); in __bind()
2227 memset(&md->geometry, 0, sizeof(md->geometry)); in __bind()
2229 set_capacity(md->disk, size); in __bind()
2235 * Leverage the fact that request-based DM targets are in __bind()
2236 * immutable singletons - used to optimize dm_mq_queue_rq. in __bind()
2238 md->immutable_target = dm_table_get_immutable_target(t); in __bind()
2241 * There is no need to reload with request-based dm because the in __bind()
2244 * Note for future: If you are to reload bioset, prep-ed in __bind()
2245 * requests in the queue may refer to bio from the old bioset, in __bind()
2246 * so you must walk through the queue to unprep. in __bind()
2248 if (!md->mempools) { in __bind()
2249 md->mempools = t->mempools; in __bind()
2250 t->mempools = NULL; in __bind()
2258 dm_free_md_mempools(md->mempools); in __bind()
2259 md->mempools = t->mempools; in __bind()
2260 t->mempools = NULL; in __bind()
2263 ret = dm_table_set_restrictions(t, md->queue, limits); in __bind()
2269 old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __bind()
2270 rcu_assign_pointer(md->map, (void *)t); in __bind()
2271 md->immutable_target_type = dm_table_get_immutable_target_type(t); in __bind()
2280 * Returns unbound table for the caller to free.
2284 struct dm_table *map = rcu_dereference_protected(md->map, 1); in __unbind()
2290 RCU_INIT_POINTER(md->map, NULL); in __unbind()
2305 return -ENXIO; in dm_create()
2314 * Functions to manage md->type.
2315 * All are required to hold md->type_lock.
2319 mutex_lock(&md->type_lock); in dm_lock_md_type()
2324 mutex_unlock(&md->type_lock); in dm_unlock_md_type()
2329 BUG_ON(!mutex_is_locked(&md->type_lock)); in dm_set_md_type()
2330 md->type = type; in dm_set_md_type()
2335 return md->type; in dm_get_md_type()
2340 return md->immutable_target_type; in dm_get_immutable_target_type()
2355 md->disk->fops = &dm_rq_blk_dops; in dm_setup_md_queue()
2358 DMERR("Cannot initialize queue for request-based dm mapped device"); in dm_setup_md_queue()
2364 blk_queue_flag_set(QUEUE_FLAG_IO_STAT, md->queue); in dm_setup_md_queue()
2376 r = dm_table_set_restrictions(t, md->queue, &limits); in dm_setup_md_queue()
2381 * Hold lock to make sure add_disk() and del_gendisk() won't concurrent in dm_setup_md_queue()
2384 mutex_lock(&md->table_devices_lock); in dm_setup_md_queue()
2385 r = add_disk(md->disk); in dm_setup_md_queue()
2386 mutex_unlock(&md->table_devices_lock); in dm_setup_md_queue()
2391 * Register the holder relationship for devices added before the disk in dm_setup_md_queue()
2394 list_for_each_entry(td, &md->table_devices, list) { in dm_setup_md_queue()
2395 r = bd_link_disk_holder(td->dm_dev.bdev, md->disk); in dm_setup_md_queue()
2404 md->type = type; in dm_setup_md_queue()
2408 list_for_each_entry_continue_reverse(td, &md->table_devices, list) in dm_setup_md_queue()
2409 bd_unlink_disk_holder(td->dm_dev.bdev, md->disk); in dm_setup_md_queue()
2410 mutex_lock(&md->table_devices_lock); in dm_setup_md_queue()
2411 del_gendisk(md->disk); in dm_setup_md_queue()
2412 mutex_unlock(&md->table_devices_lock); in dm_setup_md_queue()
2428 test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { in dm_get_md()
2442 return md->interface_ptr; in dm_get_mdptr()
2447 md->interface_ptr = ptr; in dm_set_mdptr()
2452 atomic_inc(&md->holders); in dm_get()
2453 BUG_ON(test_bit(DMF_FREEING, &md->flags)); in dm_get()
2459 if (test_bit(DMF_FREEING, &md->flags)) { in dm_hold()
2461 return -EBUSY; in dm_hold()
2471 return md->name; in dm_device_name()
2484 set_bit(DMF_FREEING, &md->flags); in __dm_destroy()
2487 blk_mark_disk_dead(md->disk); in __dm_destroy()
2491 * do not race with internal suspend. in __dm_destroy()
2493 mutex_lock(&md->suspend_lock); in __dm_destroy()
2497 set_bit(DMF_SUSPENDED, &md->flags); in __dm_destroy()
2498 set_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_destroy()
2503 mutex_unlock(&md->suspend_lock); in __dm_destroy()
2506 * Rare, but there may be I/O requests still going to complete, in __dm_destroy()
2507 * for example. Wait for all references to disappear. in __dm_destroy()
2512 while (atomic_read(&md->holders)) in __dm_destroy()
2514 else if (atomic_read(&md->holders)) in __dm_destroy()
2516 dm_device_name(md), atomic_read(&md->holders)); in __dm_destroy()
2534 atomic_dec(&md->holders); in dm_put()
2544 sum += *per_cpu_ptr(md->pending_io, cpu); in dm_in_flight_bios()
2555 prepare_to_wait(&md->wait, &wait, task_state); in dm_wait_for_bios_completion()
2561 r = -EINTR; in dm_wait_for_bios_completion()
2567 finish_wait(&md->wait, &wait); in dm_wait_for_bios_completion()
2578 if (!queue_is_mq(md->queue)) in dm_wait_for_completion()
2582 if (!blk_mq_queue_inflight(md->queue)) in dm_wait_for_completion()
2586 r = -EINTR; in dm_wait_for_completion()
2604 while (!test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) { in dm_wq_work()
2605 spin_lock_irq(&md->deferred_lock); in dm_wq_work()
2606 bio = bio_list_pop(&md->deferred); in dm_wq_work()
2607 spin_unlock_irq(&md->deferred_lock); in dm_wq_work()
2619 clear_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in dm_queue_flush()
2621 queue_work(md->wq, &md->work); in dm_queue_flush()
2625 * Swap in a new table, returning the old one for the caller to destroy.
2629 struct dm_table *live_map = NULL, *map = ERR_PTR(-EINVAL); in dm_swap_table()
2633 mutex_lock(&md->suspend_lock); in dm_swap_table()
2648 limits = md->queue->limits; in dm_swap_table()
2664 mutex_unlock(&md->suspend_lock); in dm_swap_table()
2669 * Functions to lock and unlock any filesystem running on the
2676 WARN_ON(test_bit(DMF_FROZEN, &md->flags)); in lock_fs()
2678 r = bdev_freeze(md->disk->part0); in lock_fs()
2680 set_bit(DMF_FROZEN, &md->flags); in lock_fs()
2686 if (!test_bit(DMF_FROZEN, &md->flags)) in unlock_fs()
2688 bdev_thaw(md->disk->part0); in unlock_fs()
2689 clear_bit(DMF_FROZEN, &md->flags); in unlock_fs()
2698 * now. There is no request-processing activity. All new requests
2699 * are being added to md->deferred list.
2709 lockdep_assert_held(&md->suspend_lock); in __dm_suspend()
2716 set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __dm_suspend()
2727 * Flush I/O to the device. in __dm_suspend()
2730 * (lock_fs() flushes I/Os and waits for them to complete.) in __dm_suspend()
2742 * to target drivers i.e. no one may be executing in __dm_suspend()
2745 * To get all processes out of dm_split_and_process_bio in dm_submit_bio, in __dm_suspend()
2746 * we take the write lock. To prevent any process from reentering in __dm_suspend()
2749 * flush_workqueue(md->wq). in __dm_suspend()
2751 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in __dm_suspend()
2753 synchronize_srcu(&md->io_barrier); in __dm_suspend()
2756 * Stop md->queue before flushing md->wq in case request-based in __dm_suspend()
2757 * dm defers requests to md->wq from md->queue. in __dm_suspend()
2760 dm_stop_queue(md->queue); in __dm_suspend()
2762 flush_workqueue(md->wq); in __dm_suspend()
2766 * We call dm_wait_for_completion to wait for all existing requests in __dm_suspend()
2767 * to finish. in __dm_suspend()
2771 set_bit(dmf_suspended_flag, &md->flags); in __dm_suspend()
2774 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __dm_suspend()
2776 synchronize_srcu(&md->io_barrier); in __dm_suspend()
2783 dm_start_queue(md->queue); in __dm_suspend()
2794 * We need to be able to change a mapping table under a mounted
2795 * filesystem. For example we might want to move some data in
2797 * dm_bind_table, dm_suspend must be called to flush any in
2801 * Suspend mechanism in request-based dm.
2805 * 3. Wait for all in-flight I/Os to be completed or requeued.
2807 * To abort suspend, start the request_queue.
2815 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING); in dm_suspend()
2818 r = -EINVAL; in dm_suspend()
2824 mutex_unlock(&md->suspend_lock); in dm_suspend()
2825 r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE); in dm_suspend()
2831 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in dm_suspend()
2841 set_bit(DMF_POST_SUSPENDING, &md->flags); in dm_suspend()
2843 clear_bit(DMF_POST_SUSPENDING, &md->flags); in dm_suspend()
2846 mutex_unlock(&md->suspend_lock); in dm_suspend()
2864 * Request-based dm is queueing the deferred I/Os in its request_queue. in __dm_resume()
2867 dm_start_queue(md->queue); in __dm_resume()
2880 r = -EINVAL; in dm_resume()
2881 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING); in dm_resume()
2888 mutex_unlock(&md->suspend_lock); in dm_resume()
2889 r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE); in dm_resume()
2895 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in dm_resume()
2903 clear_bit(DMF_SUSPENDED, &md->flags); in dm_resume()
2905 mutex_unlock(&md->suspend_lock); in dm_resume()
2911 * Internal suspend/resume works like userspace-driven suspend. It waits
2912 * until all bios finish and prevents issuing new bios to the target drivers.
2920 lockdep_assert_held(&md->suspend_lock); in __dm_internal_suspend()
2922 if (md->internal_suspend_count++) in __dm_internal_suspend()
2923 return; /* nested internal suspend */ in __dm_internal_suspend()
2926 set_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in __dm_internal_suspend()
2927 return; /* nest suspend */ in __dm_internal_suspend()
2930 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __dm_internal_suspend()
2933 * Using TASK_UNINTERRUPTIBLE because only NOFLUSH internal suspend is in __dm_internal_suspend()
2934 * supported. Properly supporting a TASK_INTERRUPTIBLE internal suspend in __dm_internal_suspend()
2935 * would require changing .presuspend to return an error -- avoid this in __dm_internal_suspend()
2936 * until there is a need for more elaborate variants of internal suspend. in __dm_internal_suspend()
2941 set_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_internal_suspend()
2943 clear_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_internal_suspend()
2948 BUG_ON(!md->internal_suspend_count); in __dm_internal_resume()
2950 if (--md->internal_suspend_count) in __dm_internal_resume()
2951 return; /* resume from nested internal suspend */ in __dm_internal_resume()
2954 goto done; /* resume from nested suspend */ in __dm_internal_resume()
2957 * NOTE: existing callers don't need to call dm_table_resume_targets in __dm_internal_resume()
2958 * (which may fail -- so best to avoid it for now by passing NULL map) in __dm_internal_resume()
2963 clear_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in __dm_internal_resume()
2965 wake_up_bit(&md->flags, DMF_SUSPENDED_INTERNALLY); in __dm_internal_resume()
2970 mutex_lock(&md->suspend_lock); in dm_internal_suspend_noflush()
2972 mutex_unlock(&md->suspend_lock); in dm_internal_suspend_noflush()
2978 mutex_lock(&md->suspend_lock); in dm_internal_resume()
2980 mutex_unlock(&md->suspend_lock); in dm_internal_resume()
2985 * Fast variants of internal suspend/resume hold md->suspend_lock,
2986 * which prevents interaction with userspace-driven suspend.
2991 mutex_lock(&md->suspend_lock); in dm_internal_suspend_fast()
2995 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in dm_internal_suspend_fast()
2996 synchronize_srcu(&md->io_barrier); in dm_internal_suspend_fast()
2997 flush_workqueue(md->wq); in dm_internal_suspend_fast()
3010 mutex_unlock(&md->suspend_lock); in dm_internal_resume_fast()
3015 *---------------------------------------------------------------
3017 *---------------------------------------------------------------
3038 r = kobject_uevent_env(&disk_to_dev(md->disk)->kobj, action, envp); in dm_kobject_uevent()
3047 return atomic_add_return(1, &md->uevent_seq); in dm_next_uevent_seq()
3052 return atomic_read(&md->event_nr); in dm_get_event_nr()
3057 return wait_event_interruptible(md->eventq, in dm_wait_event()
3058 (event_nr != atomic_read(&md->event_nr))); in dm_wait_event()
3065 spin_lock_irqsave(&md->uevent_lock, flags); in dm_uevent_add()
3066 list_add(elist, &md->uevent_list); in dm_uevent_add()
3067 spin_unlock_irqrestore(&md->uevent_lock, flags); in dm_uevent_add()
3076 return md->disk; in dm_disk()
3082 return &md->kobj_holder.kobj; in dm_kobject()
3092 if (test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { in dm_get_from_kobject()
3105 return test_bit(DMF_SUSPENDED, &md->flags); in dm_suspended_md()
3110 return test_bit(DMF_POST_SUSPENDING, &md->flags); in dm_post_suspending_md()
3115 return test_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in dm_suspended_internally_md()
3120 return test_bit(DMF_DEFERRED_REMOVE, &md->flags); in dm_test_deferred_remove_flag()
3125 return dm_suspended_md(ti->table->md); in dm_suspended()
3131 return dm_post_suspending_md(ti->table->md); in dm_post_suspending()
3137 return __noflush_suspending(ti->table->md); in dm_noflush_suspending()
3146 bioset_exit(&pools->bs); in dm_free_md_mempools()
3147 bioset_exit(&pools->io_bs); in dm_free_md_mempools()
3167 struct mapped_device *md = bdev->bd_disk->private_data; in dm_call_pr()
3170 int ret = -ENOTTY, srcu_idx; in dm_call_pr()
3177 if (table->num_targets != 1) in dm_call_pr()
3182 ret = -EAGAIN; in dm_call_pr()
3186 ret = -EINVAL; in dm_call_pr()
3187 if (!ti->type->iterate_devices) in dm_call_pr()
3190 ti->type->iterate_devices(ti, fn, pr); in dm_call_pr()
3198 * For register / unregister we need to manually call out to every path.
3204 const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops; in __dm_pr_register()
3207 if (!ops || !ops->pr_register) { in __dm_pr_register()
3208 pr->ret = -EOPNOTSUPP; in __dm_pr_register()
3209 return -1; in __dm_pr_register()
3212 ret = ops->pr_register(dev->bdev, pr->old_key, pr->new_key, pr->flags); in __dm_pr_register()
3216 if (!pr->ret) in __dm_pr_register()
3217 pr->ret = ret; in __dm_pr_register()
3219 if (pr->fail_early) in __dm_pr_register()
3220 return -1; in __dm_pr_register()
3239 /* Didn't even get to register a path */ in dm_pr_register()
3250 /* unregister all paths if we failed to register any path */ in dm_pr_register()
3264 const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops; in __dm_pr_reserve()
3266 if (!ops || !ops->pr_reserve) { in __dm_pr_reserve()
3267 pr->ret = -EOPNOTSUPP; in __dm_pr_reserve()
3268 return -1; in __dm_pr_reserve()
3271 pr->ret = ops->pr_reserve(dev->bdev, pr->old_key, pr->type, pr->flags); in __dm_pr_reserve()
3272 if (!pr->ret) in __dm_pr_reserve()
3273 return -1; in __dm_pr_reserve()
3298 * If there is a non-All Registrants type of reservation, the release must be
3301 * try each path to make sure we got the correct path.
3307 const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops; in __dm_pr_release()
3309 if (!ops || !ops->pr_release) { in __dm_pr_release()
3310 pr->ret = -EOPNOTSUPP; in __dm_pr_release()
3311 return -1; in __dm_pr_release()
3314 pr->ret = ops->pr_release(dev->bdev, pr->old_key, pr->type); in __dm_pr_release()
3315 if (pr->ret) in __dm_pr_release()
3316 return -1; in __dm_pr_release()
3341 const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops; in __dm_pr_preempt()
3343 if (!ops || !ops->pr_preempt) { in __dm_pr_preempt()
3344 pr->ret = -EOPNOTSUPP; in __dm_pr_preempt()
3345 return -1; in __dm_pr_preempt()
3348 pr->ret = ops->pr_preempt(dev->bdev, pr->old_key, pr->new_key, pr->type, in __dm_pr_preempt()
3349 pr->abort); in __dm_pr_preempt()
3350 if (!pr->ret) in __dm_pr_preempt()
3351 return -1; in __dm_pr_preempt()
3376 struct mapped_device *md = bdev->bd_disk->private_data; in dm_pr_clear()
3384 ops = bdev->bd_disk->fops->pr_ops; in dm_pr_clear()
3385 if (ops && ops->pr_clear) in dm_pr_clear()
3386 r = ops->pr_clear(bdev, key); in dm_pr_clear()
3388 r = -EOPNOTSUPP; in dm_pr_clear()
3398 const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops; in __dm_pr_read_keys()
3400 if (!ops || !ops->pr_read_keys) { in __dm_pr_read_keys()
3401 pr->ret = -EOPNOTSUPP; in __dm_pr_read_keys()
3402 return -1; in __dm_pr_read_keys()
3405 pr->ret = ops->pr_read_keys(dev->bdev, pr->read_keys); in __dm_pr_read_keys()
3406 if (!pr->ret) in __dm_pr_read_keys()
3407 return -1; in __dm_pr_read_keys()
3430 const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops; in __dm_pr_read_reservation()
3432 if (!ops || !ops->pr_read_reservation) { in __dm_pr_read_reservation()
3433 pr->ret = -EOPNOTSUPP; in __dm_pr_read_reservation()
3434 return -1; in __dm_pr_read_reservation()
3437 pr->ret = ops->pr_read_reservation(dev->bdev, pr->rsv); in __dm_pr_read_reservation()
3438 if (!pr->ret) in __dm_pr_read_reservation()
3439 return -1; in __dm_pr_read_reservation()
3506 MODULE_PARM_DESC(reserved_bio_based_ios, "Reserved IOs in bio-based mempools");
3515 MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");