diff options
| author | Joe Thornber <thornber@redhat.com> | 2011-10-31 16:19:11 -0400 |
|---|---|---|
| committer | Alasdair G Kergon <agk@redhat.com> | 2011-10-31 16:19:11 -0400 |
| commit | 3241b1d3e0aaafbfcd320f4d71ade629728cc4f4 (patch) | |
| tree | 499461f724d4db3d7118641f4a20f5be23549edd | |
| parent | 95d402f057f2e208e4631893f6cd4a59c7c05e41 (diff) | |
dm: add persistent data library
The persistent-data library offers a re-usable framework for the storage
and management of on-disk metadata in device-mapper targets.
It's used by the thin-provisioning target in the next patch and in an
upcoming hierarchical storage target.
For further information, please read
Documentation/device-mapper/persistent-data.txt
Signed-off-by: Joe Thornber <thornber@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
22 files changed, 5709 insertions, 0 deletions
diff --git a/Documentation/device-mapper/persistent-data.txt b/Documentation/device-mapper/persistent-data.txt new file mode 100644 index 000000000000..0e5df9b04ad2 --- /dev/null +++ b/Documentation/device-mapper/persistent-data.txt | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | Introduction | ||
| 2 | ============ | ||
| 3 | |||
| 4 | The more-sophisticated device-mapper targets require complex metadata | ||
| 5 | that is managed in kernel. In late 2010 we were seeing that various | ||
| 6 | different targets were rolling their own data strutures, for example: | ||
| 7 | |||
| 8 | - Mikulas Patocka's multisnap implementation | ||
| 9 | - Heinz Mauelshagen's thin provisioning target | ||
| 10 | - Another btree-based caching target posted to dm-devel | ||
| 11 | - Another multi-snapshot target based on a design of Daniel Phillips | ||
| 12 | |||
| 13 | Maintaining these data structures takes a lot of work, so if possible | ||
| 14 | we'd like to reduce the number. | ||
| 15 | |||
| 16 | The persistent-data library is an attempt to provide a re-usable | ||
| 17 | framework for people who want to store metadata in device-mapper | ||
| 18 | targets. It's currently used by the thin-provisioning target and an | ||
| 19 | upcoming hierarchical storage target. | ||
| 20 | |||
| 21 | Overview | ||
| 22 | ======== | ||
| 23 | |||
| 24 | The main documentation is in the header files which can all be found | ||
| 25 | under drivers/md/persistent-data. | ||
| 26 | |||
| 27 | The block manager | ||
| 28 | ----------------- | ||
| 29 | |||
| 30 | dm-block-manager.[hc] | ||
| 31 | |||
| 32 | This provides access to the data on disk in fixed sized-blocks. There | ||
| 33 | is a read/write locking interface to prevent concurrent accesses, and | ||
| 34 | keep data that is being used in the cache. | ||
| 35 | |||
| 36 | Clients of persistent-data are unlikely to use this directly. | ||
| 37 | |||
| 38 | The transaction manager | ||
| 39 | ----------------------- | ||
| 40 | |||
| 41 | dm-transaction-manager.[hc] | ||
| 42 | |||
| 43 | This restricts access to blocks and enforces copy-on-write semantics. | ||
| 44 | The only way you can get hold of a writable block through the | ||
| 45 | transaction manager is by shadowing an existing block (ie. doing | ||
| 46 | copy-on-write) or allocating a fresh one. Shadowing is elided within | ||
| 47 | the same transaction so performance is reasonable. The commit method | ||
| 48 | ensures that all data is flushed before it writes the superblock. | ||
| 49 | On power failure your metadata will be as it was when last committed. | ||
| 50 | |||
| 51 | The Space Maps | ||
| 52 | -------------- | ||
| 53 | |||
| 54 | dm-space-map.h | ||
| 55 | dm-space-map-metadata.[hc] | ||
| 56 | dm-space-map-disk.[hc] | ||
| 57 | |||
| 58 | On-disk data structures that keep track of reference counts of blocks. | ||
| 59 | Also acts as the allocator of new blocks. Currently two | ||
| 60 | implementations: a simpler one for managing blocks on a different | ||
| 61 | device (eg. thinly-provisioned data blocks); and one for managing | ||
| 62 | the metadata space. The latter is complicated by the need to store | ||
| 63 | its own data within the space it's managing. | ||
| 64 | |||
| 65 | The data structures | ||
| 66 | ------------------- | ||
| 67 | |||
| 68 | dm-btree.[hc] | ||
| 69 | dm-btree-remove.c | ||
| 70 | dm-btree-spine.c | ||
| 71 | dm-btree-internal.h | ||
| 72 | |||
| 73 | Currently there is only one data structure, a hierarchical btree. | ||
| 74 | There are plans to add more. For example, something with an | ||
| 75 | array-like interface would see a lot of use. | ||
| 76 | |||
| 77 | The btree is 'hierarchical' in that you can define it to be composed | ||
| 78 | of nested btrees, and take multiple keys. For example, the | ||
| 79 | thin-provisioning target uses a btree with two levels of nesting. | ||
| 80 | The first maps a device id to a mapping tree, and that in turn maps a | ||
| 81 | virtual block to a physical block. | ||
| 82 | |||
| 83 | Values stored in the btrees can have arbitrary size. Keys are always | ||
| 84 | 64bits, although nesting allows you to use multiple keys. | ||
diff --git a/drivers/md/persistent-data/Kconfig b/drivers/md/persistent-data/Kconfig new file mode 100644 index 000000000000..ceb359050a59 --- /dev/null +++ b/drivers/md/persistent-data/Kconfig | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | config DM_PERSISTENT_DATA | ||
| 2 | tristate | ||
| 3 | depends on BLK_DEV_DM && EXPERIMENTAL | ||
| 4 | select LIBCRC32C | ||
| 5 | select DM_BUFIO | ||
| 6 | ---help--- | ||
| 7 | Library providing immutable on-disk data structure support for | ||
| 8 | device-mapper targets such as the thin provisioning target. | ||
diff --git a/drivers/md/persistent-data/Makefile b/drivers/md/persistent-data/Makefile new file mode 100644 index 000000000000..cfa95f662230 --- /dev/null +++ b/drivers/md/persistent-data/Makefile | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | obj-$(CONFIG_DM_PERSISTENT_DATA) += dm-persistent-data.o | ||
| 2 | dm-persistent-data-objs := \ | ||
| 3 | dm-block-manager.o \ | ||
| 4 | dm-space-map-checker.o \ | ||
| 5 | dm-space-map-common.o \ | ||
| 6 | dm-space-map-disk.o \ | ||
| 7 | dm-space-map-metadata.o \ | ||
| 8 | dm-transaction-manager.o \ | ||
| 9 | dm-btree.o \ | ||
| 10 | dm-btree-remove.o \ | ||
| 11 | dm-btree-spine.o | ||
diff --git a/drivers/md/persistent-data/dm-block-manager.c b/drivers/md/persistent-data/dm-block-manager.c new file mode 100644 index 000000000000..0317ecdc6e53 --- /dev/null +++ b/drivers/md/persistent-data/dm-block-manager.c | |||
| @@ -0,0 +1,620 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2011 Red Hat, Inc. | ||
| 3 | * | ||
| 4 | * This file is released under the GPL. | ||
| 5 | */ | ||
| 6 | #include "dm-block-manager.h" | ||
| 7 | #include "dm-persistent-data-internal.h" | ||
| 8 | #include "../dm-bufio.h" | ||
| 9 | |||
| 10 | #include <linux/crc32c.h> | ||
| 11 | #include <linux/module.h> | ||
| 12 | #include <linux/slab.h> | ||
| 13 | #include <linux/rwsem.h> | ||
| 14 | #include <linux/device-mapper.h> | ||
| 15 | #include <linux/stacktrace.h> | ||
| 16 | |||
| 17 | #define DM_MSG_PREFIX "block manager" | ||
| 18 | |||
| 19 | /*----------------------------------------------------------------*/ | ||
| 20 | |||
| 21 | /* | ||
| 22 | * This is a read/write semaphore with a couple of differences. | ||
| 23 | * | ||
| 24 | * i) There is a restriction on the number of concurrent read locks that | ||
| 25 | * may be held at once. This is just an implementation detail. | ||
| 26 | * | ||
| 27 | * ii) Recursive locking attempts are detected and return EINVAL. A stack | ||
| 28 | * trace is also emitted for the previous lock aquisition. | ||
| 29 | * | ||
| 30 | * iii) Priority is given to write locks. | ||
| 31 | */ | ||
| 32 | #define MAX_HOLDERS 4 | ||
| 33 | #define MAX_STACK 10 | ||
| 34 | |||
| 35 | typedef unsigned long stack_entries[MAX_STACK]; | ||
| 36 | |||
| 37 | struct block_lock { | ||
| 38 | spinlock_t lock; | ||
| 39 | __s32 count; | ||
| 40 | struct list_head waiters; | ||
| 41 | struct task_struct *holders[MAX_HOLDERS]; | ||
| 42 | |||
| 43 | #ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING | ||
| 44 | struct stack_trace traces[MAX_HOLDERS]; | ||
| 45 | stack_entries entries[MAX_HOLDERS]; | ||
| 46 | #endif | ||
| 47 | }; | ||
| 48 | |||
| 49 | struct waiter { | ||
| 50 | struct list_head list; | ||
| 51 | struct task_struct *task; | ||
| 52 | int wants_write; | ||
| 53 | }; | ||
| 54 | |||
| 55 | static unsigned __find_holder(struct block_lock *lock, | ||
| 56 | struct task_struct *task) | ||
| 57 | { | ||
| 58 | |||
