aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Snitzer <snitzer@redhat.com>2013-08-16 10:54:19 -0400
committerMike Snitzer <snitzer@redhat.com>2013-08-23 09:02:13 -0400
commit054730446315d2a9a41f4232ebf1d5034244d054 (patch)
treeeefe6fe46fc3d389932bcac4988d9a253649f599
parent66bb2644cac8b5cc1cc477959aa37dcfe6317a23 (diff)
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: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com> Acked-by: Joe Thornber <ejt@redhat.com>
-rw-r--r--Documentation/device-mapper/cache.txt3
-rw-r--r--drivers/md/dm-cache-target.c17
2 files changed, 12 insertions, 8 deletions
diff --git a/Documentation/device-mapper/cache.txt b/Documentation/device-mapper/cache.txt
index af99c458c841..33d45ee0b737 100644
--- a/Documentation/device-mapper/cache.txt
+++ b/Documentation/device-mapper/cache.txt
@@ -58,7 +58,8 @@ Fixed block size
58 58
59The origin is divided up into blocks of a fixed size. This block size 59The origin is divided up into blocks of a fixed size. This block size
60is configurable when you first create the cache. Typically we've been 60is configurable when you first create the cache. Typically we've been
61using block sizes of 256k - 1024k. 61using block sizes of 256KB - 1024KB. The block size must be between 64
62(32KB) and 2097152 (1GB) and a multiple of 64 (32KB).
62 63
63Having a fixed block size simplifies the target a lot. But it is 64Having a fixed block size simplifies the target a lot. But it is
64something of a compromise. For instance, a small part of a block may be 65something of a compromise. For instance, a small part of a block may be
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 0df3ec085ebb..31985ea81408 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -67,9 +67,11 @@ static void free_bitset(unsigned long *bits)
67#define MIGRATION_COUNT_WINDOW 10 67#define MIGRATION_COUNT_WINDOW 10
68 68
69/* 69/*
70 * The block size of the device holding cache data must be >= 32KB 70 * The block size of the device holding cache data must be
71 * between 32KB and 1GB.
71 */ 72 */
72#define DATA_DEV_BLOCK_SIZE_MIN_SECTORS (32 * 1024 >> SECTOR_SHIFT) 73#define DATA_DEV_BLOCK_SIZE_MIN_SECTORS (32 * 1024 >> SECTOR_SHIFT)
74#define DATA_DEV_BLOCK_SIZE_MAX_SECTORS (1024 * 1024 * 1024 >> SECTOR_SHIFT)
73 75
74/* 76/*
75 * FIXME: the cache is read/write for the time being. 77 * 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,
1687static int parse_block_size(struct cache_args *ca, struct dm_arg_set *as, 1689static int parse_block_size(struct cache_args *ca, struct dm_arg_set *as,
1688 char **error) 1690 char **error)
1689{ 1691{
1690 unsigned long tmp; 1692 unsigned long block_size;
1691 1693
1692 if (!at_least_one_arg(as, error)) 1694 if (!at_least_one_arg(as, error))
1693 return -EINVAL; 1695 return -EINVAL;
1694 1696
1695 if (kstrtoul(dm_shift_arg(as), 10, &tmp) || !tmp || 1697 if (kstrtoul(dm_shift_arg(as), 10, &block_size) || !block_size ||
1696 tmp < DATA_DEV_BLOCK_SIZE_MIN_SECTORS || 1698 block_size < DATA_DEV_BLOCK_SIZE_MIN_SECTORS ||
1697 tmp & (DATA_DEV_BLOCK_SIZE_MIN_SECTORS - 1)) { 1699 block_size > DATA_DEV_BLOCK_SIZE_MAX_SECTORS ||
1700 block_size & (DATA_DEV_BLOCK_SIZE_MIN_SECTORS - 1)) {
1698 *error = "Invalid data block size"; 1701 *error = "Invalid data block size";
1699 return -EINVAL; 1702 return -EINVAL;
1700 } 1703 }
1701 1704
1702 if (tmp > ca->cache_sectors) { 1705 if (block_size > ca->cache_sectors) {
1703 *error = "Data block size is larger than the cache device"; 1706 *error = "Data block size is larger than the cache device";
1704 return -EINVAL; 1707 return -EINVAL;
1705 } 1708 }
1706 1709
1707 ca->block_size = tmp; 1710 ca->block_size = block_size;
1708 1711
1709 return 0; 1712 return 0;
1710} 1713}