Fix: poll: show the correct number of fds
[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 },
868e733e
MG
58 { "lttng-probe-kvm-x86", 0 },
59 { "lttng-probe-kvm-x86-mmu", 0 },
07e716ec 60 { "lttng-probe-lock", 0 },
e3e57ea7 61 { "lttng-probe-module", 0 },
07e716ec
WP
62 { "lttng-probe-napi", 0 },
63 { "lttng-probe-net", 0 },
64 { "lttng-probe-power", 0 },
bd69f856
AG
65 { "lttng-probe-printk", 0 },
66 { "lttng-probe-random", 0 },
67 { "lttng-probe-rcu", 0 },
68 { "lttng-probe-regmap", 0 },
07e716ec 69 { "lttng-probe-regulator", 0 },
bd69f856 70 { "lttng-probe-rpm", 0 },
096102bd 71 { "lttng-probe-sched", 0 },
07e716ec 72 { "lttng-probe-scsi", 0 },
9ae7d41d 73 { "lttng-probe-signal", 0 },
07e716ec
WP
74 { "lttng-probe-skb", 0 },
75 { "lttng-probe-sock", 0 },
bd9b9e63 76 { "lttng-probe-statedump", 0 },
bd69f856 77 { "lttng-probe-sunrpc", 0 },
7ec24b77 78 { "lttng-probe-timer", 0 },
07e716ec
WP
79 { "lttng-probe-udp", 0 },
80 { "lttng-probe-vmscan", 0 },
bd69f856
AG
81 { "lttng-probe-workqueue", 0 },
82 { "lttng-probe-writeback", 0 },
096102bd
DG
83};
84
85/*
86 * Remove control kernel module(s) in reverse load order.
87 */
88void 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
116error:
117 return;
118}
119
120/*
121 * Remove data kernel modules in reverse load order.
122 */
123void 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) {
df0f840b 133 PERROR("snprintf modprobe -r");
096102bd
DG
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
151error:
152 return;
153}
154
155/*
156 * Remove all kernel modules in reverse order.
157 */
158void 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 */
167int 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
196error:
197 return ret;
198}
199
200/*
201 * Load data kernel module(s).
202 */
203int 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) {
df0f840b 214 PERROR("snprintf modprobe");
096102bd
DG
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
232error:
233 return ret;
234}
This page took 0.044273 seconds and 4 git commands to generate.