Commit | Line | Data |
---|---|---|
096102bd DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com> | |
3 | * | |
d14d33bf AM |
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. | |
096102bd | 7 | * |
d14d33bf AM |
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. | |
096102bd | 12 | * |
d14d33bf AM |
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. | |
096102bd DG |
16 | */ |
17 | ||
18 | #define _GNU_SOURCE | |
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
21 | #include <sys/wait.h> | |
22 | ||
23 | #include <common/common.h> | |
24 | ||
25 | #include "modprobe.h" | |
26 | #include "kern-modules.h" | |
27 | ||
28 | /* MUST be loaded first */ | |
29 | const struct kern_modules_param kern_modules_control[] = { | |
d8e76ef6 | 30 | { "lttng-tracer", 1 }, |
096102bd DG |
31 | }; |
32 | ||
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 }, | |
d8e76ef6 DG |
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 }, | |
096102bd DG |
45 | { "lttng-probe-lttng", 1 }, |
46 | { "lttng-types", 0 }, | |
07e716ec | 47 | { "lttng-probe-asoc", 0 }, |
096102bd | 48 | { "lttng-probe-block", 0 }, |
bd69f856 AG |
49 | { "lttng-probe-btrfs", 0 }, |
50 | { "lttng-probe-compaction", 0 }, | |
07e716ec | 51 | { "lttng-probe-ext3", 0 }, |
bd69f856 | 52 | { "lttng-probe-ext4", 0 }, |
07e716ec | 53 | { "lttng-probe-gpio", 0 }, |
096102bd | 54 | { "lttng-probe-irq", 0 }, |
07e716ec WP |
55 | { "lttng-probe-jbd", 0 }, |
56 | { "lttng-probe-jbd2", 0 }, | |
57 | { "lttng-probe-kmem", 0 }, | |
096102bd | 58 | { "lttng-probe-kvm", 0 }, |
07e716ec | 59 | { "lttng-probe-lock", 0 }, |
e3e57ea7 | 60 | { "lttng-probe-module", 0 }, |
07e716ec WP |
61 | { "lttng-probe-napi", 0 }, |
62 | { "lttng-probe-net", 0 }, | |
63 | { "lttng-probe-power", 0 }, | |
bd69f856 AG |
64 | { "lttng-probe-printk", 0 }, |
65 | { "lttng-probe-random", 0 }, | |
66 | { "lttng-probe-rcu", 0 }, | |
67 | { "lttng-probe-regmap", 0 }, | |
07e716ec | 68 | { "lttng-probe-regulator", 0 }, |
bd69f856 | 69 | { "lttng-probe-rpm", 0 }, |
096102bd | 70 | { "lttng-probe-sched", 0 }, |
07e716ec | 71 | { "lttng-probe-scsi", 0 }, |
9ae7d41d | 72 | { "lttng-probe-signal", 0 }, |
07e716ec WP |
73 | { "lttng-probe-skb", 0 }, |
74 | { "lttng-probe-sock", 0 }, | |
bd9b9e63 | 75 | { "lttng-probe-statedump", 0 }, |
bd69f856 | 76 | { "lttng-probe-sunrpc", 0 }, |
7ec24b77 | 77 | { "lttng-probe-timer", 0 }, |
07e716ec WP |
78 | { "lttng-probe-udp", 0 }, |
79 | { "lttng-probe-vmscan", 0 }, | |
bd69f856 AG |
80 | { "lttng-probe-workqueue", 0 }, |
81 | { "lttng-probe-writeback", 0 }, | |
096102bd DG |
82 | }; |
83 | ||
84 | /* | |
85 | * Remove control kernel module(s) in reverse load order. | |
86 | */ | |
87 | void modprobe_remove_lttng_control(void) | |
88 | { | |
89 | int ret = 0, i; | |
90 | char modprobe[256]; | |
91 | ||
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); | |
96 | if (ret < 0) { | |
97 | PERROR("snprintf modprobe -r"); | |
98 | goto error; | |
99 | } | |
100 | modprobe[sizeof(modprobe) - 1] = '\0'; | |
101 | ret = system(modprobe); | |
102 | if (ret == -1) { | |
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); | |
109 | } else { | |
110 | DBG("Modprobe removal successful %s", | |
111 | kern_modules_control[i].name); | |
112 | } | |
113 | } | |
114 | ||
115 | error: | |
116 | return; | |
117 | } | |
118 | ||
119 | /* | |
120 | * Remove data kernel modules in reverse load order. | |
121 | */ | |
122 | void modprobe_remove_lttng_data(void) | |
123 | { | |
124 | int ret = 0, i; | |
125 | char modprobe[256]; | |
126 | ||
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); | |
131 | if (ret < 0) { | |
df0f840b | 132 | PERROR("snprintf modprobe -r"); |
096102bd DG |
133 | goto error; |
134 | } | |
135 | modprobe[sizeof(modprobe) - 1] = '\0'; | |
136 | ret = system(modprobe); | |
137 | if (ret == -1) { | |
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); | |
144 | } else { | |
145 | DBG("Modprobe removal successful %s", | |
146 | kern_modules_list[i].name); | |
147 | } | |
148 | } | |
149 | ||
150 | error: | |
151 | return; | |
152 | } | |
153 | ||
154 | /* | |
155 | * Remove all kernel modules in reverse order. | |
156 | */ | |
157 | void modprobe_remove_lttng_all(void) | |
158 | { | |
159 | modprobe_remove_lttng_data(); | |
160 | modprobe_remove_lttng_control(); | |
161 | } | |
162 | ||
163 | /* | |
164 | * Load control kernel module(s). | |
165 | */ | |
166 | int modprobe_lttng_control(void) | |
167 | { | |
168 | int ret = 0, i; | |
169 | char modprobe[256]; | |
170 | ||
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); | |
176 | if (ret < 0) { | |
177 | PERROR("snprintf modprobe"); | |
178 | goto error; | |
179 | } | |
180 | modprobe[sizeof(modprobe) - 1] = '\0'; | |
181 | ret = system(modprobe); | |
182 | if (ret == -1) { | |
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); | |
189 | } else { | |
190 | DBG("Modprobe successfully %s", | |
191 | kern_modules_control[i].name); | |
192 | } | |
193 | } | |
194 | ||
195 | error: | |
196 | return ret; | |
197 | } | |
198 | ||
199 | /* | |
200 | * Load data kernel module(s). | |
201 | */ | |
202 | int modprobe_lttng_data(void) | |
203 | { | |
204 | int ret = 0, i; | |
205 | char modprobe[256]; | |
206 | ||
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); | |
212 | if (ret < 0) { | |
df0f840b | 213 | PERROR("snprintf modprobe"); |
096102bd DG |
214 | goto error; |
215 | } | |
216 | modprobe[sizeof(modprobe) - 1] = '\0'; | |
217 | ret = system(modprobe); | |
218 | if (ret == -1) { | |
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); | |
225 | } else { | |
226 | DBG("Modprobe successfully %s", | |
227 | kern_modules_list[i].name); | |
228 | } | |
229 | } | |
230 | ||
231 | error: | |
232 | return ret; | |
233 | } | |
234 | ||
235 | /* | |
236 | * Load all lttng kernel modules. | |
237 | */ | |
238 | int modprobe_lttng_all(void) | |
239 | { | |
240 | int ret; | |
241 | ||
242 | ret = modprobe_lttng_control(); | |
243 | if (ret < 0) { | |
244 | goto error; | |
245 | } | |
246 | ||
247 | ret = modprobe_lttng_data(); | |
248 | if (ret < 0) { | |
249 | goto error; | |
250 | } | |
251 | ||
252 | error: | |
253 | return ret; | |
254 | } |