1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

cache: improve profile support for cache_set_policy

This commit is contained in:
Zdenek Kabelac 2017-03-07 23:54:01 +01:00
parent 4d0793f0ec
commit 21c265adcf

View File

@ -682,30 +682,36 @@ int cache_set_policy(struct lv_segment *seg, const char *name,
const struct dm_config_node *cns; const struct dm_config_node *cns;
struct dm_config_tree *old = NULL, *new = NULL, *tmp = NULL; struct dm_config_tree *old = NULL, *new = NULL, *tmp = NULL;
int r = 0; int r = 0;
const int passed_seg_is_cache = seg_is_cache(seg);
struct profile *profile = seg->lv->profile; struct profile *profile = seg->lv->profile;
if (passed_seg_is_cache) if (seg_is_cache(seg))
seg = first_seg(seg->pool_lv); seg = first_seg(seg->pool_lv);
else if (seg_is_cache_pool(seg)) {
if (!name && !settings)
return 1; /* Policy and settings can be selected later when caching LV */
} else {
log_error(INTERNAL_ERROR "Cannot set cache metadata format for non cache volume %s.",
display_lvname(seg->lv));
return 0;
}
if (name) { if (name) {
if (!(seg->policy_name = dm_pool_strdup(seg->lv->vg->vgmem, name))) { if (!(seg->policy_name = dm_pool_strdup(seg->lv->vg->vgmem, 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) {
if (!(seg->policy_name = find_config_tree_str(seg->lv->vg->cmd, allocation_cache_policy_CFG, if (!(seg->policy_name = find_config_tree_str(seg->lv->vg->cmd, allocation_cache_policy_CFG,
profile)) && profile)) &&
!(seg->policy_name = _get_default_cache_policy(seg->lv->vg->cmd))) !(seg->policy_name = _get_default_cache_policy(seg->lv->vg->cmd)))
return_0; return_0;
}
if (settings) {
if (!seg->policy_name) { if (!seg->policy_name) {
log_error(INTERNAL_ERROR "Can't set policy settings without policy name."); log_error(INTERNAL_ERROR "Can't set policy settings without policy name.");
return 0; return 0;
} }
}
if (settings) {
if (seg->policy_settings) { if (seg->policy_settings) {
if (!(old = dm_config_create())) if (!(old = dm_config_create()))
goto_out; goto_out;
@ -721,33 +727,28 @@ int cache_set_policy(struct lv_segment *seg, const char *name,
if ((cn = dm_config_find_node((tmp) ? tmp->root : settings->root, "policy_settings")) && if ((cn = dm_config_find_node((tmp) ? tmp->root : settings->root, "policy_settings")) &&
!(seg->policy_settings = dm_config_clone_node_with_mem(seg->lv->vg->vgmem, cn, 0))) !(seg->policy_settings = dm_config_clone_node_with_mem(seg->lv->vg->vgmem, cn, 0)))
goto_out; goto_out;
} else if (passed_seg_is_cache && /* Look for command's profile cache_policies */ } else if (!seg->policy_settings) {
(cns = find_config_tree_node(seg->lv->vg->cmd, allocation_cache_settings_CFG_SECTION, if ((cns = find_config_tree_node(seg->lv->vg->cmd, allocation_cache_settings_CFG_SECTION,
seg->lv->profile))) { profile))) {
/* Try to find our section for given policy */ /* Try to find our section for given policy */
for (cn = cns->child; cn; cn = cn->sib) { for (cn = cns->child; cn; cn = cn->sib) {
/* Only matching section names */
if (cn->v || strcmp(cn->key, seg->policy_name) != 0)
continue;
if (!cn->child) if (!cn->child)
break; continue; /* Ignore section without settings */
if (!(new = dm_config_create())) if (cn->v || strcmp(cn->key, seg->policy_name) != 0)
goto_out; continue; /* Ignore mismatching sections */
if (!(new->root = dm_config_clone_node_with_mem(new->mem, /* Clone nodes with policy name */
cn->child, 1))) if (!(seg->policy_settings = dm_config_clone_node_with_mem(seg->lv->vg->vgmem,
goto_out; cn, 0)))
return_0;
if (!(seg->policy_settings = dm_config_create_node(new, "policy_settings")))
goto_out;
seg->policy_settings->child = new->root;
/* Replace policy name key with 'policy_settings' */
seg->policy_settings->key = "policy_settings";
break; /* Only first match counts */ break; /* Only first match counts */
} }
} }
}
restart: /* remove any 'default" nodes */ restart: /* remove any 'default" nodes */
cn = seg->policy_settings ? seg->policy_settings->child : NULL; cn = seg->policy_settings ? seg->policy_settings->child : NULL;