1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-28 20:25:52 +03:00
Commit Graph

190 Commits

Author SHA1 Message Date
Peter Rajnoha
67c52a4453 config: add CFG_DISABLED flag and mark system_id settings with that flag
If configuration setting is marked in config_setting.h with CFG_DISABLED
flag, default value is always used for such setting, no matter if it's defined
by user (in --config/lvm.conf/lvmlocal.conf).

A warning message is displayed if this happens:

For example:

[1] f21/~ # lvm dumpconfig --validate
  WARNING: Configuration setting global/system_id_source is disabled. Using default value.
  LVM configuration valid.

[1] f21/~ # pvs
  WARNING: Configuration setting global/system_id_source is disabled. Using default value.
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sdb          lvm2 ---  128.00m 128.00m
  ...
2015-03-04 14:08:47 +01:00
Alasdair G Kergon
2a1189ebc3 config: Reinstate recursive tags setting.
In 2.02.99, _init_tags() inadvertently began to ignore the
dm_config_tree struct passed to it.  "tags" sections are not
merged together, so the "tags" section in the main config file was
being processed repeatedly and other "tags" sections were ignored.
2015-02-23 17:40:58 +00:00
Peter Rajnoha
bea003e94c config: improve config validation to check if setting with string value can be empty.
For example, with dmeventd/executable set to "" which is not allowed for
this setting, the config validation now ends up with:

$ lvm dumpconfig --validate
  Configuration setting "dmeventd/executable" invalid. It cannot be set to an empty value.
  LVM configuration invalid.

This check for empty values for string config settings was not
done before (we only checked empty arrays, but not scalar strings).
2015-01-21 16:44:02 +01:00
Zdenek Kabelac
e5356eeba1 cleanup: never return uninitialized buffer
Coverity noticed this function may return untouched buffer,
however in this state can't really happen, but anyway
ensure on error path the buffer will have zero lenght string.
2014-08-26 14:13:06 +02:00
Zdenek Kabelac
894eda4707 thin and cache: unify pool common code
Fix get_pool_params to only read params.
Add poolmetadataspare option to get_pool_params.
Move all profile code into update_pool_params.
Move recalculate code into pool_manip.c
2014-07-22 22:41:38 +02:00
Zdenek Kabelac
86e116450e cleanup: drop unneeded initialization
Code assigns this variable right after clearing.
2014-07-04 12:31:17 +02:00
Peter Rajnoha
3208396ce5 coverity: fix issues reported by coverity 2014-06-24 14:58:53 +02:00
Peter Rajnoha
9c937e7d54 dumpconfig: add --type profilable-command/profilable-metadata, --metadataprofile/--commandprofile
The dumpconfig now understands --commandprofile/--profile/--metadataprofile

The --commandprofile and --profile functionality is almost the same
with only one difference and that is that the --profile is just used
for dumping the content, it's not applied for the command itself
(while the --commandprofile profile is applied like it is done for
any other LVM command).

We also allow --metadataprofile for dumpconfig - dumpconfig *does not*
touch VG/LV and metadata in any way so it's OK to use it here (just for
dumping the content, checking the profile validity etc.).

The validity of the profile can be checked with:
      dumpconfig --commandprofile/--profile/--metadataprofile --validate

...depending on the profile type.

Also, mention --config in the dumpconfig help string so users know
that  dumpconfig handles this too (it did even before, but it was not
documented in the help string).
2014-05-20 16:27:07 +02:00
Peter Rajnoha
9e3e4d6994 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:21:48 +02:00
Peter Rajnoha
c42f72867a config: attach cft_check_handle to each config tree instead of global cmd_context
Before, the cft_check_handle used to direct configuration checking
was part of cmd_context. It's better to attach this as part of the
exact config tree against which the check is done. This patch moves
the cft_check_handle out of cmd_context and it attaches it to the
config tree directly as dm_config_tree->custom->config_source->check_handle.

This change makes it easier to track the config tree check results
and provides less space for bugs as the results are directly attached
to the tree and we don't need to be cautious whether the global value
is correct or not (and whether it needs reinitialization) as it was
in the case when the cft_check_handle was part of cmd_context.
2014-05-19 15:38:04 +02:00
Peter Rajnoha
ff9d27a1c7 config: add CONFIG_FILE_SPECIAL config source id
Add CONFIG_FILE_SPECIAL config source id to make a difference between
real configuration tree (like lvm.conf and tag configs) and special purpose
configuration tree (like LVM metadata, persistent filter).

