mirror of
git://sourceware.org/git/lvm2.git
synced 2024-10-28 03:27:58 +03:00
config: runtime default for devices/cache, devices/cache_dir
The devices/cache and devices/cache_dir are evaluated in runtime this way: - if devices/cache is set, use it - if devices_cache/dir or devices/cache_file_prefix is set, make up a path out of that for devices/cache in runtime, taking into account the LVM_SYSTEM_DIR environment variable if set - otherwise make up the path out of default which is: <LVM_SYSTEM_DIR>/<cache_dir>/<cache_file_prefix>.cache With the runtime defaults, we can encode this easily now. Also, the lvm dumpconfig can show proper and exact information about this setting then (the variant that shows default values).
This commit is contained in:
parent
b53ec37286
commit
f6adef9825
@ -893,8 +893,7 @@ bad:
|
||||
|
||||
static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
|
||||
{
|
||||
static char cache_file[PATH_MAX];
|
||||
const char *dev_cache = NULL, *cache_dir, *cache_file_prefix;
|
||||
const char *dev_cache;
|
||||
struct dev_filter *f3 = NULL, *f4 = NULL, *toplevel_components[2] = { 0 };
|
||||
struct stat st;
|
||||
const struct dm_config_node *cn;
|
||||
@ -907,33 +906,8 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
|
||||
init_ignore_suspended_devices(find_config_tree_bool(cmd, devices_ignore_suspended_devices_CFG, NULL));
|
||||
init_ignore_lvm_mirrors(find_config_tree_bool(cmd, devices_ignore_lvm_mirrors_CFG, NULL));
|
||||
|
||||
/*
|
||||
* If 'cache_dir' or 'cache_file_prefix' is set, ignore 'cache'.
|
||||
*/
|
||||
cache_dir = find_config_tree_str(cmd, devices_cache_dir_CFG, NULL);
|
||||
cache_file_prefix = find_config_tree_str(cmd, devices_cache_file_prefix_CFG, NULL);
|
||||
|
||||
if (cache_dir || cache_file_prefix) {
|
||||
if (dm_snprintf(cache_file, sizeof(cache_file),
|
||||
"%s%s%s/%s.cache",
|
||||
cache_dir ? "" : cmd->system_dir,
|
||||
cache_dir ? "" : "/",
|
||||
cache_dir ? : DEFAULT_CACHE_SUBDIR,
|
||||
cache_file_prefix ? : DEFAULT_CACHE_FILE_PREFIX) < 0) {
|
||||
log_error("Persistent cache filename too long.");
|
||||
goto bad;
|
||||
}
|
||||
} else if (!(dev_cache = find_config_tree_str(cmd, devices_cache_CFG, NULL)) &&
|
||||
(dm_snprintf(cache_file, sizeof(cache_file),
|
||||
"%s/%s/%s.cache",
|
||||
cmd->system_dir, DEFAULT_CACHE_SUBDIR,
|
||||
DEFAULT_CACHE_FILE_PREFIX) < 0)) {
|
||||
log_error("Persistent cache filename too long.");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!dev_cache)
|
||||
dev_cache = cache_file;
|
||||
if (!(dev_cache = find_config_tree_str(cmd, devices_cache_CFG, NULL)))
|
||||
goto_bad;
|
||||
|
||||
if (!(f4 = persistent_filter_create(cmd->dev_types, f3, dev_cache))) {
|
||||
log_verbose("Failed to create persistent device filter.");
|
||||
|
@ -1602,3 +1602,49 @@ int load_pending_profiles(struct cmd_context *cmd)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *get_default_devices_cache_dir_CFG(struct cmd_context *cmd, struct profile *profile)
|
||||
{
|
||||
static char buf[PATH_MAX];
|
||||
|
||||
if (dm_snprintf(buf, sizeof(buf), "%s/%s/", cmd->system_dir, DEFAULT_CACHE_SUBDIR) < 0) {
|
||||
log_error("Persistent cache directory name too long.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dm_pool_strdup(cmd->mem, buf);
|
||||
}
|
||||
|
||||
const char *get_default_devices_cache_CFG(struct cmd_context *cmd, struct profile *profile)
|
||||
{
|
||||
const char *cache_dir = NULL, *cache_file_prefix = NULL;
|
||||
static char buf[PATH_MAX];
|
||||
|
||||
/*
|
||||
* If 'cache_dir' or 'cache_file_prefix' is set, ignore 'cache'.
|
||||
*/
|
||||
if (find_config_tree_node(cmd, devices_cache_dir_CFG, profile))
|
||||
cache_dir = find_config_tree_str(cmd, devices_cache_dir_CFG, profile);
|
||||
if (find_config_tree_node(cmd, devices_cache_file_prefix_CFG, profile))
|
||||
cache_file_prefix = find_config_tree_str_allow_empty(cmd, devices_cache_file_prefix_CFG, profile);
|
||||
|
||||
if (cache_dir || cache_file_prefix) {
|
||||
if (dm_snprintf(buf, sizeof(buf),
|
||||
"%s%s%s/%s.cache",
|
||||
cache_dir ? "" : cmd->system_dir,
|
||||
cache_dir ? "" : "/",
|
||||
cache_dir ? : DEFAULT_CACHE_SUBDIR,
|
||||
cache_file_prefix ? : DEFAULT_CACHE_FILE_PREFIX) < 0) {
|
||||
log_error("Persistent cache filename too long.");
|
||||
return NULL;
|
||||
}
|
||||
return dm_pool_strdup(cmd->mem, buf);
|
||||
}
|
||||
|
||||
if (dm_snprintf(buf, sizeof(buf), "%s/%s/%s.cache", cmd->system_dir,
|
||||
DEFAULT_CACHE_SUBDIR, DEFAULT_CACHE_FILE_PREFIX) < 0) {
|
||||
log_error("Persistent cache filename too long.");
|
||||
return NULL;
|
||||
}
|
||||
return dm_pool_strdup(cmd->mem, buf);
|
||||
}
|
||||
|
@ -226,4 +226,11 @@ int64_t find_config_tree_int64(struct cmd_context *cmd, int id, struct profile *
|
||||
float find_config_tree_float(struct cmd_context *cmd, int id, struct profile *profile);
|
||||
int find_config_tree_bool(struct cmd_context *cmd, int id, struct profile *profile);
|
||||
|
||||
/*
|
||||
* Functions for individual configuration settings for
|
||||
* which the default value is evaluated at runtime.
|
||||
*/
|
||||
const char *get_default_devices_cache_dir_CFG(struct cmd_context *cmd, struct profile *profile);
|
||||
const char *get_default_devices_cache_CFG(struct cmd_context *cmd, struct profile *profile);
|
||||
|
||||
#endif
|
||||
|
@ -92,9 +92,9 @@ cfg(devices_obtain_device_list_from_udev_CFG, "obtain_device_list_from_udev", de
|
||||
cfg_array(devices_preferred_names_CFG, "preferred_names", devices_CFG_SECTION, CFG_ALLOW_EMPTY | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(1, 2, 19), NULL)
|
||||
cfg_array(devices_filter_CFG, "filter", devices_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
|
||||
cfg_array(devices_global_filter_CFG, "global_filter", devices_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(2, 2, 98), NULL)
|
||||
cfg(devices_cache_CFG, "cache", devices_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
|
||||
cfg(devices_cache_dir_CFG, "cache_dir", devices_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 2, 19), NULL)
|
||||
cfg(devices_cache_file_prefix_CFG, "cache_file_prefix", devices_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 2, 19), NULL)
|
||||
cfg_runtime(devices_cache_CFG, "cache", devices_CFG_SECTION, 0, CFG_TYPE_STRING, vsn(1, 0, 0), NULL)
|
||||
cfg_runtime(devices_cache_dir_CFG, "cache_dir", devices_CFG_SECTION, 0, CFG_TYPE_STRING, vsn(1, 2, 19), NULL)
|
||||
cfg(devices_cache_file_prefix_CFG, "cache_file_prefix", devices_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, DEFAULT_CACHE_FILE_PREFIX, vsn(1, 2, 19), NULL)
|
||||
cfg(devices_write_cache_state_CFG, "write_cache_state", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(1, 0, 0), NULL)
|
||||
cfg_array(devices_types_CFG, "types", devices_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_INT | CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
|
||||
cfg(devices_sysfs_scan_CFG, "sysfs_scan", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_SYSFS_SCAN, vsn(1, 0, 8), NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user