]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * dm-snapshot.c | |
3 | * | |
4 | * Copyright (C) 2001-2002 Sistina Software (UK) Limited. | |
5 | * | |
6 | * This file is released under the GPL. | |
7 | */ | |
8 | ||
9 | #ifndef DM_SNAPSHOT_H | |
10 | #define DM_SNAPSHOT_H | |
11 | ||
12 | #include "dm.h" | |
13 | #include <linux/blkdev.h> | |
14 | ||
15 | struct exception_table { | |
16 | uint32_t hash_mask; | |
17 | struct list_head *table; | |
18 | }; | |
19 | ||
20 | /* | |
21 | * The snapshot code deals with largish chunks of the disk at a | |
22 | * time. Typically 64k - 256k. | |
23 | */ | |
24 | /* FIXME: can we get away with limiting these to a uint32_t ? */ | |
25 | typedef sector_t chunk_t; | |
26 | ||
27 | /* | |
28 | * An exception is used where an old chunk of data has been | |
29 | * replaced by a new one. | |
30 | */ | |
31 | struct exception { | |
32 | struct list_head hash_list; | |
33 | ||
34 | chunk_t old_chunk; | |
35 | chunk_t new_chunk; | |
36 | }; | |
37 | ||
38 | /* | |
39 | * Abstraction to handle the meta/layout of exception stores (the | |
40 | * COW device). | |
41 | */ | |
42 | struct exception_store { | |
43 | ||
44 | /* | |
45 | * Destroys this object when you've finished with it. | |
46 | */ | |
47 | void (*destroy) (struct exception_store *store); | |
48 | ||
49 | /* | |
50 | * The target shouldn't read the COW device until this is | |
51 | * called. | |
52 | */ | |
53 | int (*read_metadata) (struct exception_store *store); | |
54 | ||
55 | /* | |
56 | * Find somewhere to store the next exception. | |
57 | */ | |
58 | int (*prepare_exception) (struct exception_store *store, | |
59 | struct exception *e); | |
60 | ||
61 | /* | |
62 | * Update the metadata with this exception. | |
63 | */ | |
64 | void (*commit_exception) (struct exception_store *store, | |
65 | struct exception *e, | |
66 | void (*callback) (void *, int success), | |
67 | void *callback_context); | |
68 | ||
69 | /* | |
70 | * The snapshot is invalid, note this in the metadata. | |
71 | */ | |
72 | void (*drop_snapshot) (struct exception_store *store); | |
73 | ||
74 | /* | |
75 | * Return how full the snapshot is. | |
76 | */ | |
77 | void (*fraction_full) (struct exception_store *store, | |
78 | sector_t *numerator, | |
79 | sector_t *denominator); | |
80 | ||
81 | struct dm_snapshot *snap; | |
82 | void *context; | |
83 | }; | |
84 | ||
85 | struct dm_snapshot { | |
86 | struct rw_semaphore lock; | |
87 | struct dm_table *table; | |
88 | ||
89 | struct dm_dev *origin; | |
90 | struct dm_dev *cow; | |
91 | ||
92 | /* List of snapshots per Origin */ | |
93 | struct list_head list; | |
94 | ||
95 | /* Size of data blocks saved - must be a power of 2 */ | |
96 | chunk_t chunk_size; | |
97 | chunk_t chunk_mask; | |
98 | chunk_t chunk_shift; | |
99 | ||
100 | /* You can't use a snapshot if this is 0 (e.g. if full) */ | |
101 | int valid; | |
102 | int have_metadata; | |
103 | ||
104 | /* Used for display of table */ | |
105 | char type; | |
106 | ||
107 | /* The last percentage we notified */ | |
108 | int last_percent; | |
109 | ||
110 | struct exception_table pending; | |
111 | struct exception_table complete; | |
112 | ||
113 | /* The on disk metadata handler */ | |
114 | struct exception_store store; | |
115 | ||
116 | struct kcopyd_client *kcopyd_client; | |
117 | }; | |
118 | ||
119 | /* | |
120 | * Used by the exception stores to load exceptions hen | |
121 | * initialising. | |
122 | */ | |
123 | int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new); | |
124 | ||
125 | /* | |
126 | * Constructor and destructor for the default persistent | |
127 | * store. | |
128 | */ | |
129 | int dm_create_persistent(struct exception_store *store, uint32_t chunk_size); | |
130 | ||
131 | int dm_create_transient(struct exception_store *store, | |
132 | struct dm_snapshot *s, int blocksize); | |
133 | ||
134 | /* | |
135 | * Return the number of sectors in the device. | |
136 | */ | |
137 | static inline sector_t get_dev_size(struct block_device *bdev) | |
138 | { | |
139 | return bdev->bd_inode->i_size >> SECTOR_SHIFT; | |
140 | } | |
141 | ||
142 | static inline chunk_t sector_to_chunk(struct dm_snapshot *s, sector_t sector) | |
143 | { | |
144 | return (sector & ~s->chunk_mask) >> s->chunk_shift; | |
145 | } | |
146 | ||
147 | static inline sector_t chunk_to_sector(struct dm_snapshot *s, chunk_t chunk) | |
148 | { | |
149 | return chunk << s->chunk_shift; | |
150 | } | |
151 | ||
152 | static inline int bdev_equal(struct block_device *lhs, struct block_device *rhs) | |
153 | { | |
154 | /* | |
155 | * There is only ever one instance of a particular block | |
156 | * device so we can compare pointers safely. | |
157 | */ | |
158 | return lhs == rhs; | |
159 | } | |
160 | ||
161 | #endif |