| 1 | /* |
| 2 | * SPDX-License-Identifier: LGPL-2.1-only |
| 3 | * |
| 4 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | * |
| 6 | * Holds LTTng per-session event registry. |
| 7 | */ |
| 8 | |
| 9 | #define _LGPL_SOURCE |
| 10 | #include <stdio.h> |
| 11 | #include <assert.h> |
| 12 | #include <errno.h> |
| 13 | #include <limits.h> |
| 14 | #include <pthread.h> |
| 15 | #include <sys/shm.h> |
| 16 | #include <sys/ipc.h> |
| 17 | #include <stdint.h> |
| 18 | #include <stddef.h> |
| 19 | #include <inttypes.h> |
| 20 | #include <time.h> |
| 21 | #include <stdbool.h> |
| 22 | #include <unistd.h> |
| 23 | #include <dlfcn.h> |
| 24 | #include <lttng/ust-endian.h> |
| 25 | |
| 26 | #include <urcu/arch.h> |
| 27 | #include <urcu/compiler.h> |
| 28 | #include <urcu/hlist.h> |
| 29 | #include <urcu/list.h> |
| 30 | #include <urcu/uatomic.h> |
| 31 | |
| 32 | #include <lttng/tracepoint.h> |
| 33 | #include <lttng/ust-events.h> |
| 34 | |
| 35 | #include "common/logging.h" |
| 36 | #include "common/macros.h" |
| 37 | #include <lttng/ust-ctl.h> |
| 38 | #include "common/ustcomm.h" |
| 39 | #include "common/ust-fd.h" |
| 40 | #include "common/dynamic-type.h" |
| 41 | #include "common/ust-context-provider.h" |
| 42 | |
| 43 | #include "common/tracepoint.h" |
| 44 | #include "common/strutils.h" |
| 45 | #include "lttng-bytecode.h" |
| 46 | #include "common/tracer.h" |
| 47 | #include "lttng-tracer-core.h" |
| 48 | #include "lttng-ust-statedump.h" |
| 49 | #include "context-internal.h" |
| 50 | #include "lib/lttng-ust/events.h" |
| 51 | #include "common/ringbuffer/shm.h" |
| 52 | #include "common/ringbuffer/frontend_types.h" |
| 53 | #include "common/ringbuffer/frontend.h" |
| 54 | #include "common/counter/counter.h" |
| 55 | #include "common/jhash.h" |
| 56 | #include <lttng/ust-abi.h> |
| 57 | #include "context-provider-internal.h" |
| 58 | |
| 59 | /* |
| 60 | * All operations within this file are called by the communication |
| 61 | * thread, under ust_lock protection. |
| 62 | */ |
| 63 | |
| 64 | static CDS_LIST_HEAD(sessions); |
| 65 | static CDS_LIST_HEAD(event_notifier_groups); |
| 66 | |
| 67 | struct cds_list_head *lttng_get_sessions(void) |
| 68 | { |
| 69 | return &sessions; |
| 70 | } |
| 71 | |
| 72 | static void _lttng_event_destroy(struct lttng_ust_event_common *event); |
| 73 | static void _lttng_enum_destroy(struct lttng_enum *_enum); |
| 74 | |
| 75 | static |
| 76 | void lttng_session_lazy_sync_event_enablers(struct lttng_ust_session *session); |
| 77 | static |
| 78 | void lttng_session_sync_event_enablers(struct lttng_ust_session *session); |
| 79 | static |
| 80 | void lttng_event_notifier_group_sync_enablers( |
| 81 | struct lttng_event_notifier_group *event_notifier_group); |
| 82 | static |
| 83 | void lttng_enabler_destroy(struct lttng_enabler *enabler); |
| 84 | |
| 85 | bool lttng_ust_validate_event_name(const struct lttng_ust_event_desc *desc) |
| 86 | { |
| 87 | if (strlen(desc->probe_desc->provider_name) + 1 + |
| 88 | strlen(desc->event_name) >= LTTNG_UST_ABI_SYM_NAME_LEN) |
| 89 | return false; |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | void lttng_ust_format_event_name(const struct lttng_ust_event_desc *desc, |
| 94 | char *name) |
| 95 | { |
| 96 | strcpy(name, desc->probe_desc->provider_name); |
| 97 | strcat(name, ":"); |
| 98 | strcat(name, desc->event_name); |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * Called with ust lock held. |
| 103 | */ |
| 104 | int lttng_session_active(void) |
| 105 | { |
| 106 | struct lttng_ust_session_private *iter; |
| 107 | |
| 108 | cds_list_for_each_entry(iter, &sessions, node) { |
| 109 | if (iter->pub->active) |
| 110 | return 1; |
| 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static |
| 116 | int lttng_loglevel_match(int loglevel, |
| 117 | unsigned int has_loglevel, |
| 118 | enum lttng_ust_abi_loglevel_type req_type, |
| 119 | int req_loglevel) |
| 120 | { |
| 121 | if (!has_loglevel) |
| 122 | loglevel = LTTNG_UST_TRACEPOINT_LOGLEVEL_DEFAULT; |
| 123 | switch (req_type) { |
| 124 | case LTTNG_UST_ABI_LOGLEVEL_RANGE: |
| 125 | if (loglevel <= req_loglevel |
| 126 | || (req_loglevel == -1 && loglevel <= LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG)) |
| 127 | return 1; |
| 128 | else |
| 129 | return 0; |
| 130 | case LTTNG_UST_ABI_LOGLEVEL_SINGLE: |
| 131 | if (loglevel == req_loglevel |
| 132 | || (req_loglevel == -1 && loglevel <= LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG)) |
| 133 | return 1; |
| 134 | else |
| 135 | return 0; |
| 136 | case LTTNG_UST_ABI_LOGLEVEL_ALL: |
| 137 | default: |
| 138 | if (loglevel <= LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG) |
| 139 | return 1; |
| 140 | else |
| 141 | return 0; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | struct lttng_ust_session *lttng_session_create(void) |
| 146 | { |
| 147 | struct lttng_ust_session *session; |
| 148 | struct lttng_ust_session_private *session_priv; |
| 149 | int i; |
| 150 | |
| 151 | session = zmalloc(sizeof(struct lttng_ust_session)); |
| 152 | if (!session) |
| 153 | return NULL; |
| 154 | session->struct_size = sizeof(struct lttng_ust_session); |
| 155 | session_priv = zmalloc(sizeof(struct lttng_ust_session_private)); |
| 156 | if (!session_priv) { |
| 157 | free(session); |
| 158 | return NULL; |
| 159 | } |
| 160 | session->priv = session_priv; |
| 161 | session_priv->pub = session; |
| 162 | if (lttng_context_init_all(&session->priv->ctx)) { |
| 163 | free(session_priv); |
| 164 | free(session); |
| 165 | return NULL; |
| 166 | } |
| 167 | CDS_INIT_LIST_HEAD(&session->priv->chan_head); |
| 168 | CDS_INIT_LIST_HEAD(&session->priv->events_head); |
| 169 | CDS_INIT_LIST_HEAD(&session->priv->enums_head); |
| 170 | CDS_INIT_LIST_HEAD(&session->priv->enablers_head); |
| 171 | for (i = 0; i < LTTNG_UST_EVENT_HT_SIZE; i++) |
| 172 | CDS_INIT_HLIST_HEAD(&session->priv->events_ht.table[i]); |
| 173 | for (i = 0; i < LTTNG_UST_ENUM_HT_SIZE; i++) |
| 174 | CDS_INIT_HLIST_HEAD(&session->priv->enums_ht.table[i]); |
| 175 | cds_list_add(&session->priv->node, &sessions); |
| 176 | return session; |
| 177 | } |
| 178 | |
| 179 | struct lttng_counter *lttng_ust_counter_create( |
| 180 | const char *counter_transport_name, |
| 181 | size_t number_dimensions, const struct lttng_counter_dimension *dimensions) |
| 182 | { |
| 183 | struct lttng_counter_transport *counter_transport = NULL; |
| 184 | struct lttng_counter *counter = NULL; |
| 185 | |
| 186 | counter_transport = lttng_counter_transport_find(counter_transport_name); |
| 187 | if (!counter_transport) |
| 188 | goto notransport; |
| 189 | counter = zmalloc(sizeof(struct lttng_counter)); |
| 190 | if (!counter) |
| 191 | goto nomem; |
| 192 | |
| 193 | counter->ops = &counter_transport->ops; |
| 194 | counter->transport = counter_transport; |
| 195 | |
| 196 | counter->counter = counter->ops->counter_create( |
| 197 | number_dimensions, dimensions, 0, |
| 198 | -1, 0, NULL, false); |
| 199 | if (!counter->counter) { |
| 200 | goto create_error; |
| 201 | } |
| 202 | |
| 203 | return counter; |
| 204 | |
| 205 | create_error: |
| 206 | free(counter); |
| 207 | nomem: |
| 208 | notransport: |
| 209 | return NULL; |
| 210 | } |
| 211 | |
| 212 | static |
| 213 | void lttng_ust_counter_destroy(struct lttng_counter *counter) |
| 214 | { |
| 215 | counter->ops->counter_destroy(counter->counter); |
| 216 | free(counter); |
| 217 | } |
| 218 | |
| 219 | struct lttng_event_notifier_group *lttng_event_notifier_group_create(void) |
| 220 | { |
| 221 | struct lttng_event_notifier_group *event_notifier_group; |
| 222 | int i; |
| 223 | |
| 224 | event_notifier_group = zmalloc(sizeof(struct lttng_event_notifier_group)); |
| 225 | if (!event_notifier_group) |
| 226 | return NULL; |
| 227 | |
| 228 | /* Add all contexts. */ |
| 229 | if (lttng_context_init_all(&event_notifier_group->ctx)) { |
| 230 | free(event_notifier_group); |
| 231 | return NULL; |
| 232 | } |
| 233 | |
| 234 | CDS_INIT_LIST_HEAD(&event_notifier_group->enablers_head); |
| 235 | CDS_INIT_LIST_HEAD(&event_notifier_group->event_notifiers_head); |
| 236 | for (i = 0; i < LTTNG_UST_EVENT_NOTIFIER_HT_SIZE; i++) |
| 237 | CDS_INIT_HLIST_HEAD(&event_notifier_group->event_notifiers_ht.table[i]); |
| 238 | |
| 239 | cds_list_add(&event_notifier_group->node, &event_notifier_groups); |
| 240 | |
| 241 | return event_notifier_group; |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * Only used internally at session destruction. |
| 246 | */ |
| 247 | static |
| 248 | void _lttng_channel_unmap(struct lttng_ust_channel_buffer *lttng_chan) |
| 249 | { |
| 250 | struct lttng_ust_ring_buffer_channel *chan; |
| 251 | struct lttng_ust_shm_handle *handle; |
| 252 | |
| 253 | cds_list_del(<tng_chan->priv->node); |
| 254 | lttng_destroy_context(lttng_chan->priv->ctx); |
| 255 | chan = lttng_chan->priv->rb_chan; |
| 256 | handle = chan->handle; |
| 257 | channel_destroy(chan, handle, 0); |
| 258 | free(lttng_chan->parent); |
| 259 | free(lttng_chan->priv); |
| 260 | free(lttng_chan); |
| 261 | } |
| 262 | |
| 263 | static |
| 264 | void register_event(struct lttng_ust_event_common *event) |
| 265 | { |
| 266 | int ret; |
| 267 | const struct lttng_ust_event_desc *desc; |
| 268 | |
| 269 | assert(event->priv->registered == 0); |
| 270 | desc = event->priv->desc; |
| 271 | ret = lttng_ust_tp_probe_register_queue_release(desc->probe_desc->provider_name, |
| 272 | desc->event_name, |
| 273 | desc->tp_class->probe_callback, |
| 274 | event, desc->tp_class->signature); |
| 275 | WARN_ON_ONCE(ret); |
| 276 | if (!ret) |
| 277 | event->priv->registered = 1; |
| 278 | } |
| 279 | |
| 280 | static |
| 281 | void unregister_event(struct lttng_ust_event_common *event) |
| 282 | { |
| 283 | int ret; |
| 284 | const struct lttng_ust_event_desc *desc; |
| 285 | |
| 286 | assert(event->priv->registered == 1); |
| 287 | desc = event->priv->desc; |
| 288 | ret = lttng_ust_tp_probe_unregister_queue_release(desc->probe_desc->provider_name, |
| 289 | desc->event_name, |
| 290 | desc->tp_class->probe_callback, |
| 291 | event); |
| 292 | WARN_ON_ONCE(ret); |
| 293 | if (!ret) |
| 294 | event->priv->registered = 0; |
| 295 | } |
| 296 | |
| 297 | static |
| 298 | void _lttng_event_unregister(struct lttng_ust_event_common *event) |
| 299 | { |
| 300 | if (event->priv->registered) |
| 301 | unregister_event(event); |
| 302 | } |
| 303 | |
| 304 | void lttng_session_destroy(struct lttng_ust_session *session) |
| 305 | { |
| 306 | struct lttng_ust_channel_buffer_private *chan, *tmpchan; |
| 307 | struct lttng_ust_event_recorder_private *event_recorder_priv, *tmpevent_recorder_priv; |
| 308 | struct lttng_enum *_enum, *tmp_enum; |
| 309 | struct lttng_event_enabler *event_enabler, *event_tmpenabler; |
| 310 | |
| 311 | CMM_ACCESS_ONCE(session->active) = 0; |
| 312 | cds_list_for_each_entry(event_recorder_priv, &session->priv->events_head, node) { |
| 313 | _lttng_event_unregister(event_recorder_priv->parent.pub); |
| 314 | } |
| 315 | lttng_ust_urcu_synchronize_rcu(); /* Wait for in-flight events to complete */ |
| 316 | lttng_ust_tp_probe_prune_release_queue(); |
| 317 | cds_list_for_each_entry_safe(event_enabler, event_tmpenabler, |
| 318 | &session->priv->enablers_head, node) |
| 319 | lttng_event_enabler_destroy(event_enabler); |
| 320 | cds_list_for_each_entry_safe(event_recorder_priv, tmpevent_recorder_priv, |
| 321 | &session->priv->events_head, node) |
| 322 | _lttng_event_destroy(event_recorder_priv->parent.pub); |
| 323 | cds_list_for_each_entry_safe(_enum, tmp_enum, |
| 324 | &session->priv->enums_head, node) |
| 325 | _lttng_enum_destroy(_enum); |
| 326 | cds_list_for_each_entry_safe(chan, tmpchan, &session->priv->chan_head, node) |
| 327 | _lttng_channel_unmap(chan->pub); |
| 328 | cds_list_del(&session->priv->node); |
| 329 | lttng_destroy_context(session->priv->ctx); |
| 330 | free(session->priv); |
| 331 | free(session); |
| 332 | } |
| 333 | |
| 334 | void lttng_event_notifier_group_destroy( |
| 335 | struct lttng_event_notifier_group *event_notifier_group) |
| 336 | { |
| 337 | int close_ret; |
| 338 | struct lttng_event_notifier_enabler *notifier_enabler, *tmpnotifier_enabler; |
| 339 | struct lttng_ust_event_notifier_private *event_notifier_priv, *tmpevent_notifier_priv; |
| 340 | |
| 341 | if (!event_notifier_group) { |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | cds_list_for_each_entry(event_notifier_priv, |
| 346 | &event_notifier_group->event_notifiers_head, node) |
| 347 | _lttng_event_unregister(event_notifier_priv->parent.pub); |
| 348 | |
| 349 | lttng_ust_urcu_synchronize_rcu(); |
| 350 | |
| 351 | cds_list_for_each_entry_safe(notifier_enabler, tmpnotifier_enabler, |
| 352 | &event_notifier_group->enablers_head, node) |
| 353 | lttng_event_notifier_enabler_destroy(notifier_enabler); |
| 354 | |
| 355 | cds_list_for_each_entry_safe(event_notifier_priv, tmpevent_notifier_priv, |
| 356 | &event_notifier_group->event_notifiers_head, node) |
| 357 | _lttng_event_destroy(event_notifier_priv->parent.pub); |
| 358 | |
| 359 | if (event_notifier_group->error_counter) |
| 360 | lttng_ust_counter_destroy(event_notifier_group->error_counter); |
| 361 | |
| 362 | /* Close the notification fd to the listener of event_notifiers. */ |
| 363 | |
| 364 | lttng_ust_lock_fd_tracker(); |
| 365 | close_ret = close(event_notifier_group->notification_fd); |
| 366 | if (!close_ret) { |
| 367 | lttng_ust_delete_fd_from_tracker( |
| 368 | event_notifier_group->notification_fd); |
| 369 | } else { |
| 370 | PERROR("close"); |
| 371 | abort(); |
| 372 | } |
| 373 | lttng_ust_unlock_fd_tracker(); |
| 374 | |
| 375 | cds_list_del(&event_notifier_group->node); |
| 376 | lttng_destroy_context(event_notifier_group->ctx); |
| 377 | free(event_notifier_group); |
| 378 | } |
| 379 | |
| 380 | static |
| 381 | void lttng_enabler_destroy(struct lttng_enabler *enabler) |
| 382 | { |
| 383 | struct lttng_ust_bytecode_node *filter_node, *tmp_filter_node; |
| 384 | struct lttng_ust_excluder_node *excluder_node, *tmp_excluder_node; |
| 385 | |
| 386 | if (!enabler) { |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | /* Destroy filter bytecode */ |
| 391 | cds_list_for_each_entry_safe(filter_node, tmp_filter_node, |
| 392 | &enabler->filter_bytecode_head, node) { |
| 393 | free(filter_node); |
| 394 | } |
| 395 | |
| 396 | /* Destroy excluders */ |
| 397 | cds_list_for_each_entry_safe(excluder_node, tmp_excluder_node, |
| 398 | &enabler->excluder_head, node) { |
| 399 | free(excluder_node); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | void lttng_event_notifier_enabler_destroy(struct lttng_event_notifier_enabler *event_notifier_enabler) |
| 404 | { |
| 405 | if (!event_notifier_enabler) { |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | cds_list_del(&event_notifier_enabler->node); |
| 410 | |
| 411 | lttng_enabler_destroy(lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)); |
| 412 | |
| 413 | free(event_notifier_enabler); |
| 414 | } |
| 415 | |
| 416 | static |
| 417 | int lttng_enum_create(const struct lttng_ust_enum_desc *desc, |
| 418 | struct lttng_ust_session *session) |
| 419 | { |
| 420 | const char *enum_name = desc->name; |
| 421 | struct lttng_enum *_enum; |
| 422 | struct cds_hlist_head *head; |
| 423 | int ret = 0; |
| 424 | size_t name_len = strlen(enum_name); |
| 425 | uint32_t hash; |
| 426 | int notify_socket; |
| 427 | |
| 428 | /* Check if this enum is already registered for this session. */ |
| 429 | hash = jhash(enum_name, name_len, 0); |
| 430 | head = &session->priv->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)]; |
| 431 | |
| 432 | _enum = lttng_ust_enum_get_from_desc(session, desc); |
| 433 | if (_enum) { |
| 434 | ret = -EEXIST; |
| 435 | goto exist; |
| 436 | } |
| 437 | |
| 438 | notify_socket = lttng_get_notify_socket(session->priv->owner); |
| 439 | if (notify_socket < 0) { |
| 440 | ret = notify_socket; |
| 441 | goto socket_error; |
| 442 | } |
| 443 | |
| 444 | _enum = zmalloc(sizeof(*_enum)); |
| 445 | if (!_enum) { |
| 446 | ret = -ENOMEM; |
| 447 | goto cache_error; |
| 448 | } |
| 449 | _enum->session = session; |
| 450 | _enum->desc = desc; |
| 451 | |
| 452 | ret = ustcomm_register_enum(notify_socket, |
| 453 | session->priv->objd, |
| 454 | enum_name, |
| 455 | desc->nr_entries, |
| 456 | desc->entries, |
| 457 | &_enum->id); |
| 458 | if (ret < 0) { |
| 459 | DBG("Error (%d) registering enumeration to sessiond", ret); |
| 460 | goto sessiond_register_error; |
| 461 | } |
| 462 | cds_list_add(&_enum->node, &session->priv->enums_head); |
| 463 | cds_hlist_add_head(&_enum->hlist, head); |
| 464 | return 0; |
| 465 | |
| 466 | sessiond_register_error: |
| 467 | free(_enum); |
| 468 | cache_error: |
| 469 | socket_error: |
| 470 | exist: |
| 471 | return ret; |
| 472 | } |
| 473 | |
| 474 | static |
| 475 | int lttng_create_enum_check(const struct lttng_ust_type_common *type, |
| 476 | struct lttng_ust_session *session) |
| 477 | { |
| 478 | switch (type->type) { |
| 479 | case lttng_ust_type_enum: |
| 480 | { |
| 481 | const struct lttng_ust_enum_desc *enum_desc; |
| 482 | int ret; |
| 483 | |
| 484 | enum_desc = lttng_ust_get_type_enum(type)->desc; |
| 485 | ret = lttng_enum_create(enum_desc, session); |
| 486 | if (ret && ret != -EEXIST) { |
| 487 | DBG("Unable to create enum error: (%d)", ret); |
| 488 | return ret; |
| 489 | } |
| 490 | break; |
| 491 | } |
| 492 | case lttng_ust_type_dynamic: |
| 493 | { |
| 494 | const struct lttng_ust_event_field *tag_field_generic; |
| 495 | const struct lttng_ust_enum_desc *enum_desc; |
| 496 | int ret; |
| 497 | |
| 498 | tag_field_generic = lttng_ust_dynamic_type_tag_field(); |
| 499 | enum_desc = lttng_ust_get_type_enum(tag_field_generic->type)->desc; |
| 500 | ret = lttng_enum_create(enum_desc, session); |
| 501 | if (ret && ret != -EEXIST) { |
| 502 | DBG("Unable to create enum error: (%d)", ret); |
| 503 | return ret; |
| 504 | } |
| 505 | break; |
| 506 | } |
| 507 | default: |
| 508 | /* TODO: nested types when they become supported. */ |
| 509 | break; |
| 510 | } |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | static |
| 515 | int lttng_create_all_event_enums(size_t nr_fields, |
| 516 | const struct lttng_ust_event_field * const *event_fields, |
| 517 | struct lttng_ust_session *session) |
| 518 | { |
| 519 | size_t i; |
| 520 | int ret; |
| 521 | |
| 522 | /* For each field, ensure enum is part of the session. */ |
| 523 | for (i = 0; i < nr_fields; i++) { |
| 524 | const struct lttng_ust_type_common *type = event_fields[i]->type; |
| 525 | |
| 526 | ret = lttng_create_enum_check(type, session); |
| 527 | if (ret) |
| 528 | return ret; |
| 529 | } |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | static |
| 534 | int lttng_create_all_ctx_enums(size_t nr_fields, |
| 535 | struct lttng_ust_ctx_field *ctx_fields, |
| 536 | struct lttng_ust_session *session) |
| 537 | { |
| 538 | size_t i; |
| 539 | int ret; |
| 540 | |
| 541 | /* For each field, ensure enum is part of the session. */ |
| 542 | for (i = 0; i < nr_fields; i++) { |
| 543 | const struct lttng_ust_type_common *type = ctx_fields[i].event_field->type; |
| 544 | |
| 545 | ret = lttng_create_enum_check(type, session); |
| 546 | if (ret) |
| 547 | return ret; |
| 548 | } |
| 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | /* |
| 553 | * Ensure that a state-dump will be performed for this session at the end |
| 554 | * of the current handle_message(). |
| 555 | */ |
| 556 | int lttng_session_statedump(struct lttng_ust_session *session) |
| 557 | { |
| 558 | session->priv->statedump_pending = 1; |
| 559 | lttng_ust_sockinfo_session_enabled(session->priv->owner); |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | int lttng_session_enable(struct lttng_ust_session *session) |
| 564 | { |
| 565 | int ret = 0; |
| 566 | struct lttng_ust_channel_buffer_private *chan; |
| 567 | int notify_socket; |
| 568 | |
| 569 | if (session->active) { |
| 570 | ret = -EBUSY; |
| 571 | goto end; |
| 572 | } |
| 573 | |
| 574 | notify_socket = lttng_get_notify_socket(session->priv->owner); |
| 575 | if (notify_socket < 0) |
| 576 | return notify_socket; |
| 577 | |
| 578 | /* Set transient enabler state to "enabled" */ |
| 579 | session->priv->tstate = 1; |
| 580 | |
| 581 | /* We need to sync enablers with session before activation. */ |
| 582 | lttng_session_sync_event_enablers(session); |
| 583 | |
| 584 | /* |
| 585 | * Snapshot the number of events per channel to know the type of header |
| 586 | * we need to use. |
| 587 | */ |
| 588 | cds_list_for_each_entry(chan, &session->priv->chan_head, node) { |
| 589 | struct lttng_ust_ctx *ctx; |
| 590 | struct lttng_ust_ctx_field *fields = NULL; |
| 591 | size_t nr_fields = 0; |
| 592 | uint32_t chan_id; |
| 593 | |
| 594 | /* don't change it if session stop/restart */ |
| 595 | if (chan->header_type) |
| 596 | continue; |
| 597 | ctx = chan->ctx; |
| 598 | if (ctx) { |
| 599 | nr_fields = ctx->nr_fields; |
| 600 | fields = ctx->fields; |
| 601 | ret = lttng_create_all_ctx_enums(nr_fields, fields, |
| 602 | session); |
| 603 | if (ret < 0) { |
| 604 | DBG("Error (%d) adding enum to session", ret); |
| 605 | return ret; |
| 606 | } |
| 607 | } |
| 608 | ret = ustcomm_register_channel(notify_socket, |
| 609 | session, |
| 610 | session->priv->objd, |
| 611 | chan->parent.objd, |
| 612 | nr_fields, |
| 613 | fields, |
| 614 | &chan_id, |
| 615 | &chan->header_type); |
| 616 | if (ret) { |
| 617 | DBG("Error (%d) registering channel to sessiond", ret); |
| 618 | return ret; |
| 619 | } |
| 620 | if (chan_id != chan->id) { |
| 621 | DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)", |
| 622 | chan_id, chan->id); |
| 623 | return -EINVAL; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | /* Set atomically the state to "active" */ |
| 628 | CMM_ACCESS_ONCE(session->active) = 1; |
| 629 | CMM_ACCESS_ONCE(session->priv->been_active) = 1; |
| 630 | |
| 631 | ret = lttng_session_statedump(session); |
| 632 | if (ret) |
| 633 | return ret; |
| 634 | end: |
| 635 | return ret; |
| 636 | } |
| 637 | |
| 638 | int lttng_session_disable(struct lttng_ust_session *session) |
| 639 | { |
| 640 | int ret = 0; |
| 641 | |
| 642 | if (!session->active) { |
| 643 | ret = -EBUSY; |
| 644 | goto end; |
| 645 | } |
| 646 | /* Set atomically the state to "inactive" */ |
| 647 | CMM_ACCESS_ONCE(session->active) = 0; |
| 648 | |
| 649 | /* Set transient enabler state to "disabled" */ |
| 650 | session->priv->tstate = 0; |
| 651 | lttng_session_sync_event_enablers(session); |
| 652 | end: |
| 653 | return ret; |
| 654 | } |
| 655 | |
| 656 | int lttng_channel_enable(struct lttng_ust_channel_common *lttng_channel) |
| 657 | { |
| 658 | int ret = 0; |
| 659 | |
| 660 | if (lttng_channel->enabled) { |
| 661 | ret = -EBUSY; |
| 662 | goto end; |
| 663 | } |
| 664 | /* Set transient enabler state to "enabled" */ |
| 665 | lttng_channel->priv->tstate = 1; |
| 666 | lttng_session_sync_event_enablers(lttng_channel->session); |
| 667 | /* Set atomically the state to "enabled" */ |
| 668 | CMM_ACCESS_ONCE(lttng_channel->enabled) = 1; |
| 669 | end: |
| 670 | return ret; |
| 671 | } |
| 672 | |
| 673 | int lttng_channel_disable(struct lttng_ust_channel_common *lttng_channel) |
| 674 | { |
| 675 | int ret = 0; |
| 676 | |
| 677 | if (!lttng_channel->enabled) { |
| 678 | ret = -EBUSY; |
| 679 | goto end; |
| 680 | } |
| 681 | /* Set atomically the state to "disabled" */ |
| 682 | CMM_ACCESS_ONCE(lttng_channel->enabled) = 0; |
| 683 | /* Set transient enabler state to "enabled" */ |
| 684 | lttng_channel->priv->tstate = 0; |
| 685 | lttng_session_sync_event_enablers(lttng_channel->session); |
| 686 | end: |
| 687 | return ret; |
| 688 | } |
| 689 | |
| 690 | static inline |
| 691 | struct cds_hlist_head *borrow_hash_table_bucket( |
| 692 | struct cds_hlist_head *hash_table, |
| 693 | unsigned int hash_table_size, |
| 694 | const struct lttng_ust_event_desc *desc) |
| 695 | { |
| 696 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 697 | size_t name_len; |
| 698 | uint32_t hash; |
| 699 | |
| 700 | lttng_ust_format_event_name(desc, name); |
| 701 | name_len = strlen(name); |
| 702 | |
| 703 | hash = jhash(name, name_len, 0); |
| 704 | return &hash_table[hash & (hash_table_size - 1)]; |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | * Supports event creation while tracing session is active. |
| 709 | */ |
| 710 | static |
| 711 | int lttng_event_recorder_create(const struct lttng_ust_event_desc *desc, |
| 712 | struct lttng_ust_channel_buffer *chan) |
| 713 | { |
| 714 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 715 | struct lttng_ust_event_recorder *event_recorder; |
| 716 | struct lttng_ust_event_recorder_private *event_recorder_priv; |
| 717 | struct lttng_ust_session *session = chan->parent->session; |
| 718 | struct cds_hlist_head *head; |
| 719 | int ret = 0; |
| 720 | int notify_socket, loglevel; |
| 721 | const char *uri; |
| 722 | |
| 723 | head = borrow_hash_table_bucket(chan->parent->session->priv->events_ht.table, |
| 724 | LTTNG_UST_EVENT_HT_SIZE, desc); |
| 725 | |
| 726 | notify_socket = lttng_get_notify_socket(session->priv->owner); |
| 727 | if (notify_socket < 0) { |
| 728 | ret = notify_socket; |
| 729 | goto socket_error; |
| 730 | } |
| 731 | |
| 732 | ret = lttng_create_all_event_enums(desc->tp_class->nr_fields, desc->tp_class->fields, |
| 733 | session); |
| 734 | if (ret < 0) { |
| 735 | DBG("Error (%d) adding enum to session", ret); |
| 736 | goto create_enum_error; |
| 737 | } |
| 738 | |
| 739 | /* |
| 740 | * Check if loglevel match. Refuse to connect event if not. |
| 741 | */ |
| 742 | event_recorder = zmalloc(sizeof(struct lttng_ust_event_recorder)); |
| 743 | if (!event_recorder) { |
| 744 | ret = -ENOMEM; |
| 745 | goto cache_error; |
| 746 | } |
| 747 | event_recorder->struct_size = sizeof(struct lttng_ust_event_recorder); |
| 748 | |
| 749 | event_recorder->parent = zmalloc(sizeof(struct lttng_ust_event_common)); |
| 750 | if (!event_recorder->parent) { |
| 751 | ret = -ENOMEM; |
| 752 | goto parent_error; |
| 753 | } |
| 754 | event_recorder->parent->struct_size = sizeof(struct lttng_ust_event_common); |
| 755 | event_recorder->parent->type = LTTNG_UST_EVENT_TYPE_RECORDER; |
| 756 | event_recorder->parent->child = event_recorder; |
| 757 | |
| 758 | event_recorder_priv = zmalloc(sizeof(struct lttng_ust_event_recorder_private)); |
| 759 | if (!event_recorder_priv) { |
| 760 | ret = -ENOMEM; |
| 761 | goto priv_error; |
| 762 | } |
| 763 | event_recorder->priv = event_recorder_priv; |
| 764 | event_recorder_priv->pub = event_recorder; |
| 765 | event_recorder->parent->priv = &event_recorder_priv->parent; |
| 766 | event_recorder_priv->parent.pub = event_recorder->parent; |
| 767 | |
| 768 | event_recorder->chan = chan; |
| 769 | |
| 770 | /* Event will be enabled by enabler sync. */ |
| 771 | event_recorder->parent->run_filter = lttng_ust_interpret_event_filter; |
| 772 | event_recorder->parent->enabled = 0; |
| 773 | event_recorder->parent->priv->registered = 0; |
| 774 | CDS_INIT_LIST_HEAD(&event_recorder->parent->priv->filter_bytecode_runtime_head); |
| 775 | CDS_INIT_LIST_HEAD(&event_recorder->parent->priv->enablers_ref_head); |
| 776 | event_recorder->parent->priv->desc = desc; |
| 777 | |
| 778 | if (desc->loglevel) |
| 779 | loglevel = *(*desc->loglevel); |
| 780 | else |
| 781 | loglevel = LTTNG_UST_TRACEPOINT_LOGLEVEL_DEFAULT; |
| 782 | if (desc->model_emf_uri) |
| 783 | uri = *(desc->model_emf_uri); |
| 784 | else |
| 785 | uri = NULL; |
| 786 | |
| 787 | lttng_ust_format_event_name(desc, name); |
| 788 | |
| 789 | /* Fetch event ID from sessiond */ |
| 790 | ret = ustcomm_register_event(notify_socket, |
| 791 | session, |
| 792 | session->priv->objd, |
| 793 | chan->priv->parent.objd, |
| 794 | name, |
| 795 | loglevel, |
| 796 | desc->tp_class->signature, |
| 797 | desc->tp_class->nr_fields, |
| 798 | desc->tp_class->fields, |
| 799 | uri, |
| 800 | &event_recorder->priv->id); |
| 801 | if (ret < 0) { |
| 802 | DBG("Error (%d) registering event to sessiond", ret); |
| 803 | goto sessiond_register_error; |
| 804 | } |
| 805 | |
| 806 | cds_list_add(&event_recorder_priv->node, &chan->parent->session->priv->events_head); |
| 807 | cds_hlist_add_head(&event_recorder_priv->hlist, head); |
| 808 | return 0; |
| 809 | |
| 810 | sessiond_register_error: |
| 811 | free(event_recorder_priv); |
| 812 | priv_error: |
| 813 | free(event_recorder->parent); |
| 814 | parent_error: |
| 815 | free(event_recorder); |
| 816 | cache_error: |
| 817 | create_enum_error: |
| 818 | socket_error: |
| 819 | return ret; |
| 820 | } |
| 821 | |
| 822 | static |
| 823 | int lttng_event_notifier_create(const struct lttng_ust_event_desc *desc, |
| 824 | uint64_t token, uint64_t error_counter_index, |
| 825 | struct lttng_event_notifier_group *event_notifier_group) |
| 826 | { |
| 827 | struct lttng_ust_event_notifier *event_notifier; |
| 828 | struct lttng_ust_event_notifier_private *event_notifier_priv; |
| 829 | struct cds_hlist_head *head; |
| 830 | int ret = 0; |
| 831 | |
| 832 | /* |
| 833 | * Get the hashtable bucket the created lttng_event_notifier object |
| 834 | * should be inserted. |
| 835 | */ |
| 836 | head = borrow_hash_table_bucket( |
| 837 | event_notifier_group->event_notifiers_ht.table, |
| 838 | LTTNG_UST_EVENT_NOTIFIER_HT_SIZE, desc); |
| 839 | |
| 840 | event_notifier = zmalloc(sizeof(struct lttng_ust_event_notifier)); |
| 841 | if (!event_notifier) { |
| 842 | ret = -ENOMEM; |
| 843 | goto error; |
| 844 | } |
| 845 | event_notifier->struct_size = sizeof(struct lttng_ust_event_notifier); |
| 846 | |
| 847 | event_notifier->parent = zmalloc(sizeof(struct lttng_ust_event_common)); |
| 848 | if (!event_notifier->parent) { |
| 849 | ret = -ENOMEM; |
| 850 | goto parent_error; |
| 851 | } |
| 852 | event_notifier->parent->struct_size = sizeof(struct lttng_ust_event_common); |
| 853 | event_notifier->parent->type = LTTNG_UST_EVENT_TYPE_NOTIFIER; |
| 854 | event_notifier->parent->child = event_notifier; |
| 855 | |
| 856 | event_notifier_priv = zmalloc(sizeof(struct lttng_ust_event_notifier_private)); |
| 857 | if (!event_notifier_priv) { |
| 858 | ret = -ENOMEM; |
| 859 | goto priv_error; |
| 860 | } |
| 861 | event_notifier->priv = event_notifier_priv; |
| 862 | event_notifier_priv->pub = event_notifier; |
| 863 | event_notifier->parent->priv = &event_notifier_priv->parent; |
| 864 | event_notifier_priv->parent.pub = event_notifier->parent; |
| 865 | |
| 866 | event_notifier_priv->group = event_notifier_group; |
| 867 | event_notifier_priv->parent.user_token = token; |
| 868 | event_notifier_priv->error_counter_index = error_counter_index; |
| 869 | |
| 870 | /* Event notifier will be enabled by enabler sync. */ |
| 871 | event_notifier->parent->run_filter = lttng_ust_interpret_event_filter; |
| 872 | event_notifier->parent->enabled = 0; |
| 873 | event_notifier_priv->parent.registered = 0; |
| 874 | |
| 875 | CDS_INIT_LIST_HEAD(&event_notifier->parent->priv->filter_bytecode_runtime_head); |
| 876 | CDS_INIT_LIST_HEAD(&event_notifier->priv->capture_bytecode_runtime_head); |
| 877 | CDS_INIT_LIST_HEAD(&event_notifier_priv->parent.enablers_ref_head); |
| 878 | event_notifier_priv->parent.desc = desc; |
| 879 | event_notifier->notification_send = lttng_event_notifier_notification_send; |
| 880 | |
| 881 | cds_list_add(&event_notifier_priv->node, |
| 882 | &event_notifier_group->event_notifiers_head); |
| 883 | cds_hlist_add_head(&event_notifier_priv->hlist, head); |
| 884 | |
| 885 | return 0; |
| 886 | |
| 887 | priv_error: |
| 888 | free(event_notifier->parent); |
| 889 | parent_error: |
| 890 | free(event_notifier); |
| 891 | error: |
| 892 | return ret; |
| 893 | } |
| 894 | |
| 895 | static |
| 896 | int lttng_desc_match_star_glob_enabler(const struct lttng_ust_event_desc *desc, |
| 897 | struct lttng_enabler *enabler) |
| 898 | { |
| 899 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 900 | int loglevel = 0; |
| 901 | unsigned int has_loglevel = 0; |
| 902 | |
| 903 | lttng_ust_format_event_name(desc, name); |
| 904 | assert(enabler->format_type == LTTNG_ENABLER_FORMAT_STAR_GLOB); |
| 905 | if (!strutils_star_glob_match(enabler->event_param.name, SIZE_MAX, |
| 906 | name, SIZE_MAX)) |
| 907 | return 0; |
| 908 | if (desc->loglevel) { |
| 909 | loglevel = *(*desc->loglevel); |
| 910 | has_loglevel = 1; |
| 911 | } |
| 912 | if (!lttng_loglevel_match(loglevel, |
| 913 | has_loglevel, |
| 914 | enabler->event_param.loglevel_type, |
| 915 | enabler->event_param.loglevel)) |
| 916 | return 0; |
| 917 | return 1; |
| 918 | } |
| 919 | |
| 920 | static |
| 921 | int lttng_desc_match_event_enabler(const struct lttng_ust_event_desc *desc, |
| 922 | struct lttng_enabler *enabler) |
| 923 | { |
| 924 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 925 | int loglevel = 0; |
| 926 | unsigned int has_loglevel = 0; |
| 927 | |
| 928 | lttng_ust_format_event_name(desc, name); |
| 929 | assert(enabler->format_type == LTTNG_ENABLER_FORMAT_EVENT); |
| 930 | if (strcmp(name, enabler->event_param.name)) |
| 931 | return 0; |
| 932 | if (desc->loglevel) { |
| 933 | loglevel = *(*desc->loglevel); |
| 934 | has_loglevel = 1; |
| 935 | } |
| 936 | if (!lttng_loglevel_match(loglevel, |
| 937 | has_loglevel, |
| 938 | enabler->event_param.loglevel_type, |
| 939 | enabler->event_param.loglevel)) |
| 940 | return 0; |
| 941 | return 1; |
| 942 | } |
| 943 | |
| 944 | static |
| 945 | int lttng_desc_match_enabler(const struct lttng_ust_event_desc *desc, |
| 946 | struct lttng_enabler *enabler) |
| 947 | { |
| 948 | switch (enabler->format_type) { |
| 949 | case LTTNG_ENABLER_FORMAT_STAR_GLOB: |
| 950 | { |
| 951 | struct lttng_ust_excluder_node *excluder; |
| 952 | |
| 953 | if (!lttng_desc_match_star_glob_enabler(desc, enabler)) { |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | /* |
| 958 | * If the matching event matches with an excluder, |
| 959 | * return 'does not match' |
| 960 | */ |
| 961 | cds_list_for_each_entry(excluder, &enabler->excluder_head, node) { |
| 962 | int count; |
| 963 | |
| 964 | for (count = 0; count < excluder->excluder.count; count++) { |
| 965 | int len; |
| 966 | char *excluder_name; |
| 967 | |
| 968 | excluder_name = (char *) (excluder->excluder.names) |
| 969 | + count * LTTNG_UST_ABI_SYM_NAME_LEN; |
| 970 | len = strnlen(excluder_name, LTTNG_UST_ABI_SYM_NAME_LEN); |
| 971 | if (len > 0) { |
| 972 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 973 | |
| 974 | lttng_ust_format_event_name(desc, name); |
| 975 | if (strutils_star_glob_match(excluder_name, len, name, SIZE_MAX)) { |
| 976 | return 0; |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | return 1; |
| 982 | } |
| 983 | case LTTNG_ENABLER_FORMAT_EVENT: |
| 984 | return lttng_desc_match_event_enabler(desc, enabler); |
| 985 | default: |
| 986 | return -EINVAL; |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | static |
| 991 | int lttng_event_enabler_match_event(struct lttng_event_enabler *event_enabler, |
| 992 | struct lttng_ust_event_recorder *event_recorder) |
| 993 | { |
| 994 | if (lttng_desc_match_enabler(event_recorder->parent->priv->desc, |
| 995 | lttng_event_enabler_as_enabler(event_enabler)) |
| 996 | && event_recorder->chan == event_enabler->chan) |
| 997 | return 1; |
| 998 | else |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | static |
| 1003 | int lttng_event_notifier_enabler_match_event_notifier( |
| 1004 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
| 1005 | struct lttng_ust_event_notifier *event_notifier) |
| 1006 | { |
| 1007 | int desc_matches = lttng_desc_match_enabler(event_notifier->priv->parent.desc, |
| 1008 | lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)); |
| 1009 | |
| 1010 | if (desc_matches && event_notifier->priv->group == event_notifier_enabler->group && |
| 1011 | event_notifier->priv->parent.user_token == event_notifier_enabler->user_token) |
| 1012 | return 1; |
| 1013 | else |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
| 1017 | static |
| 1018 | struct lttng_enabler_ref *lttng_enabler_ref( |
| 1019 | struct cds_list_head *enabler_ref_list, |
| 1020 | struct lttng_enabler *enabler) |
| 1021 | { |
| 1022 | struct lttng_enabler_ref *enabler_ref; |
| 1023 | |
| 1024 | cds_list_for_each_entry(enabler_ref, enabler_ref_list, node) { |
| 1025 | if (enabler_ref->ref == enabler) |
| 1026 | return enabler_ref; |
| 1027 | } |
| 1028 | return NULL; |
| 1029 | } |
| 1030 | |
| 1031 | /* |
| 1032 | * Create struct lttng_event if it is missing and present in the list of |
| 1033 | * tracepoint probes. |
| 1034 | */ |
| 1035 | static |
| 1036 | void lttng_create_event_recorder_if_missing(struct lttng_event_enabler *event_enabler) |
| 1037 | { |
| 1038 | struct lttng_ust_session *session = event_enabler->chan->parent->session; |
| 1039 | struct lttng_ust_registered_probe *reg_probe; |
| 1040 | const struct lttng_ust_event_desc *desc; |
| 1041 | struct lttng_ust_event_recorder_private *event_recorder_priv; |
| 1042 | int i; |
| 1043 | struct cds_list_head *probe_list; |
| 1044 | |
| 1045 | probe_list = lttng_get_probe_list_head(); |
| 1046 | /* |
| 1047 | * For each probe event, if we find that a probe event matches |
| 1048 | * our enabler, create an associated lttng_event if not |
| 1049 | * already present. |
| 1050 | */ |
| 1051 | cds_list_for_each_entry(reg_probe, probe_list, head) { |
| 1052 | const struct lttng_ust_probe_desc *probe_desc = reg_probe->desc; |
| 1053 | |
| 1054 | for (i = 0; i < probe_desc->nr_events; i++) { |
| 1055 | int ret; |
| 1056 | bool found = false; |
| 1057 | struct cds_hlist_head *head; |
| 1058 | struct cds_hlist_node *node; |
| 1059 | |
| 1060 | desc = probe_desc->event_desc[i]; |
| 1061 | if (!lttng_desc_match_enabler(desc, |
| 1062 | lttng_event_enabler_as_enabler(event_enabler))) |
| 1063 | continue; |
| 1064 | |
| 1065 | head = borrow_hash_table_bucket( |
| 1066 | session->priv->events_ht.table, |
| 1067 | LTTNG_UST_EVENT_HT_SIZE, desc); |
| 1068 | |
| 1069 | cds_hlist_for_each_entry(event_recorder_priv, node, head, hlist) { |
| 1070 | if (event_recorder_priv->parent.desc == desc |
| 1071 | && event_recorder_priv->pub->chan == event_enabler->chan) { |
| 1072 | found = true; |
| 1073 | break; |
| 1074 | } |
| 1075 | } |
| 1076 | if (found) |
| 1077 | continue; |
| 1078 | |
| 1079 | /* |
| 1080 | * We need to create an event for this |
| 1081 | * event probe. |
| 1082 | */ |
| 1083 | ret = lttng_event_recorder_create(probe_desc->event_desc[i], |
| 1084 | event_enabler->chan); |
| 1085 | if (ret) { |
| 1086 | DBG("Unable to create event \"%s:%s\", error %d\n", |
| 1087 | probe_desc->provider_name, |
| 1088 | probe_desc->event_desc[i]->event_name, ret); |
| 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | static |
| 1095 | void probe_provider_event_for_each(const struct lttng_ust_probe_desc *provider_desc, |
| 1096 | void (*event_func)(struct lttng_ust_event_common *event)) |
| 1097 | { |
| 1098 | struct cds_hlist_node *node, *tmp_node; |
| 1099 | struct cds_list_head *sessionsp; |
| 1100 | unsigned int i; |
| 1101 | |
| 1102 | /* Get handle on list of sessions. */ |
| 1103 | sessionsp = lttng_get_sessions(); |
| 1104 | |
| 1105 | /* |
| 1106 | * Iterate over all events in the probe provider descriptions and |
| 1107 | * sessions to queue the unregistration of the events. |
| 1108 | */ |
| 1109 | for (i = 0; i < provider_desc->nr_events; i++) { |
| 1110 | const struct lttng_ust_event_desc *event_desc; |
| 1111 | struct lttng_event_notifier_group *event_notifier_group; |
| 1112 | struct lttng_ust_event_recorder_private *event_recorder_priv; |
| 1113 | struct lttng_ust_event_notifier_private *event_notifier_priv; |
| 1114 | struct lttng_ust_session_private *session_priv; |
| 1115 | struct cds_hlist_head *head; |
| 1116 | |
| 1117 | event_desc = provider_desc->event_desc[i]; |
| 1118 | |
| 1119 | /* |
| 1120 | * Iterate over all session to find the current event |
| 1121 | * description. |
| 1122 | */ |
| 1123 | cds_list_for_each_entry(session_priv, sessionsp, node) { |
| 1124 | /* |
| 1125 | * Get the list of events in the hashtable bucket and |
| 1126 | * iterate to find the event matching this descriptor. |
| 1127 | */ |
| 1128 | head = borrow_hash_table_bucket( |
| 1129 | session_priv->events_ht.table, |
| 1130 | LTTNG_UST_EVENT_HT_SIZE, event_desc); |
| 1131 | |
| 1132 | cds_hlist_for_each_entry_safe(event_recorder_priv, node, tmp_node, head, hlist) { |
| 1133 | if (event_desc == event_recorder_priv->parent.desc) { |
| 1134 | event_func(event_recorder_priv->parent.pub); |
| 1135 | break; |
| 1136 | } |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | /* |
| 1141 | * Iterate over all event_notifier groups to find the current event |
| 1142 | * description. |
| 1143 | */ |
| 1144 | cds_list_for_each_entry(event_notifier_group, &event_notifier_groups, node) { |
| 1145 | /* |
| 1146 | * Get the list of event_notifiers in the hashtable bucket and |
| 1147 | * iterate to find the event_notifier matching this |
| 1148 | * descriptor. |
| 1149 | */ |
| 1150 | head = borrow_hash_table_bucket( |
| 1151 | event_notifier_group->event_notifiers_ht.table, |
| 1152 | LTTNG_UST_EVENT_NOTIFIER_HT_SIZE, event_desc); |
| 1153 | |
| 1154 | cds_hlist_for_each_entry_safe(event_notifier_priv, node, tmp_node, head, hlist) { |
| 1155 | if (event_desc == event_notifier_priv->parent.desc) { |
| 1156 | event_func(event_notifier_priv->parent.pub); |
| 1157 | break; |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | static |
| 1165 | void _event_enum_destroy(struct lttng_ust_event_common *event) |
| 1166 | { |
| 1167 | |
| 1168 | switch (event->type) { |
| 1169 | case LTTNG_UST_EVENT_TYPE_RECORDER: |
| 1170 | { |
| 1171 | struct lttng_ust_event_recorder *event_recorder = event->child; |
| 1172 | struct lttng_ust_session *session = event_recorder->chan->parent->session; |
| 1173 | unsigned int i; |
| 1174 | |
| 1175 | /* Destroy enums of the current event. */ |
| 1176 | for (i = 0; i < event_recorder->parent->priv->desc->tp_class->nr_fields; i++) { |
| 1177 | const struct lttng_ust_enum_desc *enum_desc; |
| 1178 | const struct lttng_ust_event_field *field; |
| 1179 | struct lttng_enum *curr_enum; |
| 1180 | |
| 1181 | field = event_recorder->parent->priv->desc->tp_class->fields[i]; |
| 1182 | switch (field->type->type) { |
| 1183 | case lttng_ust_type_enum: |
| 1184 | enum_desc = lttng_ust_get_type_enum(field->type)->desc; |
| 1185 | break; |
| 1186 | default: |
| 1187 | continue; |
| 1188 | } |
| 1189 | |
| 1190 | curr_enum = lttng_ust_enum_get_from_desc(session, enum_desc); |
| 1191 | if (curr_enum) { |
| 1192 | _lttng_enum_destroy(curr_enum); |
| 1193 | } |
| 1194 | } |
| 1195 | break; |
| 1196 | } |
| 1197 | case LTTNG_UST_EVENT_TYPE_NOTIFIER: |
| 1198 | break; |
| 1199 | default: |
| 1200 | abort(); |
| 1201 | } |
| 1202 | /* Destroy event. */ |
| 1203 | _lttng_event_destroy(event); |
| 1204 | } |
| 1205 | |
| 1206 | /* |
| 1207 | * Iterate over all the UST sessions to unregister and destroy all probes from |
| 1208 | * the probe provider descriptor received as argument. Must me called with the |
| 1209 | * ust_lock held. |
| 1210 | */ |
| 1211 | void lttng_probe_provider_unregister_events( |
| 1212 | const struct lttng_ust_probe_desc *provider_desc) |
| 1213 | { |
| 1214 | /* |
| 1215 | * Iterate over all events in the probe provider descriptions and sessions |
| 1216 | * to queue the unregistration of the events. |
| 1217 | */ |
| 1218 | probe_provider_event_for_each(provider_desc, _lttng_event_unregister); |
| 1219 | |
| 1220 | /* Wait for grace period. */ |
| 1221 | lttng_ust_urcu_synchronize_rcu(); |
| 1222 | /* Prune the unregistration queue. */ |
| 1223 | lttng_ust_tp_probe_prune_release_queue(); |
| 1224 | |
| 1225 | /* |
| 1226 | * It is now safe to destroy the events and remove them from the event list |
| 1227 | * and hashtables. |
| 1228 | */ |
| 1229 | probe_provider_event_for_each(provider_desc, _event_enum_destroy); |
| 1230 | } |
| 1231 | |
| 1232 | /* |
| 1233 | * Create events associated with an event enabler (if not already present), |
| 1234 | * and add backward reference from the event to the enabler. |
| 1235 | */ |
| 1236 | static |
| 1237 | int lttng_event_enabler_ref_event_recorders(struct lttng_event_enabler *event_enabler) |
| 1238 | { |
| 1239 | struct lttng_ust_session *session = event_enabler->chan->parent->session; |
| 1240 | struct lttng_ust_event_recorder_private *event_recorder_priv; |
| 1241 | |
| 1242 | if (!lttng_event_enabler_as_enabler(event_enabler)->enabled) |
| 1243 | goto end; |
| 1244 | |
| 1245 | /* First ensure that probe events are created for this enabler. */ |
| 1246 | lttng_create_event_recorder_if_missing(event_enabler); |
| 1247 | |
| 1248 | /* For each event matching enabler in session event list. */ |
| 1249 | cds_list_for_each_entry(event_recorder_priv, &session->priv->events_head, node) { |
| 1250 | struct lttng_enabler_ref *enabler_ref; |
| 1251 | |
| 1252 | if (!lttng_event_enabler_match_event(event_enabler, event_recorder_priv->pub)) |
| 1253 | continue; |
| 1254 | |
| 1255 | enabler_ref = lttng_enabler_ref(&event_recorder_priv->parent.enablers_ref_head, |
| 1256 | lttng_event_enabler_as_enabler(event_enabler)); |
| 1257 | if (!enabler_ref) { |
| 1258 | /* |
| 1259 | * If no backward ref, create it. |
| 1260 | * Add backward ref from event to enabler. |
| 1261 | */ |
| 1262 | enabler_ref = zmalloc(sizeof(*enabler_ref)); |
| 1263 | if (!enabler_ref) |
| 1264 | return -ENOMEM; |
| 1265 | enabler_ref->ref = lttng_event_enabler_as_enabler( |
| 1266 | event_enabler); |
| 1267 | cds_list_add(&enabler_ref->node, |
| 1268 | &event_recorder_priv->parent.enablers_ref_head); |
| 1269 | } |
| 1270 | |
| 1271 | /* |
| 1272 | * Link filter bytecodes if not linked yet. |
| 1273 | */ |
| 1274 | lttng_enabler_link_bytecode(event_recorder_priv->parent.desc, |
| 1275 | &session->priv->ctx, |
| 1276 | &event_recorder_priv->parent.filter_bytecode_runtime_head, |
| 1277 | <tng_event_enabler_as_enabler(event_enabler)->filter_bytecode_head); |
| 1278 | |
| 1279 | /* TODO: merge event context. */ |
| 1280 | } |
| 1281 | end: |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | /* |
| 1286 | * Called at library load: connect the probe on all enablers matching |
| 1287 | * this event. |
| 1288 | * Called with session mutex held. |
| 1289 | */ |
| 1290 | int lttng_fix_pending_events(void) |
| 1291 | { |
| 1292 | struct lttng_ust_session_private *session_priv; |
| 1293 | |
| 1294 | cds_list_for_each_entry(session_priv, &sessions, node) { |
| 1295 | lttng_session_lazy_sync_event_enablers(session_priv->pub); |
| 1296 | } |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | int lttng_fix_pending_event_notifiers(void) |
| 1301 | { |
| 1302 | struct lttng_event_notifier_group *event_notifier_group; |
| 1303 | |
| 1304 | cds_list_for_each_entry(event_notifier_group, &event_notifier_groups, node) { |
| 1305 | lttng_event_notifier_group_sync_enablers(event_notifier_group); |
| 1306 | } |
| 1307 | return 0; |
| 1308 | } |
| 1309 | |
| 1310 | /* |
| 1311 | * For each session of the owner thread, execute pending statedump. |
| 1312 | * Only dump state for the sessions owned by the caller thread, because |
| 1313 | * we don't keep ust_lock across the entire iteration. |
| 1314 | */ |
| 1315 | void lttng_handle_pending_statedump(void *owner) |
| 1316 | { |
| 1317 | struct lttng_ust_session_private *session_priv; |
| 1318 | |
| 1319 | /* Execute state dump */ |
| 1320 | do_lttng_ust_statedump(owner); |
| 1321 | |
| 1322 | /* Clear pending state dump */ |
| 1323 | if (ust_lock()) { |
| 1324 | goto end; |
| 1325 | } |
| 1326 | cds_list_for_each_entry(session_priv, &sessions, node) { |
| 1327 | if (session_priv->owner != owner) |
| 1328 | continue; |
| 1329 | if (!session_priv->statedump_pending) |
| 1330 | continue; |
| 1331 | session_priv->statedump_pending = 0; |
| 1332 | } |
| 1333 | end: |
| 1334 | ust_unlock(); |
| 1335 | return; |
| 1336 | } |
| 1337 | |
| 1338 | static |
| 1339 | void _lttng_event_destroy(struct lttng_ust_event_common *event) |
| 1340 | { |
| 1341 | struct lttng_enabler_ref *enabler_ref, *tmp_enabler_ref; |
| 1342 | |
| 1343 | lttng_free_event_filter_runtime(event); |
| 1344 | /* Free event enabler refs */ |
| 1345 | cds_list_for_each_entry_safe(enabler_ref, tmp_enabler_ref, |
| 1346 | &event->priv->enablers_ref_head, node) |
| 1347 | free(enabler_ref); |
| 1348 | |
| 1349 | switch (event->type) { |
| 1350 | case LTTNG_UST_EVENT_TYPE_RECORDER: |
| 1351 | { |
| 1352 | struct lttng_ust_event_recorder *event_recorder = event->child; |
| 1353 | |
| 1354 | /* Remove from event list. */ |
| 1355 | cds_list_del(&event_recorder->priv->node); |
| 1356 | /* Remove from event hash table. */ |
| 1357 | cds_hlist_del(&event_recorder->priv->hlist); |
| 1358 | |
| 1359 | lttng_destroy_context(event_recorder->priv->ctx); |
| 1360 | free(event_recorder->parent); |
| 1361 | free(event_recorder->priv); |
| 1362 | free(event_recorder); |
| 1363 | break; |
| 1364 | } |
| 1365 | case LTTNG_UST_EVENT_TYPE_NOTIFIER: |
| 1366 | { |
| 1367 | struct lttng_ust_event_notifier *event_notifier = event->child; |
| 1368 | |
| 1369 | /* Remove from event list. */ |
| 1370 | cds_list_del(&event_notifier->priv->node); |
| 1371 | /* Remove from event hash table. */ |
| 1372 | cds_hlist_del(&event_notifier->priv->hlist); |
| 1373 | |
| 1374 | free(event_notifier->priv); |
| 1375 | free(event_notifier->parent); |
| 1376 | free(event_notifier); |
| 1377 | break; |
| 1378 | } |
| 1379 | default: |
| 1380 | abort(); |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | static |
| 1385 | void _lttng_enum_destroy(struct lttng_enum *_enum) |
| 1386 | { |
| 1387 | cds_list_del(&_enum->node); |
| 1388 | cds_hlist_del(&_enum->hlist); |
| 1389 | free(_enum); |
| 1390 | } |
| 1391 | |
| 1392 | void lttng_ust_abi_events_exit(void) |
| 1393 | { |
| 1394 | struct lttng_ust_session_private *session_priv, *tmpsession_priv; |
| 1395 | |
| 1396 | cds_list_for_each_entry_safe(session_priv, tmpsession_priv, &sessions, node) |
| 1397 | lttng_session_destroy(session_priv->pub); |
| 1398 | } |
| 1399 | |
| 1400 | /* |
| 1401 | * Enabler management. |
| 1402 | */ |
| 1403 | struct lttng_event_enabler *lttng_event_enabler_create( |
| 1404 | enum lttng_enabler_format_type format_type, |
| 1405 | struct lttng_ust_abi_event *event_param, |
| 1406 | struct lttng_ust_channel_buffer *chan) |
| 1407 | { |
| 1408 | struct lttng_event_enabler *event_enabler; |
| 1409 | |
| 1410 | event_enabler = zmalloc(sizeof(*event_enabler)); |
| 1411 | if (!event_enabler) |
| 1412 | return NULL; |
| 1413 | event_enabler->base.format_type = format_type; |
| 1414 | CDS_INIT_LIST_HEAD(&event_enabler->base.filter_bytecode_head); |
| 1415 | CDS_INIT_LIST_HEAD(&event_enabler->base.excluder_head); |
| 1416 | memcpy(&event_enabler->base.event_param, event_param, |
| 1417 | sizeof(event_enabler->base.event_param)); |
| 1418 | event_enabler->chan = chan; |
| 1419 | /* ctx left NULL */ |
| 1420 | event_enabler->base.enabled = 0; |
| 1421 | cds_list_add(&event_enabler->node, &event_enabler->chan->parent->session->priv->enablers_head); |
| 1422 | lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent->session); |
| 1423 | |
| 1424 | return event_enabler; |
| 1425 | } |
| 1426 | |
| 1427 | struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( |
| 1428 | struct lttng_event_notifier_group *event_notifier_group, |
| 1429 | enum lttng_enabler_format_type format_type, |
| 1430 | struct lttng_ust_abi_event_notifier *event_notifier_param) |
| 1431 | { |
| 1432 | struct lttng_event_notifier_enabler *event_notifier_enabler; |
| 1433 | |
| 1434 | event_notifier_enabler = zmalloc(sizeof(*event_notifier_enabler)); |
| 1435 | if (!event_notifier_enabler) |
| 1436 | return NULL; |
| 1437 | event_notifier_enabler->base.format_type = format_type; |
| 1438 | CDS_INIT_LIST_HEAD(&event_notifier_enabler->base.filter_bytecode_head); |
| 1439 | CDS_INIT_LIST_HEAD(&event_notifier_enabler->capture_bytecode_head); |
| 1440 | CDS_INIT_LIST_HEAD(&event_notifier_enabler->base.excluder_head); |
| 1441 | |
| 1442 | event_notifier_enabler->user_token = event_notifier_param->event.token; |
| 1443 | event_notifier_enabler->error_counter_index = event_notifier_param->error_counter_index; |
| 1444 | event_notifier_enabler->num_captures = 0; |
| 1445 | |
| 1446 | memcpy(&event_notifier_enabler->base.event_param.name, |
| 1447 | event_notifier_param->event.name, |
| 1448 | sizeof(event_notifier_enabler->base.event_param.name)); |
| 1449 | event_notifier_enabler->base.event_param.instrumentation = |
| 1450 | event_notifier_param->event.instrumentation; |
| 1451 | event_notifier_enabler->base.event_param.loglevel = |
| 1452 | event_notifier_param->event.loglevel; |
| 1453 | event_notifier_enabler->base.event_param.loglevel_type = |
| 1454 | event_notifier_param->event.loglevel_type; |
| 1455 | |
| 1456 | event_notifier_enabler->base.enabled = 0; |
| 1457 | event_notifier_enabler->group = event_notifier_group; |
| 1458 | |
| 1459 | cds_list_add(&event_notifier_enabler->node, |
| 1460 | &event_notifier_group->enablers_head); |
| 1461 | |
| 1462 | lttng_event_notifier_group_sync_enablers(event_notifier_group); |
| 1463 | |
| 1464 | return event_notifier_enabler; |
| 1465 | } |
| 1466 | |
| 1467 | int lttng_event_enabler_enable(struct lttng_event_enabler *event_enabler) |
| 1468 | { |
| 1469 | lttng_event_enabler_as_enabler(event_enabler)->enabled = 1; |
| 1470 | lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent->session); |
| 1471 | |
| 1472 | return 0; |
| 1473 | } |
| 1474 | |
| 1475 | int lttng_event_enabler_disable(struct lttng_event_enabler *event_enabler) |
| 1476 | { |
| 1477 | lttng_event_enabler_as_enabler(event_enabler)->enabled = 0; |
| 1478 | lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent->session); |
| 1479 | |
| 1480 | return 0; |
| 1481 | } |
| 1482 | |
| 1483 | static |
| 1484 | void _lttng_enabler_attach_filter_bytecode(struct lttng_enabler *enabler, |
| 1485 | struct lttng_ust_bytecode_node **bytecode) |
| 1486 | { |
| 1487 | (*bytecode)->enabler = enabler; |
| 1488 | cds_list_add_tail(&(*bytecode)->node, &enabler->filter_bytecode_head); |
| 1489 | /* Take ownership of bytecode */ |
| 1490 | *bytecode = NULL; |
| 1491 | } |
| 1492 | |
| 1493 | int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler *event_enabler, |
| 1494 | struct lttng_ust_bytecode_node **bytecode) |
| 1495 | { |
| 1496 | _lttng_enabler_attach_filter_bytecode( |
| 1497 | lttng_event_enabler_as_enabler(event_enabler), bytecode); |
| 1498 | |
| 1499 | lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent->session); |
| 1500 | return 0; |
| 1501 | } |
| 1502 | |
| 1503 | static |
| 1504 | void _lttng_enabler_attach_exclusion(struct lttng_enabler *enabler, |
| 1505 | struct lttng_ust_excluder_node **excluder) |
| 1506 | { |
| 1507 | (*excluder)->enabler = enabler; |
| 1508 | cds_list_add_tail(&(*excluder)->node, &enabler->excluder_head); |
| 1509 | /* Take ownership of excluder */ |
| 1510 | *excluder = NULL; |
| 1511 | } |
| 1512 | |
| 1513 | int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *event_enabler, |
| 1514 | struct lttng_ust_excluder_node **excluder) |
| 1515 | { |
| 1516 | _lttng_enabler_attach_exclusion( |
| 1517 | lttng_event_enabler_as_enabler(event_enabler), excluder); |
| 1518 | |
| 1519 | lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent->session); |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
| 1523 | int lttng_event_notifier_enabler_enable( |
| 1524 | struct lttng_event_notifier_enabler *event_notifier_enabler) |
| 1525 | { |
| 1526 | lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)->enabled = 1; |
| 1527 | lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group); |
| 1528 | |
| 1529 | return 0; |
| 1530 | } |
| 1531 | |
| 1532 | int lttng_event_notifier_enabler_disable( |
| 1533 | struct lttng_event_notifier_enabler *event_notifier_enabler) |
| 1534 | { |
| 1535 | lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)->enabled = 0; |
| 1536 | lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group); |
| 1537 | |
| 1538 | return 0; |
| 1539 | } |
| 1540 | |
| 1541 | int lttng_event_notifier_enabler_attach_filter_bytecode( |
| 1542 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
| 1543 | struct lttng_ust_bytecode_node **bytecode) |
| 1544 | { |
| 1545 | _lttng_enabler_attach_filter_bytecode( |
| 1546 | lttng_event_notifier_enabler_as_enabler(event_notifier_enabler), |
| 1547 | bytecode); |
| 1548 | |
| 1549 | lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group); |
| 1550 | return 0; |
| 1551 | } |
| 1552 | |
| 1553 | int lttng_event_notifier_enabler_attach_capture_bytecode( |
| 1554 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
| 1555 | struct lttng_ust_bytecode_node **bytecode) |
| 1556 | { |
| 1557 | (*bytecode)->enabler = lttng_event_notifier_enabler_as_enabler( |
| 1558 | event_notifier_enabler); |
| 1559 | cds_list_add_tail(&(*bytecode)->node, |
| 1560 | &event_notifier_enabler->capture_bytecode_head); |
| 1561 | /* Take ownership of bytecode */ |
| 1562 | *bytecode = NULL; |
| 1563 | event_notifier_enabler->num_captures++; |
| 1564 | |
| 1565 | lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group); |
| 1566 | return 0; |
| 1567 | } |
| 1568 | |
| 1569 | int lttng_event_notifier_enabler_attach_exclusion( |
| 1570 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
| 1571 | struct lttng_ust_excluder_node **excluder) |
| 1572 | { |
| 1573 | _lttng_enabler_attach_exclusion( |
| 1574 | lttng_event_notifier_enabler_as_enabler(event_notifier_enabler), |
| 1575 | excluder); |
| 1576 | |
| 1577 | lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group); |
| 1578 | return 0; |
| 1579 | } |
| 1580 | |
| 1581 | int lttng_attach_context(struct lttng_ust_abi_context *context_param, |
| 1582 | union lttng_ust_abi_args *uargs, |
| 1583 | struct lttng_ust_ctx **ctx, struct lttng_ust_session *session) |
| 1584 | { |
| 1585 | /* |
| 1586 | * We cannot attach a context after trace has been started for a |
| 1587 | * session because the metadata does not allow expressing this |
| 1588 | * information outside of the original channel scope. |
| 1589 | */ |
| 1590 | if (session->priv->been_active) |
| 1591 | return -EPERM; |
| 1592 | |
| 1593 | switch (context_param->ctx) { |
| 1594 | case LTTNG_UST_ABI_CONTEXT_PTHREAD_ID: |
| 1595 | return lttng_add_pthread_id_to_ctx(ctx); |
| 1596 | case LTTNG_UST_ABI_CONTEXT_PERF_THREAD_COUNTER: |
| 1597 | { |
| 1598 | struct lttng_ust_abi_perf_counter_ctx *perf_ctx_param; |
| 1599 | |
| 1600 | perf_ctx_param = &context_param->u.perf_counter; |
| 1601 | return lttng_add_perf_counter_to_ctx( |
| 1602 | perf_ctx_param->type, |
| 1603 | perf_ctx_param->config, |
| 1604 | perf_ctx_param->name, |
| 1605 | ctx); |
| 1606 | } |
| 1607 | case LTTNG_UST_ABI_CONTEXT_VTID: |
| 1608 | return lttng_add_vtid_to_ctx(ctx); |
| 1609 | case LTTNG_UST_ABI_CONTEXT_VPID: |
| 1610 | return lttng_add_vpid_to_ctx(ctx); |
| 1611 | case LTTNG_UST_ABI_CONTEXT_PROCNAME: |
| 1612 | return lttng_add_procname_to_ctx(ctx); |
| 1613 | case LTTNG_UST_ABI_CONTEXT_IP: |
| 1614 | return lttng_add_ip_to_ctx(ctx); |
| 1615 | case LTTNG_UST_ABI_CONTEXT_CPU_ID: |
| 1616 | return lttng_add_cpu_id_to_ctx(ctx); |
| 1617 | case LTTNG_UST_ABI_CONTEXT_APP_CONTEXT: |
| 1618 | return lttng_ust_add_app_context_to_ctx_rcu(uargs->app_context.ctxname, |
| 1619 | ctx); |
| 1620 | case LTTNG_UST_ABI_CONTEXT_CGROUP_NS: |
| 1621 | return lttng_add_cgroup_ns_to_ctx(ctx); |
| 1622 | case LTTNG_UST_ABI_CONTEXT_IPC_NS: |
| 1623 | return lttng_add_ipc_ns_to_ctx(ctx); |
| 1624 | case LTTNG_UST_ABI_CONTEXT_MNT_NS: |
| 1625 | return lttng_add_mnt_ns_to_ctx(ctx); |
| 1626 | case LTTNG_UST_ABI_CONTEXT_NET_NS: |
| 1627 | return lttng_add_net_ns_to_ctx(ctx); |
| 1628 | case LTTNG_UST_ABI_CONTEXT_PID_NS: |
| 1629 | return lttng_add_pid_ns_to_ctx(ctx); |
| 1630 | case LTTNG_UST_ABI_CONTEXT_TIME_NS: |
| 1631 | return lttng_add_time_ns_to_ctx(ctx); |
| 1632 | case LTTNG_UST_ABI_CONTEXT_USER_NS: |
| 1633 | return lttng_add_user_ns_to_ctx(ctx); |
| 1634 | case LTTNG_UST_ABI_CONTEXT_UTS_NS: |
| 1635 | return lttng_add_uts_ns_to_ctx(ctx); |
| 1636 | case LTTNG_UST_ABI_CONTEXT_VUID: |
| 1637 | return lttng_add_vuid_to_ctx(ctx); |
| 1638 | case LTTNG_UST_ABI_CONTEXT_VEUID: |
| 1639 | return lttng_add_veuid_to_ctx(ctx); |
| 1640 | case LTTNG_UST_ABI_CONTEXT_VSUID: |
| 1641 | return lttng_add_vsuid_to_ctx(ctx); |
| 1642 | case LTTNG_UST_ABI_CONTEXT_VGID: |
| 1643 | return lttng_add_vgid_to_ctx(ctx); |
| 1644 | case LTTNG_UST_ABI_CONTEXT_VEGID: |
| 1645 | return lttng_add_vegid_to_ctx(ctx); |
| 1646 | case LTTNG_UST_ABI_CONTEXT_VSGID: |
| 1647 | return lttng_add_vsgid_to_ctx(ctx); |
| 1648 | default: |
| 1649 | return -EINVAL; |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | int lttng_event_enabler_attach_context( |
| 1654 | struct lttng_event_enabler *enabler __attribute__((unused)), |
| 1655 | struct lttng_ust_abi_context *context_param __attribute__((unused))) |
| 1656 | { |
| 1657 | return -ENOSYS; |
| 1658 | } |
| 1659 | |
| 1660 | void lttng_event_enabler_destroy(struct lttng_event_enabler *event_enabler) |
| 1661 | { |
| 1662 | if (!event_enabler) { |
| 1663 | return; |
| 1664 | } |
| 1665 | cds_list_del(&event_enabler->node); |
| 1666 | |
| 1667 | lttng_enabler_destroy(lttng_event_enabler_as_enabler(event_enabler)); |
| 1668 | |
| 1669 | lttng_destroy_context(event_enabler->ctx); |
| 1670 | free(event_enabler); |
| 1671 | } |
| 1672 | |
| 1673 | /* |
| 1674 | * lttng_session_sync_event_enablers should be called just before starting a |
| 1675 | * session. |
| 1676 | */ |
| 1677 | static |
| 1678 | void lttng_session_sync_event_enablers(struct lttng_ust_session *session) |
| 1679 | { |
| 1680 | struct lttng_event_enabler *event_enabler; |
| 1681 | struct lttng_ust_event_recorder_private *event_recorder_priv; |
| 1682 | |
| 1683 | cds_list_for_each_entry(event_enabler, &session->priv->enablers_head, node) |
| 1684 | lttng_event_enabler_ref_event_recorders(event_enabler); |
| 1685 | /* |
| 1686 | * For each event, if at least one of its enablers is enabled, |
| 1687 | * and its channel and session transient states are enabled, we |
| 1688 | * enable the event, else we disable it. |
| 1689 | */ |
| 1690 | cds_list_for_each_entry(event_recorder_priv, &session->priv->events_head, node) { |
| 1691 | struct lttng_enabler_ref *enabler_ref; |
| 1692 | struct lttng_ust_bytecode_runtime *runtime; |
| 1693 | int enabled = 0, has_enablers_without_filter_bytecode = 0; |
| 1694 | int nr_filters = 0; |
| 1695 | |
| 1696 | /* Enable events */ |
| 1697 | cds_list_for_each_entry(enabler_ref, |
| 1698 | &event_recorder_priv->parent.enablers_ref_head, node) { |
| 1699 | if (enabler_ref->ref->enabled) { |
| 1700 | enabled = 1; |
| 1701 | break; |
| 1702 | } |
| 1703 | } |
| 1704 | /* |
| 1705 | * Enabled state is based on union of enablers, with |
| 1706 | * intesection of session and channel transient enable |
| 1707 | * states. |
| 1708 | */ |
| 1709 | enabled = enabled && session->priv->tstate && event_recorder_priv->pub->chan->priv->parent.tstate; |
| 1710 | |
| 1711 | CMM_STORE_SHARED(event_recorder_priv->pub->parent->enabled, enabled); |
| 1712 | /* |
| 1713 | * Sync tracepoint registration with event enabled |
| 1714 | * state. |
| 1715 | */ |
| 1716 | if (enabled) { |
| 1717 | if (!event_recorder_priv->parent.registered) |
| 1718 | register_event(event_recorder_priv->parent.pub); |
| 1719 | } else { |
| 1720 | if (event_recorder_priv->parent.registered) |
| 1721 | unregister_event(event_recorder_priv->parent.pub); |
| 1722 | } |
| 1723 | |
| 1724 | /* Check if has enablers without bytecode enabled */ |
| 1725 | cds_list_for_each_entry(enabler_ref, |
| 1726 | &event_recorder_priv->parent.enablers_ref_head, node) { |
| 1727 | if (enabler_ref->ref->enabled |
| 1728 | && cds_list_empty(&enabler_ref->ref->filter_bytecode_head)) { |
| 1729 | has_enablers_without_filter_bytecode = 1; |
| 1730 | break; |
| 1731 | } |
| 1732 | } |
| 1733 | event_recorder_priv->parent.has_enablers_without_filter_bytecode = |
| 1734 | has_enablers_without_filter_bytecode; |
| 1735 | |
| 1736 | /* Enable filters */ |
| 1737 | cds_list_for_each_entry(runtime, |
| 1738 | &event_recorder_priv->parent.filter_bytecode_runtime_head, node) { |
| 1739 | lttng_bytecode_sync_state(runtime); |
| 1740 | nr_filters++; |
| 1741 | } |
| 1742 | CMM_STORE_SHARED(event_recorder_priv->parent.pub->eval_filter, |
| 1743 | !(has_enablers_without_filter_bytecode || !nr_filters)); |
| 1744 | } |
| 1745 | lttng_ust_tp_probe_prune_release_queue(); |
| 1746 | } |
| 1747 | |
| 1748 | /* Support for event notifier is introduced by probe provider major version 2. */ |
| 1749 | static |
| 1750 | bool lttng_ust_probe_supports_event_notifier(const struct lttng_ust_probe_desc *probe_desc) |
| 1751 | { |
| 1752 | return probe_desc->major >= 2; |
| 1753 | } |
| 1754 | |
| 1755 | static |
| 1756 | void lttng_create_event_notifier_if_missing( |
| 1757 | struct lttng_event_notifier_enabler *event_notifier_enabler) |
| 1758 | { |
| 1759 | struct lttng_event_notifier_group *event_notifier_group = event_notifier_enabler->group; |
| 1760 | struct lttng_ust_registered_probe *reg_probe; |
| 1761 | struct cds_list_head *probe_list; |
| 1762 | int i; |
| 1763 | |
| 1764 | probe_list = lttng_get_probe_list_head(); |
| 1765 | |
| 1766 | cds_list_for_each_entry(reg_probe, probe_list, head) { |
| 1767 | const struct lttng_ust_probe_desc *probe_desc = reg_probe->desc; |
| 1768 | |
| 1769 | for (i = 0; i < probe_desc->nr_events; i++) { |
| 1770 | int ret; |
| 1771 | bool found = false; |
| 1772 | const struct lttng_ust_event_desc *desc; |
| 1773 | struct lttng_ust_event_notifier_private *event_notifier_priv; |
| 1774 | struct cds_hlist_head *head; |
| 1775 | struct cds_hlist_node *node; |
| 1776 | |
| 1777 | desc = probe_desc->event_desc[i]; |
| 1778 | |
| 1779 | if (!lttng_desc_match_enabler(desc, |
| 1780 | lttng_event_notifier_enabler_as_enabler(event_notifier_enabler))) |
| 1781 | continue; |
| 1782 | |
| 1783 | /* |
| 1784 | * Given the current event_notifier group, get the bucket that |
| 1785 | * the target event_notifier would be if it was already |
| 1786 | * created. |
| 1787 | */ |
| 1788 | head = borrow_hash_table_bucket( |
| 1789 | event_notifier_group->event_notifiers_ht.table, |
| 1790 | LTTNG_UST_EVENT_NOTIFIER_HT_SIZE, desc); |
| 1791 | |
| 1792 | cds_hlist_for_each_entry(event_notifier_priv, node, head, hlist) { |
| 1793 | /* |
| 1794 | * Check if event_notifier already exists by checking |
| 1795 | * if the event_notifier and enabler share the same |
| 1796 | * description and id. |
| 1797 | */ |
| 1798 | if (event_notifier_priv->parent.desc == desc && |
| 1799 | event_notifier_priv->parent.user_token == event_notifier_enabler->user_token) { |
| 1800 | found = true; |
| 1801 | break; |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | if (found) |
| 1806 | continue; |
| 1807 | |
| 1808 | /* Check that the probe supports event notifiers, else report the error. */ |
| 1809 | if (!lttng_ust_probe_supports_event_notifier(probe_desc)) { |
| 1810 | ERR("Probe \"%s\" contains event \"%s:%s\" which matches an enabled event notifier, " |
| 1811 | "but its version (%u.%u) is too old and does not implement event notifiers. " |
| 1812 | "It needs to be recompiled against a newer version of LTTng-UST, otherwise " |
| 1813 | "this event will not generate any notification.", |
| 1814 | probe_desc->provider_name, |
| 1815 | probe_desc->provider_name, desc->event_name, |
| 1816 | probe_desc->major, |
| 1817 | probe_desc->minor); |
| 1818 | continue; |
| 1819 | } |
| 1820 | /* |
| 1821 | * We need to create a event_notifier for this event probe. |
| 1822 | */ |
| 1823 | ret = lttng_event_notifier_create(desc, |
| 1824 | event_notifier_enabler->user_token, |
| 1825 | event_notifier_enabler->error_counter_index, |
| 1826 | event_notifier_group); |
| 1827 | if (ret) { |
| 1828 | DBG("Unable to create event_notifier \"%s:%s\", error %d\n", |
| 1829 | probe_desc->provider_name, |
| 1830 | probe_desc->event_desc[i]->event_name, ret); |
| 1831 | } |
| 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | /* |
| 1837 | * Create event_notifiers associated with a event_notifier enabler (if not already present). |
| 1838 | */ |
| 1839 | static |
| 1840 | int lttng_event_notifier_enabler_ref_event_notifiers( |
| 1841 | struct lttng_event_notifier_enabler *event_notifier_enabler) |
| 1842 | { |
| 1843 | struct lttng_event_notifier_group *event_notifier_group = event_notifier_enabler->group; |
| 1844 | struct lttng_ust_event_notifier_private *event_notifier_priv; |
| 1845 | |
| 1846 | /* |
| 1847 | * Only try to create event_notifiers for enablers that are enabled, the user |
| 1848 | * might still be attaching filter or exclusion to the |
| 1849 | * event_notifier_enabler. |
| 1850 | */ |
| 1851 | if (!lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)->enabled) |
| 1852 | goto end; |
| 1853 | |
| 1854 | /* First, ensure that probe event_notifiers are created for this enabler. */ |
| 1855 | lttng_create_event_notifier_if_missing(event_notifier_enabler); |
| 1856 | |
| 1857 | /* Link the created event_notifier with its associated enabler. */ |
| 1858 | cds_list_for_each_entry(event_notifier_priv, &event_notifier_group->event_notifiers_head, node) { |
| 1859 | struct lttng_enabler_ref *enabler_ref; |
| 1860 | |
| 1861 | if (!lttng_event_notifier_enabler_match_event_notifier(event_notifier_enabler, event_notifier_priv->pub)) |
| 1862 | continue; |
| 1863 | |
| 1864 | enabler_ref = lttng_enabler_ref(&event_notifier_priv->parent.enablers_ref_head, |
| 1865 | lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)); |
| 1866 | if (!enabler_ref) { |
| 1867 | /* |
| 1868 | * If no backward ref, create it. |
| 1869 | * Add backward ref from event_notifier to enabler. |
| 1870 | */ |
| 1871 | enabler_ref = zmalloc(sizeof(*enabler_ref)); |
| 1872 | if (!enabler_ref) |
| 1873 | return -ENOMEM; |
| 1874 | |
| 1875 | enabler_ref->ref = lttng_event_notifier_enabler_as_enabler( |
| 1876 | event_notifier_enabler); |
| 1877 | cds_list_add(&enabler_ref->node, |
| 1878 | &event_notifier_priv->parent.enablers_ref_head); |
| 1879 | } |
| 1880 | |
| 1881 | /* |
| 1882 | * Link filter bytecodes if not linked yet. |
| 1883 | */ |
| 1884 | lttng_enabler_link_bytecode(event_notifier_priv->parent.desc, |
| 1885 | &event_notifier_group->ctx, |
| 1886 | &event_notifier_priv->parent.filter_bytecode_runtime_head, |
| 1887 | <tng_event_notifier_enabler_as_enabler(event_notifier_enabler)->filter_bytecode_head); |
| 1888 | |
| 1889 | /* |
| 1890 | * Link capture bytecodes if not linked yet. |
| 1891 | */ |
| 1892 | lttng_enabler_link_bytecode(event_notifier_priv->parent.desc, |
| 1893 | &event_notifier_group->ctx, &event_notifier_priv->capture_bytecode_runtime_head, |
| 1894 | &event_notifier_enabler->capture_bytecode_head); |
| 1895 | |
| 1896 | event_notifier_priv->num_captures = event_notifier_enabler->num_captures; |
| 1897 | } |
| 1898 | end: |
| 1899 | return 0; |
| 1900 | } |
| 1901 | |
| 1902 | static |
| 1903 | void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group *event_notifier_group) |
| 1904 | { |
| 1905 | struct lttng_event_notifier_enabler *event_notifier_enabler; |
| 1906 | struct lttng_ust_event_notifier_private *event_notifier_priv; |
| 1907 | |
| 1908 | cds_list_for_each_entry(event_notifier_enabler, &event_notifier_group->enablers_head, node) |
| 1909 | lttng_event_notifier_enabler_ref_event_notifiers(event_notifier_enabler); |
| 1910 | |
| 1911 | /* |
| 1912 | * For each event_notifier, if at least one of its enablers is enabled, |
| 1913 | * we enable the event_notifier, else we disable it. |
| 1914 | */ |
| 1915 | cds_list_for_each_entry(event_notifier_priv, &event_notifier_group->event_notifiers_head, node) { |
| 1916 | struct lttng_enabler_ref *enabler_ref; |
| 1917 | struct lttng_ust_bytecode_runtime *runtime; |
| 1918 | int enabled = 0, has_enablers_without_filter_bytecode = 0; |
| 1919 | int nr_filters = 0, nr_captures = 0; |
| 1920 | |
| 1921 | /* Enable event_notifiers */ |
| 1922 | cds_list_for_each_entry(enabler_ref, |
| 1923 | &event_notifier_priv->parent.enablers_ref_head, node) { |
| 1924 | if (enabler_ref->ref->enabled) { |
| 1925 | enabled = 1; |
| 1926 | break; |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | CMM_STORE_SHARED(event_notifier_priv->pub->parent->enabled, enabled); |
| 1931 | /* |
| 1932 | * Sync tracepoint registration with event_notifier enabled |
| 1933 | * state. |
| 1934 | */ |
| 1935 | if (enabled) { |
| 1936 | if (!event_notifier_priv->parent.registered) |
| 1937 | register_event(event_notifier_priv->parent.pub); |
| 1938 | } else { |
| 1939 | if (event_notifier_priv->parent.registered) |
| 1940 | unregister_event(event_notifier_priv->parent.pub); |
| 1941 | } |
| 1942 | |
| 1943 | /* Check if has enablers without bytecode enabled */ |
| 1944 | cds_list_for_each_entry(enabler_ref, |
| 1945 | &event_notifier_priv->parent.enablers_ref_head, node) { |
| 1946 | if (enabler_ref->ref->enabled |
| 1947 | && cds_list_empty(&enabler_ref->ref->filter_bytecode_head)) { |
| 1948 | has_enablers_without_filter_bytecode = 1; |
| 1949 | break; |
| 1950 | } |
| 1951 | } |
| 1952 | event_notifier_priv->parent.has_enablers_without_filter_bytecode = |
| 1953 | has_enablers_without_filter_bytecode; |
| 1954 | |
| 1955 | /* Enable filters */ |
| 1956 | cds_list_for_each_entry(runtime, |
| 1957 | &event_notifier_priv->parent.filter_bytecode_runtime_head, node) { |
| 1958 | lttng_bytecode_sync_state(runtime); |
| 1959 | nr_filters++; |
| 1960 | } |
| 1961 | CMM_STORE_SHARED(event_notifier_priv->parent.pub->eval_filter, |
| 1962 | !(has_enablers_without_filter_bytecode || !nr_filters)); |
| 1963 | |
| 1964 | /* Enable captures. */ |
| 1965 | cds_list_for_each_entry(runtime, |
| 1966 | &event_notifier_priv->capture_bytecode_runtime_head, node) { |
| 1967 | lttng_bytecode_sync_state(runtime); |
| 1968 | nr_captures++; |
| 1969 | } |
| 1970 | CMM_STORE_SHARED(event_notifier_priv->pub->eval_capture, |
| 1971 | !!nr_captures); |
| 1972 | } |
| 1973 | lttng_ust_tp_probe_prune_release_queue(); |
| 1974 | } |
| 1975 | |
| 1976 | /* |
| 1977 | * Apply enablers to session events, adding events to session if need |
| 1978 | * be. It is required after each modification applied to an active |
| 1979 | * session, and right before session "start". |
| 1980 | * "lazy" sync means we only sync if required. |
| 1981 | */ |
| 1982 | static |
| 1983 | void lttng_session_lazy_sync_event_enablers(struct lttng_ust_session *session) |
| 1984 | { |
| 1985 | /* We can skip if session is not active */ |
| 1986 | if (!session->active) |
| 1987 | return; |
| 1988 | lttng_session_sync_event_enablers(session); |
| 1989 | } |
| 1990 | |
| 1991 | /* |
| 1992 | * Update all sessions with the given app context. |
| 1993 | * Called with ust lock held. |
| 1994 | * This is invoked when an application context gets loaded/unloaded. It |
| 1995 | * ensures the context callbacks are in sync with the application |
| 1996 | * context (either app context callbacks, or dummy callbacks). |
| 1997 | */ |
| 1998 | void lttng_ust_context_set_session_provider(const char *name, |
| 1999 | size_t (*get_size)(void *priv, struct lttng_ust_probe_ctx *probe_ctx, |
| 2000 | size_t offset), |
| 2001 | void (*record)(void *priv, struct lttng_ust_probe_ctx *probe_ctx, |
| 2002 | struct lttng_ust_ring_buffer_ctx *ctx, |
| 2003 | struct lttng_ust_channel_buffer *chan), |
| 2004 | void (*get_value)(void *priv, struct lttng_ust_probe_ctx *probe_ctx, |
| 2005 | struct lttng_ust_ctx_value *value), |
| 2006 | void *priv) |
| 2007 | { |
| 2008 | struct lttng_ust_session_private *session_priv; |
| 2009 | |
| 2010 | cds_list_for_each_entry(session_priv, &sessions, node) { |
| 2011 | struct lttng_ust_channel_buffer_private *chan; |
| 2012 | struct lttng_ust_event_recorder_private *event_recorder_priv; |
| 2013 | int ret; |
| 2014 | |
| 2015 | ret = lttng_ust_context_set_provider_rcu(&session_priv->ctx, |
| 2016 | name, get_size, record, get_value, priv); |
| 2017 | if (ret) |
| 2018 | abort(); |
| 2019 | cds_list_for_each_entry(chan, &session_priv->chan_head, node) { |
| 2020 | ret = lttng_ust_context_set_provider_rcu(&chan->ctx, |
| 2021 | name, get_size, record, get_value, priv); |
| 2022 | if (ret) |
| 2023 | abort(); |
| 2024 | } |
| 2025 | cds_list_for_each_entry(event_recorder_priv, &session_priv->events_head, node) { |
| 2026 | ret = lttng_ust_context_set_provider_rcu(&event_recorder_priv->ctx, |
| 2027 | name, get_size, record, get_value, priv); |
| 2028 | if (ret) |
| 2029 | abort(); |
| 2030 | } |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | /* |
| 2035 | * Update all event_notifier groups with the given app context. |
| 2036 | * Called with ust lock held. |
| 2037 | * This is invoked when an application context gets loaded/unloaded. It |
| 2038 | * ensures the context callbacks are in sync with the application |
| 2039 | * context (either app context callbacks, or dummy callbacks). |
| 2040 | */ |
| 2041 | void lttng_ust_context_set_event_notifier_group_provider(const char *name, |
| 2042 | size_t (*get_size)(void *priv, struct lttng_ust_probe_ctx *probe_ctx, |
| 2043 | size_t offset), |
| 2044 | void (*record)(void *priv, struct lttng_ust_probe_ctx *probe_ctx, |
| 2045 | struct lttng_ust_ring_buffer_ctx *ctx, |
| 2046 | struct lttng_ust_channel_buffer *chan), |
| 2047 | void (*get_value)(void *priv, struct lttng_ust_probe_ctx *probe_ctx, |
| 2048 | struct lttng_ust_ctx_value *value), |
| 2049 | void *priv) |
| 2050 | { |
| 2051 | struct lttng_event_notifier_group *event_notifier_group; |
| 2052 | |
| 2053 | cds_list_for_each_entry(event_notifier_group, &event_notifier_groups, node) { |
| 2054 | int ret; |
| 2055 | |
| 2056 | ret = lttng_ust_context_set_provider_rcu( |
| 2057 | &event_notifier_group->ctx, |
| 2058 | name, get_size, record, get_value, priv); |
| 2059 | if (ret) |
| 2060 | abort(); |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | int lttng_ust_session_uuid_validate(struct lttng_ust_session *session, |
| 2065 | unsigned char *uuid) |
| 2066 | { |
| 2067 | if (!session) |
| 2068 | return 0; |
| 2069 | /* Compare UUID with session. */ |
| 2070 | if (session->priv->uuid_set) { |
| 2071 | if (memcmp(session->priv->uuid, uuid, LTTNG_UST_UUID_LEN)) { |
| 2072 | return -1; |
| 2073 | } |
| 2074 | } else { |
| 2075 | memcpy(session->priv->uuid, uuid, LTTNG_UST_UUID_LEN); |
| 2076 | session->priv->uuid_set = true; |
| 2077 | } |
| 2078 | return 0; |
| 2079 | |
| 2080 | } |