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 },
46 { "lttng-probe-asoc", 0 },
47 { "lttng-probe-block", 0 },
48 { "lttng-probe-btrfs", 0 },
49 { "lttng-probe-compaction", 0 },
50 { "lttng-probe-ext3", 0 },
51 { "lttng-probe-ext4", 0 },
52 { "lttng-probe-gpio", 0 },
53 { "lttng-probe-irq", 0 },
54 { "lttng-probe-jbd", 0 },
55 { "lttng-probe-jbd2", 0 },
56 { "lttng-probe-kmem", 0 },
57 { "lttng-probe-kvm", 0 },
58 { "lttng-probe-kvm-x86", 0 },
59 { "lttng-probe-kvm-x86-mmu", 0 },
60 { "lttng-probe-lock", 0 },
61 { "lttng-probe-module", 0 },
62 { "lttng-probe-napi", 0 },
63 { "lttng-probe-net", 0 },
64 { "lttng-probe-power", 0 },
65 { "lttng-probe-printk", 0 },
66 { "lttng-probe-random", 0 },
67 { "lttng-probe-rcu", 0 },
68 { "lttng-probe-regmap", 0 },
69 { "lttng-probe-regulator", 0 },
70 { "lttng-probe-rpm", 0 },
71 { "lttng-probe-sched", 0 },
72 { "lttng-probe-scsi", 0 },
73 { "lttng-probe-signal", 0 },
74 { "lttng-probe-skb", 0 },
75 { "lttng-probe-sock", 0 },
76 { "lttng-probe-statedump", 0 },
77 { "lttng-probe-sunrpc", 0 },
78 { "lttng-probe-timer", 0 },
79 { "lttng-probe-udp", 0 },
80 { "lttng-probe-vmscan", 0 },
81 { "lttng-probe-workqueue", 0 },
82 { "lttng-probe-writeback", 0 },
86 * Remove control kernel module(s) in reverse load order.
88 void modprobe_remove_lttng_control(void)
93 for (i
= ARRAY_SIZE(kern_modules_control
) - 1; i
>= 0; i
--) {
94 ret
= snprintf(modprobe
, sizeof(modprobe
),
95 "/sbin/modprobe -r -q %s",
96 kern_modules_control
[i
].name
);
98 PERROR("snprintf modprobe -r");
101 modprobe
[sizeof(modprobe
) - 1] = '\0';
102 ret
= system(modprobe
);
104 ERR("Unable to launch modprobe -r for module %s",
105 kern_modules_control
[i
].name
);
106 } else if (kern_modules_control
[i
].required
107 && WEXITSTATUS(ret
) != 0) {
108 ERR("Unable to remove module %s",
109 kern_modules_control
[i
].name
);
111 DBG("Modprobe removal successful %s",
112 kern_modules_control
[i
].name
);
121 * Remove data kernel modules in reverse load order.
123 void modprobe_remove_lttng_data(void)
128 for (i
= ARRAY_SIZE(kern_modules_list
) - 1; i
>= 0; i
--) {
129 ret
= snprintf(modprobe
, sizeof(modprobe
),
130 "/sbin/modprobe -r -q %s",
131 kern_modules_list
[i
].name
);
133 PERROR("snprintf modprobe -r");
136 modprobe
[sizeof(modprobe
) - 1] = '\0';
137 ret
= system(modprobe
);
139 ERR("Unable to launch modprobe -r for module %s",
140 kern_modules_list
[i
].name
);
141 } else if (kern_modules_list
[i
].required
142 && WEXITSTATUS(ret
) != 0) {
143 ERR("Unable to remove module %s",
144 kern_modules_list
[i
].name
);
146 DBG("Modprobe removal successful %s",
147 kern_modules_list
[i
].name
);
156 * Remove all kernel modules in reverse order.
158 void modprobe_remove_lttng_all(void)
160 modprobe_remove_lttng_data();
161 modprobe_remove_lttng_control();
165 * Load control kernel module(s).
167 int modprobe_lttng_control(void)
172 for (i
= 0; i
< ARRAY_SIZE(kern_modules_control
); i
++) {
173 ret
= snprintf(modprobe
, sizeof(modprobe
),
174 "/sbin/modprobe %s%s",
175 kern_modules_control
[i
].required
? "" : "-q ",
176 kern_modules_control
[i
].name
);
178 PERROR("snprintf modprobe");
181 modprobe
[sizeof(modprobe
) - 1] = '\0';
182 ret
= system(modprobe
);
184 ERR("Unable to launch modprobe for module %s",
185 kern_modules_control
[i
].name
);
186 } else if (kern_modules_control
[i
].required
187 && WEXITSTATUS(ret
) != 0) {
188 ERR("Unable to load module %s",
189 kern_modules_control
[i
].name
);
191 DBG("Modprobe successfully %s",
192 kern_modules_control
[i
].name
);
201 * Load data kernel module(s).
203 int modprobe_lttng_data(void)
208 for (i
= 0; i
< ARRAY_SIZE(kern_modules_list
); i
++) {
209 ret
= snprintf(modprobe
, sizeof(modprobe
),
210 "/sbin/modprobe %s%s",
211 kern_modules_list
[i
].required
? "" : "-q ",
212 kern_modules_list
[i
].name
);
214 PERROR("snprintf modprobe");
217 modprobe
[sizeof(modprobe
) - 1] = '\0';
218 ret
= system(modprobe
);
220 ERR("Unable to launch modprobe for module %s",
221 kern_modules_list
[i
].name
);
222 } else if (kern_modules_list
[i
].required
223 && WEXITSTATUS(ret
) != 0) {
224 ERR("Unable to load module %s",
225 kern_modules_list
[i
].name
);
227 DBG("Modprobe successfully %s",
228 kern_modules_list
[i
].name
);