Skip to contentSkip to conversation

dm-exception-store API

PATCH New Jonathan Brassow 1 participant 1 message Nov 13, 2008 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm-exception-store API

brassow

This patch completes the clean break we wanted between snapshots and exception stores. Now it is possible to create exception store modules and be able to use them without having to alter the snapshot code. There are currently two types of exception stores, but more have been proposed - including a 'shared' exception store.

Additionally, the constructor table has been enhanced to allow more flexibility in the arguments passed to the exception stores, as well as providing an easy path to further expand options in the future. This was done while maintaining backwards compatibility.

drivers/md/dm-exception-store.h +49 -16
Index: linux-2.6/drivers/md/dm-exception-store.h
===================================================================
@@ -10,6 +10,7 @@
 #define _LINUX_DM_EXCEPTION_STORE
 
 #include <linux/blkdev.h>
+#include <linux/device-mapper.h>
 
 /*
  * The snapshot code deals with largish chunks of the disk at a
@@ -31,23 +32,37 @@ struct dm_snap_exception {
 	chunk_t new_chunk;
 };
 
-/*
- * Abstraction to handle the meta/layout of exception stores (the
- * COW device).
- */
+struct dm_exception_store_type;
 struct dm_exception_store {
+	struct dm_exception_store_type *type;
+	struct dm_target *ti;
 
-	/*
-	 * Destroys this object when you've finished with it.
-	 */
-	void (*destroy) (struct dm_exception_store *store);
+	struct dm_dev *cow;
+
+	/* 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;
+};
+
+struct dm_exception_store_type {
+	const char *name;
+	struct module *module;
+
+	int (*ctr) (struct dm_exception_store *store,
+		    unsigned argc, char **argv);
+	void (*dtr) (struct dm_exception_store *store);
 
 	/*
 	 * The target shouldn't read the COW device until this is
-	 * called.
+	 * called.  As exceptions are read from the COW, they are
+	 * reported back via the callback.
 	 */
-	int (*read_metadata) (struct dm_exception_store *store);
-
+	int (*read_metadata) (struct dm_exception_store *store,
+			      int (*callback)(void *, chunk_t old, chunk_t new),
+			      void *callback_context);
 	/*
 	 * Find somewhere to store the next exception.
 	 */
@@ -74,8 +89,8 @@ struct dm_exception_store {
 			       sector_t *numerator,
 			       sector_t *denominator);
 
-	struct dm_snapshot *snap;
-	void *context;
+	int (*status) (struct dm_exception_store *store, status_type_t status,
+		       char *result, unsigned int maxlen);
 };
 
 /*
@@ -122,10 +137,28 @@ static inline void dm_consecutive_chunk_
 #  endif
 
 /*
- * Constructor and destructor for the exception stores
+ * Return the number of sectors in the device.
  */
-int dm_create_persistent(struct dm_exception_store *store);
+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);
+
+int dm_exception_store_create(const char *type_name, struct dm_target *ti,
+			      unsigned argc, char **argv,
+			      struct dm_exception_store **store);
+void dm_exception_store_destroy(struct dm_exception_store *store);
 
-int dm_create_transient(struct dm_exception_store *store);
+int dm_exception_store_init(void);
+void dm_exception_store_exit(void);
 
 #endif /* _LINUX_DM_EXCEPTION_STORE */
drivers/md/dm-exception-store.c +592 -102

894 lines not on this page · raw message

drivers/md/dm-snap.c +195 -137

569 lines not on this page · raw message

drivers/md/dm-snap.h deleted +0 -112

112 lines not on this page · raw message