diff options
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-exception-store.c | 1 | ||||
-rw-r--r-- | drivers/md/dm-exception-store.h | 13 | ||||
-rw-r--r-- | drivers/md/dm-snap-persistent.c | 42 | ||||
-rw-r--r-- | drivers/md/dm-snap-transient.c | 21 | ||||
-rw-r--r-- | drivers/md/dm-snap.c | 9 | ||||
-rw-r--r-- | drivers/md/dm-snap.h | 6 |
6 files changed, 55 insertions, 37 deletions
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c index 74777e0f80df..dccbfb0e010f 100644 --- a/drivers/md/dm-exception-store.c +++ b/drivers/md/dm-exception-store.c | |||
@@ -11,7 +11,6 @@ | |||
11 | #include <linux/pagemap.h> | 11 | #include <linux/pagemap.h> |
12 | #include <linux/vmalloc.h> | 12 | #include <linux/vmalloc.h> |
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/device-mapper.h> | ||
15 | 14 | ||
16 | #define DM_MSG_PREFIX "snapshot exception stores" | 15 | #define DM_MSG_PREFIX "snapshot exception stores" |
17 | 16 | ||
diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index 78d1acec77e9..bb9f33d5daa2 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h | |||
@@ -11,6 +11,7 @@ | |||
11 | #define _LINUX_DM_EXCEPTION_STORE | 11 | #define _LINUX_DM_EXCEPTION_STORE |
12 | 12 | ||
13 | #include <linux/blkdev.h> | 13 | #include <linux/blkdev.h> |
14 | #include <linux/device-mapper.h> | ||
14 | 15 | ||
15 | /* | 16 | /* |
16 | * The snapshot code deals with largish chunks of the disk at a | 17 | * The snapshot code deals with largish chunks of the disk at a |
@@ -37,7 +38,6 @@ struct dm_snap_exception { | |||
37 | * COW device). | 38 | * COW device). |
38 | */ | 39 | */ |
39 | struct dm_exception_store { | 40 | struct dm_exception_store { |
40 | |||
41 | /* | 41 | /* |
42 | * Destroys this object when you've finished with it. | 42 | * Destroys this object when you've finished with it. |
43 | */ | 43 | */ |
@@ -45,9 +45,13 @@ struct dm_exception_store { | |||
45 | 45 | ||
46 | /* | 46 | /* |
47 | * The target shouldn't read the COW device until this is | 47 | * The target shouldn't read the COW device until this is |
48 | * called. | 48 | * called. As exceptions are read from the COW, they are |
49 | * reported back via the callback. | ||
49 | */ | 50 | */ |
50 | int (*read_metadata) (struct dm_exception_store *store); | 51 | int (*read_metadata) (struct dm_exception_store *store, |
52 | int (*callback)(void *callback_context, | ||
53 | chunk_t old, chunk_t new), | ||
54 | void *callback_context); | ||
51 | 55 | ||
52 | /* | 56 | /* |
53 | * Find somewhere to store the next exception. | 57 | * Find somewhere to store the next exception. |
@@ -68,6 +72,9 @@ struct dm_exception_store { | |||
68 | */ | 72 | */ |
69 | void (*drop_snapshot) (struct dm_exception_store *store); | 73 | void (*drop_snapshot) (struct dm_exception_store *store); |
70 | 74 | ||
75 | int (*status) (struct dm_exception_store *store, status_type_t status, | ||
76 | char *result, unsigned int maxlen); | ||
77 | |||
71 | /* | 78 | /* |
72 | * Return how full the snapshot is. | 79 | * Return how full the snapshot is. |
73 | */ | 80 | */ |
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c index 57c946c69ee7..936b34e0959f 100644 --- a/drivers/md/dm-snap-persistent.c +++ b/drivers/md/dm-snap-persistent.c | |||
@@ -395,7 +395,11 @@ static void write_exception(struct pstore *ps, | |||
395 | * 'full' is filled in to indicate if the area has been | 395 | * 'full' is filled in to indicate if the area has been |
396 | * filled. | 396 | * filled. |
397 | */ | 397 | */ |
398 | static int insert_exceptions(struct pstore *ps, int *full) | 398 | static int insert_exceptions(struct pstore *ps, |
399 | int (*callback)(void *callback_context, | ||
400 | chunk_t old, chunk_t new), | ||
401 | void *callback_context, | ||
402 | int *full) | ||
399 | { | 403 | { |
400 | int r; | 404 | int r; |
401 | unsigned int i; | 405 | unsigned int i; |
@@ -428,7 +432,7 @@ static int insert_exceptions(struct pstore *ps, int *full) | |||
428 | /* | 432 | /* |
429 | * Otherwise we add the exception to the snapshot. | 433 | * Otherwise we add the exception to the snapshot. |
430 | */ | 434 | */ |
431 | r = dm_add_exception(ps->snap, de.old_chunk, de.new_chunk); | 435 | r = callback(callback_context, de.old_chunk, de.new_chunk); |
432 | if (r) | 436 | if (r) |
433 | return r; | 437 | return r; |
434 | } | 438 | } |
@@ -436,7 +440,10 @@ static int insert_exceptions(struct pstore *ps, int *full) | |||
436 | return 0; | 440 | return 0; |
437 | } | 441 | } |
438 | 442 | ||
439 | static int read_exceptions(struct pstore *ps) | 443 | static int read_exceptions(struct pstore *ps, |
444 | int (*callback)(void *callback_context, chunk_t old, | ||
445 | chunk_t new), | ||
446 | void *callback_context) | ||
440 | { | 447 | { |
441 | int r, full = 1; | 448 | int r, full = 1; |
442 | 449 | ||
@@ -449,7 +456,7 @@ static int read_exceptions(struct pstore *ps) | |||
449 | if (r) | 456 | if (r) |
450 | return r; | 457 | return r; |
451 | 458 | ||
452 | r = insert_exceptions(ps, &full); | 459 | r = insert_exceptions(ps, callback, callback_context, &full); |
453 | if (r) | 460 | if (r) |
454 | return r; | 461 | return r; |
455 | } | 462 | } |
@@ -482,7 +489,10 @@ static void persistent_destroy(struct dm_exception_store *store) | |||
482 | kfree(ps); | 489 | kfree(ps); |
483 | } | 490 | } |
484 | 491 | ||
485 | static int persistent_read_metadata(struct dm_exception_store *store) | 492 | static int persistent_read_metadata(struct dm_exception_store *store, |
493 | int (*callback)(void *callback_context, | ||
494 | chunk_t old, chunk_t new), | ||
495 | void *callback_context) | ||
486 | { | 496 | { |
487 | int r, uninitialized_var(new_snapshot); | 497 | int r, uninitialized_var(new_snapshot); |
488 | struct pstore *ps = get_info(store); | 498 | struct pstore *ps = get_info(store); |
@@ -540,7 +550,7 @@ static int persistent_read_metadata(struct dm_exception_store *store) | |||
540 | /* | 550 | /* |
541 | * Read the metadata. | 551 | * Read the metadata. |
542 | */ | 552 | */ |
543 | r = read_exceptions(ps); | 553 | r = read_exceptions(ps, callback, callback_context); |
544 | if (r) | 554 | if (r) |
545 | return r; | 555 | return r; |
546 | } | 556 | } |
@@ -548,8 +558,8 @@ static int persistent_read_metadata(struct dm_exception_store *store) | |||
548 | return 0; | 558 | return 0; |
549 | } | 559 | } |
550 | 560 | ||
551 | static int persistent_prepare(struct dm_exception_store *store, | 561 | static int persistent_prepare_exception(struct dm_exception_store *store, |
552 | struct dm_snap_exception *e) | 562 | struct dm_snap_exception *e) |
553 | { | 563 | { |
554 | struct pstore *ps = get_info(store); | 564 | struct pstore *ps = get_info(store); |
555 | uint32_t stride; | 565 | uint32_t stride; |
@@ -575,10 +585,10 @@ static int persistent_prepare(struct dm_exception_store *store, | |||
575 | return 0; | 585 | return 0; |
576 | } | 586 | } |
577 | 587 | ||
578 | static void persistent_commit(struct dm_exception_store *store, | 588 | static void persistent_commit_exception(struct dm_exception_store *store, |
579 | struct dm_snap_exception *e, | 589 | struct dm_snap_exception *e, |
580 | void (*callback) (void *, int success), | 590 | void (*callback) (void *, int success), |
581 | void *callback_context) | 591 | void *callback_context) |
582 | { | 592 | { |
583 | unsigned int i; | 593 | unsigned int i; |
584 | struct pstore *ps = get_info(store); | 594 | struct pstore *ps = get_info(store); |
@@ -637,7 +647,7 @@ static void persistent_commit(struct dm_exception_store *store, | |||
637 | ps->callback_count = 0; | 647 | ps->callback_count = 0; |
638 | } | 648 | } |
639 | 649 | ||
640 | static void persistent_drop(struct dm_exception_store *store) | 650 | static void persistent_drop_snapshot(struct dm_exception_store *store) |
641 | { | 651 | { |
642 | struct pstore *ps = get_info(store); | 652 | struct pstore *ps = get_info(store); |
643 | 653 | ||
@@ -675,9 +685,9 @@ int dm_create_persistent(struct dm_exception_store *store) | |||
675 | 685 | ||
676 | store->destroy = persistent_destroy; | 686 | store->destroy = persistent_destroy; |
677 | store->read_metadata = persistent_read_metadata; | 687 | store->read_metadata = persistent_read_metadata; |
678 | store->prepare_exception = persistent_prepare; | 688 | store->prepare_exception = persistent_prepare_exception; |
679 | store->commit_exception = persistent_commit; | 689 | store->commit_exception = persistent_commit_exception; |
680 | store->drop_snapshot = persistent_drop; | 690 | store->drop_snapshot = persistent_drop_snapshot; |
681 | store->fraction_full = persistent_fraction_full; | 691 | store->fraction_full = persistent_fraction_full; |
682 | store->context = ps; | 692 | store->context = ps; |
683 | 693 | ||
diff --git a/drivers/md/dm-snap-transient.c b/drivers/md/dm-snap-transient.c index 2a781df57fef..7f6e2e6dcb0d 100644 --- a/drivers/md/dm-snap-transient.c +++ b/drivers/md/dm-snap-transient.c | |||
@@ -28,13 +28,16 @@ static void transient_destroy(struct dm_exception_store *store) | |||
28 | kfree(store->context); | 28 | kfree(store->context); |
29 | } | 29 | } |
30 | 30 | ||
31 | static int transient_read_metadata(struct dm_exception_store *store) | 31 | static int transient_read_metadata(struct dm_exception_store *store, |
32 | int (*callback)(void *callback_context, | ||
33 | chunk_t old, chunk_t new), | ||
34 | void *callback_context) | ||
32 | { | 35 | { |
33 | return 0; | 36 | return 0; |
34 | } | 37 | } |
35 | 38 | ||
36 | static int transient_prepare(struct dm_exception_store *store, | 39 | static int transient_prepare_exception(struct dm_exception_store *store, |
37 | struct dm_snap_exception *e) | 40 | struct dm_snap_exception *e) |
38 | { | 41 | { |
39 | struct transient_c *tc = (struct transient_c *) store->context; | 42 | struct transient_c *tc = (struct transient_c *) store->context; |
40 | sector_t size = get_dev_size(store->snap->cow->bdev); | 43 | sector_t size = get_dev_size(store->snap->cow->bdev); |
@@ -48,10 +51,10 @@ static int transient_prepare(struct dm_exception_store *store, | |||
48 | return 0; | 51 | return 0; |
49 | } | 52 | } |
50 | 53 | ||
51 | static void transient_commit(struct dm_exception_store *store, | 54 | static void transient_commit_exception(struct dm_exception_store *store, |
52 | struct dm_snap_exception *e, | 55 | struct dm_snap_exception *e, |
53 | void (*callback) (void *, int success), | 56 | void (*callback) (void *, int success), |
54 | void *callback_context) | 57 | void *callback_context) |
55 | { | 58 | { |
56 | /* Just succeed */ | 59 | /* Just succeed */ |
57 | callback(callback_context, 1); | 60 | callback(callback_context, 1); |
@@ -70,8 +73,8 @@ int dm_create_transient(struct dm_exception_store *store) | |||
70 | 73 | ||
71 | store->destroy = transient_destroy; | 74 | store->destroy = transient_destroy; |
72 | store->read_metadata = transient_read_metadata; | 75 | store->read_metadata = transient_read_metadata; |
73 | store->prepare_exception = transient_prepare; | 76 | store->prepare_exception = transient_prepare_exception; |
74 | store->commit_exception = transient_commit; | 77 | store->commit_exception = transient_commit_exception; |
75 | store->drop_snapshot = NULL; | 78 | store->drop_snapshot = NULL; |
76 | store->fraction_full = transient_fraction_full; | 79 | store->fraction_full = transient_fraction_full; |
77 | 80 | ||
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 018b567fc758..65ff82ff124e 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c | |||
@@ -430,8 +430,13 @@ out: | |||
430 | list_add(&new_e->hash_list, e ? &e->hash_list : l); | 430 | list_add(&new_e->hash_list, e ? &e->hash_list : l); |
431 | } | 431 | } |
432 | 432 | ||
433 | int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new) | 433 | /* |
434 | * Callback used by the exception stores to load exceptions when | ||
435 | * initialising. | ||
436 | */ | ||
437 | static int dm_add_exception(void *context, chunk_t old, chunk_t new) | ||
434 | { | 438 | { |
439 | struct dm_snapshot *s = context; | ||
435 | struct dm_snap_exception *e; | 440 | struct dm_snap_exception *e; |
436 | 441 | ||
437 | e = alloc_exception(); | 442 | e = alloc_exception(); |
@@ -660,7 +665,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
660 | spin_lock_init(&s->tracked_chunk_lock); | 665 | spin_lock_init(&s->tracked_chunk_lock); |
661 | 666 | ||
662 | /* Metadata must only be loaded into one table at once */ | 667 | /* Metadata must only be loaded into one table at once */ |
663 | r = s->store.read_metadata(&s->store); | 668 | r = s->store.read_metadata(&s->store, dm_add_exception, (void *)s); |
664 | if (r < 0) { | 669 | if (r < 0) { |
665 | ti->error = "Failed to read snapshot metadata"; | 670 | ti->error = "Failed to read snapshot metadata"; |
666 | goto bad_load_and_register; | 671 | goto bad_load_and_register; |
diff --git a/drivers/md/dm-snap.h b/drivers/md/dm-snap.h index 928123657024..d9e62b43cf85 100644 --- a/drivers/md/dm-snap.h +++ b/drivers/md/dm-snap.h | |||
@@ -76,12 +76,6 @@ struct dm_snapshot { | |||
76 | }; | 76 | }; |
77 | 77 | ||
78 | /* | 78 | /* |
79 | * Used by the exception stores to load exceptions hen | ||
80 | * initialising. | ||
81 | */ | ||
82 | int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new); | ||
83 | |||
84 | /* | ||
85 | * Return the number of sectors in the device. | 79 | * Return the number of sectors in the device. |
86 | */ | 80 | */ |
87 | static inline sector_t get_dev_size(struct block_device *bdev) | 81 | static inline sector_t get_dev_size(struct block_device *bdev) |