2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
5 * This file is released under the GPL.
9 #include "dm-bio-list.h"
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/mutex.h>
14 #include <linux/moduleparam.h>
15 #include <linux/blkpg.h>
16 #include <linux/bio.h>
17 #include <linux/buffer_head.h>
18 #include <linux/mempool.h>
19 #include <linux/slab.h>
20 #include <linux/idr.h>
21 #include <linux/hdreg.h>
22 #include <linux/blktrace_api.h>
24 static const char *_name = DM_NAME;
26 static unsigned int major = 0;
27 static unsigned int _major = 0;
30 * One of these is allocated per bio.
33 struct mapped_device *md;
37 unsigned long start_time;
41 * One of these is allocated per target within a bio. Hopefully
42 * this will be simplified out one day.
50 union map_info *dm_get_mapinfo(struct bio *bio)
52 if (bio && bio->bi_private)
53 return &((struct target_io *)bio->bi_private)->info;
57 #define MINOR_ALLOCED ((void *)-1)
60 * Bits for the md->flags field.
62 #define DMF_BLOCK_IO 0
63 #define DMF_SUSPENDED 1
66 struct mapped_device {
67 struct rw_semaphore io_lock;
68 struct semaphore suspend_lock;
74 request_queue_t *queue;
81 * A list of ios that arrived while we were suspended.
84 wait_queue_head_t wait;
85 struct bio_list deferred;
88 * The current mapping.
93 * io objects are allocated from here.
102 wait_queue_head_t eventq;
105 * freeze/thaw support require holding onto a super block
107 struct super_block *frozen_sb;
108 struct block_device *suspended_bdev;
110 /* forced geometry settings */
111 struct hd_geometry geometry;
115 static kmem_cache_t *_io_cache;
116 static kmem_cache_t *_tio_cache;
118 static struct bio_set *dm_set;
120 static int __init local_init(void)
124 dm_set = bioset_create(16, 16, 4);
128 /* allocate a slab for the dm_ios */
129 _io_cache = kmem_cache_create("dm_io",
130 sizeof(struct dm_io), 0, 0, NULL, NULL);
134 /* allocate a slab for the target ios */
135 _tio_cache = kmem_cache_create("dm_tio", sizeof(struct target_io),
138 kmem_cache_destroy(_io_cache);
143 r = register_blkdev(_major, _name);
145 kmem_cache_destroy(_tio_cache);
146 kmem_cache_destroy(_io_cache);
156 static void local_exit(void)
158 kmem_cache_destroy(_tio_cache);
159 kmem_cache_destroy(_io_cache);
163 if (unregister_blkdev(_major, _name) < 0)
164 DMERR("devfs_unregister_blkdev failed");
168 DMINFO("cleaned up");
171 int (*_inits[])(void) __initdata = {
179 void (*_exits[])(void) = {
187 static int __init dm_init(void)
189 const int count = ARRAY_SIZE(_inits);
193 for (i = 0; i < count; i++) {
208 static void __exit dm_exit(void)
210 int i = ARRAY_SIZE(_exits);
217 * Block device functions
219 static int dm_blk_open(struct inode *inode, struct file *file)
221 struct mapped_device *md;
223 md = inode->i_bdev->bd_disk->private_data;
228 static int dm_blk_close(struct inode *inode, struct file *file)
230 struct mapped_device *md;
232 md = inode->i_bdev->bd_disk->private_data;
237 static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
239 struct mapped_device *md = bdev->bd_disk->private_data;
241 return dm_get_geometry(md, geo);
244 static inline struct dm_io *alloc_io(struct mapped_device *md)
246 return mempool_alloc(md->io_pool, GFP_NOIO);
249 static inline void free_io(struct mapped_device *md, struct dm_io *io)
251 mempool_free(io, md->io_pool);
254 static inline struct target_io *alloc_tio(struct mapped_device *md)
256 return mempool_alloc(md->tio_pool, GFP_NOIO);
259 static inline void free_tio(struct mapped_device *md, struct target_io *tio)
261 mempool_free(tio, md->tio_pool);
264 static void start_io_acct(struct dm_io *io)
266 struct mapped_device *md = io->md;
268 io->start_time = jiffies;
271 disk_round_stats(dm_disk(md));
273 dm_disk(md)->in_flight = atomic_inc_return(&md->pending);
276 static int end_io_acct(struct dm_io *io)
278 struct mapped_device *md = io->md;
279 struct bio *bio = io->bio;
280 unsigned long duration = jiffies - io->start_time;
282 int rw = bio_data_dir(bio);
285 disk_round_stats(dm_disk(md));
287 dm_disk(md)->in_flight = pending = atomic_dec_return(&md->pending);
289 disk_stat_add(dm_disk(md), ticks[rw], duration);
295 * Add the bio to the list of deferred io.
297 static int queue_io(struct mapped_device *md, struct bio *bio)
299 down_write(&md->io_lock);
301 if (!test_bit(DMF_BLOCK_IO, &md->flags)) {
302 up_write(&md->io_lock);
306 bio_list_add(&md->deferred, bio);
308 up_write(&md->io_lock);
309 return 0; /* deferred successfully */
313 * Everyone (including functions in this file), should use this
314 * function to access the md->map field, and make sure they call
315 * dm_table_put() when finished.
317 struct dm_table *dm_get_table(struct mapped_device *md)
321 read_lock(&md->map_lock);
325 read_unlock(&md->map_lock);
331 * Get the geometry associated with a dm device
333 int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo)
341 * Set the geometry of a device.
343 int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo)
345 sector_t sz = (sector_t)geo->cylinders * geo->heads * geo->sectors;
347 if (geo->start > sz) {
348 DMWARN("Start sector is beyond the geometry limits.");
357 /*-----------------------------------------------------------------
359 * A more elegant soln is in the works that uses the queue
360 * merge fn, unfortunately there are a couple of changes to
361 * the block layer that I want to make for this. So in the
362 * interests of getting something for people to use I give
363 * you this clearly demarcated crap.
364 *---------------------------------------------------------------*/
367 * Decrements the number of outstanding ios that a bio has been
368 * cloned into, completing the original io if necc.
370 static void dec_pending(struct dm_io *io, int error)
375 if (atomic_dec_and_test(&io->io_count)) {
377 /* nudge anyone waiting on suspend queue */
378 wake_up(&io->md->wait);
380 blk_add_trace_bio(io->md->queue, io->bio, BLK_TA_COMPLETE);
382 bio_endio(io->bio, io->bio->bi_size, io->error);
387 static int clone_endio(struct bio *bio, unsigned int done, int error)
390 struct target_io *tio = bio->bi_private;
391 struct dm_io *io = tio->io;
392 dm_endio_fn endio = tio->ti->type->end_io;
397 if (!bio_flagged(bio, BIO_UPTODATE) && !error)
401 r = endio(tio->ti, bio, error, &tio->info);
406 /* the target wants another shot at the io */
410 free_tio(io->md, tio);
411 dec_pending(io, error);
416 static sector_t max_io_len(struct mapped_device *md,
417 sector_t sector, struct dm_target *ti)
419 sector_t offset = sector - ti->begin;
420 sector_t len = ti->len - offset;
423 * Does the target need to split even further ?
427 boundary = ((offset + ti->split_io) & ~(ti->split_io - 1))
436 static void __map_bio(struct dm_target *ti, struct bio *clone,
437 struct target_io *tio)
445 BUG_ON(!clone->bi_size);
447 clone->bi_end_io = clone_endio;
448 clone->bi_private = tio;
451 * Map the clone. If r == 0 we don't need to do
452 * anything, the target has assumed ownership of
455 atomic_inc(&tio->io->io_count);
456 sector = clone->bi_sector;
457 r = ti->type->map(ti, clone, &tio->info);
459 /* the bio has been remapped so dispatch it */
461 blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone,
462 tio->io->bio->bi_bdev->bd_dev, sector,
465 generic_make_request(clone);
469 /* error the io and bail out */
470 struct dm_io *io = tio->io;
471 free_tio(tio->io->md, tio);
478 struct mapped_device *md;
479 struct dm_table *map;
483 sector_t sector_count;
487 static void dm_bio_destructor(struct bio *bio)
489 bio_free(bio, dm_set);
493 * Creates a little bio that is just does part of a bvec.
495 static struct bio *split_bvec(struct bio *bio, sector_t sector,
496 unsigned short idx, unsigned int offset,
500 struct bio_vec *bv = bio->bi_io_vec + idx;
502 clone = bio_alloc_bioset(GFP_NOIO, 1, dm_set);
503 clone->bi_destructor = dm_bio_destructor;
504 *clone->bi_io_vec = *bv;
506 clone->bi_sector = sector;
507 clone->bi_bdev = bio->bi_bdev;
508 clone->bi_rw = bio->bi_rw;
510 clone->bi_size = to_bytes(len);
511 clone->bi_io_vec->bv_offset = offset;
512 clone->bi_io_vec->bv_len = clone->bi_size;
518 * Creates a bio that consists of range of complete bvecs.
520 static struct bio *clone_bio(struct bio *bio, sector_t sector,
521 unsigned short idx, unsigned short bv_count,
526 clone = bio_clone(bio, GFP_NOIO);
527 clone->bi_sector = sector;
529 clone->bi_vcnt = idx + bv_count;
530 clone->bi_size = to_bytes(len);
531 clone->bi_flags &= ~(1 << BIO_SEG_VALID);
536 static void __clone_and_map(struct clone_info *ci)
538 struct bio *clone, *bio = ci->bio;
539 struct dm_target *ti = dm_table_find_target(ci->map, ci->sector);
540 sector_t len = 0, max = max_io_len(ci->md, ci->sector, ti);
541 struct target_io *tio;
544 * Allocate a target io object.
546 tio = alloc_tio(ci->md);
549 memset(&tio->info, 0, sizeof(tio->info));
551 if (ci->sector_count <= max) {
553 * Optimise for the simple case where we can do all of
554 * the remaining io with a single clone.
556 clone = clone_bio(bio, ci->sector, ci->idx,
557 bio->bi_vcnt - ci->idx, ci->sector_count);
558 __map_bio(ti, clone, tio);
559 ci->sector_count = 0;
561 } else if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) {
563 * There are some bvecs that don't span targets.
564 * Do as many of these as possible.
567 sector_t remaining = max;
570 for (i = ci->idx; remaining && (i < bio->bi_vcnt); i++) {
571 bv_len = to_sector(bio->bi_io_vec[i].bv_len);
573 if (bv_len > remaining)
580 clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len);
581 __map_bio(ti, clone, tio);
584 ci->sector_count -= len;
589 * Handle a bvec that must be split between two or more targets.
591 struct bio_vec *bv = bio->bi_io_vec + ci->idx;
592 sector_t remaining = to_sector(bv->bv_len);
593 unsigned int offset = 0;
597 ti = dm_table_find_target(ci->map, ci->sector);
598 max = max_io_len(ci->md, ci->sector, ti);
600 tio = alloc_tio(ci->md);
603 memset(&tio->info, 0, sizeof(tio->info));
606 len = min(remaining, max);
608 clone = split_bvec(bio, ci->sector, ci->idx,
609 bv->bv_offset + offset, len);
611 __map_bio(ti, clone, tio);
614 ci->sector_count -= len;
615 offset += to_bytes(len);
616 } while (remaining -= len);
623 * Split the bio into several clones.
625 static void __split_bio(struct mapped_device *md, struct bio *bio)
627 struct clone_info ci;
629 ci.map = dm_get_table(md);
631 bio_io_error(bio, bio->bi_size);
637 ci.io = alloc_io(md);
639 atomic_set(&ci.io->io_count, 1);
642 ci.sector = bio->bi_sector;
643 ci.sector_count = bio_sectors(bio);
644 ci.idx = bio->bi_idx;
646 start_io_acct(ci.io);
647 while (ci.sector_count)
648 __clone_and_map(&ci);
650 /* drop the extra reference count */
651 dec_pending(ci.io, 0);
652 dm_table_put(ci.map);
654 /*-----------------------------------------------------------------
656 *---------------------------------------------------------------*/
659 * The request function that just remaps the bio built up by
662 static int dm_request(request_queue_t *q, struct bio *bio)
665 int rw = bio_data_dir(bio);
666 struct mapped_device *md = q->queuedata;
668 down_read(&md->io_lock);
670 disk_stat_inc(dm_disk(md), ios[rw]);
671 disk_stat_add(dm_disk(md), sectors[rw], bio_sectors(bio));
674 * If we're suspended we have to queue
677 while (test_bit(DMF_BLOCK_IO, &md->flags)) {
678 up_read(&md->io_lock);
680 if (bio_rw(bio) == READA) {
681 bio_io_error(bio, bio->bi_size);
685 r = queue_io(md, bio);
687 bio_io_error(bio, bio->bi_size);
691 return 0; /* deferred successfully */
694 * We're in a while loop, because someone could suspend
695 * before we get to the following read lock.
697 down_read(&md->io_lock);
700 __split_bio(md, bio);
701 up_read(&md->io_lock);
705 static int dm_flush_all(request_queue_t *q, struct gendisk *disk,
706 sector_t *error_sector)
708 struct mapped_device *md = q->queuedata;
709 struct dm_table *map = dm_get_table(md);
713 ret = dm_table_flush_all(map);
720 static void dm_unplug_all(request_queue_t *q)
722 struct mapped_device *md = q->queuedata;
723 struct dm_table *map = dm_get_table(md);
726 dm_table_unplug_all(map);
731 static int dm_any_congested(void *congested_data, int bdi_bits)
734 struct mapped_device *md = (struct mapped_device *) congested_data;
735 struct dm_table *map = dm_get_table(md);
737 if (!map || test_bit(DMF_BLOCK_IO, &md->flags))
740 r = dm_table_any_congested(map, bdi_bits);
746 /*-----------------------------------------------------------------
747 * An IDR is used to keep track of allocated minor numbers.
748 *---------------------------------------------------------------*/
749 static DEFINE_MUTEX(_minor_lock);
750 static DEFINE_IDR(_minor_idr);
752 static void free_minor(unsigned int minor)
754 mutex_lock(&_minor_lock);
755 idr_remove(&_minor_idr, minor);
756 mutex_unlock(&_minor_lock);
760 * See if the device with a specific minor # is free.
762 static int specific_minor(struct mapped_device *md, unsigned int minor)
766 if (minor >= (1 << MINORBITS))
769 r = idr_pre_get(&_minor_idr, GFP_KERNEL);
773 mutex_lock(&_minor_lock);
775 if (idr_find(&_minor_idr, minor)) {
780 r = idr_get_new_above(&_minor_idr, MINOR_ALLOCED, minor, &m);
785 idr_remove(&_minor_idr, m);
791 mutex_unlock(&_minor_lock);
795 static int next_free_minor(struct mapped_device *md, unsigned int *minor)
800 r = idr_pre_get(&_minor_idr, GFP_KERNEL);
804 mutex_lock(&_minor_lock);
806 r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m);
811 if (m >= (1 << MINORBITS)) {
812 idr_remove(&_minor_idr, m);
820 mutex_unlock(&_minor_lock);
824 static struct block_device_operations dm_blk_dops;
827 * Allocate and initialise a blank device with a given minor.
829 static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
832 struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL);
836 DMWARN("unable to allocate device, out of memory.");
840 /* get a minor number for the dev */
841 r = persistent ? specific_minor(md, minor) : next_free_minor(md, &minor);
845 memset(md, 0, sizeof(*md));
846 init_rwsem(&md->io_lock);
847 init_MUTEX(&md->suspend_lock);
848 rwlock_init(&md->map_lock);
849 atomic_set(&md->holders, 1);
850 atomic_set(&md->event_nr, 0);
852 md->queue = blk_alloc_queue(GFP_KERNEL);
856 md->queue->queuedata = md;
857 md->queue->backing_dev_info.congested_fn = dm_any_congested;
858 md->queue->backing_dev_info.congested_data = md;
859 blk_queue_make_request(md->queue, dm_request);
860 blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
861 md->queue->unplug_fn = dm_unplug_all;
862 md->queue->issue_flush_fn = dm_flush_all;
864 md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache);
868 md->tio_pool = mempool_create_slab_pool(MIN_IOS, _tio_cache);
872 md->disk = alloc_disk(1);
876 md->disk->major = _major;
877 md->disk->first_minor = minor;
878 md->disk->fops = &dm_blk_dops;
879 md->disk->queue = md->queue;
880 md->disk->private_data = md;
881 sprintf(md->disk->disk_name, "dm-%d", minor);
883 format_dev_t(md->name, MKDEV(_major, minor));
885 atomic_set(&md->pending, 0);
886 init_waitqueue_head(&md->wait);
887 init_waitqueue_head(&md->eventq);
889 /* Populate the mapping, nobody knows we exist yet */
890 mutex_lock(&_minor_lock);
891 old_md = idr_replace(&_minor_idr, md, minor);
892 mutex_unlock(&_minor_lock);
894 BUG_ON(old_md != MINOR_ALLOCED);
899 mempool_destroy(md->tio_pool);
901 mempool_destroy(md->io_pool);
903 blk_cleanup_queue(md->queue);
910 static void free_dev(struct mapped_device *md)
912 unsigned int minor = md->disk->first_minor;
914 if (md->suspended_bdev) {
915 thaw_bdev(md->suspended_bdev, NULL);
916 bdput(md->suspended_bdev);
918 mempool_destroy(md->tio_pool);
919 mempool_destroy(md->io_pool);
920 del_gendisk(md->disk);
923 blk_cleanup_queue(md->queue);
928 * Bind a table to the device.
930 static void event_callback(void *context)
932 struct mapped_device *md = (struct mapped_device *) context;
934 atomic_inc(&md->event_nr);
935 wake_up(&md->eventq);
938 static void __set_size(struct mapped_device *md, sector_t size)
940 set_capacity(md->disk, size);
942 mutex_lock(&md->suspended_bdev->bd_inode->i_mutex);
943 i_size_write(md->suspended_bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
944 mutex_unlock(&md->suspended_bdev->bd_inode->i_mutex);
947 static int __bind(struct mapped_device *md, struct dm_table *t)
949 request_queue_t *q = md->queue;
952 size = dm_table_get_size(t);
955 * Wipe any geometry if the size of the table changed.
957 if (size != get_capacity(md->disk))
958 memset(&md->geometry, 0, sizeof(md->geometry));
960 __set_size(md, size);
965 dm_table_event_callback(t, event_callback, md);
967 write_lock(&md->map_lock);
969 dm_table_set_restrictions(t, q);
970 write_unlock(&md->map_lock);
975 static void __unbind(struct mapped_device *md)
977 struct dm_table *map = md->map;
982 dm_table_event_callback(map, NULL, NULL);
983 write_lock(&md->map_lock);
985 write_unlock(&md->map_lock);
990 * Constructor for a new device.
992 static int create_aux(unsigned int minor, int persistent,
993 struct mapped_device **result)
995 struct mapped_device *md;
997 md = alloc_dev(minor, persistent);
1005 int dm_create(struct mapped_device **result)
1007 return create_aux(0, 0, result);
1010 int dm_create_with_minor(unsigned int minor, struct mapped_device **result)
1012 return create_aux(minor, 1, result);
1015 static struct mapped_device *dm_find_md(dev_t dev)
1017 struct mapped_device *md;
1018 unsigned minor = MINOR(dev);
1020 if (MAJOR(dev) != _major || minor >= (1 << MINORBITS))
1023 mutex_lock(&_minor_lock);
1025 md = idr_find(&_minor_idr, minor);
1026 if (md && (md == MINOR_ALLOCED || (dm_disk(md)->first_minor != minor)))
1029 mutex_unlock(&_minor_lock);
1034 struct mapped_device *dm_get_md(dev_t dev)
1036 struct mapped_device *md = dm_find_md(dev);
1044 void *dm_get_mdptr(struct mapped_device *md)
1046 return md->interface_ptr;
1049 void dm_set_mdptr(struct mapped_device *md, void *ptr)
1051 md->interface_ptr = ptr;
1054 void dm_get(struct mapped_device *md)
1056 atomic_inc(&md->holders);
1059 void dm_put(struct mapped_device *md)
1061 struct dm_table *map;
1063 if (atomic_dec_and_test(&md->holders)) {
1064 map = dm_get_table(md);
1065 mutex_lock(&_minor_lock);
1066 idr_replace(&_minor_idr, MINOR_ALLOCED, dm_disk(md)->first_minor);
1067 mutex_unlock(&_minor_lock);
1068 if (!dm_suspended(md)) {
1069 dm_table_presuspend_targets(map);
1070 dm_table_postsuspend_targets(map);
1079 * Process the deferred bios
1081 static void __flush_deferred_io(struct mapped_device *md, struct bio *c)
1094 * Swap in a new table (destroying old one).
1096 int dm_swap_table(struct mapped_device *md, struct dm_table *table)
1100 down(&md->suspend_lock);
1102 /* device must be suspended */
1103 if (!dm_suspended(md))
1107 r = __bind(md, table);
1110 up(&md->suspend_lock);
1115 * Functions to lock and unlock any filesystem running on the
1118 static int lock_fs(struct mapped_device *md)
1122 WARN_ON(md->frozen_sb);
1124 md->frozen_sb = freeze_bdev(md->suspended_bdev);
1125 if (IS_ERR(md->frozen_sb)) {
1126 r = PTR_ERR(md->frozen_sb);
1127 md->frozen_sb = NULL;
1131 set_bit(DMF_FROZEN, &md->flags);
1133 /* don't bdput right now, we don't want the bdev
1134 * to go away while it is locked.
1139 static void unlock_fs(struct mapped_device *md)
1141 if (!test_bit(DMF_FROZEN, &md->flags))
1144 thaw_bdev(md->suspended_bdev, md->frozen_sb);
1145 md->frozen_sb = NULL;
1146 clear_bit(DMF_FROZEN, &md->flags);
1150 * We need to be able to change a mapping table under a mounted
1151 * filesystem. For example we might want to move some data in
1152 * the background. Before the table can be swapped with
1153 * dm_bind_table, dm_suspend must be called to flush any in
1154 * flight bios and ensure that any further io gets deferred.
1156 int dm_suspend(struct mapped_device *md, int do_lockfs)
1158 struct dm_table *map = NULL;
1159 DECLARE_WAITQUEUE(wait, current);
1163 down(&md->suspend_lock);
1165 if (dm_suspended(md))
1168 map = dm_get_table(md);
1170 /* This does not get reverted if there's an error later. */
1171 dm_table_presuspend_targets(map);
1173 md->suspended_bdev = bdget_disk(md->disk, 0);
1174 if (!md->suspended_bdev) {
1175 DMWARN("bdget failed in dm_suspend");
1180 /* Flush I/O to the device. */
1188 * First we set the BLOCK_IO flag so no more ios will be mapped.
1190 down_write(&md->io_lock);
1191 set_bit(DMF_BLOCK_IO, &md->flags);
1193 add_wait_queue(&md->wait, &wait);
1194 up_write(&md->io_lock);
1198 dm_table_unplug_all(map);
1201 * Then we wait for the already mapped ios to
1205 set_current_state(TASK_INTERRUPTIBLE);
1207 if (!atomic_read(&md->pending) || signal_pending(current))
1212 set_current_state(TASK_RUNNING);
1214 down_write(&md->io_lock);
1215 remove_wait_queue(&md->wait, &wait);
1217 /* were we interrupted ? */
1219 if (atomic_read(&md->pending)) {
1220 clear_bit(DMF_BLOCK_IO, &md->flags);
1221 def = bio_list_get(&md->deferred);
1222 __flush_deferred_io(md, def);
1223 up_write(&md->io_lock);
1227 up_write(&md->io_lock);
1229 dm_table_postsuspend_targets(map);
1231 set_bit(DMF_SUSPENDED, &md->flags);
1236 if (r && md->suspended_bdev) {
1237 bdput(md->suspended_bdev);
1238 md->suspended_bdev = NULL;
1242 up(&md->suspend_lock);
1246 int dm_resume(struct mapped_device *md)
1250 struct dm_table *map = NULL;
1252 down(&md->suspend_lock);
1253 if (!dm_suspended(md))
1256 map = dm_get_table(md);
1257 if (!map || !dm_table_get_size(map))
1260 dm_table_resume_targets(map);
1262 down_write(&md->io_lock);
1263 clear_bit(DMF_BLOCK_IO, &md->flags);
1265 def = bio_list_get(&md->deferred);
1266 __flush_deferred_io(md, def);
1267 up_write(&md->io_lock);
1271 bdput(md->suspended_bdev);
1272 md->suspended_bdev = NULL;
1274 clear_bit(DMF_SUSPENDED, &md->flags);
1276 dm_table_unplug_all(map);
1282 up(&md->suspend_lock);
1287 /*-----------------------------------------------------------------
1288 * Event notification.
1289 *---------------------------------------------------------------*/
1290 uint32_t dm_get_event_nr(struct mapped_device *md)
1292 return atomic_read(&md->event_nr);
1295 int dm_wait_event(struct mapped_device *md, int event_nr)
1297 return wait_event_interruptible(md->eventq,
1298 (event_nr != atomic_read(&md->event_nr)));
1302 * The gendisk is only valid as long as you have a reference
1305 struct gendisk *dm_disk(struct mapped_device *md)
1310 int dm_suspended(struct mapped_device *md)
1312 return test_bit(DMF_SUSPENDED, &md->flags);
1315 static struct block_device_operations dm_blk_dops = {
1316 .open = dm_blk_open,
1317 .release = dm_blk_close,
1318 .getgeo = dm_blk_getgeo,
1319 .owner = THIS_MODULE
1322 EXPORT_SYMBOL(dm_get_mapinfo);
1327 module_init(dm_init);
1328 module_exit(dm_exit);
1330 module_param(major, uint, 0);
1331 MODULE_PARM_DESC(major, "The major number of the device mapper");
1332 MODULE_DESCRIPTION(DM_NAME " driver");
1333 MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
1334 MODULE_LICENSE("GPL");