Commit 2f14f4b5 authored by Joe Thornber's avatar Joe Thornber Committed by Alasdair G Kergon

dm cache: set config value

Share configuration option processing code between the dm cache
ctr and message functions.
Signed-off-by: default avatarJoe Thornber <ejt@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 2c73c471
...@@ -1813,12 +1813,12 @@ static struct kmem_cache *migration_cache; ...@@ -1813,12 +1813,12 @@ static struct kmem_cache *migration_cache;
#define NOT_CORE_OPTION 1 #define NOT_CORE_OPTION 1
static int process_config_option(struct cache *cache, char **argv) static int process_config_option(struct cache *cache, const char *key, const char *value)
{ {
unsigned long tmp; unsigned long tmp;
if (!strcasecmp(argv[0], "migration_threshold")) { if (!strcasecmp(key, "migration_threshold")) {
if (kstrtoul(argv[1], 10, &tmp)) if (kstrtoul(value, 10, &tmp))
return -EINVAL; return -EINVAL;
cache->migration_threshold = tmp; cache->migration_threshold = tmp;
...@@ -1828,7 +1828,20 @@ static int process_config_option(struct cache *cache, char **argv) ...@@ -1828,7 +1828,20 @@ static int process_config_option(struct cache *cache, char **argv)
return NOT_CORE_OPTION; return NOT_CORE_OPTION;
} }
static int set_config_values(struct dm_cache_policy *p, int argc, const char **argv) static int set_config_value(struct cache *cache, const char *key, const char *value)
{
int r = process_config_option(cache, key, value);
if (r == NOT_CORE_OPTION)
r = policy_set_config_value(cache->policy, key, value);
if (r)
DMWARN("bad config value for %s: %s", key, value);
return r;
}
static int set_config_values(struct cache *cache, int argc, const char **argv)
{ {
int r = 0; int r = 0;
...@@ -1838,12 +1851,9 @@ static int set_config_values(struct dm_cache_policy *p, int argc, const char **a ...@@ -1838,12 +1851,9 @@ static int set_config_values(struct dm_cache_policy *p, int argc, const char **a
} }
while (argc) { while (argc) {
r = policy_set_config_value(p, argv[0], argv[1]); r = set_config_value(cache, argv[0], argv[1]);
if (r) { if (r)
DMWARN("policy_set_config_value failed: key = '%s', value = '%s'", break;
argv[0], argv[1]);
return r;
}
argc -= 2; argc -= 2;
argv += 2; argv += 2;
...@@ -1855,8 +1865,6 @@ static int set_config_values(struct dm_cache_policy *p, int argc, const char **a ...@@ -1855,8 +1865,6 @@ static int set_config_values(struct dm_cache_policy *p, int argc, const char **a
static int create_cache_policy(struct cache *cache, struct cache_args *ca, static int create_cache_policy(struct cache *cache, struct cache_args *ca,
char **error) char **error)
{ {
int r;
cache->policy = dm_cache_policy_create(ca->policy_name, cache->policy = dm_cache_policy_create(ca->policy_name,
cache->cache_size, cache->cache_size,
cache->origin_sectors, cache->origin_sectors,
...@@ -1866,14 +1874,7 @@ static int create_cache_policy(struct cache *cache, struct cache_args *ca, ...@@ -1866,14 +1874,7 @@ static int create_cache_policy(struct cache *cache, struct cache_args *ca,
return -ENOMEM; return -ENOMEM;
} }
r = set_config_values(cache->policy, ca->policy_argc, ca->policy_argv); return 0;
if (r) {
*error = "Error setting cache policy's config values";
dm_cache_policy_destroy(cache->policy);
cache->policy = NULL;
}
return r;
} }
/* /*
...@@ -1967,7 +1968,15 @@ static int cache_create(struct cache_args *ca, struct cache **result) ...@@ -1967,7 +1968,15 @@ static int cache_create(struct cache_args *ca, struct cache **result)
r = create_cache_policy(cache, ca, error); r = create_cache_policy(cache, ca, error);
if (r) if (r)
goto bad; goto bad;
cache->policy_nr_args = ca->policy_argc; cache->policy_nr_args = ca->policy_argc;
cache->migration_threshold = DEFAULT_MIGRATION_THRESHOLD;
r = set_config_values(cache, ca->policy_argc, ca->policy_argv);
if (r) {
*error = "Error setting cache policy's config values";
goto bad;
}
cmd = dm_cache_metadata_open(cache->metadata_dev->bdev, cmd = dm_cache_metadata_open(cache->metadata_dev->bdev,
ca->block_size, may_format, ca->block_size, may_format,
...@@ -1986,7 +1995,6 @@ static int cache_create(struct cache_args *ca, struct cache **result) ...@@ -1986,7 +1995,6 @@ static int cache_create(struct cache_args *ca, struct cache **result)
INIT_LIST_HEAD(&cache->quiesced_migrations); INIT_LIST_HEAD(&cache->quiesced_migrations);
INIT_LIST_HEAD(&cache->completed_migrations); INIT_LIST_HEAD(&cache->completed_migrations);
INIT_LIST_HEAD(&cache->need_commit_migrations); INIT_LIST_HEAD(&cache->need_commit_migrations);
cache->migration_threshold = DEFAULT_MIGRATION_THRESHOLD;
atomic_set(&cache->nr_migrations, 0); atomic_set(&cache->nr_migrations, 0);
init_waitqueue_head(&cache->migration_wait); init_waitqueue_head(&cache->migration_wait);
...@@ -2544,17 +2552,12 @@ static void cache_status(struct dm_target *ti, status_type_t type, ...@@ -2544,17 +2552,12 @@ static void cache_status(struct dm_target *ti, status_type_t type,
*/ */
static int cache_message(struct dm_target *ti, unsigned argc, char **argv) static int cache_message(struct dm_target *ti, unsigned argc, char **argv)
{ {
int r;
struct cache *cache = ti->private; struct cache *cache = ti->private;
if (argc != 2) if (argc != 2)
return -EINVAL; return -EINVAL;
r = process_config_option(cache, argv); return set_config_value(cache, argv[0], argv[1]);
if (r == NOT_CORE_OPTION)
return policy_set_config_value(cache->policy, argv[0], argv[1]);
return r;
} }
static int cache_iterate_devices(struct dm_target *ti, static int cache_iterate_devices(struct dm_target *ti,
...@@ -2612,7 +2615,7 @@ static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits) ...@@ -2612,7 +2615,7 @@ static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits)
static struct target_type cache_target = { static struct target_type cache_target = {
.name = "cache", .name = "cache",
.version = {1, 1, 0}, .version = {1, 1, 1},
.module = THIS_MODULE, .module = THIS_MODULE,
.ctr = cache_ctr, .ctr = cache_ctr,
.dtr = cache_dtr, .dtr = cache_dtr,
......
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