Commit | Line | Data |
---|---|---|
91d76f53 DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
82a3637f DG |
6 | * as published by the Free Software Foundation; only version 2 |
7 | * of the License. | |
91d76f53 DG |
8 | * |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | */ | |
18 | ||
19 | #define _GNU_SOURCE | |
20 | #include <errno.h> | |
21 | #include <pthread.h> | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
099e26bd | 24 | #include <string.h> |
aba8e916 DG |
25 | #include <sys/stat.h> |
26 | #include <sys/types.h> | |
099e26bd | 27 | #include <unistd.h> |
0df502fd | 28 | #include <urcu/compiler.h> |
bec39940 | 29 | |
990570ed | 30 | #include <common/common.h> |
1e307fab | 31 | |
56fff090 | 32 | #include "ust-app.h" |
48842b30 | 33 | #include "ust-consumer.h" |
d80a6244 DG |
34 | #include "ust-ctl.h" |
35 | ||
55cc08a6 DG |
36 | /* |
37 | * Delete ust context safely. RCU read lock must be held before calling | |
38 | * this function. | |
39 | */ | |
40 | static | |
41 | void delete_ust_app_ctx(int sock, struct ust_app_ctx *ua_ctx) | |
42 | { | |
43 | if (ua_ctx->obj) { | |
44 | ustctl_release_object(sock, ua_ctx->obj); | |
45 | free(ua_ctx->obj); | |
46 | } | |
47 | free(ua_ctx); | |
48 | } | |
49 | ||
d80a6244 DG |
50 | /* |
51 | * Delete ust app event safely. RCU read lock must be held before calling | |
52 | * this function. | |
53 | */ | |
8b366481 DG |
54 | static |
55 | void delete_ust_app_event(int sock, struct ust_app_event *ua_event) | |
d80a6244 | 56 | { |
55cc08a6 | 57 | int ret; |
bec39940 | 58 | struct lttng_ht_iter iter; |
55cc08a6 DG |
59 | struct ust_app_ctx *ua_ctx; |
60 | ||
fc34caaa | 61 | /* Destroy each context of event */ |
bec39940 DG |
62 | cds_lfht_for_each_entry(ua_event->ctx->ht, &iter.iter, ua_ctx, |
63 | node.node) { | |
64 | ret = lttng_ht_del(ua_event->ctx, &iter); | |
55cc08a6 DG |
65 | assert(!ret); |
66 | delete_ust_app_ctx(sock, ua_ctx); | |
67 | } | |
bec39940 | 68 | lttng_ht_destroy(ua_event->ctx); |
d80a6244 | 69 | |
edb67388 DG |
70 | if (ua_event->obj != NULL) { |
71 | ustctl_release_object(sock, ua_event->obj); | |
72 | free(ua_event->obj); | |
73 | } | |
d80a6244 DG |
74 | free(ua_event); |
75 | } | |
76 | ||
77 | /* | |
78 | * Delete ust app stream safely. RCU read lock must be held before calling | |
79 | * this function. | |
80 | */ | |
8b366481 DG |
81 | static |
82 | void delete_ust_app_stream(int sock, struct ltt_ust_stream *stream) | |
d80a6244 | 83 | { |
8b366481 DG |
84 | if (stream->obj) { |
85 | ustctl_release_object(sock, stream->obj); | |
86 | free(stream->obj); | |
87 | } | |
84cd17c6 | 88 | free(stream); |
d80a6244 DG |
89 | } |
90 | ||
91 | /* | |
92 | * Delete ust app channel safely. RCU read lock must be held before calling | |
93 | * this function. | |
94 | */ | |
8b366481 DG |
95 | static |
96 | void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan) | |
d80a6244 DG |
97 | { |
98 | int ret; | |
bec39940 | 99 | struct lttng_ht_iter iter; |
d80a6244 | 100 | struct ust_app_event *ua_event; |
55cc08a6 | 101 | struct ust_app_ctx *ua_ctx; |
d80a6244 DG |
102 | struct ltt_ust_stream *stream, *stmp; |
103 | ||
55cc08a6 | 104 | /* Wipe stream */ |
d80a6244 | 105 | cds_list_for_each_entry_safe(stream, stmp, &ua_chan->streams.head, list) { |
84cd17c6 | 106 | cds_list_del(&stream->list); |
d80a6244 DG |
107 | delete_ust_app_stream(sock, stream); |
108 | } | |
109 | ||
55cc08a6 | 110 | /* Wipe context */ |
bec39940 DG |
111 | cds_lfht_for_each_entry(ua_chan->ctx->ht, &iter.iter, ua_ctx, node.node) { |
112 | ret = lttng_ht_del(ua_chan->ctx, &iter); | |
55cc08a6 DG |
113 | assert(!ret); |
114 | delete_ust_app_ctx(sock, ua_ctx); | |
115 | } | |
bec39940 | 116 | lttng_ht_destroy(ua_chan->ctx); |
d80a6244 | 117 | |
55cc08a6 | 118 | /* Wipe events */ |
bec39940 DG |
119 | cds_lfht_for_each_entry(ua_chan->events->ht, &iter.iter, ua_event, |
120 | node.node) { | |
121 | ret = lttng_ht_del(ua_chan->events, &iter); | |
525b0740 | 122 | assert(!ret); |
d80a6244 DG |
123 | delete_ust_app_event(sock, ua_event); |
124 | } | |
bec39940 | 125 | lttng_ht_destroy(ua_chan->events); |
edb67388 DG |
126 | |
127 | if (ua_chan->obj != NULL) { | |
128 | ustctl_release_object(sock, ua_chan->obj); | |
129 | free(ua_chan->obj); | |
130 | } | |
84cd17c6 | 131 | free(ua_chan); |
d80a6244 DG |
132 | } |
133 | ||
134 | /* | |
135 | * Delete ust app session safely. RCU read lock must be held before calling | |
136 | * this function. | |
137 | */ | |
8b366481 DG |
138 | static |
139 | void delete_ust_app_session(int sock, struct ust_app_session *ua_sess) | |
d80a6244 DG |
140 | { |
141 | int ret; | |
bec39940 | 142 | struct lttng_ht_iter iter; |
d80a6244 DG |
143 | struct ust_app_channel *ua_chan; |
144 | ||
145 | if (ua_sess->metadata) { | |
8b366481 DG |
146 | if (ua_sess->metadata->stream_obj) { |
147 | ustctl_release_object(sock, ua_sess->metadata->stream_obj); | |
148 | free(ua_sess->metadata->stream_obj); | |
149 | } | |
150 | if (ua_sess->metadata->obj) { | |
151 | ustctl_release_object(sock, ua_sess->metadata->obj); | |
152 | free(ua_sess->metadata->obj); | |
153 | } | |
d80a6244 DG |
154 | } |
155 | ||
bec39940 DG |
156 | cds_lfht_for_each_entry(ua_sess->channels->ht, &iter.iter, ua_chan, |
157 | node.node) { | |
158 | ret = lttng_ht_del(ua_sess->channels, &iter); | |
525b0740 | 159 | assert(!ret); |
d80a6244 DG |
160 | delete_ust_app_channel(sock, ua_chan); |
161 | } | |
bec39940 | 162 | lttng_ht_destroy(ua_sess->channels); |
d80a6244 | 163 | |
aee6bafd MD |
164 | if (ua_sess->handle != -1) { |
165 | ustctl_release_handle(sock, ua_sess->handle); | |
166 | } | |
8b366481 | 167 | free(ua_sess); |
d80a6244 | 168 | } |
91d76f53 DG |
169 | |
170 | /* | |
284d8f55 DG |
171 | * Delete a traceable application structure from the global list. Never call |
172 | * this function outside of a call_rcu call. | |
91d76f53 | 173 | */ |
8b366481 DG |
174 | static |
175 | void delete_ust_app(struct ust_app *app) | |
91d76f53 | 176 | { |
8b366481 | 177 | int ret, sock; |
bec39940 | 178 | struct lttng_ht_iter iter; |
284d8f55 | 179 | struct ust_app_session *ua_sess; |
44d3bd01 | 180 | |
f6a9efaa | 181 | rcu_read_lock(); |
44d3bd01 | 182 | |
d80a6244 | 183 | /* Delete ust app sessions info */ |
6414a713 MD |
184 | sock = app->key.sock; |
185 | app->key.sock = -1; | |
d80a6244 | 186 | |
8b366481 | 187 | /* Wipe sessions */ |
bec39940 DG |
188 | cds_lfht_for_each_entry(app->sessions->ht, &iter.iter, ua_sess, |
189 | node.node) { | |
190 | ret = lttng_ht_del(app->sessions, &iter); | |
525b0740 | 191 | assert(!ret); |
284d8f55 | 192 | delete_ust_app_session(app->key.sock, ua_sess); |
d80a6244 | 193 | } |
bec39940 | 194 | lttng_ht_destroy(app->sessions); |
d80a6244 | 195 | |
6414a713 | 196 | /* |
bec39940 DG |
197 | * Wait until we have removed the key from the sock hash table before |
198 | * closing this socket, otherwise an application could re-use the socket ID | |
199 | * and race with the teardown, using the same hash table entry. | |
6414a713 MD |
200 | */ |
201 | close(sock); | |
d80a6244 | 202 | |
284d8f55 DG |
203 | DBG2("UST app pid %d deleted", app->key.pid); |
204 | free(app); | |
bec39940 | 205 | |
f6a9efaa | 206 | rcu_read_unlock(); |
099e26bd DG |
207 | } |
208 | ||
209 | /* | |
f6a9efaa | 210 | * URCU intermediate call to delete an UST app. |
099e26bd | 211 | */ |
8b366481 DG |
212 | static |
213 | void delete_ust_app_rcu(struct rcu_head *head) | |
099e26bd | 214 | { |
bec39940 DG |
215 | struct lttng_ht_node_ulong *node = |
216 | caa_container_of(head, struct lttng_ht_node_ulong, head); | |
f6a9efaa DG |
217 | struct ust_app *app = |
218 | caa_container_of(node, struct ust_app, node); | |
219 | ||
bec39940 | 220 | DBG3("Call RCU deleting app PID %d", app->key.pid); |
f6a9efaa | 221 | delete_ust_app(app); |
099e26bd DG |
222 | } |
223 | ||
8b366481 DG |
224 | /* |
225 | * Alloc new UST app session. | |
226 | */ | |
227 | static | |
228 | struct ust_app_session *alloc_ust_app_session(void) | |
229 | { | |
230 | struct ust_app_session *ua_sess; | |
231 | ||
232 | /* Init most of the default value by allocating and zeroing */ | |
233 | ua_sess = zmalloc(sizeof(struct ust_app_session)); | |
234 | if (ua_sess == NULL) { | |
235 | PERROR("malloc"); | |
236 | goto error; | |
237 | } | |
238 | ||
239 | ua_sess->handle = -1; | |
bec39940 | 240 | ua_sess->channels = lttng_ht_new(0, LTTNG_HT_TYPE_STRING); |
8b366481 DG |
241 | |
242 | return ua_sess; | |
243 | ||
244 | error: | |
245 | return NULL; | |
246 | } | |
247 | ||
248 | /* | |
249 | * Alloc new UST app channel. | |
250 | */ | |
251 | static | |
252 | struct ust_app_channel *alloc_ust_app_channel(char *name, | |
253 | struct lttng_ust_channel *attr) | |
254 | { | |
255 | struct ust_app_channel *ua_chan; | |
256 | ||
257 | /* Init most of the default value by allocating and zeroing */ | |
258 | ua_chan = zmalloc(sizeof(struct ust_app_channel)); | |
259 | if (ua_chan == NULL) { | |
260 | PERROR("malloc"); | |
261 | goto error; | |
262 | } | |
263 | ||
264 | /* Setup channel name */ | |
265 | strncpy(ua_chan->name, name, sizeof(ua_chan->name)); | |
266 | ua_chan->name[sizeof(ua_chan->name) - 1] = '\0'; | |
267 | ||
268 | ua_chan->enabled = 1; | |
269 | ua_chan->handle = -1; | |
bec39940 DG |
270 | ua_chan->ctx = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); |
271 | ua_chan->events = lttng_ht_new(0, LTTNG_HT_TYPE_STRING); | |
272 | lttng_ht_node_init_str(&ua_chan->node, ua_chan->name); | |
8b366481 DG |
273 | |
274 | CDS_INIT_LIST_HEAD(&ua_chan->streams.head); | |
275 | ||
276 | /* Copy attributes */ | |
277 | if (attr) { | |
278 | memcpy(&ua_chan->attr, attr, sizeof(ua_chan->attr)); | |
279 | } | |
280 | ||
281 | DBG3("UST app channel %s allocated", ua_chan->name); | |
282 | ||
283 | return ua_chan; | |
284 | ||
285 | error: | |
286 | return NULL; | |
287 | } | |
288 | ||
289 | /* | |
290 | * Alloc new UST app event. | |
291 | */ | |
292 | static | |
293 | struct ust_app_event *alloc_ust_app_event(char *name, | |
294 | struct lttng_ust_event *attr) | |
295 | { | |
296 | struct ust_app_event *ua_event; | |
297 | ||
298 | /* Init most of the default value by allocating and zeroing */ | |
299 | ua_event = zmalloc(sizeof(struct ust_app_event)); | |
300 | if (ua_event == NULL) { | |
301 | PERROR("malloc"); | |
302 | goto error; | |
303 | } | |
304 | ||
305 | ua_event->enabled = 1; | |
306 | strncpy(ua_event->name, name, sizeof(ua_event->name)); | |
307 | ua_event->name[sizeof(ua_event->name) - 1] = '\0'; | |
bec39940 DG |
308 | ua_event->ctx = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); |
309 | lttng_ht_node_init_str(&ua_event->node, ua_event->name); | |
8b366481 DG |
310 | |
311 | /* Copy attributes */ | |
312 | if (attr) { | |
313 | memcpy(&ua_event->attr, attr, sizeof(ua_event->attr)); | |
314 | } | |
315 | ||
316 | DBG3("UST app event %s allocated", ua_event->name); | |
317 | ||
318 | return ua_event; | |
319 | ||
320 | error: | |
321 | return NULL; | |
322 | } | |
323 | ||
324 | /* | |
325 | * Alloc new UST app context. | |
326 | */ | |
327 | static | |
328 | struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context *uctx) | |
329 | { | |
330 | struct ust_app_ctx *ua_ctx; | |
331 | ||
332 | ua_ctx = zmalloc(sizeof(struct ust_app_ctx)); | |
333 | if (ua_ctx == NULL) { | |
334 | goto error; | |
335 | } | |
336 | ||
337 | if (uctx) { | |
338 | memcpy(&ua_ctx->ctx, uctx, sizeof(ua_ctx->ctx)); | |
339 | } | |
340 | ||
341 | DBG3("UST app context %d allocated", ua_ctx->ctx.ctx); | |
342 | ||
343 | error: | |
344 | return ua_ctx; | |
345 | } | |
346 | ||
099e26bd | 347 | /* |
421cb601 DG |
348 | * Find an ust_app using the sock and return it. RCU read side lock must be |
349 | * held before calling this helper function. | |
099e26bd | 350 | */ |
8b366481 DG |
351 | static |
352 | struct ust_app *find_app_by_sock(int sock) | |
099e26bd | 353 | { |
bec39940 | 354 | struct lttng_ht_node_ulong *node; |
f6a9efaa | 355 | struct ust_app_key *key; |
bec39940 | 356 | struct lttng_ht_iter iter; |
f6a9efaa | 357 | |
bec39940 DG |
358 | lttng_ht_lookup(ust_app_sock_key_map, (void *)((unsigned long) sock), |
359 | &iter); | |
360 | node = lttng_ht_iter_get_node_ulong(&iter); | |
f6a9efaa DG |
361 | if (node == NULL) { |
362 | DBG2("UST app find by sock %d key not found", sock); | |
f6a9efaa DG |
363 | goto error; |
364 | } | |
f6a9efaa DG |
365 | key = caa_container_of(node, struct ust_app_key, node); |
366 | ||
bec39940 DG |
367 | lttng_ht_lookup(ust_app_ht, (void *)((unsigned long) key->pid), &iter); |
368 | node = lttng_ht_iter_get_node_ulong(&iter); | |
f6a9efaa DG |
369 | if (node == NULL) { |
370 | DBG2("UST app find by sock %d not found", sock); | |
f6a9efaa DG |
371 | goto error; |
372 | } | |
f6a9efaa DG |
373 | return caa_container_of(node, struct ust_app, node); |
374 | ||
375 | error: | |
376 | return NULL; | |
099e26bd DG |
377 | } |
378 | ||
55cc08a6 DG |
379 | /* |
380 | * Create the channel context on the tracer. | |
381 | */ | |
382 | static | |
383 | int create_ust_channel_context(struct ust_app_channel *ua_chan, | |
384 | struct ust_app_ctx *ua_ctx, struct ust_app *app) | |
385 | { | |
386 | int ret; | |
387 | ||
388 | ret = ustctl_add_context(app->key.sock, &ua_ctx->ctx, | |
389 | ua_chan->obj, &ua_ctx->obj); | |
390 | if (ret < 0) { | |
391 | goto error; | |
392 | } | |
393 | ||
394 | ua_ctx->handle = ua_ctx->obj->handle; | |
395 | ||
727d5404 | 396 | DBG2("UST app context created successfully for channel %s", ua_chan->name); |
55cc08a6 DG |
397 | |
398 | error: | |
399 | return ret; | |
400 | } | |
401 | ||
402 | /* | |
403 | * Create the event context on the tracer. | |
404 | */ | |
405 | static | |
406 | int create_ust_event_context(struct ust_app_event *ua_event, | |
407 | struct ust_app_ctx *ua_ctx, struct ust_app *app) | |
408 | { | |
409 | int ret; | |
410 | ||
411 | ret = ustctl_add_context(app->key.sock, &ua_ctx->ctx, | |
412 | ua_event->obj, &ua_ctx->obj); | |
413 | if (ret < 0) { | |
414 | goto error; | |
415 | } | |
416 | ||
417 | ua_ctx->handle = ua_ctx->obj->handle; | |
418 | ||
727d5404 | 419 | DBG2("UST app context created successfully for event %s", ua_event->name); |
55cc08a6 DG |
420 | |
421 | error: | |
422 | return ret; | |
423 | } | |
424 | ||
9730260e DG |
425 | /* |
426 | * Disable the specified event on to UST tracer for the UST session. | |
427 | */ | |
428 | static int disable_ust_event(struct ust_app *app, | |
429 | struct ust_app_session *ua_sess, struct ust_app_event *ua_event) | |
430 | { | |
431 | int ret; | |
432 | ||
433 | ret = ustctl_disable(app->key.sock, ua_event->obj); | |
434 | if (ret < 0) { | |
435 | ERR("UST app event %s disable failed for app (pid: %d) " | |
436 | "and session handle %d with ret %d", | |
437 | ua_event->attr.name, app->key.pid, ua_sess->handle, ret); | |
438 | goto error; | |
439 | } | |
440 | ||
441 | DBG2("UST app event %s disabled successfully for app (pid: %d)", | |
442 | ua_event->attr.name, app->key.pid); | |
443 | ||
444 | error: | |
445 | return ret; | |
446 | } | |
447 | ||
78f0bacd DG |
448 | /* |
449 | * Disable the specified channel on to UST tracer for the UST session. | |
450 | */ | |
451 | static int disable_ust_channel(struct ust_app *app, | |
452 | struct ust_app_session *ua_sess, struct ust_app_channel *ua_chan) | |
453 | { | |
454 | int ret; | |
455 | ||
456 | ret = ustctl_disable(app->key.sock, ua_chan->obj); | |
457 | if (ret < 0) { | |
458 | ERR("UST app channel %s disable failed for app (pid: %d) " | |
459 | "and session handle %d with ret %d", | |
460 | ua_chan->name, app->key.pid, ua_sess->handle, ret); | |
461 | goto error; | |
462 | } | |
463 | ||
78f0bacd DG |
464 | DBG2("UST app channel %s disabled successfully for app (pid: %d)", |
465 | ua_chan->name, app->key.pid); | |
466 | ||
467 | error: | |
468 | return ret; | |
469 | } | |
470 | ||
471 | /* | |
472 | * Enable the specified channel on to UST tracer for the UST session. | |
473 | */ | |
474 | static int enable_ust_channel(struct ust_app *app, | |
475 | struct ust_app_session *ua_sess, struct ust_app_channel *ua_chan) | |
476 | { | |
477 | int ret; | |
478 | ||
479 | ret = ustctl_enable(app->key.sock, ua_chan->obj); | |
480 | if (ret < 0) { | |
481 | ERR("UST app channel %s enable failed for app (pid: %d) " | |
482 | "and session handle %d with ret %d", | |
483 | ua_chan->name, app->key.pid, ua_sess->handle, ret); | |
484 | goto error; | |
485 | } | |
486 | ||
487 | ua_chan->enabled = 1; | |
488 | ||
489 | DBG2("UST app channel %s enabled successfully for app (pid: %d)", | |
490 | ua_chan->name, app->key.pid); | |
491 | ||
492 | error: | |
493 | return ret; | |
494 | } | |
495 | ||
edb67388 DG |
496 | /* |
497 | * Enable the specified event on to UST tracer for the UST session. | |
498 | */ | |
499 | static int enable_ust_event(struct ust_app *app, | |
500 | struct ust_app_session *ua_sess, struct ust_app_event *ua_event) | |
501 | { | |
502 | int ret; | |
503 | ||
504 | ret = ustctl_enable(app->key.sock, ua_event->obj); | |
505 | if (ret < 0) { | |
506 | ERR("UST app event %s enable failed for app (pid: %d) " | |
507 | "and session handle %d with ret %d", | |
508 | ua_event->attr.name, app->key.pid, ua_sess->handle, ret); | |
509 | goto error; | |
510 | } | |
511 | ||
512 | DBG2("UST app event %s enabled successfully for app (pid: %d)", | |
513 | ua_event->attr.name, app->key.pid); | |
514 | ||
515 | error: | |
516 | return ret; | |
517 | } | |
518 | ||
099e26bd | 519 | /* |
5b4a0ec0 | 520 | * Open metadata onto the UST tracer for a UST session. |
0177d773 | 521 | */ |
5b4a0ec0 DG |
522 | static int open_ust_metadata(struct ust_app *app, |
523 | struct ust_app_session *ua_sess) | |
0177d773 | 524 | { |
5b4a0ec0 DG |
525 | int ret; |
526 | struct lttng_ust_channel_attr uattr; | |
0177d773 | 527 | |
5b4a0ec0 DG |
528 | uattr.overwrite = ua_sess->metadata->attr.overwrite; |
529 | uattr.subbuf_size = ua_sess->metadata->attr.subbuf_size; | |
530 | uattr.num_subbuf = ua_sess->metadata->attr.num_subbuf; | |
531 | uattr.switch_timer_interval = | |
532 | ua_sess->metadata->attr.switch_timer_interval; | |
533 | uattr.read_timer_interval = | |
534 | ua_sess->metadata->attr.read_timer_interval; | |
535 | uattr.output = ua_sess->metadata->attr.output; | |
536 | ||
537 | /* UST tracer metadata creation */ | |
538 | ret = ustctl_open_metadata(app->key.sock, ua_sess->handle, &uattr, | |
539 | &ua_sess->metadata->obj); | |
540 | if (ret < 0) { | |
fc34caaa DG |
541 | ERR("UST app open metadata failed for app pid:%d with ret %d", |
542 | app->key.pid, ret); | |
f6a9efaa | 543 | goto error; |
0177d773 | 544 | } |
f6a9efaa | 545 | |
6d3686da DG |
546 | ua_sess->metadata->handle = ua_sess->metadata->obj->handle; |
547 | ||
f6a9efaa | 548 | error: |
5b4a0ec0 | 549 | return ret; |
91d76f53 DG |
550 | } |
551 | ||
552 | /* | |
5b4a0ec0 | 553 | * Create stream onto the UST tracer for a UST session. |
91d76f53 | 554 | */ |
5b4a0ec0 DG |
555 | static int create_ust_stream(struct ust_app *app, |
556 | struct ust_app_session *ua_sess) | |
91d76f53 | 557 | { |
5b4a0ec0 | 558 | int ret; |
421cb601 | 559 | |
5b4a0ec0 DG |
560 | ret = ustctl_create_stream(app->key.sock, ua_sess->metadata->obj, |
561 | &ua_sess->metadata->stream_obj); | |
562 | if (ret < 0) { | |
563 | ERR("UST create metadata stream failed"); | |
421cb601 | 564 | goto error; |
91d76f53 | 565 | } |
421cb601 | 566 | |
421cb601 | 567 | error: |
5b4a0ec0 | 568 | return ret; |
91d76f53 DG |
569 | } |
570 | ||
b551a063 | 571 | /* |
5b4a0ec0 | 572 | * Create the specified channel onto the UST tracer for a UST session. |
b551a063 | 573 | */ |
5b4a0ec0 DG |
574 | static int create_ust_channel(struct ust_app *app, |
575 | struct ust_app_session *ua_sess, struct ust_app_channel *ua_chan) | |
b551a063 | 576 | { |
5b4a0ec0 | 577 | int ret; |
b551a063 | 578 | |
5b4a0ec0 DG |
579 | /* TODO: remove cast and use lttng-ust-abi.h */ |
580 | ret = ustctl_create_channel(app->key.sock, ua_sess->handle, | |
581 | (struct lttng_ust_channel_attr *)&ua_chan->attr, &ua_chan->obj); | |
582 | if (ret < 0) { | |
58f3ca76 | 583 | ERR("Creating channel %s for app (pid: %d, sock: %d) " |
5b4a0ec0 DG |
584 | "and session handle %d with ret %d", |
585 | ua_chan->name, app->key.pid, app->key.sock, | |
586 | ua_sess->handle, ret); | |
b551a063 DG |
587 | goto error; |
588 | } | |
589 | ||
5b4a0ec0 | 590 | ua_chan->handle = ua_chan->obj->handle; |
b551a063 | 591 | |
5b4a0ec0 DG |
592 | DBG2("UST app channel %s created successfully for pid:%d and sock:%d", |
593 | ua_chan->name, app->key.pid, app->key.sock); | |
b551a063 | 594 | |
8535a6d9 DG |
595 | /* If channel is not enabled, disable it on the tracer */ |
596 | if (!ua_chan->enabled) { | |
597 | ret = disable_ust_channel(app, ua_sess, ua_chan); | |
598 | if (ret < 0) { | |
599 | goto error; | |
600 | } | |
601 | } | |
602 | ||
b551a063 DG |
603 | error: |
604 | return ret; | |
605 | } | |
606 | ||
91d76f53 | 607 | /* |
5b4a0ec0 | 608 | * Create the specified event onto the UST tracer for a UST session. |
91d76f53 | 609 | */ |
edb67388 DG |
610 | static |
611 | int create_ust_event(struct ust_app *app, struct ust_app_session *ua_sess, | |
612 | struct ust_app_channel *ua_chan, struct ust_app_event *ua_event) | |
91d76f53 | 613 | { |
5b4a0ec0 | 614 | int ret = 0; |
284d8f55 | 615 | |
5b4a0ec0 DG |
616 | /* Create UST event on tracer */ |
617 | ret = ustctl_create_event(app->key.sock, &ua_event->attr, ua_chan->obj, | |
618 | &ua_event->obj); | |
619 | if (ret < 0) { | |
fc34caaa DG |
620 | if (ret == -EEXIST) { |
621 | ret = 0; | |
622 | goto error; | |
623 | } | |
5b4a0ec0 DG |
624 | ERR("Error ustctl create event %s for app pid: %d with ret %d", |
625 | ua_event->attr.name, app->key.pid, ret); | |
626 | goto error; | |
91d76f53 | 627 | } |
f6a9efaa | 628 | |
5b4a0ec0 | 629 | ua_event->handle = ua_event->obj->handle; |
284d8f55 | 630 | |
5b4a0ec0 DG |
631 | DBG2("UST app event %s created successfully for pid:%d", |
632 | ua_event->attr.name, app->key.pid); | |
f6a9efaa | 633 | |
8535a6d9 | 634 | /* If event not enabled, disable it on the tracer */ |
fc34caaa | 635 | if (ua_event->enabled == 0) { |
8535a6d9 DG |
636 | ret = disable_ust_event(app, ua_sess, ua_event); |
637 | if (ret < 0) { | |
fc34caaa DG |
638 | /* |
639 | * If we hit an EPERM, something is wrong with our disable call. If | |
640 | * we get an EEXIST, there is a problem on the tracer side since we | |
641 | * just created it. | |
642 | */ | |
643 | switch (ret) { | |
644 | case -EPERM: | |
645 | /* Code flow problem */ | |
646 | assert(0); | |
647 | case -EEXIST: | |
648 | /* It's OK for our use case. */ | |
649 | ret = 0; | |
650 | break; | |
651 | default: | |
652 | break; | |
653 | } | |
8535a6d9 DG |
654 | goto error; |
655 | } | |
656 | } | |
657 | ||
5b4a0ec0 DG |
658 | error: |
659 | return ret; | |
91d76f53 | 660 | } |
48842b30 | 661 | |
5b4a0ec0 DG |
662 | /* |
663 | * Copy data between an UST app event and a LTT event. | |
664 | */ | |
421cb601 | 665 | static void shadow_copy_event(struct ust_app_event *ua_event, |
48842b30 DG |
666 | struct ltt_ust_event *uevent) |
667 | { | |
bec39940 | 668 | struct lttng_ht_iter iter; |
55cc08a6 DG |
669 | struct ltt_ust_context *uctx; |
670 | struct ust_app_ctx *ua_ctx; | |
671 | ||
48842b30 DG |
672 | strncpy(ua_event->name, uevent->attr.name, sizeof(ua_event->name)); |
673 | ua_event->name[sizeof(ua_event->name) - 1] = '\0'; | |
674 | ||
fc34caaa DG |
675 | ua_event->enabled = uevent->enabled; |
676 | ||
5b4a0ec0 DG |
677 | /* Copy event attributes */ |
678 | memcpy(&ua_event->attr, &uevent->attr, sizeof(ua_event->attr)); | |
679 | ||
bec39940 | 680 | cds_lfht_for_each_entry(uevent->ctx->ht, &iter.iter, uctx, node.node) { |
55cc08a6 DG |
681 | ua_ctx = alloc_ust_app_ctx(&uctx->ctx); |
682 | if (ua_ctx == NULL) { | |
fc34caaa DG |
683 | /* malloc() failed. We should simply stop */ |
684 | return; | |
55cc08a6 | 685 | } |
fc34caaa | 686 | |
bec39940 DG |
687 | lttng_ht_node_init_ulong(&ua_ctx->node, |
688 | (unsigned long) ua_ctx->ctx.ctx); | |
689 | lttng_ht_add_unique_ulong(ua_event->ctx, &ua_ctx->node); | |
55cc08a6 | 690 | } |
48842b30 DG |
691 | } |
692 | ||
5b4a0ec0 DG |
693 | /* |
694 | * Copy data between an UST app channel and a LTT channel. | |
695 | */ | |
421cb601 | 696 | static void shadow_copy_channel(struct ust_app_channel *ua_chan, |
48842b30 DG |
697 | struct ltt_ust_channel *uchan) |
698 | { | |
bec39940 DG |
699 | struct lttng_ht_iter iter; |
700 | struct lttng_ht_node_str *ua_event_node; | |
48842b30 | 701 | struct ltt_ust_event *uevent; |
55cc08a6 | 702 | struct ltt_ust_context *uctx; |
48842b30 | 703 | struct ust_app_event *ua_event; |
55cc08a6 | 704 | struct ust_app_ctx *ua_ctx; |
48842b30 | 705 | |
fc34caaa | 706 | DBG2("UST app shadow copy of channel %s started", ua_chan->name); |
48842b30 DG |
707 | |
708 | strncpy(ua_chan->name, uchan->name, sizeof(ua_chan->name)); | |
709 | ua_chan->name[sizeof(ua_chan->name) - 1] = '\0'; | |
5b4a0ec0 DG |
710 | /* Copy event attributes */ |
711 | memcpy(&ua_chan->attr, &uchan->attr, sizeof(ua_chan->attr)); | |
48842b30 | 712 | |
fc34caaa DG |
713 | ua_chan->enabled = uchan->enabled; |
714 | ||
bec39940 | 715 | cds_lfht_for_each_entry(uchan->ctx->ht, &iter.iter, uctx, node.node) { |
55cc08a6 DG |
716 | ua_ctx = alloc_ust_app_ctx(&uctx->ctx); |
717 | if (ua_ctx == NULL) { | |
718 | continue; | |
719 | } | |
bec39940 DG |
720 | lttng_ht_node_init_ulong(&ua_ctx->node, |
721 | (unsigned long) ua_ctx->ctx.ctx); | |
722 | lttng_ht_add_unique_ulong(ua_chan->ctx, &ua_ctx->node); | |
55cc08a6 | 723 | } |
48842b30 | 724 | |
421cb601 | 725 | /* Copy all events from ltt ust channel to ust app channel */ |
bec39940 DG |
726 | cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, node.node) { |
727 | struct lttng_ht_iter uiter; | |
ba767faf | 728 | |
bec39940 DG |
729 | lttng_ht_lookup(ua_chan->events, (void *) uevent->attr.name, &uiter); |
730 | ua_event_node = lttng_ht_iter_get_node_str(&uiter); | |
48842b30 | 731 | if (ua_event_node == NULL) { |
421cb601 | 732 | DBG2("UST event %s not found on shadow copy channel", |
48842b30 | 733 | uevent->attr.name); |
284d8f55 | 734 | ua_event = alloc_ust_app_event(uevent->attr.name, &uevent->attr); |
48842b30 | 735 | if (ua_event == NULL) { |
5b4a0ec0 | 736 | continue; |
48842b30 | 737 | } |
421cb601 | 738 | shadow_copy_event(ua_event, uevent); |
bec39940 | 739 | lttng_ht_add_unique_str(ua_chan->events, &ua_event->node); |
48842b30 | 740 | } |
48842b30 DG |
741 | } |
742 | ||
fc34caaa | 743 | DBG3("UST app shadow copy of channel %s done", ua_chan->name); |
48842b30 DG |
744 | } |
745 | ||
5b4a0ec0 DG |
746 | /* |
747 | * Copy data between a UST app session and a regular LTT session. | |
748 | */ | |
421cb601 | 749 | static void shadow_copy_session(struct ust_app_session *ua_sess, |
bec39940 | 750 | struct ltt_ust_session *usess, struct ust_app *app) |
48842b30 | 751 | { |
bec39940 DG |
752 | struct lttng_ht_node_str *ua_chan_node; |
753 | struct lttng_ht_iter iter; | |
48842b30 DG |
754 | struct ltt_ust_channel *uchan; |
755 | struct ust_app_channel *ua_chan; | |
477d7741 MD |
756 | time_t rawtime; |
757 | struct tm *timeinfo; | |
758 | char datetime[16]; | |
759 | int ret; | |
760 | ||
761 | /* Get date and time for unique app path */ | |
762 | time(&rawtime); | |
763 | timeinfo = localtime(&rawtime); | |
764 | strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo); | |
48842b30 | 765 | |
421cb601 | 766 | DBG2("Shadow copy of session handle %d", ua_sess->handle); |
48842b30 | 767 | |
a991f516 | 768 | ua_sess->id = usess->id; |
6df2e2c9 MD |
769 | ua_sess->uid = usess->uid; |
770 | ua_sess->gid = usess->gid; | |
48842b30 | 771 | |
fc34caaa DG |
772 | ret = snprintf(ua_sess->path, PATH_MAX, "%s/%s-%d-%s", usess->pathname, |
773 | app->name, app->key.pid, datetime); | |
477d7741 MD |
774 | if (ret < 0) { |
775 | PERROR("asprintf UST shadow copy session"); | |
776 | /* TODO: We cannot return an error from here.. */ | |
777 | assert(0); | |
778 | } | |
779 | ||
48842b30 DG |
780 | /* TODO: support all UST domain */ |
781 | ||
782 | /* Iterate over all channels in global domain. */ | |
bec39940 DG |
783 | cds_lfht_for_each_entry(usess->domain_global.channels->ht, &iter.iter, |
784 | uchan, node.node) { | |
785 | struct lttng_ht_iter uiter; | |
ba767faf | 786 | |
bec39940 DG |
787 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &uiter); |
788 | ua_chan_node = lttng_ht_iter_get_node_str(&uiter); | |
5b4a0ec0 | 789 | if (ua_chan_node != NULL) { |
fc34caaa | 790 | /* Session exist. Contiuing. */ |
5b4a0ec0 DG |
791 | continue; |
792 | } | |
421cb601 | 793 | |
5b4a0ec0 DG |
794 | DBG2("Channel %s not found on shadow session copy, creating it", |
795 | uchan->name); | |
796 | ua_chan = alloc_ust_app_channel(uchan->name, &uchan->attr); | |
797 | if (ua_chan == NULL) { | |
fc34caaa | 798 | /* malloc failed FIXME: Might want to do handle ENOMEM .. */ |
5b4a0ec0 | 799 | continue; |
48842b30 DG |
800 | } |
801 | ||
5b4a0ec0 | 802 | shadow_copy_channel(ua_chan, uchan); |
bec39940 | 803 | lttng_ht_add_unique_str(ua_sess->channels, &ua_chan->node); |
48842b30 DG |
804 | } |
805 | } | |
806 | ||
78f0bacd DG |
807 | /* |
808 | * Lookup sesison wrapper. | |
809 | */ | |
84cd17c6 MD |
810 | static |
811 | void __lookup_session_by_app(struct ltt_ust_session *usess, | |
bec39940 | 812 | struct ust_app *app, struct lttng_ht_iter *iter) |
84cd17c6 MD |
813 | { |
814 | /* Get right UST app session from app */ | |
2c348c10 | 815 | lttng_ht_lookup(app->sessions, (void *)((unsigned long) usess->id), iter); |
84cd17c6 MD |
816 | } |
817 | ||
421cb601 DG |
818 | /* |
819 | * Return ust app session from the app session hashtable using the UST session | |
a991f516 | 820 | * id. |
421cb601 | 821 | */ |
48842b30 DG |
822 | static struct ust_app_session *lookup_session_by_app( |
823 | struct ltt_ust_session *usess, struct ust_app *app) | |
824 | { | |
bec39940 DG |
825 | struct lttng_ht_iter iter; |
826 | struct lttng_ht_node_ulong *node; | |
48842b30 | 827 | |
84cd17c6 | 828 | __lookup_session_by_app(usess, app, &iter); |
bec39940 | 829 | node = lttng_ht_iter_get_node_ulong(&iter); |
48842b30 DG |
830 | if (node == NULL) { |
831 | goto error; | |
832 | } | |
833 | ||
834 | return caa_container_of(node, struct ust_app_session, node); | |
835 | ||
836 | error: | |
837 | return NULL; | |
838 | } | |
839 | ||
421cb601 DG |
840 | /* |
841 | * Create a UST session onto the tracer of app and add it the session | |
842 | * hashtable. | |
843 | * | |
844 | * Return ust app session or NULL on error. | |
845 | */ | |
846 | static struct ust_app_session *create_ust_app_session( | |
847 | struct ltt_ust_session *usess, struct ust_app *app) | |
848 | { | |
849 | int ret; | |
850 | struct ust_app_session *ua_sess; | |
851 | ||
852 | ua_sess = lookup_session_by_app(usess, app); | |
853 | if (ua_sess == NULL) { | |
a991f516 MD |
854 | DBG2("UST app pid: %d session id %d not found, creating it", |
855 | app->key.pid, usess->id); | |
421cb601 DG |
856 | ua_sess = alloc_ust_app_session(); |
857 | if (ua_sess == NULL) { | |
858 | /* Only malloc can failed so something is really wrong */ | |
fc34caaa | 859 | goto end; |
421cb601 | 860 | } |
477d7741 | 861 | shadow_copy_session(ua_sess, usess, app); |
421cb601 DG |
862 | } |
863 | ||
864 | if (ua_sess->handle == -1) { | |
865 | ret = ustctl_create_session(app->key.sock); | |
866 | if (ret < 0) { | |
fc34caaa | 867 | ERR("Creating session for app pid %d", app->key.pid); |
915d047c DG |
868 | /* This means that the tracer is gone... */ |
869 | ua_sess = (void*) -1UL; | |
421cb601 DG |
870 | goto error; |
871 | } | |
872 | ||
421cb601 DG |
873 | ua_sess->handle = ret; |
874 | ||
875 | /* Add ust app session to app's HT */ | |
2c348c10 | 876 | lttng_ht_node_init_ulong(&ua_sess->node, (unsigned long) ua_sess->id); |
bec39940 | 877 | lttng_ht_add_unique_ulong(app->sessions, &ua_sess->node); |
421cb601 DG |
878 | |
879 | DBG2("UST app session created successfully with handle %d", ret); | |
880 | } | |
881 | ||
fc34caaa | 882 | end: |
421cb601 DG |
883 | return ua_sess; |
884 | ||
885 | error: | |
fc34caaa | 886 | delete_ust_app_session(-1, ua_sess); |
421cb601 DG |
887 | return NULL; |
888 | } | |
889 | ||
55cc08a6 DG |
890 | /* |
891 | * Create a context for the channel on the tracer. | |
892 | */ | |
893 | static | |
894 | int create_ust_app_channel_context(struct ust_app_session *ua_sess, | |
895 | struct ust_app_channel *ua_chan, struct lttng_ust_context *uctx, | |
896 | struct ust_app *app) | |
897 | { | |
898 | int ret = 0; | |
bec39940 DG |
899 | struct lttng_ht_iter iter; |
900 | struct lttng_ht_node_ulong *node; | |
55cc08a6 DG |
901 | struct ust_app_ctx *ua_ctx; |
902 | ||
903 | DBG2("UST app adding context to channel %s", ua_chan->name); | |
904 | ||
bec39940 DG |
905 | lttng_ht_lookup(ua_chan->ctx, (void *)((unsigned long)uctx->ctx), &iter); |
906 | node = lttng_ht_iter_get_node_ulong(&iter); | |
55cc08a6 DG |
907 | if (node != NULL) { |
908 | ret = -EEXIST; | |
909 | goto error; | |
910 | } | |
911 | ||
912 | ua_ctx = alloc_ust_app_ctx(uctx); | |
913 | if (ua_ctx == NULL) { | |
914 | /* malloc failed */ | |
915 | ret = -1; | |
916 | goto error; | |
917 | } | |
918 | ||
bec39940 DG |
919 | lttng_ht_node_init_ulong(&ua_ctx->node, (unsigned long) ua_ctx->ctx.ctx); |
920 | lttng_ht_add_unique_ulong(ua_chan->ctx, &ua_ctx->node); | |
55cc08a6 DG |
921 | |
922 | ret = create_ust_channel_context(ua_chan, ua_ctx, app); | |
923 | if (ret < 0) { | |
924 | goto error; | |
925 | } | |
926 | ||
927 | error: | |
928 | return ret; | |
929 | } | |
930 | ||
931 | /* | |
932 | * Create an UST context and enable it for the event on the tracer. | |
933 | */ | |
934 | static | |
935 | int create_ust_app_event_context(struct ust_app_session *ua_sess, | |
936 | struct ust_app_event *ua_event, struct lttng_ust_context *uctx, | |
937 | struct ust_app *app) | |
938 | { | |
939 | int ret = 0; | |
bec39940 DG |
940 | struct lttng_ht_iter iter; |
941 | struct lttng_ht_node_ulong *node; | |
55cc08a6 DG |
942 | struct ust_app_ctx *ua_ctx; |
943 | ||
944 | DBG2("UST app adding context to event %s", ua_event->name); | |
945 | ||
bec39940 DG |
946 | lttng_ht_lookup(ua_event->ctx, (void *)((unsigned long)uctx->ctx), &iter); |
947 | node = lttng_ht_iter_get_node_ulong(&iter); | |
55cc08a6 DG |
948 | if (node != NULL) { |
949 | ret = -EEXIST; | |
950 | goto error; | |
951 | } | |
952 | ||
953 | ua_ctx = alloc_ust_app_ctx(uctx); | |
954 | if (ua_ctx == NULL) { | |
955 | /* malloc failed */ | |
956 | ret = -1; | |
957 | goto error; | |
958 | } | |
959 | ||
bec39940 DG |
960 | lttng_ht_node_init_ulong(&ua_ctx->node, (unsigned long) ua_ctx->ctx.ctx); |
961 | lttng_ht_add_unique_ulong(ua_event->ctx, &ua_ctx->node); | |
55cc08a6 DG |
962 | |
963 | ret = create_ust_event_context(ua_event, ua_ctx, app); | |
964 | if (ret < 0) { | |
965 | goto error; | |
966 | } | |
967 | ||
968 | error: | |
969 | return ret; | |
970 | } | |
971 | ||
edb67388 DG |
972 | /* |
973 | * Enable on the tracer side a ust app event for the session and channel. | |
974 | */ | |
975 | static | |
976 | int enable_ust_app_event(struct ust_app_session *ua_sess, | |
35a9059d | 977 | struct ust_app_event *ua_event, struct ust_app *app) |
edb67388 DG |
978 | { |
979 | int ret; | |
980 | ||
981 | ret = enable_ust_event(app, ua_sess, ua_event); | |
982 | if (ret < 0) { | |
983 | goto error; | |
984 | } | |
985 | ||
986 | ua_event->enabled = 1; | |
987 | ||
988 | error: | |
989 | return ret; | |
990 | } | |
991 | ||
9730260e DG |
992 | /* |
993 | * Disable on the tracer side a ust app event for the session and channel. | |
994 | */ | |
995 | static int disable_ust_app_event(struct ust_app_session *ua_sess, | |
7f79d3a1 | 996 | struct ust_app_event *ua_event, struct ust_app *app) |
9730260e DG |
997 | { |
998 | int ret; | |
999 | ||
1000 | ret = disable_ust_event(app, ua_sess, ua_event); | |
1001 | if (ret < 0) { | |
1002 | goto error; | |
1003 | } | |
1004 | ||
1005 | ua_event->enabled = 0; | |
1006 | ||
1007 | error: | |
1008 | return ret; | |
1009 | } | |
1010 | ||
78f0bacd DG |
1011 | /* |
1012 | * Lookup ust app channel for session and disable it on the tracer side. | |
1013 | */ | |
8535a6d9 DG |
1014 | static |
1015 | int disable_ust_app_channel(struct ust_app_session *ua_sess, | |
1016 | struct ust_app_channel *ua_chan, struct ust_app *app) | |
78f0bacd | 1017 | { |
8535a6d9 | 1018 | int ret; |
78f0bacd DG |
1019 | |
1020 | ret = disable_ust_channel(app, ua_sess, ua_chan); | |
1021 | if (ret < 0) { | |
1022 | goto error; | |
1023 | } | |
1024 | ||
8535a6d9 DG |
1025 | ua_chan->enabled = 0; |
1026 | ||
78f0bacd DG |
1027 | error: |
1028 | return ret; | |
1029 | } | |
1030 | ||
1031 | /* | |
1032 | * Lookup ust app channel for session and enable it on the tracer side. | |
1033 | */ | |
1034 | static int enable_ust_app_channel(struct ust_app_session *ua_sess, | |
1035 | struct ltt_ust_channel *uchan, struct ust_app *app) | |
1036 | { | |
1037 | int ret = 0; | |
bec39940 DG |
1038 | struct lttng_ht_iter iter; |
1039 | struct lttng_ht_node_str *ua_chan_node; | |
78f0bacd DG |
1040 | struct ust_app_channel *ua_chan; |
1041 | ||
bec39940 DG |
1042 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &iter); |
1043 | ua_chan_node = lttng_ht_iter_get_node_str(&iter); | |
78f0bacd | 1044 | if (ua_chan_node == NULL) { |
a991f516 MD |
1045 | DBG2("Unable to find channel %s in ust session id %u", |
1046 | uchan->name, ua_sess->id); | |
78f0bacd DG |
1047 | goto error; |
1048 | } | |
1049 | ||
1050 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); | |
1051 | ||
1052 | ret = enable_ust_channel(app, ua_sess, ua_chan); | |
1053 | if (ret < 0) { | |
1054 | goto error; | |
1055 | } | |
1056 | ||
1057 | error: | |
1058 | return ret; | |
1059 | } | |
1060 | ||
284d8f55 | 1061 | /* |
5b4a0ec0 | 1062 | * Create UST app channel and create it on the tracer. |
284d8f55 | 1063 | */ |
5b4a0ec0 DG |
1064 | static struct ust_app_channel *create_ust_app_channel( |
1065 | struct ust_app_session *ua_sess, struct ltt_ust_channel *uchan, | |
1066 | struct ust_app *app) | |
1067 | { | |
1068 | int ret = 0; | |
bec39940 DG |
1069 | struct lttng_ht_iter iter; |
1070 | struct lttng_ht_node_str *ua_chan_node; | |
5b4a0ec0 DG |
1071 | struct ust_app_channel *ua_chan; |
1072 | ||
1073 | /* Lookup channel in the ust app session */ | |
bec39940 DG |
1074 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &iter); |
1075 | ua_chan_node = lttng_ht_iter_get_node_str(&iter); | |
fc34caaa | 1076 | if (ua_chan_node != NULL) { |
5b4a0ec0 | 1077 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); |
fc34caaa | 1078 | goto end; |
5b4a0ec0 DG |
1079 | } |
1080 | ||
fc34caaa DG |
1081 | ua_chan = alloc_ust_app_channel(uchan->name, &uchan->attr); |
1082 | if (ua_chan == NULL) { | |
1083 | /* Only malloc can fail here */ | |
1084 | goto error; | |
1085 | } | |
1086 | shadow_copy_channel(ua_chan, uchan); | |
1087 | ||
5b4a0ec0 DG |
1088 | ret = create_ust_channel(app, ua_sess, ua_chan); |
1089 | if (ret < 0) { | |
fc34caaa DG |
1090 | /* Not found previously means that it does not exist on the tracer */ |
1091 | assert(ret != -EEXIST); | |
5b4a0ec0 DG |
1092 | goto error; |
1093 | } | |
1094 | ||
58f3ca76 DG |
1095 | lttng_ht_add_unique_str(ua_sess->channels, &ua_chan->node); |
1096 | ||
fc34caaa DG |
1097 | DBG2("UST app create channel %s for PID %d completed", ua_chan->name, |
1098 | app->key.pid); | |
1099 | ||
1100 | end: | |
5b4a0ec0 DG |
1101 | return ua_chan; |
1102 | ||
1103 | error: | |
fc34caaa | 1104 | delete_ust_app_channel(-1, ua_chan); |
5b4a0ec0 DG |
1105 | return NULL; |
1106 | } | |
1107 | ||
1108 | /* | |
1109 | * Create UST app event and create it on the tracer side. | |
1110 | */ | |
edb67388 DG |
1111 | static |
1112 | int create_ust_app_event(struct ust_app_session *ua_sess, | |
1113 | struct ust_app_channel *ua_chan, struct ltt_ust_event *uevent, | |
1114 | struct ust_app *app) | |
284d8f55 | 1115 | { |
edb67388 | 1116 | int ret = 0; |
bec39940 DG |
1117 | struct lttng_ht_iter iter; |
1118 | struct lttng_ht_node_str *ua_event_node; | |
5b4a0ec0 | 1119 | struct ust_app_event *ua_event; |
284d8f55 | 1120 | |
5b4a0ec0 | 1121 | /* Get event node */ |
bec39940 DG |
1122 | lttng_ht_lookup(ua_chan->events, (void *)uevent->attr.name, &iter); |
1123 | ua_event_node = lttng_ht_iter_get_node_str(&iter); | |
edb67388 | 1124 | if (ua_event_node != NULL) { |
fc34caaa | 1125 | ret = -EEXIST; |
edb67388 DG |
1126 | goto end; |
1127 | } | |
5b4a0ec0 | 1128 | |
edb67388 DG |
1129 | /* Does not exist so create one */ |
1130 | ua_event = alloc_ust_app_event(uevent->attr.name, &uevent->attr); | |
1131 | if (ua_event == NULL) { | |
1132 | /* Only malloc can failed so something is really wrong */ | |
1133 | ret = -ENOMEM; | |
fc34caaa | 1134 | goto end; |
5b4a0ec0 | 1135 | } |
edb67388 | 1136 | shadow_copy_event(ua_event, uevent); |
5b4a0ec0 | 1137 | |
edb67388 | 1138 | /* Create it on the tracer side */ |
5b4a0ec0 | 1139 | ret = create_ust_event(app, ua_sess, ua_chan, ua_event); |
284d8f55 | 1140 | if (ret < 0) { |
fc34caaa DG |
1141 | /* Not found previously means that it does not exist on the tracer */ |
1142 | assert(ret != -EEXIST); | |
284d8f55 DG |
1143 | goto error; |
1144 | } | |
1145 | ||
bec39940 | 1146 | lttng_ht_add_unique_str(ua_chan->events, &ua_event->node); |
284d8f55 | 1147 | |
fc34caaa DG |
1148 | DBG2("UST app create event %s for PID %d completed", ua_event->name, |
1149 | app->key.pid); | |
7f79d3a1 | 1150 | |
edb67388 | 1151 | end: |
fc34caaa DG |
1152 | return ret; |
1153 | ||
5b4a0ec0 | 1154 | error: |
fc34caaa DG |
1155 | /* Valid. Calling here is already in a read side lock */ |
1156 | delete_ust_app_event(-1, ua_event); | |
edb67388 | 1157 | return ret; |
5b4a0ec0 DG |
1158 | } |
1159 | ||
1160 | /* | |
1161 | * Create UST metadata and open it on the tracer side. | |
1162 | */ | |
1163 | static int create_ust_app_metadata(struct ust_app_session *ua_sess, | |
1164 | char *pathname, struct ust_app *app) | |
1165 | { | |
1166 | int ret = 0; | |
1167 | ||
1168 | if (ua_sess->metadata == NULL) { | |
1169 | /* Allocate UST metadata */ | |
1170 | ua_sess->metadata = trace_ust_create_metadata(pathname); | |
1171 | if (ua_sess->metadata == NULL) { | |
fc34caaa | 1172 | /* malloc() failed */ |
5b4a0ec0 DG |
1173 | goto error; |
1174 | } | |
1175 | ||
1176 | ret = open_ust_metadata(app, ua_sess); | |
1177 | if (ret < 0) { | |
7db205b5 DG |
1178 | DBG3("Opening metadata failed. Cleaning up memory"); |
1179 | ||
fc34caaa DG |
1180 | /* Cleanup failed metadata struct */ |
1181 | free(ua_sess->metadata); | |
7db205b5 DG |
1182 | /* |
1183 | * This is very important because delete_ust_app_session check if | |
1184 | * the pointer is null or not in order to delete the metadata. | |
1185 | */ | |
1186 | ua_sess->metadata = NULL; | |
5b4a0ec0 DG |
1187 | goto error; |
1188 | } | |
1189 | ||
1190 | DBG2("UST metadata opened for app pid %d", app->key.pid); | |
1191 | } | |
1192 | ||
1193 | /* Open UST metadata stream */ | |
1194 | if (ua_sess->metadata->stream_obj == NULL) { | |
1195 | ret = create_ust_stream(app, ua_sess); | |
1196 | if (ret < 0) { | |
1197 | goto error; | |
1198 | } | |
1199 | ||
e11d277b | 1200 | ret = run_as_mkdir(ua_sess->path, S_IRWXU | S_IRWXG, |
67f747d8 | 1201 | ua_sess->uid, ua_sess->gid); |
5b4a0ec0 DG |
1202 | if (ret < 0) { |
1203 | PERROR("mkdir UST metadata"); | |
1204 | goto error; | |
1205 | } | |
1206 | ||
477d7741 MD |
1207 | ret = snprintf(ua_sess->metadata->pathname, PATH_MAX, |
1208 | "%s/metadata", ua_sess->path); | |
5b4a0ec0 DG |
1209 | if (ret < 0) { |
1210 | PERROR("asprintf UST create stream"); | |
1211 | goto error; | |
1212 | } | |
1213 | ||
1214 | DBG2("UST metadata stream object created for app pid %d", | |
1215 | app->key.pid); | |
1216 | } else { | |
1217 | ERR("Attempting to create stream without metadata opened"); | |
1218 | goto error; | |
1219 | } | |
1220 | ||
1221 | return 0; | |
1222 | ||
1223 | error: | |
1224 | return -1; | |
1225 | } | |
1226 | ||
1227 | /* | |
1228 | * Return pointer to traceable apps list. | |
1229 | */ | |
bec39940 | 1230 | struct lttng_ht *ust_app_get_ht(void) |
5b4a0ec0 DG |
1231 | { |
1232 | return ust_app_ht; | |
1233 | } | |
1234 | ||
1235 | /* | |
1236 | * Return ust app pointer or NULL if not found. | |
1237 | */ | |
1238 | struct ust_app *ust_app_find_by_pid(pid_t pid) | |
1239 | { | |
bec39940 DG |
1240 | struct lttng_ht_node_ulong *node; |
1241 | struct lttng_ht_iter iter; | |
5b4a0ec0 DG |
1242 | |
1243 | rcu_read_lock(); | |
bec39940 DG |
1244 | lttng_ht_lookup(ust_app_ht, (void *)((unsigned long) pid), &iter); |
1245 | node = lttng_ht_iter_get_node_ulong(&iter); | |
5b4a0ec0 DG |
1246 | if (node == NULL) { |
1247 | DBG2("UST app no found with pid %d", pid); | |
1248 | goto error; | |
1249 | } | |
1250 | rcu_read_unlock(); | |
1251 | ||
1252 | DBG2("Found UST app by pid %d", pid); | |
1253 | ||
1254 | return caa_container_of(node, struct ust_app, node); | |
1255 | ||
1256 | error: | |
1257 | rcu_read_unlock(); | |
1258 | return NULL; | |
1259 | } | |
1260 | ||
1261 | /* | |
1262 | * Using pid and uid (of the app), allocate a new ust_app struct and | |
1263 | * add it to the global traceable app list. | |
1264 | * | |
0df502fd MD |
1265 | * On success, return 0, else return malloc -ENOMEM, or -EINVAL if app |
1266 | * bitness is not supported. | |
5b4a0ec0 DG |
1267 | */ |
1268 | int ust_app_register(struct ust_register_msg *msg, int sock) | |
1269 | { | |
1270 | struct ust_app *lta; | |
1271 | ||
7753dea8 MD |
1272 | if ((msg->bits_per_long == 64 && ust_consumerd64_fd == -EINVAL) |
1273 | || (msg->bits_per_long == 32 && ust_consumerd32_fd == -EINVAL)) { | |
f943b0fb | 1274 | ERR("Registration failed: application \"%s\" (pid: %d) has " |
7753dea8 MD |
1275 | "%d-bit long, but no consumerd for this long size is available.\n", |
1276 | msg->name, msg->pid, msg->bits_per_long); | |
88ff5b7f | 1277 | close(sock); |
0df502fd MD |
1278 | return -EINVAL; |
1279 | } | |
3f2c5fcc MD |
1280 | if (msg->major != LTTNG_UST_COMM_MAJOR) { |
1281 | ERR("Registration failed: application \"%s\" (pid: %d) has " | |
1282 | "communication protocol version %u.%u, but sessiond supports 2.x.\n", | |
1283 | msg->name, msg->pid, msg->major, msg->minor); | |
1284 | close(sock); | |
1285 | return -EINVAL; | |
1286 | } | |
5b4a0ec0 DG |
1287 | lta = zmalloc(sizeof(struct ust_app)); |
1288 | if (lta == NULL) { | |
1289 | PERROR("malloc"); | |
1290 | return -ENOMEM; | |
1291 | } | |
1292 | ||
1293 | lta->ppid = msg->ppid; | |
1294 | lta->uid = msg->uid; | |
1295 | lta->gid = msg->gid; | |
e0c7ec2b | 1296 | lta->compatible = 0; /* Not compatible until proven */ |
7753dea8 | 1297 | lta->bits_per_long = msg->bits_per_long; |
5b4a0ec0 DG |
1298 | lta->v_major = msg->major; |
1299 | lta->v_minor = msg->minor; | |
1300 | strncpy(lta->name, msg->name, sizeof(lta->name)); | |
1301 | lta->name[16] = '\0'; | |
bec39940 | 1302 | lta->sessions = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); |
5b4a0ec0 DG |
1303 | |
1304 | /* Set key map */ | |
1305 | lta->key.pid = msg->pid; | |
bec39940 | 1306 | lttng_ht_node_init_ulong(<a->node, (unsigned long)lta->key.pid); |
5b4a0ec0 | 1307 | lta->key.sock = sock; |
bec39940 | 1308 | lttng_ht_node_init_ulong(<a->key.node, (unsigned long)lta->key.sock); |
5b4a0ec0 DG |
1309 | |
1310 | rcu_read_lock(); | |
bec39940 DG |
1311 | lttng_ht_add_unique_ulong(ust_app_sock_key_map, <a->key.node); |
1312 | lttng_ht_add_unique_ulong(ust_app_ht, <a->node); | |
5b4a0ec0 DG |
1313 | rcu_read_unlock(); |
1314 | ||
1315 | DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s" | |
1316 | " (version %d.%d)", lta->key.pid, lta->ppid, lta->uid, lta->gid, | |
1317 | lta->key.sock, lta->name, lta->v_major, lta->v_minor); | |
1318 | ||
1319 | return 0; | |
1320 | } | |
1321 | ||
1322 | /* | |
1323 | * Unregister app by removing it from the global traceable app list and freeing | |
1324 | * the data struct. | |
1325 | * | |
1326 | * The socket is already closed at this point so no close to sock. | |
1327 | */ | |
1328 | void ust_app_unregister(int sock) | |
1329 | { | |
1330 | struct ust_app *lta; | |
bec39940 DG |
1331 | struct lttng_ht_node_ulong *node; |
1332 | struct lttng_ht_iter iter; | |
525b0740 | 1333 | int ret; |
5b4a0ec0 DG |
1334 | |
1335 | rcu_read_lock(); | |
1336 | lta = find_app_by_sock(sock); | |
1337 | if (lta == NULL) { | |
1338 | ERR("Unregister app sock %d not found!", sock); | |
1339 | goto error; | |
1340 | } | |
1341 | ||
1342 | DBG("PID %d unregistering with sock %d", lta->key.pid, sock); | |
1343 | ||
886459c6 MD |
1344 | /* Remove application from socket hash table */ |
1345 | lttng_ht_lookup(ust_app_sock_key_map, (void *)((unsigned long) sock), &iter); | |
1346 | ret = lttng_ht_del(ust_app_sock_key_map, &iter); | |
1347 | assert(!ret); | |
1348 | ||
5b4a0ec0 | 1349 | /* Get the node reference for a call_rcu */ |
bec39940 DG |
1350 | lttng_ht_lookup(ust_app_ht, (void *)((unsigned long) lta->key.pid), &iter); |
1351 | node = lttng_ht_iter_get_node_ulong(&iter); | |
5b4a0ec0 DG |
1352 | if (node == NULL) { |
1353 | ERR("Unable to find app sock %d by pid %d", sock, lta->key.pid); | |
1354 | goto error; | |
1355 | } | |
284d8f55 | 1356 | |
886459c6 | 1357 | /* Remove application from PID hash table */ |
bec39940 | 1358 | ret = lttng_ht_del(ust_app_ht, &iter); |
525b0740 | 1359 | assert(!ret); |
5b4a0ec0 | 1360 | call_rcu(&node->head, delete_ust_app_rcu); |
284d8f55 | 1361 | error: |
5b4a0ec0 DG |
1362 | rcu_read_unlock(); |
1363 | return; | |
284d8f55 DG |
1364 | } |
1365 | ||
1366 | /* | |
5b4a0ec0 | 1367 | * Return traceable_app_count |
284d8f55 | 1368 | */ |
5b4a0ec0 | 1369 | unsigned long ust_app_list_count(void) |
284d8f55 | 1370 | { |
5b4a0ec0 | 1371 | unsigned long count; |
284d8f55 | 1372 | |
5b4a0ec0 | 1373 | rcu_read_lock(); |
bec39940 | 1374 | count = lttng_ht_get_count(ust_app_ht); |
5b4a0ec0 | 1375 | rcu_read_unlock(); |
284d8f55 | 1376 | |
5b4a0ec0 | 1377 | return count; |
284d8f55 DG |
1378 | } |
1379 | ||
5b4a0ec0 DG |
1380 | /* |
1381 | * Fill events array with all events name of all registered apps. | |
1382 | */ | |
1383 | int ust_app_list_events(struct lttng_event **events) | |
421cb601 | 1384 | { |
5b4a0ec0 DG |
1385 | int ret, handle; |
1386 | size_t nbmem, count = 0; | |
bec39940 | 1387 | struct lttng_ht_iter iter; |
5b4a0ec0 DG |
1388 | struct ust_app *app; |
1389 | struct lttng_event *tmp; | |
421cb601 | 1390 | |
5b4a0ec0 DG |
1391 | nbmem = UST_APP_EVENT_LIST_SIZE; |
1392 | tmp = zmalloc(nbmem * sizeof(struct lttng_event)); | |
1393 | if (tmp == NULL) { | |
1394 | PERROR("zmalloc ust app events"); | |
1395 | ret = -ENOMEM; | |
421cb601 DG |
1396 | goto error; |
1397 | } | |
1398 | ||
5b4a0ec0 | 1399 | rcu_read_lock(); |
421cb601 | 1400 | |
bec39940 | 1401 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
90eaa0d2 | 1402 | struct lttng_ust_tracepoint_iter uiter; |
ac3bd9c0 | 1403 | |
e0c7ec2b DG |
1404 | if (!app->compatible) { |
1405 | /* | |
1406 | * TODO: In time, we should notice the caller of this error by | |
1407 | * telling him that this is a version error. | |
1408 | */ | |
1409 | continue; | |
1410 | } | |
5b4a0ec0 DG |
1411 | handle = ustctl_tracepoint_list(app->key.sock); |
1412 | if (handle < 0) { | |
1413 | ERR("UST app list events getting handle failed for app pid %d", | |
1414 | app->key.pid); | |
1415 | continue; | |
1416 | } | |
421cb601 | 1417 | |
5b4a0ec0 | 1418 | while ((ret = ustctl_tracepoint_list_get(app->key.sock, handle, |
90eaa0d2 | 1419 | &uiter)) != -ENOENT) { |
815564d8 MD |
1420 | if (count >= nbmem) { |
1421 | DBG2("Reallocating event list from %zu to %zu entries", nbmem, | |
1422 | 2 * nbmem); | |
1423 | nbmem *= 2; | |
2f221590 | 1424 | tmp = realloc(tmp, nbmem * sizeof(struct lttng_event)); |
5b4a0ec0 DG |
1425 | if (tmp == NULL) { |
1426 | PERROR("realloc ust app events"); | |
1427 | ret = -ENOMEM; | |
1428 | goto rcu_error; | |
1429 | } | |
1430 | } | |
90eaa0d2 | 1431 | memcpy(tmp[count].name, uiter.name, LTTNG_UST_SYM_NAME_LEN); |
8005f29a | 1432 | tmp[count].loglevel = uiter.loglevel; |
69892bbb | 1433 | tmp[count].type = LTTNG_UST_TRACEPOINT; |
5b4a0ec0 DG |
1434 | tmp[count].pid = app->key.pid; |
1435 | tmp[count].enabled = -1; | |
1436 | count++; | |
421cb601 | 1437 | } |
421cb601 DG |
1438 | } |
1439 | ||
5b4a0ec0 DG |
1440 | ret = count; |
1441 | *events = tmp; | |
421cb601 | 1442 | |
5b4a0ec0 | 1443 | DBG2("UST app list events done (%zu events)", count); |
421cb601 | 1444 | |
5b4a0ec0 DG |
1445 | rcu_error: |
1446 | rcu_read_unlock(); | |
421cb601 | 1447 | error: |
5b4a0ec0 | 1448 | return ret; |
421cb601 DG |
1449 | } |
1450 | ||
5b4a0ec0 DG |
1451 | /* |
1452 | * Free and clean all traceable apps of the global list. | |
1453 | */ | |
1454 | void ust_app_clean_list(void) | |
421cb601 | 1455 | { |
5b4a0ec0 | 1456 | int ret; |
bec39940 DG |
1457 | struct lttng_ht_iter iter; |
1458 | struct lttng_ht_node_ulong *node; | |
421cb601 | 1459 | |
5b4a0ec0 | 1460 | DBG2("UST app cleaning registered apps hash table"); |
421cb601 | 1461 | |
5b4a0ec0 | 1462 | rcu_read_lock(); |
421cb601 | 1463 | |
bec39940 DG |
1464 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, node, node) { |
1465 | ret = lttng_ht_del(ust_app_ht, &iter); | |
525b0740 | 1466 | assert(!ret); |
bec39940 | 1467 | call_rcu(&node->head, delete_ust_app_rcu); |
421cb601 | 1468 | } |
bec39940 DG |
1469 | /* Destroy is done only when the ht is empty */ |
1470 | lttng_ht_destroy(ust_app_ht); | |
421cb601 | 1471 | |
bec39940 DG |
1472 | cds_lfht_for_each_entry(ust_app_sock_key_map->ht, &iter.iter, node, node) { |
1473 | ret = lttng_ht_del(ust_app_sock_key_map, &iter); | |
1474 | assert(!ret); | |
1475 | } | |
1476 | /* Destroy is done only when the ht is empty */ | |
1477 | lttng_ht_destroy(ust_app_sock_key_map); | |
421cb601 | 1478 | |
5b4a0ec0 DG |
1479 | rcu_read_unlock(); |
1480 | } | |
1481 | ||
1482 | /* | |
1483 | * Init UST app hash table. | |
1484 | */ | |
1485 | void ust_app_ht_alloc(void) | |
1486 | { | |
bec39940 DG |
1487 | ust_app_ht = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); |
1488 | ust_app_sock_key_map = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); | |
421cb601 DG |
1489 | } |
1490 | ||
78f0bacd DG |
1491 | /* |
1492 | * For a specific UST session, disable the channel for all registered apps. | |
1493 | */ | |
35a9059d | 1494 | int ust_app_disable_channel_glb(struct ltt_ust_session *usess, |
78f0bacd DG |
1495 | struct ltt_ust_channel *uchan) |
1496 | { | |
1497 | int ret = 0; | |
bec39940 DG |
1498 | struct lttng_ht_iter iter; |
1499 | struct lttng_ht_node_str *ua_chan_node; | |
78f0bacd DG |
1500 | struct ust_app *app; |
1501 | struct ust_app_session *ua_sess; | |
8535a6d9 | 1502 | struct ust_app_channel *ua_chan; |
78f0bacd DG |
1503 | |
1504 | if (usess == NULL || uchan == NULL) { | |
1505 | ERR("Disabling UST global channel with NULL values"); | |
1506 | ret = -1; | |
1507 | goto error; | |
1508 | } | |
1509 | ||
a991f516 MD |
1510 | DBG2("UST app disabling channel %s from global domain for session id %d", |
1511 | uchan->name, usess->id); | |
78f0bacd DG |
1512 | |
1513 | rcu_read_lock(); | |
1514 | ||
1515 | /* For every registered applications */ | |
bec39940 DG |
1516 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
1517 | struct lttng_ht_iter uiter; | |
e0c7ec2b DG |
1518 | if (!app->compatible) { |
1519 | /* | |
1520 | * TODO: In time, we should notice the caller of this error by | |
1521 | * telling him that this is a version error. | |
1522 | */ | |
1523 | continue; | |
1524 | } | |
78f0bacd DG |
1525 | ua_sess = lookup_session_by_app(usess, app); |
1526 | if (ua_sess == NULL) { | |
1527 | continue; | |
1528 | } | |
1529 | ||
8535a6d9 | 1530 | /* Get channel */ |
bec39940 DG |
1531 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &uiter); |
1532 | ua_chan_node = lttng_ht_iter_get_node_str(&uiter); | |
8535a6d9 DG |
1533 | /* If the session if found for the app, the channel must be there */ |
1534 | assert(ua_chan_node); | |
1535 | ||
1536 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); | |
1537 | /* The channel must not be already disabled */ | |
1538 | assert(ua_chan->enabled == 1); | |
1539 | ||
1540 | /* Disable channel onto application */ | |
1541 | ret = disable_ust_app_channel(ua_sess, ua_chan, app); | |
78f0bacd DG |
1542 | if (ret < 0) { |
1543 | /* XXX: We might want to report this error at some point... */ | |
1544 | continue; | |
1545 | } | |
1546 | } | |
1547 | ||
1548 | rcu_read_unlock(); | |
1549 | ||
1550 | error: | |
1551 | return ret; | |
1552 | } | |
1553 | ||
1554 | /* | |
1555 | * For a specific UST session, enable the channel for all registered apps. | |
1556 | */ | |
35a9059d | 1557 | int ust_app_enable_channel_glb(struct ltt_ust_session *usess, |
78f0bacd DG |
1558 | struct ltt_ust_channel *uchan) |
1559 | { | |
1560 | int ret = 0; | |
bec39940 | 1561 | struct lttng_ht_iter iter; |
78f0bacd DG |
1562 | struct ust_app *app; |
1563 | struct ust_app_session *ua_sess; | |
1564 | ||
1565 | if (usess == NULL || uchan == NULL) { | |
1566 | ERR("Adding UST global channel to NULL values"); | |
1567 | ret = -1; | |
1568 | goto error; | |
1569 | } | |
1570 | ||
a991f516 MD |
1571 | DBG2("UST app enabling channel %s to global domain for session id %d", |
1572 | uchan->name, usess->id); | |
78f0bacd DG |
1573 | |
1574 | rcu_read_lock(); | |
1575 | ||
1576 | /* For every registered applications */ | |
bec39940 | 1577 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
e0c7ec2b DG |
1578 | if (!app->compatible) { |
1579 | /* | |
1580 | * TODO: In time, we should notice the caller of this error by | |
1581 | * telling him that this is a version error. | |
1582 | */ | |
1583 | continue; | |
1584 | } | |
78f0bacd DG |
1585 | ua_sess = lookup_session_by_app(usess, app); |
1586 | if (ua_sess == NULL) { | |
1587 | continue; | |
1588 | } | |
1589 | ||
1590 | /* Enable channel onto application */ | |
1591 | ret = enable_ust_app_channel(ua_sess, uchan, app); | |
1592 | if (ret < 0) { | |
1593 | /* XXX: We might want to report this error at some point... */ | |
1594 | continue; | |
1595 | } | |
1596 | } | |
1597 | ||
1598 | rcu_read_unlock(); | |
1599 | ||
1600 | error: | |
1601 | return ret; | |
1602 | } | |
1603 | ||
b0a40d28 DG |
1604 | /* |
1605 | * Disable an event in a channel and for a specific session. | |
1606 | */ | |
35a9059d DG |
1607 | int ust_app_disable_event_glb(struct ltt_ust_session *usess, |
1608 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent) | |
b0a40d28 DG |
1609 | { |
1610 | int ret = 0; | |
bec39940 DG |
1611 | struct lttng_ht_iter iter, uiter; |
1612 | struct lttng_ht_node_str *ua_chan_node, *ua_event_node; | |
b0a40d28 DG |
1613 | struct ust_app *app; |
1614 | struct ust_app_session *ua_sess; | |
1615 | struct ust_app_channel *ua_chan; | |
1616 | struct ust_app_event *ua_event; | |
1617 | ||
1618 | DBG("UST app disabling event %s for all apps in channel " | |
a991f516 | 1619 | "%s for session id %d", uevent->attr.name, uchan->name, usess->id); |
b0a40d28 DG |
1620 | |
1621 | rcu_read_lock(); | |
1622 | ||
1623 | /* For all registered applications */ | |
bec39940 | 1624 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
e0c7ec2b DG |
1625 | if (!app->compatible) { |
1626 | /* | |
1627 | * TODO: In time, we should notice the caller of this error by | |
1628 | * telling him that this is a version error. | |
1629 | */ | |
1630 | continue; | |
1631 | } | |
b0a40d28 DG |
1632 | ua_sess = lookup_session_by_app(usess, app); |
1633 | if (ua_sess == NULL) { | |
1634 | /* Next app */ | |
1635 | continue; | |
1636 | } | |
1637 | ||
1638 | /* Lookup channel in the ust app session */ | |
bec39940 DG |
1639 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &uiter); |
1640 | ua_chan_node = lttng_ht_iter_get_node_str(&uiter); | |
b0a40d28 | 1641 | if (ua_chan_node == NULL) { |
a991f516 MD |
1642 | DBG2("Channel %s not found in session id %d for app pid %d." |
1643 | "Skipping", uchan->name, usess->id, app->key.pid); | |
b0a40d28 DG |
1644 | continue; |
1645 | } | |
1646 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); | |
1647 | ||
bec39940 DG |
1648 | lttng_ht_lookup(ua_chan->events, (void *)uevent->attr.name, &uiter); |
1649 | ua_event_node = lttng_ht_iter_get_node_str(&uiter); | |
b0a40d28 DG |
1650 | if (ua_event_node == NULL) { |
1651 | DBG2("Event %s not found in channel %s for app pid %d." | |
35a9059d | 1652 | "Skipping", uevent->attr.name, uchan->name, app->key.pid); |
b0a40d28 DG |
1653 | continue; |
1654 | } | |
1655 | ua_event = caa_container_of(ua_event_node, struct ust_app_event, node); | |
1656 | ||
7f79d3a1 | 1657 | ret = disable_ust_app_event(ua_sess, ua_event, app); |
b0a40d28 DG |
1658 | if (ret < 0) { |
1659 | /* XXX: Report error someday... */ | |
1660 | continue; | |
1661 | } | |
1662 | } | |
1663 | ||
1664 | rcu_read_unlock(); | |
1665 | ||
1666 | return ret; | |
1667 | } | |
1668 | ||
9730260e | 1669 | /* |
edb67388 | 1670 | * For a specific UST session and UST channel, the event for all |
9730260e DG |
1671 | * registered apps. |
1672 | */ | |
35a9059d | 1673 | int ust_app_disable_all_event_glb(struct ltt_ust_session *usess, |
9730260e DG |
1674 | struct ltt_ust_channel *uchan) |
1675 | { | |
1676 | int ret = 0; | |
bec39940 DG |
1677 | struct lttng_ht_iter iter, uiter; |
1678 | struct lttng_ht_node_str *ua_chan_node; | |
9730260e DG |
1679 | struct ust_app *app; |
1680 | struct ust_app_session *ua_sess; | |
1681 | struct ust_app_channel *ua_chan; | |
1682 | struct ust_app_event *ua_event; | |
1683 | ||
1684 | DBG("UST app disabling all event for all apps in channel " | |
a991f516 | 1685 | "%s for session id %d", uchan->name, usess->id); |
9730260e DG |
1686 | |
1687 | rcu_read_lock(); | |
1688 | ||
1689 | /* For all registered applications */ | |
bec39940 | 1690 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
e0c7ec2b DG |
1691 | if (!app->compatible) { |
1692 | /* | |
1693 | * TODO: In time, we should notice the caller of this error by | |
1694 | * telling him that this is a version error. | |
1695 | */ | |
1696 | continue; | |
1697 | } | |
9730260e | 1698 | ua_sess = lookup_session_by_app(usess, app); |
edb67388 DG |
1699 | /* If ua_sess is NULL, there is a code flow error */ |
1700 | assert(ua_sess); | |
9730260e DG |
1701 | |
1702 | /* Lookup channel in the ust app session */ | |
bec39940 DG |
1703 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &uiter); |
1704 | ua_chan_node = lttng_ht_iter_get_node_str(&uiter); | |
edb67388 DG |
1705 | /* If the channel is not found, there is a code flow error */ |
1706 | assert(ua_chan_node); | |
1707 | ||
9730260e DG |
1708 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); |
1709 | ||
1710 | /* Disable each events of channel */ | |
bec39940 DG |
1711 | cds_lfht_for_each_entry(ua_chan->events->ht, &uiter.iter, ua_event, |
1712 | node.node) { | |
7f79d3a1 | 1713 | ret = disable_ust_app_event(ua_sess, ua_event, app); |
9730260e DG |
1714 | if (ret < 0) { |
1715 | /* XXX: Report error someday... */ | |
1716 | continue; | |
1717 | } | |
1718 | } | |
1719 | } | |
1720 | ||
1721 | rcu_read_unlock(); | |
1722 | ||
1723 | return ret; | |
1724 | } | |
1725 | ||
421cb601 | 1726 | /* |
5b4a0ec0 | 1727 | * For a specific UST session, create the channel for all registered apps. |
421cb601 | 1728 | */ |
35a9059d | 1729 | int ust_app_create_channel_glb(struct ltt_ust_session *usess, |
48842b30 DG |
1730 | struct ltt_ust_channel *uchan) |
1731 | { | |
bec39940 | 1732 | struct lttng_ht_iter iter; |
48842b30 DG |
1733 | struct ust_app *app; |
1734 | struct ust_app_session *ua_sess; | |
1735 | struct ust_app_channel *ua_chan; | |
1736 | ||
fc34caaa DG |
1737 | /* Very wrong code flow */ |
1738 | assert(usess); | |
1739 | assert(uchan); | |
421cb601 | 1740 | |
a991f516 MD |
1741 | DBG2("UST app adding channel %s to global domain for session id %d", |
1742 | uchan->name, usess->id); | |
48842b30 DG |
1743 | |
1744 | rcu_read_lock(); | |
421cb601 | 1745 | |
5b4a0ec0 | 1746 | /* For every registered applications */ |
bec39940 | 1747 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
e0c7ec2b DG |
1748 | if (!app->compatible) { |
1749 | /* | |
1750 | * TODO: In time, we should notice the caller of this error by | |
1751 | * telling him that this is a version error. | |
1752 | */ | |
1753 | continue; | |
1754 | } | |
edb67388 DG |
1755 | /* |
1756 | * Create session on the tracer side and add it to app session HT. Note | |
1757 | * that if session exist, it will simply return a pointer to the ust | |
1758 | * app session. | |
1759 | */ | |
421cb601 | 1760 | ua_sess = create_ust_app_session(usess, app); |
509cbaf8 | 1761 | if (ua_sess == NULL) { |
915d047c | 1762 | /* The malloc() failed. */ |
fc34caaa | 1763 | goto error; |
915d047c DG |
1764 | } else if (ua_sess == (void *) -1UL) { |
1765 | /* The application's socket is not valid. Contiuing */ | |
1766 | continue; | |
48842b30 DG |
1767 | } |
1768 | ||
421cb601 DG |
1769 | /* Create channel onto application */ |
1770 | ua_chan = create_ust_app_channel(ua_sess, uchan, app); | |
1771 | if (ua_chan == NULL) { | |
fc34caaa DG |
1772 | /* Major problem here and it's maybe the tracer or malloc() */ |
1773 | goto error; | |
48842b30 | 1774 | } |
48842b30 | 1775 | } |
5b4a0ec0 | 1776 | |
48842b30 DG |
1777 | rcu_read_unlock(); |
1778 | ||
fc34caaa DG |
1779 | return 0; |
1780 | ||
421cb601 | 1781 | error: |
fc34caaa | 1782 | return -1; |
48842b30 DG |
1783 | } |
1784 | ||
5b4a0ec0 | 1785 | /* |
edb67388 | 1786 | * Enable event for a specific session and channel on the tracer. |
5b4a0ec0 | 1787 | */ |
35a9059d | 1788 | int ust_app_enable_event_glb(struct ltt_ust_session *usess, |
48842b30 DG |
1789 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent) |
1790 | { | |
1791 | int ret = 0; | |
bec39940 DG |
1792 | struct lttng_ht_iter iter, uiter; |
1793 | struct lttng_ht_node_str *ua_chan_node, *ua_event_node; | |
48842b30 DG |
1794 | struct ust_app *app; |
1795 | struct ust_app_session *ua_sess; | |
1796 | struct ust_app_channel *ua_chan; | |
1797 | struct ust_app_event *ua_event; | |
48842b30 | 1798 | |
a991f516 MD |
1799 | DBG("UST app enabling event %s for all apps for session id %d", |
1800 | uevent->attr.name, usess->id); | |
48842b30 | 1801 | |
edb67388 DG |
1802 | /* |
1803 | * NOTE: At this point, this function is called only if the session and | |
1804 | * channel passed are already created for all apps. and enabled on the | |
1805 | * tracer also. | |
1806 | */ | |
1807 | ||
48842b30 | 1808 | rcu_read_lock(); |
421cb601 DG |
1809 | |
1810 | /* For all registered applications */ | |
bec39940 | 1811 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
e0c7ec2b DG |
1812 | if (!app->compatible) { |
1813 | /* | |
1814 | * TODO: In time, we should notice the caller of this error by | |
1815 | * telling him that this is a version error. | |
1816 | */ | |
1817 | continue; | |
1818 | } | |
edb67388 DG |
1819 | ua_sess = lookup_session_by_app(usess, app); |
1820 | /* If ua_sess is NULL, there is a code flow error */ | |
1821 | assert(ua_sess); | |
ba767faf | 1822 | |
edb67388 | 1823 | /* Lookup channel in the ust app session */ |
bec39940 DG |
1824 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &uiter); |
1825 | ua_chan_node = lttng_ht_iter_get_node_str(&uiter); | |
edb67388 DG |
1826 | /* If the channel is not found, there is a code flow error */ |
1827 | assert(ua_chan_node); | |
1828 | ||
1829 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); | |
1830 | ||
bec39940 DG |
1831 | lttng_ht_lookup(ua_chan->events, (void*)uevent->attr.name, &uiter); |
1832 | ua_event_node = lttng_ht_iter_get_node_str(&uiter); | |
35a9059d | 1833 | if (ua_event_node == NULL) { |
7f79d3a1 DG |
1834 | DBG3("UST app enable event %s not found for app PID %d." |
1835 | "Skipping app", uevent->attr.name, app->key.pid); | |
35a9059d DG |
1836 | continue; |
1837 | } | |
1838 | ua_event = caa_container_of(ua_event_node, struct ust_app_event, node); | |
1839 | ||
1840 | ret = enable_ust_app_event(ua_sess, ua_event, app); | |
1841 | if (ret < 0) { | |
7f79d3a1 | 1842 | goto error; |
48842b30 | 1843 | } |
edb67388 DG |
1844 | } |
1845 | ||
7f79d3a1 | 1846 | error: |
edb67388 | 1847 | rcu_read_unlock(); |
edb67388 DG |
1848 | return ret; |
1849 | } | |
1850 | ||
1851 | /* | |
1852 | * For a specific existing UST session and UST channel, creates the event for | |
1853 | * all registered apps. | |
1854 | */ | |
35a9059d | 1855 | int ust_app_create_event_glb(struct ltt_ust_session *usess, |
edb67388 DG |
1856 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent) |
1857 | { | |
1858 | int ret = 0; | |
bec39940 DG |
1859 | struct lttng_ht_iter iter, uiter; |
1860 | struct lttng_ht_node_str *ua_chan_node; | |
edb67388 DG |
1861 | struct ust_app *app; |
1862 | struct ust_app_session *ua_sess; | |
1863 | struct ust_app_channel *ua_chan; | |
1864 | ||
a991f516 MD |
1865 | DBG("UST app creating event %s for all apps for session id %d", |
1866 | uevent->attr.name, usess->id); | |
edb67388 | 1867 | |
edb67388 DG |
1868 | rcu_read_lock(); |
1869 | ||
1870 | /* For all registered applications */ | |
bec39940 | 1871 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
e0c7ec2b DG |
1872 | if (!app->compatible) { |
1873 | /* | |
1874 | * TODO: In time, we should notice the caller of this error by | |
1875 | * telling him that this is a version error. | |
1876 | */ | |
1877 | continue; | |
1878 | } | |
edb67388 DG |
1879 | ua_sess = lookup_session_by_app(usess, app); |
1880 | /* If ua_sess is NULL, there is a code flow error */ | |
1881 | assert(ua_sess); | |
48842b30 DG |
1882 | |
1883 | /* Lookup channel in the ust app session */ | |
bec39940 DG |
1884 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &uiter); |
1885 | ua_chan_node = lttng_ht_iter_get_node_str(&uiter); | |
edb67388 DG |
1886 | /* If the channel is not found, there is a code flow error */ |
1887 | assert(ua_chan_node); | |
1888 | ||
48842b30 DG |
1889 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); |
1890 | ||
edb67388 DG |
1891 | ret = create_ust_app_event(ua_sess, ua_chan, uevent, app); |
1892 | if (ret < 0) { | |
fc34caaa DG |
1893 | if (ret != -EEXIST) { |
1894 | /* Possible value at this point: -ENOMEM. If so, we stop! */ | |
1895 | break; | |
1896 | } | |
1897 | DBG2("UST app event %s already exist on app PID %d", | |
1898 | uevent->attr.name, app->key.pid); | |
5b4a0ec0 | 1899 | continue; |
48842b30 | 1900 | } |
48842b30 | 1901 | } |
5b4a0ec0 | 1902 | |
48842b30 DG |
1903 | rcu_read_unlock(); |
1904 | ||
1905 | return ret; | |
1906 | } | |
1907 | ||
5b4a0ec0 DG |
1908 | /* |
1909 | * Start tracing for a specific UST session and app. | |
1910 | */ | |
421cb601 | 1911 | int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app) |
48842b30 DG |
1912 | { |
1913 | int ret = 0; | |
bec39940 | 1914 | struct lttng_ht_iter iter; |
48842b30 DG |
1915 | struct ust_app_session *ua_sess; |
1916 | struct ust_app_channel *ua_chan; | |
5b4a0ec0 | 1917 | struct ltt_ust_stream *ustream; |
7753dea8 | 1918 | int consumerd_fd; |
48842b30 | 1919 | |
421cb601 | 1920 | DBG("Starting tracing for ust app pid %d", app->key.pid); |
5cf5d0e7 | 1921 | |
509cbaf8 MD |
1922 | rcu_read_lock(); |
1923 | ||
e0c7ec2b DG |
1924 | if (!app->compatible) { |
1925 | goto end; | |
1926 | } | |
1927 | ||
421cb601 DG |
1928 | ua_sess = lookup_session_by_app(usess, app); |
1929 | if (ua_sess == NULL) { | |
509cbaf8 | 1930 | goto error_rcu_unlock; |
421cb601 | 1931 | } |
48842b30 | 1932 | |
aea829b3 DG |
1933 | /* Upon restart, we skip the setup, already done */ |
1934 | if (ua_sess->started) { | |
8be98f9a | 1935 | goto skip_setup; |
aea829b3 | 1936 | } |
8be98f9a | 1937 | |
f848c3eb DG |
1938 | /* Indicate that the session has been started once */ |
1939 | ua_sess->started = 1; | |
1940 | ||
421cb601 DG |
1941 | ret = create_ust_app_metadata(ua_sess, usess->pathname, app); |
1942 | if (ret < 0) { | |
509cbaf8 | 1943 | goto error_rcu_unlock; |
421cb601 | 1944 | } |
48842b30 | 1945 | |
421cb601 | 1946 | /* For each channel */ |
bec39940 DG |
1947 | cds_lfht_for_each_entry(ua_sess->channels->ht, &iter.iter, ua_chan, |
1948 | node.node) { | |
421cb601 DG |
1949 | /* Create all streams */ |
1950 | while (1) { | |
5b4a0ec0 | 1951 | /* Create UST stream */ |
421cb601 DG |
1952 | ustream = zmalloc(sizeof(*ustream)); |
1953 | if (ustream == NULL) { | |
1954 | PERROR("zmalloc ust stream"); | |
509cbaf8 | 1955 | goto error_rcu_unlock; |
421cb601 | 1956 | } |
48842b30 | 1957 | |
421cb601 DG |
1958 | ret = ustctl_create_stream(app->key.sock, ua_chan->obj, |
1959 | &ustream->obj); | |
48842b30 | 1960 | if (ret < 0) { |
421cb601 DG |
1961 | /* Got all streams */ |
1962 | break; | |
48842b30 | 1963 | } |
421cb601 | 1964 | ustream->handle = ustream->obj->handle; |
48842b30 | 1965 | |
421cb601 DG |
1966 | /* Order is important */ |
1967 | cds_list_add_tail(&ustream->list, &ua_chan->streams.head); | |
477d7741 MD |
1968 | ret = snprintf(ustream->pathname, PATH_MAX, "%s/%s_%u", |
1969 | ua_sess->path, ua_chan->name, | |
1970 | ua_chan->streams.count++); | |
aba8e916 DG |
1971 | if (ret < 0) { |
1972 | PERROR("asprintf UST create stream"); | |
421cb601 | 1973 | continue; |
aba8e916 | 1974 | } |
421cb601 DG |
1975 | DBG2("UST stream %d ready at %s", ua_chan->streams.count, |
1976 | ustream->pathname); | |
1977 | } | |
421cb601 | 1978 | } |
aba8e916 | 1979 | |
7753dea8 MD |
1980 | switch (app->bits_per_long) { |
1981 | case 64: | |
1982 | consumerd_fd = ust_consumerd64_fd; | |
1983 | break; | |
1984 | case 32: | |
1985 | consumerd_fd = ust_consumerd32_fd; | |
1986 | break; | |
1987 | default: | |
1988 | ret = -EINVAL; | |
1989 | goto error_rcu_unlock; | |
1990 | } | |
aea829b3 | 1991 | |
421cb601 | 1992 | /* Setup UST consumer socket and send fds to it */ |
7753dea8 | 1993 | ret = ust_consumer_send_session(consumerd_fd, ua_sess); |
421cb601 | 1994 | if (ret < 0) { |
509cbaf8 | 1995 | goto error_rcu_unlock; |
421cb601 | 1996 | } |
48842b30 | 1997 | |
8be98f9a | 1998 | skip_setup: |
421cb601 DG |
1999 | /* This start the UST tracing */ |
2000 | ret = ustctl_start_session(app->key.sock, ua_sess->handle); | |
2001 | if (ret < 0) { | |
2002 | ERR("Error starting tracing for app pid: %d", app->key.pid); | |
509cbaf8 | 2003 | goto error_rcu_unlock; |
421cb601 | 2004 | } |
5b4a0ec0 | 2005 | |
421cb601 DG |
2006 | /* Quiescent wait after starting trace */ |
2007 | ustctl_wait_quiescent(app->key.sock); | |
48842b30 | 2008 | |
e0c7ec2b DG |
2009 | end: |
2010 | rcu_read_unlock(); | |
421cb601 | 2011 | return 0; |
48842b30 | 2012 | |
509cbaf8 MD |
2013 | error_rcu_unlock: |
2014 | rcu_read_unlock(); | |
421cb601 DG |
2015 | return -1; |
2016 | } | |
48842b30 | 2017 | |
8be98f9a MD |
2018 | /* |
2019 | * Stop tracing for a specific UST session and app. | |
2020 | */ | |
2021 | int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app) | |
2022 | { | |
2023 | int ret = 0; | |
bec39940 | 2024 | struct lttng_ht_iter iter; |
8be98f9a | 2025 | struct ust_app_session *ua_sess; |
6d3686da | 2026 | struct ust_app_channel *ua_chan; |
8be98f9a MD |
2027 | |
2028 | DBG("Stopping tracing for ust app pid %d", app->key.pid); | |
2029 | ||
2030 | rcu_read_lock(); | |
2031 | ||
e0c7ec2b DG |
2032 | if (!app->compatible) { |
2033 | goto end; | |
2034 | } | |
2035 | ||
8be98f9a MD |
2036 | ua_sess = lookup_session_by_app(usess, app); |
2037 | if (ua_sess == NULL) { | |
2038 | /* Only malloc can failed so something is really wrong */ | |
2039 | goto error_rcu_unlock; | |
2040 | } | |
2041 | ||
9bc07046 DG |
2042 | /* |
2043 | * If started = 0, it means that stop trace has been called for a session | |
2044 | * that was never started. This is a code flow error and should never | |
2045 | * happen. | |
2046 | */ | |
2047 | assert(ua_sess->started == 1); | |
7db205b5 | 2048 | |
9d6c7d3f DG |
2049 | /* This inhibits UST tracing */ |
2050 | ret = ustctl_stop_session(app->key.sock, ua_sess->handle); | |
2051 | if (ret < 0) { | |
2052 | ERR("Error stopping tracing for app pid: %d", app->key.pid); | |
2053 | goto error_rcu_unlock; | |
2054 | } | |
2055 | ||
2056 | /* Quiescent wait after stopping trace */ | |
2057 | ustctl_wait_quiescent(app->key.sock); | |
2058 | ||
2059 | /* Flushing buffers */ | |
bec39940 DG |
2060 | cds_lfht_for_each_entry(ua_sess->channels->ht, &iter.iter, ua_chan, |
2061 | node.node) { | |
6d3686da | 2062 | ret = ustctl_sock_flush_buffer(app->key.sock, ua_chan->obj); |
8be98f9a | 2063 | if (ret < 0) { |
7db205b5 DG |
2064 | ERR("UST app PID %d channel %s flush failed with ret %d", |
2065 | app->key.pid, ua_chan->name, ret); | |
6d3686da DG |
2066 | /* Continuing flushing all buffers */ |
2067 | continue; | |
8be98f9a MD |
2068 | } |
2069 | } | |
8be98f9a | 2070 | |
90d97d10 DG |
2071 | /* Flush all buffers before stopping */ |
2072 | ret = ustctl_sock_flush_buffer(app->key.sock, ua_sess->metadata->obj); | |
2073 | if (ret < 0) { | |
7db205b5 DG |
2074 | ERR("UST app PID %d metadata flush failed with ret %d", app->key.pid, |
2075 | ret); | |
90d97d10 DG |
2076 | } |
2077 | ||
7db205b5 DG |
2078 | end: |
2079 | rcu_read_unlock(); | |
8be98f9a MD |
2080 | return 0; |
2081 | ||
2082 | error_rcu_unlock: | |
2083 | rcu_read_unlock(); | |
2084 | return -1; | |
2085 | } | |
2086 | ||
84cd17c6 MD |
2087 | /* |
2088 | * Destroy a specific UST session in apps. | |
2089 | */ | |
2090 | int ust_app_destroy_trace(struct ltt_ust_session *usess, struct ust_app *app) | |
2091 | { | |
2092 | struct ust_app_session *ua_sess; | |
2093 | struct lttng_ust_object_data obj; | |
bec39940 DG |
2094 | struct lttng_ht_iter iter; |
2095 | struct lttng_ht_node_ulong *node; | |
525b0740 | 2096 | int ret; |
84cd17c6 MD |
2097 | |
2098 | DBG("Destroy tracing for ust app pid %d", app->key.pid); | |
2099 | ||
2100 | rcu_read_lock(); | |
2101 | ||
e0c7ec2b DG |
2102 | if (!app->compatible) { |
2103 | goto end; | |
2104 | } | |
2105 | ||
84cd17c6 | 2106 | __lookup_session_by_app(usess, app, &iter); |
bec39940 | 2107 | node = lttng_ht_iter_get_node_ulong(&iter); |
84cd17c6 MD |
2108 | if (node == NULL) { |
2109 | /* Only malloc can failed so something is really wrong */ | |
2110 | goto error_rcu_unlock; | |
2111 | } | |
2112 | ua_sess = caa_container_of(node, struct ust_app_session, node); | |
bec39940 | 2113 | ret = lttng_ht_del(app->sessions, &iter); |
525b0740 | 2114 | assert(!ret); |
84cd17c6 MD |
2115 | obj.handle = ua_sess->handle; |
2116 | obj.shm_fd = -1; | |
2117 | obj.wait_fd = -1; | |
2118 | obj.memory_map_size = 0; | |
2119 | ustctl_release_object(app->key.sock, &obj); | |
2120 | ||
7db205b5 DG |
2121 | delete_ust_app_session(app->key.sock, ua_sess); |
2122 | ||
84cd17c6 MD |
2123 | /* Quiescent wait after stopping trace */ |
2124 | ustctl_wait_quiescent(app->key.sock); | |
2125 | ||
e0c7ec2b DG |
2126 | end: |
2127 | rcu_read_unlock(); | |
84cd17c6 MD |
2128 | return 0; |
2129 | ||
2130 | error_rcu_unlock: | |
2131 | rcu_read_unlock(); | |
2132 | return -1; | |
2133 | } | |
2134 | ||
5b4a0ec0 DG |
2135 | /* |
2136 | * Start tracing for the UST session. | |
2137 | */ | |
421cb601 DG |
2138 | int ust_app_start_trace_all(struct ltt_ust_session *usess) |
2139 | { | |
2140 | int ret = 0; | |
bec39940 | 2141 | struct lttng_ht_iter iter; |
421cb601 | 2142 | struct ust_app *app; |
48842b30 | 2143 | |
421cb601 DG |
2144 | DBG("Starting all UST traces"); |
2145 | ||
2146 | rcu_read_lock(); | |
421cb601 | 2147 | |
bec39940 | 2148 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
421cb601 | 2149 | ret = ust_app_start_trace(usess, app); |
48842b30 | 2150 | if (ret < 0) { |
5b4a0ec0 DG |
2151 | /* Continue to next apps even on error */ |
2152 | continue; | |
48842b30 | 2153 | } |
48842b30 | 2154 | } |
5b4a0ec0 | 2155 | |
48842b30 DG |
2156 | rcu_read_unlock(); |
2157 | ||
2158 | return 0; | |
2159 | } | |
487cf67c | 2160 | |
8be98f9a MD |
2161 | /* |
2162 | * Start tracing for the UST session. | |
2163 | */ | |
2164 | int ust_app_stop_trace_all(struct ltt_ust_session *usess) | |
2165 | { | |
2166 | int ret = 0; | |
bec39940 | 2167 | struct lttng_ht_iter iter; |
8be98f9a MD |
2168 | struct ust_app *app; |
2169 | ||
2170 | DBG("Stopping all UST traces"); | |
2171 | ||
2172 | rcu_read_lock(); | |
2173 | ||
bec39940 | 2174 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
8be98f9a MD |
2175 | ret = ust_app_stop_trace(usess, app); |
2176 | if (ret < 0) { | |
2177 | /* Continue to next apps even on error */ | |
2178 | continue; | |
2179 | } | |
2180 | } | |
2181 | ||
2182 | rcu_read_unlock(); | |
2183 | ||
2184 | return 0; | |
2185 | } | |
2186 | ||
84cd17c6 MD |
2187 | /* |
2188 | * Destroy app UST session. | |
2189 | */ | |
2190 | int ust_app_destroy_trace_all(struct ltt_ust_session *usess) | |
2191 | { | |
2192 | int ret = 0; | |
bec39940 | 2193 | struct lttng_ht_iter iter; |
84cd17c6 MD |
2194 | struct ust_app *app; |
2195 | ||
2196 | DBG("Destroy all UST traces"); | |
2197 | ||
2198 | rcu_read_lock(); | |
2199 | ||
bec39940 | 2200 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
84cd17c6 MD |
2201 | ret = ust_app_destroy_trace(usess, app); |
2202 | if (ret < 0) { | |
2203 | /* Continue to next apps even on error */ | |
2204 | continue; | |
2205 | } | |
2206 | } | |
2207 | ||
2208 | rcu_read_unlock(); | |
2209 | ||
2210 | return 0; | |
2211 | } | |
2212 | ||
5b4a0ec0 DG |
2213 | /* |
2214 | * Add channels/events from UST global domain to registered apps at sock. | |
2215 | */ | |
487cf67c DG |
2216 | void ust_app_global_update(struct ltt_ust_session *usess, int sock) |
2217 | { | |
55c54cce | 2218 | int ret = 0; |
727d5404 | 2219 | struct lttng_ht_iter iter, uiter, iter_ctx; |
487cf67c DG |
2220 | struct ust_app *app; |
2221 | struct ust_app_session *ua_sess; | |
2222 | struct ust_app_channel *ua_chan; | |
2223 | struct ust_app_event *ua_event; | |
727d5404 | 2224 | struct ust_app_ctx *ua_ctx; |
1f3580c7 DG |
2225 | |
2226 | if (usess == NULL) { | |
5b4a0ec0 | 2227 | ERR("No UST session on global update. Returning"); |
1f3580c7 DG |
2228 | goto error; |
2229 | } | |
2230 | ||
a991f516 MD |
2231 | DBG2("UST app global update for app sock %d for session id %d", sock, |
2232 | usess->id); | |
487cf67c | 2233 | |
284d8f55 DG |
2234 | rcu_read_lock(); |
2235 | ||
487cf67c DG |
2236 | app = find_app_by_sock(sock); |
2237 | if (app == NULL) { | |
2238 | ERR("Failed to update app sock %d", sock); | |
2239 | goto error; | |
2240 | } | |
2241 | ||
e0c7ec2b DG |
2242 | if (!app->compatible) { |
2243 | goto error; | |
2244 | } | |
2245 | ||
421cb601 | 2246 | ua_sess = create_ust_app_session(usess, app); |
487cf67c | 2247 | if (ua_sess == NULL) { |
487cf67c DG |
2248 | goto error; |
2249 | } | |
2250 | ||
284d8f55 DG |
2251 | /* |
2252 | * We can iterate safely here over all UST app session sicne the create ust | |
2253 | * app session above made a shadow copy of the UST global domain from the | |
2254 | * ltt ust session. | |
2255 | */ | |
bec39940 DG |
2256 | cds_lfht_for_each_entry(ua_sess->channels->ht, &iter.iter, ua_chan, |
2257 | node.node) { | |
284d8f55 DG |
2258 | ret = create_ust_channel(app, ua_sess, ua_chan); |
2259 | if (ret < 0) { | |
2260 | /* FIXME: Should we quit here or continue... */ | |
2261 | continue; | |
487cf67c DG |
2262 | } |
2263 | ||
727d5404 DG |
2264 | cds_lfht_for_each_entry(ua_chan->ctx->ht, &iter_ctx.iter, ua_ctx, |
2265 | node.node) { | |
2266 | ret = create_ust_channel_context(ua_chan, ua_ctx, app); | |
2267 | if (ret < 0) { | |
2268 | /* FIXME: Should we quit here or continue... */ | |
2269 | continue; | |
2270 | } | |
2271 | } | |
2272 | ||
2273 | ||
284d8f55 | 2274 | /* For each events */ |
bec39940 DG |
2275 | cds_lfht_for_each_entry(ua_chan->events->ht, &uiter.iter, ua_event, |
2276 | node.node) { | |
284d8f55 DG |
2277 | ret = create_ust_event(app, ua_sess, ua_chan, ua_event); |
2278 | if (ret < 0) { | |
2279 | /* FIXME: Should we quit here or continue... */ | |
2280 | continue; | |
487cf67c | 2281 | } |
727d5404 DG |
2282 | |
2283 | /* Add context on events. */ | |
2284 | cds_lfht_for_each_entry(ua_event->ctx->ht, &iter_ctx.iter, | |
2285 | ua_ctx, node.node) { | |
2286 | ret = create_ust_event_context(ua_event, ua_ctx, app); | |
2287 | if (ret < 0) { | |
2288 | /* FIXME: Should we quit here or continue... */ | |
2289 | continue; | |
2290 | } | |
2291 | } | |
36dc12cc | 2292 | } |
487cf67c DG |
2293 | } |
2294 | ||
36dc12cc | 2295 | if (usess->start_trace) { |
421cb601 | 2296 | ret = ust_app_start_trace(usess, app); |
36dc12cc | 2297 | if (ret < 0) { |
36dc12cc DG |
2298 | goto error; |
2299 | } | |
2300 | ||
36dc12cc DG |
2301 | DBG2("UST trace started for app pid %d", app->key.pid); |
2302 | } | |
2303 | ||
487cf67c DG |
2304 | error: |
2305 | rcu_read_unlock(); | |
2306 | return; | |
2307 | } | |
55cc08a6 DG |
2308 | |
2309 | /* | |
2310 | * Add context to a specific channel for global UST domain. | |
2311 | */ | |
2312 | int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess, | |
2313 | struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx) | |
2314 | { | |
2315 | int ret = 0; | |
bec39940 DG |
2316 | struct lttng_ht_node_str *ua_chan_node; |
2317 | struct lttng_ht_iter iter, uiter; | |
55cc08a6 DG |
2318 | struct ust_app_channel *ua_chan = NULL; |
2319 | struct ust_app_session *ua_sess; | |
2320 | struct ust_app *app; | |
2321 | ||
2322 | rcu_read_lock(); | |
2323 | ||
bec39940 | 2324 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
e0c7ec2b DG |
2325 | if (!app->compatible) { |
2326 | /* | |
2327 | * TODO: In time, we should notice the caller of this error by | |
2328 | * telling him that this is a version error. | |
2329 | */ | |
2330 | continue; | |
2331 | } | |
55cc08a6 DG |
2332 | ua_sess = lookup_session_by_app(usess, app); |
2333 | if (ua_sess == NULL) { | |
2334 | continue; | |
2335 | } | |
2336 | ||
2337 | /* Lookup channel in the ust app session */ | |
bec39940 DG |
2338 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &uiter); |
2339 | ua_chan_node = lttng_ht_iter_get_node_str(&uiter); | |
55cc08a6 DG |
2340 | if (ua_chan_node == NULL) { |
2341 | continue; | |
2342 | } | |
2343 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, | |
2344 | node); | |
2345 | ||
2346 | ret = create_ust_app_channel_context(ua_sess, ua_chan, &uctx->ctx, app); | |
2347 | if (ret < 0) { | |
2348 | continue; | |
2349 | } | |
2350 | } | |
2351 | ||
55cc08a6 DG |
2352 | rcu_read_unlock(); |
2353 | return ret; | |
2354 | } | |
2355 | ||
2356 | /* | |
2357 | * Add context to a specific event in a channel for global UST domain. | |
2358 | */ | |
2359 | int ust_app_add_ctx_event_glb(struct ltt_ust_session *usess, | |
2360 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent, | |
2361 | struct ltt_ust_context *uctx) | |
2362 | { | |
2363 | int ret = 0; | |
bec39940 DG |
2364 | struct lttng_ht_node_str *ua_chan_node, *ua_event_node; |
2365 | struct lttng_ht_iter iter, uiter; | |
55cc08a6 DG |
2366 | struct ust_app_session *ua_sess; |
2367 | struct ust_app_event *ua_event; | |
2368 | struct ust_app_channel *ua_chan = NULL; | |
2369 | struct ust_app *app; | |
2370 | ||
2371 | rcu_read_lock(); | |
2372 | ||
bec39940 | 2373 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { |
e0c7ec2b DG |
2374 | if (!app->compatible) { |
2375 | /* | |
2376 | * TODO: In time, we should notice the caller of this error by | |
2377 | * telling him that this is a version error. | |
2378 | */ | |
2379 | continue; | |
2380 | } | |
55cc08a6 DG |
2381 | ua_sess = lookup_session_by_app(usess, app); |
2382 | if (ua_sess == NULL) { | |
2383 | continue; | |
2384 | } | |
2385 | ||
2386 | /* Lookup channel in the ust app session */ | |
bec39940 DG |
2387 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &uiter); |
2388 | ua_chan_node = lttng_ht_iter_get_node_str(&uiter); | |
55cc08a6 DG |
2389 | if (ua_chan_node == NULL) { |
2390 | continue; | |
2391 | } | |
2392 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, | |
2393 | node); | |
2394 | ||
bec39940 DG |
2395 | lttng_ht_lookup(ua_chan->events, (void *)uevent->attr.name, &uiter); |
2396 | ua_event_node = lttng_ht_iter_get_node_str(&uiter); | |
55cc08a6 DG |
2397 | if (ua_event_node == NULL) { |
2398 | continue; | |
2399 | } | |
2400 | ua_event = caa_container_of(ua_event_node, struct ust_app_event, | |
2401 | node); | |
2402 | ||
2403 | ret = create_ust_app_event_context(ua_sess, ua_event, &uctx->ctx, app); | |
2404 | if (ret < 0) { | |
2405 | continue; | |
2406 | } | |
2407 | } | |
2408 | ||
55cc08a6 DG |
2409 | rcu_read_unlock(); |
2410 | return ret; | |
2411 | } | |
76d45b40 DG |
2412 | |
2413 | /* | |
2414 | * Enable event for a channel from a UST session for a specific PID. | |
2415 | */ | |
2416 | int ust_app_enable_event_pid(struct ltt_ust_session *usess, | |
2417 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent, pid_t pid) | |
2418 | { | |
2419 | int ret = 0; | |
bec39940 DG |
2420 | struct lttng_ht_iter iter; |
2421 | struct lttng_ht_node_str *ua_chan_node, *ua_event_node; | |
76d45b40 DG |
2422 | struct ust_app *app; |
2423 | struct ust_app_session *ua_sess; | |
2424 | struct ust_app_channel *ua_chan; | |
2425 | struct ust_app_event *ua_event; | |
2426 | ||
2427 | DBG("UST app enabling event %s for PID %d", uevent->attr.name, pid); | |
2428 | ||
2429 | rcu_read_lock(); | |
2430 | ||
2431 | app = ust_app_find_by_pid(pid); | |
2432 | if (app == NULL) { | |
2433 | ERR("UST app enable event per PID %d not found", pid); | |
2434 | ret = -1; | |
2435 | goto error; | |
2436 | } | |
2437 | ||
e0c7ec2b DG |
2438 | if (!app->compatible) { |
2439 | ret = 0; | |
2440 | goto error; | |
2441 | } | |
2442 | ||
76d45b40 DG |
2443 | ua_sess = lookup_session_by_app(usess, app); |
2444 | /* If ua_sess is NULL, there is a code flow error */ | |
2445 | assert(ua_sess); | |
2446 | ||
2447 | /* Lookup channel in the ust app session */ | |
bec39940 DG |
2448 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &iter); |
2449 | ua_chan_node = lttng_ht_iter_get_node_str(&iter); | |
76d45b40 DG |
2450 | /* If the channel is not found, there is a code flow error */ |
2451 | assert(ua_chan_node); | |
2452 | ||
2453 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); | |
2454 | ||
bec39940 DG |
2455 | lttng_ht_lookup(ua_chan->events, (void *)uevent->attr.name, &iter); |
2456 | ua_event_node = lttng_ht_iter_get_node_str(&iter); | |
76d45b40 DG |
2457 | if (ua_event_node == NULL) { |
2458 | ret = create_ust_app_event(ua_sess, ua_chan, uevent, app); | |
2459 | if (ret < 0) { | |
2460 | goto error; | |
2461 | } | |
2462 | } else { | |
2463 | ua_event = caa_container_of(ua_event_node, struct ust_app_event, node); | |
2464 | ||
2465 | ret = enable_ust_app_event(ua_sess, ua_event, app); | |
2466 | if (ret < 0) { | |
2467 | goto error; | |
2468 | } | |
2469 | } | |
2470 | ||
2471 | error: | |
2472 | rcu_read_unlock(); | |
2473 | return ret; | |
2474 | } | |
7f79d3a1 DG |
2475 | |
2476 | /* | |
2477 | * Disable event for a channel from a UST session for a specific PID. | |
2478 | */ | |
2479 | int ust_app_disable_event_pid(struct ltt_ust_session *usess, | |
2480 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent, pid_t pid) | |
2481 | { | |
2482 | int ret = 0; | |
bec39940 DG |
2483 | struct lttng_ht_iter iter; |
2484 | struct lttng_ht_node_str *ua_chan_node, *ua_event_node; | |
7f79d3a1 DG |
2485 | struct ust_app *app; |
2486 | struct ust_app_session *ua_sess; | |
2487 | struct ust_app_channel *ua_chan; | |
2488 | struct ust_app_event *ua_event; | |
2489 | ||
2490 | DBG("UST app disabling event %s for PID %d", uevent->attr.name, pid); | |
2491 | ||
2492 | rcu_read_lock(); | |
2493 | ||
2494 | app = ust_app_find_by_pid(pid); | |
2495 | if (app == NULL) { | |
2496 | ERR("UST app disable event per PID %d not found", pid); | |
2497 | ret = -1; | |
2498 | goto error; | |
2499 | } | |
2500 | ||
e0c7ec2b DG |
2501 | if (!app->compatible) { |
2502 | ret = 0; | |
2503 | goto error; | |
2504 | } | |
2505 | ||
7f79d3a1 DG |
2506 | ua_sess = lookup_session_by_app(usess, app); |
2507 | /* If ua_sess is NULL, there is a code flow error */ | |
2508 | assert(ua_sess); | |
2509 | ||
2510 | /* Lookup channel in the ust app session */ | |
bec39940 DG |
2511 | lttng_ht_lookup(ua_sess->channels, (void *)uchan->name, &iter); |
2512 | ua_chan_node = lttng_ht_iter_get_node_str(&iter); | |
7f79d3a1 DG |
2513 | if (ua_chan_node == NULL) { |
2514 | /* Channel does not exist, skip disabling */ | |
2515 | goto error; | |
2516 | } | |
2517 | ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); | |
2518 | ||
bec39940 DG |
2519 | lttng_ht_lookup(ua_chan->events, (void *)uevent->attr.name, &iter); |
2520 | ua_event_node = lttng_ht_iter_get_node_str(&iter); | |
7f79d3a1 DG |
2521 | if (ua_event_node == NULL) { |
2522 | /* Event does not exist, skip disabling */ | |
2523 | goto error; | |
2524 | } | |
2525 | ua_event = caa_container_of(ua_event_node, struct ust_app_event, node); | |
2526 | ||
2527 | ret = disable_ust_app_event(ua_sess, ua_event, app); | |
2528 | if (ret < 0) { | |
2529 | goto error; | |
2530 | } | |
2531 | ||
2532 | error: | |
2533 | rcu_read_unlock(); | |
2534 | return ret; | |
2535 | } | |
e0c7ec2b DG |
2536 | |
2537 | /* | |
2538 | * Validate version of UST apps and set the compatible bit. | |
2539 | */ | |
2540 | int ust_app_validate_version(int sock) | |
2541 | { | |
2542 | int ret; | |
2543 | struct ust_app *app; | |
2544 | ||
2545 | rcu_read_lock(); | |
2546 | ||
2547 | app = find_app_by_sock(sock); | |
2548 | assert(app); | |
2549 | ||
2550 | ret = ustctl_tracer_version(sock, &app->version); | |
2551 | if (ret < 0) { | |
2552 | goto error; | |
2553 | } | |
2554 | ||
2555 | /* Validate version */ | |
2556 | if (app->version.major > UST_APP_MAJOR_VERSION) { | |
2557 | goto error; | |
2558 | } | |
2559 | ||
2560 | DBG2("UST app PID %d is compatible with major version %d " | |
2561 | "(supporting <= %d)", app->key.pid, app->version.major, | |
2562 | UST_APP_MAJOR_VERSION); | |
2563 | app->compatible = 1; | |
2564 | rcu_read_unlock(); | |
2565 | return 0; | |
2566 | ||
2567 | error: | |
2568 | DBG2("UST app PID %d is not compatible with major version %d " | |
2569 | "(supporting <= %d)", app->key.pid, app->version.major, | |
2570 | UST_APP_MAJOR_VERSION); | |
2571 | app->compatible = 0; | |
2572 | rcu_read_unlock(); | |
2573 | return -1; | |
2574 | } | |
4466912f DG |
2575 | |
2576 | /* | |
2577 | * Calibrate registered applications. | |
2578 | */ | |
2579 | int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate) | |
2580 | { | |
2581 | int ret = 0; | |
2582 | struct lttng_ht_iter iter; | |
2583 | struct ust_app *app; | |
2584 | ||
2585 | rcu_read_lock(); | |
2586 | ||
2587 | cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, node.node) { | |
2588 | if (!app->compatible) { | |
2589 | /* | |
2590 | * TODO: In time, we should notice the caller of this error by | |
2591 | * telling him that this is a version error. | |
2592 | */ | |
2593 | continue; | |
2594 | } | |
2595 | ||
2596 | ret = ustctl_calibrate(app->key.sock, calibrate); | |
2597 | if (ret < 0) { | |
2598 | switch (ret) { | |
2599 | case -ENOSYS: | |
2600 | /* Means that it's not implemented on the tracer side. */ | |
2601 | ret = 0; | |
2602 | break; | |
2603 | default: | |
2604 | /* TODO: Report error to user */ | |
2605 | DBG2("Calibrate app PID %d returned with error %d", | |
2606 | app->key.pid, ret); | |
2607 | break; | |
2608 | } | |
2609 | } | |
2610 | } | |
2611 | ||
2612 | DBG("UST app global domain calibration finished"); | |
2613 | ||
2614 | rcu_read_unlock(); | |
2615 | ||
2616 | return ret; | |
2617 | } |