This makes it easier to attach correct customized data to the config
tree that is created out of the source then.
2014-05-19 15:37:41 +02:00
Zdenek Kabelac
85cf5a23d2 cleanup: improve error message
Update impossile to happen error message.
2014-05-13 10:33:17 +02:00
Zdenek Kabelac
a8042f33d0 coverity: check for profile
Ensure str is not NULL for analyzer.
2014-05-07 14:15:52 +02:00
Peter Rajnoha
4e47c34ffc config: also check empty arrays for difference against default values 2014-03-24 16:30:47 +01:00
Peter Rajnoha
5dcec1734e dumpconfig: add dumpconfig --type diff to show differences from defaults 2014-03-24 15:35:54 +01:00
Peter Rajnoha
76ff38fa5c config: add support for comparing used config values with default ones 2014-03-24 15:35:47 +01:00
Peter Rajnoha
630e0af14e cleanup: move _get_def_array_values fn
So we can use reuse it for the code that will follow...
2014-03-24 15:20:19 +01:00
Peter Rajnoha
000e81a999 cleanup: add cmd_context reference to struct cft_check_handle
So we have all things needed to do a configuration check packaged
in one handle. It makes function calls inside a bit more readable.
2014-03-19 08:45:05 +01:00
Peter Rajnoha
bfffccca94 config: keep config paths with variable names properly marked on output 2014-03-07 18:04:02 +01:00
Peter Rajnoha
eeff7729d9 config: use small local static buffer instead of mempool for temporary config path
We can't use mempool for temporary variable for configuration path inside
find_config_tree_* functions since these functions can use the mempool
themselves deeper in the code and we can free mempool chunks only from
top to bottom which is not the case here (some default string
configuration values can be allocated from the mempool).
2014-03-07 17:50:01 +01:00
Peter Rajnoha
7409009a20 cleanup: remove superfluous slash in default cache dir path 2014-03-07 13:03:09 +01:00
Peter Rajnoha
74a3fc4e85 config: add default for allocation/cache_pool_chunk_size
The same as for allocation/thin_pool_chunk_size - the default value
used is just a starting point. The calculation continues using the
properties of the devices actually used.
2014-03-06 11:34:02 +01:00
Peter Rajnoha
d27868e94f config: runtime default for allocation/thin_pool_chunk_size
The allocation/thin_pool_chunk_size is a bit more complex. It's default
value is evaluated in runtime based on selected thin_pool_chunk_size_policy.
But the value is just a starting point. The calculation then continues
with dependency on the properties of the devices used. Which means for
such a default value, we know only the starting value.
2014-03-06 11:26:02 +01:00
Peter Rajnoha
932e75e89f config: separate cfg_def_default_value_hint out of cfg_def_get_default_value
If the config setting is defined as having no default value, but it's
still not NULL, it means such a value acts as a *hint* only
(e.g. a starting value from which the default value is calculated).

The new "cfg_def_get_default_value_hint" will always return the value
as defined in config_settings.h.

The original "cfg_def_get_default_value" will always return 0/NULL if
the config setting is defined with CFG_DEFAULT_UNDEFINED flag (hence
ignoring the hint).

This is needed for proper distiction between a correct default value
and the value which is just a hint or a starting point in calculation,
but it's not the final value (yes, we do have such settings!).
2014-03-06 11:18:19 +01:00
Peter Rajnoha
eecf191d3e config: runtime default for activation/mirror_image_fault_policy
The activation/mirror_image_fault_policy default value copies the
value (or default one) used for activation/mirror_device_fault_policy.
2014-03-06 11:16:23 +01:00
Peter Rajnoha
11039589d3 config: runtime default for config/profile_dir
The config/profile_dir default value takes LVM_SYSTEM_DIR into consideraton.
2014-03-06 11:16:04 +01:00
Peter Rajnoha
0da1e5d9f8 config: runtime default for backup/backup_dir, backup/archive_dir
The backup/backup_dir and backup/archive_dir default value is evaluated
in runtime and takes LVM_SYSTEM_DIR into consideration...
2014-03-06 11:15:21 +01:00
Peter Rajnoha
f6adef9825 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).
2014-03-06 11:07:54 +01:00
Peter Rajnoha
b53ec37286 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-06 10:54:17 +01:00
Peter Rajnoha
e2870c94cf config: use mempool for config paths used in find_config_tree_* functions
Using mempool is much safer than using the global static variable.
The global variable would be rewritten on each find_config_tree_* call
and we need to be very careful not to get into this problem (we don't
do now, but we can with the patches for "runtime defaults" that will follow).
2014-03-06 10:50:47 +01:00
Peter Rajnoha
f8bf4d7dfb dumpconfig: add a comment to each config with variable name, use '<name>' to denote that for config paths
Just to make the dumpconfig output (the comments) more readable
when we hit configuration lines that have variable names (e.g. tags).
2014-02-25 11:32:54 +01:00
Peter Rajnoha
558c932444 dumpconfig: comment out config lines without default values defined
To make "lvm dumpconfig --type default" output to be usable like any
other config, we need to comment out lines that have no default value
defined. Otherwise, we'd have the output with config options
with blank or zero values which is not the same as when the value
is not defined! And such configuration can't be feed into lvm again
without further edits. So let's fix this.

