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