Cleanup: add missing dot
[lttng-tools.git] / src / bin / lttng-sessiond / modprobe.c
1 /*
2 * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
3 *
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.
7 *
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.
12 *
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.
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[] = {
30 { "lttng-tracer", 1 },
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 },
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-types", 0 },
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 },
83 };
84
85 /*
86 * Remove control kernel module(s) in reverse load order.
87 */
88 void modprobe_remove_lttng_control(void)
89 {
90 int ret = 0, i;
91 char modprobe[256];
92
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);
97 if (ret < 0) {
98 PERROR("snprintf modprobe -r");
99 goto error;
100 }
101 modprobe[sizeof(modprobe) - 1] = '\0';
102 ret = system(modprobe);
103 if (ret == -1) {
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);
110 } else {
111 DBG("Modprobe removal successful %s",
112 kern_modules_control[i].name);
113 }
114 }
115
116 error:
117 return;
118 }
119
120 /*
121 * Remove data kernel modules in reverse load order.
122 */
123 void modprobe_remove_lttng_data(void)
124 {
125 int ret = 0, i;
126 char modprobe[256];
127
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);
132 if (ret < 0) {
133 PERROR("snprintf modprobe -r");
134 goto error;
135 }
136 modprobe[sizeof(modprobe) - 1] = '\0';
137 ret = system(modprobe);
138 if (ret == -1) {
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);
145 } else {
146 DBG("Modprobe removal successful %s",
147 kern_modules_list[i].name);
148 }
149 }
150
151 error:
152 return;
153 }
154
155 /*
156 * Remove all kernel modules in reverse order.
157 */
158 void modprobe_remove_lttng_all(void)
159 {
160 modprobe_remove_lttng_data();
161 modprobe_remove_lttng_control();
162 }
163
164 /*
165 * Load control kernel module(s).
166 */
167 int modprobe_lttng_control(void)
168 {
169 int ret = 0, i;
170 char modprobe[256];
171
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);
177 if (ret < 0) {
178 PERROR("snprintf modprobe");
179 goto error;
180 }
181 modprobe[sizeof(modprobe) - 1] = '\0';
182 ret = system(modprobe);
183 if (ret == -1) {
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);
190 } else {
191 DBG("Modprobe successfully %s",
192 kern_modules_control[i].name);
193 }
194 }
195
196 error:
197 return ret;
198 }
199
200 /*
201 * Load data kernel module(s).
202 */
203 int modprobe_lttng_data(void)
204 {
205 int ret = 0, i;
206 char modprobe[256];
207
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);
213 if (ret < 0) {
214 PERROR("snprintf modprobe");
215 goto error;
216 }
217 modprobe[sizeof(modprobe) - 1] = '\0';
218 ret = system(modprobe);
219 if (ret == -1) {
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);
226 } else {
227 DBG("Modprobe successfully %s",
228 kern_modules_list[i].name);
229 }
230 }
231
232 error:
233 return ret;
234 }
235
236 /*
237 * Load all lttng kernel modules.
238 */
239 int modprobe_lttng_all(void)
240 {
241 int ret;
242
243 ret = modprobe_lttng_control();
244 if (ret < 0) {
245 goto error;
246 }
247
248 ret = modprobe_lttng_data();
249 if (ret < 0) {
250 goto error;
251 }
252
253 error:
254 return ret;
255 }
This page took 0.052407 seconds and 4 git commands to generate.