Commit b2a11465 authored by Jonathan Brassow's avatar Jonathan Brassow Committed by Alasdair G Kergon

dm exception store: separate type from instance

Introduce struct dm_exception_store_type.
Signed-off-by: default avatarJonathan Brassow <jbrassow@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent ec44ab9d
...@@ -37,11 +37,15 @@ struct dm_snap_exception { ...@@ -37,11 +37,15 @@ struct dm_snap_exception {
* Abstraction to handle the meta/layout of exception stores (the * Abstraction to handle the meta/layout of exception stores (the
* COW device). * COW device).
*/ */
struct dm_exception_store { struct dm_exception_store;
struct dm_exception_store_type {
int (*ctr) (struct dm_exception_store *store,
unsigned argc, char **argv);
/* /*
* Destroys this object when you've finished with it. * Destroys this object when you've finished with it.
*/ */
void (*destroy) (struct dm_exception_store *store); void (*dtr) (struct dm_exception_store *store);
/* /*
* The target shouldn't read the COW device until this is * The target shouldn't read the COW device until this is
...@@ -81,8 +85,13 @@ struct dm_exception_store { ...@@ -81,8 +85,13 @@ struct dm_exception_store {
void (*fraction_full) (struct dm_exception_store *store, void (*fraction_full) (struct dm_exception_store *store,
sector_t *numerator, sector_t *numerator,
sector_t *denominator); sector_t *denominator);
};
struct dm_exception_store {
struct dm_exception_store_type type;
struct dm_snapshot *snap; struct dm_snapshot *snap;
void *context; void *context;
}; };
......
...@@ -683,12 +683,13 @@ int dm_create_persistent(struct dm_exception_store *store) ...@@ -683,12 +683,13 @@ int dm_create_persistent(struct dm_exception_store *store)
return -ENOMEM; return -ENOMEM;
} }
store->destroy = persistent_destroy; store->type.dtr = persistent_destroy;
store->read_metadata = persistent_read_metadata; store->type.read_metadata = persistent_read_metadata;
store->prepare_exception = persistent_prepare_exception; store->type.prepare_exception = persistent_prepare_exception;
store->commit_exception = persistent_commit_exception; store->type.commit_exception = persistent_commit_exception;
store->drop_snapshot = persistent_drop_snapshot; store->type.drop_snapshot = persistent_drop_snapshot;
store->fraction_full = persistent_fraction_full; store->type.fraction_full = persistent_fraction_full;
store->context = ps; store->context = ps;
return 0; return 0;
......
...@@ -39,7 +39,7 @@ static int transient_read_metadata(struct dm_exception_store *store, ...@@ -39,7 +39,7 @@ static int transient_read_metadata(struct dm_exception_store *store,
static int transient_prepare_exception(struct dm_exception_store *store, static int transient_prepare_exception(struct dm_exception_store *store,
struct dm_snap_exception *e) struct dm_snap_exception *e)
{ {
struct transient_c *tc = (struct transient_c *) store->context; struct transient_c *tc = store->context;
sector_t size = get_dev_size(store->snap->cow->bdev); sector_t size = get_dev_size(store->snap->cow->bdev);
if (size < (tc->next_free + store->snap->chunk_size)) if (size < (tc->next_free + store->snap->chunk_size))
...@@ -71,12 +71,12 @@ int dm_create_transient(struct dm_exception_store *store) ...@@ -71,12 +71,12 @@ int dm_create_transient(struct dm_exception_store *store)
{ {
struct transient_c *tc; struct transient_c *tc;
store->destroy = transient_destroy; store->type.dtr = transient_destroy;
store->read_metadata = transient_read_metadata; store->type.read_metadata = transient_read_metadata;
store->prepare_exception = transient_prepare_exception; store->type.prepare_exception = transient_prepare_exception;
store->commit_exception = transient_commit_exception; store->type.commit_exception = transient_commit_exception;
store->drop_snapshot = NULL; store->type.drop_snapshot = NULL;
store->fraction_full = transient_fraction_full; store->type.fraction_full = transient_fraction_full;
tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL); tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL);
if (!tc) if (!tc)
......
...@@ -665,7 +665,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -665,7 +665,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
spin_lock_init(&s->tracked_chunk_lock); spin_lock_init(&s->tracked_chunk_lock);
/* Metadata must only be loaded into one table at once */ /* Metadata must only be loaded into one table at once */
r = s->store.read_metadata(&s->store, dm_add_exception, (void *)s); r = s->store.type.read_metadata(&s->store, dm_add_exception, (void *)s);
if (r < 0) { if (r < 0) {
ti->error = "Failed to read snapshot metadata"; ti->error = "Failed to read snapshot metadata";
goto bad_load_and_register; goto bad_load_and_register;
...@@ -700,7 +700,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -700,7 +700,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
dm_kcopyd_client_destroy(s->kcopyd_client); dm_kcopyd_client_destroy(s->kcopyd_client);
bad5: bad5:
s->store.destroy(&s->store); s->store.type.dtr(&s->store);
bad4: bad4:
exit_exception_table(&s->pending, pending_cache); exit_exception_table(&s->pending, pending_cache);
...@@ -725,7 +725,7 @@ static void __free_exceptions(struct dm_snapshot *s) ...@@ -725,7 +725,7 @@ static void __free_exceptions(struct dm_snapshot *s)
exit_exception_table(&s->pending, pending_cache); exit_exception_table(&s->pending, pending_cache);
exit_exception_table(&s->complete, exception_cache); exit_exception_table(&s->complete, exception_cache);
s->store.destroy(&s->store); s->store.type.dtr(&s->store);
} }
static void snapshot_dtr(struct dm_target *ti) static void snapshot_dtr(struct dm_target *ti)
...@@ -820,8 +820,8 @@ static void __invalidate_snapshot(struct dm_snapshot *s, int err) ...@@ -820,8 +820,8 @@ static void __invalidate_snapshot(struct dm_snapshot *s, int err)
else if (err == -ENOMEM) else if (err == -ENOMEM)
DMERR("Invalidating snapshot: Unable to allocate exception."); DMERR("Invalidating snapshot: Unable to allocate exception.");
if (s->store.drop_snapshot) if (s->store.type.drop_snapshot)
s->store.drop_snapshot(&s->store); s->store.type.drop_snapshot(&s->store);
s->valid = 0; s->valid = 0;
...@@ -943,8 +943,8 @@ static void copy_callback(int read_err, unsigned long write_err, void *context) ...@@ -943,8 +943,8 @@ static void copy_callback(int read_err, unsigned long write_err, void *context)
else else
/* Update the metadata if we are persistent */ /* Update the metadata if we are persistent */
s->store.commit_exception(&s->store, &pe->e, commit_callback, s->store.type.commit_exception(&s->store, &pe->e,
pe); commit_callback, pe);
} }
/* /*
...@@ -1010,7 +1010,7 @@ __find_pending_exception(struct dm_snapshot *s, ...@@ -1010,7 +1010,7 @@ __find_pending_exception(struct dm_snapshot *s,
atomic_set(&pe->ref_count, 0); atomic_set(&pe->ref_count, 0);
pe->started = 0; pe->started = 0;
if (s->store.prepare_exception(&s->store, &pe->e)) { if (s->store.type.prepare_exception(&s->store, &pe->e)) {
free_pending_exception(pe); free_pending_exception(pe);
return NULL; return NULL;
} }
...@@ -1149,9 +1149,9 @@ static int snapshot_status(struct dm_target *ti, status_type_t type, ...@@ -1149,9 +1149,9 @@ static int snapshot_status(struct dm_target *ti, status_type_t type,
if (!snap->valid) if (!snap->valid)
snprintf(result, maxlen, "Invalid"); snprintf(result, maxlen, "Invalid");
else { else {
if (snap->store.fraction_full) { if (snap->store.type.fraction_full) {
sector_t numerator, denominator; sector_t numerator, denominator;
snap->store.fraction_full(&snap->store, snap->store.type.fraction_full(&snap->store,
&numerator, &numerator,
&denominator); &denominator);
snprintf(result, maxlen, "%llu/%llu", snprintf(result, maxlen, "%llu/%llu",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment