From 193183fb924aef705f30358e54e7386a3a64c78d Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 22 Sep 2011 22:00:56 -0400 Subject: [PATCH] Export consumer ABI, implement ring buffer modifications for consumer Signed-off-by: Mathieu Desnoyers --- include/lttng-ust-comm.h | 3 + include/ust/lttng-events.h | 12 ++- include/ust/lttng-ust-abi.h | 4 + libringbuffer/backend_types.h | 2 +- libringbuffer/frontend.h | 14 +++- libringbuffer/ring_buffer_backend.c | 18 ++--- libringbuffer/ring_buffer_frontend.c | 95 +++++++++++++++++------- libringbuffer/shm.c | 33 ++++++++ libringbuffer/shm.h | 4 +- libust/ltt-events.c | 7 +- libust/ltt-ring-buffer-client.h | 7 +- libust/ltt-ring-buffer-metadata-client.h | 7 +- libust/lttng-ust-abi.c | 5 +- libust/lttng-ust-comm.c | 26 +++++-- tests/hello/hello.c | 2 +- 15 files changed, 186 insertions(+), 53 deletions(-) diff --git a/include/lttng-ust-comm.h b/include/lttng-ust-comm.h index d792074e..2e5c7173 100644 --- a/include/lttng-ust-comm.h +++ b/include/lttng-ust-comm.h @@ -142,6 +142,9 @@ struct lttcomm_ust_reply { uint32_t ret_code; /* enum enum lttcomm_return_code */ uint32_t ret_val; /* return value */ union { + struct { + uint64_t memory_map_size; + } channel; struct { uint64_t memory_map_size; } stream; diff --git a/include/ust/lttng-events.h b/include/ust/lttng-events.h index db475cdb..005bf0d2 100644 --- a/include/ust/lttng-events.h +++ b/include/ust/lttng-events.h @@ -206,7 +206,9 @@ struct ltt_channel_ops { void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval); + unsigned int read_timer_interval, + int *shm_fd, int *wait_fd, + uint64_t *memory_map_size); void (*channel_destroy)(struct ltt_channel *ltt_chan); struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan, struct shm_handle *handle, @@ -278,12 +280,16 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval); + unsigned int read_timer_interval, + int *shm_fd, int *wait_fd, + uint64_t *memory_map_size); struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, int overwrite, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval); + unsigned int read_timer_interval, + int *shm_fd, int *wait_fd, + uint64_t *memory_map_size); struct ltt_event *ltt_event_create(struct ltt_channel *chan, struct lttng_ust_event *event_param, diff --git a/include/ust/lttng-ust-abi.h b/include/ust/lttng-ust-abi.h index 73eb61f3..ef1e7e54 100644 --- a/include/ust/lttng-ust-abi.h +++ b/include/ust/lttng-ust-abi.h @@ -41,6 +41,10 @@ struct lttng_ust_channel { unsigned int switch_timer_interval; /* usecs */ unsigned int read_timer_interval; /* usecs */ enum lttng_ust_output output; /* output mode */ + /* The following fields are used internally within UST. */ + int shm_fd; + int wait_fd; + uint64_t memory_map_size; }; /* diff --git a/libringbuffer/backend_types.h b/libringbuffer/backend_types.h index 51dcfbf9..2eb03b55 100644 --- a/libringbuffer/backend_types.h +++ b/libringbuffer/backend_types.h @@ -71,7 +71,7 @@ struct channel_backend { unsigned long num_subbuf; /* Number of sub-buffers for writer */ u64 start_tsc; /* Channel creation TSC value */ void *priv; /* Client-specific information */ - const struct lib_ring_buffer_config *config; /* Ring buffer configuration */ + struct lib_ring_buffer_config config; /* Ring buffer configuration */ char name[NAME_MAX]; /* Channel name */ struct lib_ring_buffer_shmp buf[]; }; diff --git a/libringbuffer/frontend.h b/libringbuffer/frontend.h index c1d8dd42..a88a4003 100644 --- a/libringbuffer/frontend.h +++ b/libringbuffer/frontend.h @@ -42,7 +42,19 @@ struct shm_handle *channel_create(const struct lib_ring_buffer_config *config, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval); + unsigned int read_timer_interval, + int *shm_fd, int *wait_fd, + uint64_t *memory_map_size); + +/* channel_handle_create - for consumer. */ +extern +struct shm_handle *channel_handle_create(int shm_fd, int wait_fd, + uint64_t memory_map_size); + +/* channel_handle_add_stream - for consumer. */ +extern +int channel_handle_add_stream(struct shm_handle *handle, + int shm_fd, int wait_fd, uint64_t memory_map_size); /* * channel_destroy returns the private data pointer. It finalizes all channel's diff --git a/libringbuffer/ring_buffer_backend.c b/libringbuffer/ring_buffer_backend.c index 72ddacf3..55b5f4c2 100644 --- a/libringbuffer/ring_buffer_backend.c +++ b/libringbuffer/ring_buffer_backend.c @@ -118,7 +118,7 @@ int lib_ring_buffer_backend_create(struct lib_ring_buffer_backend *bufb, struct shm_handle *handle, struct shm_object *shmobj) { - const struct lib_ring_buffer_config *config = chanb->config; + const struct lib_ring_buffer_config *config = &chanb->config; set_shmp(bufb->chan, handle->chan._ref); bufb->cpu = cpu; @@ -141,7 +141,7 @@ void lib_ring_buffer_backend_reset(struct lib_ring_buffer_backend *bufb, struct shm_handle *handle) { struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend; - const struct lib_ring_buffer_config *config = chanb->config; + const struct lib_ring_buffer_config *config = &chanb->config; unsigned long num_subbuf_alloc; unsigned int i; @@ -175,7 +175,7 @@ void lib_ring_buffer_backend_reset(struct lib_ring_buffer_backend *bufb, void channel_backend_reset(struct channel_backend *chanb) { struct channel *chan = caa_container_of(chanb, struct channel, backend); - const struct lib_ring_buffer_config *config = chanb->config; + const struct lib_ring_buffer_config *config = &chanb->config; /* * Don't reset buf_size, subbuf_size, subbuf_size_order, @@ -246,7 +246,7 @@ int channel_backend_init(struct channel_backend *chanb, chanb->num_subbuf = num_subbuf; strncpy(chanb->name, name, NAME_MAX); chanb->name[NAME_MAX - 1] = '\0'; - chanb->config = config; + memcpy(&chanb->config, config, sizeof(*config)); /* Per-cpu buffer size: control (prior to backend) */ shmsize = offset_align(shmsize, __alignof__(struct lib_ring_buffer)); @@ -336,7 +336,7 @@ end: void channel_backend_free(struct channel_backend *chanb, struct shm_handle *handle) { - const struct lib_ring_buffer_config *config = chanb->config; + const struct lib_ring_buffer_config *config = &chanb->config; unsigned int i; if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) { @@ -370,7 +370,7 @@ size_t lib_ring_buffer_read(struct lib_ring_buffer_backend *bufb, size_t offset, void *dest, size_t len, struct shm_handle *handle) { struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend; - const struct lib_ring_buffer_config *config = chanb->config; + const struct lib_ring_buffer_config *config = &chanb->config; ssize_t orig_len; struct lib_ring_buffer_backend_pages_shmp *rpages; unsigned long sb_bindex, id; @@ -408,7 +408,7 @@ int lib_ring_buffer_read_cstr(struct lib_ring_buffer_backend *bufb, size_t offse void *dest, size_t len, struct shm_handle *handle) { struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend; - const struct lib_ring_buffer_config *config = chanb->config; + const struct lib_ring_buffer_config *config = &chanb->config; ssize_t string_len, orig_offset; char *str; struct lib_ring_buffer_backend_pages_shmp *rpages; @@ -451,7 +451,7 @@ void *lib_ring_buffer_read_offset_address(struct lib_ring_buffer_backend *bufb, { struct lib_ring_buffer_backend_pages_shmp *rpages; struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend; - const struct lib_ring_buffer_config *config = chanb->config; + const struct lib_ring_buffer_config *config = &chanb->config; unsigned long sb_bindex, id; offset &= chanb->buf_size - 1; @@ -480,7 +480,7 @@ void *lib_ring_buffer_offset_address(struct lib_ring_buffer_backend *bufb, size_t sbidx; struct lib_ring_buffer_backend_pages_shmp *rpages; struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend; - const struct lib_ring_buffer_config *config = chanb->config; + const struct lib_ring_buffer_config *config = &chanb->config; unsigned long sb_bindex, id; offset &= chanb->buf_size - 1; diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index 7dab1594..5d87782e 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -116,7 +116,7 @@ void lib_ring_buffer_reset(struct lib_ring_buffer *buf, struct shm_handle *handle) { struct channel *chan = shmp(handle, buf->backend.chan); - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned int i; /* @@ -172,7 +172,7 @@ int lib_ring_buffer_create(struct lib_ring_buffer *buf, struct shm_handle *handle, struct shm_object *shmobj) { - const struct lib_ring_buffer_config *config = chanb->config; + const struct lib_ring_buffer_config *config = &chanb->config; struct channel *chan = caa_container_of(chanb, struct channel, backend); void *priv = chanb->priv; unsigned int num_subbuf; @@ -244,7 +244,7 @@ static void switch_buffer_timer(unsigned long data) { struct lib_ring_buffer *buf = (struct lib_ring_buffer *)data; struct channel *chan = shmp(handle, buf->backend.chan); - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; /* * Only flush buffers periodically if readers are active. @@ -266,7 +266,7 @@ static void lib_ring_buffer_start_switch_timer(struct lib_ring_buffer *buf, struct shm_handle *handle) { struct channel *chan = shmp(handle, buf->backend.chan); - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; if (!chan->switch_timer_interval || buf->switch_timer_enabled) return; @@ -303,7 +303,7 @@ static void read_buffer_timer(unsigned long data) { struct lib_ring_buffer *buf = (struct lib_ring_buffer *)data; struct channel *chan = shmp(handle, buf->backend.chan); - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; CHAN_WARN_ON(chan, !buf->backend.allocated); @@ -328,7 +328,7 @@ static void lib_ring_buffer_start_read_timer(struct lib_ring_buffer *buf, struct shm_handle *handle) { struct channel *chan = shmp(handle, buf->backend.chan); - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; if (config->wakeup != RING_BUFFER_WAKEUP_BY_TIMER || !chan->read_timer_interval @@ -352,7 +352,7 @@ static void lib_ring_buffer_stop_read_timer(struct lib_ring_buffer *buf, struct shm_handle *handle) { struct channel *chan = shmp(handle, buf->backend.chan); - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; if (config->wakeup != RING_BUFFER_WAKEUP_BY_TIMER || !chan->read_timer_interval @@ -376,7 +376,7 @@ static void lib_ring_buffer_stop_read_timer(struct lib_ring_buffer *buf, static void channel_unregister_notifiers(struct channel *chan, struct shm_handle *handle) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; int cpu; if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) { @@ -427,13 +427,15 @@ struct shm_handle *channel_create(const struct lib_ring_buffer_config *config, const char *name, void *priv, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval) + unsigned int read_timer_interval, + int *shm_fd, int *wait_fd, uint64_t *memory_map_size) { int ret, cpu; size_t shmsize; struct channel *chan; struct shm_handle *handle; struct shm_object *shmobj; + struct shm_ref *ref; if (lib_ring_buffer_check_config(config, switch_timer_interval, read_timer_interval)) @@ -493,7 +495,8 @@ struct shm_handle *channel_create(const struct lib_ring_buffer_config *config, lib_ring_buffer_start_switch_timer(buf, handle); lib_ring_buffer_start_read_timer(buf, handle); } - + ref = &handle->chan._ref; + shm_get_object_data(handle, ref, shm_fd, wait_fd, memory_map_size); return handle; error_backend_init: @@ -504,6 +507,48 @@ error_table_alloc: return NULL; } +struct shm_handle *channel_handle_create(int shm_fd, int wait_fd, + uint64_t memory_map_size) +{ + struct shm_handle *handle; + struct shm_object *object; + + handle = zmalloc(sizeof(struct shm_handle)); + if (!handle) + return NULL; + + /* Allocate table for channel + per-cpu buffers */ + handle->table = shm_object_table_create(1 + num_possible_cpus()); + if (!handle->table) + goto error_table_alloc; + /* Add channel object */ + object = shm_object_table_append_shadow(handle->table, + shm_fd, wait_fd, memory_map_size); + if (!object) + goto error_table_object; + + return handle; + +error_table_object: + shm_object_table_destroy(handle->table); +error_table_alloc: + free(handle); + return NULL; +} + +int channel_handle_add_stream(struct shm_handle *handle, + int shm_fd, int wait_fd, uint64_t memory_map_size) +{ + struct shm_object *object; + + /* Add stream object */ + object = shm_object_table_append_shadow(handle->table, + shm_fd, wait_fd, memory_map_size); + if (!object) + return -1; + return 0; +} + static void channel_release(struct channel *chan, struct shm_handle *handle) { @@ -523,7 +568,7 @@ void channel_release(struct channel *chan, struct shm_handle *handle) */ void *channel_destroy(struct channel *chan, struct shm_handle *handle) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; void *priv; int cpu; @@ -632,7 +677,7 @@ int lib_ring_buffer_snapshot(struct lib_ring_buffer *buf, struct shm_handle *handle) { struct channel *chan = shmp(handle, buf->backend.chan); - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned long consumed_cur, write_offset; int finalized; @@ -715,7 +760,7 @@ int lib_ring_buffer_get_subbuf(struct lib_ring_buffer *buf, struct shm_handle *handle) { struct channel *chan = shmp(handle, buf->backend.chan); - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned long consumed_cur, consumed_idx, commit_count, write_offset; int ret; int finalized; @@ -809,7 +854,7 @@ void lib_ring_buffer_put_subbuf(struct lib_ring_buffer *buf, { struct lib_ring_buffer_backend *bufb = &buf->backend; struct channel *chan = shmp(handle, bufb->chan); - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned long read_sb_bindex, consumed_idx, consumed; CHAN_WARN_ON(chan, uatomic_read(&buf->active_readers) != 1); @@ -869,7 +914,7 @@ void lib_ring_buffer_print_subbuffer_errors(struct lib_ring_buffer *buf, int cpu, struct shm_handle *handle) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned long cons_idx, commit_count, commit_count_sb; cons_idx = subbuf_index(cons_offset, chan); @@ -895,7 +940,7 @@ void lib_ring_buffer_print_buffer_errors(struct lib_ring_buffer *buf, void *priv, int cpu, struct shm_handle *handle) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned long write_offset, cons_offset; /* @@ -931,7 +976,7 @@ void lib_ring_buffer_print_errors(struct channel *chan, struct lib_ring_buffer *buf, int cpu, struct shm_handle *handle) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; void *priv = chan->backend.priv; ERRMSG("ring buffer %s, cpu %d: %lu records written, " @@ -966,7 +1011,7 @@ void lib_ring_buffer_switch_old_start(struct lib_ring_buffer *buf, u64 tsc, struct shm_handle *handle) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned long oldidx = subbuf_index(offsets->old, chan); unsigned long commit_count; @@ -1004,7 +1049,7 @@ void lib_ring_buffer_switch_old_end(struct lib_ring_buffer *buf, u64 tsc, struct shm_handle *handle) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned long oldidx = subbuf_index(offsets->old - 1, chan); unsigned long commit_count, padding_size, data_size; @@ -1041,7 +1086,7 @@ void lib_ring_buffer_switch_new_start(struct lib_ring_buffer *buf, u64 tsc, struct shm_handle *handle) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned long beginidx = subbuf_index(offsets->begin, chan); unsigned long commit_count; @@ -1077,7 +1122,7 @@ void lib_ring_buffer_switch_new_end(struct lib_ring_buffer *buf, u64 tsc, struct shm_handle *handle) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned long endidx = subbuf_index(offsets->end - 1, chan); unsigned long commit_count, padding_size, data_size; @@ -1112,7 +1157,7 @@ int lib_ring_buffer_try_switch_slow(enum switch_mode mode, struct switch_offsets *offsets, u64 *tsc) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; unsigned long off; offsets->begin = v_read(config, &buf->offset); @@ -1172,7 +1217,7 @@ void lib_ring_buffer_switch_slow(struct lib_ring_buffer *buf, enum switch_mode m struct shm_handle *handle) { struct channel *chan = shmp(handle, buf->backend.chan); - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; struct switch_offsets offsets; unsigned long oldidx; u64 tsc; @@ -1232,7 +1277,7 @@ int lib_ring_buffer_try_reserve_slow(struct lib_ring_buffer *buf, struct switch_offsets *offsets, struct lib_ring_buffer_ctx *ctx) { - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; struct shm_handle *handle = ctx->handle; unsigned long reserve_commit_diff; @@ -1369,7 +1414,7 @@ int lib_ring_buffer_reserve_slow(struct lib_ring_buffer_ctx *ctx) { struct channel *chan = ctx->chan; struct shm_handle *handle = ctx->handle; - const struct lib_ring_buffer_config *config = chan->backend.config; + const struct lib_ring_buffer_config *config = &chan->backend.config; struct lib_ring_buffer *buf; struct switch_offsets offsets; int ret; diff --git a/libringbuffer/shm.c b/libringbuffer/shm.c index 0d92572d..ae63b004 100644 --- a/libringbuffer/shm.c +++ b/libringbuffer/shm.c @@ -165,6 +165,39 @@ error_pipe: } +struct shm_object *shm_object_table_append_shadow(struct shm_object_table *table, + int shm_fd, int wait_fd, size_t memory_map_size) +{ + struct shm_object *obj; + char *memory_map; + + if (table->allocated_len >= table->size) + return NULL; + obj = &table->objects[table->allocated_len]; + + /* wait_fd: set read end of the pipe. */ + obj->wait_fd[0] = wait_fd; + obj->wait_fd[1] = -1; /* write end is unset. */ + obj->shm_fd = shm_fd; + + /* memory_map: mmap */ + memory_map = mmap(NULL, memory_map_size, PROT_READ | PROT_WRITE, + MAP_SHARED, shm_fd, 0); + if (memory_map == MAP_FAILED) { + PERROR("mmap"); + goto error_mmap; + } + obj->memory_map = memory_map; + obj->memory_map_size = memory_map_size; + obj->allocated_len = memory_map_size; + obj->index = table->allocated_len++; + + return obj; + +error_mmap: + return NULL; +} + static void shmp_object_destroy(struct shm_object *obj) { diff --git a/libringbuffer/shm.h b/libringbuffer/shm.h index 5785b71d..45b6473d 100644 --- a/libringbuffer/shm.h +++ b/libringbuffer/shm.h @@ -60,6 +60,8 @@ void _set_shmp(struct shm_ref *ref, struct shm_ref src) #define set_shmp(ref, src) _set_shmp(&(ref)._ref, src) struct shm_object_table *shm_object_table_create(size_t max_nb_obj); +struct shm_object *shm_object_table_append_shadow(struct shm_object_table *table, + int shm_fd, int wait_fd, size_t memory_map_size); void shm_object_table_destroy(struct shm_object_table *table); struct shm_object *shm_object_table_append(struct shm_object_table *table, size_t memory_map_size); @@ -117,7 +119,7 @@ int shm_get_object_data(struct shm_handle *handle, struct shm_ref *ref, obj = &table->objects[index]; *shm_fd = obj->shm_fd; *wait_fd = obj->wait_fd[0]; - *memory_map_size = obj->memory_map_size; + *memory_map_size = obj->allocated_len; return 0; } diff --git a/libust/ltt-events.c b/libust/ltt-events.c index 8f21d458..18fb8599 100644 --- a/libust/ltt-events.c +++ b/libust/ltt-events.c @@ -299,7 +299,9 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval) + unsigned int read_timer_interval, + int *shm_fd, int *wait_fd, + uint64_t *memory_map_size) { struct ltt_channel *chan; struct ltt_transport *transport; @@ -324,7 +326,8 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, */ transport->ops.channel_create("[lttng]", chan, buf_addr, subbuf_size, num_subbuf, switch_timer_interval, - read_timer_interval); + read_timer_interval, shm_fd, wait_fd, + memory_map_size); if (!chan->chan) goto create_error; chan->enabled = 1; diff --git a/libust/ltt-ring-buffer-client.h b/libust/ltt-ring-buffer-client.h index 605a2828..f3a1a27a 100644 --- a/libust/ltt-ring-buffer-client.h +++ b/libust/ltt-ring-buffer-client.h @@ -380,11 +380,14 @@ struct ltt_channel *_channel_create(const char *name, struct ltt_channel *ltt_chan, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval) + unsigned int read_timer_interval, + int *shm_fd, int *wait_fd, + uint64_t *memory_map_size) { ltt_chan->handle = channel_create(&client_config, name, ltt_chan, buf_addr, subbuf_size, num_subbuf, switch_timer_interval, - read_timer_interval); + read_timer_interval, shm_fd, wait_fd, + memory_map_size); if (!ltt_chan->handle) return NULL; ltt_chan->chan = shmp(ltt_chan->handle, ltt_chan->handle->chan); diff --git a/libust/ltt-ring-buffer-metadata-client.h b/libust/ltt-ring-buffer-metadata-client.h index dd168465..fa79485c 100644 --- a/libust/ltt-ring-buffer-metadata-client.h +++ b/libust/ltt-ring-buffer-metadata-client.h @@ -160,11 +160,14 @@ struct ltt_channel *_channel_create(const char *name, struct ltt_channel *ltt_chan, void *buf_addr, size_t subbuf_size, size_t num_subbuf, unsigned int switch_timer_interval, - unsigned int read_timer_interval) + unsigned int read_timer_interval, + int *shm_fd, int *wait_fd, + uint64_t *memory_map_size) { ltt_chan->handle = channel_create(&client_config, name, ltt_chan, buf_addr, subbuf_size, num_subbuf, switch_timer_interval, - read_timer_interval); + read_timer_interval, shm_fd, wait_fd, + memory_map_size); if (!ltt_chan->handle) return NULL; ltt_chan->chan = shmp(ltt_chan->handle, ltt_chan->handle->chan); diff --git a/libust/lttng-ust-abi.c b/libust/lttng-ust-abi.c index 0c0d6bb7..cea8c30b 100644 --- a/libust/lttng-ust-abi.c +++ b/libust/lttng-ust-abi.c @@ -408,7 +408,10 @@ int lttng_abi_create_channel(int session_objd, chan_param->subbuf_size, chan_param->num_subbuf, chan_param->switch_timer_interval, - chan_param->read_timer_interval); + chan_param->read_timer_interval, + &chan_param->shm_fd, + &chan_param->wait_fd, + &chan_param->memory_map_size); if (!chan) { ret = -EINVAL; goto chan_error; diff --git a/libust/lttng-ust-comm.c b/libust/lttng-ust-comm.c index d88c4afb..2e7e1a35 100644 --- a/libust/lttng-ust-comm.c +++ b/libust/lttng-ust-comm.c @@ -235,6 +235,7 @@ int handle_message(struct sock_info *sock_info, int ret = 0; const struct objd_ops *ops; struct lttcomm_ust_reply lur; + int shm_fd, wait_fd; ust_lock(); @@ -280,28 +281,43 @@ end: if (ret >= 0) { lur.ret_code = LTTCOMM_OK; } else { - lur.ret_code = LTTCOMM_SESSION_FAIL; + //lur.ret_code = LTTCOMM_SESSION_FAIL; + lur.ret_code = ret; } - if (lum->cmd == LTTNG_UST_STREAM) { + switch (lum->cmd) { + case LTTNG_UST_STREAM: /* * Special-case reply to send stream info. * Use lum.u output. */ lur.u.stream.memory_map_size = lum->u.stream.memory_map_size; + shm_fd = lum->u.stream.shm_fd; + wait_fd = lum->u.stream.wait_fd; + break; + case LTTNG_UST_CHANNEL: + lur.u.channel.memory_map_size = lum->u.channel.memory_map_size; + shm_fd = lum->u.channel.shm_fd; + wait_fd = lum->u.channel.wait_fd; + break; } ret = send_reply(sock, &lur); + if (ret < 0) { + perror("error sending reply"); + goto error; + } - if (lum->cmd == LTTNG_UST_STREAM && ret >= 0) { + if ((lum->cmd == LTTNG_UST_STREAM || lum->cmd == LTTNG_UST_CHANNEL) + && lur.ret_code == LTTCOMM_OK) { /* we also need to send the file descriptors. */ ret = lttcomm_send_fds_unix_sock(sock, - &lum->u.stream.shm_fd, &lum->u.stream.shm_fd, + &shm_fd, &shm_fd, 1, sizeof(int)); if (ret < 0) { perror("send shm_fd"); goto error; } ret = lttcomm_send_fds_unix_sock(sock, - &lum->u.stream.wait_fd, &lum->u.stream.wait_fd, + &wait_fd, &wait_fd, 1, sizeof(int)); if (ret < 0) { perror("send wait_fd"); diff --git a/tests/hello/hello.c b/tests/hello/hello.c index 72a30d09..03d07b67 100644 --- a/tests/hello/hello.c +++ b/tests/hello/hello.c @@ -74,7 +74,7 @@ int main(int argc, char **argv) printf("Hello, World!\n"); - sleep(1); + sleep(10); //for (i = 0; i < 50; i++) { for (i = 0; i < 1000000; i++) { -- 2.34.1