dm-snap.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  1. /*
  2. * dm-snapshot.c
  3. *
  4. * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
  5. *
  6. * This file is released under the GPL.
  7. */
  8. #include <linux/blkdev.h>
  9. #include <linux/ctype.h>
  10. #include <linux/device-mapper.h>
  11. #include <linux/fs.h>
  12. #include <linux/init.h>
  13. #include <linux/kdev_t.h>
  14. #include <linux/list.h>
  15. #include <linux/mempool.h>
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/log2.h>
  20. #include <linux/dm-kcopyd.h>
  21. #include "dm-snap.h"
  22. #include "dm-bio-list.h"
  23. #define DM_MSG_PREFIX "snapshots"
  24. /*
  25. * The percentage increment we will wake up users at
  26. */
  27. #define WAKE_UP_PERCENT 5
  28. /*
  29. * kcopyd priority of snapshot operations
  30. */
  31. #define SNAPSHOT_COPY_PRIORITY 2
  32. /*
  33. * Reserve 1MB for each snapshot initially (with minimum of 1 page).
  34. */
  35. #define SNAPSHOT_PAGES (((1UL << 20) >> PAGE_SHIFT) ? : 1)
  36. /*
  37. * The size of the mempool used to track chunks in use.
  38. */
  39. #define MIN_IOS 256
  40. static struct workqueue_struct *ksnapd;
  41. static void flush_queued_bios(struct work_struct *work);
  42. struct dm_snap_pending_exception {
  43. struct dm_snap_exception e;
  44. /*
  45. * Origin buffers waiting for this to complete are held
  46. * in a bio list
  47. */
  48. struct bio_list origin_bios;
  49. struct bio_list snapshot_bios;
  50. /*
  51. * Short-term queue of pending exceptions prior to submission.
  52. */
  53. struct list_head list;
  54. /*
  55. * The primary pending_exception is the one that holds
  56. * the ref_count and the list of origin_bios for a
  57. * group of pending_exceptions. It is always last to get freed.
  58. * These fields get set up when writing to the origin.
  59. */
  60. struct dm_snap_pending_exception *primary_pe;
  61. /*
  62. * Number of pending_exceptions processing this chunk.
  63. * When this drops to zero we must complete the origin bios.
  64. * If incrementing or decrementing this, hold pe->snap->lock for
  65. * the sibling concerned and not pe->primary_pe->snap->lock unless
  66. * they are the same.
  67. */
  68. atomic_t ref_count;
  69. /* Pointer back to snapshot context */
  70. struct dm_snapshot *snap;
  71. /*
  72. * 1 indicates the exception has already been sent to
  73. * kcopyd.
  74. */
  75. int started;
  76. };
  77. /*
  78. * Hash table mapping origin volumes to lists of snapshots and
  79. * a lock to protect it
  80. */
  81. static struct kmem_cache *exception_cache;
  82. static struct kmem_cache *pending_cache;
  83. struct dm_snap_tracked_chunk {
  84. struct hlist_node node;
  85. chunk_t chunk;
  86. };
  87. static struct kmem_cache *tracked_chunk_cache;
  88. static struct dm_snap_tracked_chunk *track_chunk(struct dm_snapshot *s,
  89. chunk_t chunk)
  90. {
  91. struct dm_snap_tracked_chunk *c = mempool_alloc(s->tracked_chunk_pool,
  92. GFP_NOIO);
  93. unsigned long flags;
  94. c->chunk = chunk;
  95. spin_lock_irqsave(&s->tracked_chunk_lock, flags);
  96. hlist_add_head(&c->node,
  97. &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)]);
  98. spin_unlock_irqrestore(&s->tracked_chunk_lock, flags);
  99. return c;
  100. }
  101. static void stop_tracking_chunk(struct dm_snapshot *s,
  102. struct dm_snap_tracked_chunk *c)
  103. {
  104. unsigned long flags;
  105. spin_lock_irqsave(&s->tracked_chunk_lock, flags);
  106. hlist_del(&c->node);
  107. spin_unlock_irqrestore(&s->tracked_chunk_lock, flags);
  108. mempool_free(c, s->tracked_chunk_pool);
  109. }
  110. static int __chunk_is_tracked(struct dm_snapshot *s, chunk_t chunk)
  111. {
  112. struct dm_snap_tracked_chunk *c;
  113. struct hlist_node *hn;
  114. int found = 0;
  115. spin_lock_irq(&s->tracked_chunk_lock);
  116. hlist_for_each_entry(c, hn,
  117. &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)], node) {
  118. if (c->chunk == chunk) {
  119. found = 1;
  120. break;
  121. }
  122. }
  123. spin_unlock_irq(&s->tracked_chunk_lock);
  124. return found;
  125. }
  126. /*
  127. * One of these per registered origin, held in the snapshot_origins hash
  128. */
  129. struct origin {
  130. /* The origin device */
  131. struct block_device *bdev;
  132. struct list_head hash_list;
  133. /* List of snapshots for this origin */
  134. struct list_head snapshots;
  135. };
  136. /*
  137. * Size of the hash table for origin volumes. If we make this
  138. * the size of the minors list then it should be nearly perfect
  139. */
  140. #define ORIGIN_HASH_SIZE 256
  141. #define ORIGIN_MASK 0xFF
  142. static struct list_head *_origins;
  143. static struct rw_semaphore _origins_lock;
  144. static int init_origin_hash(void)
  145. {
  146. int i;
  147. _origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
  148. GFP_KERNEL);
  149. if (!_origins) {
  150. DMERR("unable to allocate memory");
  151. return -ENOMEM;
  152. }
  153. for (i = 0; i < ORIGIN_HASH_SIZE; i++)
  154. INIT_LIST_HEAD(_origins + i);
  155. init_rwsem(&_origins_lock);
  156. return 0;
  157. }
  158. static void exit_origin_hash(void)
  159. {
  160. kfree(_origins);
  161. }
  162. static unsigned origin_hash(struct block_device *bdev)
  163. {
  164. return bdev->bd_dev & ORIGIN_MASK;
  165. }
  166. static struct origin *__lookup_origin(struct block_device *origin)
  167. {
  168. struct list_head *ol;
  169. struct origin *o;
  170. ol = &_origins[origin_hash(origin)];
  171. list_for_each_entry (o, ol, hash_list)
  172. if (bdev_equal(o->bdev, origin))
  173. return o;
  174. return NULL;
  175. }
  176. static void __insert_origin(struct origin *o)
  177. {
  178. struct list_head *sl = &_origins[origin_hash(o->bdev)];
  179. list_add_tail(&o->hash_list, sl);
  180. }
  181. /*
  182. * Make a note of the snapshot and its origin so we can look it
  183. * up when the origin has a write on it.
  184. */
  185. static int register_snapshot(struct dm_snapshot *snap)
  186. {
  187. struct origin *o, *new_o;
  188. struct block_device *bdev = snap->origin->bdev;
  189. new_o = kmalloc(sizeof(*new_o), GFP_KERNEL);
  190. if (!new_o)
  191. return -ENOMEM;
  192. down_write(&_origins_lock);
  193. o = __lookup_origin(bdev);
  194. if (o)
  195. kfree(new_o);
  196. else {
  197. /* New origin */
  198. o = new_o;
  199. /* Initialise the struct */
  200. INIT_LIST_HEAD(&o->snapshots);
  201. o->bdev = bdev;
  202. __insert_origin(o);
  203. }
  204. list_add_tail(&snap->list, &o->snapshots);
  205. up_write(&_origins_lock);
  206. return 0;
  207. }
  208. static void unregister_snapshot(struct dm_snapshot *s)
  209. {
  210. struct origin *o;
  211. down_write(&_origins_lock);
  212. o = __lookup_origin(s->origin->bdev);
  213. list_del(&s->list);
  214. if (list_empty(&o->snapshots)) {
  215. list_del(&o->hash_list);
  216. kfree(o);
  217. }
  218. up_write(&_origins_lock);
  219. }
  220. /*
  221. * Implementation of the exception hash tables.
  222. * The lowest hash_shift bits of the chunk number are ignored, allowing
  223. * some consecutive chunks to be grouped together.
  224. */
  225. static int init_exception_table(struct exception_table *et, uint32_t size,
  226. unsigned hash_shift)
  227. {
  228. unsigned int i;
  229. et->hash_shift = hash_shift;
  230. et->hash_mask = size - 1;
  231. et->table = dm_vcalloc(size, sizeof(struct list_head));
  232. if (!et->table)
  233. return -ENOMEM;
  234. for (i = 0; i < size; i++)
  235. INIT_LIST_HEAD(et->table + i);
  236. return 0;
  237. }
  238. static void exit_exception_table(struct exception_table *et, struct kmem_cache *mem)
  239. {
  240. struct list_head *slot;
  241. struct dm_snap_exception *ex, *next;
  242. int i, size;
  243. size = et->hash_mask + 1;
  244. for (i = 0; i < size; i++) {
  245. slot = et->table + i;
  246. list_for_each_entry_safe (ex, next, slot, hash_list)
  247. kmem_cache_free(mem, ex);
  248. }
  249. vfree(et->table);
  250. }
  251. static uint32_t exception_hash(struct exception_table *et, chunk_t chunk)
  252. {
  253. return (chunk >> et->hash_shift) & et->hash_mask;
  254. }
  255. static void insert_exception(struct exception_table *eh,
  256. struct dm_snap_exception *e)
  257. {
  258. struct list_head *l = &eh->table[exception_hash(eh, e->old_chunk)];
  259. list_add(&e->hash_list, l);
  260. }
  261. static void remove_exception(struct dm_snap_exception *e)
  262. {
  263. list_del(&e->hash_list);
  264. }
  265. /*
  266. * Return the exception data for a sector, or NULL if not
  267. * remapped.
  268. */
  269. static struct dm_snap_exception *lookup_exception(struct exception_table *et,
  270. chunk_t chunk)
  271. {
  272. struct list_head *slot;
  273. struct dm_snap_exception *e;
  274. slot = &et->table[exception_hash(et, chunk)];
  275. list_for_each_entry (e, slot, hash_list)
  276. if (chunk >= e->old_chunk &&
  277. chunk <= e->old_chunk + dm_consecutive_chunk_count(e))
  278. return e;
  279. return NULL;
  280. }
  281. static struct dm_snap_exception *alloc_exception(void)
  282. {
  283. struct dm_snap_exception *e;
  284. e = kmem_cache_alloc(exception_cache, GFP_NOIO);
  285. if (!e)
  286. e = kmem_cache_alloc(exception_cache, GFP_ATOMIC);
  287. return e;
  288. }
  289. static void free_exception(struct dm_snap_exception *e)
  290. {
  291. kmem_cache_free(exception_cache, e);
  292. }
  293. static struct dm_snap_pending_exception *alloc_pending_exception(struct dm_snapshot *s)
  294. {
  295. struct dm_snap_pending_exception *pe = mempool_alloc(s->pending_pool,
  296. GFP_NOIO);
  297. atomic_inc(&s->pending_exceptions_count);
  298. pe->snap = s;
  299. return pe;
  300. }
  301. static void free_pending_exception(struct dm_snap_pending_exception *pe)
  302. {
  303. struct dm_snapshot *s = pe->snap;
  304. mempool_free(pe, s->pending_pool);
  305. smp_mb__before_atomic_dec();
  306. atomic_dec(&s->pending_exceptions_count);
  307. }
  308. static void insert_completed_exception(struct dm_snapshot *s,
  309. struct dm_snap_exception *new_e)
  310. {
  311. struct exception_table *eh = &s->complete;
  312. struct list_head *l;
  313. struct dm_snap_exception *e = NULL;
  314. l = &eh->table[exception_hash(eh, new_e->old_chunk)];
  315. /* Add immediately if this table doesn't support consecutive chunks */
  316. if (!eh->hash_shift)
  317. goto out;
  318. /* List is ordered by old_chunk */
  319. list_for_each_entry_reverse(e, l, hash_list) {
  320. /* Insert after an existing chunk? */
  321. if (new_e->old_chunk == (e->old_chunk +
  322. dm_consecutive_chunk_count(e) + 1) &&
  323. new_e->new_chunk == (dm_chunk_number(e->new_chunk) +
  324. dm_consecutive_chunk_count(e) + 1)) {
  325. dm_consecutive_chunk_count_inc(e);
  326. free_exception(new_e);
  327. return;
  328. }
  329. /* Insert before an existing chunk? */
  330. if (new_e->old_chunk == (e->old_chunk - 1) &&
  331. new_e->new_chunk == (dm_chunk_number(e->new_chunk) - 1)) {
  332. dm_consecutive_chunk_count_inc(e);
  333. e->old_chunk--;
  334. e->new_chunk--;
  335. free_exception(new_e);
  336. return;
  337. }
  338. if (new_e->old_chunk > e->old_chunk)
  339. break;
  340. }
  341. out:
  342. list_add(&new_e->hash_list, e ? &e->hash_list : l);
  343. }
  344. int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new)
  345. {
  346. struct dm_snap_exception *e;
  347. e = alloc_exception();
  348. if (!e)
  349. return -ENOMEM;
  350. e->old_chunk = old;
  351. /* Consecutive_count is implicitly initialised to zero */
  352. e->new_chunk = new;
  353. insert_completed_exception(s, e);
  354. return 0;
  355. }
  356. /*
  357. * Hard coded magic.
  358. */
  359. static int calc_max_buckets(void)
  360. {
  361. /* use a fixed size of 2MB */
  362. unsigned long mem = 2 * 1024 * 1024;
  363. mem /= sizeof(struct list_head);
  364. return mem;
  365. }
  366. /*
  367. * Allocate room for a suitable hash table.
  368. */
  369. static int init_hash_tables(struct dm_snapshot *s)
  370. {
  371. sector_t hash_size, cow_dev_size, origin_dev_size, max_buckets;
  372. /*
  373. * Calculate based on the size of the original volume or
  374. * the COW volume...
  375. */
  376. cow_dev_size = get_dev_size(s->cow->bdev);
  377. origin_dev_size = get_dev_size(s->origin->bdev);
  378. max_buckets = calc_max_buckets();
  379. hash_size = min(origin_dev_size, cow_dev_size) >> s->chunk_shift;
  380. hash_size = min(hash_size, max_buckets);
  381. hash_size = rounddown_pow_of_two(hash_size);
  382. if (init_exception_table(&s->complete, hash_size,
  383. DM_CHUNK_CONSECUTIVE_BITS))
  384. return -ENOMEM;
  385. /*
  386. * Allocate hash table for in-flight exceptions
  387. * Make this smaller than the real hash table
  388. */
  389. hash_size >>= 3;
  390. if (hash_size < 64)
  391. hash_size = 64;
  392. if (init_exception_table(&s->pending, hash_size, 0)) {
  393. exit_exception_table(&s->complete, exception_cache);
  394. return -ENOMEM;
  395. }
  396. return 0;
  397. }
  398. /*
  399. * Round a number up to the nearest 'size' boundary. size must
  400. * be a power of 2.
  401. */
  402. static ulong round_up(ulong n, ulong size)
  403. {
  404. size--;
  405. return (n + size) & ~size;
  406. }
  407. static int set_chunk_size(struct dm_snapshot *s, const char *chunk_size_arg,
  408. char **error)
  409. {
  410. unsigned long chunk_size;
  411. char *value;
  412. chunk_size = simple_strtoul(chunk_size_arg, &value, 10);
  413. if (*chunk_size_arg == '\0' || *value != '\0') {
  414. *error = "Invalid chunk size";
  415. return -EINVAL;
  416. }
  417. if (!chunk_size) {
  418. s->chunk_size = s->chunk_mask = s->chunk_shift = 0;
  419. return 0;
  420. }
  421. /*
  422. * Chunk size must be multiple of page size. Silently
  423. * round up if it's not.
  424. */
  425. chunk_size = round_up(chunk_size, PAGE_SIZE >> 9);
  426. /* Check chunk_size is a power of 2 */
  427. if (!is_power_of_2(chunk_size)) {
  428. *error = "Chunk size is not a power of 2";
  429. return -EINVAL;
  430. }
  431. /* Validate the chunk size against the device block size */
  432. if (chunk_size % (bdev_hardsect_size(s->cow->bdev) >> 9)) {
  433. *error = "Chunk size is not a multiple of device blocksize";
  434. return -EINVAL;
  435. }
  436. s->chunk_size = chunk_size;
  437. s->chunk_mask = chunk_size - 1;
  438. s->chunk_shift = ffs(chunk_size) - 1;
  439. return 0;
  440. }
  441. /*
  442. * Construct a snapshot mapping: <origin_dev> <COW-dev> <p/n> <chunk-size>
  443. */
  444. static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
  445. {
  446. struct dm_snapshot *s;
  447. int i;
  448. int r = -EINVAL;
  449. char persistent;
  450. char *origin_path;
  451. char *cow_path;
  452. if (argc != 4) {
  453. ti->error = "requires exactly 4 arguments";
  454. r = -EINVAL;
  455. goto bad1;
  456. }
  457. origin_path = argv[0];
  458. cow_path = argv[1];
  459. persistent = toupper(*argv[2]);
  460. if (persistent != 'P' && persistent != 'N') {
  461. ti->error = "Persistent flag is not P or N";
  462. r = -EINVAL;
  463. goto bad1;
  464. }
  465. s = kmalloc(sizeof(*s), GFP_KERNEL);
  466. if (s == NULL) {
  467. ti->error = "Cannot allocate snapshot context private "
  468. "structure";
  469. r = -ENOMEM;
  470. goto bad1;
  471. }
  472. r = dm_get_device(ti, origin_path, 0, ti->len, FMODE_READ, &s->origin);
  473. if (r) {
  474. ti->error = "Cannot get origin device";
  475. goto bad2;
  476. }
  477. r = dm_get_device(ti, cow_path, 0, 0,
  478. FMODE_READ | FMODE_WRITE, &s->cow);
  479. if (r) {
  480. dm_put_device(ti, s->origin);
  481. ti->error = "Cannot get COW device";
  482. goto bad2;
  483. }
  484. r = set_chunk_size(s, argv[3], &ti->error);
  485. if (r)
  486. goto bad3;
  487. s->type = persistent;
  488. s->valid = 1;
  489. s->active = 0;
  490. atomic_set(&s->pending_exceptions_count, 0);
  491. init_rwsem(&s->lock);
  492. spin_lock_init(&s->pe_lock);
  493. s->ti = ti;
  494. /* Allocate hash table for COW data */
  495. if (init_hash_tables(s)) {
  496. ti->error = "Unable to allocate hash table space";
  497. r = -ENOMEM;
  498. goto bad3;
  499. }
  500. s->store.snap = s;
  501. if (persistent == 'P')
  502. r = dm_create_persistent(&s->store);
  503. else
  504. r = dm_create_transient(&s->store);
  505. if (r) {
  506. ti->error = "Couldn't create exception store";
  507. r = -EINVAL;
  508. goto bad4;
  509. }
  510. r = dm_kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client);
  511. if (r) {
  512. ti->error = "Could not create kcopyd client";
  513. goto bad5;
  514. }
  515. s->pending_pool = mempool_create_slab_pool(MIN_IOS, pending_cache);
  516. if (!s->pending_pool) {
  517. ti->error = "Could not allocate mempool for pending exceptions";
  518. goto bad6;
  519. }
  520. s->tracked_chunk_pool = mempool_create_slab_pool(MIN_IOS,
  521. tracked_chunk_cache);
  522. if (!s->tracked_chunk_pool) {
  523. ti->error = "Could not allocate tracked_chunk mempool for "
  524. "tracking reads";
  525. goto bad_tracked_chunk_pool;
  526. }
  527. for (i = 0; i < DM_TRACKED_CHUNK_HASH_SIZE; i++)
  528. INIT_HLIST_HEAD(&s->tracked_chunk_hash[i]);
  529. spin_lock_init(&s->tracked_chunk_lock);
  530. /* Metadata must only be loaded into one table at once */
  531. r = s->store.read_metadata(&s->store);
  532. if (r < 0) {
  533. ti->error = "Failed to read snapshot metadata";
  534. goto bad_load_and_register;
  535. } else if (r > 0) {
  536. s->valid = 0;
  537. DMWARN("Snapshot is marked invalid.");
  538. }
  539. bio_list_init(&s->queued_bios);
  540. INIT_WORK(&s->queued_bios_work, flush_queued_bios);
  541. /* Add snapshot to the list of snapshots for this origin */
  542. /* Exceptions aren't triggered till snapshot_resume() is called */
  543. if (register_snapshot(s)) {
  544. r = -EINVAL;
  545. ti->error = "Cannot register snapshot origin";
  546. goto bad_load_and_register;
  547. }
  548. ti->private = s;
  549. ti->split_io = s->chunk_size;
  550. return 0;
  551. bad_load_and_register:
  552. mempool_destroy(s->tracked_chunk_pool);
  553. bad_tracked_chunk_pool:
  554. mempool_destroy(s->pending_pool);
  555. bad6:
  556. dm_kcopyd_client_destroy(s->kcopyd_client);
  557. bad5:
  558. s->store.destroy(&s->store);
  559. bad4:
  560. exit_exception_table(&s->pending, pending_cache);
  561. exit_exception_table(&s->complete, exception_cache);
  562. bad3:
  563. dm_put_device(ti, s->cow);
  564. dm_put_device(ti, s->origin);
  565. bad2:
  566. kfree(s);
  567. bad1:
  568. return r;
  569. }
  570. static void __free_exceptions(struct dm_snapshot *s)
  571. {
  572. dm_kcopyd_client_destroy(s->kcopyd_client);
  573. s->kcopyd_client = NULL;
  574. exit_exception_table(&s->pending, pending_cache);
  575. exit_exception_table(&s->complete, exception_cache);
  576. s->store.destroy(&s->store);
  577. }
  578. static void snapshot_dtr(struct dm_target *ti)
  579. {
  580. #ifdef CONFIG_DM_DEBUG
  581. int i;
  582. #endif
  583. struct dm_snapshot *s = ti->private;
  584. flush_workqueue(ksnapd);
  585. /* Prevent further origin writes from using this snapshot. */
  586. /* After this returns there can be no new kcopyd jobs. */
  587. unregister_snapshot(s);
  588. while (atomic_read(&s->pending_exceptions_count))
  589. yield();
  590. /*
  591. * Ensure instructions in mempool_destroy aren't reordered
  592. * before atomic_read.
  593. */
  594. smp_mb();
  595. #ifdef CONFIG_DM_DEBUG
  596. for (i = 0; i < DM_TRACKED_CHUNK_HASH_SIZE; i++)
  597. BUG_ON(!hlist_empty(&s->tracked_chunk_hash[i]));
  598. #endif
  599. mempool_destroy(s->tracked_chunk_pool);
  600. __free_exceptions(s);
  601. mempool_destroy(s->pending_pool);
  602. dm_put_device(ti, s->origin);
  603. dm_put_device(ti, s->cow);
  604. kfree(s);
  605. }
  606. /*
  607. * Flush a list of buffers.
  608. */
  609. static void flush_bios(struct bio *bio)
  610. {
  611. struct bio *n;
  612. while (bio) {
  613. n = bio->bi_next;
  614. bio->bi_next = NULL;
  615. generic_make_request(bio);
  616. bio = n;
  617. }
  618. }
  619. static void flush_queued_bios(struct work_struct *work)
  620. {
  621. struct dm_snapshot *s =
  622. container_of(work, struct dm_snapshot, queued_bios_work);
  623. struct bio *queued_bios;
  624. unsigned long flags;
  625. spin_lock_irqsave(&s->pe_lock, flags);
  626. queued_bios = bio_list_get(&s->queued_bios);
  627. spin_unlock_irqrestore(&s->pe_lock, flags);
  628. flush_bios(queued_bios);
  629. }
  630. /*
  631. * Error a list of buffers.
  632. */
  633. static void error_bios(struct bio *bio)
  634. {
  635. struct bio *n;
  636. while (bio) {
  637. n = bio->bi_next;
  638. bio->bi_next = NULL;
  639. bio_io_error(bio);
  640. bio = n;
  641. }
  642. }
  643. static void __invalidate_snapshot(struct dm_snapshot *s, int err)
  644. {
  645. if (!s->valid)
  646. return;
  647. if (err == -EIO)
  648. DMERR("Invalidating snapshot: Error reading/writing.");
  649. else if (err == -ENOMEM)
  650. DMERR("Invalidating snapshot: Unable to allocate exception.");
  651. if (s->store.drop_snapshot)
  652. s->store.drop_snapshot(&s->store);
  653. s->valid = 0;
  654. dm_table_event(s->ti->table);
  655. }
  656. static void get_pending_exception(struct dm_snap_pending_exception *pe)
  657. {
  658. atomic_inc(&pe->ref_count);
  659. }
  660. static struct bio *put_pending_exception(struct dm_snap_pending_exception *pe)
  661. {
  662. struct dm_snap_pending_exception *primary_pe;
  663. struct bio *origin_bios = NULL;
  664. primary_pe = pe->primary_pe;
  665. /*
  666. * If this pe is involved in a write to the origin and
  667. * it is the last sibling to complete then release
  668. * the bios for the original write to the origin.
  669. */
  670. if (primary_pe &&
  671. atomic_dec_and_test(&primary_pe->ref_count)) {
  672. origin_bios = bio_list_get(&primary_pe->origin_bios);
  673. free_pending_exception(primary_pe);
  674. }
  675. /*
  676. * Free the pe if it's not linked to an origin write or if
  677. * it's not itself a primary pe.
  678. */
  679. if (!primary_pe || primary_pe != pe)
  680. free_pending_exception(pe);
  681. return origin_bios;
  682. }
  683. static void pending_complete(struct dm_snap_pending_exception *pe, int success)
  684. {
  685. struct dm_snap_exception *e;
  686. struct dm_snapshot *s = pe->snap;
  687. struct bio *origin_bios = NULL;
  688. struct bio *snapshot_bios = NULL;
  689. int error = 0;
  690. if (!success) {
  691. /* Read/write error - snapshot is unusable */
  692. down_write(&s->lock);
  693. __invalidate_snapshot(s, -EIO);
  694. error = 1;
  695. goto out;
  696. }
  697. e = alloc_exception();
  698. if (!e) {
  699. down_write(&s->lock);
  700. __invalidate_snapshot(s, -ENOMEM);
  701. error = 1;
  702. goto out;
  703. }
  704. *e = pe->e;
  705. down_write(&s->lock);
  706. if (!s->valid) {
  707. free_exception(e);
  708. error = 1;
  709. goto out;
  710. }
  711. /*
  712. * Check for conflicting reads. This is extremely improbable,
  713. * so yield() is sufficient and there is no need for a wait queue.
  714. */
  715. while (__chunk_is_tracked(s, pe->e.old_chunk))
  716. yield();
  717. /*
  718. * Add a proper exception, and remove the
  719. * in-flight exception from the list.
  720. */
  721. insert_completed_exception(s, e);
  722. out:
  723. remove_exception(&pe->e);
  724. snapshot_bios = bio_list_get(&pe->snapshot_bios);
  725. origin_bios = put_pending_exception(pe);
  726. up_write(&s->lock);
  727. /* Submit any pending write bios */
  728. if (error)
  729. error_bios(snapshot_bios);
  730. else
  731. flush_bios(snapshot_bios);
  732. flush_bios(origin_bios);
  733. }
  734. static void commit_callback(void *context, int success)
  735. {
  736. struct dm_snap_pending_exception *pe = context;
  737. pending_complete(pe, success);
  738. }
  739. /*
  740. * Called when the copy I/O has finished. kcopyd actually runs
  741. * this code so don't block.
  742. */
  743. static void copy_callback(int read_err, unsigned long write_err, void *context)
  744. {
  745. struct dm_snap_pending_exception *pe = context;
  746. struct dm_snapshot *s = pe->snap;
  747. if (read_err || write_err)
  748. pending_complete(pe, 0);
  749. else
  750. /* Update the metadata if we are persistent */
  751. s->store.commit_exception(&s->store, &pe->e, commit_callback,
  752. pe);
  753. }
  754. /*
  755. * Dispatches the copy operation to kcopyd.
  756. */
  757. static void start_copy(struct dm_snap_pending_exception *pe)
  758. {
  759. struct dm_snapshot *s = pe->snap;
  760. struct dm_io_region src, dest;
  761. struct block_device *bdev = s->origin->bdev;
  762. sector_t dev_size;
  763. dev_size = get_dev_size(bdev);
  764. src.bdev = bdev;
  765. src.sector = chunk_to_sector(s, pe->e.old_chunk);
  766. src.count = min(s->chunk_size, dev_size - src.sector);
  767. dest.bdev = s->cow->bdev;
  768. dest.sector = chunk_to_sector(s, pe->e.new_chunk);
  769. dest.count = src.count;
  770. /* Hand over to kcopyd */
  771. dm_kcopyd_copy(s->kcopyd_client,
  772. &src, 1, &dest, 0, copy_callback, pe);
  773. }
  774. /*
  775. * Looks to see if this snapshot already has a pending exception
  776. * for this chunk, otherwise it allocates a new one and inserts
  777. * it into the pending table.
  778. *
  779. * NOTE: a write lock must be held on snap->lock before calling
  780. * this.
  781. */
  782. static struct dm_snap_pending_exception *
  783. __find_pending_exception(struct dm_snapshot *s, struct bio *bio)
  784. {
  785. struct dm_snap_exception *e;
  786. struct dm_snap_pending_exception *pe;
  787. chunk_t chunk = sector_to_chunk(s, bio->bi_sector);
  788. /*
  789. * Is there a pending exception for this already ?
  790. */
  791. e = lookup_exception(&s->pending, chunk);
  792. if (e) {
  793. /* cast the exception to a pending exception */
  794. pe = container_of(e, struct dm_snap_pending_exception, e);
  795. goto out;
  796. }
  797. /*
  798. * Create a new pending exception, we don't want
  799. * to hold the lock while we do this.
  800. */
  801. up_write(&s->lock);
  802. pe = alloc_pending_exception(s);
  803. down_write(&s->lock);
  804. if (!s->valid) {
  805. free_pending_exception(pe);
  806. return NULL;
  807. }
  808. e = lookup_exception(&s->pending, chunk);
  809. if (e) {
  810. free_pending_exception(pe);
  811. pe = container_of(e, struct dm_snap_pending_exception, e);
  812. goto out;
  813. }
  814. pe->e.old_chunk = chunk;
  815. bio_list_init(&pe->origin_bios);
  816. bio_list_init(&pe->snapshot_bios);
  817. pe->primary_pe = NULL;
  818. atomic_set(&pe->ref_count, 0);
  819. pe->started = 0;
  820. if (s->store.prepare_exception(&s->store, &pe->e)) {
  821. free_pending_exception(pe);
  822. return NULL;
  823. }
  824. get_pending_exception(pe);
  825. insert_exception(&s->pending, &pe->e);
  826. out:
  827. return pe;
  828. }
  829. static void remap_exception(struct dm_snapshot *s, struct dm_snap_exception *e,
  830. struct bio *bio, chunk_t chunk)
  831. {
  832. bio->bi_bdev = s->cow->bdev;
  833. bio->bi_sector = chunk_to_sector(s, dm_chunk_number(e->new_chunk) +
  834. (chunk - e->old_chunk)) +
  835. (bio->bi_sector & s->chunk_mask);
  836. }
  837. static int snapshot_map(struct dm_target *ti, struct bio *bio,
  838. union map_info *map_context)
  839. {
  840. struct dm_snap_exception *e;
  841. struct dm_snapshot *s = ti->private;
  842. int r = DM_MAPIO_REMAPPED;
  843. chunk_t chunk;
  844. struct dm_snap_pending_exception *pe = NULL;
  845. chunk = sector_to_chunk(s, bio->bi_sector);
  846. /* Full snapshots are not usable */
  847. /* To get here the table must be live so s->active is always set. */
  848. if (!s->valid)
  849. return -EIO;
  850. /* FIXME: should only take write lock if we need
  851. * to copy an exception */
  852. down_write(&s->lock);
  853. if (!s->valid) {
  854. r = -EIO;
  855. goto out_unlock;
  856. }
  857. /* If the block is already remapped - use that, else remap it */
  858. e = lookup_exception(&s->complete, chunk);
  859. if (e) {
  860. remap_exception(s, e, bio, chunk);
  861. goto out_unlock;
  862. }
  863. /*
  864. * Write to snapshot - higher level takes care of RW/RO
  865. * flags so we should only get this if we are
  866. * writeable.
  867. */
  868. if (bio_rw(bio) == WRITE) {
  869. pe = __find_pending_exception(s, bio);
  870. if (!pe) {
  871. __invalidate_snapshot(s, -ENOMEM);
  872. r = -EIO;
  873. goto out_unlock;
  874. }
  875. remap_exception(s, &pe->e, bio, chunk);
  876. bio_list_add(&pe->snapshot_bios, bio);
  877. r = DM_MAPIO_SUBMITTED;
  878. if (!pe->started) {
  879. /* this is protected by snap->lock */
  880. pe->started = 1;
  881. up_write(&s->lock);
  882. start_copy(pe);
  883. goto out;
  884. }
  885. } else {
  886. bio->bi_bdev = s->origin->bdev;
  887. map_context->ptr = track_chunk(s, chunk);
  888. }
  889. out_unlock:
  890. up_write(&s->lock);
  891. out:
  892. return r;
  893. }
  894. static int snapshot_end_io(struct dm_target *ti, struct bio *bio,
  895. int error, union map_info *map_context)
  896. {
  897. struct dm_snapshot *s = ti->private;
  898. struct dm_snap_tracked_chunk *c = map_context->ptr;
  899. if (c)
  900. stop_tracking_chunk(s, c);
  901. return 0;
  902. }
  903. static void snapshot_resume(struct dm_target *ti)
  904. {
  905. struct dm_snapshot *s = ti->private;
  906. down_write(&s->lock);
  907. s->active = 1;
  908. up_write(&s->lock);
  909. }
  910. static int snapshot_status(struct dm_target *ti, status_type_t type,
  911. char *result, unsigned int maxlen)
  912. {
  913. struct dm_snapshot *snap = ti->private;
  914. switch (type) {
  915. case STATUSTYPE_INFO:
  916. if (!snap->valid)
  917. snprintf(result, maxlen, "Invalid");
  918. else {
  919. if (snap->store.fraction_full) {
  920. sector_t numerator, denominator;
  921. snap->store.fraction_full(&snap->store,
  922. &numerator,
  923. &denominator);
  924. snprintf(result, maxlen, "%llu/%llu",
  925. (unsigned long long)numerator,
  926. (unsigned long long)denominator);
  927. }
  928. else
  929. snprintf(result, maxlen, "Unknown");
  930. }
  931. break;
  932. case STATUSTYPE_TABLE:
  933. /*
  934. * kdevname returns a static pointer so we need
  935. * to make private copies if the output is to
  936. * make sense.
  937. */
  938. snprintf(result, maxlen, "%s %s %c %llu",
  939. snap->origin->name, snap->cow->name,
  940. snap->type,
  941. (unsigned long long)snap->chunk_size);
  942. break;
  943. }
  944. return 0;
  945. }
  946. /*-----------------------------------------------------------------
  947. * Origin methods
  948. *---------------------------------------------------------------*/
  949. static int __origin_write(struct list_head *snapshots, struct bio *bio)
  950. {
  951. int r = DM_MAPIO_REMAPPED, first = 0;
  952. struct dm_snapshot *snap;
  953. struct dm_snap_exception *e;
  954. struct dm_snap_pending_exception *pe, *next_pe, *primary_pe = NULL;
  955. chunk_t chunk;
  956. LIST_HEAD(pe_queue);
  957. /* Do all the snapshots on this origin */
  958. list_for_each_entry (snap, snapshots, list) {
  959. down_write(&snap->lock);
  960. /* Only deal with valid and active snapshots */
  961. if (!snap->valid || !snap->active)
  962. goto next_snapshot;
  963. /* Nothing to do if writing beyond end of snapshot */
  964. if (bio->bi_sector >= dm_table_get_size(snap->ti->table))
  965. goto next_snapshot;
  966. /*
  967. * Remember, different snapshots can have
  968. * different chunk sizes.
  969. */
  970. chunk = sector_to_chunk(snap, bio->bi_sector);
  971. /*
  972. * Check exception table to see if block
  973. * is already remapped in this snapshot
  974. * and trigger an exception if not.
  975. *
  976. * ref_count is initialised to 1 so pending_complete()
  977. * won't destroy the primary_pe while we're inside this loop.
  978. */
  979. e = lookup_exception(&snap->complete, chunk);
  980. if (e)
  981. goto next_snapshot;
  982. pe = __find_pending_exception(snap, bio);
  983. if (!pe) {
  984. __invalidate_snapshot(snap, -ENOMEM);
  985. goto next_snapshot;
  986. }
  987. if (!primary_pe) {
  988. /*
  989. * Either every pe here has same
  990. * primary_pe or none has one yet.
  991. */
  992. if (pe->primary_pe)
  993. primary_pe = pe->primary_pe;
  994. else {
  995. primary_pe = pe;
  996. first = 1;
  997. }
  998. bio_list_add(&primary_pe->origin_bios, bio);
  999. r = DM_MAPIO_SUBMITTED;
  1000. }
  1001. if (!pe->primary_pe) {
  1002. pe->primary_pe = primary_pe;
  1003. get_pending_exception(primary_pe);
  1004. }
  1005. if (!pe->started) {
  1006. pe->started = 1;
  1007. list_add_tail(&pe->list, &pe_queue);
  1008. }
  1009. next_snapshot:
  1010. up_write(&snap->lock);
  1011. }
  1012. if (!primary_pe)
  1013. return r;
  1014. /*
  1015. * If this is the first time we're processing this chunk and
  1016. * ref_count is now 1 it means all the pending exceptions
  1017. * got completed while we were in the loop above, so it falls to
  1018. * us here to remove the primary_pe and submit any origin_bios.
  1019. */
  1020. if (first && atomic_dec_and_test(&primary_pe->ref_count)) {
  1021. flush_bios(bio_list_get(&primary_pe->origin_bios));
  1022. free_pending_exception(primary_pe);
  1023. /* If we got here, pe_queue is necessarily empty. */
  1024. return r;
  1025. }
  1026. /*
  1027. * Now that we have a complete pe list we can start the copying.
  1028. */
  1029. list_for_each_entry_safe(pe, next_pe, &pe_queue, list)
  1030. start_copy(pe);
  1031. return r;
  1032. }
  1033. /*
  1034. * Called on a write from the origin driver.
  1035. */
  1036. static int do_origin(struct dm_dev *origin, struct bio *bio)
  1037. {
  1038. struct origin *o;
  1039. int r = DM_MAPIO_REMAPPED;
  1040. down_read(&_origins_lock);
  1041. o = __lookup_origin(origin->bdev);
  1042. if (o)
  1043. r = __origin_write(&o->snapshots, bio);
  1044. up_read(&_origins_lock);
  1045. return r;
  1046. }
  1047. /*
  1048. * Origin: maps a linear range of a device, with hooks for snapshotting.
  1049. */
  1050. /*
  1051. * Construct an origin mapping: <dev_path>
  1052. * The context for an origin is merely a 'struct dm_dev *'
  1053. * pointing to the real device.
  1054. */
  1055. static int origin_ctr(struct dm_target *ti, unsigned int argc, char **argv)
  1056. {
  1057. int r;
  1058. struct dm_dev *dev;
  1059. if (argc != 1) {
  1060. ti->error = "origin: incorrect number of arguments";
  1061. return -EINVAL;
  1062. }
  1063. r = dm_get_device(ti, argv[0], 0, ti->len,
  1064. dm_table_get_mode(ti->table), &dev);
  1065. if (r) {
  1066. ti->error = "Cannot get target device";
  1067. return r;
  1068. }
  1069. ti->private = dev;
  1070. return 0;
  1071. }
  1072. static void origin_dtr(struct dm_target *ti)
  1073. {
  1074. struct dm_dev *dev = ti->private;
  1075. dm_put_device(ti, dev);
  1076. }
  1077. static int origin_map(struct dm_target *ti, struct bio *bio,
  1078. union map_info *map_context)
  1079. {
  1080. struct dm_dev *dev = ti->private;
  1081. bio->bi_bdev = dev->bdev;
  1082. /* Only tell snapshots if this is a write */
  1083. return (bio_rw(bio) == WRITE) ? do_origin(dev, bio) : DM_MAPIO_REMAPPED;
  1084. }
  1085. #define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r))
  1086. /*
  1087. * Set the target "split_io" field to the minimum of all the snapshots'
  1088. * chunk sizes.
  1089. */
  1090. static void origin_resume(struct dm_target *ti)
  1091. {
  1092. struct dm_dev *dev = ti->private;
  1093. struct dm_snapshot *snap;
  1094. struct origin *o;
  1095. chunk_t chunk_size = 0;
  1096. down_read(&_origins_lock);
  1097. o = __lookup_origin(dev->bdev);
  1098. if (o)
  1099. list_for_each_entry (snap, &o->snapshots, list)
  1100. chunk_size = min_not_zero(chunk_size, snap->chunk_size);
  1101. up_read(&_origins_lock);
  1102. ti->split_io = chunk_size;
  1103. }
  1104. static int origin_status(struct dm_target *ti, status_type_t type, char *result,
  1105. unsigned int maxlen)
  1106. {
  1107. struct dm_dev *dev = ti->private;
  1108. switch (type) {
  1109. case STATUSTYPE_INFO:
  1110. result[0] = '\0';
  1111. break;
  1112. case STATUSTYPE_TABLE:
  1113. snprintf(result, maxlen, "%s", dev->name);
  1114. break;
  1115. }
  1116. return 0;
  1117. }
  1118. static struct target_type origin_target = {
  1119. .name = "snapshot-origin",
  1120. .version = {1, 6, 0},
  1121. .module = THIS_MODULE,
  1122. .ctr = origin_ctr,
  1123. .dtr = origin_dtr,
  1124. .map = origin_map,
  1125. .resume = origin_resume,
  1126. .status = origin_status,
  1127. };
  1128. static struct target_type snapshot_target = {
  1129. .name = "snapshot",
  1130. .version = {1, 6, 0},
  1131. .module = THIS_MODULE,
  1132. .ctr = snapshot_ctr,
  1133. .dtr = snapshot_dtr,
  1134. .map = snapshot_map,
  1135. .end_io = snapshot_end_io,
  1136. .resume = snapshot_resume,
  1137. .status = snapshot_status,
  1138. };
  1139. static int __init dm_snapshot_init(void)
  1140. {
  1141. int r;
  1142. r = dm_register_target(&snapshot_target);
  1143. if (r) {
  1144. DMERR("snapshot target register failed %d", r);
  1145. return r;
  1146. }
  1147. r = dm_register_target(&origin_target);
  1148. if (r < 0) {
  1149. DMERR("Origin target register failed %d", r);
  1150. goto bad1;
  1151. }
  1152. r = init_origin_hash();
  1153. if (r) {
  1154. DMERR("init_origin_hash failed.");
  1155. goto bad2;
  1156. }
  1157. exception_cache = KMEM_CACHE(dm_snap_exception, 0);
  1158. if (!exception_cache) {
  1159. DMERR("Couldn't create exception cache.");
  1160. r = -ENOMEM;
  1161. goto bad3;
  1162. }
  1163. pending_cache = KMEM_CACHE(dm_snap_pending_exception, 0);
  1164. if (!pending_cache) {
  1165. DMERR("Couldn't create pending cache.");
  1166. r = -ENOMEM;
  1167. goto bad4;
  1168. }
  1169. tracked_chunk_cache = KMEM_CACHE(dm_snap_tracked_chunk, 0);
  1170. if (!tracked_chunk_cache) {
  1171. DMERR("Couldn't create cache to track chunks in use.");
  1172. r = -ENOMEM;
  1173. goto bad5;
  1174. }
  1175. ksnapd = create_singlethread_workqueue("ksnapd");
  1176. if (!ksnapd) {
  1177. DMERR("Failed to create ksnapd workqueue.");
  1178. r = -ENOMEM;
  1179. goto bad_pending_pool;
  1180. }
  1181. return 0;
  1182. bad_pending_pool:
  1183. kmem_cache_destroy(tracked_chunk_cache);
  1184. bad5:
  1185. kmem_cache_destroy(pending_cache);
  1186. bad4:
  1187. kmem_cache_destroy(exception_cache);
  1188. bad3:
  1189. exit_origin_hash();
  1190. bad2:
  1191. dm_unregister_target(&origin_target);
  1192. bad1:
  1193. dm_unregister_target(&snapshot_target);
  1194. return r;
  1195. }
  1196. static void __exit dm_snapshot_exit(void)
  1197. {
  1198. int r;
  1199. destroy_workqueue(ksnapd);
  1200. r = dm_unregister_target(&snapshot_target);
  1201. if (r)
  1202. DMERR("snapshot unregister failed %d", r);
  1203. r = dm_unregister_target(&origin_target);
  1204. if (r)
  1205. DMERR("origin unregister failed %d", r);
  1206. exit_origin_hash();
  1207. kmem_cache_destroy(pending_cache);
  1208. kmem_cache_destroy(exception_cache);
  1209. kmem_cache_destroy(tracked_chunk_cache);
  1210. }
  1211. /* Module hooks */
  1212. module_init(dm_snapshot_init);
  1213. module_exit(dm_snapshot_exit);
  1214. MODULE_DESCRIPTION(DM_NAME " snapshot target");
  1215. MODULE_AUTHOR("Joe Thornber");
  1216. MODULE_LICENSE("GPL");