diff options
| -rw-r--r-- | drivers/md/dm-exception-store.c | 1 | ||||
| -rw-r--r-- | drivers/md/dm-exception-store.h | 131 | ||||
| -rw-r--r-- | drivers/md/dm-snap.c | 1 | ||||
| -rw-r--r-- | drivers/md/dm-snap.h | 121 |
4 files changed, 134 insertions, 120 deletions
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c index 01590f3e0009..ef152e600cb6 100644 --- a/drivers/md/dm-exception-store.c +++ b/drivers/md/dm-exception-store.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | * This file is released under the GPL. | 7 | * This file is released under the GPL. |
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | #include "dm-exception-store.h" | ||
| 10 | #include "dm-snap.h" | 11 | #include "dm-snap.h" |
| 11 | 12 | ||
| 12 | #include <linux/mm.h> | 13 | #include <linux/mm.h> |
diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h new file mode 100644 index 000000000000..d75f775562e5 --- /dev/null +++ b/drivers/md/dm-exception-store.h | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2001-2002 Sistina Software (UK) Limited. | ||
| 3 | * Copyright (C) 2008 Red Hat, Inc. All rights reserved. | ||
| 4 | * | ||
| 5 | * Device-mapper snapshot exception store. | ||
| 6 | * | ||
| 7 | * This file is released under the GPL. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #ifndef _LINUX_DM_EXCEPTION_STORE | ||
| 11 | #define _LINUX_DM_EXCEPTION_STORE | ||
| 12 | |||
| 13 | #include <linux/blkdev.h> | ||
| 14 | |||
| 15 | /* | ||
| 16 | * The snapshot code deals with largish chunks of the disk at a | ||
| 17 | * time. Typically 32k - 512k. | ||
| 18 | */ | ||
| 19 | typedef sector_t chunk_t; | ||
| 20 | |||
| 21 | /* | ||
| 22 | * An exception is used where an old chunk of data has been | ||
| 23 | * replaced by a new one. | ||
| 24 | * If chunk_t is 64 bits in size, the top 8 bits of new_chunk hold the number | ||
| 25 | * of chunks that follow contiguously. Remaining bits hold the number of the | ||
| 26 | * chunk within the device. | ||
| 27 | */ | ||
| 28 | struct dm_snap_exception { | ||
| 29 | struct list_head hash_list; | ||
| 30 | |||
| 31 | chunk_t old_chunk; | ||
| 32 | chunk_t new_chunk; | ||
| 33 | }; | ||
| 34 | |||
| 35 | /* | ||
| 36 | * Abstraction to handle the meta/layout of exception stores (the | ||
| 37 | * COW device). | ||
| 38 | */ | ||
| 39 | struct exception_store { | ||
| 40 | /* | ||
| 41 | * Destroys this object when you've finished with it. | ||
| 42 | */ | ||
| 43 | void (*destroy) (struct exception_store *store); | ||
| 44 | |||
| 45 | /* | ||
| 46 | * The target shouldn't read the COW device until this is | ||
| 47 | * called. | ||
| 48 | */ | ||
| 49 | int (*read_metadata) (struct exception_store *store); | ||
| 50 | |||
| 51 | /* | ||
| 52 | * Find somewhere to store the next exception. | ||
| 53 | */ | ||
| 54 | int (*prepare_exception) (struct exception_store *store, | ||
| 55 | struct dm_snap_exception *e); | ||
| 56 | |||
| 57 | /* | ||
| 58 | * Update the metadata with this exception. | ||
| 59 | */ | ||
| 60 | void (*commit_exception) (struct exception_store *store, | ||
| 61 | struct dm_snap_exception *e, | ||
| 62 | void (*callback) (void *, int success), | ||
| 63 | void *callback_context); | ||
| 64 | |||
| 65 | /* | ||
| 66 | * The snapshot is invalid, note this in the metadata. | ||
| 67 | */ | ||
| 68 | void (*drop_snapshot) (struct exception_store *store); | ||
| 69 | |||
| 70 | /* | ||
| 71 | * Return how full the snapshot is. | ||
| 72 | */ | ||
| 73 | void (*fraction_full) (struct exception_store *store, | ||
| 74 | sector_t *numerator, | ||
| 75 | sector_t *denominator); | ||
| 76 | |||
| 77 | struct dm_snapshot *snap; | ||
| 78 | void *context; | ||
| 79 | }; | ||
| 80 | |||
| 81 | /* | ||
| 82 | * Funtions to manipulate consecutive chunks | ||
| 83 | */ | ||
| 84 | # if defined(CONFIG_LBD) || (BITS_PER_LONG == 64) | ||
| 85 | # define DM_CHUNK_CONSECUTIVE_BITS 8 | ||
| 86 | # define DM_CHUNK_NUMBER_BITS 56 | ||
| 87 | |||
| 88 | static inline chunk_t dm_chunk_number(chunk_t chunk) | ||
| 89 | { | ||
| 90 | return chunk & (chunk_t)((1ULL << DM_CHUNK_NUMBER_BITS) - 1ULL); | ||
| 91 | } | ||
| 92 | |||
| 93 | static inline unsigned dm_consecutive_chunk_count(struct dm_snap_exception *e) | ||
| 94 | { | ||
| 95 | return e->new_chunk >> DM_CHUNK_NUMBER_BITS; | ||
| 96 | } | ||
| 97 | |||
| 98 | static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e) | ||
| 99 | { | ||
| 100 | e->new_chunk += (1ULL << DM_CHUNK_NUMBER_BITS); | ||
| 101 | |||
| 102 | BUG_ON(!dm_consecutive_chunk_count(e)); | ||
| 103 | } | ||
| 104 | |||
| 105 | # else | ||
| 106 | # define DM_CHUNK_CONSECUTIVE_BITS 0 | ||
| 107 | |||
| 108 | static inline chunk_t dm_chunk_number(chunk_t chunk) | ||
| 109 | { | ||
| 110 | return chunk; | ||
| 111 | } | ||
| 112 | |||
| 113 | static inline unsigned dm_consecutive_chunk_count(struct dm_snap_exception *e) | ||
| 114 | { | ||
| 115 | return 0; | ||
| 116 | } | ||
| 117 | |||
| 118 | static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e) | ||
| 119 | { | ||
| 120 | } | ||
| 121 | |||
| 122 | # endif | ||
| 123 | |||
| 124 | /* | ||
| 125 | * Two exception store implementations. | ||
| 126 | */ | ||
| 127 | int dm_create_persistent(struct exception_store *store); | ||
| 128 | |||
| 129 | int dm_create_transient(struct exception_store *store); | ||
| 130 | |||
| 131 | #endif /* _LINUX_DM_EXCEPTION_STORE */ | ||
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index a8005b43a06b..81f03a0e7838 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include <linux/log2.h> | 21 | #include <linux/log2.h> |
| 22 | #include <linux/dm-kcopyd.h> | 22 | #include <linux/dm-kcopyd.h> |
| 23 | 23 | ||
| 24 | #include "dm-exception-store.h" | ||
| 24 | #include "dm-snap.h" | 25 | #include "dm-snap.h" |
| 25 | #include "dm-bio-list.h" | 26 | #include "dm-bio-list.h" |
| 26 | 27 | ||
diff --git a/drivers/md/dm-snap.h b/drivers/md/dm-snap.h index 99c0106ede2d..6e4beaf89f6c 100644 --- a/drivers/md/dm-snap.h +++ b/drivers/md/dm-snap.h | |||
| @@ -1,6 +1,4 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * dm-snapshot.c | ||
| 3 | * | ||
| 4 | * Copyright (C) 2001-2002 Sistina Software (UK) Limited. | 2 | * Copyright (C) 2001-2002 Sistina Software (UK) Limited. |
| 5 | * | 3 | * |
| 6 | * This file is released under the GPL. | 4 | * This file is released under the GPL. |
| @@ -10,6 +8,7 @@ | |||
| 10 | #define DM_SNAPSHOT_H | 8 | #define DM_SNAPSHOT_H |
| 11 | 9 | ||
| 12 | #include <linux/device-mapper.h> | 10 | #include <linux/device-mapper.h> |
| 11 | #include "dm-exception-store.h" | ||
| 13 | #include "dm-bio-list.h" | 12 | #include "dm-bio-list.h" |
| 14 | #include <linux/blkdev.h> | 13 | #include <linux/blkdev.h> |
| 15 | #include <linux/workqueue.h> | 14 | #include <linux/workqueue.h> |
| @@ -20,116 +19,6 @@ struct exception_table { | |||
| 20 | struct list_head *table; | 19 | struct list_head *table; |
| 21 | }; | 20 | }; |
| 22 | 21 | ||
| 23 | /* | ||
| 24 | * The snapshot code deals with largish chunks of the disk at a | ||
| 25 | * time. Typically 32k - 512k. | ||
| 26 | */ | ||
| 27 | typedef sector_t chunk_t; | ||
| 28 | |||
| 29 | /* | ||
| 30 | * An exception is used where an old chunk of data has been | ||
| 31 | * replaced by a new one. | ||
| 32 | * If chunk_t is 64 bits in size, the top 8 bits of new_chunk hold the number | ||
| 33 | * of chunks that follow contiguously. Remaining bits hold the number of the | ||
| 34 | * chunk within the device. | ||
| 35 | */ | ||
| 36 | struct dm_snap_exception { | ||
| 37 | struct list_head hash_list; | ||
| 38 | |||
| 39 | chunk_t old_chunk; | ||
| 40 | chunk_t new_chunk; | ||
| 41 | }; | ||
| 42 | |||
| 43 | /* | ||
| 44 | * Funtions to manipulate consecutive chunks | ||
| 45 | */ | ||
| 46 | # if defined(CONFIG_LBD) || (BITS_PER_LONG == 64) | ||
| 47 | # define DM_CHUNK_CONSECUTIVE_BITS 8 | ||
| 48 | # define DM_CHUNK_NUMBER_BITS 56 | ||
| 49 | |||
| 50 | static inline chunk_t dm_chunk_number(chunk_t chunk) | ||
| 51 | { | ||
| 52 | return chunk & (chunk_t)((1ULL << DM_CHUNK_NUMBER_BITS) - 1ULL); | ||
| 53 | } | ||
| 54 | |||
| 55 | static inline unsigned dm_consecutive_chunk_count(struct dm_snap_exception *e) | ||
| 56 | { | ||
| 57 | return e->new_chunk >> DM_CHUNK_NUMBER_BITS; | ||
| 58 | } | ||
| 59 | |||
| 60 | static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e) | ||
| 61 | { | ||
| 62 | e->new_chunk += (1ULL << DM_CHUNK_NUMBER_BITS); | ||
| 63 | |||
| 64 | BUG_ON(!dm_consecutive_chunk_count(e)); | ||
| 65 | } | ||
| 66 | |||
| 67 | # else | ||
| 68 | # define DM_CHUNK_CONSECUTIVE_BITS 0 | ||
| 69 | |||
| 70 | static inline chunk_t dm_chunk_number(chunk_t chunk) | ||
| 71 | { | ||
| 72 | return chunk; | ||
| 73 | } | ||
| 74 | |||
| 75 | static inline unsigned dm_consecutive_chunk_count(struct dm_snap_exception *e) | ||
| 76 | { | ||
| 77 | return 0; | ||
| 78 | } | ||
| 79 | |||
| 80 | static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e) | ||
| 81 | { | ||
| 82 | } | ||
| 83 | |||
| 84 | # endif | ||
| 85 | |||
| 86 | /* | ||
| 87 | * Abstraction to handle the meta/layout of exception stores (the | ||
| 88 | * COW device). | ||
| 89 | */ | ||
| 90 | struct exception_store { | ||
| 91 | |||
| 92 | /* | ||
| 93 | * Destroys this object when you've finished with it. | ||
| 94 | */ | ||
| 95 | void (*destroy) (struct exception_store *store); | ||
| 96 | |||
| 97 | /* | ||
| 98 | * The target shouldn't read the COW device until this is | ||
| 99 | * called. | ||
| 100 | */ | ||
| 101 | int (*read_metadata) (struct exception_store *store); | ||
| 102 | |||
| 103 | /* | ||
| 104 | * Find somewhere to store the next exception. | ||
| 105 | */ | ||
| 106 | int (*prepare_exception) (struct exception_store *store, | ||
| 107 | struct dm_snap_exception *e); | ||
| 108 | |||
| 109 | /* | ||
| 110 | * Update the metadata with this exception. | ||
| 111 | */ | ||
| 112 | void (*commit_exception) (struct exception_store *store, | ||
| 113 | struct dm_snap_exception *e, | ||
| 114 | void (*callback) (void *, int success), | ||
| 115 | void *callback_context); | ||
| 116 | |||
| 117 | /* | ||
| 118 | * The snapshot is invalid, note this in the metadata. | ||
| 119 | */ | ||
| 120 | void (*drop_snapshot) (struct exception_store *store); | ||
| 121 | |||
| 122 | /* | ||
| 123 | * Return how full the snapshot is. | ||
| 124 | */ | ||
| 125 | void (*fraction_full) (struct exception_store *store, | ||
| 126 | sector_t *numerator, | ||
| 127 | sector_t *denominator); | ||
| 128 | |||
| 129 | struct dm_snapshot *snap; | ||
| 130 | void *context; | ||
| 131 | }; | ||
| 132 | |||
| 133 | #define DM_TRACKED_CHUNK_HASH_SIZE 16 | 22 | #define DM_TRACKED_CHUNK_HASH_SIZE 16 |
| 134 | #define DM_TRACKED_CHUNK_HASH(x) ((unsigned long)(x) & \ | 23 | #define DM_TRACKED_CHUNK_HASH(x) ((unsigned long)(x) & \ |
| 135 | (DM_TRACKED_CHUNK_HASH_SIZE - 1)) | 24 | (DM_TRACKED_CHUNK_HASH_SIZE - 1)) |
| @@ -193,14 +82,6 @@ struct dm_snapshot { | |||
| 193 | int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new); | 82 | int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new); |
| 194 | 83 | ||
| 195 | /* | 84 | /* |
| 196 | * Constructor and destructor for the default persistent | ||
| 197 | * store. | ||
| 198 | */ | ||
| 199 | int dm_create_persistent(struct exception_store *store); | ||
| 200 | |||
| 201 | int dm_create_transient(struct exception_store *store); | ||
| 202 | |||
| 203 | /* | ||
| 204 | * Return the number of sectors in the device. | 85 | * Return the number of sectors in the device. |
| 205 | */ | 86 | */ |
| 206 | static inline sector_t get_dev_size(struct block_device *bdev) | 87 | static inline sector_t get_dev_size(struct block_device *bdev) |
