diff options
author | Jonathan Brassow <jbrassow@redhat.com> | 2009-04-02 14:55:30 -0400 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2009-04-02 14:55:30 -0400 |
commit | b2a114652940ccf7e9668ad447ca78bf16a31139 (patch) | |
tree | f86e851ff752a8ae5ce1b5571cde1918c86a156a /drivers/md | |
parent | ec44ab9d6681ddf9026b593e866bec9c0e075e1d (diff) |
dm exception store: separate type from instance
Introduce struct dm_exception_store_type.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-exception-store.h | 13 | ||||
-rw-r--r-- | drivers/md/dm-snap-persistent.c | 13 | ||||
-rw-r--r-- | drivers/md/dm-snap-transient.c | 14 | ||||
-rw-r--r-- | drivers/md/dm-snap.c | 20 |
4 files changed, 35 insertions, 25 deletions
diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index bb9f33d5daa2..aed1f1172f9e 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h | |||
@@ -37,11 +37,15 @@ struct dm_snap_exception { | |||
37 | * Abstraction to handle the meta/layout of exception stores (the | 37 | * Abstraction to handle the meta/layout of exception stores (the |
38 | * COW device). | 38 | * COW device). |
39 | */ | 39 | */ |
40 | struct dm_exception_store { | 40 | struct dm_exception_store; |
41 | struct dm_exception_store_type { | ||
42 | int (*ctr) (struct dm_exception_store *store, | ||
43 | unsigned argc, char **argv); | ||
44 | |||
41 | /* | 45 | /* |
42 | * Destroys this object when you've finished with it. | 46 | * Destroys this object when you've finished with it. |
43 | */ | 47 | */ |
44 | void (*destroy) (struct dm_exception_store *store); | 48 | void (*dtr) (struct dm_exception_store *store); |
45 | 49 | ||
46 | /* | 50 | /* |
47 | * The target shouldn't read the COW device until this is | 51 | * The target shouldn't read the COW device until this is |
@@ -81,8 +85,13 @@ struct dm_exception_store { | |||
81 | void (*fraction_full) (struct dm_exception_store *store, | 85 | void (*fraction_full) (struct dm_exception_store *store, |
82 | sector_t *numerator, | 86 | sector_t *numerator, |
83 | sector_t *denominator); | 87 | sector_t *denominator); |
88 | }; | ||
89 | |||
90 | struct dm_exception_store { | ||
91 | struct dm_exception_store_type type; | ||
84 | 92 | ||
85 | struct dm_snapshot *snap; | 93 | struct dm_snapshot *snap; |
94 | |||
86 | void *context; | 95 | void *context; |
87 | }; | 96 | }; |
88 | 97 | ||
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c index 936b34e0959f..0bbbe3b7431e 100644 --- a/drivers/md/dm-snap-persistent.c +++ b/drivers/md/dm-snap-persistent.c | |||
@@ -683,12 +683,13 @@ int dm_create_persistent(struct dm_exception_store *store) | |||
683 | return -ENOMEM; | 683 | return -ENOMEM; |
684 | } | 684 | } |
685 | 685 | ||
686 | store->destroy = persistent_destroy; | 686 | store->type.dtr = persistent_destroy; |
687 | store->read_metadata = persistent_read_metadata; | 687 | store->type.read_metadata = persistent_read_metadata; |
688 | store->prepare_exception = persistent_prepare_exception; | 688 | store->type.prepare_exception = persistent_prepare_exception; |
689 | store->commit_exception = persistent_commit_exception; | 689 | store->type.commit_exception = persistent_commit_exception; |
690 | store->drop_snapshot = persistent_drop_snapshot; | 690 | store->type.drop_snapshot = persistent_drop_snapshot; |
691 | store->fraction_full = persistent_fraction_full; | 691 | store->type.fraction_full = persistent_fraction_full; |
692 | |||
692 | store->context = ps; | 693 | store->context = ps; |
693 | 694 | ||
694 | return 0; | 695 | return 0; |
diff --git a/drivers/md/dm-snap-transient.c b/drivers/md/dm-snap-transient.c index 7f6e2e6dcb0d..b558176ff020 100644 --- a/drivers/md/dm-snap-transient.c +++ b/drivers/md/dm-snap-transient.c | |||
@@ -39,7 +39,7 @@ static int transient_read_metadata(struct dm_exception_store *store, | |||
39 | static int transient_prepare_exception(struct dm_exception_store *store, | 39 | static int transient_prepare_exception(struct dm_exception_store *store, |
40 | struct dm_snap_exception *e) | 40 | struct dm_snap_exception *e) |
41 | { | 41 | { |
42 | struct transient_c *tc = (struct transient_c *) store->context; | 42 | struct transient_c *tc = store->context; |
43 | sector_t size = get_dev_size(store->snap->cow->bdev); | 43 | sector_t size = get_dev_size(store->snap->cow->bdev); |
44 | 44 | ||
45 | if (size < (tc->next_free + store->snap->chunk_size)) | 45 | if (size < (tc->next_free + store->snap->chunk_size)) |
@@ -71,12 +71,12 @@ int dm_create_transient(struct dm_exception_store *store) | |||
71 | { | 71 | { |
72 | struct transient_c *tc; | 72 | struct transient_c *tc; |
73 | 73 | ||
74 | store->destroy = transient_destroy; | 74 | store->type.dtr = transient_destroy; |
75 | store->read_metadata = transient_read_metadata; | 75 | store->type.read_metadata = transient_read_metadata; |
76 | store->prepare_exception = transient_prepare_exception; | 76 | store->type.prepare_exception = transient_prepare_exception; |
77 | store->commit_exception = transient_commit_exception; | 77 | store->type.commit_exception = transient_commit_exception; |
78 | store->drop_snapshot = NULL; | 78 | store->type.drop_snapshot = NULL; |
79 | store->fraction_full = transient_fraction_full; | 79 | store->type.fraction_full = transient_fraction_full; |
80 | 80 | ||
81 | tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL); | 81 | tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL); |
82 | if (!tc) | 82 | if (!tc) |
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 462750c66319..dabd58e9aafc 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c | |||
@@ -665,7 +665,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
665 | spin_lock_init(&s->tracked_chunk_lock); | 665 | spin_lock_init(&s->tracked_chunk_lock); |
666 | 666 | ||
667 | /* Metadata must only be loaded into one table at once */ | 667 | /* Metadata must only be loaded into one table at once */ |
668 | r = s->store.read_metadata(&s->store, dm_add_exception, (void *)s); | 668 | r = s->store.type.read_metadata(&s->store, dm_add_exception, (void *)s); |
669 | if (r < 0) { | 669 | if (r < 0) { |
670 | ti->error = "Failed to read snapshot metadata"; | 670 | ti->error = "Failed to read snapshot metadata"; |
671 | goto bad_load_and_register; | 671 | goto bad_load_and_register; |
@@ -700,7 +700,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
700 | dm_kcopyd_client_destroy(s->kcopyd_client); | 700 | dm_kcopyd_client_destroy(s->kcopyd_client); |
701 | 701 | ||
702 | bad5: | 702 | bad5: |
703 | s->store.destroy(&s->store); | 703 | s->store.type.dtr(&s->store); |
704 | 704 | ||
705 | bad4: | 705 | bad4: |
706 | exit_exception_table(&s->pending, pending_cache); | 706 | exit_exception_table(&s->pending, pending_cache); |
@@ -725,7 +725,7 @@ static void __free_exceptions(struct dm_snapshot *s) | |||
725 | exit_exception_table(&s->pending, pending_cache); | 725 | exit_exception_table(&s->pending, pending_cache); |
726 | exit_exception_table(&s->complete, exception_cache); | 726 | exit_exception_table(&s->complete, exception_cache); |
727 | 727 | ||
728 | s->store.destroy(&s->store); | 728 | s->store.type.dtr(&s->store); |
729 | } | 729 | } |
730 | 730 | ||
731 | static void snapshot_dtr(struct dm_target *ti) | 731 | static void snapshot_dtr(struct dm_target *ti) |
@@ -820,8 +820,8 @@ static void __invalidate_snapshot(struct dm_snapshot *s, int err) | |||
820 | else if (err == -ENOMEM) | 820 | else if (err == -ENOMEM) |
821 | DMERR("Invalidating snapshot: Unable to allocate exception."); | 821 | DMERR("Invalidating snapshot: Unable to allocate exception."); |
822 | 822 | ||
823 | if (s->store.drop_snapshot) | 823 | if (s->store.type.drop_snapshot) |
824 | s->store.drop_snapshot(&s->store); | 824 | s->store.type.drop_snapshot(&s->store); |
825 | 825 | ||
826 | s->valid = 0; | 826 | s->valid = 0; |
827 | 827 | ||
@@ -943,8 +943,8 @@ static void copy_callback(int read_err, unsigned long write_err, void *context) | |||
943 | 943 | ||
944 | else | 944 | else |
945 | /* Update the metadata if we are persistent */ | 945 | /* Update the metadata if we are persistent */ |
946 | s->store.commit_exception(&s->store, &pe->e, commit_callback, | 946 | s->store.type.commit_exception(&s->store, &pe->e, |
947 | pe); | 947 | commit_callback, pe); |
948 | } | 948 | } |
949 | 949 | ||
950 | /* | 950 | /* |
@@ -1010,7 +1010,7 @@ __find_pending_exception(struct dm_snapshot *s, | |||
1010 | atomic_set(&pe->ref_count, 0); | 1010 | atomic_set(&pe->ref_count, 0); |
1011 | pe->started = 0; | 1011 | pe->started = 0; |
1012 | 1012 | ||
1013 | if (s->store.prepare_exception(&s->store, &pe->e)) { | 1013 | if (s->store.type.prepare_exception(&s->store, &pe->e)) { |
1014 | free_pending_exception(pe); | 1014 | free_pending_exception(pe); |
1015 | return NULL; | 1015 | return NULL; |
1016 | } | 1016 | } |
@@ -1149,9 +1149,9 @@ static int snapshot_status(struct dm_target *ti, status_type_t type, | |||
1149 | if (!snap->valid) | 1149 | if (!snap->valid) |
1150 | snprintf(result, maxlen, "Invalid"); | 1150 | snprintf(result, maxlen, "Invalid"); |
1151 | else { | 1151 | else { |
1152 | if (snap->store.fraction_full) { | 1152 | if (snap->store.type.fraction_full) { |
1153 | sector_t numerator, denominator; | 1153 | sector_t numerator, denominator; |
1154 | snap->store.fraction_full(&snap->store, | 1154 | snap->store.type.fraction_full(&snap->store, |
1155 | &numerator, | 1155 | &numerator, |
1156 | &denominator); | 1156 | &denominator); |
1157 | snprintf(result, maxlen, "%llu/%llu", | 1157 | snprintf(result, maxlen, "%llu/%llu", |