Lines Matching full:md

307 int dm_deleting_md(struct mapped_device *md)  in dm_deleting_md()  argument
309 return test_bit(DMF_DELETING, &md->flags); in dm_deleting_md()
314 struct mapped_device *md; in dm_blk_open() local
318 md = bdev->bd_disk->private_data; in dm_blk_open()
319 if (!md) in dm_blk_open()
322 if (test_bit(DMF_FREEING, &md->flags) || in dm_blk_open()
323 dm_deleting_md(md)) { in dm_blk_open()
324 md = NULL; in dm_blk_open()
328 dm_get(md); in dm_blk_open()
329 atomic_inc(&md->open_count); in dm_blk_open()
333 return md ? 0 : -ENXIO; in dm_blk_open()
338 struct mapped_device *md; in dm_blk_close() local
342 md = disk->private_data; in dm_blk_close()
343 if (WARN_ON(!md)) 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()
350 dm_put(md); in dm_blk_close()
355 int dm_open_count(struct mapped_device *md) in dm_open_count() argument
357 return atomic_read(&md->open_count); in dm_open_count()
363 int dm_lock_for_deletion(struct mapped_device *md, bool mark_deferred, bool only_deferred) in dm_lock_for_deletion() argument
369 if (dm_open_count(md)) { 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()
376 set_bit(DMF_DELETING, &md->flags); in dm_lock_for_deletion()
383 int dm_cancel_deferred_remove(struct mapped_device *md) in dm_cancel_deferred_remove() argument
389 if (test_bit(DMF_DELETING, &md->flags)) 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() local
408 return dm_get_geometry(md, geo); in dm_blk_getgeo()
411 static int dm_prepare_ioctl(struct mapped_device *md, int *srcu_idx, in dm_prepare_ioctl() argument
420 map = dm_get_live_table(md, srcu_idx); in dm_prepare_ioctl()
432 if (dm_suspended_md(md)) in dm_prepare_ioctl()
437 dm_put_live_table(md, *srcu_idx); in dm_prepare_ioctl()
445 static void dm_unprepare_ioctl(struct mapped_device *md, int srcu_idx) in dm_unprepare_ioctl() argument
447 dm_put_live_table(md, srcu_idx); in dm_unprepare_ioctl()
453 struct mapped_device *md = bdev->bd_disk->private_data; in dm_blk_ioctl() local
456 r = dm_prepare_ioctl(md, &srcu_idx, &bdev); in dm_blk_ioctl()
479 dm_unprepare_ioctl(md, srcu_idx); in dm_blk_ioctl()
498 struct mapped_device *md = io->md; in dm_io_acct() local
520 unlikely(dm_stats_used(&md->stats))) { in dm_io_acct()
528 dm_stats_account_io(&md->stats, bio_data_dir(bio), in dm_io_acct()
570 static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio) in alloc_io() argument
576 clone = bio_alloc_clone(NULL, bio, GFP_NOIO, &md->mempools->io_bs); in alloc_io()
588 this_cpu_inc(*md->pending_io); in alloc_io()
590 io->md = md; in alloc_io()
596 dm_stats_record_start(&md->stats, &io->stats_aux); in alloc_io()
609 struct mapped_device *md = ci->io->md; in alloc_tio() local
620 &md->mempools->bs); in alloc_tio()
639 clone->bi_bdev = md->disk->part0; in alloc_tio()
641 bio_set_dev(clone, md->disk->part0); in alloc_tio()
662 static void queue_io(struct mapped_device *md, struct bio *bio) in queue_io() argument
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
677 struct dm_table *dm_get_live_table(struct mapped_device *md, in dm_get_live_table() argument
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()
685 void dm_put_live_table(struct mapped_device *md, in dm_put_live_table() argument
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()
691 void dm_sync_table(struct mapped_device *md) in dm_sync_table() argument
693 synchronize_srcu(&md->io_barrier); in dm_sync_table()
701 static struct dm_table *dm_get_live_table_fast(struct mapped_device *md) __acquires(RCU) in dm_get_live_table_fast() argument
704 return rcu_dereference(md->map); in dm_get_live_table_fast()
707 static void dm_put_live_table_fast(struct mapped_device *md) __releases(RCU) in dm_put_live_table_fast() argument
712 static inline struct dm_table *dm_get_live_table_bio(struct mapped_device *md, in dm_get_live_table_bio() argument
716 return dm_get_live_table_fast(md); in dm_get_live_table_bio()
718 return dm_get_live_table(md, srcu_idx); in dm_get_live_table_bio()
721 static inline void dm_put_live_table_bio(struct mapped_device *md, int srcu_idx, in dm_put_live_table_bio() argument
725 dm_put_live_table_fast(md); in dm_put_live_table_bio()
727 dm_put_live_table(md, srcu_idx); in dm_put_live_table_bio()
736 struct mapped_device *md) in open_table_device() argument
748 r = bd_link_disk_holder(bdev, dm_disk(md)); in open_table_device()
762 static void close_table_device(struct table_device *td, struct mapped_device *md) in close_table_device() argument
767 bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md)); in close_table_device()
786 int dm_get_table_device(struct mapped_device *md, dev_t dev, fmode_t mode, in dm_get_table_device() argument
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()
804 if ((r = open_table_device(td, dev, md))) { in dm_get_table_device()
805 mutex_unlock(&md->table_devices_lock); in dm_get_table_device()
813 list_add(&td->list, &md->table_devices); in dm_get_table_device()
817 mutex_unlock(&md->table_devices_lock); in dm_get_table_device()
823 void dm_put_table_device(struct mapped_device *md, struct dm_dev *d) in dm_put_table_device() argument
827 mutex_lock(&md->table_devices_lock); in dm_put_table_device()
829 close_table_device(td, md); in dm_put_table_device()
833 mutex_unlock(&md->table_devices_lock); in dm_put_table_device()
852 int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo) in dm_get_geometry() argument
854 *geo = md->geometry; in dm_get_geometry()
862 int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo) in dm_set_geometry() argument
871 md->geometry = *geo; in dm_set_geometry()
876 static int __noflush_suspending(struct mapped_device *md) in __noflush_suspending() argument
878 return test_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __noflush_suspending()
883 struct mapped_device *md = io->md; in dm_requeue_add_io() local
886 struct dm_io *next = md->requeue_list; in dm_requeue_add_io()
888 md->requeue_list = io; in dm_requeue_add_io()
891 bio_list_add_head(&md->deferred, io->orig_bio); in dm_requeue_add_io()
895 static void dm_kick_requeue(struct mapped_device *md, bool first_stage) in dm_kick_requeue() argument
898 queue_work(md->wq, &md->requeue_work); in dm_kick_requeue()
900 queue_work(md->wq, &md->work); in dm_kick_requeue()
913 struct mapped_device *md = io->md; in dm_handle_requeue() local
932 spin_lock_irqsave(&md->deferred_lock, flags); in dm_handle_requeue()
933 if ((__noflush_suspending(md) && in dm_handle_requeue()
934 !WARN_ON_ONCE(dm_is_zone_write(md, bio))) || in dm_handle_requeue()
945 spin_unlock_irqrestore(&md->deferred_lock, flags); in dm_handle_requeue()
949 dm_kick_requeue(md, first_stage); in dm_handle_requeue()
957 struct mapped_device *md = io->md; in __dm_io_complete() local
978 this_cpu_dec(*md->pending_io); 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()
994 queue_io(md, bio); in __dm_io_complete()
1005 struct mapped_device *md = container_of(work, struct mapped_device, in dm_wq_requeue_work() local
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()
1019 dm_io_rewind(io, &md->disk->bio_split); in dm_wq_requeue_work()
1072 __noflush_suspending(io->md))) { in dm_io_set_error()
1086 void disable_discard(struct mapped_device *md) in disable_discard() argument
1088 struct queue_limits *limits = dm_get_queue_limits(md); in disable_discard()
1094 void disable_write_zeroes(struct mapped_device *md) in disable_write_zeroes() argument
1096 struct queue_limits *limits = dm_get_queue_limits(md); in disable_write_zeroes()
1114 struct mapped_device *md = io->md; in clone_endio() local
1119 disable_discard(md); in clone_endio()
1122 disable_write_zeroes(md); in clone_endio()
1139 if (WARN_ON_ONCE(dm_is_zone_write(md, bio))) in clone_endio()
1159 up(&md->swap_bios_semaphore); in clone_endio()
1189 min(queue_max_sectors(ti->table->md->queue), in max_io_len()
1208 static struct dm_target *dm_dax_get_live_target(struct mapped_device *md, in dm_dax_get_live_target() argument
1210 __acquires(md->io_barrier) in dm_dax_get_live_target()
1215 map = dm_get_live_table(md, srcu_idx); in dm_dax_get_live_target()
1230 struct mapped_device *md = dax_get_private(dax_dev); in dm_dax_direct_access() local
1236 ti = dm_dax_get_live_target(md, sector, &srcu_idx); in dm_dax_direct_access()
1249 dm_put_live_table(md, srcu_idx); in dm_dax_direct_access()
1257 struct mapped_device *md = dax_get_private(dax_dev); in dm_dax_zero_page_range() local
1263 ti = dm_dax_get_live_target(md, sector, &srcu_idx); in dm_dax_zero_page_range()
1276 dm_put_live_table(md, srcu_idx); in dm_dax_zero_page_range()
1284 struct mapped_device *md = dax_get_private(dax_dev); in dm_dax_recovery_write() local
1290 ti = dm_dax_get_live_target(md, sector, &srcu_idx); in dm_dax_recovery_write()
1296 dm_put_live_table(md, srcu_idx); in dm_dax_recovery_write()
1379 trace_block_bio_remap(tgt_clone, disk_devt(io->md->disk), in dm_submit_bio_remap()
1385 static noinline void __set_swap_bios_limit(struct mapped_device *md, int latch) in __set_swap_bios_limit() argument
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()
1406 struct mapped_device *md = io->md; in __map_bio() local
1419 if (unlikely(latch != md->swap_bios)) in __map_bio()
1420 __set_swap_bios_limit(md, latch); in __map_bio()
1421 down(&md->swap_bios_semaphore); in __map_bio()
1430 if (unlikely(dm_emulate_zone_append(md))) in __map_bio()
1450 up(&md->swap_bios_semaphore); in __map_bio()
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()
1548 bio_init(&flush_bio, ci->io->md->disk->part0, NULL, 0, in __send_empty_flush()
1723 static void init_clone_info(struct clone_info *ci, struct mapped_device *md, in init_clone_info() argument
1727 ci->io = alloc_io(md, bio); in init_clone_info()
1743 static void dm_split_and_process_bio(struct mapped_device *md, in dm_split_and_process_bio() argument
1760 init_clone_info(&ci, md, map, bio, is_abnormal); in dm_split_and_process_bio()
1802 struct mapped_device *md = bio->bi_bdev->bd_disk->private_data; in dm_submit_bio() local
1807 map = dm_get_live_table_bio(md, &srcu_idx, bio_opf); in dm_submit_bio()
1810 if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) || in dm_submit_bio()
1817 queue_io(md, bio); in dm_submit_bio()
1821 dm_split_and_process_bio(md, map, bio); in dm_submit_bio()
1823 dm_put_live_table_bio(md, srcu_idx, bio_opf); in dm_submit_bio()
1956 static void cleanup_mapped_device(struct mapped_device *md) in cleanup_mapped_device() argument
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()
1969 dm_cleanup_zoned_dev(md); in cleanup_mapped_device()
1970 if (md->disk) { in cleanup_mapped_device()
1972 md->disk->private_data = NULL; in cleanup_mapped_device()
1974 if (dm_get_md_type(md) != DM_TYPE_NONE) { in cleanup_mapped_device()
1975 dm_sysfs_exit(md); 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()
1994 dm_mq_cleanup_mapped_device(md); in cleanup_mapped_device()
2003 struct mapped_device *md; in alloc_dev() local
2006 md = kvzalloc_node(sizeof(*md), GFP_KERNEL, numa_node_id); in alloc_dev()
2007 if (!md) { 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()
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()
2097 old_md = idr_replace(&_minor_idr, md, minor); in alloc_dev()
2102 return md; in alloc_dev()
2105 cleanup_mapped_device(md); in alloc_dev()
2111 kvfree(md); in alloc_dev()
2115 static void unlock_fs(struct mapped_device *md);
2117 static void free_dev(struct mapped_device *md) in free_dev() argument
2119 int minor = MINOR(disk_devt(md->disk)); in free_dev()
2121 unlock_fs(md); in free_dev()
2123 cleanup_mapped_device(md); in free_dev()
2125 free_table_devices(&md->table_devices); in free_dev()
2126 dm_stats_cleanup(&md->stats); in free_dev()
2130 kvfree(md); in free_dev()
2140 struct mapped_device *md = (struct mapped_device *) context; in event_callback() local
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()
2156 static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, in __bind() argument
2163 lockdep_assert_held(&md->suspend_lock); in __bind()
2170 if (size != dm_get_size(md)) 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()
2178 dm_table_event_callback(t, event_callback, md); in __bind()
2185 md->immutable_target = dm_table_get_immutable_target(t); in __bind()
2195 if (!md->mempools) { in __bind()
2196 md->mempools = t->mempools; in __bind()
2201 * The md may already have mempools that need changing. in __bind()
2205 dm_free_md_mempools(md->mempools); in __bind()
2206 md->mempools = t->mempools; 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()
2221 dm_sync_table(md); in __bind()
2229 static struct dm_table *__unbind(struct mapped_device *md) in __unbind() argument
2231 struct dm_table *map = rcu_dereference_protected(md->map, 1); in __unbind()
2237 RCU_INIT_POINTER(md->map, NULL); in __unbind()
2238 dm_sync_table(md); in __unbind()
2248 struct mapped_device *md; in dm_create() local
2250 md = alloc_dev(minor); in dm_create()
2251 if (!md) in dm_create()
2254 dm_ima_reset_data(md); in dm_create()
2256 *result = md; in dm_create()
2261 * Functions to manage md->type.
2262 * All are required to hold md->type_lock.
2264 void dm_lock_md_type(struct mapped_device *md) in dm_lock_md_type() argument
2266 mutex_lock(&md->type_lock); in dm_lock_md_type()
2269 void dm_unlock_md_type(struct mapped_device *md) in dm_unlock_md_type() argument
2271 mutex_unlock(&md->type_lock); in dm_unlock_md_type()
2274 void dm_set_md_type(struct mapped_device *md, enum dm_queue_mode type) in dm_set_md_type() argument
2276 BUG_ON(!mutex_is_locked(&md->type_lock)); in dm_set_md_type()
2277 md->type = type; in dm_set_md_type()
2280 enum dm_queue_mode dm_get_md_type(struct mapped_device *md) in dm_get_md_type() argument
2282 return md->type; in dm_get_md_type()
2285 struct target_type *dm_get_immutable_target_type(struct mapped_device *md) in dm_get_immutable_target_type() argument
2287 return md->immutable_target_type; in dm_get_immutable_target_type()
2292 * count on 'md'.
2294 struct queue_limits *dm_get_queue_limits(struct mapped_device *md) in dm_get_queue_limits() argument
2296 BUG_ON(!atomic_read(&md->holders)); in dm_get_queue_limits()
2297 return &md->queue->limits; in dm_get_queue_limits()
2302 * Setup the DM device's queue based on md's type
2304 int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t) in dm_setup_md_queue() argument
2312 md->disk->fops = &dm_rq_blk_dops; in dm_setup_md_queue()
2313 r = dm_mq_init_request_queue(md, t); 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()
2340 r = dm_sysfs_init(md); in dm_setup_md_queue()
2342 del_gendisk(md->disk); in dm_setup_md_queue()
2345 md->type = type; in dm_setup_md_queue()
2351 struct mapped_device *md; in dm_get_md() local
2359 md = idr_find(&_minor_idr, minor); in dm_get_md()
2360 if (!md || md == MINOR_ALLOCED || (MINOR(disk_devt(dm_disk(md))) != minor) || in dm_get_md()
2361 test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { in dm_get_md()
2362 md = NULL; in dm_get_md()
2365 dm_get(md); in dm_get_md()
2369 return md; in dm_get_md()
2373 void *dm_get_mdptr(struct mapped_device *md) in dm_get_mdptr() argument
2375 return md->interface_ptr; in dm_get_mdptr()
2378 void dm_set_mdptr(struct mapped_device *md, void *ptr) in dm_set_mdptr() argument
2380 md->interface_ptr = ptr; in dm_set_mdptr()
2383 void dm_get(struct mapped_device *md) in dm_get() argument
2385 atomic_inc(&md->holders); in dm_get()
2386 BUG_ON(test_bit(DMF_FREEING, &md->flags)); in dm_get()
2389 int dm_hold(struct mapped_device *md) in dm_hold() argument
2392 if (test_bit(DMF_FREEING, &md->flags)) { in dm_hold()
2396 dm_get(md); in dm_hold()
2402 const char *dm_device_name(struct mapped_device *md) in dm_device_name() argument
2404 return md->name; in dm_device_name()
2408 static void __dm_destroy(struct mapped_device *md, bool wait) in __dm_destroy() argument
2416 idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md)))); in __dm_destroy()
2417 set_bit(DMF_FREEING, &md->flags); in __dm_destroy()
2420 blk_mark_disk_dead(md->disk); in __dm_destroy()
2426 mutex_lock(&md->suspend_lock); in __dm_destroy()
2427 map = dm_get_live_table(md, &srcu_idx); in __dm_destroy()
2428 if (!dm_suspended_md(md)) { in __dm_destroy()
2430 set_bit(DMF_SUSPENDED, &md->flags); in __dm_destroy()
2431 set_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_destroy()
2435 dm_put_live_table(md, srcu_idx); in __dm_destroy()
2436 mutex_unlock(&md->suspend_lock); 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()
2451 dm_table_destroy(__unbind(md)); in __dm_destroy()
2452 free_dev(md); in __dm_destroy()
2455 void dm_destroy(struct mapped_device *md) in dm_destroy() argument
2457 __dm_destroy(md, true); in dm_destroy()
2460 void dm_destroy_immediate(struct mapped_device *md) in dm_destroy_immediate() argument
2462 __dm_destroy(md, false); in dm_destroy_immediate()
2465 void dm_put(struct mapped_device *md) in dm_put() argument
2467 atomic_dec(&md->holders); in dm_put()
2471 static bool dm_in_flight_bios(struct mapped_device *md) in dm_in_flight_bios() argument
2477 sum += *per_cpu_ptr(md->pending_io, cpu); in dm_in_flight_bios()
2482 static int dm_wait_for_bios_completion(struct mapped_device *md, unsigned int task_state) in dm_wait_for_bios_completion() argument
2488 prepare_to_wait(&md->wait, &wait, task_state); in dm_wait_for_bios_completion()
2490 if (!dm_in_flight_bios(md)) in dm_wait_for_bios_completion()
2500 finish_wait(&md->wait, &wait); in dm_wait_for_bios_completion()
2507 static int dm_wait_for_completion(struct mapped_device *md, unsigned int task_state) in dm_wait_for_completion() argument
2511 if (!queue_is_mq(md->queue)) in dm_wait_for_completion()
2512 return dm_wait_for_bios_completion(md, task_state); in dm_wait_for_completion()
2515 if (!blk_mq_queue_inflight(md->queue)) in dm_wait_for_completion()
2534 struct mapped_device *md = container_of(work, struct mapped_device, work); in dm_wq_work() local
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()
2549 static void dm_queue_flush(struct mapped_device *md) in dm_queue_flush() argument
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()
2559 struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table) in dm_swap_table() argument
2565 mutex_lock(&md->suspend_lock); in dm_swap_table()
2568 if (!dm_suspended_md(md)) in dm_swap_table()
2578 live_map = dm_get_live_table_fast(md); in dm_swap_table()
2580 limits = md->queue->limits; in dm_swap_table()
2581 dm_put_live_table_fast(md); in dm_swap_table()
2592 map = __bind(md, table, &limits); in dm_swap_table()
2596 mutex_unlock(&md->suspend_lock); in dm_swap_table()
2604 static int lock_fs(struct mapped_device *md) in lock_fs() argument
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()
2616 static void unlock_fs(struct mapped_device *md) in unlock_fs() argument
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()
2631 * are being added to md->deferred list.
2633 static int __dm_suspend(struct mapped_device *md, struct dm_table *map, in __dm_suspend() argument
2641 lockdep_assert_held(&md->suspend_lock); in __dm_suspend()
2648 set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __dm_suspend()
2650 DMDEBUG("%s: suspending with flush", dm_device_name(md)); in __dm_suspend()
2665 r = lock_fs(md); 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()
2691 if (dm_request_based(md)) in __dm_suspend()
2692 dm_stop_queue(md->queue); in __dm_suspend()
2694 flush_workqueue(md->wq); in __dm_suspend()
2701 r = dm_wait_for_completion(md, task_state); 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()
2712 dm_queue_flush(md); in __dm_suspend()
2714 if (dm_request_based(md)) in __dm_suspend()
2715 dm_start_queue(md->queue); in __dm_suspend()
2717 unlock_fs(md); in __dm_suspend()
2741 int dm_suspend(struct mapped_device *md, unsigned suspend_flags) in dm_suspend() argument
2747 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING); in dm_suspend()
2749 if (dm_suspended_md(md)) { in dm_suspend()
2754 if (dm_suspended_internally_md(md)) { 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()
2765 r = __dm_suspend(md, map, suspend_flags, TASK_INTERRUPTIBLE, DMF_SUSPENDED); 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()
2778 static int __dm_resume(struct mapped_device *md, struct dm_table *map) in __dm_resume() argument
2786 dm_queue_flush(md); in __dm_resume()
2793 if (dm_request_based(md)) in __dm_resume()
2794 dm_start_queue(md->queue); in __dm_resume()
2796 unlock_fs(md); in __dm_resume()
2801 int dm_resume(struct mapped_device *md) in dm_resume() argument
2808 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING); in dm_resume()
2810 if (!dm_suspended_md(md)) in dm_resume()
2813 if (dm_suspended_internally_md(md)) { 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()
2826 r = __dm_resume(md, map); in dm_resume()
2830 clear_bit(DMF_SUSPENDED, &md->flags); in dm_resume()
2832 mutex_unlock(&md->suspend_lock); in dm_resume()
2843 static void __dm_internal_suspend(struct mapped_device *md, unsigned suspend_flags) in __dm_internal_suspend() argument
2847 lockdep_assert_held(&md->suspend_lock); in __dm_internal_suspend()
2849 if (md->internal_suspend_count++) in __dm_internal_suspend()
2852 if (dm_suspended_md(md)) { in __dm_internal_suspend()
2853 set_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in __dm_internal_suspend()
2857 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __dm_internal_suspend()
2865 (void) __dm_suspend(md, map, suspend_flags, TASK_UNINTERRUPTIBLE, 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()
2873 static void __dm_internal_resume(struct mapped_device *md) in __dm_internal_resume() argument
2875 BUG_ON(!md->internal_suspend_count); in __dm_internal_resume()
2877 if (--md->internal_suspend_count) in __dm_internal_resume()
2880 if (dm_suspended_md(md)) in __dm_internal_resume()
2887 (void) __dm_resume(md, NULL); 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()
2895 void dm_internal_suspend_noflush(struct mapped_device *md) in dm_internal_suspend_noflush() argument
2897 mutex_lock(&md->suspend_lock); in dm_internal_suspend_noflush()
2898 __dm_internal_suspend(md, DM_SUSPEND_NOFLUSH_FLAG); in dm_internal_suspend_noflush()
2899 mutex_unlock(&md->suspend_lock); in dm_internal_suspend_noflush()
2903 void dm_internal_resume(struct mapped_device *md) in dm_internal_resume() argument
2905 mutex_lock(&md->suspend_lock); in dm_internal_resume()
2906 __dm_internal_resume(md); 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,
2916 void dm_internal_suspend_fast(struct mapped_device *md) in dm_internal_suspend_fast() argument
2918 mutex_lock(&md->suspend_lock); in dm_internal_suspend_fast()
2919 if (dm_suspended_md(md) || dm_suspended_internally_md(md)) 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()
2925 dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); in dm_internal_suspend_fast()
2929 void dm_internal_resume_fast(struct mapped_device *md) in dm_internal_resume_fast() argument
2931 if (dm_suspended_md(md) || dm_suspended_internally_md(md)) in dm_internal_resume_fast()
2934 dm_queue_flush(md); in dm_internal_resume_fast()
2937 mutex_unlock(&md->suspend_lock); in dm_internal_resume_fast()
2944 int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action, in dm_kobject_uevent() argument
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()
2968 uint32_t dm_next_uevent_seq(struct mapped_device *md) in dm_next_uevent_seq() argument
2970 return atomic_add_return(1, &md->uevent_seq); in dm_next_uevent_seq()
2973 uint32_t dm_get_event_nr(struct mapped_device *md) in dm_get_event_nr() argument
2975 return atomic_read(&md->event_nr); in dm_get_event_nr()
2978 int dm_wait_event(struct mapped_device *md, int event_nr) in dm_wait_event() argument
2980 return wait_event_interruptible(md->eventq, in dm_wait_event()
2981 (event_nr != atomic_read(&md->event_nr))); in dm_wait_event()
2984 void dm_uevent_add(struct mapped_device *md, struct list_head *elist) in dm_uevent_add() argument
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()
2995 * count on 'md'.
2997 struct gendisk *dm_disk(struct mapped_device *md) in dm_disk() argument
2999 return md->disk; in dm_disk()
3003 struct kobject *dm_kobject(struct mapped_device *md) in dm_kobject() argument
3005 return &md->kobj_holder.kobj; in dm_kobject()
3010 struct mapped_device *md; in dm_get_from_kobject() local
3012 md = container_of(kobj, struct mapped_device, kobj_holder.kobj); in dm_get_from_kobject()
3015 if (test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { in dm_get_from_kobject()
3016 md = NULL; in dm_get_from_kobject()
3019 dm_get(md); in dm_get_from_kobject()
3023 return md; in dm_get_from_kobject()
3026 int dm_suspended_md(struct mapped_device *md) in dm_suspended_md() argument
3028 return test_bit(DMF_SUSPENDED, &md->flags); in dm_suspended_md()
3031 static int dm_post_suspending_md(struct mapped_device *md) in dm_post_suspending_md() argument
3033 return test_bit(DMF_POST_SUSPENDING, &md->flags); in dm_post_suspending_md()
3036 int dm_suspended_internally_md(struct mapped_device *md) in dm_suspended_internally_md() argument
3038 return test_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in dm_suspended_internally_md()
3041 int dm_test_deferred_remove_flag(struct mapped_device *md) in dm_test_deferred_remove_flag() argument
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()
3088 struct mapped_device *md = bdev->bd_disk->private_data; in dm_call_pr() local
3093 table = dm_get_live_table(md, &srcu_idx); in dm_call_pr()
3102 if (dm_suspended_md(md)) { in dm_call_pr()
3114 dm_put_live_table(md, srcu_idx); in dm_call_pr()
3297 struct mapped_device *md = bdev->bd_disk->private_data; in dm_pr_clear() local
3301 r = dm_prepare_ioctl(md, &srcu_idx, &bdev); in dm_pr_clear()
3311 dm_unprepare_ioctl(md, srcu_idx); in dm_pr_clear()