From: Mathieu Desnoyers Date: Fri, 5 Aug 2011 20:28:01 +0000 (-0400) Subject: Unload lttng modules when sessiond quits X-Git-Tag: v2.0-pre7~7 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=ab14718513c62c38a882d103b1dc727467271ff7;p=lttng-tools.git Unload lttng modules when sessiond quits Signed-off-by: Mathieu Desnoyers --- diff --git a/ltt-sessiond/ltt-sessiond.h b/ltt-sessiond/ltt-sessiond.h index 17c9c32f8..0882d40a8 100644 --- a/ltt-sessiond/ltt-sessiond.h +++ b/ltt-sessiond/ltt-sessiond.h @@ -19,32 +19,38 @@ #ifndef _LTT_SESSIOND_H #define _LTT_SESSIOND_H -#define DEFAULT_HOME_DIR "/tmp" +#define DEFAULT_HOME_DIR "/tmp" #define DEFAULT_UST_SOCK_DIR DEFAULT_HOME_DIR "/ust-app-socks" #define DEFAULT_GLOBAL_APPS_PIPE DEFAULT_UST_SOCK_DIR "/global" -#define DEFAULT_TRACE_OUTPUT DEFAULT_HOME_DIR "/lttng" +#define DEFAULT_TRACE_OUTPUT DEFAULT_HOME_DIR "/lttng" + +struct module_param { + const char *name; + int required; +}; /* LTTng kernel tracer modules list */ -const char *kernel_modules_list[] = { - "lib-ring-buffer", - "ltt-relay", - "ltt-ring-buffer-client-discard", - "ltt-ring-buffer-client-overwrite", - "ltt-ring-buffer-metadata-client", - "ltt-ring-buffer-client-mmap-discard", - "ltt-ring-buffer-client-mmap-overwrite", - "ltt-ring-buffer-metadata-mmap-client", - "lttng-ftrace", - "lttng-kprobes", - "lttng-kretprobes", - "lttng-probe-block", - "lttng-probe-irq", - "lttng-probe-kvm", - "lttng-probe-lttng", - "lttng-probe-sched", - "lttng-probe-syscalls", - "lttng-types", - NULL, +const struct module_param kernel_modules_list[] = { + /* used by ltt-relay, unload last */ + { "lttng-ftrace", 0 }, + { "lttng-kprobes", 0 }, + { "lttng-kretprobes", 0 }, + + { "lib-ring-buffer", 1 }, + { "ltt-relay", 1 }, + { "ltt-ring-buffer-client-discard", 1 }, + { "ltt-ring-buffer-client-overwrite", 1 }, + { "ltt-ring-buffer-metadata-client", 1 }, + { "ltt-ring-buffer-client-mmap-discard", 1 }, + { "ltt-ring-buffer-client-mmap-overwrite", 1 }, + { "ltt-ring-buffer-metadata-mmap-client", 1 }, + { "lttng-probe-lttng", 1 }, + { "lttng-types", 0 }, + { "lttng-probe-block", 0 }, + { "lttng-probe-irq", 0 }, + { "lttng-probe-kvm", 0 }, + { "lttng-probe-sched", 0 }, + { "lttng-probe-syscalls", 0 }, }; extern const char default_home_dir[], diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index cb8b98c7b..b3dc0e3a6 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -99,6 +99,8 @@ static sem_t kconsumerd_sem; static pthread_mutex_t kconsumerd_pid_mutex; /* Mutex to control kconsumerd pid assignation */ +static int modprobe_remove_kernel_modules(void); + /* * Pointer initialized before thread creation. * @@ -195,6 +197,9 @@ static void cleanup() DBG("Closing kernel fd"); close(kernel_tracer_fd); + + DBG("Unloading kernel modules"); + modprobe_remove_kernel_modules(); } /* @@ -944,22 +949,67 @@ error: */ static int modprobe_kernel_modules(void) { - int ret = 0, i = 0; + int ret = 0, i; char modprobe[256]; - while (kernel_modules_list[i] != NULL) { - ret = snprintf(modprobe, sizeof(modprobe), "/sbin/modprobe %s", - kernel_modules_list[i]); + for (i = 0; i < ARRAY_SIZE(kernel_modules_list); i++) { + ret = snprintf(modprobe, sizeof(modprobe), + "/sbin/modprobe %s%s", + kernel_modules_list[i].required ? "" : "--quiet ", + kernel_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", + kernel_modules_list[i].name); + } else if (kernel_modules_list[i].required + && WEXITSTATUS(ret) != 0) { + ERR("Unable to load module %s", + kernel_modules_list[i].name); + } else { + DBG("Modprobe successfully %s", + kernel_modules_list[i].name); + } + } + +error: + return ret; +} + +/* + * modprobe_remove_kernel_modules + * Remove modules in reverse load order. + */ +static int modprobe_remove_kernel_modules(void) +{ + int ret = 0, i; + char modprobe[256]; + + for (i = ARRAY_SIZE(kernel_modules_list) - 1; i >= 0; i--) { + ret = snprintf(modprobe, sizeof(modprobe), + "/sbin/modprobe --remove --quiet %s", + kernel_modules_list[i].name); if (ret < 0) { - ERR("Unable to load module %s", kernel_modules_list[i]); + perror("snprintf modprobe --remove"); + goto error; + } + modprobe[sizeof(modprobe) - 1] = '\0'; + ret = system(modprobe); + if (ret == -1) { + ERR("Unable to launch modprobe --remove for module %s", + kernel_modules_list[i].name); + } else if (kernel_modules_list[i].required + && WEXITSTATUS(ret) != 0) { + ERR("Unable to remove module %s", + kernel_modules_list[i].name); + } else { + DBG("Modprobe removal successful %s", + kernel_modules_list[i].name); } - DBG("Modprobe successfully %s", kernel_modules_list[i]); - i++; } error: diff --git a/ltt-sessiond/utils.h b/ltt-sessiond/utils.h index 9770b2ca6..d451eb63a 100644 --- a/ltt-sessiond/utils.h +++ b/ltt-sessiond/utils.h @@ -19,6 +19,10 @@ #ifndef _LTT_UTILS_H #define _LTT_UTILS_H +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(array) (sizeof(array) / (sizeof((array)[0]))) +#endif + int mkdir_recursive(const char *path, mode_t mode); const char *get_home_dir(void);