dm.c 31 KB

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