2001-08-21 16:56:08 +04:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2007-08-21 00:55:30 +04:00
* Copyright ( C ) 2004 - 2007 Red Hat , Inc . All rights reserved .
2001-08-21 16:56:08 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2004-03-30 23:35:44 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2001-08-21 16:56:08 +04:00
*/
2001-09-25 16:49:28 +04:00
# ifndef _LVM_CONFIG_H
# define _LVM_CONFIG_H
2018-05-14 12:30:20 +03:00
# include "libdm/libdevmapper.h"
# include "lib/device/device.h"
2005-10-17 03:03:59 +04:00
2013-03-05 19:39:36 +04:00
/* 16 bits: 3 bits for major, 4 bits for minor, 9 bits for patchlevel */
2013-07-25 01:10:37 +04:00
/* FIXME Max LVM version supported: 7.15.511. Extend bits when needed. */
2013-03-05 19:39:36 +04:00
# define vsn(major, minor, patchlevel) (major << 13 | minor << 9 | patchlevel)
2004-05-04 22:28:15 +04:00
struct cmd_context ;
2003-07-05 02:34:56 +04:00
2013-06-25 14:25:43 +04:00
typedef enum {
CONFIG_UNDEFINED , /* undefined/uninitialized config */
CONFIG_FILE , /* one file config */
CONFIG_MERGED_FILES , /* config that is a result of merging more config files */
CONFIG_STRING , /* config string typed on cmdline using '--config' arg */
config: differentiate command and metadata profiles and consolidate profile handling code
- When defining configuration source, the code now uses separate
CONFIG_PROFILE_COMMAND and CONFIG_PROFILE_METADATA markers
(before, it was just CONFIG_PROFILE that did not make the
difference between the two). This helps when checking the
configuration if it contains correct set of options which
are all in either command-profilable or metadata-profilable
group without mixing these groups together - so it's a firm
distinction. The "command profile" can't contain
"metadata profile" and vice versa! This is strictly checked
and if the settings are mixed, such profile is rejected and
it's not used. So in the end, the CONFIG_PROFILE_COMMAND
set of options and CONFIG_PROFILE_METADATA are mutually exclusive
sets.
- Marking configuration with one or the other marker will also
determine the way these configuration sources are positioned
in the configuration cascade which is now:
CONFIG_STRING -> CONFIG_PROFILE_COMMAND -> CONFIG_PROFILE_METADATA -> CONFIG_FILE/CONFIG_MERGED_FILES
- Marking configuration with one or the other marker will also make
it possible to issue a command context refresh (will be probably
a part of a future patch) if needed for settings in global profile
set. For settings in metadata profile set this is impossible since
we can't refresh cmd context in the middle of reading VG/LV metadata
and for each VG/LV separately because each VG/LV can have a different
metadata profile assinged and it's not possible to change these
settings at this level.
- When command profile is incorrect, it's rejected *and also* the
command exits immediately - the profile *must* be correct for the
command that was run with a profile to be executed. Before this
patch, when the profile was found incorrect, there was just the
warning message and the command continued without profile applied.
But it's more correct to exit immediately in this case.
- When metadata profile is incorrect, we reject it during command
runtime (as we know the profile name from metadata and not early
from command line as it is in case of command profiles) and we
*do continue* with the command as we're in the middle of operation.
Also, the metadata profile is applied directly and on the fly on
find_config_tree_* fn call and even if the metadata profile is
found incorrect, we still need to return the non-profiled value
as found in the other configuration provided or default value.
To exit immediately even in this case, we'd need to refactor
existing find_config_tree_* fns so they can return error. Currently,
these fns return only config values (which end up with default
values in the end if the config is not found).
- To check the profile validity before use to be sure it's correct,
one can use :
lvm dumpconfig --commandprofile/--metadataprofile ProfileName --validate
(the --commandprofile/--metadataprofile for dumpconfig will come
as part of the subsequent patch)
- This patch also adds a reference to --commandprofile and
--metadataprofile in the cmd help string (which was missing before
for the --profile for some commands). We do not mention --profile
now as people should use --commandprofile or --metadataprofile
directly. However, the --profile is still supported for backward
compatibility and it's translated as:
--profile == --metadataprofile for lvcreate, vgcreate, lvchange and vgchange
(as these commands are able to attach profile to metadata)
--profile == --commandprofile for all the other commands
(--metadataprofile is not allowed there as it makes no sense)
- This patch also contains some cleanups to make the code handling
the profiles more readable...
2014-05-20 16:13:10 +04:00
CONFIG_PROFILE_COMMAND , /* command profile config */
CONFIG_PROFILE_METADATA , /* metadata profile config */
2014-05-19 12:58:28 +04:00
CONFIG_FILE_SPECIAL /* special purpose file config (e.g. metadata, persistent filter...) */
2013-06-25 14:25:43 +04:00
} config_source_t ;
2013-06-25 14:27:04 +04:00
struct profile {
struct dm_list list ;
config: differentiate command and metadata profiles and consolidate profile handling code
- When defining configuration source, the code now uses separate
CONFIG_PROFILE_COMMAND and CONFIG_PROFILE_METADATA markers
(before, it was just CONFIG_PROFILE that did not make the
difference between the two). This helps when checking the
configuration if it contains correct set of options which
are all in either command-profilable or metadata-profilable
group without mixing these groups together - so it's a firm
distinction. The "command profile" can't contain
"metadata profile" and vice versa! This is strictly checked
and if the settings are mixed, such profile is rejected and
it's not used. So in the end, the CONFIG_PROFILE_COMMAND
set of options and CONFIG_PROFILE_METADATA are mutually exclusive
sets.
- Marking configuration with one or the other marker will also
determine the way these configuration sources are positioned
in the configuration cascade which is now:
CONFIG_STRING -> CONFIG_PROFILE_COMMAND -> CONFIG_PROFILE_METADATA -> CONFIG_FILE/CONFIG_MERGED_FILES
- Marking configuration with one or the other marker will also make
it possible to issue a command context refresh (will be probably
a part of a future patch) if needed for settings in global profile
set. For settings in metadata profile set this is impossible since
we can't refresh cmd context in the middle of reading VG/LV metadata
and for each VG/LV separately because each VG/LV can have a different
metadata profile assinged and it's not possible to change these
settings at this level.
- When command profile is incorrect, it's rejected *and also* the
command exits immediately - the profile *must* be correct for the
command that was run with a profile to be executed. Before this
patch, when the profile was found incorrect, there was just the
warning message and the command continued without profile applied.
But it's more correct to exit immediately in this case.
- When metadata profile is incorrect, we reject it during command
runtime (as we know the profile name from metadata and not early
from command line as it is in case of command profiles) and we
*do continue* with the command as we're in the middle of operation.
Also, the metadata profile is applied directly and on the fly on
find_config_tree_* fn call and even if the metadata profile is
found incorrect, we still need to return the non-profiled value
as found in the other configuration provided or default value.
To exit immediately even in this case, we'd need to refactor
existing find_config_tree_* fns so they can return error. Currently,
these fns return only config values (which end up with default
values in the end if the config is not found).
- To check the profile validity before use to be sure it's correct,
one can use :
lvm dumpconfig --commandprofile/--metadataprofile ProfileName --validate
(the --commandprofile/--metadataprofile for dumpconfig will come
as part of the subsequent patch)
- This patch also adds a reference to --commandprofile and
--metadataprofile in the cmd help string (which was missing before
for the --profile for some commands). We do not mention --profile
now as people should use --commandprofile or --metadataprofile
directly. However, the --profile is still supported for backward
compatibility and it's translated as:
--profile == --metadataprofile for lvcreate, vgcreate, lvchange and vgchange
(as these commands are able to attach profile to metadata)
--profile == --commandprofile for all the other commands
(--metadataprofile is not allowed there as it makes no sense)
- This patch also contains some cleanups to make the code handling
the profiles more readable...
2014-05-20 16:13:10 +04:00
config_source_t source ; /* either CONFIG_PROFILE_COMMAND or CONFIG_PROFILE_METADATA */
2013-06-25 14:27:04 +04:00
const char * name ;
struct dm_config_tree * cft ;
} ;
struct profile_params {
config: differentiate command and metadata profiles and consolidate profile handling code
- When defining configuration source, the code now uses separate
CONFIG_PROFILE_COMMAND and CONFIG_PROFILE_METADATA markers
(before, it was just CONFIG_PROFILE that did not make the
difference between the two). This helps when checking the
configuration if it contains correct set of options which
are all in either command-profilable or metadata-profilable
group without mixing these groups together - so it's a firm
distinction. The "command profile" can't contain
"metadata profile" and vice versa! This is strictly checked
and if the settings are mixed, such profile is rejected and
it's not used. So in the end, the CONFIG_PROFILE_COMMAND
set of options and CONFIG_PROFILE_METADATA are mutually exclusive
sets.
- Marking configuration with one or the other marker will also
determine the way these configuration sources are positioned
in the configuration cascade which is now:
CONFIG_STRING -> CONFIG_PROFILE_COMMAND -> CONFIG_PROFILE_METADATA -> CONFIG_FILE/CONFIG_MERGED_FILES
- Marking configuration with one or the other marker will also make
it possible to issue a command context refresh (will be probably
a part of a future patch) if needed for settings in global profile
set. For settings in metadata profile set this is impossible since
we can't refresh cmd context in the middle of reading VG/LV metadata
and for each VG/LV separately because each VG/LV can have a different
metadata profile assinged and it's not possible to change these
settings at this level.
- When command profile is incorrect, it's rejected *and also* the
command exits immediately - the profile *must* be correct for the
command that was run with a profile to be executed. Before this
patch, when the profile was found incorrect, there was just the
warning message and the command continued without profile applied.
But it's more correct to exit immediately in this case.
- When metadata profile is incorrect, we reject it during command
runtime (as we know the profile name from metadata and not early
from command line as it is in case of command profiles) and we
*do continue* with the command as we're in the middle of operation.
Also, the metadata profile is applied directly and on the fly on
find_config_tree_* fn call and even if the metadata profile is
found incorrect, we still need to return the non-profiled value
as found in the other configuration provided or default value.
To exit immediately even in this case, we'd need to refactor
existing find_config_tree_* fns so they can return error. Currently,
these fns return only config values (which end up with default
values in the end if the config is not found).
- To check the profile validity before use to be sure it's correct,
one can use :
lvm dumpconfig --commandprofile/--metadataprofile ProfileName --validate
(the --commandprofile/--metadataprofile for dumpconfig will come
as part of the subsequent patch)
- This patch also adds a reference to --commandprofile and
--metadataprofile in the cmd help string (which was missing before
for the --profile for some commands). We do not mention --profile
now as people should use --commandprofile or --metadataprofile
directly. However, the --profile is still supported for backward
compatibility and it's translated as:
--profile == --metadataprofile for lvcreate, vgcreate, lvchange and vgchange
(as these commands are able to attach profile to metadata)
--profile == --commandprofile for all the other commands
(--metadataprofile is not allowed there as it makes no sense)
- This patch also contains some cleanups to make the code handling
the profiles more readable...
2014-05-20 16:13:10 +04:00
char dir [ PATH_MAX ] ; /* subdir in LVM_SYSTEM_DIR where LVM looks for profiles */
struct profile * global_command_profile ; /* profile (as given by --commandprofile cmd arg) used as global command profile */
struct profile * global_metadata_profile ; /* profile (as given by --metadataprofile cmd arg) that overrides any other VG/LV-based profile */
struct dm_list profiles_to_load ; /* list of profiles which are only added, but still need to be loaded for any use */
struct dm_list profiles ; /* list of profiles which are loaded already and which are ready for use */
2016-08-08 11:43:18 +03:00
struct profile * shell_profile ; /* master profile used in interactive/shell mode */
2013-06-25 14:27:04 +04:00
} ;
2015-07-23 15:21:35 +03:00
# define CFG_PATH_MAX_LEN 128
2013-03-05 19:49:42 +04:00
/*
* Structures used for definition of a configuration tree .
*/
/* configuration definition item type (for item's accepted types) */
typedef enum {
2013-04-29 14:38:56 +04:00
CFG_TYPE_SECTION = 1 < < 0 , /* section */
CFG_TYPE_ARRAY = 1 < < 1 , /* setting */
CFG_TYPE_BOOL = 1 < < 2 , /* setting */
CFG_TYPE_INT = 1 < < 3 , /* setting */
CFG_TYPE_FLOAT = 1 < < 4 , /* setting */
CFG_TYPE_STRING = 1 < < 5 , /* setting */
2013-03-05 19:49:42 +04:00
} cfg_def_type_t ;
config: add CFG_DEFAULT_RUN_TIME for config options with runtime defaults
Previously, we declared a default value as undefined ("NULL") for
settings which require runtime context to be set first (e.g. settings
for paths that rely on SYSTEM_DIR environment variable or they depend
on any other setting in some way).
If we want to output default values as they are really used in runtime,
we should make it possible to define a default value as function which
is evaluated, not just providing a firm constant value as it was before.
This patch defines simple prototypes for such functions. Also, there's
new helper macros "cfg_runtime" and "cfg_array_runtime" - they provide
exactly the same functionality as the original "cfg" and "cfg_array"
macros when defining the configuration settings in config_settings.h,
but they don't set the constant default value. Instead, they automatically
link the configuration setting definition with one of these functions:
typedef int (*t_fn_CFG_TYPE_BOOL) (struct cmd_context *cmd, struct profile *profile);
typedef int (*t_fn_CFG_TYPE_INT) (struct cmd_context *cmd, struct profile *profile);
typedef float (*t_fn_CFG_TYPE_FLOAT) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_STRING) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_ARRAY) (struct cmd_context *cmd, struct profile *profile);
(The new macros actually set the CFG_DEFAULT_RUNTIME flag properly and
set the default value link to the function accordingly).
Then such configuration setting requires a function of selected type to
be defined. This function has a predefined name:
get_default_<id>
...where the <id> is the id of the setting as defined in
config_settings.h. For example "backup_archive_dir_CFG" if defined
as a setting with default value evaluated in runtime with "cfg_runtime"
will automatically have "get_default_backup_archive_dir_CFG" function
linked to this setting to get the default value.
2014-03-03 15:34:11 +04:00
/* function types to evaluate default value at runtime */
typedef int ( * t_fn_CFG_TYPE_BOOL ) ( struct cmd_context * cmd , struct profile * profile ) ;
typedef int ( * t_fn_CFG_TYPE_INT ) ( struct cmd_context * cmd , struct profile * profile ) ;
typedef float ( * t_fn_CFG_TYPE_FLOAT ) ( struct cmd_context * cmd , struct profile * profile ) ;
typedef const char * ( * t_fn_CFG_TYPE_STRING ) ( struct cmd_context * cmd , struct profile * profile ) ;
typedef const char * ( * t_fn_CFG_TYPE_ARRAY ) ( struct cmd_context * cmd , struct profile * profile ) ;
2015-04-28 16:29:08 +03:00
typedef const char * ( * t_fn_UNCONFIGURED ) ( struct cmd_context * cmd ) ;
config: add CFG_DEFAULT_RUN_TIME for config options with runtime defaults
Previously, we declared a default value as undefined ("NULL") for
settings which require runtime context to be set first (e.g. settings
for paths that rely on SYSTEM_DIR environment variable or they depend
on any other setting in some way).
If we want to output default values as they are really used in runtime,
we should make it possible to define a default value as function which
is evaluated, not just providing a firm constant value as it was before.
This patch defines simple prototypes for such functions. Also, there's
new helper macros "cfg_runtime" and "cfg_array_runtime" - they provide
exactly the same functionality as the original "cfg" and "cfg_array"
macros when defining the configuration settings in config_settings.h,
but they don't set the constant default value. Instead, they automatically
link the configuration setting definition with one of these functions:
typedef int (*t_fn_CFG_TYPE_BOOL) (struct cmd_context *cmd, struct profile *profile);
typedef int (*t_fn_CFG_TYPE_INT) (struct cmd_context *cmd, struct profile *profile);
typedef float (*t_fn_CFG_TYPE_FLOAT) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_STRING) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_ARRAY) (struct cmd_context *cmd, struct profile *profile);
(The new macros actually set the CFG_DEFAULT_RUNTIME flag properly and
set the default value link to the function accordingly).
Then such configuration setting requires a function of selected type to
be defined. This function has a predefined name:
get_default_<id>
...where the <id> is the id of the setting as defined in
config_settings.h. For example "backup_archive_dir_CFG" if defined
as a setting with default value evaluated in runtime with "cfg_runtime"
will automatically have "get_default_backup_archive_dir_CFG" function
linked to this setting to get the default value.
2014-03-03 15:34:11 +04:00
2013-03-05 19:49:42 +04:00
/* configuration definition item value (for item's default value) */
typedef union {
config: add CFG_DEFAULT_RUN_TIME for config options with runtime defaults
Previously, we declared a default value as undefined ("NULL") for
settings which require runtime context to be set first (e.g. settings
for paths that rely on SYSTEM_DIR environment variable or they depend
on any other setting in some way).
If we want to output default values as they are really used in runtime,
we should make it possible to define a default value as function which
is evaluated, not just providing a firm constant value as it was before.
This patch defines simple prototypes for such functions. Also, there's
new helper macros "cfg_runtime" and "cfg_array_runtime" - they provide
exactly the same functionality as the original "cfg" and "cfg_array"
macros when defining the configuration settings in config_settings.h,
but they don't set the constant default value. Instead, they automatically
link the configuration setting definition with one of these functions:
typedef int (*t_fn_CFG_TYPE_BOOL) (struct cmd_context *cmd, struct profile *profile);
typedef int (*t_fn_CFG_TYPE_INT) (struct cmd_context *cmd, struct profile *profile);
typedef float (*t_fn_CFG_TYPE_FLOAT) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_STRING) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_ARRAY) (struct cmd_context *cmd, struct profile *profile);
(The new macros actually set the CFG_DEFAULT_RUNTIME flag properly and
set the default value link to the function accordingly).
Then such configuration setting requires a function of selected type to
be defined. This function has a predefined name:
get_default_<id>
...where the <id> is the id of the setting as defined in
config_settings.h. For example "backup_archive_dir_CFG" if defined
as a setting with default value evaluated in runtime with "cfg_runtime"
will automatically have "get_default_backup_archive_dir_CFG" function
linked to this setting to get the default value.
2014-03-03 15:34:11 +04:00
/* static value - returns a variable */
2013-03-05 19:49:42 +04:00
const int v_CFG_TYPE_BOOL , v_CFG_TYPE_INT ;
const float v_CFG_TYPE_FLOAT ;
const char * v_CFG_TYPE_STRING , * v_CFG_TYPE_ARRAY ;
config: add CFG_DEFAULT_RUN_TIME for config options with runtime defaults
Previously, we declared a default value as undefined ("NULL") for
settings which require runtime context to be set first (e.g. settings
for paths that rely on SYSTEM_DIR environment variable or they depend
on any other setting in some way).
If we want to output default values as they are really used in runtime,
we should make it possible to define a default value as function which
is evaluated, not just providing a firm constant value as it was before.
This patch defines simple prototypes for such functions. Also, there's
new helper macros "cfg_runtime" and "cfg_array_runtime" - they provide
exactly the same functionality as the original "cfg" and "cfg_array"
macros when defining the configuration settings in config_settings.h,
but they don't set the constant default value. Instead, they automatically
link the configuration setting definition with one of these functions:
typedef int (*t_fn_CFG_TYPE_BOOL) (struct cmd_context *cmd, struct profile *profile);
typedef int (*t_fn_CFG_TYPE_INT) (struct cmd_context *cmd, struct profile *profile);
typedef float (*t_fn_CFG_TYPE_FLOAT) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_STRING) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_ARRAY) (struct cmd_context *cmd, struct profile *profile);
(The new macros actually set the CFG_DEFAULT_RUNTIME flag properly and
set the default value link to the function accordingly).
Then such configuration setting requires a function of selected type to
be defined. This function has a predefined name:
get_default_<id>
...where the <id> is the id of the setting as defined in
config_settings.h. For example "backup_archive_dir_CFG" if defined
as a setting with default value evaluated in runtime with "cfg_runtime"
will automatically have "get_default_backup_archive_dir_CFG" function
linked to this setting to get the default value.
2014-03-03 15:34:11 +04:00
/* run-time value - evaluates a function */
t_fn_CFG_TYPE_BOOL fn_CFG_TYPE_BOOL ;
t_fn_CFG_TYPE_INT fn_CFG_TYPE_INT ;
t_fn_CFG_TYPE_FLOAT fn_CFG_TYPE_FLOAT ;
t_fn_CFG_TYPE_STRING fn_CFG_TYPE_STRING ;
t_fn_CFG_TYPE_ARRAY fn_CFG_TYPE_ARRAY ;
2013-03-05 19:49:42 +04:00
} cfg_def_value_t ;
2015-04-28 16:29:08 +03:00
typedef union {
const char * v_UNCONFIGURED ;
t_fn_UNCONFIGURED fn_UNCONFIGURED ;
} cfg_def_unconfigured_value_t ;
2013-03-05 19:49:42 +04:00
/* configuration definition item flags: */
2015-03-04 16:08:47 +03:00
2013-03-05 19:49:42 +04:00
/* whether the configuration item name is variable */
2016-08-08 11:43:18 +03:00
# define CFG_NAME_VARIABLE 0x0001
2013-03-05 19:49:42 +04:00
/* whether empty value is allowed */
2016-08-08 11:43:18 +03:00
# define CFG_ALLOW_EMPTY 0x0002
2013-03-05 19:49:42 +04:00
/* whether the configuration item is for advanced use only */
2016-08-08 11:43:18 +03:00
# define CFG_ADVANCED 0x0004
2013-06-26 18:27:28 +04:00
/* whether the configuration item is not officially supported */
2016-08-08 11:43:18 +03:00
# define CFG_UNSUPPORTED 0x0008
2013-06-26 18:27:28 +04:00
/* whether the configuration item is customizable by a profile */
2016-08-08 11:43:18 +03:00
# define CFG_PROFILABLE 0x0010
/* whether the configuration item is customizable by a profile
* and whether it can be attached to VG / LV metadata at the same time
2014-05-19 18:29:50 +04:00
* The CFG_PROFILABLE_METADATA flag incorporates CFG_PROFILABLE flag ! ! ! */
2016-08-08 11:43:18 +03:00
# define CFG_PROFILABLE_METADATA 0x0030
2014-02-25 14:05:23 +04:00
/* whether the default value is undefned */
2016-08-08 11:43:18 +03:00
# define CFG_DEFAULT_UNDEFINED 0x0040
2015-04-30 19:26:56 +03:00
/* whether the default value is commented out on output */
2016-08-08 11:43:18 +03:00
# define CFG_DEFAULT_COMMENTED 0x0080
2015-03-04 16:08:47 +03:00
/* whether the default value is calculated during run time */
2016-08-08 11:43:18 +03:00
# define CFG_DEFAULT_RUN_TIME 0x0100
2015-03-04 16:08:47 +03:00
/* whether the configuration setting is disabled (and hence defaults always used) */
2016-08-08 11:43:18 +03:00
# define CFG_DISABLED 0x0200
2015-06-23 14:02:45 +03:00
/* whether to print integers in octal form (prefixed by "0") */
2016-08-08 11:43:18 +03:00
# define CFG_FORMAT_INT_OCTAL 0x0400
2015-07-22 15:19:07 +03:00
/* whether to disable checks for the whole config section subtree */
2016-08-08 11:43:18 +03:00
# define CFG_SECTION_NO_CHECK 0x0800
/* whether to disallow a possibility to override configuration
* setting for commands run interactively ( e . g . in lvm shell ) */
# define CFG_DISALLOW_INTERACTIVE 0x1000
2013-03-05 19:49:42 +04:00
/* configuration definition item structure */
typedef struct cfg_def_item {
2015-04-28 16:29:08 +03:00
int id ; /* ID of this item */
int parent ; /* ID of parent item */
const char * name ; /* name of the item in configuration tree */
int type ; /* configuration item type (bits of cfg_def_type_t) */
cfg_def_value_t default_value ; /* default value (only for settings) */
uint16_t flags ; /* configuration item definition flags */
uint16_t since_version ; /* version this item appeared in */
cfg_def_unconfigured_value_t default_unconfigured_value ; /* default value in terms of @FOO@, pre-configured (only for settings) */
2015-04-30 16:34:07 +03:00
uint16_t deprecated_since_version ; /* version since this item is deprecated */
const char * deprecation_comment ; /* comment about reasons for deprecation and settings that supersede this one */
2015-04-28 16:29:08 +03:00
const char * comment ; /* comment */
2017-08-05 18:18:36 +03:00
const char * file_premable ; /* comment text to use at the start of the file */
2013-03-05 19:49:42 +04:00
} cfg_def_item_t ;
2013-03-05 20:36:10 +04:00
/* configuration definition tree types */
typedef enum {
CFG_DEF_TREE_CURRENT , /* tree of nodes with values currently set in the config */
CFG_DEF_TREE_MISSING , /* tree of nodes missing in current config using default values */
2015-06-25 11:51:30 +03:00
CFG_DEF_TREE_FULL , /* CURRENT + MISSING, the tree actually used within execution */
2013-03-05 20:36:10 +04:00
CFG_DEF_TREE_DEFAULT , /* tree of all possible config nodes with default values */
2013-07-09 11:57:46 +04:00
CFG_DEF_TREE_NEW , /* tree of all new nodes that appeared in given version */
2015-11-25 16:09:20 +03:00
CFG_DEF_TREE_NEW_SINCE , /* tree of all new nodes that appeared since given version */
2014-03-24 16:19:15 +04:00
CFG_DEF_TREE_PROFILABLE , /* tree of all nodes that are customizable by profiles */
2014-05-20 16:45:20 +04:00
CFG_DEF_TREE_PROFILABLE_CMD , /* tree of all nodes that are customizable by command profiles (subset of PROFILABLE) */
CFG_DEF_TREE_PROFILABLE_MDA , /* tree of all nodes that are customizable by metadata profiles (subset of PROFILABLE) */
2014-03-24 16:19:15 +04:00
CFG_DEF_TREE_DIFF , /* tree of all nodes that differ from defaults */
2015-04-29 12:11:58 +03:00
CFG_DEF_TREE_LIST , /* list all nodes */
2013-03-05 20:36:10 +04:00
} cfg_def_tree_t ;
/* configuration definition tree specification */
struct config_def_tree_spec {
2015-06-25 11:51:30 +03:00
struct cmd_context * cmd ; /* command context (for run-time defaults */
struct dm_config_tree * current_cft ; /* current config tree which is defined explicitly - defaults are not used */
cfg_def_tree_t type ; /* tree type */
uint16_t version ; /* tree at this LVM2 version */
unsigned ignoreadvanced : 1 ; /* do not include advanced configs */
unsigned ignoreunsupported : 1 ; /* do not include unsupported configs */
unsigned ignoredeprecated : 1 ; /* do not include deprecated configs */
unsigned ignorelocal : 1 ; /* do not include the local section */
unsigned withsummary : 1 ; /* include first line of comments - a summary */
unsigned withcomments : 1 ; /* include all comment lines */
unsigned withversions : 1 ; /* include versions */
unsigned withspaces : 1 ; /* add more spaces in output for better readability */
unsigned unconfigured : 1 ; /* use unconfigured path strings */
2017-08-05 18:18:36 +03:00
unsigned withgeneralpreamble : 1 ; /* include preamble for a general config file */
unsigned withlocalpreamble : 1 ; /* include preamble for a local config file */
2015-06-25 11:51:30 +03:00
uint8_t * check_status ; /* status of last tree check (currently needed for CFG_DEF_TREE_MISSING only) */
2013-03-05 20:36:10 +04:00
} ;
2013-06-26 16:53:57 +04:00
/* flag to mark the item as used in a config tree instance during validation */
# define CFG_USED 0x01
/* flag to mark the item as valid in a config tree instance during validation */
# define CFG_VALID 0x02
2014-03-21 13:43:44 +04:00
/* flag to mark the item as having the value different from default one */
# define CFG_DIFF 0x04
2013-06-26 16:53:57 +04:00
2013-03-05 19:49:42 +04:00
/*
* Register ID for each possible item in the configuration tree .
*/
enum {
2015-04-30 16:34:07 +03:00
# define cfg_section(id, name, parent, flags, since_version, deprecated_since_version, deprecation_comment, comment) id,
# define cfg(id, name, parent, flags, type, default_value, since_version, unconfigured_value, deprecated_since_version, deprecation_comment, comment) id,
# define cfg_runtime(id, name, parent, flags, type, since_version, deprecated_since_version, deprecation_comment, comment) id,
# define cfg_array(id, name, parent, flags, types, default_value, since_version, unconfigured_value, deprecated_since_version, deprecation_comment, comment) id,
# define cfg_array_runtime(id, name, parent, flags, types, since_version, deprecated_since_version, deprecation_comment, comment) id,
2018-05-14 12:30:20 +03:00
# include "lib/config/config_settings.h"
2013-03-05 19:49:42 +04:00
# undef cfg_section
# undef cfg
config: add CFG_DEFAULT_RUN_TIME for config options with runtime defaults
Previously, we declared a default value as undefined ("NULL") for
settings which require runtime context to be set first (e.g. settings
for paths that rely on SYSTEM_DIR environment variable or they depend
on any other setting in some way).
If we want to output default values as they are really used in runtime,
we should make it possible to define a default value as function which
is evaluated, not just providing a firm constant value as it was before.
This patch defines simple prototypes for such functions. Also, there's
new helper macros "cfg_runtime" and "cfg_array_runtime" - they provide
exactly the same functionality as the original "cfg" and "cfg_array"
macros when defining the configuration settings in config_settings.h,
but they don't set the constant default value. Instead, they automatically
link the configuration setting definition with one of these functions:
typedef int (*t_fn_CFG_TYPE_BOOL) (struct cmd_context *cmd, struct profile *profile);
typedef int (*t_fn_CFG_TYPE_INT) (struct cmd_context *cmd, struct profile *profile);
typedef float (*t_fn_CFG_TYPE_FLOAT) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_STRING) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_ARRAY) (struct cmd_context *cmd, struct profile *profile);
(The new macros actually set the CFG_DEFAULT_RUNTIME flag properly and
set the default value link to the function accordingly).
Then such configuration setting requires a function of selected type to
be defined. This function has a predefined name:
get_default_<id>
...where the <id> is the id of the setting as defined in
config_settings.h. For example "backup_archive_dir_CFG" if defined
as a setting with default value evaluated in runtime with "cfg_runtime"
will automatically have "get_default_backup_archive_dir_CFG" function
linked to this setting to get the default value.
2014-03-03 15:34:11 +04:00
# undef cfg_runtime
2013-03-05 19:49:42 +04:00
# undef cfg_array
config: add CFG_DEFAULT_RUN_TIME for config options with runtime defaults
Previously, we declared a default value as undefined ("NULL") for
settings which require runtime context to be set first (e.g. settings
for paths that rely on SYSTEM_DIR environment variable or they depend
on any other setting in some way).
If we want to output default values as they are really used in runtime,
we should make it possible to define a default value as function which
is evaluated, not just providing a firm constant value as it was before.
This patch defines simple prototypes for such functions. Also, there's
new helper macros "cfg_runtime" and "cfg_array_runtime" - they provide
exactly the same functionality as the original "cfg" and "cfg_array"
macros when defining the configuration settings in config_settings.h,
but they don't set the constant default value. Instead, they automatically
link the configuration setting definition with one of these functions:
typedef int (*t_fn_CFG_TYPE_BOOL) (struct cmd_context *cmd, struct profile *profile);
typedef int (*t_fn_CFG_TYPE_INT) (struct cmd_context *cmd, struct profile *profile);
typedef float (*t_fn_CFG_TYPE_FLOAT) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_STRING) (struct cmd_context *cmd, struct profile *profile);
typedef const char* (*t_fn_CFG_TYPE_ARRAY) (struct cmd_context *cmd, struct profile *profile);
(The new macros actually set the CFG_DEFAULT_RUNTIME flag properly and
set the default value link to the function accordingly).
Then such configuration setting requires a function of selected type to
be defined. This function has a predefined name:
get_default_<id>
...where the <id> is the id of the setting as defined in
config_settings.h. For example "backup_archive_dir_CFG" if defined
as a setting with default value evaluated in runtime with "cfg_runtime"
will automatically have "get_default_backup_archive_dir_CFG" function
linked to this setting to get the default value.
2014-03-03 15:34:11 +04:00
# undef cfg_array_runtime
2013-03-05 19:49:42 +04:00
} ;
config: differentiate command and metadata profiles and consolidate profile handling code
- When defining configuration source, the code now uses separate
CONFIG_PROFILE_COMMAND and CONFIG_PROFILE_METADATA markers
(before, it was just CONFIG_PROFILE that did not make the
difference between the two). This helps when checking the
configuration if it contains correct set of options which
are all in either command-profilable or metadata-profilable
group without mixing these groups together - so it's a firm
distinction. The "command profile" can't contain
"metadata profile" and vice versa! This is strictly checked
and if the settings are mixed, such profile is rejected and
it's not used. So in the end, the CONFIG_PROFILE_COMMAND
set of options and CONFIG_PROFILE_METADATA are mutually exclusive
sets.
- Marking configuration with one or the other marker will also
determine the way these configuration sources are positioned
in the configuration cascade which is now:
CONFIG_STRING -> CONFIG_PROFILE_COMMAND -> CONFIG_PROFILE_METADATA -> CONFIG_FILE/CONFIG_MERGED_FILES
- Marking configuration with one or the other marker will also make
it possible to issue a command context refresh (will be probably
a part of a future patch) if needed for settings in global profile
set. For settings in metadata profile set this is impossible since
we can't refresh cmd context in the middle of reading VG/LV metadata
and for each VG/LV separately because each VG/LV can have a different
metadata profile assinged and it's not possible to change these
settings at this level.
- When command profile is incorrect, it's rejected *and also* the
command exits immediately - the profile *must* be correct for the
command that was run with a profile to be executed. Before this
patch, when the profile was found incorrect, there was just the
warning message and the command continued without profile applied.
But it's more correct to exit immediately in this case.
- When metadata profile is incorrect, we reject it during command
runtime (as we know the profile name from metadata and not early
from command line as it is in case of command profiles) and we
*do continue* with the command as we're in the middle of operation.
Also, the metadata profile is applied directly and on the fly on
find_config_tree_* fn call and even if the metadata profile is
found incorrect, we still need to return the non-profiled value
as found in the other configuration provided or default value.
To exit immediately even in this case, we'd need to refactor
existing find_config_tree_* fns so they can return error. Currently,
these fns return only config values (which end up with default
values in the end if the config is not found).
- To check the profile validity before use to be sure it's correct,
one can use :
lvm dumpconfig --commandprofile/--metadataprofile ProfileName --validate
(the --commandprofile/--metadataprofile for dumpconfig will come
as part of the subsequent patch)
- This patch also adds a reference to --commandprofile and
--metadataprofile in the cmd help string (which was missing before
for the --profile for some commands). We do not mention --profile
now as people should use --commandprofile or --metadataprofile
directly. However, the --profile is still supported for backward
compatibility and it's translated as:
--profile == --metadataprofile for lvcreate, vgcreate, lvchange and vgchange
(as these commands are able to attach profile to metadata)
--profile == --commandprofile for all the other commands
(--metadataprofile is not allowed there as it makes no sense)
- This patch also contains some cleanups to make the code handling
the profiles more readable...
2014-05-20 16:13:10 +04:00
struct profile * add_profile ( struct cmd_context * cmd , const char * profile_name , config_source_t source ) ;
2013-06-25 14:27:04 +04:00
int load_profile ( struct cmd_context * cmd , struct profile * profile ) ;
int load_pending_profiles ( struct cmd_context * cmd ) ;
2013-06-26 16:53:57 +04:00
/* configuration check handle for each instance of the validation check */
struct cft_check_handle {
2014-03-19 11:45:05 +04:00
struct cmd_context * cmd ; /* command context */
2013-06-26 16:53:57 +04:00
struct dm_config_tree * cft ; /* the tree for which the check is done */
2013-06-26 18:27:28 +04:00
config_source_t source ; /* configuration source */
2013-06-26 16:53:57 +04:00
unsigned force_check : 1 ; /* force check even if disabled by config/checks setting */
unsigned skip_if_checked : 1 ; /* skip the check if already done before - return last state */
unsigned suppress_messages : 1 ; /* suppress messages during the check if config item is found invalid */
2014-03-21 13:43:44 +04:00
unsigned check_diff : 1 ; /* check if the value used differs from default one */
2015-04-29 17:07:52 +03:00
unsigned ignoreadvanced : 1 ; /* do not include advnced configs */
unsigned ignoreunsupported : 1 ; /* do not include unsupported configs */
2016-08-08 11:43:18 +03:00
uint16_t disallowed_flags ; /* set of disallowed flags */
2013-06-26 16:53:57 +04:00
uint8_t status [ CFG_COUNT ] ; /* flags for each configuration item - the result of the check */
} ;
2013-03-05 19:49:42 +04:00
int config_def_get_path ( char * buf , size_t buf_size , int id ) ;
2016-08-08 13:55:15 +03:00
/* Checks config using given handle - the handle may be reused. */
2014-03-19 11:45:05 +04:00
int config_def_check ( struct cft_check_handle * handle ) ;
2016-08-08 13:55:15 +03:00
/* Forces config check and automatically creates a new handle inside with defaults and discards the handle after the check. */
int config_force_check ( struct cmd_context * cmd , config_source_t source , struct dm_config_tree * cft ) ;
2013-03-05 19:49:42 +04:00
2013-06-25 14:25:43 +04:00
int override_config_tree_from_string ( struct cmd_context * cmd , const char * config_settings ) ;
2013-06-25 14:27:37 +04:00
int override_config_tree_from_profile ( struct cmd_context * cmd , struct profile * profile ) ;
2014-05-19 15:23:12 +04:00
struct dm_config_tree * get_config_tree_by_source ( struct cmd_context * , config_source_t source ) ;
2013-06-25 14:25:43 +04:00
struct dm_config_tree * remove_config_tree_by_source ( struct cmd_context * cmd , config_source_t source ) ;
2014-05-19 15:23:12 +04:00
struct cft_check_handle * get_config_tree_check_handle ( struct cmd_context * cmd , struct dm_config_tree * cft ) ;
2013-06-25 14:25:43 +04:00
config_source_t config_get_source_type ( struct dm_config_tree * cft ) ;
2001-08-21 16:56:08 +04:00
2010-09-27 23:09:34 +04:00
typedef uint32_t ( * checksum_fn_t ) ( uint32_t initial , const uint8_t * buf , uint32_t size ) ;
2002-11-18 17:01:16 +03:00
2013-06-25 14:25:43 +04:00
struct dm_config_tree * config_open ( config_source_t source , const char * filename , int keep_open ) ;
2018-04-20 18:43:50 +03:00
int config_file_read_fd ( struct dm_config_tree * cft , struct device * dev , dev_io_reason_t reason ,
2011-12-19 01:56:03 +04:00
off_t offset , size_t size , off_t offset2 , size_t size2 ,
2012-03-26 15:35:26 +04:00
checksum_fn_t checksum_fn , uint32_t checksum ,
2018-04-20 18:43:50 +03:00
int skip_parse , int no_dup_node_check ) ;
int config_file_read ( struct dm_config_tree * cft ) ;
2014-05-19 15:23:12 +04:00
struct dm_config_tree * config_file_open_and_read ( const char * config_file , config_source_t source ,
struct cmd_context * cmd ) ;
2014-02-25 14:05:23 +04:00
int config_write ( struct dm_config_tree * cft , struct config_def_tree_spec * tree_spec ,
2013-03-05 21:21:13 +04:00
const char * file , int argc , char * * argv ) ;
2013-03-05 20:36:10 +04:00
struct dm_config_tree * config_def_create_tree ( struct config_def_tree_spec * spec ) ;
2013-06-25 14:25:43 +04:00
void config_destroy ( struct dm_config_tree * cft ) ;
2011-12-19 01:56:03 +04:00
2015-03-18 12:59:41 +03:00
struct timespec config_file_timestamp ( struct dm_config_tree * cft ) ;
2011-12-19 01:56:03 +04:00
int config_file_changed ( struct dm_config_tree * cft ) ;
int config_file_check ( struct dm_config_tree * cft , const char * * filename , struct stat * info ) ;
2011-12-12 03:18:20 +04:00
2009-10-16 21:41:49 +04:00
2013-07-08 16:31:44 +04:00
typedef enum {
CONFIG_MERGE_TYPE_RAW , /* always replace old config values with new config values when merging */
CONFIG_MERGE_TYPE_TAGS /* apply some exceptions when merging tag configs:
- skip tags section
- do not replace , but merge values of these settings :
activation / volume_list
devices / filter
devices / types
*/
} config_merge_t ;
2011-08-30 18:55:15 +04:00
int merge_config_tree ( struct cmd_context * cmd , struct dm_config_tree * cft ,
2013-07-08 16:31:44 +04:00
struct dm_config_tree * newdata , config_merge_t ) ;
2001-08-21 16:56:08 +04:00
2015-02-23 20:40:58 +03:00
/*
* The next two do not check config overrides and must only be used for the tags section .
*/
const struct dm_config_node * find_config_node ( struct cmd_context * cmd , struct dm_config_tree * cft , int id ) ;
int find_config_bool ( struct cmd_context * cmd , struct dm_config_tree * cft , int id ) ;
2006-05-16 20:48:31 +04:00
/*
* These versions check an override tree , if present , first .
*/
2013-06-25 14:29:33 +04:00
const struct dm_config_node * find_config_tree_node ( struct cmd_context * cmd , int id , struct profile * profile ) ;
2013-06-25 14:29:54 +04:00
const char * find_config_tree_str ( struct cmd_context * cmd , int id , struct profile * profile ) ;
2013-06-25 14:30:08 +04:00
const char * find_config_tree_str_allow_empty ( struct cmd_context * cmd , int id , struct profile * profile ) ;
2013-06-25 14:30:34 +04:00
int find_config_tree_int ( struct cmd_context * cmd , int id , struct profile * profile ) ;
2013-06-25 14:31:24 +04:00
int64_t find_config_tree_int64 ( struct cmd_context * cmd , int id , struct profile * profile ) ;
2013-06-25 14:31:36 +04:00
float find_config_tree_float ( struct cmd_context * cmd , int id , struct profile * profile ) ;
2013-06-25 14:31:53 +04:00
int find_config_tree_bool ( struct cmd_context * cmd , int id , struct profile * profile ) ;
2015-07-08 12:22:24 +03:00
const struct dm_config_node * find_config_tree_array ( struct cmd_context * cmd , int id , struct profile * profile ) ;
2002-01-10 19:47:58 +03:00
2014-03-03 15:47:32 +04:00
/*
2014-03-03 16:24:30 +04:00
* Functions for configuration settings for which the default
* value is evaluated at runtime based on command context .
2014-03-03 15:47:32 +04:00
*/
const char * get_default_devices_cache_dir_CFG ( struct cmd_context * cmd , struct profile * profile ) ;
2015-04-28 16:29:08 +03:00
const char * get_default_unconfigured_devices_cache_dir_CFG ( struct cmd_context * cmd ) ;
2014-03-03 15:47:32 +04:00
const char * get_default_devices_cache_CFG ( struct cmd_context * cmd , struct profile * profile ) ;
2015-04-28 16:29:08 +03:00
const char * get_default_unconfigured_devices_cache_CFG ( struct cmd_context * cmd ) ;
2014-03-03 16:24:30 +04:00
const char * get_default_backup_backup_dir_CFG ( struct cmd_context * cmd , struct profile * profile ) ;
2015-04-28 16:29:08 +03:00
const char * get_default_unconfigured_backup_backup_dir_CFG ( struct cmd_context * cmd ) ;
2014-03-03 16:24:30 +04:00
const char * get_default_backup_archive_dir_CFG ( struct cmd_context * cmd , struct profile * profile ) ;
2015-04-28 16:29:08 +03:00
const char * get_default_unconfigured_backup_archive_dir_CFG ( struct cmd_context * cmd ) ;
2014-03-03 16:30:13 +04:00
const char * get_default_config_profile_dir_CFG ( struct cmd_context * cmd , struct profile * profile ) ;
2015-04-28 16:29:08 +03:00
const char * get_default_unconfigured_config_profile_dir_CFG ( struct cmd_context * cmd ) ;
2014-03-03 16:37:35 +04:00
const char * get_default_activation_mirror_image_fault_policy_CFG ( struct cmd_context * cmd , struct profile * profile ) ;
2015-04-28 16:29:08 +03:00
# define get_default_unconfigured_activation_mirror_image_fault_policy_CFG NULL
2014-03-04 14:10:59 +04:00
int get_default_allocation_thin_pool_chunk_size_CFG ( struct cmd_context * cmd , struct profile * profile ) ;
2015-04-28 16:29:08 +03:00
# define get_default_unconfigured_allocation_thin_pool_chunk_size_CFG NULL
2014-03-04 14:15:54 +04:00
int get_default_allocation_cache_pool_chunk_size_CFG ( struct cmd_context * cmd , struct profile * profile ) ;
2015-04-28 16:29:08 +03:00
# define get_default_unconfigured_allocation_cache_pool_chunk_size_CFG NULL
2015-07-20 12:44:15 +03:00
const char * get_default_allocation_cache_policy_CFG ( struct cmd_context * cmd , struct profile * profile ) ;
# define get_default_unconfigured_allocation_cache_policy_CFG NULL
2016-08-24 11:16:01 +03:00
uint64_t get_default_allocation_cache_pool_max_chunks_CFG ( struct cmd_context * cmd , struct profile * profile ) ;
2014-03-03 15:47:32 +04:00
2001-08-21 16:56:08 +04:00
# endif