aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-exception-store.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md/dm-exception-store.c')
-rw-r--r--drivers/md/dm-exception-store.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index 41f408068a7c..769ab677f8e0 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -108,12 +108,12 @@ struct pstore {
108 * Used to keep track of which metadata area the data in 108 * Used to keep track of which metadata area the data in
109 * 'chunk' refers to. 109 * 'chunk' refers to.
110 */ 110 */
111 uint32_t current_area; 111 chunk_t current_area;
112 112
113 /* 113 /*
114 * The next free chunk for an exception. 114 * The next free chunk for an exception.
115 */ 115 */
116 uint32_t next_free; 116 chunk_t next_free;
117 117
118 /* 118 /*
119 * The index of next free exception in the current 119 * The index of next free exception in the current
@@ -175,7 +175,7 @@ static void do_metadata(struct work_struct *work)
175/* 175/*
176 * Read or write a chunk aligned and sized block of data from a device. 176 * Read or write a chunk aligned and sized block of data from a device.
177 */ 177 */
178static int chunk_io(struct pstore *ps, uint32_t chunk, int rw, int metadata) 178static int chunk_io(struct pstore *ps, chunk_t chunk, int rw, int metadata)
179{ 179{
180 struct dm_io_region where = { 180 struct dm_io_region where = {
181 .bdev = ps->snap->cow->bdev, 181 .bdev = ps->snap->cow->bdev,
@@ -209,16 +209,23 @@ static int chunk_io(struct pstore *ps, uint32_t chunk, int rw, int metadata)
209} 209}
210 210
211/* 211/*
212 * Convert a metadata area index to a chunk index.
213 */
214static chunk_t area_location(struct pstore *ps, chunk_t area)
215{
216 return 1 + ((ps->exceptions_per_area + 1) * area);
217}
218
219/*
212 * Read or write a metadata area. Remembering to skip the first 220 * Read or write a metadata area. Remembering to skip the first
213 * chunk which holds the header. 221 * chunk which holds the header.
214 */ 222 */
215static int area_io(struct pstore *ps, uint32_t area, int rw) 223static int area_io(struct pstore *ps, chunk_t area, int rw)
216{ 224{
217 int r; 225 int r;
218 uint32_t chunk; 226 chunk_t chunk;
219 227
220 /* convert a metadata area index to a chunk index */ 228 chunk = area_location(ps, area);
221 chunk = 1 + ((ps->exceptions_per_area + 1) * area);
222 229
223 r = chunk_io(ps, chunk, rw, 0); 230 r = chunk_io(ps, chunk, rw, 0);
224 if (r) 231 if (r)
@@ -228,7 +235,7 @@ static int area_io(struct pstore *ps, uint32_t area, int rw)
228 return 0; 235 return 0;
229} 236}
230 237
231static int zero_area(struct pstore *ps, uint32_t area) 238static int zero_area(struct pstore *ps, chunk_t area)
232{ 239{
233 memset(ps->area, 0, ps->snap->chunk_size << SECTOR_SHIFT); 240 memset(ps->area, 0, ps->snap->chunk_size << SECTOR_SHIFT);
234 return area_io(ps, area, WRITE); 241 return area_io(ps, area, WRITE);
@@ -404,7 +411,7 @@ static int insert_exceptions(struct pstore *ps, int *full)
404 411
405static int read_exceptions(struct pstore *ps) 412static int read_exceptions(struct pstore *ps)
406{ 413{
407 uint32_t area; 414 chunk_t area;
408 int r, full = 1; 415 int r, full = 1;
409 416
410 /* 417 /*
@@ -517,6 +524,7 @@ static int persistent_prepare(struct exception_store *store,
517{ 524{
518 struct pstore *ps = get_info(store); 525 struct pstore *ps = get_info(store);
519 uint32_t stride; 526 uint32_t stride;
527 chunk_t next_free;
520 sector_t size = get_dev_size(store->snap->cow->bdev); 528 sector_t size = get_dev_size(store->snap->cow->bdev);
521 529
522 /* Is there enough room ? */ 530 /* Is there enough room ? */
@@ -530,7 +538,8 @@ static int persistent_prepare(struct exception_store *store,
530 * into account the location of the metadata chunks. 538 * into account the location of the metadata chunks.
531 */ 539 */
532 stride = (ps->exceptions_per_area + 1); 540 stride = (ps->exceptions_per_area + 1);
533 if ((++ps->next_free % stride) == 1) 541 next_free = ++ps->next_free;
542 if (sector_div(next_free, stride) == 1)
534 ps->next_free++; 543 ps->next_free++;
535 544
536 atomic_inc(&ps->pending_count); 545 atomic_inc(&ps->pending_count);