dm snapshot: fix on disk chunk size validation
Fix some problems seen in the chunk size processing when activating a pre-existing snapshot. For a new snapshot, the chunk size can either be supplied by the creator or a default value can be used. For an existing snapshot, the chunk size in the snapshot header on disk should always be used. If someone attempts to load an existing snapshot and has the 'default chunk size' option set, the kernel uses its default value even when it is incorrect for the snapshot being loaded. This patch ensures the correct on-disk value is always used. Secondly, when the code does use the chunk size stored on the disk it is prudent to revalidate it, so the code can exit cleanly if it got corrupted as happened in https://bugzilla.redhat.com/show_bug.cgi?id=461506 . Cc: stable@kernel.org Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
This commit is contained in:
parent
2defcc3fb4
commit
ae0b7448e9
|
@ -191,6 +191,11 @@ int dm_exception_store_set_chunk_size(struct dm_exception_store *store,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chunk_size_ulong > INT_MAX >> SECTOR_SHIFT) {
|
||||||
|
*error = "Chunk size is too high";
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
store->chunk_size = chunk_size_ulong;
|
store->chunk_size = chunk_size_ulong;
|
||||||
store->chunk_mask = chunk_size_ulong - 1;
|
store->chunk_mask = chunk_size_ulong - 1;
|
||||||
store->chunk_shift = ffs(chunk_size_ulong) - 1;
|
store->chunk_shift = ffs(chunk_size_ulong) - 1;
|
||||||
|
|
|
@ -286,6 +286,7 @@ static int read_header(struct pstore *ps, int *new_snapshot)
|
||||||
struct disk_header *dh;
|
struct disk_header *dh;
|
||||||
chunk_t chunk_size;
|
chunk_t chunk_size;
|
||||||
int chunk_size_supplied = 1;
|
int chunk_size_supplied = 1;
|
||||||
|
char *chunk_err;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use default chunk size (or hardsect_size, if larger) if none supplied
|
* Use default chunk size (or hardsect_size, if larger) if none supplied
|
||||||
|
@ -329,9 +330,10 @@ static int read_header(struct pstore *ps, int *new_snapshot)
|
||||||
ps->version = le32_to_cpu(dh->version);
|
ps->version = le32_to_cpu(dh->version);
|
||||||
chunk_size = le32_to_cpu(dh->chunk_size);
|
chunk_size = le32_to_cpu(dh->chunk_size);
|
||||||
|
|
||||||
if (!chunk_size_supplied || ps->store->chunk_size == chunk_size)
|
if (ps->store->chunk_size == chunk_size)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (chunk_size_supplied)
|
||||||
DMWARN("chunk size %llu in device metadata overrides "
|
DMWARN("chunk size %llu in device metadata overrides "
|
||||||
"table chunk size of %llu.",
|
"table chunk size of %llu.",
|
||||||
(unsigned long long)chunk_size,
|
(unsigned long long)chunk_size,
|
||||||
|
@ -340,9 +342,13 @@ static int read_header(struct pstore *ps, int *new_snapshot)
|
||||||
/* We had a bogus chunk_size. Fix stuff up. */
|
/* We had a bogus chunk_size. Fix stuff up. */
|
||||||
free_area(ps);
|
free_area(ps);
|
||||||
|
|
||||||
ps->store->chunk_size = chunk_size;
|
r = dm_exception_store_set_chunk_size(ps->store, chunk_size,
|
||||||
ps->store->chunk_mask = chunk_size - 1;
|
&chunk_err);
|
||||||
ps->store->chunk_shift = ffs(chunk_size) - 1;
|
if (r) {
|
||||||
|
DMERR("invalid on-disk chunk size %llu: %s.",
|
||||||
|
(unsigned long long)chunk_size, chunk_err);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
r = dm_io_client_resize(sectors_to_pages(ps->store->chunk_size),
|
r = dm_io_client_resize(sectors_to_pages(ps->store->chunk_size),
|
||||||
ps->io_client);
|
ps->io_client);
|
||||||
|
|
Loading…
Reference in New Issue