dm-raid1.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. /*
  2. * Copyright (C) 2003 Sistina Software Limited.
  3. * Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved.
  4. *
  5. * This file is released under the GPL.
  6. */
  7. #include "dm-bio-record.h"
  8. #include <linux/init.h>
  9. #include <linux/mempool.h>
  10. #include <linux/module.h>
  11. #include <linux/pagemap.h>
  12. #include <linux/slab.h>
  13. #include <linux/workqueue.h>
  14. #include <linux/device-mapper.h>
  15. #include <linux/dm-io.h>
  16. #include <linux/dm-dirty-log.h>
  17. #include <linux/dm-kcopyd.h>
  18. #include <linux/dm-region-hash.h>
  19. #define DM_MSG_PREFIX "raid1"
  20. #define MAX_RECOVERY 1 /* Maximum number of regions recovered in parallel. */
  21. #define DM_IO_PAGES 64
  22. #define DM_KCOPYD_PAGES 64
  23. #define DM_RAID1_HANDLE_ERRORS 0x01
  24. #define errors_handled(p) ((p)->features & DM_RAID1_HANDLE_ERRORS)
  25. static DECLARE_WAIT_QUEUE_HEAD(_kmirrord_recovery_stopped);
  26. /*-----------------------------------------------------------------
  27. * Mirror set structures.
  28. *---------------------------------------------------------------*/
  29. enum dm_raid1_error {
  30. DM_RAID1_WRITE_ERROR,
  31. DM_RAID1_FLUSH_ERROR,
  32. DM_RAID1_SYNC_ERROR,
  33. DM_RAID1_READ_ERROR
  34. };
  35. struct mirror {
  36. struct mirror_set *ms;
  37. atomic_t error_count;
  38. unsigned long error_type;
  39. struct dm_dev *dev;
  40. sector_t offset;
  41. };
  42. struct mirror_set {
  43. struct dm_target *ti;
  44. struct list_head list;
  45. uint64_t features;
  46. spinlock_t lock; /* protects the lists */
  47. struct bio_list reads;
  48. struct bio_list writes;
  49. struct bio_list failures;
  50. struct dm_region_hash *rh;
  51. struct dm_kcopyd_client *kcopyd_client;
  52. struct dm_io_client *io_client;
  53. mempool_t *read_record_pool;
  54. /* recovery */
  55. region_t nr_regions;
  56. int in_sync;
  57. int log_failure;
  58. atomic_t suspend;
  59. atomic_t default_mirror; /* Default mirror */
  60. struct workqueue_struct *kmirrord_wq;
  61. struct work_struct kmirrord_work;
  62. struct timer_list timer;
  63. unsigned long timer_pending;
  64. struct work_struct trigger_event;
  65. unsigned nr_mirrors;
  66. struct mirror mirror[0];
  67. };
  68. static void wakeup_mirrord(void *context)
  69. {
  70. struct mirror_set *ms = context;
  71. queue_work(ms->kmirrord_wq, &ms->kmirrord_work);
  72. }
  73. static void delayed_wake_fn(unsigned long data)
  74. {
  75. struct mirror_set *ms = (struct mirror_set *) data;
  76. clear_bit(0, &ms->timer_pending);
  77. wakeup_mirrord(ms);
  78. }
  79. static void delayed_wake(struct mirror_set *ms)
  80. {
  81. if (test_and_set_bit(0, &ms->timer_pending))
  82. return;
  83. ms->timer.expires = jiffies + HZ / 5;
  84. ms->timer.data = (unsigned long) ms;
  85. ms->timer.function = delayed_wake_fn;
  86. add_timer(&ms->timer);
  87. }
  88. static void wakeup_all_recovery_waiters(void *context)
  89. {
  90. wake_up_all(&_kmirrord_recovery_stopped);
  91. }
  92. static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw)
  93. {
  94. unsigned long flags;
  95. int should_wake = 0;
  96. struct bio_list *bl;
  97. bl = (rw == WRITE) ? &ms->writes : &ms->reads;
  98. spin_lock_irqsave(&ms->lock, flags);
  99. should_wake = !(bl->head);
  100. bio_list_add(bl, bio);
  101. spin_unlock_irqrestore(&ms->lock, flags);
  102. if (should_wake)
  103. wakeup_mirrord(ms);
  104. }
  105. static void dispatch_bios(void *context, struct bio_list *bio_list)
  106. {
  107. struct mirror_set *ms = context;
  108. struct bio *bio;
  109. while ((bio = bio_list_pop(bio_list)))
  110. queue_bio(ms, bio, WRITE);
  111. }
  112. #define MIN_READ_RECORDS 20
  113. struct dm_raid1_read_record {
  114. struct mirror *m;
  115. struct dm_bio_details details;
  116. };
  117. static struct kmem_cache *_dm_raid1_read_record_cache;
  118. /*
  119. * Every mirror should look like this one.
  120. */
  121. #define DEFAULT_MIRROR 0
  122. /*
  123. * This is yucky. We squirrel the mirror struct away inside
  124. * bi_next for read/write buffers. This is safe since the bh
  125. * doesn't get submitted to the lower levels of block layer.
  126. */
  127. static struct mirror *bio_get_m(struct bio *bio)
  128. {
  129. return (struct mirror *) bio->bi_next;
  130. }
  131. static void bio_set_m(struct bio *bio, struct mirror *m)
  132. {
  133. bio->bi_next = (struct bio *) m;
  134. }
  135. static struct mirror *get_default_mirror(struct mirror_set *ms)
  136. {
  137. return &ms->mirror[atomic_read(&ms->default_mirror)];
  138. }
  139. static void set_default_mirror(struct mirror *m)
  140. {
  141. struct mirror_set *ms = m->ms;
  142. struct mirror *m0 = &(ms->mirror[0]);
  143. atomic_set(&ms->default_mirror, m - m0);
  144. }
  145. /* fail_mirror
  146. * @m: mirror device to fail
  147. * @error_type: one of the enum's, DM_RAID1_*_ERROR
  148. *
  149. * If errors are being handled, record the type of
  150. * error encountered for this device. If this type
  151. * of error has already been recorded, we can return;
  152. * otherwise, we must signal userspace by triggering
  153. * an event. Additionally, if the device is the
  154. * primary device, we must choose a new primary, but
  155. * only if the mirror is in-sync.
  156. *
  157. * This function must not block.
  158. */
  159. static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
  160. {
  161. struct mirror_set *ms = m->ms;
  162. struct mirror *new;
  163. /*
  164. * error_count is used for nothing more than a
  165. * simple way to tell if a device has encountered
  166. * errors.
  167. */
  168. atomic_inc(&m->error_count);
  169. if (test_and_set_bit(error_type, &m->error_type))
  170. return;
  171. if (!errors_handled(ms))
  172. return;
  173. if (m != get_default_mirror(ms))
  174. goto out;
  175. if (!ms->in_sync) {
  176. /*
  177. * Better to issue requests to same failing device
  178. * than to risk returning corrupt data.
  179. */
  180. DMERR("Primary mirror (%s) failed while out-of-sync: "
  181. "Reads may fail.", m->dev->name);
  182. goto out;
  183. }
  184. for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
  185. if (!atomic_read(&new->error_count)) {
  186. set_default_mirror(new);
  187. break;
  188. }
  189. if (unlikely(new == ms->mirror + ms->nr_mirrors))
  190. DMWARN("All sides of mirror have failed.");
  191. out:
  192. schedule_work(&ms->trigger_event);
  193. }
  194. static int mirror_flush(struct dm_target *ti)
  195. {
  196. struct mirror_set *ms = ti->private;
  197. unsigned long error_bits;
  198. unsigned int i;
  199. struct dm_io_region io[ms->nr_mirrors];
  200. struct mirror *m;
  201. struct dm_io_request io_req = {
  202. .bi_rw = WRITE_BARRIER,
  203. .mem.type = DM_IO_KMEM,
  204. .mem.ptr.bvec = NULL,
  205. .client = ms->io_client,
  206. };
  207. for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++) {
  208. io[i].bdev = m->dev->bdev;
  209. io[i].sector = 0;
  210. io[i].count = 0;
  211. }
  212. error_bits = -1;
  213. dm_io(&io_req, ms->nr_mirrors, io, &error_bits);
  214. if (unlikely(error_bits != 0)) {
  215. for (i = 0; i < ms->nr_mirrors; i++)
  216. if (test_bit(i, &error_bits))
  217. fail_mirror(ms->mirror + i,
  218. DM_RAID1_FLUSH_ERROR);
  219. return -EIO;
  220. }
  221. return 0;
  222. }
  223. /*-----------------------------------------------------------------
  224. * Recovery.
  225. *
  226. * When a mirror is first activated we may find that some regions
  227. * are in the no-sync state. We have to recover these by
  228. * recopying from the default mirror to all the others.
  229. *---------------------------------------------------------------*/
  230. static void recovery_complete(int read_err, unsigned long write_err,
  231. void *context)
  232. {
  233. struct dm_region *reg = context;
  234. struct mirror_set *ms = dm_rh_region_context(reg);
  235. int m, bit = 0;
  236. if (read_err) {
  237. /* Read error means the failure of default mirror. */
  238. DMERR_LIMIT("Unable to read primary mirror during recovery");
  239. fail_mirror(get_default_mirror(ms), DM_RAID1_SYNC_ERROR);
  240. }
  241. if (write_err) {
  242. DMERR_LIMIT("Write error during recovery (error = 0x%lx)",
  243. write_err);
  244. /*
  245. * Bits correspond to devices (excluding default mirror).
  246. * The default mirror cannot change during recovery.
  247. */
  248. for (m = 0; m < ms->nr_mirrors; m++) {
  249. if (&ms->mirror[m] == get_default_mirror(ms))
  250. continue;
  251. if (test_bit(bit, &write_err))
  252. fail_mirror(ms->mirror + m,
  253. DM_RAID1_SYNC_ERROR);
  254. bit++;
  255. }
  256. }
  257. dm_rh_recovery_end(reg, !(read_err || write_err));
  258. }
  259. static int recover(struct mirror_set *ms, struct dm_region *reg)
  260. {
  261. int r;
  262. unsigned i;
  263. struct dm_io_region from, to[DM_KCOPYD_MAX_REGIONS], *dest;
  264. struct mirror *m;
  265. unsigned long flags = 0;
  266. region_t key = dm_rh_get_region_key(reg);
  267. sector_t region_size = dm_rh_get_region_size(ms->rh);
  268. /* fill in the source */
  269. m = get_default_mirror(ms);
  270. from.bdev = m->dev->bdev;
  271. from.sector = m->offset + dm_rh_region_to_sector(ms->rh, key);
  272. if (key == (ms->nr_regions - 1)) {
  273. /*
  274. * The final region may be smaller than
  275. * region_size.
  276. */
  277. from.count = ms->ti->len & (region_size - 1);
  278. if (!from.count)
  279. from.count = region_size;
  280. } else
  281. from.count = region_size;
  282. /* fill in the destinations */
  283. for (i = 0, dest = to; i < ms->nr_mirrors; i++) {
  284. if (&ms->mirror[i] == get_default_mirror(ms))
  285. continue;
  286. m = ms->mirror + i;
  287. dest->bdev = m->dev->bdev;
  288. dest->sector = m->offset + dm_rh_region_to_sector(ms->rh, key);
  289. dest->count = from.count;
  290. dest++;
  291. }
  292. /* hand to kcopyd */
  293. if (!errors_handled(ms))
  294. set_bit(DM_KCOPYD_IGNORE_ERROR, &flags);
  295. r = dm_kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to,
  296. flags, recovery_complete, reg);
  297. return r;
  298. }
  299. static void do_recovery(struct mirror_set *ms)
  300. {
  301. struct dm_region *reg;
  302. struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
  303. int r;
  304. /*
  305. * Start quiescing some regions.
  306. */
  307. dm_rh_recovery_prepare(ms->rh);
  308. /*
  309. * Copy any already quiesced regions.
  310. */
  311. while ((reg = dm_rh_recovery_start(ms->rh))) {
  312. r = recover(ms, reg);
  313. if (r)
  314. dm_rh_recovery_end(reg, 0);
  315. }
  316. /*
  317. * Update the in sync flag.
  318. */
  319. if (!ms->in_sync &&
  320. (log->type->get_sync_count(log) == ms->nr_regions)) {
  321. /* the sync is complete */
  322. dm_table_event(ms->ti->table);
  323. ms->in_sync = 1;
  324. }
  325. }
  326. /*-----------------------------------------------------------------
  327. * Reads
  328. *---------------------------------------------------------------*/
  329. static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
  330. {
  331. struct mirror *m = get_default_mirror(ms);
  332. do {
  333. if (likely(!atomic_read(&m->error_count)))
  334. return m;
  335. if (m-- == ms->mirror)
  336. m += ms->nr_mirrors;
  337. } while (m != get_default_mirror(ms));
  338. return NULL;
  339. }
  340. static int default_ok(struct mirror *m)
  341. {
  342. struct mirror *default_mirror = get_default_mirror(m->ms);
  343. return !atomic_read(&default_mirror->error_count);
  344. }
  345. static int mirror_available(struct mirror_set *ms, struct bio *bio)
  346. {
  347. struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
  348. region_t region = dm_rh_bio_to_region(ms->rh, bio);
  349. if (log->type->in_sync(log, region, 0))
  350. return choose_mirror(ms, bio->bi_sector) ? 1 : 0;
  351. return 0;
  352. }
  353. /*
  354. * remap a buffer to a particular mirror.
  355. */
  356. static sector_t map_sector(struct mirror *m, struct bio *bio)
  357. {
  358. if (unlikely(!bio->bi_size))
  359. return 0;
  360. return m->offset + (bio->bi_sector - m->ms->ti->begin);
  361. }
  362. static void map_bio(struct mirror *m, struct bio *bio)
  363. {
  364. bio->bi_bdev = m->dev->bdev;
  365. bio->bi_sector = map_sector(m, bio);
  366. }
  367. static void map_region(struct dm_io_region *io, struct mirror *m,
  368. struct bio *bio)
  369. {
  370. io->bdev = m->dev->bdev;
  371. io->sector = map_sector(m, bio);
  372. io->count = bio->bi_size >> 9;
  373. }
  374. /*-----------------------------------------------------------------
  375. * Reads
  376. *---------------------------------------------------------------*/
  377. static void read_callback(unsigned long error, void *context)
  378. {
  379. struct bio *bio = context;
  380. struct mirror *m;
  381. m = bio_get_m(bio);
  382. bio_set_m(bio, NULL);
  383. if (likely(!error)) {
  384. bio_endio(bio, 0);
  385. return;
  386. }
  387. fail_mirror(m, DM_RAID1_READ_ERROR);
  388. if (likely(default_ok(m)) || mirror_available(m->ms, bio)) {
  389. DMWARN_LIMIT("Read failure on mirror device %s. "
  390. "Trying alternative device.",
  391. m->dev->name);
  392. queue_bio(m->ms, bio, bio_rw(bio));
  393. return;
  394. }
  395. DMERR_LIMIT("Read failure on mirror device %s. Failing I/O.",
  396. m->dev->name);
  397. bio_endio(bio, -EIO);
  398. }
  399. /* Asynchronous read. */
  400. static void read_async_bio(struct mirror *m, struct bio *bio)
  401. {
  402. struct dm_io_region io;
  403. struct dm_io_request io_req = {
  404. .bi_rw = READ,
  405. .mem.type = DM_IO_BVEC,
  406. .mem.ptr.bvec = bio->bi_io_vec + bio->bi_idx,
  407. .notify.fn = read_callback,
  408. .notify.context = bio,
  409. .client = m->ms->io_client,
  410. };
  411. map_region(&io, m, bio);
  412. bio_set_m(bio, m);
  413. BUG_ON(dm_io(&io_req, 1, &io, NULL));
  414. }
  415. static inline int region_in_sync(struct mirror_set *ms, region_t region,
  416. int may_block)
  417. {
  418. int state = dm_rh_get_state(ms->rh, region, may_block);
  419. return state == DM_RH_CLEAN || state == DM_RH_DIRTY;
  420. }
  421. static void do_reads(struct mirror_set *ms, struct bio_list *reads)
  422. {
  423. region_t region;
  424. struct bio *bio;
  425. struct mirror *m;
  426. while ((bio = bio_list_pop(reads))) {
  427. region = dm_rh_bio_to_region(ms->rh, bio);
  428. m = get_default_mirror(ms);
  429. /*
  430. * We can only read balance if the region is in sync.
  431. */
  432. if (likely(region_in_sync(ms, region, 1)))
  433. m = choose_mirror(ms, bio->bi_sector);
  434. else if (m && atomic_read(&m->error_count))
  435. m = NULL;
  436. if (likely(m))
  437. read_async_bio(m, bio);
  438. else
  439. bio_endio(bio, -EIO);
  440. }
  441. }
  442. /*-----------------------------------------------------------------
  443. * Writes.
  444. *
  445. * We do different things with the write io depending on the
  446. * state of the region that it's in:
  447. *
  448. * SYNC: increment pending, use kcopyd to write to *all* mirrors
  449. * RECOVERING: delay the io until recovery completes
  450. * NOSYNC: increment pending, just write to the default mirror
  451. *---------------------------------------------------------------*/
  452. static void write_callback(unsigned long error, void *context)
  453. {
  454. unsigned i, ret = 0;
  455. struct bio *bio = (struct bio *) context;
  456. struct mirror_set *ms;
  457. int uptodate = 0;
  458. int should_wake = 0;
  459. unsigned long flags;
  460. ms = bio_get_m(bio)->ms;
  461. bio_set_m(bio, NULL);
  462. /*
  463. * NOTE: We don't decrement the pending count here,
  464. * instead it is done by the targets endio function.
  465. * This way we handle both writes to SYNC and NOSYNC
  466. * regions with the same code.
  467. */
  468. if (likely(!error))
  469. goto out;
  470. for (i = 0; i < ms->nr_mirrors; i++)
  471. if (test_bit(i, &error))
  472. fail_mirror(ms->mirror + i, DM_RAID1_WRITE_ERROR);
  473. else
  474. uptodate = 1;
  475. if (unlikely(!uptodate)) {
  476. DMERR("All replicated volumes dead, failing I/O");
  477. /* None of the writes succeeded, fail the I/O. */
  478. ret = -EIO;
  479. } else if (errors_handled(ms)) {
  480. /*
  481. * Need to raise event. Since raising
  482. * events can block, we need to do it in
  483. * the main thread.
  484. */
  485. spin_lock_irqsave(&ms->lock, flags);
  486. if (!ms->failures.head)
  487. should_wake = 1;
  488. bio_list_add(&ms->failures, bio);
  489. spin_unlock_irqrestore(&ms->lock, flags);
  490. if (should_wake)
  491. wakeup_mirrord(ms);
  492. return;
  493. }
  494. out:
  495. bio_endio(bio, ret);
  496. }
  497. static void do_write(struct mirror_set *ms, struct bio *bio)
  498. {
  499. unsigned int i;
  500. struct dm_io_region io[ms->nr_mirrors], *dest = io;
  501. struct mirror *m;
  502. struct dm_io_request io_req = {
  503. .bi_rw = WRITE | (bio->bi_rw & WRITE_BARRIER),
  504. .mem.type = DM_IO_BVEC,
  505. .mem.ptr.bvec = bio->bi_io_vec + bio->bi_idx,
  506. .notify.fn = write_callback,
  507. .notify.context = bio,
  508. .client = ms->io_client,
  509. };
  510. for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++)
  511. map_region(dest++, m, bio);
  512. /*
  513. * Use default mirror because we only need it to retrieve the reference
  514. * to the mirror set in write_callback().
  515. */
  516. bio_set_m(bio, get_default_mirror(ms));
  517. BUG_ON(dm_io(&io_req, ms->nr_mirrors, io, NULL));
  518. }
  519. static void do_writes(struct mirror_set *ms, struct bio_list *writes)
  520. {
  521. int state;
  522. struct bio *bio;
  523. struct bio_list sync, nosync, recover, *this_list = NULL;
  524. struct bio_list requeue;
  525. struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
  526. region_t region;
  527. if (!writes->head)
  528. return;
  529. /*
  530. * Classify each write.
  531. */
  532. bio_list_init(&sync);
  533. bio_list_init(&nosync);
  534. bio_list_init(&recover);
  535. bio_list_init(&requeue);
  536. while ((bio = bio_list_pop(writes))) {
  537. if (unlikely(bio_empty_barrier(bio))) {
  538. bio_list_add(&sync, bio);
  539. continue;
  540. }
  541. region = dm_rh_bio_to_region(ms->rh, bio);
  542. if (log->type->is_remote_recovering &&
  543. log->type->is_remote_recovering(log, region)) {
  544. bio_list_add(&requeue, bio);
  545. continue;
  546. }
  547. state = dm_rh_get_state(ms->rh, region, 1);
  548. switch (state) {
  549. case DM_RH_CLEAN:
  550. case DM_RH_DIRTY:
  551. this_list = &sync;
  552. break;
  553. case DM_RH_NOSYNC:
  554. this_list = &nosync;
  555. break;
  556. case DM_RH_RECOVERING:
  557. this_list = &recover;
  558. break;
  559. }
  560. bio_list_add(this_list, bio);
  561. }
  562. /*
  563. * Add bios that are delayed due to remote recovery
  564. * back on to the write queue
  565. */
  566. if (unlikely(requeue.head)) {
  567. spin_lock_irq(&ms->lock);
  568. bio_list_merge(&ms->writes, &requeue);
  569. spin_unlock_irq(&ms->lock);
  570. delayed_wake(ms);
  571. }
  572. /*
  573. * Increment the pending counts for any regions that will
  574. * be written to (writes to recover regions are going to
  575. * be delayed).
  576. */
  577. dm_rh_inc_pending(ms->rh, &sync);
  578. dm_rh_inc_pending(ms->rh, &nosync);
  579. /*
  580. * If the flush fails on a previous call and succeeds here,
  581. * we must not reset the log_failure variable. We need
  582. * userspace interaction to do that.
  583. */
  584. ms->log_failure = dm_rh_flush(ms->rh) ? 1 : ms->log_failure;
  585. /*
  586. * Dispatch io.
  587. */
  588. if (unlikely(ms->log_failure)) {
  589. spin_lock_irq(&ms->lock);
  590. bio_list_merge(&ms->failures, &sync);
  591. spin_unlock_irq(&ms->lock);
  592. wakeup_mirrord(ms);
  593. } else
  594. while ((bio = bio_list_pop(&sync)))
  595. do_write(ms, bio);
  596. while ((bio = bio_list_pop(&recover)))
  597. dm_rh_delay(ms->rh, bio);
  598. while ((bio = bio_list_pop(&nosync))) {
  599. map_bio(get_default_mirror(ms), bio);
  600. generic_make_request(bio);
  601. }
  602. }
  603. static void do_failures(struct mirror_set *ms, struct bio_list *failures)
  604. {
  605. struct bio *bio;
  606. if (!failures->head)
  607. return;
  608. if (!ms->log_failure) {
  609. while ((bio = bio_list_pop(failures))) {
  610. ms->in_sync = 0;
  611. dm_rh_mark_nosync(ms->rh, bio, bio->bi_size, 0);
  612. }
  613. return;
  614. }
  615. /*
  616. * If the log has failed, unattempted writes are being
  617. * put on the failures list. We can't issue those writes
  618. * until a log has been marked, so we must store them.
  619. *
  620. * If a 'noflush' suspend is in progress, we can requeue
  621. * the I/O's to the core. This give userspace a chance
  622. * to reconfigure the mirror, at which point the core
  623. * will reissue the writes. If the 'noflush' flag is
  624. * not set, we have no choice but to return errors.
  625. *
  626. * Some writes on the failures list may have been
  627. * submitted before the log failure and represent a
  628. * failure to write to one of the devices. It is ok
  629. * for us to treat them the same and requeue them
  630. * as well.
  631. */
  632. if (dm_noflush_suspending(ms->ti)) {
  633. while ((bio = bio_list_pop(failures)))
  634. bio_endio(bio, DM_ENDIO_REQUEUE);
  635. return;
  636. }
  637. if (atomic_read(&ms->suspend)) {
  638. while ((bio = bio_list_pop(failures)))
  639. bio_endio(bio, -EIO);
  640. return;
  641. }
  642. spin_lock_irq(&ms->lock);
  643. bio_list_merge(&ms->failures, failures);
  644. spin_unlock_irq(&ms->lock);
  645. delayed_wake(ms);
  646. }
  647. static void trigger_event(struct work_struct *work)
  648. {
  649. struct mirror_set *ms =
  650. container_of(work, struct mirror_set, trigger_event);
  651. dm_table_event(ms->ti->table);
  652. }
  653. /*-----------------------------------------------------------------
  654. * kmirrord
  655. *---------------------------------------------------------------*/
  656. static void do_mirror(struct work_struct *work)
  657. {
  658. struct mirror_set *ms = container_of(work, struct mirror_set,
  659. kmirrord_work);
  660. struct bio_list reads, writes, failures;
  661. unsigned long flags;
  662. spin_lock_irqsave(&ms->lock, flags);
  663. reads = ms->reads;
  664. writes = ms->writes;
  665. failures = ms->failures;
  666. bio_list_init(&ms->reads);
  667. bio_list_init(&ms->writes);
  668. bio_list_init(&ms->failures);
  669. spin_unlock_irqrestore(&ms->lock, flags);
  670. dm_rh_update_states(ms->rh, errors_handled(ms));
  671. do_recovery(ms);
  672. do_reads(ms, &reads);
  673. do_writes(ms, &writes);
  674. do_failures(ms, &failures);
  675. dm_table_unplug_all(ms->ti->table);
  676. }
  677. /*-----------------------------------------------------------------
  678. * Target functions
  679. *---------------------------------------------------------------*/
  680. static struct mirror_set *alloc_context(unsigned int nr_mirrors,
  681. uint32_t region_size,
  682. struct dm_target *ti,
  683. struct dm_dirty_log *dl)
  684. {
  685. size_t len;
  686. struct mirror_set *ms = NULL;
  687. len = sizeof(*ms) + (sizeof(ms->mirror[0]) * nr_mirrors);
  688. ms = kzalloc(len, GFP_KERNEL);
  689. if (!ms) {
  690. ti->error = "Cannot allocate mirror context";
  691. return NULL;
  692. }
  693. spin_lock_init(&ms->lock);
  694. ms->ti = ti;
  695. ms->nr_mirrors = nr_mirrors;
  696. ms->nr_regions = dm_sector_div_up(ti->len, region_size);
  697. ms->in_sync = 0;
  698. ms->log_failure = 0;
  699. atomic_set(&ms->suspend, 0);
  700. atomic_set(&ms->default_mirror, DEFAULT_MIRROR);
  701. ms->read_record_pool = mempool_create_slab_pool(MIN_READ_RECORDS,
  702. _dm_raid1_read_record_cache);
  703. if (!ms->read_record_pool) {
  704. ti->error = "Error creating mirror read_record_pool";
  705. kfree(ms);
  706. return NULL;
  707. }
  708. ms->io_client = dm_io_client_create(DM_IO_PAGES);
  709. if (IS_ERR(ms->io_client)) {
  710. ti->error = "Error creating dm_io client";
  711. mempool_destroy(ms->read_record_pool);
  712. kfree(ms);
  713. return NULL;
  714. }
  715. ms->rh = dm_region_hash_create(ms, dispatch_bios, wakeup_mirrord,
  716. wakeup_all_recovery_waiters,
  717. ms->ti->begin, MAX_RECOVERY,
  718. dl, region_size, ms->nr_regions);
  719. if (IS_ERR(ms->rh)) {
  720. ti->error = "Error creating dirty region hash";
  721. dm_io_client_destroy(ms->io_client);
  722. mempool_destroy(ms->read_record_pool);
  723. kfree(ms);
  724. return NULL;
  725. }
  726. return ms;
  727. }
  728. static void free_context(struct mirror_set *ms, struct dm_target *ti,
  729. unsigned int m)
  730. {
  731. while (m--)
  732. dm_put_device(ti, ms->mirror[m].dev);
  733. dm_io_client_destroy(ms->io_client);
  734. dm_region_hash_destroy(ms->rh);
  735. mempool_destroy(ms->read_record_pool);
  736. kfree(ms);
  737. }
  738. static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
  739. unsigned int mirror, char **argv)
  740. {
  741. unsigned long long offset;
  742. if (sscanf(argv[1], "%llu", &offset) != 1) {
  743. ti->error = "Invalid offset";
  744. return -EINVAL;
  745. }
  746. if (dm_get_device(ti, argv[0], offset, ti->len,
  747. dm_table_get_mode(ti->table),
  748. &ms->mirror[mirror].dev)) {
  749. ti->error = "Device lookup failure";
  750. return -ENXIO;
  751. }
  752. ms->mirror[mirror].ms = ms;
  753. atomic_set(&(ms->mirror[mirror].error_count), 0);
  754. ms->mirror[mirror].error_type = 0;
  755. ms->mirror[mirror].offset = offset;
  756. return 0;
  757. }
  758. /*
  759. * Create dirty log: log_type #log_params <log_params>
  760. */
  761. static struct dm_dirty_log *create_dirty_log(struct dm_target *ti,
  762. unsigned argc, char **argv,
  763. unsigned *args_used)
  764. {
  765. unsigned param_count;
  766. struct dm_dirty_log *dl;
  767. if (argc < 2) {
  768. ti->error = "Insufficient mirror log arguments";
  769. return NULL;
  770. }
  771. if (sscanf(argv[1], "%u", &param_count) != 1) {
  772. ti->error = "Invalid mirror log argument count";
  773. return NULL;
  774. }
  775. *args_used = 2 + param_count;
  776. if (argc < *args_used) {
  777. ti->error = "Insufficient mirror log arguments";
  778. return NULL;
  779. }
  780. dl = dm_dirty_log_create(argv[0], ti, mirror_flush, param_count,
  781. argv + 2);
  782. if (!dl) {
  783. ti->error = "Error creating mirror dirty log";
  784. return NULL;
  785. }
  786. return dl;
  787. }
  788. static int parse_features(struct mirror_set *ms, unsigned argc, char **argv,
  789. unsigned *args_used)
  790. {
  791. unsigned num_features;
  792. struct dm_target *ti = ms->ti;
  793. *args_used = 0;
  794. if (!argc)
  795. return 0;
  796. if (sscanf(argv[0], "%u", &num_features) != 1) {
  797. ti->error = "Invalid number of features";
  798. return -EINVAL;
  799. }
  800. argc--;
  801. argv++;
  802. (*args_used)++;
  803. if (num_features > argc) {
  804. ti->error = "Not enough arguments to support feature count";
  805. return -EINVAL;
  806. }
  807. if (!strcmp("handle_errors", argv[0]))
  808. ms->features |= DM_RAID1_HANDLE_ERRORS;
  809. else {
  810. ti->error = "Unrecognised feature requested";
  811. return -EINVAL;
  812. }
  813. (*args_used)++;
  814. return 0;
  815. }
  816. /*
  817. * Construct a mirror mapping:
  818. *
  819. * log_type #log_params <log_params>
  820. * #mirrors [mirror_path offset]{2,}
  821. * [#features <features>]
  822. *
  823. * log_type is "core" or "disk"
  824. * #log_params is between 1 and 3
  825. *
  826. * If present, features must be "handle_errors".
  827. */
  828. static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
  829. {
  830. int r;
  831. unsigned int nr_mirrors, m, args_used;
  832. struct mirror_set *ms;
  833. struct dm_dirty_log *dl;
  834. dl = create_dirty_log(ti, argc, argv, &args_used);
  835. if (!dl)
  836. return -EINVAL;
  837. argv += args_used;
  838. argc -= args_used;
  839. if (!argc || sscanf(argv[0], "%u", &nr_mirrors) != 1 ||
  840. nr_mirrors < 2 || nr_mirrors > DM_KCOPYD_MAX_REGIONS + 1) {
  841. ti->error = "Invalid number of mirrors";
  842. dm_dirty_log_destroy(dl);
  843. return -EINVAL;
  844. }
  845. argv++, argc--;
  846. if (argc < nr_mirrors * 2) {
  847. ti->error = "Too few mirror arguments";
  848. dm_dirty_log_destroy(dl);
  849. return -EINVAL;
  850. }
  851. ms = alloc_context(nr_mirrors, dl->type->get_region_size(dl), ti, dl);
  852. if (!ms) {
  853. dm_dirty_log_destroy(dl);
  854. return -ENOMEM;
  855. }
  856. /* Get the mirror parameter sets */
  857. for (m = 0; m < nr_mirrors; m++) {
  858. r = get_mirror(ms, ti, m, argv);
  859. if (r) {
  860. free_context(ms, ti, m);
  861. return r;
  862. }
  863. argv += 2;
  864. argc -= 2;
  865. }
  866. ti->private = ms;
  867. ti->split_io = dm_rh_get_region_size(ms->rh);
  868. ti->num_flush_requests = 1;
  869. ms->kmirrord_wq = create_singlethread_workqueue("kmirrord");
  870. if (!ms->kmirrord_wq) {
  871. DMERR("couldn't start kmirrord");
  872. r = -ENOMEM;
  873. goto err_free_context;
  874. }
  875. INIT_WORK(&ms->kmirrord_work, do_mirror);
  876. init_timer(&ms->timer);
  877. ms->timer_pending = 0;
  878. INIT_WORK(&ms->trigger_event, trigger_event);
  879. r = parse_features(ms, argc, argv, &args_used);
  880. if (r)
  881. goto err_destroy_wq;
  882. argv += args_used;
  883. argc -= args_used;
  884. /*
  885. * Any read-balancing addition depends on the
  886. * DM_RAID1_HANDLE_ERRORS flag being present.
  887. * This is because the decision to balance depends
  888. * on the sync state of a region. If the above
  889. * flag is not present, we ignore errors; and
  890. * the sync state may be inaccurate.
  891. */
  892. if (argc) {
  893. ti->error = "Too many mirror arguments";
  894. r = -EINVAL;
  895. goto err_destroy_wq;
  896. }
  897. r = dm_kcopyd_client_create(DM_KCOPYD_PAGES, &ms->kcopyd_client);
  898. if (r)
  899. goto err_destroy_wq;
  900. wakeup_mirrord(ms);
  901. return 0;
  902. err_destroy_wq:
  903. destroy_workqueue(ms->kmirrord_wq);
  904. err_free_context:
  905. free_context(ms, ti, ms->nr_mirrors);
  906. return r;
  907. }
  908. static void mirror_dtr(struct dm_target *ti)
  909. {
  910. struct mirror_set *ms = (struct mirror_set *) ti->private;
  911. del_timer_sync(&ms->timer);
  912. flush_workqueue(ms->kmirrord_wq);
  913. flush_scheduled_work();
  914. dm_kcopyd_client_destroy(ms->kcopyd_client);
  915. destroy_workqueue(ms->kmirrord_wq);
  916. free_context(ms, ti, ms->nr_mirrors);
  917. }
  918. /*
  919. * Mirror mapping function
  920. */
  921. static int mirror_map(struct dm_target *ti, struct bio *bio,
  922. union map_info *map_context)
  923. {
  924. int r, rw = bio_rw(bio);
  925. struct mirror *m;
  926. struct mirror_set *ms = ti->private;
  927. struct dm_raid1_read_record *read_record = NULL;
  928. struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
  929. if (rw == WRITE) {
  930. /* Save region for mirror_end_io() handler */
  931. map_context->ll = dm_rh_bio_to_region(ms->rh, bio);
  932. queue_bio(ms, bio, rw);
  933. return DM_MAPIO_SUBMITTED;
  934. }
  935. r = log->type->in_sync(log, dm_rh_bio_to_region(ms->rh, bio), 0);
  936. if (r < 0 && r != -EWOULDBLOCK)
  937. return r;
  938. /*
  939. * If region is not in-sync queue the bio.
  940. */
  941. if (!r || (r == -EWOULDBLOCK)) {
  942. if (rw == READA)
  943. return -EWOULDBLOCK;
  944. queue_bio(ms, bio, rw);
  945. return DM_MAPIO_SUBMITTED;
  946. }
  947. /*
  948. * The region is in-sync and we can perform reads directly.
  949. * Store enough information so we can retry if it fails.
  950. */
  951. m = choose_mirror(ms, bio->bi_sector);
  952. if (unlikely(!m))
  953. return -EIO;
  954. read_record = mempool_alloc(ms->read_record_pool, GFP_NOIO);
  955. if (likely(read_record)) {
  956. dm_bio_record(&read_record->details, bio);
  957. map_context->ptr = read_record;
  958. read_record->m = m;
  959. }
  960. map_bio(m, bio);
  961. return DM_MAPIO_REMAPPED;
  962. }
  963. static int mirror_end_io(struct dm_target *ti, struct bio *bio,
  964. int error, union map_info *map_context)
  965. {
  966. int rw = bio_rw(bio);
  967. struct mirror_set *ms = (struct mirror_set *) ti->private;
  968. struct mirror *m = NULL;
  969. struct dm_bio_details *bd = NULL;
  970. struct dm_raid1_read_record *read_record = map_context->ptr;
  971. /*
  972. * We need to dec pending if this was a write.
  973. */
  974. if (rw == WRITE) {
  975. if (likely(!bio_empty_barrier(bio)))
  976. dm_rh_dec(ms->rh, map_context->ll);
  977. return error;
  978. }
  979. if (error == -EOPNOTSUPP)
  980. goto out;
  981. if ((error == -EWOULDBLOCK) && bio_rw_flagged(bio, BIO_RW_AHEAD))
  982. goto out;
  983. if (unlikely(error)) {
  984. if (!read_record) {
  985. /*
  986. * There wasn't enough memory to record necessary
  987. * information for a retry or there was no other
  988. * mirror in-sync.
  989. */
  990. DMERR_LIMIT("Mirror read failed.");
  991. return -EIO;
  992. }
  993. m = read_record->m;
  994. DMERR("Mirror read failed from %s. Trying alternative device.",
  995. m->dev->name);
  996. fail_mirror(m, DM_RAID1_READ_ERROR);
  997. /*
  998. * A failed read is requeued for another attempt using an intact
  999. * mirror.
  1000. */
  1001. if (default_ok(m) || mirror_available(ms, bio)) {
  1002. bd = &read_record->details;
  1003. dm_bio_restore(bd, bio);
  1004. mempool_free(read_record, ms->read_record_pool);
  1005. map_context->ptr = NULL;
  1006. queue_bio(ms, bio, rw);
  1007. return 1;
  1008. }
  1009. DMERR("All replicated volumes dead, failing I/O");
  1010. }
  1011. out:
  1012. if (read_record) {
  1013. mempool_free(read_record, ms->read_record_pool);
  1014. map_context->ptr = NULL;
  1015. }
  1016. return error;
  1017. }
  1018. static void mirror_presuspend(struct dm_target *ti)
  1019. {
  1020. struct mirror_set *ms = (struct mirror_set *) ti->private;
  1021. struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
  1022. atomic_set(&ms->suspend, 1);
  1023. /*
  1024. * We must finish up all the work that we've
  1025. * generated (i.e. recovery work).
  1026. */
  1027. dm_rh_stop_recovery(ms->rh);
  1028. wait_event(_kmirrord_recovery_stopped,
  1029. !dm_rh_recovery_in_flight(ms->rh));
  1030. if (log->type->presuspend && log->type->presuspend(log))
  1031. /* FIXME: need better error handling */
  1032. DMWARN("log presuspend failed");
  1033. /*
  1034. * Now that recovery is complete/stopped and the
  1035. * delayed bios are queued, we need to wait for
  1036. * the worker thread to complete. This way,
  1037. * we know that all of our I/O has been pushed.
  1038. */
  1039. flush_workqueue(ms->kmirrord_wq);
  1040. }
  1041. static void mirror_postsuspend(struct dm_target *ti)
  1042. {
  1043. struct mirror_set *ms = ti->private;
  1044. struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
  1045. if (log->type->postsuspend && log->type->postsuspend(log))
  1046. /* FIXME: need better error handling */
  1047. DMWARN("log postsuspend failed");
  1048. }
  1049. static void mirror_resume(struct dm_target *ti)
  1050. {
  1051. struct mirror_set *ms = ti->private;
  1052. struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
  1053. atomic_set(&ms->suspend, 0);
  1054. if (log->type->resume && log->type->resume(log))
  1055. /* FIXME: need better error handling */
  1056. DMWARN("log resume failed");
  1057. dm_rh_start_recovery(ms->rh);
  1058. }
  1059. /*
  1060. * device_status_char
  1061. * @m: mirror device/leg we want the status of
  1062. *
  1063. * We return one character representing the most severe error
  1064. * we have encountered.
  1065. * A => Alive - No failures
  1066. * D => Dead - A write failure occurred leaving mirror out-of-sync
  1067. * S => Sync - A sychronization failure occurred, mirror out-of-sync
  1068. * R => Read - A read failure occurred, mirror data unaffected
  1069. *
  1070. * Returns: <char>
  1071. */
  1072. static char device_status_char(struct mirror *m)
  1073. {
  1074. if (!atomic_read(&(m->error_count)))
  1075. return 'A';
  1076. return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
  1077. (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
  1078. (test_bit(DM_RAID1_SYNC_ERROR, &(m->error_type))) ? 'S' :
  1079. (test_bit(DM_RAID1_READ_ERROR, &(m->error_type))) ? 'R' : 'U';
  1080. }
  1081. static int mirror_status(struct dm_target *ti, status_type_t type,
  1082. char *result, unsigned int maxlen)
  1083. {
  1084. unsigned int m, sz = 0;
  1085. struct mirror_set *ms = (struct mirror_set *) ti->private;
  1086. struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
  1087. char buffer[ms->nr_mirrors + 1];
  1088. switch (type) {
  1089. case STATUSTYPE_INFO:
  1090. DMEMIT("%d ", ms->nr_mirrors);
  1091. for (m = 0; m < ms->nr_mirrors; m++) {
  1092. DMEMIT("%s ", ms->mirror[m].dev->name);
  1093. buffer[m] = device_status_char(&(ms->mirror[m]));
  1094. }
  1095. buffer[m] = '\0';
  1096. DMEMIT("%llu/%llu 1 %s ",
  1097. (unsigned long long)log->type->get_sync_count(log),
  1098. (unsigned long long)ms->nr_regions, buffer);
  1099. sz += log->type->status(log, type, result+sz, maxlen-sz);
  1100. break;
  1101. case STATUSTYPE_TABLE:
  1102. sz = log->type->status(log, type, result, maxlen);
  1103. DMEMIT("%d", ms->nr_mirrors);
  1104. for (m = 0; m < ms->nr_mirrors; m++)
  1105. DMEMIT(" %s %llu", ms->mirror[m].dev->name,
  1106. (unsigned long long)ms->mirror[m].offset);
  1107. if (ms->features & DM_RAID1_HANDLE_ERRORS)
  1108. DMEMIT(" 1 handle_errors");
  1109. }
  1110. return 0;
  1111. }
  1112. static int mirror_iterate_devices(struct dm_target *ti,
  1113. iterate_devices_callout_fn fn, void *data)
  1114. {
  1115. struct mirror_set *ms = ti->private;
  1116. int ret = 0;
  1117. unsigned i;
  1118. for (i = 0; !ret && i < ms->nr_mirrors; i++)
  1119. ret = fn(ti, ms->mirror[i].dev,
  1120. ms->mirror[i].offset, ti->len, data);
  1121. return ret;
  1122. }
  1123. static struct target_type mirror_target = {
  1124. .name = "mirror",
  1125. .version = {1, 12, 0},
  1126. .module = THIS_MODULE,
  1127. .ctr = mirror_ctr,
  1128. .dtr = mirror_dtr,
  1129. .map = mirror_map,
  1130. .end_io = mirror_end_io,
  1131. .presuspend = mirror_presuspend,
  1132. .postsuspend = mirror_postsuspend,
  1133. .resume = mirror_resume,
  1134. .status = mirror_status,
  1135. .iterate_devices = mirror_iterate_devices,
  1136. };
  1137. static int __init dm_mirror_init(void)
  1138. {
  1139. int r;
  1140. _dm_raid1_read_record_cache = KMEM_CACHE(dm_raid1_read_record, 0);
  1141. if (!_dm_raid1_read_record_cache) {
  1142. DMERR("Can't allocate dm_raid1_read_record cache");
  1143. r = -ENOMEM;
  1144. goto bad_cache;
  1145. }
  1146. r = dm_register_target(&mirror_target);
  1147. if (r < 0) {
  1148. DMERR("Failed to register mirror target");
  1149. goto bad_target;
  1150. }
  1151. return 0;
  1152. bad_target:
  1153. kmem_cache_destroy(_dm_raid1_read_record_cache);
  1154. bad_cache:
  1155. return r;
  1156. }
  1157. static void __exit dm_mirror_exit(void)
  1158. {
  1159. dm_unregister_target(&mirror_target);
  1160. kmem_cache_destroy(_dm_raid1_read_record_cache);
  1161. }
  1162. /* Module hooks */
  1163. module_init(dm_mirror_init);
  1164. module_exit(dm_mirror_exit);
  1165. MODULE_DESCRIPTION(DM_NAME " mirror target");
  1166. MODULE_AUTHOR("Joe Thornber");
  1167. MODULE_LICENSE("GPL");