From b2a114652940ccf7e9668ad447ca78bf16a31139 Mon Sep 17 00:00:00 2001 From: Jonathan Brassow Date: Thu, 2 Apr 2009 19:55:30 +0100 Subject: dm exception store: separate type from instance Introduce struct dm_exception_store_type. Signed-off-by: Jonathan Brassow Signed-off-by: Alasdair G Kergon --- drivers/md/dm-exception-store.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'drivers/md/dm-exception-store.h') diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index bb9f33d5daa..aed1f1172f9 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h @@ -37,11 +37,15 @@ struct dm_snap_exception { * Abstraction to handle the meta/layout of exception stores (the * 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. */ - 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 @@ -81,8 +85,13 @@ struct dm_exception_store { void (*fraction_full) (struct dm_exception_store *store, sector_t *numerator, sector_t *denominator); +}; + +struct dm_exception_store { + struct dm_exception_store_type type; struct dm_snapshot *snap; + void *context; }; -- cgit v1.2.3 From 493df71c6420b211a68ae82b889c1e8a5fe701be Mon Sep 17 00:00:00 2001 From: Jonathan Brassow Date: Thu, 2 Apr 2009 19:55:31 +0100 Subject: dm exception store: introduce registry Move exception stores into a registry. Signed-off-by: Jonathan Brassow Signed-off-by: Alasdair G Kergon --- drivers/md/dm-exception-store.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'drivers/md/dm-exception-store.h') diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index aed1f1172f9..31377150080 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h @@ -39,6 +39,9 @@ struct dm_snap_exception { */ struct dm_exception_store; struct dm_exception_store_type { + const char *name; + struct module *module; + int (*ctr) (struct dm_exception_store *store, unsigned argc, char **argv); @@ -85,10 +88,13 @@ struct dm_exception_store_type { void (*fraction_full) (struct dm_exception_store *store, sector_t *numerator, sector_t *denominator); + + /* For internal device-mapper use only. */ + struct list_head list; }; struct dm_exception_store { - struct dm_exception_store_type type; + struct dm_exception_store_type *type; struct dm_snapshot *snap; @@ -138,6 +144,13 @@ static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e) # endif +int dm_exception_store_type_register(struct dm_exception_store_type *type); +int dm_exception_store_type_unregister(struct dm_exception_store_type *type); + +int dm_exception_store_create(const char *type_name, + struct dm_exception_store **store); +void dm_exception_store_destroy(struct dm_exception_store *store); + int dm_exception_store_init(void); void dm_exception_store_exit(void); @@ -150,8 +163,4 @@ void dm_persistent_snapshot_exit(void); int dm_transient_snapshot_init(void); void dm_transient_snapshot_exit(void); -int dm_create_persistent(struct dm_exception_store *store); - -int dm_create_transient(struct dm_exception_store *store); - #endif /* _LINUX_DM_EXCEPTION_STORE */ -- cgit v1.2.3 From 0cea9c78270cdf1d2ad74ce0e083d5555a0842e8 Mon Sep 17 00:00:00 2001 From: Jonathan Brassow Date: Thu, 2 Apr 2009 19:55:32 +0100 Subject: dm exception store: move dm_target pointer Move target pointer from snapshot to exception store. Signed-off-by: Jonathan Brassow Signed-off-by: Alasdair G Kergon --- drivers/md/dm-exception-store.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/md/dm-exception-store.h') diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index 31377150080..4b7f7d441f5 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h @@ -95,6 +95,7 @@ struct dm_exception_store_type { struct dm_exception_store { struct dm_exception_store_type *type; + struct dm_target *ti; struct dm_snapshot *snap; @@ -147,7 +148,7 @@ static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e) int dm_exception_store_type_register(struct dm_exception_store_type *type); int dm_exception_store_type_unregister(struct dm_exception_store_type *type); -int dm_exception_store_create(const char *type_name, +int dm_exception_store_create(const char *type_name, struct dm_target *ti, struct dm_exception_store **store); void dm_exception_store_destroy(struct dm_exception_store *store); -- cgit v1.2.3 From d0216849519bec8dc96301a3cd80316e71243839 Mon Sep 17 00:00:00 2001 From: Jonathan Brassow Date: Thu, 2 Apr 2009 19:55:32 +0100 Subject: dm exception store: move chunk_fields Move chunk fields from snapshot to exception store. Signed-off-by: Jonathan Brassow Signed-off-by: Alasdair G Kergon --- drivers/md/dm-exception-store.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/md/dm-exception-store.h') diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index 4b7f7d441f5..449a1e48f7a 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h @@ -99,6 +99,11 @@ struct dm_exception_store { struct dm_snapshot *snap; + /* Size of data blocks saved - must be a power of 2 */ + chunk_t chunk_size; + chunk_t chunk_mask; + chunk_t chunk_shift; + void *context; }; @@ -149,6 +154,8 @@ int dm_exception_store_type_register(struct dm_exception_store_type *type); int dm_exception_store_type_unregister(struct dm_exception_store_type *type); int dm_exception_store_create(const char *type_name, struct dm_target *ti, + chunk_t chunk_size, chunk_t chunk_mask, + chunk_t chunk_shift, struct dm_exception_store **store); void dm_exception_store_destroy(struct dm_exception_store *store); -- cgit v1.2.3 From 49beb2b87a972a994ff77633234ca3bf0d30a1d8 Mon Sep 17 00:00:00 2001 From: Jonathan Brassow Date: Thu, 2 Apr 2009 19:55:33 +0100 Subject: dm exception store: move cow pointer Move COW device from snapshot to exception store. Signed-off-by: Jonathan Brassow Signed-off-by: Alasdair G Kergon --- drivers/md/dm-exception-store.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/md/dm-exception-store.h') diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index 449a1e48f7a..4dbf3577408 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h @@ -99,6 +99,8 @@ struct dm_exception_store { struct dm_snapshot *snap; + struct dm_dev *cow; + /* Size of data blocks saved - must be a power of 2 */ chunk_t chunk_size; chunk_t chunk_mask; @@ -155,7 +157,7 @@ int dm_exception_store_type_unregister(struct dm_exception_store_type *type); int dm_exception_store_create(const char *type_name, struct dm_target *ti, chunk_t chunk_size, chunk_t chunk_mask, - chunk_t chunk_shift, + chunk_t chunk_shift, struct dm_dev *cow, struct dm_exception_store **store); void dm_exception_store_destroy(struct dm_exception_store *store); -- cgit v1.2.3 From 71fab00a6bef7fb53119271a8abdbaf40970d28a Mon Sep 17 00:00:00 2001 From: Jonathan Brassow Date: Thu, 2 Apr 2009 19:55:33 +0100 Subject: dm snapshot: remove dm_snap header use Move useful functions out of dm-snap.h and stop using dm-snap.h. Signed-off-by: Jonathan Brassow Signed-off-by: Alasdair G Kergon --- drivers/md/dm-exception-store.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'drivers/md/dm-exception-store.h') diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index 4dbf3577408..835f402d947 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h @@ -97,8 +97,6 @@ struct dm_exception_store { struct dm_exception_store_type *type; struct dm_target *ti; - struct dm_snapshot *snap; - struct dm_dev *cow; /* Size of data blocks saved - must be a power of 2 */ @@ -152,6 +150,20 @@ static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e) # endif +/* + * Return the number of sectors in the device. + */ +static inline sector_t get_dev_size(struct block_device *bdev) +{ + return bdev->bd_inode->i_size >> SECTOR_SHIFT; +} + +static inline chunk_t sector_to_chunk(struct dm_exception_store *store, + sector_t sector) +{ + return (sector & ~store->chunk_mask) >> store->chunk_shift; +} + int dm_exception_store_type_register(struct dm_exception_store_type *type); int dm_exception_store_type_unregister(struct dm_exception_store_type *type); -- cgit v1.2.3 From fee1998e9c690f9920671e1e0ef187a48cfbbde4 Mon Sep 17 00:00:00 2001 From: Jonathan Brassow Date: Thu, 2 Apr 2009 19:55:34 +0100 Subject: dm snapshot: move ctr parsing to exception store First step of having the exception stores parse their own arguments - generalizing the interface. Signed-off-by: Jonathan Brassow Signed-off-by: Alasdair G Kergon --- drivers/md/dm-exception-store.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/md/dm-exception-store.h') diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index 835f402d947..023a707503c 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h @@ -167,9 +167,8 @@ static inline chunk_t sector_to_chunk(struct dm_exception_store *store, int dm_exception_store_type_register(struct dm_exception_store_type *type); int dm_exception_store_type_unregister(struct dm_exception_store_type *type); -int dm_exception_store_create(const char *type_name, struct dm_target *ti, - chunk_t chunk_size, chunk_t chunk_mask, - chunk_t chunk_shift, struct dm_dev *cow, +int dm_exception_store_create(struct dm_target *ti, int argc, char **argv, + unsigned *args_used, struct dm_exception_store **store); void dm_exception_store_destroy(struct dm_exception_store *store); -- cgit v1.2.3 From 1e302a929e2da6e8448e2058e4b07b07252b57fe Mon Sep 17 00:00:00 2001 From: Jonathan Brassow Date: Thu, 2 Apr 2009 19:55:35 +0100 Subject: dm snapshot: move status to exception store Let the exception store types print out their status through the new API, rather than having the snapshot code do it. Adjust the buffer position to allow for the preceding DMEMIT in the arguments to type->status(). Signed-off-by: Jonathan Brassow Signed-off-by: Alasdair G Kergon --- drivers/md/dm-exception-store.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/md/dm-exception-store.h') diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index 023a707503c..0a2e6e7f67b 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h @@ -79,8 +79,9 @@ struct dm_exception_store_type { */ void (*drop_snapshot) (struct dm_exception_store *store); - int (*status) (struct dm_exception_store *store, status_type_t status, - char *result, unsigned int maxlen); + unsigned (*status) (struct dm_exception_store *store, + status_type_t status, char *result, + unsigned maxlen); /* * Return how full the snapshot is. -- cgit v1.2.3