Currently this covers these configuration options exactly:

  devices/loopfiles
  devices/preferred_names
  devices/filter
  devices/global_filter
  devices/types
  allocation/cling_tag_list
  global/format_libraries
  global/segment_libraries
  activation/volume_list
  activation/auto_activation_volume_list
  activation/read_only_volume_list
  activation/mlock_filter
  metadata/dirs
  metadata/disk_areas
  metadata/disk_areas/<disk_area>
  metadata/disk_areas/<disk_area>/start_sector
  metadata/disk_areas/<disk_area>/size
  metadata/disk_areas/<disk_area>/id
  tags/<tag>
  tags/<tag>/host_list
2014-02-25 11:32:54 +01:00
Peter Rajnoha
2f61478436 workaround: gcc v4.8 on 32 bit param. passing bug when -02 opimization used
gcc -O2 v4.8 on 32 bit architecture is causing a bug in parameter
passing. It does not happen with -01 nor -O0.

The problematic part of the code was strlen use in config.c in
the config_def_check fn and the call for _config_def_check_tree in it:

<snip>
  rplen = strlen(rp);
  if (!_config_def_check_tree(handle, vp, vp + strlen(vp), rp, rp + rplen, CFG_PATH_MAX_LEN - rplen, cn, cmd->cft_def_hash)) ...
</snip>

If compiled with -O0 (correct):

Breakpoint 1, config_def_check (cmd=0x819b050, handle=0x81a04f8) at config/config.c:775
(gdb) p	vp
$1 = 0x8189ee0 <_cfg_path> "config"
(gdb) p	strlen(vp)
$2 = 6
(gdb)
_config_def_check_tree (handle=0x81a04f8, vp=0x8189ee0 <_cfg_path>
"config", pvp=0x8189ee6 <_cfg_path+6> "", rp=0xbfffe1e8 "config",
prp=0xbfffe1ee "", buf_size=58, root=0x81a2568, ht=0x81a65
48) at config/config.c:680
(gdb) p	vp
$4 = 0x8189ee0 <_cfg_path> "config"
(gdb) p	pvp
$5 = 0x8189ee6 <_cfg_path+6> ""

If compiled with -O2 (incorrect):

Breakpoint 1, config_def_check (cmd=cmd@entry=0x8183050, handle=0x81884f8) at config/config.c:775
(gdb) p	vp
$1 = 0x8172fc0 <_cfg_path> "config"
(gdb) p strlen(vp)
$2 = 6
(gdb) p	vp + strlen(vp)
$3 = 0x8172fc6 <_cfg_path+6> ""
(gdb)
_config_def_check_tree (handle=handle@entry=0x81884f8, pvp=0x8172fc7
<_cfg_path+7> "host_list", rp=rp@entry=0xbffff190 "config",
prp=prp@entry=0xbffff196 "", buf_size=buf_size@entry=58, ht=0x
818e548, root=0x818a568, vp=0x8172fc0 <_cfg_path> "config") at
config/config.c:674
(gdb) p	pvp
$4 = 0x8172fc7 <_cfg_path+7> "host_list"

The difference is in passing the "pvp" arg for _config_def_check_tree.
While in the correct case, the value of _cfg_path+6 is passed
(the result of vp + strlen(vp) - see the snippet of the code above),
in the incorrect case, this value is increased by 1 to _cfg_path+7,
hence totally malforming the string that is being processed.

This ends up with incorrect validation check and incorrect warning
messages are issued like:

 "Configuration setting "config/checks" has invalid type. Found integer, expected section."

To workaround this issue, remove the "static" qualifier from the
"static char _cfg_path[CFG_PATH_MAX_LEN]". This causes the optimalizer
to be less aggressive (also shuffling the arg list for
_config_def_check_tree call helps).
2013-08-09 13:24:50 +02:00
Peter Rajnoha
a9dbe2c4fa fix: apply profile and then get the config path + auto_set_activation not profilable
cfg_def_get_path uses a global static var to store the result (for efficiency).
So we need to apply the profile first and then get the path for the config item
when calling find_config_tree_* fns.

Also activation/auto_set_activation is not profilable (at least not now,
maybe later if we need that).
2013-07-15 13:33:14 +02:00
Peter Rajnoha
618d13705c config: fix unterminated strings in arrays
...when creating config trees while calling config_def_create_tree fn
that constructs a tree out of config_settings.h definition
(CFG_DEF_TREE_NEW/MISSING/DEFAULT/PROFILABLE).
2013-07-09 13:49:58 +02:00
Peter Rajnoha
934616d4c7 dumpconfig: honour --atversion with --type profilable
raw/~ $ lvm dumpconfig --type profilable
  allocation {
	  thin_pool_zero=1
	  thin_pool_discards="passdown"
	  thin_pool_chunk_size=64
  }
  activation {
	  thin_pool_autoextend_threshold=100
	  thin_pool_autoextend_percent=20
  }

  raw/~ $ lvm dumpconfig --type profilable --atversion 2.2.90
  activation {
	  thin_pool_autoextend_threshold=100
	  thin_pool_autoextend_percent=20
  }
