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 },
54 * Remove control kernel module(s) in reverse load order.
56 void modprobe_remove_lttng_control(void)
61 for (i
= ARRAY_SIZE(kern_modules_control
) - 1; i
>= 0; i
--) {
62 ret
= snprintf(modprobe
, sizeof(modprobe
),
63 "/sbin/modprobe -r -q %s",
64 kern_modules_control
[i
].name
);
66 PERROR("snprintf modprobe -r");
69 modprobe
[sizeof(modprobe
) - 1] = '\0';
70 ret
= system(modprobe
);
72 ERR("Unable to launch modprobe -r for module %s",
73 kern_modules_control
[i
].name
);
74 } else if (kern_modules_control
[i
].required
75 && WEXITSTATUS(ret
) != 0) {
76 ERR("Unable to remove module %s",
77 kern_modules_control
[i
].name
);
79 DBG("Modprobe removal successful %s",
80 kern_modules_control
[i
].name
);
89 * Remove data kernel modules in reverse load order.
91 void modprobe_remove_lttng_data(void)
96 for (i
= ARRAY_SIZE(kern_modules_list
) - 1; i
>= 0; i
--) {
97 ret
= snprintf(modprobe
, sizeof(modprobe
),
98 "/sbin/modprobe -r -q %s",
99 kern_modules_list
[i
].name
);
101 perror("snprintf modprobe -r");
104 modprobe
[sizeof(modprobe
) - 1] = '\0';
105 ret
= system(modprobe
);
107 ERR("Unable to launch modprobe -r for module %s",
108 kern_modules_list
[i
].name
);
109 } else if (kern_modules_list
[i
].required
110 && WEXITSTATUS(ret
) != 0) {
111 ERR("Unable to remove module %s",
112 kern_modules_list
[i
].name
);
114 DBG("Modprobe removal successful %s",
115 kern_modules_list
[i
].name
);
124 * Remove all kernel modules in reverse order.
126 void modprobe_remove_lttng_all(void)
128 modprobe_remove_lttng_data();
129 modprobe_remove_lttng_control();
133 * Load control kernel module(s).
135 int modprobe_lttng_control(void)
140 for (i
= 0; i
< ARRAY_SIZE(kern_modules_control
); i
++) {
141 ret
= snprintf(modprobe
, sizeof(modprobe
),
142 "/sbin/modprobe %s%s",
143 kern_modules_control
[i
].required
? "" : "-q ",
144 kern_modules_control
[i
].name
);
146 PERROR("snprintf modprobe");
149 modprobe
[sizeof(modprobe
) - 1] = '\0';
150 ret
= system(modprobe
);
152 ERR("Unable to launch modprobe for module %s",
153 kern_modules_control
[i
].name
);
154 } else if (kern_modules_control
[i
].required
155 && WEXITSTATUS(ret
) != 0) {
156 ERR("Unable to load module %s",
157 kern_modules_control
[i
].name
);
159 DBG("Modprobe successfully %s",
160 kern_modules_control
[i
].name
);
169 * Load data kernel module(s).
171 int modprobe_lttng_data(void)
176 for (i
= 0; i
< ARRAY_SIZE(kern_modules_list
); i
++) {
177 ret
= snprintf(modprobe
, sizeof(modprobe
),
178 "/sbin/modprobe %s%s",
179 kern_modules_list
[i
].required
? "" : "-q ",
180 kern_modules_list
[i
].name
);
182 perror("snprintf modprobe");
185 modprobe
[sizeof(modprobe
) - 1] = '\0';
186 ret
= system(modprobe
);
188 ERR("Unable to launch modprobe for module %s",
189 kern_modules_list
[i
].name
);
190 } else if (kern_modules_list
[i
].required
191 && WEXITSTATUS(ret
) != 0) {
192 ERR("Unable to load module %s",
193 kern_modules_list
[i
].name
);
195 DBG("Modprobe successfully %s",
196 kern_modules_list
[i
].name
);
205 * Load all lttng kernel modules.
207 int modprobe_lttng_all(void)
211 ret
= modprobe_lttng_control();
216 ret
= modprobe_lttng_data();