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 ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 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
2005-10-17 03:03:59 +04:00
# include "lvm-types.h"
2013-03-05 19:49:42 +04:00
# include "defaults.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 device ;
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_PROFILE /* profile config */
} config_source_t ;
2013-06-25 14:27:04 +04:00
struct profile {
struct dm_list list ;
const char * name ;
struct dm_config_tree * cft ;
} ;
struct profile_params {
const char * dir ; /* subdir in LVM_SYSTEM_DIR where LVM looks for profiles */
struct profile * global_profile ; /* profile that overrides any other VG/LV-based profile ('--profile' cmd line arg) */
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 */
} ;
2013-03-05 19:49:42 +04:00
# define CFG_PATH_MAX_LEN 64
/*
* 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 ;
/* configuration definition item value (for item's default value) */
typedef union {
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 ;
} cfg_def_value_t ;
/* configuration definition item flags: */
/* whether the configuration item name is variable */
# define CFG_NAME_VARIABLE 0x01
/* whether empty value is allowed */
# define CFG_ALLOW_EMPTY 0x02
/* whether the configuration item is for advanced use only */
# define CFG_ADVANCED 0x04
2013-06-26 18:27:28 +04:00
/* whether the configuration item is not officially supported */
2013-03-05 19:49:42 +04:00
# define CFG_UNSUPPORTED 0x08
2013-06-26 18:27:28 +04:00
/* whether the configuration item is customizable by a profile */
# define CFG_PROFILABLE 0x10
2013-03-05 19:49:42 +04:00
/* configuration definition item structure */
typedef struct cfg_def_item {
int id ; /* ID of this item */
int parent ; /* ID of parent item */
const char * name ; /* name of the item in configuration tree */
cfg_def_type_t type ; /* configuration item type */
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 */
const char * comment ; /* brief comment */
} 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 */
CFG_DEF_TREE_COMPLETE , /* CURRENT + MISSING, the tree actually used within execution, not implemented yet */
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 */
CFG_DEF_TREE_PROFILABLE /* tree of all nodes that are customizable by profiles */
2013-03-05 20:36:10 +04:00
} cfg_def_tree_t ;
/* configuration definition tree specification */
struct config_def_tree_spec {
cfg_def_tree_t type ; /* tree type */
uint16_t version ; /* tree at this LVM2 version */
int ignoreadvanced ; /* do not include advanced configs */
int ignoreunsupported ; /* do not include unsupported configs */
2013-07-08 16:13:09 +04: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
2013-03-05 19:49:42 +04:00
/*
* Register ID for each possible item in the configuration tree .
*/
enum {
# define cfg_section(id, name, parent, flags, since_version, comment) id,
# define cfg(id, name, parent, flags, type, default_value, since_version, comment) id,
# define cfg_array(id, name, parent, flags, types, default_value, since_version, comment) id,
# include "config_settings.h"
# undef cfg_section
# undef cfg
# undef cfg_array
} ;
2013-06-25 14:27:04 +04:00
struct profile * add_profile ( struct cmd_context * cmd , const char * profile_name ) ;
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 {
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 */
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 ) ;
2013-06-26 16:53:57 +04:00
int config_def_check ( struct cmd_context * cmd , struct cft_check_handle * handle ) ;
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 ) ;
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 ) ;
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 ) ;
2011-12-19 01:56:03 +04:00
int config_file_read_fd ( struct dm_config_tree * cft , struct device * dev ,
off_t offset , size_t size , off_t offset2 , size_t size2 ,
checksum_fn_t checksum_fn , uint32_t checksum ) ;
2013-01-19 15:04:17 +04:00
int config_file_read ( struct dm_config_tree * cft ) ;
2013-06-25 14:25:43 +04:00
struct dm_config_tree * config_file_open_and_read ( const char * config_file , config_source_t source ) ;
2013-03-05 21:21:13 +04:00
int config_write ( struct dm_config_tree * cft ,
int withcomment , int withversion ,
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
time_t config_file_timestamp ( struct dm_config_tree * cft ) ;
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
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 ) ;
2002-01-10 19:47:58 +03:00
2001-08-21 16:56:08 +04:00
# endif