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 mutex_lock(&_minor_lock);
771 if (idr_find(&_minor_idr, minor)) {
776 r = idr_pre_get(&_minor_idr, GFP_KERNEL);
782 r = idr_get_new_above(&_minor_idr, MINOR_ALLOCED, minor, &m);
788 idr_remove(&_minor_idr, m);
794 mutex_unlock(&_minor_lock);
798 static int next_free_minor(struct mapped_device *md, unsigned int *minor)
803 mutex_lock(&_minor_lock);
805 r = idr_pre_get(&_minor_idr, GFP_KERNEL);
811 r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m);
816 if (m >= (1 << MINORBITS)) {
817 idr_remove(&_minor_idr, m);
825 mutex_unlock(&_minor_lock);
829 static struct block_device_operations dm_blk_dops;
832 * Allocate and initialise a blank device with a given minor.
834 static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
837 struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL);
841 DMWARN("unable to allocate device, out of memory.");
845 /* get a minor number for the dev */
846 r = persistent ? specific_minor(md, minor) : next_free_minor(md, &minor);
850 memset(md, 0, sizeof(*md));
851 init_rwsem(&md->io_lock);
852 init_MUTEX(&md->suspend_lock);
853 rwlock_init(&md->map_lock);
854 atomic_set(&md->holders, 1);
855 atomic_set(&md->event_nr, 0);
857 md->queue = blk_alloc_queue(GFP_KERNEL);
861 md->queue->queuedata = md;
862 md->queue->backing_dev_info.congested_fn = dm_any_congested;
863 md->queue->backing_dev_info.congested_data = md;
864 blk_queue_make_request(md->queue, dm_request);
865 blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
866 md->queue->unplug_fn = dm_unplug_all;
867 md->queue->issue_flush_fn = dm_flush_all;
869 md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache);
873 md->tio_pool = mempool_create_slab_pool(MIN_IOS, _tio_cache);
877 md->disk = alloc_disk(1);
881 md->disk->major = _major;
882 md->disk->first_minor = minor;
883 md->disk->fops = &dm_blk_dops;
884 md->disk->queue = md->queue;
885 md->disk->private_data = md;
886 sprintf(md->disk->disk_name, "dm-%d", minor);
888 format_dev_t(md->name, MKDEV(_major, minor));
890 atomic_set(&md->pending, 0);
891 init_waitqueue_head(&md->wait);
892 init_waitqueue_head(&md->eventq);
894 /* Populate the mapping, nobody knows we exist yet */
895 mutex_lock(&_minor_lock);
896 old_md = idr_replace(&_minor_idr, md, minor);
897 mutex_unlock(&_minor_lock);
899 BUG_ON(old_md != MINOR_ALLOCED);
904 mempool_destroy(md->tio_pool);
906 mempool_destroy(md->io_pool);
908 blk_cleanup_queue(md->queue);
915 static void free_dev(struct mapped_device *md)
917 unsigned int minor = md->disk->first_minor;
919 if (md->suspended_bdev) {
920 thaw_bdev(md->suspended_bdev, NULL);
921 bdput(md->suspended_bdev);
923 mempool_destroy(md->tio_pool);
924 mempool_destroy(md->io_pool);
925 del_gendisk(md->disk);
928 blk_cleanup_queue(md->queue);
933 * Bind a table to the device.
935 static void event_callback(void *context)
937 struct mapped_device *md = (struct mapped_device *) context;
939 atomic_inc(&md->event_nr);
940 wake_up(&md->eventq);
943 static void __set_size(struct mapped_device *md, sector_t size)
945 set_capacity(md->disk, size);
947 mutex_lock(&md->suspended_bdev->bd_inode->i_mutex);
948 i_size_write(md->suspended_bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
949 mutex_unlock(&md->suspended_bdev->bd_inode->i_mutex);
952 static int __bind(struct mapped_device *md, struct dm_table *t)
954 request_queue_t *q = md->queue;
957 size = dm_table_get_size(t);
960 * Wipe any geometry if the size of the table changed.
962 if (size != get_capacity(md->disk))
963 memset(&md->geometry, 0, sizeof(md->geometry));
965 __set_size(md, size);
970 dm_table_event_callback(t, event_callback, md);
972 write_lock(&md->map_lock);
974 dm_table_set_restrictions(t, q);
975 write_unlock(&md->map_lock);
980 static void __unbind(struct mapped_device *md)
982 struct dm_table *map = md->map;
987 dm_table_event_callback(map, NULL, NULL);
988 write_lock(&md->map_lock);
990 write_unlock(&md->map_lock);
995 * Constructor for a new device.
997 static int create_aux(unsigned int minor, int persistent,
998 struct mapped_device **result)
1000 struct mapped_device *md;
1002 md = alloc_dev(minor, persistent);
1010 int dm_create(struct mapped_device **result)
1012 return create_aux(0, 0, result);
1015 int dm_create_with_minor(unsigned int minor, struct mapped_device **result)
1017 return create_aux(minor, 1, result);
1020 static struct mapped_device *dm_find_md(dev_t dev)
1022 struct mapped_device *md;
1023 unsigned minor = MINOR(dev);
1025 if (MAJOR(dev) != _major || minor >= (1 << MINORBITS))
1028 mutex_lock(&_minor_lock);
1030 md = idr_find(&_minor_idr, minor);
1031 if (md && (md == MINOR_ALLOCED || (dm_disk(md)->first_minor != minor)))
1034 mutex_unlock(&_minor_lock);
1039 struct mapped_device *dm_get_md(dev_t dev)
1041 struct mapped_device *md = dm_find_md(dev);
1049 void *dm_get_mdptr(struct mapped_device *md)
1051 return md->interface_ptr;
1054 void dm_set_mdptr(struct mapped_device *md, void *ptr)
1056 md->interface_ptr = ptr;
1059 void dm_get(struct mapped_device *md)
1061 atomic_inc(&md->holders);
1064 void dm_put(struct mapped_device *md)
1066 struct dm_table *map;
1068 if (atomic_dec_and_test(&md->holders)) {
1069 map = dm_get_table(md);
1070 mutex_lock(&_minor_lock);
1071 idr_replace(&_minor_idr, MINOR_ALLOCED, dm_disk(md)->first_minor);
1072 mutex_unlock(&_minor_lock);
1073 if (!dm_suspended(md)) {
1074 dm_table_presuspend_targets(map);
1075 dm_table_postsuspend_targets(map);
1084 * Process the deferred bios
1086 static void __flush_deferred_io(struct mapped_device *md, struct bio *c)
1099 * Swap in a new table (destroying old one).
1101 int dm_swap_table(struct mapped_device *md, struct dm_table *table)
1105 down(&md->suspend_lock);
1107 /* device must be suspended */
1108 if (!dm_suspended(md))
1112 r = __bind(md, table);
1115 up(&md->suspend_lock);
1120 * Functions to lock and unlock any filesystem running on the
1123 static int lock_fs(struct mapped_device *md)
1127 WARN_ON(md->frozen_sb);
1129 md->frozen_sb = freeze_bdev(md->suspended_bdev);
1130 if (IS_ERR(md->frozen_sb)) {
1131 r = PTR_ERR(md->frozen_sb);
1132 md->frozen_sb = NULL;
1136 set_bit(DMF_FROZEN, &md->flags);
1138 /* don't bdput right now, we don't want the bdev
1139 * to go away while it is locked.
1144 static void unlock_fs(struct mapped_device *md)
1146 if (!test_bit(DMF_FROZEN, &md->flags))
1149 thaw_bdev(md->suspended_bdev, md->frozen_sb);
1150 md->frozen_sb = NULL;
1151 clear_bit(DMF_FROZEN, &md->flags);
1155 * We need to be able to change a mapping table under a mounted
1156 * filesystem. For example we might want to move some data in
1157 * the background. Before the table can be swapped with
1158 * dm_bind_table, dm_suspend must be called to flush any in
1159 * flight bios and ensure that any further io gets deferred.
1161 int dm_suspend(struct mapped_device *md, int do_lockfs)
1163 struct dm_table *map = NULL;
1164 DECLARE_WAITQUEUE(wait, current);
1168 down(&md->suspend_lock);
1170 if (dm_suspended(md))
1173 map = dm_get_table(md);
1175 /* This does not get reverted if there's an error later. */
1176 dm_table_presuspend_targets(map);
1178 md->suspended_bdev = bdget_disk(md->disk, 0);
1179 if (!md->suspended_bdev) {
1180 DMWARN("bdget failed in dm_suspend");
1185 /* Flush I/O to the device. */
1193 * First we set the BLOCK_IO flag so no more ios will be mapped.
1195 down_write(&md->io_lock);
1196 set_bit(DMF_BLOCK_IO, &md->flags);
1198 add_wait_queue(&md->wait, &wait);
1199 up_write(&md->io_lock);
1203 dm_table_unplug_all(map);
1206 * Then we wait for the already mapped ios to
1210 set_current_state(TASK_INTERRUPTIBLE);
1212 if (!atomic_read(&md->pending) || signal_pending(current))
1217 set_current_state(TASK_RUNNING);
1219 down_write(&md->io_lock);
1220 remove_wait_queue(&md->wait, &wait);
1222 /* were we interrupted ? */
1224 if (atomic_read(&md->pending)) {
1225 clear_bit(DMF_BLOCK_IO, &md->flags);
1226 def = bio_list_get(&md->deferred);
1227 __flush_deferred_io(md, def);
1228 up_write(&md->io_lock);
1232 up_write(&md->io_lock);
1234 dm_table_postsuspend_targets(map);
1236 set_bit(DMF_SUSPENDED, &md->flags);
1241 if (r && md->suspended_bdev) {
1242 bdput(md->suspended_bdev);
1243 md->suspended_bdev = NULL;
1247 up(&md->suspend_lock);
1251 int dm_resume(struct mapped_device *md)
1255 struct dm_table *map = NULL;
1257 down(&md->suspend_lock);
1258 if (!dm_suspended(md))
1261 map = dm_get_table(md);
1262 if (!map || !dm_table_get_size(map))
1265 dm_table_resume_targets(map);
1267 down_write(&md->io_lock);
1268 clear_bit(DMF_BLOCK_IO, &md->flags);
1270 def = bio_list_get(&md->deferred);
1271 __flush_deferred_io(md, def);
1272 up_write(&md->io_lock);
1276 bdput(md->suspended_bdev);
1277 md->suspended_bdev = NULL;
1279 clear_bit(DMF_SUSPENDED, &md->flags);
1281 dm_table_unplug_all(map);
1287 up(&md->suspend_lock);
1292 /*-----------------------------------------------------------------
1293 * Event notification.
1294 *---------------------------------------------------------------*/
1295 uint32_t dm_get_event_nr(struct mapped_device *md)
1297 return atomic_read(&md->event_nr);
1300 int dm_wait_event(struct mapped_device *md, int event_nr)
1302 return wait_event_interruptible(md->eventq,
1303 (event_nr != atomic_read(&md->event_nr)));
1307 * The gendisk is only valid as long as you have a reference
1310 struct gendisk *dm_disk(struct mapped_device *md)
1315 int dm_suspended(struct mapped_device *md)
1317 return test_bit(DMF_SUSPENDED, &md->flags);
1320 static struct block_device_operations dm_blk_dops = {
1321 .open = dm_blk_open,
1322 .release = dm_blk_close,
1323 .getgeo = dm_blk_getgeo,
1324 .owner = THIS_MODULE
1327 EXPORT_SYMBOL(dm_get_mapinfo);
1332 module_init(dm_init);
1333 module_exit(dm_exit);
1335 module_param(major, uint, 0);
1336 MODULE_PARM_DESC(major, "The major number of the device mapper");
1337 MODULE_DESCRIPTION(DM_NAME " driver");
1338 MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
1339 MODULE_LICENSE("GPL");