| 1 | /* |
| 2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License, version 2 only, |
| 6 | * as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | */ |
| 17 | |
| 18 | #ifndef _LTT_UST_APP_H |
| 19 | #define _LTT_UST_APP_H |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | |
| 23 | #include <common/compat/uuid.h> |
| 24 | #include "trace-ust.h" |
| 25 | #include "ust-registry.h" |
| 26 | |
| 27 | /* lttng-ust supported version. */ |
| 28 | //#define LTTNG_UST_COMM_MAJOR 2 /* comm protocol major version */ |
| 29 | //#define UST_APP_MAJOR_VERSION 3 /* Internal UST version supported */ |
| 30 | |
| 31 | #define UST_APP_EVENT_LIST_SIZE 32 |
| 32 | |
| 33 | /* Process name (short). Extra for the NULL byte. */ |
| 34 | #define UST_APP_PROCNAME_LEN 17 |
| 35 | |
| 36 | struct lttng_filter_bytecode; |
| 37 | struct lttng_ust_filter_bytecode; |
| 38 | |
| 39 | extern int ust_consumerd64_fd, ust_consumerd32_fd; |
| 40 | |
| 41 | struct ust_app_ht_key { |
| 42 | const char *name; |
| 43 | const struct lttng_ust_filter_bytecode *filter; |
| 44 | enum lttng_ust_loglevel_type loglevel; |
| 45 | }; |
| 46 | |
| 47 | /* |
| 48 | * Application registration data structure. |
| 49 | */ |
| 50 | struct ust_register_msg { |
| 51 | enum ustctl_socket_type type; |
| 52 | uint32_t major; |
| 53 | uint32_t minor; |
| 54 | uint32_t abi_major; |
| 55 | uint32_t abi_minor; |
| 56 | pid_t pid; |
| 57 | pid_t ppid; |
| 58 | uid_t uid; |
| 59 | gid_t gid; |
| 60 | uint32_t bits_per_long; |
| 61 | uint32_t uint8_t_alignment; |
| 62 | uint32_t uint16_t_alignment; |
| 63 | uint32_t uint32_t_alignment; |
| 64 | uint32_t uint64_t_alignment; |
| 65 | uint32_t long_alignment; |
| 66 | int byte_order; /* BIG_ENDIAN or LITTLE_ENDIAN */ |
| 67 | char name[LTTNG_UST_ABI_PROCNAME_LEN]; |
| 68 | }; |
| 69 | |
| 70 | /* |
| 71 | * Global applications HT used by the session daemon. This table is indexed by |
| 72 | * PID using the pid_n node and pid value of an ust_app. |
| 73 | */ |
| 74 | struct lttng_ht *ust_app_ht; |
| 75 | |
| 76 | /* |
| 77 | * Global applications HT used by the session daemon. This table is indexed by |
| 78 | * socket using the sock_n node and sock value of an ust_app. |
| 79 | */ |
| 80 | struct lttng_ht *ust_app_ht_by_sock; |
| 81 | |
| 82 | /* |
| 83 | * Global applications HT used by the session daemon. This table is indexed by |
| 84 | * socket using the notify_sock_n node and notify_sock value of an ust_app. |
| 85 | */ |
| 86 | struct lttng_ht *ust_app_ht_by_notify_sock; |
| 87 | |
| 88 | /* Stream list containing ust_app_stream. */ |
| 89 | struct ust_app_stream_list { |
| 90 | unsigned int count; |
| 91 | struct cds_list_head head; |
| 92 | }; |
| 93 | |
| 94 | struct ust_app_ctx { |
| 95 | int handle; |
| 96 | struct lttng_ust_context ctx; |
| 97 | struct lttng_ust_object_data *obj; |
| 98 | struct lttng_ht_node_ulong node; |
| 99 | }; |
| 100 | |
| 101 | struct ust_app_event { |
| 102 | int enabled; |
| 103 | int handle; |
| 104 | struct lttng_ust_object_data *obj; |
| 105 | struct lttng_ust_event attr; |
| 106 | char name[LTTNG_UST_SYM_NAME_LEN]; |
| 107 | struct lttng_ht_node_str node; |
| 108 | struct lttng_ust_filter_bytecode *filter; |
| 109 | }; |
| 110 | |
| 111 | struct ust_app_stream { |
| 112 | int handle; |
| 113 | char pathname[PATH_MAX]; |
| 114 | /* Format is %s_%d respectively channel name and CPU number. */ |
| 115 | char name[DEFAULT_STREAM_NAME_LEN]; |
| 116 | struct lttng_ust_object_data *obj; |
| 117 | /* Using a list of streams to keep order. */ |
| 118 | struct cds_list_head list; |
| 119 | }; |
| 120 | |
| 121 | struct ust_app_channel { |
| 122 | int enabled; |
| 123 | int handle; |
| 124 | /* Channel and streams were sent to the UST tracer. */ |
| 125 | int is_sent; |
| 126 | /* Unique key used to identify the channel on the consumer side. */ |
| 127 | unsigned long key; |
| 128 | /* Number of stream that this channel is expected to receive. */ |
| 129 | unsigned int expected_stream_count; |
| 130 | char name[LTTNG_UST_SYM_NAME_LEN]; |
| 131 | struct lttng_ust_object_data *obj; |
| 132 | struct ustctl_consumer_channel_attr attr; |
| 133 | struct ust_app_stream_list streams; |
| 134 | /* Session pointer that owns this object. */ |
| 135 | struct ust_app_session *session; |
| 136 | struct lttng_ht *ctx; |
| 137 | struct lttng_ht *events; |
| 138 | /* |
| 139 | * UST event registry. The ONLY writer is the application thread. |
| 140 | */ |
| 141 | struct ust_registry_channel registry; |
| 142 | /* |
| 143 | * Node indexed by channel name in the channels' hash table of a session. |
| 144 | */ |
| 145 | struct lttng_ht_node_str node; |
| 146 | /* |
| 147 | * Node indexed by UST channel object descriptor (handle). Stored in the |
| 148 | * ust_objd hash table in the ust_app object. |
| 149 | */ |
| 150 | struct lttng_ht_node_ulong ust_objd_node; |
| 151 | }; |
| 152 | |
| 153 | struct ust_app_session { |
| 154 | /* |
| 155 | * Lock protecting this session's ust app interaction. Held |
| 156 | * across command send/recv to/from app. Never nests within the |
| 157 | * session registry lock. |
| 158 | */ |
| 159 | pthread_mutex_t lock; |
| 160 | |
| 161 | int enabled; |
| 162 | /* started: has the session been in started state at any time ? */ |
| 163 | int started; /* allows detection of start vs restart. */ |
| 164 | int handle; /* used has unique identifier for app session */ |
| 165 | int id; /* session unique identifier */ |
| 166 | struct ust_app_channel *metadata; |
| 167 | struct ust_registry_session registry; |
| 168 | struct lttng_ht *channels; /* Registered channels */ |
| 169 | struct lttng_ht_node_ulong node; |
| 170 | char path[PATH_MAX]; |
| 171 | /* UID/GID of the user owning the session */ |
| 172 | uid_t uid; |
| 173 | gid_t gid; |
| 174 | struct cds_list_head teardown_node; |
| 175 | }; |
| 176 | |
| 177 | /* |
| 178 | * Registered traceable applications. Libust registers to the session daemon |
| 179 | * and a linked list is kept of all running traceable app. |
| 180 | */ |
| 181 | struct ust_app { |
| 182 | int sock; |
| 183 | int notify_sock; |
| 184 | pid_t pid; |
| 185 | pid_t ppid; |
| 186 | uid_t uid; /* User ID that owns the apps */ |
| 187 | gid_t gid; /* Group ID that owns the apps */ |
| 188 | |
| 189 | /* App ABI */ |
| 190 | uint32_t bits_per_long; |
| 191 | uint32_t uint8_t_alignment; |
| 192 | uint32_t uint16_t_alignment; |
| 193 | uint32_t uint32_t_alignment; |
| 194 | uint32_t uint64_t_alignment; |
| 195 | uint32_t long_alignment; |
| 196 | int byte_order; /* BIG_ENDIAN or LITTLE_ENDIAN */ |
| 197 | |
| 198 | int compatible; /* If the lttng-ust tracer version does not match the |
| 199 | supported version of the session daemon, this flag is |
| 200 | set to 0 (NOT compatible) else 1. */ |
| 201 | struct lttng_ust_tracer_version version; |
| 202 | uint32_t v_major; /* Version major number */ |
| 203 | uint32_t v_minor; /* Version minor number */ |
| 204 | char name[UST_APP_PROCNAME_LEN]; |
| 205 | struct lttng_ht *sessions; |
| 206 | struct lttng_ht_node_ulong pid_n; |
| 207 | struct lttng_ht_node_ulong sock_n; |
| 208 | struct lttng_ht_node_ulong notify_sock_n; |
| 209 | /* |
| 210 | * This is a list of ust app session that, once the app is going into |
| 211 | * teardown mode, in the RCU call, each node in this list is removed and |
| 212 | * deleted. |
| 213 | * |
| 214 | * Element of the list are added when an application unregisters after each |
| 215 | * ht_del of ust_app_session associated to this app. This list is NOT used |
| 216 | * when a session is destroyed. |
| 217 | */ |
| 218 | struct cds_list_head teardown_head; |
| 219 | /* |
| 220 | * Hash table containing ust_app_channel indexed by channel objd. |
| 221 | */ |
| 222 | struct lttng_ht *ust_objd; |
| 223 | }; |
| 224 | |
| 225 | #ifdef HAVE_LIBLTTNG_UST_CTL |
| 226 | |
| 227 | int ust_app_register(struct ust_register_msg *msg, int sock); |
| 228 | static inline |
| 229 | int ust_app_register_done(int sock) |
| 230 | { |
| 231 | return ustctl_register_done(sock); |
| 232 | } |
| 233 | int ust_app_version(struct ust_app *app); |
| 234 | void ust_app_unregister(int sock); |
| 235 | unsigned long ust_app_list_count(void); |
| 236 | int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app); |
| 237 | int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app); |
| 238 | int ust_app_start_trace_all(struct ltt_ust_session *usess); |
| 239 | int ust_app_stop_trace_all(struct ltt_ust_session *usess); |
| 240 | int ust_app_destroy_trace_all(struct ltt_ust_session *usess); |
| 241 | int ust_app_list_events(struct lttng_event **events); |
| 242 | int ust_app_list_event_fields(struct lttng_event_field **fields); |
| 243 | int ust_app_create_channel_glb(struct ltt_ust_session *usess, |
| 244 | struct ltt_ust_channel *uchan); |
| 245 | int ust_app_create_event_glb(struct ltt_ust_session *usess, |
| 246 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent); |
| 247 | int ust_app_disable_event_pid(struct ltt_ust_session *usess, |
| 248 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent, |
| 249 | pid_t pid); |
| 250 | int ust_app_enable_event_pid(struct ltt_ust_session *usess, |
| 251 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent, |
| 252 | pid_t pid); |
| 253 | int ust_app_disable_channel_glb(struct ltt_ust_session *usess, |
| 254 | struct ltt_ust_channel *uchan); |
| 255 | int ust_app_enable_channel_glb(struct ltt_ust_session *usess, |
| 256 | struct ltt_ust_channel *uchan); |
| 257 | int ust_app_enable_event_glb(struct ltt_ust_session *usess, |
| 258 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent); |
| 259 | int ust_app_disable_all_event_glb(struct ltt_ust_session *usess, |
| 260 | struct ltt_ust_channel *uchan); |
| 261 | int ust_app_enable_all_event_glb(struct ltt_ust_session *usess, |
| 262 | struct ltt_ust_channel *uchan); |
| 263 | int ust_app_disable_event_glb(struct ltt_ust_session *usess, |
| 264 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent); |
| 265 | int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess, |
| 266 | struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx); |
| 267 | void ust_app_global_update(struct ltt_ust_session *usess, int sock); |
| 268 | |
| 269 | void ust_app_clean_list(void); |
| 270 | void ust_app_ht_alloc(void); |
| 271 | struct lttng_ht *ust_app_get_ht(void); |
| 272 | struct ust_app *ust_app_find_by_pid(pid_t pid); |
| 273 | int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate); |
| 274 | struct ust_app_stream *ust_app_alloc_stream(void); |
| 275 | int ust_app_recv_registration(int sock, struct ust_register_msg *msg); |
| 276 | int ust_app_recv_notify(int sock); |
| 277 | void ust_app_add(struct ust_app *app); |
| 278 | struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock); |
| 279 | |
| 280 | #else /* HAVE_LIBLTTNG_UST_CTL */ |
| 281 | |
| 282 | static inline |
| 283 | int ust_app_destroy_trace_all(struct ltt_ust_session *usess) |
| 284 | { |
| 285 | return 0; |
| 286 | } |
| 287 | static inline |
| 288 | int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app) |
| 289 | { |
| 290 | return 0; |
| 291 | } |
| 292 | static inline |
| 293 | int ust_app_start_trace_all(struct ltt_ust_session *usess) |
| 294 | { |
| 295 | return 0; |
| 296 | } |
| 297 | static inline |
| 298 | int ust_app_stop_trace_all(struct ltt_ust_session *usess) |
| 299 | { |
| 300 | return 0; |
| 301 | } |
| 302 | static inline |
| 303 | int ust_app_list_events(struct lttng_event **events) |
| 304 | { |
| 305 | return -ENOSYS; |
| 306 | } |
| 307 | static inline |
| 308 | int ust_app_list_event_fields(struct lttng_event_field **fields) |
| 309 | { |
| 310 | return -ENOSYS; |
| 311 | } |
| 312 | static inline |
| 313 | int ust_app_register(struct ust_register_msg *msg, int sock) |
| 314 | { |
| 315 | return -ENOSYS; |
| 316 | } |
| 317 | static inline |
| 318 | int ust_app_register_done(int sock) |
| 319 | { |
| 320 | return -ENOSYS; |
| 321 | } |
| 322 | static inline |
| 323 | int ust_app_version(struct ust_app *app) |
| 324 | { |
| 325 | return -ENOSYS; |
| 326 | } |
| 327 | static inline |
| 328 | void ust_app_unregister(int sock) |
| 329 | { |
| 330 | } |
| 331 | static inline |
| 332 | unsigned int ust_app_list_count(void) |
| 333 | { |
| 334 | return 0; |
| 335 | } |
| 336 | static inline |
| 337 | void ust_app_lock_list(void) |
| 338 | { |
| 339 | } |
| 340 | static inline |
| 341 | void ust_app_unlock_list(void) |
| 342 | { |
| 343 | } |
| 344 | static inline |
| 345 | void ust_app_clean_list(void) |
| 346 | { |
| 347 | } |
| 348 | static inline |
| 349 | struct ust_app_list *ust_app_get_list(void) |
| 350 | { |
| 351 | return NULL; |
| 352 | } |
| 353 | static inline |
| 354 | struct ust_app *ust_app_get_by_pid(pid_t pid) |
| 355 | { |
| 356 | return NULL; |
| 357 | } |
| 358 | static inline |
| 359 | struct lttng_ht *ust_app_get_ht(void) |
| 360 | { |
| 361 | return NULL; |
| 362 | } |
| 363 | static inline |
| 364 | void ust_app_ht_alloc(void) |
| 365 | {} |
| 366 | static inline |
| 367 | void ust_app_global_update(struct ltt_ust_session *usess, int sock) |
| 368 | {} |
| 369 | static inline |
| 370 | int ust_app_disable_channel_glb(struct ltt_ust_session *usess, |
| 371 | struct ltt_ust_channel *uchan) |
| 372 | { |
| 373 | return 0; |
| 374 | } |
| 375 | static inline |
| 376 | int ust_app_enable_channel_glb(struct ltt_ust_session *usess, |
| 377 | struct ltt_ust_channel *uchan) |
| 378 | { |
| 379 | return 0; |
| 380 | } |
| 381 | static inline |
| 382 | int ust_app_create_channel_glb(struct ltt_ust_session *usess, |
| 383 | struct ltt_ust_channel *uchan) |
| 384 | { |
| 385 | return 0; |
| 386 | } |
| 387 | static inline |
| 388 | int ust_app_disable_all_event_glb(struct ltt_ust_session *usess, |
| 389 | struct ltt_ust_channel *uchan) |
| 390 | { |
| 391 | return 0; |
| 392 | } |
| 393 | static inline |
| 394 | int ust_app_enable_all_event_glb(struct ltt_ust_session *usess, |
| 395 | struct ltt_ust_channel *uchan) |
| 396 | { |
| 397 | return 0; |
| 398 | } |
| 399 | static inline |
| 400 | int ust_app_create_event_glb(struct ltt_ust_session *usess, |
| 401 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent) |
| 402 | { |
| 403 | return 0; |
| 404 | } |
| 405 | static inline |
| 406 | int ust_app_disable_event_glb(struct ltt_ust_session *usess, |
| 407 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent) |
| 408 | { |
| 409 | return 0; |
| 410 | } |
| 411 | static inline |
| 412 | int ust_app_enable_event_glb(struct ltt_ust_session *usess, |
| 413 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent) |
| 414 | { |
| 415 | return 0; |
| 416 | } |
| 417 | static inline |
| 418 | int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess, |
| 419 | struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx) |
| 420 | { |
| 421 | return 0; |
| 422 | } |
| 423 | static inline |
| 424 | int ust_app_enable_event_pid(struct ltt_ust_session *usess, |
| 425 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent, |
| 426 | pid_t pid) |
| 427 | { |
| 428 | return 0; |
| 429 | } |
| 430 | static inline |
| 431 | int ust_app_disable_event_pid(struct ltt_ust_session *usess, |
| 432 | struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent, |
| 433 | pid_t pid) |
| 434 | { |
| 435 | return 0; |
| 436 | } |
| 437 | static inline |
| 438 | int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate) |
| 439 | { |
| 440 | return 0; |
| 441 | } |
| 442 | static inline |
| 443 | int ust_app_recv_registration(int sock, struct ust_register_msg *msg) |
| 444 | { |
| 445 | return 0; |
| 446 | } |
| 447 | static inline |
| 448 | int ust_app_recv_notify(int sock) |
| 449 | { |
| 450 | return 0; |
| 451 | } |
| 452 | static inline |
| 453 | struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock) |
| 454 | { |
| 455 | return NULL; |
| 456 | } |
| 457 | static inline |
| 458 | void ust_app_add(struct ust_app *app) |
| 459 | { |
| 460 | } |
| 461 | |
| 462 | #endif /* HAVE_LIBLTTNG_UST_CTL */ |
| 463 | |
| 464 | #endif /* _LTT_UST_APP_H */ |