diff options
author | Petr Rockai <prockai@redhat.com> | 2014-11-20 12:05:40 +0100 |
---|---|---|
committer | Petr Rockai <prockai@redhat.com> | 2014-11-20 16:51:07 +0100 |
commit | c75ae0846e4c1a74fbd44d85837e2b6dc50e9783 (patch) | |
tree | 75b6b98d4b5f089bbf35a22212c17b2363a3ad4b | |
parent | 4b9b8e12825d5611d3b8d73aa8e381a4caffff5a (diff) | |
download | lvm2-c75ae0846e4c1a74fbd44d85837e2b6dc50e9783.tar.gz |
cache: Implement 'default' as a policy settings value to clear the record.
-rw-r--r-- | lib/metadata/cache_manip.c | 40 | ||||
-rw-r--r-- | test/shell/lvchange-cache.sh | 14 |
2 files changed, 51 insertions, 3 deletions
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c index f7b1b995d..6a13ec1c1 100644 --- a/lib/metadata/cache_manip.c +++ b/lib/metadata/cache_manip.c @@ -399,18 +399,52 @@ int lv_cache_setpolicy(struct logical_volume *lv, struct dm_config_tree *policy) { struct lv_segment *seg = first_seg(lv); const char *name; + struct dm_config_node *cn; + struct dm_config_tree *old = NULL, *new = NULL, *tmp = NULL; + int r = 0; if (lv_is_cache(lv)) seg = first_seg(seg->pool_lv); + if (seg->policy_settings) { + if (!(old = dm_config_create())) + goto_out; + if (!(new = dm_config_create())) + goto_out; + new->root = policy->root; + old->root = seg->policy_settings; + new->cascade = old; + if (!(tmp = policy = dm_config_flatten(new))) + goto_out; + } + if (!(seg->policy_settings = dm_config_clone_node_with_mem(lv->vg->vgmem, policy->root, 0))) - return_0; + goto_out; if ((name = dm_config_find_str(policy->root, "policy", NULL)) && !(seg->policy_name = dm_pool_strdup(lv->vg->vgmem, name))) - return_0; + goto_out; + +restart: /* remove any 'default" nodes */ + cn = seg->policy_settings->child; + while (cn) { + if (cn->v->type == DM_CFG_STRING && !strcmp(cn->v->v.str, "default")) { + dm_config_remove_node(seg->policy_settings, cn); + goto restart; + } + cn = cn->sib; + } - return 1; + r = 1; + +out: + if (old) + dm_config_destroy(old); + if (new) + dm_config_destroy(new); + if (tmp) + dm_config_destroy(tmp); + return r; } /* diff --git a/test/shell/lvchange-cache.sh b/test/shell/lvchange-cache.sh index 997b7705e..4845bba6b 100644 --- a/test/shell/lvchange-cache.sh +++ b/test/shell/lvchange-cache.sh @@ -33,4 +33,18 @@ lvchange --cachesettings 'migration_threshold = 233 sequential_threshold = 13' $ dmsetup status | grep $vg-corigin | grep 'migration_threshold 233' dmsetup status | grep $vg-corigin | grep 'sequential_threshold 13' +lvchange --cachesettings 'migration_threshold = 17' $vg/corigin +dmsetup status | grep $vg-corigin | grep 'migration_threshold 17' +dmsetup status | grep $vg-corigin | grep 'sequential_threshold 13' + +lvchange --cachesettings 'migration_threshold = default' $vg/corigin +dmsetup status | grep $vg-corigin | grep 'migration_threshold 2048' +dmsetup status | grep $vg-corigin | grep 'sequential_threshold 13' + +lvchange --cachesettings 'migration_threshold = 233 sequential_threshold = 13 random_threshold = 1' $vg/corigin +lvchange --cachesettings 'random_threshold = default migration_threshold = default' $vg/corigin +dmsetup status | grep $vg-corigin | grep 'migration_threshold 2048' +dmsetup status | grep $vg-corigin | grep 'sequential_threshold 13' +dmsetup status | grep $vg-corigin | grep 'random_threshold 4' + vgremove -f $vg |