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