dm-snap.c 32 KB

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