From: Simon Marchi Date: Wed, 15 Dec 2021 20:13:05 +0000 (-0500) Subject: Rename C++ header files to .hpp X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c9e313bc594f40a86eed237dce222c0fc99c957f;p=lttng-tools.git Rename C++ header files to .hpp Rename all C++ header files (include/**/*-internal.h, src/**/*.h except argpar and msgpack, some headers in tests) to have the .hpp extension. Doing so highlights that we include some C++ header files in some test files still compiled as C. This is ok for now, as the files they include don't actually contain C++ code incompatible with C yet, but they could eventually. This is something we can fix later. Change-Id: I8bf326b6b2946a3e26704f3ef3ac5831bbe9bc26 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- diff --git a/doc/examples/trigger-condition-event-matches/notification-client.cpp b/doc/examples/trigger-condition-event-matches/notification-client.cpp index 4a2515569..d1d5d8721 100644 --- a/doc/examples/trigger-condition-event-matches/notification-client.cpp +++ b/doc/examples/trigger-condition-event-matches/notification-client.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include static int print_capture(const struct lttng_condition *condition, const struct lttng_event_field_value *capture, diff --git a/include/Makefile.am b/include/Makefile.am index 6fe724b3a..d840d58dc 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -163,51 +163,51 @@ lttngeventruleinclude_HEADERS= \ lttng/event-rule/user-tracepoint.h noinst_HEADERS = \ - lttng/action/action-internal.h \ - lttng/action/list-internal.h \ - lttng/action/notify-internal.h \ - lttng/action/path-internal.h \ - lttng/action/rotate-session-internal.h \ - lttng/action/snapshot-session-internal.h \ - lttng/action/start-session-internal.h \ - lttng/action/stop-session-internal.h \ - lttng/action/rate-policy-internal.h \ - lttng/channel-internal.h \ - lttng/condition/buffer-usage-internal.h \ - lttng/condition/condition-internal.h \ - lttng/condition/evaluation-internal.h \ - lttng/condition/event-rule-matches-internal.h \ - lttng/condition/session-consumed-size-internal.h \ - lttng/condition/session-rotation-internal.h \ - lttng/domain-internal.h \ - lttng/endpoint-internal.h \ - lttng/error-query-internal.h \ - lttng/event-expr-internal.h \ - lttng/event-field-value-internal.h \ - lttng/event-internal.h \ - lttng/event-rule/event-rule-internal.h \ - lttng/event-rule/jul-logging-internal.h \ - lttng/event-rule/kernel-kprobe-internal.h \ - lttng/event-rule/kernel-syscall-internal.h \ - lttng/event-rule/kernel-tracepoint-internal.h \ - lttng/event-rule/kernel-uprobe-internal.h \ - lttng/event-rule/log4j-logging-internal.h \ - lttng/event-rule/python-logging-internal.h \ - lttng/event-rule/user-tracepoint-internal.h \ - lttng/health-internal.h \ - lttng/kernel-probe-internal.h \ - lttng/load-internal.h \ - lttng/location-internal.h \ - lttng/log-level-rule-internal.h \ - lttng/notification/channel-internal.h \ - lttng/notification/notification-internal.h \ - lttng/ref-internal.h \ - lttng/rotate-internal.h \ - lttng/save-internal.h \ - lttng/session-descriptor-internal.h \ - lttng/session-internal.h \ - lttng/snapshot-internal.h \ - lttng/trigger/trigger-internal.h \ - lttng/userspace-probe-internal.h \ - version.h \ + lttng/action/action-internal.hpp \ + lttng/action/list-internal.hpp \ + lttng/action/notify-internal.hpp \ + lttng/action/path-internal.hpp \ + lttng/action/rotate-session-internal.hpp \ + lttng/action/snapshot-session-internal.hpp \ + lttng/action/start-session-internal.hpp \ + lttng/action/stop-session-internal.hpp \ + lttng/action/rate-policy-internal.hpp \ + lttng/channel-internal.hpp \ + lttng/condition/buffer-usage-internal.hpp \ + lttng/condition/condition-internal.hpp \ + lttng/condition/evaluation-internal.hpp \ + lttng/condition/event-rule-matches-internal.hpp \ + lttng/condition/session-consumed-size-internal.hpp \ + lttng/condition/session-rotation-internal.hpp \ + lttng/domain-internal.hpp \ + lttng/endpoint-internal.hpp \ + lttng/error-query-internal.hpp \ + lttng/event-expr-internal.hpp \ + lttng/event-field-value-internal.hpp \ + lttng/event-internal.hpp \ + lttng/event-rule/event-rule-internal.hpp \ + lttng/event-rule/jul-logging-internal.hpp \ + lttng/event-rule/kernel-kprobe-internal.hpp \ + lttng/event-rule/kernel-syscall-internal.hpp \ + lttng/event-rule/kernel-tracepoint-internal.hpp \ + lttng/event-rule/kernel-uprobe-internal.hpp \ + lttng/event-rule/log4j-logging-internal.hpp \ + lttng/event-rule/python-logging-internal.hpp \ + lttng/event-rule/user-tracepoint-internal.hpp \ + lttng/health-internal.hpp \ + lttng/kernel-probe-internal.hpp \ + lttng/load-internal.hpp \ + lttng/location-internal.hpp \ + lttng/log-level-rule-internal.hpp \ + lttng/notification/channel-internal.hpp \ + lttng/notification/notification-internal.hpp \ + lttng/ref-internal.hpp \ + lttng/rotate-internal.hpp \ + lttng/save-internal.hpp \ + lttng/session-descriptor-internal.hpp \ + lttng/session-internal.hpp \ + lttng/snapshot-internal.hpp \ + lttng/trigger/trigger-internal.hpp \ + lttng/userspace-probe-internal.hpp \ + version.hpp \ version.i diff --git a/include/lttng/action/action-internal.h b/include/lttng/action/action-internal.h deleted file mode 100644 index 71270a835..000000000 --- a/include/lttng/action/action-internal.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_ACTION_INTERNAL_H -#define LTTNG_ACTION_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct lttng_rate_policy; -struct mi_writer; -struct mi_lttng_error_query_callbacks; -struct lttng_trigger; - -typedef bool (*action_validate_cb)(struct lttng_action *action); -typedef void (*action_destroy_cb)(struct lttng_action *action); -typedef int (*action_serialize_cb)(struct lttng_action *action, - struct lttng_payload *payload); -typedef bool (*action_equal_cb)(const struct lttng_action *a, - const struct lttng_action *b); -typedef ssize_t (*action_create_from_payload_cb)( - struct lttng_payload_view *view, - struct lttng_action **action); -typedef const struct lttng_rate_policy *(*action_get_rate_policy_cb)( - const struct lttng_action *action); -typedef enum lttng_action_status (*action_add_error_query_results_cb)( - const struct lttng_action *action, - struct lttng_error_query_results *results); -typedef enum lttng_error_code (*action_mi_serialize_cb)( - const struct lttng_action *condition, struct mi_writer *writer); - -struct lttng_action { - struct urcu_ref ref; - enum lttng_action_type type; - action_validate_cb validate; - action_serialize_cb serialize; - action_equal_cb equal; - action_destroy_cb destroy; - action_get_rate_policy_cb get_rate_policy; - action_add_error_query_results_cb add_error_query_results; - action_mi_serialize_cb mi_serialize; - - /* Internal use only. */ - - /* The number of time the actions was enqueued for execution. */ - uint64_t execution_request_counter; - /* - * The number of time the action was actually executed. - * Action rate policy can impact on this number. - * */ - uint64_t execution_counter; - /* - * The number of time the action execution failed. - * An unsigned long is used to use a type which makes atomic - * operations possible. - */ - unsigned long execution_failure_counter; -}; - -struct lttng_action_comm { - /* enum lttng_action_type */ - int8_t action_type; -} LTTNG_PACKED; - -void lttng_action_init(struct lttng_action *action, - enum lttng_action_type type, - action_validate_cb validate, - action_serialize_cb serialize, - action_equal_cb equal, - action_destroy_cb destroy, - action_get_rate_policy_cb get_rate_policy, - action_add_error_query_results_cb add_error_query_results, - action_mi_serialize_cb mi); - -bool lttng_action_validate(struct lttng_action *action); - -int lttng_action_serialize(struct lttng_action *action, - struct lttng_payload *buf); - -ssize_t lttng_action_create_from_payload(struct lttng_payload_view *view, - struct lttng_action **action); - -bool lttng_action_is_equal(const struct lttng_action *a, - const struct lttng_action *b); - -void lttng_action_get(struct lttng_action *action); - -void lttng_action_put(struct lttng_action *action); - -const char* lttng_action_type_string(enum lttng_action_type action_type); - -void lttng_action_increase_execution_request_count(struct lttng_action *action); - -void lttng_action_increase_execution_count(struct lttng_action *action); - -void lttng_action_increase_execution_failure_count(struct lttng_action *action); - -bool lttng_action_should_execute(const struct lttng_action *action); - -enum lttng_action_status lttng_action_add_error_query_results( - const struct lttng_action *action, - struct lttng_error_query_results *results); - -/* - * For use by the various lttng_action implementation. Implements the default - * behavior to the generic error "execution failure counter" that all actions - * (except list, which passes-through) provide. - */ -enum lttng_action_status lttng_action_generic_add_error_query_results( - const struct lttng_action *action, - struct lttng_error_query_results *results); -enum lttng_error_code lttng_action_mi_serialize(const struct lttng_trigger *trigger, - const struct lttng_action *action, - struct mi_writer *writer, - const struct mi_lttng_error_query_callbacks - *error_query_callbacks, - struct lttng_dynamic_array *action_path_indexes); - -#endif /* LTTNG_ACTION_INTERNAL_H */ diff --git a/include/lttng/action/action-internal.hpp b/include/lttng/action/action-internal.hpp new file mode 100644 index 000000000..996e166ec --- /dev/null +++ b/include/lttng/action/action-internal.hpp @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_ACTION_INTERNAL_H +#define LTTNG_ACTION_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct lttng_rate_policy; +struct mi_writer; +struct mi_lttng_error_query_callbacks; +struct lttng_trigger; + +typedef bool (*action_validate_cb)(struct lttng_action *action); +typedef void (*action_destroy_cb)(struct lttng_action *action); +typedef int (*action_serialize_cb)(struct lttng_action *action, + struct lttng_payload *payload); +typedef bool (*action_equal_cb)(const struct lttng_action *a, + const struct lttng_action *b); +typedef ssize_t (*action_create_from_payload_cb)( + struct lttng_payload_view *view, + struct lttng_action **action); +typedef const struct lttng_rate_policy *(*action_get_rate_policy_cb)( + const struct lttng_action *action); +typedef enum lttng_action_status (*action_add_error_query_results_cb)( + const struct lttng_action *action, + struct lttng_error_query_results *results); +typedef enum lttng_error_code (*action_mi_serialize_cb)( + const struct lttng_action *condition, struct mi_writer *writer); + +struct lttng_action { + struct urcu_ref ref; + enum lttng_action_type type; + action_validate_cb validate; + action_serialize_cb serialize; + action_equal_cb equal; + action_destroy_cb destroy; + action_get_rate_policy_cb get_rate_policy; + action_add_error_query_results_cb add_error_query_results; + action_mi_serialize_cb mi_serialize; + + /* Internal use only. */ + + /* The number of time the actions was enqueued for execution. */ + uint64_t execution_request_counter; + /* + * The number of time the action was actually executed. + * Action rate policy can impact on this number. + * */ + uint64_t execution_counter; + /* + * The number of time the action execution failed. + * An unsigned long is used to use a type which makes atomic + * operations possible. + */ + unsigned long execution_failure_counter; +}; + +struct lttng_action_comm { + /* enum lttng_action_type */ + int8_t action_type; +} LTTNG_PACKED; + +void lttng_action_init(struct lttng_action *action, + enum lttng_action_type type, + action_validate_cb validate, + action_serialize_cb serialize, + action_equal_cb equal, + action_destroy_cb destroy, + action_get_rate_policy_cb get_rate_policy, + action_add_error_query_results_cb add_error_query_results, + action_mi_serialize_cb mi); + +bool lttng_action_validate(struct lttng_action *action); + +int lttng_action_serialize(struct lttng_action *action, + struct lttng_payload *buf); + +ssize_t lttng_action_create_from_payload(struct lttng_payload_view *view, + struct lttng_action **action); + +bool lttng_action_is_equal(const struct lttng_action *a, + const struct lttng_action *b); + +void lttng_action_get(struct lttng_action *action); + +void lttng_action_put(struct lttng_action *action); + +const char* lttng_action_type_string(enum lttng_action_type action_type); + +void lttng_action_increase_execution_request_count(struct lttng_action *action); + +void lttng_action_increase_execution_count(struct lttng_action *action); + +void lttng_action_increase_execution_failure_count(struct lttng_action *action); + +bool lttng_action_should_execute(const struct lttng_action *action); + +enum lttng_action_status lttng_action_add_error_query_results( + const struct lttng_action *action, + struct lttng_error_query_results *results); + +/* + * For use by the various lttng_action implementation. Implements the default + * behavior to the generic error "execution failure counter" that all actions + * (except list, which passes-through) provide. + */ +enum lttng_action_status lttng_action_generic_add_error_query_results( + const struct lttng_action *action, + struct lttng_error_query_results *results); +enum lttng_error_code lttng_action_mi_serialize(const struct lttng_trigger *trigger, + const struct lttng_action *action, + struct mi_writer *writer, + const struct mi_lttng_error_query_callbacks + *error_query_callbacks, + struct lttng_dynamic_array *action_path_indexes); + +#endif /* LTTNG_ACTION_INTERNAL_H */ diff --git a/include/lttng/action/list-internal.h b/include/lttng/action/list-internal.h deleted file mode 100644 index 231755fd6..000000000 --- a/include/lttng/action/list-internal.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2019 Simon Marchi - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_ACTION_LIST_INTERNAL_H -#define LTTNG_ACTION_LIST_INTERNAL_H - -#include - -#include - -struct lttng_action; -struct lttng_payload_view; -struct mi_writer; -struct mi_lttng_error_query_callbacks; -struct lttng_dynamic_array; -struct lttng_trigger; - -/* - * Create an action list from a payload view. - * - * On success, return the number of bytes consumed from `view`, and the created - * list in `*list`. On failure, return -1. - */ -extern ssize_t lttng_action_list_create_from_payload( - struct lttng_payload_view *view, - struct lttng_action **list); - -extern struct lttng_action *lttng_action_list_borrow_mutable_at_index( - const struct lttng_action *list, unsigned int index); - -enum lttng_error_code lttng_action_list_mi_serialize(const struct lttng_trigger *trigger, - const struct lttng_action *action, - struct mi_writer *writer, - const struct mi_lttng_error_query_callbacks - *error_query_callbacks, - struct lttng_dynamic_array *action_path_indexes); - -#endif /* LTTNG_ACTION_LIST_INTERNAL_H */ diff --git a/include/lttng/action/list-internal.hpp b/include/lttng/action/list-internal.hpp new file mode 100644 index 000000000..294a53ca2 --- /dev/null +++ b/include/lttng/action/list-internal.hpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2019 Simon Marchi + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_ACTION_LIST_INTERNAL_H +#define LTTNG_ACTION_LIST_INTERNAL_H + +#include + +#include + +struct lttng_action; +struct lttng_payload_view; +struct mi_writer; +struct mi_lttng_error_query_callbacks; +struct lttng_dynamic_array; +struct lttng_trigger; + +/* + * Create an action list from a payload view. + * + * On success, return the number of bytes consumed from `view`, and the created + * list in `*list`. On failure, return -1. + */ +extern ssize_t lttng_action_list_create_from_payload( + struct lttng_payload_view *view, + struct lttng_action **list); + +extern struct lttng_action *lttng_action_list_borrow_mutable_at_index( + const struct lttng_action *list, unsigned int index); + +enum lttng_error_code lttng_action_list_mi_serialize(const struct lttng_trigger *trigger, + const struct lttng_action *action, + struct mi_writer *writer, + const struct mi_lttng_error_query_callbacks + *error_query_callbacks, + struct lttng_dynamic_array *action_path_indexes); + +#endif /* LTTNG_ACTION_LIST_INTERNAL_H */ diff --git a/include/lttng/action/notify-internal.h b/include/lttng/action/notify-internal.h deleted file mode 100644 index 8588ac295..000000000 --- a/include/lttng/action/notify-internal.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_ACTION_NOTIFY_INTERNAL_H -#define LTTNG_ACTION_NOTIFY_INTERNAL_H - -#include -#include - -struct lttng_action_notify { - struct lttng_action parent; - struct lttng_rate_policy *policy; -}; - -ssize_t lttng_action_notify_create_from_payload( - struct lttng_payload_view *view, - struct lttng_action **action); - -#endif /* LTTNG_ACTION_NOTIFY_INTERNAL_H */ diff --git a/include/lttng/action/notify-internal.hpp b/include/lttng/action/notify-internal.hpp new file mode 100644 index 000000000..c923019c3 --- /dev/null +++ b/include/lttng/action/notify-internal.hpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_ACTION_NOTIFY_INTERNAL_H +#define LTTNG_ACTION_NOTIFY_INTERNAL_H + +#include +#include + +struct lttng_action_notify { + struct lttng_action parent; + struct lttng_rate_policy *policy; +}; + +ssize_t lttng_action_notify_create_from_payload( + struct lttng_payload_view *view, + struct lttng_action **action); + +#endif /* LTTNG_ACTION_NOTIFY_INTERNAL_H */ diff --git a/include/lttng/action/path-internal.h b/include/lttng/action/path-internal.h deleted file mode 100644 index 8a255f0b7..000000000 --- a/include/lttng/action/path-internal.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2021 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_ACTION_PATH_INTERNAL_H -#define LTTNG_ACTION_PATH_INTERNAL_H - -#include -#include -#include -#include -#include -#include - -struct lttng_action_path { - struct lttng_dynamic_array indexes; -}; - -/* Assumes that 'dst' is uninitialized. */ -int lttng_action_path_copy(const struct lttng_action_path *src, - struct lttng_action_path *dst); - -ssize_t lttng_action_path_create_from_payload( - struct lttng_payload_view *view, - struct lttng_action_path **action_path); - -int lttng_action_path_serialize(const struct lttng_action_path *action_path, - struct lttng_payload *payload); - -#endif /* LTTNG_ACTION_PATH_INTERNAL_H */ diff --git a/include/lttng/action/path-internal.hpp b/include/lttng/action/path-internal.hpp new file mode 100644 index 000000000..9b9a4d10d --- /dev/null +++ b/include/lttng/action/path-internal.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_ACTION_PATH_INTERNAL_H +#define LTTNG_ACTION_PATH_INTERNAL_H + +#include +#include +#include +#include +#include +#include + +struct lttng_action_path { + struct lttng_dynamic_array indexes; +}; + +/* Assumes that 'dst' is uninitialized. */ +int lttng_action_path_copy(const struct lttng_action_path *src, + struct lttng_action_path *dst); + +ssize_t lttng_action_path_create_from_payload( + struct lttng_payload_view *view, + struct lttng_action_path **action_path); + +int lttng_action_path_serialize(const struct lttng_action_path *action_path, + struct lttng_payload *payload); + +#endif /* LTTNG_ACTION_PATH_INTERNAL_H */ diff --git a/include/lttng/action/rate-policy-internal.h b/include/lttng/action/rate-policy-internal.h deleted file mode 100644 index b24ed5238..000000000 --- a/include/lttng/action/rate-policy-internal.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2021 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_RATE_POLICY_INTERNAL_H -#define LTTNG_RATE_POLICY_INTERNAL_H - -#include -#include -#include -#include -#include - - -struct mi_writer; - -int lttng_rate_policy_serialize(struct lttng_rate_policy *rate_policy, - struct lttng_payload *buf); - -ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view, - struct lttng_rate_policy **rate_policy); - -bool lttng_rate_policy_is_equal(const struct lttng_rate_policy *a, - const struct lttng_rate_policy *b); - -const char *lttng_rate_policy_type_string( - enum lttng_rate_policy_type rate_policy_type); - -struct lttng_rate_policy *lttng_rate_policy_copy( - const struct lttng_rate_policy *source); - -bool lttng_rate_policy_should_execute( - const struct lttng_rate_policy *policy, uint64_t counter); - -enum lttng_error_code lttng_rate_policy_mi_serialize( - const struct lttng_rate_policy *policy, - struct mi_writer *writer); - -#endif /* LTTNG_RATE_POLICY */ diff --git a/include/lttng/action/rate-policy-internal.hpp b/include/lttng/action/rate-policy-internal.hpp new file mode 100644 index 000000000..5f6eb1f45 --- /dev/null +++ b/include/lttng/action/rate-policy-internal.hpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_RATE_POLICY_INTERNAL_H +#define LTTNG_RATE_POLICY_INTERNAL_H + +#include +#include +#include +#include +#include + + +struct mi_writer; + +int lttng_rate_policy_serialize(struct lttng_rate_policy *rate_policy, + struct lttng_payload *buf); + +ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view, + struct lttng_rate_policy **rate_policy); + +bool lttng_rate_policy_is_equal(const struct lttng_rate_policy *a, + const struct lttng_rate_policy *b); + +const char *lttng_rate_policy_type_string( + enum lttng_rate_policy_type rate_policy_type); + +struct lttng_rate_policy *lttng_rate_policy_copy( + const struct lttng_rate_policy *source); + +bool lttng_rate_policy_should_execute( + const struct lttng_rate_policy *policy, uint64_t counter); + +enum lttng_error_code lttng_rate_policy_mi_serialize( + const struct lttng_rate_policy *policy, + struct mi_writer *writer); + +#endif /* LTTNG_RATE_POLICY */ diff --git a/include/lttng/action/rotate-session-internal.h b/include/lttng/action/rotate-session-internal.h deleted file mode 100644 index 9a451f81c..000000000 --- a/include/lttng/action/rotate-session-internal.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2019 Simon Marchi - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_ACTION_ROTATE_SESSION_INTERNAL_H -#define LTTNG_ACTION_ROTATE_SESSION_INTERNAL_H - -#include - -struct lttng_action; -struct lttng_payload_view; - -/* - * Create a "rotate session" action from a payload view. - * - * On success, return the number of bytes consumed from `view`, and the created - * action in `*action`. On failure, return -1. - */ -extern ssize_t lttng_action_rotate_session_create_from_payload( - struct lttng_payload_view *view, - struct lttng_action **action); - -#endif /* LTTNG_ACTION_ROTATE_SESSION_INTERNAL_H */ diff --git a/include/lttng/action/rotate-session-internal.hpp b/include/lttng/action/rotate-session-internal.hpp new file mode 100644 index 000000000..5030aeac3 --- /dev/null +++ b/include/lttng/action/rotate-session-internal.hpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2019 Simon Marchi + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_ACTION_ROTATE_SESSION_INTERNAL_H +#define LTTNG_ACTION_ROTATE_SESSION_INTERNAL_H + +#include + +struct lttng_action; +struct lttng_payload_view; + +/* + * Create a "rotate session" action from a payload view. + * + * On success, return the number of bytes consumed from `view`, and the created + * action in `*action`. On failure, return -1. + */ +extern ssize_t lttng_action_rotate_session_create_from_payload( + struct lttng_payload_view *view, + struct lttng_action **action); + +#endif /* LTTNG_ACTION_ROTATE_SESSION_INTERNAL_H */ diff --git a/include/lttng/action/snapshot-session-internal.h b/include/lttng/action/snapshot-session-internal.h deleted file mode 100644 index 7396c2960..000000000 --- a/include/lttng/action/snapshot-session-internal.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2019 Simon Marchi - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_ACTION_SNAPSHOT_SESSION_INTERNAL_H -#define LTTNG_ACTION_SNAPSHOT_SESSION_INTERNAL_H - -#include - -#include - -struct lttng_action; -struct lttng_payload_view; - -/* - * Create a "snapshot session" action from a payload view. - * - * On success, return the number of bytes consumed from `view`, and the created - * action in `*action`. On failure, return -1. - */ -extern ssize_t lttng_action_snapshot_session_create_from_payload( - struct lttng_payload_view *view, - struct lttng_action **action); - -#endif /* LTTNG_ACTION_SNAPSHOT_SESSION_INTERNAL_H */ diff --git a/include/lttng/action/snapshot-session-internal.hpp b/include/lttng/action/snapshot-session-internal.hpp new file mode 100644 index 000000000..27a8795ad --- /dev/null +++ b/include/lttng/action/snapshot-session-internal.hpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2019 Simon Marchi + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_ACTION_SNAPSHOT_SESSION_INTERNAL_H +#define LTTNG_ACTION_SNAPSHOT_SESSION_INTERNAL_H + +#include + +#include + +struct lttng_action; +struct lttng_payload_view; + +/* + * Create a "snapshot session" action from a payload view. + * + * On success, return the number of bytes consumed from `view`, and the created + * action in `*action`. On failure, return -1. + */ +extern ssize_t lttng_action_snapshot_session_create_from_payload( + struct lttng_payload_view *view, + struct lttng_action **action); + +#endif /* LTTNG_ACTION_SNAPSHOT_SESSION_INTERNAL_H */ diff --git a/include/lttng/action/start-session-internal.h b/include/lttng/action/start-session-internal.h deleted file mode 100644 index 56ffb71b4..000000000 --- a/include/lttng/action/start-session-internal.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2019 Simon Marchi - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_ACTION_START_SESSION_INTERNAL_H -#define LTTNG_ACTION_START_SESSION_INTERNAL_H - -#include - -struct lttng_action; -struct lttng_payload_view; - -/* - * Create a "start session" action from a payload view. - * - * On success, return the number of bytes consumed from `view`, and the created - * action in `*action`. On failure, return -1. - */ -extern ssize_t lttng_action_start_session_create_from_payload( - struct lttng_payload_view *view, - struct lttng_action **action); - -#endif /* LTTNG_ACTION_START_SESSION_INTERNAL_H */ diff --git a/include/lttng/action/start-session-internal.hpp b/include/lttng/action/start-session-internal.hpp new file mode 100644 index 000000000..44dab1bf1 --- /dev/null +++ b/include/lttng/action/start-session-internal.hpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2019 Simon Marchi + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_ACTION_START_SESSION_INTERNAL_H +#define LTTNG_ACTION_START_SESSION_INTERNAL_H + +#include + +struct lttng_action; +struct lttng_payload_view; + +/* + * Create a "start session" action from a payload view. + * + * On success, return the number of bytes consumed from `view`, and the created + * action in `*action`. On failure, return -1. + */ +extern ssize_t lttng_action_start_session_create_from_payload( + struct lttng_payload_view *view, + struct lttng_action **action); + +#endif /* LTTNG_ACTION_START_SESSION_INTERNAL_H */ diff --git a/include/lttng/action/stop-session-internal.h b/include/lttng/action/stop-session-internal.h deleted file mode 100644 index da4a5aac1..000000000 --- a/include/lttng/action/stop-session-internal.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2019 Simon Marchi - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_ACTION_STOP_SESSION_INTERNAL_H -#define LTTNG_ACTION_STOP_SESSION_INTERNAL_H - -#include - -struct lttng_action; -struct lttng_payload_view; - -/* - * Create a "stop session" action from a payload view. - * - * On success, return the number of bytes consumed from `view`, and the created - * action in `*action`. On failure, return -1. - */ -extern ssize_t lttng_action_stop_session_create_from_payload( - struct lttng_payload_view *view, - struct lttng_action **action); - -#endif /* LTTNG_ACTION_STOP_SESSION_INTERNAL_H */ diff --git a/include/lttng/action/stop-session-internal.hpp b/include/lttng/action/stop-session-internal.hpp new file mode 100644 index 000000000..22055352f --- /dev/null +++ b/include/lttng/action/stop-session-internal.hpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2019 Simon Marchi + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_ACTION_STOP_SESSION_INTERNAL_H +#define LTTNG_ACTION_STOP_SESSION_INTERNAL_H + +#include + +struct lttng_action; +struct lttng_payload_view; + +/* + * Create a "stop session" action from a payload view. + * + * On success, return the number of bytes consumed from `view`, and the created + * action in `*action`. On failure, return -1. + */ +extern ssize_t lttng_action_stop_session_create_from_payload( + struct lttng_payload_view *view, + struct lttng_action **action); + +#endif /* LTTNG_ACTION_STOP_SESSION_INTERNAL_H */ diff --git a/include/lttng/channel-internal.h b/include/lttng/channel-internal.h deleted file mode 100644 index c3e123063..000000000 --- a/include/lttng/channel-internal.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2015 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_CHANNEL_INTERNAL_H -#define LTTNG_CHANNEL_INTERNAL_H - -#include -#include -#include - -struct lttng_dynamic_buffer; -struct lttng_buffer_view; - -struct lttng_channel_extended { - uint64_t discarded_events; - uint64_t lost_packets; - uint64_t monitor_timer_interval; - int64_t blocking_timeout; -} LTTNG_PACKED; - -struct lttng_channel_comm { - /* Includes terminator `\0`. */ - uint32_t name_len; - uint8_t enabled; - - /* attr */ - int8_t overwrite; - uint64_t subbuf_size; - uint64_t num_subbuf; - uint32_t switch_timer_interval; - uint32_t read_timer_interval; - uint8_t output; - uint64_t tracefile_size; - uint64_t tracefile_count; - uint32_t live_timer_interval; - - /* Extended struct */ - uint64_t discarded_events; - uint64_t lost_packets; - uint64_t monitor_timer_interval; - int64_t blocking_timeout; -} LTTNG_PACKED; - -struct lttng_channel *lttng_channel_create_internal(void); - -struct lttng_channel *lttng_channel_copy(const struct lttng_channel *src); - -ssize_t lttng_channel_create_from_buffer(const struct lttng_buffer_view *view, - struct lttng_channel **event); - -int lttng_channel_serialize(struct lttng_channel *channel, - struct lttng_dynamic_buffer *buf); - -void lttng_channel_set_default_extended_attr(struct lttng_domain *domain, - struct lttng_channel_extended *extended_attr); - -enum lttng_error_code lttng_channels_create_and_flatten_from_buffer( - const struct lttng_buffer_view *view, - unsigned int count, - struct lttng_channel **channels); - -#endif /* LTTNG_CHANNEL_INTERNAL_H */ diff --git a/include/lttng/channel-internal.hpp b/include/lttng/channel-internal.hpp new file mode 100644 index 000000000..d4960828e --- /dev/null +++ b/include/lttng/channel-internal.hpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2015 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_CHANNEL_INTERNAL_H +#define LTTNG_CHANNEL_INTERNAL_H + +#include + +struct lttng_channel_extended { + uint64_t discarded_events; + uint64_t lost_packets; + uint64_t monitor_timer_interval; + int64_t blocking_timeout; +} LTTNG_PACKED; + +struct lttng_channel_comm { + /* Includes terminator `\0`. */ + uint32_t name_len; + uint8_t enabled; + + /* attr */ + int8_t overwrite; + uint64_t subbuf_size; + uint64_t num_subbuf; + uint32_t switch_timer_interval; + uint32_t read_timer_interval; + uint8_t output; + uint64_t tracefile_size; + uint64_t tracefile_count; + uint32_t live_timer_interval; + + /* Extended struct */ + uint64_t discarded_events; + uint64_t lost_packets; + uint64_t monitor_timer_interval; + int64_t blocking_timeout; +} LTTNG_PACKED; + +struct lttng_channel *lttng_channel_create_internal(void); + +struct lttng_channel *lttng_channel_copy(const struct lttng_channel *src); + +ssize_t lttng_channel_create_from_buffer(const struct lttng_buffer_view *view, + struct lttng_channel **event); + +int lttng_channel_serialize(struct lttng_channel *channel, + struct lttng_dynamic_buffer *buf); + +void lttng_channel_set_default_extended_attr(struct lttng_domain *domain, + struct lttng_channel_extended *extended_attr); + +enum lttng_error_code lttng_channels_create_and_flatten_from_buffer( + const struct lttng_buffer_view *view, + unsigned int count, + struct lttng_channel **channels); + +#endif /* LTTNG_CHANNEL_INTERNAL_H */ diff --git a/include/lttng/condition/buffer-usage-internal.h b/include/lttng/condition/buffer-usage-internal.h deleted file mode 100644 index 1e6d5a509..000000000 --- a/include/lttng/condition/buffer-usage-internal.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_CONDITION_BUFFER_USAGE_INTERNAL_H -#define LTTNG_CONDITION_BUFFER_USAGE_INTERNAL_H - -#include -#include -#include -#include -#include "common/buffer-view.h" -#include - -struct lttng_condition_buffer_usage { - struct lttng_condition parent; - struct { - bool set; - uint64_t value; - } threshold_bytes; - struct { - bool set; - double value; - } threshold_ratio; - char *session_name; - char *channel_name; - struct { - bool set; - enum lttng_domain_type type; - } domain; -}; - -struct lttng_condition_buffer_usage_comm { - uint8_t threshold_set_in_bytes; - uint64_t threshold_bytes; - double threshold_ratio; - /* Both lengths include the trailing \0. */ - uint32_t session_name_len; - uint32_t channel_name_len; - /* enum lttng_domain_type */ - int8_t domain_type; - /* session and channel names. */ - char names[]; -} LTTNG_PACKED; - -struct lttng_evaluation_buffer_usage { - struct lttng_evaluation parent; - uint64_t buffer_use; - uint64_t buffer_capacity; -}; - -struct lttng_evaluation_buffer_usage_comm { - uint64_t buffer_use; - uint64_t buffer_capacity; -} LTTNG_PACKED; - -struct lttng_evaluation *lttng_evaluation_buffer_usage_create( - enum lttng_condition_type type, uint64_t use, - uint64_t capacity); - -ssize_t lttng_condition_buffer_usage_low_create_from_payload( - struct lttng_payload_view *view, - struct lttng_condition **condition); - -ssize_t lttng_condition_buffer_usage_high_create_from_payload( - struct lttng_payload_view *view, - struct lttng_condition **condition); - -ssize_t lttng_evaluation_buffer_usage_low_create_from_payload( - struct lttng_payload_view *view, - struct lttng_evaluation **evaluation); - -ssize_t lttng_evaluation_buffer_usage_high_create_from_payload( - struct lttng_payload_view *view, - struct lttng_evaluation **evaluation); - -#endif /* LTTNG_CONDITION_BUFFER_USAGE_INTERNAL_H */ diff --git a/include/lttng/condition/buffer-usage-internal.hpp b/include/lttng/condition/buffer-usage-internal.hpp new file mode 100644 index 000000000..b2e6f85c1 --- /dev/null +++ b/include/lttng/condition/buffer-usage-internal.hpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_CONDITION_BUFFER_USAGE_INTERNAL_H +#define LTTNG_CONDITION_BUFFER_USAGE_INTERNAL_H + +#include +#include +#include +#include +#include "common/buffer-view.hpp" +#include + +struct lttng_condition_buffer_usage { + struct lttng_condition parent; + struct { + bool set; + uint64_t value; + } threshold_bytes; + struct { + bool set; + double value; + } threshold_ratio; + char *session_name; + char *channel_name; + struct { + bool set; + enum lttng_domain_type type; + } domain; +}; + +struct lttng_condition_buffer_usage_comm { + uint8_t threshold_set_in_bytes; + uint64_t threshold_bytes; + double threshold_ratio; + /* Both lengths include the trailing \0. */ + uint32_t session_name_len; + uint32_t channel_name_len; + /* enum lttng_domain_type */ + int8_t domain_type; + /* session and channel names. */ + char names[]; +} LTTNG_PACKED; + +struct lttng_evaluation_buffer_usage { + struct lttng_evaluation parent; + uint64_t buffer_use; + uint64_t buffer_capacity; +}; + +struct lttng_evaluation_buffer_usage_comm { + uint64_t buffer_use; + uint64_t buffer_capacity; +} LTTNG_PACKED; + +struct lttng_evaluation *lttng_evaluation_buffer_usage_create( + enum lttng_condition_type type, uint64_t use, + uint64_t capacity); + +ssize_t lttng_condition_buffer_usage_low_create_from_payload( + struct lttng_payload_view *view, + struct lttng_condition **condition); + +ssize_t lttng_condition_buffer_usage_high_create_from_payload( + struct lttng_payload_view *view, + struct lttng_condition **condition); + +ssize_t lttng_evaluation_buffer_usage_low_create_from_payload( + struct lttng_payload_view *view, + struct lttng_evaluation **evaluation); + +ssize_t lttng_evaluation_buffer_usage_high_create_from_payload( + struct lttng_payload_view *view, + struct lttng_evaluation **evaluation); + +#endif /* LTTNG_CONDITION_BUFFER_USAGE_INTERNAL_H */ diff --git a/include/lttng/condition/condition-internal.h b/include/lttng/condition/condition-internal.h deleted file mode 100644 index 5bafaf05b..000000000 --- a/include/lttng/condition/condition-internal.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_CONDITION_INTERNAL_H -#define LTTNG_CONDITION_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct mi_writer; -struct mi_lttng_error_query_callbacks; -struct lttng_trigger; - -typedef void (*condition_destroy_cb)(struct lttng_condition *condition); -typedef bool (*condition_validate_cb)(const struct lttng_condition *condition); -typedef int (*condition_serialize_cb)( - const struct lttng_condition *condition, - struct lttng_payload *payload); -typedef bool (*condition_equal_cb)(const struct lttng_condition *a, - const struct lttng_condition *b); -typedef ssize_t (*condition_create_from_payload_cb)( - struct lttng_payload_view *view, - struct lttng_condition **condition); -typedef enum lttng_error_code (*condition_mi_serialize_cb)( - const struct lttng_condition *condition, - struct mi_writer *writer); - -struct lttng_condition { - /* Reference counting is only exposed to internal users. */ - struct urcu_ref ref; - enum lttng_condition_type type; - condition_validate_cb validate; - condition_serialize_cb serialize; - condition_equal_cb equal; - condition_destroy_cb destroy; - condition_mi_serialize_cb mi_serialize; -}; - -struct lttng_condition_comm { - /* enum lttng_condition_type */ - int8_t condition_type; - char payload[]; -}; - -void lttng_condition_get(struct lttng_condition *condition); - -void lttng_condition_put(struct lttng_condition *condition); - -void lttng_condition_init(struct lttng_condition *condition, - enum lttng_condition_type type); - -bool lttng_condition_validate(const struct lttng_condition *condition); - -ssize_t lttng_condition_create_from_payload( - struct lttng_payload_view *view, - struct lttng_condition **condition); - -int lttng_condition_serialize(const struct lttng_condition *condition, - struct lttng_payload *payload); - -bool lttng_condition_is_equal(const struct lttng_condition *a, - const struct lttng_condition *b); - -enum lttng_error_code lttng_condition_mi_serialize( - const struct lttng_trigger *trigger, - const struct lttng_condition *condition, - struct mi_writer *writer, - const struct mi_lttng_error_query_callbacks - *error_query_callbacks); - -const char *lttng_condition_type_str(enum lttng_condition_type type); - -#endif /* LTTNG_CONDITION_INTERNAL_H */ diff --git a/include/lttng/condition/condition-internal.hpp b/include/lttng/condition/condition-internal.hpp new file mode 100644 index 000000000..27407d07a --- /dev/null +++ b/include/lttng/condition/condition-internal.hpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_CONDITION_INTERNAL_H +#define LTTNG_CONDITION_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct mi_writer; +struct mi_lttng_error_query_callbacks; +struct lttng_trigger; + +typedef void (*condition_destroy_cb)(struct lttng_condition *condition); +typedef bool (*condition_validate_cb)(const struct lttng_condition *condition); +typedef int (*condition_serialize_cb)( + const struct lttng_condition *condition, + struct lttng_payload *payload); +typedef bool (*condition_equal_cb)(const struct lttng_condition *a, + const struct lttng_condition *b); +typedef ssize_t (*condition_create_from_payload_cb)( + struct lttng_payload_view *view, + struct lttng_condition **condition); +typedef enum lttng_error_code (*condition_mi_serialize_cb)( + const struct lttng_condition *condition, + struct mi_writer *writer); + +struct lttng_condition { + /* Reference counting is only exposed to internal users. */ + struct urcu_ref ref; + enum lttng_condition_type type; + condition_validate_cb validate; + condition_serialize_cb serialize; + condition_equal_cb equal; + condition_destroy_cb destroy; + condition_mi_serialize_cb mi_serialize; +}; + +struct lttng_condition_comm { + /* enum lttng_condition_type */ + int8_t condition_type; + char payload[]; +}; + +void lttng_condition_get(struct lttng_condition *condition); + +void lttng_condition_put(struct lttng_condition *condition); + +void lttng_condition_init(struct lttng_condition *condition, + enum lttng_condition_type type); + +bool lttng_condition_validate(const struct lttng_condition *condition); + +ssize_t lttng_condition_create_from_payload( + struct lttng_payload_view *view, + struct lttng_condition **condition); + +int lttng_condition_serialize(const struct lttng_condition *condition, + struct lttng_payload *payload); + +bool lttng_condition_is_equal(const struct lttng_condition *a, + const struct lttng_condition *b); + +enum lttng_error_code lttng_condition_mi_serialize( + const struct lttng_trigger *trigger, + const struct lttng_condition *condition, + struct mi_writer *writer, + const struct mi_lttng_error_query_callbacks + *error_query_callbacks); + +const char *lttng_condition_type_str(enum lttng_condition_type type); + +#endif /* LTTNG_CONDITION_INTERNAL_H */ diff --git a/include/lttng/condition/evaluation-internal.h b/include/lttng/condition/evaluation-internal.h deleted file mode 100644 index 12ea104d8..000000000 --- a/include/lttng/condition/evaluation-internal.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVALUATION_INTERNAL_H -#define LTTNG_EVALUATION_INTERNAL_H - -#include -#include -#include -#include -#include - -struct lttng_payload; -struct lttng_payload_view; - -typedef void (*evaluation_destroy_cb)(struct lttng_evaluation *evaluation); -typedef int (*evaluation_serialize_cb)( - const struct lttng_evaluation *evaluation, - struct lttng_payload *payload); - -struct lttng_evaluation_comm { - /* enum lttng_condition_type type */ - int8_t type; - char payload[]; -} LTTNG_PACKED; - -struct lttng_evaluation { - enum lttng_condition_type type; - evaluation_serialize_cb serialize; - evaluation_destroy_cb destroy; -}; - -void lttng_evaluation_init(struct lttng_evaluation *evaluation, - enum lttng_condition_type type); - -ssize_t lttng_evaluation_create_from_payload( - const struct lttng_condition *condition, - struct lttng_payload_view *view, - struct lttng_evaluation **evaluation); - -int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation, - struct lttng_payload *payload); - -#endif /* LTTNG_EVALUATION_INTERNAL_H */ diff --git a/include/lttng/condition/evaluation-internal.hpp b/include/lttng/condition/evaluation-internal.hpp new file mode 100644 index 000000000..f74927c24 --- /dev/null +++ b/include/lttng/condition/evaluation-internal.hpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVALUATION_INTERNAL_H +#define LTTNG_EVALUATION_INTERNAL_H + +#include +#include +#include +#include +#include + +struct lttng_payload; +struct lttng_payload_view; + +typedef void (*evaluation_destroy_cb)(struct lttng_evaluation *evaluation); +typedef int (*evaluation_serialize_cb)( + const struct lttng_evaluation *evaluation, + struct lttng_payload *payload); + +struct lttng_evaluation_comm { + /* enum lttng_condition_type type */ + int8_t type; + char payload[]; +} LTTNG_PACKED; + +struct lttng_evaluation { + enum lttng_condition_type type; + evaluation_serialize_cb serialize; + evaluation_destroy_cb destroy; +}; + +void lttng_evaluation_init(struct lttng_evaluation *evaluation, + enum lttng_condition_type type); + +ssize_t lttng_evaluation_create_from_payload( + const struct lttng_condition *condition, + struct lttng_payload_view *view, + struct lttng_evaluation **evaluation); + +int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation, + struct lttng_payload *payload); + +#endif /* LTTNG_EVALUATION_INTERNAL_H */ diff --git a/include/lttng/condition/event-rule-matches-internal.h b/include/lttng/condition/event-rule-matches-internal.h deleted file mode 100644 index ef39f4f04..000000000 --- a/include/lttng/condition/event-rule-matches-internal.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2019 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_CONDITION_EVENT_RULE_MATCHES_INTERNAL_H -#define LTTNG_CONDITION_EVENT_RULE_MATCHES_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include - -struct lttng_capture_descriptor { - struct lttng_event_expr *event_expression; - struct lttng_bytecode *bytecode; -}; - -struct lttng_condition_event_rule_matches { - struct lttng_condition parent; - struct lttng_event_rule *rule; - - /* - * Internal use only. - * Error accounting counter index. - */ - LTTNG_OPTIONAL(uint64_t) error_counter_index; - - /* Array of `struct lttng_capture_descriptor *`. */ - struct lttng_dynamic_pointer_array capture_descriptors; -}; - -struct lttng_evaluation_event_rule_matches { - struct lttng_evaluation parent; - - /* MessagePack-encoded captured event field values. */ - struct lttng_dynamic_buffer capture_payload; - - /* - * The content of this array event field value is the decoded - * version of `capture_payload` above. - * - * This is a cache: it's not serialized/deserialized in - * communications from/to the library and the session daemon. - */ - struct lttng_event_field_value *captured_values; -}; - -ssize_t lttng_condition_event_rule_matches_create_from_payload( - struct lttng_payload_view *view, - struct lttng_condition **condition); - -enum lttng_condition_status -lttng_condition_event_rule_matches_borrow_rule_mutable( - const struct lttng_condition *condition, - struct lttng_event_rule **rule); - -void lttng_condition_event_rule_matches_set_error_counter_index( - struct lttng_condition *condition, - uint64_t error_counter_index); - -uint64_t lttng_condition_event_rule_matches_get_error_counter_index( - const struct lttng_condition *condition); - -struct lttng_evaluation *lttng_evaluation_event_rule_matches_create( - const struct lttng_condition_event_rule_matches *condition, - const char *capture_payload, - size_t capture_payload_size, - bool decode_capture_payload); - -ssize_t lttng_evaluation_event_rule_matches_create_from_payload( - const struct lttng_condition_event_rule_matches *condition, - struct lttng_payload_view *view, - struct lttng_evaluation **_evaluation); - -enum lttng_error_code -lttng_condition_event_rule_matches_generate_capture_descriptor_bytecode( - struct lttng_condition *condition); - -const struct lttng_bytecode * -lttng_condition_event_rule_matches_get_capture_bytecode_at_index( - const struct lttng_condition *condition, unsigned int index); - -#endif /* LTTNG_CONDITION_EVENT_RULE_MATCHES_INTERNAL_H */ diff --git a/include/lttng/condition/event-rule-matches-internal.hpp b/include/lttng/condition/event-rule-matches-internal.hpp new file mode 100644 index 000000000..bb7e03e21 --- /dev/null +++ b/include/lttng/condition/event-rule-matches-internal.hpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2019 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_CONDITION_EVENT_RULE_MATCHES_INTERNAL_H +#define LTTNG_CONDITION_EVENT_RULE_MATCHES_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include + +struct lttng_capture_descriptor { + struct lttng_event_expr *event_expression; + struct lttng_bytecode *bytecode; +}; + +struct lttng_condition_event_rule_matches { + struct lttng_condition parent; + struct lttng_event_rule *rule; + + /* + * Internal use only. + * Error accounting counter index. + */ + LTTNG_OPTIONAL(uint64_t) error_counter_index; + + /* Array of `struct lttng_capture_descriptor *`. */ + struct lttng_dynamic_pointer_array capture_descriptors; +}; + +struct lttng_evaluation_event_rule_matches { + struct lttng_evaluation parent; + + /* MessagePack-encoded captured event field values. */ + struct lttng_dynamic_buffer capture_payload; + + /* + * The content of this array event field value is the decoded + * version of `capture_payload` above. + * + * This is a cache: it's not serialized/deserialized in + * communications from/to the library and the session daemon. + */ + struct lttng_event_field_value *captured_values; +}; + +ssize_t lttng_condition_event_rule_matches_create_from_payload( + struct lttng_payload_view *view, + struct lttng_condition **condition); + +enum lttng_condition_status +lttng_condition_event_rule_matches_borrow_rule_mutable( + const struct lttng_condition *condition, + struct lttng_event_rule **rule); + +void lttng_condition_event_rule_matches_set_error_counter_index( + struct lttng_condition *condition, + uint64_t error_counter_index); + +uint64_t lttng_condition_event_rule_matches_get_error_counter_index( + const struct lttng_condition *condition); + +struct lttng_evaluation *lttng_evaluation_event_rule_matches_create( + const struct lttng_condition_event_rule_matches *condition, + const char *capture_payload, + size_t capture_payload_size, + bool decode_capture_payload); + +ssize_t lttng_evaluation_event_rule_matches_create_from_payload( + const struct lttng_condition_event_rule_matches *condition, + struct lttng_payload_view *view, + struct lttng_evaluation **_evaluation); + +enum lttng_error_code +lttng_condition_event_rule_matches_generate_capture_descriptor_bytecode( + struct lttng_condition *condition); + +const struct lttng_bytecode * +lttng_condition_event_rule_matches_get_capture_bytecode_at_index( + const struct lttng_condition *condition, unsigned int index); + +#endif /* LTTNG_CONDITION_EVENT_RULE_MATCHES_INTERNAL_H */ diff --git a/include/lttng/condition/session-consumed-size-internal.h b/include/lttng/condition/session-consumed-size-internal.h deleted file mode 100644 index 9340a5f23..000000000 --- a/include/lttng/condition/session-consumed-size-internal.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_CONDITION_SESSION_CONSUMED_SIZE_INTERNAL_H -#define LTTNG_CONDITION_SESSION_CONSUMED_SIZE_INTERNAL_H - -#include -#include -#include -#include -#include - -struct lttng_payload; -struct lttng_payload_view; - -struct lttng_condition_session_consumed_size { - struct lttng_condition parent; - struct { - bool set; - uint64_t value; - } consumed_threshold_bytes; - char *session_name; -}; - -struct lttng_condition_session_consumed_size_comm { - uint64_t consumed_threshold_bytes; - /* Length includes the trailing \0. */ - uint32_t session_name_len; - char session_name[]; -} LTTNG_PACKED; - -struct lttng_evaluation_session_consumed_size { - struct lttng_evaluation parent; - uint64_t session_consumed; -}; - -struct lttng_evaluation_session_consumed_size_comm { - uint64_t session_consumed; -} LTTNG_PACKED; - -struct lttng_evaluation *lttng_evaluation_session_consumed_size_create( - uint64_t consumed); - -ssize_t lttng_condition_session_consumed_size_create_from_payload( - struct lttng_payload_view *view, - struct lttng_condition **condition); - -ssize_t lttng_evaluation_session_consumed_size_create_from_payload( - struct lttng_payload_view *view, - struct lttng_evaluation **evaluation); - -#endif /* LTTNG_CONDITION_SESSION_CONSUMED_SIZE_INTERNAL_H */ diff --git a/include/lttng/condition/session-consumed-size-internal.hpp b/include/lttng/condition/session-consumed-size-internal.hpp new file mode 100644 index 000000000..cdfa10034 --- /dev/null +++ b/include/lttng/condition/session-consumed-size-internal.hpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_CONDITION_SESSION_CONSUMED_SIZE_INTERNAL_H +#define LTTNG_CONDITION_SESSION_CONSUMED_SIZE_INTERNAL_H + +#include +#include +#include +#include +#include + +struct lttng_payload; +struct lttng_payload_view; + +struct lttng_condition_session_consumed_size { + struct lttng_condition parent; + struct { + bool set; + uint64_t value; + } consumed_threshold_bytes; + char *session_name; +}; + +struct lttng_condition_session_consumed_size_comm { + uint64_t consumed_threshold_bytes; + /* Length includes the trailing \0. */ + uint32_t session_name_len; + char session_name[]; +} LTTNG_PACKED; + +struct lttng_evaluation_session_consumed_size { + struct lttng_evaluation parent; + uint64_t session_consumed; +}; + +struct lttng_evaluation_session_consumed_size_comm { + uint64_t session_consumed; +} LTTNG_PACKED; + +struct lttng_evaluation *lttng_evaluation_session_consumed_size_create( + uint64_t consumed); + +ssize_t lttng_condition_session_consumed_size_create_from_payload( + struct lttng_payload_view *view, + struct lttng_condition **condition); + +ssize_t lttng_evaluation_session_consumed_size_create_from_payload( + struct lttng_payload_view *view, + struct lttng_evaluation **evaluation); + +#endif /* LTTNG_CONDITION_SESSION_CONSUMED_SIZE_INTERNAL_H */ diff --git a/include/lttng/condition/session-rotation-internal.h b/include/lttng/condition/session-rotation-internal.h deleted file mode 100644 index c723c6d6a..000000000 --- a/include/lttng/condition/session-rotation-internal.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_CONDITION_SESSION_ROTATION_INTERNAL_H -#define LTTNG_CONDITION_SESSION_ROTATION_INTERNAL_H - -#include -#include -#include -#include "common/buffer-view.h" -#include -#include - -struct lttng_condition_session_rotation { - struct lttng_condition parent; - char *session_name; -}; - -struct lttng_condition_session_rotation_comm { - /* Length includes the trailing \0. */ - uint32_t session_name_len; - char session_name[]; -} LTTNG_PACKED; - -struct lttng_evaluation_session_rotation { - struct lttng_evaluation parent; - uint64_t id; - struct lttng_trace_archive_location *location; -}; - -struct lttng_evaluation_session_rotation_comm { - uint64_t id; - uint8_t has_location; -} LTTNG_PACKED; - -ssize_t lttng_condition_session_rotation_ongoing_create_from_payload( - struct lttng_payload_view *view, - struct lttng_condition **condition); - -ssize_t lttng_condition_session_rotation_completed_create_from_payload( - struct lttng_payload_view *view, - struct lttng_condition **condition); - -struct lttng_evaluation *lttng_evaluation_session_rotation_ongoing_create( - uint64_t id); - -/* Ownership of location is transferred to the evaluation. */ -struct lttng_evaluation *lttng_evaluation_session_rotation_completed_create( - uint64_t id, - struct lttng_trace_archive_location *location); - -ssize_t lttng_evaluation_session_rotation_ongoing_create_from_payload( - struct lttng_payload_view *view, - struct lttng_evaluation **evaluation); - -ssize_t lttng_evaluation_session_rotation_completed_create_from_payload( - struct lttng_payload_view *view, - struct lttng_evaluation **evaluation); - -#endif /* LTTNG_CONDITION_SESSION_ROTATION_INTERNAL_H */ diff --git a/include/lttng/condition/session-rotation-internal.hpp b/include/lttng/condition/session-rotation-internal.hpp new file mode 100644 index 000000000..e9a298445 --- /dev/null +++ b/include/lttng/condition/session-rotation-internal.hpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_CONDITION_SESSION_ROTATION_INTERNAL_H +#define LTTNG_CONDITION_SESSION_ROTATION_INTERNAL_H + +#include +#include +#include +#include "common/buffer-view.hpp" +#include +#include + +struct lttng_condition_session_rotation { + struct lttng_condition parent; + char *session_name; +}; + +struct lttng_condition_session_rotation_comm { + /* Length includes the trailing \0. */ + uint32_t session_name_len; + char session_name[]; +} LTTNG_PACKED; + +struct lttng_evaluation_session_rotation { + struct lttng_evaluation parent; + uint64_t id; + struct lttng_trace_archive_location *location; +}; + +struct lttng_evaluation_session_rotation_comm { + uint64_t id; + uint8_t has_location; +} LTTNG_PACKED; + +ssize_t lttng_condition_session_rotation_ongoing_create_from_payload( + struct lttng_payload_view *view, + struct lttng_condition **condition); + +ssize_t lttng_condition_session_rotation_completed_create_from_payload( + struct lttng_payload_view *view, + struct lttng_condition **condition); + +struct lttng_evaluation *lttng_evaluation_session_rotation_ongoing_create( + uint64_t id); + +/* Ownership of location is transferred to the evaluation. */ +struct lttng_evaluation *lttng_evaluation_session_rotation_completed_create( + uint64_t id, + struct lttng_trace_archive_location *location); + +ssize_t lttng_evaluation_session_rotation_ongoing_create_from_payload( + struct lttng_payload_view *view, + struct lttng_evaluation **evaluation); + +ssize_t lttng_evaluation_session_rotation_completed_create_from_payload( + struct lttng_payload_view *view, + struct lttng_evaluation **evaluation); + +#endif /* LTTNG_CONDITION_SESSION_ROTATION_INTERNAL_H */ diff --git a/include/lttng/domain-internal.h b/include/lttng/domain-internal.h deleted file mode 100644 index c34ba1930..000000000 --- a/include/lttng/domain-internal.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2020 Simon Marchi - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_DOMAIN_INTERNAL_H -#define LTTNG_DOMAIN_INTERNAL_H - -#include "lttng/domain.h" -#include "common/macros.h" - -const char *lttng_domain_type_str(enum lttng_domain_type domain_type); - -#endif /* LTTNG_DOMAIN_INTERNAL_H */ diff --git a/include/lttng/domain-internal.hpp b/include/lttng/domain-internal.hpp new file mode 100644 index 000000000..4439c7825 --- /dev/null +++ b/include/lttng/domain-internal.hpp @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2020 Simon Marchi + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_DOMAIN_INTERNAL_H +#define LTTNG_DOMAIN_INTERNAL_H + +#include "lttng/domain.h" +#include "common/macros.hpp" + +const char *lttng_domain_type_str(enum lttng_domain_type domain_type); + +#endif /* LTTNG_DOMAIN_INTERNAL_H */ diff --git a/include/lttng/endpoint-internal.h b/include/lttng/endpoint-internal.h deleted file mode 100644 index 3ec1df9c4..000000000 --- a/include/lttng/endpoint-internal.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_ENDPOINT_INTERNAL_H -#define LTTNG_ENDPOINT_INTERNAL_H - -#include -#include - -enum lttng_endpoint_type { - LTTNG_ENDPOINT_TYPE_DEFAULT_SESSIOND_NOTIFICATION = 0, - LTTNG_ENDPOINT_TYPE_DEFAULT_SESSIOND_COMMAND = 1, -}; - -struct lttng_endpoint { - enum lttng_endpoint_type type; -}; - -#endif /* LTTNG_ENDPOINT_INTERNAL_H */ diff --git a/include/lttng/endpoint-internal.hpp b/include/lttng/endpoint-internal.hpp new file mode 100644 index 000000000..5317f7ff5 --- /dev/null +++ b/include/lttng/endpoint-internal.hpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_ENDPOINT_INTERNAL_H +#define LTTNG_ENDPOINT_INTERNAL_H + +#include +#include + +enum lttng_endpoint_type { + LTTNG_ENDPOINT_TYPE_DEFAULT_SESSIOND_NOTIFICATION = 0, + LTTNG_ENDPOINT_TYPE_DEFAULT_SESSIOND_COMMAND = 1, +}; + +struct lttng_endpoint { + enum lttng_endpoint_type type; +}; + +#endif /* LTTNG_ENDPOINT_INTERNAL_H */ diff --git a/include/lttng/error-query-internal.h b/include/lttng/error-query-internal.h deleted file mode 100644 index 07e2280d7..000000000 --- a/include/lttng/error-query-internal.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * error-query-internal.h - * - * Copyright (C) 2021 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.1-only - * - */ - -#ifndef LTTNG_ERROR_QUERY_INTERNAL_H -#define LTTNG_ERROR_QUERY_INTERNAL_H - -#include -#include -#include -#include - -struct mi_writer; - -enum lttng_error_query_target_type { - LTTNG_ERROR_QUERY_TARGET_TYPE_TRIGGER, - LTTNG_ERROR_QUERY_TARGET_TYPE_CONDITION, - LTTNG_ERROR_QUERY_TARGET_TYPE_ACTION, -}; - -enum lttng_error_query_target_type lttng_error_query_get_target_type( - const struct lttng_error_query *query); - -const struct lttng_trigger *lttng_error_query_trigger_borrow_target( - const struct lttng_error_query *query); - -const struct lttng_trigger *lttng_error_query_condition_borrow_target( - const struct lttng_error_query *query); - -const struct lttng_trigger *lttng_error_query_action_borrow_trigger_target( - const struct lttng_error_query *query); - -struct lttng_action *lttng_error_query_action_borrow_action_target( - const struct lttng_error_query *query, - struct lttng_trigger *trigger); - -int lttng_error_query_serialize(const struct lttng_error_query *query, - struct lttng_payload *payload); - -ssize_t lttng_error_query_create_from_payload(struct lttng_payload_view *view, - struct lttng_error_query **query); - -int lttng_error_query_result_serialize( - const struct lttng_error_query_result *result, - struct lttng_payload *payload); - -ssize_t lttng_error_query_result_create_from_payload( - struct lttng_payload_view *view, - struct lttng_error_query_result **result); - -int lttng_error_query_results_serialize( - const struct lttng_error_query_results *results, - struct lttng_payload *payload); - -ssize_t lttng_error_query_results_create_from_payload( - struct lttng_payload_view *view, - struct lttng_error_query_results **results); - -struct lttng_error_query_result * -lttng_error_query_result_counter_create( - const char *name, const char *description, uint64_t value); - -void lttng_error_query_result_destroy(struct lttng_error_query_result *result); - -struct lttng_error_query_results *lttng_error_query_results_create(void); - -/* Ownership of `result` is transferred on success. */ -int lttng_error_query_results_add_result( - struct lttng_error_query_results *results, - struct lttng_error_query_result *result); - -enum lttng_error_code lttng_error_query_results_mi_serialize( - const struct lttng_error_query_results *results, - struct mi_writer *writer); - -#endif /* LTTNG_ERROR_QUERY_INTERNAL_H */ diff --git a/include/lttng/error-query-internal.hpp b/include/lttng/error-query-internal.hpp new file mode 100644 index 000000000..7bf4da748 --- /dev/null +++ b/include/lttng/error-query-internal.hpp @@ -0,0 +1,81 @@ +/* + * error-query-internal.h + * + * Copyright (C) 2021 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.1-only + * + */ + +#ifndef LTTNG_ERROR_QUERY_INTERNAL_H +#define LTTNG_ERROR_QUERY_INTERNAL_H + +#include +#include +#include +#include + +struct mi_writer; + +enum lttng_error_query_target_type { + LTTNG_ERROR_QUERY_TARGET_TYPE_TRIGGER, + LTTNG_ERROR_QUERY_TARGET_TYPE_CONDITION, + LTTNG_ERROR_QUERY_TARGET_TYPE_ACTION, +}; + +enum lttng_error_query_target_type lttng_error_query_get_target_type( + const struct lttng_error_query *query); + +const struct lttng_trigger *lttng_error_query_trigger_borrow_target( + const struct lttng_error_query *query); + +const struct lttng_trigger *lttng_error_query_condition_borrow_target( + const struct lttng_error_query *query); + +const struct lttng_trigger *lttng_error_query_action_borrow_trigger_target( + const struct lttng_error_query *query); + +struct lttng_action *lttng_error_query_action_borrow_action_target( + const struct lttng_error_query *query, + struct lttng_trigger *trigger); + +int lttng_error_query_serialize(const struct lttng_error_query *query, + struct lttng_payload *payload); + +ssize_t lttng_error_query_create_from_payload(struct lttng_payload_view *view, + struct lttng_error_query **query); + +int lttng_error_query_result_serialize( + const struct lttng_error_query_result *result, + struct lttng_payload *payload); + +ssize_t lttng_error_query_result_create_from_payload( + struct lttng_payload_view *view, + struct lttng_error_query_result **result); + +int lttng_error_query_results_serialize( + const struct lttng_error_query_results *results, + struct lttng_payload *payload); + +ssize_t lttng_error_query_results_create_from_payload( + struct lttng_payload_view *view, + struct lttng_error_query_results **results); + +struct lttng_error_query_result * +lttng_error_query_result_counter_create( + const char *name, const char *description, uint64_t value); + +void lttng_error_query_result_destroy(struct lttng_error_query_result *result); + +struct lttng_error_query_results *lttng_error_query_results_create(void); + +/* Ownership of `result` is transferred on success. */ +int lttng_error_query_results_add_result( + struct lttng_error_query_results *results, + struct lttng_error_query_result *result); + +enum lttng_error_code lttng_error_query_results_mi_serialize( + const struct lttng_error_query_results *results, + struct mi_writer *writer); + +#endif /* LTTNG_ERROR_QUERY_INTERNAL_H */ diff --git a/include/lttng/event-expr-internal.h b/include/lttng/event-expr-internal.h deleted file mode 100644 index 469fd17bb..000000000 --- a/include/lttng/event-expr-internal.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2020 Philippe Proulx - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_EXPR_INTERNAL_H -#define LTTNG_EVENT_EXPR_INTERNAL_H - -#include -#include - -struct lttng_bytecode; -struct mi_writer; - -struct lttng_event_expr { - enum lttng_event_expr_type type; -}; - -/* - * `LTTNG_EVENT_EXPR_TYPE_EVENT_PAYLOAD_FIELD` and - * `LTTNG_EVENT_EXPR_TYPE_CHANNEL_CONTEXT_FIELD`. - */ -struct lttng_event_expr_field { - struct lttng_event_expr parent; - char *name; -}; - -/* `LTTNG_EVENT_EXPR_TYPE_APP_SPECIFIC_CONTEXT_FIELD` */ -struct lttng_event_expr_app_specific_context_field { - struct lttng_event_expr parent; - char *provider_name; - char *type_name; -}; - -/* `LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT` */ -struct lttng_event_expr_array_field_element { - struct lttng_event_expr parent; - - /* Owned by this */ - struct lttng_event_expr *array_field_expr; - - unsigned int index; -}; - -/* - * Returns whether or not `expr` is an l-value (locator value). - */ -static inline -bool lttng_event_expr_is_lvalue(const struct lttng_event_expr *expr) -{ - LTTNG_ASSERT(expr); - return expr->type == LTTNG_EVENT_EXPR_TYPE_EVENT_PAYLOAD_FIELD || - expr->type == LTTNG_EVENT_EXPR_TYPE_CHANNEL_CONTEXT_FIELD || - expr->type == LTTNG_EVENT_EXPR_TYPE_APP_SPECIFIC_CONTEXT_FIELD || - expr->type == LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT; -} - -int lttng_event_expr_to_bytecode(const struct lttng_event_expr *expr, - struct lttng_bytecode **bytecode_out); - -enum lttng_error_code lttng_event_expr_mi_serialize( - const struct lttng_event_expr *expression, - struct mi_writer *writer); - -#endif /* LTTNG_EVENT_EXPR_INTERNAL_H */ diff --git a/include/lttng/event-expr-internal.hpp b/include/lttng/event-expr-internal.hpp new file mode 100644 index 000000000..07547e587 --- /dev/null +++ b/include/lttng/event-expr-internal.hpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2020 Philippe Proulx + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_EXPR_INTERNAL_H +#define LTTNG_EVENT_EXPR_INTERNAL_H + +#include +#include + +struct lttng_bytecode; +struct mi_writer; + +struct lttng_event_expr { + enum lttng_event_expr_type type; +}; + +/* + * `LTTNG_EVENT_EXPR_TYPE_EVENT_PAYLOAD_FIELD` and + * `LTTNG_EVENT_EXPR_TYPE_CHANNEL_CONTEXT_FIELD`. + */ +struct lttng_event_expr_field { + struct lttng_event_expr parent; + char *name; +}; + +/* `LTTNG_EVENT_EXPR_TYPE_APP_SPECIFIC_CONTEXT_FIELD` */ +struct lttng_event_expr_app_specific_context_field { + struct lttng_event_expr parent; + char *provider_name; + char *type_name; +}; + +/* `LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT` */ +struct lttng_event_expr_array_field_element { + struct lttng_event_expr parent; + + /* Owned by this */ + struct lttng_event_expr *array_field_expr; + + unsigned int index; +}; + +/* + * Returns whether or not `expr` is an l-value (locator value). + */ +static inline +bool lttng_event_expr_is_lvalue(const struct lttng_event_expr *expr) +{ + LTTNG_ASSERT(expr); + return expr->type == LTTNG_EVENT_EXPR_TYPE_EVENT_PAYLOAD_FIELD || + expr->type == LTTNG_EVENT_EXPR_TYPE_CHANNEL_CONTEXT_FIELD || + expr->type == LTTNG_EVENT_EXPR_TYPE_APP_SPECIFIC_CONTEXT_FIELD || + expr->type == LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT; +} + +int lttng_event_expr_to_bytecode(const struct lttng_event_expr *expr, + struct lttng_bytecode **bytecode_out); + +enum lttng_error_code lttng_event_expr_mi_serialize( + const struct lttng_event_expr *expression, + struct mi_writer *writer); + +#endif /* LTTNG_EVENT_EXPR_INTERNAL_H */ diff --git a/include/lttng/event-field-value-internal.h b/include/lttng/event-field-value-internal.h deleted file mode 100644 index 510420ac0..000000000 --- a/include/lttng/event-field-value-internal.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2020 Philippe Proulx - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_FIELD_VALUE_INTERNAL_H -#define LTTNG_EVENT_FIELD_VALUE_INTERNAL_H - -#include -#include -#include - -struct lttng_event_field_value { - enum lttng_event_field_value_type type; -}; - -/* - * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT`. - */ -struct lttng_event_field_value_uint { - struct lttng_event_field_value parent; - uint64_t val; -}; - -/* - * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT`. - */ -struct lttng_event_field_value_int { - struct lttng_event_field_value parent; - int64_t val; -}; - -/* - * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` and - * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM` (base). - */ -struct lttng_event_field_value_enum { - struct lttng_event_field_value parent; - - /* - * Array of `char *` (owned by this). - */ - struct lttng_dynamic_pointer_array labels; -}; - -/* - * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM`. - */ -struct lttng_event_field_value_enum_uint { - struct lttng_event_field_value_enum parent; - uint64_t val; -}; - -/* - * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. - */ -struct lttng_event_field_value_enum_int { - struct lttng_event_field_value_enum parent; - int64_t val; -}; - -/* `LTTNG_EVENT_FIELD_VALUE_TYPE_REAL` */ -struct lttng_event_field_value_real { - struct lttng_event_field_value parent; - double val; -}; - -/* `LTTNG_EVENT_FIELD_VALUE_TYPE_STRING` */ -struct lttng_event_field_value_string { - struct lttng_event_field_value parent; - - /* Owned by this */ - char *val; -}; - -/* `LTTNG_EVENT_FIELD_VALUE_TYPE_STRING` */ -struct lttng_event_field_value_array { - struct lttng_event_field_value parent; - - /* - * Array of `struct lttng_event_field_value *` (owned by this). - * - * A `NULL` element means it's unavailable - * (`LTTNG_EVENT_FIELD_VALUE_STATUS_UNAVAILABLE` status). - */ - struct lttng_dynamic_pointer_array elems; -}; - -/* - * This is internal since the session daemon knows nothing about the - * enumeration fields produced by the kernel tracer. Indeed, the kernel tracer - * manages its own metadata which remains opaque to the rest of the toolchain. - * - * Enumerations could be supported for the user space tracer, but it is not the - * case right now. - */ - -/* - * Sets `*count` to the number of labels of the enumeration event field - * value `field_val`. - * - * Returns: - * - * `LTTNG_EVENT_FIELD_VALUE_STATUS_OK`: - * Success. - * - * `LTTNG_EVENT_FIELD_VALUE_STATUS_INVALID`: - * * `field_val` is `NULL`. - * * The type of `field_val` is not - * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` or - * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. - * * `count` is `NULL`. - */ -enum lttng_event_field_value_status -lttng_event_field_value_enum_get_label_count( - const struct lttng_event_field_value *field_val, - unsigned int *count); - -/* - * Returns the label at index `index` of the enumeration event field - * value `field_val`, or `NULL` if: - * - * * `field_val` is `NULL`. - * * The type of `field_val` is not - * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` or - * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. - * * `index` is greater than or equal to the label count of `field_val`, - * as returned by lttng_event_field_value_enum_get_label_count(). - */ -const char *lttng_event_field_value_enum_get_label_at_index( - const struct lttng_event_field_value *field_val, - unsigned int index); - -struct lttng_event_field_value *lttng_event_field_value_uint_create( - uint64_t val); - -struct lttng_event_field_value *lttng_event_field_value_int_create( - int64_t val); - -struct lttng_event_field_value *lttng_event_field_value_enum_uint_create( - uint64_t val); - -struct lttng_event_field_value *lttng_event_field_value_enum_int_create( - int64_t val); - -struct lttng_event_field_value *lttng_event_field_value_real_create(double val); - -struct lttng_event_field_value *lttng_event_field_value_string_create( - const char *val); - -struct lttng_event_field_value *lttng_event_field_value_string_create_with_size( - const char *val, size_t size); - -struct lttng_event_field_value *lttng_event_field_value_array_create(void); - -int lttng_event_field_value_enum_append_label( - struct lttng_event_field_value *field_val, const char *label); - -int lttng_event_field_value_enum_append_label_with_size( - struct lttng_event_field_value *field_val, const char *label, - size_t size); - -int lttng_event_field_value_array_append( - struct lttng_event_field_value *array_field_val, - struct lttng_event_field_value *field_val); - -int lttng_event_field_value_array_append_unavailable( - struct lttng_event_field_value *array_field_val); - -void lttng_event_field_value_destroy(struct lttng_event_field_value *field_val); - -#endif /* LTTNG_EVENT_FIELD_VALUE_INTERNAL_H */ diff --git a/include/lttng/event-field-value-internal.hpp b/include/lttng/event-field-value-internal.hpp new file mode 100644 index 000000000..03ef8960b --- /dev/null +++ b/include/lttng/event-field-value-internal.hpp @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2020 Philippe Proulx + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_FIELD_VALUE_INTERNAL_H +#define LTTNG_EVENT_FIELD_VALUE_INTERNAL_H + +#include +#include +#include + +struct lttng_event_field_value { + enum lttng_event_field_value_type type; +}; + +/* + * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT`. + */ +struct lttng_event_field_value_uint { + struct lttng_event_field_value parent; + uint64_t val; +}; + +/* + * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT`. + */ +struct lttng_event_field_value_int { + struct lttng_event_field_value parent; + int64_t val; +}; + +/* + * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` and + * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM` (base). + */ +struct lttng_event_field_value_enum { + struct lttng_event_field_value parent; + + /* + * Array of `char *` (owned by this). + */ + struct lttng_dynamic_pointer_array labels; +}; + +/* + * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM`. + */ +struct lttng_event_field_value_enum_uint { + struct lttng_event_field_value_enum parent; + uint64_t val; +}; + +/* + * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. + */ +struct lttng_event_field_value_enum_int { + struct lttng_event_field_value_enum parent; + int64_t val; +}; + +/* `LTTNG_EVENT_FIELD_VALUE_TYPE_REAL` */ +struct lttng_event_field_value_real { + struct lttng_event_field_value parent; + double val; +}; + +/* `LTTNG_EVENT_FIELD_VALUE_TYPE_STRING` */ +struct lttng_event_field_value_string { + struct lttng_event_field_value parent; + + /* Owned by this */ + char *val; +}; + +/* `LTTNG_EVENT_FIELD_VALUE_TYPE_STRING` */ +struct lttng_event_field_value_array { + struct lttng_event_field_value parent; + + /* + * Array of `struct lttng_event_field_value *` (owned by this). + * + * A `NULL` element means it's unavailable + * (`LTTNG_EVENT_FIELD_VALUE_STATUS_UNAVAILABLE` status). + */ + struct lttng_dynamic_pointer_array elems; +}; + +/* + * This is internal since the session daemon knows nothing about the + * enumeration fields produced by the kernel tracer. Indeed, the kernel tracer + * manages its own metadata which remains opaque to the rest of the toolchain. + * + * Enumerations could be supported for the user space tracer, but it is not the + * case right now. + */ + +/* + * Sets `*count` to the number of labels of the enumeration event field + * value `field_val`. + * + * Returns: + * + * `LTTNG_EVENT_FIELD_VALUE_STATUS_OK`: + * Success. + * + * `LTTNG_EVENT_FIELD_VALUE_STATUS_INVALID`: + * * `field_val` is `NULL`. + * * The type of `field_val` is not + * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` or + * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. + * * `count` is `NULL`. + */ +enum lttng_event_field_value_status +lttng_event_field_value_enum_get_label_count( + const struct lttng_event_field_value *field_val, + unsigned int *count); + +/* + * Returns the label at index `index` of the enumeration event field + * value `field_val`, or `NULL` if: + * + * * `field_val` is `NULL`. + * * The type of `field_val` is not + * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` or + * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. + * * `index` is greater than or equal to the label count of `field_val`, + * as returned by lttng_event_field_value_enum_get_label_count(). + */ +const char *lttng_event_field_value_enum_get_label_at_index( + const struct lttng_event_field_value *field_val, + unsigned int index); + +struct lttng_event_field_value *lttng_event_field_value_uint_create( + uint64_t val); + +struct lttng_event_field_value *lttng_event_field_value_int_create( + int64_t val); + +struct lttng_event_field_value *lttng_event_field_value_enum_uint_create( + uint64_t val); + +struct lttng_event_field_value *lttng_event_field_value_enum_int_create( + int64_t val); + +struct lttng_event_field_value *lttng_event_field_value_real_create(double val); + +struct lttng_event_field_value *lttng_event_field_value_string_create( + const char *val); + +struct lttng_event_field_value *lttng_event_field_value_string_create_with_size( + const char *val, size_t size); + +struct lttng_event_field_value *lttng_event_field_value_array_create(void); + +int lttng_event_field_value_enum_append_label( + struct lttng_event_field_value *field_val, const char *label); + +int lttng_event_field_value_enum_append_label_with_size( + struct lttng_event_field_value *field_val, const char *label, + size_t size); + +int lttng_event_field_value_array_append( + struct lttng_event_field_value *array_field_val, + struct lttng_event_field_value *field_val); + +int lttng_event_field_value_array_append_unavailable( + struct lttng_event_field_value *array_field_val); + +void lttng_event_field_value_destroy(struct lttng_event_field_value *field_val); + +#endif /* LTTNG_EVENT_FIELD_VALUE_INTERNAL_H */ diff --git a/include/lttng/event-internal.h b/include/lttng/event-internal.h deleted file mode 100644 index 52f7f7857..000000000 --- a/include/lttng/event-internal.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * event-internal.h - * - * Linux Trace Toolkit Control Library - * - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_INTERNAL_H -#define LTTNG_EVENT_INTERNAL_H - -#include -#include -#include - -struct lttng_event_exclusion; -struct lttng_userspace_probe_location; -struct lttng_dynamic_buffer; -struct lttng_buffer_view; - -struct lttng_event_comm { - int8_t event_type; - int8_t loglevel_type; - int32_t loglevel; - int8_t enabled; - int32_t pid; - uint32_t flags; - - /* Payload. */ - /* Includes terminator `\0`. */ - uint32_t name_len; - uint32_t exclusion_count; - /* Includes terminator `\0`. */ - uint32_t filter_expression_len; - uint32_t bytecode_len; - - /* Type specific payload. */ - uint32_t userspace_probe_location_len; - uint32_t lttng_event_probe_attr_len; - uint32_t lttng_event_function_attr_len; - - /* - * Contain: - * - name [name_len], - * - exclusions if any - * - char filter_expression[filter_expression_len], - * - unsigned char filter_bytecode[bytecode_len], - * - userspace probe location [userspace_probe_location_len], - * - probe or ftrace based on event type. - */ - - char payload[]; -} LTTNG_PACKED; - -struct lttng_event_exclusion_comm { - /* Includes terminator `\0`. */ - uint32_t len; - char payload []; -} LTTNG_PACKED; - -struct lttng_event_probe_attr_comm { - uint64_t addr; - uint64_t offset; - /* Includes terminator `\0`. */ - uint32_t symbol_name_len; - - char payload[]; -} LTTNG_PACKED; - -struct lttng_event_function_attr_comm { - /* Includes terminator `\0`. */ - uint32_t symbol_name_len; - - char payload[]; -} LTTNG_PACKED; - -struct lttng_event_context_comm { - uint32_t type; - /* - * Depending on the type. - * For: - * - LTTNG_EVENT_CONTEXT_APP_CONTEXT. - * - * -> struct lttng_event_context_app_comm - * - * For - * - LTTNG_EVENT_CONTEXT_PERF_COUNTER, - * - LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER, - * - LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER. - * - * -> struct lttng_event_context_perf_counter_comm - * - * Other type -> no payload. - */ - char payload[]; -} LTTNG_PACKED; - -struct lttng_event_context_perf_counter_comm { - uint32_t type; - uint64_t config; - /* Includes terminator `\0`. */ - uint32_t name_len; - /* - * char name [name_len] - */ - char payload[]; -} LTTNG_PACKED; - -struct lttng_event_context_app_comm { - /* Includes terminator `\0`. */ - uint32_t provider_name_len; - /* Includes terminator `\0`. */ - uint32_t ctx_name_len; - /* - * provider name [provider_name_len] - * ctx name [ctx_name_len] - */ - char payload[]; -} LTTNG_PACKED; - -struct lttng_event_field_comm { - uint8_t type; - uint8_t nowrite; - /* Includes terminator `\0`. */ - uint32_t name_len; - uint32_t event_len; - - /* - * - name [name_len] - * - lttng_event object - */ - char payload[]; -} LTTNG_PACKED; - -struct lttng_event_extended { - /* - * exclusions and filter_expression are only set when the lttng_event - * was created/allocated by a list operation. These two elements must - * not be free'd as they are part of the same contiguous buffer that - * contains all events returned by the listing. - */ - char *filter_expression; - struct { - unsigned int count; - /* Array of strings of fixed LTTNG_SYMBOL_NAME_LEN length. */ - char *strings; - } exclusions; - struct lttng_userspace_probe_location *probe_location; -}; - -struct lttng_event *lttng_event_copy(const struct lttng_event *event); - -ssize_t lttng_event_create_from_payload(struct lttng_payload_view *view, - struct lttng_event **out_event, - struct lttng_event_exclusion **out_exclusion, - char **out_filter_expression, - struct lttng_bytecode **out_bytecode); - -int lttng_event_serialize(const struct lttng_event *event, - unsigned int exclusion_count, - char **exclusion_list, - char *filter_expression, - size_t bytecode_len, - struct lttng_bytecode *bytecode, - struct lttng_payload *payload); - -ssize_t lttng_event_context_create_from_payload( - struct lttng_payload_view *view, - struct lttng_event_context **event_ctx); - -int lttng_event_context_serialize(struct lttng_event_context *context, - struct lttng_payload *payload); - -void lttng_event_context_destroy(struct lttng_event_context *context); - -enum lttng_error_code lttng_events_create_and_flatten_from_payload( - struct lttng_payload_view *view, - unsigned int count, - struct lttng_event **events); - -ssize_t lttng_event_field_create_from_payload( - struct lttng_payload_view *view, - struct lttng_event_field **field); - -int lttng_event_field_serialize(const struct lttng_event_field *field, - struct lttng_payload *payload); - -enum lttng_error_code lttng_event_fields_create_and_flatten_from_payload( - struct lttng_payload_view *view, - unsigned int count, - struct lttng_event_field **fields); - -#endif /* LTTNG_EVENT_INTERNAL_H */ diff --git a/include/lttng/event-internal.hpp b/include/lttng/event-internal.hpp new file mode 100644 index 000000000..daa8fa68e --- /dev/null +++ b/include/lttng/event-internal.hpp @@ -0,0 +1,196 @@ +/* + * event-internal.h + * + * Linux Trace Toolkit Control Library + * + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_INTERNAL_H +#define LTTNG_EVENT_INTERNAL_H + +#include +#include +#include + +struct lttng_event_exclusion; +struct lttng_userspace_probe_location; +struct lttng_dynamic_buffer; +struct lttng_buffer_view; + +struct lttng_event_comm { + int8_t event_type; + int8_t loglevel_type; + int32_t loglevel; + int8_t enabled; + int32_t pid; + uint32_t flags; + + /* Payload. */ + /* Includes terminator `\0`. */ + uint32_t name_len; + uint32_t exclusion_count; + /* Includes terminator `\0`. */ + uint32_t filter_expression_len; + uint32_t bytecode_len; + + /* Type specific payload. */ + uint32_t userspace_probe_location_len; + uint32_t lttng_event_probe_attr_len; + uint32_t lttng_event_function_attr_len; + + /* + * Contain: + * - name [name_len], + * - exclusions if any + * - char filter_expression[filter_expression_len], + * - unsigned char filter_bytecode[bytecode_len], + * - userspace probe location [userspace_probe_location_len], + * - probe or ftrace based on event type. + */ + + char payload[]; +} LTTNG_PACKED; + +struct lttng_event_exclusion_comm { + /* Includes terminator `\0`. */ + uint32_t len; + char payload []; +} LTTNG_PACKED; + +struct lttng_event_probe_attr_comm { + uint64_t addr; + uint64_t offset; + /* Includes terminator `\0`. */ + uint32_t symbol_name_len; + + char payload[]; +} LTTNG_PACKED; + +struct lttng_event_function_attr_comm { + /* Includes terminator `\0`. */ + uint32_t symbol_name_len; + + char payload[]; +} LTTNG_PACKED; + +struct lttng_event_context_comm { + uint32_t type; + /* + * Depending on the type. + * For: + * - LTTNG_EVENT_CONTEXT_APP_CONTEXT. + * + * -> struct lttng_event_context_app_comm + * + * For + * - LTTNG_EVENT_CONTEXT_PERF_COUNTER, + * - LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER, + * - LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER. + * + * -> struct lttng_event_context_perf_counter_comm + * + * Other type -> no payload. + */ + char payload[]; +} LTTNG_PACKED; + +struct lttng_event_context_perf_counter_comm { + uint32_t type; + uint64_t config; + /* Includes terminator `\0`. */ + uint32_t name_len; + /* + * char name [name_len] + */ + char payload[]; +} LTTNG_PACKED; + +struct lttng_event_context_app_comm { + /* Includes terminator `\0`. */ + uint32_t provider_name_len; + /* Includes terminator `\0`. */ + uint32_t ctx_name_len; + /* + * provider name [provider_name_len] + * ctx name [ctx_name_len] + */ + char payload[]; +} LTTNG_PACKED; + +struct lttng_event_field_comm { + uint8_t type; + uint8_t nowrite; + /* Includes terminator `\0`. */ + uint32_t name_len; + uint32_t event_len; + + /* + * - name [name_len] + * - lttng_event object + */ + char payload[]; +} LTTNG_PACKED; + +struct lttng_event_extended { + /* + * exclusions and filter_expression are only set when the lttng_event + * was created/allocated by a list operation. These two elements must + * not be free'd as they are part of the same contiguous buffer that + * contains all events returned by the listing. + */ + char *filter_expression; + struct { + unsigned int count; + /* Array of strings of fixed LTTNG_SYMBOL_NAME_LEN length. */ + char *strings; + } exclusions; + struct lttng_userspace_probe_location *probe_location; +}; + +struct lttng_event *lttng_event_copy(const struct lttng_event *event); + +ssize_t lttng_event_create_from_payload(struct lttng_payload_view *view, + struct lttng_event **out_event, + struct lttng_event_exclusion **out_exclusion, + char **out_filter_expression, + struct lttng_bytecode **out_bytecode); + +int lttng_event_serialize(const struct lttng_event *event, + unsigned int exclusion_count, + char **exclusion_list, + char *filter_expression, + size_t bytecode_len, + struct lttng_bytecode *bytecode, + struct lttng_payload *payload); + +ssize_t lttng_event_context_create_from_payload( + struct lttng_payload_view *view, + struct lttng_event_context **event_ctx); + +int lttng_event_context_serialize(struct lttng_event_context *context, + struct lttng_payload *payload); + +void lttng_event_context_destroy(struct lttng_event_context *context); + +enum lttng_error_code lttng_events_create_and_flatten_from_payload( + struct lttng_payload_view *view, + unsigned int count, + struct lttng_event **events); + +ssize_t lttng_event_field_create_from_payload( + struct lttng_payload_view *view, + struct lttng_event_field **field); + +int lttng_event_field_serialize(const struct lttng_event_field *field, + struct lttng_payload *payload); + +enum lttng_error_code lttng_event_fields_create_and_flatten_from_payload( + struct lttng_payload_view *view, + unsigned int count, + struct lttng_event_field **fields); + +#endif /* LTTNG_EVENT_INTERNAL_H */ diff --git a/include/lttng/event-rule/event-rule-internal.h b/include/lttng/event-rule/event-rule-internal.h deleted file mode 100644 index 802674863..000000000 --- a/include/lttng/event-rule/event-rule-internal.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (C) 2019 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_RULE_INTERNAL_H -#define LTTNG_EVENT_RULE_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct lttng_payload; -struct lttng_payload_view; -struct mi_writer; - -enum lttng_event_rule_generate_exclusions_status { - LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OK, - LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_NONE, - LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_ERROR, - LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OUT_OF_MEMORY, -}; - -typedef void (*event_rule_destroy_cb)(struct lttng_event_rule *event_rule); -typedef bool (*event_rule_validate_cb)( - const struct lttng_event_rule *event_rule); -typedef int (*event_rule_serialize_cb)( - const struct lttng_event_rule *event_rule, - struct lttng_payload *payload); -typedef bool (*event_rule_equal_cb)(const struct lttng_event_rule *a, - const struct lttng_event_rule *b); -typedef ssize_t (*event_rule_create_from_payload_cb)( - struct lttng_payload_view *view, - struct lttng_event_rule **event_rule); -typedef enum lttng_error_code (*event_rule_generate_filter_bytecode_cb)( - struct lttng_event_rule *event_rule, - const struct lttng_credentials *creds); -typedef const char *(*event_rule_get_filter_cb)( - const struct lttng_event_rule *event_rule); -typedef const struct lttng_bytecode *( - *event_rule_get_filter_bytecode_cb)( - const struct lttng_event_rule *event_rule); -typedef enum lttng_event_rule_generate_exclusions_status ( - *event_rule_generate_exclusions_cb)( - const struct lttng_event_rule *event_rule, - struct lttng_event_exclusion **exclusions); -typedef unsigned long (*event_rule_hash_cb)( - const struct lttng_event_rule *event_rule); -typedef struct lttng_event *(*event_rule_generate_lttng_event_cb)( - const struct lttng_event_rule *event_rule); -typedef enum lttng_error_code (*event_rule_mi_serialize_cb)( - const struct lttng_event_rule *event_rule, - struct mi_writer *writer); - -struct lttng_event_rule { - struct urcu_ref ref; - enum lttng_event_rule_type type; - event_rule_validate_cb validate; - event_rule_serialize_cb serialize; - event_rule_equal_cb equal; - event_rule_destroy_cb destroy; - event_rule_generate_filter_bytecode_cb generate_filter_bytecode; - event_rule_get_filter_cb get_filter; - event_rule_get_filter_bytecode_cb get_filter_bytecode; - event_rule_generate_exclusions_cb generate_exclusions; - event_rule_hash_cb hash; - event_rule_generate_lttng_event_cb generate_lttng_event; - event_rule_mi_serialize_cb mi_serialize; -}; - -struct lttng_event_rule_comm { - /* enum lttng_event_rule_type */ - int8_t event_rule_type; - char payload[]; -}; - -void lttng_event_rule_init(struct lttng_event_rule *event_rule, - enum lttng_event_rule_type type); - -bool lttng_event_rule_validate(const struct lttng_event_rule *event_rule); - -ssize_t lttng_event_rule_create_from_payload( - struct lttng_payload_view *payload, - struct lttng_event_rule **event_rule); - -int lttng_event_rule_serialize(const struct lttng_event_rule *event_rule, - struct lttng_payload *payload); - -bool lttng_event_rule_is_equal(const struct lttng_event_rule *a, - const struct lttng_event_rule *b); - -bool lttng_event_rule_get(struct lttng_event_rule *rule); - -void lttng_event_rule_put(struct lttng_event_rule *rule); - -enum lttng_domain_type lttng_event_rule_get_domain_type( - const struct lttng_event_rule *rule); - -enum lttng_error_code lttng_event_rule_generate_filter_bytecode( - struct lttng_event_rule *rule, - const struct lttng_credentials *creds); - -/* - * If not present/implemented returns NULL. - * Caller DOES NOT own the returned object. - */ -const char *lttng_event_rule_get_filter(const struct lttng_event_rule *rule); - -/* - * If not present/implemented returns NULL. - * Caller DOES NOT own the returned object. - */ -const struct lttng_bytecode *lttng_event_rule_get_filter_bytecode( - const struct lttng_event_rule *rule); - -/* - * If not present/implemented return NULL. - * Caller OWNS the returned object. - */ -enum lttng_event_rule_generate_exclusions_status -lttng_event_rule_generate_exclusions(const struct lttng_event_rule *rule, - struct lttng_event_exclusion **exclusions); - -const char *lttng_event_rule_type_str(enum lttng_event_rule_type type); - -unsigned long lttng_event_rule_hash(const struct lttng_event_rule *rule); - -/* - * This is a compatibility helper allowing us to generate a sessiond-side (not - * communication) `struct lttng_event` object from an event rule. - * - * This effectively bridges older parts of the code using those structures and - * new event-rule based code. - * - * The caller owns the returned object. - */ -struct lttng_event *lttng_event_rule_generate_lttng_event( - const struct lttng_event_rule *rule); - -/* Test if an event rule targets an agent domain. */ -bool lttng_event_rule_targets_agent_domain(const struct lttng_event_rule *rule); - -enum lttng_error_code lttng_event_rule_mi_serialize( - const struct lttng_event_rule *rule, struct mi_writer *writer); - -#endif /* LTTNG_EVENT_RULE_INTERNAL_H */ diff --git a/include/lttng/event-rule/event-rule-internal.hpp b/include/lttng/event-rule/event-rule-internal.hpp new file mode 100644 index 000000000..46fb98144 --- /dev/null +++ b/include/lttng/event-rule/event-rule-internal.hpp @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2019 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_RULE_INTERNAL_H +#define LTTNG_EVENT_RULE_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct lttng_payload; +struct lttng_payload_view; +struct mi_writer; + +enum lttng_event_rule_generate_exclusions_status { + LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OK, + LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_NONE, + LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_ERROR, + LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OUT_OF_MEMORY, +}; + +typedef void (*event_rule_destroy_cb)(struct lttng_event_rule *event_rule); +typedef bool (*event_rule_validate_cb)( + const struct lttng_event_rule *event_rule); +typedef int (*event_rule_serialize_cb)( + const struct lttng_event_rule *event_rule, + struct lttng_payload *payload); +typedef bool (*event_rule_equal_cb)(const struct lttng_event_rule *a, + const struct lttng_event_rule *b); +typedef ssize_t (*event_rule_create_from_payload_cb)( + struct lttng_payload_view *view, + struct lttng_event_rule **event_rule); +typedef enum lttng_error_code (*event_rule_generate_filter_bytecode_cb)( + struct lttng_event_rule *event_rule, + const struct lttng_credentials *creds); +typedef const char *(*event_rule_get_filter_cb)( + const struct lttng_event_rule *event_rule); +typedef const struct lttng_bytecode *( + *event_rule_get_filter_bytecode_cb)( + const struct lttng_event_rule *event_rule); +typedef enum lttng_event_rule_generate_exclusions_status ( + *event_rule_generate_exclusions_cb)( + const struct lttng_event_rule *event_rule, + struct lttng_event_exclusion **exclusions); +typedef unsigned long (*event_rule_hash_cb)( + const struct lttng_event_rule *event_rule); +typedef struct lttng_event *(*event_rule_generate_lttng_event_cb)( + const struct lttng_event_rule *event_rule); +typedef enum lttng_error_code (*event_rule_mi_serialize_cb)( + const struct lttng_event_rule *event_rule, + struct mi_writer *writer); + +struct lttng_event_rule { + struct urcu_ref ref; + enum lttng_event_rule_type type; + event_rule_validate_cb validate; + event_rule_serialize_cb serialize; + event_rule_equal_cb equal; + event_rule_destroy_cb destroy; + event_rule_generate_filter_bytecode_cb generate_filter_bytecode; + event_rule_get_filter_cb get_filter; + event_rule_get_filter_bytecode_cb get_filter_bytecode; + event_rule_generate_exclusions_cb generate_exclusions; + event_rule_hash_cb hash; + event_rule_generate_lttng_event_cb generate_lttng_event; + event_rule_mi_serialize_cb mi_serialize; +}; + +struct lttng_event_rule_comm { + /* enum lttng_event_rule_type */ + int8_t event_rule_type; + char payload[]; +}; + +void lttng_event_rule_init(struct lttng_event_rule *event_rule, + enum lttng_event_rule_type type); + +bool lttng_event_rule_validate(const struct lttng_event_rule *event_rule); + +ssize_t lttng_event_rule_create_from_payload( + struct lttng_payload_view *payload, + struct lttng_event_rule **event_rule); + +int lttng_event_rule_serialize(const struct lttng_event_rule *event_rule, + struct lttng_payload *payload); + +bool lttng_event_rule_is_equal(const struct lttng_event_rule *a, + const struct lttng_event_rule *b); + +bool lttng_event_rule_get(struct lttng_event_rule *rule); + +void lttng_event_rule_put(struct lttng_event_rule *rule); + +enum lttng_domain_type lttng_event_rule_get_domain_type( + const struct lttng_event_rule *rule); + +enum lttng_error_code lttng_event_rule_generate_filter_bytecode( + struct lttng_event_rule *rule, + const struct lttng_credentials *creds); + +/* + * If not present/implemented returns NULL. + * Caller DOES NOT own the returned object. + */ +const char *lttng_event_rule_get_filter(const struct lttng_event_rule *rule); + +/* + * If not present/implemented returns NULL. + * Caller DOES NOT own the returned object. + */ +const struct lttng_bytecode *lttng_event_rule_get_filter_bytecode( + const struct lttng_event_rule *rule); + +/* + * If not present/implemented return NULL. + * Caller OWNS the returned object. + */ +enum lttng_event_rule_generate_exclusions_status +lttng_event_rule_generate_exclusions(const struct lttng_event_rule *rule, + struct lttng_event_exclusion **exclusions); + +const char *lttng_event_rule_type_str(enum lttng_event_rule_type type); + +unsigned long lttng_event_rule_hash(const struct lttng_event_rule *rule); + +/* + * This is a compatibility helper allowing us to generate a sessiond-side (not + * communication) `struct lttng_event` object from an event rule. + * + * This effectively bridges older parts of the code using those structures and + * new event-rule based code. + * + * The caller owns the returned object. + */ +struct lttng_event *lttng_event_rule_generate_lttng_event( + const struct lttng_event_rule *rule); + +/* Test if an event rule targets an agent domain. */ +bool lttng_event_rule_targets_agent_domain(const struct lttng_event_rule *rule); + +enum lttng_error_code lttng_event_rule_mi_serialize( + const struct lttng_event_rule *rule, struct mi_writer *writer); + +#endif /* LTTNG_EVENT_RULE_INTERNAL_H */ diff --git a/include/lttng/event-rule/jul-logging-internal.h b/include/lttng/event-rule/jul-logging-internal.h deleted file mode 100644 index 21a99eb7e..000000000 --- a/include/lttng/event-rule/jul-logging-internal.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_RULE_JUL_LOGGING_INTERNAL_H -#define LTTNG_EVENT_RULE_JUL_LOGGING_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include - -struct lttng_event_rule_jul_logging { - struct lttng_event_rule parent; - - /* Name pattern. */ - char *pattern; - - /* Filter. */ - char *filter_expression; - - /* Log level. */ - struct lttng_log_level_rule *log_level_rule; - - /* internal use only. */ - struct { - char *filter; - struct lttng_bytecode *bytecode; - } internal_filter; -}; - -struct lttng_event_rule_jul_logging_comm { - /* Includes terminator `\0`. */ - uint32_t pattern_len; - /* Includes terminator `\0`. */ - uint32_t filter_expression_len; - /* enum lttng_log_level_rule_comm + payload if any */ - uint32_t log_level_rule_len; - /* - * Payload is composed of, in that order: - * - pattern (null terminated), - * - filter expression (null terminated), - * - log level rule serialized object, - */ - char payload[]; -} LTTNG_PACKED; - -ssize_t lttng_event_rule_jul_logging_create_from_payload( - struct lttng_payload_view *view, - struct lttng_event_rule **rule); - -#endif /* LTTNG_EVENT_RULE_JUL_LOGGING_INTERNAL_H */ diff --git a/include/lttng/event-rule/jul-logging-internal.hpp b/include/lttng/event-rule/jul-logging-internal.hpp new file mode 100644 index 000000000..b769f0f80 --- /dev/null +++ b/include/lttng/event-rule/jul-logging-internal.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2021 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_RULE_JUL_LOGGING_INTERNAL_H +#define LTTNG_EVENT_RULE_JUL_LOGGING_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include + +struct lttng_event_rule_jul_logging { + struct lttng_event_rule parent; + + /* Name pattern. */ + char *pattern; + + /* Filter. */ + char *filter_expression; + + /* Log level. */ + struct lttng_log_level_rule *log_level_rule; + + /* internal use only. */ + struct { + char *filter; + struct lttng_bytecode *bytecode; + } internal_filter; +}; + +struct lttng_event_rule_jul_logging_comm { + /* Includes terminator `\0`. */ + uint32_t pattern_len; + /* Includes terminator `\0`. */ + uint32_t filter_expression_len; + /* enum lttng_log_level_rule_comm + payload if any */ + uint32_t log_level_rule_len; + /* + * Payload is composed of, in that order: + * - pattern (null terminated), + * - filter expression (null terminated), + * - log level rule serialized object, + */ + char payload[]; +} LTTNG_PACKED; + +ssize_t lttng_event_rule_jul_logging_create_from_payload( + struct lttng_payload_view *view, + struct lttng_event_rule **rule); + +#endif /* LTTNG_EVENT_RULE_JUL_LOGGING_INTERNAL_H */ diff --git a/include/lttng/event-rule/kernel-kprobe-internal.h b/include/lttng/event-rule/kernel-kprobe-internal.h deleted file mode 100644 index 16ac2bd3c..000000000 --- a/include/lttng/event-rule/kernel-kprobe-internal.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2019 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_RULE_KERNEL_KPROBE_INTERNAL_H -#define LTTNG_EVENT_RULE_KERNEL_KPROBE_INTERNAL_H - -#include -#include -#include -#include - -struct lttng_event_rule_kernel_kprobe { - struct lttng_event_rule parent; - char *name; - struct lttng_kernel_probe_location *location; -}; - -struct lttng_event_rule_kernel_kprobe_comm { - /* Includes terminator `\0`. */ - uint32_t name_len; - uint32_t location_len; - /* - * Payload is composed of, in that order: - * - name (null terminated), - * - kernel probe location object. - */ - char payload[]; -} LTTNG_PACKED; - -ssize_t lttng_event_rule_kernel_kprobe_create_from_payload( - struct lttng_payload_view *payload, - struct lttng_event_rule **rule); - -#endif /* LTTNG_EVENT_RULE_KERNEL_KPROBE_INTERNAL_H */ diff --git a/include/lttng/event-rule/kernel-kprobe-internal.hpp b/include/lttng/event-rule/kernel-kprobe-internal.hpp new file mode 100644 index 000000000..5b4997987 --- /dev/null +++ b/include/lttng/event-rule/kernel-kprobe-internal.hpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_RULE_KERNEL_KPROBE_INTERNAL_H +#define LTTNG_EVENT_RULE_KERNEL_KPROBE_INTERNAL_H + +#include +#include +#include +#include + +struct lttng_event_rule_kernel_kprobe { + struct lttng_event_rule parent; + char *name; + struct lttng_kernel_probe_location *location; +}; + +struct lttng_event_rule_kernel_kprobe_comm { + /* Includes terminator `\0`. */ + uint32_t name_len; + uint32_t location_len; + /* + * Payload is composed of, in that order: + * - name (null terminated), + * - kernel probe location object. + */ + char payload[]; +} LTTNG_PACKED; + +ssize_t lttng_event_rule_kernel_kprobe_create_from_payload( + struct lttng_payload_view *payload, + struct lttng_event_rule **rule); + +#endif /* LTTNG_EVENT_RULE_KERNEL_KPROBE_INTERNAL_H */ diff --git a/include/lttng/event-rule/kernel-syscall-internal.h b/include/lttng/event-rule/kernel-syscall-internal.h deleted file mode 100644 index 301238153..000000000 --- a/include/lttng/event-rule/kernel-syscall-internal.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2019 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_RULE_KERNEL_SYSCALL_INTERNAL_H -#define LTTNG_EVENT_RULE_KERNEL_SYSCALL_INTERNAL_H - -#include -#include -#include -#include - -struct lttng_event_rule_kernel_syscall { - struct lttng_event_rule parent; - enum lttng_event_rule_kernel_syscall_emission_site emission_site; - char *pattern; - char *filter_expression; - - /* Internal use only. */ - struct { - char *filter; - struct lttng_bytecode *bytecode; - } internal_filter; -}; - -struct lttng_event_rule_kernel_syscall_comm { - uint32_t emission_site; - /* Includes terminator `\0`. */ - uint32_t pattern_len; - /* Includes terminator `\0`. */ - uint32_t filter_expression_len; - /* - * Payload is composed of, in that order: - * - Pattern (null terminated), - * - Filter expression (null terminated). - */ - char payload[]; -} LTTNG_PACKED; - -ssize_t lttng_event_rule_kernel_syscall_create_from_payload( - struct lttng_payload_view *view, - struct lttng_event_rule **rule); - -const char *lttng_event_rule_kernel_syscall_emission_site_str( - enum lttng_event_rule_kernel_syscall_emission_site emission_site); - -#endif /* LTTNG_EVENT_RULE_KERNEL_SYSCALL_INTERNAL_H */ diff --git a/include/lttng/event-rule/kernel-syscall-internal.hpp b/include/lttng/event-rule/kernel-syscall-internal.hpp new file mode 100644 index 000000000..2ca1823ec --- /dev/null +++ b/include/lttng/event-rule/kernel-syscall-internal.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_RULE_KERNEL_SYSCALL_INTERNAL_H +#define LTTNG_EVENT_RULE_KERNEL_SYSCALL_INTERNAL_H + +#include +#include +#include +#include + +struct lttng_event_rule_kernel_syscall { + struct lttng_event_rule parent; + enum lttng_event_rule_kernel_syscall_emission_site emission_site; + char *pattern; + char *filter_expression; + + /* Internal use only. */ + struct { + char *filter; + struct lttng_bytecode *bytecode; + } internal_filter; +}; + +struct lttng_event_rule_kernel_syscall_comm { + uint32_t emission_site; + /* Includes terminator `\0`. */ + uint32_t pattern_len; + /* Includes terminator `\0`. */ + uint32_t filter_expression_len; + /* + * Payload is composed of, in that order: + * - Pattern (null terminated), + * - Filter expression (null terminated). + */ + char payload[]; +} LTTNG_PACKED; + +ssize_t lttng_event_rule_kernel_syscall_create_from_payload( + struct lttng_payload_view *view, + struct lttng_event_rule **rule); + +const char *lttng_event_rule_kernel_syscall_emission_site_str( + enum lttng_event_rule_kernel_syscall_emission_site emission_site); + +#endif /* LTTNG_EVENT_RULE_KERNEL_SYSCALL_INTERNAL_H */ diff --git a/include/lttng/event-rule/kernel-tracepoint-internal.h b/include/lttng/event-rule/kernel-tracepoint-internal.h deleted file mode 100644 index e16596e64..000000000 --- a/include/lttng/event-rule/kernel-tracepoint-internal.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2019 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_RULE_KERNEL_TRACEPOINT_INTERNAL_H -#define LTTNG_EVENT_RULE_KERNEL_TRACEPOINT_INTERNAL_H - -#include -#include -#include -#include -#include -#include - -struct lttng_event_rule_kernel_tracepoint { - struct lttng_event_rule parent; - - /* Name pattern. */ - char *pattern; - - /* Filter. */ - char *filter_expression; - - /* internal use only. */ - struct { - char *filter; - struct lttng_bytecode *bytecode; - } internal_filter; -}; - -struct lttng_event_rule_kernel_tracepoint_comm { - /* Includes terminator `\0`. */ - uint32_t pattern_len; - /* Includes terminator `\0`. */ - uint32_t filter_expression_len; - /* - * Payload is composed of, in that order: - * - pattern (null terminated), - * - filter expression (null terminated), - */ - char payload[]; -} LTTNG_PACKED; - -ssize_t lttng_event_rule_kernel_tracepoint_create_from_payload( - struct lttng_payload_view *view, - struct lttng_event_rule **rule); - -#endif /* LTTNG_EVENT_RULE_KERNEL_TRACEPOINT_INTERNAL_H */ diff --git a/include/lttng/event-rule/kernel-tracepoint-internal.hpp b/include/lttng/event-rule/kernel-tracepoint-internal.hpp new file mode 100644 index 000000000..d800eef91 --- /dev/null +++ b/include/lttng/event-rule/kernel-tracepoint-internal.hpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_RULE_KERNEL_TRACEPOINT_INTERNAL_H +#define LTTNG_EVENT_RULE_KERNEL_TRACEPOINT_INTERNAL_H + +#include +#include +#include +#include +#include +#include + +struct lttng_event_rule_kernel_tracepoint { + struct lttng_event_rule parent; + + /* Name pattern. */ + char *pattern; + + /* Filter. */ + char *filter_expression; + + /* internal use only. */ + struct { + char *filter; + struct lttng_bytecode *bytecode; + } internal_filter; +}; + +struct lttng_event_rule_kernel_tracepoint_comm { + /* Includes terminator `\0`. */ + uint32_t pattern_len; + /* Includes terminator `\0`. */ + uint32_t filter_expression_len; + /* + * Payload is composed of, in that order: + * - pattern (null terminated), + * - filter expression (null terminated), + */ + char payload[]; +} LTTNG_PACKED; + +ssize_t lttng_event_rule_kernel_tracepoint_create_from_payload( + struct lttng_payload_view *view, + struct lttng_event_rule **rule); + +#endif /* LTTNG_EVENT_RULE_KERNEL_TRACEPOINT_INTERNAL_H */ diff --git a/include/lttng/event-rule/kernel-uprobe-internal.h b/include/lttng/event-rule/kernel-uprobe-internal.h deleted file mode 100644 index d8ce55793..000000000 --- a/include/lttng/event-rule/kernel-uprobe-internal.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2019 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_RULE_KERNEL_UPROBE_INTERNAL_H -#define LTTNG_EVENT_RULE_KERNEL_UPROBE_INTERNAL_H - -#include -#include -#include -#include - -struct lttng_event_rule_kernel_uprobe { - struct lttng_event_rule parent; - char *name; - struct lttng_userspace_probe_location *location; -}; - -struct lttng_event_rule_kernel_uprobe_comm { - /* Includes terminator `\0`. */ - uint32_t name_len; - /* Includes terminator `\0`. */ - uint32_t location_len; - /* - * Payload is composed of, in that order: - * - name (null terminated), - * - user space probe location object. - */ - char payload[]; -} LTTNG_PACKED; - -ssize_t lttng_event_rule_kernel_uprobe_create_from_payload( - struct lttng_payload_view *view, - struct lttng_event_rule **rule); - -struct lttng_userspace_probe_location * -lttng_event_rule_kernel_uprobe_get_location_mutable( - const struct lttng_event_rule *rule); - -#endif /* LTTNG_EVENT_RULE_KERNEL_UPROBE_INTERNAL_H */ diff --git a/include/lttng/event-rule/kernel-uprobe-internal.hpp b/include/lttng/event-rule/kernel-uprobe-internal.hpp new file mode 100644 index 000000000..f9a193100 --- /dev/null +++ b/include/lttng/event-rule/kernel-uprobe-internal.hpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2019 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_RULE_KERNEL_UPROBE_INTERNAL_H +#define LTTNG_EVENT_RULE_KERNEL_UPROBE_INTERNAL_H + +#include +#include +#include +#include + +struct lttng_event_rule_kernel_uprobe { + struct lttng_event_rule parent; + char *name; + struct lttng_userspace_probe_location *location; +}; + +struct lttng_event_rule_kernel_uprobe_comm { + /* Includes terminator `\0`. */ + uint32_t name_len; + /* Includes terminator `\0`. */ + uint32_t location_len; + /* + * Payload is composed of, in that order: + * - name (null terminated), + * - user space probe location object. + */ + char payload[]; +} LTTNG_PACKED; + +ssize_t lttng_event_rule_kernel_uprobe_create_from_payload( + struct lttng_payload_view *view, + struct lttng_event_rule **rule); + +struct lttng_userspace_probe_location * +lttng_event_rule_kernel_uprobe_get_location_mutable( + const struct lttng_event_rule *rule); + +#endif /* LTTNG_EVENT_RULE_KERNEL_UPROBE_INTERNAL_H */ diff --git a/include/lttng/event-rule/log4j-logging-internal.h b/include/lttng/event-rule/log4j-logging-internal.h deleted file mode 100644 index 7a1ac2831..000000000 --- a/include/lttng/event-rule/log4j-logging-internal.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_RULE_LOG4J_LOGGING_INTERNAL_H -#define LTTNG_EVENT_RULE_LOG4J_LOGGING_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include - -struct lttng_event_rule_log4j_logging { - struct lttng_event_rule parent; - - /* Name pattern. */ - char *pattern; - - /* Filter. */ - char *filter_expression; - - /* Log level. */ - struct lttng_log_level_rule *log_level_rule; - - /* internal use only. */ - struct { - char *filter; - struct lttng_bytecode *bytecode; - } internal_filter; -}; - -struct lttng_event_rule_log4j_logging_comm { - /* Includes terminator `\0`. */ - uint32_t pattern_len; - /* Includes terminator `\0`. */ - uint32_t filter_expression_len; - /* enum lttng_log_level_rule_comm + payload if any */ - uint32_t log_level_rule_len; - /* - * Payload is composed of, in that order: - * - pattern (null terminated), - * - filter expression (null terminated), - * - log level rule serialized object, - */ - char payload[]; -} LTTNG_PACKED; - -ssize_t lttng_event_rule_log4j_logging_create_from_payload( - struct lttng_payload_view *view, - struct lttng_event_rule **rule); - -#endif /* LTTNG_EVENT_RULE_LOG4J_LOGGING_INTERNAL_H */ diff --git a/include/lttng/event-rule/log4j-logging-internal.hpp b/include/lttng/event-rule/log4j-logging-internal.hpp new file mode 100644 index 000000000..a65e74b6d --- /dev/null +++ b/include/lttng/event-rule/log4j-logging-internal.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2021 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_RULE_LOG4J_LOGGING_INTERNAL_H +#define LTTNG_EVENT_RULE_LOG4J_LOGGING_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include + +struct lttng_event_rule_log4j_logging { + struct lttng_event_rule parent; + + /* Name pattern. */ + char *pattern; + + /* Filter. */ + char *filter_expression; + + /* Log level. */ + struct lttng_log_level_rule *log_level_rule; + + /* internal use only. */ + struct { + char *filter; + struct lttng_bytecode *bytecode; + } internal_filter; +}; + +struct lttng_event_rule_log4j_logging_comm { + /* Includes terminator `\0`. */ + uint32_t pattern_len; + /* Includes terminator `\0`. */ + uint32_t filter_expression_len; + /* enum lttng_log_level_rule_comm + payload if any */ + uint32_t log_level_rule_len; + /* + * Payload is composed of, in that order: + * - pattern (null terminated), + * - filter expression (null terminated), + * - log level rule serialized object, + */ + char payload[]; +} LTTNG_PACKED; + +ssize_t lttng_event_rule_log4j_logging_create_from_payload( + struct lttng_payload_view *view, + struct lttng_event_rule **rule); + +#endif /* LTTNG_EVENT_RULE_LOG4J_LOGGING_INTERNAL_H */ diff --git a/include/lttng/event-rule/python-logging-internal.h b/include/lttng/event-rule/python-logging-internal.h deleted file mode 100644 index 9f6f7fe68..000000000 --- a/include/lttng/event-rule/python-logging-internal.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_RULE_PYTHON_LOGGING_INTERNAL_H -#define LTTNG_EVENT_RULE_PYTHON_LOGGING_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include - -struct lttng_event_rule_python_logging { - struct lttng_event_rule parent; - - /* Name pattern. */ - char *pattern; - - /* Filter. */ - char *filter_expression; - - /* Log level. */ - struct lttng_log_level_rule *log_level_rule; - - /* internal use only. */ - struct { - char *filter; - struct lttng_bytecode *bytecode; - } internal_filter; -}; - -struct lttng_event_rule_python_logging_comm { - /* Includes terminator `\0`. */ - uint32_t pattern_len; - /* Includes terminator `\0`. */ - uint32_t filter_expression_len; - /* enum lttng_log_level_rule_comm + payload if any */ - uint32_t log_level_rule_len; - /* - * Payload is composed of, in that order: - * - pattern (null terminated), - * - filter expression (null terminated), - * - log level rule serialized object, - */ - char payload[]; -} LTTNG_PACKED; - -ssize_t lttng_event_rule_python_logging_create_from_payload( - struct lttng_payload_view *view, - struct lttng_event_rule **rule); - -#endif /* LTTNG_EVENT_RULE_PYTHON_LOGGING_INTERNAL_H */ diff --git a/include/lttng/event-rule/python-logging-internal.hpp b/include/lttng/event-rule/python-logging-internal.hpp new file mode 100644 index 000000000..d23f4e2a5 --- /dev/null +++ b/include/lttng/event-rule/python-logging-internal.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2021 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_RULE_PYTHON_LOGGING_INTERNAL_H +#define LTTNG_EVENT_RULE_PYTHON_LOGGING_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include + +struct lttng_event_rule_python_logging { + struct lttng_event_rule parent; + + /* Name pattern. */ + char *pattern; + + /* Filter. */ + char *filter_expression; + + /* Log level. */ + struct lttng_log_level_rule *log_level_rule; + + /* internal use only. */ + struct { + char *filter; + struct lttng_bytecode *bytecode; + } internal_filter; +}; + +struct lttng_event_rule_python_logging_comm { + /* Includes terminator `\0`. */ + uint32_t pattern_len; + /* Includes terminator `\0`. */ + uint32_t filter_expression_len; + /* enum lttng_log_level_rule_comm + payload if any */ + uint32_t log_level_rule_len; + /* + * Payload is composed of, in that order: + * - pattern (null terminated), + * - filter expression (null terminated), + * - log level rule serialized object, + */ + char payload[]; +} LTTNG_PACKED; + +ssize_t lttng_event_rule_python_logging_create_from_payload( + struct lttng_payload_view *view, + struct lttng_event_rule **rule); + +#endif /* LTTNG_EVENT_RULE_PYTHON_LOGGING_INTERNAL_H */ diff --git a/include/lttng/event-rule/user-tracepoint-internal.h b/include/lttng/event-rule/user-tracepoint-internal.h deleted file mode 100644 index 9cd8b0582..000000000 --- a/include/lttng/event-rule/user-tracepoint-internal.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2021 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_EVENT_RULE_USER_TRACEPOINT_INTERNAL_H -#define LTTNG_EVENT_RULE_USER_TRACEPOINT_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include -#include - -struct lttng_event_rule_user_tracepoint { - struct lttng_event_rule parent; - - /* Name pattern. */ - char *pattern; - - /* Filter. */ - char *filter_expression; - - /* Log level. */ - struct lttng_log_level_rule *log_level_rule; - - /* Exclusions. */ - struct lttng_dynamic_pointer_array exclusions; - - /* internal use only. */ - struct { - char *filter; - struct lttng_bytecode *bytecode; - } internal_filter; -}; - -struct lttng_event_rule_user_tracepoint_comm { - /* Includes terminator `\0`. */ - uint32_t pattern_len; - /* Includes terminator `\0`. */ - uint32_t filter_expression_len; - /* enum lttng_log_level_rule_comm + payload if any */ - uint32_t log_level_rule_len; - uint32_t exclusions_count; - uint32_t exclusions_len; - /* - * Payload is composed of, in that order: - * - pattern (null terminated), - * - filter expression (null terminated), - * - log level rule serialized object, - * - exclusions (32 bit length + null terminated string). - */ - char payload[]; -} LTTNG_PACKED; - -ssize_t lttng_event_rule_user_tracepoint_create_from_payload( - struct lttng_payload_view *view, - struct lttng_event_rule **rule); - -#endif /* LTTNG_EVENT_RULE_USER_TRACEPOINT_INTERNAL_H */ diff --git a/include/lttng/event-rule/user-tracepoint-internal.hpp b/include/lttng/event-rule/user-tracepoint-internal.hpp new file mode 100644 index 000000000..1960a8a4d --- /dev/null +++ b/include/lttng/event-rule/user-tracepoint-internal.hpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2021 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EVENT_RULE_USER_TRACEPOINT_INTERNAL_H +#define LTTNG_EVENT_RULE_USER_TRACEPOINT_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include +#include + +struct lttng_event_rule_user_tracepoint { + struct lttng_event_rule parent; + + /* Name pattern. */ + char *pattern; + + /* Filter. */ + char *filter_expression; + + /* Log level. */ + struct lttng_log_level_rule *log_level_rule; + + /* Exclusions. */ + struct lttng_dynamic_pointer_array exclusions; + + /* internal use only. */ + struct { + char *filter; + struct lttng_bytecode *bytecode; + } internal_filter; +}; + +struct lttng_event_rule_user_tracepoint_comm { + /* Includes terminator `\0`. */ + uint32_t pattern_len; + /* Includes terminator `\0`. */ + uint32_t filter_expression_len; + /* enum lttng_log_level_rule_comm + payload if any */ + uint32_t log_level_rule_len; + uint32_t exclusions_count; + uint32_t exclusions_len; + /* + * Payload is composed of, in that order: + * - pattern (null terminated), + * - filter expression (null terminated), + * - log level rule serialized object, + * - exclusions (32 bit length + null terminated string). + */ + char payload[]; +} LTTNG_PACKED; + +ssize_t lttng_event_rule_user_tracepoint_create_from_payload( + struct lttng_payload_view *view, + struct lttng_event_rule **rule); + +#endif /* LTTNG_EVENT_RULE_USER_TRACEPOINT_INTERNAL_H */ diff --git a/include/lttng/health-internal.h b/include/lttng/health-internal.h deleted file mode 100644 index ceda0a8dd..000000000 --- a/include/lttng/health-internal.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef HEALTH_INTERNAL_H -#define HEALTH_INTERNAL_H - -/* - * Copyright (C) 2012 David Goulet - * Copyright (C) 2013 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include -#include -#include -#include -#include -#include - -/* - * These are the value added to the current state depending of the position in - * the thread where is either waiting on a poll() or running in the code. - */ -#define HEALTH_POLL_VALUE (1UL << 0) -#define HEALTH_CODE_VALUE (1UL << 1) - -#define HEALTH_IS_IN_POLL(x) ((x) & HEALTH_POLL_VALUE) - -struct health_app; - -enum health_flags { - HEALTH_ERROR = (1U << 0), -}; - -struct health_state { - /* - * last counter and last_time are only read and updated by the health_check - * thread (single updater). - */ - unsigned long last; - struct timespec last_time; - - /* - * current and flags are updated by multiple threads concurrently. - */ - unsigned long current; /* progress counter, updated atomically */ - enum health_flags flags; /* other flags, updated atomically */ - int type; /* Indicates the nature of the thread. */ - /* Node of the global TLS state list. */ - struct cds_list_head node; -}; - -enum health_cmd { - HEALTH_CMD_CHECK = 0, -}; - -struct health_comm_msg { - uint32_t cmd; /* enum health_cmd */ -} LTTNG_PACKED; - -struct health_comm_reply { - uint64_t ret_code; /* bitmask of threads in bad health */ -} LTTNG_PACKED; - -/* Declare TLS health state. */ -extern DECLARE_URCU_TLS(struct health_state, health_state); - -/* - * Update current counter by 1 to indicate that the thread entered or left a - * blocking state caused by a poll(). If the counter's value is not an even - * number (meaning a code execution flow), an LTTNG_ASSERT() is raised. - */ -static inline void health_poll_entry(void) -{ - /* Code MUST be in code execution state which is an even number. */ - LTTNG_ASSERT(!(uatomic_read(&URCU_TLS(health_state).current) - & HEALTH_POLL_VALUE)); - - uatomic_add(&URCU_TLS(health_state).current, HEALTH_POLL_VALUE); -} - -/* - * Update current counter by 1 indicating the exit of a poll or blocking call. - * If the counter's value is not an odd number (a poll execution), an LTTNG_ASSERT() - * is raised. - */ -static inline void health_poll_exit(void) -{ - /* Code MUST be in poll execution state which is an odd number. */ - LTTNG_ASSERT(uatomic_read(&URCU_TLS(health_state).current) - & HEALTH_POLL_VALUE); - - uatomic_add(&URCU_TLS(health_state).current, HEALTH_POLL_VALUE); -} - -/* - * Update current counter by 2 indicates progress in execution of a - * thread. - */ -static inline void health_code_update(void) -{ - uatomic_add(&URCU_TLS(health_state).current, HEALTH_CODE_VALUE); -} - -/* - * Set health "error" flag. - */ -static inline void health_error(void) -{ - uatomic_or(&URCU_TLS(health_state).flags, HEALTH_ERROR); -} - -struct health_app *health_app_create(int nr_types); -void health_app_destroy(struct health_app *ha); -int health_check_state(struct health_app *ha, int type); -void health_register(struct health_app *ha, int type); -void health_unregister(struct health_app *ha); - -#endif /* HEALTH_INTERNAL_H */ diff --git a/include/lttng/health-internal.hpp b/include/lttng/health-internal.hpp new file mode 100644 index 000000000..67bdc6a5e --- /dev/null +++ b/include/lttng/health-internal.hpp @@ -0,0 +1,119 @@ +#ifndef HEALTH_INTERNAL_H +#define HEALTH_INTERNAL_H + +/* + * Copyright (C) 2012 David Goulet + * Copyright (C) 2013 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include +#include +#include +#include +#include +#include + +/* + * These are the value added to the current state depending of the position in + * the thread where is either waiting on a poll() or running in the code. + */ +#define HEALTH_POLL_VALUE (1UL << 0) +#define HEALTH_CODE_VALUE (1UL << 1) + +#define HEALTH_IS_IN_POLL(x) ((x) & HEALTH_POLL_VALUE) + +struct health_app; + +enum health_flags { + HEALTH_ERROR = (1U << 0), +}; + +struct health_state { + /* + * last counter and last_time are only read and updated by the health_check + * thread (single updater). + */ + unsigned long last; + struct timespec last_time; + + /* + * current and flags are updated by multiple threads concurrently. + */ + unsigned long current; /* progress counter, updated atomically */ + enum health_flags flags; /* other flags, updated atomically */ + int type; /* Indicates the nature of the thread. */ + /* Node of the global TLS state list. */ + struct cds_list_head node; +}; + +enum health_cmd { + HEALTH_CMD_CHECK = 0, +}; + +struct health_comm_msg { + uint32_t cmd; /* enum health_cmd */ +} LTTNG_PACKED; + +struct health_comm_reply { + uint64_t ret_code; /* bitmask of threads in bad health */ +} LTTNG_PACKED; + +/* Declare TLS health state. */ +extern DECLARE_URCU_TLS(struct health_state, health_state); + +/* + * Update current counter by 1 to indicate that the thread entered or left a + * blocking state caused by a poll(). If the counter's value is not an even + * number (meaning a code execution flow), an LTTNG_ASSERT() is raised. + */ +static inline void health_poll_entry(void) +{ + /* Code MUST be in code execution state which is an even number. */ + LTTNG_ASSERT(!(uatomic_read(&URCU_TLS(health_state).current) + & HEALTH_POLL_VALUE)); + + uatomic_add(&URCU_TLS(health_state).current, HEALTH_POLL_VALUE); +} + +/* + * Update current counter by 1 indicating the exit of a poll or blocking call. + * If the counter's value is not an odd number (a poll execution), an LTTNG_ASSERT() + * is raised. + */ +static inline void health_poll_exit(void) +{ + /* Code MUST be in poll execution state which is an odd number. */ + LTTNG_ASSERT(uatomic_read(&URCU_TLS(health_state).current) + & HEALTH_POLL_VALUE); + + uatomic_add(&URCU_TLS(health_state).current, HEALTH_POLL_VALUE); +} + +/* + * Update current counter by 2 indicates progress in execution of a + * thread. + */ +static inline void health_code_update(void) +{ + uatomic_add(&URCU_TLS(health_state).current, HEALTH_CODE_VALUE); +} + +/* + * Set health "error" flag. + */ +static inline void health_error(void) +{ + uatomic_or(&URCU_TLS(health_state).flags, HEALTH_ERROR); +} + +struct health_app *health_app_create(int nr_types); +void health_app_destroy(struct health_app *ha); +int health_check_state(struct health_app *ha, int type); +void health_register(struct health_app *ha, int type); +void health_unregister(struct health_app *ha); + +#endif /* HEALTH_INTERNAL_H */ diff --git a/include/lttng/kernel-probe-internal.h b/include/lttng/kernel-probe-internal.h deleted file mode 100644 index 2d2ab8684..000000000 --- a/include/lttng/kernel-probe-internal.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2020 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_KERNEL_PROBE_INTERNAL_H -#define LTTNG_KERNEL_PROBE_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include -#include - -struct lttng_payload; -struct lttng_payload_view; -struct lttng_dynamic_buffer; -struct mi_writer; - -typedef bool (*kernel_probe_location_equal_cb)( - const struct lttng_kernel_probe_location *a, - const struct lttng_kernel_probe_location *b); -typedef int (*kernel_probe_location_serialize_cb)( - const struct lttng_kernel_probe_location *kernel_probe_location, - struct lttng_payload *payload); -typedef bool (*kernel_probe_location_equal_cb)( - const struct lttng_kernel_probe_location *a, - const struct lttng_kernel_probe_location *b); -typedef ssize_t (*kernel_probe_location_create_from_payload_cb)( - struct lttng_payload_view *view, - struct lttng_kernel_probe_location **kernel_probe_location); -typedef unsigned long (*kernel_probe_location_hash_cb)( - const struct lttng_kernel_probe_location *location); -typedef enum lttng_error_code (*kernel_probe_location_mi_serialize_cb)( - const struct lttng_kernel_probe_location *location, - struct mi_writer *writer); - -struct lttng_kernel_probe_location_comm { - /* enum lttng_kernel_probe_location_type */ - int8_t type; - /* - * Payload is composed of, in that order, - * - type-specific payload - */ - char payload[]; -} LTTNG_PACKED; - -struct lttng_kernel_probe_location_symbol_comm { - /* Includes the trailing \0. */ - uint32_t symbol_len; - /* The offset from the symbol. */ - uint64_t offset; - /* - * Payload is composed of, in that order, - * - symbol name (with trailing \0). - */ - char payload[]; -} LTTNG_PACKED; - -struct lttng_kernel_probe_location_address_comm { - uint64_t address; -} LTTNG_PACKED; - -/* Common ancestor of all kernel probe locations. */ -struct lttng_kernel_probe_location { - enum lttng_kernel_probe_location_type type; - kernel_probe_location_equal_cb equal; - kernel_probe_location_serialize_cb serialize; - kernel_probe_location_hash_cb hash; - kernel_probe_location_mi_serialize_cb mi_serialize; -}; - -struct lttng_kernel_probe_location_symbol { - struct lttng_kernel_probe_location parent; - char *symbol_name; - uint64_t offset; -}; - -struct lttng_kernel_probe_location_address { - struct lttng_kernel_probe_location parent; - uint64_t address; -}; - -int lttng_kernel_probe_location_serialize( - const struct lttng_kernel_probe_location *location, - struct lttng_payload *payload); - -ssize_t lttng_kernel_probe_location_create_from_payload( - struct lttng_payload_view *view, - struct lttng_kernel_probe_location **probe_location); - -bool lttng_kernel_probe_location_is_equal( - const struct lttng_kernel_probe_location *a, - const struct lttng_kernel_probe_location *b); - -struct lttng_kernel_probe_location *lttng_kernel_probe_location_copy( - const struct lttng_kernel_probe_location *location); - -unsigned long lttng_kernel_probe_location_hash( - const struct lttng_kernel_probe_location *location); - -enum lttng_error_code lttng_kernel_probe_location_mi_serialize( - const struct lttng_kernel_probe_location *location, - struct mi_writer *writer); - -#endif /* LTTNG_KERNEL_PROBE_INTERNAL_H */ diff --git a/include/lttng/kernel-probe-internal.hpp b/include/lttng/kernel-probe-internal.hpp new file mode 100644 index 000000000..07c546f9d --- /dev/null +++ b/include/lttng/kernel-probe-internal.hpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2020 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_KERNEL_PROBE_INTERNAL_H +#define LTTNG_KERNEL_PROBE_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include +#include + +struct lttng_payload; +struct lttng_payload_view; +struct lttng_dynamic_buffer; +struct mi_writer; + +typedef bool (*kernel_probe_location_equal_cb)( + const struct lttng_kernel_probe_location *a, + const struct lttng_kernel_probe_location *b); +typedef int (*kernel_probe_location_serialize_cb)( + const struct lttng_kernel_probe_location *kernel_probe_location, + struct lttng_payload *payload); +typedef bool (*kernel_probe_location_equal_cb)( + const struct lttng_kernel_probe_location *a, + const struct lttng_kernel_probe_location *b); +typedef ssize_t (*kernel_probe_location_create_from_payload_cb)( + struct lttng_payload_view *view, + struct lttng_kernel_probe_location **kernel_probe_location); +typedef unsigned long (*kernel_probe_location_hash_cb)( + const struct lttng_kernel_probe_location *location); +typedef enum lttng_error_code (*kernel_probe_location_mi_serialize_cb)( + const struct lttng_kernel_probe_location *location, + struct mi_writer *writer); + +struct lttng_kernel_probe_location_comm { + /* enum lttng_kernel_probe_location_type */ + int8_t type; + /* + * Payload is composed of, in that order, + * - type-specific payload + */ + char payload[]; +} LTTNG_PACKED; + +struct lttng_kernel_probe_location_symbol_comm { + /* Includes the trailing \0. */ + uint32_t symbol_len; + /* The offset from the symbol. */ + uint64_t offset; + /* + * Payload is composed of, in that order, + * - symbol name (with trailing \0). + */ + char payload[]; +} LTTNG_PACKED; + +struct lttng_kernel_probe_location_address_comm { + uint64_t address; +} LTTNG_PACKED; + +/* Common ancestor of all kernel probe locations. */ +struct lttng_kernel_probe_location { + enum lttng_kernel_probe_location_type type; + kernel_probe_location_equal_cb equal; + kernel_probe_location_serialize_cb serialize; + kernel_probe_location_hash_cb hash; + kernel_probe_location_mi_serialize_cb mi_serialize; +}; + +struct lttng_kernel_probe_location_symbol { + struct lttng_kernel_probe_location parent; + char *symbol_name; + uint64_t offset; +}; + +struct lttng_kernel_probe_location_address { + struct lttng_kernel_probe_location parent; + uint64_t address; +}; + +int lttng_kernel_probe_location_serialize( + const struct lttng_kernel_probe_location *location, + struct lttng_payload *payload); + +ssize_t lttng_kernel_probe_location_create_from_payload( + struct lttng_payload_view *view, + struct lttng_kernel_probe_location **probe_location); + +bool lttng_kernel_probe_location_is_equal( + const struct lttng_kernel_probe_location *a, + const struct lttng_kernel_probe_location *b); + +struct lttng_kernel_probe_location *lttng_kernel_probe_location_copy( + const struct lttng_kernel_probe_location *location); + +unsigned long lttng_kernel_probe_location_hash( + const struct lttng_kernel_probe_location *location); + +enum lttng_error_code lttng_kernel_probe_location_mi_serialize( + const struct lttng_kernel_probe_location *location, + struct mi_writer *writer); + +#endif /* LTTNG_KERNEL_PROBE_INTERNAL_H */ diff --git a/include/lttng/load-internal.h b/include/lttng/load-internal.h deleted file mode 100644 index 9284741df..000000000 --- a/include/lttng/load-internal.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2014 Jérémie Galarneau - * Copyright (C) 2014 David Goulet - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_LOAD_INTERNAL_ABI_H -#define LTTNG_LOAD_INTERNAL_ABI_H - -#include -#include - -#include -#include -#include - -/* - * Object used by the load_session API. This is opaque to the public library. - */ -struct lttng_load_session_attr { - /* Name of the session to load, empty string means all. */ - char session_name[LTTNG_NAME_MAX]; - /* URL of the session configuration file to load. */ - char input_url[PATH_MAX]; - /* Overwrite the session if it exists. */ - uint32_t overwrite; - /* The raw override url for getter */ - char *raw_override_url; - /* The raw override path url for getter */ - char *raw_override_path_url; - /* The raw override ctrl url for getter */ - char *raw_override_ctrl_url; - /* The raw override data url for getter */ - char *raw_override_data_url; - /* Override struct */ - struct config_load_session_override_attr *override_attr; -} LTTNG_PACKED; - -#endif /* LTTNG_LOAD_INTERNAL_ABI_H */ diff --git a/include/lttng/load-internal.hpp b/include/lttng/load-internal.hpp new file mode 100644 index 000000000..ef09ffd9c --- /dev/null +++ b/include/lttng/load-internal.hpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2014 Jérémie Galarneau + * Copyright (C) 2014 David Goulet + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_LOAD_INTERNAL_ABI_H +#define LTTNG_LOAD_INTERNAL_ABI_H + +#include +#include + +#include +#include +#include + +/* + * Object used by the load_session API. This is opaque to the public library. + */ +struct lttng_load_session_attr { + /* Name of the session to load, empty string means all. */ + char session_name[LTTNG_NAME_MAX]; + /* URL of the session configuration file to load. */ + char input_url[PATH_MAX]; + /* Overwrite the session if it exists. */ + uint32_t overwrite; + /* The raw override url for getter */ + char *raw_override_url; + /* The raw override path url for getter */ + char *raw_override_path_url; + /* The raw override ctrl url for getter */ + char *raw_override_ctrl_url; + /* The raw override data url for getter */ + char *raw_override_data_url; + /* Override struct */ + struct config_load_session_override_attr *override_attr; +} LTTNG_PACKED; + +#endif /* LTTNG_LOAD_INTERNAL_ABI_H */ diff --git a/include/lttng/location-internal.h b/include/lttng/location-internal.h deleted file mode 100644 index 33498c90d..000000000 --- a/include/lttng/location-internal.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_LOCATION_INTERNAL_H -#define LTTNG_LOCATION_INTERNAL_H - -#include -#include -#include -#include -#include -#include - -/* - * The public API assumes that trace archive locations are always - * provided as "constant". This means that the user of liblttng-ctl never - * has to destroy a trace archive location. Hence, users of liblttng-ctl - * have no visibility of the reference counting of archive locations. - */ -struct lttng_trace_archive_location { - struct urcu_ref ref; - enum lttng_trace_archive_location_type type; - union { - struct { - char *absolute_path; - } local; - struct { - char *host; - enum lttng_trace_archive_location_relay_protocol_type protocol; - struct { - uint16_t control, data; - } ports; - char *relative_path; - } relay; - } types; -}; - -struct lttng_trace_archive_location_comm { - /* A value from enum lttng_trace_archive_location_type */ - int8_t type; - union { - struct { - /* Includes the trailing \0. */ - uint32_t absolute_path_len; - } LTTNG_PACKED local; - struct { - /* Includes the trailing \0. */ - uint32_t hostname_len; - /* - * A value from - * enum lttng_trace_archive_location_relay_protocol_type. - */ - int8_t protocol; - struct { - uint16_t control, data; - } ports; - /* Includes the trailing \0. */ - uint32_t relative_path_len; - } LTTNG_PACKED relay; - } LTTNG_PACKED types; - /* - * Payload is composed of: - * - LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL - * - absolute path, including \0 - * - LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY - * - hostname, including \0 - * - relative path, including \0 - */ - char payload[]; -} LTTNG_PACKED; - - -struct lttng_trace_archive_location *lttng_trace_archive_location_local_create( - const char *path); - -struct lttng_trace_archive_location *lttng_trace_archive_location_relay_create( - const char *host, - enum lttng_trace_archive_location_relay_protocol_type protocol, - uint16_t control_port, uint16_t data_port, - const char *relative_path); - -ssize_t lttng_trace_archive_location_create_from_buffer( - const struct lttng_buffer_view *buffer, - struct lttng_trace_archive_location **location); - -ssize_t lttng_trace_archive_location_serialize( - const struct lttng_trace_archive_location *location, - struct lttng_dynamic_buffer *buffer); - -void lttng_trace_archive_location_get( - struct lttng_trace_archive_location *location); - -void lttng_trace_archive_location_put( - struct lttng_trace_archive_location *location); - -#endif /* LTTNG_LOCATION_INTERNAL_H */ diff --git a/include/lttng/location-internal.hpp b/include/lttng/location-internal.hpp new file mode 100644 index 000000000..4daeed061 --- /dev/null +++ b/include/lttng/location-internal.hpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_LOCATION_INTERNAL_H +#define LTTNG_LOCATION_INTERNAL_H + +#include +#include +#include +#include +#include +#include + +/* + * The public API assumes that trace archive locations are always + * provided as "constant". This means that the user of liblttng-ctl never + * has to destroy a trace archive location. Hence, users of liblttng-ctl + * have no visibility of the reference counting of archive locations. + */ +struct lttng_trace_archive_location { + struct urcu_ref ref; + enum lttng_trace_archive_location_type type; + union { + struct { + char *absolute_path; + } local; + struct { + char *host; + enum lttng_trace_archive_location_relay_protocol_type protocol; + struct { + uint16_t control, data; + } ports; + char *relative_path; + } relay; + } types; +}; + +struct lttng_trace_archive_location_comm { + /* A value from enum lttng_trace_archive_location_type */ + int8_t type; + union { + struct { + /* Includes the trailing \0. */ + uint32_t absolute_path_len; + } LTTNG_PACKED local; + struct { + /* Includes the trailing \0. */ + uint32_t hostname_len; + /* + * A value from + * enum lttng_trace_archive_location_relay_protocol_type. + */ + int8_t protocol; + struct { + uint16_t control, data; + } ports; + /* Includes the trailing \0. */ + uint32_t relative_path_len; + } LTTNG_PACKED relay; + } LTTNG_PACKED types; + /* + * Payload is composed of: + * - LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL + * - absolute path, including \0 + * - LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY + * - hostname, including \0 + * - relative path, including \0 + */ + char payload[]; +} LTTNG_PACKED; + + +struct lttng_trace_archive_location *lttng_trace_archive_location_local_create( + const char *path); + +struct lttng_trace_archive_location *lttng_trace_archive_location_relay_create( + const char *host, + enum lttng_trace_archive_location_relay_protocol_type protocol, + uint16_t control_port, uint16_t data_port, + const char *relative_path); + +ssize_t lttng_trace_archive_location_create_from_buffer( + const struct lttng_buffer_view *buffer, + struct lttng_trace_archive_location **location); + +ssize_t lttng_trace_archive_location_serialize( + const struct lttng_trace_archive_location *location, + struct lttng_dynamic_buffer *buffer); + +void lttng_trace_archive_location_get( + struct lttng_trace_archive_location *location); + +void lttng_trace_archive_location_put( + struct lttng_trace_archive_location *location); + +#endif /* LTTNG_LOCATION_INTERNAL_H */ diff --git a/include/lttng/log-level-rule-internal.h b/include/lttng/log-level-rule-internal.h deleted file mode 100644 index ac0f74b71..000000000 --- a/include/lttng/log-level-rule-internal.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2020 Jonathan Rajotte - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_LOG_LEVEL_RULE_INTERNAL_H -#define LTTNG_LOG_LEVEL_RULE_INTERNAL_H - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -struct mi_writer; - -/* - * For now only a single backing struct is used for both type of log level - * rule (exactly, as_severe) since both only have require "level" as property. - */ -struct lttng_log_level_rule { - enum lttng_log_level_rule_type type; - int level; -}; - -struct lttng_log_level_rule_comm { - /* enum lttng_log_level_rule_type */ - int8_t type; - int32_t level; -}; - -ssize_t lttng_log_level_rule_create_from_payload( - struct lttng_payload_view *view, - struct lttng_log_level_rule **rule); - -int lttng_log_level_rule_serialize(const struct lttng_log_level_rule *rule, - struct lttng_payload *payload); - -bool lttng_log_level_rule_is_equal(const struct lttng_log_level_rule *a, - const struct lttng_log_level_rule *b); - -struct lttng_log_level_rule *lttng_log_level_rule_copy( - const struct lttng_log_level_rule *source); - -void lttng_log_level_rule_to_loglevel( - const struct lttng_log_level_rule *log_level_rule, - enum lttng_loglevel_type *loglevel_type, - int *loglevel_value); - -unsigned long lttng_log_level_rule_hash( - const struct lttng_log_level_rule *log_level_rule); - -enum lttng_error_code lttng_log_level_rule_mi_serialize( - const struct lttng_log_level_rule *rule, - struct mi_writer *writer); - -#endif /* LTTNG_LOG_LEVEL_RULE_INTERNAL_H */ diff --git a/include/lttng/log-level-rule-internal.hpp b/include/lttng/log-level-rule-internal.hpp new file mode 100644 index 000000000..71447cfe3 --- /dev/null +++ b/include/lttng/log-level-rule-internal.hpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2020 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_LOG_LEVEL_RULE_INTERNAL_H +#define LTTNG_LOG_LEVEL_RULE_INTERNAL_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +struct mi_writer; + +/* + * For now only a single backing struct is used for both type of log level + * rule (exactly, as_severe) since both only have require "level" as property. + */ +struct lttng_log_level_rule { + enum lttng_log_level_rule_type type; + int level; +}; + +struct lttng_log_level_rule_comm { + /* enum lttng_log_level_rule_type */ + int8_t type; + int32_t level; +}; + +ssize_t lttng_log_level_rule_create_from_payload( + struct lttng_payload_view *view, + struct lttng_log_level_rule **rule); + +int lttng_log_level_rule_serialize(const struct lttng_log_level_rule *rule, + struct lttng_payload *payload); + +bool lttng_log_level_rule_is_equal(const struct lttng_log_level_rule *a, + const struct lttng_log_level_rule *b); + +struct lttng_log_level_rule *lttng_log_level_rule_copy( + const struct lttng_log_level_rule *source); + +void lttng_log_level_rule_to_loglevel( + const struct lttng_log_level_rule *log_level_rule, + enum lttng_loglevel_type *loglevel_type, + int *loglevel_value); + +unsigned long lttng_log_level_rule_hash( + const struct lttng_log_level_rule *log_level_rule); + +enum lttng_error_code lttng_log_level_rule_mi_serialize( + const struct lttng_log_level_rule *rule, + struct mi_writer *writer); + +#endif /* LTTNG_LOG_LEVEL_RULE_INTERNAL_H */ diff --git a/include/lttng/notification/channel-internal.h b/include/lttng/notification/channel-internal.h deleted file mode 100644 index befdca083..000000000 --- a/include/lttng/notification/channel-internal.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H -#define LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include - -/* - * Protocol version change log: - * - v1.0 - * - Initial implementation of the notification channel protocol, - * - Supported conditions are LOW/HIGH buffer usage conditions, - * - v1.1 - * - New condition type "LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE" added, - * - New condition type "LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING" added, - * - New condition type "LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED" added, - */ -#define LTTNG_NOTIFICATION_CHANNEL_VERSION_MAJOR 1 -#define LTTNG_NOTIFICATION_CHANNEL_VERSION_MINOR 1 - -enum lttng_notification_channel_message_type { - LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNKNOWN = -1, - LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_HANDSHAKE = 0, - LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_SUBSCRIBE = 1, - LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNSUBSCRIBE = 2, - LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_COMMAND_REPLY = 3, - LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION = 4, - LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION_DROPPED = 5, -}; - -struct lttng_notification_channel_message { - /* enum lttng_notification_channel_message_type */ - int8_t type; - /* Size of the payload following this field. */ - uint32_t size; - /* Number of FDs sent. */ - uint32_t fds; - char payload[]; -} LTTNG_PACKED; - -struct lttng_notification_channel_command_handshake { - uint8_t major; - uint8_t minor; -} LTTNG_PACKED; - -struct lttng_notification_channel_command_reply { - /* enum lttng_notification_channel_status */ - int8_t status; -} LTTNG_PACKED; - -struct pending_notification { - /* NULL means "notification dropped". */ - struct lttng_notification *notification; - struct cds_list_head node; -}; - -/* - * The notification channel protocol is bidirectional and accommodates - * synchronous and asynchronous communication modes: - * - * - Synchronous: commands emitted by the client to which a reply is expected - * (e.g. subscribing/unsubscribing to conditions), - * - Asynchronous: notifications which are sent by the lttng_endpoint to the - * client as one of the subscribed condition has occurred. - * - * The nature of this hybrid communication mode means that asynchronous messages - * (e.g. notifications) may be interleaved between synchronous messages (e.g. a - * command and its reply). - * - * Notifications that are received between a command and its reply and enqueued - * in the pending_notifications list. - */ -struct lttng_notification_channel { - pthread_mutex_t lock; - int socket; - struct { - /* Count of pending notifications. */ - unsigned int count; - /* List of struct pending_notification. */ - struct cds_list_head list; - } pending_notifications; - struct lttng_payload reception_payload; - /* Sessiond notification protocol version. */ - struct { - bool set; - int8_t major, minor; - } version; -}; - -#endif /* LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H */ diff --git a/include/lttng/notification/channel-internal.hpp b/include/lttng/notification/channel-internal.hpp new file mode 100644 index 000000000..3364704ee --- /dev/null +++ b/include/lttng/notification/channel-internal.hpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H +#define LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include + +/* + * Protocol version change log: + * - v1.0 + * - Initial implementation of the notification channel protocol, + * - Supported conditions are LOW/HIGH buffer usage conditions, + * - v1.1 + * - New condition type "LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE" added, + * - New condition type "LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING" added, + * - New condition type "LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED" added, + */ +#define LTTNG_NOTIFICATION_CHANNEL_VERSION_MAJOR 1 +#define LTTNG_NOTIFICATION_CHANNEL_VERSION_MINOR 1 + +enum lttng_notification_channel_message_type { + LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNKNOWN = -1, + LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_HANDSHAKE = 0, + LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_SUBSCRIBE = 1, + LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_UNSUBSCRIBE = 2, + LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_COMMAND_REPLY = 3, + LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION = 4, + LTTNG_NOTIFICATION_CHANNEL_MESSAGE_TYPE_NOTIFICATION_DROPPED = 5, +}; + +struct lttng_notification_channel_message { + /* enum lttng_notification_channel_message_type */ + int8_t type; + /* Size of the payload following this field. */ + uint32_t size; + /* Number of FDs sent. */ + uint32_t fds; + char payload[]; +} LTTNG_PACKED; + +struct lttng_notification_channel_command_handshake { + uint8_t major; + uint8_t minor; +} LTTNG_PACKED; + +struct lttng_notification_channel_command_reply { + /* enum lttng_notification_channel_status */ + int8_t status; +} LTTNG_PACKED; + +struct pending_notification { + /* NULL means "notification dropped". */ + struct lttng_notification *notification; + struct cds_list_head node; +}; + +/* + * The notification channel protocol is bidirectional and accommodates + * synchronous and asynchronous communication modes: + * + * - Synchronous: commands emitted by the client to which a reply is expected + * (e.g. subscribing/unsubscribing to conditions), + * - Asynchronous: notifications which are sent by the lttng_endpoint to the + * client as one of the subscribed condition has occurred. + * + * The nature of this hybrid communication mode means that asynchronous messages + * (e.g. notifications) may be interleaved between synchronous messages (e.g. a + * command and its reply). + * + * Notifications that are received between a command and its reply and enqueued + * in the pending_notifications list. + */ +struct lttng_notification_channel { + pthread_mutex_t lock; + int socket; + struct { + /* Count of pending notifications. */ + unsigned int count; + /* List of struct pending_notification. */ + struct cds_list_head list; + } pending_notifications; + struct lttng_payload reception_payload; + /* Sessiond notification protocol version. */ + struct { + bool set; + int8_t major, minor; + } version; +}; + +#endif /* LTTNG_NOTIFICATION_CHANNEL_INTERNAL_H */ diff --git a/include/lttng/notification/notification-internal.h b/include/lttng/notification/notification-internal.h deleted file mode 100644 index 7e601b0c7..000000000 --- a/include/lttng/notification/notification-internal.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_NOTIFICATION_INTERNAL_H -#define LTTNG_NOTIFICATION_INTERNAL_H - -#include -#include -#include -#include -#include - -struct lttng_payload; -struct lttng_payload_view; - -struct lttng_notification { - struct lttng_trigger *trigger; - struct lttng_evaluation *evaluation; -}; - -struct lttng_notification_comm { - /* Size of the payload following this field. */ - uint32_t length; - /* Trigger and evaluation objects follow. */ - char payload[]; -} LTTNG_PACKED; - -struct lttng_notification *lttng_notification_create( - struct lttng_trigger *trigger, - struct lttng_evaluation *evaluation); - -int lttng_notification_serialize(const struct lttng_notification *notification, - struct lttng_payload *payload); - -ssize_t lttng_notification_create_from_payload( - struct lttng_payload_view *view, - struct lttng_notification **notification); - -#endif /* LTTNG_NOTIFICATION_INTERNAL_H */ diff --git a/include/lttng/notification/notification-internal.hpp b/include/lttng/notification/notification-internal.hpp new file mode 100644 index 000000000..37c8f2af9 --- /dev/null +++ b/include/lttng/notification/notification-internal.hpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_NOTIFICATION_INTERNAL_H +#define LTTNG_NOTIFICATION_INTERNAL_H + +#include +#include +#include +#include +#include + +struct lttng_payload; +struct lttng_payload_view; + +struct lttng_notification { + struct lttng_trigger *trigger; + struct lttng_evaluation *evaluation; +}; + +struct lttng_notification_comm { + /* Size of the payload following this field. */ + uint32_t length; + /* Trigger and evaluation objects follow. */ + char payload[]; +} LTTNG_PACKED; + +struct lttng_notification *lttng_notification_create( + struct lttng_trigger *trigger, + struct lttng_evaluation *evaluation); + +int lttng_notification_serialize(const struct lttng_notification *notification, + struct lttng_payload *payload); + +ssize_t lttng_notification_create_from_payload( + struct lttng_payload_view *view, + struct lttng_notification **notification); + +#endif /* LTTNG_NOTIFICATION_INTERNAL_H */ diff --git a/include/lttng/ref-internal.h b/include/lttng/ref-internal.h deleted file mode 100644 index a02ae4cdc..000000000 --- a/include/lttng/ref-internal.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef LTTNG_REF_INTERNAL_H -#define LTTNG_REF_INTERNAL_H - -/* - * LTTng - Non thread-safe reference counting - * - * Copyright 2013, 2014 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - - -typedef void (*lttng_release_func)(void *); - -struct lttng_ref { - unsigned long count; - lttng_release_func release; -}; - -static inline -void lttng_ref_init(struct lttng_ref *ref, lttng_release_func release) -{ - LTTNG_ASSERT(ref); - ref->count = 1; - ref->release = release; -} - -static inline -void lttng_ref_get(struct lttng_ref *ref) -{ - LTTNG_ASSERT(ref); - ref->count++; - /* Overflow check. */ - LTTNG_ASSERT(ref->count); -} - -static inline -void lttng_ref_put(struct lttng_ref *ref) -{ - LTTNG_ASSERT(ref); - /* Underflow check. */ - LTTNG_ASSERT(ref->count); - if (caa_unlikely((--ref->count) == 0)) { - ref->release(ref); - } -} - -#endif /* LTTNG_REF_INTERNAL_H */ diff --git a/include/lttng/ref-internal.hpp b/include/lttng/ref-internal.hpp new file mode 100644 index 000000000..a02ae4cdc --- /dev/null +++ b/include/lttng/ref-internal.hpp @@ -0,0 +1,49 @@ +#ifndef LTTNG_REF_INTERNAL_H +#define LTTNG_REF_INTERNAL_H + +/* + * LTTng - Non thread-safe reference counting + * + * Copyright 2013, 2014 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + + +typedef void (*lttng_release_func)(void *); + +struct lttng_ref { + unsigned long count; + lttng_release_func release; +}; + +static inline +void lttng_ref_init(struct lttng_ref *ref, lttng_release_func release) +{ + LTTNG_ASSERT(ref); + ref->count = 1; + ref->release = release; +} + +static inline +void lttng_ref_get(struct lttng_ref *ref) +{ + LTTNG_ASSERT(ref); + ref->count++; + /* Overflow check. */ + LTTNG_ASSERT(ref->count); +} + +static inline +void lttng_ref_put(struct lttng_ref *ref) +{ + LTTNG_ASSERT(ref); + /* Underflow check. */ + LTTNG_ASSERT(ref->count); + if (caa_unlikely((--ref->count) == 0)) { + ref->release(ref); + } +} + +#endif /* LTTNG_REF_INTERNAL_H */ diff --git a/include/lttng/rotate-internal.h b/include/lttng/rotate-internal.h deleted file mode 100644 index 0296efed1..000000000 --- a/include/lttng/rotate-internal.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2017 Julien Desfossez - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_ROTATE_INTERNAL_ABI_H -#define LTTNG_ROTATE_INTERNAL_ABI_H - -#include -#include -#include - -#include -#include -#include - -/* - * Object returned by the rotate session API. - * This is opaque to the public library. - */ -struct lttng_rotation_handle { - char session_name[LTTNG_NAME_MAX]; - /* - * ID of the rotate command. - * This matches the session->rotate_count, so the handle is valid until - * the next rotate command. After that, the rotation_get_state command - * returns the "expired" state. - */ - uint64_t rotation_id; - /* - * Where the rotated (readable) trace has been stored when the - * rotation is completed. - */ - struct lttng_trace_archive_location *archive_location; -}; - -struct lttng_rotation_schedule { - enum lttng_rotation_schedule_type type; -}; - -struct lttng_rotation_schedule_size_threshold { - struct lttng_rotation_schedule parent; - struct { - bool set; - uint64_t bytes; - } size; -}; - -struct lttng_rotation_schedule_periodic { - struct lttng_rotation_schedule parent; - struct { - bool set; - uint64_t us; - } period; -}; - -struct lttng_rotation_schedules { - /* - * Only one rotation schedule per type is supported for now. - * Schedules are owned by this object. - */ - unsigned int count; - struct lttng_rotation_schedule *schedules[2]; -}; - -/* - * Internal objects between lttng-ctl and the session daemon, the values - * are then copied to the user's lttng_rotation_handle object. - */ - -/* For the LTTNG_ROTATE_SESSION command. */ -struct lttng_rotate_session_return { - uint64_t rotation_id; -} LTTNG_PACKED; - -/* For the LTTNG_ROTATION_GET_INFO command. */ -struct lttng_rotation_get_info_return { - /* Represents values defined in enum lttng_rotation_state. */ - int32_t status; - /* - * Represents values defined in enum lttng_trace_archive_location_type. - */ - int8_t location_type; - union { - struct { - char absolute_path[LTTNG_PATH_MAX]; - } LTTNG_PACKED local; - struct { - char host[LTTNG_HOST_NAME_MAX]; - /* - * Represents values defined in - * enum lttng_trace_archive_location_relay_protocol_type. - */ - int8_t protocol; - struct { - uint16_t control; - uint16_t data; - } LTTNG_PACKED ports; - char relative_path[LTTNG_PATH_MAX]; - } LTTNG_PACKED relay; - } location; -} LTTNG_PACKED; - -/* For the LTTNG_SESSION_LIST_SCHEDULES command. */ -struct lttng_session_list_schedules_return { - struct { - uint8_t set; - uint64_t value; - } LTTNG_PACKED periodic; - struct { - uint8_t set; - uint64_t value; - } LTTNG_PACKED size; -} LTTNG_PACKED; - -#endif /* LTTNG_ROTATE_INTERNAL_ABI_H */ diff --git a/include/lttng/rotate-internal.hpp b/include/lttng/rotate-internal.hpp new file mode 100644 index 000000000..076f50a9a --- /dev/null +++ b/include/lttng/rotate-internal.hpp @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2017 Julien Desfossez + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_ROTATE_INTERNAL_ABI_H +#define LTTNG_ROTATE_INTERNAL_ABI_H + +#include +#include +#include + +#include +#include +#include + +/* + * Object returned by the rotate session API. + * This is opaque to the public library. + */ +struct lttng_rotation_handle { + char session_name[LTTNG_NAME_MAX]; + /* + * ID of the rotate command. + * This matches the session->rotate_count, so the handle is valid until + * the next rotate command. After that, the rotation_get_state command + * returns the "expired" state. + */ + uint64_t rotation_id; + /* + * Where the rotated (readable) trace has been stored when the + * rotation is completed. + */ + struct lttng_trace_archive_location *archive_location; +}; + +struct lttng_rotation_schedule { + enum lttng_rotation_schedule_type type; +}; + +struct lttng_rotation_schedule_size_threshold { + struct lttng_rotation_schedule parent; + struct { + bool set; + uint64_t bytes; + } size; +}; + +struct lttng_rotation_schedule_periodic { + struct lttng_rotation_schedule parent; + struct { + bool set; + uint64_t us; + } period; +}; + +struct lttng_rotation_schedules { + /* + * Only one rotation schedule per type is supported for now. + * Schedules are owned by this object. + */ + unsigned int count; + struct lttng_rotation_schedule *schedules[2]; +}; + +/* + * Internal objects between lttng-ctl and the session daemon, the values + * are then copied to the user's lttng_rotation_handle object. + */ + +/* For the LTTNG_ROTATE_SESSION command. */ +struct lttng_rotate_session_return { + uint64_t rotation_id; +} LTTNG_PACKED; + +/* For the LTTNG_ROTATION_GET_INFO command. */ +struct lttng_rotation_get_info_return { + /* Represents values defined in enum lttng_rotation_state. */ + int32_t status; + /* + * Represents values defined in enum lttng_trace_archive_location_type. + */ + int8_t location_type; + union { + struct { + char absolute_path[LTTNG_PATH_MAX]; + } LTTNG_PACKED local; + struct { + char host[LTTNG_HOST_NAME_MAX]; + /* + * Represents values defined in + * enum lttng_trace_archive_location_relay_protocol_type. + */ + int8_t protocol; + struct { + uint16_t control; + uint16_t data; + } LTTNG_PACKED ports; + char relative_path[LTTNG_PATH_MAX]; + } LTTNG_PACKED relay; + } location; +} LTTNG_PACKED; + +/* For the LTTNG_SESSION_LIST_SCHEDULES command. */ +struct lttng_session_list_schedules_return { + struct { + uint8_t set; + uint64_t value; + } LTTNG_PACKED periodic; + struct { + uint8_t set; + uint64_t value; + } LTTNG_PACKED size; +} LTTNG_PACKED; + +#endif /* LTTNG_ROTATE_INTERNAL_ABI_H */ diff --git a/include/lttng/save-internal.h b/include/lttng/save-internal.h deleted file mode 100644 index 1af3f87e1..000000000 --- a/include/lttng/save-internal.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2013 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_SAVE_INTERNAL_ABI_H -#define LTTNG_SAVE_INTERNAL_ABI_H - -#include -#include - -#include -#include - -/* - * Object used by the save_session API. This is opaque to the public library. - */ -struct lttng_save_session_attr { - /* Name of the session to save, empty string means all. */ - char session_name[LTTNG_NAME_MAX]; - /* Destination of the session configuration. See lttng(1) for URL format. */ - char configuration_url[PATH_MAX]; - /* Overwrite the session configuration file if it exists. */ - uint8_t overwrite; - /* Omit the sessions' name(s). */ - uint8_t omit_name; - /* Omit the sessions' output(s). */ - uint8_t omit_output; -} LTTNG_PACKED; - -#endif /* LTTNG_SAVE_INTERNAL_ABI_H */ diff --git a/include/lttng/save-internal.hpp b/include/lttng/save-internal.hpp new file mode 100644 index 000000000..6b2bb9433 --- /dev/null +++ b/include/lttng/save-internal.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2013 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_SAVE_INTERNAL_ABI_H +#define LTTNG_SAVE_INTERNAL_ABI_H + +#include +#include + +#include +#include + +/* + * Object used by the save_session API. This is opaque to the public library. + */ +struct lttng_save_session_attr { + /* Name of the session to save, empty string means all. */ + char session_name[LTTNG_NAME_MAX]; + /* Destination of the session configuration. See lttng(1) for URL format. */ + char configuration_url[PATH_MAX]; + /* Overwrite the session configuration file if it exists. */ + uint8_t overwrite; + /* Omit the sessions' name(s). */ + uint8_t omit_name; + /* Omit the sessions' output(s). */ + uint8_t omit_output; +} LTTNG_PACKED; + +#endif /* LTTNG_SAVE_INTERNAL_ABI_H */ diff --git a/include/lttng/session-descriptor-internal.h b/include/lttng/session-descriptor-internal.h deleted file mode 100644 index f438d4812..000000000 --- a/include/lttng/session-descriptor-internal.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2019 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_SESSION_DESCRIPTOR_INTERNAL_H -#define LTTNG_SESSION_DESCRIPTOR_INTERNAL_H - -#include -#include -#include -#include -#include -#include - -/* Note that these enums are used as part of the lttnctl protocol. */ -enum lttng_session_descriptor_type { - LTTNG_SESSION_DESCRIPTOR_TYPE_UNKNOWN = -1, - /* - * The output type determines whether this is a no-output, local, - * or networked tracing session. - */ - LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR = 1, - LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT = 2, - LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE = 3, -}; - -enum lttng_session_descriptor_output_type { - LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE = 0, - LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL = 1, - LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK = 2, -}; - -ssize_t lttng_session_descriptor_create_from_buffer( - const struct lttng_buffer_view *view, - struct lttng_session_descriptor **descriptor); - -int lttng_session_descriptor_serialize( - const struct lttng_session_descriptor *descriptor, - struct lttng_dynamic_buffer *buffer); - -enum lttng_session_descriptor_type -lttng_session_descriptor_get_type( - const struct lttng_session_descriptor *descriptor); - -enum lttng_session_descriptor_output_type -lttng_session_descriptor_get_output_type( - const struct lttng_session_descriptor *descriptor); - -void lttng_session_descriptor_get_local_output_uri( - const struct lttng_session_descriptor *descriptor, - struct lttng_uri *local_uri); - -void lttng_session_descriptor_get_network_output_uris( - const struct lttng_session_descriptor *descriptor, - struct lttng_uri *control, - struct lttng_uri *data); - -unsigned long long -lttng_session_descriptor_live_get_timer_interval( - const struct lttng_session_descriptor *descriptor); - -int lttng_session_descriptor_set_session_name( - struct lttng_session_descriptor *descriptor, - const char *name); - -bool lttng_session_descriptor_is_output_destination_initialized( - const struct lttng_session_descriptor *descriptor); - -bool lttng_session_descriptor_has_output_directory( - const struct lttng_session_descriptor *descriptor); - -enum lttng_error_code lttng_session_descriptor_set_default_output( - struct lttng_session_descriptor *descriptor, - time_t *session_creation_time, - const char *absolute_home_path); - -int lttng_session_descriptor_assign( - struct lttng_session_descriptor *dst_descriptor, - const struct lttng_session_descriptor *src_descriptor); - -#endif /* LTTNG_SESSION_DESCRIPTOR_INTERNAL_H */ diff --git a/include/lttng/session-descriptor-internal.hpp b/include/lttng/session-descriptor-internal.hpp new file mode 100644 index 000000000..c132f5600 --- /dev/null +++ b/include/lttng/session-descriptor-internal.hpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2019 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_SESSION_DESCRIPTOR_INTERNAL_H +#define LTTNG_SESSION_DESCRIPTOR_INTERNAL_H + +#include +#include +#include +#include +#include +#include + +/* Note that these enums are used as part of the lttnctl protocol. */ +enum lttng_session_descriptor_type { + LTTNG_SESSION_DESCRIPTOR_TYPE_UNKNOWN = -1, + /* + * The output type determines whether this is a no-output, local, + * or networked tracing session. + */ + LTTNG_SESSION_DESCRIPTOR_TYPE_REGULAR = 1, + LTTNG_SESSION_DESCRIPTOR_TYPE_SNAPSHOT = 2, + LTTNG_SESSION_DESCRIPTOR_TYPE_LIVE = 3, +}; + +enum lttng_session_descriptor_output_type { + LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE = 0, + LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL = 1, + LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK = 2, +}; + +ssize_t lttng_session_descriptor_create_from_buffer( + const struct lttng_buffer_view *view, + struct lttng_session_descriptor **descriptor); + +int lttng_session_descriptor_serialize( + const struct lttng_session_descriptor *descriptor, + struct lttng_dynamic_buffer *buffer); + +enum lttng_session_descriptor_type +lttng_session_descriptor_get_type( + const struct lttng_session_descriptor *descriptor); + +enum lttng_session_descriptor_output_type +lttng_session_descriptor_get_output_type( + const struct lttng_session_descriptor *descriptor); + +void lttng_session_descriptor_get_local_output_uri( + const struct lttng_session_descriptor *descriptor, + struct lttng_uri *local_uri); + +void lttng_session_descriptor_get_network_output_uris( + const struct lttng_session_descriptor *descriptor, + struct lttng_uri *control, + struct lttng_uri *data); + +unsigned long long +lttng_session_descriptor_live_get_timer_interval( + const struct lttng_session_descriptor *descriptor); + +int lttng_session_descriptor_set_session_name( + struct lttng_session_descriptor *descriptor, + const char *name); + +bool lttng_session_descriptor_is_output_destination_initialized( + const struct lttng_session_descriptor *descriptor); + +bool lttng_session_descriptor_has_output_directory( + const struct lttng_session_descriptor *descriptor); + +enum lttng_error_code lttng_session_descriptor_set_default_output( + struct lttng_session_descriptor *descriptor, + time_t *session_creation_time, + const char *absolute_home_path); + +int lttng_session_descriptor_assign( + struct lttng_session_descriptor *dst_descriptor, + const struct lttng_session_descriptor *src_descriptor); + +#endif /* LTTNG_SESSION_DESCRIPTOR_INTERNAL_H */ diff --git a/include/lttng/session-internal.h b/include/lttng/session-internal.h deleted file mode 100644 index 305c3f5f5..000000000 --- a/include/lttng/session-internal.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2019 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_SESSION_INTERNAL_H -#define LTTNG_SESSION_INTERNAL_H - -#include -#include - -struct lttng_session_extended { - struct { - uint64_t value; - uint8_t is_set; - } LTTNG_PACKED creation_time; -} LTTNG_PACKED; - -#endif /* LTTNG_SESSION_INTERNAL_H */ diff --git a/include/lttng/session-internal.hpp b/include/lttng/session-internal.hpp new file mode 100644 index 000000000..7f73b9610 --- /dev/null +++ b/include/lttng/session-internal.hpp @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2019 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_SESSION_INTERNAL_H +#define LTTNG_SESSION_INTERNAL_H + +#include +#include + +struct lttng_session_extended { + struct { + uint64_t value; + uint8_t is_set; + } LTTNG_PACKED creation_time; +} LTTNG_PACKED; + +#endif /* LTTNG_SESSION_INTERNAL_H */ diff --git a/include/lttng/snapshot-internal.h b/include/lttng/snapshot-internal.h deleted file mode 100644 index 78c741349..000000000 --- a/include/lttng/snapshot-internal.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2013 David Goulet - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_SNAPSHOT_INTERNAL_ABI_H -#define LTTNG_SNAPSHOT_INTERNAL_ABI_H - -#include -#include -#include -#include - -/* - * Object used for the snapshot API. This is opaque to the public library. - */ -struct lttng_snapshot_output { - /* - * ID of the snapshot output. This is only used when they are listed. It is - * assigned by the session daemon so when adding an output, this value will - * not be used. - */ - uint32_t id; - /* - * Maximum size in bytes of the snapshot meaning the total size of all - * stream combined. A value of 0 is unlimited. - */ - uint64_t max_size; - /* Name of the output so it can be recognized easily when listing them. */ - char name[LTTNG_NAME_MAX]; - /* Destination of the output. See lttng(1) for URL format. */ - char ctrl_url[PATH_MAX]; - /* Destination of the output. See lttng(1) for URL format. */ - char data_url[PATH_MAX]; -} LTTNG_PACKED; - -/* - * Snapshot output list object opaque to the user. - */ -struct lttng_snapshot_output_list { - /* - * The position in the output array. This is changed by a get_next call. - */ - int index; - - /* - * Number of element in the array. - */ - size_t count; - - /* - * Contains snapshot output object. - */ - struct lttng_snapshot_output *array; -}; - -#endif /* LTTNG_SNAPSHOT_INTERNAL_ABI_H */ diff --git a/include/lttng/snapshot-internal.hpp b/include/lttng/snapshot-internal.hpp new file mode 100644 index 000000000..c60a1963b --- /dev/null +++ b/include/lttng/snapshot-internal.hpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2013 David Goulet + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_SNAPSHOT_INTERNAL_ABI_H +#define LTTNG_SNAPSHOT_INTERNAL_ABI_H + +#include +#include +#include +#include + +/* + * Object used for the snapshot API. This is opaque to the public library. + */ +struct lttng_snapshot_output { + /* + * ID of the snapshot output. This is only used when they are listed. It is + * assigned by the session daemon so when adding an output, this value will + * not be used. + */ + uint32_t id; + /* + * Maximum size in bytes of the snapshot meaning the total size of all + * stream combined. A value of 0 is unlimited. + */ + uint64_t max_size; + /* Name of the output so it can be recognized easily when listing them. */ + char name[LTTNG_NAME_MAX]; + /* Destination of the output. See lttng(1) for URL format. */ + char ctrl_url[PATH_MAX]; + /* Destination of the output. See lttng(1) for URL format. */ + char data_url[PATH_MAX]; +} LTTNG_PACKED; + +/* + * Snapshot output list object opaque to the user. + */ +struct lttng_snapshot_output_list { + /* + * The position in the output array. This is changed by a get_next call. + */ + int index; + + /* + * Number of element in the array. + */ + size_t count; + + /* + * Contains snapshot output object. + */ + struct lttng_snapshot_output *array; +}; + +#endif /* LTTNG_SNAPSHOT_INTERNAL_ABI_H */ diff --git a/include/lttng/trigger/trigger-internal.h b/include/lttng/trigger/trigger-internal.h deleted file mode 100644 index dab46ae07..000000000 --- a/include/lttng/trigger/trigger-internal.h +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_TRIGGER_INTERNAL_H -#define LTTNG_TRIGGER_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct lttng_payload; -struct lttng_payload_view; -struct mi_writer; -struct mi_lttng_error_query_callbacks; - -struct lttng_trigger { - /* Reference counting is only exposed to internal users. */ - struct urcu_ref ref; - - struct lttng_condition *condition; - struct lttng_action *action; - char *name; - /* For now only the uid portion of the credentials is used. */ - struct lttng_credentials creds; - /* - * Internal use only. - * The unique token passed to the tracer to identify an event-rule - * notification. - */ - LTTNG_OPTIONAL(uint64_t) tracer_token; - - /* - * Is the trigger registered? - * - * This is necessary since a reference holder might be interested in the - * overall state of the trigger from the point of view of its owner. - * - * The main user is the action executor since we want to prevent the - * execution of actions related to a trigger that is unregistered. - * - * Not considered for `is_equal`. - */ - bool registered; - - /* - * A "hidden" trigger is a trigger that is not externally listed. - * It is used to hide triggers that are used internally by the session - * daemon so that they can't be listed nor unregistered by external - * clients. - * - * This is a property that can only be set internally by the session - * daemon. As such, it is not serialized nor set by a - * "create_from_buffer" constructor. - * - * The hidden property is preserved by copies. - * - * Note that notifications originating from an "hidden" trigger will not - * be sent to clients that are not within the session daemon's process. - */ - bool is_hidden; - - /* - * The lock is used to protect against concurrent trigger execution and - * trigger removal. - */ - pthread_mutex_t lock; -}; - -struct lttng_triggers { - struct lttng_dynamic_pointer_array array; -}; - -struct lttng_trigger_comm { - /* - * Credentials, only the uid portion is used for now. - * Used as an override when desired by the root user. - */ - uint64_t uid; - /* - * Length of the variable length payload (name, condition, and - * an action). - */ - uint32_t length; - /* Includes '\0' terminator. */ - uint32_t name_length; - /* A null-terminated name, a condition, and an action follow. */ - char payload[]; -} LTTNG_PACKED; - -struct lttng_triggers_comm { - uint32_t count; - uint32_t length; - /* Count * lttng_trigger_comm structure */ - char payload[]; -}; - -ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view, - struct lttng_trigger **trigger); - -int lttng_trigger_serialize(const struct lttng_trigger *trigger, - struct lttng_payload *payload); - -bool lttng_trigger_validate(const struct lttng_trigger *trigger); - -int lttng_trigger_assign_name( - struct lttng_trigger *dst, const struct lttng_trigger *src); - -void lttng_trigger_set_tracer_token( - struct lttng_trigger *trigger, uint64_t token); - -uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger); - -int lttng_trigger_generate_name(struct lttng_trigger *trigger, - uint64_t unique_id); - -bool lttng_trigger_is_equal( - const struct lttng_trigger *a, const struct lttng_trigger *b); - -bool lttng_trigger_is_hidden(const struct lttng_trigger *trigger); - -void lttng_trigger_set_hidden(struct lttng_trigger *trigger); - -void lttng_trigger_get(struct lttng_trigger *trigger); - -void lttng_trigger_put(struct lttng_trigger *trigger); - -/* - * Serialize a trigger to a mi_writer. - * Return LTTNG_OK in success, other enum lttng_error_code on error. - */ -enum lttng_error_code lttng_trigger_mi_serialize(const struct lttng_trigger *trigger, - struct mi_writer *writer, - const struct mi_lttng_error_query_callbacks - *error_query_callbacks); - -/* - * Allocate a new set of triggers. - * The returned object must be freed via lttng_triggers_destroy. - */ -struct lttng_triggers *lttng_triggers_create(void); - -/* - * Return the a pointer to a mutable element at index "index" of an - * lttng_triggers set. - * - * This differs from the public `lttng_triggers_get_at_index` in that - * the returned pointer to a mutable trigger. - * - * The ownership of the trigger set element is NOT transfered. - * The returned object can NOT be freed via lttng_trigger_destroy. - */ -struct lttng_trigger *lttng_triggers_borrow_mutable_at_index( - const struct lttng_triggers *triggers, unsigned int index); - -/* - * Add a trigger to the triggers set. - * - * A reference to the added trigger is acquired on behalf of the trigger set - * on success. - */ -int lttng_triggers_add( - struct lttng_triggers *triggers, struct lttng_trigger *trigger); - -/* - * Remove all triggers marked as hidden from the provided trigger set. - */ -int lttng_triggers_remove_hidden_triggers(struct lttng_triggers *triggers); - -/* - * Serialize a trigger set to an lttng_payload object. - * Return LTTNG_OK on success, negative lttng error code on error. - */ -int lttng_triggers_serialize(const struct lttng_triggers *triggers, - struct lttng_payload *payload); - -ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view, - struct lttng_triggers **triggers); - -/* - * Serialize a trigger set to a mi_writer. - * Return LTTNG_OK in success, other enum lttng_error_code on error. - */ -enum lttng_error_code lttng_triggers_mi_serialize(const struct lttng_triggers *triggers, - struct mi_writer *writer, - const struct mi_lttng_error_query_callbacks - *error_query_callbacks); - -const struct lttng_credentials *lttng_trigger_get_credentials( - const struct lttng_trigger *trigger); - -void lttng_trigger_set_credentials(struct lttng_trigger *trigger, - const struct lttng_credentials *creds); - -/* - * Return the type of any underlying domain restriction. If no particular - * requirement is present, returns LTTNG_DOMAIN_NONE. - */ -enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction( - const struct lttng_trigger *trigger); - -/* - * Generate any bytecode related to the trigger. - * On success LTTNG_OK. On error, returns lttng_error code. - */ -enum lttng_error_code lttng_trigger_generate_bytecode( - struct lttng_trigger *trigger, - const struct lttng_credentials *creds); - -/* - * Note that the trigger object is not locked by "copy" as it is const and - * used with a number of 'const' triggers. If the trigger could be shared at - * the moment of the copy, it is the caller's responsability to lock it for - * the duration of the copy. - */ -struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger); - -/* - * A given trigger needs a tracer notifier if - * it has an event-rule condition, - * AND - * it has one or more sessiond-execution action. - */ -bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger); - -void lttng_trigger_set_as_registered(struct lttng_trigger *trigger); - -void lttng_trigger_set_as_unregistered(struct lttng_trigger *trigger); - -/* - * The trigger must be locked before calling lttng_trigger_is_registered. - * - * The lock is necessary since a trigger can be unregistered at any time. - * - * Manipulations requiring that the trigger be registered must always acquire - * the trigger lock for the duration of the manipulation using - * `lttng_trigger_lock` and `lttng_trigger_unlock`. - */ -bool lttng_trigger_is_registered(struct lttng_trigger *trigger); - -void lttng_trigger_lock(struct lttng_trigger *trigger); - -void lttng_trigger_unlock(struct lttng_trigger *trigger); - -enum lttng_trigger_status lttng_trigger_add_error_results( - const struct lttng_trigger *trigger, - struct lttng_error_query_results *results); - -enum lttng_trigger_status lttng_trigger_condition_add_error_results( - const struct lttng_trigger *trigger, - struct lttng_error_query_results *results); - -enum lttng_trigger_status lttng_trigger_add_action_error_query_results( - struct lttng_trigger *trigger, - struct lttng_error_query_results *results); - -/* - * Set the trigger name. - * - * A name is optional. - * A name will be assigned on trigger registration if no name is set. - * - * The name is copied. - * - * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID - * if invalid parameters are passed. - */ -enum lttng_trigger_status lttng_trigger_set_name( - struct lttng_trigger *trigger, const char *name); - -#endif /* LTTNG_TRIGGER_INTERNAL_H */ diff --git a/include/lttng/trigger/trigger-internal.hpp b/include/lttng/trigger/trigger-internal.hpp new file mode 100644 index 000000000..206e7dfa8 --- /dev/null +++ b/include/lttng/trigger/trigger-internal.hpp @@ -0,0 +1,281 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_TRIGGER_INTERNAL_H +#define LTTNG_TRIGGER_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct lttng_payload; +struct lttng_payload_view; +struct mi_writer; +struct mi_lttng_error_query_callbacks; + +struct lttng_trigger { + /* Reference counting is only exposed to internal users. */ + struct urcu_ref ref; + + struct lttng_condition *condition; + struct lttng_action *action; + char *name; + /* For now only the uid portion of the credentials is used. */ + struct lttng_credentials creds; + /* + * Internal use only. + * The unique token passed to the tracer to identify an event-rule + * notification. + */ + LTTNG_OPTIONAL(uint64_t) tracer_token; + + /* + * Is the trigger registered? + * + * This is necessary since a reference holder might be interested in the + * overall state of the trigger from the point of view of its owner. + * + * The main user is the action executor since we want to prevent the + * execution of actions related to a trigger that is unregistered. + * + * Not considered for `is_equal`. + */ + bool registered; + + /* + * A "hidden" trigger is a trigger that is not externally listed. + * It is used to hide triggers that are used internally by the session + * daemon so that they can't be listed nor unregistered by external + * clients. + * + * This is a property that can only be set internally by the session + * daemon. As such, it is not serialized nor set by a + * "create_from_buffer" constructor. + * + * The hidden property is preserved by copies. + * + * Note that notifications originating from an "hidden" trigger will not + * be sent to clients that are not within the session daemon's process. + */ + bool is_hidden; + + /* + * The lock is used to protect against concurrent trigger execution and + * trigger removal. + */ + pthread_mutex_t lock; +}; + +struct lttng_triggers { + struct lttng_dynamic_pointer_array array; +}; + +struct lttng_trigger_comm { + /* + * Credentials, only the uid portion is used for now. + * Used as an override when desired by the root user. + */ + uint64_t uid; + /* + * Length of the variable length payload (name, condition, and + * an action). + */ + uint32_t length; + /* Includes '\0' terminator. */ + uint32_t name_length; + /* A null-terminated name, a condition, and an action follow. */ + char payload[]; +} LTTNG_PACKED; + +struct lttng_triggers_comm { + uint32_t count; + uint32_t length; + /* Count * lttng_trigger_comm structure */ + char payload[]; +}; + +ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view, + struct lttng_trigger **trigger); + +int lttng_trigger_serialize(const struct lttng_trigger *trigger, + struct lttng_payload *payload); + +bool lttng_trigger_validate(const struct lttng_trigger *trigger); + +int lttng_trigger_assign_name( + struct lttng_trigger *dst, const struct lttng_trigger *src); + +void lttng_trigger_set_tracer_token( + struct lttng_trigger *trigger, uint64_t token); + +uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger); + +int lttng_trigger_generate_name(struct lttng_trigger *trigger, + uint64_t unique_id); + +bool lttng_trigger_is_equal( + const struct lttng_trigger *a, const struct lttng_trigger *b); + +bool lttng_trigger_is_hidden(const struct lttng_trigger *trigger); + +void lttng_trigger_set_hidden(struct lttng_trigger *trigger); + +void lttng_trigger_get(struct lttng_trigger *trigger); + +void lttng_trigger_put(struct lttng_trigger *trigger); + +/* + * Serialize a trigger to a mi_writer. + * Return LTTNG_OK in success, other enum lttng_error_code on error. + */ +enum lttng_error_code lttng_trigger_mi_serialize(const struct lttng_trigger *trigger, + struct mi_writer *writer, + const struct mi_lttng_error_query_callbacks + *error_query_callbacks); + +/* + * Allocate a new set of triggers. + * The returned object must be freed via lttng_triggers_destroy. + */ +struct lttng_triggers *lttng_triggers_create(void); + +/* + * Return the a pointer to a mutable element at index "index" of an + * lttng_triggers set. + * + * This differs from the public `lttng_triggers_get_at_index` in that + * the returned pointer to a mutable trigger. + * + * The ownership of the trigger set element is NOT transfered. + * The returned object can NOT be freed via lttng_trigger_destroy. + */ +struct lttng_trigger *lttng_triggers_borrow_mutable_at_index( + const struct lttng_triggers *triggers, unsigned int index); + +/* + * Add a trigger to the triggers set. + * + * A reference to the added trigger is acquired on behalf of the trigger set + * on success. + */ +int lttng_triggers_add( + struct lttng_triggers *triggers, struct lttng_trigger *trigger); + +/* + * Remove all triggers marked as hidden from the provided trigger set. + */ +int lttng_triggers_remove_hidden_triggers(struct lttng_triggers *triggers); + +/* + * Serialize a trigger set to an lttng_payload object. + * Return LTTNG_OK on success, negative lttng error code on error. + */ +int lttng_triggers_serialize(const struct lttng_triggers *triggers, + struct lttng_payload *payload); + +ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view, + struct lttng_triggers **triggers); + +/* + * Serialize a trigger set to a mi_writer. + * Return LTTNG_OK in success, other enum lttng_error_code on error. + */ +enum lttng_error_code lttng_triggers_mi_serialize(const struct lttng_triggers *triggers, + struct mi_writer *writer, + const struct mi_lttng_error_query_callbacks + *error_query_callbacks); + +const struct lttng_credentials *lttng_trigger_get_credentials( + const struct lttng_trigger *trigger); + +void lttng_trigger_set_credentials(struct lttng_trigger *trigger, + const struct lttng_credentials *creds); + +/* + * Return the type of any underlying domain restriction. If no particular + * requirement is present, returns LTTNG_DOMAIN_NONE. + */ +enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction( + const struct lttng_trigger *trigger); + +/* + * Generate any bytecode related to the trigger. + * On success LTTNG_OK. On error, returns lttng_error code. + */ +enum lttng_error_code lttng_trigger_generate_bytecode( + struct lttng_trigger *trigger, + const struct lttng_credentials *creds); + +/* + * Note that the trigger object is not locked by "copy" as it is const and + * used with a number of 'const' triggers. If the trigger could be shared at + * the moment of the copy, it is the caller's responsability to lock it for + * the duration of the copy. + */ +struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger); + +/* + * A given trigger needs a tracer notifier if + * it has an event-rule condition, + * AND + * it has one or more sessiond-execution action. + */ +bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger); + +void lttng_trigger_set_as_registered(struct lttng_trigger *trigger); + +void lttng_trigger_set_as_unregistered(struct lttng_trigger *trigger); + +/* + * The trigger must be locked before calling lttng_trigger_is_registered. + * + * The lock is necessary since a trigger can be unregistered at any time. + * + * Manipulations requiring that the trigger be registered must always acquire + * the trigger lock for the duration of the manipulation using + * `lttng_trigger_lock` and `lttng_trigger_unlock`. + */ +bool lttng_trigger_is_registered(struct lttng_trigger *trigger); + +void lttng_trigger_lock(struct lttng_trigger *trigger); + +void lttng_trigger_unlock(struct lttng_trigger *trigger); + +enum lttng_trigger_status lttng_trigger_add_error_results( + const struct lttng_trigger *trigger, + struct lttng_error_query_results *results); + +enum lttng_trigger_status lttng_trigger_condition_add_error_results( + const struct lttng_trigger *trigger, + struct lttng_error_query_results *results); + +enum lttng_trigger_status lttng_trigger_add_action_error_query_results( + struct lttng_trigger *trigger, + struct lttng_error_query_results *results); + +/* + * Set the trigger name. + * + * A name is optional. + * A name will be assigned on trigger registration if no name is set. + * + * The name is copied. + * + * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID + * if invalid parameters are passed. + */ +enum lttng_trigger_status lttng_trigger_set_name( + struct lttng_trigger *trigger, const char *name); + +#endif /* LTTNG_TRIGGER_INTERNAL_H */ diff --git a/include/lttng/userspace-probe-internal.h b/include/lttng/userspace-probe-internal.h deleted file mode 100644 index 5e960c106..000000000 --- a/include/lttng/userspace-probe-internal.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * Copyright (C) 2018 Francis Deslauriers - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_USERSPACE_PROBE_INTERNAL_H -#define LTTNG_USERSPACE_PROBE_INTERNAL_H - -#include -#include -#include -#include - -struct lttng_payload; -struct lttng_payload_view; -struct lttng_dynamic_buffer; -struct mi_writer; - -typedef bool (*userspace_probe_location_equal_cb)( - const struct lttng_userspace_probe_location *a, - const struct lttng_userspace_probe_location *b); -typedef unsigned long (*userspace_probe_location_hash_cb)( - const struct lttng_userspace_probe_location *location); -typedef enum lttng_error_code (*userspace_probe_location_mi)( - const struct lttng_userspace_probe_location *location, - struct mi_writer); - -/* - * No elf-specific comm structure is defined since no elf-specific payload is - * currently needed. - */ -struct lttng_userspace_probe_location_lookup_method_comm { - /* enum lttng_userspace_probe_location_lookup_method_type */ - int8_t type; - /* type-specific payload */ - char payload[]; -}; - -/* Common ancestor of all userspace probe location lookup methods. */ -struct lttng_userspace_probe_location_lookup_method { - enum lttng_userspace_probe_location_lookup_method_type type; -}; - -struct lttng_userspace_probe_location_lookup_method_elf { - struct lttng_userspace_probe_location_lookup_method parent; -}; - -struct lttng_userspace_probe_location_lookup_method_sdt { - struct lttng_userspace_probe_location_lookup_method parent; -}; - -struct lttng_userspace_probe_location_comm { - /* enum lttng_userspace_probe_location_type */ - int8_t type; - /* - * Payload is composed of, in that order, - * - type-specific payload - * - struct lttng_userspace_probe_location_lookup_method_comm - */ - char payload[]; -}; - -struct lttng_userspace_probe_location_function_comm { - /* Both lengths include the trailing \0. */ - uint32_t function_name_len; - uint32_t binary_path_len; - /* - * Payload is composed of, in that order, - * - function name (with trailing \0), - * - absolute binary path (with trailing \0) - */ - char payload[]; -} LTTNG_PACKED; - -struct lttng_userspace_probe_location_tracepoint_comm { - /* The three lengths include the trailing \0. */ - uint32_t probe_name_len; - uint32_t provider_name_len; - uint32_t binary_path_len; - /* - * Payload is composed of, in that order, - * - probe name (with trailing \0), - * - provider name (with trailing \0), - * - absolute binary path (with trailing \0) - */ - char payload[]; -} LTTNG_PACKED; - -/* Common ancestor of all userspace probe locations. */ -struct lttng_userspace_probe_location { - enum lttng_userspace_probe_location_type type; - struct lttng_userspace_probe_location_lookup_method *lookup_method; - userspace_probe_location_equal_cb equal; - userspace_probe_location_hash_cb hash; - userspace_probe_location_hash_cb mi; -}; - -struct lttng_userspace_probe_location_function { - struct lttng_userspace_probe_location parent; - char *function_name; - char *binary_path; - /* - * binary_fd is a file descriptor to the executable file. It's open - * early on to keep the backing inode valid over the course of the - * intrumentation and use. It prevents deletion and reuse races. - */ - struct fd_handle *binary_fd_handle; - enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type; -}; - -struct lttng_userspace_probe_location_tracepoint { - struct lttng_userspace_probe_location parent; - char *probe_name; - char *provider_name; - char *binary_path; - /* - * binary_fd is a file descriptor to the executable file. It's open - * early on to keep the backing inode valid over the course of the - * intrumentation and use. It prevents deletion and reuse races. - */ - struct fd_handle *binary_fd_handle; -}; - -int lttng_userspace_probe_location_serialize( - const struct lttng_userspace_probe_location *location, - struct lttng_payload *payload); - -int lttng_userspace_probe_location_create_from_payload( - struct lttng_payload_view *view, - struct lttng_userspace_probe_location **probe_location); - -/* - * Returns a version of the location that is serialized to a contiguous region - * of memory. Pass NULL to buffer to only get the storage requirement of the - * flattened userspace probe location. - */ -int lttng_userspace_probe_location_flatten( - const struct lttng_userspace_probe_location *location, - struct lttng_dynamic_buffer *buffer); - -struct lttng_userspace_probe_location *lttng_userspace_probe_location_copy( - const struct lttng_userspace_probe_location *location); - -bool lttng_userspace_probe_location_lookup_method_is_equal( - const struct lttng_userspace_probe_location_lookup_method *a, - const struct lttng_userspace_probe_location_lookup_method *b); - -bool lttng_userspace_probe_location_is_equal( - const struct lttng_userspace_probe_location *a, - const struct lttng_userspace_probe_location *b); - -unsigned long lttng_userspace_probe_location_hash( - const struct lttng_userspace_probe_location *location); - -enum lttng_error_code lttng_userspace_probe_location_mi_serialize( - const struct lttng_userspace_probe_location *location, - struct mi_writer *writer); - -#endif /* LTTNG_USERSPACE_PROBE_INTERNAL_H */ diff --git a/include/lttng/userspace-probe-internal.hpp b/include/lttng/userspace-probe-internal.hpp new file mode 100644 index 000000000..392242dae --- /dev/null +++ b/include/lttng/userspace-probe-internal.hpp @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * Copyright (C) 2018 Francis Deslauriers + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_USERSPACE_PROBE_INTERNAL_H +#define LTTNG_USERSPACE_PROBE_INTERNAL_H + +#include +#include +#include +#include + +struct lttng_payload; +struct lttng_payload_view; +struct lttng_dynamic_buffer; +struct mi_writer; + +typedef bool (*userspace_probe_location_equal_cb)( + const struct lttng_userspace_probe_location *a, + const struct lttng_userspace_probe_location *b); +typedef unsigned long (*userspace_probe_location_hash_cb)( + const struct lttng_userspace_probe_location *location); +typedef enum lttng_error_code (*userspace_probe_location_mi)( + const struct lttng_userspace_probe_location *location, + struct mi_writer); + +/* + * No elf-specific comm structure is defined since no elf-specific payload is + * currently needed. + */ +struct lttng_userspace_probe_location_lookup_method_comm { + /* enum lttng_userspace_probe_location_lookup_method_type */ + int8_t type; + /* type-specific payload */ + char payload[]; +}; + +/* Common ancestor of all userspace probe location lookup methods. */ +struct lttng_userspace_probe_location_lookup_method { + enum lttng_userspace_probe_location_lookup_method_type type; +}; + +struct lttng_userspace_probe_location_lookup_method_elf { + struct lttng_userspace_probe_location_lookup_method parent; +}; + +struct lttng_userspace_probe_location_lookup_method_sdt { + struct lttng_userspace_probe_location_lookup_method parent; +}; + +struct lttng_userspace_probe_location_comm { + /* enum lttng_userspace_probe_location_type */ + int8_t type; + /* + * Payload is composed of, in that order, + * - type-specific payload + * - struct lttng_userspace_probe_location_lookup_method_comm + */ + char payload[]; +}; + +struct lttng_userspace_probe_location_function_comm { + /* Both lengths include the trailing \0. */ + uint32_t function_name_len; + uint32_t binary_path_len; + /* + * Payload is composed of, in that order, + * - function name (with trailing \0), + * - absolute binary path (with trailing \0) + */ + char payload[]; +} LTTNG_PACKED; + +struct lttng_userspace_probe_location_tracepoint_comm { + /* The three lengths include the trailing \0. */ + uint32_t probe_name_len; + uint32_t provider_name_len; + uint32_t binary_path_len; + /* + * Payload is composed of, in that order, + * - probe name (with trailing \0), + * - provider name (with trailing \0), + * - absolute binary path (with trailing \0) + */ + char payload[]; +} LTTNG_PACKED; + +/* Common ancestor of all userspace probe locations. */ +struct lttng_userspace_probe_location { + enum lttng_userspace_probe_location_type type; + struct lttng_userspace_probe_location_lookup_method *lookup_method; + userspace_probe_location_equal_cb equal; + userspace_probe_location_hash_cb hash; + userspace_probe_location_hash_cb mi; +}; + +struct lttng_userspace_probe_location_function { + struct lttng_userspace_probe_location parent; + char *function_name; + char *binary_path; + /* + * binary_fd is a file descriptor to the executable file. It's open + * early on to keep the backing inode valid over the course of the + * intrumentation and use. It prevents deletion and reuse races. + */ + struct fd_handle *binary_fd_handle; + enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type; +}; + +struct lttng_userspace_probe_location_tracepoint { + struct lttng_userspace_probe_location parent; + char *probe_name; + char *provider_name; + char *binary_path; + /* + * binary_fd is a file descriptor to the executable file. It's open + * early on to keep the backing inode valid over the course of the + * intrumentation and use. It prevents deletion and reuse races. + */ + struct fd_handle *binary_fd_handle; +}; + +int lttng_userspace_probe_location_serialize( + const struct lttng_userspace_probe_location *location, + struct lttng_payload *payload); + +int lttng_userspace_probe_location_create_from_payload( + struct lttng_payload_view *view, + struct lttng_userspace_probe_location **probe_location); + +/* + * Returns a version of the location that is serialized to a contiguous region + * of memory. Pass NULL to buffer to only get the storage requirement of the + * flattened userspace probe location. + */ +int lttng_userspace_probe_location_flatten( + const struct lttng_userspace_probe_location *location, + struct lttng_dynamic_buffer *buffer); + +struct lttng_userspace_probe_location *lttng_userspace_probe_location_copy( + const struct lttng_userspace_probe_location *location); + +bool lttng_userspace_probe_location_lookup_method_is_equal( + const struct lttng_userspace_probe_location_lookup_method *a, + const struct lttng_userspace_probe_location_lookup_method *b); + +bool lttng_userspace_probe_location_is_equal( + const struct lttng_userspace_probe_location *a, + const struct lttng_userspace_probe_location *b); + +unsigned long lttng_userspace_probe_location_hash( + const struct lttng_userspace_probe_location *location); + +enum lttng_error_code lttng_userspace_probe_location_mi_serialize( + const struct lttng_userspace_probe_location *location, + struct mi_writer *writer); + +#endif /* LTTNG_USERSPACE_PROBE_INTERNAL_H */ diff --git a/include/version.h b/include/version.h deleted file mode 100644 index 9bd5e0ca9..000000000 --- a/include/version.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (C) 2013-2014 Raphaël Beamonte - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef VERSION_H -#define VERSION_H - -#include - -#endif /* VERSION_H */ diff --git a/include/version.hpp b/include/version.hpp new file mode 100644 index 000000000..9bd5e0ca9 --- /dev/null +++ b/include/version.hpp @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2013-2014 Raphaël Beamonte + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef VERSION_H +#define VERSION_H + +#include + +#endif /* VERSION_H */ diff --git a/src/bin/lttng-consumerd/Makefile.am b/src/bin/lttng-consumerd/Makefile.am index 19bc7ed4c..3ad8210cc 100644 --- a/src/bin/lttng-consumerd/Makefile.am +++ b/src/bin/lttng-consumerd/Makefile.am @@ -4,9 +4,9 @@ lttnglibexec_PROGRAMS = lttng-consumerd lttng_consumerd_SOURCES = \ lttng-consumerd.cpp \ - lttng-consumerd.h \ + lttng-consumerd.hpp \ health-consumerd.cpp \ - health-consumerd.h + health-consumerd.hpp lttng_consumerd_LDADD = \ $(top_builddir)/src/common/libconsumer.la \ diff --git a/src/bin/lttng-consumerd/health-consumerd.cpp b/src/bin/lttng-consumerd/health-consumerd.cpp index e3adbe142..8417fc6dc 100644 --- a/src/bin/lttng-consumerd/health-consumerd.cpp +++ b/src/bin/lttng-consumerd/health-consumerd.cpp @@ -29,16 +29,16 @@ #include #include -#include -#include -#include -#include -#include -#include -#include - -#include "lttng-consumerd.h" -#include "health-consumerd.h" +#include +#include +#include +#include +#include +#include +#include + +#include "lttng-consumerd.hpp" +#include "health-consumerd.hpp" /* Global health check unix path */ static char health_unix_sock_path[PATH_MAX]; diff --git a/src/bin/lttng-consumerd/health-consumerd.h b/src/bin/lttng-consumerd/health-consumerd.h deleted file mode 100644 index 9faa081d4..000000000 --- a/src/bin/lttng-consumerd/health-consumerd.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef HEALTH_CONSUMERD_H -#define HEALTH_CONSUMERD_H - -/* - * Copyright (C) 2012 David Goulet - * Copyright (C) 2013 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include - -enum health_type_consumerd { - HEALTH_CONSUMERD_TYPE_CHANNEL = 0, - HEALTH_CONSUMERD_TYPE_METADATA = 1, - HEALTH_CONSUMERD_TYPE_DATA = 2, - HEALTH_CONSUMERD_TYPE_SESSIOND = 3, - HEALTH_CONSUMERD_TYPE_METADATA_TIMER = 4, - - NR_HEALTH_CONSUMERD_TYPES, -}; - -/* Consumerd health monitoring */ -extern struct health_app *health_consumerd; - -void *thread_manage_health_consumerd(void *data); - -extern int health_quit_pipe[2]; - -#endif /* HEALTH_CONSUMERD_H */ diff --git a/src/bin/lttng-consumerd/health-consumerd.hpp b/src/bin/lttng-consumerd/health-consumerd.hpp new file mode 100644 index 000000000..4e3bf8686 --- /dev/null +++ b/src/bin/lttng-consumerd/health-consumerd.hpp @@ -0,0 +1,30 @@ +#ifndef HEALTH_CONSUMERD_H +#define HEALTH_CONSUMERD_H + +/* + * Copyright (C) 2012 David Goulet + * Copyright (C) 2013 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#include + +enum health_type_consumerd { + HEALTH_CONSUMERD_TYPE_CHANNEL = 0, + HEALTH_CONSUMERD_TYPE_METADATA = 1, + HEALTH_CONSUMERD_TYPE_DATA = 2, + HEALTH_CONSUMERD_TYPE_SESSIOND = 3, + HEALTH_CONSUMERD_TYPE_METADATA_TIMER = 4, + + NR_HEALTH_CONSUMERD_TYPES, +}; + +/* Consumerd health monitoring */ +extern struct health_app *health_consumerd; + +void *thread_manage_health_consumerd(void *data); + +extern int health_quit_pipe[2]; + +#endif /* HEALTH_CONSUMERD_H */ diff --git a/src/bin/lttng-consumerd/lttng-consumerd.cpp b/src/bin/lttng-consumerd/lttng-consumerd.cpp index 3ee13dcb5..47d1e113d 100644 --- a/src/bin/lttng-consumerd/lttng-consumerd.cpp +++ b/src/bin/lttng-consumerd/lttng-consumerd.cpp @@ -29,17 +29,17 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "lttng-consumerd.h" -#include "health-consumerd.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include "lttng-consumerd.hpp" +#include "health-consumerd.hpp" /* threads (channel handling, poll, metadata, sessiond) */ diff --git a/src/bin/lttng-consumerd/lttng-consumerd.h b/src/bin/lttng-consumerd/lttng-consumerd.h deleted file mode 100644 index 833116ade..000000000 --- a/src/bin/lttng-consumerd/lttng-consumerd.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * Copyright (C) 2011 EfficiOS Inc. - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _LTTNG_CONSUMERD_H -#define _LTTNG_CONSUMERD_H - - -#define NR_LTTNG_CONSUMER_READY 1 -extern int lttng_consumer_ready; - -extern const char *tracing_group_name; - -/* - * This function is dlsym-ed from a test, so needs to be exported. Making it - * have a C linkage name makes it easier, as it avoids having to look up a - * mangled name. - */ -extern "C" LTTNG_EXPORT -enum lttng_consumer_type lttng_consumer_get_type(); - -#endif /* _LTTNG_CONSUMERD_H */ diff --git a/src/bin/lttng-consumerd/lttng-consumerd.hpp b/src/bin/lttng-consumerd/lttng-consumerd.hpp new file mode 100644 index 000000000..833116ade --- /dev/null +++ b/src/bin/lttng-consumerd/lttng-consumerd.hpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * Copyright (C) 2011 EfficiOS Inc. + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _LTTNG_CONSUMERD_H +#define _LTTNG_CONSUMERD_H + + +#define NR_LTTNG_CONSUMER_READY 1 +extern int lttng_consumer_ready; + +extern const char *tracing_group_name; + +/* + * This function is dlsym-ed from a test, so needs to be exported. Making it + * have a C linkage name makes it easier, as it avoids having to look up a + * mangled name. + */ +extern "C" LTTNG_EXPORT +enum lttng_consumer_type lttng_consumer_get_type(); + +#endif /* _LTTNG_CONSUMERD_H */ diff --git a/src/bin/lttng-consumerd/testpoint.h b/src/bin/lttng-consumerd/testpoint.h deleted file mode 100644 index e0b8b3e67..000000000 --- a/src/bin/lttng-consumerd/testpoint.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef CONSUMERD_TESTPOINT_H -#define CONSUMERD_TESTPOINT_H - -#include - -/* Testpoints, internal use only */ -TESTPOINT_DECL(consumerd_data_thread_poll); - -#endif /* CONSUMERD_TESTPOINT_H */ diff --git a/src/bin/lttng-consumerd/testpoint.hpp b/src/bin/lttng-consumerd/testpoint.hpp new file mode 100644 index 000000000..da7eed5f3 --- /dev/null +++ b/src/bin/lttng-consumerd/testpoint.hpp @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef CONSUMERD_TESTPOINT_H +#define CONSUMERD_TESTPOINT_H + +#include + +/* Testpoints, internal use only */ +TESTPOINT_DECL(consumerd_data_thread_poll); + +#endif /* CONSUMERD_TESTPOINT_H */ diff --git a/src/bin/lttng-crash/lttng-crash.cpp b/src/bin/lttng-crash/lttng-crash.cpp index bee9c29b0..0b4afc91b 100644 --- a/src/bin/lttng-crash/lttng-crash.cpp +++ b/src/bin/lttng-crash/lttng-crash.cpp @@ -20,15 +20,15 @@ #include #include #include -#include +#include #include #include -#include +#include #include -#include -#include -#include +#include +#include +#include #define COPY_BUFLEN 4096 #define RB_CRASH_DUMP_ABI_LEN 32 diff --git a/src/bin/lttng-relayd/Makefile.am b/src/bin/lttng-relayd/Makefile.am index afb435f06..b473d5c62 100644 --- a/src/bin/lttng-relayd/Makefile.am +++ b/src/bin/lttng-relayd/Makefile.am @@ -9,23 +9,23 @@ endif bin_PROGRAMS = lttng-relayd -lttng_relayd_SOURCES = main.cpp lttng-relayd.h utils.h utils.cpp cmd.h \ - index.cpp index.h live.cpp live.h ctf-trace.cpp ctf-trace.h \ - cmd-2-1.cpp cmd-2-1.h \ - cmd-2-2.cpp cmd-2-2.h \ - cmd-2-4.cpp cmd-2-4.h \ - cmd-2-11.cpp cmd-2-11.h \ - health-relayd.cpp health-relayd.h \ - lttng-viewer-abi.h testpoint.h \ - viewer-stream.h viewer-stream.cpp \ - session.cpp session.h \ - stream.cpp stream.h \ - connection.cpp connection.h \ - viewer-session.cpp viewer-session.h \ - tracefile-array.cpp tracefile-array.h \ - tcp_keep_alive.cpp tcp_keep_alive.h \ - sessiond-trace-chunks.cpp sessiond-trace-chunks.h \ - backward-compatibility-group-by.cpp backward-compatibility-group-by.h +lttng_relayd_SOURCES = main.cpp lttng-relayd.hpp utils.hpp utils.cpp cmd.hpp \ + index.cpp index.hpp live.cpp live.hpp ctf-trace.cpp ctf-trace.hpp \ + cmd-2-1.cpp cmd-2-1.hpp \ + cmd-2-2.cpp cmd-2-2.hpp \ + cmd-2-4.cpp cmd-2-4.hpp \ + cmd-2-11.cpp cmd-2-11.hpp \ + health-relayd.cpp health-relayd.hpp \ + lttng-viewer-abi.hpp testpoint.hpp \ + viewer-stream.hpp viewer-stream.cpp \ + session.cpp session.hpp \ + stream.cpp stream.hpp \ + connection.cpp connection.hpp \ + viewer-session.cpp viewer-session.hpp \ + tracefile-array.cpp tracefile-array.hpp \ + tcp_keep_alive.cpp tcp_keep_alive.hpp \ + sessiond-trace-chunks.cpp sessiond-trace-chunks.hpp \ + backward-compatibility-group-by.cpp backward-compatibility-group-by.hpp # link on liblttngctl for check if relayd is already alive. lttng_relayd_LDADD = $(URCU_LIBS) \ diff --git a/src/bin/lttng-relayd/backward-compatibility-group-by.cpp b/src/bin/lttng-relayd/backward-compatibility-group-by.cpp index f0454a56b..e1d289d98 100644 --- a/src/bin/lttng-relayd/backward-compatibility-group-by.cpp +++ b/src/bin/lttng-relayd/backward-compatibility-group-by.cpp @@ -5,17 +5,17 @@ * */ -#include "common/time.h" +#include "common/time.hpp" #include #include #include #include -#include -#include -#include +#include +#include +#include -#include "backward-compatibility-group-by.h" +#include "backward-compatibility-group-by.hpp" #define DATETIME_REGEX \ ".*-[1-2][0-9][0-9][0-9][0-1][0-9][0-3][0-9]-[0-2][0-9][0-5][0-9][0-5][0-9]$" diff --git a/src/bin/lttng-relayd/backward-compatibility-group-by.h b/src/bin/lttng-relayd/backward-compatibility-group-by.h deleted file mode 100644 index 4cf7462de..000000000 --- a/src/bin/lttng-relayd/backward-compatibility-group-by.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) 2019 Jonathan Rajotte - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef BACKWARD_COMPATIBILITY_GROUP_BY_H -#define BACKWARD_COMPATIBILITY_GROUP_BY_H - -#include - -char *backward_compat_group_by_session(const char *path, - const char *local_session_name, - time_t session_creation_time); - -#endif /* BACKWARD_COMPATIBILITY_GROUP_BY_H */ diff --git a/src/bin/lttng-relayd/backward-compatibility-group-by.hpp b/src/bin/lttng-relayd/backward-compatibility-group-by.hpp new file mode 100644 index 000000000..4cf7462de --- /dev/null +++ b/src/bin/lttng-relayd/backward-compatibility-group-by.hpp @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2019 Jonathan Rajotte + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef BACKWARD_COMPATIBILITY_GROUP_BY_H +#define BACKWARD_COMPATIBILITY_GROUP_BY_H + +#include + +char *backward_compat_group_by_session(const char *path, + const char *local_session_name, + time_t session_creation_time); + +#endif /* BACKWARD_COMPATIBILITY_GROUP_BY_H */ diff --git a/src/bin/lttng-relayd/cmd-2-1.cpp b/src/bin/lttng-relayd/cmd-2-1.cpp index 1f939dd07..9befdd606 100644 --- a/src/bin/lttng-relayd/cmd-2-1.cpp +++ b/src/bin/lttng-relayd/cmd-2-1.cpp @@ -9,13 +9,13 @@ #define _LGPL_SOURCE -#include -#include -#include +#include +#include +#include #include -#include "cmd-2-1.h" -#include "utils.h" +#include "cmd-2-1.hpp" +#include "utils.hpp" /* * cmd_recv_stream_2_1 allocates path_name and channel_name. diff --git a/src/bin/lttng-relayd/cmd-2-1.h b/src/bin/lttng-relayd/cmd-2-1.h deleted file mode 100644 index 7040e4fd8..000000000 --- a/src/bin/lttng-relayd/cmd-2-1.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef RELAYD_CMD_2_1_H -#define RELAYD_CMD_2_1_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include "lttng-relayd.h" -#include - -int cmd_recv_stream_2_1(const struct lttng_buffer_view *payload, - char **path_name, char **channel_name); - -#endif /* RELAYD_CMD_2_1_H */ diff --git a/src/bin/lttng-relayd/cmd-2-1.hpp b/src/bin/lttng-relayd/cmd-2-1.hpp new file mode 100644 index 000000000..147069b6b --- /dev/null +++ b/src/bin/lttng-relayd/cmd-2-1.hpp @@ -0,0 +1,19 @@ +#ifndef RELAYD_CMD_2_1_H +#define RELAYD_CMD_2_1_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include "lttng-relayd.hpp" +#include + +int cmd_recv_stream_2_1(const struct lttng_buffer_view *payload, + char **path_name, char **channel_name); + +#endif /* RELAYD_CMD_2_1_H */ diff --git a/src/bin/lttng-relayd/cmd-2-11.cpp b/src/bin/lttng-relayd/cmd-2-11.cpp index 572b1836c..680cb307b 100644 --- a/src/bin/lttng-relayd/cmd-2-11.cpp +++ b/src/bin/lttng-relayd/cmd-2-11.cpp @@ -8,15 +8,15 @@ #define _LGPL_SOURCE #include -#include -#include +#include +#include -#include -#include +#include +#include #include -#include "cmd-2-11.h" -#include "utils.h" +#include "cmd-2-11.hpp" +#include "utils.hpp" int cmd_create_session_2_11(const struct lttng_buffer_view *payload, char *session_name, char *hostname, char *base_path, diff --git a/src/bin/lttng-relayd/cmd-2-11.h b/src/bin/lttng-relayd/cmd-2-11.h deleted file mode 100644 index b3a3a997a..000000000 --- a/src/bin/lttng-relayd/cmd-2-11.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2018 Jonathan Rajotte - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef RELAYD_CMD_2_11_H -#define RELAYD_CMD_2_11_H - -#include "lttng-relayd.h" -#include -#include - -int cmd_create_session_2_11(const struct lttng_buffer_view *payload, - char *session_name, char *hostname, char *base_path, - uint32_t *live_timer, bool *snapshot, - uint64_t *id_sessiond, lttng_uuid sessiond_uuid, - bool *has_current_chunk, uint64_t *current_chunk_id, - time_t *creation_time, - bool *session_name_contains_creation_time); - -int cmd_recv_stream_2_11(const struct lttng_buffer_view *payload, - char **ret_path_name, char **ret_channel_name, - uint64_t *tracefile_size, uint64_t *tracefile_count, - uint64_t *trace_archive_id); - -#endif /* RELAYD_CMD_2_11_H */ diff --git a/src/bin/lttng-relayd/cmd-2-11.hpp b/src/bin/lttng-relayd/cmd-2-11.hpp new file mode 100644 index 000000000..4b004f0d3 --- /dev/null +++ b/src/bin/lttng-relayd/cmd-2-11.hpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2018 Jonathan Rajotte + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef RELAYD_CMD_2_11_H +#define RELAYD_CMD_2_11_H + +#include "lttng-relayd.hpp" +#include +#include + +int cmd_create_session_2_11(const struct lttng_buffer_view *payload, + char *session_name, char *hostname, char *base_path, + uint32_t *live_timer, bool *snapshot, + uint64_t *id_sessiond, lttng_uuid sessiond_uuid, + bool *has_current_chunk, uint64_t *current_chunk_id, + time_t *creation_time, + bool *session_name_contains_creation_time); + +int cmd_recv_stream_2_11(const struct lttng_buffer_view *payload, + char **ret_path_name, char **ret_channel_name, + uint64_t *tracefile_size, uint64_t *tracefile_count, + uint64_t *trace_archive_id); + +#endif /* RELAYD_CMD_2_11_H */ diff --git a/src/bin/lttng-relayd/cmd-2-2.cpp b/src/bin/lttng-relayd/cmd-2-2.cpp index bd18714af..3d9af63a3 100644 --- a/src/bin/lttng-relayd/cmd-2-2.cpp +++ b/src/bin/lttng-relayd/cmd-2-2.cpp @@ -9,16 +9,16 @@ #define _LGPL_SOURCE -#include -#include +#include +#include -#include -#include +#include +#include #include -#include "cmd-2-2.h" -#include "cmd-2-1.h" -#include "utils.h" +#include "cmd-2-2.hpp" +#include "cmd-2-1.hpp" +#include "utils.hpp" /* * cmd_recv_stream_2_2 allocates path_name and channel_name. diff --git a/src/bin/lttng-relayd/cmd-2-2.h b/src/bin/lttng-relayd/cmd-2-2.h deleted file mode 100644 index e754ace4c..000000000 --- a/src/bin/lttng-relayd/cmd-2-2.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef RELAYD_CMD_2_2_H -#define RELAYD_CMD_2_2_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include "lttng-relayd.h" -#include - -int cmd_recv_stream_2_2(const struct lttng_buffer_view *payload, - char **path_name, char **channel_name, - uint64_t *tracefile_size, uint64_t *tracefile_count); - -#endif /* RELAYD_CMD_2_2_H */ diff --git a/src/bin/lttng-relayd/cmd-2-2.hpp b/src/bin/lttng-relayd/cmd-2-2.hpp new file mode 100644 index 000000000..010bbb127 --- /dev/null +++ b/src/bin/lttng-relayd/cmd-2-2.hpp @@ -0,0 +1,20 @@ +#ifndef RELAYD_CMD_2_2_H +#define RELAYD_CMD_2_2_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include "lttng-relayd.hpp" +#include + +int cmd_recv_stream_2_2(const struct lttng_buffer_view *payload, + char **path_name, char **channel_name, + uint64_t *tracefile_size, uint64_t *tracefile_count); + +#endif /* RELAYD_CMD_2_2_H */ diff --git a/src/bin/lttng-relayd/cmd-2-4.cpp b/src/bin/lttng-relayd/cmd-2-4.cpp index 7abc371f0..7b546c7f6 100644 --- a/src/bin/lttng-relayd/cmd-2-4.cpp +++ b/src/bin/lttng-relayd/cmd-2-4.cpp @@ -9,15 +9,15 @@ #define _LGPL_SOURCE -#include -#include +#include +#include -#include -#include +#include +#include #include -#include "cmd-2-4.h" -#include "lttng-relayd.h" +#include "cmd-2-4.hpp" +#include "lttng-relayd.hpp" int cmd_create_session_2_4(const struct lttng_buffer_view *payload, char *session_name, char *hostname, diff --git a/src/bin/lttng-relayd/cmd-2-4.h b/src/bin/lttng-relayd/cmd-2-4.h deleted file mode 100644 index 094928717..000000000 --- a/src/bin/lttng-relayd/cmd-2-4.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef RELAYD_CMD_2_4_H -#define RELAYD_CMD_2_4_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include "lttng-relayd.h" -#include - -int cmd_create_session_2_4(const struct lttng_buffer_view *payload, - char *session_name, char *hostname, - uint32_t *live_timer, bool *snapshot); - -#endif /* RELAYD_CMD_2_4_H */ diff --git a/src/bin/lttng-relayd/cmd-2-4.hpp b/src/bin/lttng-relayd/cmd-2-4.hpp new file mode 100644 index 000000000..b3d105c84 --- /dev/null +++ b/src/bin/lttng-relayd/cmd-2-4.hpp @@ -0,0 +1,20 @@ +#ifndef RELAYD_CMD_2_4_H +#define RELAYD_CMD_2_4_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include "lttng-relayd.hpp" +#include + +int cmd_create_session_2_4(const struct lttng_buffer_view *payload, + char *session_name, char *hostname, + uint32_t *live_timer, bool *snapshot); + +#endif /* RELAYD_CMD_2_4_H */ diff --git a/src/bin/lttng-relayd/cmd.h b/src/bin/lttng-relayd/cmd.h deleted file mode 100644 index 86668b420..000000000 --- a/src/bin/lttng-relayd/cmd.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef RELAYD_CMD_H -#define RELAYD_CMD_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include "cmd-2-1.h" -#include "cmd-2-2.h" -#include "cmd-2-4.h" -#include "cmd-2-11.h" - -#endif /* RELAYD_CMD_H */ diff --git a/src/bin/lttng-relayd/cmd.hpp b/src/bin/lttng-relayd/cmd.hpp new file mode 100644 index 000000000..24e361a4b --- /dev/null +++ b/src/bin/lttng-relayd/cmd.hpp @@ -0,0 +1,18 @@ +#ifndef RELAYD_CMD_H +#define RELAYD_CMD_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include "cmd-2-1.hpp" +#include "cmd-2-2.hpp" +#include "cmd-2-4.hpp" +#include "cmd-2-11.hpp" + +#endif /* RELAYD_CMD_H */ diff --git a/src/bin/lttng-relayd/connection.cpp b/src/bin/lttng-relayd/connection.cpp index 98ffad29f..c1e58aba3 100644 --- a/src/bin/lttng-relayd/connection.cpp +++ b/src/bin/lttng-relayd/connection.cpp @@ -8,12 +8,12 @@ */ #define _LGPL_SOURCE -#include +#include #include -#include "connection.h" -#include "stream.h" -#include "viewer-session.h" +#include "connection.hpp" +#include "stream.hpp" +#include "viewer-session.hpp" bool connection_get(struct relay_connection *conn) { diff --git a/src/bin/lttng-relayd/connection.h b/src/bin/lttng-relayd/connection.h deleted file mode 100644 index 98ca91590..000000000 --- a/src/bin/lttng-relayd/connection.h +++ /dev/null @@ -1,144 +0,0 @@ -#ifndef _CONNECTION_H -#define _CONNECTION_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "session.h" - -enum connection_type { - RELAY_CONNECTION_UNKNOWN = 0, - RELAY_DATA = 1, - RELAY_CONTROL = 2, - RELAY_VIEWER_COMMAND = 3, - RELAY_VIEWER_NOTIFICATION = 4, -}; - -enum data_connection_state { - DATA_CONNECTION_STATE_RECEIVE_HEADER = 0, - DATA_CONNECTION_STATE_RECEIVE_PAYLOAD = 1, -}; - -enum ctrl_connection_state { - CTRL_CONNECTION_STATE_RECEIVE_HEADER = 0, - CTRL_CONNECTION_STATE_RECEIVE_PAYLOAD = 1, -}; - -struct data_connection_state_receive_header { - uint64_t received, left_to_receive; - char header_reception_buffer[sizeof(struct lttcomm_relayd_data_hdr)]; -}; - -struct data_connection_state_receive_payload { - uint64_t received, left_to_receive; - struct lttcomm_relayd_data_hdr header; - bool rotate_index; -}; - -struct ctrl_connection_state_receive_header { - uint64_t received, left_to_receive; -}; - -struct ctrl_connection_state_receive_payload { - uint64_t received, left_to_receive; - struct lttcomm_relayd_hdr header; -}; - -/* - * Internal structure to map a socket with the corresponding session. - * A hashtable indexed on the socket FD is used for the lookups. - * - * Connections are assumed to be accessed from a single thread. Live - * connections between the relay and a live client are only accessed - * from the live worker thread. - * - * The connections between the consumerd/sessiond and the relayd are only - * handled by the "main" worker thread (as in, the worker thread in main.c). - * - * This is why there are no back references to connections from the - * sessions and session list. - */ -struct relay_connection { - struct lttcomm_sock *sock; - struct cds_wfcq_node qnode; - - enum connection_type type; - /* - * session is only ever set for RELAY_CONTROL connection type. - */ - struct relay_session *session; - /* - * viewer_session is only ever set for RELAY_VIEWER_COMMAND - * connection type. - */ - struct relay_viewer_session *viewer_session; - - /* - * Protocol version to use for this connection. Only valid for - * RELAY_CONTROL connection type. - */ - uint32_t major; - uint32_t minor; - - struct urcu_ref ref; - - bool version_check_done; - - /* - * Node member of connection within global socket hash table. - */ - struct lttng_ht_node_ulong sock_n; - bool in_socket_ht; - struct lttng_ht *socket_ht; /* HACK: Contained within this hash table. */ - struct rcu_head rcu_node; /* For call_rcu teardown. */ - - union { - struct { - enum data_connection_state state_id; - union { - struct data_connection_state_receive_header receive_header; - struct data_connection_state_receive_payload receive_payload; - } state; - } data; - struct { - enum ctrl_connection_state state_id; - union { - struct ctrl_connection_state_receive_header receive_header; - struct ctrl_connection_state_receive_payload receive_payload; - } state; - struct lttng_dynamic_buffer reception_buffer; - } ctrl; - } protocol; -}; - -struct relay_connection *connection_create(struct lttcomm_sock *sock, - enum connection_type type); -struct relay_connection *connection_get_by_sock(struct lttng_ht *relay_connections_ht, - int sock); -int connection_reset_protocol_state(struct relay_connection *connection); -bool connection_get(struct relay_connection *connection); -void connection_put(struct relay_connection *connection); -void connection_ht_add(struct lttng_ht *relay_connections_ht, - struct relay_connection *conn); -int connection_set_session(struct relay_connection *conn, - struct relay_session *session); - -#endif /* _CONNECTION_H */ diff --git a/src/bin/lttng-relayd/connection.hpp b/src/bin/lttng-relayd/connection.hpp new file mode 100644 index 000000000..de25255a7 --- /dev/null +++ b/src/bin/lttng-relayd/connection.hpp @@ -0,0 +1,144 @@ +#ifndef _CONNECTION_H +#define _CONNECTION_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "session.hpp" + +enum connection_type { + RELAY_CONNECTION_UNKNOWN = 0, + RELAY_DATA = 1, + RELAY_CONTROL = 2, + RELAY_VIEWER_COMMAND = 3, + RELAY_VIEWER_NOTIFICATION = 4, +}; + +enum data_connection_state { + DATA_CONNECTION_STATE_RECEIVE_HEADER = 0, + DATA_CONNECTION_STATE_RECEIVE_PAYLOAD = 1, +}; + +enum ctrl_connection_state { + CTRL_CONNECTION_STATE_RECEIVE_HEADER = 0, + CTRL_CONNECTION_STATE_RECEIVE_PAYLOAD = 1, +}; + +struct data_connection_state_receive_header { + uint64_t received, left_to_receive; + char header_reception_buffer[sizeof(struct lttcomm_relayd_data_hdr)]; +}; + +struct data_connection_state_receive_payload { + uint64_t received, left_to_receive; + struct lttcomm_relayd_data_hdr header; + bool rotate_index; +}; + +struct ctrl_connection_state_receive_header { + uint64_t received, left_to_receive; +}; + +struct ctrl_connection_state_receive_payload { + uint64_t received, left_to_receive; + struct lttcomm_relayd_hdr header; +}; + +/* + * Internal structure to map a socket with the corresponding session. + * A hashtable indexed on the socket FD is used for the lookups. + * + * Connections are assumed to be accessed from a single thread. Live + * connections between the relay and a live client are only accessed + * from the live worker thread. + * + * The connections between the consumerd/sessiond and the relayd are only + * handled by the "main" worker thread (as in, the worker thread in main.c). + * + * This is why there are no back references to connections from the + * sessions and session list. + */ +struct relay_connection { + struct lttcomm_sock *sock; + struct cds_wfcq_node qnode; + + enum connection_type type; + /* + * session is only ever set for RELAY_CONTROL connection type. + */ + struct relay_session *session; + /* + * viewer_session is only ever set for RELAY_VIEWER_COMMAND + * connection type. + */ + struct relay_viewer_session *viewer_session; + + /* + * Protocol version to use for this connection. Only valid for + * RELAY_CONTROL connection type. + */ + uint32_t major; + uint32_t minor; + + struct urcu_ref ref; + + bool version_check_done; + + /* + * Node member of connection within global socket hash table. + */ + struct lttng_ht_node_ulong sock_n; + bool in_socket_ht; + struct lttng_ht *socket_ht; /* HACK: Contained within this hash table. */ + struct rcu_head rcu_node; /* For call_rcu teardown. */ + + union { + struct { + enum data_connection_state state_id; + union { + struct data_connection_state_receive_header receive_header; + struct data_connection_state_receive_payload receive_payload; + } state; + } data; + struct { + enum ctrl_connection_state state_id; + union { + struct ctrl_connection_state_receive_header receive_header; + struct ctrl_connection_state_receive_payload receive_payload; + } state; + struct lttng_dynamic_buffer reception_buffer; + } ctrl; + } protocol; +}; + +struct relay_connection *connection_create(struct lttcomm_sock *sock, + enum connection_type type); +struct relay_connection *connection_get_by_sock(struct lttng_ht *relay_connections_ht, + int sock); +int connection_reset_protocol_state(struct relay_connection *connection); +bool connection_get(struct relay_connection *connection); +void connection_put(struct relay_connection *connection); +void connection_ht_add(struct lttng_ht *relay_connections_ht, + struct relay_connection *conn); +int connection_set_session(struct relay_connection *conn, + struct relay_session *session); + +#endif /* _CONNECTION_H */ diff --git a/src/bin/lttng-relayd/ctf-trace.cpp b/src/bin/lttng-relayd/ctf-trace.cpp index 861bcfbb3..4ee745a10 100644 --- a/src/bin/lttng-relayd/ctf-trace.cpp +++ b/src/bin/lttng-relayd/ctf-trace.cpp @@ -9,13 +9,13 @@ #define _LGPL_SOURCE -#include -#include +#include +#include #include -#include "ctf-trace.h" -#include "lttng-relayd.h" -#include "stream.h" +#include "ctf-trace.hpp" +#include "lttng-relayd.hpp" +#include "stream.hpp" static uint64_t last_relay_ctf_trace_id; static pthread_mutex_t last_relay_ctf_trace_id_lock = PTHREAD_MUTEX_INITIALIZER; diff --git a/src/bin/lttng-relayd/ctf-trace.h b/src/bin/lttng-relayd/ctf-trace.h deleted file mode 100644 index 3afc00fe8..000000000 --- a/src/bin/lttng-relayd/ctf-trace.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef _CTF_TRACE_H -#define _CTF_TRACE_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include - -#include - -#include "session.h" -#include "stream.h" -#include "viewer-stream.h" - -struct ctf_trace { - struct urcu_ref ref; /* Every stream has a ref on the trace. */ - struct relay_session *session; /* Back ref to trace session */ - - /* Trace sub-folder relative to the session output path. */ - char *path; - - /* - * The ctf_trace lock nests inside the session lock. - */ - pthread_mutex_t lock; - uint64_t id; - struct relay_viewer_stream *viewer_metadata_stream; /* RCU protected */ - - /* - * Relay streams associated with this ctf trace. - * Updates are protected by the stream_list lock. - * Traversals are protected by RCU. - */ - struct cds_list_head stream_list; - pthread_mutex_t stream_list_lock; - - /* - * Node within session trace hash table. Node is indexed by - * stream path name. - */ - struct lttng_ht_node_str node; - struct rcu_head rcu_node; /* For call_rcu teardown. */ - - /* - * True if the metadata stream of this trace was sent the viewer in the - * past. - */ - bool metadata_stream_sent_to_viewer; -}; - -struct ctf_trace *ctf_trace_get_by_path_or_create(struct relay_session *session, - const char *subpath); -bool ctf_trace_get(struct ctf_trace *trace); -void ctf_trace_put(struct ctf_trace *trace); - -int ctf_trace_close(struct ctf_trace *trace); - -struct relay_viewer_stream *ctf_trace_get_viewer_metadata_stream(struct ctf_trace *trace); - -#endif /* _CTF_TRACE_H */ diff --git a/src/bin/lttng-relayd/ctf-trace.hpp b/src/bin/lttng-relayd/ctf-trace.hpp new file mode 100644 index 000000000..dbf7d3fa2 --- /dev/null +++ b/src/bin/lttng-relayd/ctf-trace.hpp @@ -0,0 +1,67 @@ +#ifndef _CTF_TRACE_H +#define _CTF_TRACE_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include + +#include + +#include "session.hpp" +#include "stream.hpp" +#include "viewer-stream.hpp" + +struct ctf_trace { + struct urcu_ref ref; /* Every stream has a ref on the trace. */ + struct relay_session *session; /* Back ref to trace session */ + + /* Trace sub-folder relative to the session output path. */ + char *path; + + /* + * The ctf_trace lock nests inside the session lock. + */ + pthread_mutex_t lock; + uint64_t id; + struct relay_viewer_stream *viewer_metadata_stream; /* RCU protected */ + + /* + * Relay streams associated with this ctf trace. + * Updates are protected by the stream_list lock. + * Traversals are protected by RCU. + */ + struct cds_list_head stream_list; + pthread_mutex_t stream_list_lock; + + /* + * Node within session trace hash table. Node is indexed by + * stream path name. + */ + struct lttng_ht_node_str node; + struct rcu_head rcu_node; /* For call_rcu teardown. */ + + /* + * True if the metadata stream of this trace was sent the viewer in the + * past. + */ + bool metadata_stream_sent_to_viewer; +}; + +struct ctf_trace *ctf_trace_get_by_path_or_create(struct relay_session *session, + const char *subpath); +bool ctf_trace_get(struct ctf_trace *trace); +void ctf_trace_put(struct ctf_trace *trace); + +int ctf_trace_close(struct ctf_trace *trace); + +struct relay_viewer_stream *ctf_trace_get_viewer_metadata_stream(struct ctf_trace *trace); + +#endif /* _CTF_TRACE_H */ diff --git a/src/bin/lttng-relayd/health-relayd.cpp b/src/bin/lttng-relayd/health-relayd.cpp index d43c37185..8e22dfe66 100644 --- a/src/bin/lttng-relayd/health-relayd.cpp +++ b/src/bin/lttng-relayd/health-relayd.cpp @@ -28,18 +28,18 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "lttng-relayd.h" -#include "health-relayd.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "lttng-relayd.hpp" +#include "health-relayd.hpp" /* Global health check unix path */ static diff --git a/src/bin/lttng-relayd/health-relayd.h b/src/bin/lttng-relayd/health-relayd.h deleted file mode 100644 index 4cd3ec1e7..000000000 --- a/src/bin/lttng-relayd/health-relayd.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef HEALTH_RELAYD_H -#define HEALTH_RELAYD_H - -/* - * Copyright (C) 2012 David Goulet - * Copyright (C) 2013 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include - -#define LTTNG_RELAYD_HEALTH_ENV "LTTNG_RELAYD_HEALTH" - -enum health_type_relayd { - HEALTH_RELAYD_TYPE_DISPATCHER = 0, - HEALTH_RELAYD_TYPE_WORKER = 1, - HEALTH_RELAYD_TYPE_LISTENER = 2, - HEALTH_RELAYD_TYPE_LIVE_DISPATCHER = 3, - HEALTH_RELAYD_TYPE_LIVE_WORKER = 4, - HEALTH_RELAYD_TYPE_LIVE_LISTENER = 5, - - NR_HEALTH_RELAYD_TYPES, -}; - -extern struct health_app *health_relayd; - -extern int health_quit_pipe[2]; - -void *thread_manage_health_relayd(void *data); - -#endif /* HEALTH_RELAYD_H */ diff --git a/src/bin/lttng-relayd/health-relayd.hpp b/src/bin/lttng-relayd/health-relayd.hpp new file mode 100644 index 000000000..7d885c672 --- /dev/null +++ b/src/bin/lttng-relayd/health-relayd.hpp @@ -0,0 +1,34 @@ +#ifndef HEALTH_RELAYD_H +#define HEALTH_RELAYD_H + +/* + * Copyright (C) 2012 David Goulet + * Copyright (C) 2013 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include + +#define LTTNG_RELAYD_HEALTH_ENV "LTTNG_RELAYD_HEALTH" + +enum health_type_relayd { + HEALTH_RELAYD_TYPE_DISPATCHER = 0, + HEALTH_RELAYD_TYPE_WORKER = 1, + HEALTH_RELAYD_TYPE_LISTENER = 2, + HEALTH_RELAYD_TYPE_LIVE_DISPATCHER = 3, + HEALTH_RELAYD_TYPE_LIVE_WORKER = 4, + HEALTH_RELAYD_TYPE_LIVE_LISTENER = 5, + + NR_HEALTH_RELAYD_TYPES, +}; + +extern struct health_app *health_relayd; + +extern int health_quit_pipe[2]; + +void *thread_manage_health_relayd(void *data); + +#endif /* HEALTH_RELAYD_H */ diff --git a/src/bin/lttng-relayd/index.cpp b/src/bin/lttng-relayd/index.cpp index 6cf131b25..651b36715 100644 --- a/src/bin/lttng-relayd/index.cpp +++ b/src/bin/lttng-relayd/index.cpp @@ -9,14 +9,14 @@ #define _LGPL_SOURCE -#include -#include -#include - -#include "lttng-relayd.h" -#include "stream.h" -#include "index.h" -#include "connection.h" +#include +#include +#include + +#include "lttng-relayd.hpp" +#include "stream.hpp" +#include "index.hpp" +#include "connection.hpp" /* * Allocate a new relay index object. Pass the stream in which it is diff --git a/src/bin/lttng-relayd/index.h b/src/bin/lttng-relayd/index.h deleted file mode 100644 index 4364f12ff..000000000 --- a/src/bin/lttng-relayd/index.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef _RELAY_INDEX_H -#define _RELAY_INDEX_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include - -#include -#include - -struct relay_stream; -struct relay_connection; -struct lttcomm_relayd_index; - -struct relay_index { - /* - * index lock nests inside stream lock. - */ - struct urcu_ref ref; /* Reference from getters. */ - struct relay_stream *stream; /* Back ref to stream */ - - pthread_mutex_t lock; - /* - * index file on which to write the index data. May differ from - * stream->index_file due to tracefile rotation. - */ - struct lttng_index_file *index_file; - - /* Index packet data. This is the data that is written on disk. */ - struct ctf_packet_index index_data; - /* Data + padding size of this packet, filled by the data thread. */ - uint64_t total_size; - - bool has_index_data; - bool flushed; - bool in_hash_table; - - /* - * Node within indexes_ht that corresponds to this struct - * relay_index. Indexed by net_seq_num, which is unique for this - * index across the stream. - */ - struct lttng_ht_node_u64 index_n; - struct rcu_head rcu_node; /* For call_rcu teardown. */ -}; - -struct relay_index *relay_index_get_by_id_or_create(struct relay_stream *stream, - uint64_t net_seq_num); -void relay_index_put(struct relay_index *index); -int relay_index_set_file(struct relay_index *index, - struct lttng_index_file *index_file, - uint64_t data_offset); -int relay_index_set_data(struct relay_index *index, - const struct ctf_packet_index *data); -int relay_index_try_flush(struct relay_index *index); - -void relay_index_close_all(struct relay_stream *stream); -void relay_index_close_partial_fd(struct relay_stream *stream); -uint64_t relay_index_find_last(struct relay_stream *stream); -int relay_index_switch_all_files(struct relay_stream *stream); -int relay_index_set_control_data(struct relay_index *index, - const struct lttcomm_relayd_index *data, - unsigned int minor_version); - -#endif /* _RELAY_INDEX_H */ diff --git a/src/bin/lttng-relayd/index.hpp b/src/bin/lttng-relayd/index.hpp new file mode 100644 index 000000000..cb29485eb --- /dev/null +++ b/src/bin/lttng-relayd/index.hpp @@ -0,0 +1,73 @@ +#ifndef _RELAY_INDEX_H +#define _RELAY_INDEX_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include + +#include +#include + +struct relay_stream; +struct relay_connection; +struct lttcomm_relayd_index; + +struct relay_index { + /* + * index lock nests inside stream lock. + */ + struct urcu_ref ref; /* Reference from getters. */ + struct relay_stream *stream; /* Back ref to stream */ + + pthread_mutex_t lock; + /* + * index file on which to write the index data. May differ from + * stream->index_file due to tracefile rotation. + */ + struct lttng_index_file *index_file; + + /* Index packet data. This is the data that is written on disk. */ + struct ctf_packet_index index_data; + /* Data + padding size of this packet, filled by the data thread. */ + uint64_t total_size; + + bool has_index_data; + bool flushed; + bool in_hash_table; + + /* + * Node within indexes_ht that corresponds to this struct + * relay_index. Indexed by net_seq_num, which is unique for this + * index across the stream. + */ + struct lttng_ht_node_u64 index_n; + struct rcu_head rcu_node; /* For call_rcu teardown. */ +}; + +struct relay_index *relay_index_get_by_id_or_create(struct relay_stream *stream, + uint64_t net_seq_num); +void relay_index_put(struct relay_index *index); +int relay_index_set_file(struct relay_index *index, + struct lttng_index_file *index_file, + uint64_t data_offset); +int relay_index_set_data(struct relay_index *index, + const struct ctf_packet_index *data); +int relay_index_try_flush(struct relay_index *index); + +void relay_index_close_all(struct relay_stream *stream); +void relay_index_close_partial_fd(struct relay_stream *stream); +uint64_t relay_index_find_last(struct relay_stream *stream); +int relay_index_switch_all_files(struct relay_stream *stream); +int relay_index_set_control_data(struct relay_index *index, + const struct lttcomm_relayd_index *data, + unsigned int minor_version); + +#endif /* _RELAY_INDEX_H */ diff --git a/src/bin/lttng-relayd/live.cpp b/src/bin/lttng-relayd/live.cpp index 5aa899b28..64c194fdc 100644 --- a/src/bin/lttng-relayd/live.cpp +++ b/src/bin/lttng-relayd/live.cpp @@ -31,34 +31,34 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "cmd.h" -#include "connection.h" -#include "ctf-trace.h" -#include "health-relayd.h" -#include "live.h" -#include "lttng-relayd.h" -#include "session.h" -#include "stream.h" -#include "testpoint.h" -#include "utils.h" -#include "viewer-session.h" -#include "viewer-stream.h" +#include "cmd.hpp" +#include "connection.hpp" +#include "ctf-trace.hpp" +#include "health-relayd.hpp" +#include "live.hpp" +#include "lttng-relayd.hpp" +#include "session.hpp" +#include "stream.hpp" +#include "testpoint.hpp" +#include "utils.hpp" +#include "viewer-session.hpp" +#include "viewer-stream.hpp" #define SESSION_BUF_DEFAULT_COUNT 16 diff --git a/src/bin/lttng-relayd/live.h b/src/bin/lttng-relayd/live.h deleted file mode 100644 index d6ec89e0f..000000000 --- a/src/bin/lttng-relayd/live.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef LTTNG_RELAYD_LIVE_H -#define LTTNG_RELAYD_LIVE_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include - -#include "lttng-relayd.h" - -int relayd_live_create(struct lttng_uri *live_uri); -int relayd_live_stop(void); -int relayd_live_join(void); - -#endif /* LTTNG_RELAYD_LIVE_H */ diff --git a/src/bin/lttng-relayd/live.hpp b/src/bin/lttng-relayd/live.hpp new file mode 100644 index 000000000..d1866d3f5 --- /dev/null +++ b/src/bin/lttng-relayd/live.hpp @@ -0,0 +1,21 @@ +#ifndef LTTNG_RELAYD_LIVE_H +#define LTTNG_RELAYD_LIVE_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include + +#include "lttng-relayd.hpp" + +int relayd_live_create(struct lttng_uri *live_uri); +int relayd_live_stop(void); +int relayd_live_join(void); + +#endif /* LTTNG_RELAYD_LIVE_H */ diff --git a/src/bin/lttng-relayd/lttng-relayd.h b/src/bin/lttng-relayd/lttng-relayd.h deleted file mode 100644 index e64bb373f..000000000 --- a/src/bin/lttng-relayd/lttng-relayd.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef LTTNG_RELAYD_H -#define LTTNG_RELAYD_H - -/* - * Copyright (C) 2012 Julien Desfossez - * Copyright (C) 2012 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include -#include - -#include -#include - -struct sessiond_trace_chunk_registry; - -/* - * Queue used to enqueue relay requests - */ -struct relay_conn_queue { - struct cds_wfcq_head head; - struct cds_wfcq_tail tail; - int32_t futex; -}; - -enum relay_group_output_by { - RELAYD_GROUP_OUTPUT_BY_UNKNOWN, - RELAYD_GROUP_OUTPUT_BY_HOST, - RELAYD_GROUP_OUTPUT_BY_SESSION, -}; - -/* - * Contains stream indexed by ID. This is important since many commands lookup - * streams only by ID thus also keeping them in this hash table makes the - * search O(1). - */ -extern struct lttng_ht *sessions_ht; -extern struct lttng_ht *relay_streams_ht; -extern struct lttng_ht *viewer_streams_ht; -extern struct sessiond_trace_chunk_registry *sessiond_trace_chunk_registry; - -extern char *opt_output_path; -extern const char *tracing_group_name; -extern const char * const config_section_name; -extern enum relay_group_output_by opt_group_output_by; - -extern int thread_quit_pipe[2]; - -extern struct fd_tracker *the_fd_tracker; - -void lttng_relay_notify_ready(void); -int lttng_relay_stop_threads(void); - -#endif /* LTTNG_RELAYD_H */ diff --git a/src/bin/lttng-relayd/lttng-relayd.hpp b/src/bin/lttng-relayd/lttng-relayd.hpp new file mode 100644 index 000000000..a92ace77d --- /dev/null +++ b/src/bin/lttng-relayd/lttng-relayd.hpp @@ -0,0 +1,59 @@ +#ifndef LTTNG_RELAYD_H +#define LTTNG_RELAYD_H + +/* + * Copyright (C) 2012 Julien Desfossez + * Copyright (C) 2012 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include +#include + +#include +#include + +struct sessiond_trace_chunk_registry; + +/* + * Queue used to enqueue relay requests + */ +struct relay_conn_queue { + struct cds_wfcq_head head; + struct cds_wfcq_tail tail; + int32_t futex; +}; + +enum relay_group_output_by { + RELAYD_GROUP_OUTPUT_BY_UNKNOWN, + RELAYD_GROUP_OUTPUT_BY_HOST, + RELAYD_GROUP_OUTPUT_BY_SESSION, +}; + +/* + * Contains stream indexed by ID. This is important since many commands lookup + * streams only by ID thus also keeping them in this hash table makes the + * search O(1). + */ +extern struct lttng_ht *sessions_ht; +extern struct lttng_ht *relay_streams_ht; +extern struct lttng_ht *viewer_streams_ht; +extern struct sessiond_trace_chunk_registry *sessiond_trace_chunk_registry; + +extern char *opt_output_path; +extern const char *tracing_group_name; +extern const char * const config_section_name; +extern enum relay_group_output_by opt_group_output_by; + +extern int thread_quit_pipe[2]; + +extern struct fd_tracker *the_fd_tracker; + +void lttng_relay_notify_ready(void); +int lttng_relay_stop_threads(void); + +#endif /* LTTNG_RELAYD_H */ diff --git a/src/bin/lttng-relayd/lttng-viewer-abi.h b/src/bin/lttng-relayd/lttng-viewer-abi.h deleted file mode 100644 index f5f61b4d9..000000000 --- a/src/bin/lttng-relayd/lttng-viewer-abi.h +++ /dev/null @@ -1,240 +0,0 @@ -#ifndef LTTNG_VIEWER_ABI_H -#define LTTNG_VIEWER_ABI_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 Mathieu Desnoyers - * Copyright (C) 2013 David Goulet - * - * SPDX-License-Identifier: MIT - * - */ - -#include -#include - -#define LTTNG_VIEWER_PATH_MAX 4096 -#define LTTNG_VIEWER_NAME_MAX 255 -#define LTTNG_VIEWER_HOST_NAME_MAX 64 - -/* Flags in reply to get_next_index and get_packet. */ -enum { - /* New metadata is required to read this packet. */ - LTTNG_VIEWER_FLAG_NEW_METADATA = (1 << 0), - /* New stream got added to the trace. */ - LTTNG_VIEWER_FLAG_NEW_STREAM = (1 << 1), -}; - -enum lttng_viewer_command { - LTTNG_VIEWER_CONNECT = 1, - LTTNG_VIEWER_LIST_SESSIONS = 2, - LTTNG_VIEWER_ATTACH_SESSION = 3, - LTTNG_VIEWER_GET_NEXT_INDEX = 4, - LTTNG_VIEWER_GET_PACKET = 5, - LTTNG_VIEWER_GET_METADATA = 6, - LTTNG_VIEWER_GET_NEW_STREAMS = 7, - LTTNG_VIEWER_CREATE_SESSION = 8, - LTTNG_VIEWER_DETACH_SESSION = 9, -}; - -enum lttng_viewer_attach_return_code { - LTTNG_VIEWER_ATTACH_OK = 1, /* The attach command succeeded. */ - LTTNG_VIEWER_ATTACH_ALREADY = 2, /* A viewer is already attached. */ - LTTNG_VIEWER_ATTACH_UNK = 3, /* The session ID is unknown. */ - LTTNG_VIEWER_ATTACH_NOT_LIVE = 4, /* The session is not live. */ - LTTNG_VIEWER_ATTACH_SEEK_ERR = 5, /* Seek error. */ - LTTNG_VIEWER_ATTACH_NO_SESSION = 6, /* No viewer session created. */ -}; - -enum lttng_viewer_next_index_return_code { - LTTNG_VIEWER_INDEX_OK = 1, /* Index is available. */ - LTTNG_VIEWER_INDEX_RETRY = 2, /* Index not yet available. */ - LTTNG_VIEWER_INDEX_HUP = 3, /* Index closed (trace destroyed). */ - LTTNG_VIEWER_INDEX_ERR = 4, /* Unknow error. */ - LTTNG_VIEWER_INDEX_INACTIVE = 5, /* Inactive stream beacon. */ - LTTNG_VIEWER_INDEX_EOF = 6, /* End of index file. */ -}; - -enum lttng_viewer_get_packet_return_code { - LTTNG_VIEWER_GET_PACKET_OK = 1, - LTTNG_VIEWER_GET_PACKET_RETRY = 2, - LTTNG_VIEWER_GET_PACKET_ERR = 3, - LTTNG_VIEWER_GET_PACKET_EOF = 4, -}; - -enum lttng_viewer_get_metadata_return_code { - LTTNG_VIEWER_METADATA_OK = 1, - LTTNG_VIEWER_NO_NEW_METADATA = 2, - LTTNG_VIEWER_METADATA_ERR = 3, -}; - -enum lttng_viewer_connection_type { - LTTNG_VIEWER_CLIENT_COMMAND = 1, - LTTNG_VIEWER_CLIENT_NOTIFICATION = 2, -}; - -enum lttng_viewer_seek { - /* Receive the trace packets from the beginning. */ - LTTNG_VIEWER_SEEK_BEGINNING = 1, - /* Receive the trace packets from now. */ - LTTNG_VIEWER_SEEK_LAST = 2, -}; - -enum lttng_viewer_new_streams_return_code { - LTTNG_VIEWER_NEW_STREAMS_OK = 1, /* If new streams are being sent. */ - LTTNG_VIEWER_NEW_STREAMS_NO_NEW = 2, /* If no new streams are available. */ - LTTNG_VIEWER_NEW_STREAMS_ERR = 3, /* Error. */ - LTTNG_VIEWER_NEW_STREAMS_HUP = 4, /* Session closed. */ -}; - -enum lttng_viewer_create_session_return_code { - LTTNG_VIEWER_CREATE_SESSION_OK = 1, - LTTNG_VIEWER_CREATE_SESSION_ERR = 2, -}; - -enum lttng_viewer_detach_session_return_code { - LTTNG_VIEWER_DETACH_SESSION_OK = 1, - LTTNG_VIEWER_DETACH_SESSION_UNK = 2, - LTTNG_VIEWER_DETACH_SESSION_ERR = 3, -}; - -struct lttng_viewer_session { - uint64_t id; - uint32_t live_timer; - uint32_t clients; - uint32_t streams; - char hostname[LTTNG_VIEWER_HOST_NAME_MAX]; - char session_name[LTTNG_VIEWER_NAME_MAX]; -} LTTNG_PACKED; - -struct lttng_viewer_stream { - uint64_t id; - uint64_t ctf_trace_id; - uint32_t metadata_flag; - char path_name[LTTNG_VIEWER_PATH_MAX]; - char channel_name[LTTNG_VIEWER_NAME_MAX]; -} LTTNG_PACKED; - -struct lttng_viewer_cmd { - uint64_t data_size; /* data size following this header */ - uint32_t cmd; /* enum lttcomm_relayd_command */ - uint32_t cmd_version; /* command version */ -} LTTNG_PACKED; - -/* - * LTTNG_VIEWER_CONNECT payload. - */ -struct lttng_viewer_connect { - /* session ID assigned by the relay for command connections */ - uint64_t viewer_session_id; - uint32_t major; - uint32_t minor; - uint32_t type; /* enum lttng_viewer_connection_type */ -} LTTNG_PACKED; - -/* - * LTTNG_VIEWER_LIST_SESSIONS payload. - */ -struct lttng_viewer_list_sessions { - uint32_t sessions_count; - char session_list[]; /* struct lttng_viewer_session */ -} LTTNG_PACKED; - -/* - * LTTNG_VIEWER_ATTACH_SESSION payload. - */ -struct lttng_viewer_attach_session_request { - uint64_t session_id; - uint64_t offset; /* unused for now */ - uint32_t seek; /* enum lttng_viewer_seek */ -} LTTNG_PACKED; - -struct lttng_viewer_attach_session_response { - /* enum lttng_viewer_attach_return_code */ - uint32_t status; - uint32_t streams_count; - /* struct lttng_viewer_stream */ - char stream_list[]; -} LTTNG_PACKED; - -/* - * LTTNG_VIEWER_GET_NEXT_INDEX payload. - */ -struct lttng_viewer_get_next_index { - uint64_t stream_id; -} __attribute__ ((__packed__)); - -struct lttng_viewer_index { - uint64_t offset; - uint64_t packet_size; - uint64_t content_size; - uint64_t timestamp_begin; - uint64_t timestamp_end; - uint64_t events_discarded; - uint64_t stream_id; - uint32_t status; /* enum lttng_viewer_next_index_return_code */ - uint32_t flags; /* LTTNG_VIEWER_FLAG_* */ -} __attribute__ ((__packed__)); - -/* - * LTTNG_VIEWER_GET_PACKET payload. - */ -struct lttng_viewer_get_packet { - uint64_t stream_id; - uint64_t offset; - uint32_t len; -} LTTNG_PACKED; - -struct lttng_viewer_trace_packet { - uint32_t status; /* enum lttng_viewer_get_packet_return_code */ - uint32_t len; - uint32_t flags; /* LTTNG_VIEWER_FLAG_* */ - char data[]; -} LTTNG_PACKED; - -/* - * LTTNG_VIEWER_GET_METADATA payload. - */ -struct lttng_viewer_get_metadata { - uint64_t stream_id; -} LTTNG_PACKED; - -struct lttng_viewer_metadata_packet { - uint64_t len; - uint32_t status; /* enum lttng_viewer_get_metadata_return_code */ - char data[]; -} LTTNG_PACKED; - -/* - * LTTNG_VIEWER_GET_NEW_STREAMS payload. - */ -struct lttng_viewer_new_streams_request { - uint64_t session_id; -} LTTNG_PACKED; - -struct lttng_viewer_new_streams_response { - /* enum lttng_viewer_new_streams_return_code */ - uint32_t status; - uint32_t streams_count; - /* struct lttng_viewer_stream */ - char stream_list[]; -} LTTNG_PACKED; - -struct lttng_viewer_create_session_response { - /* enum lttng_viewer_create_session_return_code */ - uint32_t status; -} LTTNG_PACKED; - -/* - * LTTNG_VIEWER_DETACH_SESSION payload. - */ -struct lttng_viewer_detach_session_request { - uint64_t session_id; -} LTTNG_PACKED; - -struct lttng_viewer_detach_session_response { - /* enum lttng_viewer_detach_session_return_code */ - uint32_t status; -} LTTNG_PACKED; - -#endif /* LTTNG_VIEWER_ABI_H */ diff --git a/src/bin/lttng-relayd/lttng-viewer-abi.hpp b/src/bin/lttng-relayd/lttng-viewer-abi.hpp new file mode 100644 index 000000000..6fdb7fa60 --- /dev/null +++ b/src/bin/lttng-relayd/lttng-viewer-abi.hpp @@ -0,0 +1,240 @@ +#ifndef LTTNG_VIEWER_ABI_H +#define LTTNG_VIEWER_ABI_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 Mathieu Desnoyers + * Copyright (C) 2013 David Goulet + * + * SPDX-License-Identifier: MIT + * + */ + +#include +#include + +#define LTTNG_VIEWER_PATH_MAX 4096 +#define LTTNG_VIEWER_NAME_MAX 255 +#define LTTNG_VIEWER_HOST_NAME_MAX 64 + +/* Flags in reply to get_next_index and get_packet. */ +enum { + /* New metadata is required to read this packet. */ + LTTNG_VIEWER_FLAG_NEW_METADATA = (1 << 0), + /* New stream got added to the trace. */ + LTTNG_VIEWER_FLAG_NEW_STREAM = (1 << 1), +}; + +enum lttng_viewer_command { + LTTNG_VIEWER_CONNECT = 1, + LTTNG_VIEWER_LIST_SESSIONS = 2, + LTTNG_VIEWER_ATTACH_SESSION = 3, + LTTNG_VIEWER_GET_NEXT_INDEX = 4, + LTTNG_VIEWER_GET_PACKET = 5, + LTTNG_VIEWER_GET_METADATA = 6, + LTTNG_VIEWER_GET_NEW_STREAMS = 7, + LTTNG_VIEWER_CREATE_SESSION = 8, + LTTNG_VIEWER_DETACH_SESSION = 9, +}; + +enum lttng_viewer_attach_return_code { + LTTNG_VIEWER_ATTACH_OK = 1, /* The attach command succeeded. */ + LTTNG_VIEWER_ATTACH_ALREADY = 2, /* A viewer is already attached. */ + LTTNG_VIEWER_ATTACH_UNK = 3, /* The session ID is unknown. */ + LTTNG_VIEWER_ATTACH_NOT_LIVE = 4, /* The session is not live. */ + LTTNG_VIEWER_ATTACH_SEEK_ERR = 5, /* Seek error. */ + LTTNG_VIEWER_ATTACH_NO_SESSION = 6, /* No viewer session created. */ +}; + +enum lttng_viewer_next_index_return_code { + LTTNG_VIEWER_INDEX_OK = 1, /* Index is available. */ + LTTNG_VIEWER_INDEX_RETRY = 2, /* Index not yet available. */ + LTTNG_VIEWER_INDEX_HUP = 3, /* Index closed (trace destroyed). */ + LTTNG_VIEWER_INDEX_ERR = 4, /* Unknow error. */ + LTTNG_VIEWER_INDEX_INACTIVE = 5, /* Inactive stream beacon. */ + LTTNG_VIEWER_INDEX_EOF = 6, /* End of index file. */ +}; + +enum lttng_viewer_get_packet_return_code { + LTTNG_VIEWER_GET_PACKET_OK = 1, + LTTNG_VIEWER_GET_PACKET_RETRY = 2, + LTTNG_VIEWER_GET_PACKET_ERR = 3, + LTTNG_VIEWER_GET_PACKET_EOF = 4, +}; + +enum lttng_viewer_get_metadata_return_code { + LTTNG_VIEWER_METADATA_OK = 1, + LTTNG_VIEWER_NO_NEW_METADATA = 2, + LTTNG_VIEWER_METADATA_ERR = 3, +}; + +enum lttng_viewer_connection_type { + LTTNG_VIEWER_CLIENT_COMMAND = 1, + LTTNG_VIEWER_CLIENT_NOTIFICATION = 2, +}; + +enum lttng_viewer_seek { + /* Receive the trace packets from the beginning. */ + LTTNG_VIEWER_SEEK_BEGINNING = 1, + /* Receive the trace packets from now. */ + LTTNG_VIEWER_SEEK_LAST = 2, +}; + +enum lttng_viewer_new_streams_return_code { + LTTNG_VIEWER_NEW_STREAMS_OK = 1, /* If new streams are being sent. */ + LTTNG_VIEWER_NEW_STREAMS_NO_NEW = 2, /* If no new streams are available. */ + LTTNG_VIEWER_NEW_STREAMS_ERR = 3, /* Error. */ + LTTNG_VIEWER_NEW_STREAMS_HUP = 4, /* Session closed. */ +}; + +enum lttng_viewer_create_session_return_code { + LTTNG_VIEWER_CREATE_SESSION_OK = 1, + LTTNG_VIEWER_CREATE_SESSION_ERR = 2, +}; + +enum lttng_viewer_detach_session_return_code { + LTTNG_VIEWER_DETACH_SESSION_OK = 1, + LTTNG_VIEWER_DETACH_SESSION_UNK = 2, + LTTNG_VIEWER_DETACH_SESSION_ERR = 3, +}; + +struct lttng_viewer_session { + uint64_t id; + uint32_t live_timer; + uint32_t clients; + uint32_t streams; + char hostname[LTTNG_VIEWER_HOST_NAME_MAX]; + char session_name[LTTNG_VIEWER_NAME_MAX]; +} LTTNG_PACKED; + +struct lttng_viewer_stream { + uint64_t id; + uint64_t ctf_trace_id; + uint32_t metadata_flag; + char path_name[LTTNG_VIEWER_PATH_MAX]; + char channel_name[LTTNG_VIEWER_NAME_MAX]; +} LTTNG_PACKED; + +struct lttng_viewer_cmd { + uint64_t data_size; /* data size following this header */ + uint32_t cmd; /* enum lttcomm_relayd_command */ + uint32_t cmd_version; /* command version */ +} LTTNG_PACKED; + +/* + * LTTNG_VIEWER_CONNECT payload. + */ +struct lttng_viewer_connect { + /* session ID assigned by the relay for command connections */ + uint64_t viewer_session_id; + uint32_t major; + uint32_t minor; + uint32_t type; /* enum lttng_viewer_connection_type */ +} LTTNG_PACKED; + +/* + * LTTNG_VIEWER_LIST_SESSIONS payload. + */ +struct lttng_viewer_list_sessions { + uint32_t sessions_count; + char session_list[]; /* struct lttng_viewer_session */ +} LTTNG_PACKED; + +/* + * LTTNG_VIEWER_ATTACH_SESSION payload. + */ +struct lttng_viewer_attach_session_request { + uint64_t session_id; + uint64_t offset; /* unused for now */ + uint32_t seek; /* enum lttng_viewer_seek */ +} LTTNG_PACKED; + +struct lttng_viewer_attach_session_response { + /* enum lttng_viewer_attach_return_code */ + uint32_t status; + uint32_t streams_count; + /* struct lttng_viewer_stream */ + char stream_list[]; +} LTTNG_PACKED; + +/* + * LTTNG_VIEWER_GET_NEXT_INDEX payload. + */ +struct lttng_viewer_get_next_index { + uint64_t stream_id; +} __attribute__ ((__packed__)); + +struct lttng_viewer_index { + uint64_t offset; + uint64_t packet_size; + uint64_t content_size; + uint64_t timestamp_begin; + uint64_t timestamp_end; + uint64_t events_discarded; + uint64_t stream_id; + uint32_t status; /* enum lttng_viewer_next_index_return_code */ + uint32_t flags; /* LTTNG_VIEWER_FLAG_* */ +} __attribute__ ((__packed__)); + +/* + * LTTNG_VIEWER_GET_PACKET payload. + */ +struct lttng_viewer_get_packet { + uint64_t stream_id; + uint64_t offset; + uint32_t len; +} LTTNG_PACKED; + +struct lttng_viewer_trace_packet { + uint32_t status; /* enum lttng_viewer_get_packet_return_code */ + uint32_t len; + uint32_t flags; /* LTTNG_VIEWER_FLAG_* */ + char data[]; +} LTTNG_PACKED; + +/* + * LTTNG_VIEWER_GET_METADATA payload. + */ +struct lttng_viewer_get_metadata { + uint64_t stream_id; +} LTTNG_PACKED; + +struct lttng_viewer_metadata_packet { + uint64_t len; + uint32_t status; /* enum lttng_viewer_get_metadata_return_code */ + char data[]; +} LTTNG_PACKED; + +/* + * LTTNG_VIEWER_GET_NEW_STREAMS payload. + */ +struct lttng_viewer_new_streams_request { + uint64_t session_id; +} LTTNG_PACKED; + +struct lttng_viewer_new_streams_response { + /* enum lttng_viewer_new_streams_return_code */ + uint32_t status; + uint32_t streams_count; + /* struct lttng_viewer_stream */ + char stream_list[]; +} LTTNG_PACKED; + +struct lttng_viewer_create_session_response { + /* enum lttng_viewer_create_session_return_code */ + uint32_t status; +} LTTNG_PACKED; + +/* + * LTTNG_VIEWER_DETACH_SESSION payload. + */ +struct lttng_viewer_detach_session_request { + uint64_t session_id; +} LTTNG_PACKED; + +struct lttng_viewer_detach_session_response { + /* enum lttng_viewer_detach_session_return_code */ + uint32_t status; +} LTTNG_PACKED; + +#endif /* LTTNG_VIEWER_ABI_H */ diff --git a/src/bin/lttng-relayd/main.cpp b/src/bin/lttng-relayd/main.cpp index 42eb09a89..e1c74e358 100644 --- a/src/bin/lttng-relayd/main.cpp +++ b/src/bin/lttng-relayd/main.cpp @@ -36,45 +36,45 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "backward-compatibility-group-by.h" -#include "cmd.h" -#include "connection.h" -#include "ctf-trace.h" -#include "health-relayd.h" -#include "index.h" -#include "live.h" -#include "lttng-relayd.h" -#include "session.h" -#include "sessiond-trace-chunks.h" -#include "stream.h" -#include "tcp_keep_alive.h" -#include "testpoint.h" -#include "tracefile-array.h" -#include "utils.h" -#include "version.h" -#include "viewer-stream.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "backward-compatibility-group-by.hpp" +#include "cmd.hpp" +#include "connection.hpp" +#include "ctf-trace.hpp" +#include "health-relayd.hpp" +#include "index.hpp" +#include "live.hpp" +#include "lttng-relayd.hpp" +#include "session.hpp" +#include "sessiond-trace-chunks.hpp" +#include "stream.hpp" +#include "tcp_keep_alive.hpp" +#include "testpoint.hpp" +#include "tracefile-array.hpp" +#include "utils.hpp" +#include "version.hpp" +#include "viewer-stream.hpp" static const char *help_msg = #ifdef LTTNG_EMBED_HELP diff --git a/src/bin/lttng-relayd/session.cpp b/src/bin/lttng-relayd/session.cpp index ca8e183e6..abefc0d27 100644 --- a/src/bin/lttng-relayd/session.cpp +++ b/src/bin/lttng-relayd/session.cpp @@ -8,23 +8,23 @@ */ #define _LGPL_SOURCE -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include -#include "ctf-trace.h" -#include "lttng-relayd.h" -#include "session.h" -#include "sessiond-trace-chunks.h" -#include "stream.h" -#include -#include "utils.h" +#include "ctf-trace.hpp" +#include "lttng-relayd.hpp" +#include "session.hpp" +#include "sessiond-trace-chunks.hpp" +#include "stream.hpp" +#include +#include "utils.hpp" /* Global session id used in the session creation. */ static uint64_t last_relay_session_id; diff --git a/src/bin/lttng-relayd/session.h b/src/bin/lttng-relayd/session.h deleted file mode 100644 index 8029dcd8e..000000000 --- a/src/bin/lttng-relayd/session.h +++ /dev/null @@ -1,163 +0,0 @@ -#ifndef _SESSION_H -#define _SESSION_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -/* - * Represents a session for the relay point of view - */ -struct relay_session { - /* - * This session id is generated by the relay daemon to guarantee - * its uniqueness even when serving multiple session daemons. - * It is used to match a set of streams to their session. - */ - uint64_t id; - /* - * ID of the session in the session daemon's domain. - * This information is only provided by 2.11+ peers. - */ - LTTNG_OPTIONAL(uint64_t) id_sessiond; - /* - * Only provided by 2.11+ peers. However, the UUID is set to 'nil' in - * the other cases. - */ - lttng_uuid sessiond_uuid; - /* - * Contains the creation time on the session daemon's end for 2.11+ - * peers. Otherwise, this contains the session creation time on the - * relay daemon's end. - */ - LTTNG_OPTIONAL(time_t) creation_time; - /* Must _not_ be empty for 2.4+ peers. */ - char session_name[LTTNG_NAME_MAX]; - char hostname[LTTNG_HOST_NAME_MAX]; - char base_path[LTTNG_PATH_MAX]; - /* - * Session output path relative to relayd's output path. - * Will be empty when interacting with peers < 2.11 since their - * streams' path are expressed relative to the relay daemon's - * output path. - */ - char output_path[LTTNG_PATH_MAX]; - uint32_t live_timer; - - /* Session in snapshot mode. */ - bool snapshot; - - /* - * Session has no back reference to its connection because it - * has a life-time that can be longer than the consumer connection's - * life-time; a reference can still be held by the viewer - * connection through the viewer streams. - */ - - struct urcu_ref ref; - - mutable pthread_mutex_t lock; - - /* major/minor version used for this session. */ - uint32_t major; - uint32_t minor; - - bool viewer_attached; - /* Tell if the session connection has been closed on the streaming side. */ - bool connection_closed; - - /* - * Tell if the session is currently living in a exiting relayd and - * should be cleaned forcefully without waiting for pending data or - * pending ctrl data. - */ - bool aborted; - - bool session_name_contains_creation_time; - /* Whether session has performed an explicit rotation. */ - bool has_rotated; - - /* Contains ctf_trace object of that session indexed by path name. */ - struct lttng_ht *ctf_traces_ht; - - /* - * This contains streams that are received on that connection. - * It's used to store them until we get the streams sent - * command. When this is received, we remove those streams from - * the list and publish them. - * - * Updates are protected by the recv_list_lock. - * Traversals are protected by RCU. - * recv_list_lock also protects stream_count. - */ - struct cds_list_head recv_list; /* RCU list. */ - uint32_t stream_count; - pthread_mutex_t recv_list_lock; - - /* - * Flag checked and exchanged with uatomic_cmpxchg to tell the - * viewer-side if new streams got added since the last check. - */ - unsigned long new_streams; - - /* - * Node in the global session hash table. - */ - struct lttng_ht_node_u64 session_n; - /* - * Member of the session list in struct relay_viewer_session. - * Updates are protected by the relay_viewer_session - * session_list_lock. Traversals are protected by RCU. - */ - struct cds_list_head viewer_session_node; - struct lttng_trace_chunk *current_trace_chunk; - struct lttng_trace_chunk *pending_closure_trace_chunk; - /* - * Prevent live viewers from taking of copy of the chunk - * while new chunk has a temporary directory name. - */ - bool ongoing_rotation; - struct lttng_directory_handle *output_directory; - struct rcu_head rcu_node; /* For call_rcu teardown. */ -}; - -struct relay_session *session_create(const char *session_name, - const char *hostname, const char *base_path, - uint32_t live_timer, - bool snapshot, - const lttng_uuid sessiond_uuid, - const uint64_t *id_sessiond, - const uint64_t *current_chunk_id, - const time_t *creation_time, - uint32_t major, - uint32_t minor, - bool session_name_contains_creation_timestamp); -struct relay_session *session_get_by_id(uint64_t id); -bool session_get(struct relay_session *session); -void session_put(struct relay_session *session); - -int session_close(struct relay_session *session); -int session_abort(struct relay_session *session); - -bool session_has_ongoing_rotation(const struct relay_session *session); - -void print_sessions(void); - -#endif /* _SESSION_H */ diff --git a/src/bin/lttng-relayd/session.hpp b/src/bin/lttng-relayd/session.hpp new file mode 100644 index 000000000..9c61b942b --- /dev/null +++ b/src/bin/lttng-relayd/session.hpp @@ -0,0 +1,163 @@ +#ifndef _SESSION_H +#define _SESSION_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/* + * Represents a session for the relay point of view + */ +struct relay_session { + /* + * This session id is generated by the relay daemon to guarantee + * its uniqueness even when serving multiple session daemons. + * It is used to match a set of streams to their session. + */ + uint64_t id; + /* + * ID of the session in the session daemon's domain. + * This information is only provided by 2.11+ peers. + */ + LTTNG_OPTIONAL(uint64_t) id_sessiond; + /* + * Only provided by 2.11+ peers. However, the UUID is set to 'nil' in + * the other cases. + */ + lttng_uuid sessiond_uuid; + /* + * Contains the creation time on the session daemon's end for 2.11+ + * peers. Otherwise, this contains the session creation time on the + * relay daemon's end. + */ + LTTNG_OPTIONAL(time_t) creation_time; + /* Must _not_ be empty for 2.4+ peers. */ + char session_name[LTTNG_NAME_MAX]; + char hostname[LTTNG_HOST_NAME_MAX]; + char base_path[LTTNG_PATH_MAX]; + /* + * Session output path relative to relayd's output path. + * Will be empty when interacting with peers < 2.11 since their + * streams' path are expressed relative to the relay daemon's + * output path. + */ + char output_path[LTTNG_PATH_MAX]; + uint32_t live_timer; + + /* Session in snapshot mode. */ + bool snapshot; + + /* + * Session has no back reference to its connection because it + * has a life-time that can be longer than the consumer connection's + * life-time; a reference can still be held by the viewer + * connection through the viewer streams. + */ + + struct urcu_ref ref; + + mutable pthread_mutex_t lock; + + /* major/minor version used for this session. */ + uint32_t major; + uint32_t minor; + + bool viewer_attached; + /* Tell if the session connection has been closed on the streaming side. */ + bool connection_closed; + + /* + * Tell if the session is currently living in a exiting relayd and + * should be cleaned forcefully without waiting for pending data or + * pending ctrl data. + */ + bool aborted; + + bool session_name_contains_creation_time; + /* Whether session has performed an explicit rotation. */ + bool has_rotated; + + /* Contains ctf_trace object of that session indexed by path name. */ + struct lttng_ht *ctf_traces_ht; + + /* + * This contains streams that are received on that connection. + * It's used to store them until we get the streams sent + * command. When this is received, we remove those streams from + * the list and publish them. + * + * Updates are protected by the recv_list_lock. + * Traversals are protected by RCU. + * recv_list_lock also protects stream_count. + */ + struct cds_list_head recv_list; /* RCU list. */ + uint32_t stream_count; + pthread_mutex_t recv_list_lock; + + /* + * Flag checked and exchanged with uatomic_cmpxchg to tell the + * viewer-side if new streams got added since the last check. + */ + unsigned long new_streams; + + /* + * Node in the global session hash table. + */ + struct lttng_ht_node_u64 session_n; + /* + * Member of the session list in struct relay_viewer_session. + * Updates are protected by the relay_viewer_session + * session_list_lock. Traversals are protected by RCU. + */ + struct cds_list_head viewer_session_node; + struct lttng_trace_chunk *current_trace_chunk; + struct lttng_trace_chunk *pending_closure_trace_chunk; + /* + * Prevent live viewers from taking of copy of the chunk + * while new chunk has a temporary directory name. + */ + bool ongoing_rotation; + struct lttng_directory_handle *output_directory; + struct rcu_head rcu_node; /* For call_rcu teardown. */ +}; + +struct relay_session *session_create(const char *session_name, + const char *hostname, const char *base_path, + uint32_t live_timer, + bool snapshot, + const lttng_uuid sessiond_uuid, + const uint64_t *id_sessiond, + const uint64_t *current_chunk_id, + const time_t *creation_time, + uint32_t major, + uint32_t minor, + bool session_name_contains_creation_timestamp); +struct relay_session *session_get_by_id(uint64_t id); +bool session_get(struct relay_session *session); +void session_put(struct relay_session *session); + +int session_close(struct relay_session *session); +int session_abort(struct relay_session *session); + +bool session_has_ongoing_rotation(const struct relay_session *session); + +void print_sessions(void); + +#endif /* _SESSION_H */ diff --git a/src/bin/lttng-relayd/sessiond-trace-chunks.cpp b/src/bin/lttng-relayd/sessiond-trace-chunks.cpp index 18ef586d0..0a5c44825 100644 --- a/src/bin/lttng-relayd/sessiond-trace-chunks.cpp +++ b/src/bin/lttng-relayd/sessiond-trace-chunks.cpp @@ -5,17 +5,17 @@ * */ -#include "sessiond-trace-chunks.h" +#include "sessiond-trace-chunks.hpp" #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/src/bin/lttng-relayd/sessiond-trace-chunks.h b/src/bin/lttng-relayd/sessiond-trace-chunks.h deleted file mode 100644 index 2c771d809..000000000 --- a/src/bin/lttng-relayd/sessiond-trace-chunks.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2019 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef SESSIOND_TRACE_CHUNK_REGISTRY_H -#define SESSIOND_TRACE_CHUNK_REGISTRY_H - -#include -#include -#include - -/* - * A session trace chunk registry allows the relay daemon to share trace chunks - * used by different "relay sessions" when they were created for the same - * user-visible session daemon session. Tracing multiple domains (e.g. ust and - * kernel) results in per-domain relay sessions being created. - * - * Sharing trace chunks, and their output directory more specifically, is - * essential to properly implement session rotations. The sharing of output - * directory handles allows directory renames to be performed once and without - * races that would stem from from multiple renames. - */ -struct sessiond_trace_chunk_registry; - -struct sessiond_trace_chunk_registry * -sessiond_trace_chunk_registry_create(void); - -void sessiond_trace_chunk_registry_destroy( - struct sessiond_trace_chunk_registry *sessiond_registry); - -int sessiond_trace_chunk_registry_session_created( - struct sessiond_trace_chunk_registry *sessiond_registry, - const lttng_uuid sessiond_uuid); - -int sessiond_trace_chunk_registry_session_destroyed( - struct sessiond_trace_chunk_registry *sessiond_registry, - const lttng_uuid sessiond_uuid); - -struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk( - struct sessiond_trace_chunk_registry *sessiond_registry, - const lttng_uuid sessiond_uuid, uint64_t session_id, - struct lttng_trace_chunk *chunk); - -struct lttng_trace_chunk * -sessiond_trace_chunk_registry_get_anonymous_chunk( - struct sessiond_trace_chunk_registry *sessiond_registry, - const lttng_uuid sessiond_uuid, - uint64_t session_id); - -struct lttng_trace_chunk * -sessiond_trace_chunk_registry_get_chunk( - struct sessiond_trace_chunk_registry *sessiond_registry, - const lttng_uuid sessiond_uuid, - uint64_t session_id, uint64_t chunk_id); - -int sessiond_trace_chunk_registry_chunk_exists( - struct sessiond_trace_chunk_registry *sessiond_registry, - const lttng_uuid sessiond_uuid, - uint64_t session_id, uint64_t chunk_id, bool *chunk_exists); - -#endif /* SESSIOND_TRACE_CHUNK_REGISTRY_H */ diff --git a/src/bin/lttng-relayd/sessiond-trace-chunks.hpp b/src/bin/lttng-relayd/sessiond-trace-chunks.hpp new file mode 100644 index 000000000..2e494292a --- /dev/null +++ b/src/bin/lttng-relayd/sessiond-trace-chunks.hpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2019 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef SESSIOND_TRACE_CHUNK_REGISTRY_H +#define SESSIOND_TRACE_CHUNK_REGISTRY_H + +#include +#include +#include + +/* + * A session trace chunk registry allows the relay daemon to share trace chunks + * used by different "relay sessions" when they were created for the same + * user-visible session daemon session. Tracing multiple domains (e.g. ust and + * kernel) results in per-domain relay sessions being created. + * + * Sharing trace chunks, and their output directory more specifically, is + * essential to properly implement session rotations. The sharing of output + * directory handles allows directory renames to be performed once and without + * races that would stem from from multiple renames. + */ +struct sessiond_trace_chunk_registry; + +struct sessiond_trace_chunk_registry * +sessiond_trace_chunk_registry_create(void); + +void sessiond_trace_chunk_registry_destroy( + struct sessiond_trace_chunk_registry *sessiond_registry); + +int sessiond_trace_chunk_registry_session_created( + struct sessiond_trace_chunk_registry *sessiond_registry, + const lttng_uuid sessiond_uuid); + +int sessiond_trace_chunk_registry_session_destroyed( + struct sessiond_trace_chunk_registry *sessiond_registry, + const lttng_uuid sessiond_uuid); + +struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk( + struct sessiond_trace_chunk_registry *sessiond_registry, + const lttng_uuid sessiond_uuid, uint64_t session_id, + struct lttng_trace_chunk *chunk); + +struct lttng_trace_chunk * +sessiond_trace_chunk_registry_get_anonymous_chunk( + struct sessiond_trace_chunk_registry *sessiond_registry, + const lttng_uuid sessiond_uuid, + uint64_t session_id); + +struct lttng_trace_chunk * +sessiond_trace_chunk_registry_get_chunk( + struct sessiond_trace_chunk_registry *sessiond_registry, + const lttng_uuid sessiond_uuid, + uint64_t session_id, uint64_t chunk_id); + +int sessiond_trace_chunk_registry_chunk_exists( + struct sessiond_trace_chunk_registry *sessiond_registry, + const lttng_uuid sessiond_uuid, + uint64_t session_id, uint64_t chunk_id, bool *chunk_exists); + +#endif /* SESSIOND_TRACE_CHUNK_REGISTRY_H */ diff --git a/src/bin/lttng-relayd/stream.cpp b/src/bin/lttng-relayd/stream.cpp index 65a8ce11a..aba160bfa 100644 --- a/src/bin/lttng-relayd/stream.cpp +++ b/src/bin/lttng-relayd/stream.cpp @@ -10,18 +10,18 @@ #define _LGPL_SOURCE #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -#include "lttng-relayd.h" -#include "index.h" -#include "stream.h" -#include "viewer-stream.h" +#include "lttng-relayd.hpp" +#include "index.hpp" +#include "stream.hpp" +#include "viewer-stream.hpp" #include #include diff --git a/src/bin/lttng-relayd/stream.h b/src/bin/lttng-relayd/stream.h deleted file mode 100644 index c64b18045..000000000 --- a/src/bin/lttng-relayd/stream.h +++ /dev/null @@ -1,220 +0,0 @@ -#ifndef _STREAM_H -#define _STREAM_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "session.h" -#include "tracefile-array.h" - -struct lttcomm_relayd_index; - -struct relay_stream_rotation { - /* - * Indicates if the stream's data and index have been rotated. A - * rotation is considered completed when both rotations have occurred. - */ - bool data_rotated; - bool index_rotated; - /* - * Packet sequence number of the first packet of the new trace chunk to - * which the stream is rotating. - */ - uint64_t packet_seq_num; - /* - * Monotonically increasing previous network sequence number of first - * data packet of the new trace chunk to which the stream is rotating. - */ - uint64_t prev_data_net_seq; - struct lttng_trace_chunk *next_trace_chunk; -}; - -/* - * Represents a stream in the relay - */ -struct relay_stream { - uint64_t stream_handle; - - struct urcu_ref ref; - /* Back reference to trace. Protected by refcount on trace object. */ - struct ctf_trace *trace; - - /* - * To protect from concurrent read/update. The viewer stream - * lock nests inside the stream lock. The stream lock nests - * inside the ctf_trace lock. - */ - pthread_mutex_t lock; - /* previous data sequence number written to disk. */ - uint64_t prev_data_seq; - /* previous index sequence number written to disk. */ - uint64_t prev_index_seq; - /* seq num to encounter before closing. */ - uint64_t last_net_seq_num; - - struct fs_handle *file; - /* index file on which to write the index data. */ - struct lttng_index_file *index_file; - - char *path_name; - char *channel_name; - - /* On-disk circular buffer of tracefiles. */ - uint64_t tracefile_size; - uint64_t tracefile_size_current; - /* Max number of trace files for this stream. */ - uint64_t tracefile_count; - /* - * Index of the currently active file for this stream's on-disk - * ring buffer. - */ - uint64_t tracefile_current_index; - /* - * Indicates that the on-disk buffer has wrapped around. Stream - * files shall be unlinked before being opened after this has occurred. - */ - bool tracefile_wrapped_around; - - /* - * Position in the tracefile where we have the full index also on disk. - */ - uint64_t pos_after_last_complete_data_index; - - /* - * Counts the number of received indexes. The "tag" associated - * with an index is taken before incrementing this seqcount. - * Therefore, the sequence tag associated with the last index - * received is always index_received_seqcount - 1. - */ - uint64_t index_received_seqcount; - - /* - * Packet sequence number of the last received packet index. - * Only populated when interacting with CTF_INDEX 1.1+. - */ - LTTNG_OPTIONAL(uint64_t) received_packet_seq_num; - - /* - * Tracefile array is an index of the stream trace files, - * indexed by position. It allows keeping track of the oldest - * available indexes when overwriting trace files in tracefile - * rotation. - */ - struct tracefile_array *tfa; - - bool closed; /* Stream is closed. */ - bool close_requested; /* Close command has been received. */ - - /* - * Counts number of indexes in indexes_ht. Redundant info. - * Protected by stream lock. - */ - int indexes_in_flight; - struct lttng_ht *indexes_ht; - - /* - * If the stream is inactive, this field is updated with the - * live beacon timestamp end, when it is active, this - * field == -1ULL. - */ - uint64_t beacon_ts_end; - - /* CTF stream ID, -1ULL when unset (first packet not received yet). */ - uint64_t ctf_stream_id; - - /* Indicate if the stream was initialized for a data pending command. */ - bool data_pending_check_done; - - /* Is this stream a metadata stream ? */ - bool is_metadata; - /* Amount of metadata received (bytes). */ - uint64_t metadata_received; - - /* - * Member of the stream list in struct ctf_trace. - * Updates are protected by the stream_list_lock. - * Traversals are protected by RCU. - */ - struct cds_list_head stream_node; - /* - * Temporary list belonging to the connection until all streams - * are received for that connection. - * Member of the stream recv list in the connection. - * Updates are protected by the stream_recv_list_lock. - * Traversals are protected by RCU. - */ - bool in_recv_list; - struct cds_list_head recv_node; - /* Protected by session lock. */ - bool published; - /* Notified viewer that no new metadata is available. */ - bool no_new_metadata_notified; - /* - * Node of stream within global stream hash table. - */ - struct lttng_ht_node_u64 node; - bool in_stream_ht; /* is stream in stream hash table. */ - struct rcu_head rcu_node; /* For call_rcu teardown. */ - /* - * The trace chunk to which the file currently being produced (if any) - * belongs. - * - * Note that a relay stream can have no output trace chunk. For - * instance, after a session stop followed by a session clear, - * streams will not have an output trace chunk until the session - * is resumed. - */ - struct lttng_trace_chunk *trace_chunk; - LTTNG_OPTIONAL(struct relay_stream_rotation) ongoing_rotation; - uint64_t completed_rotation_count; -}; - -struct relay_stream *stream_create(struct ctf_trace *trace, - uint64_t stream_handle, char *path_name, - char *channel_name, uint64_t tracefile_size, - uint64_t tracefile_count); - -struct relay_stream *stream_get_by_id(uint64_t stream_id); -bool stream_get(struct relay_stream *stream); -void stream_put(struct relay_stream *stream); -int stream_rotate_output_files(struct relay_session *session, - struct relay_stream *stream); -int stream_set_pending_rotation(struct relay_stream *stream, - struct lttng_trace_chunk *next_trace_chunk, - uint64_t rotation_sequence_number); -void try_stream_close(struct relay_stream *stream); -void stream_publish(struct relay_stream *stream); -int stream_init_packet(struct relay_stream *stream, size_t packet_size, - bool *file_rotated); -int stream_write(struct relay_stream *stream, - const struct lttng_buffer_view *packet, size_t padding_len); -/* Called after the reception of a complete data packet. */ -int stream_update_index(struct relay_stream *stream, uint64_t net_seq_num, - bool rotate_index, bool *flushed, uint64_t total_size); -int stream_complete_packet(struct relay_stream *stream, - size_t packet_total_size, uint64_t sequence_number, - bool index_flushed); -/* Index info is in host endianness. */ -int stream_add_index(struct relay_stream *stream, - const struct lttcomm_relayd_index *index_info); -int stream_reset_file(struct relay_stream *stream); - -void print_relay_streams(void); - -#endif /* _STREAM_H */ diff --git a/src/bin/lttng-relayd/stream.hpp b/src/bin/lttng-relayd/stream.hpp new file mode 100644 index 000000000..6e09c5571 --- /dev/null +++ b/src/bin/lttng-relayd/stream.hpp @@ -0,0 +1,220 @@ +#ifndef _STREAM_H +#define _STREAM_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "session.hpp" +#include "tracefile-array.hpp" + +struct lttcomm_relayd_index; + +struct relay_stream_rotation { + /* + * Indicates if the stream's data and index have been rotated. A + * rotation is considered completed when both rotations have occurred. + */ + bool data_rotated; + bool index_rotated; + /* + * Packet sequence number of the first packet of the new trace chunk to + * which the stream is rotating. + */ + uint64_t packet_seq_num; + /* + * Monotonically increasing previous network sequence number of first + * data packet of the new trace chunk to which the stream is rotating. + */ + uint64_t prev_data_net_seq; + struct lttng_trace_chunk *next_trace_chunk; +}; + +/* + * Represents a stream in the relay + */ +struct relay_stream { + uint64_t stream_handle; + + struct urcu_ref ref; + /* Back reference to trace. Protected by refcount on trace object. */ + struct ctf_trace *trace; + + /* + * To protect from concurrent read/update. The viewer stream + * lock nests inside the stream lock. The stream lock nests + * inside the ctf_trace lock. + */ + pthread_mutex_t lock; + /* previous data sequence number written to disk. */ + uint64_t prev_data_seq; + /* previous index sequence number written to disk. */ + uint64_t prev_index_seq; + /* seq num to encounter before closing. */ + uint64_t last_net_seq_num; + + struct fs_handle *file; + /* index file on which to write the index data. */ + struct lttng_index_file *index_file; + + char *path_name; + char *channel_name; + + /* On-disk circular buffer of tracefiles. */ + uint64_t tracefile_size; + uint64_t tracefile_size_current; + /* Max number of trace files for this stream. */ + uint64_t tracefile_count; + /* + * Index of the currently active file for this stream's on-disk + * ring buffer. + */ + uint64_t tracefile_current_index; + /* + * Indicates that the on-disk buffer has wrapped around. Stream + * files shall be unlinked before being opened after this has occurred. + */ + bool tracefile_wrapped_around; + + /* + * Position in the tracefile where we have the full index also on disk. + */ + uint64_t pos_after_last_complete_data_index; + + /* + * Counts the number of received indexes. The "tag" associated + * with an index is taken before incrementing this seqcount. + * Therefore, the sequence tag associated with the last index + * received is always index_received_seqcount - 1. + */ + uint64_t index_received_seqcount; + + /* + * Packet sequence number of the last received packet index. + * Only populated when interacting with CTF_INDEX 1.1+. + */ + LTTNG_OPTIONAL(uint64_t) received_packet_seq_num; + + /* + * Tracefile array is an index of the stream trace files, + * indexed by position. It allows keeping track of the oldest + * available indexes when overwriting trace files in tracefile + * rotation. + */ + struct tracefile_array *tfa; + + bool closed; /* Stream is closed. */ + bool close_requested; /* Close command has been received. */ + + /* + * Counts number of indexes in indexes_ht. Redundant info. + * Protected by stream lock. + */ + int indexes_in_flight; + struct lttng_ht *indexes_ht; + + /* + * If the stream is inactive, this field is updated with the + * live beacon timestamp end, when it is active, this + * field == -1ULL. + */ + uint64_t beacon_ts_end; + + /* CTF stream ID, -1ULL when unset (first packet not received yet). */ + uint64_t ctf_stream_id; + + /* Indicate if the stream was initialized for a data pending command. */ + bool data_pending_check_done; + + /* Is this stream a metadata stream ? */ + bool is_metadata; + /* Amount of metadata received (bytes). */ + uint64_t metadata_received; + + /* + * Member of the stream list in struct ctf_trace. + * Updates are protected by the stream_list_lock. + * Traversals are protected by RCU. + */ + struct cds_list_head stream_node; + /* + * Temporary list belonging to the connection until all streams + * are received for that connection. + * Member of the stream recv list in the connection. + * Updates are protected by the stream_recv_list_lock. + * Traversals are protected by RCU. + */ + bool in_recv_list; + struct cds_list_head recv_node; + /* Protected by session lock. */ + bool published; + /* Notified viewer that no new metadata is available. */ + bool no_new_metadata_notified; + /* + * Node of stream within global stream hash table. + */ + struct lttng_ht_node_u64 node; + bool in_stream_ht; /* is stream in stream hash table. */ + struct rcu_head rcu_node; /* For call_rcu teardown. */ + /* + * The trace chunk to which the file currently being produced (if any) + * belongs. + * + * Note that a relay stream can have no output trace chunk. For + * instance, after a session stop followed by a session clear, + * streams will not have an output trace chunk until the session + * is resumed. + */ + struct lttng_trace_chunk *trace_chunk; + LTTNG_OPTIONAL(struct relay_stream_rotation) ongoing_rotation; + uint64_t completed_rotation_count; +}; + +struct relay_stream *stream_create(struct ctf_trace *trace, + uint64_t stream_handle, char *path_name, + char *channel_name, uint64_t tracefile_size, + uint64_t tracefile_count); + +struct relay_stream *stream_get_by_id(uint64_t stream_id); +bool stream_get(struct relay_stream *stream); +void stream_put(struct relay_stream *stream); +int stream_rotate_output_files(struct relay_session *session, + struct relay_stream *stream); +int stream_set_pending_rotation(struct relay_stream *stream, + struct lttng_trace_chunk *next_trace_chunk, + uint64_t rotation_sequence_number); +void try_stream_close(struct relay_stream *stream); +void stream_publish(struct relay_stream *stream); +int stream_init_packet(struct relay_stream *stream, size_t packet_size, + bool *file_rotated); +int stream_write(struct relay_stream *stream, + const struct lttng_buffer_view *packet, size_t padding_len); +/* Called after the reception of a complete data packet. */ +int stream_update_index(struct relay_stream *stream, uint64_t net_seq_num, + bool rotate_index, bool *flushed, uint64_t total_size); +int stream_complete_packet(struct relay_stream *stream, + size_t packet_total_size, uint64_t sequence_number, + bool index_flushed); +/* Index info is in host endianness. */ +int stream_add_index(struct relay_stream *stream, + const struct lttcomm_relayd_index *index_info); +int stream_reset_file(struct relay_stream *stream); + +void print_relay_streams(void); + +#endif /* _STREAM_H */ diff --git a/src/bin/lttng-relayd/tcp_keep_alive.cpp b/src/bin/lttng-relayd/tcp_keep_alive.cpp index c52a55ffb..885b2a6a5 100644 --- a/src/bin/lttng-relayd/tcp_keep_alive.cpp +++ b/src/bin/lttng-relayd/tcp_keep_alive.cpp @@ -11,12 +11,12 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include "tcp_keep_alive.h" +#include "tcp_keep_alive.hpp" #define SOLARIS_IDLE_TIME_MIN_S 10 #define SOLARIS_IDLE_TIME_MAX_S 864000 /* 10 days */ diff --git a/src/bin/lttng-relayd/tcp_keep_alive.h b/src/bin/lttng-relayd/tcp_keep_alive.h deleted file mode 100644 index 223602835..000000000 --- a/src/bin/lttng-relayd/tcp_keep_alive.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2017 Jonathan Rajotte - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef RELAYD_TCP_KEEP_ALIVE_H -#define RELAYD_TCP_KEEP_ALIVE_H - -#include - -int socket_apply_keep_alive_config(int socket_fd); - -#endif /* RELAYD_TCP_KEEP_ALIVE_H */ diff --git a/src/bin/lttng-relayd/tcp_keep_alive.hpp b/src/bin/lttng-relayd/tcp_keep_alive.hpp new file mode 100644 index 000000000..840730f60 --- /dev/null +++ b/src/bin/lttng-relayd/tcp_keep_alive.hpp @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2017 Jonathan Rajotte + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef RELAYD_TCP_KEEP_ALIVE_H +#define RELAYD_TCP_KEEP_ALIVE_H + +#include + +int socket_apply_keep_alive_config(int socket_fd); + +#endif /* RELAYD_TCP_KEEP_ALIVE_H */ diff --git a/src/bin/lttng-relayd/testpoint.h b/src/bin/lttng-relayd/testpoint.h deleted file mode 100644 index f58836a96..000000000 --- a/src/bin/lttng-relayd/testpoint.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef RELAYD_TESTPOINT_H -#define RELAYD_TESTPOINT_H - -/* - * Copyright (C) 2012 Christian Babeux - * Copyright (C) 2014 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include - -/* Testpoints, internal use only */ -TESTPOINT_DECL(relayd_thread_dispatcher); -TESTPOINT_DECL(relayd_thread_worker); -TESTPOINT_DECL(relayd_thread_listener); -TESTPOINT_DECL(relayd_thread_live_dispatcher); -TESTPOINT_DECL(relayd_thread_live_worker); -TESTPOINT_DECL(relayd_thread_live_listener); - -#endif /* SESSIOND_TESTPOINT_H */ diff --git a/src/bin/lttng-relayd/testpoint.hpp b/src/bin/lttng-relayd/testpoint.hpp new file mode 100644 index 000000000..84fb4a868 --- /dev/null +++ b/src/bin/lttng-relayd/testpoint.hpp @@ -0,0 +1,22 @@ +#ifndef RELAYD_TESTPOINT_H +#define RELAYD_TESTPOINT_H + +/* + * Copyright (C) 2012 Christian Babeux + * Copyright (C) 2014 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include + +/* Testpoints, internal use only */ +TESTPOINT_DECL(relayd_thread_dispatcher); +TESTPOINT_DECL(relayd_thread_worker); +TESTPOINT_DECL(relayd_thread_listener); +TESTPOINT_DECL(relayd_thread_live_dispatcher); +TESTPOINT_DECL(relayd_thread_live_worker); +TESTPOINT_DECL(relayd_thread_live_listener); + +#endif /* SESSIOND_TESTPOINT_H */ diff --git a/src/bin/lttng-relayd/tracefile-array.cpp b/src/bin/lttng-relayd/tracefile-array.cpp index 05012b642..8b1b533d5 100644 --- a/src/bin/lttng-relayd/tracefile-array.cpp +++ b/src/bin/lttng-relayd/tracefile-array.cpp @@ -6,11 +6,11 @@ */ #define _LGPL_SOURCE -#include -#include -#include +#include +#include +#include -#include "tracefile-array.h" +#include "tracefile-array.hpp" struct tracefile_array *tracefile_array_create(size_t count) { diff --git a/src/bin/lttng-relayd/tracefile-array.h b/src/bin/lttng-relayd/tracefile-array.h deleted file mode 100644 index 09c425fad..000000000 --- a/src/bin/lttng-relayd/tracefile-array.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef _TRACEFILE_ARRAY_H -#define _TRACEFILE_ARRAY_H - -/* - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include -#include -#include - -struct tracefile { - /* Per-tracefile head/tail seq. */ - uint64_t seq_head; /* Newest seqcount. Inclusive. */ - uint64_t seq_tail; /* Oldest seqcount. Inclusive. */ -}; - -enum tracefile_rotate_type { - TRACEFILE_ROTATE_READ, - TRACEFILE_ROTATE_WRITE, -}; - -/* - * Represents an array of trace files in a stream. - * head is the most recent file/trace packet. - * tail is the oldest file/trace packet. - * - * There are two heads: a "read" head and a "write" head. The "write" head is - * the position of the newest data file. The "read" head position is only moved - * forward when the index is received. - * - * The viewer uses the "read" head position as upper bound, which - * ensures it never attempts to open a non-existing index file. - */ -struct tracefile_array { - struct tracefile *tf; - size_t count; - - /* Current head/tail files. */ - uint64_t file_head_read; - uint64_t file_head_write; - uint64_t file_tail; - - /* Overall head/tail seq for the entire array. Inclusive. */ - uint64_t seq_head; - uint64_t seq_tail; -}; - -struct tracefile_array *tracefile_array_create(size_t count); -void tracefile_array_destroy(struct tracefile_array *tfa); - -void tracefile_array_file_rotate(struct tracefile_array *tfa, enum tracefile_rotate_type type); -void tracefile_array_commit_seq(struct tracefile_array *tfa, - uint64_t new_seq_head); -void tracefile_array_reset(struct tracefile_array *tfa); - -uint64_t tracefile_array_get_read_file_index_head(struct tracefile_array *tfa); -/* May return -1ULL in the case where we have not received any indexes yet. */ -uint64_t tracefile_array_get_seq_head(struct tracefile_array *tfa); - -uint64_t tracefile_array_get_file_index_tail(struct tracefile_array *tfa); -/* May return -1ULL in the case where we have not received any indexes yet. */ -uint64_t tracefile_array_get_seq_tail(struct tracefile_array *tfa); - -bool tracefile_array_seq_in_file(struct tracefile_array *tfa, - uint64_t file_index, uint64_t seq); - -#endif /* _STREAM_H */ diff --git a/src/bin/lttng-relayd/tracefile-array.hpp b/src/bin/lttng-relayd/tracefile-array.hpp new file mode 100644 index 000000000..09c425fad --- /dev/null +++ b/src/bin/lttng-relayd/tracefile-array.hpp @@ -0,0 +1,72 @@ +#ifndef _TRACEFILE_ARRAY_H +#define _TRACEFILE_ARRAY_H + +/* + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include +#include +#include + +struct tracefile { + /* Per-tracefile head/tail seq. */ + uint64_t seq_head; /* Newest seqcount. Inclusive. */ + uint64_t seq_tail; /* Oldest seqcount. Inclusive. */ +}; + +enum tracefile_rotate_type { + TRACEFILE_ROTATE_READ, + TRACEFILE_ROTATE_WRITE, +}; + +/* + * Represents an array of trace files in a stream. + * head is the most recent file/trace packet. + * tail is the oldest file/trace packet. + * + * There are two heads: a "read" head and a "write" head. The "write" head is + * the position of the newest data file. The "read" head position is only moved + * forward when the index is received. + * + * The viewer uses the "read" head position as upper bound, which + * ensures it never attempts to open a non-existing index file. + */ +struct tracefile_array { + struct tracefile *tf; + size_t count; + + /* Current head/tail files. */ + uint64_t file_head_read; + uint64_t file_head_write; + uint64_t file_tail; + + /* Overall head/tail seq for the entire array. Inclusive. */ + uint64_t seq_head; + uint64_t seq_tail; +}; + +struct tracefile_array *tracefile_array_create(size_t count); +void tracefile_array_destroy(struct tracefile_array *tfa); + +void tracefile_array_file_rotate(struct tracefile_array *tfa, enum tracefile_rotate_type type); +void tracefile_array_commit_seq(struct tracefile_array *tfa, + uint64_t new_seq_head); +void tracefile_array_reset(struct tracefile_array *tfa); + +uint64_t tracefile_array_get_read_file_index_head(struct tracefile_array *tfa); +/* May return -1ULL in the case where we have not received any indexes yet. */ +uint64_t tracefile_array_get_seq_head(struct tracefile_array *tfa); + +uint64_t tracefile_array_get_file_index_tail(struct tracefile_array *tfa); +/* May return -1ULL in the case where we have not received any indexes yet. */ +uint64_t tracefile_array_get_seq_tail(struct tracefile_array *tfa); + +bool tracefile_array_seq_in_file(struct tracefile_array *tfa, + uint64_t file_index, uint64_t seq); + +#endif /* _STREAM_H */ diff --git a/src/bin/lttng-relayd/utils.cpp b/src/bin/lttng-relayd/utils.cpp index 52ac19e8a..ccfc3a92a 100644 --- a/src/bin/lttng-relayd/utils.cpp +++ b/src/bin/lttng-relayd/utils.cpp @@ -11,13 +11,13 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include "lttng-relayd.h" -#include "utils.h" +#include "lttng-relayd.hpp" +#include "utils.hpp" static char *create_output_path_auto(const char *path_name) { diff --git a/src/bin/lttng-relayd/utils.h b/src/bin/lttng-relayd/utils.h deleted file mode 100644 index b02a791b1..000000000 --- a/src/bin/lttng-relayd/utils.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef RELAYD_UTILS_H -#define RELAYD_UTILS_H - -/* - * Copyright (C) 2012 Julien Desfossez - * Copyright (C) 2012 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -char *create_output_path(const char *path_name); - -#endif /* RELAYD_UTILS_H */ diff --git a/src/bin/lttng-relayd/utils.hpp b/src/bin/lttng-relayd/utils.hpp new file mode 100644 index 000000000..b02a791b1 --- /dev/null +++ b/src/bin/lttng-relayd/utils.hpp @@ -0,0 +1,15 @@ +#ifndef RELAYD_UTILS_H +#define RELAYD_UTILS_H + +/* + * Copyright (C) 2012 Julien Desfossez + * Copyright (C) 2012 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +char *create_output_path(const char *path_name); + +#endif /* RELAYD_UTILS_H */ diff --git a/src/bin/lttng-relayd/viewer-session.cpp b/src/bin/lttng-relayd/viewer-session.cpp index ac14dbff0..4529a21fa 100644 --- a/src/bin/lttng-relayd/viewer-session.cpp +++ b/src/bin/lttng-relayd/viewer-session.cpp @@ -8,15 +8,15 @@ */ #define _LGPL_SOURCE -#include +#include #include -#include "lttng-relayd.h" -#include "ctf-trace.h" -#include "session.h" -#include "viewer-session.h" -#include "viewer-stream.h" -#include "stream.h" +#include "lttng-relayd.hpp" +#include "ctf-trace.hpp" +#include "session.hpp" +#include "viewer-session.hpp" +#include "viewer-stream.hpp" +#include "stream.hpp" struct relay_viewer_session *viewer_session_create(void) { diff --git a/src/bin/lttng-relayd/viewer-session.h b/src/bin/lttng-relayd/viewer-session.h deleted file mode 100644 index f70daed7b..000000000 --- a/src/bin/lttng-relayd/viewer-session.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef _VIEWER_SESSION_H -#define _VIEWER_SESSION_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include "session.h" -#include "lttng-viewer-abi.h" - -struct relay_viewer_session { - /* - * Session list. Updates are protected by the session_list_lock. - * Traversals are protected by RCU. - * This list limits the design to having the sessions in at most - * one viewer session. - */ - struct cds_list_head session_list; /* RCU list. */ - pthread_mutex_t session_list_lock; /* Protects list updates. */ - /* - * The viewer session's current trace chunk is initially set, when - * a viewer attaches to the viewer session, to a copy the corresponding - * relay_session's current trace chunk. - * - * A live session always attempts to "catch-up" to the newest available - * trace chunk. This means that when a viewer reaches the end of a - * trace chunk, the viewer session may not transition to the "next" one: - * it jumps to the most recent trace chunk available (the one being - * produced by the relay_session). Hence, if the producer performs - * multiple rotations before a viewer completes the consumption of a - * trace chunk, it will skip over those "intermediary" trace chunks. - * - * A viewer session updates its current trace chunk when: - * 1) new viewer streams are created, - * 2) a new index is requested, - * 3) metadata is requested. - * - * Hence, as a general principle, the viewer session will reference the - * most recent trace chunk available _even if its streams do not point to - * it_. It indicates which trace chunk viewer streams should transition - * to when the end of their current trace chunk is reached. - * - * Note that a viewer session's trace chunk points to the session's - * output directory. The sub-directories in which the various stream files - * are created are considered as being a part of their name. - */ - struct lttng_trace_chunk *current_trace_chunk; -}; - -struct relay_viewer_session *viewer_session_create(void); -void viewer_session_destroy(struct relay_viewer_session *vsession); -void viewer_session_close(struct relay_viewer_session *vsession); - -enum lttng_viewer_attach_return_code viewer_session_attach( - struct relay_viewer_session *vsession, - struct relay_session *session); -int viewer_session_is_attached(struct relay_viewer_session *vsession, - struct relay_session *session); -void viewer_session_close_one_session(struct relay_viewer_session *vsession, - struct relay_session *session); -int viewer_session_set_trace_chunk_copy(struct relay_viewer_session *vsession, - struct lttng_trace_chunk *relay_session_trace_chunk); - -#endif /* _VIEWER_SESSION_H */ diff --git a/src/bin/lttng-relayd/viewer-session.hpp b/src/bin/lttng-relayd/viewer-session.hpp new file mode 100644 index 000000000..65ad3e11a --- /dev/null +++ b/src/bin/lttng-relayd/viewer-session.hpp @@ -0,0 +1,78 @@ +#ifndef _VIEWER_SESSION_H +#define _VIEWER_SESSION_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "session.hpp" +#include "lttng-viewer-abi.hpp" + +struct relay_viewer_session { + /* + * Session list. Updates are protected by the session_list_lock. + * Traversals are protected by RCU. + * This list limits the design to having the sessions in at most + * one viewer session. + */ + struct cds_list_head session_list; /* RCU list. */ + pthread_mutex_t session_list_lock; /* Protects list updates. */ + /* + * The viewer session's current trace chunk is initially set, when + * a viewer attaches to the viewer session, to a copy the corresponding + * relay_session's current trace chunk. + * + * A live session always attempts to "catch-up" to the newest available + * trace chunk. This means that when a viewer reaches the end of a + * trace chunk, the viewer session may not transition to the "next" one: + * it jumps to the most recent trace chunk available (the one being + * produced by the relay_session). Hence, if the producer performs + * multiple rotations before a viewer completes the consumption of a + * trace chunk, it will skip over those "intermediary" trace chunks. + * + * A viewer session updates its current trace chunk when: + * 1) new viewer streams are created, + * 2) a new index is requested, + * 3) metadata is requested. + * + * Hence, as a general principle, the viewer session will reference the + * most recent trace chunk available _even if its streams do not point to + * it_. It indicates which trace chunk viewer streams should transition + * to when the end of their current trace chunk is reached. + * + * Note that a viewer session's trace chunk points to the session's + * output directory. The sub-directories in which the various stream files + * are created are considered as being a part of their name. + */ + struct lttng_trace_chunk *current_trace_chunk; +}; + +struct relay_viewer_session *viewer_session_create(void); +void viewer_session_destroy(struct relay_viewer_session *vsession); +void viewer_session_close(struct relay_viewer_session *vsession); + +enum lttng_viewer_attach_return_code viewer_session_attach( + struct relay_viewer_session *vsession, + struct relay_session *session); +int viewer_session_is_attached(struct relay_viewer_session *vsession, + struct relay_session *session); +void viewer_session_close_one_session(struct relay_viewer_session *vsession, + struct relay_session *session); +int viewer_session_set_trace_chunk_copy(struct relay_viewer_session *vsession, + struct lttng_trace_chunk *relay_session_trace_chunk); + +#endif /* _VIEWER_SESSION_H */ diff --git a/src/bin/lttng-relayd/viewer-stream.cpp b/src/bin/lttng-relayd/viewer-stream.cpp index 69671bd7a..fa447d45b 100644 --- a/src/bin/lttng-relayd/viewer-stream.cpp +++ b/src/bin/lttng-relayd/viewer-stream.cpp @@ -8,17 +8,17 @@ */ #define _LGPL_SOURCE -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include -#include "lttng-relayd.h" -#include "viewer-stream.h" +#include "lttng-relayd.hpp" +#include "viewer-stream.hpp" static void viewer_stream_release_composite_objects(struct relay_viewer_stream *vstream) { diff --git a/src/bin/lttng-relayd/viewer-stream.h b/src/bin/lttng-relayd/viewer-stream.h deleted file mode 100644 index e7d733b9e..000000000 --- a/src/bin/lttng-relayd/viewer-stream.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef _VIEWER_STREAM_H -#define _VIEWER_STREAM_H - -/* - * Copyright (C) 2013 Julien Desfossez - * Copyright (C) 2013 David Goulet - * Copyright (C) 2015 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include -#include - -#include - -#include "ctf-trace.h" -#include "lttng-viewer-abi.h" -#include "stream.h" - -struct relay_stream; - -/* - * The viewer stream's lifetime is the intersection of their viewer connection's - * lifetime and the duration during which at least: - * a) their input source is still active - * b) they still have data left to send to the client. - * - * This means that both the sessiond/consumerd connection or the viewer - * connection may tear down (and unpublish) a relay_viewer_stream. - * - * Viewer stream updates are protected by their associated stream's lock. - */ -struct relay_viewer_stream { - struct urcu_ref ref; - - /* Back ref to stream. */ - struct relay_stream *stream; - - struct { - struct fs_handle *handle; - struct lttng_trace_chunk *trace_chunk; - } stream_file; - /* index file from which to read the index data. */ - struct lttng_index_file *index_file; - /* - * Last seen rotation count in stream. - * - * Sampled on every change to the viewer stream trace chunk, - * this allows the live server to determine if it saw the latest - * rotation that occurred on the receiving end. - */ - uint64_t last_seen_rotation_count; - - char *path_name; - char *channel_name; - - uint64_t current_tracefile_id; - - /* - * Counts the number of sent indexes. The "tag" associated - * with an index to send is the current index_received_seqcount, - * because we increment index_received_seqcount after sending - * each index. This index_received_seqcount counter can also be - * updated when catching up with the producer. - */ - uint64_t index_sent_seqcount; - - /* Indicates if this stream has been sent to a viewer client. */ - bool sent_flag; - /* For metadata stream, how much metadata has been sent. */ - uint64_t metadata_sent; - - struct lttng_ht_node_u64 stream_n; - struct rcu_head rcu_node; -}; - -struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, - struct lttng_trace_chunk *viewer_trace_chunk, - enum lttng_viewer_seek seek_t); - -struct relay_viewer_stream *viewer_stream_get_by_id(uint64_t id); -bool viewer_stream_get(struct relay_viewer_stream *vstream); -void viewer_stream_put(struct relay_viewer_stream *vstream); -int viewer_stream_rotate(struct relay_viewer_stream *vstream); -bool viewer_stream_is_tracefile_seq_readable(struct relay_viewer_stream *vstream, - uint64_t seq); -void print_viewer_streams(void); -void viewer_stream_close_files(struct relay_viewer_stream *vstream); -void viewer_stream_sync_tracefile_array_tail(struct relay_viewer_stream *vstream); - -#endif /* _VIEWER_STREAM_H */ diff --git a/src/bin/lttng-relayd/viewer-stream.hpp b/src/bin/lttng-relayd/viewer-stream.hpp new file mode 100644 index 000000000..42bdc1e20 --- /dev/null +++ b/src/bin/lttng-relayd/viewer-stream.hpp @@ -0,0 +1,94 @@ +#ifndef _VIEWER_STREAM_H +#define _VIEWER_STREAM_H + +/* + * Copyright (C) 2013 Julien Desfossez + * Copyright (C) 2013 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include +#include + +#include + +#include "ctf-trace.hpp" +#include "lttng-viewer-abi.hpp" +#include "stream.hpp" + +struct relay_stream; + +/* + * The viewer stream's lifetime is the intersection of their viewer connection's + * lifetime and the duration during which at least: + * a) their input source is still active + * b) they still have data left to send to the client. + * + * This means that both the sessiond/consumerd connection or the viewer + * connection may tear down (and unpublish) a relay_viewer_stream. + * + * Viewer stream updates are protected by their associated stream's lock. + */ +struct relay_viewer_stream { + struct urcu_ref ref; + + /* Back ref to stream. */ + struct relay_stream *stream; + + struct { + struct fs_handle *handle; + struct lttng_trace_chunk *trace_chunk; + } stream_file; + /* index file from which to read the index data. */ + struct lttng_index_file *index_file; + /* + * Last seen rotation count in stream. + * + * Sampled on every change to the viewer stream trace chunk, + * this allows the live server to determine if it saw the latest + * rotation that occurred on the receiving end. + */ + uint64_t last_seen_rotation_count; + + char *path_name; + char *channel_name; + + uint64_t current_tracefile_id; + + /* + * Counts the number of sent indexes. The "tag" associated + * with an index to send is the current index_received_seqcount, + * because we increment index_received_seqcount after sending + * each index. This index_received_seqcount counter can also be + * updated when catching up with the producer. + */ + uint64_t index_sent_seqcount; + + /* Indicates if this stream has been sent to a viewer client. */ + bool sent_flag; + /* For metadata stream, how much metadata has been sent. */ + uint64_t metadata_sent; + + struct lttng_ht_node_u64 stream_n; + struct rcu_head rcu_node; +}; + +struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, + struct lttng_trace_chunk *viewer_trace_chunk, + enum lttng_viewer_seek seek_t); + +struct relay_viewer_stream *viewer_stream_get_by_id(uint64_t id); +bool viewer_stream_get(struct relay_viewer_stream *vstream); +void viewer_stream_put(struct relay_viewer_stream *vstream); +int viewer_stream_rotate(struct relay_viewer_stream *vstream); +bool viewer_stream_is_tracefile_seq_readable(struct relay_viewer_stream *vstream, + uint64_t seq); +void print_viewer_streams(void); +void viewer_stream_close_files(struct relay_viewer_stream *vstream); +void viewer_stream_sync_tracefile_array_tail(struct relay_viewer_stream *vstream); + +#endif /* _VIEWER_STREAM_H */ diff --git a/src/bin/lttng-sessiond/Makefile.am b/src/bin/lttng-sessiond/Makefile.am index 96a20a4dd..13fdb714e 100644 --- a/src/bin/lttng-sessiond/Makefile.am +++ b/src/bin/lttng-sessiond/Makefile.am @@ -9,61 +9,61 @@ endif noinst_LTLIBRARIES = liblttng-sessiond-common.la -liblttng_sessiond_common_la_SOURCES = utils.cpp utils.h \ - trace-kernel.cpp trace-kernel.h \ - kernel.cpp kernel.h \ - ust-app.h ust-sigbus.h trace-ust.h notify-apps.h \ - lttng-ust-ctl.h lttng-ust-abi.h lttng-ust-error.h \ - ust-ctl-internal.h ust-abi-internal.h ust-error-internal.h \ - ust-registry.h \ - condition-internal.cpp condition-internal.h \ - context.cpp context.h \ - channel.cpp channel.h \ - event.cpp event.h \ - consumer.cpp consumer.h \ - session.cpp session.h \ - modprobe.cpp modprobe.h kern-modules.h \ - fd-limit.cpp fd-limit.h \ - kernel-consumer.cpp kernel-consumer.h \ - consumer.h \ - health-sessiond.h \ - cmd.cpp cmd.h \ - buffer-registry.cpp buffer-registry.h \ - testpoint.h \ - snapshot.cpp snapshot.h \ - agent.cpp agent.h \ - save.h save.cpp \ - lttng-syscall.h lttng-syscall.cpp \ - notification-thread.h notification-thread.cpp \ - notification-thread-internal.h \ - notification-thread-commands.h notification-thread-commands.cpp \ - notification-thread-events.h notification-thread-events.cpp \ - sessiond-config.h sessiond-config.cpp \ - rotate.h rotate.cpp \ - rotation-thread.h rotation-thread.cpp \ - timer.cpp timer.h \ +liblttng_sessiond_common_la_SOURCES = utils.cpp utils.hpp \ + trace-kernel.cpp trace-kernel.hpp \ + kernel.cpp kernel.hpp \ + ust-app.hpp ust-sigbus.hpp trace-ust.hpp notify-apps.hpp \ + lttng-ust-ctl.hpp lttng-ust-abi.hpp lttng-ust-error.hpp \ + ust-ctl-internal.hpp ust-abi-internal.hpp ust-error-internal.hpp \ + ust-registry.hpp \ + condition-internal.cpp condition-internal.hpp \ + context.cpp context.hpp \ + channel.cpp channel.hpp \ + event.cpp event.hpp \ + consumer.cpp consumer.hpp \ + session.cpp session.hpp \ + modprobe.cpp modprobe.hpp kern-modules.hpp \ + fd-limit.cpp fd-limit.hpp \ + kernel-consumer.cpp kernel-consumer.hpp \ + consumer.hpp \ + health-sessiond.hpp \ + cmd.cpp cmd.hpp \ + buffer-registry.cpp buffer-registry.hpp \ + testpoint.hpp \ + snapshot.cpp snapshot.hpp \ + agent.cpp agent.hpp \ + save.hpp save.cpp \ + lttng-syscall.hpp lttng-syscall.cpp \ + notification-thread.hpp notification-thread.cpp \ + notification-thread-internal.hpp \ + notification-thread-commands.hpp notification-thread-commands.cpp \ + notification-thread-events.hpp notification-thread-events.cpp \ + sessiond-config.hpp sessiond-config.cpp \ + rotate.hpp rotate.cpp \ + rotation-thread.hpp rotation-thread.cpp \ + timer.cpp timer.hpp \ globals.cpp \ thread-utils.cpp \ process-utils.cpp \ - thread.cpp thread.h \ + thread.cpp thread.hpp \ health.cpp \ - client.cpp client.h \ - dispatch.cpp dispatch.h \ - register.cpp register.h \ - manage-apps.cpp manage-apps.h \ - manage-kernel.cpp manage-kernel.h \ - manage-consumer.cpp manage-consumer.h \ - clear.cpp clear.h \ - tracker.cpp tracker.h \ - event-notifier-error-accounting.cpp event-notifier-error-accounting.h \ - action-executor.cpp action-executor.h\ + client.cpp client.hpp \ + dispatch.cpp dispatch.hpp \ + register.cpp register.hpp \ + manage-apps.cpp manage-apps.hpp \ + manage-kernel.cpp manage-kernel.hpp \ + manage-consumer.cpp manage-consumer.hpp \ + clear.cpp clear.hpp \ + tracker.cpp tracker.hpp \ + event-notifier-error-accounting.cpp event-notifier-error-accounting.hpp \ + action-executor.cpp action-executor.hpp\ trigger-error-query.cpp if HAVE_LIBLTTNG_UST_CTL liblttng_sessiond_common_la_SOURCES += trace-ust.cpp ust-registry.cpp ust-app.cpp \ - ust-consumer.cpp ust-consumer.h notify-apps.cpp \ - ust-metadata.cpp ust-clock.h agent-thread.cpp agent-thread.h \ - ust-field-utils.h ust-field-utils.cpp \ + ust-consumer.cpp ust-consumer.hpp notify-apps.cpp \ + ust-metadata.cpp ust-clock.hpp agent-thread.cpp agent-thread.hpp \ + ust-field-utils.hpp ust-field-utils.cpp \ ust-sigbus.cpp endif @@ -87,7 +87,7 @@ endif bin_PROGRAMS = lttng-sessiond -lttng_sessiond_SOURCES = lttng-sessiond.h main.cpp +lttng_sessiond_SOURCES = lttng-sessiond.hpp main.cpp lttng_sessiond_LDFLAGS = -rdynamic diff --git a/src/bin/lttng-sessiond/action-executor.cpp b/src/bin/lttng-sessiond/action-executor.cpp index e2eeed451..f43716c63 100644 --- a/src/bin/lttng-sessiond/action-executor.cpp +++ b/src/bin/lttng-sessiond/action-executor.cpp @@ -5,29 +5,29 @@ * */ -#include "action-executor.h" -#include "cmd.h" -#include "health-sessiond.h" -#include "lttng-sessiond.h" -#include "notification-thread-internal.h" -#include "session.h" -#include "thread.h" -#include -#include -#include -#include -#include +#include "action-executor.hpp" +#include "cmd.hpp" +#include "health-sessiond.hpp" +#include "lttng-sessiond.hpp" +#include "notification-thread-internal.hpp" +#include "session.hpp" +#include "thread.hpp" +#include +#include +#include +#include +#include #include -#include +#include #include #include #include #include #include #include -#include +#include #include -#include +#include #include #include #include diff --git a/src/bin/lttng-sessiond/action-executor.h b/src/bin/lttng-sessiond/action-executor.h deleted file mode 100644 index 85d5931fe..000000000 --- a/src/bin/lttng-sessiond/action-executor.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2020 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef ACTION_EXECUTOR_H -#define ACTION_EXECUTOR_H - -struct action_executor; -struct notification_thread_handle; -struct lttng_evaluation; -struct lttng_trigger; -struct notification_client_list; -struct lttng_credentials; - -enum action_executor_status { - ACTION_EXECUTOR_STATUS_OK, - ACTION_EXECUTOR_STATUS_OVERFLOW, - ACTION_EXECUTOR_STATUS_ERROR, - ACTION_EXECUTOR_STATUS_INVALID, -}; - -struct action_executor *action_executor_create( - struct notification_thread_handle *handle); - -void action_executor_destroy(struct action_executor *executor); - -/* - * Enqueue a job on an action executor's work queue to perform the actions - * associated with a trigger. - * - * A reference to `trigger` is acquired. - * A reference to `list` is acquired. - * - * This function assumes the ownership of the `evaluation` both on success and - * failure: the caller should no longer access it once the function returns. - */ -enum action_executor_status action_executor_enqueue_trigger( - struct action_executor *executor, - struct lttng_trigger *trigger, - struct lttng_evaluation *evaluation, - const struct lttng_credentials *object_creds, - struct notification_client_list *list); - -#endif /* ACTION_EXECUTOR_H */ diff --git a/src/bin/lttng-sessiond/action-executor.hpp b/src/bin/lttng-sessiond/action-executor.hpp new file mode 100644 index 000000000..85d5931fe --- /dev/null +++ b/src/bin/lttng-sessiond/action-executor.hpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2020 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef ACTION_EXECUTOR_H +#define ACTION_EXECUTOR_H + +struct action_executor; +struct notification_thread_handle; +struct lttng_evaluation; +struct lttng_trigger; +struct notification_client_list; +struct lttng_credentials; + +enum action_executor_status { + ACTION_EXECUTOR_STATUS_OK, + ACTION_EXECUTOR_STATUS_OVERFLOW, + ACTION_EXECUTOR_STATUS_ERROR, + ACTION_EXECUTOR_STATUS_INVALID, +}; + +struct action_executor *action_executor_create( + struct notification_thread_handle *handle); + +void action_executor_destroy(struct action_executor *executor); + +/* + * Enqueue a job on an action executor's work queue to perform the actions + * associated with a trigger. + * + * A reference to `trigger` is acquired. + * A reference to `list` is acquired. + * + * This function assumes the ownership of the `evaluation` both on success and + * failure: the caller should no longer access it once the function returns. + */ +enum action_executor_status action_executor_enqueue_trigger( + struct action_executor *executor, + struct lttng_trigger *trigger, + struct lttng_evaluation *evaluation, + const struct lttng_credentials *object_creds, + struct notification_client_list *list); + +#endif /* ACTION_EXECUTOR_H */ diff --git a/src/bin/lttng-sessiond/agent-thread.cpp b/src/bin/lttng-sessiond/agent-thread.cpp index 5e158b49b..77470b3ee 100644 --- a/src/bin/lttng-sessiond/agent-thread.cpp +++ b/src/bin/lttng-sessiond/agent-thread.cpp @@ -7,20 +7,20 @@ #define _LGPL_SOURCE -#include -#include -#include -#include - -#include - -#include "fd-limit.h" -#include "agent-thread.h" -#include "agent.h" -#include "lttng-sessiond.h" -#include "session.h" -#include "utils.h" -#include "thread.h" +#include +#include +#include +#include + +#include + +#include "fd-limit.hpp" +#include "agent-thread.hpp" +#include "agent.hpp" +#include "lttng-sessiond.hpp" +#include "session.hpp" +#include "utils.hpp" +#include "thread.hpp" struct thread_notifiers { struct lttng_pipe *quit_pipe; diff --git a/src/bin/lttng-sessiond/agent-thread.h b/src/bin/lttng-sessiond/agent-thread.h deleted file mode 100644 index d84ea6172..000000000 --- a/src/bin/lttng-sessiond/agent-thread.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2013 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include - -#ifndef LTTNG_SESSIOND_AGENT_THREAD_H -#define LTTNG_SESSIOND_AGENT_THREAD_H - -#ifdef HAVE_LIBLTTNG_UST_CTL - -bool launch_agent_management_thread(void); -bool agent_tracing_is_enabled(void); - -#else /* HAVE_LIBLTTNG_UST_CTL */ - -static inline -bool launch_agent_management_thread(void) -{ - return true; -} - -static inline -bool agent_tracing_is_enabled(void) -{ - return false; -} - -#endif /* HAVE_LIBLTTNG_UST_CTL */ - -#endif /* LTTNG_SESSIOND_AGENT_THREAD_H */ diff --git a/src/bin/lttng-sessiond/agent-thread.hpp b/src/bin/lttng-sessiond/agent-thread.hpp new file mode 100644 index 000000000..d84ea6172 --- /dev/null +++ b/src/bin/lttng-sessiond/agent-thread.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2013 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include + +#ifndef LTTNG_SESSIOND_AGENT_THREAD_H +#define LTTNG_SESSIOND_AGENT_THREAD_H + +#ifdef HAVE_LIBLTTNG_UST_CTL + +bool launch_agent_management_thread(void); +bool agent_tracing_is_enabled(void); + +#else /* HAVE_LIBLTTNG_UST_CTL */ + +static inline +bool launch_agent_management_thread(void) +{ + return true; +} + +static inline +bool agent_tracing_is_enabled(void) +{ + return false; +} + +#endif /* HAVE_LIBLTTNG_UST_CTL */ + +#endif /* LTTNG_SESSIOND_AGENT_THREAD_H */ diff --git a/src/bin/lttng-sessiond/agent.cpp b/src/bin/lttng-sessiond/agent.cpp index b0ac94b13..ed8a8d126 100644 --- a/src/bin/lttng-sessiond/agent.cpp +++ b/src/bin/lttng-sessiond/agent.cpp @@ -11,24 +11,24 @@ #include #include -#include +#include #include #include #include #include #include -#include -#include +#include +#include -#include -#include +#include +#include -#include +#include -#include "agent.h" -#include "ust-app.h" -#include "utils.h" -#include "common/error.h" +#include "agent.hpp" +#include "ust-app.hpp" +#include "utils.hpp" +#include "common/error.hpp" typedef enum lttng_event_rule_status (*event_rule_logging_get_name_pattern)( const struct lttng_event_rule *rule, const char **pattern); diff --git a/src/bin/lttng-sessiond/agent.h b/src/bin/lttng-sessiond/agent.h deleted file mode 100644 index b0a4fa863..000000000 --- a/src/bin/lttng-sessiond/agent.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2013 David Goulet - * Copyright (C) 2016 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef LTTNG_SESSIOND_AGENT_H -#define LTTNG_SESSIOND_AGENT_H - -#include - -#include -#include - -/* Agent protocol version that is verified during the agent registration. */ -#define AGENT_MAJOR_VERSION 2 -#define AGENT_MINOR_VERSION 0 - -/* - * Hash table that contains the agent app created upon registration indexed by - * socket. Global to the session daemon. - */ -extern struct lttng_ht *the_agent_apps_ht_by_sock; - -/* - * Hash table that contains the trigger agents by domain */ -extern struct lttng_ht *the_trigger_agents_ht_by_domain; - -struct agent_ht_key { - const char *name; - int loglevel_value; - enum lttng_loglevel_type loglevel_type; - const char *filter_expression; -}; - -/* - * Registration message payload from an agent application. The PID is used to - * find back the corresponding UST app object so both socket can be linked. - */ -struct agent_register_msg { - /* This maps to a lttng_domain_type. */ - uint32_t domain; - uint32_t pid; - uint32_t major_version; - uint32_t minor_version; -}; - -/* - * Agent application object created after a successful registration. This - * object is linked to its associated UST app by their PID through hash table - * lookups. - */ -struct agent_app { - /* - * PID sent during registration of an agent application. - */ - pid_t pid; - - /* Domain of the application. */ - enum lttng_domain_type domain; - - /* - * AGENT TCP socket that was created upon registration. - */ - struct lttcomm_sock *sock; - - /* Initialized with the AGENT sock value. */ - struct lttng_ht_node_ulong node; -}; - -/* - * Agent event representation. - * Accesses to this structure are protected by the session list lock. - */ -struct agent_event { - /* Name of the event. */ - char name[LTTNG_SYMBOL_NAME_LEN]; - int loglevel_value; - enum lttng_loglevel_type loglevel_type; - - /* - * Tells if the event is enabled or not on the agent. While this can be - * implicitly tested as a boolean, it is in fact a reference count and - * the AGENT_EVENT_IS_ENABLED macro should be used to prevent accidental - * comparisons to non-zero literals (e.g. '1'). - * - * Multiple triggers and events can map to the same agent event as it - * is merely a "filter" in front of a user space tracer enabler. - * - * This count is updated to ensure an event is only disabled when all - * matching enablers are disabled. - */ - unsigned int enabled_count; - - /* Hash table node of the agent domain object. */ - struct lttng_ht_node_str node; - - /* Filter associated with the event. NULL if none. */ - struct lttng_bytecode *filter; - char *filter_expression; - struct lttng_event_exclusion *exclusion; -}; - -#define AGENT_EVENT_IS_ENABLED(agent_event) (!!agent_event->enabled_count) - -/* - * Agent object containing events enabled/disabled for a given domain in a - * scope. The scope is typically a session, but can also be "global" in the - * context of event notifiers: see event_notifiers_find_agent(). - */ -struct agent { - /* - * This indicates if that domain is being used meaning if at least one - * event has been at some point in time added to it. This is used so when - * listing domains for a session, we can tell or not if the agent is - * actually enabled. - */ - unsigned int being_used:1; - - /* What domain this agent is. */ - enum lttng_domain_type domain; - - /* Contains event indexed by name. */ - struct lttng_ht *events; - - /* Application context list (struct agent_app_ctx). */ - struct cds_list_head app_ctx_list; - - /* Node used for the hash table indexed by domain type. */ - struct lttng_ht_node_u64 node; -}; - -/* Allocate agent apps hash table */ -int agent_app_ht_alloc(void); -/* Clean-up agent apps hash table */ -void agent_app_ht_clean(void); - -/* Initialize an already allocated agent domain. */ -int agent_init(struct agent *agt); -struct agent *agent_create(enum lttng_domain_type domain); -void agent_destroy(struct agent *agt); -void agent_add(struct agent *agt, struct lttng_ht *ht); - -/* Agent event API. */ -struct agent_event *agent_create_event(const char *name, - enum lttng_loglevel_type loglevel_type, int loglevel_value, - struct lttng_bytecode *filter, - char *filter_expression); -void agent_add_event(struct agent_event *event, struct agent *agt); - -struct agent_event *agent_find_event(const char *name, - enum lttng_loglevel_type loglevel_type, - int loglevel_value, - const char *filter_expression, - struct agent *agt); -void agent_find_events_by_name(const char *name, struct agent *agt, - struct lttng_ht_iter* iter); -void agent_event_next_duplicate(const char *name, - struct agent *agt, struct lttng_ht_iter* iter); -void agent_delete_event(struct agent_event *event, struct agent *agt); -void agent_destroy_event(struct agent_event *event); - -/* Agent context API.*/ -int agent_enable_context(const struct lttng_event_context *ctx, - enum lttng_domain_type domain); -int agent_add_context(const struct lttng_event_context *ctx, - struct agent *agt); - -/* Agent app API. */ -struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain, - struct lttcomm_sock *sock); -void agent_add_app(struct agent_app *app); -void agent_delete_app(struct agent_app *app); -struct agent_app *agent_find_app_by_sock(int sock); -void agent_destroy_app(struct agent_app *app); -void agent_destroy_app_by_sock(int sock); -int agent_send_registration_done(struct agent_app *app); - -/* Agent action API */ -int agent_enable_event(struct agent_event *event, - enum lttng_domain_type domain); -int agent_disable_event(struct agent_event *event, - enum lttng_domain_type domain); -void agent_update(const struct agent *agt, const struct agent_app *app); -int agent_list_events(struct lttng_event **events, - enum lttng_domain_type domain); - -struct agent_event *agent_find_event_by_trigger( - const struct lttng_trigger *trigger, struct agent *agt); - -/* Global event notifier per-domain agents. */ -struct agent *agent_find_by_event_notifier_domain( - enum lttng_domain_type domain_type); -void agent_by_event_notifier_domain_ht_destroy(void); -int agent_by_event_notifier_domain_ht_create(void); - -#endif /* LTTNG_SESSIOND_AGENT_H */ diff --git a/src/bin/lttng-sessiond/agent.hpp b/src/bin/lttng-sessiond/agent.hpp new file mode 100644 index 000000000..2ad42c3f4 --- /dev/null +++ b/src/bin/lttng-sessiond/agent.hpp @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2013 David Goulet + * Copyright (C) 2016 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef LTTNG_SESSIOND_AGENT_H +#define LTTNG_SESSIOND_AGENT_H + +#include + +#include +#include + +/* Agent protocol version that is verified during the agent registration. */ +#define AGENT_MAJOR_VERSION 2 +#define AGENT_MINOR_VERSION 0 + +/* + * Hash table that contains the agent app created upon registration indexed by + * socket. Global to the session daemon. + */ +extern struct lttng_ht *the_agent_apps_ht_by_sock; + +/* + * Hash table that contains the trigger agents by domain */ +extern struct lttng_ht *the_trigger_agents_ht_by_domain; + +struct agent_ht_key { + const char *name; + int loglevel_value; + enum lttng_loglevel_type loglevel_type; + const char *filter_expression; +}; + +/* + * Registration message payload from an agent application. The PID is used to + * find back the corresponding UST app object so both socket can be linked. + */ +struct agent_register_msg { + /* This maps to a lttng_domain_type. */ + uint32_t domain; + uint32_t pid; + uint32_t major_version; + uint32_t minor_version; +}; + +/* + * Agent application object created after a successful registration. This + * object is linked to its associated UST app by their PID through hash table + * lookups. + */ +struct agent_app { + /* + * PID sent during registration of an agent application. + */ + pid_t pid; + + /* Domain of the application. */ + enum lttng_domain_type domain; + + /* + * AGENT TCP socket that was created upon registration. + */ + struct lttcomm_sock *sock; + + /* Initialized with the AGENT sock value. */ + struct lttng_ht_node_ulong node; +}; + +/* + * Agent event representation. + * Accesses to this structure are protected by the session list lock. + */ +struct agent_event { + /* Name of the event. */ + char name[LTTNG_SYMBOL_NAME_LEN]; + int loglevel_value; + enum lttng_loglevel_type loglevel_type; + + /* + * Tells if the event is enabled or not on the agent. While this can be + * implicitly tested as a boolean, it is in fact a reference count and + * the AGENT_EVENT_IS_ENABLED macro should be used to prevent accidental + * comparisons to non-zero literals (e.g. '1'). + * + * Multiple triggers and events can map to the same agent event as it + * is merely a "filter" in front of a user space tracer enabler. + * + * This count is updated to ensure an event is only disabled when all + * matching enablers are disabled. + */ + unsigned int enabled_count; + + /* Hash table node of the agent domain object. */ + struct lttng_ht_node_str node; + + /* Filter associated with the event. NULL if none. */ + struct lttng_bytecode *filter; + char *filter_expression; + struct lttng_event_exclusion *exclusion; +}; + +#define AGENT_EVENT_IS_ENABLED(agent_event) (!!agent_event->enabled_count) + +/* + * Agent object containing events enabled/disabled for a given domain in a + * scope. The scope is typically a session, but can also be "global" in the + * context of event notifiers: see event_notifiers_find_agent(). + */ +struct agent { + /* + * This indicates if that domain is being used meaning if at least one + * event has been at some point in time added to it. This is used so when + * listing domains for a session, we can tell or not if the agent is + * actually enabled. + */ + unsigned int being_used:1; + + /* What domain this agent is. */ + enum lttng_domain_type domain; + + /* Contains event indexed by name. */ + struct lttng_ht *events; + + /* Application context list (struct agent_app_ctx). */ + struct cds_list_head app_ctx_list; + + /* Node used for the hash table indexed by domain type. */ + struct lttng_ht_node_u64 node; +}; + +/* Allocate agent apps hash table */ +int agent_app_ht_alloc(void); +/* Clean-up agent apps hash table */ +void agent_app_ht_clean(void); + +/* Initialize an already allocated agent domain. */ +int agent_init(struct agent *agt); +struct agent *agent_create(enum lttng_domain_type domain); +void agent_destroy(struct agent *agt); +void agent_add(struct agent *agt, struct lttng_ht *ht); + +/* Agent event API. */ +struct agent_event *agent_create_event(const char *name, + enum lttng_loglevel_type loglevel_type, int loglevel_value, + struct lttng_bytecode *filter, + char *filter_expression); +void agent_add_event(struct agent_event *event, struct agent *agt); + +struct agent_event *agent_find_event(const char *name, + enum lttng_loglevel_type loglevel_type, + int loglevel_value, + const char *filter_expression, + struct agent *agt); +void agent_find_events_by_name(const char *name, struct agent *agt, + struct lttng_ht_iter* iter); +void agent_event_next_duplicate(const char *name, + struct agent *agt, struct lttng_ht_iter* iter); +void agent_delete_event(struct agent_event *event, struct agent *agt); +void agent_destroy_event(struct agent_event *event); + +/* Agent context API.*/ +int agent_enable_context(const struct lttng_event_context *ctx, + enum lttng_domain_type domain); +int agent_add_context(const struct lttng_event_context *ctx, + struct agent *agt); + +/* Agent app API. */ +struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain, + struct lttcomm_sock *sock); +void agent_add_app(struct agent_app *app); +void agent_delete_app(struct agent_app *app); +struct agent_app *agent_find_app_by_sock(int sock); +void agent_destroy_app(struct agent_app *app); +void agent_destroy_app_by_sock(int sock); +int agent_send_registration_done(struct agent_app *app); + +/* Agent action API */ +int agent_enable_event(struct agent_event *event, + enum lttng_domain_type domain); +int agent_disable_event(struct agent_event *event, + enum lttng_domain_type domain); +void agent_update(const struct agent *agt, const struct agent_app *app); +int agent_list_events(struct lttng_event **events, + enum lttng_domain_type domain); + +struct agent_event *agent_find_event_by_trigger( + const struct lttng_trigger *trigger, struct agent *agt); + +/* Global event notifier per-domain agents. */ +struct agent *agent_find_by_event_notifier_domain( + enum lttng_domain_type domain_type); +void agent_by_event_notifier_domain_ht_destroy(void); +int agent_by_event_notifier_domain_ht_create(void); + +#endif /* LTTNG_SESSIOND_AGENT_H */ diff --git a/src/bin/lttng-sessiond/buffer-registry.cpp b/src/bin/lttng-sessiond/buffer-registry.cpp index 64e98333f..ca7830a38 100644 --- a/src/bin/lttng-sessiond/buffer-registry.cpp +++ b/src/bin/lttng-sessiond/buffer-registry.cpp @@ -8,15 +8,15 @@ #define _LGPL_SOURCE #include -#include -#include - -#include "buffer-registry.h" -#include "fd-limit.h" -#include "ust-consumer.h" -#include "lttng-ust-ctl.h" -#include "lttng-ust-error.h" -#include "utils.h" +#include +#include + +#include "buffer-registry.hpp" +#include "fd-limit.hpp" +#include "ust-consumer.hpp" +#include "lttng-ust-ctl.hpp" +#include "lttng-ust-error.hpp" +#include "utils.hpp" /* * Set in main.c during initialization process of the daemon. This contains diff --git a/src/bin/lttng-sessiond/buffer-registry.h b/src/bin/lttng-sessiond/buffer-registry.h deleted file mode 100644 index 440493d47..000000000 --- a/src/bin/lttng-sessiond/buffer-registry.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2013 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef LTTNG_BUFFER_REGISTRY_H -#define LTTNG_BUFFER_REGISTRY_H - -#include -#include - -#include -#include - -#include "consumer.h" -#include "lttng-ust-ctl.h" -#include "ust-registry.h" - -struct buffer_reg_stream { - struct cds_list_head lnode; - union { - /* Original object data that MUST be copied over. */ - struct lttng_ust_abi_object_data *ust; - } obj; -}; - -struct buffer_reg_channel { - /* This key is the same as a tracing channel key. */ - uint32_t key; - /* Key of the channel on the consumer side. */ - uint64_t consumer_key; - /* Stream registry object of this channel registry. */ - struct cds_list_head streams; - /* Total number of stream in the list. */ - uint64_t stream_count; - /* Used to ensure mutual exclusion to the stream's list. */ - pthread_mutex_t stream_list_lock; - /* Node for hash table usage. */ - struct lttng_ht_node_u64 node; - /* Size of subbuffers in this channel. */ - size_t subbuf_size; - /* Number of subbuffers per stream. */ - size_t num_subbuf; - union { - /* Original object data that MUST be copied over. */ - struct lttng_ust_abi_object_data *ust; - } obj; -}; - -struct buffer_reg_session { - /* Registry per domain. */ - union { - struct ust_registry_session *ust; - } reg; - - /* Contains buffer registry channel indexed by tracing channel key. */ - struct lttng_ht *channels; -}; - -/* - * Registry object for per UID buffers. - */ -struct buffer_reg_uid { - /* - * Keys to match this object in a hash table. The following three variables - * identify a unique per UID buffer registry. - */ - uint64_t session_id; /* Unique tracing session id. */ - int bits_per_long; /* ABI */ - uid_t uid; /* Owner. */ - - enum lttng_domain_type domain; - struct buffer_reg_session *registry; - - /* Indexed by session id. */ - struct lttng_ht_node_u64 node; - /* Node of a linked list used to teardown object at a destroy session. */ - struct cds_list_head lnode; - - char root_shm_path[PATH_MAX]; - char shm_path[PATH_MAX]; -}; - -/* - * Registry object for per PID buffers. - */ -struct buffer_reg_pid { - uint64_t session_id; - - struct buffer_reg_session *registry; - - /* Indexed by session id. */ - struct lttng_ht_node_u64 node; - - char root_shm_path[PATH_MAX]; - char shm_path[PATH_MAX]; -}; - -/* Buffer registry per UID. */ -void buffer_reg_init_uid_registry(void); -int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid, - enum lttng_domain_type domain, struct buffer_reg_uid **regp, - const char *root_shm_path, const char *shm_path); -void buffer_reg_uid_add(struct buffer_reg_uid *reg); -struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id, - uint32_t bits_per_long, uid_t uid); -void buffer_reg_uid_remove(struct buffer_reg_uid *regp); -void buffer_reg_uid_destroy(struct buffer_reg_uid *regp, - struct consumer_output *consumer); - -/* Buffer registry per PID. */ -void buffer_reg_init_pid_registry(void); -int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp, - const char *root_shm_path, const char *shm_path); -void buffer_reg_pid_add(struct buffer_reg_pid *reg); -struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id); -void buffer_reg_pid_remove(struct buffer_reg_pid *regp); -void buffer_reg_pid_destroy(struct buffer_reg_pid *regp); - -/* Channel */ -int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp); -void buffer_reg_channel_add(struct buffer_reg_session *session, - struct buffer_reg_channel *channel); -struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key, - struct buffer_reg_uid *reg); -void buffer_reg_channel_remove(struct buffer_reg_session *session, - struct buffer_reg_channel *regp); -void buffer_reg_channel_destroy(struct buffer_reg_channel *regp, - enum lttng_domain_type domain); - -/* Stream */ -int buffer_reg_stream_create(struct buffer_reg_stream **regp); -void buffer_reg_stream_add(struct buffer_reg_stream *stream, - struct buffer_reg_channel *channel); -void buffer_reg_stream_destroy(struct buffer_reg_stream *regp, - enum lttng_domain_type domain); - -/* Global registry. */ -void buffer_reg_destroy_registries(void); - -int buffer_reg_uid_consumer_channel_key( - struct cds_list_head *buffer_reg_uid_list, - uint64_t chan_key, uint64_t *consumer_chan_key); - -#endif /* LTTNG_BUFFER_REGISTRY_H */ diff --git a/src/bin/lttng-sessiond/buffer-registry.hpp b/src/bin/lttng-sessiond/buffer-registry.hpp new file mode 100644 index 000000000..a06be6010 --- /dev/null +++ b/src/bin/lttng-sessiond/buffer-registry.hpp @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2013 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef LTTNG_BUFFER_REGISTRY_H +#define LTTNG_BUFFER_REGISTRY_H + +#include +#include + +#include +#include + +#include "consumer.hpp" +#include "lttng-ust-ctl.hpp" +#include "ust-registry.hpp" + +struct buffer_reg_stream { + struct cds_list_head lnode; + union { + /* Original object data that MUST be copied over. */ + struct lttng_ust_abi_object_data *ust; + } obj; +}; + +struct buffer_reg_channel { + /* This key is the same as a tracing channel key. */ + uint32_t key; + /* Key of the channel on the consumer side. */ + uint64_t consumer_key; + /* Stream registry object of this channel registry. */ + struct cds_list_head streams; + /* Total number of stream in the list. */ + uint64_t stream_count; + /* Used to ensure mutual exclusion to the stream's list. */ + pthread_mutex_t stream_list_lock; + /* Node for hash table usage. */ + struct lttng_ht_node_u64 node; + /* Size of subbuffers in this channel. */ + size_t subbuf_size; + /* Number of subbuffers per stream. */ + size_t num_subbuf; + union { + /* Original object data that MUST be copied over. */ + struct lttng_ust_abi_object_data *ust; + } obj; +}; + +struct buffer_reg_session { + /* Registry per domain. */ + union { + struct ust_registry_session *ust; + } reg; + + /* Contains buffer registry channel indexed by tracing channel key. */ + struct lttng_ht *channels; +}; + +/* + * Registry object for per UID buffers. + */ +struct buffer_reg_uid { + /* + * Keys to match this object in a hash table. The following three variables + * identify a unique per UID buffer registry. + */ + uint64_t session_id; /* Unique tracing session id. */ + int bits_per_long; /* ABI */ + uid_t uid; /* Owner. */ + + enum lttng_domain_type domain; + struct buffer_reg_session *registry; + + /* Indexed by session id. */ + struct lttng_ht_node_u64 node; + /* Node of a linked list used to teardown object at a destroy session. */ + struct cds_list_head lnode; + + char root_shm_path[PATH_MAX]; + char shm_path[PATH_MAX]; +}; + +/* + * Registry object for per PID buffers. + */ +struct buffer_reg_pid { + uint64_t session_id; + + struct buffer_reg_session *registry; + + /* Indexed by session id. */ + struct lttng_ht_node_u64 node; + + char root_shm_path[PATH_MAX]; + char shm_path[PATH_MAX]; +}; + +/* Buffer registry per UID. */ +void buffer_reg_init_uid_registry(void); +int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid, + enum lttng_domain_type domain, struct buffer_reg_uid **regp, + const char *root_shm_path, const char *shm_path); +void buffer_reg_uid_add(struct buffer_reg_uid *reg); +struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id, + uint32_t bits_per_long, uid_t uid); +void buffer_reg_uid_remove(struct buffer_reg_uid *regp); +void buffer_reg_uid_destroy(struct buffer_reg_uid *regp, + struct consumer_output *consumer); + +/* Buffer registry per PID. */ +void buffer_reg_init_pid_registry(void); +int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp, + const char *root_shm_path, const char *shm_path); +void buffer_reg_pid_add(struct buffer_reg_pid *reg); +struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id); +void buffer_reg_pid_remove(struct buffer_reg_pid *regp); +void buffer_reg_pid_destroy(struct buffer_reg_pid *regp); + +/* Channel */ +int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp); +void buffer_reg_channel_add(struct buffer_reg_session *session, + struct buffer_reg_channel *channel); +struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key, + struct buffer_reg_uid *reg); +void buffer_reg_channel_remove(struct buffer_reg_session *session, + struct buffer_reg_channel *regp); +void buffer_reg_channel_destroy(struct buffer_reg_channel *regp, + enum lttng_domain_type domain); + +/* Stream */ +int buffer_reg_stream_create(struct buffer_reg_stream **regp); +void buffer_reg_stream_add(struct buffer_reg_stream *stream, + struct buffer_reg_channel *channel); +void buffer_reg_stream_destroy(struct buffer_reg_stream *regp, + enum lttng_domain_type domain); + +/* Global registry. */ +void buffer_reg_destroy_registries(void); + +int buffer_reg_uid_consumer_channel_key( + struct cds_list_head *buffer_reg_uid_list, + uint64_t chan_key, uint64_t *consumer_chan_key); + +#endif /* LTTNG_BUFFER_REGISTRY_H */ diff --git a/src/bin/lttng-sessiond/channel.cpp b/src/bin/lttng-sessiond/channel.cpp index c5b944d61..e3bb232fa 100644 --- a/src/bin/lttng-sessiond/channel.cpp +++ b/src/bin/lttng-sessiond/channel.cpp @@ -11,18 +11,18 @@ #include #include -#include -#include -#include - -#include "channel.h" -#include "lttng-sessiond.h" -#include "kernel.h" -#include "lttng-ust-ctl.h" -#include "lttng-ust-error.h" -#include "utils.h" -#include "ust-app.h" -#include "agent.h" +#include +#include +#include + +#include "channel.hpp" +#include "lttng-sessiond.hpp" +#include "kernel.hpp" +#include "lttng-ust-ctl.hpp" +#include "lttng-ust-error.hpp" +#include "utils.hpp" +#include "ust-app.hpp" +#include "agent.hpp" /* * Return allocated channel attributes. diff --git a/src/bin/lttng-sessiond/channel.h b/src/bin/lttng-sessiond/channel.h deleted file mode 100644 index fcc4d6b63..000000000 --- a/src/bin/lttng-sessiond/channel.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _LTT_CHANNEL_H -#define _LTT_CHANNEL_H - -#include - -#include "trace-kernel.h" -#include "trace-ust.h" - -int channel_kernel_disable(struct ltt_kernel_session *ksession, - char *channel_name); -enum lttng_error_code channel_kernel_enable(struct ltt_kernel_session *ksession, - struct ltt_kernel_channel *kchan); -enum lttng_error_code channel_kernel_create(struct ltt_kernel_session *ksession, - struct lttng_channel *chan, - int kernel_pipe); - -struct lttng_channel *channel_new_default_attr(int domain, - enum lttng_buffer_type type); -void channel_attr_destroy(struct lttng_channel *channel); - -enum lttng_error_code channel_ust_create(struct ltt_ust_session *usess, - struct lttng_channel *attr, enum lttng_buffer_type type); -enum lttng_error_code channel_ust_enable(struct ltt_ust_session *usess, - struct ltt_ust_channel *uchan); -int channel_ust_disable(struct ltt_ust_session *usess, - struct ltt_ust_channel *uchan); - -struct lttng_channel *trace_ust_channel_to_lttng_channel( - const struct ltt_ust_channel *uchan); - -#endif /* _LTT_CHANNEL_H */ diff --git a/src/bin/lttng-sessiond/channel.hpp b/src/bin/lttng-sessiond/channel.hpp new file mode 100644 index 000000000..342e30f78 --- /dev/null +++ b/src/bin/lttng-sessiond/channel.hpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _LTT_CHANNEL_H +#define _LTT_CHANNEL_H + +#include + +#include "trace-kernel.hpp" +#include "trace-ust.hpp" + +int channel_kernel_disable(struct ltt_kernel_session *ksession, + char *channel_name); +enum lttng_error_code channel_kernel_enable(struct ltt_kernel_session *ksession, + struct ltt_kernel_channel *kchan); +enum lttng_error_code channel_kernel_create(struct ltt_kernel_session *ksession, + struct lttng_channel *chan, + int kernel_pipe); + +struct lttng_channel *channel_new_default_attr(int domain, + enum lttng_buffer_type type); +void channel_attr_destroy(struct lttng_channel *channel); + +enum lttng_error_code channel_ust_create(struct ltt_ust_session *usess, + struct lttng_channel *attr, enum lttng_buffer_type type); +enum lttng_error_code channel_ust_enable(struct ltt_ust_session *usess, + struct ltt_ust_channel *uchan); +int channel_ust_disable(struct ltt_ust_session *usess, + struct ltt_ust_channel *uchan); + +struct lttng_channel *trace_ust_channel_to_lttng_channel( + const struct ltt_ust_channel *uchan); + +#endif /* _LTT_CHANNEL_H */ diff --git a/src/bin/lttng-sessiond/clear.cpp b/src/bin/lttng-sessiond/clear.cpp index a0817c2da..fcac76ffa 100644 --- a/src/bin/lttng-sessiond/clear.cpp +++ b/src/bin/lttng-sessiond/clear.cpp @@ -10,15 +10,15 @@ #include #include -#include -#include -#include - -#include "clear.h" -#include "session.h" -#include "ust-app.h" -#include "kernel.h" -#include "cmd.h" +#include +#include +#include + +#include "clear.hpp" +#include "session.hpp" +#include "ust-app.hpp" +#include "kernel.hpp" +#include "cmd.hpp" struct cmd_clear_session_reply_context { int reply_sock_fd; diff --git a/src/bin/lttng-sessiond/clear.h b/src/bin/lttng-sessiond/clear.h deleted file mode 100644 index e788ec7bb..000000000 --- a/src/bin/lttng-sessiond/clear.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2019 Jonathan Rajotte - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef CLEAR_H -#define CLEAR_H - -#include "session.h" - -int cmd_clear_session(struct ltt_session *session, int *sock_fd); - -#endif /* CLEAT_H */ diff --git a/src/bin/lttng-sessiond/clear.hpp b/src/bin/lttng-sessiond/clear.hpp new file mode 100644 index 000000000..aca20d35a --- /dev/null +++ b/src/bin/lttng-sessiond/clear.hpp @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2019 Jonathan Rajotte + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef CLEAR_H +#define CLEAR_H + +#include "session.hpp" + +int cmd_clear_session(struct ltt_session *session, int *sock_fd); + +#endif /* CLEAT_H */ diff --git a/src/bin/lttng-sessiond/client.cpp b/src/bin/lttng-sessiond/client.cpp index 4c1f6954b..cf3fd4424 100644 --- a/src/bin/lttng-sessiond/client.cpp +++ b/src/bin/lttng-sessiond/client.cpp @@ -7,25 +7,25 @@ * */ -#include "common/buffer-view.h" -#include "common/compat/socket.h" -#include "common/dynamic-array.h" -#include "common/dynamic-buffer.h" -#include "common/fd-handle.h" -#include "common/payload-view.h" -#include "common/payload.h" -#include "common/sessiond-comm/sessiond-comm.h" +#include "common/buffer-view.hpp" +#include "common/compat/socket.hpp" +#include "common/dynamic-array.hpp" +#include "common/dynamic-buffer.hpp" +#include "common/fd-handle.hpp" +#include "common/payload-view.hpp" +#include "common/payload.hpp" +#include "common/sessiond-comm/sessiond-comm.hpp" #include "lttng/lttng-error.h" #include "lttng/tracker.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -33,17 +33,17 @@ #include #include -#include "agent-thread.h" -#include "clear.h" -#include "client.h" -#include "cmd.h" -#include "health-sessiond.h" -#include "kernel.h" -#include "lttng-sessiond.h" -#include "manage-consumer.h" -#include "save.h" -#include "testpoint.h" -#include "utils.h" +#include "agent-thread.hpp" +#include "clear.hpp" +#include "client.hpp" +#include "cmd.hpp" +#include "health-sessiond.hpp" +#include "kernel.hpp" +#include "lttng-sessiond.hpp" +#include "manage-consumer.hpp" +#include "save.hpp" +#include "testpoint.hpp" +#include "utils.hpp" static bool is_root; diff --git a/src/bin/lttng-sessiond/client.h b/src/bin/lttng-sessiond/client.h deleted file mode 100644 index 0610d4509..000000000 --- a/src/bin/lttng-sessiond/client.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * Copyright (C) 2011 Mathieu Desnoyers - * Copyright (C) 2013 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef CLIENT_SESSIOND_H -#define CLIENT_SESSIOND_H - -#include "thread.h" - -struct lttng_thread *launch_client_thread(void); - -#endif /* CLIENT_SESSIOND_H */ diff --git a/src/bin/lttng-sessiond/client.hpp b/src/bin/lttng-sessiond/client.hpp new file mode 100644 index 000000000..49a454dfb --- /dev/null +++ b/src/bin/lttng-sessiond/client.hpp @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * Copyright (C) 2011 Mathieu Desnoyers + * Copyright (C) 2013 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef CLIENT_SESSIOND_H +#define CLIENT_SESSIOND_H + +#include "thread.hpp" + +struct lttng_thread *launch_client_thread(void); + +#endif /* CLIENT_SESSIOND_H */ diff --git a/src/bin/lttng-sessiond/cmd.cpp b/src/bin/lttng-sessiond/cmd.cpp index 3ed56f7b0..47c049b31 100644 --- a/src/bin/lttng-sessiond/cmd.cpp +++ b/src/bin/lttng-sessiond/cmd.cpp @@ -15,53 +15,61 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include +#include #include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "agent-thread.h" -#include "agent.h" -#include "buffer-registry.h" -#include "channel.h" -#include "cmd.h" -#include "consumer.h" -#include "event-notifier-error-accounting.h" -#include "event.h" -#include "health-sessiond.h" -#include "kernel-consumer.h" -#include "kernel.h" -#include "lttng-sessiond.h" -#include "lttng-syscall.h" -#include "notification-thread-commands.h" -#include "notification-thread.h" -#include "rotate.h" -#include "rotation-thread.h" -#include "session.h" -#include "timer.h" -#include "tracker.h" -#include "utils.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "agent-thread.hpp" +#include "agent.hpp" +#include "buffer-registry.hpp" +#include "channel.hpp" +#include "cmd.hpp" +#include "consumer.hpp" +#include "event-notifier-error-accounting.hpp" +#include "event.hpp" +#include "health-sessiond.hpp" +#include "kernel-consumer.hpp" +#include "kernel.hpp" +#include "lttng-sessiond.hpp" +#include "lttng-syscall.hpp" +#include "notification-thread-commands.hpp" +#include "notification-thread.hpp" +#include "rotate.hpp" +#include "rotation-thread.hpp" +#include "session.hpp" +#include "timer.hpp" +#include "tracker.hpp" +#include "utils.hpp" /* Sleep for 100ms between each check for the shm path's deletion. */ #define SESSION_DESTROY_SHM_PATH_CHECK_DELAY_US 100000 diff --git a/src/bin/lttng-sessiond/cmd.h b/src/bin/lttng-sessiond/cmd.h deleted file mode 100644 index 13d540e25..000000000 --- a/src/bin/lttng-sessiond/cmd.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (C) 2012 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef CMD_H -#define CMD_H - -#include "context.h" -#include "lttng-sessiond.h" -#include "lttng/tracker.h" -#include "session.h" -#include - -struct notification_thread_handle; -struct lttng_dynamic_buffer; - -/* - * A callback (and associated user data) that should be run after a command - * has been executed. No locks should be taken while executing this handler. - * - * The command's reply should not be sent until the handler has run and - * completed successfully. On failure, the handler's return code should - * be the only reply sent to the client. - */ -typedef enum lttng_error_code (*completion_handler_function)(void *); -struct cmd_completion_handler { - completion_handler_function run; - void *data; -}; - -/* - * Init the command subsystem. Must be called before using any of the functions - * above. This is called in the main() of the session daemon. - */ -void cmd_init(void); - -/* Session commands */ -enum lttng_error_code cmd_create_session(struct command_ctx *cmd_ctx, int sock, - struct lttng_session_descriptor **return_descriptor); -int cmd_destroy_session(struct ltt_session *session, - struct notification_thread_handle *notification_thread_handle, - int *sock_fd); - -/* Channel commands */ -int cmd_disable_channel(struct ltt_session *session, - enum lttng_domain_type domain, char *channel_name); -int cmd_enable_channel(struct command_ctx *cmd_ctx, int sock, int wpipe); - -/* Process attribute tracker commands */ -enum lttng_error_code cmd_process_attr_tracker_get_tracking_policy( - struct ltt_session *session, - enum lttng_domain_type domain, - enum lttng_process_attr process_attr, - enum lttng_tracking_policy *policy); -enum lttng_error_code cmd_process_attr_tracker_set_tracking_policy( - struct ltt_session *session, - enum lttng_domain_type domain, - enum lttng_process_attr process_attr, - enum lttng_tracking_policy policy); -enum lttng_error_code cmd_process_attr_tracker_inclusion_set_add_value( - struct ltt_session *session, - enum lttng_domain_type domain, - enum lttng_process_attr process_attr, - const struct process_attr_value *value); -enum lttng_error_code cmd_process_attr_tracker_inclusion_set_remove_value( - struct ltt_session *session, - enum lttng_domain_type domain, - enum lttng_process_attr process_attr, - const struct process_attr_value *value); -enum lttng_error_code cmd_process_attr_tracker_get_inclusion_set( - struct ltt_session *session, - enum lttng_domain_type domain, - enum lttng_process_attr process_attr, - struct lttng_process_attr_values **values); - -/* Event commands */ -int cmd_disable_event(struct command_ctx *cmd_ctx, - struct lttng_event *event, - char *filter_expression, - struct lttng_bytecode *filter, - struct lttng_event_exclusion *exclusion); -int cmd_add_context(struct command_ctx *cmd_ctx, - const struct lttng_event_context *event_context, - int kwpipe); -int cmd_set_filter(struct ltt_session *session, enum lttng_domain_type domain, - char *channel_name, struct lttng_event *event, - struct lttng_bytecode *bytecode); -int cmd_enable_event(struct command_ctx *cmd_ctx, - struct lttng_event *event, - char *filter_expression, - struct lttng_event_exclusion *exclusion, - struct lttng_bytecode *bytecode, - int wpipe); - -/* Trace session action commands */ -int cmd_start_trace(struct ltt_session *session); -int cmd_stop_trace(struct ltt_session *session); - -/* Consumer commands */ -int cmd_register_consumer(struct ltt_session *session, - enum lttng_domain_type domain, - const char *sock_path, struct consumer_data *cdata); -int cmd_set_consumer_uri(struct ltt_session *session, size_t nb_uri, - struct lttng_uri *uris); -int cmd_setup_relayd(struct ltt_session *session); - -/* Listing commands */ -ssize_t cmd_list_domains(struct ltt_session *session, - struct lttng_domain **domains); -enum lttng_error_code cmd_list_events(enum lttng_domain_type domain, - struct ltt_session *session, - char *channel_name, - struct lttng_payload *payload); -enum lttng_error_code cmd_list_channels(enum lttng_domain_type domain, - struct ltt_session *session, - struct lttng_payload *payload); -void cmd_list_lttng_sessions(struct lttng_session *sessions, - size_t session_count, uid_t uid, gid_t gid); -enum lttng_error_code cmd_list_tracepoint_fields(enum lttng_domain_type domain, - struct lttng_payload *reply); -enum lttng_error_code cmd_list_tracepoints(enum lttng_domain_type domain, - struct lttng_payload *reply_payload); -ssize_t cmd_snapshot_list_outputs(struct ltt_session *session, - struct lttng_snapshot_output **outputs); -enum lttng_error_code cmd_list_syscalls( - struct lttng_payload *reply_payload); - -int cmd_data_pending(struct ltt_session *session); - -/* Snapshot */ -int cmd_snapshot_add_output(struct ltt_session *session, - const struct lttng_snapshot_output *output, uint32_t *id); -int cmd_snapshot_del_output(struct ltt_session *session, - const struct lttng_snapshot_output *output); -int cmd_snapshot_record(struct ltt_session *session, - const struct lttng_snapshot_output *output, int wait); - -int cmd_set_session_shm_path(struct ltt_session *session, - const char *shm_path); -int cmd_regenerate_metadata(struct ltt_session *session); -int cmd_regenerate_statedump(struct ltt_session *session); - -enum lttng_error_code cmd_register_trigger( - const struct lttng_credentials *cmd_creds, - struct lttng_trigger *trigger, - bool is_anonymous_trigger, - struct notification_thread_handle *notification_thread_handle, - struct lttng_trigger **return_trigger); -enum lttng_error_code cmd_unregister_trigger( - const struct lttng_credentials *cmd_creds, - const struct lttng_trigger *trigger, - struct notification_thread_handle *notification_thread_handle); - -enum lttng_error_code cmd_list_triggers(struct command_ctx *cmd_ctx, - struct notification_thread_handle *notification_thread_handle, - struct lttng_triggers **return_triggers); -enum lttng_error_code cmd_execute_error_query(const struct lttng_credentials *cmd_creds, - const struct lttng_error_query *query, - struct lttng_error_query_results **_results, - struct notification_thread_handle *notification_thread); - -int cmd_rotate_session(struct ltt_session *session, - struct lttng_rotate_session_return *rotate_return, - bool quiet_rotation, - enum lttng_trace_chunk_command_type command); -int cmd_rotate_get_info(struct ltt_session *session, - struct lttng_rotation_get_info_return *info_return, - uint64_t rotate_id); -int cmd_rotation_set_schedule(struct ltt_session *session, - bool activate, enum lttng_rotation_schedule_type schedule_type, - uint64_t value, - struct notification_thread_handle *notification_thread_handle); - -const struct cmd_completion_handler *cmd_pop_completion_handler(void); -int start_kernel_session(struct ltt_kernel_session *ksess); -int stop_kernel_session(struct ltt_kernel_session *ksess); - -#endif /* CMD_H */ diff --git a/src/bin/lttng-sessiond/cmd.hpp b/src/bin/lttng-sessiond/cmd.hpp new file mode 100644 index 000000000..8727e741b --- /dev/null +++ b/src/bin/lttng-sessiond/cmd.hpp @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2012 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef CMD_H +#define CMD_H + +#include "context.hpp" +#include "lttng-sessiond.hpp" +#include "lttng/tracker.h" +#include "session.hpp" +#include + +struct notification_thread_handle; +struct lttng_dynamic_buffer; + +/* + * A callback (and associated user data) that should be run after a command + * has been executed. No locks should be taken while executing this handler. + * + * The command's reply should not be sent until the handler has run and + * completed successfully. On failure, the handler's return code should + * be the only reply sent to the client. + */ +typedef enum lttng_error_code (*completion_handler_function)(void *); +struct cmd_completion_handler { + completion_handler_function run; + void *data; +}; + +/* + * Init the command subsystem. Must be called before using any of the functions + * above. This is called in the main() of the session daemon. + */ +void cmd_init(void); + +/* Session commands */ +enum lttng_error_code cmd_create_session(struct command_ctx *cmd_ctx, int sock, + struct lttng_session_descriptor **return_descriptor); +int cmd_destroy_session(struct ltt_session *session, + struct notification_thread_handle *notification_thread_handle, + int *sock_fd); + +/* Channel commands */ +int cmd_disable_channel(struct ltt_session *session, + enum lttng_domain_type domain, char *channel_name); +int cmd_enable_channel(struct command_ctx *cmd_ctx, int sock, int wpipe); + +/* Process attribute tracker commands */ +enum lttng_error_code cmd_process_attr_tracker_get_tracking_policy( + struct ltt_session *session, + enum lttng_domain_type domain, + enum lttng_process_attr process_attr, + enum lttng_tracking_policy *policy); +enum lttng_error_code cmd_process_attr_tracker_set_tracking_policy( + struct ltt_session *session, + enum lttng_domain_type domain, + enum lttng_process_attr process_attr, + enum lttng_tracking_policy policy); +enum lttng_error_code cmd_process_attr_tracker_inclusion_set_add_value( + struct ltt_session *session, + enum lttng_domain_type domain, + enum lttng_process_attr process_attr, + const struct process_attr_value *value); +enum lttng_error_code cmd_process_attr_tracker_inclusion_set_remove_value( + struct ltt_session *session, + enum lttng_domain_type domain, + enum lttng_process_attr process_attr, + const struct process_attr_value *value); +enum lttng_error_code cmd_process_attr_tracker_get_inclusion_set( + struct ltt_session *session, + enum lttng_domain_type domain, + enum lttng_process_attr process_attr, + struct lttng_process_attr_values **values); + +/* Event commands */ +int cmd_disable_event(struct command_ctx *cmd_ctx, + struct lttng_event *event, + char *filter_expression, + struct lttng_bytecode *filter, + struct lttng_event_exclusion *exclusion); +int cmd_add_context(struct command_ctx *cmd_ctx, + const struct lttng_event_context *event_context, + int kwpipe); +int cmd_set_filter(struct ltt_session *session, enum lttng_domain_type domain, + char *channel_name, struct lttng_event *event, + struct lttng_bytecode *bytecode); +int cmd_enable_event(struct command_ctx *cmd_ctx, + struct lttng_event *event, + char *filter_expression, + struct lttng_event_exclusion *exclusion, + struct lttng_bytecode *bytecode, + int wpipe); + +/* Trace session action commands */ +int cmd_start_trace(struct ltt_session *session); +int cmd_stop_trace(struct ltt_session *session); + +/* Consumer commands */ +int cmd_register_consumer(struct ltt_session *session, + enum lttng_domain_type domain, + const char *sock_path, struct consumer_data *cdata); +int cmd_set_consumer_uri(struct ltt_session *session, size_t nb_uri, + struct lttng_uri *uris); +int cmd_setup_relayd(struct ltt_session *session); + +/* Listing commands */ +ssize_t cmd_list_domains(struct ltt_session *session, + struct lttng_domain **domains); +enum lttng_error_code cmd_list_events(enum lttng_domain_type domain, + struct ltt_session *session, + char *channel_name, + struct lttng_payload *payload); +enum lttng_error_code cmd_list_channels(enum lttng_domain_type domain, + struct ltt_session *session, + struct lttng_payload *payload); +void cmd_list_lttng_sessions(struct lttng_session *sessions, + size_t session_count, uid_t uid, gid_t gid); +enum lttng_error_code cmd_list_tracepoint_fields(enum lttng_domain_type domain, + struct lttng_payload *reply); +enum lttng_error_code cmd_list_tracepoints(enum lttng_domain_type domain, + struct lttng_payload *reply_payload); +ssize_t cmd_snapshot_list_outputs(struct ltt_session *session, + struct lttng_snapshot_output **outputs); +enum lttng_error_code cmd_list_syscalls( + struct lttng_payload *reply_payload); + +int cmd_data_pending(struct ltt_session *session); + +/* Snapshot */ +int cmd_snapshot_add_output(struct ltt_session *session, + const struct lttng_snapshot_output *output, uint32_t *id); +int cmd_snapshot_del_output(struct ltt_session *session, + const struct lttng_snapshot_output *output); +int cmd_snapshot_record(struct ltt_session *session, + const struct lttng_snapshot_output *output, int wait); + +int cmd_set_session_shm_path(struct ltt_session *session, + const char *shm_path); +int cmd_regenerate_metadata(struct ltt_session *session); +int cmd_regenerate_statedump(struct ltt_session *session); + +enum lttng_error_code cmd_register_trigger( + const struct lttng_credentials *cmd_creds, + struct lttng_trigger *trigger, + bool is_anonymous_trigger, + struct notification_thread_handle *notification_thread_handle, + struct lttng_trigger **return_trigger); +enum lttng_error_code cmd_unregister_trigger( + const struct lttng_credentials *cmd_creds, + const struct lttng_trigger *trigger, + struct notification_thread_handle *notification_thread_handle); + +enum lttng_error_code cmd_list_triggers(struct command_ctx *cmd_ctx, + struct notification_thread_handle *notification_thread_handle, + struct lttng_triggers **return_triggers); +enum lttng_error_code cmd_execute_error_query(const struct lttng_credentials *cmd_creds, + const struct lttng_error_query *query, + struct lttng_error_query_results **_results, + struct notification_thread_handle *notification_thread); + +int cmd_rotate_session(struct ltt_session *session, + struct lttng_rotate_session_return *rotate_return, + bool quiet_rotation, + enum lttng_trace_chunk_command_type command); +int cmd_rotate_get_info(struct ltt_session *session, + struct lttng_rotation_get_info_return *info_return, + uint64_t rotate_id); +int cmd_rotation_set_schedule(struct ltt_session *session, + bool activate, enum lttng_rotation_schedule_type schedule_type, + uint64_t value, + struct notification_thread_handle *notification_thread_handle); + +const struct cmd_completion_handler *cmd_pop_completion_handler(void); +int start_kernel_session(struct ltt_kernel_session *ksess); +int stop_kernel_session(struct ltt_kernel_session *ksess); + +#endif /* CMD_H */ diff --git a/src/bin/lttng-sessiond/condition-internal.cpp b/src/bin/lttng-sessiond/condition-internal.cpp index dd9c244b3..7daa53625 100644 --- a/src/bin/lttng-sessiond/condition-internal.cpp +++ b/src/bin/lttng-sessiond/condition-internal.cpp @@ -5,19 +5,19 @@ * */ -#include -#include +#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include -#include -#include "condition-internal.h" +#include +#include +#include "condition-internal.hpp" static unsigned long lttng_condition_buffer_usage_hash( diff --git a/src/bin/lttng-sessiond/condition-internal.h b/src/bin/lttng-sessiond/condition-internal.h deleted file mode 100644 index 49a074952..000000000 --- a/src/bin/lttng-sessiond/condition-internal.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2020 Francis Deslauriers - * - * SPDX-License-Identifier: LGPL-2.1-only - * - */ - -#ifndef LTTNG_SESSIOND_CONDITION_INTERNAL_H -#define LTTNG_SESSIOND_CONDITION_INTERNAL_H - -#include - -/* - * The lttng_condition hashing code is kept in this file (rather than - * condition.c) since it makes use of GPLv2 code (hashtable utils), which we - * don't want to link in liblttng-ctl. - */ -unsigned long lttng_condition_hash(const struct lttng_condition *condition); - -struct lttng_condition *lttng_condition_copy( - const struct lttng_condition *condition); - -#endif /* LTTNG_SESSIOND_CONDITION_INTERNAL_H */ diff --git a/src/bin/lttng-sessiond/condition-internal.hpp b/src/bin/lttng-sessiond/condition-internal.hpp new file mode 100644 index 000000000..49a074952 --- /dev/null +++ b/src/bin/lttng-sessiond/condition-internal.hpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2020 Francis Deslauriers + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_SESSIOND_CONDITION_INTERNAL_H +#define LTTNG_SESSIOND_CONDITION_INTERNAL_H + +#include + +/* + * The lttng_condition hashing code is kept in this file (rather than + * condition.c) since it makes use of GPLv2 code (hashtable utils), which we + * don't want to link in liblttng-ctl. + */ +unsigned long lttng_condition_hash(const struct lttng_condition *condition); + +struct lttng_condition *lttng_condition_copy( + const struct lttng_condition *condition); + +#endif /* LTTNG_SESSIOND_CONDITION_INTERNAL_H */ diff --git a/src/bin/lttng-sessiond/consumer.cpp b/src/bin/lttng-sessiond/consumer.cpp index f76dffa7e..238da0508 100644 --- a/src/bin/lttng-sessiond/consumer.cpp +++ b/src/bin/lttng-sessiond/consumer.cpp @@ -15,17 +15,17 @@ #include #include -#include -#include -#include -#include -#include - -#include "consumer.h" -#include "health-sessiond.h" -#include "ust-app.h" -#include "utils.h" -#include "lttng-sessiond.h" +#include +#include +#include +#include +#include + +#include "consumer.hpp" +#include "health-sessiond.hpp" +#include "ust-app.hpp" +#include "utils.hpp" +#include "lttng-sessiond.hpp" /* * Return allocated full pathname of the session using the consumer trace path diff --git a/src/bin/lttng-sessiond/consumer.h b/src/bin/lttng-sessiond/consumer.h deleted file mode 100644 index a179206fc..000000000 --- a/src/bin/lttng-sessiond/consumer.h +++ /dev/null @@ -1,346 +0,0 @@ -/* - * Copyright (C) 2012 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _CONSUMER_H -#define _CONSUMER_H - -#include -#include -#include -#include -#include - -#include "snapshot.h" - -struct snapshot; -struct snapshot_output; -struct ltt_session; - -/* - * Needed until we use C++14, where std::max is constexpr. - * - * Use a static_assert so we remember to remove it when we upgrade to a newer - * C++. - */ -static_assert(__cplusplus == 201103L, ""); -template -constexpr T max_constexpr(T l, T r) -{ - return l > r ? l : r; -} - -enum consumer_dst_type { - CONSUMER_DST_LOCAL, - CONSUMER_DST_NET, -}; - -enum consumer_trace_chunk_exists_status { - CONSUMER_TRACE_CHUNK_EXISTS_STATUS_EXISTS_LOCAL, - CONSUMER_TRACE_CHUNK_EXISTS_STATUS_EXISTS_REMOTE, - CONSUMER_TRACE_CHUNK_EXISTS_STATUS_UNKNOWN_CHUNK, -}; - -struct consumer_socket { - /* - * File descriptor. This is just a reference to the consumer data meaning - * that every access must be locked and checked for a possible invalid - * value. - */ - int *fd_ptr; - - /* - * To use this socket (send/recv), this lock MUST be acquired. - */ - pthread_mutex_t *lock; - - /* - * Indicates if the socket was registered by a third part - * (REGISTER_CONSUMER) or is the spawn consumer of the session daemon. - * During the destroy phase of a consumer output, we close the socket if - * this flag is set to 1 since we don't need the fd anymore. - */ - unsigned int registered; - - /* Flag if network sockets were sent to the consumer. */ - unsigned int control_sock_sent; - unsigned int data_sock_sent; - - struct lttng_ht_node_ulong node; - - enum lttng_consumer_type type; -}; - -struct consumer_data { - consumer_data (lttng_consumer_type type_) - : type(type_) - {} - - enum lttng_consumer_type type; - - /* Mutex to control consumerd pid assignation */ - pthread_mutex_t pid_mutex = PTHREAD_MUTEX_INITIALIZER; - pid_t pid = 0; - - int err_sock = -1; - /* These two sockets uses the cmd_unix_sock_path. */ - int cmd_sock = -1; - /* - * Write-end of the channel monitoring pipe to be passed to the - * consumer. - */ - int channel_monitor_pipe = -1; - /* - * The metadata socket object is handled differently and only created - * locally in this object thus it's the only reference available in the - * session daemon. For that reason, a variable for the fd is required and - * the metadata socket fd points to it. - */ - int metadata_fd = 0; - struct consumer_socket metadata_sock {}; - - /* consumer error and command Unix socket path */ - const char *err_unix_sock_path = nullptr; - const char *cmd_unix_sock_path = nullptr; - - /* - * This lock has two purposes. It protects any change to the consumer - * socket and make sure only one thread uses this object for read/write - * operations. - */ - pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; -}; - -/* - * Network URIs - */ -struct consumer_net { - /* - * Indicate if URI type is set. Those flags should only be set when the - * created URI is done AND valid. - */ - int control_isset; - int data_isset; - - /* - * The following two URIs MUST have the same destination address for - * network streaming to work. Network hop are not yet supported. - */ - - /* Control path for network streaming. */ - struct lttng_uri control; - - /* Data path for network streaming. */ - struct lttng_uri data; - - /* / */ - char base_dir[PATH_MAX]; -}; - -/* - * Consumer output object describing where and how to send data. - */ -struct consumer_output { - struct urcu_ref ref; /* Refcount */ - - /* If the consumer is enabled meaning that should be used */ - unsigned int enabled; - enum consumer_dst_type type; - - /* - * The net_seq_index is the index of the network stream on the consumer - * side. It tells the consumer which streams goes to which relayd with this - * index. The relayd sockets are index with it on the consumer side. - */ - uint64_t net_seq_index; - /* Store the relay protocol in use if the session is remote. */ - uint32_t relay_major_version; - uint32_t relay_minor_version; - - /* True if relayd supports the clear feature. */ - bool relay_allows_clear; - - /* - * Subdirectory path name used for both local and network - * consumer ("kernel", "ust", or empty). - */ - char domain_subdir[ - max_constexpr(sizeof(DEFAULT_KERNEL_TRACE_DIR), - sizeof(DEFAULT_UST_TRACE_DIR))]; - - /* - * Hashtable of consumer_socket index by the file descriptor value. For - * multiarch consumer support, we can have more than one consumer (ex: - * 32 and 64 bit). - */ - struct lttng_ht *socks; - - /* Tell if this output is used for snapshot. */ - unsigned int snapshot:1; - - union { - char session_root_path[LTTNG_PATH_MAX]; - struct consumer_net net; - } dst; - - /* - * Sub-directory below the session_root_path where the next chunk of - * trace will be stored (\0 before the first session rotation). - */ - char chunk_path[LTTNG_PATH_MAX]; -}; - -struct consumer_socket *consumer_find_socket(int key, - const struct consumer_output *consumer); -struct consumer_socket *consumer_find_socket_by_bitness(int bits, - const struct consumer_output *consumer); -struct consumer_socket *consumer_allocate_socket(int *fd); -void consumer_add_socket(struct consumer_socket *sock, - struct consumer_output *consumer); -void consumer_del_socket(struct consumer_socket *sock, - struct consumer_output *consumer); -void consumer_destroy_socket(struct consumer_socket *sock); -int consumer_copy_sockets(struct consumer_output *dst, - struct consumer_output *src); -void consumer_destroy_output_sockets(struct consumer_output *obj); -int consumer_socket_send(struct consumer_socket *socket, const void *msg, - size_t len); -int consumer_socket_recv(struct consumer_socket *socket, void *msg, - size_t len); - -struct consumer_output *consumer_create_output(enum consumer_dst_type type); -struct consumer_output *consumer_copy_output(struct consumer_output *obj); -void consumer_output_get(struct consumer_output *obj); -void consumer_output_put(struct consumer_output *obj); -int consumer_set_network_uri(const struct ltt_session *session, - struct consumer_output *obj, - struct lttng_uri *uri); -int consumer_send_fds(struct consumer_socket *sock, const int *fds, - size_t nb_fd); -int consumer_send_msg(struct consumer_socket *sock, - const struct lttcomm_consumer_msg *msg); -int consumer_send_stream(struct consumer_socket *sock, - struct consumer_output *dst, struct lttcomm_consumer_msg *msg, - const int *fds, size_t nb_fd); -int consumer_send_channel(struct consumer_socket *sock, - struct lttcomm_consumer_msg *msg); -int consumer_send_relayd_socket(struct consumer_socket *consumer_sock, - struct lttcomm_relayd_sock *rsock, struct consumer_output *consumer, - enum lttng_stream_type type, uint64_t session_id, - const char *session_name, const char *hostname, - const char *base_path, int session_live_timer, - const uint64_t *current_chunk_id, time_t session_creation_time, - bool session_name_contains_creation_time); -int consumer_send_channel_monitor_pipe(struct consumer_socket *consumer_sock, - int pipe); -int consumer_send_destroy_relayd(struct consumer_socket *sock, - struct consumer_output *consumer); -int consumer_recv_status_reply(struct consumer_socket *sock); -int consumer_recv_status_channel(struct consumer_socket *sock, - uint64_t *key, unsigned int *stream_count); -void consumer_output_send_destroy_relayd(struct consumer_output *consumer); -int consumer_create_socket(struct consumer_data *data, - struct consumer_output *output); - -void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg, - uint64_t subbuf_size, - uint64_t num_subbuf, - int overwrite, - unsigned int switch_timer_interval, - unsigned int read_timer_interval, - unsigned int live_timer_interval, - bool is_in_live_session, - unsigned int monitor_timer_interval, - int output, - int type, - uint64_t session_id, - const char *pathname, - const char *name, - uint64_t relayd_id, - uint64_t key, - unsigned char *uuid, - uint32_t chan_id, - uint64_t tracefile_size, - uint64_t tracefile_count, - uint64_t session_id_per_pid, - unsigned int monitor, - uint32_t ust_app_uid, - int64_t blocking_timeout, - const char *root_shm_path, - const char *shm_path, - struct lttng_trace_chunk *trace_chunk, - const struct lttng_credentials *buffer_credentials); -void consumer_init_add_stream_comm_msg(struct lttcomm_consumer_msg *msg, - uint64_t channel_key, - uint64_t stream_key, - int32_t cpu); -void consumer_init_streams_sent_comm_msg(struct lttcomm_consumer_msg *msg, - enum lttng_consumer_command cmd, - uint64_t channel_key, uint64_t net_seq_idx); -void consumer_init_add_channel_comm_msg(struct lttcomm_consumer_msg *msg, - uint64_t channel_key, - uint64_t session_id, - const char *pathname, - uint64_t relayd_id, - const char *name, - unsigned int nb_init_streams, - enum lttng_event_output output, - int type, - uint64_t tracefile_size, - uint64_t tracefile_count, - unsigned int monitor, - unsigned int live_timer_interval, - bool is_in_live_session, - unsigned int monitor_timer_interval, - struct lttng_trace_chunk *trace_chunk); -int consumer_is_data_pending(uint64_t session_id, - struct consumer_output *consumer); -int consumer_close_metadata(struct consumer_socket *socket, - uint64_t metadata_key); -int consumer_setup_metadata(struct consumer_socket *socket, - uint64_t metadata_key); -int consumer_push_metadata(struct consumer_socket *socket, - uint64_t metadata_key, char *metadata_str, size_t len, - size_t target_offset, uint64_t version); -int consumer_flush_channel(struct consumer_socket *socket, uint64_t key); -int consumer_clear_quiescent_channel(struct consumer_socket *socket, uint64_t key); -int consumer_get_discarded_events(uint64_t session_id, uint64_t channel_key, - struct consumer_output *consumer, uint64_t *discarded); -int consumer_get_lost_packets(uint64_t session_id, uint64_t channel_key, - struct consumer_output *consumer, uint64_t *lost); - -/* Snapshot command. */ -enum lttng_error_code consumer_snapshot_channel(struct consumer_socket *socket, - uint64_t key, const struct consumer_output *output, int metadata, - const char *channel_path, uint64_t nb_packets_per_stream); - -/* Rotation commands. */ -int consumer_rotate_channel(struct consumer_socket *socket, uint64_t key, - struct consumer_output *output, bool is_metadata_channel); -int consumer_init(struct consumer_socket *socket, - const lttng_uuid sessiond_uuid); - -int consumer_create_trace_chunk(struct consumer_socket *socket, - uint64_t relayd_id, uint64_t session_id, - struct lttng_trace_chunk *chunk, - const char *domain_subdir); -int consumer_close_trace_chunk(struct consumer_socket *socket, - uint64_t relayd_id, uint64_t session_id, - struct lttng_trace_chunk *chunk, - char *closed_trace_chunk_path); -int consumer_trace_chunk_exists(struct consumer_socket *socket, - uint64_t relayd_id, uint64_t session_id, - struct lttng_trace_chunk *chunk, - enum consumer_trace_chunk_exists_status *result); -int consumer_open_channel_packets(struct consumer_socket *socket, uint64_t key); - -char *setup_channel_trace_path(struct consumer_output *consumer, - const char *session_path, size_t *consumer_path_offset); - -/* Clear command */ -int consumer_clear_channel(struct consumer_socket *socket, uint64_t key); - -#endif /* _CONSUMER_H */ diff --git a/src/bin/lttng-sessiond/consumer.hpp b/src/bin/lttng-sessiond/consumer.hpp new file mode 100644 index 000000000..15e2a2fc7 --- /dev/null +++ b/src/bin/lttng-sessiond/consumer.hpp @@ -0,0 +1,346 @@ +/* + * Copyright (C) 2012 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _CONSUMER_H +#define _CONSUMER_H + +#include +#include +#include +#include +#include + +#include "snapshot.hpp" + +struct snapshot; +struct snapshot_output; +struct ltt_session; + +/* + * Needed until we use C++14, where std::max is constexpr. + * + * Use a static_assert so we remember to remove it when we upgrade to a newer + * C++. + */ +static_assert(__cplusplus == 201103L, ""); +template +constexpr T max_constexpr(T l, T r) +{ + return l > r ? l : r; +} + +enum consumer_dst_type { + CONSUMER_DST_LOCAL, + CONSUMER_DST_NET, +}; + +enum consumer_trace_chunk_exists_status { + CONSUMER_TRACE_CHUNK_EXISTS_STATUS_EXISTS_LOCAL, + CONSUMER_TRACE_CHUNK_EXISTS_STATUS_EXISTS_REMOTE, + CONSUMER_TRACE_CHUNK_EXISTS_STATUS_UNKNOWN_CHUNK, +}; + +struct consumer_socket { + /* + * File descriptor. This is just a reference to the consumer data meaning + * that every access must be locked and checked for a possible invalid + * value. + */ + int *fd_ptr; + + /* + * To use this socket (send/recv), this lock MUST be acquired. + */ + pthread_mutex_t *lock; + + /* + * Indicates if the socket was registered by a third part + * (REGISTER_CONSUMER) or is the spawn consumer of the session daemon. + * During the destroy phase of a consumer output, we close the socket if + * this flag is set to 1 since we don't need the fd anymore. + */ + unsigned int registered; + + /* Flag if network sockets were sent to the consumer. */ + unsigned int control_sock_sent; + unsigned int data_sock_sent; + + struct lttng_ht_node_ulong node; + + enum lttng_consumer_type type; +}; + +struct consumer_data { + consumer_data (lttng_consumer_type type_) + : type(type_) + {} + + enum lttng_consumer_type type; + + /* Mutex to control consumerd pid assignation */ + pthread_mutex_t pid_mutex = PTHREAD_MUTEX_INITIALIZER; + pid_t pid = 0; + + int err_sock = -1; + /* These two sockets uses the cmd_unix_sock_path. */ + int cmd_sock = -1; + /* + * Write-end of the channel monitoring pipe to be passed to the + * consumer. + */ + int channel_monitor_pipe = -1; + /* + * The metadata socket object is handled differently and only created + * locally in this object thus it's the only reference available in the + * session daemon. For that reason, a variable for the fd is required and + * the metadata socket fd points to it. + */ + int metadata_fd = 0; + struct consumer_socket metadata_sock {}; + + /* consumer error and command Unix socket path */ + const char *err_unix_sock_path = nullptr; + const char *cmd_unix_sock_path = nullptr; + + /* + * This lock has two purposes. It protects any change to the consumer + * socket and make sure only one thread uses this object for read/write + * operations. + */ + pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +}; + +/* + * Network URIs + */ +struct consumer_net { + /* + * Indicate if URI type is set. Those flags should only be set when the + * created URI is done AND valid. + */ + int control_isset; + int data_isset; + + /* + * The following two URIs MUST have the same destination address for + * network streaming to work. Network hop are not yet supported. + */ + + /* Control path for network streaming. */ + struct lttng_uri control; + + /* Data path for network streaming. */ + struct lttng_uri data; + + /* / */ + char base_dir[PATH_MAX]; +}; + +/* + * Consumer output object describing where and how to send data. + */ +struct consumer_output { + struct urcu_ref ref; /* Refcount */ + + /* If the consumer is enabled meaning that should be used */ + unsigned int enabled; + enum consumer_dst_type type; + + /* + * The net_seq_index is the index of the network stream on the consumer + * side. It tells the consumer which streams goes to which relayd with this + * index. The relayd sockets are index with it on the consumer side. + */ + uint64_t net_seq_index; + /* Store the relay protocol in use if the session is remote. */ + uint32_t relay_major_version; + uint32_t relay_minor_version; + + /* True if relayd supports the clear feature. */ + bool relay_allows_clear; + + /* + * Subdirectory path name used for both local and network + * consumer ("kernel", "ust", or empty). + */ + char domain_subdir[ + max_constexpr(sizeof(DEFAULT_KERNEL_TRACE_DIR), + sizeof(DEFAULT_UST_TRACE_DIR))]; + + /* + * Hashtable of consumer_socket index by the file descriptor value. For + * multiarch consumer support, we can have more than one consumer (ex: + * 32 and 64 bit). + */ + struct lttng_ht *socks; + + /* Tell if this output is used for snapshot. */ + unsigned int snapshot:1; + + union { + char session_root_path[LTTNG_PATH_MAX]; + struct consumer_net net; + } dst; + + /* + * Sub-directory below the session_root_path where the next chunk of + * trace will be stored (\0 before the first session rotation). + */ + char chunk_path[LTTNG_PATH_MAX]; +}; + +struct consumer_socket *consumer_find_socket(int key, + const struct consumer_output *consumer); +struct consumer_socket *consumer_find_socket_by_bitness(int bits, + const struct consumer_output *consumer); +struct consumer_socket *consumer_allocate_socket(int *fd); +void consumer_add_socket(struct consumer_socket *sock, + struct consumer_output *consumer); +void consumer_del_socket(struct consumer_socket *sock, + struct consumer_output *consumer); +void consumer_destroy_socket(struct consumer_socket *sock); +int consumer_copy_sockets(struct consumer_output *dst, + struct consumer_output *src); +void consumer_destroy_output_sockets(struct consumer_output *obj); +int consumer_socket_send(struct consumer_socket *socket, const void *msg, + size_t len); +int consumer_socket_recv(struct consumer_socket *socket, void *msg, + size_t len); + +struct consumer_output *consumer_create_output(enum consumer_dst_type type); +struct consumer_output *consumer_copy_output(struct consumer_output *obj); +void consumer_output_get(struct consumer_output *obj); +void consumer_output_put(struct consumer_output *obj); +int consumer_set_network_uri(const struct ltt_session *session, + struct consumer_output *obj, + struct lttng_uri *uri); +int consumer_send_fds(struct consumer_socket *sock, const int *fds, + size_t nb_fd); +int consumer_send_msg(struct consumer_socket *sock, + const struct lttcomm_consumer_msg *msg); +int consumer_send_stream(struct consumer_socket *sock, + struct consumer_output *dst, struct lttcomm_consumer_msg *msg, + const int *fds, size_t nb_fd); +int consumer_send_channel(struct consumer_socket *sock, + struct lttcomm_consumer_msg *msg); +int consumer_send_relayd_socket(struct consumer_socket *consumer_sock, + struct lttcomm_relayd_sock *rsock, struct consumer_output *consumer, + enum lttng_stream_type type, uint64_t session_id, + const char *session_name, const char *hostname, + const char *base_path, int session_live_timer, + const uint64_t *current_chunk_id, time_t session_creation_time, + bool session_name_contains_creation_time); +int consumer_send_channel_monitor_pipe(struct consumer_socket *consumer_sock, + int pipe); +int consumer_send_destroy_relayd(struct consumer_socket *sock, + struct consumer_output *consumer); +int consumer_recv_status_reply(struct consumer_socket *sock); +int consumer_recv_status_channel(struct consumer_socket *sock, + uint64_t *key, unsigned int *stream_count); +void consumer_output_send_destroy_relayd(struct consumer_output *consumer); +int consumer_create_socket(struct consumer_data *data, + struct consumer_output *output); + +void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg, + uint64_t subbuf_size, + uint64_t num_subbuf, + int overwrite, + unsigned int switch_timer_interval, + unsigned int read_timer_interval, + unsigned int live_timer_interval, + bool is_in_live_session, + unsigned int monitor_timer_interval, + int output, + int type, + uint64_t session_id, + const char *pathname, + const char *name, + uint64_t relayd_id, + uint64_t key, + unsigned char *uuid, + uint32_t chan_id, + uint64_t tracefile_size, + uint64_t tracefile_count, + uint64_t session_id_per_pid, + unsigned int monitor, + uint32_t ust_app_uid, + int64_t blocking_timeout, + const char *root_shm_path, + const char *shm_path, + struct lttng_trace_chunk *trace_chunk, + const struct lttng_credentials *buffer_credentials); +void consumer_init_add_stream_comm_msg(struct lttcomm_consumer_msg *msg, + uint64_t channel_key, + uint64_t stream_key, + int32_t cpu); +void consumer_init_streams_sent_comm_msg(struct lttcomm_consumer_msg *msg, + enum lttng_consumer_command cmd, + uint64_t channel_key, uint64_t net_seq_idx); +void consumer_init_add_channel_comm_msg(struct lttcomm_consumer_msg *msg, + uint64_t channel_key, + uint64_t session_id, + const char *pathname, + uint64_t relayd_id, + const char *name, + unsigned int nb_init_streams, + enum lttng_event_output output, + int type, + uint64_t tracefile_size, + uint64_t tracefile_count, + unsigned int monitor, + unsigned int live_timer_interval, + bool is_in_live_session, + unsigned int monitor_timer_interval, + struct lttng_trace_chunk *trace_chunk); +int consumer_is_data_pending(uint64_t session_id, + struct consumer_output *consumer); +int consumer_close_metadata(struct consumer_socket *socket, + uint64_t metadata_key); +int consumer_setup_metadata(struct consumer_socket *socket, + uint64_t metadata_key); +int consumer_push_metadata(struct consumer_socket *socket, + uint64_t metadata_key, char *metadata_str, size_t len, + size_t target_offset, uint64_t version); +int consumer_flush_channel(struct consumer_socket *socket, uint64_t key); +int consumer_clear_quiescent_channel(struct consumer_socket *socket, uint64_t key); +int consumer_get_discarded_events(uint64_t session_id, uint64_t channel_key, + struct consumer_output *consumer, uint64_t *discarded); +int consumer_get_lost_packets(uint64_t session_id, uint64_t channel_key, + struct consumer_output *consumer, uint64_t *lost); + +/* Snapshot command. */ +enum lttng_error_code consumer_snapshot_channel(struct consumer_socket *socket, + uint64_t key, const struct consumer_output *output, int metadata, + const char *channel_path, uint64_t nb_packets_per_stream); + +/* Rotation commands. */ +int consumer_rotate_channel(struct consumer_socket *socket, uint64_t key, + struct consumer_output *output, bool is_metadata_channel); +int consumer_init(struct consumer_socket *socket, + const lttng_uuid sessiond_uuid); + +int consumer_create_trace_chunk(struct consumer_socket *socket, + uint64_t relayd_id, uint64_t session_id, + struct lttng_trace_chunk *chunk, + const char *domain_subdir); +int consumer_close_trace_chunk(struct consumer_socket *socket, + uint64_t relayd_id, uint64_t session_id, + struct lttng_trace_chunk *chunk, + char *closed_trace_chunk_path); +int consumer_trace_chunk_exists(struct consumer_socket *socket, + uint64_t relayd_id, uint64_t session_id, + struct lttng_trace_chunk *chunk, + enum consumer_trace_chunk_exists_status *result); +int consumer_open_channel_packets(struct consumer_socket *socket, uint64_t key); + +char *setup_channel_trace_path(struct consumer_output *consumer, + const char *session_path, size_t *consumer_path_offset); + +/* Clear command */ +int consumer_clear_channel(struct consumer_socket *socket, uint64_t key); + +#endif /* _CONSUMER_H */ diff --git a/src/bin/lttng-sessiond/context.cpp b/src/bin/lttng-sessiond/context.cpp index 1f1fcb3c2..8dc82fbe8 100644 --- a/src/bin/lttng-sessiond/context.cpp +++ b/src/bin/lttng-sessiond/context.cpp @@ -13,14 +13,14 @@ #include #include -#include -#include - -#include "context.h" -#include "kernel.h" -#include "ust-app.h" -#include "trace-ust.h" -#include "agent.h" +#include +#include + +#include "context.hpp" +#include "kernel.hpp" +#include "ust-app.hpp" +#include "trace-ust.hpp" +#include "agent.hpp" /* * Add kernel context to all channel. diff --git a/src/bin/lttng-sessiond/context.h b/src/bin/lttng-sessiond/context.h deleted file mode 100644 index 073a2e178..000000000 --- a/src/bin/lttng-sessiond/context.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _LTT_CONTEXT_H -#define _LTT_CONTEXT_H - -#include - -#include "trace-kernel.h" -#include "trace-ust.h" -#include "lttng-ust-ctl.h" - -int context_kernel_add(struct ltt_kernel_session *ksession, - const struct lttng_event_context *ctx, - const char *channel_name); -int context_ust_add(struct ltt_ust_session *usess, - enum lttng_domain_type domain, - const struct lttng_event_context *ctx, - const char *channel_name); - -#endif /* _LTT_CONTEXT_H */ diff --git a/src/bin/lttng-sessiond/context.hpp b/src/bin/lttng-sessiond/context.hpp new file mode 100644 index 000000000..a55f57116 --- /dev/null +++ b/src/bin/lttng-sessiond/context.hpp @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _LTT_CONTEXT_H +#define _LTT_CONTEXT_H + +#include + +#include "trace-kernel.hpp" +#include "trace-ust.hpp" +#include "lttng-ust-ctl.hpp" + +int context_kernel_add(struct ltt_kernel_session *ksession, + const struct lttng_event_context *ctx, + const char *channel_name); +int context_ust_add(struct ltt_ust_session *usess, + enum lttng_domain_type domain, + const struct lttng_event_context *ctx, + const char *channel_name); + +#endif /* _LTT_CONTEXT_H */ diff --git a/src/bin/lttng-sessiond/dispatch.cpp b/src/bin/lttng-sessiond/dispatch.cpp index 6cbb26126..7988f1ba8 100644 --- a/src/bin/lttng-sessiond/dispatch.cpp +++ b/src/bin/lttng-sessiond/dispatch.cpp @@ -10,16 +10,16 @@ #include #include #include -#include -#include - -#include "dispatch.h" -#include "ust-app.h" -#include "testpoint.h" -#include "fd-limit.h" -#include "health-sessiond.h" -#include "lttng-sessiond.h" -#include "thread.h" +#include +#include + +#include "dispatch.hpp" +#include "ust-app.hpp" +#include "testpoint.hpp" +#include "fd-limit.hpp" +#include "health-sessiond.hpp" +#include "lttng-sessiond.hpp" +#include "thread.hpp" struct thread_notifiers { struct ust_cmd_queue *ust_cmd_queue; diff --git a/src/bin/lttng-sessiond/dispatch.h b/src/bin/lttng-sessiond/dispatch.h deleted file mode 100644 index 7c8790e46..000000000 --- a/src/bin/lttng-sessiond/dispatch.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * Copyright (C) 2011 Mathieu Desnoyers - * Copyright (C) 2013 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef SESSIOND_UST_DISPATCH_THREAD_H -#define SESSIOND_UST_DISPATCH_THREAD_H - -#include -#include "lttng-sessiond.h" - -bool launch_ust_dispatch_thread(struct ust_cmd_queue *cmd_queue, - int apps_cmd_pipe_write_fd, - int apps_cmd_notify_write_fd); - -#endif /* SESSIOND_UST_DISPATCH_THREAD_H */ diff --git a/src/bin/lttng-sessiond/dispatch.hpp b/src/bin/lttng-sessiond/dispatch.hpp new file mode 100644 index 000000000..d5ec8c9c3 --- /dev/null +++ b/src/bin/lttng-sessiond/dispatch.hpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * Copyright (C) 2011 Mathieu Desnoyers + * Copyright (C) 2013 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef SESSIOND_UST_DISPATCH_THREAD_H +#define SESSIOND_UST_DISPATCH_THREAD_H + +#include +#include "lttng-sessiond.hpp" + +bool launch_ust_dispatch_thread(struct ust_cmd_queue *cmd_queue, + int apps_cmd_pipe_write_fd, + int apps_cmd_notify_write_fd); + +#endif /* SESSIOND_UST_DISPATCH_THREAD_H */ diff --git a/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp b/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp index 138d51b4d..10d69493b 100644 --- a/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp +++ b/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp @@ -12,16 +12,16 @@ #include #include -#include -#include -#include -#include -#include -#include - -#include "event-notifier-error-accounting.h" -#include "lttng-ust-error.h" -#include "ust-app.h" +#include +#include +#include +#include +#include +#include + +#include "event-notifier-error-accounting.hpp" +#include "lttng-ust-error.hpp" +#include "ust-app.hpp" #define ERROR_COUNTER_INDEX_HT_INITIAL_SIZE 16 diff --git a/src/bin/lttng-sessiond/event-notifier-error-accounting.h b/src/bin/lttng-sessiond/event-notifier-error-accounting.h deleted file mode 100644 index 440b9d091..000000000 --- a/src/bin/lttng-sessiond/event-notifier-error-accounting.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2020 Francis Deslauriers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _EVENT_NOTIFIER_ERROR_ACCOUNTING_H -#define _EVENT_NOTIFIER_ERROR_ACCOUNTING_H - -#include - -#include - -#include "ust-app.h" - -enum event_notifier_error_accounting_status { - EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK, - EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_ERR, - EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NOT_FOUND, - EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NOMEM, - EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NO_INDEX_AVAILABLE, - EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_APP_DEAD, - EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_UNSUPPORTED, -}; - -/* - * Initialize the event notifier error accounting system. - * `buffer_size_kernel` and `buffer_size_ust` represent the number of buckets - * to be allocated for each domain. - */ -enum event_notifier_error_accounting_status -event_notifier_error_accounting_init(uint64_t buffer_size_kernel, - uint64_t buffer_size_ust); - -/* - * Register the kernel event notifier group. - * This allocates the counter object on the kernel side. - */ -enum event_notifier_error_accounting_status -event_notifier_error_accounting_register_kernel( - int kernel_event_notifier_group_fd); - -#ifdef HAVE_LIBLTTNG_UST_CTL - -/* - * Register a UST application. - * - * This reuses (or creates) the counter object of the app UID. - */ -enum event_notifier_error_accounting_status -event_notifier_error_accounting_register_app(struct ust_app *app); - -/* - * Unregister a UST application. - */ -enum event_notifier_error_accounting_status -event_notifier_error_accounting_unregister_app(struct ust_app *app); - -#else /* HAVE_LIBLTTNG_UST_CTL */ - -static inline -enum event_notifier_error_accounting_status -event_notifier_error_accounting_register_app( - struct ust_app *app __attribute__((unused))) -{ - return EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK; -} - -static inline -enum event_notifier_error_accounting_status -event_notifier_error_accounting_unregister_app( - struct ust_app *app __attribute__((unused))) -{ - return EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK; -} -#endif /* HAVE_LIBLTTNG_UST_CTL */ - -/* - * Allocates, reserves and returns the error counter index for that trigger. - */ -enum event_notifier_error_accounting_status -event_notifier_error_accounting_register_event_notifier( - const struct lttng_trigger *trigger, - uint64_t *error_counter_index); - -enum event_notifier_error_accounting_status -event_notifier_error_accounting_get_count( - const struct lttng_trigger *trigger, - uint64_t *count); - -void event_notifier_error_accounting_unregister_event_notifier( - const struct lttng_trigger *trigger); - -void event_notifier_error_accounting_fini(void); - -#endif /* _EVENT_NOTIFIER_ERROR_ACCOUNTING_H */ diff --git a/src/bin/lttng-sessiond/event-notifier-error-accounting.hpp b/src/bin/lttng-sessiond/event-notifier-error-accounting.hpp new file mode 100644 index 000000000..89466bd44 --- /dev/null +++ b/src/bin/lttng-sessiond/event-notifier-error-accounting.hpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2020 Francis Deslauriers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _EVENT_NOTIFIER_ERROR_ACCOUNTING_H +#define _EVENT_NOTIFIER_ERROR_ACCOUNTING_H + +#include + +#include + +#include "ust-app.hpp" + +enum event_notifier_error_accounting_status { + EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK, + EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_ERR, + EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NOT_FOUND, + EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NOMEM, + EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NO_INDEX_AVAILABLE, + EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_APP_DEAD, + EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_UNSUPPORTED, +}; + +/* + * Initialize the event notifier error accounting system. + * `buffer_size_kernel` and `buffer_size_ust` represent the number of buckets + * to be allocated for each domain. + */ +enum event_notifier_error_accounting_status +event_notifier_error_accounting_init(uint64_t buffer_size_kernel, + uint64_t buffer_size_ust); + +/* + * Register the kernel event notifier group. + * This allocates the counter object on the kernel side. + */ +enum event_notifier_error_accounting_status +event_notifier_error_accounting_register_kernel( + int kernel_event_notifier_group_fd); + +#ifdef HAVE_LIBLTTNG_UST_CTL + +/* + * Register a UST application. + * + * This reuses (or creates) the counter object of the app UID. + */ +enum event_notifier_error_accounting_status +event_notifier_error_accounting_register_app(struct ust_app *app); + +/* + * Unregister a UST application. + */ +enum event_notifier_error_accounting_status +event_notifier_error_accounting_unregister_app(struct ust_app *app); + +#else /* HAVE_LIBLTTNG_UST_CTL */ + +static inline +enum event_notifier_error_accounting_status +event_notifier_error_accounting_register_app( + struct ust_app *app __attribute__((unused))) +{ + return EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK; +} + +static inline +enum event_notifier_error_accounting_status +event_notifier_error_accounting_unregister_app( + struct ust_app *app __attribute__((unused))) +{ + return EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK; +} +#endif /* HAVE_LIBLTTNG_UST_CTL */ + +/* + * Allocates, reserves and returns the error counter index for that trigger. + */ +enum event_notifier_error_accounting_status +event_notifier_error_accounting_register_event_notifier( + const struct lttng_trigger *trigger, + uint64_t *error_counter_index); + +enum event_notifier_error_accounting_status +event_notifier_error_accounting_get_count( + const struct lttng_trigger *trigger, + uint64_t *count); + +void event_notifier_error_accounting_unregister_event_notifier( + const struct lttng_trigger *trigger); + +void event_notifier_error_accounting_fini(void); + +#endif /* _EVENT_NOTIFIER_ERROR_ACCOUNTING_H */ diff --git a/src/bin/lttng-sessiond/event.cpp b/src/bin/lttng-sessiond/event.cpp index 924df3af1..797219dff 100644 --- a/src/bin/lttng-sessiond/event.cpp +++ b/src/bin/lttng-sessiond/event.cpp @@ -10,29 +10,29 @@ #include #include -#include +#include #include #include #include #include -#include -#include -#include -#include -#include -#include - -#include "channel.h" -#include "event.h" -#include "kernel.h" -#include "lttng-sessiond.h" -#include "lttng-ust-ctl.h" -#include "lttng-ust-error.h" -#include "ust-app.h" -#include "trace-kernel.h" -#include "trace-ust.h" -#include "agent.h" -#include "utils.h" +#include +#include +#include +#include +#include +#include + +#include "channel.hpp" +#include "event.hpp" +#include "kernel.hpp" +#include "lttng-sessiond.hpp" +#include "lttng-ust-ctl.hpp" +#include "lttng-ust-error.hpp" +#include "ust-app.hpp" +#include "trace-kernel.hpp" +#include "trace-ust.hpp" +#include "agent.hpp" +#include "utils.hpp" /* * Add unique UST event based on the event name, filter bytecode and loglevel. diff --git a/src/bin/lttng-sessiond/event.h b/src/bin/lttng-sessiond/event.h deleted file mode 100644 index 01be565b4..000000000 --- a/src/bin/lttng-sessiond/event.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _LTT_EVENT_H -#define _LTT_EVENT_H - -#include "trace-kernel.h" - -struct agent; - -int event_kernel_disable_event(struct ltt_kernel_channel *kchan, - const char *event_name, enum lttng_event_type event_type); - -int event_kernel_enable_event(struct ltt_kernel_channel *kchan, - struct lttng_event *event, char *filter_expression, - struct lttng_bytecode *filter); - -int event_ust_enable_tracepoint(struct ltt_ust_session *usess, - struct ltt_ust_channel *uchan, struct lttng_event *event, - char *filter_expression, - struct lttng_bytecode *filter, - struct lttng_event_exclusion *exclusion, - bool internal_event); -int event_ust_disable_tracepoint(struct ltt_ust_session *usess, - struct ltt_ust_channel *uchan, const char *event_name); - -int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess, - struct ltt_ust_channel *uchan); - -int event_agent_enable(struct ltt_ust_session *usess, struct agent *agt, - struct lttng_event *event, struct lttng_bytecode *filter, - char *filter_expression); -int event_agent_enable_all(struct ltt_ust_session *usess, struct agent *agt, - struct lttng_event *event, struct lttng_bytecode *filter, - char *filter_expression); - -int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, - const char *event_name); -int event_agent_disable_all(struct ltt_ust_session *usess, struct agent *agt); - -int trigger_agent_enable( - const struct lttng_trigger *trigger, struct agent *agt); -int trigger_agent_disable( - const struct lttng_trigger *trigger, struct agent *agt); - -const char *event_get_default_agent_ust_name(enum lttng_domain_type domain); - -#endif /* _LTT_EVENT_H */ diff --git a/src/bin/lttng-sessiond/event.hpp b/src/bin/lttng-sessiond/event.hpp new file mode 100644 index 000000000..efc4ad5d0 --- /dev/null +++ b/src/bin/lttng-sessiond/event.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _LTT_EVENT_H +#define _LTT_EVENT_H + +#include "trace-kernel.hpp" + +struct agent; + +int event_kernel_disable_event(struct ltt_kernel_channel *kchan, + const char *event_name, enum lttng_event_type event_type); + +int event_kernel_enable_event(struct ltt_kernel_channel *kchan, + struct lttng_event *event, char *filter_expression, + struct lttng_bytecode *filter); + +int event_ust_enable_tracepoint(struct ltt_ust_session *usess, + struct ltt_ust_channel *uchan, struct lttng_event *event, + char *filter_expression, + struct lttng_bytecode *filter, + struct lttng_event_exclusion *exclusion, + bool internal_event); +int event_ust_disable_tracepoint(struct ltt_ust_session *usess, + struct ltt_ust_channel *uchan, const char *event_name); + +int event_ust_disable_all_tracepoints(struct ltt_ust_session *usess, + struct ltt_ust_channel *uchan); + +int event_agent_enable(struct ltt_ust_session *usess, struct agent *agt, + struct lttng_event *event, struct lttng_bytecode *filter, + char *filter_expression); +int event_agent_enable_all(struct ltt_ust_session *usess, struct agent *agt, + struct lttng_event *event, struct lttng_bytecode *filter, + char *filter_expression); + +int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, + const char *event_name); +int event_agent_disable_all(struct ltt_ust_session *usess, struct agent *agt); + +int trigger_agent_enable( + const struct lttng_trigger *trigger, struct agent *agt); +int trigger_agent_disable( + const struct lttng_trigger *trigger, struct agent *agt); + +const char *event_get_default_agent_ust_name(enum lttng_domain_type domain); + +#endif /* _LTT_EVENT_H */ diff --git a/src/bin/lttng-sessiond/fd-limit.cpp b/src/bin/lttng-sessiond/fd-limit.cpp index 684332e9f..ac5c83f4b 100644 --- a/src/bin/lttng-sessiond/fd-limit.cpp +++ b/src/bin/lttng-sessiond/fd-limit.cpp @@ -10,9 +10,9 @@ #include #include #include -#include "fd-limit.h" -#include -#include +#include "fd-limit.hpp" +#include +#include /* total count of fd. */ static long fd_count; diff --git a/src/bin/lttng-sessiond/fd-limit.h b/src/bin/lttng-sessiond/fd-limit.h deleted file mode 100644 index 8666cdc00..000000000 --- a/src/bin/lttng-sessiond/fd-limit.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _LTTNG_FD_LIMIT_H -#define _LTTNG_FD_LIMIT_H - -/* - * Copyright (C) 2012 Mathieu Desnoyers - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -enum lttng_fd_type { - LTTNG_FD_APPS, - LTTNG_FD_NR_TYPES, -}; - -int lttng_fd_get(enum lttng_fd_type type, unsigned int nr); -void lttng_fd_put(enum lttng_fd_type type, unsigned int nr); -void lttng_fd_init(void); - -#endif /* _LTTNG_FD_LIMIT_H */ diff --git a/src/bin/lttng-sessiond/fd-limit.hpp b/src/bin/lttng-sessiond/fd-limit.hpp new file mode 100644 index 000000000..8666cdc00 --- /dev/null +++ b/src/bin/lttng-sessiond/fd-limit.hpp @@ -0,0 +1,20 @@ +#ifndef _LTTNG_FD_LIMIT_H +#define _LTTNG_FD_LIMIT_H + +/* + * Copyright (C) 2012 Mathieu Desnoyers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +enum lttng_fd_type { + LTTNG_FD_APPS, + LTTNG_FD_NR_TYPES, +}; + +int lttng_fd_get(enum lttng_fd_type type, unsigned int nr); +void lttng_fd_put(enum lttng_fd_type type, unsigned int nr); +void lttng_fd_init(void); + +#endif /* _LTTNG_FD_LIMIT_H */ diff --git a/src/bin/lttng-sessiond/globals.cpp b/src/bin/lttng-sessiond/globals.cpp index d07478316..c8710d62a 100644 --- a/src/bin/lttng-sessiond/globals.cpp +++ b/src/bin/lttng-sessiond/globals.cpp @@ -7,8 +7,8 @@ * */ -#include "lttng-sessiond.h" -#include +#include "lttng-sessiond.hpp" +#include lttng_uuid the_sessiond_uuid; diff --git a/src/bin/lttng-sessiond/health-sessiond.h b/src/bin/lttng-sessiond/health-sessiond.h deleted file mode 100644 index 163676aae..000000000 --- a/src/bin/lttng-sessiond/health-sessiond.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef HEALTH_SESSIOND_H -#define HEALTH_SESSIOND_H - -/* - * Copyright (C) 2012 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include -#include - -enum health_type_sessiond { - HEALTH_SESSIOND_TYPE_CMD = 0, - HEALTH_SESSIOND_TYPE_APP_MANAGE = 1, - HEALTH_SESSIOND_TYPE_APP_REG = 2, - HEALTH_SESSIOND_TYPE_KERNEL = 3, - HEALTH_SESSIOND_TYPE_CONSUMER = 4, - HEALTH_SESSIOND_TYPE_APP_MANAGE_NOTIFY = 6, - HEALTH_SESSIOND_TYPE_APP_REG_DISPATCH = 7, - HEALTH_SESSIOND_TYPE_NOTIFICATION = 8, - HEALTH_SESSIOND_TYPE_ROTATION = 9, - HEALTH_SESSIOND_TYPE_TIMER = 10, - HEALTH_SESSIOND_TYPE_ACTION_EXECUTOR = 11, - - NR_HEALTH_SESSIOND_TYPES, -}; - -/* Application health monitoring */ -extern struct health_app *the_health_sessiond; - -bool launch_health_management_thread(void); - -#endif /* HEALTH_SESSIOND_H */ diff --git a/src/bin/lttng-sessiond/health-sessiond.hpp b/src/bin/lttng-sessiond/health-sessiond.hpp new file mode 100644 index 000000000..52f38e2d8 --- /dev/null +++ b/src/bin/lttng-sessiond/health-sessiond.hpp @@ -0,0 +1,35 @@ +#ifndef HEALTH_SESSIOND_H +#define HEALTH_SESSIOND_H + +/* + * Copyright (C) 2012 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include + +enum health_type_sessiond { + HEALTH_SESSIOND_TYPE_CMD = 0, + HEALTH_SESSIOND_TYPE_APP_MANAGE = 1, + HEALTH_SESSIOND_TYPE_APP_REG = 2, + HEALTH_SESSIOND_TYPE_KERNEL = 3, + HEALTH_SESSIOND_TYPE_CONSUMER = 4, + HEALTH_SESSIOND_TYPE_APP_MANAGE_NOTIFY = 6, + HEALTH_SESSIOND_TYPE_APP_REG_DISPATCH = 7, + HEALTH_SESSIOND_TYPE_NOTIFICATION = 8, + HEALTH_SESSIOND_TYPE_ROTATION = 9, + HEALTH_SESSIOND_TYPE_TIMER = 10, + HEALTH_SESSIOND_TYPE_ACTION_EXECUTOR = 11, + + NR_HEALTH_SESSIOND_TYPES, +}; + +/* Application health monitoring */ +extern struct health_app *the_health_sessiond; + +bool launch_health_management_thread(void); + +#endif /* HEALTH_SESSIOND_H */ diff --git a/src/bin/lttng-sessiond/health.cpp b/src/bin/lttng-sessiond/health.cpp index 53b9ee01f..a7f4bdcbb 100644 --- a/src/bin/lttng-sessiond/health.cpp +++ b/src/bin/lttng-sessiond/health.cpp @@ -6,16 +6,16 @@ * */ -#include "lttng-sessiond.h" -#include "health-sessiond.h" -#include -#include -#include -#include +#include "lttng-sessiond.hpp" +#include "health-sessiond.hpp" +#include +#include +#include +#include #include #include -#include "utils.h" -#include "thread.h" +#include "utils.hpp" +#include "thread.hpp" struct thread_notifiers { struct lttng_pipe *quit_pipe; diff --git a/src/bin/lttng-sessiond/kern-modules.h b/src/bin/lttng-sessiond/kern-modules.h deleted file mode 100644 index d91436256..000000000 --- a/src/bin/lttng-sessiond/kern-modules.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2011 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _KERN_MODULES_H -#define _KERN_MODULES_H - -/* - * Compatible lttng-modules version. - */ -#define KERN_MODULES_PRE_MAJOR 1 -#define KERN_MODULES_PRE_MINOR 9 - -#define KERN_MODULES_MAJOR 2 -#define KERN_MODULES_MINOR 0 - -enum kernel_module_property_load_policy { - KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED = 0, - KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL = 1, -}; - -struct kern_modules_param { - char *name; - enum kernel_module_property_load_policy load_policy; - bool loaded; -}; - -#endif /* _KERN_MODULES_H */ diff --git a/src/bin/lttng-sessiond/kern-modules.hpp b/src/bin/lttng-sessiond/kern-modules.hpp new file mode 100644 index 000000000..d91436256 --- /dev/null +++ b/src/bin/lttng-sessiond/kern-modules.hpp @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2011 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _KERN_MODULES_H +#define _KERN_MODULES_H + +/* + * Compatible lttng-modules version. + */ +#define KERN_MODULES_PRE_MAJOR 1 +#define KERN_MODULES_PRE_MINOR 9 + +#define KERN_MODULES_MAJOR 2 +#define KERN_MODULES_MINOR 0 + +enum kernel_module_property_load_policy { + KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED = 0, + KERNEL_MODULE_PROPERTY_LOAD_POLICY_OPTIONAL = 1, +}; + +struct kern_modules_param { + char *name; + enum kernel_module_property_load_policy load_policy; + bool loaded; +}; + +#endif /* _KERN_MODULES_H */ diff --git a/src/bin/lttng-sessiond/kernel-consumer.cpp b/src/bin/lttng-sessiond/kernel-consumer.cpp index d224b4cb7..844f53541 100644 --- a/src/bin/lttng-sessiond/kernel-consumer.cpp +++ b/src/bin/lttng-sessiond/kernel-consumer.cpp @@ -12,16 +12,16 @@ #include #include -#include -#include -#include - -#include "consumer.h" -#include "health-sessiond.h" -#include "kernel-consumer.h" -#include "notification-thread-commands.h" -#include "session.h" -#include "lttng-sessiond.h" +#include +#include +#include + +#include "consumer.hpp" +#include "health-sessiond.hpp" +#include "kernel-consumer.hpp" +#include "notification-thread-commands.hpp" +#include "session.hpp" +#include "lttng-sessiond.hpp" static char *create_channel_path(struct consumer_output *consumer, size_t *consumer_path_offset) diff --git a/src/bin/lttng-sessiond/kernel-consumer.h b/src/bin/lttng-sessiond/kernel-consumer.h deleted file mode 100644 index 31771703e..000000000 --- a/src/bin/lttng-sessiond/kernel-consumer.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2012 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#include - -#include - -#include "trace-kernel.h" - -int kernel_consumer_send_channel_streams(struct consumer_socket *sock, - struct ltt_kernel_channel *channel, struct ltt_kernel_session *session, - unsigned int monitor); - -int kernel_consumer_send_session(struct consumer_socket *sock, - struct ltt_kernel_session *session); - -int kernel_consumer_add_metadata(struct consumer_socket *sock, - struct ltt_kernel_session *session, unsigned int monitor); - -int kernel_consumer_destroy_channel(struct consumer_socket *socket, - struct ltt_kernel_channel *channel); - -int kernel_consumer_destroy_metadata(struct consumer_socket *socket, - struct ltt_kernel_metadata *metadata); - -int kernel_consumer_streams_sent(struct consumer_socket *sock, - struct ltt_kernel_session *session, uint64_t channel_key); diff --git a/src/bin/lttng-sessiond/kernel-consumer.hpp b/src/bin/lttng-sessiond/kernel-consumer.hpp new file mode 100644 index 000000000..276312e6c --- /dev/null +++ b/src/bin/lttng-sessiond/kernel-consumer.hpp @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2012 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include + +#include + +#include "trace-kernel.hpp" + +int kernel_consumer_send_channel_streams(struct consumer_socket *sock, + struct ltt_kernel_channel *channel, struct ltt_kernel_session *session, + unsigned int monitor); + +int kernel_consumer_send_session(struct consumer_socket *sock, + struct ltt_kernel_session *session); + +int kernel_consumer_add_metadata(struct consumer_socket *sock, + struct ltt_kernel_session *session, unsigned int monitor); + +int kernel_consumer_destroy_channel(struct consumer_socket *socket, + struct ltt_kernel_channel *channel); + +int kernel_consumer_destroy_metadata(struct consumer_socket *socket, + struct ltt_kernel_metadata *metadata); + +int kernel_consumer_streams_sent(struct consumer_socket *sock, + struct ltt_kernel_session *session, uint64_t channel_key); diff --git a/src/bin/lttng-sessiond/kernel.cpp b/src/bin/lttng-sessiond/kernel.cpp index c4662af0d..9d256e207 100644 --- a/src/bin/lttng-sessiond/kernel.cpp +++ b/src/bin/lttng-sessiond/kernel.cpp @@ -14,40 +14,40 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include -#include +#include #include -#include +#include #include -#include -#include - -#include "event-notifier-error-accounting.h" -#include "lttng-sessiond.h" -#include "lttng-syscall.h" -#include "condition-internal.h" -#include "consumer.h" -#include "kernel.h" -#include "kernel-consumer.h" -#include "kern-modules.h" -#include "sessiond-config.h" -#include "utils.h" -#include "rotate.h" -#include "modprobe.h" -#include "tracker.h" -#include "notification-thread-commands.h" +#include +#include + +#include "event-notifier-error-accounting.hpp" +#include "lttng-sessiond.hpp" +#include "lttng-syscall.hpp" +#include "condition-internal.hpp" +#include "consumer.hpp" +#include "kernel.hpp" +#include "kernel-consumer.hpp" +#include "kern-modules.hpp" +#include "sessiond-config.hpp" +#include "utils.hpp" +#include "rotate.hpp" +#include "modprobe.hpp" +#include "tracker.hpp" +#include "notification-thread-commands.hpp" /* * Key used to reference a channel between the sessiond and the consumer. This diff --git a/src/bin/lttng-sessiond/kernel.h b/src/bin/lttng-sessiond/kernel.h deleted file mode 100644 index 4eb788d5c..000000000 --- a/src/bin/lttng-sessiond/kernel.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _LTT_KERNEL_CTL_H -#define _LTT_KERNEL_CTL_H - -#include "lttng/lttng-error.h" -#include "lttng/tracker.h" -#include "session.h" -#include "snapshot.h" -#include "trace-kernel.h" - -/* - * Default size for the event list when kernel_list_events is called. This size - * value is based on the initial LTTng 2.0 version set of tracepoints. - * - * This is NOT an upper bound because if the real event list size is bigger, - * dynamic reallocation is performed. - */ -#define KERNEL_EVENT_INIT_LIST_SIZE 64 - -int kernel_add_channel_context(struct ltt_kernel_channel *chan, - struct ltt_kernel_context *ctx); -int kernel_create_session(struct ltt_session *session); -int kernel_create_channel(struct ltt_kernel_session *session, - struct lttng_channel *chan); -int kernel_create_event(struct lttng_event *ev, struct ltt_kernel_channel *channel, - char *filter_expression, struct lttng_bytecode *filter); -int kernel_disable_channel(struct ltt_kernel_channel *chan); -int kernel_disable_event(struct ltt_kernel_event *event); -int kernel_enable_event(struct ltt_kernel_event *event); -int kernel_enable_channel(struct ltt_kernel_channel *chan); -enum lttng_error_code kernel_process_attr_tracker_set_tracking_policy( - struct ltt_kernel_session *session, - enum lttng_process_attr process_attr, - enum lttng_tracking_policy policy); -enum lttng_error_code kernel_process_attr_tracker_inclusion_set_add_value( - struct ltt_kernel_session *session, - enum lttng_process_attr process_attr, - const struct process_attr_value *value); -enum lttng_error_code kernel_process_attr_tracker_inclusion_set_remove_value( - struct ltt_kernel_session *session, - enum lttng_process_attr process_attr, - const struct process_attr_value *value); -const struct process_attr_tracker *kernel_get_process_attr_tracker( - struct ltt_kernel_session *session, - enum lttng_process_attr process_attr); -int kernel_open_metadata(struct ltt_kernel_session *session); -int kernel_open_metadata_stream(struct ltt_kernel_session *session); -int kernel_open_channel_stream(struct ltt_kernel_channel *channel); -int kernel_flush_buffer(struct ltt_kernel_channel *channel); -int kernel_metadata_flush_buffer(int fd); -int kernel_start_session(struct ltt_kernel_session *session); -int kernel_stop_session(struct ltt_kernel_session *session); -ssize_t kernel_list_events(struct lttng_event **event_list); -void kernel_wait_quiescent(void); -int kernel_validate_version(struct lttng_kernel_abi_tracer_version *kernel_tracer_version, - struct lttng_kernel_abi_tracer_abi_version *kernel_tracer_abi_version); -void kernel_destroy_session(struct ltt_kernel_session *ksess); -void kernel_free_session(struct ltt_kernel_session *ksess); -void kernel_destroy_channel(struct ltt_kernel_channel *kchan); -enum lttng_error_code kernel_snapshot_record( - struct ltt_kernel_session *ksess, - const struct consumer_output *output, - uint64_t nb_packets_per_stream); -int kernel_syscall_mask(int chan_fd, char **syscall_mask, uint32_t *nr_bits); -enum lttng_error_code kernel_rotate_session(struct ltt_session *session); -enum lttng_error_code kernel_clear_session(struct ltt_session *session); - -int init_kernel_workarounds(void); -int kernel_supports_ring_buffer_snapshot_sample_positions(void); -int kernel_supports_ring_buffer_packet_sequence_number(void); -int kernel_supports_event_notifiers(void); -int init_kernel_tracer(void); -void cleanup_kernel_tracer(void); -bool kernel_tracer_is_initialized(void); - -enum lttng_error_code kernel_create_channel_subdirectories( - const struct ltt_kernel_session *ksess); - -enum lttng_error_code kernel_create_event_notifier_group_notification_fd( - int *event_notifier_group_notification_fd); -enum lttng_error_code kernel_destroy_event_notifier_group_notification_fd( - int event_notifier_group_notification_fd); - -enum lttng_error_code kernel_register_event_notifier( - struct lttng_trigger *trigger, - const struct lttng_credentials *cmd_creds); -enum lttng_error_code kernel_unregister_event_notifier( - const struct lttng_trigger *trigger); - -int kernel_get_notification_fd(void); - -#endif /* _LTT_KERNEL_CTL_H */ diff --git a/src/bin/lttng-sessiond/kernel.hpp b/src/bin/lttng-sessiond/kernel.hpp new file mode 100644 index 000000000..bb0165121 --- /dev/null +++ b/src/bin/lttng-sessiond/kernel.hpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _LTT_KERNEL_CTL_H +#define _LTT_KERNEL_CTL_H + +#include "lttng/lttng-error.h" +#include "lttng/tracker.h" +#include "session.hpp" +#include "snapshot.hpp" +#include "trace-kernel.hpp" + +/* + * Default size for the event list when kernel_list_events is called. This size + * value is based on the initial LTTng 2.0 version set of tracepoints. + * + * This is NOT an upper bound because if the real event list size is bigger, + * dynamic reallocation is performed. + */ +#define KERNEL_EVENT_INIT_LIST_SIZE 64 + +int kernel_add_channel_context(struct ltt_kernel_channel *chan, + struct ltt_kernel_context *ctx); +int kernel_create_session(struct ltt_session *session); +int kernel_create_channel(struct ltt_kernel_session *session, + struct lttng_channel *chan); +int kernel_create_event(struct lttng_event *ev, struct ltt_kernel_channel *channel, + char *filter_expression, struct lttng_bytecode *filter); +int kernel_disable_channel(struct ltt_kernel_channel *chan); +int kernel_disable_event(struct ltt_kernel_event *event); +int kernel_enable_event(struct ltt_kernel_event *event); +int kernel_enable_channel(struct ltt_kernel_channel *chan); +enum lttng_error_code kernel_process_attr_tracker_set_tracking_policy( + struct ltt_kernel_session *session, + enum lttng_process_attr process_attr, + enum lttng_tracking_policy policy); +enum lttng_error_code kernel_process_attr_tracker_inclusion_set_add_value( + struct ltt_kernel_session *session, + enum lttng_process_attr process_attr, + const struct process_attr_value *value); +enum lttng_error_code kernel_process_attr_tracker_inclusion_set_remove_value( + struct ltt_kernel_session *session, + enum lttng_process_attr process_attr, + const struct process_attr_value *value); +const struct process_attr_tracker *kernel_get_process_attr_tracker( + struct ltt_kernel_session *session, + enum lttng_process_attr process_attr); +int kernel_open_metadata(struct ltt_kernel_session *session); +int kernel_open_metadata_stream(struct ltt_kernel_session *session); +int kernel_open_channel_stream(struct ltt_kernel_channel *channel); +int kernel_flush_buffer(struct ltt_kernel_channel *channel); +int kernel_metadata_flush_buffer(int fd); +int kernel_start_session(struct ltt_kernel_session *session); +int kernel_stop_session(struct ltt_kernel_session *session); +ssize_t kernel_list_events(struct lttng_event **event_list); +void kernel_wait_quiescent(void); +int kernel_validate_version(struct lttng_kernel_abi_tracer_version *kernel_tracer_version, + struct lttng_kernel_abi_tracer_abi_version *kernel_tracer_abi_version); +void kernel_destroy_session(struct ltt_kernel_session *ksess); +void kernel_free_session(struct ltt_kernel_session *ksess); +void kernel_destroy_channel(struct ltt_kernel_channel *kchan); +enum lttng_error_code kernel_snapshot_record( + struct ltt_kernel_session *ksess, + const struct consumer_output *output, + uint64_t nb_packets_per_stream); +int kernel_syscall_mask(int chan_fd, char **syscall_mask, uint32_t *nr_bits); +enum lttng_error_code kernel_rotate_session(struct ltt_session *session); +enum lttng_error_code kernel_clear_session(struct ltt_session *session); + +int init_kernel_workarounds(void); +int kernel_supports_ring_buffer_snapshot_sample_positions(void); +int kernel_supports_ring_buffer_packet_sequence_number(void); +int kernel_supports_event_notifiers(void); +int init_kernel_tracer(void); +void cleanup_kernel_tracer(void); +bool kernel_tracer_is_initialized(void); + +enum lttng_error_code kernel_create_channel_subdirectories( + const struct ltt_kernel_session *ksess); + +enum lttng_error_code kernel_create_event_notifier_group_notification_fd( + int *event_notifier_group_notification_fd); +enum lttng_error_code kernel_destroy_event_notifier_group_notification_fd( + int event_notifier_group_notification_fd); + +enum lttng_error_code kernel_register_event_notifier( + struct lttng_trigger *trigger, + const struct lttng_credentials *cmd_creds); +enum lttng_error_code kernel_unregister_event_notifier( + const struct lttng_trigger *trigger); + +int kernel_get_notification_fd(void); + +#endif /* _LTT_KERNEL_CTL_H */ diff --git a/src/bin/lttng-sessiond/lttng-sessiond.h b/src/bin/lttng-sessiond/lttng-sessiond.h deleted file mode 100644 index 5dad32fc9..000000000 --- a/src/bin/lttng-sessiond/lttng-sessiond.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * Copyright (C) 2013 Raphaël Beamonte - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _LTT_SESSIOND_H -#define _LTT_SESSIOND_H - -#include -#include - -#include -#include -#include -#include -#include - -#include "session.h" -#include "ust-app.h" -#include "notification-thread.h" -#include "sessiond-config.h" - -/* - * Consumer daemon state which is changed when spawning it, killing it or in - * case of a fatal error. - */ -enum consumerd_state { - CONSUMER_STARTED = 1, - CONSUMER_STOPPED = 2, - CONSUMER_ERROR = 3, -}; - -/* Unique identifier of a session daemon instance. */ -extern lttng_uuid the_sessiond_uuid; - -/* - * This consumer daemon state is used to validate if a client command will be - * able to reach the consumer. If not, the client is informed. For instance, - * doing a "lttng start" when the consumer state is set to ERROR will return an - * error to the client. - * - * The following example shows a possible race condition of this scheme: - * - * consumer thread error happens - * client cmd arrives - * client cmd checks state -> still OK - * consumer thread exit, sets error - * client cmd try to talk to consumer - * ... - * - * However, since the consumer is a different daemon, we have no way of making - * sure the command will reach it safely even with this state flag. This is why - * we consider that up to the state validation during command processing, the - * command is safe. After that, we can not guarantee the correctness of the - * client request vis-a-vis the consumer. - */ -extern enum consumerd_state the_ust_consumerd_state; -extern enum consumerd_state the_kernel_consumerd_state; - -/* Set in main.c at boot time of the daemon */ -extern struct lttng_kernel_abi_tracer_version the_kernel_tracer_version; -extern struct lttng_kernel_abi_tracer_abi_version the_kernel_tracer_abi_version; - -/* Notification thread handle. */ -extern struct notification_thread_handle *the_notification_thread_handle; - -/* - * This contains extra data needed for processing a command received by the - * session daemon from the lttng client. - */ -struct command_ctx { - unsigned int lttng_msg_size; - struct ltt_session *session; - /* Input message */ - struct lttcomm_session_msg lsm; - /* Reply content, starts with an lttcomm_lttng_msg header. */ - struct lttng_payload reply_payload; - lttng_sock_cred creds; -}; - -struct ust_command { - int sock; - struct ust_register_msg reg_msg; - struct cds_wfcq_node node; -}; - -/* - * Queue used to enqueue UST registration request (ust_command) and synchronized - * by a futex with a scheme N wakers / 1 waiters. See futex.c/.h - */ -struct ust_cmd_queue { - int32_t futex; - struct cds_wfcq_head head; - struct cds_wfcq_tail tail; -}; - -/* - * This is the wait queue containing wait nodes during the application - * registration process. - */ -struct ust_reg_wait_queue { - unsigned long count; - struct cds_list_head head; -}; - -/* - * Use by the dispatch registration to queue UST command socket to wait for the - * notify socket. - */ -struct ust_reg_wait_node { - struct ust_app *app; - struct cds_list_head head; -}; - -extern int the_kernel_poll_pipe[2]; - -/* - * Populated when the daemon starts with the current page size of the system. - * Set in main() with the current page size. - */ -extern long the_page_size; - -/* Application health monitoring */ -extern struct health_app *the_health_sessiond; - -extern struct sessiond_config the_config; - -extern int the_ust_consumerd64_fd, the_ust_consumerd32_fd; - -/* Parent PID for --sig-parent option */ -extern pid_t the_ppid; -/* Internal parent PID use with daemonize. */ -extern pid_t the_child_ppid; - -/* Consumer daemon specific control data. */ -extern struct consumer_data the_ustconsumer32_data; -extern struct consumer_data the_ustconsumer64_data; -extern struct consumer_data the_kconsumer_data; - -int sessiond_init_thread_quit_pipe(void); -int sessiond_check_thread_quit_pipe(int fd, uint32_t events); -int sessiond_wait_for_quit_pipe(int timeout_ms); -int sessiond_notify_quit_pipe(void); -void sessiond_close_quit_pipe(void); - -int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size); -void sessiond_signal_parents(void); - -void sessiond_set_client_thread_state(bool running); -void sessiond_wait_client_thread_stopped(void); - -void *thread_manage_consumer(void *data); - -#endif /* _LTT_SESSIOND_H */ diff --git a/src/bin/lttng-sessiond/lttng-sessiond.hpp b/src/bin/lttng-sessiond/lttng-sessiond.hpp new file mode 100644 index 000000000..fa4601d69 --- /dev/null +++ b/src/bin/lttng-sessiond/lttng-sessiond.hpp @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * Copyright (C) 2013 Raphaël Beamonte + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _LTT_SESSIOND_H +#define _LTT_SESSIOND_H + +#include +#include + +#include +#include +#include +#include +#include + +#include "session.hpp" +#include "ust-app.hpp" +#include "notification-thread.hpp" +#include "sessiond-config.hpp" + +/* + * Consumer daemon state which is changed when spawning it, killing it or in + * case of a fatal error. + */ +enum consumerd_state { + CONSUMER_STARTED = 1, + CONSUMER_STOPPED = 2, + CONSUMER_ERROR = 3, +}; + +/* Unique identifier of a session daemon instance. */ +extern lttng_uuid the_sessiond_uuid; + +/* + * This consumer daemon state is used to validate if a client command will be + * able to reach the consumer. If not, the client is informed. For instance, + * doing a "lttng start" when the consumer state is set to ERROR will return an + * error to the client. + * + * The following example shows a possible race condition of this scheme: + * + * consumer thread error happens + * client cmd arrives + * client cmd checks state -> still OK + * consumer thread exit, sets error + * client cmd try to talk to consumer + * ... + * + * However, since the consumer is a different daemon, we have no way of making + * sure the command will reach it safely even with this state flag. This is why + * we consider that up to the state validation during command processing, the + * command is safe. After that, we can not guarantee the correctness of the + * client request vis-a-vis the consumer. + */ +extern enum consumerd_state the_ust_consumerd_state; +extern enum consumerd_state the_kernel_consumerd_state; + +/* Set in main.c at boot time of the daemon */ +extern struct lttng_kernel_abi_tracer_version the_kernel_tracer_version; +extern struct lttng_kernel_abi_tracer_abi_version the_kernel_tracer_abi_version; + +/* Notification thread handle. */ +extern struct notification_thread_handle *the_notification_thread_handle; + +/* + * This contains extra data needed for processing a command received by the + * session daemon from the lttng client. + */ +struct command_ctx { + unsigned int lttng_msg_size; + struct ltt_session *session; + /* Input message */ + struct lttcomm_session_msg lsm; + /* Reply content, starts with an lttcomm_lttng_msg header. */ + struct lttng_payload reply_payload; + lttng_sock_cred creds; +}; + +struct ust_command { + int sock; + struct ust_register_msg reg_msg; + struct cds_wfcq_node node; +}; + +/* + * Queue used to enqueue UST registration request (ust_command) and synchronized + * by a futex with a scheme N wakers / 1 waiters. See futex.c/.h + */ +struct ust_cmd_queue { + int32_t futex; + struct cds_wfcq_head head; + struct cds_wfcq_tail tail; +}; + +/* + * This is the wait queue containing wait nodes during the application + * registration process. + */ +struct ust_reg_wait_queue { + unsigned long count; + struct cds_list_head head; +}; + +/* + * Use by the dispatch registration to queue UST command socket to wait for the + * notify socket. + */ +struct ust_reg_wait_node { + struct ust_app *app; + struct cds_list_head head; +}; + +extern int the_kernel_poll_pipe[2]; + +/* + * Populated when the daemon starts with the current page size of the system. + * Set in main() with the current page size. + */ +extern long the_page_size; + +/* Application health monitoring */ +extern struct health_app *the_health_sessiond; + +extern struct sessiond_config the_config; + +extern int the_ust_consumerd64_fd, the_ust_consumerd32_fd; + +/* Parent PID for --sig-parent option */ +extern pid_t the_ppid; +/* Internal parent PID use with daemonize. */ +extern pid_t the_child_ppid; + +/* Consumer daemon specific control data. */ +extern struct consumer_data the_ustconsumer32_data; +extern struct consumer_data the_ustconsumer64_data; +extern struct consumer_data the_kconsumer_data; + +int sessiond_init_thread_quit_pipe(void); +int sessiond_check_thread_quit_pipe(int fd, uint32_t events); +int sessiond_wait_for_quit_pipe(int timeout_ms); +int sessiond_notify_quit_pipe(void); +void sessiond_close_quit_pipe(void); + +int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size); +void sessiond_signal_parents(void); + +void sessiond_set_client_thread_state(bool running); +void sessiond_wait_client_thread_stopped(void); + +void *thread_manage_consumer(void *data); + +#endif /* _LTT_SESSIOND_H */ diff --git a/src/bin/lttng-sessiond/lttng-syscall.cpp b/src/bin/lttng-sessiond/lttng-syscall.cpp index 42e902b5e..d7f6327ae 100644 --- a/src/bin/lttng-sessiond/lttng-syscall.cpp +++ b/src/bin/lttng-sessiond/lttng-syscall.cpp @@ -8,13 +8,13 @@ #define _LGPL_SOURCE #include -#include -#include +#include +#include -#include "lttng-sessiond.h" -#include "kernel.h" -#include "lttng-syscall.h" -#include "utils.h" +#include "lttng-sessiond.hpp" +#include "kernel.hpp" +#include "lttng-syscall.hpp" +#include "utils.hpp" /* Global syscall table. */ struct syscall *syscall_table; diff --git a/src/bin/lttng-sessiond/lttng-syscall.h b/src/bin/lttng-sessiond/lttng-syscall.h deleted file mode 100644 index fa77c7083..000000000 --- a/src/bin/lttng-sessiond/lttng-syscall.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2014 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef LTTNG_SYSCALL_H -#define LTTNG_SYSCALL_H - -#include -#include - -#include "trace-kernel.h" - -/* - * Default size of the kernel system call array. With this size, we usually - * reallocate twice considering a 32 bit compat layer also. - */ -#define SYSCALL_TABLE_INIT_SIZE 256 - -/* Maximum length of a syscall name. */ -#define SYSCALL_NAME_LEN 255 - -/* - * Represent a kernel syscall and used when we are populating the internal - * list. - */ -struct syscall { - uint32_t index; - uint32_t bitness; - char name[SYSCALL_NAME_LEN]; - /* Used by the list syscalls command. */ - struct lttng_ht_node_str node; -}; - -/* - * Allocated once when listing all syscalls at boot time. This is an array - * indexed by the syscall index provided in the listing. - */ -extern struct syscall *syscall_table; - -/* Use to list kernel system calls. */ -int syscall_init_table(int tracer_fd); -ssize_t syscall_table_list(struct lttng_event **events); - -#endif /* LTTNG_SYSCALL_H */ diff --git a/src/bin/lttng-sessiond/lttng-syscall.hpp b/src/bin/lttng-sessiond/lttng-syscall.hpp new file mode 100644 index 000000000..78691f95d --- /dev/null +++ b/src/bin/lttng-sessiond/lttng-syscall.hpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2014 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef LTTNG_SYSCALL_H +#define LTTNG_SYSCALL_H + +#include +#include + +#include "trace-kernel.hpp" + +/* + * Default size of the kernel system call array. With this size, we usually + * reallocate twice considering a 32 bit compat layer also. + */ +#define SYSCALL_TABLE_INIT_SIZE 256 + +/* Maximum length of a syscall name. */ +#define SYSCALL_NAME_LEN 255 + +/* + * Represent a kernel syscall and used when we are populating the internal + * list. + */ +struct syscall { + uint32_t index; + uint32_t bitness; + char name[SYSCALL_NAME_LEN]; + /* Used by the list syscalls command. */ + struct lttng_ht_node_str node; +}; + +/* + * Allocated once when listing all syscalls at boot time. This is an array + * indexed by the syscall index provided in the listing. + */ +extern struct syscall *syscall_table; + +/* Use to list kernel system calls. */ +int syscall_init_table(int tracer_fd); +ssize_t syscall_table_list(struct lttng_event **events); + +#endif /* LTTNG_SYSCALL_H */ diff --git a/src/bin/lttng-sessiond/lttng-ust-abi.h b/src/bin/lttng-sessiond/lttng-ust-abi.h deleted file mode 100644 index e2b8cf919..000000000 --- a/src/bin/lttng-sessiond/lttng-ust-abi.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2019 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef LTTNG_UST_ABI_H -#define LTTNG_UST_ABI_H - -#ifdef HAVE_LIBLTTNG_UST_CTL -#include -#else /* HAVE_LIBLTTNG_UST_CTL */ -/* Use local copy of the LTTng-UST header. */ -#include "ust-abi-internal.h" -#endif /* HAVE_LIBLTTNG_UST_CTL */ - -#endif /* LTTNG_UST_ABI_H */ diff --git a/src/bin/lttng-sessiond/lttng-ust-abi.hpp b/src/bin/lttng-sessiond/lttng-ust-abi.hpp new file mode 100644 index 000000000..faf232190 --- /dev/null +++ b/src/bin/lttng-sessiond/lttng-ust-abi.hpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2019 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef LTTNG_UST_ABI_H +#define LTTNG_UST_ABI_H + +#ifdef HAVE_LIBLTTNG_UST_CTL +#include +#else /* HAVE_LIBLTTNG_UST_CTL */ +/* Use local copy of the LTTng-UST header. */ +#include "ust-abi-internal.hpp" +#endif /* HAVE_LIBLTTNG_UST_CTL */ + +#endif /* LTTNG_UST_ABI_H */ diff --git a/src/bin/lttng-sessiond/lttng-ust-ctl.h b/src/bin/lttng-sessiond/lttng-ust-ctl.h deleted file mode 100644 index 7e5713be2..000000000 --- a/src/bin/lttng-sessiond/lttng-ust-ctl.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2019 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef LTTNG_UST_CTL_H -#define LTTNG_UST_CTL_H - -#ifdef HAVE_LIBLTTNG_UST_CTL -#include -#else /* HAVE_LIBLTTNG_UST_CTL */ -/* Use local copy of the LTTng-UST header. */ -#include "ust-ctl-internal.h" -#endif /* HAVE_LIBLTTNG_UST_CTL */ - -#endif /* LTTNG_UST_CTL_H */ diff --git a/src/bin/lttng-sessiond/lttng-ust-ctl.hpp b/src/bin/lttng-sessiond/lttng-ust-ctl.hpp new file mode 100644 index 000000000..dcd6bf640 --- /dev/null +++ b/src/bin/lttng-sessiond/lttng-ust-ctl.hpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2019 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef LTTNG_UST_CTL_H +#define LTTNG_UST_CTL_H + +#ifdef HAVE_LIBLTTNG_UST_CTL +#include +#else /* HAVE_LIBLTTNG_UST_CTL */ +/* Use local copy of the LTTng-UST header. */ +#include "ust-ctl-internal.hpp" +#endif /* HAVE_LIBLTTNG_UST_CTL */ + +#endif /* LTTNG_UST_CTL_H */ diff --git a/src/bin/lttng-sessiond/lttng-ust-error.h b/src/bin/lttng-sessiond/lttng-ust-error.h deleted file mode 100644 index 326383b9f..000000000 --- a/src/bin/lttng-sessiond/lttng-ust-error.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2019 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef LTTNG_UST_ERROR_H -#define LTTNG_UST_ERROR_H - -#ifdef HAVE_LIBLTTNG_UST_CTL -#include -#else /* HAVE_LIBLTTNG_UST_CTL */ -/* Use local copy of the LTTng-UST header. */ -#include "ust-error-internal.h" -#endif /* HAVE_LIBLTTNG_UST_CTL */ - -#endif /* LTTNG_UST_ERROR_H */ diff --git a/src/bin/lttng-sessiond/lttng-ust-error.hpp b/src/bin/lttng-sessiond/lttng-ust-error.hpp new file mode 100644 index 000000000..173908e4d --- /dev/null +++ b/src/bin/lttng-sessiond/lttng-ust-error.hpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2019 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef LTTNG_UST_ERROR_H +#define LTTNG_UST_ERROR_H + +#ifdef HAVE_LIBLTTNG_UST_CTL +#include +#else /* HAVE_LIBLTTNG_UST_CTL */ +/* Use local copy of the LTTng-UST header. */ +#include "ust-error-internal.hpp" +#endif /* HAVE_LIBLTTNG_UST_CTL */ + +#endif /* LTTNG_UST_ERROR_H */ diff --git a/src/bin/lttng-sessiond/main.cpp b/src/bin/lttng-sessiond/main.cpp index 34e881c4d..cf7aa9e9e 100644 --- a/src/bin/lttng-sessiond/main.cpp +++ b/src/bin/lttng-sessiond/main.cpp @@ -29,54 +29,53 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "lttng-sessiond.h" -#include "buffer-registry.h" -#include "channel.h" -#include "cmd.h" -#include "consumer.h" -#include "context.h" -#include "event.h" -#include "event-notifier-error-accounting.h" -#include "kernel.h" -#include "kernel-consumer.h" -#include "lttng-ust-ctl.h" -#include "ust-consumer.h" -#include "utils.h" -#include "fd-limit.h" -#include "health-sessiond.h" -#include "testpoint.h" -#include "notify-apps.h" -#include "agent-thread.h" -#include "save.h" -#include "notification-thread.h" -#include "notification-thread-commands.h" -#include "rotation-thread.h" -#include "agent.h" -#include "sessiond-config.h" -#include "timer.h" -#include "thread.h" -#include "client.h" -#include "dispatch.h" -#include "register.h" -#include "manage-apps.h" -#include "manage-kernel.h" -#include "modprobe.h" -#include "ust-sigbus.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lttng-sessiond.hpp" +#include "buffer-registry.hpp" +#include "channel.hpp" +#include "cmd.hpp" +#include "consumer.hpp" +#include "context.hpp" +#include "event.hpp" +#include "event-notifier-error-accounting.hpp" +#include "kernel.hpp" +#include "kernel-consumer.hpp" +#include "lttng-ust-ctl.hpp" +#include "ust-consumer.hpp" +#include "utils.hpp" +#include "fd-limit.hpp" +#include "health-sessiond.hpp" +#include "testpoint.hpp" +#include "notify-apps.hpp" +#include "agent-thread.hpp" +#include "save.hpp" +#include "notification-thread.hpp" +#include "notification-thread-commands.hpp" +#include "rotation-thread.hpp" +#include "agent.hpp" +#include "sessiond-config.hpp" +#include "timer.hpp" +#include "thread.hpp" +#include "client.hpp" +#include "dispatch.hpp" +#include "register.hpp" +#include "manage-apps.hpp" +#include "manage-kernel.hpp" +#include "modprobe.hpp" +#include "ust-sigbus.hpp" static const char *help_msg = #ifdef LTTNG_EMBED_HELP diff --git a/src/bin/lttng-sessiond/manage-apps.cpp b/src/bin/lttng-sessiond/manage-apps.cpp index 588e83b6c..4ee3538b2 100644 --- a/src/bin/lttng-sessiond/manage-apps.cpp +++ b/src/bin/lttng-sessiond/manage-apps.cpp @@ -7,11 +7,11 @@ * */ -#include "manage-apps.h" -#include "testpoint.h" -#include "health-sessiond.h" -#include "utils.h" -#include "thread.h" +#include "manage-apps.hpp" +#include "testpoint.hpp" +#include "health-sessiond.hpp" +#include "utils.hpp" +#include "thread.hpp" struct thread_notifiers { struct lttng_pipe *quit_pipe; diff --git a/src/bin/lttng-sessiond/manage-apps.h b/src/bin/lttng-sessiond/manage-apps.h deleted file mode 100644 index 3cd3b9c33..000000000 --- a/src/bin/lttng-sessiond/manage-apps.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * Copyright (C) 2011 Mathieu Desnoyers - * Copyright (C) 2013 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef SESSIOND_APPLICATION_MANAGEMENT_THREAD_H -#define SESSIOND_APPLICATION_MANAGEMENT_THREAD_H - -#include -#include "lttng-sessiond.h" - -bool launch_application_management_thread(int apps_cmd_pipe_read_fd); - -#endif /* SESSIOND_APPLICATION_MANAGEMENT_THREAD_H */ diff --git a/src/bin/lttng-sessiond/manage-apps.hpp b/src/bin/lttng-sessiond/manage-apps.hpp new file mode 100644 index 000000000..a865d9a8f --- /dev/null +++ b/src/bin/lttng-sessiond/manage-apps.hpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * Copyright (C) 2011 Mathieu Desnoyers + * Copyright (C) 2013 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef SESSIOND_APPLICATION_MANAGEMENT_THREAD_H +#define SESSIOND_APPLICATION_MANAGEMENT_THREAD_H + +#include +#include "lttng-sessiond.hpp" + +bool launch_application_management_thread(int apps_cmd_pipe_read_fd); + +#endif /* SESSIOND_APPLICATION_MANAGEMENT_THREAD_H */ diff --git a/src/bin/lttng-sessiond/manage-consumer.cpp b/src/bin/lttng-sessiond/manage-consumer.cpp index cce48526e..4a3e3b4ab 100644 --- a/src/bin/lttng-sessiond/manage-consumer.cpp +++ b/src/bin/lttng-sessiond/manage-consumer.cpp @@ -9,15 +9,15 @@ #include -#include -#include - -#include "manage-consumer.h" -#include "testpoint.h" -#include "health-sessiond.h" -#include "utils.h" -#include "thread.h" -#include "ust-consumer.h" +#include +#include + +#include "manage-consumer.hpp" +#include "testpoint.hpp" +#include "health-sessiond.hpp" +#include "utils.hpp" +#include "thread.hpp" +#include "ust-consumer.hpp" struct thread_notifiers { struct lttng_pipe *quit_pipe; diff --git a/src/bin/lttng-sessiond/manage-consumer.h b/src/bin/lttng-sessiond/manage-consumer.h deleted file mode 100644 index 16eb62dd9..000000000 --- a/src/bin/lttng-sessiond/manage-consumer.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * Copyright (C) 2011 Mathieu Desnoyers - * Copyright (C) 2013 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef SESSIOND_CONSUMER_MANAGEMENT_THREAD_H -#define SESSIOND_CONSUMER_MANAGEMENT_THREAD_H - -#include -#include "lttng-sessiond.h" - -bool launch_consumer_management_thread(struct consumer_data *consumer_data); - -#endif /* SESSIOND_CONSUMER_MANAGEMENT_THREAD_H */ diff --git a/src/bin/lttng-sessiond/manage-consumer.hpp b/src/bin/lttng-sessiond/manage-consumer.hpp new file mode 100644 index 000000000..9e35a9051 --- /dev/null +++ b/src/bin/lttng-sessiond/manage-consumer.hpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * Copyright (C) 2011 Mathieu Desnoyers + * Copyright (C) 2013 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef SESSIOND_CONSUMER_MANAGEMENT_THREAD_H +#define SESSIOND_CONSUMER_MANAGEMENT_THREAD_H + +#include +#include "lttng-sessiond.hpp" + +bool launch_consumer_management_thread(struct consumer_data *consumer_data); + +#endif /* SESSIOND_CONSUMER_MANAGEMENT_THREAD_H */ diff --git a/src/bin/lttng-sessiond/manage-kernel.cpp b/src/bin/lttng-sessiond/manage-kernel.cpp index a789a0b29..a5d21b0fe 100644 --- a/src/bin/lttng-sessiond/manage-kernel.cpp +++ b/src/bin/lttng-sessiond/manage-kernel.cpp @@ -7,16 +7,16 @@ * */ -#include -#include - -#include "manage-kernel.h" -#include "testpoint.h" -#include "health-sessiond.h" -#include "utils.h" -#include "thread.h" -#include "kernel.h" -#include "kernel-consumer.h" +#include +#include + +#include "manage-kernel.hpp" +#include "testpoint.hpp" +#include "health-sessiond.hpp" +#include "utils.hpp" +#include "thread.hpp" +#include "kernel.hpp" +#include "kernel-consumer.hpp" struct thread_notifiers { struct lttng_pipe *quit_pipe; diff --git a/src/bin/lttng-sessiond/manage-kernel.h b/src/bin/lttng-sessiond/manage-kernel.h deleted file mode 100644 index 3be665811..000000000 --- a/src/bin/lttng-sessiond/manage-kernel.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * Copyright (C) 2011 Mathieu Desnoyers - * Copyright (C) 2013 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef SESSIOND_KERNEL_MANAGEMENT_THREAD_H -#define SESSIOND_KERNEL_MANAGEMENT_THREAD_H - -#include -#include "lttng-sessiond.h" - -bool launch_kernel_management_thread(int kernel_poll_pipe_read_fd); - -#endif /* SESSIOND_KERNEL_MANAGEMENT_THREAD_H */ diff --git a/src/bin/lttng-sessiond/manage-kernel.hpp b/src/bin/lttng-sessiond/manage-kernel.hpp new file mode 100644 index 000000000..fe0d8b013 --- /dev/null +++ b/src/bin/lttng-sessiond/manage-kernel.hpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * Copyright (C) 2011 Mathieu Desnoyers + * Copyright (C) 2013 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef SESSIOND_KERNEL_MANAGEMENT_THREAD_H +#define SESSIOND_KERNEL_MANAGEMENT_THREAD_H + +#include +#include "lttng-sessiond.hpp" + +bool launch_kernel_management_thread(int kernel_poll_pipe_read_fd); + +#endif /* SESSIOND_KERNEL_MANAGEMENT_THREAD_H */ diff --git a/src/bin/lttng-sessiond/modprobe.cpp b/src/bin/lttng-sessiond/modprobe.cpp index 782dcc6b2..0dc123de1 100644 --- a/src/bin/lttng-sessiond/modprobe.cpp +++ b/src/bin/lttng-sessiond/modprobe.cpp @@ -18,12 +18,12 @@ #include #include -#include -#include +#include +#include -#include "modprobe.h" -#include "kern-modules.h" -#include "lttng-sessiond.h" +#include "modprobe.hpp" +#include "kern-modules.hpp" +#include "lttng-sessiond.hpp" /* LTTng kernel tracer mandatory core modules list */ struct kern_modules_param kern_modules_control_core[] = { diff --git a/src/bin/lttng-sessiond/modprobe.h b/src/bin/lttng-sessiond/modprobe.h deleted file mode 100644 index f0ad01c9c..000000000 --- a/src/bin/lttng-sessiond/modprobe.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) 2011 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _MODPROBE_H -#define _MODPROBE_H - -void modprobe_remove_lttng_all(void); -void modprobe_remove_lttng_control(void); -void modprobe_remove_lttng_data(void); -int modprobe_lttng_control(void); -int modprobe_lttng_data(void); - -#endif /* _MODPROBE_H */ diff --git a/src/bin/lttng-sessiond/modprobe.hpp b/src/bin/lttng-sessiond/modprobe.hpp new file mode 100644 index 000000000..f0ad01c9c --- /dev/null +++ b/src/bin/lttng-sessiond/modprobe.hpp @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2011 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _MODPROBE_H +#define _MODPROBE_H + +void modprobe_remove_lttng_all(void); +void modprobe_remove_lttng_control(void); +void modprobe_remove_lttng_data(void); +int modprobe_lttng_control(void); +int modprobe_lttng_data(void); + +#endif /* _MODPROBE_H */ diff --git a/src/bin/lttng-sessiond/notification-thread-commands.cpp b/src/bin/lttng-sessiond/notification-thread-commands.cpp index 600951159..ce499eb1c 100644 --- a/src/bin/lttng-sessiond/notification-thread-commands.cpp +++ b/src/bin/lttng-sessiond/notification-thread-commands.cpp @@ -7,9 +7,9 @@ #include #include -#include "notification-thread.h" -#include "notification-thread-commands.h" -#include +#include "notification-thread.hpp" +#include "notification-thread-commands.hpp" +#include #include #include #include diff --git a/src/bin/lttng-sessiond/notification-thread-commands.h b/src/bin/lttng-sessiond/notification-thread-commands.h deleted file mode 100644 index 643b0e602..000000000 --- a/src/bin/lttng-sessiond/notification-thread-commands.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef NOTIFICATION_THREAD_COMMANDS_H -#define NOTIFICATION_THREAD_COMMANDS_H - -#include -#include -#include -#include "notification-thread.h" -#include "notification-thread-internal.h" -#include "notification-thread-events.h" -#include -#include - -struct notification_thread_data; -struct lttng_trigger; - -enum notification_thread_command_type { - NOTIFICATION_COMMAND_TYPE_REGISTER_TRIGGER, - NOTIFICATION_COMMAND_TYPE_UNREGISTER_TRIGGER, - NOTIFICATION_COMMAND_TYPE_ADD_CHANNEL, - NOTIFICATION_COMMAND_TYPE_REMOVE_CHANNEL, - NOTIFICATION_COMMAND_TYPE_SESSION_ROTATION_ONGOING, - NOTIFICATION_COMMAND_TYPE_SESSION_ROTATION_COMPLETED, - NOTIFICATION_COMMAND_TYPE_ADD_TRACER_EVENT_SOURCE, - NOTIFICATION_COMMAND_TYPE_REMOVE_TRACER_EVENT_SOURCE, - NOTIFICATION_COMMAND_TYPE_LIST_TRIGGERS, - NOTIFICATION_COMMAND_TYPE_QUIT, - NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE, - NOTIFICATION_COMMAND_TYPE_GET_TRIGGER, -}; - -struct notification_thread_command { - struct cds_list_head cmd_list_node; - - enum notification_thread_command_type type; - union { - /* Register trigger. */ - struct { - struct lttng_trigger *trigger; - bool is_trigger_anonymous; - } register_trigger; - /* Unregister trigger. */ - struct { - const struct lttng_trigger *trigger; - } unregister_trigger; - /* Add channel. */ - struct { - struct { - const char *name; - uid_t uid; - gid_t gid; - } session; - struct { - const char *name; - enum lttng_domain_type domain; - uint64_t key; - uint64_t capacity; - } channel; - } add_channel; - /* Remove channel. */ - struct { - uint64_t key; - enum lttng_domain_type domain; - } remove_channel; - struct { - const char *session_name; - uid_t uid; - gid_t gid; - uint64_t trace_archive_chunk_id; - /* Weak reference. */ - struct lttng_trace_archive_location *location; - } session_rotation; - /* Add/Remove tracer event source fd. */ - struct { - int tracer_event_source_fd; - enum lttng_domain_type domain; - } tracer_event_source; - /* List triggers. */ - struct { - /* Credentials of the requesting user. */ - uid_t uid; - } list_triggers; - /* Client communication update. */ - struct { - notification_client_id id; - enum client_transmission_status status; - } client_communication_update; - - struct { - const struct lttng_trigger *trigger; - } get_trigger; - - } parameters; - - union { - struct { - struct lttng_triggers *triggers; - } list_triggers; - struct { - struct lttng_trigger *trigger; - } get_trigger; - } reply; - /* lttng_waiter on which to wait for command reply (optional). */ - struct lttng_waiter reply_waiter; - enum lttng_error_code reply_code; - bool is_async; -}; - -enum lttng_error_code notification_thread_command_register_trigger( - struct notification_thread_handle *handle, - struct lttng_trigger *trigger, - bool is_anonymous_trigger); - -enum lttng_error_code notification_thread_command_unregister_trigger( - struct notification_thread_handle *handle, - const struct lttng_trigger *trigger); - -enum lttng_error_code notification_thread_command_add_channel( - struct notification_thread_handle *handle, - char *session_name, uid_t session_uid, gid_t session_gid, - char *channel_name, uint64_t key, - enum lttng_domain_type domain, uint64_t capacity); - -enum lttng_error_code notification_thread_command_remove_channel( - struct notification_thread_handle *handle, - uint64_t key, enum lttng_domain_type domain); - -enum lttng_error_code notification_thread_command_session_rotation_ongoing( - struct notification_thread_handle *handle, - const char *session_name, uid_t session_uid, gid_t session_gid, - uint64_t trace_archive_chunk_id); - -/* Ownership of location is transferred. */ -enum lttng_error_code notification_thread_command_session_rotation_completed( - struct notification_thread_handle *handle, - const char *session_name, uid_t session_uid, gid_t session_gid, - uint64_t trace_archive_chunk_id, - struct lttng_trace_archive_location *location); - -/* - * Return the set of triggers visible to a given client. - * - * The trigger objects contained in the set are the actual trigger instances - * used by the notification subsystem (i.e. not a copy). Given that the command - * is only used to serialize the triggers, this is fine: the properties that - * are serialized are immutable over the lifetime of the triggers. - * - * Moreover, the lifetime of the trigger instances is protected through - * reference counting (references are held by the trigger set). - * - * The caller has the exclusive ownership of the returned trigger set. - */ -enum lttng_error_code notification_thread_command_list_triggers( - struct notification_thread_handle *handle, - uid_t client_uid, - struct lttng_triggers **triggers); - -/* - * The ownership of trigger_event_application_pipe is _not_ transferred to - * the notification thread. - */ -enum lttng_error_code notification_thread_command_add_tracer_event_source( - struct notification_thread_handle *handle, - int tracer_event_source_fd, - enum lttng_domain_type domain); - -enum lttng_error_code notification_thread_command_remove_tracer_event_source( - struct notification_thread_handle *handle, - int tracer_event_source_fd); - -void notification_thread_command_quit( - struct notification_thread_handle *handle); - -enum lttng_error_code notification_thread_command_get_trigger( - struct notification_thread_handle *handle, - const struct lttng_trigger *trigger, - struct lttng_trigger **real_trigger); - -#endif /* NOTIFICATION_THREAD_COMMANDS_H */ diff --git a/src/bin/lttng-sessiond/notification-thread-commands.hpp b/src/bin/lttng-sessiond/notification-thread-commands.hpp new file mode 100644 index 000000000..98b0abcee --- /dev/null +++ b/src/bin/lttng-sessiond/notification-thread-commands.hpp @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef NOTIFICATION_THREAD_COMMANDS_H +#define NOTIFICATION_THREAD_COMMANDS_H + +#include +#include +#include +#include "notification-thread.hpp" +#include "notification-thread-internal.hpp" +#include "notification-thread-events.hpp" +#include +#include + +struct notification_thread_data; +struct lttng_trigger; + +enum notification_thread_command_type { + NOTIFICATION_COMMAND_TYPE_REGISTER_TRIGGER, + NOTIFICATION_COMMAND_TYPE_UNREGISTER_TRIGGER, + NOTIFICATION_COMMAND_TYPE_ADD_CHANNEL, + NOTIFICATION_COMMAND_TYPE_REMOVE_CHANNEL, + NOTIFICATION_COMMAND_TYPE_SESSION_ROTATION_ONGOING, + NOTIFICATION_COMMAND_TYPE_SESSION_ROTATION_COMPLETED, + NOTIFICATION_COMMAND_TYPE_ADD_TRACER_EVENT_SOURCE, + NOTIFICATION_COMMAND_TYPE_REMOVE_TRACER_EVENT_SOURCE, + NOTIFICATION_COMMAND_TYPE_LIST_TRIGGERS, + NOTIFICATION_COMMAND_TYPE_QUIT, + NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE, + NOTIFICATION_COMMAND_TYPE_GET_TRIGGER, +}; + +struct notification_thread_command { + struct cds_list_head cmd_list_node; + + enum notification_thread_command_type type; + union { + /* Register trigger. */ + struct { + struct lttng_trigger *trigger; + bool is_trigger_anonymous; + } register_trigger; + /* Unregister trigger. */ + struct { + const struct lttng_trigger *trigger; + } unregister_trigger; + /* Add channel. */ + struct { + struct { + const char *name; + uid_t uid; + gid_t gid; + } session; + struct { + const char *name; + enum lttng_domain_type domain; + uint64_t key; + uint64_t capacity; + } channel; + } add_channel; + /* Remove channel. */ + struct { + uint64_t key; + enum lttng_domain_type domain; + } remove_channel; + struct { + const char *session_name; + uid_t uid; + gid_t gid; + uint64_t trace_archive_chunk_id; + /* Weak reference. */ + struct lttng_trace_archive_location *location; + } session_rotation; + /* Add/Remove tracer event source fd. */ + struct { + int tracer_event_source_fd; + enum lttng_domain_type domain; + } tracer_event_source; + /* List triggers. */ + struct { + /* Credentials of the requesting user. */ + uid_t uid; + } list_triggers; + /* Client communication update. */ + struct { + notification_client_id id; + enum client_transmission_status status; + } client_communication_update; + + struct { + const struct lttng_trigger *trigger; + } get_trigger; + + } parameters; + + union { + struct { + struct lttng_triggers *triggers; + } list_triggers; + struct { + struct lttng_trigger *trigger; + } get_trigger; + } reply; + /* lttng_waiter on which to wait for command reply (optional). */ + struct lttng_waiter reply_waiter; + enum lttng_error_code reply_code; + bool is_async; +}; + +enum lttng_error_code notification_thread_command_register_trigger( + struct notification_thread_handle *handle, + struct lttng_trigger *trigger, + bool is_anonymous_trigger); + +enum lttng_error_code notification_thread_command_unregister_trigger( + struct notification_thread_handle *handle, + const struct lttng_trigger *trigger); + +enum lttng_error_code notification_thread_command_add_channel( + struct notification_thread_handle *handle, + char *session_name, uid_t session_uid, gid_t session_gid, + char *channel_name, uint64_t key, + enum lttng_domain_type domain, uint64_t capacity); + +enum lttng_error_code notification_thread_command_remove_channel( + struct notification_thread_handle *handle, + uint64_t key, enum lttng_domain_type domain); + +enum lttng_error_code notification_thread_command_session_rotation_ongoing( + struct notification_thread_handle *handle, + const char *session_name, uid_t session_uid, gid_t session_gid, + uint64_t trace_archive_chunk_id); + +/* Ownership of location is transferred. */ +enum lttng_error_code notification_thread_command_session_rotation_completed( + struct notification_thread_handle *handle, + const char *session_name, uid_t session_uid, gid_t session_gid, + uint64_t trace_archive_chunk_id, + struct lttng_trace_archive_location *location); + +/* + * Return the set of triggers visible to a given client. + * + * The trigger objects contained in the set are the actual trigger instances + * used by the notification subsystem (i.e. not a copy). Given that the command + * is only used to serialize the triggers, this is fine: the properties that + * are serialized are immutable over the lifetime of the triggers. + * + * Moreover, the lifetime of the trigger instances is protected through + * reference counting (references are held by the trigger set). + * + * The caller has the exclusive ownership of the returned trigger set. + */ +enum lttng_error_code notification_thread_command_list_triggers( + struct notification_thread_handle *handle, + uid_t client_uid, + struct lttng_triggers **triggers); + +/* + * The ownership of trigger_event_application_pipe is _not_ transferred to + * the notification thread. + */ +enum lttng_error_code notification_thread_command_add_tracer_event_source( + struct notification_thread_handle *handle, + int tracer_event_source_fd, + enum lttng_domain_type domain); + +enum lttng_error_code notification_thread_command_remove_tracer_event_source( + struct notification_thread_handle *handle, + int tracer_event_source_fd); + +void notification_thread_command_quit( + struct notification_thread_handle *handle); + +enum lttng_error_code notification_thread_command_get_trigger( + struct notification_thread_handle *handle, + const struct lttng_trigger *trigger, + struct lttng_trigger **real_trigger); + +#endif /* NOTIFICATION_THREAD_COMMANDS_H */ diff --git a/src/bin/lttng-sessiond/notification-thread-events.cpp b/src/bin/lttng-sessiond/notification-thread-events.cpp index 9e1aa5300..67fca2a35 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.cpp +++ b/src/bin/lttng-sessiond/notification-thread-events.cpp @@ -6,46 +6,46 @@ */ #include "lttng/action/action.h" -#include "lttng/trigger/trigger-internal.h" +#include "lttng/trigger/trigger-internal.hpp" #define _LGPL_SOURCE #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include -#include "condition-internal.h" -#include "event-notifier-error-accounting.h" -#include "notification-thread.h" -#include "notification-thread-events.h" -#include "notification-thread-commands.h" -#include "lttng-sessiond.h" -#include "kernel.h" +#include "condition-internal.hpp" +#include "event-notifier-error-accounting.hpp" +#include "notification-thread.hpp" +#include "notification-thread-events.hpp" +#include "notification-thread-commands.hpp" +#include "lttng-sessiond.hpp" +#include "kernel.hpp" #define CLIENT_POLL_MASK_IN (LPOLLIN | LPOLLERR | LPOLLHUP | LPOLLRDHUP) #define CLIENT_POLL_MASK_IN_OUT (CLIENT_POLL_MASK_IN | LPOLLOUT) diff --git a/src/bin/lttng-sessiond/notification-thread-events.h b/src/bin/lttng-sessiond/notification-thread-events.h deleted file mode 100644 index 265719181..000000000 --- a/src/bin/lttng-sessiond/notification-thread-events.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef NOTIFICATION_THREAD_EVENTS_H -#define NOTIFICATION_THREAD_EVENTS_H - -#include -#include "notification-thread.h" - -/** - * Event handling function shall only return an error if - * the thread should be stopped. - */ -int handle_notification_thread_command( - struct notification_thread_handle *handle, - struct notification_thread_state *state); - -int handle_notification_thread_client_connect( - struct notification_thread_state *state); - -int handle_notification_thread_client_disconnect( - int client_fd, - struct notification_thread_state *state); - -int handle_notification_thread_client_disconnect_all( - struct notification_thread_state *state); - -int handle_notification_thread_trigger_unregister_all( - struct notification_thread_state *state); - -int handle_notification_thread_tracer_event_source_died( - struct notification_thread_state *state, - int tracer_event_source_fd); - -int handle_notification_thread_client_in( - struct notification_thread_state *state, - int socket); - -int handle_notification_thread_client_out( - struct notification_thread_state *state, - int socket); - -int handle_notification_thread_channel_sample( - struct notification_thread_state *state, int pipe, - enum lttng_domain_type domain); - -int handle_notification_thread_event_notification( - struct notification_thread_state *state, int pipe, - enum lttng_domain_type domain); - -#endif /* NOTIFICATION_THREAD_EVENTS_H */ diff --git a/src/bin/lttng-sessiond/notification-thread-events.hpp b/src/bin/lttng-sessiond/notification-thread-events.hpp new file mode 100644 index 000000000..50abad916 --- /dev/null +++ b/src/bin/lttng-sessiond/notification-thread-events.hpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef NOTIFICATION_THREAD_EVENTS_H +#define NOTIFICATION_THREAD_EVENTS_H + +#include +#include "notification-thread.hpp" + +/** + * Event handling function shall only return an error if + * the thread should be stopped. + */ +int handle_notification_thread_command( + struct notification_thread_handle *handle, + struct notification_thread_state *state); + +int handle_notification_thread_client_connect( + struct notification_thread_state *state); + +int handle_notification_thread_client_disconnect( + int client_fd, + struct notification_thread_state *state); + +int handle_notification_thread_client_disconnect_all( + struct notification_thread_state *state); + +int handle_notification_thread_trigger_unregister_all( + struct notification_thread_state *state); + +int handle_notification_thread_tracer_event_source_died( + struct notification_thread_state *state, + int tracer_event_source_fd); + +int handle_notification_thread_client_in( + struct notification_thread_state *state, + int socket); + +int handle_notification_thread_client_out( + struct notification_thread_state *state, + int socket); + +int handle_notification_thread_channel_sample( + struct notification_thread_state *state, int pipe, + enum lttng_domain_type domain); + +int handle_notification_thread_event_notification( + struct notification_thread_state *state, int pipe, + enum lttng_domain_type domain); + +#endif /* NOTIFICATION_THREAD_EVENTS_H */ diff --git a/src/bin/lttng-sessiond/notification-thread-internal.h b/src/bin/lttng-sessiond/notification-thread-internal.h deleted file mode 100644 index 9e7059acf..000000000 --- a/src/bin/lttng-sessiond/notification-thread-internal.h +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef NOTIFICATION_THREAD_INTERNAL_H -#define NOTIFICATION_THREAD_INTERNAL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "notification-thread.h" - -struct lttng_evaluation; -struct notification_thread_handle; - -struct channel_key { - uint64_t key; - enum lttng_domain_type domain; -}; - -struct session_info { - struct lttng_ref ref; - char *name; - uid_t uid; - gid_t gid; - /* - * Hashtable containing back-refs (weak) to all channels in this session. - * The hashtable's key is a hash of (struct channel_key) and - * the value is of type (struct channel_info *). - */ - struct cds_lfht *channel_infos_ht; - struct lttng_session_trigger_list *trigger_list; - /* Node in the notification thread state's sessions_ht. */ - struct cds_lfht_node sessions_ht_node; - /* - * Weak reference to the thread state's sessions_ht. Used for removal on - * destruction. - */ - struct cds_lfht *sessions_ht; - uint64_t consumed_data_size; - struct { - /* Whether a rotation is ongoing for this session. */ - bool ongoing; - /* Identifier of the currently ongoing rotation. */ - uint64_t id; - } rotation; - /* call_rcu delayed reclaim. */ - struct rcu_head rcu_node; -}; - -struct channel_info { - struct channel_key key; - char *name; - uint64_t capacity; - /* - * A channel info holds a reference (lttng_ref) on session_info. - * session_info, in return, holds a weak reference to the channel. - */ - struct session_info *session_info; - /* Node in the notification thread state's channels_ht. */ - struct cds_lfht_node channels_ht_node; - /* Node in the session_info's channels_ht. */ - struct cds_lfht_node session_info_channels_ht_node; - /* call_rcu delayed reclaim. */ - struct rcu_head rcu_node; -}; - -/* - * Facilities to carry the different notifications type in the action - * processing code path. - */ -struct lttng_event_notifier_notification { - uint64_t tracer_token; - enum lttng_domain_type type; - size_t capture_buf_size; - char *capture_buffer; -}; - -struct notification_client_list_element { - struct notification_client *client; - struct cds_list_head node; -}; - -/* - * Thread safety of notification_client and notification_client_list. - * - * The notification thread (main thread) and the action executor - * interact through client lists. Hence, when the action executor - * thread looks-up the list of clients subscribed to a given - * condition, it will acquire a reference to the list and lock it - * while attempting to communicate with the various clients. - * - * It is not necessary to reference-count clients as they are guaranteed - * to be 'alive' if they are present in a list and that list is locked. Indeed, - * removing references to the client from those subscription lists is part of - * the work performed on destruction of a client. - * - * No provision for other access scenarios are taken into account; - * this is the bare minimum to make these accesses safe and the - * notification thread's state is _not_ "thread-safe" in any general - * sense. - */ -struct notification_client_list { - pthread_mutex_t lock; - struct urcu_ref ref; - struct lttng_condition *condition; - /* List of triggers that have an identical condition than `condition`. */ - struct cds_list_head triggers_list; - struct cds_list_head clients_list; - /* Weak reference to container. */ - struct cds_lfht *notification_trigger_clients_ht; - struct cds_lfht_node notification_trigger_clients_ht_node; - /* call_rcu delayed reclaim. */ - struct rcu_head rcu_node; -}; - -struct notification_client { - /* - * Nests within the notification_client_list lock. - * - * Protects the outbound communication and the active flag which - * is used by both the notification and action executor threads. - * - * The remaining fields of the object can be used without any - * synchronization as they are either immutable (id, creds, version) or - * only accessed by the notification thread. - */ - pthread_mutex_t lock; - notification_client_id id; - int socket; - /* Client protocol version. */ - uint8_t major, minor; - uid_t uid; - gid_t gid; - bool is_sessiond; - /* - * Indicates if the credentials and versions of the client have been - * checked. - */ - bool validated; - /* - * Conditions to which the client's notification channel is subscribed. - * List of struct lttng_condition_list_node. The condition member is - * owned by the client. - */ - struct cds_list_head condition_list; - struct cds_lfht_node client_socket_ht_node; - struct cds_lfht_node client_id_ht_node; - struct { - /* - * If a client's communication is inactive, it means that a - * fatal error has occurred (could be either a protocol error or - * the socket API returned a fatal error). No further - * communication should be attempted; the client is queued for - * clean-up. - */ - bool active; - struct { - /* - * During the reception of a message, the reception - * buffers' "size" is set to contain the current - * message's complete payload. - */ - struct lttng_payload payload; - /* Bytes left to receive for the current message. */ - size_t bytes_to_receive; - /* FDs left to receive for the current message. */ - int fds_to_receive; - /* Type of the message being received. */ - enum lttng_notification_channel_message_type msg_type; - /* - * Indicates whether or not credentials are expected - * from the client. - */ - bool expect_creds; - /* - * Indicates whether or not credentials were received - * from the client. - */ - bool creds_received; - /* Only used during credentials reception. */ - lttng_sock_cred creds; - } inbound; - struct { - /* - * Indicates whether or not a notification addressed to - * this client was dropped because a command reply was - * already buffered. - * - * A notification is dropped whenever the buffer is not - * empty. - */ - bool dropped_notification; - /* - * Indicates whether or not a command reply is already - * buffered. In this case, it means that the client is - * not consuming command replies before emitting a new - * one. This could be caused by a protocol error or a - * misbehaving/malicious client. - */ - bool queued_command_reply; - struct lttng_payload payload; - } outbound; - } communication; - /* call_rcu delayed reclaim. */ - struct rcu_head rcu_node; -}; - -enum client_transmission_status { - CLIENT_TRANSMISSION_STATUS_COMPLETE, - CLIENT_TRANSMISSION_STATUS_QUEUED, - /* Communication failure. */ - CLIENT_TRANSMISSION_STATUS_FAIL, - /* Fatal error. */ - CLIENT_TRANSMISSION_STATUS_ERROR, -}; - -bool notification_client_list_get(struct notification_client_list *list); - -void notification_client_list_put(struct notification_client_list *list); - -/* Only returns a non-zero value if a fatal error occurred. */ -typedef int (*report_client_transmission_result_cb)( - struct notification_client *client, - enum client_transmission_status status, - void *user_data); - -int notification_client_list_send_evaluation( - struct notification_client_list *list, - const struct lttng_trigger *trigger, - const struct lttng_evaluation *evaluation, - const struct lttng_credentials *source_object_creds, - report_client_transmission_result_cb client_report, - void *user_data); - -int notification_thread_client_communication_update( - struct notification_thread_handle *handle, - notification_client_id id, - enum client_transmission_status transmission_status); - -/* - * Takes ownership of the payload if present. - */ -struct lttng_event_notifier_notification *lttng_event_notifier_notification_create( - uint64_t tracer_token, - enum lttng_domain_type domain, - char *payload, - size_t payload_size); - -void lttng_event_notifier_notification_destroy( - struct lttng_event_notifier_notification *event_notifier_notification); - -#endif /* NOTIFICATION_THREAD_INTERNAL_H */ diff --git a/src/bin/lttng-sessiond/notification-thread-internal.hpp b/src/bin/lttng-sessiond/notification-thread-internal.hpp new file mode 100644 index 000000000..497484ba0 --- /dev/null +++ b/src/bin/lttng-sessiond/notification-thread-internal.hpp @@ -0,0 +1,263 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef NOTIFICATION_THREAD_INTERNAL_H +#define NOTIFICATION_THREAD_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "notification-thread.hpp" + +struct lttng_evaluation; +struct notification_thread_handle; + +struct channel_key { + uint64_t key; + enum lttng_domain_type domain; +}; + +struct session_info { + struct lttng_ref ref; + char *name; + uid_t uid; + gid_t gid; + /* + * Hashtable containing back-refs (weak) to all channels in this session. + * The hashtable's key is a hash of (struct channel_key) and + * the value is of type (struct channel_info *). + */ + struct cds_lfht *channel_infos_ht; + struct lttng_session_trigger_list *trigger_list; + /* Node in the notification thread state's sessions_ht. */ + struct cds_lfht_node sessions_ht_node; + /* + * Weak reference to the thread state's sessions_ht. Used for removal on + * destruction. + */ + struct cds_lfht *sessions_ht; + uint64_t consumed_data_size; + struct { + /* Whether a rotation is ongoing for this session. */ + bool ongoing; + /* Identifier of the currently ongoing rotation. */ + uint64_t id; + } rotation; + /* call_rcu delayed reclaim. */ + struct rcu_head rcu_node; +}; + +struct channel_info { + struct channel_key key; + char *name; + uint64_t capacity; + /* + * A channel info holds a reference (lttng_ref) on session_info. + * session_info, in return, holds a weak reference to the channel. + */ + struct session_info *session_info; + /* Node in the notification thread state's channels_ht. */ + struct cds_lfht_node channels_ht_node; + /* Node in the session_info's channels_ht. */ + struct cds_lfht_node session_info_channels_ht_node; + /* call_rcu delayed reclaim. */ + struct rcu_head rcu_node; +}; + +/* + * Facilities to carry the different notifications type in the action + * processing code path. + */ +struct lttng_event_notifier_notification { + uint64_t tracer_token; + enum lttng_domain_type type; + size_t capture_buf_size; + char *capture_buffer; +}; + +struct notification_client_list_element { + struct notification_client *client; + struct cds_list_head node; +}; + +/* + * Thread safety of notification_client and notification_client_list. + * + * The notification thread (main thread) and the action executor + * interact through client lists. Hence, when the action executor + * thread looks-up the list of clients subscribed to a given + * condition, it will acquire a reference to the list and lock it + * while attempting to communicate with the various clients. + * + * It is not necessary to reference-count clients as they are guaranteed + * to be 'alive' if they are present in a list and that list is locked. Indeed, + * removing references to the client from those subscription lists is part of + * the work performed on destruction of a client. + * + * No provision for other access scenarios are taken into account; + * this is the bare minimum to make these accesses safe and the + * notification thread's state is _not_ "thread-safe" in any general + * sense. + */ +struct notification_client_list { + pthread_mutex_t lock; + struct urcu_ref ref; + struct lttng_condition *condition; + /* List of triggers that have an identical condition than `condition`. */ + struct cds_list_head triggers_list; + struct cds_list_head clients_list; + /* Weak reference to container. */ + struct cds_lfht *notification_trigger_clients_ht; + struct cds_lfht_node notification_trigger_clients_ht_node; + /* call_rcu delayed reclaim. */ + struct rcu_head rcu_node; +}; + +struct notification_client { + /* + * Nests within the notification_client_list lock. + * + * Protects the outbound communication and the active flag which + * is used by both the notification and action executor threads. + * + * The remaining fields of the object can be used without any + * synchronization as they are either immutable (id, creds, version) or + * only accessed by the notification thread. + */ + pthread_mutex_t lock; + notification_client_id id; + int socket; + /* Client protocol version. */ + uint8_t major, minor; + uid_t uid; + gid_t gid; + bool is_sessiond; + /* + * Indicates if the credentials and versions of the client have been + * checked. + */ + bool validated; + /* + * Conditions to which the client's notification channel is subscribed. + * List of struct lttng_condition_list_node. The condition member is + * owned by the client. + */ + struct cds_list_head condition_list; + struct cds_lfht_node client_socket_ht_node; + struct cds_lfht_node client_id_ht_node; + struct { + /* + * If a client's communication is inactive, it means that a + * fatal error has occurred (could be either a protocol error or + * the socket API returned a fatal error). No further + * communication should be attempted; the client is queued for + * clean-up. + */ + bool active; + struct { + /* + * During the reception of a message, the reception + * buffers' "size" is set to contain the current + * message's complete payload. + */ + struct lttng_payload payload; + /* Bytes left to receive for the current message. */ + size_t bytes_to_receive; + /* FDs left to receive for the current message. */ + int fds_to_receive; + /* Type of the message being received. */ + enum lttng_notification_channel_message_type msg_type; + /* + * Indicates whether or not credentials are expected + * from the client. + */ + bool expect_creds; + /* + * Indicates whether or not credentials were received + * from the client. + */ + bool creds_received; + /* Only used during credentials reception. */ + lttng_sock_cred creds; + } inbound; + struct { + /* + * Indicates whether or not a notification addressed to + * this client was dropped because a command reply was + * already buffered. + * + * A notification is dropped whenever the buffer is not + * empty. + */ + bool dropped_notification; + /* + * Indicates whether or not a command reply is already + * buffered. In this case, it means that the client is + * not consuming command replies before emitting a new + * one. This could be caused by a protocol error or a + * misbehaving/malicious client. + */ + bool queued_command_reply; + struct lttng_payload payload; + } outbound; + } communication; + /* call_rcu delayed reclaim. */ + struct rcu_head rcu_node; +}; + +enum client_transmission_status { + CLIENT_TRANSMISSION_STATUS_COMPLETE, + CLIENT_TRANSMISSION_STATUS_QUEUED, + /* Communication failure. */ + CLIENT_TRANSMISSION_STATUS_FAIL, + /* Fatal error. */ + CLIENT_TRANSMISSION_STATUS_ERROR, +}; + +bool notification_client_list_get(struct notification_client_list *list); + +void notification_client_list_put(struct notification_client_list *list); + +/* Only returns a non-zero value if a fatal error occurred. */ +typedef int (*report_client_transmission_result_cb)( + struct notification_client *client, + enum client_transmission_status status, + void *user_data); + +int notification_client_list_send_evaluation( + struct notification_client_list *list, + const struct lttng_trigger *trigger, + const struct lttng_evaluation *evaluation, + const struct lttng_credentials *source_object_creds, + report_client_transmission_result_cb client_report, + void *user_data); + +int notification_thread_client_communication_update( + struct notification_thread_handle *handle, + notification_client_id id, + enum client_transmission_status transmission_status); + +/* + * Takes ownership of the payload if present. + */ +struct lttng_event_notifier_notification *lttng_event_notifier_notification_create( + uint64_t tracer_token, + enum lttng_domain_type domain, + char *payload, + size_t payload_size); + +void lttng_event_notifier_notification_destroy( + struct lttng_event_notifier_notification *event_notifier_notification); + +#endif /* NOTIFICATION_THREAD_INTERNAL_H */ diff --git a/src/bin/lttng-sessiond/notification-thread.cpp b/src/bin/lttng-sessiond/notification-thread.cpp index 867fc7c04..74e37902d 100644 --- a/src/bin/lttng-sessiond/notification-thread.cpp +++ b/src/bin/lttng-sessiond/notification-thread.cpp @@ -7,30 +7,30 @@ #define _LGPL_SOURCE #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include "notification-thread.h" -#include "notification-thread-events.h" -#include "notification-thread-commands.h" -#include "lttng-sessiond.h" -#include "health-sessiond.h" -#include "thread.h" -#include "testpoint.h" +#include "notification-thread.hpp" +#include "notification-thread-events.hpp" +#include "notification-thread-commands.hpp" +#include "lttng-sessiond.hpp" +#include "health-sessiond.hpp" +#include "thread.hpp" +#include "testpoint.hpp" -#include "kernel.h" -#include +#include "kernel.hpp" +#include #include #include diff --git a/src/bin/lttng-sessiond/notification-thread.h b/src/bin/lttng-sessiond/notification-thread.h deleted file mode 100644 index 8b4c7af2b..000000000 --- a/src/bin/lttng-sessiond/notification-thread.h +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef NOTIFICATION_THREAD_H -#define NOTIFICATION_THREAD_H - -#include "action-executor.h" -#include "thread.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef uint64_t notification_client_id; - -/* - * The notification thread holds no ownership of the tracer event source pipe - * file descriptor. The tracer management logic must remove the event source - * from the notification thread (see external commands) before releasing - * this file descriptor. - */ -struct notification_event_tracer_event_source_element { - int fd; - /* - * A tracer event source can be removed from the notification thread's - * poll set before the end of its lifetime (for instance, when an error - * or hang-up is detected on its file descriptor). This is done to - * allow the notification thread to ignore follow-up events on this - * file descriptors. - * - * Under such circumstances, the notification thread still expects - * the normal clean-up to occur through the 'REMOVE_TRACER_EVENT_SOURCE' - * command. - */ - bool is_fd_in_poll_set; - enum lttng_domain_type domain; - struct cds_list_head node; -}; - -struct notification_trigger_tokens_ht_element { - uint64_t token; - /* Weak reference to the trigger. */ - struct lttng_trigger *trigger; - struct cds_lfht_node node; - /* call_rcu delayed reclaim. */ - struct rcu_head rcu_node; -}; - -struct notification_thread_handle { - /* - * Queue of struct notification command. - * event_pipe must be WRITE(2) to signal that a new command - * has been enqueued. - */ - struct { - struct lttng_pipe *event_pipe; - struct cds_list_head list; - pthread_mutex_t lock; - } cmd_queue; - /* - * Read side of pipes used to receive channel status info collected - * by the various consumer daemons. - */ - struct { - int ust32_consumer; - int ust64_consumer; - int kernel_consumer; - } channel_monitoring_pipes; - /* Used to wait for the launch of the notification thread. */ - sem_t ready; -}; - -/** - * This thread maintains an internal state associating clients and triggers. - * - * In order to speed-up and simplify queries, hash tables providing the - * following associations are maintained: - * - * - client_socket_ht: associate a client's socket (fd) to its - * "struct notification_client". - * This hash table owns the "struct notification_client" which must - * thus be disposed-of on removal from the hash table. - * - * - client_id_ht: associate a client's id to its "struct notification_client" - * This hash table holds a _weak_ reference to the - * "struct notification_client". - * - * - channel_triggers_ht: - * associates a channel key to a list of - * struct lttng_trigger_list_nodes. The triggers in this list are - * those that have conditions that apply to a particular channel. - * A channel entry is only created when a channel is added; the - * list of triggers applying to such a channel is built at that - * moment. - * This hash table owns the list, but not the triggers themselves. - * - * - session_triggers_ht: - * associates a session name to a list of - * struct lttng_trigger_list_nodes. The triggers in this list are - * those that have conditions that apply to a particular session. - * A session entry is only created when a session is created; the - * list of triggers applying to this new session is built at that - * moment. This happens at the time of creation of a session_info. - * Likewise, the list is destroyed at the time of the session_info's - * destruction. - * - * - channel_state_ht: - * associates a pair (channel key, channel domain) to its last - * sampled state received from the consumer daemon - * (struct channel_state). - * This previous sample is kept to implement edge-triggered - * conditions as we need to detect the state transitions. - * This hash table owns the channel state. - * - * - notification_trigger_clients_ht: - * associates notification-emitting triggers to clients - * (struct notification_client_list) subscribed to those - * conditions. - * The condition's hash and match functions are used directly since - * all triggers in this hash table have the "notify" action. - * This hash table holds no ownership. - * - * - channels_ht: - * associates a channel_key to a struct channel_info. The hash table - * holds the ownership of the struct channel_info. - * - * - sessions_ht: - * associates a session_name (hash) to a struct session_info. The - * hash table holds no ownership of the struct session_info; - * the session_info structure is owned by the session's various - * channels through their struct channel_info (ref-counting is used). - * - * - triggers_ht: - * associates a trigger to a struct lttng_trigger_ht_element. - * The hash table holds the ownership of the - * lttng_trigger_ht_elements along with the triggers themselves. - * - triggers_by_name_uid_ht: - * associates a trigger (name, uid) tuple to - * a struct lttng_trigger_ht_element. - * The hash table does not hold any ownership and is used strictly - * for lookup on registration. - * - tracer_event_sources_list: - * A list of tracer event source (read side fd) of type -* struct notification_event_tracer_event_source_element. -* - * - * The thread reacts to the following internal events: - * 1) creation of a tracing channel, - * 2) destruction of a tracing channel, - * 3) registration of a trigger, - * 4) unregistration of a trigger, - * 5) reception of a channel monitor sample from the consumer daemon, - * 6) Session rotation ongoing, - * 7) Session rotation completed, - * 8) registration of a tracer event source, - * 9) unregistration of a tracer event source, - * - * Events specific to notification-emitting triggers: - * 9) connection of a notification client, - * 10) disconnection of a notification client, - * 11) subscription of a client to a conditions' notifications, - * 12) unsubscription of a client from a conditions' notifications, - * - * - * 1) Creation of a tracing channel - * - notification_trigger_clients_ht is traversed to identify - * triggers which apply to this new channel, - * - triggers identified are added to the channel_triggers_ht. - * - add channel to channels_ht - * - if it is the first channel of a session, a session_info is created and - * added to the sessions_ht. A list of the triggers associated with that - * session is built, and it is added to session_triggers_ht. - * - * 2) Destruction of a tracing channel - * - remove entry from channel_triggers_ht, releasing the list wrapper and - * elements, - * - remove entry from the channel_state_ht. - * - remove channel from channels_ht - * - if it was the last known channel of a session, the session_info - * structure is torndown, which in return destroys the list of triggers - * applying to that session. - * - * 3) Registration of a trigger - * - if the trigger's action is of type "notify", - * - traverse the list of conditions of every client to build a list of - * clients which have to be notified when this trigger's condition is met, - * - add list of clients (even if it is empty) to the - * notification_trigger_clients_ht, - * - add trigger to channel_triggers_ht (if applicable), - * - add trigger to session_triggers_ht (if applicable), - * - add trigger to triggers_by_name_uid_ht - * - add trigger to triggers_ht - * - evaluate the trigger's condition right away to react if that condition - * is true from the beginning. - * - * 4) Unregistration of a trigger - * - if the trigger's action is of type "notify", - * - remove the trigger from the notification_trigger_clients_ht, - * - remove trigger from channel_triggers_ht (if applicable), - * - remove trigger from session_triggers_ht (if applicable), - * - remove trigger from triggers_by_name_uid_ht - * - remove trigger from triggers_ht - * - * 5) Reception of a channel monitor sample from the consumer daemon - * - evaluate the conditions associated with the triggers found in - * the channel_triggers_ht, - * - if a condition evaluates to "true" and the condition is of type - * "notify", query the notification_trigger_clients_ht and send - * a notification to the clients. - * - * 6) Session rotation ongoing - * - * 7) Session rotation completed - * - * 8) Registration of a tracer event source - * - Add the tracer event source of the application to - * tracer_event_sources_list, - * - Add the trace event source to the pollset. - * - * 8) Unregistration of a tracer event source - * - Remove the tracer event source of the application from - * tracer_event_sources_list, - * - Remove the trace event source from the pollset. - * - * 10) Connection of a client - * - add client socket to the client_socket_ht, - * - add client socket to the client_id_ht. - * - * 11) Disconnection of a client - * - remove client socket from the client_id_ht, - * - remove client socket from the client_socket_ht, - * - traverse all conditions to which the client is subscribed and remove - * the client from the notification_trigger_clients_ht. - * - * 12) Subscription of a client to a condition's notifications - * - Add the condition to the client's list of subscribed conditions, - * - Look-up notification_trigger_clients_ht and add the client to - * list of clients. - * - Evaluate the condition for the client that subscribed if the trigger - * was already registered. - * - * 13) Unsubscription of a client to a condition's notifications - * - Remove the condition from the client's list of subscribed conditions, - * - Look-up notification_trigger_clients_ht and remove the client - * from the list of clients. - */ -struct notification_thread_state { - int notification_channel_socket; - struct lttng_poll_event events; - struct cds_lfht *client_socket_ht; - struct cds_lfht *client_id_ht; - struct cds_lfht *channel_triggers_ht; - struct cds_lfht *session_triggers_ht; - struct cds_lfht *channel_state_ht; - struct cds_lfht *notification_trigger_clients_ht; - struct cds_lfht *channels_ht; - struct cds_lfht *sessions_ht; - struct cds_lfht *triggers_ht; - struct cds_lfht *triggers_by_name_uid_ht; - struct cds_lfht *trigger_tokens_ht; - struct { - uint64_t next_tracer_token; - uint64_t name_offset; - } trigger_id; - /* - * Read side of the pipes used to receive tracer events. As their name - * implies, tracer event source activity originate from either - * registered applications (user space tracer) or from the kernel - * tracer. - * - * The list is not protected by a lock since add and remove operations - * are currently done only by the notification thread through in - * response to blocking commands. - */ - struct cds_list_head tracer_event_sources_list; - notification_client_id next_notification_client_id; - struct action_executor *executor; - - /* - * Indicates the thread to break for the poll event processing loop and - * call _poll_wait() again. - * - * This is necessary because some events on one fd might trigger the - * consumption of another fd. - * For example, a single _poll_wait() call can return notification - * thread commands and events from the tracer event source (event - * notifier). - * Picture a scenario where we receive two events: - * the first one is a _REMOVE_TRACER_EVENT_SOURCE command, and - * the second is an POLLIN on the tracer event source fd. - * - * The _REMOVE_TRACER_EVENT_SOURCE will read all the data of the - * removed tracer event source. - * - * The second event is now invalid has we consumed all the data for - * which we received the POLLIN. - * - * For this reason, we need to break for the event processing loop and - * call _poll_wait() again to get a clean view of the activity on the - * fds. - */ - bool restart_poll; -}; - -/* notification_thread_data takes ownership of the channel monitor pipes. */ -struct notification_thread_handle *notification_thread_handle_create( - struct lttng_pipe *ust32_channel_monitor_pipe, - struct lttng_pipe *ust64_channel_monitor_pipe, - struct lttng_pipe *kernel_channel_monitor_pipe); -void notification_thread_handle_destroy( - struct notification_thread_handle *handle); -struct lttng_thread *launch_notification_thread( - struct notification_thread_handle *handle); - -#endif /* NOTIFICATION_THREAD_H */ diff --git a/src/bin/lttng-sessiond/notification-thread.hpp b/src/bin/lttng-sessiond/notification-thread.hpp new file mode 100644 index 000000000..3444af9c0 --- /dev/null +++ b/src/bin/lttng-sessiond/notification-thread.hpp @@ -0,0 +1,325 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef NOTIFICATION_THREAD_H +#define NOTIFICATION_THREAD_H + +#include "action-executor.hpp" +#include "thread.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef uint64_t notification_client_id; + +/* + * The notification thread holds no ownership of the tracer event source pipe + * file descriptor. The tracer management logic must remove the event source + * from the notification thread (see external commands) before releasing + * this file descriptor. + */ +struct notification_event_tracer_event_source_element { + int fd; + /* + * A tracer event source can be removed from the notification thread's + * poll set before the end of its lifetime (for instance, when an error + * or hang-up is detected on its file descriptor). This is done to + * allow the notification thread to ignore follow-up events on this + * file descriptors. + * + * Under such circumstances, the notification thread still expects + * the normal clean-up to occur through the 'REMOVE_TRACER_EVENT_SOURCE' + * command. + */ + bool is_fd_in_poll_set; + enum lttng_domain_type domain; + struct cds_list_head node; +}; + +struct notification_trigger_tokens_ht_element { + uint64_t token; + /* Weak reference to the trigger. */ + struct lttng_trigger *trigger; + struct cds_lfht_node node; + /* call_rcu delayed reclaim. */ + struct rcu_head rcu_node; +}; + +struct notification_thread_handle { + /* + * Queue of struct notification command. + * event_pipe must be WRITE(2) to signal that a new command + * has been enqueued. + */ + struct { + struct lttng_pipe *event_pipe; + struct cds_list_head list; + pthread_mutex_t lock; + } cmd_queue; + /* + * Read side of pipes used to receive channel status info collected + * by the various consumer daemons. + */ + struct { + int ust32_consumer; + int ust64_consumer; + int kernel_consumer; + } channel_monitoring_pipes; + /* Used to wait for the launch of the notification thread. */ + sem_t ready; +}; + +/** + * This thread maintains an internal state associating clients and triggers. + * + * In order to speed-up and simplify queries, hash tables providing the + * following associations are maintained: + * + * - client_socket_ht: associate a client's socket (fd) to its + * "struct notification_client". + * This hash table owns the "struct notification_client" which must + * thus be disposed-of on removal from the hash table. + * + * - client_id_ht: associate a client's id to its "struct notification_client" + * This hash table holds a _weak_ reference to the + * "struct notification_client". + * + * - channel_triggers_ht: + * associates a channel key to a list of + * struct lttng_trigger_list_nodes. The triggers in this list are + * those that have conditions that apply to a particular channel. + * A channel entry is only created when a channel is added; the + * list of triggers applying to such a channel is built at that + * moment. + * This hash table owns the list, but not the triggers themselves. + * + * - session_triggers_ht: + * associates a session name to a list of + * struct lttng_trigger_list_nodes. The triggers in this list are + * those that have conditions that apply to a particular session. + * A session entry is only created when a session is created; the + * list of triggers applying to this new session is built at that + * moment. This happens at the time of creation of a session_info. + * Likewise, the list is destroyed at the time of the session_info's + * destruction. + * + * - channel_state_ht: + * associates a pair (channel key, channel domain) to its last + * sampled state received from the consumer daemon + * (struct channel_state). + * This previous sample is kept to implement edge-triggered + * conditions as we need to detect the state transitions. + * This hash table owns the channel state. + * + * - notification_trigger_clients_ht: + * associates notification-emitting triggers to clients + * (struct notification_client_list) subscribed to those + * conditions. + * The condition's hash and match functions are used directly since + * all triggers in this hash table have the "notify" action. + * This hash table holds no ownership. + * + * - channels_ht: + * associates a channel_key to a struct channel_info. The hash table + * holds the ownership of the struct channel_info. + * + * - sessions_ht: + * associates a session_name (hash) to a struct session_info. The + * hash table holds no ownership of the struct session_info; + * the session_info structure is owned by the session's various + * channels through their struct channel_info (ref-counting is used). + * + * - triggers_ht: + * associates a trigger to a struct lttng_trigger_ht_element. + * The hash table holds the ownership of the + * lttng_trigger_ht_elements along with the triggers themselves. + * - triggers_by_name_uid_ht: + * associates a trigger (name, uid) tuple to + * a struct lttng_trigger_ht_element. + * The hash table does not hold any ownership and is used strictly + * for lookup on registration. + * - tracer_event_sources_list: + * A list of tracer event source (read side fd) of type +* struct notification_event_tracer_event_source_element. +* + * + * The thread reacts to the following internal events: + * 1) creation of a tracing channel, + * 2) destruction of a tracing channel, + * 3) registration of a trigger, + * 4) unregistration of a trigger, + * 5) reception of a channel monitor sample from the consumer daemon, + * 6) Session rotation ongoing, + * 7) Session rotation completed, + * 8) registration of a tracer event source, + * 9) unregistration of a tracer event source, + * + * Events specific to notification-emitting triggers: + * 9) connection of a notification client, + * 10) disconnection of a notification client, + * 11) subscription of a client to a conditions' notifications, + * 12) unsubscription of a client from a conditions' notifications, + * + * + * 1) Creation of a tracing channel + * - notification_trigger_clients_ht is traversed to identify + * triggers which apply to this new channel, + * - triggers identified are added to the channel_triggers_ht. + * - add channel to channels_ht + * - if it is the first channel of a session, a session_info is created and + * added to the sessions_ht. A list of the triggers associated with that + * session is built, and it is added to session_triggers_ht. + * + * 2) Destruction of a tracing channel + * - remove entry from channel_triggers_ht, releasing the list wrapper and + * elements, + * - remove entry from the channel_state_ht. + * - remove channel from channels_ht + * - if it was the last known channel of a session, the session_info + * structure is torndown, which in return destroys the list of triggers + * applying to that session. + * + * 3) Registration of a trigger + * - if the trigger's action is of type "notify", + * - traverse the list of conditions of every client to build a list of + * clients which have to be notified when this trigger's condition is met, + * - add list of clients (even if it is empty) to the + * notification_trigger_clients_ht, + * - add trigger to channel_triggers_ht (if applicable), + * - add trigger to session_triggers_ht (if applicable), + * - add trigger to triggers_by_name_uid_ht + * - add trigger to triggers_ht + * - evaluate the trigger's condition right away to react if that condition + * is true from the beginning. + * + * 4) Unregistration of a trigger + * - if the trigger's action is of type "notify", + * - remove the trigger from the notification_trigger_clients_ht, + * - remove trigger from channel_triggers_ht (if applicable), + * - remove trigger from session_triggers_ht (if applicable), + * - remove trigger from triggers_by_name_uid_ht + * - remove trigger from triggers_ht + * + * 5) Reception of a channel monitor sample from the consumer daemon + * - evaluate the conditions associated with the triggers found in + * the channel_triggers_ht, + * - if a condition evaluates to "true" and the condition is of type + * "notify", query the notification_trigger_clients_ht and send + * a notification to the clients. + * + * 6) Session rotation ongoing + * + * 7) Session rotation completed + * + * 8) Registration of a tracer event source + * - Add the tracer event source of the application to + * tracer_event_sources_list, + * - Add the trace event source to the pollset. + * + * 8) Unregistration of a tracer event source + * - Remove the tracer event source of the application from + * tracer_event_sources_list, + * - Remove the trace event source from the pollset. + * + * 10) Connection of a client + * - add client socket to the client_socket_ht, + * - add client socket to the client_id_ht. + * + * 11) Disconnection of a client + * - remove client socket from the client_id_ht, + * - remove client socket from the client_socket_ht, + * - traverse all conditions to which the client is subscribed and remove + * the client from the notification_trigger_clients_ht. + * + * 12) Subscription of a client to a condition's notifications + * - Add the condition to the client's list of subscribed conditions, + * - Look-up notification_trigger_clients_ht and add the client to + * list of clients. + * - Evaluate the condition for the client that subscribed if the trigger + * was already registered. + * + * 13) Unsubscription of a client to a condition's notifications + * - Remove the condition from the client's list of subscribed conditions, + * - Look-up notification_trigger_clients_ht and remove the client + * from the list of clients. + */ +struct notification_thread_state { + int notification_channel_socket; + struct lttng_poll_event events; + struct cds_lfht *client_socket_ht; + struct cds_lfht *client_id_ht; + struct cds_lfht *channel_triggers_ht; + struct cds_lfht *session_triggers_ht; + struct cds_lfht *channel_state_ht; + struct cds_lfht *notification_trigger_clients_ht; + struct cds_lfht *channels_ht; + struct cds_lfht *sessions_ht; + struct cds_lfht *triggers_ht; + struct cds_lfht *triggers_by_name_uid_ht; + struct cds_lfht *trigger_tokens_ht; + struct { + uint64_t next_tracer_token; + uint64_t name_offset; + } trigger_id; + /* + * Read side of the pipes used to receive tracer events. As their name + * implies, tracer event source activity originate from either + * registered applications (user space tracer) or from the kernel + * tracer. + * + * The list is not protected by a lock since add and remove operations + * are currently done only by the notification thread through in + * response to blocking commands. + */ + struct cds_list_head tracer_event_sources_list; + notification_client_id next_notification_client_id; + struct action_executor *executor; + + /* + * Indicates the thread to break for the poll event processing loop and + * call _poll_wait() again. + * + * This is necessary because some events on one fd might trigger the + * consumption of another fd. + * For example, a single _poll_wait() call can return notification + * thread commands and events from the tracer event source (event + * notifier). + * Picture a scenario where we receive two events: + * the first one is a _REMOVE_TRACER_EVENT_SOURCE command, and + * the second is an POLLIN on the tracer event source fd. + * + * The _REMOVE_TRACER_EVENT_SOURCE will read all the data of the + * removed tracer event source. + * + * The second event is now invalid has we consumed all the data for + * which we received the POLLIN. + * + * For this reason, we need to break for the event processing loop and + * call _poll_wait() again to get a clean view of the activity on the + * fds. + */ + bool restart_poll; +}; + +/* notification_thread_data takes ownership of the channel monitor pipes. */ +struct notification_thread_handle *notification_thread_handle_create( + struct lttng_pipe *ust32_channel_monitor_pipe, + struct lttng_pipe *ust64_channel_monitor_pipe, + struct lttng_pipe *kernel_channel_monitor_pipe); +void notification_thread_handle_destroy( + struct notification_thread_handle *handle); +struct lttng_thread *launch_notification_thread( + struct notification_thread_handle *handle); + +#endif /* NOTIFICATION_THREAD_H */ diff --git a/src/bin/lttng-sessiond/notify-apps.cpp b/src/bin/lttng-sessiond/notify-apps.cpp index 0e799ff26..8e238e5c1 100644 --- a/src/bin/lttng-sessiond/notify-apps.cpp +++ b/src/bin/lttng-sessiond/notify-apps.cpp @@ -7,16 +7,16 @@ #define _LGPL_SOURCE -#include -#include - -#include "fd-limit.h" -#include "lttng-sessiond.h" -#include "notify-apps.h" -#include "health-sessiond.h" -#include "testpoint.h" -#include "utils.h" -#include "thread.h" +#include +#include + +#include "fd-limit.hpp" +#include "lttng-sessiond.hpp" +#include "notify-apps.hpp" +#include "health-sessiond.hpp" +#include "testpoint.hpp" +#include "utils.hpp" +#include "thread.hpp" struct thread_notifiers { struct lttng_pipe *quit_pipe; diff --git a/src/bin/lttng-sessiond/notify-apps.h b/src/bin/lttng-sessiond/notify-apps.h deleted file mode 100644 index 152a52a20..000000000 --- a/src/bin/lttng-sessiond/notify-apps.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2013 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef UST_THREAD_H -#define UST_THREAD_H - -#ifdef HAVE_LIBLTTNG_UST_CTL - -bool launch_application_notification_thread(int apps_cmd_notify_pipe_read_fd); - -#else /* HAVE_LIBLTTNG_UST_CTL */ - -static -bool launch_application_notification_thread( - int apps_cmd_notify_pipe_read_fd __attribute__((unused))) -{ - return true; -} - -#endif /* HAVE_LIBLTTNG_UST_CTL */ - -#endif /* UST_THREAD_H */ diff --git a/src/bin/lttng-sessiond/notify-apps.hpp b/src/bin/lttng-sessiond/notify-apps.hpp new file mode 100644 index 000000000..152a52a20 --- /dev/null +++ b/src/bin/lttng-sessiond/notify-apps.hpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2013 David Goulet + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef UST_THREAD_H +#define UST_THREAD_H + +#ifdef HAVE_LIBLTTNG_UST_CTL + +bool launch_application_notification_thread(int apps_cmd_notify_pipe_read_fd); + +#else /* HAVE_LIBLTTNG_UST_CTL */ + +static +bool launch_application_notification_thread( + int apps_cmd_notify_pipe_read_fd __attribute__((unused))) +{ + return true; +} + +#endif /* HAVE_LIBLTTNG_UST_CTL */ + +#endif /* UST_THREAD_H */ diff --git a/src/bin/lttng-sessiond/process-utils.cpp b/src/bin/lttng-sessiond/process-utils.cpp index d2e52172e..a3122da75 100644 --- a/src/bin/lttng-sessiond/process-utils.cpp +++ b/src/bin/lttng-sessiond/process-utils.cpp @@ -8,7 +8,7 @@ */ #include -#include "lttng-sessiond.h" +#include "lttng-sessiond.hpp" /* Notify parents that we are ready for cmd and health check */ void sessiond_signal_parents(void) diff --git a/src/bin/lttng-sessiond/register.cpp b/src/bin/lttng-sessiond/register.cpp index a20db57f6..36a29d863 100644 --- a/src/bin/lttng-sessiond/register.cpp +++ b/src/bin/lttng-sessiond/register.cpp @@ -10,19 +10,19 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include "register.h" -#include "lttng-sessiond.h" -#include "testpoint.h" -#include "health-sessiond.h" -#include "fd-limit.h" -#include "utils.h" -#include "thread.h" +#include "register.hpp" +#include "lttng-sessiond.hpp" +#include "testpoint.hpp" +#include "health-sessiond.hpp" +#include "fd-limit.hpp" +#include "utils.hpp" +#include "thread.hpp" struct thread_state { struct lttng_pipe *quit_pipe; diff --git a/src/bin/lttng-sessiond/register.h b/src/bin/lttng-sessiond/register.h deleted file mode 100644 index 8b51ad48e..000000000 --- a/src/bin/lttng-sessiond/register.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * Copyright (C) 2011 Mathieu Desnoyers - * Copyright (C) 2013 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef SESSIOND_APPLICATION_REGISTRATION_THREAD_H -#define SESSIOND_APPLICATION_REGISTRATION_THREAD_H - -#include -#include "lttng-sessiond.h" - -struct lttng_thread *launch_application_registration_thread( - struct ust_cmd_queue *cmd_queue); - -#endif /* SESSIOND_APPLICATION_REGISTRATION_THREAD_H */ diff --git a/src/bin/lttng-sessiond/register.hpp b/src/bin/lttng-sessiond/register.hpp new file mode 100644 index 000000000..ef82a2ca2 --- /dev/null +++ b/src/bin/lttng-sessiond/register.hpp @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * Copyright (C) 2011 Mathieu Desnoyers + * Copyright (C) 2013 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef SESSIOND_APPLICATION_REGISTRATION_THREAD_H +#define SESSIOND_APPLICATION_REGISTRATION_THREAD_H + +#include +#include "lttng-sessiond.hpp" + +struct lttng_thread *launch_application_registration_thread( + struct ust_cmd_queue *cmd_queue); + +#endif /* SESSIOND_APPLICATION_REGISTRATION_THREAD_H */ diff --git a/src/bin/lttng-sessiond/rotate.cpp b/src/bin/lttng-sessiond/rotate.cpp index cdf95f353..51fc5e8aa 100644 --- a/src/bin/lttng-sessiond/rotate.cpp +++ b/src/bin/lttng-sessiond/rotate.cpp @@ -8,32 +8,32 @@ #define _LGPL_SOURCE #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include -#include -#include - -#include "session.h" -#include "rotate.h" -#include "rotation-thread.h" -#include "lttng-sessiond.h" -#include "health-sessiond.h" -#include "cmd.h" -#include "utils.h" -#include "notification-thread-commands.h" +#include +#include + +#include "session.hpp" +#include "rotate.hpp" +#include "rotation-thread.hpp" +#include "lttng-sessiond.hpp" +#include "health-sessiond.hpp" +#include "cmd.hpp" +#include "utils.hpp" +#include "notification-thread-commands.hpp" #include #include diff --git a/src/bin/lttng-sessiond/rotate.h b/src/bin/lttng-sessiond/rotate.h deleted file mode 100644 index a2adaf0d6..000000000 --- a/src/bin/lttng-sessiond/rotate.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2017 Julien Desfossez - * Copyright (C) 2018 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef ROTATE_H -#define ROTATE_H - -#include "rotation-thread.h" -#include - -/* - * Subscribe/unsubscribe the notification_channel from the rotation_thread to - * session usage notifications to perform size-based rotations. - */ -int subscribe_session_consumed_size_rotation(struct ltt_session *session, - uint64_t size, - struct notification_thread_handle *notification_thread_handle); -int unsubscribe_session_consumed_size_rotation(struct ltt_session *session, - struct notification_thread_handle *notification_thread_handle); - -#endif /* ROTATE_H */ diff --git a/src/bin/lttng-sessiond/rotate.hpp b/src/bin/lttng-sessiond/rotate.hpp new file mode 100644 index 000000000..965a8c76c --- /dev/null +++ b/src/bin/lttng-sessiond/rotate.hpp @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2017 Julien Desfossez + * Copyright (C) 2018 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef ROTATE_H +#define ROTATE_H + +#include "rotation-thread.hpp" +#include + +/* + * Subscribe/unsubscribe the notification_channel from the rotation_thread to + * session usage notifications to perform size-based rotations. + */ +int subscribe_session_consumed_size_rotation(struct ltt_session *session, + uint64_t size, + struct notification_thread_handle *notification_thread_handle); +int unsubscribe_session_consumed_size_rotation(struct ltt_session *session, + struct notification_thread_handle *notification_thread_handle); + +#endif /* ROTATE_H */ diff --git a/src/bin/lttng-sessiond/rotation-thread.cpp b/src/bin/lttng-sessiond/rotation-thread.cpp index 9c873aec5..2f89fbc64 100644 --- a/src/bin/lttng-sessiond/rotation-thread.cpp +++ b/src/bin/lttng-sessiond/rotation-thread.cpp @@ -8,35 +8,35 @@ #define _LGPL_SOURCE #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include -#include - -#include "rotation-thread.h" -#include "lttng-sessiond.h" -#include "health-sessiond.h" -#include "rotate.h" -#include "cmd.h" -#include "session.h" -#include "timer.h" -#include "notification-thread-commands.h" -#include "utils.h" -#include "thread.h" +#include +#include +#include +#include +#include + +#include "rotation-thread.hpp" +#include "lttng-sessiond.hpp" +#include "health-sessiond.hpp" +#include "rotate.hpp" +#include "cmd.hpp" +#include "session.hpp" +#include "timer.hpp" +#include "notification-thread-commands.hpp" +#include "utils.hpp" +#include "thread.hpp" #include #include diff --git a/src/bin/lttng-sessiond/rotation-thread.h b/src/bin/lttng-sessiond/rotation-thread.h deleted file mode 100644 index 27ef3954e..000000000 --- a/src/bin/lttng-sessiond/rotation-thread.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2017 Julien Desfossez - * Copyright (C) 2018 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef ROTATION_THREAD_H -#define ROTATION_THREAD_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "session.h" -#include "notification-thread.h" - -extern struct lttng_notification_channel *rotate_notification_channel; - -enum rotation_thread_job_type { - ROTATION_THREAD_JOB_TYPE_SCHEDULED_ROTATION, - ROTATION_THREAD_JOB_TYPE_CHECK_PENDING_ROTATION -}; - -struct rotation_thread_timer_queue; -struct rotation_thread_handle; - -struct rotation_thread_timer_queue *rotation_thread_timer_queue_create(void); -void rotation_thread_timer_queue_destroy( - struct rotation_thread_timer_queue *queue); - -struct rotation_thread_handle *rotation_thread_handle_create( - struct rotation_thread_timer_queue *rotation_timer_queue, - struct notification_thread_handle *notification_thread_handle); - -void rotation_thread_handle_destroy( - struct rotation_thread_handle *handle); - -void rotation_thread_enqueue_job(struct rotation_thread_timer_queue *queue, - enum rotation_thread_job_type job_type, - struct ltt_session *session); - -bool launch_rotation_thread(struct rotation_thread_handle *handle); - -#endif /* ROTATION_THREAD_H */ diff --git a/src/bin/lttng-sessiond/rotation-thread.hpp b/src/bin/lttng-sessiond/rotation-thread.hpp new file mode 100644 index 000000000..d2bbf2966 --- /dev/null +++ b/src/bin/lttng-sessiond/rotation-thread.hpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2017 Julien Desfossez + * Copyright (C) 2018 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef ROTATION_THREAD_H +#define ROTATION_THREAD_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "session.hpp" +#include "notification-thread.hpp" + +extern struct lttng_notification_channel *rotate_notification_channel; + +enum rotation_thread_job_type { + ROTATION_THREAD_JOB_TYPE_SCHEDULED_ROTATION, + ROTATION_THREAD_JOB_TYPE_CHECK_PENDING_ROTATION +}; + +struct rotation_thread_timer_queue; +struct rotation_thread_handle; + +struct rotation_thread_timer_queue *rotation_thread_timer_queue_create(void); +void rotation_thread_timer_queue_destroy( + struct rotation_thread_timer_queue *queue); + +struct rotation_thread_handle *rotation_thread_handle_create( + struct rotation_thread_timer_queue *rotation_timer_queue, + struct notification_thread_handle *notification_thread_handle); + +void rotation_thread_handle_destroy( + struct rotation_thread_handle *handle); + +void rotation_thread_enqueue_job(struct rotation_thread_timer_queue *queue, + enum rotation_thread_job_type job_type, + struct ltt_session *session); + +bool launch_rotation_thread(struct rotation_thread_handle *handle); + +#endif /* ROTATION_THREAD_H */ diff --git a/src/bin/lttng-sessiond/save.cpp b/src/bin/lttng-sessiond/save.cpp index 2055e867d..16b270514 100644 --- a/src/bin/lttng-sessiond/save.cpp +++ b/src/bin/lttng-sessiond/save.cpp @@ -11,19 +11,19 @@ #include #include -#include -#include -#include -#include -#include -#include - -#include "kernel.h" -#include "save.h" -#include "session.h" -#include "lttng-syscall.h" -#include "trace-ust.h" -#include "agent.h" +#include +#include +#include +#include +#include +#include + +#include "kernel.hpp" +#include "save.hpp" +#include "session.hpp" +#include "lttng-syscall.hpp" +#include "trace-ust.hpp" +#include "agent.hpp" /* Return LTTNG_OK on success else a LTTNG_ERR* code. */ static diff --git a/src/bin/lttng-sessiond/save.h b/src/bin/lttng-sessiond/save.h deleted file mode 100644 index a39a12a84..000000000 --- a/src/bin/lttng-sessiond/save.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) 2013 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef SAVE_H -#define SAVE_H - -#include -#include - -int cmd_save_sessions(struct lttng_save_session_attr *attr, - lttng_sock_cred *creds); - -#endif /* SAVE_H */ diff --git a/src/bin/lttng-sessiond/save.hpp b/src/bin/lttng-sessiond/save.hpp new file mode 100644 index 000000000..367b41c17 --- /dev/null +++ b/src/bin/lttng-sessiond/save.hpp @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2013 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef SAVE_H +#define SAVE_H + +#include +#include + +int cmd_save_sessions(struct lttng_save_session_attr *attr, + lttng_sock_cred *creds); + +#endif /* SAVE_H */ diff --git a/src/bin/lttng-sessiond/session.cpp b/src/bin/lttng-sessiond/session.cpp index 14de5468c..bcab0147d 100644 --- a/src/bin/lttng-sessiond/session.cpp +++ b/src/bin/lttng-sessiond/session.cpp @@ -17,19 +17,19 @@ #include #include -#include -#include -#include -#include -#include -#include "lttng-sessiond.h" -#include "kernel.h" - -#include "session.h" -#include "utils.h" -#include "trace-ust.h" -#include "timer.h" -#include "cmd.h" +#include +#include +#include +#include +#include +#include "lttng-sessiond.hpp" +#include "kernel.hpp" + +#include "session.hpp" +#include "utils.hpp" +#include "trace-ust.hpp" +#include "timer.hpp" +#include "cmd.hpp" struct ltt_session_destroy_notifier_element { ltt_session_destroy_notifier notifier; diff --git a/src/bin/lttng-sessiond/session.h b/src/bin/lttng-sessiond/session.h deleted file mode 100644 index 1a68d8e2f..000000000 --- a/src/bin/lttng-sessiond/session.h +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (C) 2011 EfficiOS Inc. - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef _LTT_SESSION_H -#define _LTT_SESSION_H - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "snapshot.h" -#include "trace-kernel.h" -#include "consumer.h" - -struct ltt_ust_session; - -typedef void (*ltt_session_destroy_notifier)(const struct ltt_session *session, - void *user_data); -typedef void (*ltt_session_clear_notifier)(const struct ltt_session *session, - void *user_data); - -/* - * Tracing session list - * - * Statically declared in session.c and can be accessed by using - * session_get_list() function that returns the pointer to the list. - */ -struct ltt_session_list { - /* - * This lock protects any read/write access to the list and - * next_uuid. All public functions in session.c acquire this - * lock and release it before returning. If none of those - * functions are used, the lock MUST be acquired in order to - * iterate or/and do any actions on that list. - */ - pthread_mutex_t lock; - /* - * This condition variable is signaled on every removal from - * the session list. - */ - pthread_cond_t removal_cond; - - /* - * Session unique ID generator. The session list lock MUST be - * upon update and read of this counter. - */ - uint64_t next_uuid; - - /* Linked list head */ - struct cds_list_head head; -}; - -/* - * This data structure contains information needed to identify a tracing - * session for both LTTng and UST. - */ -struct ltt_session { - char name[NAME_MAX]; - bool has_auto_generated_name; - bool name_contains_creation_time; - char hostname[LTTNG_HOST_NAME_MAX]; /* Local hostname. */ - /* Path of the last closed chunk. */ - char last_chunk_path[LTTNG_PATH_MAX]; - time_t creation_time; - struct ltt_kernel_session *kernel_session; - struct ltt_ust_session *ust_session; - struct urcu_ref ref; - /* - * Protect any read/write on this session data structure. This lock must be - * acquired *before* using any public functions declared below. Use - * session_lock() and session_unlock() for that. - */ - pthread_mutex_t lock; - struct cds_list_head list; - uint64_t id; /* session unique identifier */ - /* Indicates if the session has been added to the session list and ht.*/ - bool published; - /* Indicates if a destroy command has been applied to this session. */ - bool destroyed; - /* UID/GID of the user owning the session */ - uid_t uid; - gid_t gid; - /* - * Network session handle. A value of 0 means that there is no remote - * session established. - */ - uint64_t net_handle; - /* - * This consumer is only set when the create_session_uri call is made. - * This contains the temporary information for a consumer output. Upon - * creation of the UST or kernel session, this consumer, if available, is - * copied into those sessions. - */ - struct consumer_output *consumer; - /* - * Indicates whether or not the user has specified an output directory - * or if it was configured using the default configuration. - */ - bool has_user_specified_directory; - /* Did at least ONE start command has been triggered?. */ - unsigned int has_been_started:1; - /* - * Is the session active? Start trace command sets this to 1 and the stop - * command reset it to 0. - */ - unsigned int active:1; - - /* Snapshot representation in a session. */ - struct snapshot snapshot; - /* Indicate if the session has to output the traces or not. */ - unsigned int output_traces; - /* - * This session is in snapshot mode. This means that channels enabled - * will be set in overwrite mode by default and must be in mmap - * output mode. Note that snapshots can be taken on a session that - * is not in "snapshot_mode". This parameter only affects channel - * creation defaults. - */ - unsigned int snapshot_mode; - /* - * A session that has channels that don't use 'mmap' output can't be - * used to capture snapshots. This is set to true whenever a - * 'splice' kernel channel is enabled. - */ - bool has_non_mmap_channel; - /* - * Timer set when the session is created for live reading. - */ - unsigned int live_timer; - /* - * Path where to keep the shared memory files. - */ - char shm_path[PATH_MAX]; - /* - * Node in ltt_sessions_ht_by_id. - */ - struct lttng_ht_node_u64 node; - /* - * Node in ltt_sessions_ht_by_name. - */ - struct lttng_ht_node_str node_by_name; - /* - * Timer to check periodically if a relay and/or consumer has completed - * the last rotation. - */ - bool rotation_pending_check_timer_enabled; - timer_t rotation_pending_check_timer; - /* Timer to periodically rotate a session. */ - bool rotation_schedule_timer_enabled; - timer_t rotation_schedule_timer; - /* Value for periodic rotations, 0 if disabled. */ - uint64_t rotate_timer_period; - /* Value for size-based rotations, 0 if disabled. */ - uint64_t rotate_size; - /* - * Keep a state if this session was rotated after the last stop command. - * We only allow one rotation after a stop. At destroy, we also need to - * know if a rotation occurred since the last stop to rename the current - * chunk. After a stop followed by rotate, all subsequent clear - * (without prior start) will succeed, but will be effect-less. - */ - bool rotated_after_last_stop; - /* - * Track whether the session was cleared after last stop. All subsequent - * clear (without prior start) will succeed, but will be effect-less. A - * subsequent rotate (without prior start) will return an error. - */ - bool cleared_after_last_stop; - /* - * True if the session has had an explicit non-quiet rotation. - */ - bool rotated; - /* - * Condition and trigger for size-based rotations. - */ - struct lttng_condition *rotate_condition; - struct lttng_trigger *rotate_trigger; - LTTNG_OPTIONAL(uint64_t) most_recent_chunk_id; - struct lttng_trace_chunk *current_trace_chunk; - struct lttng_trace_chunk *chunk_being_archived; - /* Current state of a rotation. */ - enum lttng_rotation_state rotation_state; - bool quiet_rotation; - char *last_archived_chunk_name; - LTTNG_OPTIONAL(uint64_t) last_archived_chunk_id; - struct lttng_dynamic_array destroy_notifiers; - struct lttng_dynamic_array clear_notifiers; - /* Session base path override. Set non-null. */ - char *base_path; -}; - -enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid, - struct ltt_session **out_session); -void session_lock(struct ltt_session *session); -void session_unlock(struct ltt_session *session); - -/* - * The session list lock covers more ground than its name implies. While - * it does protect against concurent mutations of the session list, it is - * also used as a multi-session lock when synchronizing newly-registered - * 'user space tracer' and 'agent' applications. - * - * In other words, it prevents tracer configurations from changing while they - * are being transmitted to the various applications. - */ -void session_lock_list(void); -int session_trylock_list(void); -void session_unlock_list(void); - -void session_destroy(struct ltt_session *session); -int session_add_destroy_notifier(struct ltt_session *session, - ltt_session_destroy_notifier notifier, void *user_data); - -int session_add_clear_notifier(struct ltt_session *session, - ltt_session_clear_notifier notifier, void *user_data); -void session_notify_clear(struct ltt_session *session); - -bool session_get(struct ltt_session *session); -void session_put(struct ltt_session *session); - -enum consumer_dst_type session_get_consumer_destination_type( - const struct ltt_session *session); -const char *session_get_net_consumer_hostname( - const struct ltt_session *session); -void session_get_net_consumer_ports( - const struct ltt_session *session, - uint16_t *control_port, uint16_t *data_port); -struct lttng_trace_archive_location *session_get_trace_archive_location( - const struct ltt_session *session); - -struct ltt_session *session_find_by_name(const char *name); -struct ltt_session *session_find_by_id(uint64_t id); - -struct ltt_session_list *session_get_list(void); -void session_list_wait_empty(void); - -bool session_access_ok(struct ltt_session *session, uid_t uid); - -int session_reset_rotation_state(struct ltt_session *session, - enum lttng_rotation_state result); - -/* Create a new trace chunk object from the session's configuration. */ -struct lttng_trace_chunk *session_create_new_trace_chunk( - const struct ltt_session *session, - const struct consumer_output *consumer_output_override, - const char *session_base_path_override, - const char *chunk_name_override); - -/* - * Set `new_trace_chunk` as the session's current trace chunk. A reference - * to `new_trace_chunk` is acquired by the session. The chunk is created - * on remote peers (consumer and relay daemons). - * - * A reference to the session's current trace chunk is returned through - * `current_session_trace_chunk` on success. - */ -int session_set_trace_chunk(struct ltt_session *session, - struct lttng_trace_chunk *new_trace_chunk, - struct lttng_trace_chunk **current_session_trace_chunk); - -/* - * Close a chunk on the remote peers of a session. Has no effect on the - * ltt_session itself. - */ -int session_close_trace_chunk(struct ltt_session *session, - struct lttng_trace_chunk *trace_chunk, - enum lttng_trace_chunk_command_type close_command, - char *path); - -/* Open a packet in all channels of a given session. */ -enum lttng_error_code session_open_packets(struct ltt_session *session); - -bool session_output_supports_trace_chunks(const struct ltt_session *session); - -/* - * Sample the id of a session looked up via its name. - * Here the term "sampling" hint the caller that this return the id at a given - * point in time with no guarantee that the session for which the id was - * sampled still exist at that point. - * - * Return 0 when the session is not found, - * Return 1 when the session is found and set `id`. - */ -bool sample_session_id_by_name(const char *name, uint64_t *id); - -#endif /* _LTT_SESSION_H */ diff --git a/src/bin/lttng-sessiond/session.hpp b/src/bin/lttng-sessiond/session.hpp new file mode 100644 index 000000000..85450b66a --- /dev/null +++ b/src/bin/lttng-sessiond/session.hpp @@ -0,0 +1,296 @@ +/* + * Copyright (C) 2011 EfficiOS Inc. + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _LTT_SESSION_H +#define _LTT_SESSION_H + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "snapshot.hpp" +#include "trace-kernel.hpp" +#include "consumer.hpp" + +struct ltt_ust_session; + +typedef void (*ltt_session_destroy_notifier)(const struct ltt_session *session, + void *user_data); +typedef void (*ltt_session_clear_notifier)(const struct ltt_session *session, + void *user_data); + +/* + * Tracing session list + * + * Statically declared in session.c and can be accessed by using + * session_get_list() function that returns the pointer to the list. + */ +struct ltt_session_list { + /* + * This lock protects any read/write access to the list and + * next_uuid. All public functions in session.c acquire this + * lock and release it before returning. If none of those + * functions are used, the lock MUST be acquired in order to + * iterate or/and do any actions on that list. + */ + pthread_mutex_t lock; + /* + * This condition variable is signaled on every removal from + * the session list. + */ + pthread_cond_t removal_cond; + + /* + * Session unique ID generator. The session list lock MUST be + * upon update and read of this counter. + */ + uint64_t next_uuid; + + /* Linked list head */ + struct cds_list_head head; +}; + +/* + * This data structure contains information needed to identify a tracing + * session for both LTTng and UST. + */ +struct ltt_session { + char name[NAME_MAX]; + bool has_auto_generated_name; + bool name_contains_creation_time; + char hostname[LTTNG_HOST_NAME_MAX]; /* Local hostname. */ + /* Path of the last closed chunk. */ + char last_chunk_path[LTTNG_PATH_MAX]; + time_t creation_time; + struct ltt_kernel_session *kernel_session; + struct ltt_ust_session *ust_session; + struct urcu_ref ref; + /* + * Protect any read/write on this session data structure. This lock must be + * acquired *before* using any public functions declared below. Use + * session_lock() and session_unlock() for that. + */ + pthread_mutex_t lock; + struct cds_list_head list; + uint64_t id; /* session unique identifier */ + /* Indicates if the session has been added to the session list and ht.*/ + bool published; + /* Indicates if a destroy command has been applied to this session. */ + bool destroyed; + /* UID/GID of the user owning the session */ + uid_t uid; + gid_t gid; + /* + * Network session handle. A value of 0 means that there is no remote + * session established. + */ + uint64_t net_handle; + /* + * This consumer is only set when the create_session_uri call is made. + * This contains the temporary information for a consumer output. Upon + * creation of the UST or kernel session, this consumer, if available, is + * copied into those sessions. + */ + struct consumer_output *consumer; + /* + * Indicates whether or not the user has specified an output directory + * or if it was configured using the default configuration. + */ + bool has_user_specified_directory; + /* Did at least ONE start command has been triggered?. */ + unsigned int has_been_started:1; + /* + * Is the session active? Start trace command sets this to 1 and the stop + * command reset it to 0. + */ + unsigned int active:1; + + /* Snapshot representation in a session. */ + struct snapshot snapshot; + /* Indicate if the session has to output the traces or not. */ + unsigned int output_traces; + /* + * This session is in snapshot mode. This means that channels enabled + * will be set in overwrite mode by default and must be in mmap + * output mode. Note that snapshots can be taken on a session that + * is not in "snapshot_mode". This parameter only affects channel + * creation defaults. + */ + unsigned int snapshot_mode; + /* + * A session that has channels that don't use 'mmap' output can't be + * used to capture snapshots. This is set to true whenever a + * 'splice' kernel channel is enabled. + */ + bool has_non_mmap_channel; + /* + * Timer set when the session is created for live reading. + */ + unsigned int live_timer; + /* + * Path where to keep the shared memory files. + */ + char shm_path[PATH_MAX]; + /* + * Node in ltt_sessions_ht_by_id. + */ + struct lttng_ht_node_u64 node; + /* + * Node in ltt_sessions_ht_by_name. + */ + struct lttng_ht_node_str node_by_name; + /* + * Timer to check periodically if a relay and/or consumer has completed + * the last rotation. + */ + bool rotation_pending_check_timer_enabled; + timer_t rotation_pending_check_timer; + /* Timer to periodically rotate a session. */ + bool rotation_schedule_timer_enabled; + timer_t rotation_schedule_timer; + /* Value for periodic rotations, 0 if disabled. */ + uint64_t rotate_timer_period; + /* Value for size-based rotations, 0 if disabled. */ + uint64_t rotate_size; + /* + * Keep a state if this session was rotated after the last stop command. + * We only allow one rotation after a stop. At destroy, we also need to + * know if a rotation occurred since the last stop to rename the current + * chunk. After a stop followed by rotate, all subsequent clear + * (without prior start) will succeed, but will be effect-less. + */ + bool rotated_after_last_stop; + /* + * Track whether the session was cleared after last stop. All subsequent + * clear (without prior start) will succeed, but will be effect-less. A + * subsequent rotate (without prior start) will return an error. + */ + bool cleared_after_last_stop; + /* + * True if the session has had an explicit non-quiet rotation. + */ + bool rotated; + /* + * Condition and trigger for size-based rotations. + */ + struct lttng_condition *rotate_condition; + struct lttng_trigger *rotate_trigger; + LTTNG_OPTIONAL(uint64_t) most_recent_chunk_id; + struct lttng_trace_chunk *current_trace_chunk; + struct lttng_trace_chunk *chunk_being_archived; + /* Current state of a rotation. */ + enum lttng_rotation_state rotation_state; + bool quiet_rotation; + char *last_archived_chunk_name; + LTTNG_OPTIONAL(uint64_t) last_archived_chunk_id; + struct lttng_dynamic_array destroy_notifiers; + struct lttng_dynamic_array clear_notifiers; + /* Session base path override. Set non-null. */ + char *base_path; +}; + +enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid, + struct ltt_session **out_session); +void session_lock(struct ltt_session *session); +void session_unlock(struct ltt_session *session); + +/* + * The session list lock covers more ground than its name implies. While + * it does protect against concurent mutations of the session list, it is + * also used as a multi-session lock when synchronizing newly-registered + * 'user space tracer' and 'agent' applications. + * + * In other words, it prevents tracer configurations from changing while they + * are being transmitted to the various applications. + */ +void session_lock_list(void); +int session_trylock_list(void); +void session_unlock_list(void); + +void session_destroy(struct ltt_session *session); +int session_add_destroy_notifier(struct ltt_session *session, + ltt_session_destroy_notifier notifier, void *user_data); + +int session_add_clear_notifier(struct ltt_session *session, + ltt_session_clear_notifier notifier, void *user_data); +void session_notify_clear(struct ltt_session *session); + +bool session_get(struct ltt_session *session); +void session_put(struct ltt_session *session); + +enum consumer_dst_type session_get_consumer_destination_type( + const struct ltt_session *session); +const char *session_get_net_consumer_hostname( + const struct ltt_session *session); +void session_get_net_consumer_ports( + const struct ltt_session *session, + uint16_t *control_port, uint16_t *data_port); +struct lttng_trace_archive_location *session_get_trace_archive_location( + const struct ltt_session *session); + +struct ltt_session *session_find_by_name(const char *name); +struct ltt_session *session_find_by_id(uint64_t id); + +struct ltt_session_list *session_get_list(void); +void session_list_wait_empty(void); + +bool session_access_ok(struct ltt_session *session, uid_t uid); + +int session_reset_rotation_state(struct ltt_session *session, + enum lttng_rotation_state result); + +/* Create a new trace chunk object from the session's configuration. */ +struct lttng_trace_chunk *session_create_new_trace_chunk( + const struct ltt_session *session, + const struct consumer_output *consumer_output_override, + const char *session_base_path_override, + const char *chunk_name_override); + +/* + * Set `new_trace_chunk` as the session's current trace chunk. A reference + * to `new_trace_chunk` is acquired by the session. The chunk is created + * on remote peers (consumer and relay daemons). + * + * A reference to the session's current trace chunk is returned through + * `current_session_trace_chunk` on success. + */ +int session_set_trace_chunk(struct ltt_session *session, + struct lttng_trace_chunk *new_trace_chunk, + struct lttng_trace_chunk **current_session_trace_chunk); + +/* + * Close a chunk on the remote peers of a session. Has no effect on the + * ltt_session itself. + */ +int session_close_trace_chunk(struct ltt_session *session, + struct lttng_trace_chunk *trace_chunk, + enum lttng_trace_chunk_command_type close_command, + char *path); + +/* Open a packet in all channels of a given session. */ +enum lttng_error_code session_open_packets(struct ltt_session *session); + +bool session_output_supports_trace_chunks(const struct ltt_session *session); + +/* + * Sample the id of a session looked up via its name. + * Here the term "sampling" hint the caller that this return the id at a given + * point in time with no guarantee that the session for which the id was + * sampled still exist at that point. + * + * Return 0 when the session is not found, + * Return 1 when the session is found and set `id`. + */ +bool sample_session_id_by_name(const char *name, uint64_t *id); + +#endif /* _LTT_SESSION_H */ diff --git a/src/bin/lttng-sessiond/sessiond-config.cpp b/src/bin/lttng-sessiond/sessiond-config.cpp index 228d9c16b..8ebb2a07c 100644 --- a/src/bin/lttng-sessiond/sessiond-config.cpp +++ b/src/bin/lttng-sessiond/sessiond-config.cpp @@ -5,17 +5,17 @@ * */ -#include "version.h" -#include "sessiond-config.h" -#include "lttng-ust-ctl.h" -#include +#include "version.hpp" +#include "sessiond-config.hpp" +#include "lttng-ust-ctl.hpp" +#include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static struct sessiond_config sessiond_config_build_defaults = { diff --git a/src/bin/lttng-sessiond/sessiond-config.h b/src/bin/lttng-sessiond/sessiond-config.h deleted file mode 100644 index 136ca95b8..000000000 --- a/src/bin/lttng-sessiond/sessiond-config.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2017 Jérémie Galarneau - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef LTTNG_SESSIOND_CONFIG_H -#define LTTNG_SESSIOND_CONFIG_H - -#include -#include - -struct config_string { - char *value; - bool should_free; -}; - -struct config_int_range { - int begin, end; -}; - -/* Config string takes ownership of value. */ -void config_string_set(struct config_string *string, char *value); - -struct sessiond_config { - int verbose; - int verbose_consumer; - /* Agent TCP port range for registration. Used by the agent thread. */ - struct config_int_range agent_tcp_port; - - int event_notifier_buffer_size_kernel; - int event_notifier_buffer_size_userspace; - /* Socket timeout for receiving and sending (in seconds). */ - int app_socket_timeout; - - bool quiet; - bool no_kernel; - bool background; - bool daemonize; - bool sig_parent; - - struct config_string tracing_group_name; - - struct config_string kmod_probes_list; - struct config_string kmod_extra_probes_list; - - struct config_string rundir; - - /* Global application Unix socket path */ - struct config_string apps_unix_sock_path; - /* Global client Unix socket path */ - struct config_string client_unix_sock_path; - /* Global wait shm path for UST */ - struct config_string wait_shm_path; - /* Global health check unix path */ - struct config_string health_unix_sock_path; - /* - * LTTNG_UST_CLOCK_PLUGIN environment variable to be passed to spawned - * consumer daemons. - */ - struct config_string lttng_ust_clock_plugin; - struct config_string pid_file_path; - struct config_string lock_file_path; - struct config_string load_session_path; - struct config_string agent_port_file_path; - - struct config_string consumerd32_path; - struct config_string consumerd32_bin_path; - struct config_string consumerd32_lib_dir; - struct config_string consumerd32_err_unix_sock_path; - struct config_string consumerd32_cmd_unix_sock_path; - - struct config_string consumerd64_path; - struct config_string consumerd64_bin_path; - struct config_string consumerd64_lib_dir; - struct config_string consumerd64_err_unix_sock_path; - struct config_string consumerd64_cmd_unix_sock_path; - - struct config_string kconsumerd_path; - struct config_string kconsumerd_err_unix_sock_path; - struct config_string kconsumerd_cmd_unix_sock_path; -}; - -/* Initialize the sessiond_config values to build-defaults. */ -int sessiond_config_init(struct sessiond_config *config); - -/* Override sessiond_config values with values specified by the environment. */ -int sessiond_config_apply_env_config(struct sessiond_config *config); - -void sessiond_config_fini(struct sessiond_config *config); - -int sessiond_config_resolve_paths(struct sessiond_config *config); - -void sessiond_config_log(struct sessiond_config *config); - -#endif /* LTTNG_SESSIOND_CONFIG_H */ diff --git a/src/bin/lttng-sessiond/sessiond-config.hpp b/src/bin/lttng-sessiond/sessiond-config.hpp new file mode 100644 index 000000000..fa0bfeb82 --- /dev/null +++ b/src/bin/lttng-sessiond/sessiond-config.hpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 Jérémie Galarneau + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef LTTNG_SESSIOND_CONFIG_H +#define LTTNG_SESSIOND_CONFIG_H + +#include +#include + +struct config_string { + char *value; + bool should_free; +}; + +struct config_int_range { + int begin, end; +}; + +/* Config string takes ownership of value. */ +void config_string_set(struct config_string *string, char *value); + +struct sessiond_config { + int verbose; + int verbose_consumer; + /* Agent TCP port range for registration. Used by the agent thread. */ + struct config_int_range agent_tcp_port; + + int event_notifier_buffer_size_kernel; + int event_notifier_buffer_size_userspace; + /* Socket timeout for receiving and sending (in seconds). */ + int app_socket_timeout; + + bool quiet; + bool no_kernel; + bool background; + bool daemonize; + bool sig_parent; + + struct config_string tracing_group_name; + + struct config_string kmod_probes_list; + struct config_string kmod_extra_probes_list; + + struct config_string rundir; + + /* Global application Unix socket path */ + struct config_string apps_unix_sock_path; + /* Global client Unix socket path */ + struct config_string client_unix_sock_path; + /* Global wait shm path for UST */ + struct config_string wait_shm_path; + /* Global health check unix path */ + struct config_string health_unix_sock_path; + /* + * LTTNG_UST_CLOCK_PLUGIN environment variable to be passed to spawned + * consumer daemons. + */ + struct config_string lttng_ust_clock_plugin; + struct config_string pid_file_path; + struct config_string lock_file_path; + struct config_string load_session_path; + struct config_string agent_port_file_path; + + struct config_string consumerd32_path; + struct config_string consumerd32_bin_path; + struct config_string consumerd32_lib_dir; + struct config_string consumerd32_err_unix_sock_path; + struct config_string consumerd32_cmd_unix_sock_path; + + struct config_string consumerd64_path; + struct config_string consumerd64_bin_path; + struct config_string consumerd64_lib_dir; + struct config_string consumerd64_err_unix_sock_path; + struct config_string consumerd64_cmd_unix_sock_path; + + struct config_string kconsumerd_path; + struct config_string kconsumerd_err_unix_sock_path; + struct config_string kconsumerd_cmd_unix_sock_path; +}; + +/* Initialize the sessiond_config values to build-defaults. */ +int sessiond_config_init(struct sessiond_config *config); + +/* Override sessiond_config values with values specified by the environment. */ +int sessiond_config_apply_env_config(struct sessiond_config *config); + +void sessiond_config_fini(struct sessiond_config *config); + +int sessiond_config_resolve_paths(struct sessiond_config *config); + +void sessiond_config_log(struct sessiond_config *config); + +#endif /* LTTNG_SESSIOND_CONFIG_H */ diff --git a/src/bin/lttng-sessiond/snapshot.cpp b/src/bin/lttng-sessiond/snapshot.cpp index 727dc5db8..f7821da95 100644 --- a/src/bin/lttng-sessiond/snapshot.cpp +++ b/src/bin/lttng-sessiond/snapshot.cpp @@ -10,10 +10,10 @@ #include #include -#include +#include -#include "snapshot.h" -#include "utils.h" +#include "snapshot.hpp" +#include "utils.hpp" /* * Return the atomically incremented value of next_output_id. diff --git a/src/bin/lttng-sessiond/snapshot.h b/src/bin/lttng-sessiond/snapshot.h deleted file mode 100644 index 027b098c0..000000000 --- a/src/bin/lttng-sessiond/snapshot.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2013 David Goulet - * - * SPDX-License-Identifier: GPL-2.0-only - * - */ - -#ifndef SNAPSHOT_H -#define SNAPSHOT_H - -#include -#include - -#include -#include -#include - -#include "consumer.h" - -struct consumer_output; -struct ltt_session; - -struct snapshot_output { - uint32_t id; - uint64_t max_size; - /* Number of snapshot taken with that output. */ - uint64_t nb_snapshot; - char name[NAME_MAX]; - struct consumer_output *consumer; - int kernel_sockets_copied; - int ust_sockets_copied; - /* - * Contains the string with "-