From 0a30bf9be799ddb162530ea7581172e923055973 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 4 Jul 2019 08:59:08 -0400 Subject: [PATCH] Use a "comm" variant of the LTTNG_OPTIONAL helper in sessiond-comm MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The LTTNG_OPTIONAL helper is currently communication safe (as long as LTTNG_PACKED is used). However, this could change in the future. An LTTNG_OPTIONAL_COMM alias is introduced in order to make it easier to change the layout of LTTNG_OPTIONAL should it become necessary in the future. Signed-off-by: Jérémie Galarneau --- src/common/optional.h | 13 ++++++++++--- src/common/sessiond-comm/sessiond-comm.h | 10 +++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/common/optional.h b/src/common/optional.h index 1da5fda5d..aee5fcc5e 100644 --- a/src/common/optional.h +++ b/src/common/optional.h @@ -32,9 +32,6 @@ * Prefer using this macro where "special" values would be used, e.g. * -1ULL for uint64_t types. * - * LTTNG_OPTIONAL should be combined with the LTTNG_PACKED macro when - * used for IPC / network communication. - * * Declaration example: * struct my_struct { * int a; @@ -57,6 +54,16 @@ type value; \ } +/* + * Alias used for communication structures. If the layout of an LTTNG_OPTIONAL + * is changed, the original layout should still be used for communication + * purposes. + * + * LTTNG_OPTIONAL_COMM should be combined with the LTTNG_PACKED macro when + * used for IPC / network communication. + */ +#define LTTNG_OPTIONAL_COMM LTTNG_OPTIONAL + /* * This macro is available as a 'convenience' to allow sites that assume * an optional value is set to assert() that it is set when accessing it. diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index 3b0093bfb..d9177cf37 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -480,7 +480,7 @@ struct lttcomm_consumer_msg { uint64_t channel_key; uint64_t session_id; /* ID of the session's current trace chunk. */ - LTTNG_OPTIONAL(uint64_t) LTTNG_PACKED chunk_id; + LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id; char pathname[PATH_MAX]; uint64_t relayd_id; /* nb_init_streams is the number of streams open initially. */ @@ -542,7 +542,7 @@ struct lttcomm_consumer_msg { uint64_t relayd_id; /* Relayd id if apply. */ uint64_t key; /* Unique channel key. */ /* ID of the session's current trace chunk. */ - LTTNG_OPTIONAL(uint64_t) LTTNG_PACKED chunk_id; + LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id; unsigned char uuid[UUID_LEN]; /* uuid for ust tracer. */ uint32_t chan_id; /* Channel ID on the tracer side. */ uint64_t tracefile_size; /* bytes */ @@ -634,7 +634,7 @@ struct lttcomm_consumer_msg { * `override_name` is left NULL (all-zeroes) if the * chunk's name is not overriden. */ - LTTNG_OPTIONAL(uint64_t) LTTNG_PACKED relayd_id; + LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id; char override_name[LTTNG_NAME_MAX]; uint64_t session_id; uint64_t chunk_id; @@ -645,13 +645,13 @@ struct lttcomm_consumer_msg { } LTTNG_PACKED credentials; } LTTNG_PACKED create_trace_chunk; struct { - LTTNG_OPTIONAL(uint64_t) LTTNG_PACKED relayd_id; + LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id; uint64_t session_id; uint64_t chunk_id; uint64_t close_timestamp; } LTTNG_PACKED close_trace_chunk; struct { - LTTNG_OPTIONAL(uint64_t) LTTNG_PACKED relayd_id; + LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id; uint64_t session_id; uint64_t chunk_id; } LTTNG_PACKED trace_chunk_exists; -- 2.34.1