aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2013-05-10 09:37:21 -0400
committerAlasdair G Kergon <agk@redhat.com>2013-05-10 09:37:21 -0400
commit2f14f4b51ed34fe2b704af8df178f5cd8c81f65e (patch)
treeda47c5a3bbb49435588898f7cfc19f39eb26fa01 /drivers/md
parent2c73c471fb3b1e127df1efda506e796b83da44d2 (diff)
dm cache: set config value
Share configuration option processing code between the dm cache ctr and message functions. Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm-cache-target.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 5159e25ea082..df44b60e66f2 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -1813,12 +1813,12 @@ static struct kmem_cache *migration_cache;
1813 1813
1814#define NOT_CORE_OPTION 1 1814#define NOT_CORE_OPTION 1
1815 1815
1816static int process_config_option(struct cache *cache, char **argv) 1816static int process_config_option(struct cache *cache, const char *key, const char *value)
1817{ 1817{
1818 unsigned long tmp; 1818 unsigned long tmp;
1819 1819
1820 if (!strcasecmp(argv[0], "migration_threshold")) { 1820 if (!strcasecmp(key, "migration_threshold")) {
1821 if (kstrtoul(argv[1], 10, &tmp)) 1821 if (kstrtoul(value, 10, &tmp))
1822 return -EINVAL; 1822 return -EINVAL;
1823 1823
1824 cache->migration_threshold = tmp; 1824 cache->migration_threshold = tmp;
@@ -1828,7 +1828,20 @@ static int process_config_option(struct cache *cache, char **argv)
1828 return NOT_CORE_OPTION; 1828 return NOT_CORE_OPTION;
1829} 1829}
1830 1830
1831static int set_config_values(struct dm_cache_policy *p, int argc, const char **argv) 1831static int set_config_value(struct cache *cache, const char *key, const char *value)
1832{
1833 int r = process_config_option(cache, key, value);
1834
1835 if (r == NOT_CORE_OPTION)
1836 r = policy_set_config_value(cache->policy, key, value);
1837
1838 if (r)
1839 DMWARN("bad config value for %s: %s", key, value);
1840
1841 return r;
1842}
1843
1844static int set_config_values(struct cache *cache, int argc, const char **argv)
1832{ 1845{
1833 int r = 0; 1846 int r = 0;
1834 1847
@@ -1838,12 +1851,9 @@ static int set_config_values(struct dm_cache_policy *p, int argc, const char **a
1838 } 1851 }
1839 1852
1840 while (argc) { 1853 while (argc) {
1841 r = policy_set_config_value(p, argv[0], argv[1]); 1854 r = set_config_value(cache, argv[0], argv[1]);
1842 if (r) { 1855 if (r)
1843 DMWARN("policy_set_config_value failed: key = '%s', value = '%s'", 1856 break;
1844 argv[0], argv[1]);
1845 return r;
1846 }
1847 1857
1848 argc -= 2; 1858 argc -= 2;
1849 argv += 2; 1859 argv += 2;
@@ -1855,8 +1865,6 @@ static int set_config_values(struct dm_cache_policy *p, int argc, const char **a
1855static int create_cache_policy(struct cache *cache, struct cache_args *ca, 1865static int create_cache_policy(struct cache *cache, struct cache_args *ca,
1856 char **error) 1866 char **error)
1857{ 1867{
1858 int r;
1859
1860 cache->policy = dm_cache_policy_create(ca->policy_name, 1868 cache->policy = dm_cache_policy_create(ca->policy_name,
1861 cache->cache_size, 1869 cache->cache_size,
1862 cache->origin_sectors, 1870 cache->origin_sectors,
@@ -1866,14 +1874,7 @@ static int create_cache_policy(struct cache *cache, struct cache_args *ca,
1866 return -ENOMEM; 1874 return -ENOMEM;
1867 } 1875 }
1868 1876
1869 r = set_config_values(cache->policy, ca->policy_argc, ca->policy_argv); 1877 return 0;
1870 if (r) {
1871 *error = "Error setting cache policy's config values";
1872 dm_cache_policy_destroy(cache->policy);
1873 cache->policy = NULL;
1874 }
1875
1876 return r;
1877} 1878}
1878 1879
1879/* 1880/*
@@ -1967,7 +1968,15 @@ static int cache_create(struct cache_args *ca, struct cache **result)
1967 r = create_cache_policy(cache, ca, error); 1968 r = create_cache_policy(cache, ca, error);
1968 if (r) 1969 if (r)
1969 goto bad; 1970 goto bad;
1971
1970 cache->policy_nr_args = ca->policy_argc; 1972 cache->policy_nr_args = ca->policy_argc;
1973 cache->migration_threshold = DEFAULT_MIGRATION_THRESHOLD;
1974
1975 r = set_config_values(cache, ca->policy_argc, ca->policy_argv);
1976 if (r) {
1977 *error = "Error setting cache policy's config values";
1978 goto bad;
1979 }
1971 1980
1972 cmd = dm_cache_metadata_open(cache->metadata_dev->bdev, 1981 cmd = dm_cache_metadata_open(cache->metadata_dev->bdev,
1973 ca->block_size, may_format, 1982 ca->block_size, may_format,
@@ -1986,7 +1995,6 @@ static int cache_create(struct cache_args *ca, struct cache **result)
1986 INIT_LIST_HEAD(&cache->quiesced_migrations); 1995 INIT_LIST_HEAD(&cache->quiesced_migrations);
1987 INIT_LIST_HEAD(&cache->completed_migrations); 1996 INIT_LIST_HEAD(&cache->completed_migrations);
1988 INIT_LIST_HEAD(&cache->need_commit_migrations); 1997 INIT_LIST_HEAD(&cache->need_commit_migrations);
1989 cache->migration_threshold = DEFAULT_MIGRATION_THRESHOLD;
1990 atomic_set(&cache->nr_migrations, 0); 1998 atomic_set(&cache->nr_migrations, 0);
1991 init_waitqueue_head(&cache->migration_wait); 1999 init_waitqueue_head(&cache->migration_wait);
1992 2000
@@ -2544,17 +2552,12 @@ err:
2544 */ 2552 */
2545static int cache_message(struct dm_target *ti, unsigned argc, char **argv) 2553static int cache_message(struct dm_target *ti, unsigned argc, char **argv)
2546{ 2554{
2547 int r;
2548 struct cache *cache = ti->private; 2555 struct cache *cache = ti->private;
2549 2556
2550 if (argc != 2) 2557 if (argc != 2)
2551 return -EINVAL; 2558 return -EINVAL;
2552 2559
2553 r = process_config_option(cache, argv); 2560 return set_config_value(cache, argv[0], argv[1]);
2554 if (r == NOT_CORE_OPTION)
2555 return policy_set_config_value(cache->policy, argv[0], argv[1]);
2556
2557 return r;
2558} 2561}
2559 2562
2560static int cache_iterate_devices(struct dm_target *ti, 2563static 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 2615
2613static struct target_type cache_target = { 2616static struct target_type cache_target = {
2614 .name = "cache", 2617 .name = "cache",
2615 .version = {1, 1, 0}, 2618 .version = {1, 1, 1},
2616 .module = THIS_MODULE, 2619 .module = THIS_MODULE,
2617 .ctr = cache_ctr, 2620 .ctr = cache_ctr,
2618 .dtr = cache_dtr, 2621 .dtr = cache_dtr,