Commit df96eee679ba28c98cf722fa7c9f4286ee1ed0bd

Authored by Mikulas Patocka
Committed by Alasdair G Kergon
1 parent 4c6fff445d

dm snapshot: use unsigned integer chunk size

Use unsigned integer chunk size.

Maximum chunk size is 512kB, there won't ever be need to use 4GB chunk size,
so the number can be 32-bit. This fixes compiler failure on 32-bit systems
with large block devices.

Cc: stable@kernel.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Reviewed-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>

Showing 4 changed files with 25 additions and 23 deletions Side-by-side Diff

drivers/md/dm-exception-store.c
... ... @@ -155,7 +155,8 @@
155 155 char *value;
156 156  
157 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 160 *error = "Invalid chunk size";
160 161 return -EINVAL;
161 162 }
162 163  
163 164  
164 165  
165 166  
166 167  
... ... @@ -171,34 +172,35 @@
171 172 */
172 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 177 error);
176 178 }
177 179  
178 180 int dm_exception_store_set_chunk_size(struct dm_exception_store *store,
179   - unsigned long chunk_size_ulong,
  181 + unsigned chunk_size,
180 182 char **error)
181 183 {
182 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 186 *error = "Chunk size is not a power of 2";
185 187 return -EINVAL;
186 188 }
187 189  
188 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 192 *error = "Chunk size is not a multiple of device blocksize";
191 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 197 *error = "Chunk size is too high";
196 198 return -EINVAL;
197 199 }
198 200  
199   - store->chunk_size = chunk_size_ulong;
200   - store->chunk_mask = chunk_size_ulong - 1;
201   - store->chunk_shift = ffs(chunk_size_ulong) - 1;
  201 + store->chunk_size = chunk_size;
  202 + store->chunk_mask = chunk_size - 1;
  203 + store->chunk_shift = ffs(chunk_size) - 1;
202 204  
203 205 return 0;
204 206 }
drivers/md/dm-exception-store.h
... ... @@ -101,9 +101,9 @@
101 101 struct dm_dev *cow;
102 102  
103 103 /* Size of data blocks saved - must be a power of 2 */
104   - chunk_t chunk_size;
105   - chunk_t chunk_mask;
106   - chunk_t chunk_shift;
  104 + unsigned chunk_size;
  105 + unsigned chunk_mask;
  106 + unsigned chunk_shift;
107 107  
108 108 void *context;
109 109 };
... ... @@ -169,7 +169,7 @@
169 169 int dm_exception_store_type_unregister(struct dm_exception_store_type *type);
170 170  
171 171 int dm_exception_store_set_chunk_size(struct dm_exception_store *store,
172   - unsigned long chunk_size_ulong,
  172 + unsigned chunk_size,
173 173 char **error);
174 174  
175 175 int dm_exception_store_create(struct dm_target *ti, int argc, char **argv,
drivers/md/dm-snap-persistent.c
... ... @@ -284,12 +284,13 @@
284 284 {
285 285 int r;
286 286 struct disk_header *dh;
287   - chunk_t chunk_size;
  287 + unsigned chunk_size;
288 288 int chunk_size_supplied = 1;
289 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 295 if (!ps->store->chunk_size) {
295 296 ps->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS,
... ... @@ -334,10 +335,9 @@
334 335 return 0;
335 336  
336 337 if (chunk_size_supplied)
337   - DMWARN("chunk size %llu in device metadata overrides "
338   - "table chunk size of %llu.",
339   - (unsigned long long)chunk_size,
340   - (unsigned long long)ps->store->chunk_size);
  338 + DMWARN("chunk size %u in device metadata overrides "
  339 + "table chunk size of %u.",
  340 + chunk_size, ps->store->chunk_size);
341 341  
342 342 /* We had a bogus chunk_size. Fix stuff up. */
343 343 free_area(ps);
... ... @@ -345,8 +345,8 @@
345 345 r = dm_exception_store_set_chunk_size(ps->store, chunk_size,
346 346 &chunk_err);
347 347 if (r) {
348   - DMERR("invalid on-disk chunk size %llu: %s.",
349   - (unsigned long long)chunk_size, chunk_err);
  348 + DMERR("invalid on-disk chunk size %u: %s.",
  349 + chunk_size, chunk_err);
350 350 return r;
351 351 }
352 352  
drivers/md/dm-snap.c
... ... @@ -961,7 +961,7 @@
961 961  
962 962 src.bdev = bdev;
963 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 966 dest.bdev = s->store->cow->bdev;
967 967 dest.sector = chunk_to_sector(s->store, pe->e.new_chunk);
... ... @@ -1402,7 +1402,7 @@
1402 1402 struct dm_dev *dev = ti->private;
1403 1403 struct dm_snapshot *snap;
1404 1404 struct origin *o;
1405   - chunk_t chunk_size = 0;
  1405 + unsigned chunk_size = 0;
1406 1406  
1407 1407 down_read(&_origins_lock);
1408 1408 o = __lookup_origin(dev->bdev);