• 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()
1550 bio_init(&flush_bio, ci->io->md->disk->part0, NULL, 0, opf); in __send_empty_flush()
1620 struct queue_limits *limits = dm_get_queue_limits(ti->table->md); in __process_abnormal_io()
1738 static void init_clone_info(struct clone_info *ci, struct mapped_device *md, in init_clone_info() argument
1742 ci->io = alloc_io(md, bio); in init_clone_info()
1758 static void dm_split_and_process_bio(struct mapped_device *md, in dm_split_and_process_bio() argument
1777 init_clone_info(&ci, md, map, bio, is_abnormal); in dm_split_and_process_bio()
1819 struct mapped_device *md = bio->bi_bdev->bd_disk->private_data; in dm_submit_bio() local
1823 map = dm_get_live_table(md, &srcu_idx); in dm_submit_bio()
1826 dm_device_name(md)); in dm_submit_bio()
1832 if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags))) { in dm_submit_bio()
1838 queue_io(md, bio); in dm_submit_bio()
1842 dm_split_and_process_bio(md, map, bio); in dm_submit_bio()
1844 dm_put_live_table(md, srcu_idx); in dm_submit_bio()
1979 static void cleanup_mapped_device(struct mapped_device *md) in cleanup_mapped_device() argument
1981 if (md->wq) in cleanup_mapped_device()
1982 destroy_workqueue(md->wq); in cleanup_mapped_device()
1983 dm_free_md_mempools(md->mempools); in cleanup_mapped_device()
1985 if (md->dax_dev) { in cleanup_mapped_device()
1986 dax_remove_host(md->disk); in cleanup_mapped_device()
1987 kill_dax(md->dax_dev); in cleanup_mapped_device()
1988 put_dax(md->dax_dev); in cleanup_mapped_device()
1989 md->dax_dev = NULL; in cleanup_mapped_device()
1992 dm_cleanup_zoned_dev(md); in cleanup_mapped_device()
1993 if (md->disk) { in cleanup_mapped_device()
1995 md->disk->private_data = NULL; in cleanup_mapped_device()
1997 if (dm_get_md_type(md) != DM_TYPE_NONE) { in cleanup_mapped_device()
2000 dm_sysfs_exit(md); in cleanup_mapped_device()
2001 list_for_each_entry(td, &md->table_devices, list) { in cleanup_mapped_device()
2003 md->disk); in cleanup_mapped_device()
2010 mutex_lock(&md->table_devices_lock); in cleanup_mapped_device()
2011 del_gendisk(md->disk); in cleanup_mapped_device()
2012 mutex_unlock(&md->table_devices_lock); in cleanup_mapped_device()
2014 dm_queue_destroy_crypto_profile(md->queue); in cleanup_mapped_device()
2015 put_disk(md->disk); in cleanup_mapped_device()
2018 if (md->pending_io) { in cleanup_mapped_device()
2019 free_percpu(md->pending_io); in cleanup_mapped_device()
2020 md->pending_io = NULL; in cleanup_mapped_device()
2023 cleanup_srcu_struct(&md->io_barrier); in cleanup_mapped_device()
2025 mutex_destroy(&md->suspend_lock); in cleanup_mapped_device()
2026 mutex_destroy(&md->type_lock); in cleanup_mapped_device()
2027 mutex_destroy(&md->table_devices_lock); in cleanup_mapped_device()
2028 mutex_destroy(&md->swap_bios_lock); in cleanup_mapped_device()
2030 dm_mq_cleanup_mapped_device(md); in cleanup_mapped_device()
2039 struct mapped_device *md; in alloc_dev() local
2042 md = kvzalloc_node(sizeof(*md), GFP_KERNEL, numa_node_id); in alloc_dev()
2043 if (!md) { in alloc_dev()
2059 r = init_srcu_struct(&md->io_barrier); in alloc_dev()
2063 md->numa_node_id = numa_node_id; in alloc_dev()
2064 md->init_tio_pdu = false; in alloc_dev()
2065 md->type = DM_TYPE_NONE; in alloc_dev()
2066 mutex_init(&md->suspend_lock); in alloc_dev()
2067 mutex_init(&md->type_lock); in alloc_dev()
2068 mutex_init(&md->table_devices_lock); in alloc_dev()
2069 spin_lock_init(&md->deferred_lock); in alloc_dev()
2070 atomic_set(&md->holders, 1); in alloc_dev()
2071 atomic_set(&md->open_count, 0); in alloc_dev()
2072 atomic_set(&md->event_nr, 0); in alloc_dev()
2073 atomic_set(&md->uevent_seq, 0); in alloc_dev()
2074 INIT_LIST_HEAD(&md->uevent_list); in alloc_dev()
2075 INIT_LIST_HEAD(&md->table_devices); in alloc_dev()
2076 spin_lock_init(&md->uevent_lock); in alloc_dev()
2079 * default to bio-based until DM table is loaded and md->type in alloc_dev()
2083 md->disk = blk_alloc_disk(md->numa_node_id); in alloc_dev()
2084 if (!md->disk) in alloc_dev()
2086 md->queue = md->disk->queue; in alloc_dev()
2088 init_waitqueue_head(&md->wait); in alloc_dev()
2089 INIT_WORK(&md->work, dm_wq_work); in alloc_dev()
2090 INIT_WORK(&md->requeue_work, dm_wq_requeue_work); in alloc_dev()
2091 init_waitqueue_head(&md->eventq); in alloc_dev()
2092 init_completion(&md->kobj_holder.completion); in alloc_dev()
2094 md->requeue_list = NULL; in alloc_dev()
2095 md->swap_bios = get_swap_bios(); in alloc_dev()
2096 sema_init(&md->swap_bios_semaphore, md->swap_bios); in alloc_dev()
2097 mutex_init(&md->swap_bios_lock); in alloc_dev()
2099 md->disk->major = _major; in alloc_dev()
2100 md->disk->first_minor = minor; in alloc_dev()
2101 md->disk->minors = 1; in alloc_dev()
2102 md->disk->flags |= GENHD_FL_NO_PART; in alloc_dev()
2103 md->disk->fops = &dm_blk_dops; in alloc_dev()
2104 md->disk->private_data = md; in alloc_dev()
2105 sprintf(md->disk->disk_name, "dm-%d", minor); in alloc_dev()
2108 md->dax_dev = alloc_dax(md, &dm_dax_ops); in alloc_dev()
2109 if (IS_ERR(md->dax_dev)) { in alloc_dev()
2110 md->dax_dev = NULL; in alloc_dev()
2113 set_dax_nocache(md->dax_dev); in alloc_dev()
2114 set_dax_nomc(md->dax_dev); in alloc_dev()
2115 if (dax_add_host(md->dax_dev, md->disk)) in alloc_dev()
2119 format_dev_t(md->name, MKDEV(_major, minor)); in alloc_dev()
2121 md->wq = alloc_workqueue("kdmflush/%s", WQ_MEM_RECLAIM, 0, md->name); in alloc_dev()
2122 if (!md->wq) in alloc_dev()
2125 md->pending_io = alloc_percpu(unsigned long); in alloc_dev()
2126 if (!md->pending_io) in alloc_dev()
2129 r = dm_stats_init(&md->stats); in alloc_dev()
2135 old_md = idr_replace(&_minor_idr, md, minor); in alloc_dev()
2140 return md; in alloc_dev()
2143 cleanup_mapped_device(md); in alloc_dev()
2149 kvfree(md); in alloc_dev()
2153 static void unlock_fs(struct mapped_device *md);
2155 static void free_dev(struct mapped_device *md) in free_dev() argument
2157 int minor = MINOR(disk_devt(md->disk)); in free_dev()
2159 unlock_fs(md); in free_dev()
2161 cleanup_mapped_device(md); in free_dev()
2163 WARN_ON_ONCE(!list_empty(&md->table_devices)); in free_dev()
2164 dm_stats_cleanup(&md->stats); in free_dev()
2168 kvfree(md); in free_dev()
2178 struct mapped_device *md = context; in event_callback() local
2180 spin_lock_irqsave(&md->uevent_lock, flags); in event_callback()
2181 list_splice_init(&md->uevent_list, &uevents); in event_callback()
2182 spin_unlock_irqrestore(&md->uevent_lock, flags); in event_callback()
2184 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj); in event_callback()
2186 atomic_inc(&md->event_nr); in event_callback()
2187 wake_up(&md->eventq); in event_callback()
2194 static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, in __bind() argument
2201 lockdep_assert_held(&md->suspend_lock); in __bind()
2205 old_size = dm_get_size(md); in __bind()
2206 set_capacity(md->disk, size); in __bind()
2208 ret = dm_table_set_restrictions(t, md->queue, limits); in __bind()
2210 set_capacity(md->disk, old_size); in __bind()
2219 memset(&md->geometry, 0, sizeof(md->geometry)); in __bind()
2221 dm_table_event_callback(t, event_callback, md); in __bind()
2228 md->immutable_target = dm_table_get_immutable_target(t); in __bind()
2238 if (!md->mempools) in __bind()
2239 md->mempools = t->mempools; in __bind()
2244 * The md may already have mempools that need changing. in __bind()
2248 dm_free_md_mempools(md->mempools); in __bind()
2249 md->mempools = t->mempools; in __bind()
2253 old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __bind()
2254 rcu_assign_pointer(md->map, (void *)t); in __bind()
2255 md->immutable_target_type = dm_table_get_immutable_target_type(t); in __bind()
2258 dm_sync_table(md); in __bind()
2266 static struct dm_table *__unbind(struct mapped_device *md) in __unbind() argument
2268 struct dm_table *map = rcu_dereference_protected(md->map, 1); in __unbind()
2274 RCU_INIT_POINTER(md->map, NULL); in __unbind()
2275 dm_sync_table(md); in __unbind()
2285 struct mapped_device *md; in dm_create() local
2287 md = alloc_dev(minor); in dm_create()
2288 if (!md) in dm_create()
2291 dm_ima_reset_data(md); in dm_create()
2293 *result = md; in dm_create()
2298 * Functions to manage md->type.
2299 * All are required to hold md->type_lock.
2301 void dm_lock_md_type(struct mapped_device *md) in dm_lock_md_type() argument
2303 mutex_lock(&md->type_lock); in dm_lock_md_type()
2306 void dm_unlock_md_type(struct mapped_device *md) in dm_unlock_md_type() argument
2308 mutex_unlock(&md->type_lock); in dm_unlock_md_type()
2311 void dm_set_md_type(struct mapped_device *md, enum dm_queue_mode type) in dm_set_md_type() argument
2313 BUG_ON(!mutex_is_locked(&md->type_lock)); in dm_set_md_type()
2314 md->type = type; in dm_set_md_type()
2317 enum dm_queue_mode dm_get_md_type(struct mapped_device *md) in dm_get_md_type() argument
2319 return md->type; in dm_get_md_type()
2322 struct target_type *dm_get_immutable_target_type(struct mapped_device *md) in dm_get_immutable_target_type() argument
2324 return md->immutable_target_type; in dm_get_immutable_target_type()
2328 * Setup the DM device's queue based on md's type
2330 int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t) in dm_setup_md_queue() argument
2339 md->disk->fops = &dm_rq_blk_dops; in dm_setup_md_queue()
2340 r = dm_mq_init_request_queue(md, t); in dm_setup_md_queue()
2348 blk_queue_flag_set(QUEUE_FLAG_IO_STAT, md->queue); in dm_setup_md_queue()
2360 r = dm_table_set_restrictions(t, md->queue, &limits); in dm_setup_md_queue()
2368 mutex_lock(&md->table_devices_lock); in dm_setup_md_queue()
2369 r = add_disk(md->disk); in dm_setup_md_queue()
2370 mutex_unlock(&md->table_devices_lock); in dm_setup_md_queue()
2378 list_for_each_entry(td, &md->table_devices, list) { in dm_setup_md_queue()
2379 r = bd_link_disk_holder(td->dm_dev.bdev, md->disk); in dm_setup_md_queue()
2384 r = dm_sysfs_init(md); in dm_setup_md_queue()
2388 md->type = type; in dm_setup_md_queue()
2392 list_for_each_entry_continue_reverse(td, &md->table_devices, list) in dm_setup_md_queue()
2393 bd_unlink_disk_holder(td->dm_dev.bdev, md->disk); in dm_setup_md_queue()
2394 mutex_lock(&md->table_devices_lock); in dm_setup_md_queue()
2395 del_gendisk(md->disk); in dm_setup_md_queue()
2396 mutex_unlock(&md->table_devices_lock); in dm_setup_md_queue()
2402 struct mapped_device *md; in dm_get_md() local
2410 md = idr_find(&_minor_idr, minor); in dm_get_md()
2411 if (!md || md == MINOR_ALLOCED || (MINOR(disk_devt(dm_disk(md))) != minor) || in dm_get_md()
2412 test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { in dm_get_md()
2413 md = NULL; in dm_get_md()
2416 dm_get(md); in dm_get_md()
2420 return md; in dm_get_md()
2424 void *dm_get_mdptr(struct mapped_device *md) in dm_get_mdptr() argument
2426 return md->interface_ptr; in dm_get_mdptr()
2429 void dm_set_mdptr(struct mapped_device *md, void *ptr) in dm_set_mdptr() argument
2431 md->interface_ptr = ptr; in dm_set_mdptr()
2434 void dm_get(struct mapped_device *md) in dm_get() argument
2436 atomic_inc(&md->holders); in dm_get()
2437 BUG_ON(test_bit(DMF_FREEING, &md->flags)); in dm_get()
2440 int dm_hold(struct mapped_device *md) in dm_hold() argument
2443 if (test_bit(DMF_FREEING, &md->flags)) { in dm_hold()
2447 dm_get(md); in dm_hold()
2453 const char *dm_device_name(struct mapped_device *md) in dm_device_name() argument
2455 return md->name; in dm_device_name()
2459 static void __dm_destroy(struct mapped_device *md, bool wait) in __dm_destroy() argument
2467 idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md)))); in __dm_destroy()
2468 set_bit(DMF_FREEING, &md->flags); in __dm_destroy()
2471 blk_mark_disk_dead(md->disk); in __dm_destroy()
2477 mutex_lock(&md->suspend_lock); in __dm_destroy()
2478 map = dm_get_live_table(md, &srcu_idx); in __dm_destroy()
2479 if (!dm_suspended_md(md)) { in __dm_destroy()
2481 set_bit(DMF_SUSPENDED, &md->flags); in __dm_destroy()
2482 set_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_destroy()
2486 dm_put_live_table(md, srcu_idx); in __dm_destroy()
2487 mutex_unlock(&md->suspend_lock); in __dm_destroy()
2496 while (atomic_read(&md->holders)) in __dm_destroy()
2498 else if (atomic_read(&md->holders)) in __dm_destroy()
2500 dm_device_name(md), atomic_read(&md->holders)); in __dm_destroy()
2502 dm_table_destroy(__unbind(md)); in __dm_destroy()
2503 free_dev(md); in __dm_destroy()
2506 void dm_destroy(struct mapped_device *md) in dm_destroy() argument
2508 __dm_destroy(md, true); in dm_destroy()
2511 void dm_destroy_immediate(struct mapped_device *md) in dm_destroy_immediate() argument
2513 __dm_destroy(md, false); in dm_destroy_immediate()
2516 void dm_put(struct mapped_device *md) in dm_put() argument
2518 atomic_dec(&md->holders); in dm_put()
2522 static bool dm_in_flight_bios(struct mapped_device *md) in dm_in_flight_bios() argument
2528 sum += *per_cpu_ptr(md->pending_io, cpu); in dm_in_flight_bios()
2533 static int dm_wait_for_bios_completion(struct mapped_device *md, unsigned int task_state) in dm_wait_for_bios_completion() argument
2539 prepare_to_wait(&md->wait, &wait, task_state); in dm_wait_for_bios_completion()
2541 if (!dm_in_flight_bios(md)) in dm_wait_for_bios_completion()
2551 finish_wait(&md->wait, &wait); in dm_wait_for_bios_completion()
2558 static int dm_wait_for_completion(struct mapped_device *md, unsigned int task_state) in dm_wait_for_completion() argument
2562 if (!queue_is_mq(md->queue)) in dm_wait_for_completion()
2563 return dm_wait_for_bios_completion(md, task_state); in dm_wait_for_completion()
2566 if (!blk_mq_queue_inflight(md->queue)) in dm_wait_for_completion()
2585 struct mapped_device *md = container_of(work, struct mapped_device, work); in dm_wq_work() local
2588 while (!test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) { in dm_wq_work()
2589 spin_lock_irq(&md->deferred_lock); in dm_wq_work()
2590 bio = bio_list_pop(&md->deferred); in dm_wq_work()
2591 spin_unlock_irq(&md->deferred_lock); in dm_wq_work()
2601 static void dm_queue_flush(struct mapped_device *md) in dm_queue_flush() argument
2603 clear_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in dm_queue_flush()
2605 queue_work(md->wq, &md->work); in dm_queue_flush()
2611 struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table) in dm_swap_table() argument
2617 mutex_lock(&md->suspend_lock); in dm_swap_table()
2620 if (!dm_suspended_md(md)) in dm_swap_table()
2630 live_map = dm_get_live_table_fast(md); in dm_swap_table()
2632 limits = md->queue->limits; in dm_swap_table()
2633 dm_put_live_table_fast(md); in dm_swap_table()
2644 map = __bind(md, table, &limits); in dm_swap_table()
2648 mutex_unlock(&md->suspend_lock); in dm_swap_table()
2656 static int lock_fs(struct mapped_device *md) in lock_fs() argument
2660 WARN_ON(test_bit(DMF_FROZEN, &md->flags)); in lock_fs()
2662 r = freeze_bdev(md->disk->part0); in lock_fs()
2664 set_bit(DMF_FROZEN, &md->flags); in lock_fs()
2668 static void unlock_fs(struct mapped_device *md) in unlock_fs() argument
2670 if (!test_bit(DMF_FROZEN, &md->flags)) in unlock_fs()
2672 thaw_bdev(md->disk->part0); in unlock_fs()
2673 clear_bit(DMF_FROZEN, &md->flags); in unlock_fs()
2683 * are being added to md->deferred list.
2685 static int __dm_suspend(struct mapped_device *md, struct dm_table *map, in __dm_suspend() argument
2693 lockdep_assert_held(&md->suspend_lock); in __dm_suspend()
2700 set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __dm_suspend()
2702 DMDEBUG("%s: suspending with flush", dm_device_name(md)); in __dm_suspend()
2717 r = lock_fs(md); in __dm_suspend()
2733 * flush_workqueue(md->wq). in __dm_suspend()
2735 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in __dm_suspend()
2737 synchronize_srcu(&md->io_barrier); in __dm_suspend()
2740 * Stop md->queue before flushing md->wq in case request-based in __dm_suspend()
2741 * dm defers requests to md->wq from md->queue. in __dm_suspend()
2743 if (dm_request_based(md)) in __dm_suspend()
2744 dm_stop_queue(md->queue); in __dm_suspend()
2746 flush_workqueue(md->wq); in __dm_suspend()
2753 r = dm_wait_for_completion(md, task_state); in __dm_suspend()
2755 set_bit(dmf_suspended_flag, &md->flags); in __dm_suspend()
2758 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); in __dm_suspend()
2760 synchronize_srcu(&md->io_barrier); in __dm_suspend()
2764 dm_queue_flush(md); in __dm_suspend()
2766 if (dm_request_based(md)) in __dm_suspend()
2767 dm_start_queue(md->queue); in __dm_suspend()
2769 unlock_fs(md); in __dm_suspend()
2793 int dm_suspend(struct mapped_device *md, unsigned int suspend_flags) in dm_suspend() argument
2799 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING); in dm_suspend()
2801 if (dm_suspended_md(md)) { in dm_suspend()
2806 if (dm_suspended_internally_md(md)) { in dm_suspend()
2808 mutex_unlock(&md->suspend_lock); in dm_suspend()
2809 r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE); in dm_suspend()
2815 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in dm_suspend()
2821 r = __dm_suspend(md, map, suspend_flags, TASK_INTERRUPTIBLE, DMF_SUSPENDED); in dm_suspend()
2825 set_bit(DMF_POST_SUSPENDING, &md->flags); in dm_suspend()
2827 clear_bit(DMF_POST_SUSPENDING, &md->flags); in dm_suspend()
2830 mutex_unlock(&md->suspend_lock); in dm_suspend()
2834 static int __dm_resume(struct mapped_device *md, struct dm_table *map) in __dm_resume() argument
2843 dm_queue_flush(md); in __dm_resume()
2850 if (dm_request_based(md)) in __dm_resume()
2851 dm_start_queue(md->queue); in __dm_resume()
2853 unlock_fs(md); in __dm_resume()
2858 int dm_resume(struct mapped_device *md) in dm_resume() argument
2865 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING); in dm_resume()
2867 if (!dm_suspended_md(md)) in dm_resume()
2870 if (dm_suspended_internally_md(md)) { in dm_resume()
2872 mutex_unlock(&md->suspend_lock); in dm_resume()
2873 r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE); in dm_resume()
2879 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in dm_resume()
2883 r = __dm_resume(md, map); in dm_resume()
2887 clear_bit(DMF_SUSPENDED, &md->flags); in dm_resume()
2889 mutex_unlock(&md->suspend_lock); in dm_resume()
2900 static void __dm_internal_suspend(struct mapped_device *md, unsigned int suspend_flags) in __dm_internal_suspend() argument
2904 lockdep_assert_held(&md->suspend_lock); in __dm_internal_suspend()
2906 if (md->internal_suspend_count++) in __dm_internal_suspend()
2909 if (dm_suspended_md(md)) { in __dm_internal_suspend()
2910 set_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in __dm_internal_suspend()
2914 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __dm_internal_suspend()
2922 (void) __dm_suspend(md, map, suspend_flags, TASK_UNINTERRUPTIBLE, in __dm_internal_suspend()
2925 set_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_internal_suspend()
2927 clear_bit(DMF_POST_SUSPENDING, &md->flags); in __dm_internal_suspend()
2930 static void __dm_internal_resume(struct mapped_device *md) in __dm_internal_resume() argument
2935 BUG_ON(!md->internal_suspend_count); in __dm_internal_resume()
2937 if (--md->internal_suspend_count) in __dm_internal_resume()
2940 if (dm_suspended_md(md)) in __dm_internal_resume()
2943 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); in __dm_internal_resume()
2944 r = __dm_resume(md, map); in __dm_internal_resume()
2958 set_bit(DMF_SUSPENDED, &md->flags); in __dm_internal_resume()
2961 clear_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in __dm_internal_resume()
2963 wake_up_bit(&md->flags, DMF_SUSPENDED_INTERNALLY); in __dm_internal_resume()
2966 void dm_internal_suspend_noflush(struct mapped_device *md) in dm_internal_suspend_noflush() argument
2968 mutex_lock(&md->suspend_lock); in dm_internal_suspend_noflush()
2969 __dm_internal_suspend(md, DM_SUSPEND_NOFLUSH_FLAG); in dm_internal_suspend_noflush()
2970 mutex_unlock(&md->suspend_lock); in dm_internal_suspend_noflush()
2974 void dm_internal_resume(struct mapped_device *md) in dm_internal_resume() argument
2976 mutex_lock(&md->suspend_lock); in dm_internal_resume()
2977 __dm_internal_resume(md); in dm_internal_resume()
2978 mutex_unlock(&md->suspend_lock); in dm_internal_resume()
2983 * Fast variants of internal suspend/resume hold md->suspend_lock,
2987 void dm_internal_suspend_fast(struct mapped_device *md) in dm_internal_suspend_fast() argument
2989 mutex_lock(&md->suspend_lock); in dm_internal_suspend_fast()
2990 if (dm_suspended_md(md) || dm_suspended_internally_md(md)) in dm_internal_suspend_fast()
2993 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); in dm_internal_suspend_fast()
2994 synchronize_srcu(&md->io_barrier); in dm_internal_suspend_fast()
2995 flush_workqueue(md->wq); in dm_internal_suspend_fast()
2996 dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); in dm_internal_suspend_fast()
3000 void dm_internal_resume_fast(struct mapped_device *md) in dm_internal_resume_fast() argument
3002 if (dm_suspended_md(md) || dm_suspended_internally_md(md)) in dm_internal_resume_fast()
3005 dm_queue_flush(md); in dm_internal_resume_fast()
3008 mutex_unlock(&md->suspend_lock); in dm_internal_resume_fast()
3017 int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action, in dm_kobject_uevent() argument
3036 r = kobject_uevent_env(&disk_to_dev(md->disk)->kobj, action, envp); in dm_kobject_uevent()
3043 uint32_t dm_next_uevent_seq(struct mapped_device *md) in dm_next_uevent_seq() argument
3045 return atomic_add_return(1, &md->uevent_seq); in dm_next_uevent_seq()
3048 uint32_t dm_get_event_nr(struct mapped_device *md) in dm_get_event_nr() argument
3050 return atomic_read(&md->event_nr); in dm_get_event_nr()
3053 int dm_wait_event(struct mapped_device *md, int event_nr) in dm_wait_event() argument
3055 return wait_event_interruptible(md->eventq, in dm_wait_event()
3056 (event_nr != atomic_read(&md->event_nr))); in dm_wait_event()
3059 void dm_uevent_add(struct mapped_device *md, struct list_head *elist) in dm_uevent_add() argument
3063 spin_lock_irqsave(&md->uevent_lock, flags); in dm_uevent_add()
3064 list_add(elist, &md->uevent_list); in dm_uevent_add()
3065 spin_unlock_irqrestore(&md->uevent_lock, flags); in dm_uevent_add()
3070 * count on 'md'.
3072 struct gendisk *dm_disk(struct mapped_device *md) in dm_disk() argument
3074 return md->disk; in dm_disk()
3078 struct kobject *dm_kobject(struct mapped_device *md) in dm_kobject() argument
3080 return &md->kobj_holder.kobj; in dm_kobject()
3085 struct mapped_device *md; in dm_get_from_kobject() local
3087 md = container_of(kobj, struct mapped_device, kobj_holder.kobj); in dm_get_from_kobject()
3090 if (test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) { in dm_get_from_kobject()
3091 md = NULL; in dm_get_from_kobject()
3094 dm_get(md); in dm_get_from_kobject()
3098 return md; in dm_get_from_kobject()
3101 int dm_suspended_md(struct mapped_device *md) in dm_suspended_md() argument
3103 return test_bit(DMF_SUSPENDED, &md->flags); in dm_suspended_md()
3106 static int dm_post_suspending_md(struct mapped_device *md) in dm_post_suspending_md() argument
3108 return test_bit(DMF_POST_SUSPENDING, &md->flags); in dm_post_suspending_md()
3111 int dm_suspended_internally_md(struct mapped_device *md) in dm_suspended_internally_md() argument
3113 return test_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); in dm_suspended_internally_md()
3116 int dm_test_deferred_remove_flag(struct mapped_device *md) in dm_test_deferred_remove_flag() argument
3118 return test_bit(DMF_DEFERRED_REMOVE, &md->flags); in dm_test_deferred_remove_flag()
3123 return dm_suspended_md(ti->table->md); in dm_suspended()
3129 return dm_post_suspending_md(ti->table->md); in dm_post_suspending()
3135 return __noflush_suspending(ti->table->md); in dm_noflush_suspending()
3165 struct mapped_device *md = bdev->bd_disk->private_data; in dm_call_pr() local
3170 table = dm_get_live_table(md, &srcu_idx); in dm_call_pr()
3179 if (dm_suspended_md(md)) { in dm_call_pr()
3191 dm_put_live_table(md, srcu_idx); in dm_call_pr()
3374 struct mapped_device *md = bdev->bd_disk->private_data; in dm_pr_clear() local
3378 r = dm_prepare_ioctl(md, &srcu_idx, &bdev); in dm_pr_clear()
3388 dm_unprepare_ioctl(md, srcu_idx); in dm_pr_clear()