Unload lttng modules when sessiond quits
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 5 Aug 2011 20:28:01 +0000 (16:28 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 5 Aug 2011 20:28:01 +0000 (16:28 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
ltt-sessiond/ltt-sessiond.h
ltt-sessiond/main.c
ltt-sessiond/utils.h

index 17c9c32f8fd75c7a5a445f65f6e941e803cf78a6..0882d40a83dc4128426ceca3435575dab231e51e 100644 (file)
 #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[],
index cb8b98c7b7141ec4b9492738ee3d87abf846d4b5..b3dc0e3a6f08ee397935c8a672e2470179633980 100644 (file)
@@ -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:
index 9770b2ca65ba3804060185962972e8d0ecf2a884..d451eb63a668b023f342affdf6cf128a63317150 100644 (file)
 #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);
 
This page took 0.038953 seconds and 4 git commands to generate.