dm snapshot: move cow ref from exception store to snap core
[firefly-linux-kernel-4.4.55.git] / drivers / md / dm-snap.c
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
9 #include <linux/blkdev.h>
10 #include <linux/device-mapper.h>
11 #include <linux/delay.h>
12 #include <linux/fs.h>
13 #include <linux/init.h>
14 #include <linux/kdev_t.h>
15 #include <linux/list.h>
16 #include <linux/mempool.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/vmalloc.h>
20 #include <linux/log2.h>
21 #include <linux/dm-kcopyd.h>
22 #include <linux/workqueue.h>
23
24 #include "dm-exception-store.h"
25
26 #define DM_MSG_PREFIX "snapshots"
27
28 /*
29  * The percentage increment we will wake up users at
30  */
31 #define WAKE_UP_PERCENT 5
32
33 /*
34  * kcopyd priority of snapshot operations
35  */
36 #define SNAPSHOT_COPY_PRIORITY 2
37
38 /*
39  * Reserve 1MB for each snapshot initially (with minimum of 1 page).
40  */
41 #define SNAPSHOT_PAGES (((1UL << 20) >> PAGE_SHIFT) ? : 1)
42
43 /*
44  * The size of the mempool used to track chunks in use.
45  */
46 #define MIN_IOS 256
47
48 #define DM_TRACKED_CHUNK_HASH_SIZE      16
49 #define DM_TRACKED_CHUNK_HASH(x)        ((unsigned long)(x) & \
50                                          (DM_TRACKED_CHUNK_HASH_SIZE - 1))
51
52 struct dm_exception_table {
53         uint32_t hash_mask;
54         unsigned hash_shift;
55         struct list_head *table;
56 };
57
58 struct dm_snapshot {
59         struct rw_semaphore lock;
60
61         struct dm_dev *origin;
62         struct dm_dev *cow;
63
64         struct dm_target *ti;
65
66         /* List of snapshots per Origin */
67         struct list_head list;
68
69         /* You can't use a snapshot if this is 0 (e.g. if full) */
70         int valid;
71
72         /* Origin writes don't trigger exceptions until this is set */
73         int active;
74
75         mempool_t *pending_pool;
76
77         atomic_t pending_exceptions_count;
78
79         struct dm_exception_table pending;
80         struct dm_exception_table complete;
81
82         /*
83          * pe_lock protects all pending_exception operations and access
84          * as well as the snapshot_bios list.
85          */
86         spinlock_t pe_lock;
87
88         /* The on disk metadata handler */
89         struct dm_exception_store *store;
90
91         struct dm_kcopyd_client *kcopyd_client;
92
93         /* Queue of snapshot writes for ksnapd to flush */
94         struct bio_list queued_bios;
95         struct work_struct queued_bios_work;
96
97         /* Chunks with outstanding reads */
98         mempool_t *tracked_chunk_pool;
99         spinlock_t tracked_chunk_lock;
100         struct hlist_head tracked_chunk_hash[DM_TRACKED_CHUNK_HASH_SIZE];
101 };
102
103 struct dm_dev *dm_snap_cow(struct dm_snapshot *s)
104 {
105         return s->cow;
106 }
107 EXPORT_SYMBOL(dm_snap_cow);
108
109 static struct workqueue_struct *ksnapd;
110 static void flush_queued_bios(struct work_struct *work);
111
112 static sector_t chunk_to_sector(struct dm_exception_store *store,
113                                 chunk_t chunk)
114 {
115         return chunk << store->chunk_shift;
116 }
117
118 static int bdev_equal(struct block_device *lhs, struct block_device *rhs)
119 {
120         /*
121          * There is only ever one instance of a particular block
122          * device so we can compare pointers safely.
123          */
124         return lhs == rhs;
125 }
126
127 struct dm_snap_pending_exception {
128         struct dm_exception e;
129
130         /*
131          * Origin buffers waiting for this to complete are held
132          * in a bio list
133          */
134         struct bio_list origin_bios;
135         struct bio_list snapshot_bios;
136
137         /*
138          * Short-term queue of pending exceptions prior to submission.
139          */
140         struct list_head list;
141
142         /*
143          * The primary pending_exception is the one that holds
144          * the ref_count and the list of origin_bios for a
145          * group of pending_exceptions.  It is always last to get freed.
146          * These fields get set up when writing to the origin.
147          */
148         struct dm_snap_pending_exception *primary_pe;
149
150         /*
151          * Number of pending_exceptions processing this chunk.
152          * When this drops to zero we must complete the origin bios.
153          * If incrementing or decrementing this, hold pe->snap->lock for
154          * the sibling concerned and not pe->primary_pe->snap->lock unless
155          * they are the same.
156          */
157         atomic_t ref_count;
158
159         /* Pointer back to snapshot context */
160         struct dm_snapshot *snap;
161
162         /*
163          * 1 indicates the exception has already been sent to
164          * kcopyd.
165          */
166         int started;
167 };
168
169 /*
170  * Hash table mapping origin volumes to lists of snapshots and
171  * a lock to protect it
172  */
173 static struct kmem_cache *exception_cache;
174 static struct kmem_cache *pending_cache;
175
176 struct dm_snap_tracked_chunk {
177         struct hlist_node node;
178         chunk_t chunk;
179 };
180
181 static struct kmem_cache *tracked_chunk_cache;
182
183 static struct dm_snap_tracked_chunk *track_chunk(struct dm_snapshot *s,
184                                                  chunk_t chunk)
185 {
186         struct dm_snap_tracked_chunk *c = mempool_alloc(s->tracked_chunk_pool,
187                                                         GFP_NOIO);
188         unsigned long flags;
189
190         c->chunk = chunk;
191
192         spin_lock_irqsave(&s->tracked_chunk_lock, flags);
193         hlist_add_head(&c->node,
194                        &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)]);
195         spin_unlock_irqrestore(&s->tracked_chunk_lock, flags);
196
197         return c;
198 }
199
200 static void stop_tracking_chunk(struct dm_snapshot *s,
201                                 struct dm_snap_tracked_chunk *c)
202 {
203         unsigned long flags;
204
205         spin_lock_irqsave(&s->tracked_chunk_lock, flags);
206         hlist_del(&c->node);
207         spin_unlock_irqrestore(&s->tracked_chunk_lock, flags);
208
209         mempool_free(c, s->tracked_chunk_pool);
210 }
211
212 static int __chunk_is_tracked(struct dm_snapshot *s, chunk_t chunk)
213 {
214         struct dm_snap_tracked_chunk *c;
215         struct hlist_node *hn;
216         int found = 0;
217
218         spin_lock_irq(&s->tracked_chunk_lock);
219
220         hlist_for_each_entry(c, hn,
221             &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)], node) {
222                 if (c->chunk == chunk) {
223                         found = 1;
224                         break;
225                 }
226         }
227
228         spin_unlock_irq(&s->tracked_chunk_lock);
229
230         return found;
231 }
232
233 /*
234  * One of these per registered origin, held in the snapshot_origins hash
235  */
236 struct origin {
237         /* The origin device */
238         struct block_device *bdev;
239
240         struct list_head hash_list;
241
242         /* List of snapshots for this origin */
243         struct list_head snapshots;
244 };
245
246 /*
247  * Size of the hash table for origin volumes. If we make this
248  * the size of the minors list then it should be nearly perfect
249  */
250 #define ORIGIN_HASH_SIZE 256
251 #define ORIGIN_MASK      0xFF
252 static struct list_head *_origins;
253 static struct rw_semaphore _origins_lock;
254
255 static int init_origin_hash(void)
256 {
257         int i;
258
259         _origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
260                            GFP_KERNEL);
261         if (!_origins) {
262                 DMERR("unable to allocate memory");
263                 return -ENOMEM;
264         }
265
266         for (i = 0; i < ORIGIN_HASH_SIZE; i++)
267                 INIT_LIST_HEAD(_origins + i);
268         init_rwsem(&_origins_lock);
269
270         return 0;
271 }
272
273 static void exit_origin_hash(void)
274 {
275         kfree(_origins);
276 }
277
278 static unsigned origin_hash(struct block_device *bdev)
279 {
280         return bdev->bd_dev & ORIGIN_MASK;
281 }
282
283 static struct origin *__lookup_origin(struct block_device *origin)
284 {
285         struct list_head *ol;
286         struct origin *o;
287
288         ol = &_origins[origin_hash(origin)];
289         list_for_each_entry (o, ol, hash_list)
290                 if (bdev_equal(o->bdev, origin))
291                         return o;
292
293         return NULL;
294 }
295
296 static void __insert_origin(struct origin *o)
297 {
298         struct list_head *sl = &_origins[origin_hash(o->bdev)];
299         list_add_tail(&o->hash_list, sl);
300 }
301
302 /*
303  * Make a note of the snapshot and its origin so we can look it
304  * up when the origin has a write on it.
305  */
306 static int register_snapshot(struct dm_snapshot *snap)
307 {
308         struct dm_snapshot *l;
309         struct origin *o, *new_o;
310         struct block_device *bdev = snap->origin->bdev;
311
312         new_o = kmalloc(sizeof(*new_o), GFP_KERNEL);
313         if (!new_o)
314                 return -ENOMEM;
315
316         down_write(&_origins_lock);
317         o = __lookup_origin(bdev);
318
319         if (o)
320                 kfree(new_o);
321         else {
322                 /* New origin */
323                 o = new_o;
324
325                 /* Initialise the struct */
326                 INIT_LIST_HEAD(&o->snapshots);
327                 o->bdev = bdev;
328
329                 __insert_origin(o);
330         }
331
332         /* Sort the list according to chunk size, largest-first smallest-last */
333         list_for_each_entry(l, &o->snapshots, list)
334                 if (l->store->chunk_size < snap->store->chunk_size)
335                         break;
336         list_add_tail(&snap->list, &l->list);
337
338         up_write(&_origins_lock);
339         return 0;
340 }
341
342 static void unregister_snapshot(struct dm_snapshot *s)
343 {
344         struct origin *o;
345
346         down_write(&_origins_lock);
347         o = __lookup_origin(s->origin->bdev);
348
349         list_del(&s->list);
350         if (list_empty(&o->snapshots)) {
351                 list_del(&o->hash_list);
352                 kfree(o);
353         }
354
355         up_write(&_origins_lock);
356 }
357
358 /*
359  * Implementation of the exception hash tables.
360  * The lowest hash_shift bits of the chunk number are ignored, allowing
361  * some consecutive chunks to be grouped together.
362  */
363 static int dm_exception_table_init(struct dm_exception_table *et,
364                                    uint32_t size, unsigned hash_shift)
365 {
366         unsigned int i;
367
368         et->hash_shift = hash_shift;
369         et->hash_mask = size - 1;
370         et->table = dm_vcalloc(size, sizeof(struct list_head));
371         if (!et->table)
372                 return -ENOMEM;
373
374         for (i = 0; i < size; i++)
375                 INIT_LIST_HEAD(et->table + i);
376
377         return 0;
378 }
379
380 static void dm_exception_table_exit(struct dm_exception_table *et,
381                                     struct kmem_cache *mem)
382 {
383         struct list_head *slot;
384         struct dm_exception *ex, *next;
385         int i, size;
386
387         size = et->hash_mask + 1;
388         for (i = 0; i < size; i++) {
389                 slot = et->table + i;
390
391                 list_for_each_entry_safe (ex, next, slot, hash_list)
392                         kmem_cache_free(mem, ex);
393         }
394
395         vfree(et->table);
396 }
397
398 static uint32_t exception_hash(struct dm_exception_table *et, chunk_t chunk)
399 {
400         return (chunk >> et->hash_shift) & et->hash_mask;
401 }
402
403 static void dm_remove_exception(struct dm_exception *e)
404 {
405         list_del(&e->hash_list);
406 }
407
408 /*
409  * Return the exception data for a sector, or NULL if not
410  * remapped.
411  */
412 static struct dm_exception *dm_lookup_exception(struct dm_exception_table *et,
413                                                 chunk_t chunk)
414 {
415         struct list_head *slot;
416         struct dm_exception *e;
417
418         slot = &et->table[exception_hash(et, chunk)];
419         list_for_each_entry (e, slot, hash_list)
420                 if (chunk >= e->old_chunk &&
421                     chunk <= e->old_chunk + dm_consecutive_chunk_count(e))
422                         return e;
423
424         return NULL;
425 }
426
427 static struct dm_exception *alloc_completed_exception(void)
428 {
429         struct dm_exception *e;
430
431         e = kmem_cache_alloc(exception_cache, GFP_NOIO);
432         if (!e)
433                 e = kmem_cache_alloc(exception_cache, GFP_ATOMIC);
434
435         return e;
436 }
437
438 static void free_completed_exception(struct dm_exception *e)
439 {
440         kmem_cache_free(exception_cache, e);
441 }
442
443 static struct dm_snap_pending_exception *alloc_pending_exception(struct dm_snapshot *s)
444 {
445         struct dm_snap_pending_exception *pe = mempool_alloc(s->pending_pool,
446                                                              GFP_NOIO);
447
448         atomic_inc(&s->pending_exceptions_count);
449         pe->snap = s;
450
451         return pe;
452 }
453
454 static void free_pending_exception(struct dm_snap_pending_exception *pe)
455 {
456         struct dm_snapshot *s = pe->snap;
457
458         mempool_free(pe, s->pending_pool);
459         smp_mb__before_atomic_dec();
460         atomic_dec(&s->pending_exceptions_count);
461 }
462
463 static void dm_insert_exception(struct dm_exception_table *eh,
464                                 struct dm_exception *new_e)
465 {
466         struct list_head *l;
467         struct dm_exception *e = NULL;
468
469         l = &eh->table[exception_hash(eh, new_e->old_chunk)];
470
471         /* Add immediately if this table doesn't support consecutive chunks */
472         if (!eh->hash_shift)
473                 goto out;
474
475         /* List is ordered by old_chunk */
476         list_for_each_entry_reverse(e, l, hash_list) {
477                 /* Insert after an existing chunk? */
478                 if (new_e->old_chunk == (e->old_chunk +
479                                          dm_consecutive_chunk_count(e) + 1) &&
480                     new_e->new_chunk == (dm_chunk_number(e->new_chunk) +
481                                          dm_consecutive_chunk_count(e) + 1)) {
482                         dm_consecutive_chunk_count_inc(e);
483                         free_completed_exception(new_e);
484                         return;
485                 }
486
487                 /* Insert before an existing chunk? */
488                 if (new_e->old_chunk == (e->old_chunk - 1) &&
489                     new_e->new_chunk == (dm_chunk_number(e->new_chunk) - 1)) {
490                         dm_consecutive_chunk_count_inc(e);
491                         e->old_chunk--;
492                         e->new_chunk--;
493                         free_completed_exception(new_e);
494                         return;
495                 }
496
497                 if (new_e->old_chunk > e->old_chunk)
498                         break;
499         }
500
501 out:
502         list_add(&new_e->hash_list, e ? &e->hash_list : l);
503 }
504
505 /*
506  * Callback used by the exception stores to load exceptions when
507  * initialising.
508  */
509 static int dm_add_exception(void *context, chunk_t old, chunk_t new)
510 {
511         struct dm_snapshot *s = context;
512         struct dm_exception *e;
513
514         e = alloc_completed_exception();
515         if (!e)
516                 return -ENOMEM;
517
518         e->old_chunk = old;
519
520         /* Consecutive_count is implicitly initialised to zero */
521         e->new_chunk = new;
522
523         dm_insert_exception(&s->complete, e);
524
525         return 0;
526 }
527
528 #define min_not_zero(l, r) (((l) == 0) ? (r) : (((r) == 0) ? (l) : min(l, r)))
529
530 /*
531  * Return a minimum chunk size of all snapshots that have the specified origin.
532  * Return zero if the origin has no snapshots.
533  */
534 static sector_t __minimum_chunk_size(struct origin *o)
535 {
536         struct dm_snapshot *snap;
537         unsigned chunk_size = 0;
538
539         if (o)
540                 list_for_each_entry(snap, &o->snapshots, list)
541                         chunk_size = min_not_zero(chunk_size,
542                                                   snap->store->chunk_size);
543
544         return chunk_size;
545 }
546
547 /*
548  * Hard coded magic.
549  */
550 static int calc_max_buckets(void)
551 {
552         /* use a fixed size of 2MB */
553         unsigned long mem = 2 * 1024 * 1024;
554         mem /= sizeof(struct list_head);
555
556         return mem;
557 }
558
559 /*
560  * Allocate room for a suitable hash table.
561  */
562 static int init_hash_tables(struct dm_snapshot *s)
563 {
564         sector_t hash_size, cow_dev_size, origin_dev_size, max_buckets;
565
566         /*
567          * Calculate based on the size of the original volume or
568          * the COW volume...
569          */
570         cow_dev_size = get_dev_size(s->cow->bdev);
571         origin_dev_size = get_dev_size(s->origin->bdev);
572         max_buckets = calc_max_buckets();
573
574         hash_size = min(origin_dev_size, cow_dev_size) >> s->store->chunk_shift;
575         hash_size = min(hash_size, max_buckets);
576
577         if (hash_size < 64)
578                 hash_size = 64;
579         hash_size = rounddown_pow_of_two(hash_size);
580         if (dm_exception_table_init(&s->complete, hash_size,
581                                     DM_CHUNK_CONSECUTIVE_BITS))
582                 return -ENOMEM;
583
584         /*
585          * Allocate hash table for in-flight exceptions
586          * Make this smaller than the real hash table
587          */
588         hash_size >>= 3;
589         if (hash_size < 64)
590                 hash_size = 64;
591
592         if (dm_exception_table_init(&s->pending, hash_size, 0)) {
593                 dm_exception_table_exit(&s->complete, exception_cache);
594                 return -ENOMEM;
595         }
596
597         return 0;
598 }
599
600 /*
601  * Construct a snapshot mapping: <origin_dev> <COW-dev> <p/n> <chunk-size>
602  */
603 static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
604 {
605         struct dm_snapshot *s;
606         int i;
607         int r = -EINVAL;
608         char *origin_path, *cow_path;
609         unsigned args_used;
610
611         if (argc != 4) {
612                 ti->error = "requires exactly 4 arguments";
613                 r = -EINVAL;
614                 goto bad;
615         }
616
617         origin_path = argv[0];
618         argv++;
619         argc--;
620
621         s = kmalloc(sizeof(*s), GFP_KERNEL);
622         if (!s) {
623                 ti->error = "Cannot allocate snapshot context private "
624                     "structure";
625                 r = -ENOMEM;
626                 goto bad;
627         }
628
629         cow_path = argv[0];
630         argv++;
631         argc--;
632
633         r = dm_get_device(ti, cow_path, 0, 0,
634                           FMODE_READ | FMODE_WRITE, &s->cow);
635         if (r) {
636                 ti->error = "Cannot get COW device";
637                 goto bad_cow;
638         }
639
640         r = dm_exception_store_create(ti, argc, argv, s, &args_used, &s->store);
641         if (r) {
642                 ti->error = "Couldn't create exception store";
643                 r = -EINVAL;
644                 goto bad_store;
645         }
646
647         argv += args_used;
648         argc -= args_used;
649
650         r = dm_get_device(ti, origin_path, 0, ti->len, FMODE_READ, &s->origin);
651         if (r) {
652                 ti->error = "Cannot get origin device";
653                 goto bad_origin;
654         }
655
656         s->ti = ti;
657         s->valid = 1;
658         s->active = 0;
659         atomic_set(&s->pending_exceptions_count, 0);
660         init_rwsem(&s->lock);
661         spin_lock_init(&s->pe_lock);
662
663         /* Allocate hash table for COW data */
664         if (init_hash_tables(s)) {
665                 ti->error = "Unable to allocate hash table space";
666                 r = -ENOMEM;
667                 goto bad_hash_tables;
668         }
669
670         r = dm_kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client);
671         if (r) {
672                 ti->error = "Could not create kcopyd client";
673                 goto bad_kcopyd;
674         }
675
676         s->pending_pool = mempool_create_slab_pool(MIN_IOS, pending_cache);
677         if (!s->pending_pool) {
678                 ti->error = "Could not allocate mempool for pending exceptions";
679                 goto bad_pending_pool;
680         }
681
682         s->tracked_chunk_pool = mempool_create_slab_pool(MIN_IOS,
683                                                          tracked_chunk_cache);
684         if (!s->tracked_chunk_pool) {
685                 ti->error = "Could not allocate tracked_chunk mempool for "
686                             "tracking reads";
687                 goto bad_tracked_chunk_pool;
688         }
689
690         for (i = 0; i < DM_TRACKED_CHUNK_HASH_SIZE; i++)
691                 INIT_HLIST_HEAD(&s->tracked_chunk_hash[i]);
692
693         spin_lock_init(&s->tracked_chunk_lock);
694
695         /* Metadata must only be loaded into one table at once */
696         r = s->store->type->read_metadata(s->store, dm_add_exception,
697                                           (void *)s);
698         if (r < 0) {
699                 ti->error = "Failed to read snapshot metadata";
700                 goto bad_load_and_register;
701         } else if (r > 0) {
702                 s->valid = 0;
703                 DMWARN("Snapshot is marked invalid.");
704         }
705
706         bio_list_init(&s->queued_bios);
707         INIT_WORK(&s->queued_bios_work, flush_queued_bios);
708
709         if (!s->store->chunk_size) {
710                 ti->error = "Chunk size not set";
711                 goto bad_load_and_register;
712         }
713
714         /* Add snapshot to the list of snapshots for this origin */
715         /* Exceptions aren't triggered till snapshot_resume() is called */
716         if (register_snapshot(s)) {
717                 r = -EINVAL;
718                 ti->error = "Cannot register snapshot origin";
719                 goto bad_load_and_register;
720         }
721
722         ti->private = s;
723         ti->split_io = s->store->chunk_size;
724         ti->num_flush_requests = 1;
725
726         return 0;
727
728 bad_load_and_register:
729         mempool_destroy(s->tracked_chunk_pool);
730
731 bad_tracked_chunk_pool:
732         mempool_destroy(s->pending_pool);
733
734 bad_pending_pool:
735         dm_kcopyd_client_destroy(s->kcopyd_client);
736
737 bad_kcopyd:
738         dm_exception_table_exit(&s->pending, pending_cache);
739         dm_exception_table_exit(&s->complete, exception_cache);
740
741 bad_hash_tables:
742         dm_put_device(ti, s->origin);
743
744 bad_origin:
745         dm_exception_store_destroy(s->store);
746
747 bad_store:
748         dm_put_device(ti, s->cow);
749
750 bad_cow:
751         kfree(s);
752
753 bad:
754         return r;
755 }
756
757 static void __free_exceptions(struct dm_snapshot *s)
758 {
759         dm_kcopyd_client_destroy(s->kcopyd_client);
760         s->kcopyd_client = NULL;
761
762         dm_exception_table_exit(&s->pending, pending_cache);
763         dm_exception_table_exit(&s->complete, exception_cache);
764 }
765
766 static void snapshot_dtr(struct dm_target *ti)
767 {
768 #ifdef CONFIG_DM_DEBUG
769         int i;
770 #endif
771         struct dm_snapshot *s = ti->private;
772
773         flush_workqueue(ksnapd);
774
775         /* Prevent further origin writes from using this snapshot. */
776         /* After this returns there can be no new kcopyd jobs. */
777         unregister_snapshot(s);
778
779         while (atomic_read(&s->pending_exceptions_count))
780                 msleep(1);
781         /*
782          * Ensure instructions in mempool_destroy aren't reordered
783          * before atomic_read.
784          */
785         smp_mb();
786
787 #ifdef CONFIG_DM_DEBUG
788         for (i = 0; i < DM_TRACKED_CHUNK_HASH_SIZE; i++)
789                 BUG_ON(!hlist_empty(&s->tracked_chunk_hash[i]));
790 #endif
791
792         mempool_destroy(s->tracked_chunk_pool);
793
794         __free_exceptions(s);
795
796         mempool_destroy(s->pending_pool);
797
798         dm_put_device(ti, s->origin);
799
800         dm_exception_store_destroy(s->store);
801
802         dm_put_device(ti, s->cow);
803
804         kfree(s);
805 }
806
807 /*
808  * Flush a list of buffers.
809  */
810 static void flush_bios(struct bio *bio)
811 {
812         struct bio *n;
813
814         while (bio) {
815                 n = bio->bi_next;
816                 bio->bi_next = NULL;
817                 generic_make_request(bio);
818                 bio = n;
819         }
820 }
821
822 static void flush_queued_bios(struct work_struct *work)
823 {
824         struct dm_snapshot *s =
825                 container_of(work, struct dm_snapshot, queued_bios_work);
826         struct bio *queued_bios;
827         unsigned long flags;
828
829         spin_lock_irqsave(&s->pe_lock, flags);
830         queued_bios = bio_list_get(&s->queued_bios);
831         spin_unlock_irqrestore(&s->pe_lock, flags);
832
833         flush_bios(queued_bios);
834 }
835
836 /*
837  * Error a list of buffers.
838  */
839 static void error_bios(struct bio *bio)
840 {
841         struct bio *n;
842
843         while (bio) {
844                 n = bio->bi_next;
845                 bio->bi_next = NULL;
846                 bio_io_error(bio);
847                 bio = n;
848         }
849 }
850
851 static void __invalidate_snapshot(struct dm_snapshot *s, int err)
852 {
853         if (!s->valid)
854                 return;
855
856         if (err == -EIO)
857                 DMERR("Invalidating snapshot: Error reading/writing.");
858         else if (err == -ENOMEM)
859                 DMERR("Invalidating snapshot: Unable to allocate exception.");
860
861         if (s->store->type->drop_snapshot)
862                 s->store->type->drop_snapshot(s->store);
863
864         s->valid = 0;
865
866         dm_table_event(s->ti->table);
867 }
868
869 static void get_pending_exception(struct dm_snap_pending_exception *pe)
870 {
871         atomic_inc(&pe->ref_count);
872 }
873
874 static struct bio *put_pending_exception(struct dm_snap_pending_exception *pe)
875 {
876         struct dm_snap_pending_exception *primary_pe;
877         struct bio *origin_bios = NULL;
878
879         primary_pe = pe->primary_pe;
880
881         /*
882          * If this pe is involved in a write to the origin and
883          * it is the last sibling to complete then release
884          * the bios for the original write to the origin.
885          */
886         if (primary_pe &&
887             atomic_dec_and_test(&primary_pe->ref_count)) {
888                 origin_bios = bio_list_get(&primary_pe->origin_bios);
889                 free_pending_exception(primary_pe);
890         }
891
892         /*
893          * Free the pe if it's not linked to an origin write or if
894          * it's not itself a primary pe.
895          */
896         if (!primary_pe || primary_pe != pe)
897                 free_pending_exception(pe);
898
899         return origin_bios;
900 }
901
902 static void pending_complete(struct dm_snap_pending_exception *pe, int success)
903 {
904         struct dm_exception *e;
905         struct dm_snapshot *s = pe->snap;
906         struct bio *origin_bios = NULL;
907         struct bio *snapshot_bios = NULL;
908         int error = 0;
909
910         if (!success) {
911                 /* Read/write error - snapshot is unusable */
912                 down_write(&s->lock);
913                 __invalidate_snapshot(s, -EIO);
914                 error = 1;
915                 goto out;
916         }
917
918         e = alloc_completed_exception();
919         if (!e) {
920                 down_write(&s->lock);
921                 __invalidate_snapshot(s, -ENOMEM);
922                 error = 1;
923                 goto out;
924         }
925         *e = pe->e;
926
927         down_write(&s->lock);
928         if (!s->valid) {
929                 free_completed_exception(e);
930                 error = 1;
931                 goto out;
932         }
933
934         /*
935          * Check for conflicting reads. This is extremely improbable,
936          * so msleep(1) is sufficient and there is no need for a wait queue.
937          */
938         while (__chunk_is_tracked(s, pe->e.old_chunk))
939                 msleep(1);
940
941         /*
942          * Add a proper exception, and remove the
943          * in-flight exception from the list.
944          */
945         dm_insert_exception(&s->complete, e);
946
947  out:
948         dm_remove_exception(&pe->e);
949         snapshot_bios = bio_list_get(&pe->snapshot_bios);
950         origin_bios = put_pending_exception(pe);
951
952         up_write(&s->lock);
953
954         /* Submit any pending write bios */
955         if (error)
956                 error_bios(snapshot_bios);
957         else
958                 flush_bios(snapshot_bios);
959
960         flush_bios(origin_bios);
961 }
962
963 static void commit_callback(void *context, int success)
964 {
965         struct dm_snap_pending_exception *pe = context;
966
967         pending_complete(pe, success);
968 }
969
970 /*
971  * Called when the copy I/O has finished.  kcopyd actually runs
972  * this code so don't block.
973  */
974 static void copy_callback(int read_err, unsigned long write_err, void *context)
975 {
976         struct dm_snap_pending_exception *pe = context;
977         struct dm_snapshot *s = pe->snap;
978
979         if (read_err || write_err)
980                 pending_complete(pe, 0);
981
982         else
983                 /* Update the metadata if we are persistent */
984                 s->store->type->commit_exception(s->store, &pe->e,
985                                                  commit_callback, pe);
986 }
987
988 /*
989  * Dispatches the copy operation to kcopyd.
990  */
991 static void start_copy(struct dm_snap_pending_exception *pe)
992 {
993         struct dm_snapshot *s = pe->snap;
994         struct dm_io_region src, dest;
995         struct block_device *bdev = s->origin->bdev;
996         sector_t dev_size;
997
998         dev_size = get_dev_size(bdev);
999
1000         src.bdev = bdev;
1001         src.sector = chunk_to_sector(s->store, pe->e.old_chunk);
1002         src.count = min((sector_t)s->store->chunk_size, dev_size - src.sector);
1003
1004         dest.bdev = s->cow->bdev;
1005         dest.sector = chunk_to_sector(s->store, pe->e.new_chunk);
1006         dest.count = src.count;
1007
1008         /* Hand over to kcopyd */
1009         dm_kcopyd_copy(s->kcopyd_client,
1010                     &src, 1, &dest, 0, copy_callback, pe);
1011 }
1012
1013 static struct dm_snap_pending_exception *
1014 __lookup_pending_exception(struct dm_snapshot *s, chunk_t chunk)
1015 {
1016         struct dm_exception *e = dm_lookup_exception(&s->pending, chunk);
1017
1018         if (!e)
1019                 return NULL;
1020
1021         return container_of(e, struct dm_snap_pending_exception, e);
1022 }
1023
1024 /*
1025  * Looks to see if this snapshot already has a pending exception
1026  * for this chunk, otherwise it allocates a new one and inserts
1027  * it into the pending table.
1028  *
1029  * NOTE: a write lock must be held on snap->lock before calling
1030  * this.
1031  */
1032 static struct dm_snap_pending_exception *
1033 __find_pending_exception(struct dm_snapshot *s,
1034                          struct dm_snap_pending_exception *pe, chunk_t chunk)
1035 {
1036         struct dm_snap_pending_exception *pe2;
1037
1038         pe2 = __lookup_pending_exception(s, chunk);
1039         if (pe2) {
1040                 free_pending_exception(pe);
1041                 return pe2;
1042         }
1043
1044         pe->e.old_chunk = chunk;
1045         bio_list_init(&pe->origin_bios);
1046         bio_list_init(&pe->snapshot_bios);
1047         pe->primary_pe = NULL;
1048         atomic_set(&pe->ref_count, 0);
1049         pe->started = 0;
1050
1051         if (s->store->type->prepare_exception(s->store, &pe->e)) {
1052                 free_pending_exception(pe);
1053                 return NULL;
1054         }
1055
1056         get_pending_exception(pe);
1057         dm_insert_exception(&s->pending, &pe->e);
1058
1059         return pe;
1060 }
1061
1062 static void remap_exception(struct dm_snapshot *s, struct dm_exception *e,
1063                             struct bio *bio, chunk_t chunk)
1064 {
1065         bio->bi_bdev = s->cow->bdev;
1066         bio->bi_sector = chunk_to_sector(s->store,
1067                                          dm_chunk_number(e->new_chunk) +
1068                                          (chunk - e->old_chunk)) +
1069                                          (bio->bi_sector &
1070                                           s->store->chunk_mask);
1071 }
1072
1073 static int snapshot_map(struct dm_target *ti, struct bio *bio,
1074                         union map_info *map_context)
1075 {
1076         struct dm_exception *e;
1077         struct dm_snapshot *s = ti->private;
1078         int r = DM_MAPIO_REMAPPED;
1079         chunk_t chunk;
1080         struct dm_snap_pending_exception *pe = NULL;
1081
1082         if (unlikely(bio_empty_barrier(bio))) {
1083                 bio->bi_bdev = s->cow->bdev;
1084                 return DM_MAPIO_REMAPPED;
1085         }
1086
1087         chunk = sector_to_chunk(s->store, bio->bi_sector);
1088
1089         /* Full snapshots are not usable */
1090         /* To get here the table must be live so s->active is always set. */
1091         if (!s->valid)
1092                 return -EIO;
1093
1094         /* FIXME: should only take write lock if we need
1095          * to copy an exception */
1096         down_write(&s->lock);
1097
1098         if (!s->valid) {
1099                 r = -EIO;
1100                 goto out_unlock;
1101         }
1102
1103         /* If the block is already remapped - use that, else remap it */
1104         e = dm_lookup_exception(&s->complete, chunk);
1105         if (e) {
1106                 remap_exception(s, e, bio, chunk);
1107                 goto out_unlock;
1108         }
1109
1110         /*
1111          * Write to snapshot - higher level takes care of RW/RO
1112          * flags so we should only get this if we are
1113          * writeable.
1114          */
1115         if (bio_rw(bio) == WRITE) {
1116                 pe = __lookup_pending_exception(s, chunk);
1117                 if (!pe) {
1118                         up_write(&s->lock);
1119                         pe = alloc_pending_exception(s);
1120                         down_write(&s->lock);
1121
1122                         if (!s->valid) {
1123                                 free_pending_exception(pe);
1124                                 r = -EIO;
1125                                 goto out_unlock;
1126                         }
1127
1128                         e = dm_lookup_exception(&s->complete, chunk);
1129                         if (e) {
1130                                 free_pending_exception(pe);
1131                                 remap_exception(s, e, bio, chunk);
1132                                 goto out_unlock;
1133                         }
1134
1135                         pe = __find_pending_exception(s, pe, chunk);
1136                         if (!pe) {
1137                                 __invalidate_snapshot(s, -ENOMEM);
1138                                 r = -EIO;
1139                                 goto out_unlock;
1140                         }
1141                 }
1142
1143                 remap_exception(s, &pe->e, bio, chunk);
1144                 bio_list_add(&pe->snapshot_bios, bio);
1145
1146                 r = DM_MAPIO_SUBMITTED;
1147
1148                 if (!pe->started) {
1149                         /* this is protected by snap->lock */
1150                         pe->started = 1;
1151                         up_write(&s->lock);
1152                         start_copy(pe);
1153                         goto out;
1154                 }
1155         } else {
1156                 bio->bi_bdev = s->origin->bdev;
1157                 map_context->ptr = track_chunk(s, chunk);
1158         }
1159
1160  out_unlock:
1161         up_write(&s->lock);
1162  out:
1163         return r;
1164 }
1165
1166 static int snapshot_end_io(struct dm_target *ti, struct bio *bio,
1167                            int error, union map_info *map_context)
1168 {
1169         struct dm_snapshot *s = ti->private;
1170         struct dm_snap_tracked_chunk *c = map_context->ptr;
1171
1172         if (c)
1173                 stop_tracking_chunk(s, c);
1174
1175         return 0;
1176 }
1177
1178 static void snapshot_resume(struct dm_target *ti)
1179 {
1180         struct dm_snapshot *s = ti->private;
1181
1182         down_write(&s->lock);
1183         s->active = 1;
1184         up_write(&s->lock);
1185 }
1186
1187 static int snapshot_status(struct dm_target *ti, status_type_t type,
1188                            char *result, unsigned int maxlen)
1189 {
1190         unsigned sz = 0;
1191         struct dm_snapshot *snap = ti->private;
1192
1193         switch (type) {
1194         case STATUSTYPE_INFO:
1195
1196                 down_write(&snap->lock);
1197
1198                 if (!snap->valid)
1199                         DMEMIT("Invalid");
1200                 else {
1201                         if (snap->store->type->usage) {
1202                                 sector_t total_sectors, sectors_allocated,
1203                                          metadata_sectors;
1204                                 snap->store->type->usage(snap->store,
1205                                                          &total_sectors,
1206                                                          &sectors_allocated,
1207                                                          &metadata_sectors);
1208                                 DMEMIT("%llu/%llu %llu",
1209                                        (unsigned long long)sectors_allocated,
1210                                        (unsigned long long)total_sectors,
1211                                        (unsigned long long)metadata_sectors);
1212                         }
1213                         else
1214                                 DMEMIT("Unknown");
1215                 }
1216
1217                 up_write(&snap->lock);
1218
1219                 break;
1220
1221         case STATUSTYPE_TABLE:
1222                 /*
1223                  * kdevname returns a static pointer so we need
1224                  * to make private copies if the output is to
1225                  * make sense.
1226                  */
1227                 DMEMIT("%s %s", snap->origin->name, snap->cow->name);
1228                 snap->store->type->status(snap->store, type, result + sz,
1229                                           maxlen - sz);
1230                 break;
1231         }
1232
1233         return 0;
1234 }
1235
1236 static int snapshot_iterate_devices(struct dm_target *ti,
1237                                     iterate_devices_callout_fn fn, void *data)
1238 {
1239         struct dm_snapshot *snap = ti->private;
1240
1241         return fn(ti, snap->origin, 0, ti->len, data);
1242 }
1243
1244
1245 /*-----------------------------------------------------------------
1246  * Origin methods
1247  *---------------------------------------------------------------*/
1248 static int __origin_write(struct list_head *snapshots, struct bio *bio)
1249 {
1250         int r = DM_MAPIO_REMAPPED, first = 0;
1251         struct dm_snapshot *snap;
1252         struct dm_exception *e;
1253         struct dm_snap_pending_exception *pe, *next_pe, *primary_pe = NULL;
1254         chunk_t chunk;
1255         LIST_HEAD(pe_queue);
1256
1257         /* Do all the snapshots on this origin */
1258         list_for_each_entry (snap, snapshots, list) {
1259
1260                 down_write(&snap->lock);
1261
1262                 /* Only deal with valid and active snapshots */
1263                 if (!snap->valid || !snap->active)
1264                         goto next_snapshot;
1265
1266                 /* Nothing to do if writing beyond end of snapshot */
1267                 if (bio->bi_sector >= dm_table_get_size(snap->ti->table))
1268                         goto next_snapshot;
1269
1270                 /*
1271                  * Remember, different snapshots can have
1272                  * different chunk sizes.
1273                  */
1274                 chunk = sector_to_chunk(snap->store, bio->bi_sector);
1275
1276                 /*
1277                  * Check exception table to see if block
1278                  * is already remapped in this snapshot
1279                  * and trigger an exception if not.
1280                  *
1281                  * ref_count is initialised to 1 so pending_complete()
1282                  * won't destroy the primary_pe while we're inside this loop.
1283                  */
1284                 e = dm_lookup_exception(&snap->complete, chunk);
1285                 if (e)
1286                         goto next_snapshot;
1287
1288                 pe = __lookup_pending_exception(snap, chunk);
1289                 if (!pe) {
1290                         up_write(&snap->lock);
1291                         pe = alloc_pending_exception(snap);
1292                         down_write(&snap->lock);
1293
1294                         if (!snap->valid) {
1295                                 free_pending_exception(pe);
1296                                 goto next_snapshot;
1297                         }
1298
1299                         e = dm_lookup_exception(&snap->complete, chunk);
1300                         if (e) {
1301                                 free_pending_exception(pe);
1302                                 goto next_snapshot;
1303                         }
1304
1305                         pe = __find_pending_exception(snap, pe, chunk);
1306                         if (!pe) {
1307                                 __invalidate_snapshot(snap, -ENOMEM);
1308                                 goto next_snapshot;
1309                         }
1310                 }
1311
1312                 if (!primary_pe) {
1313                         /*
1314                          * Either every pe here has same
1315                          * primary_pe or none has one yet.
1316                          */
1317                         if (pe->primary_pe)
1318                                 primary_pe = pe->primary_pe;
1319                         else {
1320                                 primary_pe = pe;
1321                                 first = 1;
1322                         }
1323
1324                         bio_list_add(&primary_pe->origin_bios, bio);
1325
1326                         r = DM_MAPIO_SUBMITTED;
1327                 }
1328
1329                 if (!pe->primary_pe) {
1330                         pe->primary_pe = primary_pe;
1331                         get_pending_exception(primary_pe);
1332                 }
1333
1334                 if (!pe->started) {
1335                         pe->started = 1;
1336                         list_add_tail(&pe->list, &pe_queue);
1337                 }
1338
1339  next_snapshot:
1340                 up_write(&snap->lock);
1341         }
1342
1343         if (!primary_pe)
1344                 return r;
1345
1346         /*
1347          * If this is the first time we're processing this chunk and
1348          * ref_count is now 1 it means all the pending exceptions
1349          * got completed while we were in the loop above, so it falls to
1350          * us here to remove the primary_pe and submit any origin_bios.
1351          */
1352
1353         if (first && atomic_dec_and_test(&primary_pe->ref_count)) {
1354                 flush_bios(bio_list_get(&primary_pe->origin_bios));
1355                 free_pending_exception(primary_pe);
1356                 /* If we got here, pe_queue is necessarily empty. */
1357                 return r;
1358         }
1359
1360         /*
1361          * Now that we have a complete pe list we can start the copying.
1362          */
1363         list_for_each_entry_safe(pe, next_pe, &pe_queue, list)
1364                 start_copy(pe);
1365
1366         return r;
1367 }
1368
1369 /*
1370  * Called on a write from the origin driver.
1371  */
1372 static int do_origin(struct dm_dev *origin, struct bio *bio)
1373 {
1374         struct origin *o;
1375         int r = DM_MAPIO_REMAPPED;
1376
1377         down_read(&_origins_lock);
1378         o = __lookup_origin(origin->bdev);
1379         if (o)
1380                 r = __origin_write(&o->snapshots, bio);
1381         up_read(&_origins_lock);
1382
1383         return r;
1384 }
1385
1386 /*
1387  * Origin: maps a linear range of a device, with hooks for snapshotting.
1388  */
1389
1390 /*
1391  * Construct an origin mapping: <dev_path>
1392  * The context for an origin is merely a 'struct dm_dev *'
1393  * pointing to the real device.
1394  */
1395 static int origin_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1396 {
1397         int r;
1398         struct dm_dev *dev;
1399
1400         if (argc != 1) {
1401                 ti->error = "origin: incorrect number of arguments";
1402                 return -EINVAL;
1403         }
1404
1405         r = dm_get_device(ti, argv[0], 0, ti->len,
1406                           dm_table_get_mode(ti->table), &dev);
1407         if (r) {
1408                 ti->error = "Cannot get target device";
1409                 return r;
1410         }
1411
1412         ti->private = dev;
1413         ti->num_flush_requests = 1;
1414
1415         return 0;
1416 }
1417
1418 static void origin_dtr(struct dm_target *ti)
1419 {
1420         struct dm_dev *dev = ti->private;
1421         dm_put_device(ti, dev);
1422 }
1423
1424 static int origin_map(struct dm_target *ti, struct bio *bio,
1425                       union map_info *map_context)
1426 {
1427         struct dm_dev *dev = ti->private;
1428         bio->bi_bdev = dev->bdev;
1429
1430         if (unlikely(bio_empty_barrier(bio)))
1431                 return DM_MAPIO_REMAPPED;
1432
1433         /* Only tell snapshots if this is a write */
1434         return (bio_rw(bio) == WRITE) ? do_origin(dev, bio) : DM_MAPIO_REMAPPED;
1435 }
1436
1437 /*
1438  * Set the target "split_io" field to the minimum of all the snapshots'
1439  * chunk sizes.
1440  */
1441 static void origin_resume(struct dm_target *ti)
1442 {
1443         struct dm_dev *dev = ti->private;
1444
1445         down_read(&_origins_lock);
1446
1447         ti->split_io = __minimum_chunk_size(__lookup_origin(dev->bdev));
1448
1449         up_read(&_origins_lock);
1450 }
1451
1452 static int origin_status(struct dm_target *ti, status_type_t type, char *result,
1453                          unsigned int maxlen)
1454 {
1455         struct dm_dev *dev = ti->private;
1456
1457         switch (type) {
1458         case STATUSTYPE_INFO:
1459                 result[0] = '\0';
1460                 break;
1461
1462         case STATUSTYPE_TABLE:
1463                 snprintf(result, maxlen, "%s", dev->name);
1464                 break;
1465         }
1466
1467         return 0;
1468 }
1469
1470 static int origin_iterate_devices(struct dm_target *ti,
1471                                   iterate_devices_callout_fn fn, void *data)
1472 {
1473         struct dm_dev *dev = ti->private;
1474
1475         return fn(ti, dev, 0, ti->len, data);
1476 }
1477
1478 static struct target_type origin_target = {
1479         .name    = "snapshot-origin",
1480         .version = {1, 7, 0},
1481         .module  = THIS_MODULE,
1482         .ctr     = origin_ctr,
1483         .dtr     = origin_dtr,
1484         .map     = origin_map,
1485         .resume  = origin_resume,
1486         .status  = origin_status,
1487         .iterate_devices = origin_iterate_devices,
1488 };
1489
1490 static struct target_type snapshot_target = {
1491         .name    = "snapshot",
1492         .version = {1, 8, 0},
1493         .module  = THIS_MODULE,
1494         .ctr     = snapshot_ctr,
1495         .dtr     = snapshot_dtr,
1496         .map     = snapshot_map,
1497         .end_io  = snapshot_end_io,
1498         .resume  = snapshot_resume,
1499         .status  = snapshot_status,
1500         .iterate_devices = snapshot_iterate_devices,
1501 };
1502
1503 static int __init dm_snapshot_init(void)
1504 {
1505         int r;
1506
1507         r = dm_exception_store_init();
1508         if (r) {
1509                 DMERR("Failed to initialize exception stores");
1510                 return r;
1511         }
1512
1513         r = dm_register_target(&snapshot_target);
1514         if (r) {
1515                 DMERR("snapshot target register failed %d", r);
1516                 goto bad_register_snapshot_target;
1517         }
1518
1519         r = dm_register_target(&origin_target);
1520         if (r < 0) {
1521                 DMERR("Origin target register failed %d", r);
1522                 goto bad1;
1523         }
1524
1525         r = init_origin_hash();
1526         if (r) {
1527                 DMERR("init_origin_hash failed.");
1528                 goto bad2;
1529         }
1530
1531         exception_cache = KMEM_CACHE(dm_exception, 0);
1532         if (!exception_cache) {
1533                 DMERR("Couldn't create exception cache.");
1534                 r = -ENOMEM;
1535                 goto bad3;
1536         }
1537
1538         pending_cache = KMEM_CACHE(dm_snap_pending_exception, 0);
1539         if (!pending_cache) {
1540                 DMERR("Couldn't create pending cache.");
1541                 r = -ENOMEM;
1542                 goto bad4;
1543         }
1544
1545         tracked_chunk_cache = KMEM_CACHE(dm_snap_tracked_chunk, 0);
1546         if (!tracked_chunk_cache) {
1547                 DMERR("Couldn't create cache to track chunks in use.");
1548                 r = -ENOMEM;
1549                 goto bad5;
1550         }
1551
1552         ksnapd = create_singlethread_workqueue("ksnapd");
1553         if (!ksnapd) {
1554                 DMERR("Failed to create ksnapd workqueue.");
1555                 r = -ENOMEM;
1556                 goto bad_pending_pool;
1557         }
1558
1559         return 0;
1560
1561 bad_pending_pool:
1562         kmem_cache_destroy(tracked_chunk_cache);
1563 bad5:
1564         kmem_cache_destroy(pending_cache);
1565 bad4:
1566         kmem_cache_destroy(exception_cache);
1567 bad3:
1568         exit_origin_hash();
1569 bad2:
1570         dm_unregister_target(&origin_target);
1571 bad1:
1572         dm_unregister_target(&snapshot_target);
1573
1574 bad_register_snapshot_target:
1575         dm_exception_store_exit();
1576         return r;
1577 }
1578
1579 static void __exit dm_snapshot_exit(void)
1580 {
1581         destroy_workqueue(ksnapd);
1582
1583         dm_unregister_target(&snapshot_target);
1584         dm_unregister_target(&origin_target);
1585
1586         exit_origin_hash();
1587         kmem_cache_destroy(pending_cache);
1588         kmem_cache_destroy(exception_cache);
1589         kmem_cache_destroy(tracked_chunk_cache);
1590
1591         dm_exception_store_exit();
1592 }
1593
1594 /* Module hooks */
1595 module_init(dm_snapshot_init);
1596 module_exit(dm_snapshot_exit);
1597
1598 MODULE_DESCRIPTION(DM_NAME " snapshot target");
1599 MODULE_AUTHOR("Joe Thornber");
1600 MODULE_LICENSE("GPL");