diff options
author | Jonathan Brassow <jbrassow@redhat.com> | 2009-04-02 14:55:33 -0400 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2009-04-02 14:55:33 -0400 |
commit | 71fab00a6bef7fb53119271a8abdbaf40970d28a (patch) | |
tree | 4881f8f6d1b1c42528889d7a56fb8674d2aa7723 /drivers/md | |
parent | 49beb2b87a972a994ff77633234ca3bf0d30a1d8 (diff) |
dm snapshot: remove dm_snap header use
Move useful functions out of dm-snap.h and stop using dm-snap.h.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-exception-store.h | 16 | ||||
-rw-r--r-- | drivers/md/dm-snap-persistent.c | 56 | ||||
-rw-r--r-- | drivers/md/dm-snap-transient.c | 3 | ||||
-rw-r--r-- | drivers/md/dm-snap.c | 18 | ||||
-rw-r--r-- | drivers/md/dm-snap.h | 18 |
5 files changed, 54 insertions, 57 deletions
diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index 4dbf3577408e..835f402d9470 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h | |||
@@ -97,8 +97,6 @@ struct dm_exception_store { | |||
97 | struct dm_exception_store_type *type; | 97 | struct dm_exception_store_type *type; |
98 | struct dm_target *ti; | 98 | struct dm_target *ti; |
99 | 99 | ||
100 | struct dm_snapshot *snap; | ||
101 | |||
102 | struct dm_dev *cow; | 100 | struct dm_dev *cow; |
103 | 101 | ||
104 | /* Size of data blocks saved - must be a power of 2 */ | 102 | /* Size of data blocks saved - must be a power of 2 */ |
@@ -152,6 +150,20 @@ static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e) | |||
152 | 150 | ||
153 | # endif | 151 | # endif |
154 | 152 | ||
153 | /* | ||
154 | * Return the number of sectors in the device. | ||
155 | */ | ||
156 | static inline sector_t get_dev_size(struct block_device *bdev) | ||
157 | { | ||
158 | return bdev->bd_inode->i_size >> SECTOR_SHIFT; | ||
159 | } | ||
160 | |||
161 | static inline chunk_t sector_to_chunk(struct dm_exception_store *store, | ||
162 | sector_t sector) | ||
163 | { | ||
164 | return (sector & ~store->chunk_mask) >> store->chunk_shift; | ||
165 | } | ||
166 | |||
155 | int dm_exception_store_type_register(struct dm_exception_store_type *type); | 167 | int dm_exception_store_type_register(struct dm_exception_store_type *type); |
156 | int dm_exception_store_type_unregister(struct dm_exception_store_type *type); | 168 | int dm_exception_store_type_unregister(struct dm_exception_store_type *type); |
157 | 169 | ||
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c index 505afac9976f..3907c4ce2ae5 100644 --- a/drivers/md/dm-snap-persistent.c +++ b/drivers/md/dm-snap-persistent.c | |||
@@ -6,7 +6,6 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include "dm-exception-store.h" | 8 | #include "dm-exception-store.h" |
9 | #include "dm-snap.h" | ||
10 | 9 | ||
11 | #include <linux/mm.h> | 10 | #include <linux/mm.h> |
12 | #include <linux/pagemap.h> | 11 | #include <linux/pagemap.h> |
@@ -89,7 +88,7 @@ struct commit_callback { | |||
89 | * The top level structure for a persistent exception store. | 88 | * The top level structure for a persistent exception store. |
90 | */ | 89 | */ |
91 | struct pstore { | 90 | struct pstore { |
92 | struct dm_snapshot *snap; /* up pointer to my snapshot */ | 91 | struct dm_exception_store *store; |
93 | int version; | 92 | int version; |
94 | int valid; | 93 | int valid; |
95 | uint32_t exceptions_per_area; | 94 | uint32_t exceptions_per_area; |
@@ -141,7 +140,7 @@ static int alloc_area(struct pstore *ps) | |||
141 | int r = -ENOMEM; | 140 | int r = -ENOMEM; |
142 | size_t len; | 141 | size_t len; |
143 | 142 | ||
144 | len = ps->snap->store->chunk_size << SECTOR_SHIFT; | 143 | len = ps->store->chunk_size << SECTOR_SHIFT; |
145 | 144 | ||
146 | /* | 145 | /* |
147 | * Allocate the chunk_size block of memory that will hold | 146 | * Allocate the chunk_size block of memory that will hold |
@@ -189,9 +188,9 @@ static void do_metadata(struct work_struct *work) | |||
189 | static int chunk_io(struct pstore *ps, chunk_t chunk, int rw, int metadata) | 188 | static int chunk_io(struct pstore *ps, chunk_t chunk, int rw, int metadata) |
190 | { | 189 | { |
191 | struct dm_io_region where = { | 190 | struct dm_io_region where = { |
192 | .bdev = ps->snap->store->cow->bdev, | 191 | .bdev = ps->store->cow->bdev, |
193 | .sector = ps->snap->store->chunk_size * chunk, | 192 | .sector = ps->store->chunk_size * chunk, |
194 | .count = ps->snap->store->chunk_size, | 193 | .count = ps->store->chunk_size, |
195 | }; | 194 | }; |
196 | struct dm_io_request io_req = { | 195 | struct dm_io_request io_req = { |
197 | .bi_rw = rw, | 196 | .bi_rw = rw, |
@@ -247,15 +246,15 @@ static int area_io(struct pstore *ps, int rw) | |||
247 | 246 | ||
248 | static void zero_memory_area(struct pstore *ps) | 247 | static void zero_memory_area(struct pstore *ps) |
249 | { | 248 | { |
250 | memset(ps->area, 0, ps->snap->store->chunk_size << SECTOR_SHIFT); | 249 | memset(ps->area, 0, ps->store->chunk_size << SECTOR_SHIFT); |
251 | } | 250 | } |
252 | 251 | ||
253 | static int zero_disk_area(struct pstore *ps, chunk_t area) | 252 | static int zero_disk_area(struct pstore *ps, chunk_t area) |
254 | { | 253 | { |
255 | struct dm_io_region where = { | 254 | struct dm_io_region where = { |
256 | .bdev = ps->snap->store->cow->bdev, | 255 | .bdev = ps->store->cow->bdev, |
257 | .sector = ps->snap->store->chunk_size * area_location(ps, area), | 256 | .sector = ps->store->chunk_size * area_location(ps, area), |
258 | .count = ps->snap->store->chunk_size, | 257 | .count = ps->store->chunk_size, |
259 | }; | 258 | }; |
260 | struct dm_io_request io_req = { | 259 | struct dm_io_request io_req = { |
261 | .bi_rw = WRITE, | 260 | .bi_rw = WRITE, |
@@ -278,17 +277,16 @@ static int read_header(struct pstore *ps, int *new_snapshot) | |||
278 | /* | 277 | /* |
279 | * Use default chunk size (or hardsect_size, if larger) if none supplied | 278 | * Use default chunk size (or hardsect_size, if larger) if none supplied |
280 | */ | 279 | */ |
281 | if (!ps->snap->store->chunk_size) { | 280 | if (!ps->store->chunk_size) { |
282 | ps->snap->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS, | 281 | ps->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS, |
283 | bdev_hardsect_size(ps->snap->store->cow->bdev) >> 9); | 282 | bdev_hardsect_size(ps->store->cow->bdev) >> 9); |
284 | ps->snap->store->chunk_mask = ps->snap->store->chunk_size - 1; | 283 | ps->store->chunk_mask = ps->store->chunk_size - 1; |
285 | ps->snap->store->chunk_shift = ffs(ps->snap->store->chunk_size) | 284 | ps->store->chunk_shift = ffs(ps->store->chunk_size) - 1; |
286 | - 1; | ||
287 | chunk_size_supplied = 0; | 285 | chunk_size_supplied = 0; |
288 | } | 286 | } |
289 | 287 | ||
290 | ps->io_client = dm_io_client_create(sectors_to_pages(ps->snap-> | 288 | ps->io_client = dm_io_client_create(sectors_to_pages(ps->store-> |
291 | store->chunk_size)); | 289 | chunk_size)); |
292 | if (IS_ERR(ps->io_client)) | 290 | if (IS_ERR(ps->io_client)) |
293 | return PTR_ERR(ps->io_client); | 291 | return PTR_ERR(ps->io_client); |
294 | 292 | ||
@@ -318,22 +316,22 @@ static int read_header(struct pstore *ps, int *new_snapshot) | |||
318 | ps->version = le32_to_cpu(dh->version); | 316 | ps->version = le32_to_cpu(dh->version); |
319 | chunk_size = le32_to_cpu(dh->chunk_size); | 317 | chunk_size = le32_to_cpu(dh->chunk_size); |
320 | 318 | ||
321 | if (!chunk_size_supplied || ps->snap->store->chunk_size == chunk_size) | 319 | if (!chunk_size_supplied || ps->store->chunk_size == chunk_size) |
322 | return 0; | 320 | return 0; |
323 | 321 | ||
324 | DMWARN("chunk size %llu in device metadata overrides " | 322 | DMWARN("chunk size %llu in device metadata overrides " |
325 | "table chunk size of %llu.", | 323 | "table chunk size of %llu.", |
326 | (unsigned long long)chunk_size, | 324 | (unsigned long long)chunk_size, |
327 | (unsigned long long)ps->snap->store->chunk_size); | 325 | (unsigned long long)ps->store->chunk_size); |
328 | 326 | ||
329 | /* We had a bogus chunk_size. Fix stuff up. */ | 327 | /* We had a bogus chunk_size. Fix stuff up. */ |
330 | free_area(ps); | 328 | free_area(ps); |
331 | 329 | ||
332 | ps->snap->store->chunk_size = chunk_size; | 330 | ps->store->chunk_size = chunk_size; |
333 | ps->snap->store->chunk_mask = chunk_size - 1; | 331 | ps->store->chunk_mask = chunk_size - 1; |
334 | ps->snap->store->chunk_shift = ffs(chunk_size) - 1; | 332 | ps->store->chunk_shift = ffs(chunk_size) - 1; |
335 | 333 | ||
336 | r = dm_io_client_resize(sectors_to_pages(ps->snap->store->chunk_size), | 334 | r = dm_io_client_resize(sectors_to_pages(ps->store->chunk_size), |
337 | ps->io_client); | 335 | ps->io_client); |
338 | if (r) | 336 | if (r) |
339 | return r; | 337 | return r; |
@@ -350,13 +348,13 @@ static int write_header(struct pstore *ps) | |||
350 | { | 348 | { |
351 | struct disk_header *dh; | 349 | struct disk_header *dh; |
352 | 350 | ||
353 | memset(ps->area, 0, ps->snap->store->chunk_size << SECTOR_SHIFT); | 351 | memset(ps->area, 0, ps->store->chunk_size << SECTOR_SHIFT); |
354 | 352 | ||
355 | dh = (struct disk_header *) ps->area; | 353 | dh = (struct disk_header *) ps->area; |
356 | dh->magic = cpu_to_le32(SNAP_MAGIC); | 354 | dh->magic = cpu_to_le32(SNAP_MAGIC); |
357 | dh->valid = cpu_to_le32(ps->valid); | 355 | dh->valid = cpu_to_le32(ps->valid); |
358 | dh->version = cpu_to_le32(ps->version); | 356 | dh->version = cpu_to_le32(ps->version); |
359 | dh->chunk_size = cpu_to_le32(ps->snap->store->chunk_size); | 357 | dh->chunk_size = cpu_to_le32(ps->store->chunk_size); |
360 | 358 | ||
361 | return chunk_io(ps, 0, WRITE, 1); | 359 | return chunk_io(ps, 0, WRITE, 1); |
362 | } | 360 | } |
@@ -508,8 +506,8 @@ static int persistent_read_metadata(struct dm_exception_store *store, | |||
508 | /* | 506 | /* |
509 | * Now we know correct chunk_size, complete the initialisation. | 507 | * Now we know correct chunk_size, complete the initialisation. |
510 | */ | 508 | */ |
511 | ps->exceptions_per_area = (ps->snap->store->chunk_size << SECTOR_SHIFT) | 509 | ps->exceptions_per_area = (ps->store->chunk_size << SECTOR_SHIFT) / |
512 | / sizeof(struct disk_exception); | 510 | sizeof(struct disk_exception); |
513 | ps->callbacks = dm_vcalloc(ps->exceptions_per_area, | 511 | ps->callbacks = dm_vcalloc(ps->exceptions_per_area, |
514 | sizeof(*ps->callbacks)); | 512 | sizeof(*ps->callbacks)); |
515 | if (!ps->callbacks) | 513 | if (!ps->callbacks) |
@@ -667,7 +665,7 @@ static int persistent_ctr(struct dm_exception_store *store, | |||
667 | if (!ps) | 665 | if (!ps) |
668 | return -ENOMEM; | 666 | return -ENOMEM; |
669 | 667 | ||
670 | ps->snap = store->snap; | 668 | ps->store = store; |
671 | ps->valid = 1; | 669 | ps->valid = 1; |
672 | ps->version = SNAPSHOT_DISK_VERSION; | 670 | ps->version = SNAPSHOT_DISK_VERSION; |
673 | ps->area = NULL; | 671 | ps->area = NULL; |
diff --git a/drivers/md/dm-snap-transient.c b/drivers/md/dm-snap-transient.c index 77f58be080c4..a883d6e658be 100644 --- a/drivers/md/dm-snap-transient.c +++ b/drivers/md/dm-snap-transient.c | |||
@@ -6,7 +6,6 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include "dm-exception-store.h" | 8 | #include "dm-exception-store.h" |
9 | #include "dm-snap.h" | ||
10 | 9 | ||
11 | #include <linux/mm.h> | 10 | #include <linux/mm.h> |
12 | #include <linux/pagemap.h> | 11 | #include <linux/pagemap.h> |
@@ -45,7 +44,7 @@ static int transient_prepare_exception(struct dm_exception_store *store, | |||
45 | if (size < (tc->next_free + store->chunk_size)) | 44 | if (size < (tc->next_free + store->chunk_size)) |
46 | return -1; | 45 | return -1; |
47 | 46 | ||
48 | e->new_chunk = sector_to_chunk(store->snap, tc->next_free); | 47 | e->new_chunk = sector_to_chunk(store, tc->next_free); |
49 | tc->next_free += store->chunk_size; | 48 | tc->next_free += store->chunk_size; |
50 | 49 | ||
51 | return 0; | 50 | return 0; |
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 5c067efc665f..467c586e2439 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c | |||
@@ -637,8 +637,6 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
637 | goto bad4; | 637 | goto bad4; |
638 | } | 638 | } |
639 | 639 | ||
640 | s->store->snap = s; | ||
641 | |||
642 | r = dm_kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client); | 640 | r = dm_kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client); |
643 | if (r) { | 641 | if (r) { |
644 | ti->error = "Could not create kcopyd client"; | 642 | ti->error = "Could not create kcopyd client"; |
@@ -962,11 +960,11 @@ static void start_copy(struct dm_snap_pending_exception *pe) | |||
962 | dev_size = get_dev_size(bdev); | 960 | dev_size = get_dev_size(bdev); |
963 | 961 | ||
964 | src.bdev = bdev; | 962 | src.bdev = bdev; |
965 | src.sector = chunk_to_sector(s, pe->e.old_chunk); | 963 | src.sector = chunk_to_sector(s->store, pe->e.old_chunk); |
966 | src.count = min(s->store->chunk_size, dev_size - src.sector); | 964 | src.count = min(s->store->chunk_size, dev_size - src.sector); |
967 | 965 | ||
968 | dest.bdev = s->store->cow->bdev; | 966 | dest.bdev = s->store->cow->bdev; |
969 | dest.sector = chunk_to_sector(s, pe->e.new_chunk); | 967 | dest.sector = chunk_to_sector(s->store, pe->e.new_chunk); |
970 | dest.count = src.count; | 968 | dest.count = src.count; |
971 | 969 | ||
972 | /* Hand over to kcopyd */ | 970 | /* Hand over to kcopyd */ |
@@ -1027,9 +1025,11 @@ static void remap_exception(struct dm_snapshot *s, struct dm_snap_exception *e, | |||
1027 | struct bio *bio, chunk_t chunk) | 1025 | struct bio *bio, chunk_t chunk) |
1028 | { | 1026 | { |
1029 | bio->bi_bdev = s->store->cow->bdev; | 1027 | bio->bi_bdev = s->store->cow->bdev; |
1030 | bio->bi_sector = chunk_to_sector(s, dm_chunk_number(e->new_chunk) + | 1028 | bio->bi_sector = chunk_to_sector(s->store, |
1031 | (chunk - e->old_chunk)) + | 1029 | dm_chunk_number(e->new_chunk) + |
1032 | (bio->bi_sector & s->store->chunk_mask); | 1030 | (chunk - e->old_chunk)) + |
1031 | (bio->bi_sector & | ||
1032 | s->store->chunk_mask); | ||
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | static int snapshot_map(struct dm_target *ti, struct bio *bio, | 1035 | static int snapshot_map(struct dm_target *ti, struct bio *bio, |
@@ -1041,7 +1041,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio, | |||
1041 | chunk_t chunk; | 1041 | chunk_t chunk; |
1042 | struct dm_snap_pending_exception *pe = NULL; | 1042 | struct dm_snap_pending_exception *pe = NULL; |
1043 | 1043 | ||
1044 | chunk = sector_to_chunk(s, bio->bi_sector); | 1044 | chunk = sector_to_chunk(s->store, bio->bi_sector); |
1045 | 1045 | ||
1046 | /* Full snapshots are not usable */ | 1046 | /* Full snapshots are not usable */ |
1047 | /* To get here the table must be live so s->active is always set. */ | 1047 | /* To get here the table must be live so s->active is always set. */ |
@@ -1210,7 +1210,7 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio) | |||
1210 | * Remember, different snapshots can have | 1210 | * Remember, different snapshots can have |
1211 | * different chunk sizes. | 1211 | * different chunk sizes. |
1212 | */ | 1212 | */ |
1213 | chunk = sector_to_chunk(snap, bio->bi_sector); | 1213 | chunk = sector_to_chunk(snap->store, bio->bi_sector); |
1214 | 1214 | ||
1215 | /* | 1215 | /* |
1216 | * Check exception table to see if block | 1216 | * Check exception table to see if block |
diff --git a/drivers/md/dm-snap.h b/drivers/md/dm-snap.h index c8a486e0ea2c..4f61bc4c14f6 100644 --- a/drivers/md/dm-snap.h +++ b/drivers/md/dm-snap.h | |||
@@ -68,22 +68,10 @@ struct dm_snapshot { | |||
68 | struct hlist_head tracked_chunk_hash[DM_TRACKED_CHUNK_HASH_SIZE]; | 68 | struct hlist_head tracked_chunk_hash[DM_TRACKED_CHUNK_HASH_SIZE]; |
69 | }; | 69 | }; |
70 | 70 | ||
71 | /* | 71 | static inline sector_t chunk_to_sector(struct dm_exception_store *store, |
72 | * Return the number of sectors in the device. | 72 | chunk_t chunk) |
73 | */ | ||
74 | static inline sector_t get_dev_size(struct block_device *bdev) | ||
75 | { | ||
76 | return bdev->bd_inode->i_size >> SECTOR_SHIFT; | ||
77 | } | ||
78 | |||
79 | static inline chunk_t sector_to_chunk(struct dm_snapshot *s, sector_t sector) | ||
80 | { | ||
81 | return (sector & ~s->store->chunk_mask) >> s->store->chunk_shift; | ||
82 | } | ||
83 | |||
84 | static inline sector_t chunk_to_sector(struct dm_snapshot *s, chunk_t chunk) | ||
85 | { | 73 | { |
86 | return chunk << s->store->chunk_shift; | 74 | return chunk << store->chunk_shift; |
87 | } | 75 | } |
88 | 76 | ||
89 | static inline int bdev_equal(struct block_device *lhs, struct block_device *rhs) | 77 | static inline int bdev_equal(struct block_device *lhs, struct block_device *rhs) |