2013-07-09 10:23:46 +02:00
Peter Rajnoha
953a438e93 dumpconfig: add --type profilable
The --type profilable shows all config settings that
are customizable by profiles:

  raw/~ $ lvm dumpconfig --type profilable
  allocation {
	  thin_pool_zero=1
	  thin_pool_discards="passdown"
	  thin_pool_chunk_size=64
  }
  activation {
	  thin_pool_autoextend_threshold=100
	  thin_pool_autoextend_percent=20
  }
2013-07-09 10:00:47 +02:00
Peter Rajnoha
f1e2890012 config: make it possible to do a raw config tree merge
Till now, we needed the config tree merge only for merging
tag configs with lvm.conf. However, this type of merging
did a few extra exceptions:

  - leaving out the tags section
  - merging values in activation/volume_list
  - merging values in devices/filter
  - merging values in devices/types

Any other config values were replaced by new values.
However, we'd like to do a 'raw merge' as well, simply
bypassing the exceptions listed above. This will help
us to create a single tree representing the cascaded
configs like CONFIG_STRING -> CONFIG_PROFILE -> ...

The reason for this patch is that when trees are cascaded,
the first value found while traversing the cascade is used,
not making any exceptions like we do for tag configs.
2013-07-08 15:59:25 +02:00
Peter Rajnoha
661406a417 config: fix use of last config check status if creating CFG_DEF_TREE_MISSING tree
When CFG_DEF_TREE_MISSING is created, it needs to know the status
of the check done on the tree used (the CFG_USED flag).

This bug was introduced with f1c292cc38
"make it possible to run several instances of configuration check at
once". This patch separated the CFG_USED and CFG_VALID flags in
a separate 'status' field in struct cft_check_handle.

However, when creating some trees, like CFG_DEF_TREE_MISSING,
we need this status to do a comparison with full config definition
to determine which items are missing and for which default values
were used. Otherwise, all items would be considered missing.

So, pass this status in a new field called 'check_status' in
struct config_def_tree_spec that defines how the (dumpconfig) tree
should be constructed (and this struct is passed to
config_def_create_tree fn then).
2013-07-08 15:57:49 +02:00
Peter Rajnoha
1cb66fe16e config: fix timestamp comparison during merge 2013-07-04 14:51:37 +02:00
Peter Rajnoha
9c12a23a99 profile: strictly require profiles to be valid
We must ensure that the profile is valid and contains
only items that are profilable - the check is forced
for profiles.
2013-07-02 15:22:11 +02:00
Peter Rajnoha
e8832917f6 config: add validation for configuration profiles
Besides the classical configuration checks (type checking and
checking whether the item is recognized by lvm tools) for profiles,
do an extra check whether the configuration setting is customizable
by a profile at all. Give a warning message if not.
2013-07-02 15:22:11 +02:00
Peter Rajnoha
f1c292cc38 config: make it possible to run several instances of configuration check at once
Before, the status of the configuration check (config_def_check fn call)
was saved directly in global configuration definitinion array (as part
of the cfg_def_item_t/flags)

This patch introduces the "struct cft_check_handle" that defines
configuration check parameters as well as separate place to store
the status (status here means CFG_USED and CFG_VALID flags, formerly
saved in cfg_def_item_t/flags). This struct can hold config check
parameters as well as the status for each config tree separately,
thus making it possible to run several instances of config_def_check
without interference.
2013-07-02 15:22:11 +02:00
Peter Rajnoha
d6a91da4be config: add profile arg to find_config_tree_bool 2013-07-02 15:19:09 +02:00
Peter Rajnoha
aeffa4cb5b config: add profile arg to find_config_tree_float 2013-07-02 15:19:09 +02:00
Peter Rajnoha
dbea545ffb config: add profile arg to find_config_tree_int64 2013-07-02 15:19:09 +02:00
Peter Rajnoha
50bf2c0db1 config: add profile arg to find_config_tree_int 2013-07-02 15:19:09 +02:00
Peter Rajnoha
8ac4fcf8ff config: add profile arg to find_config_tree_str_allow_empty 2013-07-02 15:19:09 +02:00
Peter Rajnoha
06dd66af54 config: add profile arg to find_config_tree_str 2013-07-02 15:19:09 +02:00
Peter Rajnoha
eeb7b0f7fa config: add profile arg to find_config_tree_node 2013-07-02 15:19:09 +02:00