2 * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <common/common.h>
26 #include "kern-modules.h"
28 /* MUST be loaded first */
29 const struct kern_modules_param kern_modules_control
[] = {
30 { "lttng-tracer", 1 },
33 /* LTTng kernel tracer modules list */
34 const struct kern_modules_param kern_modules_list
[] = {
35 { "lttng-ftrace", 0 },
36 { "lttng-kprobes", 0 },
37 { "lttng-kretprobes", 0 },
38 { "lttng-lib-ring-buffer", 1 },
39 { "lttng-ring-buffer-client-discard", 1 },
40 { "lttng-ring-buffer-client-overwrite", 1 },
41 { "lttng-ring-buffer-metadata-client", 1 },
42 { "lttng-ring-buffer-client-mmap-discard", 1 },
43 { "lttng-ring-buffer-client-mmap-overwrite", 1 },
44 { "lttng-ring-buffer-metadata-mmap-client", 1 },
45 { "lttng-probe-lttng", 1 },
47 { "lttng-probe-block", 0 },
48 { "lttng-probe-irq", 0 },
49 { "lttng-probe-kvm", 0 },
50 { "lttng-probe-sched", 0 },
51 { "lttng-probe-signal", 0 },
52 { "lttng-probe-statedump", 0 },
53 { "lttng-probe-timer", 0 },
57 * Remove control kernel module(s) in reverse load order.
59 void modprobe_remove_lttng_control(void)
64 for (i
= ARRAY_SIZE(kern_modules_control
) - 1; i
>= 0; i
--) {
65 ret
= snprintf(modprobe
, sizeof(modprobe
),
66 "/sbin/modprobe -r -q %s",
67 kern_modules_control
[i
].name
);
69 PERROR("snprintf modprobe -r");
72 modprobe
[sizeof(modprobe
) - 1] = '\0';
73 ret
= system(modprobe
);
75 ERR("Unable to launch modprobe -r for module %s",
76 kern_modules_control
[i
].name
);
77 } else if (kern_modules_control
[i
].required
78 && WEXITSTATUS(ret
) != 0) {
79 ERR("Unable to remove module %s",
80 kern_modules_control
[i
].name
);
82 DBG("Modprobe removal successful %s",
83 kern_modules_control
[i
].name
);
92 * Remove data kernel modules in reverse load order.
94 void modprobe_remove_lttng_data(void)
99 for (i
= ARRAY_SIZE(kern_modules_list
) - 1; i
>= 0; i
--) {
100 ret
= snprintf(modprobe
, sizeof(modprobe
),
101 "/sbin/modprobe -r -q %s",
102 kern_modules_list
[i
].name
);
104 PERROR("snprintf modprobe -r");
107 modprobe
[sizeof(modprobe
) - 1] = '\0';
108 ret
= system(modprobe
);
110 ERR("Unable to launch modprobe -r for module %s",
111 kern_modules_list
[i
].name
);
112 } else if (kern_modules_list
[i
].required
113 && WEXITSTATUS(ret
) != 0) {
114 ERR("Unable to remove module %s",
115 kern_modules_list
[i
].name
);
117 DBG("Modprobe removal successful %s",
118 kern_modules_list
[i
].name
);
127 * Remove all kernel modules in reverse order.
129 void modprobe_remove_lttng_all(void)
131 modprobe_remove_lttng_data();
132 modprobe_remove_lttng_control();
136 * Load control kernel module(s).
138 int modprobe_lttng_control(void)
143 for (i
= 0; i
< ARRAY_SIZE(kern_modules_control
); i
++) {
144 ret
= snprintf(modprobe
, sizeof(modprobe
),
145 "/sbin/modprobe %s%s",
146 kern_modules_control
[i
].required
? "" : "-q ",
147 kern_modules_control
[i
].name
);
149 PERROR("snprintf modprobe");
152 modprobe
[sizeof(modprobe
) - 1] = '\0';
153 ret
= system(modprobe
);
155 ERR("Unable to launch modprobe for module %s",
156 kern_modules_control
[i
].name
);
157 } else if (kern_modules_control
[i
].required
158 && WEXITSTATUS(ret
) != 0) {
159 ERR("Unable to load module %s",
160 kern_modules_control
[i
].name
);
162 DBG("Modprobe successfully %s",
163 kern_modules_control
[i
].name
);
172 * Load data kernel module(s).
174 int modprobe_lttng_data(void)
179 for (i
= 0; i
< ARRAY_SIZE(kern_modules_list
); i
++) {
180 ret
= snprintf(modprobe
, sizeof(modprobe
),
181 "/sbin/modprobe %s%s",
182 kern_modules_list
[i
].required
? "" : "-q ",
183 kern_modules_list
[i
].name
);
185 PERROR("snprintf modprobe");
188 modprobe
[sizeof(modprobe
) - 1] = '\0';
189 ret
= system(modprobe
);
191 ERR("Unable to launch modprobe for module %s",
192 kern_modules_list
[i
].name
);
193 } else if (kern_modules_list
[i
].required
194 && WEXITSTATUS(ret
) != 0) {
195 ERR("Unable to load module %s",
196 kern_modules_list
[i
].name
);
198 DBG("Modprobe successfully %s",
199 kern_modules_list
[i
].name
);
208 * Load all lttng kernel modules.
210 int modprobe_lttng_all(void)
214 ret
= modprobe_lttng_control();
219 ret
= modprobe_lttng_data();