diff options
Diffstat (limited to 'drivers/md/dm.c')
-rw-r--r-- | drivers/md/dm.c | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 73f28802dc7a..8001fe9e3434 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c | |||
@@ -433,7 +433,6 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode) | |||
433 | 433 | ||
434 | dm_get(md); | 434 | dm_get(md); |
435 | atomic_inc(&md->open_count); | 435 | atomic_inc(&md->open_count); |
436 | |||
437 | out: | 436 | out: |
438 | spin_unlock(&_minor_lock); | 437 | spin_unlock(&_minor_lock); |
439 | 438 | ||
@@ -442,16 +441,20 @@ out: | |||
442 | 441 | ||
443 | static void dm_blk_close(struct gendisk *disk, fmode_t mode) | 442 | static void dm_blk_close(struct gendisk *disk, fmode_t mode) |
444 | { | 443 | { |
445 | struct mapped_device *md = disk->private_data; | 444 | struct mapped_device *md; |
446 | 445 | ||
447 | spin_lock(&_minor_lock); | 446 | spin_lock(&_minor_lock); |
448 | 447 | ||
448 | md = disk->private_data; | ||
449 | if (WARN_ON(!md)) | ||
450 | goto out; | ||
451 | |||
449 | if (atomic_dec_and_test(&md->open_count) && | 452 | if (atomic_dec_and_test(&md->open_count) && |
450 | (test_bit(DMF_DEFERRED_REMOVE, &md->flags))) | 453 | (test_bit(DMF_DEFERRED_REMOVE, &md->flags))) |
451 | queue_work(deferred_remove_workqueue, &deferred_remove_work); | 454 | queue_work(deferred_remove_workqueue, &deferred_remove_work); |
452 | 455 | ||
453 | dm_put(md); | 456 | dm_put(md); |
454 | 457 | out: | |
455 | spin_unlock(&_minor_lock); | 458 | spin_unlock(&_minor_lock); |
456 | } | 459 | } |
457 | 460 | ||
@@ -2241,7 +2244,6 @@ static void free_dev(struct mapped_device *md) | |||
2241 | int minor = MINOR(disk_devt(md->disk)); | 2244 | int minor = MINOR(disk_devt(md->disk)); |
2242 | 2245 | ||
2243 | unlock_fs(md); | 2246 | unlock_fs(md); |
2244 | bdput(md->bdev); | ||
2245 | destroy_workqueue(md->wq); | 2247 | destroy_workqueue(md->wq); |
2246 | 2248 | ||
2247 | if (md->kworker_task) | 2249 | if (md->kworker_task) |
@@ -2252,19 +2254,22 @@ static void free_dev(struct mapped_device *md) | |||
2252 | mempool_destroy(md->rq_pool); | 2254 | mempool_destroy(md->rq_pool); |
2253 | if (md->bs) | 2255 | if (md->bs) |
2254 | bioset_free(md->bs); | 2256 | bioset_free(md->bs); |
2255 | blk_integrity_unregister(md->disk); | 2257 | |
2256 | del_gendisk(md->disk); | ||
2257 | cleanup_srcu_struct(&md->io_barrier); | 2258 | cleanup_srcu_struct(&md->io_barrier); |
2258 | free_table_devices(&md->table_devices); | 2259 | free_table_devices(&md->table_devices); |
2259 | free_minor(minor); | 2260 | dm_stats_cleanup(&md->stats); |
2260 | 2261 | ||
2261 | spin_lock(&_minor_lock); | 2262 | spin_lock(&_minor_lock); |
2262 | md->disk->private_data = NULL; | 2263 | md->disk->private_data = NULL; |
2263 | spin_unlock(&_minor_lock); | 2264 | spin_unlock(&_minor_lock); |
2264 | 2265 | if (blk_get_integrity(md->disk)) | |
2266 | blk_integrity_unregister(md->disk); | ||
2267 | del_gendisk(md->disk); | ||
2265 | put_disk(md->disk); | 2268 | put_disk(md->disk); |
2266 | blk_cleanup_queue(md->queue); | 2269 | blk_cleanup_queue(md->queue); |
2267 | dm_stats_cleanup(&md->stats); | 2270 | bdput(md->bdev); |
2271 | free_minor(minor); | ||
2272 | |||
2268 | module_put(THIS_MODULE); | 2273 | module_put(THIS_MODULE); |
2269 | kfree(md); | 2274 | kfree(md); |
2270 | } | 2275 | } |
@@ -2616,6 +2621,19 @@ void dm_get(struct mapped_device *md) | |||
2616 | BUG_ON(test_bit(DMF_FREEING, &md->flags)); | 2621 | BUG_ON(test_bit(DMF_FREEING, &md->flags)); |
2617 | } | 2622 | } |
2618 | 2623 | ||
2624 | int dm_hold(struct mapped_device *md) | ||
2625 | { | ||
2626 | spin_lock(&_minor_lock); | ||
2627 | if (test_bit(DMF_FREEING, &md->flags)) { | ||
2628 | spin_unlock(&_minor_lock); | ||
2629 | return -EBUSY; | ||
2630 | } | ||
2631 | dm_get(md); | ||
2632 | spin_unlock(&_minor_lock); | ||
2633 | return 0; | ||
2634 | } | ||
2635 | EXPORT_SYMBOL_GPL(dm_hold); | ||
2636 | |||
2619 | const char *dm_device_name(struct mapped_device *md) | 2637 | const char *dm_device_name(struct mapped_device *md) |
2620 | { | 2638 | { |
2621 | return md->name; | 2639 | return md->name; |
@@ -2629,8 +2647,9 @@ static void __dm_destroy(struct mapped_device *md, bool wait) | |||
2629 | 2647 | ||
2630 | might_sleep(); | 2648 | might_sleep(); |
2631 | 2649 | ||
2632 | spin_lock(&_minor_lock); | ||
2633 | map = dm_get_live_table(md, &srcu_idx); | 2650 | map = dm_get_live_table(md, &srcu_idx); |
2651 | |||
2652 | spin_lock(&_minor_lock); | ||
2634 | idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md)))); | 2653 | idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md)))); |
2635 | set_bit(DMF_FREEING, &md->flags); | 2654 | set_bit(DMF_FREEING, &md->flags); |
2636 | spin_unlock(&_minor_lock); | 2655 | spin_unlock(&_minor_lock); |
@@ -2638,10 +2657,16 @@ static void __dm_destroy(struct mapped_device *md, bool wait) | |||
2638 | if (dm_request_based(md)) | 2657 | if (dm_request_based(md)) |
2639 | flush_kthread_worker(&md->kworker); | 2658 | flush_kthread_worker(&md->kworker); |
2640 | 2659 | ||
2660 | /* | ||
2661 | * Take suspend_lock so that presuspend and postsuspend methods | ||
2662 | * do not race with internal suspend. | ||
2663 | */ | ||
2664 | mutex_lock(&md->suspend_lock); | ||
2641 | if (!dm_suspended_md(md)) { | 2665 | if (!dm_suspended_md(md)) { |
2642 | dm_table_presuspend_targets(map); | 2666 | dm_table_presuspend_targets(map); |
2643 | dm_table_postsuspend_targets(map); | 2667 | dm_table_postsuspend_targets(map); |
2644 | } | 2668 | } |
2669 | mutex_unlock(&md->suspend_lock); | ||
2645 | 2670 | ||
2646 | /* dm_put_live_table must be before msleep, otherwise deadlock is possible */ | 2671 | /* dm_put_live_table must be before msleep, otherwise deadlock is possible */ |
2647 | dm_put_live_table(md, srcu_idx); | 2672 | dm_put_live_table(md, srcu_idx); |
@@ -3115,6 +3140,7 @@ void dm_internal_suspend_fast(struct mapped_device *md) | |||
3115 | flush_workqueue(md->wq); | 3140 | flush_workqueue(md->wq); |
3116 | dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); | 3141 | dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); |
3117 | } | 3142 | } |
3143 | EXPORT_SYMBOL_GPL(dm_internal_suspend_fast); | ||
3118 | 3144 | ||
3119 | void dm_internal_resume_fast(struct mapped_device *md) | 3145 | void dm_internal_resume_fast(struct mapped_device *md) |
3120 | { | 3146 | { |
@@ -3126,6 +3152,7 @@ void dm_internal_resume_fast(struct mapped_device *md) | |||
3126 | done: | 3152 | done: |
3127 | mutex_unlock(&md->suspend_lock); | 3153 | mutex_unlock(&md->suspend_lock); |
3128 | } | 3154 | } |
3155 | EXPORT_SYMBOL_GPL(dm_internal_resume_fast); | ||
3129 | 3156 | ||
3130 | /*----------------------------------------------------------------- | 3157 | /*----------------------------------------------------------------- |
3131 | * Event notification. | 3158 | * Event notification. |