• Home
  • Raw
  • Download

Lines Matching full:md

308 int dm_deleting_md(struct mapped_device *md)  in dm_deleting_md()  argument
310 return test_bit(DMF_DELETING, &md->flags); in dm_deleting_md()
315 struct mapped_device *md; in dm_blk_open() local
319 md = disk->private_data; in dm_blk_open()
320 if (!md) in dm_blk_open()
323 if (test_bit(DMF_FREEING, &md->flags) || in dm_blk_open()
324 dm_deleting_md(md)) { in dm_blk_open()
325 md = NULL; in dm_blk_open()
329 dm_get(md); in dm_blk_open()
330 atomic_inc(&md->open_count); in dm_blk_open()
334 return md ? 0 : -ENXIO; in dm_blk_open()
339 struct mapped_device *md; in dm_blk_close() local
343 md = disk->private_data; in dm_blk_close()
344 if (WARN_ON(!md)) 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()
351 dm_put(md); in dm_blk_close()
356 int dm_open_count(struct mapped_device *md) in dm_open_count() argument
358 return atomic_read(&md->open_count); in dm_open_count()
364 int dm_lock_for_deletion(struct mapped_device *md, bool mark_deferred, bool only_deferred) in dm_lock_for_deletion() argument
370 if (dm_open_count(md)) { 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()
377 set_bit(DMF_DELETING, &md->flags); in dm_lock_for_deletion()
384 int dm_cancel_deferred_remove(struct mapped_device *md) in dm_cancel_deferred_remove() argument
390 if (test_bit(DMF_DELETING, &md->flags)) 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() local
409 return dm_get_geometry(md, geo); in dm_blk_getgeo()
412 static int dm_prepare_ioctl(struct mapped_device *md, int *srcu_idx, in dm_prepare_ioctl() argument
421 map = dm_get_live_table(md, srcu_idx); in dm_prepare_ioctl()
433 if (dm_suspended_md(md)) in dm_prepare_ioctl()
438 dm_put_live_table(md, *srcu_idx); in dm_prepare_ioctl()
446 static void dm_unprepare_ioctl(struct mapped_device *md, int srcu_idx) in dm_unprepare_ioctl() argument
448 dm_put_live_table(md, srcu_idx); in dm_unprepare_ioctl()
454 struct mapped_device *md = bdev->bd_disk->private_data; in dm_blk_ioctl() local
457 r = dm_prepare_ioctl(md, &srcu_idx, &bdev); in dm_blk_ioctl()
480 dm_unprepare_ioctl(md, srcu_idx); in dm_blk_ioctl()
523 unlikely(dm_stats_used(&io->md->stats))) { in dm_io_acct()
531 dm_stats_account_io(&io->md->stats, bio_data_dir(bio), in dm_io_acct()
573 static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio) in alloc_io() argument
579 clone = bio_alloc_clone(NULL, bio, GFP_NOIO, &md->mempools->io_bs); in alloc_io()
591 this_cpu_inc(*md->pending_io); in alloc_io()
593 io->md = md; in alloc_io()
597 if (blk_queue_io_stat(md->queue)) in alloc_io()
601 unlikely(dm_stats_used(&md->stats))) in alloc_io()
602 dm_stats_record_start(&md->stats, &io->stats_aux); in alloc_io()
615 struct mapped_device *md = ci->io->md; in alloc_tio() local
626 &md->mempools->bs); in alloc_tio()
645 clone->bi_bdev = md->disk->part0; in alloc_tio()
647 bio_set_dev(clone, md->disk->part0); in alloc_tio()
668 static void queue_io(struct mapped_device *md, struct bio *bio) in queue_io() argument
672 spin_lock_irqsave(&md->deferred_lock, flags); in queue_io()
673 bio_list_add(&md->deferred, bio); in queue_io()
674 spin_unlock_irqrestore(&md->deferred_lock, flags); in queue_io()
675 queue_work(md->wq, &md->work); in queue_io()
680 * function to access the md->map field, and make sure they call
683 struct dm_table *dm_get_live_table(struct mapped_device *md, in dm_get_live_table() argument
684 int *srcu_idx) __acquires(md->io_barrier) in dm_get_live_table()
686 *srcu_idx = srcu_read_lock(&md->io_barrier); in dm_get_live_table()
688 return srcu_dereference(md->map, &md->io_barrier); in dm_get_live_table()
691 void dm_put_live_table(struct mapped_device *md, in dm_put_live_table() argument
692 int srcu_idx) __releases(md->io_barrier) in dm_put_live_table()
694 srcu_read_unlock(&md->io_barrier, srcu_idx); in dm_put_live_table()
697 void dm_sync_table(struct mapped_device *md) in dm_sync_table() argument
699 synchronize_srcu(&md->io_barrier); in dm_sync_table()
707 static struct dm_table *dm_get_live_table_fast(struct mapped_device *md) __acquires(RCU) in dm_get_live_table_fast() argument
710 return rcu_dereference(md->map); in dm_get_live_table_fast()
713 static void dm_put_live_table_fast(struct mapped_device *md) __releases(RCU) in dm_put_live_table_fast() argument
723 static struct table_device *open_table_device(struct mapped_device *md, in open_table_device() argument
731 td = kmalloc_node(sizeof(*td), GFP_KERNEL, md->numa_node_id); in open_table_device()
747 if (md->disk->slave_dir) { in open_table_device()
748 r = bd_link_disk_holder(bdev, md->disk); in open_table_device()
757 list_add(&td->list, &md->table_devices); in open_table_device()
770 static void close_table_device(struct table_device *td, struct mapped_device *md) in close_table_device() argument
772 if (md->disk->slave_dir) in close_table_device()
773 bd_unlink_disk_holder(td->dm_dev.bdev, md->disk); in close_table_device()
792 int dm_get_table_device(struct mapped_device *md, dev_t dev, blk_mode_t mode, in dm_get_table_device() argument
797 mutex_lock(&md->table_devices_lock); in dm_get_table_device()
798 td = find_table_device(&md->table_devices, dev, mode); in dm_get_table_device()
800 td = open_table_device(md, dev, mode); in dm_get_table_device()
802 mutex_unlock(&md->table_devices_lock); in dm_get_table_device()
808 mutex_unlock(&md->table_devices_lock); in dm_get_table_device()
814 void dm_put_table_device(struct mapped_device *md, struct dm_dev *d) in dm_put_table_device() argument
818 mutex_lock(&md->table_devices_lock); in dm_put_table_device()
820 close_table_device(td, md); in dm_put_table_device()
821 mutex_unlock(&md->table_devices_lock); in dm_put_table_device()
827 int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo) in dm_get_geometry() argument
829 *geo = md->geometry; in dm_get_geometry()
837 int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo) in dm_set_geometry() argument
846 md->geometry = *geo; in dm_set_geometry()
851 static int __noflush_suspending(struct mapped_device *md) in __noflush_suspending() argument
853 return test_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __noflush_suspending()
858 struct mapped_device *md = io->md; in dm_requeue_add_io() local
861 struct dm_io *next = md->requeue_list; in dm_requeue_add_io()
863 md->requeue_list = io; in dm_requeue_add_io()
866 bio_list_add_head(&md->deferred, io->orig_bio); in dm_requeue_add_io()
870 static void dm_kick_requeue(struct mapped_device *md, bool first_stage) in dm_kick_requeue() argument
873 queue_work(md->wq, &md->requeue_work); in dm_kick_requeue()
875 queue_work(md->wq, &md->work); in dm_kick_requeue()
888 struct mapped_device *md = io->md; in dm_handle_requeue() local
907 spin_lock_irqsave(&md->deferred_lock, flags); in dm_handle_requeue()
908 if ((__noflush_suspending(md) && in dm_handle_requeue()
909 !WARN_ON_ONCE(dm_is_zone_write(md, bio))) || in dm_handle_requeue()
920 spin_unlock_irqrestore(&md->deferred_lock, flags); in dm_handle_requeue()
924 dm_kick_requeue(md, first_stage); in dm_handle_requeue()
932 struct mapped_device *md = io->md; in __dm_io_complete() local
953 this_cpu_dec(*md->pending_io); in __dm_io_complete()
956 if (unlikely(wq_has_sleeper(&md->wait))) in __dm_io_complete()
957 wake_up(&md->wait); in __dm_io_complete()
969 queue_io(md, bio); in __dm_io_complete()
980 struct mapped_device *md = container_of(work, struct mapped_device, in dm_wq_requeue_work() local
986 spin_lock_irqsave(&md->deferred_lock, flags); in dm_wq_requeue_work()
987 io = md->requeue_list; in dm_wq_requeue_work()
988 md->requeue_list = NULL; in dm_wq_requeue_work()
989 spin_unlock_irqrestore(&md->deferred_lock, flags); in dm_wq_requeue_work()
994 dm_io_rewind(io, &md->disk->bio_split); in dm_wq_requeue_work()
1048 __noflush_suspending(io->md))) { in dm_io_set_error()
1064 * count on 'md'. But _not_ imposing verification to avoid atomic_read(),
1066 static inline struct queue_limits *dm_get_queue_limits(struct mapped_device *md) in dm_get_queue_limits() argument
1068 return &md->queue->limits; in dm_get_queue_limits()
1071 void disable_discard(struct mapped_device *md) in disable_discard() argument
1073 struct queue_limits *limits = dm_get_queue_limits(md); in disable_discard()
1079 void disable_write_zeroes(struct mapped_device *md) in disable_write_zeroes() argument
1081 struct queue_limits *limits = dm_get_queue_limits(md); in disable_write_zeroes()
1099 struct mapped_device *md = io->md; in clone_endio() local
1104 disable_discard(md); in clone_endio()
1107 disable_write_zeroes(md); in clone_endio()
1125 if (WARN_ON_ONCE(dm_is_zone_write(md, bio))) in clone_endio()
1145 up(&md->swap_bios_semaphore); in clone_endio()
1177 min(max_sectors ? : queue_max_sectors(ti->table->md->queue), in __max_io_len()
1201 static struct dm_target *dm_dax_get_live_target(struct mapped_device *md, in dm_dax_get_live_target() argument
1203 __acquires(md->io_barrier) in dm_dax_get_live_target()
1208 map = dm_get_live_table(md, srcu_idx); in dm_dax_get_live_target()
1223 struct mapped_device *md = dax_get_private(dax_dev); in dm_dax_direct_access() local
1229 ti = dm_dax_get_live_target(md, sector, &srcu_idx); in dm_dax_direct_access()
1242 dm_put_live_table(md, srcu_idx); in dm_dax_direct_access()
1250 struct mapped_device *md = dax_get_private(dax_dev); in dm_dax_zero_page_range() local
1256 ti = dm_dax_get_live_target(md, sector, &srcu_idx); in dm_dax_zero_page_range()
1269 dm_put_live_table(md, srcu_idx); in dm_dax_zero_page_range()
1277 struct mapped_device *md = dax_get_private(dax_dev); in dm_dax_recovery_write() local
1283 ti = dm_dax_get_live_target(md, sector, &srcu_idx); in dm_dax_recovery_write()
1289 dm_put_live_table(md, srcu_idx); in dm_dax_recovery_write()
1372 trace_block_bio_remap(tgt_clone, disk_devt(io->md->disk), in dm_submit_bio_remap()
1378 static noinline void __set_swap_bios_limit(struct mapped_device *md, int latch) in __set_swap_bios_limit() argument
1380 mutex_lock(&md->swap_bios_lock); in __set_swap_bios_limit()
1381 while (latch < md->swap_bios) { in __set_swap_bios_limit()
1383 down(&md->swap_bios_semaphore); in __set_swap_bios_limit()
1384 md->swap_bios--; in __set_swap_bios_limit()
1386 while (latch > md->swap_bios) { in __set_swap_bios_limit()
1388 up(&md->swap_bios_semaphore); in __set_swap_bios_limit()
1389 md->swap_bios++; in __set_swap_bios_limit()
1391 mutex_unlock(&md->swap_bios_lock); in __set_swap_bios_limit()
1399 struct mapped_device *md = io->md; in __map_bio() local
1413 if (unlikely(latch != md->swap_bios)) in __map_bio()
1414 __set_swap_bios_limit(md, latch); in __map_bio()
1415 down(&md->swap_bios_semaphore); in __map_bio()
1424 if (unlikely(dm_emulate_zone_append(md))) in __map_bio()
1444 up(&md->swap_bios_semaphore); in __map_bio()
1483 mutex_lock(&ci->io->md->table_devices_lock); in alloc_multiple_bios()
1493 mutex_unlock(&ci->io->md->table_devices_lock); in alloc_multiple_bios()
1545 bio_init(&flush_bio, ci->io->md->disk->part0, NULL, 0, in __send_empty_flush()
1616 struct queue_limits *limits = dm_get_queue_limits(ti->table->md); in __process_abnormal_io()
1734 static void init_clone_info(struct clone_info *ci, struct mapped_device *md, in init_clone_info() argument
1738 ci->io = alloc_io(md, bio); in init_clone_info()
1754 static void dm_split_and_process_bio(struct mapped_device *md, in dm_split_and_process_bio() argument
1773 init_clone_info(&ci, md, map, bio, is_abnormal); in dm_split_and_process_bio()
1815 struct mapped_device *md = bio->bi_bdev->bd_disk->private_data; in dm_submit_bio() local
1819 map = dm_get_live_table(md, &srcu_idx); in dm_submit_bio()
1822 dm_device_name(md)); in dm_submit_bio()
1828 if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags))) { in dm_submit_bio()
1834 queue_io(md, bio); in dm_submit_bio()
1838 dm_split_and_process_bio(md, map, bio); in dm_submit_bio()
1840 dm_put_live_table(md, srcu_idx); in dm_submit_bio()
1975 static void cleanup_mapped_device(struct mapped_device *md) in cleanup_mapped_device() argument
1977 if (md->wq) in cleanup_mapped_device()
1978 destroy_workqueue(md->wq); in cleanup_mapped_device()
1979 dm_free_md_mempools(md->mempools); in cleanup_mapped_device()
1981 if (md->dax_dev) { in cleanup_mapped_device()
1982 dax_remove_host(md->disk); in cleanup_mapped_device()
1983 kill_dax(md->dax_dev); in cleanup_mapped_device()
1984 put_dax(md->dax_dev); in cleanup_mapped_device()
1985 md->dax_dev = NULL; in cleanup_mapped_device()
1988 dm_cleanup_zoned_dev(md); in cleanup_mapped_device()
1989 if (md->disk) { in cleanup_mapped_device()
1991 md->disk->private_data = NULL; in cleanup_mapped_device()
1993 if (dm_get_md_type(md) != DM_TYPE_NONE) { in cleanup_mapped_device()
1996 dm_sysfs_exit(md); in cleanup_mapped_device()
1997 list_for_each_entry(td, &md->table_devices, list) { in cleanup_mapped_device()
1999 md->disk); in cleanup_mapped_device()
2006 mutex_lock(&md->table_devices_lock); in cleanup_mapped_device()
2007 del_gendisk(md->disk); in cleanup_mapped_device()
2008 mutex_unlock(&md->table_devices_lock); in cleanup_mapped_device()
2010 dm_queue_destroy_crypto_profile(md->queue); in cleanup_mapped_device()
2011 put_disk(md->disk); in cleanup_mapped_device()
2014 if (md->pending_io) { in cleanup_mapped_device()
2015 free_percpu(md->pending_io); in cleanup_mapped_device()
2016 md->pending_io = NULL; in cleanup_mapped_device()
2019 cleanup_srcu_struct(&md->io_barrier); in cleanup_mapped_device()
2021 mutex_destroy(&md->suspend_lock); in cleanup_mapped_device()
2022 mutex_destroy(&md->type_lock); in cleanup_mapped_device()
2023 mutex_destroy(&md->table_devices_lock); in cleanup_mapped_device()
2024 mutex_destroy(&md->swap_bios_lock); in cleanup_mapped_device()
2026 dm_mq_cleanup_mapped_device(md); in cleanup_mapped_device()
2035 struct mapped_device *md; in alloc_dev() local
2038 md = kvzalloc_node(sizeof(*md), GFP_KERNEL, numa_node_id); in alloc_dev()
2039 if (!md) { in alloc_dev()
2055 r = init_srcu_struct(&md->io_barrier); in alloc_dev()
2059 md->numa_node_id = numa_node_id; in alloc_dev()
2060 md->init_tio_pdu = false; in alloc_dev()
2061 md->type = DM_TYPE_NONE; in alloc_dev()
2062 mutex_init(&md->suspend_lock); in alloc_dev()
2063 mutex_init(&md->type_lock); in alloc_dev()
2064 mutex_init(&md->table_devices_lock); in alloc_dev()
2065 spin_lock_init(&md->deferred_lock); in alloc_dev()
2066 atomic_set(&md->holders, 1); in alloc_dev()
2067 atomic_set(&md->open_count, 0); in alloc_dev()
2068 atomic_set(&md->event_nr, 0); in alloc_dev()
2069 atomic_set(&md->uevent_seq, 0); in alloc_dev()
2070 INIT_LIST_HEAD(&md->uevent_list); in alloc_dev()
2071 INIT_LIST_HEAD(&md->table_devices); in alloc_dev()
2072 spin_lock_init(&md->uevent_lock); in alloc_dev()
2075 * default to bio-based until DM table is loaded and md->type in alloc_dev()
2079 md->disk = blk_alloc_disk(md->numa_node_id); in alloc_dev()
2080 if (!md->disk) in alloc_dev()
2082 md->queue = md->disk->queue; in alloc_dev()
2084 init_waitqueue_head(&md->wait); in alloc_dev()
2085 INIT_WORK(&md->work, dm_wq_work); in alloc_dev()
2086 INIT_WORK(&md->requeue_work, dm_wq_requeue_work); in alloc_dev()
2087 init_waitqueue_head(&md->eventq); in alloc_dev()
2088 init_completion(&md->kobj_holder.completion); in alloc_dev()
2090 md->requeue_list = NULL; in alloc_dev()
2091 md->swap_bios = get_swap_bios(); in alloc_dev()
2092 sema_init(&md->swap_bios_semaphore, md->swap_bios); in alloc_dev()
2093 mutex_init(&md->swap_bios_lock); in alloc_dev()
2095 md->disk->major = _major; in alloc_dev()
2096 md->disk->first_minor = minor; in alloc_dev()
2097 md->disk->minors = 1; in alloc_dev()
2098 md->disk->flags |= GENHD_FL_NO_PART; in alloc_dev()
2099 md->disk->fops = &dm_blk_dops; in alloc_dev()
2100 md->disk->private_data = md; in alloc_dev()
2101 sprintf(md->disk->disk_name, "dm-%d", minor); in alloc_dev()
2104 md->dax_dev = alloc_dax(md, &dm_dax_ops); in alloc_dev()
2105 if (IS_ERR(md->dax_dev)) { in alloc_dev()
2106 md->dax_dev = NULL; in alloc_dev()
2109 set_dax_nocache(md->dax_dev); in alloc_dev()
2110 set_dax_nomc(md->dax_dev); in alloc_dev()
2111 if (dax_add_host(md->dax_dev, md->disk)) in alloc_dev()
2115 format_dev_t(md->name, MKDEV(_major, minor)); in alloc_dev()
2117 md->wq = alloc_workqueue("kdmflush/%s", WQ_MEM_RECLAIM, 0, md->name); in alloc_dev()
2118 if (!md->wq) in alloc_dev()
2121 md->pending_io = alloc_percpu(unsigned long); in alloc_dev()
2122 if (!md->pending_io) in alloc_dev()
2125 r = dm_stats_init(&md->stats); in alloc_dev()
2131 old_md = idr_replace(&_minor_idr, md, minor); in alloc_dev()
2136 return md; in alloc_dev()
2139 cleanup_mapped_device(md); in alloc_dev()
2145 kvfree(md); in alloc_dev()
2149 static void unlock_fs(struct mapped_device *md);
2151 static void free_dev(struct mapped_device *md) in free_dev() argument
2153 int minor = MINOR(disk_devt(md->disk)); in free_dev()
2155 unlock_fs(md); in free_dev()
2157 cleanup_mapped_device(md); in free_dev()
2159 WARN_ON_ONCE(!list_empty(&md->table_devices)); in free_dev()
2160 dm_stats_cleanup(&md->stats); in free_dev()
2164 kvfree(md); in free_dev()
2174 struct mapped_device *md = context; in event_callback() local
2176 spin_lock_irqsave(&md->uevent_lock, flags); in event_callback()
2177 list_splice_init(&md->uevent_list, &uevents); in event_callback()
2178 spin_unlock_irqrestore(&md->uevent_lock, flags); in event_callback()
2180 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj); in event_callback()
2182 atomic_inc(&md->event_nr); in event_callback()
2183 wake_up(&md->eventq); in event_callback()
2190 static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, in __bind() argument
2197 lockdep_assert_held(&md->suspend_lock); in __bind()
2204 if (size != dm_get_size(md)) in __bind()
2205 memset(&md->geometry, 0, sizeof(md->geometry)); in __bind()
2207 set_capacity(md->disk, size); in __bind()
2209 dm_table_event_callback(t, event_callback, md); in __bind()
2216 md->immutable_target = dm_table_get_immutable_target(t); in __bind()
2226 if (!md->mempools) { in __bind()
2227 md->mempools = t->mempools; in __bind()
2232 * The md may already have mempools that need changing. in __bind()
2236 dm_free_md_mempools(md->mempools); in __bind()
2237 md->mempools = t->mempools; in __bind()
2241 ret = dm_table_set_restrictions(t, md->queue, limits); in __bind()
2247 old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __bind()
2248 rcu_assign_pointer(md->map, (void *)t); in __bind()
2249 md->immutable_target_type = dm_table_get_immutable_target_type(t); in __bind()
2252 dm_sync_table(md); in __bind()
2260 static struct dm_table *__unbind(struct mapped_device *md) in __unbind() argument
2262 struct dm_table *map = rcu_dereference_protected(md->map, 1); in __unbind()
2268 RCU_INIT_POINTER(md->map, NULL); in __unbind()
2269 dm_sync_table(md); in __unbind()
2279 struct mapped_device *md; in dm_create() local
2281 md = alloc_dev(minor); in dm_create()
2282 if (!md) in dm_create()
2285 dm_ima_reset_data(md); in dm_create()
2287 *result = md; in dm_create()
2292 * Functions to manage md->type.
2293 * All are required to hold md->type_lock.
2295 void dm_lock_md_type(struct mapped_device *md) in dm_lock_md_type() argument
2297 mutex_lock(&md->type_lock); in dm_lock_md_type()
2300 void dm_unlock_md_type(struct mapped_device *md) in dm_unlock_md_type() argument
2302 mutex_unlock(&md->type_lock); in dm_unlock_md_type()
2305 void dm_set_md_type(struct mapped_device *md, enum dm_queue_mode type) in dm_set_md_type() argument
2307 BUG_ON(!mutex_is_locked(&md->type_lock)); in dm_set_md_type()
2308 md->type = type; in dm_set_md_type()
2311 enum dm_queue_mode dm_get_md_type(struct mapped_device *md) in dm_get_md_type() argument
2313 return md->type; in dm_get_md_type()
2316 struct target_type *dm_get_immutable_target_type(struct mapped_device *md) in dm_get_immutable_target_type() argument
2318 return md->immutable_target_type; in dm_get_immutable_target_type()
2322 * Setup the DM device's queue based on md's type
2324 int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t) in dm_setup_md_queue() argument
2333 md->disk->fops = &dm_rq_blk_dops; in dm_setup_md_queue()
2334 r = dm_mq_init_request_queue(md, t); in dm_setup_md_queue()
2342 blk_queue_flag_set(QUEUE_FLAG_IO_STAT, md->queue); in dm_setup_md_queue()
2354 r = dm_table_set_restrictions(t, md->queue, &limits); in dm_setup_md_queue()
2362 mutex_lock(&md->table_devices_lock); in dm_setup_md_queue()
2363 r = add_disk(md->disk); in dm_setup_md_queue()
2364 mutex_unlock(&md->table_devices_lock); in dm_setup_md_queue()
2372 list_for_each_entry(td, &md->table_devices, list) { in dm_setup_md_queue()
2373 r = bd_link_disk_holder(td->dm_dev.bdev, md->disk); in dm_setup_md_queue()
2378 r = dm_sysfs_init(md); in dm_setup_md_queue()
2382 md->type = type; in dm_setup_md_queue()
2386 list_for_each_entry_continue_reverse(td, &md->table_devices, list) in dm_setup_md_queue()
2387 bd_unlink_disk_holder(td->dm_dev.bdev, md->disk); in dm_setup_md_queue()
2388 mutex_lock(&md->table_devices_lock); in dm_setup_md_queue()
2389 del_gendisk(md->disk); in dm_setup_md_queue()
2390 mutex_unlock(&md->table_devices_lock); in dm_setup_md_queue()
2396 struct mapped_device *md; in dm_get_md() local
2404 md = idr_find(&_minor_idr, minor); in dm_get_md()
2405 if (!md || md == MINOR_ALLOCED || (MINOR(disk_devt(dm_disk(md))) != minor) || in dm_get_md()
2406 test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { in dm_get_md()
2407 md = NULL; in dm_get_md()
2410 dm_get(md); in dm_get_md()
2414 return md; in dm_get_md()
2418 void *dm_get_mdptr(struct mapped_device *md) in dm_get_mdptr() argument
2420 return md->interface_ptr; in dm_get_mdptr()
2423 void dm_set_mdptr(struct mapped_device *md, void *ptr) in dm_set_mdptr() argument
2425 md->interface_ptr = ptr; in dm_set_mdptr()
2428 void dm_get(struct mapped_device *md) in dm_get() argument
2430 atomic_inc(&md->holders); in dm_get()
2431 BUG_ON(test_bit(DMF_FREEING, &md->flags)); in dm_get()
2434 int dm_hold(struct mapped_device *md) in dm_hold() argument
2437 if (test_bit(DMF_FREEING, &md->flags)) { in dm_hold()
2441 dm_get(md); in dm_hold()
2447 const char *dm_device_name(struct mapped_device *md) in dm_device_name() argument
2449 return md->name; in dm_device_name()
2453 static void __dm_destroy(struct mapped_device *md, bool wait) in __dm_destroy() argument
2461 idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md)))); in __dm_destroy()
2462 set_bit(DMF_FREEING, &md->flags); in __dm_destroy()
2465 blk_mark_disk_dead(md->disk); in __dm_destroy()
2471 mutex_lock(&md->suspend_lock); in __dm_destroy()
2472 map = dm_get_live_table(md, &srcu_idx); in __dm_destroy()
2473 if (!dm_suspended_md(md)) { in __dm_destroy()
2475 set_bit(DMF_SUSPENDED, &md->flags); in __dm_destroy()
2476 set_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_destroy()
2480 dm_put_live_table(md, srcu_idx); in __dm_destroy()
2481 mutex_unlock(&md->suspend_lock); in __dm_destroy()
2490 while (atomic_read(&md->holders)) in __dm_destroy()
2492 else if (atomic_read(&md->holders)) in __dm_destroy()
2494 dm_device_name(md), atomic_read(&md->holders)); in __dm_destroy()
2496 dm_table_destroy(__unbind(md)); in __dm_destroy()
2497 free_dev(md); in __dm_destroy()
2500 void dm_destroy(struct mapped_device *md) in dm_destroy() argument
2502 __dm_destroy(md, true); in dm_destroy()
2505 void dm_destroy_immediate(struct mapped_device *md) in dm_destroy_immediate() argument
2507 __dm_destroy(md, false); in dm_destroy_immediate()
2510 void dm_put(struct mapped_device *md) in dm_put() argument
2512 atomic_dec(&md->holders); in dm_put()
2516 static bool dm_in_flight_bios(struct mapped_device *md) in dm_in_flight_bios() argument
2522 sum += *per_cpu_ptr(md->pending_io, cpu); in dm_in_flight_bios()
2527 static int dm_wait_for_bios_completion(struct mapped_device *md, unsigned int task_state) in dm_wait_for_bios_completion() argument
2533 prepare_to_wait(&md->wait, &wait, task_state); in dm_wait_for_bios_completion()
2535 if (!dm_in_flight_bios(md)) in dm_wait_for_bios_completion()
2545 finish_wait(&md->wait, &wait); in dm_wait_for_bios_completion()
2552 static int dm_wait_for_completion(struct mapped_device *md, unsigned int task_state) in dm_wait_for_completion() argument
2556 if (!queue_is_mq(md->queue)) in dm_wait_for_completion()
2557 return dm_wait_for_bios_completion(md, task_state); in dm_wait_for_completion()
2560 if (!blk_mq_queue_inflight(md->queue)) in dm_wait_for_completion()
2579 struct mapped_device *md = container_of(work, struct mapped_device, work); in dm_wq_work() local
2582 while (!test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) { in dm_wq_work()
2583 spin_lock_irq(&md->deferred_lock); in dm_wq_work()
2584 bio = bio_list_pop(&md->deferred); in dm_wq_work()
2585 spin_unlock_irq(&md->deferred_lock); in dm_wq_work()
2595 static void dm_queue_flush(struct mapped_device *md) in dm_queue_flush() argument
2597 clear_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in dm_queue_flush()
2599 queue_work(md->wq, &md->work); in dm_queue_flush()
2605 struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table) in dm_swap_table() argument
2611 mutex_lock(&md->suspend_lock); in dm_swap_table()
2614 if (!dm_suspended_md(md)) in dm_swap_table()
2624 live_map = dm_get_live_table_fast(md); in dm_swap_table()
2626 limits = md->queue->limits; in dm_swap_table()
2627 dm_put_live_table_fast(md); in dm_swap_table()
2638 map = __bind(md, table, &limits); in dm_swap_table()
2642 mutex_unlock(&md->suspend_lock); in dm_swap_table()
2650 static int lock_fs(struct mapped_device *md) in lock_fs() argument
2654 WARN_ON(test_bit(DMF_FROZEN, &md->flags)); in lock_fs()
2656 r = freeze_bdev(md->disk->part0); in lock_fs()
2658 set_bit(DMF_FROZEN, &md->flags); in lock_fs()
2662 static void unlock_fs(struct mapped_device *md) in unlock_fs() argument
2664 if (!test_bit(DMF_FROZEN, &md->flags)) in unlock_fs()
2666 thaw_bdev(md->disk->part0); in unlock_fs()
2667 clear_bit(DMF_FROZEN, &md->flags); in unlock_fs()
2677 * are being added to md->deferred list.
2679 static int __dm_suspend(struct mapped_device *md, struct dm_table *map, in __dm_suspend() argument
2687 lockdep_assert_held(&md->suspend_lock); in __dm_suspend()
2694 set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __dm_suspend()
2696 DMDEBUG("%s: suspending with flush", dm_device_name(md)); in __dm_suspend()
2711 r = lock_fs(md); in __dm_suspend()
2727 * flush_workqueue(md->wq). in __dm_suspend()
2729 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in __dm_suspend()
2731 synchronize_srcu(&md->io_barrier); in __dm_suspend()
2734 * Stop md->queue before flushing md->wq in case request-based in __dm_suspend()
2735 * dm defers requests to md->wq from md->queue. in __dm_suspend()
2737 if (dm_request_based(md)) in __dm_suspend()
2738 dm_stop_queue(md->queue); in __dm_suspend()
2740 flush_workqueue(md->wq); in __dm_suspend()
2747 r = dm_wait_for_completion(md, task_state); in __dm_suspend()
2749 set_bit(dmf_suspended_flag, &md->flags); in __dm_suspend()
2752 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __dm_suspend()
2754 synchronize_srcu(&md->io_barrier); in __dm_suspend()
2758 dm_queue_flush(md); in __dm_suspend()
2760 if (dm_request_based(md)) in __dm_suspend()
2761 dm_start_queue(md->queue); in __dm_suspend()
2763 unlock_fs(md); in __dm_suspend()
2787 int dm_suspend(struct mapped_device *md, unsigned int suspend_flags) in dm_suspend() argument
2793 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING); in dm_suspend()
2795 if (dm_suspended_md(md)) { in dm_suspend()
2800 if (dm_suspended_internally_md(md)) { in dm_suspend()
2802 mutex_unlock(&md->suspend_lock); in dm_suspend()
2803 r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE); in dm_suspend()
2809 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in dm_suspend()
2815 r = __dm_suspend(md, map, suspend_flags, TASK_INTERRUPTIBLE, DMF_SUSPENDED); in dm_suspend()
2819 set_bit(DMF_POST_SUSPENDING, &md->flags); in dm_suspend()
2821 clear_bit(DMF_POST_SUSPENDING, &md->flags); in dm_suspend()
2824 mutex_unlock(&md->suspend_lock); in dm_suspend()
2828 static int __dm_resume(struct mapped_device *md, struct dm_table *map) in __dm_resume() argument
2837 dm_queue_flush(md); in __dm_resume()
2844 if (dm_request_based(md)) in __dm_resume()
2845 dm_start_queue(md->queue); in __dm_resume()
2847 unlock_fs(md); in __dm_resume()
2852 int dm_resume(struct mapped_device *md) in dm_resume() argument
2859 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING); in dm_resume()
2861 if (!dm_suspended_md(md)) in dm_resume()
2864 if (dm_suspended_internally_md(md)) { in dm_resume()
2866 mutex_unlock(&md->suspend_lock); in dm_resume()
2867 r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE); in dm_resume()
2873 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in dm_resume()
2877 r = __dm_resume(md, map); in dm_resume()
2881 clear_bit(DMF_SUSPENDED, &md->flags); in dm_resume()
2883 mutex_unlock(&md->suspend_lock); in dm_resume()
2894 static void __dm_internal_suspend(struct mapped_device *md, unsigned int suspend_flags) in __dm_internal_suspend() argument
2898 lockdep_assert_held(&md->suspend_lock); in __dm_internal_suspend()
2900 if (md->internal_suspend_count++) in __dm_internal_suspend()
2903 if (dm_suspended_md(md)) { in __dm_internal_suspend()
2904 set_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in __dm_internal_suspend()
2908 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __dm_internal_suspend()
2916 (void) __dm_suspend(md, map, suspend_flags, TASK_UNINTERRUPTIBLE, in __dm_internal_suspend()
2919 set_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_internal_suspend()
2921 clear_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_internal_suspend()
2924 static void __dm_internal_resume(struct mapped_device *md) in __dm_internal_resume() argument
2929 BUG_ON(!md->internal_suspend_count); in __dm_internal_resume()
2931 if (--md->internal_suspend_count) in __dm_internal_resume()
2934 if (dm_suspended_md(md)) in __dm_internal_resume()
2937 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __dm_internal_resume()
2938 r = __dm_resume(md, map); in __dm_internal_resume()
2952 set_bit(DMF_SUSPENDED, &md->flags); in __dm_internal_resume()
2955 clear_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in __dm_internal_resume()
2957 wake_up_bit(&md->flags, DMF_SUSPENDED_INTERNALLY); in __dm_internal_resume()
2960 void dm_internal_suspend_noflush(struct mapped_device *md) in dm_internal_suspend_noflush() argument
2962 mutex_lock(&md->suspend_lock); in dm_internal_suspend_noflush()
2963 __dm_internal_suspend(md, DM_SUSPEND_NOFLUSH_FLAG); in dm_internal_suspend_noflush()
2964 mutex_unlock(&md->suspend_lock); in dm_internal_suspend_noflush()
2968 void dm_internal_resume(struct mapped_device *md) in dm_internal_resume() argument
2970 mutex_lock(&md->suspend_lock); in dm_internal_resume()
2971 __dm_internal_resume(md); in dm_internal_resume()
2972 mutex_unlock(&md->suspend_lock); in dm_internal_resume()
2977 * Fast variants of internal suspend/resume hold md->suspend_lock,
2981 void dm_internal_suspend_fast(struct mapped_device *md) in dm_internal_suspend_fast() argument
2983 mutex_lock(&md->suspend_lock); in dm_internal_suspend_fast()
2984 if (dm_suspended_md(md) || dm_suspended_internally_md(md)) in dm_internal_suspend_fast()
2987 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in dm_internal_suspend_fast()
2988 synchronize_srcu(&md->io_barrier); in dm_internal_suspend_fast()
2989 flush_workqueue(md->wq); in dm_internal_suspend_fast()
2990 dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); in dm_internal_suspend_fast()
2994 void dm_internal_resume_fast(struct mapped_device *md) in dm_internal_resume_fast() argument
2996 if (dm_suspended_md(md) || dm_suspended_internally_md(md)) in dm_internal_resume_fast()
2999 dm_queue_flush(md); in dm_internal_resume_fast()
3002 mutex_unlock(&md->suspend_lock); in dm_internal_resume_fast()
3011 int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action, in dm_kobject_uevent() argument
3030 r = kobject_uevent_env(&disk_to_dev(md->disk)->kobj, action, envp); in dm_kobject_uevent()
3037 uint32_t dm_next_uevent_seq(struct mapped_device *md) in dm_next_uevent_seq() argument
3039 return atomic_add_return(1, &md->uevent_seq); in dm_next_uevent_seq()
3042 uint32_t dm_get_event_nr(struct mapped_device *md) in dm_get_event_nr() argument
3044 return atomic_read(&md->event_nr); in dm_get_event_nr()
3047 int dm_wait_event(struct mapped_device *md, int event_nr) in dm_wait_event() argument
3049 return wait_event_interruptible(md->eventq, in dm_wait_event()
3050 (event_nr != atomic_read(&md->event_nr))); in dm_wait_event()
3053 void dm_uevent_add(struct mapped_device *md, struct list_head *elist) in dm_uevent_add() argument
3057 spin_lock_irqsave(&md->uevent_lock, flags); in dm_uevent_add()
3058 list_add(elist, &md->uevent_list); in dm_uevent_add()
3059 spin_unlock_irqrestore(&md->uevent_lock, flags); in dm_uevent_add()
3064 * count on 'md'.
3066 struct gendisk *dm_disk(struct mapped_device *md) in dm_disk() argument
3068 return md->disk; in dm_disk()
3072 struct kobject *dm_kobject(struct mapped_device *md) in dm_kobject() argument
3074 return &md->kobj_holder.kobj; in dm_kobject()
3079 struct mapped_device *md; in dm_get_from_kobject() local
3081 md = container_of(kobj, struct mapped_device, kobj_holder.kobj); in dm_get_from_kobject()
3084 if (test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { in dm_get_from_kobject()
3085 md = NULL; in dm_get_from_kobject()
3088 dm_get(md); in dm_get_from_kobject()
3092 return md; in dm_get_from_kobject()
3095 int dm_suspended_md(struct mapped_device *md) in dm_suspended_md() argument
3097 return test_bit(DMF_SUSPENDED, &md->flags); in dm_suspended_md()
3100 static int dm_post_suspending_md(struct mapped_device *md) in dm_post_suspending_md() argument
3102 return test_bit(DMF_POST_SUSPENDING, &md->flags); in dm_post_suspending_md()
3105 int dm_suspended_internally_md(struct mapped_device *md) in dm_suspended_internally_md() argument
3107 return test_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in dm_suspended_internally_md()
3110 int dm_test_deferred_remove_flag(struct mapped_device *md) in dm_test_deferred_remove_flag() argument
3112 return test_bit(DMF_DEFERRED_REMOVE, &md->flags); in dm_test_deferred_remove_flag()
3117 return dm_suspended_md(ti->table->md); in dm_suspended()
3123 return dm_post_suspending_md(ti->table->md); in dm_post_suspending()
3129 return __noflush_suspending(ti->table->md); in dm_noflush_suspending()
3159 struct mapped_device *md = bdev->bd_disk->private_data; in dm_call_pr() local
3164 table = dm_get_live_table(md, &srcu_idx); in dm_call_pr()
3173 if (dm_suspended_md(md)) { in dm_call_pr()
3185 dm_put_live_table(md, srcu_idx); in dm_call_pr()
3368 struct mapped_device *md = bdev->bd_disk->private_data; in dm_pr_clear() local
3372 r = dm_prepare_ioctl(md, &srcu_idx, &bdev); in dm_pr_clear()
3382 dm_unprepare_ioctl(md, srcu_idx); in dm_pr_clear()