2 * Copyright (C) 2011 - David Goulet <dgoulet@efficios.com>
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.
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
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.
23 #include <common/common.h>
26 #include "kern-modules.h"
28 /* MUST be loaded first */
29 const struct kern_modules_param kern_modules_control
[] = {
30 { "lttng-tracer", 1 },
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 },
47 { "lttng-probe-block", 0 },
48 { "lttng-probe-irq", 0 },
49 { "lttng-probe-kvm", 0 },
50 { "lttng-probe-sched", 0 },
51 { "lttng-probe-statedump", 0 },
55 * Remove control kernel module(s) in reverse load order.
57 void modprobe_remove_lttng_control(void)
62 for (i
= ARRAY_SIZE(kern_modules_control
) - 1; i
>= 0; i
--) {
63 ret
= snprintf(modprobe
, sizeof(modprobe
),
64 "/sbin/modprobe -r -q %s",
65 kern_modules_control
[i
].name
);
67 PERROR("snprintf modprobe -r");
70 modprobe
[sizeof(modprobe
) - 1] = '\0';
71 ret
= system(modprobe
);
73 ERR("Unable to launch modprobe -r for module %s",
74 kern_modules_control
[i
].name
);
75 } else if (kern_modules_control
[i
].required
76 && WEXITSTATUS(ret
) != 0) {
77 ERR("Unable to remove module %s",
78 kern_modules_control
[i
].name
);
80 DBG("Modprobe removal successful %s",
81 kern_modules_control
[i
].name
);
90 * Remove data kernel modules in reverse load order.
92 void modprobe_remove_lttng_data(void)
97 for (i
= ARRAY_SIZE(kern_modules_list
) - 1; i
>= 0; i
--) {
98 ret
= snprintf(modprobe
, sizeof(modprobe
),
99 "/sbin/modprobe -r -q %s",
100 kern_modules_list
[i
].name
);
102 perror("snprintf modprobe -r");
105 modprobe
[sizeof(modprobe
) - 1] = '\0';
106 ret
= system(modprobe
);
108 ERR("Unable to launch modprobe -r for module %s",
109 kern_modules_list
[i
].name
);
110 } else if (kern_modules_list
[i
].required
111 && WEXITSTATUS(ret
) != 0) {
112 ERR("Unable to remove module %s",
113 kern_modules_list
[i
].name
);
115 DBG("Modprobe removal successful %s",
116 kern_modules_list
[i
].name
);
125 * Remove all kernel modules in reverse order.
127 void modprobe_remove_lttng_all(void)
129 modprobe_remove_lttng_data();
130 modprobe_remove_lttng_control();
134 * Load control kernel module(s).
136 int modprobe_lttng_control(void)
141 for (i
= 0; i
< ARRAY_SIZE(kern_modules_control
); i
++) {
142 ret
= snprintf(modprobe
, sizeof(modprobe
),
143 "/sbin/modprobe %s%s",
144 kern_modules_control
[i
].required
? "" : "-q ",
145 kern_modules_control
[i
].name
);
147 PERROR("snprintf modprobe");
150 modprobe
[sizeof(modprobe
) - 1] = '\0';
151 ret
= system(modprobe
);
153 ERR("Unable to launch modprobe for module %s",
154 kern_modules_control
[i
].name
);
155 } else if (kern_modules_control
[i
].required
156 && WEXITSTATUS(ret
) != 0) {
157 ERR("Unable to load module %s",
158 kern_modules_control
[i
].name
);
160 DBG("Modprobe successfully %s",
161 kern_modules_control
[i
].name
);
170 * Load data kernel module(s).
172 int modprobe_lttng_data(void)
177 for (i
= 0; i
< ARRAY_SIZE(kern_modules_list
); i
++) {
178 ret
= snprintf(modprobe
, sizeof(modprobe
),
179 "/sbin/modprobe %s%s",
180 kern_modules_list
[i
].required
? "" : "-q ",
181 kern_modules_list
[i
].name
);
183 perror("snprintf modprobe");
186 modprobe
[sizeof(modprobe
) - 1] = '\0';
187 ret
= system(modprobe
);
189 ERR("Unable to launch modprobe for module %s",
190 kern_modules_list
[i
].name
);
191 } else if (kern_modules_list
[i
].required
192 && WEXITSTATUS(ret
) != 0) {
193 ERR("Unable to load module %s",
194 kern_modules_list
[i
].name
);
196 DBG("Modprobe successfully %s",
197 kern_modules_list
[i
].name
);
206 * Load all lttng kernel modules.
208 int modprobe_lttng_all(void)
212 ret
= modprobe_lttng_control();
217 ret
= modprobe_lttng_data();