modprobe lttng-probe-signal
[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 it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; only version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307, 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-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 },
51 { "lttng-probe-signal", 0 },
52 { "lttng-probe-statedump", 0 },
53 };
54
55 /*
56 * Remove control kernel module(s) in reverse load order.
57 */
58 void modprobe_remove_lttng_control(void)
59 {
60 int ret = 0, i;
61 char modprobe[256];
62
63 for (i = ARRAY_SIZE(kern_modules_control) - 1; i >= 0; i--) {
64 ret = snprintf(modprobe, sizeof(modprobe),
65 "/sbin/modprobe -r -q %s",
66 kern_modules_control[i].name);
67 if (ret < 0) {
68 PERROR("snprintf modprobe -r");
69 goto error;
70 }
71 modprobe[sizeof(modprobe) - 1] = '\0';
72 ret = system(modprobe);
73 if (ret == -1) {
74 ERR("Unable to launch modprobe -r for module %s",
75 kern_modules_control[i].name);
76 } else if (kern_modules_control[i].required
77 && WEXITSTATUS(ret) != 0) {
78 ERR("Unable to remove module %s",
79 kern_modules_control[i].name);
80 } else {
81 DBG("Modprobe removal successful %s",
82 kern_modules_control[i].name);
83 }
84 }
85
86 error:
87 return;
88 }
89
90 /*
91 * Remove data kernel modules in reverse load order.
92 */
93 void modprobe_remove_lttng_data(void)
94 {
95 int ret = 0, i;
96 char modprobe[256];
97
98 for (i = ARRAY_SIZE(kern_modules_list) - 1; i >= 0; i--) {
99 ret = snprintf(modprobe, sizeof(modprobe),
100 "/sbin/modprobe -r -q %s",
101 kern_modules_list[i].name);
102 if (ret < 0) {
103 perror("snprintf modprobe -r");
104 goto error;
105 }
106 modprobe[sizeof(modprobe) - 1] = '\0';
107 ret = system(modprobe);
108 if (ret == -1) {
109 ERR("Unable to launch modprobe -r for module %s",
110 kern_modules_list[i].name);
111 } else if (kern_modules_list[i].required
112 && WEXITSTATUS(ret) != 0) {
113 ERR("Unable to remove module %s",
114 kern_modules_list[i].name);
115 } else {
116 DBG("Modprobe removal successful %s",
117 kern_modules_list[i].name);
118 }
119 }
120
121 error:
122 return;
123 }
124
125 /*
126 * Remove all kernel modules in reverse order.
127 */
128 void modprobe_remove_lttng_all(void)
129 {
130 modprobe_remove_lttng_data();
131 modprobe_remove_lttng_control();
132 }
133
134 /*
135 * Load control kernel module(s).
136 */
137 int modprobe_lttng_control(void)
138 {
139 int ret = 0, i;
140 char modprobe[256];
141
142 for (i = 0; i < ARRAY_SIZE(kern_modules_control); i++) {
143 ret = snprintf(modprobe, sizeof(modprobe),
144 "/sbin/modprobe %s%s",
145 kern_modules_control[i].required ? "" : "-q ",
146 kern_modules_control[i].name);
147 if (ret < 0) {
148 PERROR("snprintf modprobe");
149 goto error;
150 }
151 modprobe[sizeof(modprobe) - 1] = '\0';
152 ret = system(modprobe);
153 if (ret == -1) {
154 ERR("Unable to launch modprobe for module %s",
155 kern_modules_control[i].name);
156 } else if (kern_modules_control[i].required
157 && WEXITSTATUS(ret) != 0) {
158 ERR("Unable to load module %s",
159 kern_modules_control[i].name);
160 } else {
161 DBG("Modprobe successfully %s",
162 kern_modules_control[i].name);
163 }
164 }
165
166 error:
167 return ret;
168 }
169
170 /*
171 * Load data kernel module(s).
172 */
173 int modprobe_lttng_data(void)
174 {
175 int ret = 0, i;
176 char modprobe[256];
177
178 for (i = 0; i < ARRAY_SIZE(kern_modules_list); i++) {
179 ret = snprintf(modprobe, sizeof(modprobe),
180 "/sbin/modprobe %s%s",
181 kern_modules_list[i].required ? "" : "-q ",
182 kern_modules_list[i].name);
183 if (ret < 0) {
184 perror("snprintf modprobe");
185 goto error;
186 }
187 modprobe[sizeof(modprobe) - 1] = '\0';
188 ret = system(modprobe);
189 if (ret == -1) {
190 ERR("Unable to launch modprobe for module %s",
191 kern_modules_list[i].name);
192 } else if (kern_modules_list[i].required
193 && WEXITSTATUS(ret) != 0) {
194 ERR("Unable to load module %s",
195 kern_modules_list[i].name);
196 } else {
197 DBG("Modprobe successfully %s",
198 kern_modules_list[i].name);
199 }
200 }
201
202 error:
203 return ret;
204 }
205
206 /*
207 * Load all lttng kernel modules.
208 */
209 int modprobe_lttng_all(void)
210 {
211 int ret;
212
213 ret = modprobe_lttng_control();
214 if (ret < 0) {
215 goto error;
216 }
217
218 ret = modprobe_lttng_data();
219 if (ret < 0) {
220 goto error;
221 }
222
223 error:
224 return ret;
225 }
This page took 0.05194 seconds and 5 git commands to generate.