Tests: add kernel snapshot streaming to root regression
[lttng-tools.git] / src / bin / lttng-sessiond / modprobe.c
CommitLineData
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 */
29const struct kern_modules_param kern_modules_control[] = {
d8e76ef6 30 { "lttng-tracer", 1 },
096102bd
DG
31};
32
33/* LTTng kernel tracer modules list */
34const 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 45 { "lttng-types", 0 },
07e716ec 46 { "lttng-probe-asoc", 0 },
096102bd 47 { "lttng-probe-block", 0 },
bd69f856
AG
48 { "lttng-probe-btrfs", 0 },
49 { "lttng-probe-compaction", 0 },
07e716ec 50 { "lttng-probe-ext3", 0 },
bd69f856 51 { "lttng-probe-ext4", 0 },
07e716ec 52 { "lttng-probe-gpio", 0 },
096102bd 53 { "lttng-probe-irq", 0 },
07e716ec
WP
54 { "lttng-probe-jbd", 0 },
55 { "lttng-probe-jbd2", 0 },
56 { "lttng-probe-kmem", 0 },
096102bd 57 { "lttng-probe-kvm", 0 },
07e716ec 58 { "lttng-probe-lock", 0 },
e3e57ea7 59 { "lttng-probe-module", 0 },
07e716ec
WP
60 { "lttng-probe-napi", 0 },
61 { "lttng-probe-net", 0 },
62 { "lttng-probe-power", 0 },
bd69f856
AG
63 { "lttng-probe-printk", 0 },
64 { "lttng-probe-random", 0 },
65 { "lttng-probe-rcu", 0 },
66 { "lttng-probe-regmap", 0 },
07e716ec 67 { "lttng-probe-regulator", 0 },
bd69f856 68 { "lttng-probe-rpm", 0 },
096102bd 69 { "lttng-probe-sched", 0 },
07e716ec 70 { "lttng-probe-scsi", 0 },
9ae7d41d 71 { "lttng-probe-signal", 0 },
07e716ec
WP
72 { "lttng-probe-skb", 0 },
73 { "lttng-probe-sock", 0 },
bd9b9e63 74 { "lttng-probe-statedump", 0 },
bd69f856 75 { "lttng-probe-sunrpc", 0 },
7ec24b77 76 { "lttng-probe-timer", 0 },
07e716ec
WP
77 { "lttng-probe-udp", 0 },
78 { "lttng-probe-vmscan", 0 },
bd69f856
AG
79 { "lttng-probe-workqueue", 0 },
80 { "lttng-probe-writeback", 0 },
096102bd
DG
81};
82
83/*
84 * Remove control kernel module(s) in reverse load order.
85 */
86void modprobe_remove_lttng_control(void)
87{
88 int ret = 0, i;
89 char modprobe[256];
90
91 for (i = ARRAY_SIZE(kern_modules_control) - 1; i >= 0; i--) {
92 ret = snprintf(modprobe, sizeof(modprobe),
93 "/sbin/modprobe -r -q %s",
94 kern_modules_control[i].name);
95 if (ret < 0) {
96 PERROR("snprintf modprobe -r");
97 goto error;
98 }
99 modprobe[sizeof(modprobe) - 1] = '\0';
100 ret = system(modprobe);
101 if (ret == -1) {
102 ERR("Unable to launch modprobe -r for module %s",
103 kern_modules_control[i].name);
104 } else if (kern_modules_control[i].required
105 && WEXITSTATUS(ret) != 0) {
106 ERR("Unable to remove module %s",
107 kern_modules_control[i].name);
108 } else {
109 DBG("Modprobe removal successful %s",
110 kern_modules_control[i].name);
111 }
112 }
113
114error:
115 return;
116}
117
118/*
119 * Remove data kernel modules in reverse load order.
120 */
121void modprobe_remove_lttng_data(void)
122{
123 int ret = 0, i;
124 char modprobe[256];
125
126 for (i = ARRAY_SIZE(kern_modules_list) - 1; i >= 0; i--) {
127 ret = snprintf(modprobe, sizeof(modprobe),
128 "/sbin/modprobe -r -q %s",
129 kern_modules_list[i].name);
130 if (ret < 0) {
df0f840b 131 PERROR("snprintf modprobe -r");
096102bd
DG
132 goto error;
133 }
134 modprobe[sizeof(modprobe) - 1] = '\0';
135 ret = system(modprobe);
136 if (ret == -1) {
137 ERR("Unable to launch modprobe -r for module %s",
138 kern_modules_list[i].name);
139 } else if (kern_modules_list[i].required
140 && WEXITSTATUS(ret) != 0) {
141 ERR("Unable to remove module %s",
142 kern_modules_list[i].name);
143 } else {
144 DBG("Modprobe removal successful %s",
145 kern_modules_list[i].name);
146 }
147 }
148
149error:
150 return;
151}
152
153/*
154 * Remove all kernel modules in reverse order.
155 */
156void modprobe_remove_lttng_all(void)
157{
158 modprobe_remove_lttng_data();
159 modprobe_remove_lttng_control();
160}
161
162/*
163 * Load control kernel module(s).
164 */
165int modprobe_lttng_control(void)
166{
167 int ret = 0, i;
168 char modprobe[256];
169
170 for (i = 0; i < ARRAY_SIZE(kern_modules_control); i++) {
171 ret = snprintf(modprobe, sizeof(modprobe),
172 "/sbin/modprobe %s%s",
173 kern_modules_control[i].required ? "" : "-q ",
174 kern_modules_control[i].name);
175 if (ret < 0) {
176 PERROR("snprintf modprobe");
177 goto error;
178 }
179 modprobe[sizeof(modprobe) - 1] = '\0';
180 ret = system(modprobe);
181 if (ret == -1) {
182 ERR("Unable to launch modprobe for module %s",
183 kern_modules_control[i].name);
184 } else if (kern_modules_control[i].required
185 && WEXITSTATUS(ret) != 0) {
186 ERR("Unable to load module %s",
187 kern_modules_control[i].name);
188 } else {
189 DBG("Modprobe successfully %s",
190 kern_modules_control[i].name);
191 }
192 }
193
194error:
195 return ret;
196}
197
198/*
199 * Load data kernel module(s).
200 */
201int modprobe_lttng_data(void)
202{
203 int ret = 0, i;
204 char modprobe[256];
205
206 for (i = 0; i < ARRAY_SIZE(kern_modules_list); i++) {
207 ret = snprintf(modprobe, sizeof(modprobe),
208 "/sbin/modprobe %s%s",
209 kern_modules_list[i].required ? "" : "-q ",
210 kern_modules_list[i].name);
211 if (ret < 0) {
df0f840b 212 PERROR("snprintf modprobe");
096102bd
DG
213 goto error;
214 }
215 modprobe[sizeof(modprobe) - 1] = '\0';
216 ret = system(modprobe);
217 if (ret == -1) {
218 ERR("Unable to launch modprobe for module %s",
219 kern_modules_list[i].name);
220 } else if (kern_modules_list[i].required
221 && WEXITSTATUS(ret) != 0) {
222 ERR("Unable to load module %s",
223 kern_modules_list[i].name);
224 } else {
225 DBG("Modprobe successfully %s",
226 kern_modules_list[i].name);
227 }
228 }
229
230error:
231 return ret;
232}
233
234/*
235 * Load all lttng kernel modules.
236 */
237int modprobe_lttng_all(void)
238{
239 int ret;
240
241 ret = modprobe_lttng_control();
242 if (ret < 0) {
243 goto error;
244 }
245
246 ret = modprobe_lttng_data();
247 if (ret < 0) {
248 goto error;
249 }
250
251error:
252 return ret;
253}
This page took 0.039582 seconds and 4 git commands to generate.