dm.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  1. /*
  2. * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This file is released under the GPL.
  6. */
  7. #include "dm.h"
  8. #include "dm-bio-list.h"
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/mutex.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/blkpg.h>
  14. #include <linux/bio.h>
  15. #include <linux/buffer_head.h>
  16. #include <linux/mempool.h>
  17. #include <linux/slab.h>
  18. #include <linux/idr.h>
  19. #include <linux/hdreg.h>
  20. #include <linux/blktrace_api.h>
  21. #include <linux/smp_lock.h>
  22. #define DM_MSG_PREFIX "core"
  23. static const char *_name = DM_NAME;
  24. static unsigned int major = 0;
  25. static unsigned int _major = 0;
  26. static DEFINE_SPINLOCK(_minor_lock);
  27. /*
  28. * One of these is allocated per bio.
  29. */
  30. struct dm_io {
  31. struct mapped_device *md;
  32. int error;
  33. struct bio *bio;
  34. atomic_t io_count;
  35. unsigned long start_time;
  36. };
  37. /*
  38. * One of these is allocated per target within a bio. Hopefully
  39. * this will be simplified out one day.
  40. */
  41. struct dm_target_io {
  42. struct dm_io *io;
  43. struct dm_target *ti;
  44. union map_info info;
  45. };
  46. union map_info *dm_get_mapinfo(struct bio *bio)
  47. {
  48. if (bio && bio->bi_private)
  49. return &((struct dm_target_io *)bio->bi_private)->info;
  50. return NULL;
  51. }
  52. #define MINOR_ALLOCED ((void *)-1)
  53. /*
  54. * Bits for the md->flags field.
  55. */
  56. #define DMF_BLOCK_IO 0
  57. #define DMF_SUSPENDED 1
  58. #define DMF_FROZEN 2
  59. #define DMF_FREEING 3
  60. #define DMF_DELETING 4
  61. #define DMF_NOFLUSH_SUSPENDING 5
  62. struct mapped_device {
  63. struct rw_semaphore io_lock;
  64. struct semaphore suspend_lock;
  65. spinlock_t pushback_lock;
  66. rwlock_t map_lock;
  67. atomic_t holders;
  68. atomic_t open_count;
  69. unsigned long flags;
  70. struct request_queue *queue;
  71. struct gendisk *disk;
  72. char name[16];
  73. void *interface_ptr;
  74. /*
  75. * A list of ios that arrived while we were suspended.
  76. */
  77. atomic_t pending;
  78. wait_queue_head_t wait;
  79. struct bio_list deferred;
  80. struct bio_list pushback;
  81. /*
  82. * The current mapping.
  83. */
  84. struct dm_table *map;
  85. /*
  86. * io objects are allocated from here.
  87. */
  88. mempool_t *io_pool;
  89. mempool_t *tio_pool;
  90. struct bio_set *bs;
  91. /*
  92. * Event handling.
  93. */
  94. atomic_t event_nr;
  95. wait_queue_head_t eventq;
  96. /*
  97. * freeze/thaw support require holding onto a super block
  98. */
  99. struct super_block *frozen_sb;
  100. struct block_device *suspended_bdev;
  101. /* forced geometry settings */
  102. struct hd_geometry geometry;
  103. };
  104. #define MIN_IOS 256
  105. static struct kmem_cache *_io_cache;
  106. static struct kmem_cache *_tio_cache;
  107. static int __init local_init(void)
  108. {
  109. int r;
  110. /* allocate a slab for the dm_ios */
  111. _io_cache = KMEM_CACHE(dm_io, 0);
  112. if (!_io_cache)
  113. return -ENOMEM;
  114. /* allocate a slab for the target ios */
  115. _tio_cache = KMEM_CACHE(dm_target_io, 0);
  116. if (!_tio_cache) {
  117. kmem_cache_destroy(_io_cache);
  118. return -ENOMEM;
  119. }
  120. _major = major;
  121. r = register_blkdev(_major, _name);
  122. if (r < 0) {
  123. kmem_cache_destroy(_tio_cache);
  124. kmem_cache_destroy(_io_cache);
  125. return r;
  126. }
  127. if (!_major)
  128. _major = r;
  129. return 0;
  130. }
  131. static void local_exit(void)
  132. {
  133. kmem_cache_destroy(_tio_cache);
  134. kmem_cache_destroy(_io_cache);
  135. unregister_blkdev(_major, _name);
  136. _major = 0;
  137. DMINFO("cleaned up");
  138. }
  139. int (*_inits[])(void) __initdata = {
  140. local_init,
  141. dm_target_init,
  142. dm_linear_init,
  143. dm_stripe_init,
  144. dm_interface_init,
  145. };
  146. void (*_exits[])(void) = {
  147. local_exit,
  148. dm_target_exit,
  149. dm_linear_exit,
  150. dm_stripe_exit,
  151. dm_interface_exit,
  152. };
  153. static int __init dm_init(void)
  154. {
  155. const int count = ARRAY_SIZE(_inits);
  156. int r, i;
  157. for (i = 0; i < count; i++) {
  158. r = _inits[i]();
  159. if (r)
  160. goto bad;
  161. }
  162. return 0;
  163. bad:
  164. while (i--)
  165. _exits[i]();
  166. return r;
  167. }
  168. static void __exit dm_exit(void)
  169. {
  170. int i = ARRAY_SIZE(_exits);
  171. while (i--)
  172. _exits[i]();
  173. }
  174. /*
  175. * Block device functions
  176. */
  177. static int dm_blk_open(struct inode *inode, struct file *file)
  178. {
  179. struct mapped_device *md;
  180. spin_lock(&_minor_lock);
  181. md = inode->i_bdev->bd_disk->private_data;
  182. if (!md)
  183. goto out;
  184. if (test_bit(DMF_FREEING, &md->flags) ||
  185. test_bit(DMF_DELETING, &md->flags)) {
  186. md = NULL;
  187. goto out;
  188. }
  189. dm_get(md);
  190. atomic_inc(&md->open_count);
  191. out:
  192. spin_unlock(&_minor_lock);
  193. return md ? 0 : -ENXIO;
  194. }
  195. static int dm_blk_close(struct inode *inode, struct file *file)
  196. {
  197. struct mapped_device *md;
  198. md = inode->i_bdev->bd_disk->private_data;
  199. atomic_dec(&md->open_count);
  200. dm_put(md);
  201. return 0;
  202. }
  203. int dm_open_count(struct mapped_device *md)
  204. {
  205. return atomic_read(&md->open_count);
  206. }
  207. /*
  208. * Guarantees nothing is using the device before it's deleted.
  209. */
  210. int dm_lock_for_deletion(struct mapped_device *md)
  211. {
  212. int r = 0;
  213. spin_lock(&_minor_lock);
  214. if (dm_open_count(md))
  215. r = -EBUSY;
  216. else
  217. set_bit(DMF_DELETING, &md->flags);
  218. spin_unlock(&_minor_lock);
  219. return r;
  220. }
  221. static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  222. {
  223. struct mapped_device *md = bdev->bd_disk->private_data;
  224. return dm_get_geometry(md, geo);
  225. }
  226. static int dm_blk_ioctl(struct inode *inode, struct file *file,
  227. unsigned int cmd, unsigned long arg)
  228. {
  229. struct mapped_device *md;
  230. struct dm_table *map;
  231. struct dm_target *tgt;
  232. int r = -ENOTTY;
  233. /* We don't really need this lock, but we do need 'inode'. */
  234. unlock_kernel();
  235. md = inode->i_bdev->bd_disk->private_data;
  236. map = dm_get_table(md);
  237. if (!map || !dm_table_get_size(map))
  238. goto out;
  239. /* We only support devices that have a single target */
  240. if (dm_table_get_num_targets(map) != 1)
  241. goto out;
  242. tgt = dm_table_get_target(map, 0);
  243. if (dm_suspended(md)) {
  244. r = -EAGAIN;
  245. goto out;
  246. }
  247. if (tgt->type->ioctl)
  248. r = tgt->type->ioctl(tgt, inode, file, cmd, arg);
  249. out:
  250. dm_table_put(map);
  251. lock_kernel();
  252. return r;
  253. }
  254. static struct dm_io *alloc_io(struct mapped_device *md)
  255. {
  256. return mempool_alloc(md->io_pool, GFP_NOIO);
  257. }
  258. static void free_io(struct mapped_device *md, struct dm_io *io)
  259. {
  260. mempool_free(io, md->io_pool);
  261. }
  262. static struct dm_target_io *alloc_tio(struct mapped_device *md)
  263. {
  264. return mempool_alloc(md->tio_pool, GFP_NOIO);
  265. }
  266. static void free_tio(struct mapped_device *md, struct dm_target_io *tio)
  267. {
  268. mempool_free(tio, md->tio_pool);
  269. }
  270. static void start_io_acct(struct dm_io *io)
  271. {
  272. struct mapped_device *md = io->md;
  273. io->start_time = jiffies;
  274. preempt_disable();
  275. disk_round_stats(dm_disk(md));
  276. preempt_enable();
  277. dm_disk(md)->in_flight = atomic_inc_return(&md->pending);
  278. }
  279. static int end_io_acct(struct dm_io *io)
  280. {
  281. struct mapped_device *md = io->md;
  282. struct bio *bio = io->bio;
  283. unsigned long duration = jiffies - io->start_time;
  284. int pending;
  285. int rw = bio_data_dir(bio);
  286. preempt_disable();
  287. disk_round_stats(dm_disk(md));
  288. preempt_enable();
  289. dm_disk(md)->in_flight = pending = atomic_dec_return(&md->pending);
  290. disk_stat_add(dm_disk(md), ticks[rw], duration);
  291. return !pending;
  292. }
  293. /*
  294. * Add the bio to the list of deferred io.
  295. */
  296. static int queue_io(struct mapped_device *md, struct bio *bio)
  297. {
  298. down_write(&md->io_lock);
  299. if (!test_bit(DMF_BLOCK_IO, &md->flags)) {
  300. up_write(&md->io_lock);
  301. return 1;
  302. }
  303. bio_list_add(&md->deferred, bio);
  304. up_write(&md->io_lock);
  305. return 0; /* deferred successfully */
  306. }
  307. /*
  308. * Everyone (including functions in this file), should use this
  309. * function to access the md->map field, and make sure they call
  310. * dm_table_put() when finished.
  311. */
  312. struct dm_table *dm_get_table(struct mapped_device *md)
  313. {
  314. struct dm_table *t;
  315. read_lock(&md->map_lock);
  316. t = md->map;
  317. if (t)
  318. dm_table_get(t);
  319. read_unlock(&md->map_lock);
  320. return t;
  321. }
  322. /*
  323. * Get the geometry associated with a dm device
  324. */
  325. int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo)
  326. {
  327. *geo = md->geometry;
  328. return 0;
  329. }
  330. /*
  331. * Set the geometry of a device.
  332. */
  333. int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo)
  334. {
  335. sector_t sz = (sector_t)geo->cylinders * geo->heads * geo->sectors;
  336. if (geo->start > sz) {
  337. DMWARN("Start sector is beyond the geometry limits.");
  338. return -EINVAL;
  339. }
  340. md->geometry = *geo;
  341. return 0;
  342. }
  343. /*-----------------------------------------------------------------
  344. * CRUD START:
  345. * A more elegant soln is in the works that uses the queue
  346. * merge fn, unfortunately there are a couple of changes to
  347. * the block layer that I want to make for this. So in the
  348. * interests of getting something for people to use I give
  349. * you this clearly demarcated crap.
  350. *---------------------------------------------------------------*/
  351. static int __noflush_suspending(struct mapped_device *md)
  352. {
  353. return test_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
  354. }
  355. /*
  356. * Decrements the number of outstanding ios that a bio has been
  357. * cloned into, completing the original io if necc.
  358. */
  359. static void dec_pending(struct dm_io *io, int error)
  360. {
  361. unsigned long flags;
  362. /* Push-back supersedes any I/O errors */
  363. if (error && !(io->error > 0 && __noflush_suspending(io->md)))
  364. io->error = error;
  365. if (atomic_dec_and_test(&io->io_count)) {
  366. if (io->error == DM_ENDIO_REQUEUE) {
  367. /*
  368. * Target requested pushing back the I/O.
  369. * This must be handled before the sleeper on
  370. * suspend queue merges the pushback list.
  371. */
  372. spin_lock_irqsave(&io->md->pushback_lock, flags);
  373. if (__noflush_suspending(io->md))
  374. bio_list_add(&io->md->pushback, io->bio);
  375. else
  376. /* noflush suspend was interrupted. */
  377. io->error = -EIO;
  378. spin_unlock_irqrestore(&io->md->pushback_lock, flags);
  379. }
  380. if (end_io_acct(io))
  381. /* nudge anyone waiting on suspend queue */
  382. wake_up(&io->md->wait);
  383. if (io->error != DM_ENDIO_REQUEUE) {
  384. blk_add_trace_bio(io->md->queue, io->bio,
  385. BLK_TA_COMPLETE);
  386. bio_endio(io->bio, io->error);
  387. }
  388. free_io(io->md, io);
  389. }
  390. }
  391. static void clone_endio(struct bio *bio, int error)
  392. {
  393. int r = 0;
  394. struct dm_target_io *tio = bio->bi_private;
  395. struct mapped_device *md = tio->io->md;
  396. dm_endio_fn endio = tio->ti->type->end_io;
  397. if (!bio_flagged(bio, BIO_UPTODATE) && !error)
  398. error = -EIO;
  399. if (endio) {
  400. r = endio(tio->ti, bio, error, &tio->info);
  401. if (r < 0 || r == DM_ENDIO_REQUEUE)
  402. /*
  403. * error and requeue request are handled
  404. * in dec_pending().
  405. */
  406. error = r;
  407. else if (r == DM_ENDIO_INCOMPLETE)
  408. /* The target will handle the io */
  409. return;
  410. else if (r) {
  411. DMWARN("unimplemented target endio return value: %d", r);
  412. BUG();
  413. }
  414. }
  415. dec_pending(tio->io, error);
  416. /*
  417. * Store md for cleanup instead of tio which is about to get freed.
  418. */
  419. bio->bi_private = md->bs;
  420. bio_put(bio);
  421. free_tio(md, tio);
  422. }
  423. static sector_t max_io_len(struct mapped_device *md,
  424. sector_t sector, struct dm_target *ti)
  425. {
  426. sector_t offset = sector - ti->begin;
  427. sector_t len = ti->len - offset;
  428. /*
  429. * Does the target need to split even further ?
  430. */
  431. if (ti->split_io) {
  432. sector_t boundary;
  433. boundary = ((offset + ti->split_io) & ~(ti->split_io - 1))
  434. - offset;
  435. if (len > boundary)
  436. len = boundary;
  437. }
  438. return len;
  439. }
  440. static void __map_bio(struct dm_target *ti, struct bio *clone,
  441. struct dm_target_io *tio)
  442. {
  443. int r;
  444. sector_t sector;
  445. struct mapped_device *md;
  446. /*
  447. * Sanity checks.
  448. */
  449. BUG_ON(!clone->bi_size);
  450. clone->bi_end_io = clone_endio;
  451. clone->bi_private = tio;
  452. /*
  453. * Map the clone. If r == 0 we don't need to do
  454. * anything, the target has assumed ownership of
  455. * this io.
  456. */
  457. atomic_inc(&tio->io->io_count);
  458. sector = clone->bi_sector;
  459. r = ti->type->map(ti, clone, &tio->info);
  460. if (r == DM_MAPIO_REMAPPED) {
  461. /* the bio has been remapped so dispatch it */
  462. blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone,
  463. tio->io->bio->bi_bdev->bd_dev,
  464. clone->bi_sector, sector);
  465. generic_make_request(clone);
  466. } else if (r < 0 || r == DM_MAPIO_REQUEUE) {
  467. /* error the io and bail out, or requeue it if needed */
  468. md = tio->io->md;
  469. dec_pending(tio->io, r);
  470. /*
  471. * Store bio_set for cleanup.
  472. */
  473. clone->bi_private = md->bs;
  474. bio_put(clone);
  475. free_tio(md, tio);
  476. } else if (r) {
  477. DMWARN("unimplemented target map return value: %d", r);
  478. BUG();
  479. }
  480. }
  481. struct clone_info {
  482. struct mapped_device *md;
  483. struct dm_table *map;
  484. struct bio *bio;
  485. struct dm_io *io;
  486. sector_t sector;
  487. sector_t sector_count;
  488. unsigned short idx;
  489. };
  490. static void dm_bio_destructor(struct bio *bio)
  491. {
  492. struct bio_set *bs = bio->bi_private;
  493. bio_free(bio, bs);
  494. }
  495. /*
  496. * Creates a little bio that is just does part of a bvec.
  497. */
  498. static struct bio *split_bvec(struct bio *bio, sector_t sector,
  499. unsigned short idx, unsigned int offset,
  500. unsigned int len, struct bio_set *bs)
  501. {
  502. struct bio *clone;
  503. struct bio_vec *bv = bio->bi_io_vec + idx;
  504. clone = bio_alloc_bioset(GFP_NOIO, 1, bs);
  505. clone->bi_destructor = dm_bio_destructor;
  506. *clone->bi_io_vec = *bv;
  507. clone->bi_sector = sector;
  508. clone->bi_bdev = bio->bi_bdev;
  509. clone->bi_rw = bio->bi_rw;
  510. clone->bi_vcnt = 1;
  511. clone->bi_size = to_bytes(len);
  512. clone->bi_io_vec->bv_offset = offset;
  513. clone->bi_io_vec->bv_len = clone->bi_size;
  514. return clone;
  515. }
  516. /*
  517. * Creates a bio that consists of range of complete bvecs.
  518. */
  519. static struct bio *clone_bio(struct bio *bio, sector_t sector,
  520. unsigned short idx, unsigned short bv_count,
  521. unsigned int len, struct bio_set *bs)
  522. {
  523. struct bio *clone;
  524. clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs);
  525. __bio_clone(clone, bio);
  526. clone->bi_destructor = dm_bio_destructor;
  527. clone->bi_sector = sector;
  528. clone->bi_idx = idx;
  529. clone->bi_vcnt = idx + bv_count;
  530. clone->bi_size = to_bytes(len);
  531. clone->bi_flags &= ~(1 << BIO_SEG_VALID);
  532. return clone;
  533. }
  534. static void __clone_and_map(struct clone_info *ci)
  535. {
  536. struct bio *clone, *bio = ci->bio;
  537. struct dm_target *ti = dm_table_find_target(ci->map, ci->sector);
  538. sector_t len = 0, max = max_io_len(ci->md, ci->sector, ti);
  539. struct dm_target_io *tio;
  540. /*
  541. * Allocate a target io object.
  542. */
  543. tio = alloc_tio(ci->md);
  544. tio->io = ci->io;
  545. tio->ti = ti;
  546. memset(&tio->info, 0, sizeof(tio->info));
  547. if (ci->sector_count <= max) {
  548. /*
  549. * Optimise for the simple case where we can do all of
  550. * the remaining io with a single clone.
  551. */
  552. clone = clone_bio(bio, ci->sector, ci->idx,
  553. bio->bi_vcnt - ci->idx, ci->sector_count,
  554. ci->md->bs);
  555. __map_bio(ti, clone, tio);
  556. ci->sector_count = 0;
  557. } else if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) {
  558. /*
  559. * There are some bvecs that don't span targets.
  560. * Do as many of these as possible.
  561. */
  562. int i;
  563. sector_t remaining = max;
  564. sector_t bv_len;
  565. for (i = ci->idx; remaining && (i < bio->bi_vcnt); i++) {
  566. bv_len = to_sector(bio->bi_io_vec[i].bv_len);
  567. if (bv_len > remaining)
  568. break;
  569. remaining -= bv_len;
  570. len += bv_len;
  571. }
  572. clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len,
  573. ci->md->bs);
  574. __map_bio(ti, clone, tio);
  575. ci->sector += len;
  576. ci->sector_count -= len;
  577. ci->idx = i;
  578. } else {
  579. /*
  580. * Handle a bvec that must be split between two or more targets.
  581. */
  582. struct bio_vec *bv = bio->bi_io_vec + ci->idx;
  583. sector_t remaining = to_sector(bv->bv_len);
  584. unsigned int offset = 0;
  585. do {
  586. if (offset) {
  587. ti = dm_table_find_target(ci->map, ci->sector);
  588. max = max_io_len(ci->md, ci->sector, ti);
  589. tio = alloc_tio(ci->md);
  590. tio->io = ci->io;
  591. tio->ti = ti;
  592. memset(&tio->info, 0, sizeof(tio->info));
  593. }
  594. len = min(remaining, max);
  595. clone = split_bvec(bio, ci->sector, ci->idx,
  596. bv->bv_offset + offset, len,
  597. ci->md->bs);
  598. __map_bio(ti, clone, tio);
  599. ci->sector += len;
  600. ci->sector_count -= len;
  601. offset += to_bytes(len);
  602. } while (remaining -= len);
  603. ci->idx++;
  604. }
  605. }
  606. /*
  607. * Split the bio into several clones.
  608. */
  609. static void __split_bio(struct mapped_device *md, struct bio *bio)
  610. {
  611. struct clone_info ci;
  612. ci.map = dm_get_table(md);
  613. if (!ci.map) {
  614. bio_io_error(bio);
  615. return;
  616. }
  617. ci.md = md;
  618. ci.bio = bio;
  619. ci.io = alloc_io(md);
  620. ci.io->error = 0;
  621. atomic_set(&ci.io->io_count, 1);
  622. ci.io->bio = bio;
  623. ci.io->md = md;
  624. ci.sector = bio->bi_sector;
  625. ci.sector_count = bio_sectors(bio);
  626. ci.idx = bio->bi_idx;
  627. start_io_acct(ci.io);
  628. while (ci.sector_count)
  629. __clone_and_map(&ci);
  630. /* drop the extra reference count */
  631. dec_pending(ci.io, 0);
  632. dm_table_put(ci.map);
  633. }
  634. /*-----------------------------------------------------------------
  635. * CRUD END
  636. *---------------------------------------------------------------*/
  637. /*
  638. * The request function that just remaps the bio built up by
  639. * dm_merge_bvec.
  640. */
  641. static int dm_request(struct request_queue *q, struct bio *bio)
  642. {
  643. int r;
  644. int rw = bio_data_dir(bio);
  645. struct mapped_device *md = q->queuedata;
  646. /*
  647. * There is no use in forwarding any barrier request since we can't
  648. * guarantee it is (or can be) handled by the targets correctly.
  649. */
  650. if (unlikely(bio_barrier(bio))) {
  651. bio_endio(bio, -EOPNOTSUPP);
  652. return 0;
  653. }
  654. down_read(&md->io_lock);
  655. disk_stat_inc(dm_disk(md), ios[rw]);
  656. disk_stat_add(dm_disk(md), sectors[rw], bio_sectors(bio));
  657. /*
  658. * If we're suspended we have to queue
  659. * this io for later.
  660. */
  661. while (test_bit(DMF_BLOCK_IO, &md->flags)) {
  662. up_read(&md->io_lock);
  663. if (bio_rw(bio) == READA) {
  664. bio_io_error(bio);
  665. return 0;
  666. }
  667. r = queue_io(md, bio);
  668. if (r < 0) {
  669. bio_io_error(bio);
  670. return 0;
  671. } else if (r == 0)
  672. return 0; /* deferred successfully */
  673. /*
  674. * We're in a while loop, because someone could suspend
  675. * before we get to the following read lock.
  676. */
  677. down_read(&md->io_lock);
  678. }
  679. __split_bio(md, bio);
  680. up_read(&md->io_lock);
  681. return 0;
  682. }
  683. static int dm_flush_all(struct request_queue *q, struct gendisk *disk,
  684. sector_t *error_sector)
  685. {
  686. struct mapped_device *md = q->queuedata;
  687. struct dm_table *map = dm_get_table(md);
  688. int ret = -ENXIO;
  689. if (map) {
  690. ret = dm_table_flush_all(map);
  691. dm_table_put(map);
  692. }
  693. return ret;
  694. }
  695. static void dm_unplug_all(struct request_queue *q)
  696. {
  697. struct mapped_device *md = q->queuedata;
  698. struct dm_table *map = dm_get_table(md);
  699. if (map) {
  700. dm_table_unplug_all(map);
  701. dm_table_put(map);
  702. }
  703. }
  704. static int dm_any_congested(void *congested_data, int bdi_bits)
  705. {
  706. int r;
  707. struct mapped_device *md = (struct mapped_device *) congested_data;
  708. struct dm_table *map = dm_get_table(md);
  709. if (!map || test_bit(DMF_BLOCK_IO, &md->flags))
  710. r = bdi_bits;
  711. else
  712. r = dm_table_any_congested(map, bdi_bits);
  713. dm_table_put(map);
  714. return r;
  715. }
  716. /*-----------------------------------------------------------------
  717. * An IDR is used to keep track of allocated minor numbers.
  718. *---------------------------------------------------------------*/
  719. static DEFINE_IDR(_minor_idr);
  720. static void free_minor(int minor)
  721. {
  722. spin_lock(&_minor_lock);
  723. idr_remove(&_minor_idr, minor);
  724. spin_unlock(&_minor_lock);
  725. }
  726. /*
  727. * See if the device with a specific minor # is free.
  728. */
  729. static int specific_minor(struct mapped_device *md, int minor)
  730. {
  731. int r, m;
  732. if (minor >= (1 << MINORBITS))
  733. return -EINVAL;
  734. r = idr_pre_get(&_minor_idr, GFP_KERNEL);
  735. if (!r)
  736. return -ENOMEM;
  737. spin_lock(&_minor_lock);
  738. if (idr_find(&_minor_idr, minor)) {
  739. r = -EBUSY;
  740. goto out;
  741. }
  742. r = idr_get_new_above(&_minor_idr, MINOR_ALLOCED, minor, &m);
  743. if (r)
  744. goto out;
  745. if (m != minor) {
  746. idr_remove(&_minor_idr, m);
  747. r = -EBUSY;
  748. goto out;
  749. }
  750. out:
  751. spin_unlock(&_minor_lock);
  752. return r;
  753. }
  754. static int next_free_minor(struct mapped_device *md, int *minor)
  755. {
  756. int r, m;
  757. r = idr_pre_get(&_minor_idr, GFP_KERNEL);
  758. if (!r)
  759. return -ENOMEM;
  760. spin_lock(&_minor_lock);
  761. r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m);
  762. if (r) {
  763. goto out;
  764. }
  765. if (m >= (1 << MINORBITS)) {
  766. idr_remove(&_minor_idr, m);
  767. r = -ENOSPC;
  768. goto out;
  769. }
  770. *minor = m;
  771. out:
  772. spin_unlock(&_minor_lock);
  773. return r;
  774. }
  775. static struct block_device_operations dm_blk_dops;
  776. /*
  777. * Allocate and initialise a blank device with a given minor.
  778. */
  779. static struct mapped_device *alloc_dev(int minor)
  780. {
  781. int r;
  782. struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL);
  783. void *old_md;
  784. if (!md) {
  785. DMWARN("unable to allocate device, out of memory.");
  786. return NULL;
  787. }
  788. if (!try_module_get(THIS_MODULE))
  789. goto bad0;
  790. /* get a minor number for the dev */
  791. if (minor == DM_ANY_MINOR)
  792. r = next_free_minor(md, &minor);
  793. else
  794. r = specific_minor(md, minor);
  795. if (r < 0)
  796. goto bad1;
  797. memset(md, 0, sizeof(*md));
  798. init_rwsem(&md->io_lock);
  799. init_MUTEX(&md->suspend_lock);
  800. spin_lock_init(&md->pushback_lock);
  801. rwlock_init(&md->map_lock);
  802. atomic_set(&md->holders, 1);
  803. atomic_set(&md->open_count, 0);
  804. atomic_set(&md->event_nr, 0);
  805. md->queue = blk_alloc_queue(GFP_KERNEL);
  806. if (!md->queue)
  807. goto bad1_free_minor;
  808. md->queue->queuedata = md;
  809. md->queue->backing_dev_info.congested_fn = dm_any_congested;
  810. md->queue->backing_dev_info.congested_data = md;
  811. blk_queue_make_request(md->queue, dm_request);
  812. blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
  813. md->queue->unplug_fn = dm_unplug_all;
  814. md->queue->issue_flush_fn = dm_flush_all;
  815. md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache);
  816. if (!md->io_pool)
  817. goto bad2;
  818. md->tio_pool = mempool_create_slab_pool(MIN_IOS, _tio_cache);
  819. if (!md->tio_pool)
  820. goto bad3;
  821. md->bs = bioset_create(16, 16);
  822. if (!md->bs)
  823. goto bad_no_bioset;
  824. md->disk = alloc_disk(1);
  825. if (!md->disk)
  826. goto bad4;
  827. atomic_set(&md->pending, 0);
  828. init_waitqueue_head(&md->wait);
  829. init_waitqueue_head(&md->eventq);
  830. md->disk->major = _major;
  831. md->disk->first_minor = minor;
  832. md->disk->fops = &dm_blk_dops;
  833. md->disk->queue = md->queue;
  834. md->disk->private_data = md;
  835. sprintf(md->disk->disk_name, "dm-%d", minor);
  836. add_disk(md->disk);
  837. format_dev_t(md->name, MKDEV(_major, minor));
  838. /* Populate the mapping, nobody knows we exist yet */
  839. spin_lock(&_minor_lock);
  840. old_md = idr_replace(&_minor_idr, md, minor);
  841. spin_unlock(&_minor_lock);
  842. BUG_ON(old_md != MINOR_ALLOCED);
  843. return md;
  844. bad4:
  845. bioset_free(md->bs);
  846. bad_no_bioset:
  847. mempool_destroy(md->tio_pool);
  848. bad3:
  849. mempool_destroy(md->io_pool);
  850. bad2:
  851. blk_cleanup_queue(md->queue);
  852. bad1_free_minor:
  853. free_minor(minor);
  854. bad1:
  855. module_put(THIS_MODULE);
  856. bad0:
  857. kfree(md);
  858. return NULL;
  859. }
  860. static void free_dev(struct mapped_device *md)
  861. {
  862. int minor = md->disk->first_minor;
  863. if (md->suspended_bdev) {
  864. thaw_bdev(md->suspended_bdev, NULL);
  865. bdput(md->suspended_bdev);
  866. }
  867. mempool_destroy(md->tio_pool);
  868. mempool_destroy(md->io_pool);
  869. bioset_free(md->bs);
  870. del_gendisk(md->disk);
  871. free_minor(minor);
  872. spin_lock(&_minor_lock);
  873. md->disk->private_data = NULL;
  874. spin_unlock(&_minor_lock);
  875. put_disk(md->disk);
  876. blk_cleanup_queue(md->queue);
  877. module_put(THIS_MODULE);
  878. kfree(md);
  879. }
  880. /*
  881. * Bind a table to the device.
  882. */
  883. static void event_callback(void *context)
  884. {
  885. struct mapped_device *md = (struct mapped_device *) context;
  886. atomic_inc(&md->event_nr);
  887. wake_up(&md->eventq);
  888. }
  889. static void __set_size(struct mapped_device *md, sector_t size)
  890. {
  891. set_capacity(md->disk, size);
  892. mutex_lock(&md->suspended_bdev->bd_inode->i_mutex);
  893. i_size_write(md->suspended_bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
  894. mutex_unlock(&md->suspended_bdev->bd_inode->i_mutex);
  895. }
  896. static int __bind(struct mapped_device *md, struct dm_table *t)
  897. {
  898. struct request_queue *q = md->queue;
  899. sector_t size;
  900. size = dm_table_get_size(t);
  901. /*
  902. * Wipe any geometry if the size of the table changed.
  903. */
  904. if (size != get_capacity(md->disk))
  905. memset(&md->geometry, 0, sizeof(md->geometry));
  906. if (md->suspended_bdev)
  907. __set_size(md, size);
  908. if (size == 0)
  909. return 0;
  910. dm_table_get(t);
  911. dm_table_event_callback(t, event_callback, md);
  912. write_lock(&md->map_lock);
  913. md->map = t;
  914. dm_table_set_restrictions(t, q);
  915. write_unlock(&md->map_lock);
  916. return 0;
  917. }
  918. static void __unbind(struct mapped_device *md)
  919. {
  920. struct dm_table *map = md->map;
  921. if (!map)
  922. return;
  923. dm_table_event_callback(map, NULL, NULL);
  924. write_lock(&md->map_lock);
  925. md->map = NULL;
  926. write_unlock(&md->map_lock);
  927. dm_table_put(map);
  928. }
  929. /*
  930. * Constructor for a new device.
  931. */
  932. int dm_create(int minor, struct mapped_device **result)
  933. {
  934. struct mapped_device *md;
  935. md = alloc_dev(minor);
  936. if (!md)
  937. return -ENXIO;
  938. *result = md;
  939. return 0;
  940. }
  941. static struct mapped_device *dm_find_md(dev_t dev)
  942. {
  943. struct mapped_device *md;
  944. unsigned minor = MINOR(dev);
  945. if (MAJOR(dev) != _major || minor >= (1 << MINORBITS))
  946. return NULL;
  947. spin_lock(&_minor_lock);
  948. md = idr_find(&_minor_idr, minor);
  949. if (md && (md == MINOR_ALLOCED ||
  950. (dm_disk(md)->first_minor != minor) ||
  951. test_bit(DMF_FREEING, &md->flags))) {
  952. md = NULL;
  953. goto out;
  954. }
  955. out:
  956. spin_unlock(&_minor_lock);
  957. return md;
  958. }
  959. struct mapped_device *dm_get_md(dev_t dev)
  960. {
  961. struct mapped_device *md = dm_find_md(dev);
  962. if (md)
  963. dm_get(md);
  964. return md;
  965. }
  966. void *dm_get_mdptr(struct mapped_device *md)
  967. {
  968. return md->interface_ptr;
  969. }
  970. void dm_set_mdptr(struct mapped_device *md, void *ptr)
  971. {
  972. md->interface_ptr = ptr;
  973. }
  974. void dm_get(struct mapped_device *md)
  975. {
  976. atomic_inc(&md->holders);
  977. }
  978. const char *dm_device_name(struct mapped_device *md)
  979. {
  980. return md->name;
  981. }
  982. EXPORT_SYMBOL_GPL(dm_device_name);
  983. void dm_put(struct mapped_device *md)
  984. {
  985. struct dm_table *map;
  986. BUG_ON(test_bit(DMF_FREEING, &md->flags));
  987. if (atomic_dec_and_lock(&md->holders, &_minor_lock)) {
  988. map = dm_get_table(md);
  989. idr_replace(&_minor_idr, MINOR_ALLOCED, dm_disk(md)->first_minor);
  990. set_bit(DMF_FREEING, &md->flags);
  991. spin_unlock(&_minor_lock);
  992. if (!dm_suspended(md)) {
  993. dm_table_presuspend_targets(map);
  994. dm_table_postsuspend_targets(map);
  995. }
  996. __unbind(md);
  997. dm_table_put(map);
  998. free_dev(md);
  999. }
  1000. }
  1001. EXPORT_SYMBOL_GPL(dm_put);
  1002. /*
  1003. * Process the deferred bios
  1004. */
  1005. static void __flush_deferred_io(struct mapped_device *md, struct bio *c)
  1006. {
  1007. struct bio *n;
  1008. while (c) {
  1009. n = c->bi_next;
  1010. c->bi_next = NULL;
  1011. __split_bio(md, c);
  1012. c = n;
  1013. }
  1014. }
  1015. /*
  1016. * Swap in a new table (destroying old one).
  1017. */
  1018. int dm_swap_table(struct mapped_device *md, struct dm_table *table)
  1019. {
  1020. int r = -EINVAL;
  1021. down(&md->suspend_lock);
  1022. /* device must be suspended */
  1023. if (!dm_suspended(md))
  1024. goto out;
  1025. /* without bdev, the device size cannot be changed */
  1026. if (!md->suspended_bdev)
  1027. if (get_capacity(md->disk) != dm_table_get_size(table))
  1028. goto out;
  1029. __unbind(md);
  1030. r = __bind(md, table);
  1031. out:
  1032. up(&md->suspend_lock);
  1033. return r;
  1034. }
  1035. /*
  1036. * Functions to lock and unlock any filesystem running on the
  1037. * device.
  1038. */
  1039. static int lock_fs(struct mapped_device *md)
  1040. {
  1041. int r;
  1042. WARN_ON(md->frozen_sb);
  1043. md->frozen_sb = freeze_bdev(md->suspended_bdev);
  1044. if (IS_ERR(md->frozen_sb)) {
  1045. r = PTR_ERR(md->frozen_sb);
  1046. md->frozen_sb = NULL;
  1047. return r;
  1048. }
  1049. set_bit(DMF_FROZEN, &md->flags);
  1050. /* don't bdput right now, we don't want the bdev
  1051. * to go away while it is locked.
  1052. */
  1053. return 0;
  1054. }
  1055. static void unlock_fs(struct mapped_device *md)
  1056. {
  1057. if (!test_bit(DMF_FROZEN, &md->flags))
  1058. return;
  1059. thaw_bdev(md->suspended_bdev, md->frozen_sb);
  1060. md->frozen_sb = NULL;
  1061. clear_bit(DMF_FROZEN, &md->flags);
  1062. }
  1063. /*
  1064. * We need to be able to change a mapping table under a mounted
  1065. * filesystem. For example we might want to move some data in
  1066. * the background. Before the table can be swapped with
  1067. * dm_bind_table, dm_suspend must be called to flush any in
  1068. * flight bios and ensure that any further io gets deferred.
  1069. */
  1070. int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
  1071. {
  1072. struct dm_table *map = NULL;
  1073. unsigned long flags;
  1074. DECLARE_WAITQUEUE(wait, current);
  1075. struct bio *def;
  1076. int r = -EINVAL;
  1077. int do_lockfs = suspend_flags & DM_SUSPEND_LOCKFS_FLAG ? 1 : 0;
  1078. int noflush = suspend_flags & DM_SUSPEND_NOFLUSH_FLAG ? 1 : 0;
  1079. down(&md->suspend_lock);
  1080. if (dm_suspended(md))
  1081. goto out_unlock;
  1082. map = dm_get_table(md);
  1083. /*
  1084. * DMF_NOFLUSH_SUSPENDING must be set before presuspend.
  1085. * This flag is cleared before dm_suspend returns.
  1086. */
  1087. if (noflush)
  1088. set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
  1089. /* This does not get reverted if there's an error later. */
  1090. dm_table_presuspend_targets(map);
  1091. /* bdget() can stall if the pending I/Os are not flushed */
  1092. if (!noflush) {
  1093. md->suspended_bdev = bdget_disk(md->disk, 0);
  1094. if (!md->suspended_bdev) {
  1095. DMWARN("bdget failed in dm_suspend");
  1096. r = -ENOMEM;
  1097. goto flush_and_out;
  1098. }
  1099. }
  1100. /*
  1101. * Flush I/O to the device.
  1102. * noflush supersedes do_lockfs, because lock_fs() needs to flush I/Os.
  1103. */
  1104. if (do_lockfs && !noflush) {
  1105. r = lock_fs(md);
  1106. if (r)
  1107. goto out;
  1108. }
  1109. /*
  1110. * First we set the BLOCK_IO flag so no more ios will be mapped.
  1111. */
  1112. down_write(&md->io_lock);
  1113. set_bit(DMF_BLOCK_IO, &md->flags);
  1114. add_wait_queue(&md->wait, &wait);
  1115. up_write(&md->io_lock);
  1116. /* unplug */
  1117. if (map)
  1118. dm_table_unplug_all(map);
  1119. /*
  1120. * Then we wait for the already mapped ios to
  1121. * complete.
  1122. */
  1123. while (1) {
  1124. set_current_state(TASK_INTERRUPTIBLE);
  1125. if (!atomic_read(&md->pending) || signal_pending(current))
  1126. break;
  1127. io_schedule();
  1128. }
  1129. set_current_state(TASK_RUNNING);
  1130. down_write(&md->io_lock);
  1131. remove_wait_queue(&md->wait, &wait);
  1132. if (noflush) {
  1133. spin_lock_irqsave(&md->pushback_lock, flags);
  1134. clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
  1135. bio_list_merge_head(&md->deferred, &md->pushback);
  1136. bio_list_init(&md->pushback);
  1137. spin_unlock_irqrestore(&md->pushback_lock, flags);
  1138. }
  1139. /* were we interrupted ? */
  1140. r = -EINTR;
  1141. if (atomic_read(&md->pending)) {
  1142. clear_bit(DMF_BLOCK_IO, &md->flags);
  1143. def = bio_list_get(&md->deferred);
  1144. __flush_deferred_io(md, def);
  1145. up_write(&md->io_lock);
  1146. unlock_fs(md);
  1147. goto out; /* pushback list is already flushed, so skip flush */
  1148. }
  1149. up_write(&md->io_lock);
  1150. dm_table_postsuspend_targets(map);
  1151. set_bit(DMF_SUSPENDED, &md->flags);
  1152. r = 0;
  1153. flush_and_out:
  1154. if (r && noflush) {
  1155. /*
  1156. * Because there may be already I/Os in the pushback list,
  1157. * flush them before return.
  1158. */
  1159. down_write(&md->io_lock);
  1160. spin_lock_irqsave(&md->pushback_lock, flags);
  1161. clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
  1162. bio_list_merge_head(&md->deferred, &md->pushback);
  1163. bio_list_init(&md->pushback);
  1164. spin_unlock_irqrestore(&md->pushback_lock, flags);
  1165. def = bio_list_get(&md->deferred);
  1166. __flush_deferred_io(md, def);
  1167. up_write(&md->io_lock);
  1168. }
  1169. out:
  1170. if (r && md->suspended_bdev) {
  1171. bdput(md->suspended_bdev);
  1172. md->suspended_bdev = NULL;
  1173. }
  1174. dm_table_put(map);
  1175. out_unlock:
  1176. up(&md->suspend_lock);
  1177. return r;
  1178. }
  1179. int dm_resume(struct mapped_device *md)
  1180. {
  1181. int r = -EINVAL;
  1182. struct bio *def;
  1183. struct dm_table *map = NULL;
  1184. down(&md->suspend_lock);
  1185. if (!dm_suspended(md))
  1186. goto out;
  1187. map = dm_get_table(md);
  1188. if (!map || !dm_table_get_size(map))
  1189. goto out;
  1190. r = dm_table_resume_targets(map);
  1191. if (r)
  1192. goto out;
  1193. down_write(&md->io_lock);
  1194. clear_bit(DMF_BLOCK_IO, &md->flags);
  1195. def = bio_list_get(&md->deferred);
  1196. __flush_deferred_io(md, def);
  1197. up_write(&md->io_lock);
  1198. unlock_fs(md);
  1199. if (md->suspended_bdev) {
  1200. bdput(md->suspended_bdev);
  1201. md->suspended_bdev = NULL;
  1202. }
  1203. clear_bit(DMF_SUSPENDED, &md->flags);
  1204. dm_table_unplug_all(map);
  1205. kobject_uevent(&md->disk->kobj, KOBJ_CHANGE);
  1206. r = 0;
  1207. out:
  1208. dm_table_put(map);
  1209. up(&md->suspend_lock);
  1210. return r;
  1211. }
  1212. /*-----------------------------------------------------------------
  1213. * Event notification.
  1214. *---------------------------------------------------------------*/
  1215. uint32_t dm_get_event_nr(struct mapped_device *md)
  1216. {
  1217. return atomic_read(&md->event_nr);
  1218. }
  1219. int dm_wait_event(struct mapped_device *md, int event_nr)
  1220. {
  1221. return wait_event_interruptible(md->eventq,
  1222. (event_nr != atomic_read(&md->event_nr)));
  1223. }
  1224. /*
  1225. * The gendisk is only valid as long as you have a reference
  1226. * count on 'md'.
  1227. */
  1228. struct gendisk *dm_disk(struct mapped_device *md)
  1229. {
  1230. return md->disk;
  1231. }
  1232. int dm_suspended(struct mapped_device *md)
  1233. {
  1234. return test_bit(DMF_SUSPENDED, &md->flags);
  1235. }
  1236. int dm_noflush_suspending(struct dm_target *ti)
  1237. {
  1238. struct mapped_device *md = dm_table_get_md(ti->table);
  1239. int r = __noflush_suspending(md);
  1240. dm_put(md);
  1241. return r;
  1242. }
  1243. EXPORT_SYMBOL_GPL(dm_noflush_suspending);
  1244. static struct block_device_operations dm_blk_dops = {
  1245. .open = dm_blk_open,
  1246. .release = dm_blk_close,
  1247. .ioctl = dm_blk_ioctl,
  1248. .getgeo = dm_blk_getgeo,
  1249. .owner = THIS_MODULE
  1250. };
  1251. EXPORT_SYMBOL(dm_get_mapinfo);
  1252. /*
  1253. * module hooks
  1254. */
  1255. module_init(dm_init);
  1256. module_exit(dm_exit);
  1257. module_param(major, uint, 0);
  1258. MODULE_PARM_DESC(major, "The major number of the device mapper");
  1259. MODULE_DESCRIPTION(DM_NAME " driver");
  1260. MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
  1261. MODULE_LICENSE("GPL");