diff options
-rw-r--r-- | drivers/md/dm-exception-store.c | 20 | ||||
-rw-r--r-- | drivers/md/dm-exception-store.h | 8 | ||||
-rw-r--r-- | drivers/md/dm-snap-persistent.c | 16 | ||||
-rw-r--r-- | drivers/md/dm-snap.c | 4 |
4 files changed, 25 insertions, 23 deletions
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c index e5de7627c52d..932d1b123143 100644 --- a/drivers/md/dm-exception-store.c +++ b/drivers/md/dm-exception-store.c | |||
@@ -155,7 +155,8 @@ static int set_chunk_size(struct dm_exception_store *store, | |||
155 | char *value; | 155 | char *value; |
156 | 156 | ||
157 | chunk_size_ulong = simple_strtoul(chunk_size_arg, &value, 10); | 157 | chunk_size_ulong = simple_strtoul(chunk_size_arg, &value, 10); |
158 | if (*chunk_size_arg == '\0' || *value != '\0') { | 158 | if (*chunk_size_arg == '\0' || *value != '\0' || |
159 | chunk_size_ulong > UINT_MAX) { | ||
159 | *error = "Invalid chunk size"; | 160 | *error = "Invalid chunk size"; |
160 | return -EINVAL; | 161 | return -EINVAL; |
161 | } | 162 | } |
@@ -171,34 +172,35 @@ static int set_chunk_size(struct dm_exception_store *store, | |||
171 | */ | 172 | */ |
172 | chunk_size_ulong = round_up(chunk_size_ulong, PAGE_SIZE >> 9); | 173 | chunk_size_ulong = round_up(chunk_size_ulong, PAGE_SIZE >> 9); |
173 | 174 | ||
174 | return dm_exception_store_set_chunk_size(store, chunk_size_ulong, | 175 | return dm_exception_store_set_chunk_size(store, |
176 | (unsigned) chunk_size_ulong, | ||
175 | error); | 177 | error); |
176 | } | 178 | } |
177 | 179 | ||
178 | int dm_exception_store_set_chunk_size(struct dm_exception_store *store, | 180 | int dm_exception_store_set_chunk_size(struct dm_exception_store *store, |
179 | unsigned long chunk_size_ulong, | 181 | unsigned chunk_size, |
180 | char **error) | 182 | char **error) |
181 | { | 183 | { |
182 | /* Check chunk_size is a power of 2 */ | 184 | /* Check chunk_size is a power of 2 */ |
183 | if (!is_power_of_2(chunk_size_ulong)) { | 185 | if (!is_power_of_2(chunk_size)) { |
184 | *error = "Chunk size is not a power of 2"; | 186 | *error = "Chunk size is not a power of 2"; |
185 | return -EINVAL; | 187 | return -EINVAL; |
186 | } | 188 | } |
187 | 189 | ||
188 | /* Validate the chunk size against the device block size */ | 190 | /* Validate the chunk size against the device block size */ |
189 | if (chunk_size_ulong % (bdev_logical_block_size(store->cow->bdev) >> 9)) { | 191 | if (chunk_size % (bdev_logical_block_size(store->cow->bdev) >> 9)) { |
190 | *error = "Chunk size is not a multiple of device blocksize"; | 192 | *error = "Chunk size is not a multiple of device blocksize"; |
191 | return -EINVAL; | 193 | return -EINVAL; |
192 | } | 194 | } |
193 | 195 | ||
194 | if (chunk_size_ulong > INT_MAX >> SECTOR_SHIFT) { | 196 | if (chunk_size > INT_MAX >> SECTOR_SHIFT) { |
195 | *error = "Chunk size is too high"; | 197 | *error = "Chunk size is too high"; |
196 | return -EINVAL; | 198 | return -EINVAL; |
197 | } | 199 | } |
198 | 200 | ||
199 | store->chunk_size = chunk_size_ulong; | 201 | store->chunk_size = chunk_size; |
200 | store->chunk_mask = chunk_size_ulong - 1; | 202 | store->chunk_mask = chunk_size - 1; |
201 | store->chunk_shift = ffs(chunk_size_ulong) - 1; | 203 | store->chunk_shift = ffs(chunk_size) - 1; |
202 | 204 | ||
203 | return 0; | 205 | return 0; |
204 | } | 206 | } |
diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h index 812c71872ba0..8a223a48802c 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h | |||
@@ -101,9 +101,9 @@ struct dm_exception_store { | |||
101 | struct dm_dev *cow; | 101 | struct dm_dev *cow; |
102 | 102 | ||
103 | /* Size of data blocks saved - must be a power of 2 */ | 103 | /* Size of data blocks saved - must be a power of 2 */ |
104 | chunk_t chunk_size; | 104 | unsigned chunk_size; |
105 | chunk_t chunk_mask; | 105 | unsigned chunk_mask; |
106 | chunk_t chunk_shift; | 106 | unsigned chunk_shift; |
107 | 107 | ||
108 | void *context; | 108 | void *context; |
109 | }; | 109 | }; |
@@ -169,7 +169,7 @@ int dm_exception_store_type_register(struct dm_exception_store_type *type); | |||
169 | int dm_exception_store_type_unregister(struct dm_exception_store_type *type); | 169 | int dm_exception_store_type_unregister(struct dm_exception_store_type *type); |
170 | 170 | ||
171 | int dm_exception_store_set_chunk_size(struct dm_exception_store *store, | 171 | int dm_exception_store_set_chunk_size(struct dm_exception_store *store, |
172 | unsigned long chunk_size_ulong, | 172 | unsigned chunk_size, |
173 | char **error); | 173 | char **error); |
174 | 174 | ||
175 | int dm_exception_store_create(struct dm_target *ti, int argc, char **argv, | 175 | int dm_exception_store_create(struct dm_target *ti, int argc, char **argv, |
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c index d5b2e08750d5..0c746420c008 100644 --- a/drivers/md/dm-snap-persistent.c +++ b/drivers/md/dm-snap-persistent.c | |||
@@ -284,12 +284,13 @@ static int read_header(struct pstore *ps, int *new_snapshot) | |||
284 | { | 284 | { |
285 | int r; | 285 | int r; |
286 | struct disk_header *dh; | 286 | struct disk_header *dh; |
287 | chunk_t chunk_size; | 287 | unsigned chunk_size; |
288 | int chunk_size_supplied = 1; | 288 | int chunk_size_supplied = 1; |
289 | char *chunk_err; | 289 | char *chunk_err; |
290 | 290 | ||
291 | /* | 291 | /* |
292 | * Use default chunk size (or hardsect_size, if larger) if none supplied | 292 | * Use default chunk size (or logical_block_size, if larger) |
293 | * if none supplied | ||
293 | */ | 294 | */ |
294 | if (!ps->store->chunk_size) { | 295 | if (!ps->store->chunk_size) { |
295 | ps->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS, | 296 | ps->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS, |
@@ -334,10 +335,9 @@ static int read_header(struct pstore *ps, int *new_snapshot) | |||
334 | return 0; | 335 | return 0; |
335 | 336 | ||
336 | if (chunk_size_supplied) | 337 | if (chunk_size_supplied) |
337 | DMWARN("chunk size %llu in device metadata overrides " | 338 | DMWARN("chunk size %u in device metadata overrides " |
338 | "table chunk size of %llu.", | 339 | "table chunk size of %u.", |
339 | (unsigned long long)chunk_size, | 340 | chunk_size, ps->store->chunk_size); |
340 | (unsigned long long)ps->store->chunk_size); | ||
341 | 341 | ||
342 | /* We had a bogus chunk_size. Fix stuff up. */ | 342 | /* We had a bogus chunk_size. Fix stuff up. */ |
343 | free_area(ps); | 343 | free_area(ps); |
@@ -345,8 +345,8 @@ static int read_header(struct pstore *ps, int *new_snapshot) | |||
345 | r = dm_exception_store_set_chunk_size(ps->store, chunk_size, | 345 | r = dm_exception_store_set_chunk_size(ps->store, chunk_size, |
346 | &chunk_err); | 346 | &chunk_err); |
347 | if (r) { | 347 | if (r) { |
348 | DMERR("invalid on-disk chunk size %llu: %s.", | 348 | DMERR("invalid on-disk chunk size %u: %s.", |
349 | (unsigned long long)chunk_size, chunk_err); | 349 | chunk_size, chunk_err); |
350 | return r; | 350 | return r; |
351 | } | 351 | } |
352 | 352 | ||
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 9bc814aa2bbd..3a3ba46e6d4b 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c | |||
@@ -961,7 +961,7 @@ static void start_copy(struct dm_snap_pending_exception *pe) | |||
961 | 961 | ||
962 | src.bdev = bdev; | 962 | src.bdev = bdev; |
963 | src.sector = chunk_to_sector(s->store, pe->e.old_chunk); | 963 | src.sector = chunk_to_sector(s->store, pe->e.old_chunk); |
964 | src.count = min(s->store->chunk_size, dev_size - src.sector); | 964 | src.count = min((sector_t)s->store->chunk_size, dev_size - src.sector); |
965 | 965 | ||
966 | dest.bdev = s->store->cow->bdev; | 966 | dest.bdev = s->store->cow->bdev; |
967 | dest.sector = chunk_to_sector(s->store, pe->e.new_chunk); | 967 | dest.sector = chunk_to_sector(s->store, pe->e.new_chunk); |
@@ -1402,7 +1402,7 @@ static void origin_resume(struct dm_target *ti) | |||
1402 | struct dm_dev *dev = ti->private; | 1402 | struct dm_dev *dev = ti->private; |
1403 | struct dm_snapshot *snap; | 1403 | struct dm_snapshot *snap; |
1404 | struct origin *o; | 1404 | struct origin *o; |
1405 | chunk_t chunk_size = 0; | 1405 | unsigned chunk_size = 0; |
1406 | 1406 | ||
1407 | down_read(&_origins_lock); | 1407 | down_read(&_origins_lock); |
1408 | o = __lookup_origin(dev->bdev); | 1408 | o = __lookup_origin(dev->bdev); |