From feb8e9a7907c91bd55769b4e3ae625434f2ba589 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sun, 26 Jul 2015 23:05:11 +0200 Subject: [PATCH] cache: runtime detect default policy When the policy is not preset in lvm.conf, detect in runtime whether to use 'mq' or new available 'smq'. --- WHATS_NEW | 1 + lib/config/config.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/WHATS_NEW b/WHATS_NEW index 347fcd48f..da0ef4dd0 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.128 - =================================== + Runtime detect presence of cache smq policy. Add demo cache-mq and cache-smq profiles. Add cmd profilable allocation/cache_policy,cache_settings,cache_mode. Require cache_check 0.5.4 for use of --clear-needs-check-flag. diff --git a/lib/config/config.c b/lib/config/config.c index 436efff15..cd6c1d808 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -23,6 +23,7 @@ #include "toolcontext.h" #include "lvm-file.h" #include "memlock.h" +#include "segtype.h" #include #include @@ -2418,5 +2419,24 @@ int get_default_allocation_cache_pool_chunk_size_CFG(struct cmd_context *cmd, st const char *get_default_allocation_cache_policy_CFG(struct cmd_context *cmd, struct profile *profile) { - return DEFAULT_CACHE_POLICY; + 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; }