Refactoring: struct lttng_ust_channel_ops
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 16 Mar 2021 20:31:30 +0000 (16:31 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 16 Mar 2021 20:31:30 +0000 (16:31 -0400)
- Move internal fields to struct lttng_ust_channel_ops_private.
- Add private/public relationships between the two structures.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Id8018d8e11df6db569e20fffb6f2ed08e47c452e

include/lttng/ust-events.h
liblttng-ust-ctl/ustctl.c
liblttng-ust/lttng-ring-buffer-client.h
liblttng-ust/lttng-ring-buffer-metadata-client.h
liblttng-ust/lttng-ust-abi.c
liblttng-ust/ust-events-internal.h

index 703bd24cc06d4bb8da1c24655fde73a5dd7ba844..5025b1877f58d9e1e337b757a9bae6de54a6e6f4 100644 (file)
@@ -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);
 
index 84476a97966a7eae18f767c6f6683e269b80b603..2a7c7d8a39ca0d3beadecdbab820fd90666b6999 100644 (file)
@@ -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);
index 31934b674637c71df83351a65c05fc07ea1bcfeb..188efb0fe12960880b0c1ae5d5cdcb8455a4b944 100644 (file)
@@ -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 = &lttng_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,
index ae606b4cc21a577cd0b85746ef273d8bc4f357a4..2b2aae7dc9920b5a5ce56e9401d3831450ce1cfa 100644 (file)
@@ -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 = &lttng_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,
 };
index 4674d000a804043ec2a54cc328de978711d84cf0..428061295de57168e37a53e3ddcf25ce66a6f006 100644 (file)
@@ -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;
        }
index be0fa963e11ed1e337543218111ac62d4b9d05bd..44d605c666141071e87aa4b947aeb4b804603908 100644 (file)
@@ -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)
This page took 0.029879 seconds and 4 git commands to generate.