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-asoc", 0 },
48 { "lttng-probe-block", 0 },
49 { "lttng-probe-ext3", 0 },
50 { "lttng-probe-gpio", 0 },
51 { "lttng-probe-irq", 0 },
52 { "lttng-probe-jbd", 0 },
53 { "lttng-probe-jbd2", 0 },
54 { "lttng-probe-kmem", 0 },
55 { "lttng-probe-kvm", 0 },
56 { "lttng-probe-lock", 0 },
57 { "lttng-probe-module", 0 },
58 { "lttng-probe-napi", 0 },
59 { "lttng-probe-net", 0 },
60 { "lttng-probe-power", 0 },
61 { "lttng-probe-regulator", 0 },
62 { "lttng-probe-sched", 0 },
63 { "lttng-probe-scsi", 0 },
64 { "lttng-probe-signal", 0 },
65 { "lttng-probe-skb", 0 },
66 { "lttng-probe-sock", 0 },
67 { "lttng-probe-statedump", 0 },
68 { "lttng-probe-timer", 0 },
69 { "lttng-probe-udp", 0 },
70 { "lttng-probe-vmscan", 0 },
74 * Remove control kernel module(s) in reverse load order.
76 void modprobe_remove_lttng_control(void)
81 for (i
= ARRAY_SIZE(kern_modules_control
) - 1; i
>= 0; i
--) {
82 ret
= snprintf(modprobe
, sizeof(modprobe
),
83 "/sbin/modprobe -r -q %s",
84 kern_modules_control
[i
].name
);
86 PERROR("snprintf modprobe -r");
89 modprobe
[sizeof(modprobe
) - 1] = '\0';
90 ret
= system(modprobe
);
92 ERR("Unable to launch modprobe -r for module %s",
93 kern_modules_control
[i
].name
);
94 } else if (kern_modules_control
[i
].required
95 && WEXITSTATUS(ret
) != 0) {
96 ERR("Unable to remove module %s",
97 kern_modules_control
[i
].name
);
99 DBG("Modprobe removal successful %s",
100 kern_modules_control
[i
].name
);
109 * Remove data kernel modules in reverse load order.
111 void modprobe_remove_lttng_data(void)
116 for (i
= ARRAY_SIZE(kern_modules_list
) - 1; i
>= 0; i
--) {
117 ret
= snprintf(modprobe
, sizeof(modprobe
),
118 "/sbin/modprobe -r -q %s",
119 kern_modules_list
[i
].name
);
121 PERROR("snprintf modprobe -r");
124 modprobe
[sizeof(modprobe
) - 1] = '\0';
125 ret
= system(modprobe
);
127 ERR("Unable to launch modprobe -r for module %s",
128 kern_modules_list
[i
].name
);
129 } else if (kern_modules_list
[i
].required
130 && WEXITSTATUS(ret
) != 0) {
131 ERR("Unable to remove module %s",
132 kern_modules_list
[i
].name
);
134 DBG("Modprobe removal successful %s",
135 kern_modules_list
[i
].name
);
144 * Remove all kernel modules in reverse order.
146 void modprobe_remove_lttng_all(void)
148 modprobe_remove_lttng_data();
149 modprobe_remove_lttng_control();
153 * Load control kernel module(s).
155 int modprobe_lttng_control(void)
160 for (i
= 0; i
< ARRAY_SIZE(kern_modules_control
); i
++) {
161 ret
= snprintf(modprobe
, sizeof(modprobe
),
162 "/sbin/modprobe %s%s",
163 kern_modules_control
[i
].required
? "" : "-q ",
164 kern_modules_control
[i
].name
);
166 PERROR("snprintf modprobe");
169 modprobe
[sizeof(modprobe
) - 1] = '\0';
170 ret
= system(modprobe
);
172 ERR("Unable to launch modprobe for module %s",
173 kern_modules_control
[i
].name
);
174 } else if (kern_modules_control
[i
].required
175 && WEXITSTATUS(ret
) != 0) {
176 ERR("Unable to load module %s",
177 kern_modules_control
[i
].name
);
179 DBG("Modprobe successfully %s",
180 kern_modules_control
[i
].name
);
189 * Load data kernel module(s).
191 int modprobe_lttng_data(void)
196 for (i
= 0; i
< ARRAY_SIZE(kern_modules_list
); i
++) {
197 ret
= snprintf(modprobe
, sizeof(modprobe
),
198 "/sbin/modprobe %s%s",
199 kern_modules_list
[i
].required
? "" : "-q ",
200 kern_modules_list
[i
].name
);
202 PERROR("snprintf modprobe");
205 modprobe
[sizeof(modprobe
) - 1] = '\0';
206 ret
= system(modprobe
);
208 ERR("Unable to launch modprobe for module %s",
209 kern_modules_list
[i
].name
);
210 } else if (kern_modules_list
[i
].required
211 && WEXITSTATUS(ret
) != 0) {
212 ERR("Unable to load module %s",
213 kern_modules_list
[i
].name
);
215 DBG("Modprobe successfully %s",
216 kern_modules_list
[i
].name
);
225 * Load all lttng kernel modules.
227 int modprobe_lttng_all(void)
231 ret
= modprobe_lttng_control();
236 ret
= modprobe_lttng_data();