From: Mathieu Desnoyers Date: Tue, 8 Nov 2011 14:59:54 +0000 (-0500) Subject: init private data X-Git-Tag: v1.9.1~122 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d028eddb5959160ef6ec4b09f786730910d0f8f8;p=lttng-ust.git init private data Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 5068a3b3..9ce39701 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -221,7 +221,8 @@ struct ltt_channel_ops { unsigned int switch_timer_interval, unsigned int read_timer_interval, int *shm_fd, int *wait_fd, - uint64_t *memory_map_size); + uint64_t *memory_map_size, + struct ltt_channel *chan_priv_init); void (*channel_destroy)(struct ltt_channel *ltt_chan); struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan, struct lttng_ust_shm_handle *handle, @@ -306,7 +307,8 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, unsigned int switch_timer_interval, unsigned int read_timer_interval, int *shm_fd, int *wait_fd, - uint64_t *memory_map_size); + uint64_t *memory_map_size, + struct ltt_channel *chan_priv_init); struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, int overwrite, void *buf_addr, size_t subbuf_size, size_t num_subbuf, diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index d31412c6..4c41531a 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -293,7 +293,8 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, unsigned int switch_timer_interval, unsigned int read_timer_interval, int *shm_fd, int *wait_fd, - uint64_t *memory_map_size) + uint64_t *memory_map_size, + struct ltt_channel *chan_priv_init) { struct ltt_channel *chan = NULL; struct ltt_transport *transport; @@ -306,6 +307,8 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, transport_name); goto notransport; } + chan_priv_init->id = session->free_chan_id++; + chan_priv_init->session = session; /* * Note: the channel creation op already writes into the packet * headers. Therefore the "chan" information used as input @@ -314,11 +317,9 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, chan = transport->ops.channel_create("[lttng]", buf_addr, subbuf_size, num_subbuf, switch_timer_interval, read_timer_interval, shm_fd, wait_fd, - memory_map_size); + memory_map_size, chan_priv_init); if (!chan) goto create_error; - chan->session = session; - chan->id = session->free_chan_id++; chan->enabled = 1; chan->ops = &transport->ops; cds_list_add(&chan->list, &session->chan); diff --git a/liblttng-ust/ltt-ring-buffer-client.h b/liblttng-ust/ltt-ring-buffer-client.h index abbaf705..8844ae28 100644 --- a/liblttng-ust/ltt-ring-buffer-client.h +++ b/liblttng-ust/ltt-ring-buffer-client.h @@ -386,7 +386,8 @@ struct ltt_channel *_channel_create(const char *name, unsigned int switch_timer_interval, unsigned int read_timer_interval, int *shm_fd, int *wait_fd, - uint64_t *memory_map_size) + uint64_t *memory_map_size, + struct ltt_channel *chan_priv_init) { void *priv; struct ltt_channel *ltt_chan = NULL; @@ -394,6 +395,7 @@ struct ltt_channel *_channel_create(const char *name, handle = channel_create(&client_config, name, &priv, __alignof__(*ltt_chan), sizeof(*ltt_chan), + chan_priv_init, buf_addr, subbuf_size, num_subbuf, switch_timer_interval, read_timer_interval, shm_fd, wait_fd, memory_map_size); diff --git a/liblttng-ust/ltt-ring-buffer-metadata-client.h b/liblttng-ust/ltt-ring-buffer-metadata-client.h index 46aab3cc..0fd4d222 100644 --- a/liblttng-ust/ltt-ring-buffer-metadata-client.h +++ b/liblttng-ust/ltt-ring-buffer-metadata-client.h @@ -169,7 +169,8 @@ struct ltt_channel *_channel_create(const char *name, unsigned int switch_timer_interval, unsigned int read_timer_interval, int *shm_fd, int *wait_fd, - uint64_t *memory_map_size) + uint64_t *memory_map_size, + struct ltt_channel *chan_priv_init) { void *priv; struct ltt_channel *ltt_chan = NULL; @@ -177,6 +178,7 @@ struct ltt_channel *_channel_create(const char *name, handle = channel_create(&client_config, name, &priv, __alignof__(*ltt_chan), sizeof(*ltt_chan), + chan_priv_init, buf_addr, subbuf_size, num_subbuf, switch_timer_interval, read_timer_interval, shm_fd, wait_fd, memory_map_size); diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 639165eb..e7ef1579 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -370,6 +370,7 @@ int lttng_abi_create_channel(int session_objd, struct ltt_channel *chan; int chan_objd; int ret = 0; + struct ltt_channel chan_priv_init; chan_objd = objd_alloc(NULL, <tng_channel_ops); if (chan_objd < 0) { @@ -397,6 +398,10 @@ int lttng_abi_create_channel(int session_objd, transport_name = ""; break; } + memset(&chan_priv_init, 0, sizeof(chan_priv_init)); + /* Copy of session UUID for consumer (availability through shm) */ + memcpy(chan_priv_init.uuid, session->uuid, sizeof(session->uuid)); + /* * We tolerate no failure path after channel creation. It will stay * invariant for the rest of the session. @@ -408,7 +413,8 @@ int lttng_abi_create_channel(int session_objd, chan_param->read_timer_interval, &chan_param->shm_fd, &chan_param->wait_fd, - &chan_param->memory_map_size); + &chan_param->memory_map_size, + &chan_priv_init); if (!chan) { ret = -EINVAL; goto chan_error; @@ -421,8 +427,6 @@ int lttng_abi_create_channel(int session_objd, } /* The channel created holds a reference on the session */ objd_ref(session_objd); - /* Copy of session UUID for consumer (availability through shm) */ - memcpy(chan->uuid, session->uuid, sizeof(session->uuid)); return chan_objd; diff --git a/libringbuffer/frontend.h b/libringbuffer/frontend.h index 993a3917..eb95e622 100644 --- a/libringbuffer/frontend.h +++ b/libringbuffer/frontend.h @@ -47,6 +47,7 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff void **priv_data, size_t priv_data_align, size_t priv_data_size, + void *priv_data_init, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index fdb4bdfc..6de83368 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -411,6 +411,7 @@ static void channel_free(struct channel *chan, struct lttng_ust_shm_handle *hand * @name: name of the channel * @priv_data: ring buffer client private data area pointer (output) * @priv_data_size: length, in bytes, of the private data area. + * @priv_data_init: initialization data for private data. * @buf_addr: pointer the the beginning of the preallocated buffer contiguous * address mapping. It is used only by RING_BUFFER_STATIC * configuration. It can be set to NULL for other backends. @@ -429,6 +430,7 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff void **priv_data, size_t priv_data_align, size_t priv_data_size, + void *priv_data_init, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, unsigned int read_timer_interval, @@ -486,6 +488,7 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff if (!shmp(handle, priv_data_alloc)) goto error_append; *priv_data = channel_get_private(chan); + memcpy(*priv_data, priv_data_init, priv_data_size); } else { chan->priv_data_offset = -1; *priv_data = NULL;