Export consumer ABI, implement ring buffer modifications for consumer
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 23 Sep 2011 02:00:56 +0000 (22:00 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 23 Sep 2011 02:00:56 +0000 (22:00 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
15 files changed:
include/lttng-ust-comm.h
include/ust/lttng-events.h
include/ust/lttng-ust-abi.h
libringbuffer/backend_types.h
libringbuffer/frontend.h
libringbuffer/ring_buffer_backend.c
libringbuffer/ring_buffer_frontend.c
libringbuffer/shm.c
libringbuffer/shm.h
libust/ltt-events.c
libust/ltt-ring-buffer-client.h
libust/ltt-ring-buffer-metadata-client.h
libust/lttng-ust-abi.c
libust/lttng-ust-comm.c
tests/hello/hello.c

index d792074e3810eb5a0ed5e54428cdc4a10a27b4a7..2e5c7173c40668e6ca76c78d156aa911f660c020 100644 (file)
@@ -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;
index db475cdb25959fa48eb17abb2d92603352689088..005bf0d26013831a3295be6c0a5d65d7cdff6956 100644 (file)
@@ -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,
index 73eb61f3f4d11cbb48c0dd4ead8a1b7a98f7c548..ef1e7e542548140f612bcfeaef94d5cdb7c28483 100644 (file)
@@ -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;
 };
 
 /*
index 51dcfbf9a7a9238776d2392d66e6ed03659e7bc1..2eb03b55dee2628e6bcca25a74cfd50702289d93 100644 (file)
@@ -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[];
 };
index c1d8dd4276962b769395df9e6407dd934b9da11a..a88a400395cde93aeeecdea3f6dcfbcb39167bce 100644 (file)
@@ -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
index 72ddacf3d54e5abd395e9acb4ab999e9ab744153..55b5f4c228dd84677f5de5ef5b773adaf584a46a 100644 (file)
@@ -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;
index 7dab1594c3061a178d0c279e7f2c5fdb19d7eefd..5d87782ee321e79d51e8164d0f80087369872b06 100644 (file)
@@ -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;
index 0d92572d7b5b6170d79ed7e457e115bba957b7ef..ae63b004fd50723cd9c73511049bb8d042928f59 100644 (file)
@@ -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)
 {
index 5785b71d8483d26c3684bdd8875c70aa13f00ca2..45b6473d6fb0e9cee2a8e4c551e4d421912b020c 100644 (file)
@@ -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;
 }
 
index 8f21d458080b150f13c998fb3dd546a2cb1b963b..18fb8599ee09a5e87b5f529cbe4c4750d57185bf 100644 (file)
@@ -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;
index 605a28284e7e32c74664ff25190db46b7c7ddad5..f3a1a27aaca49629e5831de7b3a2156993f68cd3 100644 (file)
@@ -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);
index dd168465655f5a646c8c62f4a3ded71210c03e26..fa79485c98634d4892ef45c9199a0764add004f6 100644 (file)
@@ -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);
index 0c0d6bb726f9c62804f9f17ee7f726bd5627bf93..cea8c30bffe8d29e39d4792bbfd6032b62c21d4c 100644 (file)
@@ -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;
index d88c4afb2346c000dedd5a96c9fa5239f37bb265..2e7e1a3515abd1f6b46024364ddb1747057e8a4f 100644 (file)
@@ -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");
index 72a30d0996c9c51751492875e3061fd213921baa..03d07b675e8e99107ec12c78bd6a5de1f4ef9815 100644 (file)
@@ -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++) {
This page took 0.038142 seconds and 4 git commands to generate.