From: Mathieu Desnoyers Date: Tue, 16 Mar 2021 20:31:30 +0000 (-0400) Subject: Refactoring: struct lttng_ust_channel_ops X-Git-Tag: v2.13.0-rc1~268 X-Git-Url: http://git.lttng.org/?p=lttng-ust.git;a=commitdiff_plain;h=a880bae51b3d8e927f68ceae2804636976bd62d8 Refactoring: struct lttng_ust_channel_ops - Move internal fields to struct lttng_ust_channel_ops_private. - Add private/public relationships between the two structures. Signed-off-by: Mathieu Desnoyers Change-Id: Id8018d8e11df6db569e20fffb6f2ed08e47c452e --- diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 703bd24c..5025b187 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -438,6 +438,7 @@ struct lttng_ust_event_notifier { struct lttng_ust_lib_ring_buffer_channel; struct lttng_ust_shm_handle; +struct lttng_ust_channel_ops_private; /* * IMPORTANT: this structure is part of the ABI between the probe and @@ -451,32 +452,13 @@ struct lttng_ust_shm_handle; struct lttng_ust_channel_ops { uint32_t struct_size; - struct lttng_channel *(*channel_create)(const char *name, - void *buf_addr, - size_t subbuf_size, size_t num_subbuf, - unsigned int switch_timer_interval, - unsigned int read_timer_interval, - unsigned char *uuid, - uint32_t chan_id, - const int *stream_fds, int nr_stream_fds, - int64_t blocking_timeout); - void (*channel_destroy)(struct lttng_channel *chan); + struct lttng_ust_channel_ops_private *priv; /* Private channel ops interface */ + int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx, uint32_t event_id); void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx); void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src, size_t len); - /* - * packet_avail_size returns the available size in the current - * packet. Note that the size returned is only a hint, since it - * may change due to concurrent writes. - */ - size_t (*packet_avail_size)(struct lttng_ust_lib_ring_buffer_channel *chan, - struct lttng_ust_shm_handle *handle); - int (*is_finalized)(struct lttng_ust_lib_ring_buffer_channel *chan); - int (*is_disabled)(struct lttng_ust_lib_ring_buffer_channel *chan); - int (*flush_buffer)(struct lttng_ust_lib_ring_buffer_channel *chan, - struct lttng_ust_shm_handle *handle); void (*event_strcpy)(struct lttng_ust_lib_ring_buffer_ctx *ctx, const char *src, size_t len); diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index 84476a97..2a7c7d8a 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -1279,7 +1279,7 @@ struct ustctl_consumer_channel * if (!chan) return NULL; - chan->chan = transport->ops.channel_create(transport_name, NULL, + chan->chan = transport->ops.priv->channel_create(transport_name, NULL, attr->subbuf_size, attr->num_subbuf, attr->switch_timer_interval, attr->read_timer_interval, @@ -1304,7 +1304,7 @@ void ustctl_destroy_channel(struct ustctl_consumer_channel *chan) { (void) ustctl_channel_close_wait_fd(chan); (void) ustctl_channel_close_wakeup_fd(chan); - chan->chan->ops->channel_destroy(chan->chan); + chan->chan->ops->priv->channel_destroy(chan->chan); free(chan); } @@ -1350,7 +1350,7 @@ int ustctl_write_metadata_to_channel( for (pos = 0; pos < len; pos += reserve_len) { reserve_len = min_t(size_t, - chan->ops->packet_avail_size(chan->chan, chan->handle), + chan->ops->priv->packet_avail_size(chan->chan, chan->handle), len - pos); lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len, sizeof(char), -1, chan->handle); @@ -1397,7 +1397,7 @@ ssize_t ustctl_write_one_packet_to_channel( int ret; reserve_len = min_t(ssize_t, - chan->ops->packet_avail_size(chan->chan, chan->handle), + chan->ops->priv->packet_avail_size(chan->chan, chan->handle), len); lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len, sizeof(char), -1, chan->handle); diff --git a/liblttng-ust/lttng-ring-buffer-client.h b/liblttng-ust/lttng-ring-buffer-client.h index 31934b67..188efb0f 100644 --- a/liblttng-ust/lttng-ring-buffer-client.h +++ b/liblttng-ust/lttng-ring-buffer-client.h @@ -797,15 +797,18 @@ static struct lttng_transport lttng_relay_transport = { .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING "-mmap", .ops = { .struct_size = sizeof(struct lttng_ust_channel_ops), - .channel_create = _channel_create, - .channel_destroy = lttng_channel_destroy, + .priv = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_channel_ops_private, { + .pub = <tng_relay_transport.ops, + .channel_create = _channel_create, + .channel_destroy = lttng_channel_destroy, + .packet_avail_size = NULL, /* Would be racy anyway */ + .is_finalized = lttng_is_finalized, + .is_disabled = lttng_is_disabled, + .flush_buffer = lttng_flush_buffer, + }), .event_reserve = lttng_event_reserve, .event_commit = lttng_event_commit, .event_write = lttng_event_write, - .packet_avail_size = NULL, /* Would be racy anyway */ - .is_finalized = lttng_is_finalized, - .is_disabled = lttng_is_disabled, - .flush_buffer = lttng_flush_buffer, .event_strcpy = lttng_event_strcpy, }, .client_config = &client_config, diff --git a/liblttng-ust/lttng-ring-buffer-metadata-client.h b/liblttng-ust/lttng-ring-buffer-metadata-client.h index ae606b4c..2b2aae7d 100644 --- a/liblttng-ust/lttng-ring-buffer-metadata-client.h +++ b/liblttng-ust/lttng-ring-buffer-metadata-client.h @@ -320,15 +320,18 @@ static struct lttng_transport lttng_relay_transport = { .ops = { .struct_size = sizeof(struct lttng_ust_channel_ops), - .channel_create = _channel_create, - .channel_destroy = lttng_channel_destroy, + .priv = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_channel_ops_private, { + .pub = <tng_relay_transport.ops, + .channel_create = _channel_create, + .channel_destroy = lttng_channel_destroy, + .packet_avail_size = lttng_packet_avail_size, + .is_finalized = lttng_is_finalized, + .is_disabled = lttng_is_disabled, + .flush_buffer = lttng_flush_buffer, + }), .event_reserve = lttng_event_reserve, .event_commit = lttng_event_commit, .event_write = lttng_event_write, - .packet_avail_size = lttng_packet_avail_size, - .is_finalized = lttng_is_finalized, - .is_disabled = lttng_is_disabled, - .flush_buffer = lttng_flush_buffer, }, .client_config = &client_config, }; diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 4674d000..42806129 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -1227,7 +1227,7 @@ long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg, case LTTNG_UST_ABI_DISABLE: return lttng_channel_disable(channel); case LTTNG_UST_ABI_FLUSH_BUFFER: - return channel->ops->flush_buffer(channel->chan, channel->handle); + return channel->ops->priv->flush_buffer(channel->chan, channel->handle); default: return -EINVAL; } diff --git a/liblttng-ust/ust-events-internal.h b/liblttng-ust/ust-events-internal.h index be0fa963..44d605c6 100644 --- a/liblttng-ust/ust-events-internal.h +++ b/liblttng-ust/ust-events-internal.h @@ -315,6 +315,32 @@ struct lttng_enum { uint64_t id; /* Enumeration ID in sessiond */ }; +struct lttng_ust_channel_ops_private { + struct lttng_ust_channel_ops *pub; /* Public channels ops interface */ + + struct lttng_channel *(*channel_create)(const char *name, + void *buf_addr, + size_t subbuf_size, size_t num_subbuf, + unsigned int switch_timer_interval, + unsigned int read_timer_interval, + unsigned char *uuid, + uint32_t chan_id, + const int *stream_fds, int nr_stream_fds, + int64_t blocking_timeout); + void (*channel_destroy)(struct lttng_channel *chan); + /* + * packet_avail_size returns the available size in the current + * packet. Note that the size returned is only a hint, since it + * may change due to concurrent writes. + */ + size_t (*packet_avail_size)(struct lttng_ust_lib_ring_buffer_channel *chan, + struct lttng_ust_shm_handle *handle); + int (*is_finalized)(struct lttng_ust_lib_ring_buffer_channel *chan); + int (*is_disabled)(struct lttng_ust_lib_ring_buffer_channel *chan); + int (*flush_buffer)(struct lttng_ust_lib_ring_buffer_channel *chan, + struct lttng_ust_shm_handle *handle); +}; + static inline struct lttng_enabler *lttng_event_enabler_as_enabler( struct lttng_event_enabler *event_enabler)