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-btrfs", 0 },
50 { "lttng-probe-compaction", 0 },
51 { "lttng-probe-ext3", 0 },
52 { "lttng-probe-ext4", 0 },
53 { "lttng-probe-gpio", 0 },
54 { "lttng-probe-irq", 0 },
55 { "lttng-probe-jbd", 0 },
56 { "lttng-probe-jbd2", 0 },
57 { "lttng-probe-kmem", 0 },
58 { "lttng-probe-kvm", 0 },
59 { "lttng-probe-lock", 0 },
60 { "lttng-probe-module", 0 },
61 { "lttng-probe-napi", 0 },
62 { "lttng-probe-net", 0 },
63 { "lttng-probe-power", 0 },
64 { "lttng-probe-printk", 0 },
65 { "lttng-probe-random", 0 },
66 { "lttng-probe-rcu", 0 },
67 { "lttng-probe-regmap", 0 },
68 { "lttng-probe-regulator", 0 },
69 { "lttng-probe-rpm", 0 },
70 { "lttng-probe-sched", 0 },
71 { "lttng-probe-scsi", 0 },
72 { "lttng-probe-signal", 0 },
73 { "lttng-probe-skb", 0 },
74 { "lttng-probe-sock", 0 },
75 { "lttng-probe-statedump", 0 },
76 { "lttng-probe-sunrpc", 0 },
77 { "lttng-probe-timer", 0 },
78 { "lttng-probe-udp", 0 },
79 { "lttng-probe-vmscan", 0 },
80 { "lttng-probe-workqueue", 0 },
81 { "lttng-probe-writeback", 0 },
85 * Remove control kernel module(s) in reverse load order.
87 void modprobe_remove_lttng_control(void)
92 for (i
= ARRAY_SIZE(kern_modules_control
) - 1; i
>= 0; i
--) {
93 ret
= snprintf(modprobe
, sizeof(modprobe
),
94 "/sbin/modprobe -r -q %s",
95 kern_modules_control
[i
].name
);
97 PERROR("snprintf modprobe -r");
100 modprobe
[sizeof(modprobe
) - 1] = '\0';
101 ret
= system(modprobe
);
103 ERR("Unable to launch modprobe -r for module %s",
104 kern_modules_control
[i
].name
);
105 } else if (kern_modules_control
[i
].required
106 && WEXITSTATUS(ret
) != 0) {
107 ERR("Unable to remove module %s",
108 kern_modules_control
[i
].name
);
110 DBG("Modprobe removal successful %s",
111 kern_modules_control
[i
].name
);
120 * Remove data kernel modules in reverse load order.
122 void modprobe_remove_lttng_data(void)
127 for (i
= ARRAY_SIZE(kern_modules_list
) - 1; i
>= 0; i
--) {
128 ret
= snprintf(modprobe
, sizeof(modprobe
),
129 "/sbin/modprobe -r -q %s",
130 kern_modules_list
[i
].name
);
132 PERROR("snprintf modprobe -r");
135 modprobe
[sizeof(modprobe
) - 1] = '\0';
136 ret
= system(modprobe
);
138 ERR("Unable to launch modprobe -r for module %s",
139 kern_modules_list
[i
].name
);
140 } else if (kern_modules_list
[i
].required
141 && WEXITSTATUS(ret
) != 0) {
142 ERR("Unable to remove module %s",
143 kern_modules_list
[i
].name
);
145 DBG("Modprobe removal successful %s",
146 kern_modules_list
[i
].name
);
155 * Remove all kernel modules in reverse order.
157 void modprobe_remove_lttng_all(void)
159 modprobe_remove_lttng_data();
160 modprobe_remove_lttng_control();
164 * Load control kernel module(s).
166 int modprobe_lttng_control(void)
171 for (i
= 0; i
< ARRAY_SIZE(kern_modules_control
); i
++) {
172 ret
= snprintf(modprobe
, sizeof(modprobe
),
173 "/sbin/modprobe %s%s",
174 kern_modules_control
[i
].required
? "" : "-q ",
175 kern_modules_control
[i
].name
);
177 PERROR("snprintf modprobe");
180 modprobe
[sizeof(modprobe
) - 1] = '\0';
181 ret
= system(modprobe
);
183 ERR("Unable to launch modprobe for module %s",
184 kern_modules_control
[i
].name
);
185 } else if (kern_modules_control
[i
].required
186 && WEXITSTATUS(ret
) != 0) {
187 ERR("Unable to load module %s",
188 kern_modules_control
[i
].name
);
190 DBG("Modprobe successfully %s",
191 kern_modules_control
[i
].name
);
200 * Load data kernel module(s).
202 int modprobe_lttng_data(void)
207 for (i
= 0; i
< ARRAY_SIZE(kern_modules_list
); i
++) {
208 ret
= snprintf(modprobe
, sizeof(modprobe
),
209 "/sbin/modprobe %s%s",
210 kern_modules_list
[i
].required
? "" : "-q ",
211 kern_modules_list
[i
].name
);
213 PERROR("snprintf modprobe");
216 modprobe
[sizeof(modprobe
) - 1] = '\0';
217 ret
= system(modprobe
);
219 ERR("Unable to launch modprobe for module %s",
220 kern_modules_list
[i
].name
);
221 } else if (kern_modules_list
[i
].required
222 && WEXITSTATUS(ret
) != 0) {
223 ERR("Unable to load module %s",
224 kern_modules_list
[i
].name
);
226 DBG("Modprobe successfully %s",
227 kern_modules_list
[i
].name
);
236 * Load all lttng kernel modules.
238 int modprobe_lttng_all(void)
242 ret
= modprobe_lttng_control();
247 ret
= modprobe_lttng_data();