dm kcopyd: accept zero size jobs
[deliverable/linux.git] / drivers / md / dm.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
784aae73 3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
1da177e4
LT
4 *
5 * This file is released under the GPL.
6 */
7
8#include "dm.h"
51e5b2bd 9#include "dm-uevent.h"
1da177e4
LT
10
11#include <linux/init.h>
12#include <linux/module.h>
48c9c27b 13#include <linux/mutex.h>
1da177e4
LT
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>
3ac51e74 21#include <linux/hdreg.h>
55782138
LZ
22
23#include <trace/events/block.h>
1da177e4 24
72d94861
AK
25#define DM_MSG_PREFIX "core"
26
60935eb2
MB
27/*
28 * Cookies are numeric values sent with CHANGE and REMOVE
29 * uevents while resuming, removing or renaming the device.
30 */
31#define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE"
32#define DM_COOKIE_LENGTH 24
33
1da177e4
LT
34static const char *_name = DM_NAME;
35
36static unsigned int major = 0;
37static unsigned int _major = 0;
38
f32c10b0 39static DEFINE_SPINLOCK(_minor_lock);
1da177e4 40/*
8fbf26ad 41 * For bio-based dm.
1da177e4
LT
42 * One of these is allocated per bio.
43 */
44struct dm_io {
45 struct mapped_device *md;
46 int error;
1da177e4 47 atomic_t io_count;
6ae2fa67 48 struct bio *bio;
3eaf840e 49 unsigned long start_time;
f88fb981 50 spinlock_t endio_lock;
1da177e4
LT
51};
52
53/*
8fbf26ad 54 * For bio-based dm.
1da177e4
LT
55 * One of these is allocated per target within a bio. Hopefully
56 * this will be simplified out one day.
57 */
028867ac 58struct dm_target_io {
1da177e4
LT
59 struct dm_io *io;
60 struct dm_target *ti;
61 union map_info info;
62};
63
8fbf26ad
KU
64/*
65 * For request-based dm.
66 * One of these is allocated per request.
67 */
68struct dm_rq_target_io {
69 struct mapped_device *md;
70 struct dm_target *ti;
71 struct request *orig, clone;
72 int error;
73 union map_info info;
74};
75
76/*
77 * For request-based dm.
78 * One of these is allocated per bio.
79 */
80struct dm_rq_clone_bio_info {
81 struct bio *orig;
cec47e3d 82 struct dm_rq_target_io *tio;
8fbf26ad
KU
83};
84
1da177e4
LT
85union map_info *dm_get_mapinfo(struct bio *bio)
86{
17b2f66f 87 if (bio && bio->bi_private)
028867ac 88 return &((struct dm_target_io *)bio->bi_private)->info;
17b2f66f 89 return NULL;
1da177e4
LT
90}
91
cec47e3d
KU
92union map_info *dm_get_rq_mapinfo(struct request *rq)
93{
94 if (rq && rq->end_io_data)
95 return &((struct dm_rq_target_io *)rq->end_io_data)->info;
96 return NULL;
97}
98EXPORT_SYMBOL_GPL(dm_get_rq_mapinfo);
99
ba61fdd1
JM
100#define MINOR_ALLOCED ((void *)-1)
101
1da177e4
LT
102/*
103 * Bits for the md->flags field.
104 */
1eb787ec 105#define DMF_BLOCK_IO_FOR_SUSPEND 0
1da177e4 106#define DMF_SUSPENDED 1
aa8d7c2f 107#define DMF_FROZEN 2
fba9f90e 108#define DMF_FREEING 3
5c6bd75d 109#define DMF_DELETING 4
2e93ccc1 110#define DMF_NOFLUSH_SUSPENDING 5
1eb787ec 111#define DMF_QUEUE_IO_TO_THREAD 6
1da177e4 112
304f3f6a
MB
113/*
114 * Work processed by per-device workqueue.
115 */
1da177e4 116struct mapped_device {
2ca3310e 117 struct rw_semaphore io_lock;
e61290a4 118 struct mutex suspend_lock;
1da177e4
LT
119 rwlock_t map_lock;
120 atomic_t holders;
5c6bd75d 121 atomic_t open_count;
1da177e4
LT
122
123 unsigned long flags;
124
165125e1 125 struct request_queue *queue;
1da177e4 126 struct gendisk *disk;
7e51f257 127 char name[16];
1da177e4
LT
128
129 void *interface_ptr;
130
131 /*
132 * A list of ios that arrived while we were suspended.
133 */
316d315b 134 atomic_t pending[2];
1da177e4 135 wait_queue_head_t wait;
53d5914f 136 struct work_struct work;
74859364 137 struct bio_list deferred;
022c2611 138 spinlock_t deferred_lock;
1da177e4 139
af7e466a
MP
140 /*
141 * An error from the barrier request currently being processed.
142 */
143 int barrier_error;
144
304f3f6a
MB
145 /*
146 * Processing queue (flush/barriers)
147 */
148 struct workqueue_struct *wq;
149
1da177e4
LT
150 /*
151 * The current mapping.
152 */
153 struct dm_table *map;
154
155 /*
156 * io objects are allocated from here.
157 */
158 mempool_t *io_pool;
159 mempool_t *tio_pool;
160
9faf400f
SB
161 struct bio_set *bs;
162
1da177e4
LT
163 /*
164 * Event handling.
165 */
166 atomic_t event_nr;
167 wait_queue_head_t eventq;
7a8c3d3b
MA
168 atomic_t uevent_seq;
169 struct list_head uevent_list;
170 spinlock_t uevent_lock; /* Protect access to uevent_list */
1da177e4
LT
171
172 /*
173 * freeze/thaw support require holding onto a super block
174 */
175 struct super_block *frozen_sb;
db8fef4f 176 struct block_device *bdev;
3ac51e74
DW
177
178 /* forced geometry settings */
179 struct hd_geometry geometry;
784aae73 180
cec47e3d
KU
181 /* marker of flush suspend for request-based dm */
182 struct request suspend_rq;
183
184 /* For saving the address of __make_request for request based dm */
185 make_request_fn *saved_make_request_fn;
186
784aae73
MB
187 /* sysfs handle */
188 struct kobject kobj;
52b1fd5a
MP
189
190 /* zero-length barrier that will be cloned and submitted to targets */
191 struct bio barrier_bio;
1da177e4
LT
192};
193
e6ee8c0b
KU
194/*
195 * For mempools pre-allocation at the table loading time.
196 */
197struct dm_md_mempools {
198 mempool_t *io_pool;
199 mempool_t *tio_pool;
200 struct bio_set *bs;
201};
202
1da177e4 203#define MIN_IOS 256
e18b890b
CL
204static struct kmem_cache *_io_cache;
205static struct kmem_cache *_tio_cache;
8fbf26ad
KU
206static struct kmem_cache *_rq_tio_cache;
207static struct kmem_cache *_rq_bio_info_cache;
1da177e4 208
1da177e4
LT
209static int __init local_init(void)
210{
51157b4a 211 int r = -ENOMEM;
1da177e4 212
1da177e4 213 /* allocate a slab for the dm_ios */
028867ac 214 _io_cache = KMEM_CACHE(dm_io, 0);
1da177e4 215 if (!_io_cache)
51157b4a 216 return r;
1da177e4
LT
217
218 /* allocate a slab for the target ios */
028867ac 219 _tio_cache = KMEM_CACHE(dm_target_io, 0);
51157b4a
KU
220 if (!_tio_cache)
221 goto out_free_io_cache;
1da177e4 222
8fbf26ad
KU
223 _rq_tio_cache = KMEM_CACHE(dm_rq_target_io, 0);
224 if (!_rq_tio_cache)
225 goto out_free_tio_cache;
226
227 _rq_bio_info_cache = KMEM_CACHE(dm_rq_clone_bio_info, 0);
228 if (!_rq_bio_info_cache)
229 goto out_free_rq_tio_cache;
230
51e5b2bd 231 r = dm_uevent_init();
51157b4a 232 if (r)
8fbf26ad 233 goto out_free_rq_bio_info_cache;
51e5b2bd 234
1da177e4
LT
235 _major = major;
236 r = register_blkdev(_major, _name);
51157b4a
KU
237 if (r < 0)
238 goto out_uevent_exit;
1da177e4
LT
239
240 if (!_major)
241 _major = r;
242
243 return 0;
51157b4a
KU
244
245out_uevent_exit:
246 dm_uevent_exit();
8fbf26ad
KU
247out_free_rq_bio_info_cache:
248 kmem_cache_destroy(_rq_bio_info_cache);
249out_free_rq_tio_cache:
250 kmem_cache_destroy(_rq_tio_cache);
51157b4a
KU
251out_free_tio_cache:
252 kmem_cache_destroy(_tio_cache);
253out_free_io_cache:
254 kmem_cache_destroy(_io_cache);
255
256 return r;
1da177e4
LT
257}
258
259static void local_exit(void)
260{
8fbf26ad
KU
261 kmem_cache_destroy(_rq_bio_info_cache);
262 kmem_cache_destroy(_rq_tio_cache);
1da177e4
LT
263 kmem_cache_destroy(_tio_cache);
264 kmem_cache_destroy(_io_cache);
00d59405 265 unregister_blkdev(_major, _name);
51e5b2bd 266 dm_uevent_exit();
1da177e4
LT
267
268 _major = 0;
269
270 DMINFO("cleaned up");
271}
272
b9249e55 273static int (*_inits[])(void) __initdata = {
1da177e4
LT
274 local_init,
275 dm_target_init,
276 dm_linear_init,
277 dm_stripe_init,
952b3557 278 dm_io_init,
945fa4d2 279 dm_kcopyd_init,
1da177e4
LT
280 dm_interface_init,
281};
282
b9249e55 283static void (*_exits[])(void) = {
1da177e4
LT
284 local_exit,
285 dm_target_exit,
286 dm_linear_exit,
287 dm_stripe_exit,
952b3557 288 dm_io_exit,
945fa4d2 289 dm_kcopyd_exit,
1da177e4
LT
290 dm_interface_exit,
291};
292
293static int __init dm_init(void)
294{
295 const int count = ARRAY_SIZE(_inits);
296
297 int r, i;
298
299 for (i = 0; i < count; i++) {
300 r = _inits[i]();
301 if (r)
302 goto bad;
303 }
304
305 return 0;
306
307 bad:
308 while (i--)
309 _exits[i]();
310
311 return r;
312}
313
314static void __exit dm_exit(void)
315{
316 int i = ARRAY_SIZE(_exits);
317
318 while (i--)
319 _exits[i]();
320}
321
322/*
323 * Block device functions
324 */
fe5f9f2c 325static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1da177e4
LT
326{
327 struct mapped_device *md;
328
fba9f90e
JM
329 spin_lock(&_minor_lock);
330
fe5f9f2c 331 md = bdev->bd_disk->private_data;
fba9f90e
JM
332 if (!md)
333 goto out;
334
5c6bd75d
AK
335 if (test_bit(DMF_FREEING, &md->flags) ||
336 test_bit(DMF_DELETING, &md->flags)) {
fba9f90e
JM
337 md = NULL;
338 goto out;
339 }
340
1da177e4 341 dm_get(md);
5c6bd75d 342 atomic_inc(&md->open_count);
fba9f90e
JM
343
344out:
345 spin_unlock(&_minor_lock);
346
347 return md ? 0 : -ENXIO;
1da177e4
LT
348}
349
fe5f9f2c 350static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1da177e4 351{
fe5f9f2c 352 struct mapped_device *md = disk->private_data;
5c6bd75d 353 atomic_dec(&md->open_count);
1da177e4
LT
354 dm_put(md);
355 return 0;
356}
357
5c6bd75d
AK
358int dm_open_count(struct mapped_device *md)
359{
360 return atomic_read(&md->open_count);
361}
362
363/*
364 * Guarantees nothing is using the device before it's deleted.
365 */
366int dm_lock_for_deletion(struct mapped_device *md)
367{
368 int r = 0;
369
370 spin_lock(&_minor_lock);
371
372 if (dm_open_count(md))
373 r = -EBUSY;
374 else
375 set_bit(DMF_DELETING, &md->flags);
376
377 spin_unlock(&_minor_lock);
378
379 return r;
380}
381
3ac51e74
DW
382static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
383{
384 struct mapped_device *md = bdev->bd_disk->private_data;
385
386 return dm_get_geometry(md, geo);
387}
388
fe5f9f2c 389static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,
aa129a22
MB
390 unsigned int cmd, unsigned long arg)
391{
fe5f9f2c
AV
392 struct mapped_device *md = bdev->bd_disk->private_data;
393 struct dm_table *map = dm_get_table(md);
aa129a22
MB
394 struct dm_target *tgt;
395 int r = -ENOTTY;
396
aa129a22
MB
397 if (!map || !dm_table_get_size(map))
398 goto out;
399
400 /* We only support devices that have a single target */
401 if (dm_table_get_num_targets(map) != 1)
402 goto out;
403
404 tgt = dm_table_get_target(map, 0);
405
406 if (dm_suspended(md)) {
407 r = -EAGAIN;
408 goto out;
409 }
410
411 if (tgt->type->ioctl)
647b3d00 412 r = tgt->type->ioctl(tgt, cmd, arg);
aa129a22
MB
413
414out:
415 dm_table_put(map);
416
aa129a22
MB
417 return r;
418}
419
028867ac 420static struct dm_io *alloc_io(struct mapped_device *md)
1da177e4
LT
421{
422 return mempool_alloc(md->io_pool, GFP_NOIO);
423}
424
028867ac 425static void free_io(struct mapped_device *md, struct dm_io *io)
1da177e4
LT
426{
427 mempool_free(io, md->io_pool);
428}
429
028867ac 430static void free_tio(struct mapped_device *md, struct dm_target_io *tio)
1da177e4
LT
431{
432 mempool_free(tio, md->tio_pool);
433}
434
cec47e3d
KU
435static struct dm_rq_target_io *alloc_rq_tio(struct mapped_device *md)
436{
437 return mempool_alloc(md->tio_pool, GFP_ATOMIC);
438}
439
440static void free_rq_tio(struct dm_rq_target_io *tio)
441{
442 mempool_free(tio, tio->md->tio_pool);
443}
444
445static struct dm_rq_clone_bio_info *alloc_bio_info(struct mapped_device *md)
446{
447 return mempool_alloc(md->io_pool, GFP_ATOMIC);
448}
449
450static void free_bio_info(struct dm_rq_clone_bio_info *info)
451{
452 mempool_free(info, info->tio->md->io_pool);
453}
454
3eaf840e
JNN
455static void start_io_acct(struct dm_io *io)
456{
457 struct mapped_device *md = io->md;
c9959059 458 int cpu;
316d315b 459 int rw = bio_data_dir(io->bio);
3eaf840e
JNN
460
461 io->start_time = jiffies;
462
074a7aca
TH
463 cpu = part_stat_lock();
464 part_round_stats(cpu, &dm_disk(md)->part0);
465 part_stat_unlock();
316d315b 466 dm_disk(md)->part0.in_flight[rw] = atomic_inc_return(&md->pending[rw]);
3eaf840e
JNN
467}
468
d221d2e7 469static void end_io_acct(struct dm_io *io)
3eaf840e
JNN
470{
471 struct mapped_device *md = io->md;
472 struct bio *bio = io->bio;
473 unsigned long duration = jiffies - io->start_time;
c9959059 474 int pending, cpu;
3eaf840e
JNN
475 int rw = bio_data_dir(bio);
476
074a7aca
TH
477 cpu = part_stat_lock();
478 part_round_stats(cpu, &dm_disk(md)->part0);
479 part_stat_add(cpu, &dm_disk(md)->part0, ticks[rw], duration);
480 part_stat_unlock();
3eaf840e 481
af7e466a
MP
482 /*
483 * After this is decremented the bio must not be touched if it is
484 * a barrier.
485 */
316d315b
NK
486 dm_disk(md)->part0.in_flight[rw] = pending =
487 atomic_dec_return(&md->pending[rw]);
488 pending += atomic_read(&md->pending[rw^0x1]);
3eaf840e 489
d221d2e7
MP
490 /* nudge anyone waiting on suspend queue */
491 if (!pending)
492 wake_up(&md->wait);
3eaf840e
JNN
493}
494
1da177e4
LT
495/*
496 * Add the bio to the list of deferred io.
497 */
92c63902 498static void queue_io(struct mapped_device *md, struct bio *bio)
1da177e4 499{
2ca3310e 500 down_write(&md->io_lock);
1da177e4 501
022c2611 502 spin_lock_irq(&md->deferred_lock);
1da177e4 503 bio_list_add(&md->deferred, bio);
022c2611 504 spin_unlock_irq(&md->deferred_lock);
1da177e4 505
92c63902
MP
506 if (!test_and_set_bit(DMF_QUEUE_IO_TO_THREAD, &md->flags))
507 queue_work(md->wq, &md->work);
508
2ca3310e 509 up_write(&md->io_lock);
1da177e4
LT
510}
511
512/*
513 * Everyone (including functions in this file), should use this
514 * function to access the md->map field, and make sure they call
515 * dm_table_put() when finished.
516 */
517struct dm_table *dm_get_table(struct mapped_device *md)
518{
519 struct dm_table *t;
523d9297 520 unsigned long flags;
1da177e4 521
523d9297 522 read_lock_irqsave(&md->map_lock, flags);
1da177e4
LT
523 t = md->map;
524 if (t)
525 dm_table_get(t);
523d9297 526 read_unlock_irqrestore(&md->map_lock, flags);
1da177e4
LT
527
528 return t;
529}
530
3ac51e74
DW
531/*
532 * Get the geometry associated with a dm device
533 */
534int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo)
535{
536 *geo = md->geometry;
537
538 return 0;
539}
540
541/*
542 * Set the geometry of a device.
543 */
544int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo)
545{
546 sector_t sz = (sector_t)geo->cylinders * geo->heads * geo->sectors;
547
548 if (geo->start > sz) {
549 DMWARN("Start sector is beyond the geometry limits.");
550 return -EINVAL;
551 }
552
553 md->geometry = *geo;
554
555 return 0;
556}
557
1da177e4
LT
558/*-----------------------------------------------------------------
559 * CRUD START:
560 * A more elegant soln is in the works that uses the queue
561 * merge fn, unfortunately there are a couple of changes to
562 * the block layer that I want to make for this. So in the
563 * interests of getting something for people to use I give
564 * you this clearly demarcated crap.
565 *---------------------------------------------------------------*/
566
2e93ccc1
KU
567static int __noflush_suspending(struct mapped_device *md)
568{
569 return test_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
570}
571
1da177e4
LT
572/*
573 * Decrements the number of outstanding ios that a bio has been
574 * cloned into, completing the original io if necc.
575 */
858119e1 576static void dec_pending(struct dm_io *io, int error)
1da177e4 577{
2e93ccc1 578 unsigned long flags;
b35f8caa
MB
579 int io_error;
580 struct bio *bio;
581 struct mapped_device *md = io->md;
2e93ccc1
KU
582
583 /* Push-back supersedes any I/O errors */
f88fb981
KU
584 if (unlikely(error)) {
585 spin_lock_irqsave(&io->endio_lock, flags);
586 if (!(io->error > 0 && __noflush_suspending(md)))
587 io->error = error;
588 spin_unlock_irqrestore(&io->endio_lock, flags);
589 }
1da177e4
LT
590
591 if (atomic_dec_and_test(&io->io_count)) {
2e93ccc1
KU
592 if (io->error == DM_ENDIO_REQUEUE) {
593 /*
594 * Target requested pushing back the I/O.
2e93ccc1 595 */
022c2611 596 spin_lock_irqsave(&md->deferred_lock, flags);
2761e95f 597 if (__noflush_suspending(md)) {
1f98a13f 598 if (!bio_rw_flagged(io->bio, BIO_RW_BARRIER))
2761e95f
MP
599 bio_list_add_head(&md->deferred,
600 io->bio);
601 } else
2e93ccc1
KU
602 /* noflush suspend was interrupted. */
603 io->error = -EIO;
022c2611 604 spin_unlock_irqrestore(&md->deferred_lock, flags);
2e93ccc1
KU
605 }
606
b35f8caa
MB
607 io_error = io->error;
608 bio = io->bio;
2e93ccc1 609
1f98a13f 610 if (bio_rw_flagged(bio, BIO_RW_BARRIER)) {
af7e466a
MP
611 /*
612 * There can be just one barrier request so we use
613 * a per-device variable for error reporting.
614 * Note that you can't touch the bio after end_io_acct
615 */
fdb9572b 616 if (!md->barrier_error && io_error != -EOPNOTSUPP)
5aa2781d 617 md->barrier_error = io_error;
af7e466a
MP
618 end_io_acct(io);
619 } else {
620 end_io_acct(io);
b35f8caa 621
af7e466a
MP
622 if (io_error != DM_ENDIO_REQUEUE) {
623 trace_block_bio_complete(md->queue, bio);
2056a782 624
af7e466a
MP
625 bio_endio(bio, io_error);
626 }
b35f8caa 627 }
af7e466a
MP
628
629 free_io(md, io);
1da177e4
LT
630 }
631}
632
6712ecf8 633static void clone_endio(struct bio *bio, int error)
1da177e4
LT
634{
635 int r = 0;
028867ac 636 struct dm_target_io *tio = bio->bi_private;
b35f8caa 637 struct dm_io *io = tio->io;
9faf400f 638 struct mapped_device *md = tio->io->md;
1da177e4
LT
639 dm_endio_fn endio = tio->ti->type->end_io;
640
1da177e4
LT
641 if (!bio_flagged(bio, BIO_UPTODATE) && !error)
642 error = -EIO;
643
644 if (endio) {
645 r = endio(tio->ti, bio, error, &tio->info);
2e93ccc1
KU
646 if (r < 0 || r == DM_ENDIO_REQUEUE)
647 /*
648 * error and requeue request are handled
649 * in dec_pending().
650 */
1da177e4 651 error = r;
45cbcd79
KU
652 else if (r == DM_ENDIO_INCOMPLETE)
653 /* The target will handle the io */
6712ecf8 654 return;
45cbcd79
KU
655 else if (r) {
656 DMWARN("unimplemented target endio return value: %d", r);
657 BUG();
658 }
1da177e4
LT
659 }
660
9faf400f
SB
661 /*
662 * Store md for cleanup instead of tio which is about to get freed.
663 */
664 bio->bi_private = md->bs;
665
9faf400f 666 free_tio(md, tio);
b35f8caa
MB
667 bio_put(bio);
668 dec_pending(io, error);
1da177e4
LT
669}
670
cec47e3d
KU
671/*
672 * Partial completion handling for request-based dm
673 */
674static void end_clone_bio(struct bio *clone, int error)
675{
676 struct dm_rq_clone_bio_info *info = clone->bi_private;
677 struct dm_rq_target_io *tio = info->tio;
678 struct bio *bio = info->orig;
679 unsigned int nr_bytes = info->orig->bi_size;
680
681 bio_put(clone);
682
683 if (tio->error)
684 /*
685 * An error has already been detected on the request.
686 * Once error occurred, just let clone->end_io() handle
687 * the remainder.
688 */
689 return;
690 else if (error) {
691 /*
692 * Don't notice the error to the upper layer yet.
693 * The error handling decision is made by the target driver,
694 * when the request is completed.
695 */
696 tio->error = error;
697 return;
698 }
699
700 /*
701 * I/O for the bio successfully completed.
702 * Notice the data completion to the upper layer.
703 */
704
705 /*
706 * bios are processed from the head of the list.
707 * So the completing bio should always be rq->bio.
708 * If it's not, something wrong is happening.
709 */
710 if (tio->orig->bio != bio)
711 DMERR("bio completion is going in the middle of the request");
712
713 /*
714 * Update the original request.
715 * Do not use blk_end_request() here, because it may complete
716 * the original request before the clone, and break the ordering.
717 */
718 blk_update_request(tio->orig, 0, nr_bytes);
719}
720
721/*
722 * Don't touch any member of the md after calling this function because
723 * the md may be freed in dm_put() at the end of this function.
724 * Or do dm_get() before calling this function and dm_put() later.
725 */
726static void rq_completed(struct mapped_device *md, int run_queue)
727{
728 int wakeup_waiters = 0;
729 struct request_queue *q = md->queue;
730 unsigned long flags;
731
732 spin_lock_irqsave(q->queue_lock, flags);
733 if (!queue_in_flight(q))
734 wakeup_waiters = 1;
735 spin_unlock_irqrestore(q->queue_lock, flags);
736
737 /* nudge anyone waiting on suspend queue */
738 if (wakeup_waiters)
739 wake_up(&md->wait);
740
741 if (run_queue)
742 blk_run_queue(q);
743
744 /*
745 * dm_put() must be at the end of this function. See the comment above
746 */
747 dm_put(md);
748}
749
a77e28c7
KU
750static void free_rq_clone(struct request *clone)
751{
752 struct dm_rq_target_io *tio = clone->end_io_data;
753
754 blk_rq_unprep_clone(clone);
755 free_rq_tio(tio);
756}
757
cec47e3d
KU
758static void dm_unprep_request(struct request *rq)
759{
760 struct request *clone = rq->special;
cec47e3d
KU
761
762 rq->special = NULL;
763 rq->cmd_flags &= ~REQ_DONTPREP;
764
a77e28c7 765 free_rq_clone(clone);
cec47e3d
KU
766}
767
768/*
769 * Requeue the original request of a clone.
770 */
771void dm_requeue_unmapped_request(struct request *clone)
772{
773 struct dm_rq_target_io *tio = clone->end_io_data;
774 struct mapped_device *md = tio->md;
775 struct request *rq = tio->orig;
776 struct request_queue *q = rq->q;
777 unsigned long flags;
778
779 dm_unprep_request(rq);
780
781 spin_lock_irqsave(q->queue_lock, flags);
782 if (elv_queue_empty(q))
783 blk_plug_device(q);
784 blk_requeue_request(q, rq);
785 spin_unlock_irqrestore(q->queue_lock, flags);
786
787 rq_completed(md, 0);
788}
789EXPORT_SYMBOL_GPL(dm_requeue_unmapped_request);
790
791static void __stop_queue(struct request_queue *q)
792{
793 blk_stop_queue(q);
794}
795
796static void stop_queue(struct request_queue *q)
797{
798 unsigned long flags;
799
800 spin_lock_irqsave(q->queue_lock, flags);
801 __stop_queue(q);
802 spin_unlock_irqrestore(q->queue_lock, flags);
803}
804
805static void __start_queue(struct request_queue *q)
806{
807 if (blk_queue_stopped(q))
808 blk_start_queue(q);
809}
810
811static void start_queue(struct request_queue *q)
812{
813 unsigned long flags;
814
815 spin_lock_irqsave(q->queue_lock, flags);
816 __start_queue(q);
817 spin_unlock_irqrestore(q->queue_lock, flags);
818}
819
820/*
821 * Complete the clone and the original request.
822 * Must be called without queue lock.
823 */
824static void dm_end_request(struct request *clone, int error)
825{
826 struct dm_rq_target_io *tio = clone->end_io_data;
827 struct mapped_device *md = tio->md;
828 struct request *rq = tio->orig;
829
830 if (blk_pc_request(rq)) {
831 rq->errors = clone->errors;
832 rq->resid_len = clone->resid_len;
833
834 if (rq->sense)
835 /*
836 * We are using the sense buffer of the original
837 * request.
838 * So setting the length of the sense data is enough.
839 */
840 rq->sense_len = clone->sense_len;
841 }
842
a77e28c7 843 free_rq_clone(clone);
cec47e3d
KU
844
845 blk_end_request_all(rq, error);
846
847 rq_completed(md, 1);
848}
849
850/*
851 * Request completion handler for request-based dm
852 */
853static void dm_softirq_done(struct request *rq)
854{
855 struct request *clone = rq->completion_data;
856 struct dm_rq_target_io *tio = clone->end_io_data;
857 dm_request_endio_fn rq_end_io = tio->ti->type->rq_end_io;
858 int error = tio->error;
859
860 if (!(rq->cmd_flags & REQ_FAILED) && rq_end_io)
861 error = rq_end_io(tio->ti, clone, error, &tio->info);
862
863 if (error <= 0)
864 /* The target wants to complete the I/O */
865 dm_end_request(clone, error);
866 else if (error == DM_ENDIO_INCOMPLETE)
867 /* The target will handle the I/O */
868 return;
869 else if (error == DM_ENDIO_REQUEUE)
870 /* The target wants to requeue the I/O */
871 dm_requeue_unmapped_request(clone);
872 else {
873 DMWARN("unimplemented target endio return value: %d", error);
874 BUG();
875 }
876}
877
878/*
879 * Complete the clone and the original request with the error status
880 * through softirq context.
881 */
882static void dm_complete_request(struct request *clone, int error)
883{
884 struct dm_rq_target_io *tio = clone->end_io_data;
885 struct request *rq = tio->orig;
886
887 tio->error = error;
888 rq->completion_data = clone;
889 blk_complete_request(rq);
890}
891
892/*
893 * Complete the not-mapped clone and the original request with the error status
894 * through softirq context.
895 * Target's rq_end_io() function isn't called.
896 * This may be used when the target's map_rq() function fails.
897 */
898void dm_kill_unmapped_request(struct request *clone, int error)
899{
900 struct dm_rq_target_io *tio = clone->end_io_data;
901 struct request *rq = tio->orig;
902
903 rq->cmd_flags |= REQ_FAILED;
904 dm_complete_request(clone, error);
905}
906EXPORT_SYMBOL_GPL(dm_kill_unmapped_request);
907
908/*
909 * Called with the queue lock held
910 */
911static void end_clone_request(struct request *clone, int error)
912{
913 /*
914 * For just cleaning up the information of the queue in which
915 * the clone was dispatched.
916 * The clone is *NOT* freed actually here because it is alloced from
917 * dm own mempool and REQ_ALLOCED isn't set in clone->cmd_flags.
918 */
919 __blk_put_request(clone->q, clone);
920
921 /*
922 * Actual request completion is done in a softirq context which doesn't
923 * hold the queue lock. Otherwise, deadlock could occur because:
924 * - another request may be submitted by the upper level driver
925 * of the stacking during the completion
926 * - the submission which requires queue lock may be done
927 * against this queue
928 */
929 dm_complete_request(clone, error);
930}
931
1da177e4
LT
932static sector_t max_io_len(struct mapped_device *md,
933 sector_t sector, struct dm_target *ti)
934{
935 sector_t offset = sector - ti->begin;
936 sector_t len = ti->len - offset;
937
938 /*
939 * Does the target need to split even further ?
940 */
941 if (ti->split_io) {
942 sector_t boundary;
943 boundary = ((offset + ti->split_io) & ~(ti->split_io - 1))
944 - offset;
945 if (len > boundary)
946 len = boundary;
947 }
948
949 return len;
950}
951
952static void __map_bio(struct dm_target *ti, struct bio *clone,
028867ac 953 struct dm_target_io *tio)
1da177e4
LT
954{
955 int r;
2056a782 956 sector_t sector;
9faf400f 957 struct mapped_device *md;
1da177e4 958
1da177e4
LT
959 clone->bi_end_io = clone_endio;
960 clone->bi_private = tio;
961
962 /*
963 * Map the clone. If r == 0 we don't need to do
964 * anything, the target has assumed ownership of
965 * this io.
966 */
967 atomic_inc(&tio->io->io_count);
2056a782 968 sector = clone->bi_sector;
1da177e4 969 r = ti->type->map(ti, clone, &tio->info);
45cbcd79 970 if (r == DM_MAPIO_REMAPPED) {
1da177e4 971 /* the bio has been remapped so dispatch it */
2056a782 972
5f3ea37c 973 trace_block_remap(bdev_get_queue(clone->bi_bdev), clone,
22a7c31a 974 tio->io->bio->bi_bdev->bd_dev, sector);
2056a782 975
1da177e4 976 generic_make_request(clone);
2e93ccc1
KU
977 } else if (r < 0 || r == DM_MAPIO_REQUEUE) {
978 /* error the io and bail out, or requeue it if needed */
9faf400f
SB
979 md = tio->io->md;
980 dec_pending(tio->io, r);
981 /*
982 * Store bio_set for cleanup.
983 */
984 clone->bi_private = md->bs;
1da177e4 985 bio_put(clone);
9faf400f 986 free_tio(md, tio);
45cbcd79
KU
987 } else if (r) {
988 DMWARN("unimplemented target map return value: %d", r);
989 BUG();
1da177e4
LT
990 }
991}
992
993struct clone_info {
994 struct mapped_device *md;
995 struct dm_table *map;
996 struct bio *bio;
997 struct dm_io *io;
998 sector_t sector;
999 sector_t sector_count;
1000 unsigned short idx;
1001};
1002
3676347a
PO
1003static void dm_bio_destructor(struct bio *bio)
1004{
9faf400f
SB
1005 struct bio_set *bs = bio->bi_private;
1006
1007 bio_free(bio, bs);
3676347a
PO
1008}
1009
1da177e4
LT
1010/*
1011 * Creates a little bio that is just does part of a bvec.
1012 */
1013static struct bio *split_bvec(struct bio *bio, sector_t sector,
1014 unsigned short idx, unsigned int offset,
9faf400f 1015 unsigned int len, struct bio_set *bs)
1da177e4
LT
1016{
1017 struct bio *clone;
1018 struct bio_vec *bv = bio->bi_io_vec + idx;
1019
9faf400f 1020 clone = bio_alloc_bioset(GFP_NOIO, 1, bs);
3676347a 1021 clone->bi_destructor = dm_bio_destructor;
1da177e4
LT
1022 *clone->bi_io_vec = *bv;
1023
1024 clone->bi_sector = sector;
1025 clone->bi_bdev = bio->bi_bdev;
af7e466a 1026 clone->bi_rw = bio->bi_rw & ~(1 << BIO_RW_BARRIER);
1da177e4
LT
1027 clone->bi_vcnt = 1;
1028 clone->bi_size = to_bytes(len);
1029 clone->bi_io_vec->bv_offset = offset;
1030 clone->bi_io_vec->bv_len = clone->bi_size;
f3e1d26e 1031 clone->bi_flags |= 1 << BIO_CLONED;
1da177e4 1032
9c47008d 1033 if (bio_integrity(bio)) {
7878cba9 1034 bio_integrity_clone(clone, bio, GFP_NOIO, bs);
9c47008d
MP
1035 bio_integrity_trim(clone,
1036 bio_sector_offset(bio, idx, offset), len);
1037 }
1038
1da177e4
LT
1039 return clone;
1040}
1041
1042/*
1043 * Creates a bio that consists of range of complete bvecs.
1044 */
1045static struct bio *clone_bio(struct bio *bio, sector_t sector,
1046 unsigned short idx, unsigned short bv_count,
9faf400f 1047 unsigned int len, struct bio_set *bs)
1da177e4
LT
1048{
1049 struct bio *clone;
1050
9faf400f
SB
1051 clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs);
1052 __bio_clone(clone, bio);
af7e466a 1053 clone->bi_rw &= ~(1 << BIO_RW_BARRIER);
9faf400f 1054 clone->bi_destructor = dm_bio_destructor;
1da177e4
LT
1055 clone->bi_sector = sector;
1056 clone->bi_idx = idx;
1057 clone->bi_vcnt = idx + bv_count;
1058 clone->bi_size = to_bytes(len);
1059 clone->bi_flags &= ~(1 << BIO_SEG_VALID);
1060
9c47008d 1061 if (bio_integrity(bio)) {
7878cba9 1062 bio_integrity_clone(clone, bio, GFP_NOIO, bs);
9c47008d
MP
1063
1064 if (idx != bio->bi_idx || clone->bi_size < bio->bi_size)
1065 bio_integrity_trim(clone,
1066 bio_sector_offset(bio, idx, 0), len);
1067 }
1068
1da177e4
LT
1069 return clone;
1070}
1071
9015df24
AK
1072static struct dm_target_io *alloc_tio(struct clone_info *ci,
1073 struct dm_target *ti)
f9ab94ce 1074{
9015df24 1075 struct dm_target_io *tio = mempool_alloc(ci->md->tio_pool, GFP_NOIO);
f9ab94ce
MP
1076
1077 tio->io = ci->io;
1078 tio->ti = ti;
f9ab94ce 1079 memset(&tio->info, 0, sizeof(tio->info));
9015df24
AK
1080
1081 return tio;
1082}
1083
1084static void __flush_target(struct clone_info *ci, struct dm_target *ti,
1085 unsigned flush_nr)
1086{
1087 struct dm_target_io *tio = alloc_tio(ci, ti);
1088 struct bio *clone;
1089
f9ab94ce
MP
1090 tio->info.flush_request = flush_nr;
1091
1092 clone = bio_alloc_bioset(GFP_NOIO, 0, ci->md->bs);
1093 __bio_clone(clone, ci->bio);
1094 clone->bi_destructor = dm_bio_destructor;
1095
1096 __map_bio(ti, clone, tio);
1097}
1098
1099static int __clone_and_map_empty_barrier(struct clone_info *ci)
1100{
1101 unsigned target_nr = 0, flush_nr;
1102 struct dm_target *ti;
1103
1104 while ((ti = dm_table_get_target(ci->map, target_nr++)))
1105 for (flush_nr = 0; flush_nr < ti->num_flush_requests;
1106 flush_nr++)
1107 __flush_target(ci, ti, flush_nr);
1108
1109 ci->sector_count = 0;
1110
1111 return 0;
1112}
1113
512875bd 1114static int __clone_and_map(struct clone_info *ci)
1da177e4
LT
1115{
1116 struct bio *clone, *bio = ci->bio;
512875bd
JN
1117 struct dm_target *ti;
1118 sector_t len = 0, max;
028867ac 1119 struct dm_target_io *tio;
1da177e4 1120
f9ab94ce
MP
1121 if (unlikely(bio_empty_barrier(bio)))
1122 return __clone_and_map_empty_barrier(ci);
1123
512875bd
JN
1124 ti = dm_table_find_target(ci->map, ci->sector);
1125 if (!dm_target_is_valid(ti))
1126 return -EIO;
1127
1128 max = max_io_len(ci->md, ci->sector, ti);
1129
1da177e4
LT
1130 /*
1131 * Allocate a target io object.
1132 */
9015df24 1133 tio = alloc_tio(ci, ti);
1da177e4
LT
1134
1135 if (ci->sector_count <= max) {
1136 /*
1137 * Optimise for the simple case where we can do all of
1138 * the remaining io with a single clone.
1139 */
1140 clone = clone_bio(bio, ci->sector, ci->idx,
9faf400f
SB
1141 bio->bi_vcnt - ci->idx, ci->sector_count,
1142 ci->md->bs);
1da177e4
LT
1143 __map_bio(ti, clone, tio);
1144 ci->sector_count = 0;
1145
1146 } else if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) {
1147 /*
1148 * There are some bvecs that don't span targets.
1149 * Do as many of these as possible.
1150 */
1151 int i;
1152 sector_t remaining = max;
1153 sector_t bv_len;
1154
1155 for (i = ci->idx; remaining && (i < bio->bi_vcnt); i++) {
1156 bv_len = to_sector(bio->bi_io_vec[i].bv_len);
1157
1158 if (bv_len > remaining)
1159 break;
1160
1161 remaining -= bv_len;
1162 len += bv_len;
1163 }
1164
9faf400f
SB
1165 clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len,
1166 ci->md->bs);
1da177e4
LT
1167 __map_bio(ti, clone, tio);
1168
1169 ci->sector += len;
1170 ci->sector_count -= len;
1171 ci->idx = i;
1172
1173 } else {
1174 /*
d2044a94 1175 * Handle a bvec that must be split between two or more targets.
1da177e4
LT
1176 */
1177 struct bio_vec *bv = bio->bi_io_vec + ci->idx;
d2044a94
AK
1178 sector_t remaining = to_sector(bv->bv_len);
1179 unsigned int offset = 0;
1da177e4 1180
d2044a94
AK
1181 do {
1182 if (offset) {
1183 ti = dm_table_find_target(ci->map, ci->sector);
512875bd
JN
1184 if (!dm_target_is_valid(ti))
1185 return -EIO;
1186
d2044a94 1187 max = max_io_len(ci->md, ci->sector, ti);
1da177e4 1188
9015df24 1189 tio = alloc_tio(ci, ti);
d2044a94
AK
1190 }
1191
1192 len = min(remaining, max);
1193
1194 clone = split_bvec(bio, ci->sector, ci->idx,
9faf400f
SB
1195 bv->bv_offset + offset, len,
1196 ci->md->bs);
d2044a94
AK
1197
1198 __map_bio(ti, clone, tio);
1199
1200 ci->sector += len;
1201 ci->sector_count -= len;
1202 offset += to_bytes(len);
1203 } while (remaining -= len);
1da177e4 1204
1da177e4
LT
1205 ci->idx++;
1206 }
512875bd
JN
1207
1208 return 0;
1da177e4
LT
1209}
1210
1211/*
8a53c28d 1212 * Split the bio into several clones and submit it to targets.
1da177e4 1213 */
f0b9a450 1214static void __split_and_process_bio(struct mapped_device *md, struct bio *bio)
1da177e4
LT
1215{
1216 struct clone_info ci;
512875bd 1217 int error = 0;
1da177e4
LT
1218
1219 ci.map = dm_get_table(md);
f0b9a450 1220 if (unlikely(!ci.map)) {
1f98a13f 1221 if (!bio_rw_flagged(bio, BIO_RW_BARRIER))
af7e466a
MP
1222 bio_io_error(bio);
1223 else
5aa2781d
MP
1224 if (!md->barrier_error)
1225 md->barrier_error = -EIO;
f0b9a450
MP
1226 return;
1227 }
692d0eb9 1228
1da177e4
LT
1229 ci.md = md;
1230 ci.bio = bio;
1231 ci.io = alloc_io(md);
1232 ci.io->error = 0;
1233 atomic_set(&ci.io->io_count, 1);
1234 ci.io->bio = bio;
1235 ci.io->md = md;
f88fb981 1236 spin_lock_init(&ci.io->endio_lock);
1da177e4
LT
1237 ci.sector = bio->bi_sector;
1238 ci.sector_count = bio_sectors(bio);
f9ab94ce
MP
1239 if (unlikely(bio_empty_barrier(bio)))
1240 ci.sector_count = 1;
1da177e4
LT
1241 ci.idx = bio->bi_idx;
1242
3eaf840e 1243 start_io_acct(ci.io);
512875bd
JN
1244 while (ci.sector_count && !error)
1245 error = __clone_and_map(&ci);
1da177e4
LT
1246
1247 /* drop the extra reference count */
512875bd 1248 dec_pending(ci.io, error);
1da177e4
LT
1249 dm_table_put(ci.map);
1250}
1251/*-----------------------------------------------------------------
1252 * CRUD END
1253 *---------------------------------------------------------------*/
1254
f6fccb12
MB
1255static int dm_merge_bvec(struct request_queue *q,
1256 struct bvec_merge_data *bvm,
1257 struct bio_vec *biovec)
1258{
1259 struct mapped_device *md = q->queuedata;
1260 struct dm_table *map = dm_get_table(md);
1261 struct dm_target *ti;
1262 sector_t max_sectors;
5037108a 1263 int max_size = 0;
f6fccb12
MB
1264
1265 if (unlikely(!map))
5037108a 1266 goto out;
f6fccb12
MB
1267
1268 ti = dm_table_find_target(map, bvm->bi_sector);
b01cd5ac
MP
1269 if (!dm_target_is_valid(ti))
1270 goto out_table;
f6fccb12
MB
1271
1272 /*
1273 * Find maximum amount of I/O that won't need splitting
1274 */
1275 max_sectors = min(max_io_len(md, bvm->bi_sector, ti),
1276 (sector_t) BIO_MAX_SECTORS);
1277 max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size;
1278 if (max_size < 0)
1279 max_size = 0;
1280
1281 /*
1282 * merge_bvec_fn() returns number of bytes
1283 * it can accept at this offset
1284 * max is precomputed maximal io size
1285 */
1286 if (max_size && ti->type->merge)
1287 max_size = ti->type->merge(ti, bvm, biovec, max_size);
8cbeb67a
MP
1288 /*
1289 * If the target doesn't support merge method and some of the devices
1290 * provided their merge_bvec method (we know this by looking at
1291 * queue_max_hw_sectors), then we can't allow bios with multiple vector
1292 * entries. So always set max_size to 0, and the code below allows
1293 * just one page.
1294 */
1295 else if (queue_max_hw_sectors(q) <= PAGE_SIZE >> 9)
1296
1297 max_size = 0;
f6fccb12 1298
b01cd5ac 1299out_table:
5037108a
MP
1300 dm_table_put(map);
1301
1302out:
f6fccb12
MB
1303 /*
1304 * Always allow an entire first page
1305 */
1306 if (max_size <= biovec->bv_len && !(bvm->bi_size >> SECTOR_SHIFT))
1307 max_size = biovec->bv_len;
1308
f6fccb12
MB
1309 return max_size;
1310}
1311
1da177e4
LT
1312/*
1313 * The request function that just remaps the bio built up by
1314 * dm_merge_bvec.
1315 */
cec47e3d 1316static int _dm_request(struct request_queue *q, struct bio *bio)
1da177e4 1317{
12f03a49 1318 int rw = bio_data_dir(bio);
1da177e4 1319 struct mapped_device *md = q->queuedata;
c9959059 1320 int cpu;
1da177e4 1321
2ca3310e 1322 down_read(&md->io_lock);
1da177e4 1323
074a7aca
TH
1324 cpu = part_stat_lock();
1325 part_stat_inc(cpu, &dm_disk(md)->part0, ios[rw]);
1326 part_stat_add(cpu, &dm_disk(md)->part0, sectors[rw], bio_sectors(bio));
1327 part_stat_unlock();
12f03a49 1328
1da177e4 1329 /*
1eb787ec
AK
1330 * If we're suspended or the thread is processing barriers
1331 * we have to queue this io for later.
1da177e4 1332 */
af7e466a 1333 if (unlikely(test_bit(DMF_QUEUE_IO_TO_THREAD, &md->flags)) ||
1f98a13f 1334 unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER))) {
2ca3310e 1335 up_read(&md->io_lock);
1da177e4 1336
54d9a1b4
AK
1337 if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) &&
1338 bio_rw(bio) == READA) {
1339 bio_io_error(bio);
1340 return 0;
1341 }
1da177e4 1342
92c63902 1343 queue_io(md, bio);
1da177e4 1344
92c63902 1345 return 0;
1da177e4
LT
1346 }
1347
f0b9a450 1348 __split_and_process_bio(md, bio);
2ca3310e 1349 up_read(&md->io_lock);
f0b9a450 1350 return 0;
1da177e4
LT
1351}
1352
cec47e3d
KU
1353static int dm_make_request(struct request_queue *q, struct bio *bio)
1354{
1355 struct mapped_device *md = q->queuedata;
1356
1f98a13f 1357 if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER))) {
cec47e3d
KU
1358 bio_endio(bio, -EOPNOTSUPP);
1359 return 0;
1360 }
1361
1362 return md->saved_make_request_fn(q, bio); /* call __make_request() */
1363}
1364
1365static int dm_request_based(struct mapped_device *md)
1366{
1367 return blk_queue_stackable(md->queue);
1368}
1369
1370static int dm_request(struct request_queue *q, struct bio *bio)
1371{
1372 struct mapped_device *md = q->queuedata;
1373
1374 if (dm_request_based(md))
1375 return dm_make_request(q, bio);
1376
1377 return _dm_request(q, bio);
1378}
1379
1380void dm_dispatch_request(struct request *rq)
1381{
1382 int r;
1383
1384 if (blk_queue_io_stat(rq->q))
1385 rq->cmd_flags |= REQ_IO_STAT;
1386
1387 rq->start_time = jiffies;
1388 r = blk_insert_cloned_request(rq->q, rq);
1389 if (r)
1390 dm_complete_request(rq, r);
1391}
1392EXPORT_SYMBOL_GPL(dm_dispatch_request);
1393
1394static void dm_rq_bio_destructor(struct bio *bio)
1395{
1396 struct dm_rq_clone_bio_info *info = bio->bi_private;
1397 struct mapped_device *md = info->tio->md;
1398
1399 free_bio_info(info);
1400 bio_free(bio, md->bs);
1401}
1402
1403static int dm_rq_bio_constructor(struct bio *bio, struct bio *bio_orig,
1404 void *data)
1405{
1406 struct dm_rq_target_io *tio = data;
1407 struct mapped_device *md = tio->md;
1408 struct dm_rq_clone_bio_info *info = alloc_bio_info(md);
1409
1410 if (!info)
1411 return -ENOMEM;
1412
1413 info->orig = bio_orig;
1414 info->tio = tio;
1415 bio->bi_end_io = end_clone_bio;
1416 bio->bi_private = info;
1417 bio->bi_destructor = dm_rq_bio_destructor;
1418
1419 return 0;
1420}
1421
1422static int setup_clone(struct request *clone, struct request *rq,
1423 struct dm_rq_target_io *tio)
1424{
1425 int r = blk_rq_prep_clone(clone, rq, tio->md->bs, GFP_ATOMIC,
1426 dm_rq_bio_constructor, tio);
1427
1428 if (r)
1429 return r;
1430
1431 clone->cmd = rq->cmd;
1432 clone->cmd_len = rq->cmd_len;
1433 clone->sense = rq->sense;
1434 clone->buffer = rq->buffer;
1435 clone->end_io = end_clone_request;
1436 clone->end_io_data = tio;
1437
1438 return 0;
1439}
1440
1441static int dm_rq_flush_suspending(struct mapped_device *md)
1442{
1443 return !md->suspend_rq.special;
1444}
1445
1446/*
1447 * Called with the queue lock held.
1448 */
1449static int dm_prep_fn(struct request_queue *q, struct request *rq)
1450{
1451 struct mapped_device *md = q->queuedata;
1452 struct dm_rq_target_io *tio;
1453 struct request *clone;
1454
1455 if (unlikely(rq == &md->suspend_rq)) {
1456 if (dm_rq_flush_suspending(md))
1457 return BLKPREP_OK;
1458 else
1459 /* The flush suspend was interrupted */
1460 return BLKPREP_KILL;
1461 }
1462
1463 if (unlikely(rq->special)) {
1464 DMWARN("Already has something in rq->special.");
1465 return BLKPREP_KILL;
1466 }
1467
1468 tio = alloc_rq_tio(md); /* Only one for each original request */
1469 if (!tio)
1470 /* -ENOMEM */
1471 return BLKPREP_DEFER;
1472
1473 tio->md = md;
1474 tio->ti = NULL;
1475 tio->orig = rq;
1476 tio->error = 0;
1477 memset(&tio->info, 0, sizeof(tio->info));
1478
1479 clone = &tio->clone;
1480 if (setup_clone(clone, rq, tio)) {
1481 /* -ENOMEM */
1482 free_rq_tio(tio);
1483 return BLKPREP_DEFER;
1484 }
1485
1486 rq->special = clone;
1487 rq->cmd_flags |= REQ_DONTPREP;
1488
1489 return BLKPREP_OK;
1490}
1491
1492static void map_request(struct dm_target *ti, struct request *rq,
1493 struct mapped_device *md)
1494{
1495 int r;
1496 struct request *clone = rq->special;
1497 struct dm_rq_target_io *tio = clone->end_io_data;
1498
1499 /*
1500 * Hold the md reference here for the in-flight I/O.
1501 * We can't rely on the reference count by device opener,
1502 * because the device may be closed during the request completion
1503 * when all bios are completed.
1504 * See the comment in rq_completed() too.
1505 */
1506 dm_get(md);
1507
1508 tio->ti = ti;
1509 r = ti->type->map_rq(ti, clone, &tio->info);
1510 switch (r) {
1511 case DM_MAPIO_SUBMITTED:
1512 /* The target has taken the I/O to submit by itself later */
1513 break;
1514 case DM_MAPIO_REMAPPED:
1515 /* The target has remapped the I/O so dispatch it */
1516 dm_dispatch_request(clone);
1517 break;
1518 case DM_MAPIO_REQUEUE:
1519 /* The target wants to requeue the I/O */
1520 dm_requeue_unmapped_request(clone);
1521 break;
1522 default:
1523 if (r > 0) {
1524 DMWARN("unimplemented target map return value: %d", r);
1525 BUG();
1526 }
1527
1528 /* The target wants to complete the I/O */
1529 dm_kill_unmapped_request(clone, r);
1530 break;
1531 }
1532}
1533
1534/*
1535 * q->request_fn for request-based dm.
1536 * Called with the queue lock held.
1537 */
1538static void dm_request_fn(struct request_queue *q)
1539{
1540 struct mapped_device *md = q->queuedata;
1541 struct dm_table *map = dm_get_table(md);
1542 struct dm_target *ti;
1543 struct request *rq;
1544
1545 /*
1546 * For noflush suspend, check blk_queue_stopped() to immediately
1547 * quit I/O dispatching.
1548 */
1549 while (!blk_queue_plugged(q) && !blk_queue_stopped(q)) {
1550 rq = blk_peek_request(q);
1551 if (!rq)
1552 goto plug_and_out;
1553
1554 if (unlikely(rq == &md->suspend_rq)) { /* Flush suspend maker */
1555 if (queue_in_flight(q))
1556 /* Not quiet yet. Wait more */
1557 goto plug_and_out;
1558
1559 /* This device should be quiet now */
1560 __stop_queue(q);
1561 blk_start_request(rq);
1562 __blk_end_request_all(rq, 0);
1563 wake_up(&md->wait);
1564 goto out;
1565 }
1566
1567 ti = dm_table_find_target(map, blk_rq_pos(rq));
1568 if (ti->type->busy && ti->type->busy(ti))
1569 goto plug_and_out;
1570
1571 blk_start_request(rq);
1572 spin_unlock(q->queue_lock);
1573 map_request(ti, rq, md);
1574 spin_lock_irq(q->queue_lock);
1575 }
1576
1577 goto out;
1578
1579plug_and_out:
1580 if (!elv_queue_empty(q))
1581 /* Some requests still remain, retry later */
1582 blk_plug_device(q);
1583
1584out:
1585 dm_table_put(map);
1586
1587 return;
1588}
1589
1590int dm_underlying_device_busy(struct request_queue *q)
1591{
1592 return blk_lld_busy(q);
1593}
1594EXPORT_SYMBOL_GPL(dm_underlying_device_busy);
1595
1596static int dm_lld_busy(struct request_queue *q)
1597{
1598 int r;
1599 struct mapped_device *md = q->queuedata;
1600 struct dm_table *map = dm_get_table(md);
1601
1602 if (!map || test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags))
1603 r = 1;
1604 else
1605 r = dm_table_any_busy_target(map);
1606
1607 dm_table_put(map);
1608
1609 return r;
1610}
1611
165125e1 1612static void dm_unplug_all(struct request_queue *q)
1da177e4
LT
1613{
1614 struct mapped_device *md = q->queuedata;
1615 struct dm_table *map = dm_get_table(md);
1616
1617 if (map) {
cec47e3d
KU
1618 if (dm_request_based(md))
1619 generic_unplug_device(q);
1620
1da177e4
LT
1621 dm_table_unplug_all(map);
1622 dm_table_put(map);
1623 }
1624}
1625
1626static int dm_any_congested(void *congested_data, int bdi_bits)
1627{
8a57dfc6
CS
1628 int r = bdi_bits;
1629 struct mapped_device *md = congested_data;
1630 struct dm_table *map;
1da177e4 1631
1eb787ec 1632 if (!test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) {
8a57dfc6
CS
1633 map = dm_get_table(md);
1634 if (map) {
cec47e3d
KU
1635 /*
1636 * Request-based dm cares about only own queue for
1637 * the query about congestion status of request_queue
1638 */
1639 if (dm_request_based(md))
1640 r = md->queue->backing_dev_info.state &
1641 bdi_bits;
1642 else
1643 r = dm_table_any_congested(map, bdi_bits);
1644
8a57dfc6
CS
1645 dm_table_put(map);
1646 }
1647 }
1648
1da177e4
LT
1649 return r;
1650}
1651
1652/*-----------------------------------------------------------------
1653 * An IDR is used to keep track of allocated minor numbers.
1654 *---------------------------------------------------------------*/
1da177e4
LT
1655static DEFINE_IDR(_minor_idr);
1656
2b06cfff 1657static void free_minor(int minor)
1da177e4 1658{
f32c10b0 1659 spin_lock(&_minor_lock);
1da177e4 1660 idr_remove(&_minor_idr, minor);
f32c10b0 1661 spin_unlock(&_minor_lock);
1da177e4
LT
1662}
1663
1664/*
1665 * See if the device with a specific minor # is free.
1666 */
cf13ab8e 1667static int specific_minor(int minor)
1da177e4
LT
1668{
1669 int r, m;
1670
1671 if (minor >= (1 << MINORBITS))
1672 return -EINVAL;
1673
62f75c2f
JM
1674 r = idr_pre_get(&_minor_idr, GFP_KERNEL);
1675 if (!r)
1676 return -ENOMEM;
1677
f32c10b0 1678 spin_lock(&_minor_lock);
1da177e4
LT
1679
1680 if (idr_find(&_minor_idr, minor)) {
1681 r = -EBUSY;
1682 goto out;
1683 }
1684
ba61fdd1 1685 r = idr_get_new_above(&_minor_idr, MINOR_ALLOCED, minor, &m);
62f75c2f 1686 if (r)
1da177e4 1687 goto out;
1da177e4
LT
1688
1689 if (m != minor) {
1690 idr_remove(&_minor_idr, m);
1691 r = -EBUSY;
1692 goto out;
1693 }
1694
1695out:
f32c10b0 1696 spin_unlock(&_minor_lock);
1da177e4
LT
1697 return r;
1698}
1699
cf13ab8e 1700static int next_free_minor(int *minor)
1da177e4 1701{
2b06cfff 1702 int r, m;
1da177e4 1703
1da177e4 1704 r = idr_pre_get(&_minor_idr, GFP_KERNEL);
62f75c2f
JM
1705 if (!r)
1706 return -ENOMEM;
1707
f32c10b0 1708 spin_lock(&_minor_lock);
1da177e4 1709
ba61fdd1 1710 r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m);
cf13ab8e 1711 if (r)
1da177e4 1712 goto out;
1da177e4
LT
1713
1714 if (m >= (1 << MINORBITS)) {
1715 idr_remove(&_minor_idr, m);
1716 r = -ENOSPC;
1717 goto out;
1718 }
1719
1720 *minor = m;
1721
1722out:
f32c10b0 1723 spin_unlock(&_minor_lock);
1da177e4
LT
1724 return r;
1725}
1726
83d5cde4 1727static const struct block_device_operations dm_blk_dops;
1da177e4 1728
53d5914f
MP
1729static void dm_wq_work(struct work_struct *work);
1730
1da177e4
LT
1731/*
1732 * Allocate and initialise a blank device with a given minor.
1733 */
2b06cfff 1734static struct mapped_device *alloc_dev(int minor)
1da177e4
LT
1735{
1736 int r;
cf13ab8e 1737 struct mapped_device *md = kzalloc(sizeof(*md), GFP_KERNEL);
ba61fdd1 1738 void *old_md;
1da177e4
LT
1739
1740 if (!md) {
1741 DMWARN("unable to allocate device, out of memory.");
1742 return NULL;
1743 }
1744
10da4f79 1745 if (!try_module_get(THIS_MODULE))
6ed7ade8 1746 goto bad_module_get;
10da4f79 1747
1da177e4 1748 /* get a minor number for the dev */
2b06cfff 1749 if (minor == DM_ANY_MINOR)
cf13ab8e 1750 r = next_free_minor(&minor);
2b06cfff 1751 else
cf13ab8e 1752 r = specific_minor(minor);
1da177e4 1753 if (r < 0)
6ed7ade8 1754 goto bad_minor;
1da177e4 1755
2ca3310e 1756 init_rwsem(&md->io_lock);
e61290a4 1757 mutex_init(&md->suspend_lock);
022c2611 1758 spin_lock_init(&md->deferred_lock);
1da177e4
LT
1759 rwlock_init(&md->map_lock);
1760 atomic_set(&md->holders, 1);
5c6bd75d 1761 atomic_set(&md->open_count, 0);
1da177e4 1762 atomic_set(&md->event_nr, 0);
7a8c3d3b
MA
1763 atomic_set(&md->uevent_seq, 0);
1764 INIT_LIST_HEAD(&md->uevent_list);
1765 spin_lock_init(&md->uevent_lock);
1da177e4 1766
e6ee8c0b 1767 md->queue = blk_init_queue(dm_request_fn, NULL);
1da177e4 1768 if (!md->queue)
6ed7ade8 1769 goto bad_queue;
1da177e4 1770
e6ee8c0b
KU
1771 /*
1772 * Request-based dm devices cannot be stacked on top of bio-based dm
1773 * devices. The type of this dm device has not been decided yet,
1774 * although we initialized the queue using blk_init_queue().
1775 * The type is decided at the first table loading time.
1776 * To prevent problematic device stacking, clear the queue flag
1777 * for request stacking support until then.
1778 *
1779 * This queue is new, so no concurrency on the queue_flags.
1780 */
1781 queue_flag_clear_unlocked(QUEUE_FLAG_STACKABLE, md->queue);
1782 md->saved_make_request_fn = md->queue->make_request_fn;
1da177e4
LT
1783 md->queue->queuedata = md;
1784 md->queue->backing_dev_info.congested_fn = dm_any_congested;
1785 md->queue->backing_dev_info.congested_data = md;
1786 blk_queue_make_request(md->queue, dm_request);
daef265f 1787 blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
1da177e4 1788 md->queue->unplug_fn = dm_unplug_all;
f6fccb12 1789 blk_queue_merge_bvec(md->queue, dm_merge_bvec);
e6ee8c0b
KU
1790 blk_queue_softirq_done(md->queue, dm_softirq_done);
1791 blk_queue_prep_rq(md->queue, dm_prep_fn);
1792 blk_queue_lld_busy(md->queue, dm_lld_busy);
9faf400f 1793
1da177e4
LT
1794 md->disk = alloc_disk(1);
1795 if (!md->disk)
6ed7ade8 1796 goto bad_disk;
1da177e4 1797
316d315b
NK
1798 atomic_set(&md->pending[0], 0);
1799 atomic_set(&md->pending[1], 0);
f0b04115 1800 init_waitqueue_head(&md->wait);
53d5914f 1801 INIT_WORK(&md->work, dm_wq_work);
f0b04115
JM
1802 init_waitqueue_head(&md->eventq);
1803
1da177e4
LT
1804 md->disk->major = _major;
1805 md->disk->first_minor = minor;
1806 md->disk->fops = &dm_blk_dops;
1807 md->disk->queue = md->queue;
1808 md->disk->private_data = md;
1809 sprintf(md->disk->disk_name, "dm-%d", minor);
1810 add_disk(md->disk);
7e51f257 1811 format_dev_t(md->name, MKDEV(_major, minor));
1da177e4 1812
304f3f6a
MB
1813 md->wq = create_singlethread_workqueue("kdmflush");
1814 if (!md->wq)
1815 goto bad_thread;
1816
32a926da
MP
1817 md->bdev = bdget_disk(md->disk, 0);
1818 if (!md->bdev)
1819 goto bad_bdev;
1820
ba61fdd1 1821 /* Populate the mapping, nobody knows we exist yet */
f32c10b0 1822 spin_lock(&_minor_lock);
ba61fdd1 1823 old_md = idr_replace(&_minor_idr, md, minor);
f32c10b0 1824 spin_unlock(&_minor_lock);
ba61fdd1
JM
1825
1826 BUG_ON(old_md != MINOR_ALLOCED);
1827
1da177e4
LT
1828 return md;
1829
32a926da
MP
1830bad_bdev:
1831 destroy_workqueue(md->wq);
304f3f6a 1832bad_thread:
03022c54 1833 del_gendisk(md->disk);
304f3f6a 1834 put_disk(md->disk);
6ed7ade8 1835bad_disk:
1312f40e 1836 blk_cleanup_queue(md->queue);
6ed7ade8 1837bad_queue:
1da177e4 1838 free_minor(minor);
6ed7ade8 1839bad_minor:
10da4f79 1840 module_put(THIS_MODULE);
6ed7ade8 1841bad_module_get:
1da177e4
LT
1842 kfree(md);
1843 return NULL;
1844}
1845
ae9da83f
JN
1846static void unlock_fs(struct mapped_device *md);
1847
1da177e4
LT
1848static void free_dev(struct mapped_device *md)
1849{
f331c029 1850 int minor = MINOR(disk_devt(md->disk));
63d94e48 1851
32a926da
MP
1852 unlock_fs(md);
1853 bdput(md->bdev);
304f3f6a 1854 destroy_workqueue(md->wq);
e6ee8c0b
KU
1855 if (md->tio_pool)
1856 mempool_destroy(md->tio_pool);
1857 if (md->io_pool)
1858 mempool_destroy(md->io_pool);
1859 if (md->bs)
1860 bioset_free(md->bs);
9c47008d 1861 blk_integrity_unregister(md->disk);
1da177e4 1862 del_gendisk(md->disk);
63d94e48 1863 free_minor(minor);
fba9f90e
JM
1864
1865 spin_lock(&_minor_lock);
1866 md->disk->private_data = NULL;
1867 spin_unlock(&_minor_lock);
1868
1da177e4 1869 put_disk(md->disk);
1312f40e 1870 blk_cleanup_queue(md->queue);
10da4f79 1871 module_put(THIS_MODULE);
1da177e4
LT
1872 kfree(md);
1873}
1874
e6ee8c0b
KU
1875static void __bind_mempools(struct mapped_device *md, struct dm_table *t)
1876{
1877 struct dm_md_mempools *p;
1878
1879 if (md->io_pool && md->tio_pool && md->bs)
1880 /* the md already has necessary mempools */
1881 goto out;
1882
1883 p = dm_table_get_md_mempools(t);
1884 BUG_ON(!p || md->io_pool || md->tio_pool || md->bs);
1885
1886 md->io_pool = p->io_pool;
1887 p->io_pool = NULL;
1888 md->tio_pool = p->tio_pool;
1889 p->tio_pool = NULL;
1890 md->bs = p->bs;
1891 p->bs = NULL;
1892
1893out:
1894 /* mempool bind completed, now no need any mempools in the table */
1895 dm_table_free_md_mempools(t);
1896}
1897
1da177e4
LT
1898/*
1899 * Bind a table to the device.
1900 */
1901static void event_callback(void *context)
1902{
7a8c3d3b
MA
1903 unsigned long flags;
1904 LIST_HEAD(uevents);
1da177e4
LT
1905 struct mapped_device *md = (struct mapped_device *) context;
1906
7a8c3d3b
MA
1907 spin_lock_irqsave(&md->uevent_lock, flags);
1908 list_splice_init(&md->uevent_list, &uevents);
1909 spin_unlock_irqrestore(&md->uevent_lock, flags);
1910
ed9e1982 1911 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
7a8c3d3b 1912
1da177e4
LT
1913 atomic_inc(&md->event_nr);
1914 wake_up(&md->eventq);
1915}
1916
4e90188b 1917static void __set_size(struct mapped_device *md, sector_t size)
1da177e4 1918{
4e90188b 1919 set_capacity(md->disk, size);
1da177e4 1920
db8fef4f
MP
1921 mutex_lock(&md->bdev->bd_inode->i_mutex);
1922 i_size_write(md->bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
1923 mutex_unlock(&md->bdev->bd_inode->i_mutex);
1da177e4
LT
1924}
1925
754c5fc7
MS
1926static int __bind(struct mapped_device *md, struct dm_table *t,
1927 struct queue_limits *limits)
1da177e4 1928{
165125e1 1929 struct request_queue *q = md->queue;
1da177e4 1930 sector_t size;
523d9297 1931 unsigned long flags;
1da177e4
LT
1932
1933 size = dm_table_get_size(t);
3ac51e74
DW
1934
1935 /*
1936 * Wipe any geometry if the size of the table changed.
1937 */
1938 if (size != get_capacity(md->disk))
1939 memset(&md->geometry, 0, sizeof(md->geometry));
1940
32a926da 1941 __set_size(md, size);
d5816876
MP
1942
1943 if (!size) {
1944 dm_table_destroy(t);
1da177e4 1945 return 0;
d5816876 1946 }
1da177e4 1947
2ca3310e
AK
1948 dm_table_event_callback(t, event_callback, md);
1949
e6ee8c0b
KU
1950 /*
1951 * The queue hasn't been stopped yet, if the old table type wasn't
1952 * for request-based during suspension. So stop it to prevent
1953 * I/O mapping before resume.
1954 * This must be done before setting the queue restrictions,
1955 * because request-based dm may be run just after the setting.
1956 */
1957 if (dm_table_request_based(t) && !blk_queue_stopped(q))
1958 stop_queue(q);
1959
1960 __bind_mempools(md, t);
1961
523d9297 1962 write_lock_irqsave(&md->map_lock, flags);
1da177e4 1963 md->map = t;
754c5fc7 1964 dm_table_set_restrictions(t, q, limits);
523d9297 1965 write_unlock_irqrestore(&md->map_lock, flags);
1da177e4 1966
1da177e4
LT
1967 return 0;
1968}
1969
1970static void __unbind(struct mapped_device *md)
1971{
1972 struct dm_table *map = md->map;
523d9297 1973 unsigned long flags;
1da177e4
LT
1974
1975 if (!map)
1976 return;
1977
1978 dm_table_event_callback(map, NULL, NULL);
523d9297 1979 write_lock_irqsave(&md->map_lock, flags);
1da177e4 1980 md->map = NULL;
523d9297 1981 write_unlock_irqrestore(&md->map_lock, flags);
d5816876 1982 dm_table_destroy(map);
1da177e4
LT
1983}
1984
1985/*
1986 * Constructor for a new device.
1987 */
2b06cfff 1988int dm_create(int minor, struct mapped_device **result)
1da177e4
LT
1989{
1990 struct mapped_device *md;
1991
2b06cfff 1992 md = alloc_dev(minor);
1da177e4
LT
1993 if (!md)
1994 return -ENXIO;
1995
784aae73
MB
1996 dm_sysfs_init(md);
1997
1da177e4
LT
1998 *result = md;
1999 return 0;
2000}
2001
637842cf 2002static struct mapped_device *dm_find_md(dev_t dev)
1da177e4
LT
2003{
2004 struct mapped_device *md;
1da177e4
LT
2005 unsigned minor = MINOR(dev);
2006
2007 if (MAJOR(dev) != _major || minor >= (1 << MINORBITS))
2008 return NULL;
2009
f32c10b0 2010 spin_lock(&_minor_lock);
1da177e4
LT
2011
2012 md = idr_find(&_minor_idr, minor);
fba9f90e 2013 if (md && (md == MINOR_ALLOCED ||
f331c029 2014 (MINOR(disk_devt(dm_disk(md))) != minor) ||
17b2f66f 2015 test_bit(DMF_FREEING, &md->flags))) {
637842cf 2016 md = NULL;
fba9f90e
JM
2017 goto out;
2018 }
1da177e4 2019
fba9f90e 2020out:
f32c10b0 2021 spin_unlock(&_minor_lock);
1da177e4 2022
637842cf
DT
2023 return md;
2024}
2025
d229a958
DT
2026struct mapped_device *dm_get_md(dev_t dev)
2027{
2028 struct mapped_device *md = dm_find_md(dev);
2029
2030 if (md)
2031 dm_get(md);
2032
2033 return md;
2034}
2035
9ade92a9 2036void *dm_get_mdptr(struct mapped_device *md)
637842cf 2037{
9ade92a9 2038 return md->interface_ptr;
1da177e4
LT
2039}
2040
2041void dm_set_mdptr(struct mapped_device *md, void *ptr)
2042{
2043 md->interface_ptr = ptr;
2044}
2045
2046void dm_get(struct mapped_device *md)
2047{
2048 atomic_inc(&md->holders);
2049}
2050
72d94861
AK
2051const char *dm_device_name(struct mapped_device *md)
2052{
2053 return md->name;
2054}
2055EXPORT_SYMBOL_GPL(dm_device_name);
2056
1da177e4
LT
2057void dm_put(struct mapped_device *md)
2058{
1134e5ae 2059 struct dm_table *map;
1da177e4 2060
fba9f90e
JM
2061 BUG_ON(test_bit(DMF_FREEING, &md->flags));
2062
f32c10b0 2063 if (atomic_dec_and_lock(&md->holders, &_minor_lock)) {
1134e5ae 2064 map = dm_get_table(md);
f331c029
TH
2065 idr_replace(&_minor_idr, MINOR_ALLOCED,
2066 MINOR(disk_devt(dm_disk(md))));
fba9f90e 2067 set_bit(DMF_FREEING, &md->flags);
f32c10b0 2068 spin_unlock(&_minor_lock);
cf222b37 2069 if (!dm_suspended(md)) {
1da177e4
LT
2070 dm_table_presuspend_targets(map);
2071 dm_table_postsuspend_targets(map);
2072 }
784aae73 2073 dm_sysfs_exit(md);
1134e5ae 2074 dm_table_put(map);
a1b51e98 2075 __unbind(md);
1da177e4
LT
2076 free_dev(md);
2077 }
1da177e4 2078}
79eb885c 2079EXPORT_SYMBOL_GPL(dm_put);
1da177e4 2080
401600df 2081static int dm_wait_for_completion(struct mapped_device *md, int interruptible)
46125c1c
MB
2082{
2083 int r = 0;
b44ebeb0 2084 DECLARE_WAITQUEUE(wait, current);
cec47e3d
KU
2085 struct request_queue *q = md->queue;
2086 unsigned long flags;
b44ebeb0
MP
2087
2088 dm_unplug_all(md->queue);
2089
2090 add_wait_queue(&md->wait, &wait);
46125c1c
MB
2091
2092 while (1) {
401600df 2093 set_current_state(interruptible);
46125c1c
MB
2094
2095 smp_mb();
cec47e3d
KU
2096 if (dm_request_based(md)) {
2097 spin_lock_irqsave(q->queue_lock, flags);
2098 if (!queue_in_flight(q) && blk_queue_stopped(q)) {
2099 spin_unlock_irqrestore(q->queue_lock, flags);
2100 break;
2101 }
2102 spin_unlock_irqrestore(q->queue_lock, flags);
316d315b
NK
2103 } else if (!atomic_read(&md->pending[0]) &&
2104 !atomic_read(&md->pending[1]))
46125c1c
MB
2105 break;
2106
401600df
MP
2107 if (interruptible == TASK_INTERRUPTIBLE &&
2108 signal_pending(current)) {
46125c1c
MB
2109 r = -EINTR;
2110 break;
2111 }
2112
2113 io_schedule();
2114 }
2115 set_current_state(TASK_RUNNING);
2116
b44ebeb0
MP
2117 remove_wait_queue(&md->wait, &wait);
2118
46125c1c
MB
2119 return r;
2120}
2121
531fe963 2122static void dm_flush(struct mapped_device *md)
af7e466a
MP
2123{
2124 dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE);
52b1fd5a
MP
2125
2126 bio_init(&md->barrier_bio);
2127 md->barrier_bio.bi_bdev = md->bdev;
2128 md->barrier_bio.bi_rw = WRITE_BARRIER;
2129 __split_and_process_bio(md, &md->barrier_bio);
2130
2131 dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE);
af7e466a
MP
2132}
2133
2134static void process_barrier(struct mapped_device *md, struct bio *bio)
2135{
5aa2781d
MP
2136 md->barrier_error = 0;
2137
531fe963 2138 dm_flush(md);
af7e466a 2139
5aa2781d
MP
2140 if (!bio_empty_barrier(bio)) {
2141 __split_and_process_bio(md, bio);
2142 dm_flush(md);
af7e466a
MP
2143 }
2144
af7e466a 2145 if (md->barrier_error != DM_ENDIO_REQUEUE)
531fe963 2146 bio_endio(bio, md->barrier_error);
2761e95f
MP
2147 else {
2148 spin_lock_irq(&md->deferred_lock);
2149 bio_list_add_head(&md->deferred, bio);
2150 spin_unlock_irq(&md->deferred_lock);
2151 }
af7e466a
MP
2152}
2153
1da177e4
LT
2154/*
2155 * Process the deferred bios
2156 */
ef208587 2157static void dm_wq_work(struct work_struct *work)
1da177e4 2158{
ef208587
MP
2159 struct mapped_device *md = container_of(work, struct mapped_device,
2160 work);
6d6f10df 2161 struct bio *c;
1da177e4 2162
ef208587
MP
2163 down_write(&md->io_lock);
2164
3b00b203 2165 while (!test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) {
df12ee99
AK
2166 spin_lock_irq(&md->deferred_lock);
2167 c = bio_list_pop(&md->deferred);
2168 spin_unlock_irq(&md->deferred_lock);
2169
2170 if (!c) {
1eb787ec 2171 clear_bit(DMF_QUEUE_IO_TO_THREAD, &md->flags);
df12ee99
AK
2172 break;
2173 }
022c2611 2174
3b00b203
MP
2175 up_write(&md->io_lock);
2176
e6ee8c0b
KU
2177 if (dm_request_based(md))
2178 generic_make_request(c);
2179 else {
1f98a13f 2180 if (bio_rw_flagged(c, BIO_RW_BARRIER))
e6ee8c0b
KU
2181 process_barrier(md, c);
2182 else
2183 __split_and_process_bio(md, c);
2184 }
3b00b203
MP
2185
2186 down_write(&md->io_lock);
022c2611 2187 }
73d410c0 2188
ef208587 2189 up_write(&md->io_lock);
1da177e4
LT
2190}
2191
9a1fb464 2192static void dm_queue_flush(struct mapped_device *md)
304f3f6a 2193{
3b00b203
MP
2194 clear_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags);
2195 smp_mb__after_clear_bit();
53d5914f 2196 queue_work(md->wq, &md->work);
304f3f6a
MB
2197}
2198
1da177e4
LT
2199/*
2200 * Swap in a new table (destroying old one).
2201 */
2202int dm_swap_table(struct mapped_device *md, struct dm_table *table)
2203{
754c5fc7 2204 struct queue_limits limits;
93c534ae 2205 int r = -EINVAL;
1da177e4 2206
e61290a4 2207 mutex_lock(&md->suspend_lock);
1da177e4
LT
2208
2209 /* device must be suspended */
cf222b37 2210 if (!dm_suspended(md))
93c534ae 2211 goto out;
1da177e4 2212
754c5fc7
MS
2213 r = dm_calculate_queue_limits(table, &limits);
2214 if (r)
2215 goto out;
2216
e6ee8c0b
KU
2217 /* cannot change the device type, once a table is bound */
2218 if (md->map &&
2219 (dm_table_get_type(md->map) != dm_table_get_type(table))) {
2220 DMWARN("can't change the device type after a table is bound");
2221 goto out;
2222 }
2223
1da177e4 2224 __unbind(md);
754c5fc7 2225 r = __bind(md, table, &limits);
1da177e4 2226
93c534ae 2227out:
e61290a4 2228 mutex_unlock(&md->suspend_lock);
93c534ae 2229 return r;
1da177e4
LT
2230}
2231
cec47e3d
KU
2232static void dm_rq_invalidate_suspend_marker(struct mapped_device *md)
2233{
2234 md->suspend_rq.special = (void *)0x1;
2235}
2236
2237static void dm_rq_abort_suspend(struct mapped_device *md, int noflush)
2238{
2239 struct request_queue *q = md->queue;
2240 unsigned long flags;
2241
2242 spin_lock_irqsave(q->queue_lock, flags);
2243 if (!noflush)
2244 dm_rq_invalidate_suspend_marker(md);
2245 __start_queue(q);
2246 spin_unlock_irqrestore(q->queue_lock, flags);
2247}
2248
2249static void dm_rq_start_suspend(struct mapped_device *md, int noflush)
2250{
2251 struct request *rq = &md->suspend_rq;
2252 struct request_queue *q = md->queue;
2253
2254 if (noflush)
2255 stop_queue(q);
2256 else {
2257 blk_rq_init(q, rq);
2258 blk_insert_request(q, rq, 0, NULL);
2259 }
2260}
2261
2262static int dm_rq_suspend_available(struct mapped_device *md, int noflush)
2263{
2264 int r = 1;
2265 struct request *rq = &md->suspend_rq;
2266 struct request_queue *q = md->queue;
2267 unsigned long flags;
2268
2269 if (noflush)
2270 return r;
2271
2272 /* The marker must be protected by queue lock if it is in use */
2273 spin_lock_irqsave(q->queue_lock, flags);
2274 if (unlikely(rq->ref_count)) {
2275 /*
2276 * This can happen, when the previous flush suspend was
2277 * interrupted, the marker is still in the queue and
2278 * this flush suspend has been invoked, because we don't
2279 * remove the marker at the time of suspend interruption.
2280 * We have only one marker per mapped_device, so we can't
2281 * start another flush suspend while it is in use.
2282 */
2283 BUG_ON(!rq->special); /* The marker should be invalidated */
2284 DMWARN("Invalidating the previous flush suspend is still in"
2285 " progress. Please retry later.");
2286 r = 0;
2287 }
2288 spin_unlock_irqrestore(q->queue_lock, flags);
2289
2290 return r;
2291}
2292
1da177e4
LT
2293/*
2294 * Functions to lock and unlock any filesystem running on the
2295 * device.
2296 */
2ca3310e 2297static int lock_fs(struct mapped_device *md)
1da177e4 2298{
e39e2e95 2299 int r;
1da177e4
LT
2300
2301 WARN_ON(md->frozen_sb);
dfbe03f6 2302
db8fef4f 2303 md->frozen_sb = freeze_bdev(md->bdev);
dfbe03f6 2304 if (IS_ERR(md->frozen_sb)) {
cf222b37 2305 r = PTR_ERR(md->frozen_sb);
e39e2e95
AK
2306 md->frozen_sb = NULL;
2307 return r;
dfbe03f6
AK
2308 }
2309
aa8d7c2f
AK
2310 set_bit(DMF_FROZEN, &md->flags);
2311
1da177e4
LT
2312 return 0;
2313}
2314
2ca3310e 2315static void unlock_fs(struct mapped_device *md)
1da177e4 2316{
aa8d7c2f
AK
2317 if (!test_bit(DMF_FROZEN, &md->flags))
2318 return;
2319
db8fef4f 2320 thaw_bdev(md->bdev, md->frozen_sb);
1da177e4 2321 md->frozen_sb = NULL;
aa8d7c2f 2322 clear_bit(DMF_FROZEN, &md->flags);
1da177e4
LT
2323}
2324
2325/*
2326 * We need to be able to change a mapping table under a mounted
2327 * filesystem. For example we might want to move some data in
2328 * the background. Before the table can be swapped with
2329 * dm_bind_table, dm_suspend must be called to flush any in
2330 * flight bios and ensure that any further io gets deferred.
2331 */
cec47e3d
KU
2332/*
2333 * Suspend mechanism in request-based dm.
2334 *
2335 * After the suspend starts, further incoming requests are kept in
2336 * the request_queue and deferred.
2337 * Remaining requests in the request_queue at the start of suspend are flushed
2338 * if it is flush suspend.
2339 * The suspend completes when the following conditions have been satisfied,
2340 * so wait for it:
2341 * 1. q->in_flight is 0 (which means no in_flight request)
2342 * 2. queue has been stopped (which means no request dispatching)
2343 *
2344 *
2345 * Noflush suspend
2346 * ---------------
2347 * Noflush suspend doesn't need to dispatch remaining requests.
2348 * So stop the queue immediately. Then, wait for all in_flight requests
2349 * to be completed or requeued.
2350 *
2351 * To abort noflush suspend, start the queue.
2352 *
2353 *
2354 * Flush suspend
2355 * -------------
2356 * Flush suspend needs to dispatch remaining requests. So stop the queue
2357 * after the remaining requests are completed. (Requeued request must be also
2358 * re-dispatched and completed. Until then, we can't stop the queue.)
2359 *
2360 * During flushing the remaining requests, further incoming requests are also
2361 * inserted to the same queue. To distinguish which requests are to be
2362 * flushed, we insert a marker request to the queue at the time of starting
2363 * flush suspend, like a barrier.
2364 * The dispatching is blocked when the marker is found on the top of the queue.
2365 * And the queue is stopped when all in_flight requests are completed, since
2366 * that means the remaining requests are completely flushed.
2367 * Then, the marker is removed from the queue.
2368 *
2369 * To abort flush suspend, we also need to take care of the marker, not only
2370 * starting the queue.
2371 * We don't remove the marker forcibly from the queue since it's against
2372 * the block-layer manner. Instead, we put a invalidated mark on the marker.
2373 * When the invalidated marker is found on the top of the queue, it is
2374 * immediately removed from the queue, so it doesn't block dispatching.
2375 * Because we have only one marker per mapped_device, we can't start another
2376 * flush suspend until the invalidated marker is removed from the queue.
2377 * So fail and return with -EBUSY in such a case.
2378 */
a3d77d35 2379int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
1da177e4 2380{
2ca3310e 2381 struct dm_table *map = NULL;
46125c1c 2382 int r = 0;
a3d77d35 2383 int do_lockfs = suspend_flags & DM_SUSPEND_LOCKFS_FLAG ? 1 : 0;
2e93ccc1 2384 int noflush = suspend_flags & DM_SUSPEND_NOFLUSH_FLAG ? 1 : 0;
1da177e4 2385
e61290a4 2386 mutex_lock(&md->suspend_lock);
2ca3310e 2387
73d410c0
MB
2388 if (dm_suspended(md)) {
2389 r = -EINVAL;
d287483d 2390 goto out_unlock;
73d410c0 2391 }
1da177e4 2392
cec47e3d
KU
2393 if (dm_request_based(md) && !dm_rq_suspend_available(md, noflush)) {
2394 r = -EBUSY;
2395 goto out_unlock;
2396 }
2397
1da177e4 2398 map = dm_get_table(md);
1da177e4 2399
2e93ccc1
KU
2400 /*
2401 * DMF_NOFLUSH_SUSPENDING must be set before presuspend.
2402 * This flag is cleared before dm_suspend returns.
2403 */
2404 if (noflush)
2405 set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
2406
cf222b37
AK
2407 /* This does not get reverted if there's an error later. */
2408 dm_table_presuspend_targets(map);
2409
32a926da
MP
2410 /*
2411 * Flush I/O to the device. noflush supersedes do_lockfs,
2412 * because lock_fs() needs to flush I/Os.
2413 */
2414 if (!noflush && do_lockfs) {
2415 r = lock_fs(md);
2416 if (r)
f431d966 2417 goto out;
aa8d7c2f 2418 }
1da177e4
LT
2419
2420 /*
3b00b203
MP
2421 * Here we must make sure that no processes are submitting requests
2422 * to target drivers i.e. no one may be executing
2423 * __split_and_process_bio. This is called from dm_request and
2424 * dm_wq_work.
2425 *
2426 * To get all processes out of __split_and_process_bio in dm_request,
2427 * we take the write lock. To prevent any process from reentering
2428 * __split_and_process_bio from dm_request, we set
2429 * DMF_QUEUE_IO_TO_THREAD.
2430 *
2431 * To quiesce the thread (dm_wq_work), we set DMF_BLOCK_IO_FOR_SUSPEND
2432 * and call flush_workqueue(md->wq). flush_workqueue will wait until
2433 * dm_wq_work exits and DMF_BLOCK_IO_FOR_SUSPEND will prevent any
2434 * further calls to __split_and_process_bio from dm_wq_work.
1da177e4 2435 */
2ca3310e 2436 down_write(&md->io_lock);
1eb787ec
AK
2437 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags);
2438 set_bit(DMF_QUEUE_IO_TO_THREAD, &md->flags);
2ca3310e 2439 up_write(&md->io_lock);
1da177e4 2440
3b00b203
MP
2441 flush_workqueue(md->wq);
2442
cec47e3d
KU
2443 if (dm_request_based(md))
2444 dm_rq_start_suspend(md, noflush);
2445
1da177e4 2446 /*
3b00b203
MP
2447 * At this point no more requests are entering target request routines.
2448 * We call dm_wait_for_completion to wait for all existing requests
2449 * to finish.
1da177e4 2450 */
401600df 2451 r = dm_wait_for_completion(md, TASK_INTERRUPTIBLE);
1da177e4 2452
2ca3310e 2453 down_write(&md->io_lock);
6d6f10df 2454 if (noflush)
022c2611 2455 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
94d6351e 2456 up_write(&md->io_lock);
2e93ccc1 2457
1da177e4 2458 /* were we interrupted ? */
46125c1c 2459 if (r < 0) {
9a1fb464 2460 dm_queue_flush(md);
73d410c0 2461
cec47e3d
KU
2462 if (dm_request_based(md))
2463 dm_rq_abort_suspend(md, noflush);
2464
2ca3310e 2465 unlock_fs(md);
2e93ccc1 2466 goto out; /* pushback list is already flushed, so skip flush */
2ca3310e 2467 }
1da177e4 2468
3b00b203
MP
2469 /*
2470 * If dm_wait_for_completion returned 0, the device is completely
2471 * quiescent now. There is no request-processing activity. All new
2472 * requests are being added to md->deferred list.
2473 */
2474
cf222b37 2475 dm_table_postsuspend_targets(map);
1da177e4 2476
2ca3310e 2477 set_bit(DMF_SUSPENDED, &md->flags);
b84b0287 2478
2ca3310e
AK
2479out:
2480 dm_table_put(map);
d287483d
AK
2481
2482out_unlock:
e61290a4 2483 mutex_unlock(&md->suspend_lock);
cf222b37 2484 return r;
1da177e4
LT
2485}
2486
2487int dm_resume(struct mapped_device *md)
2488{
cf222b37 2489 int r = -EINVAL;
cf222b37 2490 struct dm_table *map = NULL;
1da177e4 2491
e61290a4 2492 mutex_lock(&md->suspend_lock);
2ca3310e 2493 if (!dm_suspended(md))
cf222b37 2494 goto out;
cf222b37
AK
2495
2496 map = dm_get_table(md);
2ca3310e 2497 if (!map || !dm_table_get_size(map))
cf222b37 2498 goto out;
1da177e4 2499
8757b776
MB
2500 r = dm_table_resume_targets(map);
2501 if (r)
2502 goto out;
2ca3310e 2503
9a1fb464 2504 dm_queue_flush(md);
2ca3310e 2505
cec47e3d
KU
2506 /*
2507 * Flushing deferred I/Os must be done after targets are resumed
2508 * so that mapping of targets can work correctly.
2509 * Request-based dm is queueing the deferred I/Os in its request_queue.
2510 */
2511 if (dm_request_based(md))
2512 start_queue(md->queue);
2513
2ca3310e
AK
2514 unlock_fs(md);
2515
2516 clear_bit(DMF_SUSPENDED, &md->flags);
2517
1da177e4 2518 dm_table_unplug_all(map);
cf222b37
AK
2519 r = 0;
2520out:
2521 dm_table_put(map);
e61290a4 2522 mutex_unlock(&md->suspend_lock);
2ca3310e 2523
cf222b37 2524 return r;
1da177e4
LT
2525}
2526
2527/*-----------------------------------------------------------------
2528 * Event notification.
2529 *---------------------------------------------------------------*/
60935eb2
MB
2530void dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
2531 unsigned cookie)
69267a30 2532{
60935eb2
MB
2533 char udev_cookie[DM_COOKIE_LENGTH];
2534 char *envp[] = { udev_cookie, NULL };
2535
2536 if (!cookie)
2537 kobject_uevent(&disk_to_dev(md->disk)->kobj, action);
2538 else {
2539 snprintf(udev_cookie, DM_COOKIE_LENGTH, "%s=%u",
2540 DM_COOKIE_ENV_VAR_NAME, cookie);
2541 kobject_uevent_env(&disk_to_dev(md->disk)->kobj, action, envp);
2542 }
69267a30
AK
2543}
2544
7a8c3d3b
MA
2545uint32_t dm_next_uevent_seq(struct mapped_device *md)
2546{
2547 return atomic_add_return(1, &md->uevent_seq);
2548}
2549
1da177e4
LT
2550uint32_t dm_get_event_nr(struct mapped_device *md)
2551{
2552 return atomic_read(&md->event_nr);
2553}
2554
2555int dm_wait_event(struct mapped_device *md, int event_nr)
2556{
2557 return wait_event_interruptible(md->eventq,
2558 (event_nr != atomic_read(&md->event_nr)));
2559}
2560
7a8c3d3b
MA
2561void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
2562{
2563 unsigned long flags;
2564
2565 spin_lock_irqsave(&md->uevent_lock, flags);
2566 list_add(elist, &md->uevent_list);
2567 spin_unlock_irqrestore(&md->uevent_lock, flags);
2568}
2569
1da177e4
LT
2570/*
2571 * The gendisk is only valid as long as you have a reference
2572 * count on 'md'.
2573 */
2574struct gendisk *dm_disk(struct mapped_device *md)
2575{
2576 return md->disk;
2577}
2578
784aae73
MB
2579struct kobject *dm_kobject(struct mapped_device *md)
2580{
2581 return &md->kobj;
2582}
2583
2584/*
2585 * struct mapped_device should not be exported outside of dm.c
2586 * so use this check to verify that kobj is part of md structure
2587 */
2588struct mapped_device *dm_get_from_kobject(struct kobject *kobj)
2589{
2590 struct mapped_device *md;
2591
2592 md = container_of(kobj, struct mapped_device, kobj);
2593 if (&md->kobj != kobj)
2594 return NULL;
2595
4d89b7b4
MB
2596 if (test_bit(DMF_FREEING, &md->flags) ||
2597 test_bit(DMF_DELETING, &md->flags))
2598 return NULL;
2599
784aae73
MB
2600 dm_get(md);
2601 return md;
2602}
2603
1da177e4
LT
2604int dm_suspended(struct mapped_device *md)
2605{
2606 return test_bit(DMF_SUSPENDED, &md->flags);
2607}
2608
2e93ccc1
KU
2609int dm_noflush_suspending(struct dm_target *ti)
2610{
2611 struct mapped_device *md = dm_table_get_md(ti->table);
2612 int r = __noflush_suspending(md);
2613
2614 dm_put(md);
2615
2616 return r;
2617}
2618EXPORT_SYMBOL_GPL(dm_noflush_suspending);
2619
e6ee8c0b
KU
2620struct dm_md_mempools *dm_alloc_md_mempools(unsigned type)
2621{
2622 struct dm_md_mempools *pools = kmalloc(sizeof(*pools), GFP_KERNEL);
2623
2624 if (!pools)
2625 return NULL;
2626
2627 pools->io_pool = (type == DM_TYPE_BIO_BASED) ?
2628 mempool_create_slab_pool(MIN_IOS, _io_cache) :
2629 mempool_create_slab_pool(MIN_IOS, _rq_bio_info_cache);
2630 if (!pools->io_pool)
2631 goto free_pools_and_out;
2632
2633 pools->tio_pool = (type == DM_TYPE_BIO_BASED) ?
2634 mempool_create_slab_pool(MIN_IOS, _tio_cache) :
2635 mempool_create_slab_pool(MIN_IOS, _rq_tio_cache);
2636 if (!pools->tio_pool)
2637 goto free_io_pool_and_out;
2638
2639 pools->bs = (type == DM_TYPE_BIO_BASED) ?
2640 bioset_create(16, 0) : bioset_create(MIN_IOS, 0);
2641 if (!pools->bs)
2642 goto free_tio_pool_and_out;
2643
2644 return pools;
2645
2646free_tio_pool_and_out:
2647 mempool_destroy(pools->tio_pool);
2648
2649free_io_pool_and_out:
2650 mempool_destroy(pools->io_pool);
2651
2652free_pools_and_out:
2653 kfree(pools);
2654
2655 return NULL;
2656}
2657
2658void dm_free_md_mempools(struct dm_md_mempools *pools)
2659{
2660 if (!pools)
2661 return;
2662
2663 if (pools->io_pool)
2664 mempool_destroy(pools->io_pool);
2665
2666 if (pools->tio_pool)
2667 mempool_destroy(pools->tio_pool);
2668
2669 if (pools->bs)
2670 bioset_free(pools->bs);
2671
2672 kfree(pools);
2673}
2674
83d5cde4 2675static const struct block_device_operations dm_blk_dops = {
1da177e4
LT
2676 .open = dm_blk_open,
2677 .release = dm_blk_close,
aa129a22 2678 .ioctl = dm_blk_ioctl,
3ac51e74 2679 .getgeo = dm_blk_getgeo,
1da177e4
LT
2680 .owner = THIS_MODULE
2681};
2682
2683EXPORT_SYMBOL(dm_get_mapinfo);
2684
2685/*
2686 * module hooks
2687 */
2688module_init(dm_init);
2689module_exit(dm_exit);
2690
2691module_param(major, uint, 0);
2692MODULE_PARM_DESC(major, "The major number of the device mapper");
2693MODULE_DESCRIPTION(DM_NAME " driver");
2694MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
2695MODULE_LICENSE("GPL");
This page took 0.752681 seconds and 5 git commands to generate.