aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-snap.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/dm-snap.c')
-rw-r--r--drivers/md/dm-snap.c105
1 files changed, 50 insertions, 55 deletions
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 0821a2b68a73..1da41229fbf2 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -42,8 +42,8 @@
42static struct workqueue_struct *ksnapd; 42static struct workqueue_struct *ksnapd;
43static void flush_queued_bios(struct work_struct *work); 43static void flush_queued_bios(struct work_struct *work);
44 44
45struct pending_exception { 45struct dm_snap_pending_exception {
46 struct exception e; 46 struct dm_snap_exception e;
47 47
48 /* 48 /*
49 * Origin buffers waiting for this to complete are held 49 * Origin buffers waiting for this to complete are held
@@ -63,7 +63,7 @@ struct pending_exception {
63 * group of pending_exceptions. It is always last to get freed. 63 * group of pending_exceptions. It is always last to get freed.
64 * These fields get set up when writing to the origin. 64 * These fields get set up when writing to the origin.
65 */ 65 */
66 struct pending_exception *primary_pe; 66 struct dm_snap_pending_exception *primary_pe;
67 67
68 /* 68 /*
69 * Number of pending_exceptions processing this chunk. 69 * Number of pending_exceptions processing this chunk.
@@ -137,7 +137,7 @@ static void exit_origin_hash(void)
137 kfree(_origins); 137 kfree(_origins);
138} 138}
139 139
140static inline unsigned int origin_hash(struct block_device *bdev) 140static unsigned origin_hash(struct block_device *bdev)
141{ 141{
142 return bdev->bd_dev & ORIGIN_MASK; 142 return bdev->bd_dev & ORIGIN_MASK;
143} 143}
@@ -231,7 +231,7 @@ static int init_exception_table(struct exception_table *et, uint32_t size)
231static void exit_exception_table(struct exception_table *et, struct kmem_cache *mem) 231static void exit_exception_table(struct exception_table *et, struct kmem_cache *mem)
232{ 232{
233 struct list_head *slot; 233 struct list_head *slot;
234 struct exception *ex, *next; 234 struct dm_snap_exception *ex, *next;
235 int i, size; 235 int i, size;
236 236
237 size = et->hash_mask + 1; 237 size = et->hash_mask + 1;
@@ -245,18 +245,19 @@ static void exit_exception_table(struct exception_table *et, struct kmem_cache *
245 vfree(et->table); 245 vfree(et->table);
246} 246}
247 247
248static inline uint32_t exception_hash(struct exception_table *et, chunk_t chunk) 248static uint32_t exception_hash(struct exception_table *et, chunk_t chunk)
249{ 249{
250 return chunk & et->hash_mask; 250 return chunk & et->hash_mask;
251} 251}
252 252
253static void insert_exception(struct exception_table *eh, struct exception *e) 253static void insert_exception(struct exception_table *eh,
254 struct dm_snap_exception *e)
254{ 255{
255 struct list_head *l = &eh->table[exception_hash(eh, e->old_chunk)]; 256 struct list_head *l = &eh->table[exception_hash(eh, e->old_chunk)];
256 list_add(&e->hash_list, l); 257 list_add(&e->hash_list, l);
257} 258}
258 259
259static inline void remove_exception(struct exception *e) 260static void remove_exception(struct dm_snap_exception *e)
260{ 261{
261 list_del(&e->hash_list); 262 list_del(&e->hash_list);
262} 263}
@@ -265,11 +266,11 @@ static inline void remove_exception(struct exception *e)
265 * Return the exception data for a sector, or NULL if not 266 * Return the exception data for a sector, or NULL if not
266 * remapped. 267 * remapped.
267 */ 268 */
268static struct exception *lookup_exception(struct exception_table *et, 269static struct dm_snap_exception *lookup_exception(struct exception_table *et,
269 chunk_t chunk) 270 chunk_t chunk)
270{ 271{
271 struct list_head *slot; 272 struct list_head *slot;
272 struct exception *e; 273 struct dm_snap_exception *e;
273 274
274 slot = &et->table[exception_hash(et, chunk)]; 275 slot = &et->table[exception_hash(et, chunk)];
275 list_for_each_entry (e, slot, hash_list) 276 list_for_each_entry (e, slot, hash_list)
@@ -279,9 +280,9 @@ static struct exception *lookup_exception(struct exception_table *et,
279 return NULL; 280 return NULL;
280} 281}
281 282
282static inline struct exception *alloc_exception(void) 283static struct dm_snap_exception *alloc_exception(void)
283{ 284{
284 struct exception *e; 285 struct dm_snap_exception *e;
285 286
286 e = kmem_cache_alloc(exception_cache, GFP_NOIO); 287 e = kmem_cache_alloc(exception_cache, GFP_NOIO);
287 if (!e) 288 if (!e)
@@ -290,24 +291,24 @@ static inline struct exception *alloc_exception(void)
290 return e; 291 return e;
291} 292}
292 293
293static inline void free_exception(struct exception *e) 294static void free_exception(struct dm_snap_exception *e)
294{ 295{
295 kmem_cache_free(exception_cache, e); 296 kmem_cache_free(exception_cache, e);
296} 297}
297 298
298static inline struct pending_exception *alloc_pending_exception(void) 299static struct dm_snap_pending_exception *alloc_pending_exception(void)
299{ 300{
300 return mempool_alloc(pending_pool, GFP_NOIO); 301 return mempool_alloc(pending_pool, GFP_NOIO);
301} 302}
302 303
303static inline void free_pending_exception(struct pending_exception *pe) 304static void free_pending_exception(struct dm_snap_pending_exception *pe)
304{ 305{
305 mempool_free(pe, pending_pool); 306 mempool_free(pe, pending_pool);
306} 307}
307 308
308int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new) 309int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new)
309{ 310{
310 struct exception *e; 311 struct dm_snap_exception *e;
311 312
312 e = alloc_exception(); 313 e = alloc_exception();
313 if (!e) 314 if (!e)
@@ -334,7 +335,7 @@ static int calc_max_buckets(void)
334/* 335/*
335 * Rounds a number down to a power of 2. 336 * Rounds a number down to a power of 2.
336 */ 337 */
337static inline uint32_t round_down(uint32_t n) 338static uint32_t round_down(uint32_t n)
338{ 339{
339 while (n & (n - 1)) 340 while (n & (n - 1))
340 n &= (n - 1); 341 n &= (n - 1);
@@ -384,7 +385,7 @@ static int init_hash_tables(struct dm_snapshot *s)
384 * Round a number up to the nearest 'size' boundary. size must 385 * Round a number up to the nearest 'size' boundary. size must
385 * be a power of 2. 386 * be a power of 2.
386 */ 387 */
387static inline ulong round_up(ulong n, ulong size) 388static ulong round_up(ulong n, ulong size)
388{ 389{
389 size--; 390 size--;
390 return (n + size) & ~size; 391 return (n + size) & ~size;
@@ -577,7 +578,7 @@ static void __free_exceptions(struct dm_snapshot *s)
577 578
578static void snapshot_dtr(struct dm_target *ti) 579static void snapshot_dtr(struct dm_target *ti)
579{ 580{
580 struct dm_snapshot *s = (struct dm_snapshot *) ti->private; 581 struct dm_snapshot *s = ti->private;
581 582
582 flush_workqueue(ksnapd); 583 flush_workqueue(ksnapd);
583 584
@@ -655,14 +656,14 @@ static void __invalidate_snapshot(struct dm_snapshot *s, int err)
655 dm_table_event(s->table); 656 dm_table_event(s->table);
656} 657}
657 658
658static void get_pending_exception(struct pending_exception *pe) 659static void get_pending_exception(struct dm_snap_pending_exception *pe)
659{ 660{
660 atomic_inc(&pe->ref_count); 661 atomic_inc(&pe->ref_count);
661} 662}
662 663
663static struct bio *put_pending_exception(struct pending_exception *pe) 664static struct bio *put_pending_exception(struct dm_snap_pending_exception *pe)
664{ 665{
665 struct pending_exception *primary_pe; 666 struct dm_snap_pending_exception *primary_pe;
666 struct bio *origin_bios = NULL; 667 struct bio *origin_bios = NULL;
667 668
668 primary_pe = pe->primary_pe; 669 primary_pe = pe->primary_pe;
@@ -692,9 +693,9 @@ static struct bio *put_pending_exception(struct pending_exception *pe)
692 return origin_bios; 693 return origin_bios;
693} 694}
694 695
695static void pending_complete(struct pending_exception *pe, int success) 696static void pending_complete(struct dm_snap_pending_exception *pe, int success)
696{ 697{
697 struct exception *e; 698 struct dm_snap_exception *e;
698 struct dm_snapshot *s = pe->snap; 699 struct dm_snapshot *s = pe->snap;
699 struct bio *origin_bios = NULL; 700 struct bio *origin_bios = NULL;
700 struct bio *snapshot_bios = NULL; 701 struct bio *snapshot_bios = NULL;
@@ -748,7 +749,8 @@ static void pending_complete(struct pending_exception *pe, int success)
748 749
749static void commit_callback(void *context, int success) 750static void commit_callback(void *context, int success)
750{ 751{
751 struct pending_exception *pe = (struct pending_exception *) context; 752 struct dm_snap_pending_exception *pe = context;
753
752 pending_complete(pe, success); 754 pending_complete(pe, success);
753} 755}
754 756
@@ -758,7 +760,7 @@ static void commit_callback(void *context, int success)
758 */ 760 */
759static void copy_callback(int read_err, unsigned int write_err, void *context) 761static void copy_callback(int read_err, unsigned int write_err, void *context)
760{ 762{
761 struct pending_exception *pe = (struct pending_exception *) context; 763 struct dm_snap_pending_exception *pe = context;
762 struct dm_snapshot *s = pe->snap; 764 struct dm_snapshot *s = pe->snap;
763 765
764 if (read_err || write_err) 766 if (read_err || write_err)
@@ -773,7 +775,7 @@ static void copy_callback(int read_err, unsigned int write_err, void *context)
773/* 775/*
774 * Dispatches the copy operation to kcopyd. 776 * Dispatches the copy operation to kcopyd.
775 */ 777 */
776static void start_copy(struct pending_exception *pe) 778static void start_copy(struct dm_snap_pending_exception *pe)
777{ 779{
778 struct dm_snapshot *s = pe->snap; 780 struct dm_snapshot *s = pe->snap;
779 struct io_region src, dest; 781 struct io_region src, dest;
@@ -803,11 +805,11 @@ static void start_copy(struct pending_exception *pe)
803 * NOTE: a write lock must be held on snap->lock before calling 805 * NOTE: a write lock must be held on snap->lock before calling
804 * this. 806 * this.
805 */ 807 */
806static struct pending_exception * 808static struct dm_snap_pending_exception *
807__find_pending_exception(struct dm_snapshot *s, struct bio *bio) 809__find_pending_exception(struct dm_snapshot *s, struct bio *bio)
808{ 810{
809 struct exception *e; 811 struct dm_snap_exception *e;
810 struct pending_exception *pe; 812 struct dm_snap_pending_exception *pe;
811 chunk_t chunk = sector_to_chunk(s, bio->bi_sector); 813 chunk_t chunk = sector_to_chunk(s, bio->bi_sector);
812 814
813 /* 815 /*
@@ -816,7 +818,7 @@ __find_pending_exception(struct dm_snapshot *s, struct bio *bio)
816 e = lookup_exception(&s->pending, chunk); 818 e = lookup_exception(&s->pending, chunk);
817 if (e) { 819 if (e) {
818 /* cast the exception to a pending exception */ 820 /* cast the exception to a pending exception */
819 pe = container_of(e, struct pending_exception, e); 821 pe = container_of(e, struct dm_snap_pending_exception, e);
820 goto out; 822 goto out;
821 } 823 }
822 824
@@ -836,7 +838,7 @@ __find_pending_exception(struct dm_snapshot *s, struct bio *bio)
836 e = lookup_exception(&s->pending, chunk); 838 e = lookup_exception(&s->pending, chunk);
837 if (e) { 839 if (e) {
838 free_pending_exception(pe); 840 free_pending_exception(pe);
839 pe = container_of(e, struct pending_exception, e); 841 pe = container_of(e, struct dm_snap_pending_exception, e);
840 goto out; 842 goto out;
841 } 843 }
842 844
@@ -860,8 +862,8 @@ __find_pending_exception(struct dm_snapshot *s, struct bio *bio)
860 return pe; 862 return pe;
861} 863}
862 864
863static inline void remap_exception(struct dm_snapshot *s, struct exception *e, 865static void remap_exception(struct dm_snapshot *s, struct dm_snap_exception *e,
864 struct bio *bio) 866 struct bio *bio)
865{ 867{
866 bio->bi_bdev = s->cow->bdev; 868 bio->bi_bdev = s->cow->bdev;
867 bio->bi_sector = chunk_to_sector(s, e->new_chunk) + 869 bio->bi_sector = chunk_to_sector(s, e->new_chunk) +
@@ -871,11 +873,11 @@ static inline void remap_exception(struct dm_snapshot *s, struct exception *e,
871static int snapshot_map(struct dm_target *ti, struct bio *bio, 873static int snapshot_map(struct dm_target *ti, struct bio *bio,
872 union map_info *map_context) 874 union map_info *map_context)
873{ 875{
874 struct exception *e; 876 struct dm_snap_exception *e;
875 struct dm_snapshot *s = (struct dm_snapshot *) ti->private; 877 struct dm_snapshot *s = ti->private;
876 int r = DM_MAPIO_REMAPPED; 878 int r = DM_MAPIO_REMAPPED;
877 chunk_t chunk; 879 chunk_t chunk;
878 struct pending_exception *pe = NULL; 880 struct dm_snap_pending_exception *pe = NULL;
879 881
880 chunk = sector_to_chunk(s, bio->bi_sector); 882 chunk = sector_to_chunk(s, bio->bi_sector);
881 883
@@ -945,7 +947,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
945 947
946static void snapshot_resume(struct dm_target *ti) 948static void snapshot_resume(struct dm_target *ti)
947{ 949{
948 struct dm_snapshot *s = (struct dm_snapshot *) ti->private; 950 struct dm_snapshot *s = ti->private;
949 951
950 down_write(&s->lock); 952 down_write(&s->lock);
951 s->active = 1; 953 s->active = 1;
@@ -955,7 +957,7 @@ static void snapshot_resume(struct dm_target *ti)
955static int snapshot_status(struct dm_target *ti, status_type_t type, 957static int snapshot_status(struct dm_target *ti, status_type_t type,
956 char *result, unsigned int maxlen) 958 char *result, unsigned int maxlen)
957{ 959{
958 struct dm_snapshot *snap = (struct dm_snapshot *) ti->private; 960 struct dm_snapshot *snap = ti->private;
959 961
960 switch (type) { 962 switch (type) {
961 case STATUSTYPE_INFO: 963 case STATUSTYPE_INFO:
@@ -999,8 +1001,8 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
999{ 1001{
1000 int r = DM_MAPIO_REMAPPED, first = 0; 1002 int r = DM_MAPIO_REMAPPED, first = 0;
1001 struct dm_snapshot *snap; 1003 struct dm_snapshot *snap;
1002 struct exception *e; 1004 struct dm_snap_exception *e;
1003 struct pending_exception *pe, *next_pe, *primary_pe = NULL; 1005 struct dm_snap_pending_exception *pe, *next_pe, *primary_pe = NULL;
1004 chunk_t chunk; 1006 chunk_t chunk;
1005 LIST_HEAD(pe_queue); 1007 LIST_HEAD(pe_queue);
1006 1008
@@ -1147,14 +1149,14 @@ static int origin_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1147 1149
1148static void origin_dtr(struct dm_target *ti) 1150static void origin_dtr(struct dm_target *ti)
1149{ 1151{
1150 struct dm_dev *dev = (struct dm_dev *) ti->private; 1152 struct dm_dev *dev = ti->private;
1151 dm_put_device(ti, dev); 1153 dm_put_device(ti, dev);
1152} 1154}
1153 1155
1154static int origin_map(struct dm_target *ti, struct bio *bio, 1156static int origin_map(struct dm_target *ti, struct bio *bio,
1155 union map_info *map_context) 1157 union map_info *map_context)
1156{ 1158{
1157 struct dm_dev *dev = (struct dm_dev *) ti->private; 1159 struct dm_dev *dev = ti->private;
1158 bio->bi_bdev = dev->bdev; 1160 bio->bi_bdev = dev->bdev;
1159 1161
1160 if (unlikely(bio_barrier(bio))) 1162 if (unlikely(bio_barrier(bio)))
@@ -1172,7 +1174,7 @@ static int origin_map(struct dm_target *ti, struct bio *bio,
1172 */ 1174 */
1173static void origin_resume(struct dm_target *ti) 1175static void origin_resume(struct dm_target *ti)
1174{ 1176{
1175 struct dm_dev *dev = (struct dm_dev *) ti->private; 1177 struct dm_dev *dev = ti->private;
1176 struct dm_snapshot *snap; 1178 struct dm_snapshot *snap;
1177 struct origin *o; 1179 struct origin *o;
1178 chunk_t chunk_size = 0; 1180 chunk_t chunk_size = 0;
@@ -1190,7 +1192,7 @@ static void origin_resume(struct dm_target *ti)
1190static int origin_status(struct dm_target *ti, status_type_t type, char *result, 1192static int origin_status(struct dm_target *ti, status_type_t type, char *result,
1191 unsigned int maxlen) 1193 unsigned int maxlen)
1192{ 1194{
1193 struct dm_dev *dev = (struct dm_dev *) ti->private; 1195 struct dm_dev *dev = ti->private;
1194 1196
1195 switch (type) { 1197 switch (type) {
1196 case STATUSTYPE_INFO: 1198 case STATUSTYPE_INFO:
@@ -1249,21 +1251,14 @@ static int __init dm_snapshot_init(void)
1249 goto bad2; 1251 goto bad2;
1250 } 1252 }
1251 1253
1252 exception_cache = kmem_cache_create("dm-snapshot-ex", 1254 exception_cache = KMEM_CACHE(dm_snap_exception, 0);
1253 sizeof(struct exception),
1254 __alignof__(struct exception),
1255 0, NULL, NULL);
1256 if (!exception_cache) { 1255 if (!exception_cache) {
1257 DMERR("Couldn't create exception cache."); 1256 DMERR("Couldn't create exception cache.");
1258 r = -ENOMEM; 1257 r = -ENOMEM;
1259 goto bad3; 1258 goto bad3;
1260 } 1259 }
1261 1260
1262 pending_cache = 1261 pending_cache = KMEM_CACHE(dm_snap_pending_exception, 0);
1263 kmem_cache_create("dm-snapshot-in",
1264 sizeof(struct pending_exception),
1265 __alignof__(struct pending_exception),
1266 0, NULL, NULL);
1267 if (!pending_cache) { 1262 if (!pending_cache) {
1268 DMERR("Couldn't create pending cache."); 1263 DMERR("Couldn't create pending cache.");
1269 r = -ENOMEM; 1264 r = -ENOMEM;