Add final liblvm APIs for functional freeze, update tests
cover Add final liblvm APIs for functional freeze, update tests
Add skeletons for the not yet implemented lvresize and pvresize APIs. Add a lvm_config_override API which allows the caller to pass a string, similar to --config, and override the LVM configuration. This is useful to filter devices, which anaconda uses.
Finally, update the tests and fix a couple small bugs in lvm_reload_config.
We think this covers the functionality anaconda needs.
PATCH 1/1 Add skeletons of lvm_lv_resize and lvm_pv_resize - not yet implemented.
From: Thomas Woerner <[email protected]>
These lower-priority interfaces are not currently implemented in liblvm but are on the TODO list in the near term.
Author: Thomas Woerner <[email protected]>
--- liblvm/lvm.h | 24 ++++++++++++++++++++++++ liblvm/lvm_lv.c | 7 +++++++ liblvm/lvm_pv.c | 7 +++++++ 3 files changed, 38 insertions(+), 0 deletions(-)
liblvm/lvm.h +24 -0
@@ -565,6 +565,18 @@ uint64_t lvm_lv_is_active(const lv_t *lv);*/ uint64_t lvm_lv_is_suspended (const lv_t *lv); +/** +* Resize logical volume to new_size bytes. +* +* \param lv +* Logical volume handle. +* \param new_size +* New size in bytes. +* \return 0 (success) or -1 (failure). +* +*/ +int lvm_lv_resize (const lv_t *lv,uint64_t new_size); +/************************** physical volume handling ************************/ /**
@@ -616,4 +628,16 @@ char *lvm_pv_get_name(const pv_t *pv);*/ uint64_t lvm_pv_get_mda_count (const pv_t *pv); +/** +* Resize physical volume to new_size bytes. +* +* \param pv +* Physical volume handle. +* \param new_size +* New size in bytes. +* \return 0 (success) or -1 (failure). +* +*/ +int lvm_pv_resize (const pv_t *pv,uint64_t new_size); +#endif /* _LIB_LVM_H */
liblvm/lvm_lv.c +7 -0
@@ -173,3 +173,10 @@ int lvm_lv_deactivate(lv_t *lv) }return 0 ; } + +int lvm_lv_resize (const lv_t *lv,uint64_t new_size) +{ +/* FIXME: add lv resize code here */ +log_error ("NOT IMPLEMENTED YET\n" ); +return -1 ; +}
liblvm/lvm_pv.c +7 -0
@@ -42,3 +42,10 @@ uint64_t lvm_pv_get_mda_count(const pv_t *pv) {return (uint64_t )pv_mda_count (pv); } + +int lvm_pv_resize (const pv_t *pv,uint64_t new_size) +{ +/* FIXME: add pv resize code here */ +log_error ("NOT IMPLEMENTED YET\n" ); +return -1 ; +}
Signature · 1 line
1.6.0.6
PATCH 1/1 Refactor _override_settings to take the new config string as input.
We will re-use this function from liblvm.
--- tools/lvmcmdline.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
tools/lvmcmdline.c +4 -3
@@ -887,9 +887,9 @@ int help(struct cmd_context *cmd __attribute((unused)), int argc, char **argv)return ret; } -static int _override_settings (struct cmd_context *cmd) +static int _override_settings (struct cmd_context *cmd,const char *config_settings) { -if (!(cmd->cft_override =create_config_tree_from_string (cmd,arg_str_value (cmd, config_ARG,"" )))) { +if (!(cmd->cft_override =create_config_tree_from_string (cmd, config_settings))) {log_error ("Failed to set overridden configuration entries." );return EINVALID_CMD_LINE ; }
@@ -986,7 +986,8 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)set_cmd_name (cmd->command->name);if (arg_count (cmd, config_ARG)) -if ((ret =_override_settings (cmd))) +if ((ret =_override_settings (cmd, +arg_str_value (cmd, config_ARG,"" )))) goto_out;if (arg_count (cmd, config_ARG) || !cmd->config_valid ||config_files_changed (cmd)) {
Signature · 1 line
1.6.0.6
PATCH 1/1 Rename _override_settings into override_config_tree_from_string and move.
Move _override_settings from tools/lvmcmdline.c into lib/config/config.c and export so we can re-use in liblvm.
--- lib/config/config.c | 11 +++++++++++ lib/config/config.h | 2 ++ tools/lvmcmdline.c | 16 ++++------------ 3 files changed, 17 insertions(+), 12 deletions(-)
lib/config/config.c +11 -0
@@ -186,6 +186,17 @@ struct config_tree *create_config_tree_from_string(struct cmd_context *cmd __attreturn cft; } +int override_config_tree_from_string (struct cmd_context *cmd, +const char *config_settings) +{ +if (!(cmd->cft_override =create_config_tree_from_string (cmd,config_settings))) { +log_error ("Failed to set overridden configuration entries." ); +return 1 ; + } + +return 0 ; +} +int read_config_fd (struct 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)
lib/config/config.h +2 -0
@@ -56,6 +56,8 @@ struct config_tree_list {struct config_tree *create_config_tree (const char *filename,int keep_open);struct config_tree *create_config_tree_from_string (struct cmd_context *cmd,const char *config_settings); +int override_config_tree_from_string (struct cmd_context *cmd, +const char *config_settings);void destroy_config_tree (struct config_tree *cft);typedef uint32_t (*checksum_fn_t ) (uint32_t initial,const void *buf,uint32_t size);
tools/lvmcmdline.c +4 -12
@@ -887,16 +887,6 @@ int help(struct cmd_context *cmd __attribute((unused)), int argc, char **argv)return ret; } -static int _override_settings (struct cmd_context *cmd,const char *config_settings) -{ -if (!(cmd->cft_override =create_config_tree_from_string (cmd, config_settings))) { -log_error ("Failed to set overridden configuration entries." ); -return EINVALID_CMD_LINE ; - } - -return 0 ; -} -static void _apply_settings (struct cmd_context *cmd) {init_debug (cmd->current_settings.debug);
@@ -986,9 +976,11 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)set_cmd_name (cmd->command->name);if (arg_count (cmd, config_ARG)) -if ((ret =_override_settings (cmd, -arg_str_value (cmd, config_ARG,"" )))) +if ((ret =override_config_tree_from_string (cmd, +arg_str_value (cmd, config_ARG,"" )))) { + ret =EINVALID_CMD_LINE ; goto_out; + }if (arg_count (cmd, config_ARG) || !cmd->config_valid ||config_files_changed (cmd)) {/* Reinitialise various settings inc. logging, filters */
Signature · 1 line
1.6.0.6
PATCH 1/1 Add lvm_config_override - allow caller to override config, similar to --config.
Allowing the caller to override the LVM configuration with an API will enable them to use things such as device filters.
While very flexible, there is some danger to this API in that it will make it harder to debug setups that have a changing config and deduce what might have happened. At some point we may want to limit the scope of this API but for now it is as open as the --config option to lvm commands.
Update exported symbols. When I renamed lvm_reload_config to lvm_config_reload I forgot to rename so I renamed that one here.
This I believe is the last liblvm API for now. ;-)
--- liblvm/.exported_symbols | 3 ++- liblvm/lvm.h | 16 ++++++++++++++++ liblvm/lvm_base.c | 8 ++++++++ 3 files changed, 26 insertions(+), 1 deletions(-)
liblvm/.exported_symbols +2 -1
@@ -1,6 +1,7 @@ lvm_create lvm_destroy -lvm_reload_config +lvm_config_reload +lvm_config_override lvm_pv_get_name lvm_pv_get_uuid lvm_pv_get_mda_count
liblvm/lvm.h +16 -0
@@ -149,6 +149,22 @@ void lvm_destroy(lvm_t libh);int lvm_config_reload (lvm_t libh);/** +* Override the LVM configuration with a configuration string. +* +* This API is equivalent to the --config option on lvm commands. +* FIXME: submit a patch to document the --config option +* Once this API has been used to over-ride the configuration, +* you should use lvm_config_reload to apply the new settings. +* \param libh +* Handle obtained from lvm_create. +* \param config_settings +* LVM configuration string to apply. See the lvm.conf file man page +* for the format of the config string. +* \return 0 (success) or -1 (failure). +*/ +int lvm_config_override (lvm_t libh,const char *config_string); + +/** * Return stored error no describing last LVM API error. * * Users of liblvm should use lvm_errno to determine success or failure
liblvm/lvm_base.c +8 -0
@@ -72,6 +72,14 @@ int lvm_config_reload(lvm_t libh)return 0 ; } +int lvm_config_override (lvm_t libh,const char *config_settings) +{ +struct cmd_context *cmd = (struct cmd_context *)libh; +if (override_config_tree_from_string (cmd, config_settings)) +return -1 ; +return 0 ; +} +int lvm_errno (lvm_t libh) {return stored_errno ();
Signature · 1 line
1.6.0.6
PATCH 1/1 Update return code for lvm_config_reload.
--- liblvm/lvm_base.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
liblvm/lvm_base.c +1 -1
@@ -67,7 +67,7 @@ void lvm_destroy(lvm_t libh)int lvm_config_reload (lvm_t libh) {/* FIXME: re-init locking needed here? */ -if (refresh_toolcontext ((struct cmd_context *)libh)) +if (!refresh_toolcontext ((struct cmd_context *)libh))return -1 ;return 0 ; }
Signature · 1 line
1.6.0.6
PATCH 1/1 Add config_reload and config_override to test.c.
PV PV UUID VG
/dev/loop1 A95EvV-iqmb-ZFuJ-u8MV-Npwn-wlc2-Ul1Mnn vg1 /dev/loop0 R16FDG-OmoS-HNGt-LSZY-OAlC-7qeU-t2gztp vg1
lvm> config_override loop0
Success overriding LVM configuration
lvm> config_reload
Success reloading LVM configuration
lvm> vg_open vg1
Couldn't find device with uuid 'A95EvV-iqmb-ZFuJ-u8MV-Npwn-wlc2-Ul1Mnn'. Success opening vg vg1
lvm> vg_close vg1
lvm> quit
Maybe a bug in lvm_vg_open for missing pvs but the filter seems to work.
--- test/api/test.c | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-)
test/api/test.c +37 -0
@@ -80,6 +80,10 @@ static void _show_help(void) "Issue a lvm_vg_open() API call on VG 'vgname'\n");printf ("'vg_close vgname': " "Issue a lvm_vg_close() API call on VG 'vgname'\n" ); +printf ("'config_reload': " +"Issue a lvm_config_reload() API to reload LVM config\n" ); +printf ("'config_override' device: " +"Issue a lvm_config_override() with accept device filter\n" );printf ("'quit': exit the program\n" ); }
@@ -221,6 +225,35 @@ static void _vg_reduce(char **argv, int argc, lvm_t libh)_remove_device_from_pvname_hash (pvs, argv[2 ]); } +static void _config_override (char **argv,int argc,lvm_t libh) +{ +int rc; +char tmp[64 ]; + +if (argc <2 ) { +printf ("Please enter device\n" ); +return ; + } +snprintf (tmp,63 ,"devices{filter=[\"a|%s|\", \"r|.*|\"]}" , argv[1 ]); + rc =lvm_config_override (libh, tmp); +if (rc) +printf ("Error " ); +else +printf ("Success " ); +printf ("overriding LVM configuration\n" ); +} + +static void _config_reload (char **argv,int argc,lvm_t libh) +{ +int rc; + rc =lvm_config_reload (libh); +if (rc) +printf ("Error " ); +else +printf ("Success " ); +printf ("reloading LVM configuration\n" ); +} +static void _vg_extend (char **argv,int argc,lvm_t libh) {vg_t *vg;
@@ -521,6 +554,10 @@ static int lvmapi_test_shell(lvm_t libh)break ; }else if (!strcmp (argv[0 ],"?" ) || !strcmp (argv[0 ],"help" )) {_show_help (); + }else if (!strcmp (argv[0 ],"config_reload" )) { +_config_reload (argv, argc, libh); + }else if (!strcmp (argv[0 ],"config_override" )) { +_config_override (argv, argc, libh); }else if (!strcmp (argv[0 ],"vg_extend" )) {_vg_extend (argv, argc, libh); }else if (!strcmp (argv[0 ],"vg_reduce" )) {
Signature · 1 line
1.6.0.6