Use common functions for module loading and unloading
PATCH v3 1/4 Use common functions for module loading and unloading
In reply to a message not in the archiveModule loading (and unloading) is identical for control and data modules so use common funtions to avoid code duplication.
--- src/bin/lttng-sessiond/modprobe.c | 109 ++++++++++++------------------------- 1 file changed, 34 insertions(+), 75 deletions(-)
src/bin/lttng-sessiond/modprobe.c +34 -75
@@ -83,18 +83,16 @@ const struct kern_modules_param kern_modules_list[] = { { "lttng-probe-writeback", 0 }, }; -/* -* Remove control kernel module(s) in reverse load order. -*/ -void modprobe_remove_lttng_control (void ) +void modprobe_remove_lttng (const struct kern_modules_param *modules, +int entries) {int ret =0 , i;char modprobe[256 ]; -for (i =ARRAY_SIZE (kern_modules_control) -1 ; i >=0 ; i--) { +for (i = entries -1 ; i >=0 ; i--) { ret =snprintf (modprobe,sizeof (modprobe),"/sbin/modprobe -r -q %s" , - kern_modules_control[i].name); + modules[i].name);if (ret <0 ) {PERROR ("snprintf modprobe -r" ); goto error;
@@ -116,6 +114,16 @@ void modprobe_remove_lttng_control(void) error:return ; + +} + +/* +* Remove control kernel module(s) in reverse load order. +*/ +void modprobe_remove_lttng_control (void ) +{ +return modprobe_remove_lttng (kern_modules_control, +ARRAY_SIZE (kern_modules_control)); }/*
@@ -123,34 +131,8 @@ error:*/ void modprobe_remove_lttng_data (void ) { -int ret =0 , i; -char modprobe[256 ]; - -for (i =ARRAY_SIZE (kern_modules_list) -1 ; i >=0 ; i--) { - ret =snprintf (modprobe,sizeof (modprobe), -"/sbin/modprobe -r -q %s" , - kern_modules_list[i].name); -if (ret <0 ) { -PERROR ("snprintf modprobe -r" ); - goto error; - } - modprobe[sizeof (modprobe) -1 ] ='\0' ; - ret =system (modprobe); -if (ret ==-1 ) { -ERR ("Unable to launch modprobe -r for module %s" , - kern_modules_list[i].name); - }else if (kern_modules_list[i].required - &&WEXITSTATUS (ret) !=0 ) { -ERR ("Unable to remove module %s" , - kern_modules_list[i].name); - }else { -DBG ("Modprobe removal successful %s" , - kern_modules_list[i].name); - } - } - -error: -return ; +return modprobe_remove_lttng (kern_modules_list, +ARRAY_SIZE (kern_modules_list)); }/*
@@ -162,19 +144,16 @@ void modprobe_remove_lttng_all(void)modprobe_remove_lttng_control (); } -/* -* Load control kernel module(s). -*/ -int modprobe_lttng_control (void ) +static int modprobe_lttng (const struct kern_modules_param *modules,int entries) {int ret =0 , i;char modprobe[256 ]; -for (i =0 ; i <ARRAY_SIZE (kern_modules_control); i++) { +for (i =0 ; i < entries; i++) { ret =snprintf (modprobe,sizeof (modprobe),"/sbin/modprobe %s%s" , - kern_modules_control[i].required ?"" :"-q " , - kern_modules_control[i].name); + modules[i].required ?"" :"-q " , + modules[i].name);if (ret <0 ) {PERROR ("snprintf modprobe" ); goto error;
@@ -183,14 +162,13 @@ int modprobe_lttng_control(void) ret =system (modprobe);if (ret ==-1 ) {ERR ("Unable to launch modprobe for module %s" , - kern_modules_control[i].name); - }else if (kern_modules_control[i].required - &&WEXITSTATUS (ret) !=0 ) { + modules[i].name); + }else if (modules[i].required &&WEXITSTATUS (ret) !=0 ) {ERR ("Unable to load module %s" , - kern_modules_control[i].name); + modules[i].name); }else {DBG ("Modprobe successfully %s" , - kern_modules_control[i].name); + modules[i].name); } }
@@ -199,37 +177,18 @@ error: }/* +* Load control kernel module(s). +*/ +int modprobe_lttng_control (void ) +{ +return modprobe_lttng (kern_modules_control, +ARRAY_SIZE (kern_modules_control)); +} +/* * Load data kernel module(s). */ int modprobe_lttng_data (void ) { -int ret =0 , i; -char modprobe[256 ]; - -for (i =0 ; i <ARRAY_SIZE (kern_modules_list); i++) { - ret =snprintf (modprobe,sizeof (modprobe), -"/sbin/modprobe %s%s" , - kern_modules_list[i].required ?"" :"-q " , - kern_modules_list[i].name); -if (ret <0 ) { -PERROR ("snprintf modprobe" ); - goto error; - } - modprobe[sizeof (modprobe) -1 ] ='\0' ; - ret =system (modprobe); -if (ret ==-1 ) { -ERR ("Unable to launch modprobe for module %s" , - kern_modules_list[i].name); - }else if (kern_modules_list[i].required - &&WEXITSTATUS (ret) !=0 ) { -ERR ("Unable to load module %s" , - kern_modules_list[i].name); - }else { -DBG ("Modprobe successfully %s" , - kern_modules_list[i].name); - } - } - -error: -return ret; +return modprobe_lttng (kern_modules_list, +ARRAY_SIZE (kern_modules_list)); }
Signature · 1 line
1.7.9.5
PATCH v3 2/4 Seperate probe modules from control modules
In reply to a message not in the archiveMove all control modules to the control list and make a seperate probes list.
--- src/bin/lttng-sessiond/modprobe.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
src/bin/lttng-sessiond/modprobe.c +12 -12
@@ -25,16 +25,9 @@#include "modprobe.h" #include "kern-modules.h" -/* MUST be loaded first */ +/* LTTng kernel tracer base modules list */ const struct kern_modules_param kern_modules_control[] = { - {"lttng-tracer" ,1 }, -}; - -/* LTTng kernel tracer modules list */ -const struct kern_modules_param kern_modules_list[] = { - {"lttng-ftrace" ,0 }, - {"lttng-kprobes" ,0 }, - {"lttng-kretprobes" ,0 }, + {"lttng-tracer" ,1 },/* MUST be loaded first so keep at top */ {"lttng-lib-ring-buffer" ,1 }, {"lttng-ring-buffer-client-discard" ,1 }, {"lttng-ring-buffer-client-overwrite" ,1 },
@@ -43,6 +36,13 @@ const struct kern_modules_param kern_modules_list[] = { { "lttng-ring-buffer-client-mmap-overwrite", 1 }, { "lttng-ring-buffer-metadata-mmap-client", 1 }, { "lttng-types", 0 }, + { "lttng-ftrace", 0 }, + { "lttng-kprobes", 0 }, + { "lttng-kretprobes", 0 }, +}; + +/* LTTng kernel tracer probe modules list */ +const struct kern_modules_param kern_modules_probes[] = { {"lttng-probe-asoc" ,0 }, {"lttng-probe-block" ,0 }, { "lttng-probe-btrfs", 0 },
@@ -131,7 +131,7 @@ void modprobe_remove_lttng_control(void)*/ void modprobe_remove_lttng_data (void ) { -return modprobe_remove_lttng (kern_modules_list, +return modprobe_remove_lttng (kern_modules_probes,ARRAY_SIZE (kern_modules_list)); }
@@ -189,6 +189,6 @@ int modprobe_lttng_control(void)*/ int modprobe_lttng_data (void ) { -return modprobe_lttng (kern_modules_list, -ARRAY_SIZE (kern_modules_list)); +return modprobe_lttng (kern_modules_probes, +ARRAY_SIZE (kern_modules_probes)); }
Signature · 1 line
1.7.9.5
PATCH v3 3/4 Remove required parameter from module parameters
In reply to a message not in the archiveRemove the per module required parameter by adding another list for optional core modules, so we have:
- required core modules
- optional core modules
- optional probe modules
--- src/bin/lttng-sessiond/kern-modules.h | 1 - src/bin/lttng-sessiond/modprobe.c | 169 ++++++++++++++++++--------------- 2 files changed, 93 insertions(+), 77 deletions(-)
src/bin/lttng-sessiond/kern-modules.h +0 -1
@@ -29,7 +29,6 @@struct kern_modules_param {const char *name; -int required; };#endif /* _KERN_MODULES_H */
src/bin/lttng-sessiond/modprobe.c +93 -76
240 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v3 4/4 Configurable kernel module probes support
In reply to a message not in the archiveCreate a kernel module probes list and use it to load the specified probes. The probes are selectable by the --kmod-probes command line option to lttng-sessiond or the LTTNG_KMOD_PROBES environment variable. If neither is set all probes are loaded so the current behaviour is not changed.
--- doc/man/lttng-sessiond.8 | 7 +++ src/bin/lttng-sessiond/kern-modules.h | 2 +- src/bin/lttng-sessiond/main.c | 5 ++ src/bin/lttng-sessiond/modprobe.c | 87 +++++++++++++++++++++++++++------ src/bin/lttng-sessiond/modprobe.h | 2 + src/common/defaults.h | 3 ++ src/common/utils.c | 10 ++++ src/common/utils.h | 1 + 8 files changed, 102 insertions(+), 15 deletions(-)
doc/man/lttng-sessiond.8 +7 -0
@@ -81,6 +81,11 @@ No kernel tracer support .BR " --jul-tcp-port" JUL application registration TCP port (default: 5345) .TP +.BR " --kmod-probes=probe1, probe2, ..." +Specify the kernel modules containing LTTng probes to load by the session daemon. +Only the component name of the probe needs to be specified, e.g. to load the +lttng-probe-irq and lttng-probe-sched use: --kmod-probes="irq, sched". +.TP .BR "-c, --client-sock=PATH" Specify path for the client unix socket .TP
@@ -150,6 +155,8 @@ parameter: the timeout value, in milliseconds. A value of 0 or -1 uses the timeout of the operating system (this is the default). .IP "LTTNG_SESSION_CONFIG_XSD_PATH" Specify the path that contains the XML session configuration schema (xsd). +.IP "LTTNG_KMOD_PROBES" +Specify the kernel modules probes that should be loaded by the session daemon. .SH "SEE ALSO" .PP
src/bin/lttng-sessiond/kern-modules.h +1 -1
@@ -28,7 +28,7 @@#define KERN_MODULES_MINOR 0struct kern_modules_param { -const char *name; +char *name; };#endif /* _KERN_MODULES_H */
src/bin/lttng-sessiond/main.c +5 -0
@@ -155,6 +155,7 @@ static const struct option long_options[] = { { "jul-tcp-port", 1, 0, 'J' }, { "config", 1, 0, 'f' }, { "load", 1, 0, 'l' }, + { "kmod-probes", 1, 0, 'P' }, { NULL, 0, 0, 0 } };
@@ -4132,6 +4133,7 @@ static void usage(void)fprintf (stderr," --jul-tcp-port JUL application registration TCP port\n" );fprintf (stderr," -f --config Load daemon configuration file\n" );fprintf (stderr," -l --load PATH Load session configuration\n" ); +fprintf (stderr," --kmod-probes Specify kernel module probes to load\n" ); }/*
@@ -4258,6 +4260,9 @@ static int set_option(int opt, const char *arg, const char *optname) ret = -ENOMEM ; }break ; +case 'P' :/* probe modules list */ + kmod_probes_list =strdup (arg); +break ;default :/* Unknown option or other error. * Error is printed by getopt, just return */
src/bin/lttng-sessiond/modprobe.c +73 -14
140 lines not on this page · raw message
src/bin/lttng-sessiond/modprobe.h +2 -0
@@ -24,4 +24,6 @@ void modprobe_remove_lttng_data(void);int modprobe_lttng_control (void );int modprobe_lttng_data (void ); +char *kmod_probes_list; +#endif /* _MODPROBE_H */
src/common/defaults.h +3 -0
@@ -90,6 +90,9 @@#define DEFAULT_LTTNG_SESSIOND_PIDFILE "lttng-sessiond.pid"#define DEFAULT_LTTNG_SESSIOND_JULPORT_FILE "jul.port" +/* Default probes list */ +#define DEFAULT_LTTNG_KMOD_PROBES "LTTNG_KMOD_PROBES" +/* Default unix socket path */ #define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK DEFAULT_LTTNG_RUNDIR "/client-lttng-sessiond"#define DEFAULT_HOME_CLIENT_UNIX_SOCK DEFAULT_LTTNG_HOME_RUNDIR "/client-lttng-sessiond"
src/common/utils.c +10 -0
@@ -870,6 +870,16 @@ end: }/* +* Obtain the value of LTTNG_KMOD_PROBES environment variable, if exists. +* Otherwise returns an empty string. +*/ +LTTNG_HIDDEN +char *utils_get_kmod_probes_list(void) +{ +return getenv (DEFAULT_LTTNG_KMOD_PROBES ); +} + +/* * With the given format, fill dst with the time of len maximum siz. * * Return amount of bytes set in the buffer or else 0 on error.
src/common/utils.h +1 -0
@@ -47,6 +47,7 @@ int utils_parse_size_suffix(char const * const str, uint64_t * const size);int utils_get_count_order_u32 (uint32_t x);char *utils_get_home_dir (void );char *utils_get_user_home_dir (uid_t uid); +char *utils_get_kmod_probes_list (void );size_t utils_get_current_time_str (const char *format,char *dst,size_t len);gid_t utils_get_group_id (const char *name); char *utils_generate_optstring(const struct option *long_options,
Signature · 1 line
1.7.9.5
Re: [PATCH lttng-tools v3 0/4] Dynamic probe list support
In reply to a message not in the archiveMerged!
I merged it with some minor syntax fixes mostly in modprobe.c. There is one thing I don't accept at all is if/else without {}. Remember the goto fail; bug :).
Anyhow, I fixed them to fit my OCD if/else issue. ;)
Big thanks for that, this is really great! I would love to improve that with support in the "lttng" command line that could take a list and spawn the sessiond with it. Also, the configuration file coming in 2.5 (currently in master).
Cheers!
David
Quoted 11 lines · Jan Glauber
Hi David,
here are the rebased patches (onto 88564da). There are no functional changes to the previous version.
Jan Glauber (4):
Use common functions for module loading and unloading Seperate probe modules from control modules Remove required parameter from module parameters Configurable kernel module probes support
Quoted 13 lines
doc/man/lttng-sessiond.8 | 7 + src/bin/lttng-sessiond/kern-modules.h | 3 +- src/bin/lttng-sessiond/main.c | 5 + src/bin/lttng-sessiond/modprobe.c | 307 ++++++++++++++++++--------------- src/bin/lttng-sessiond/modprobe.h | 2 + src/common/defaults.h | 3 + src/common/utils.c | 10 ++ src/common/utils.h | 1 + 8 files changed, 200 insertions(+), 138 deletions(-)Signature · 1 line
1.7.9.5
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Re: [PATCH lttng-tools v3 0/4] Dynamic probe list support
In reply to a message not in the archiveThanks David! I've had the impression that LTTng follows kernel coding style but it diverts on the if/else case.
Personaly I don't buy the {} is better argument, but I'll try to remember your preference :)
If you could help me a bit with the config file syntax I'll be happy to add support for it.
What would help me is a working example with all the required values. As I said
an empty config file did not work for me, so there seems to be some required options and I was not able to
figure them out.
Cheers,
Jan
2014-05-14 22:47 GMT+02:00 David Goulet <[email protected]>:
Quoted 28 lines
Merged!
I merged it with some minor syntax fixes mostly in
modprobe.c. There is one thing I don't accept at all is if/else without {}. Remember the goto fail; bug :).Anyhow, I fixed them to fit my OCD if/else issue. ;)
Big thanks for that, this is really great! I would love to improve that with support in the "lttng" command line that could take a list and spawn the sessiond with it. Also, the configuration file coming in 2.5 (currently in master).
Cheers!
DavidQuoted 11 lines · Jan Glauber
Hi David,
here are the rebased patches (onto 88564da). There are no functional changes to the previous version.
Jan Glauber (4):
Use common functions for module loading and unloading Seperate probe modules from control modules Remove required parameter from module parameters Configurable kernel module probes support
Quoted 15 lines
Quoted 4 lines
doc/man/lttng-sessiond.8 | 7 + src/bin/lttng-sessiond/kern-modules.h | 3 +- src/bin/lttng-sessiond/main.c | 5 + src/bin/lttng-sessiond/modprobe.c | 307++++++++++++++++++---------------
Quoted 9 lines
src/bin/lttng-sessiond/modprobe.h | 2 + src/common/defaults.h | 3 + src/common/utils.c | 10 ++ src/common/utils.h | 1 + 8 files changed, 200 insertions(+), 138 deletions(-)--
1.7.9.5
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev