1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

cache: move detection code to cache_set_policy

Move code which runtime detects settings for cache_policy
out of config dir to cache seg handling code.

Also mark cache_mode as command profilable setting.
This commit is contained in:
Zdenek Kabelac 2015-08-17 15:35:43 +02:00
parent 94c56559ca
commit 4b28383b1c
3 changed files with 35 additions and 28 deletions

View File

@ -2419,27 +2419,3 @@ int get_default_allocation_cache_pool_chunk_size_CFG(struct cmd_context *cmd, st
{ {
return DEFAULT_CACHE_POOL_CHUNK_SIZE * 2; return DEFAULT_CACHE_POOL_CHUNK_SIZE * 2;
} }
const char *get_default_allocation_cache_policy_CFG(struct cmd_context *cmd, struct profile *profile)
{
const struct segment_type *segtype = get_segtype_from_string(cmd, "cache");
unsigned attr = ~0;
if (!segtype ||
!segtype->ops->target_present ||
!segtype->ops->target_present(cmd, NULL, &attr)) {
log_warn("WARNING: Cannot detect default cache policy, using \""
DEFAULT_CACHE_POLICY "\".");
return DEFAULT_CACHE_POLICY;
}
if (attr & CACHE_FEATURE_POLICY_SMQ)
return "smq";
if (attr & CACHE_FEATURE_POLICY_MQ)
return "mq";
log_warn("WARNING: Default cache policy not available.");
return NULL;
}

View File

@ -466,7 +466,7 @@ cfg(allocation_cache_pool_cachemode_CFG, "cache_pool_cachemode", allocation_CFG_
"This has been replaced by the allocation/cache_mode setting.\n", "This has been replaced by the allocation/cache_mode setting.\n",
"Cache mode.\n") "Cache mode.\n")
cfg(allocation_cache_mode_CFG, "cache_mode", allocation_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, DEFAULT_CACHE_MODE, vsn(2, 2, 128), NULL, 0, NULL, cfg(allocation_cache_mode_CFG, "cache_mode", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, DEFAULT_CACHE_MODE, vsn(2, 2, 128), NULL, 0, NULL,
"The default cache mode used for new cache.\n" "The default cache mode used for new cache.\n"
"Possible options are: writethrough, writeback.\n" "Possible options are: writethrough, writeback.\n"
"writethrough - Data blocks are immediately written from\n" "writethrough - Data blocks are immediately written from\n"
@ -474,7 +474,7 @@ cfg(allocation_cache_mode_CFG, "cache_mode", allocation_CFG_SECTION, CFG_DEFAULT
"writeback - Data blocks are written from the cache back\n" "writeback - Data blocks are written from the cache back\n"
"to disk after some delay to improve performance.\n") "to disk after some delay to improve performance.\n")
cfg_runtime(allocation_cache_policy_CFG, "cache_policy", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, vsn(2, 2, 128), 0, NULL, cfg(allocation_cache_policy_CFG, "cache_policy", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, 0, vsn(2, 2, 128), NULL, 0, NULL,
"The default cache policy used for new cache volume.\n" "The default cache policy used for new cache volume.\n"
"For the kernel 4.2 and newer the default policy is smq\n" "For the kernel 4.2 and newer the default policy is smq\n"
"(Stochastic multique), otherwise the older mq (Multiqueue),\n" "(Stochastic multique), otherwise the older mq (Multiqueue),\n"

View File

@ -434,6 +434,34 @@ int lv_is_cache_origin(const struct logical_volume *lv)
return seg && lv_is_cache(seg->lv) && !lv_is_pending_delete(seg->lv) && (seg_lv(seg, 0) == lv); return seg && lv_is_cache(seg->lv) && !lv_is_pending_delete(seg->lv) && (seg_lv(seg, 0) == lv);
} }
static const char *_get_default_cache_policy(struct cmd_context *cmd)
{
const struct segment_type *segtype = get_segtype_from_string(cmd, "cache");
unsigned attr = ~0;
const char *def = NULL;
if (!segtype ||
!segtype->ops->target_present ||
!segtype->ops->target_present(cmd, NULL, &attr)) {
log_warn("WARNING: Cannot detect default cache policy, using \""
DEFAULT_CACHE_POLICY "\".");
return DEFAULT_CACHE_POLICY;
}
if (attr & CACHE_FEATURE_POLICY_SMQ)
def = "smq";
else if (attr & CACHE_FEATURE_POLICY_MQ)
def = "mq";
else {
log_error("Default cache policy is not available.");
return NULL;
}
log_debug_metadata("Detected default cache_policy \"%s\".", def);
return def;
}
int cache_set_policy(struct lv_segment *seg, const char *name, int cache_set_policy(struct lv_segment *seg, const char *name,
const struct dm_config_tree *settings) const struct dm_config_tree *settings)
{ {
@ -451,8 +479,11 @@ int cache_set_policy(struct lv_segment *seg, const char *name,
log_error("Failed to duplicate policy name."); log_error("Failed to duplicate policy name.");
return 0; return 0;
} }
} else if (!seg->policy_name && passed_seg_is_cache) } else if (!seg->policy_name && passed_seg_is_cache) {
seg->policy_name = find_config_tree_str(seg->lv->vg->cmd, allocation_cache_policy_CFG, NULL); if (!(seg->policy_name = find_config_tree_str(seg->lv->vg->cmd, allocation_cache_policy_CFG, NULL)) &&
!(seg->policy_name = _get_default_cache_policy(seg->lv->vg->cmd)))
return_0;
}
if (settings) { if (settings) {
if (!seg->policy_name) { if (!seg->policy_name) {