Commit 05473044 authored by Mike Snitzer's avatar Mike Snitzer

dm cache: add data block size limits to code and Documentation

Place upper bound on the cache's data block size (1GB).

Inform users that the data block size can't be any arbitrary number,
i.e. its value must be between 32KB and 1GB.  Also, it should be a
multiple of 32KB.
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
Acked-by: default avatarJoe Thornber <ejt@redhat.com>
parent 66bb2644
...@@ -58,7 +58,8 @@ Fixed block size ...@@ -58,7 +58,8 @@ Fixed block size
The origin is divided up into blocks of a fixed size. This block size The origin is divided up into blocks of a fixed size. This block size
is configurable when you first create the cache. Typically we've been is configurable when you first create the cache. Typically we've been
using block sizes of 256k - 1024k. using block sizes of 256KB - 1024KB. The block size must be between 64
(32KB) and 2097152 (1GB) and a multiple of 64 (32KB).
Having a fixed block size simplifies the target a lot. But it is Having a fixed block size simplifies the target a lot. But it is
something of a compromise. For instance, a small part of a block may be something of a compromise. For instance, a small part of a block may be
......
...@@ -67,9 +67,11 @@ static void free_bitset(unsigned long *bits) ...@@ -67,9 +67,11 @@ static void free_bitset(unsigned long *bits)
#define MIGRATION_COUNT_WINDOW 10 #define MIGRATION_COUNT_WINDOW 10
/* /*
* The block size of the device holding cache data must be >= 32KB * The block size of the device holding cache data must be
* between 32KB and 1GB.
*/ */
#define DATA_DEV_BLOCK_SIZE_MIN_SECTORS (32 * 1024 >> SECTOR_SHIFT) #define DATA_DEV_BLOCK_SIZE_MIN_SECTORS (32 * 1024 >> SECTOR_SHIFT)
#define DATA_DEV_BLOCK_SIZE_MAX_SECTORS (1024 * 1024 * 1024 >> SECTOR_SHIFT)
/* /*
* FIXME: the cache is read/write for the time being. * FIXME: the cache is read/write for the time being.
...@@ -1687,24 +1689,25 @@ static int parse_origin_dev(struct cache_args *ca, struct dm_arg_set *as, ...@@ -1687,24 +1689,25 @@ static int parse_origin_dev(struct cache_args *ca, struct dm_arg_set *as,
static int parse_block_size(struct cache_args *ca, struct dm_arg_set *as, static int parse_block_size(struct cache_args *ca, struct dm_arg_set *as,
char **error) char **error)
{ {
unsigned long tmp; unsigned long block_size;
if (!at_least_one_arg(as, error)) if (!at_least_one_arg(as, error))
return -EINVAL; return -EINVAL;
if (kstrtoul(dm_shift_arg(as), 10, &tmp) || !tmp || if (kstrtoul(dm_shift_arg(as), 10, &block_size) || !block_size ||
tmp < DATA_DEV_BLOCK_SIZE_MIN_SECTORS || block_size < DATA_DEV_BLOCK_SIZE_MIN_SECTORS ||
tmp & (DATA_DEV_BLOCK_SIZE_MIN_SECTORS - 1)) { block_size > DATA_DEV_BLOCK_SIZE_MAX_SECTORS ||
block_size & (DATA_DEV_BLOCK_SIZE_MIN_SECTORS - 1)) {
*error = "Invalid data block size"; *error = "Invalid data block size";
return -EINVAL; return -EINVAL;
} }
if (tmp > ca->cache_sectors) { if (block_size > ca->cache_sectors) {
*error = "Data block size is larger than the cache device"; *error = "Data block size is larger than the cache device";
return -EINVAL; return -EINVAL;
} }
ca->block_size = tmp; ca->block_size = block_size;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment