1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

lvmcmdlib: lvm2_init_threaded

cmd context has 'threaded' value that used be set
by clvmd - and allowed proper memory locking management.
Reuse same bit for dmeventd.

Since dmeventd is using 300KiB stack per thread,
we will ignore any user settings for allocation/reserved_stack
until some better solution is find.
This avoids crashing of dmevend when user changes this value
and because in most cases lvm2 should work ok with 64K stack
size, this change should not cause any problems.
This commit is contained in:
Zdenek Kabelac 2020-10-20 22:22:52 +02:00
parent 756066a2e8
commit bd272e3bce
7 changed files with 28 additions and 10 deletions

View File

@ -71,7 +71,7 @@ int dmeventd_lvm2_init(void)
if (!_lvm_handle) {
lvm2_log_fn(_lvm2_print_log);
if (!(_lvm_handle = lvm2_init()))
if (!(_lvm_handle = lvm2_init_threaded()))
goto out;
/*

View File

@ -17,5 +17,10 @@
void *lvm2_init(void)
{
return cmdlib_lvm2_init(1);
return cmdlib_lvm2_init(1, 0);
}
void *lvm2_init_threaded(void)
{
return cmdlib_lvm2_init(1, 1);
}

View File

@ -17,7 +17,12 @@
void *lvm2_init(void)
{
return cmdlib_lvm2_init(0);
return cmdlib_lvm2_init(0, 0);
}
void *lvm2_init_threaded(void)
{
return cmdlib_lvm2_init(0, 1);
}
int lvm_shell(struct cmd_context *cmd __attribute__((unused)),

View File

@ -58,6 +58,12 @@ void lvm2_log_fn(lvm2_log_fn_t log_fn);
*/
void *lvm2_init(void);
/*
* Initialise library for threaded user
* Returns a handle so repeated use of lvm2_run is more efficient.
*/
void *lvm2_init_threaded(void);
/*
* Disable any dmeventd calls that the library may otherwise do. Useful to avoid
* recursive calls from dmeventd to itself.

View File

@ -28,10 +28,10 @@ struct cmdline_context {
int lvm2_main(int argc, char **argv);
void *cmdlib_lvm2_init(unsigned static_compile);
void *cmdlib_lvm2_init(unsigned static_compile, unsigned threaded);
void lvm_fin(struct cmd_context *cmd);
struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters);
struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters, unsigned threaded);
int lvm_register_commands(struct cmd_context *cmdtool, const char *name);
int lvm_split(char *str, int *argc, char **argv, int max);
int lvm_run_command(struct cmd_context *cmd, int argc, char **argv);

View File

@ -25,12 +25,12 @@
#include <time.h>
#include <sys/resource.h>
void *cmdlib_lvm2_init(unsigned static_compile)
void *cmdlib_lvm2_init(unsigned static_compile, unsigned threaded)
{
struct cmd_context *cmd;
init_is_static(static_compile);
if (!(cmd = init_lvm(1, 1)))
if (!(cmd = init_lvm(1, 1, threaded)))
return NULL;
if (!lvm_register_commands(cmd, NULL))

View File

@ -3434,7 +3434,9 @@ static int _close_stray_fds(const char *command, struct custom_fds *custom_fds)
return 1;
}
struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters)
struct cmd_context *init_lvm(unsigned set_connections,
unsigned set_filters,
unsigned threaded)
{
struct cmd_context *cmd;
@ -3448,7 +3450,7 @@ struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters)
*/
dm_set_name_mangling_mode(DM_STRING_MANGLING_NONE);
if (!(cmd = create_toolcontext(0, NULL, 1, 0,
if (!(cmd = create_toolcontext(0, NULL, 1, threaded,
set_connections, set_filters))) {
udev_fin_library_context();
return_NULL;
@ -3602,7 +3604,7 @@ int lvm2_main(int argc, char **argv)
if (!alias && (argc > 2) && !strcmp(argv[2], "-?"))
argv[2] = (char *)"-h";
if (!(cmd = init_lvm(0, 0)))
if (!(cmd = init_lvm(0, 0, 0)))
return EINIT_FAILED;
/* Store original argv location so we may customise it if we become a daemon */