Blame view
drivers/md/dm-exception-store.h
5.27 KB
aea53d92f
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/* * Copyright (C) 2001-2002 Sistina Software (UK) Limited. * Copyright (C) 2008 Red Hat, Inc. All rights reserved. * * Device-mapper snapshot exception store. * * This file is released under the GPL. */ #ifndef _LINUX_DM_EXCEPTION_STORE #define _LINUX_DM_EXCEPTION_STORE #include <linux/blkdev.h> |
f79ae415b
|
14 |
#include <linux/list_bl.h> |
a159c1ac5
|
15 |
#include <linux/device-mapper.h> |
aea53d92f
|
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* * The snapshot code deals with largish chunks of the disk at a * time. Typically 32k - 512k. */ typedef sector_t chunk_t; /* * An exception is used where an old chunk of data has been * replaced by a new one. * If chunk_t is 64 bits in size, the top 8 bits of new_chunk hold the number * of chunks that follow contiguously. Remaining bits hold the number of the * chunk within the device. */ |
1d4989c85
|
30 |
struct dm_exception { |
f79ae415b
|
31 |
struct hlist_bl_node hash_list; |
aea53d92f
|
32 33 34 35 36 37 38 39 40 |
chunk_t old_chunk; chunk_t new_chunk; }; /* * Abstraction to handle the meta/layout of exception stores (the * COW device). */ |
b2a114652
|
41 42 |
struct dm_exception_store; struct dm_exception_store_type { |
493df71c6
|
43 44 |
const char *name; struct module *module; |
b0d3cc011
|
45 |
int (*ctr) (struct dm_exception_store *store, char *options); |
b2a114652
|
46 |
|
aea53d92f
|
47 48 49 |
/* * Destroys this object when you've finished with it. */ |
b2a114652
|
50 |
void (*dtr) (struct dm_exception_store *store); |
aea53d92f
|
51 52 53 |
/* * The target shouldn't read the COW device until this is |
a159c1ac5
|
54 55 |
* called. As exceptions are read from the COW, they are * reported back via the callback. |
aea53d92f
|
56 |
*/ |
a159c1ac5
|
57 58 59 60 |
int (*read_metadata) (struct dm_exception_store *store, int (*callback)(void *callback_context, chunk_t old, chunk_t new), void *callback_context); |
aea53d92f
|
61 62 63 64 |
/* * Find somewhere to store the next exception. */ |
1ae25f9c9
|
65 |
int (*prepare_exception) (struct dm_exception_store *store, |
1d4989c85
|
66 |
struct dm_exception *e); |
aea53d92f
|
67 68 69 70 |
/* * Update the metadata with this exception. */ |
1ae25f9c9
|
71 |
void (*commit_exception) (struct dm_exception_store *store, |
385277bfb
|
72 |
struct dm_exception *e, int valid, |
aea53d92f
|
73 74 75 76 |
void (*callback) (void *, int success), void *callback_context); /* |
4454a6216
|
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
* Returns 0 if the exception store is empty. * * If there are exceptions still to be merged, sets * *last_old_chunk and *last_new_chunk to the most recent * still-to-be-merged chunk and returns the number of * consecutive previous ones. */ int (*prepare_merge) (struct dm_exception_store *store, chunk_t *last_old_chunk, chunk_t *last_new_chunk); /* * Clear the last n exceptions. * nr_merged must be <= the value returned by prepare_merge. */ int (*commit_merge) (struct dm_exception_store *store, int nr_merged); /* |
aea53d92f
|
94 95 |
* The snapshot is invalid, note this in the metadata. */ |
1ae25f9c9
|
96 |
void (*drop_snapshot) (struct dm_exception_store *store); |
aea53d92f
|
97 |
|
1e302a929
|
98 99 100 |
unsigned (*status) (struct dm_exception_store *store, status_type_t status, char *result, unsigned maxlen); |
a159c1ac5
|
101 |
|
aea53d92f
|
102 103 104 |
/* * Return how full the snapshot is. */ |
985903bb3
|
105 106 107 |
void (*usage) (struct dm_exception_store *store, sector_t *total_sectors, sector_t *sectors_allocated, sector_t *metadata_sectors); |
493df71c6
|
108 109 110 |
/* For internal device-mapper use only. */ struct list_head list; |
b2a114652
|
111 |
}; |
fc56f6fbc
|
112 |
struct dm_snapshot; |
b2a114652
|
113 |
struct dm_exception_store { |
493df71c6
|
114 |
struct dm_exception_store_type *type; |
fc56f6fbc
|
115 |
struct dm_snapshot *snap; |
49beb2b87
|
116 |
|
d02168495
|
117 |
/* Size of data blocks saved - must be a power of 2 */ |
df96eee67
|
118 119 120 |
unsigned chunk_size; unsigned chunk_mask; unsigned chunk_shift; |
d02168495
|
121 |
|
aea53d92f
|
122 |
void *context; |
b0d3cc011
|
123 124 |
bool userspace_supports_overflow; |
aea53d92f
|
125 126 127 |
}; /* |
c24110450
|
128 |
* Obtain the origin or cow device used by a given snapshot. |
fc56f6fbc
|
129 |
*/ |
c24110450
|
130 |
struct dm_dev *dm_snap_origin(struct dm_snapshot *snap); |
fc56f6fbc
|
131 132 133 |
struct dm_dev *dm_snap_cow(struct dm_snapshot *snap); /* |
aea53d92f
|
134 135 |
* Funtions to manipulate consecutive chunks */ |
72deb455b
|
136 137 |
#define DM_CHUNK_CONSECUTIVE_BITS 8 #define DM_CHUNK_NUMBER_BITS 56 |
aea53d92f
|
138 139 140 141 142 |
static inline chunk_t dm_chunk_number(chunk_t chunk) { return chunk & (chunk_t)((1ULL << DM_CHUNK_NUMBER_BITS) - 1ULL); } |
1d4989c85
|
143 |
static inline unsigned dm_consecutive_chunk_count(struct dm_exception *e) |
aea53d92f
|
144 145 146 |
{ return e->new_chunk >> DM_CHUNK_NUMBER_BITS; } |
1d4989c85
|
147 |
static inline void dm_consecutive_chunk_count_inc(struct dm_exception *e) |
aea53d92f
|
148 149 150 151 152 |
{ e->new_chunk += (1ULL << DM_CHUNK_NUMBER_BITS); BUG_ON(!dm_consecutive_chunk_count(e)); } |
1e03f97e4
|
153 154 155 156 157 158 |
static inline void dm_consecutive_chunk_count_dec(struct dm_exception *e) { BUG_ON(!dm_consecutive_chunk_count(e)); e->new_chunk -= (1ULL << DM_CHUNK_NUMBER_BITS); } |
71fab00a6
|
159 160 161 162 163 |
/* * Return the number of sectors in the device. */ static inline sector_t get_dev_size(struct block_device *bdev) { |
5657e8fa4
|
164 |
return i_size_read(bdev->bd_inode) >> SECTOR_SHIFT; |
71fab00a6
|
165 166 167 168 169 |
} static inline chunk_t sector_to_chunk(struct dm_exception_store *store, sector_t sector) { |
102c6ddb1
|
170 |
return sector >> store->chunk_shift; |
71fab00a6
|
171 |
} |
493df71c6
|
172 173 |
int dm_exception_store_type_register(struct dm_exception_store_type *type); int dm_exception_store_type_unregister(struct dm_exception_store_type *type); |
2defcc3fb
|
174 |
int dm_exception_store_set_chunk_size(struct dm_exception_store *store, |
df96eee67
|
175 |
unsigned chunk_size, |
2defcc3fb
|
176 |
char **error); |
fee1998e9
|
177 |
int dm_exception_store_create(struct dm_target *ti, int argc, char **argv, |
fc56f6fbc
|
178 |
struct dm_snapshot *snap, |
fee1998e9
|
179 |
unsigned *args_used, |
493df71c6
|
180 181 |
struct dm_exception_store **store); void dm_exception_store_destroy(struct dm_exception_store *store); |
4db6bfe02
|
182 183 |
int dm_exception_store_init(void); void dm_exception_store_exit(void); |
aea53d92f
|
184 185 186 |
/* * Two exception store implementations. */ |
4db6bfe02
|
187 188 189 190 191 |
int dm_persistent_snapshot_init(void); void dm_persistent_snapshot_exit(void); int dm_transient_snapshot_init(void); void dm_transient_snapshot_exit(void); |
aea53d92f
|
192 |
#endif /* _LINUX_DM_EXCEPTION_STORE */ |