Fix: consumer handling of metadata for relayd
authorJulien Desfossez <jdesfossez@efficios.com>
Fri, 14 Jun 2013 18:55:23 +0000 (14:55 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 27 Jun 2013 19:08:56 +0000 (15:08 -0400)
This patch sends the metadata stream to relayd and close it once done.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/common/kernel-consumer/kernel-consumer.c

index 29ef3a4ce426d1db8755796fdafffceed43525b6..84be2db463fb0b8cd8a3a6107fd321531eef2aa9 100644 (file)
@@ -350,7 +350,7 @@ end:
  * Returns 0 on success, < 0 on error
  */
 int lttng_kconsumer_snapshot_metadata(uint64_t key, char *path,
-               struct lttng_consumer_local_data *ctx)
+               uint64_t relayd_id, struct lttng_consumer_local_data *ctx)
 {
        struct lttng_consumer_channel *metadata_channel;
        struct lttng_consumer_stream *metadata_stream;
@@ -371,14 +371,22 @@ int lttng_kconsumer_snapshot_metadata(uint64_t key, char *path,
        metadata_stream = metadata_channel->metadata_stream;
        assert(metadata_stream);
 
-       ret = utils_create_stream_file(path, metadata_stream->name,
-                       metadata_stream->chan->tracefile_size,
-                       metadata_stream->tracefile_count_current,
-                       metadata_stream->uid, metadata_stream->gid);
-       if (ret < 0) {
-               goto end;
+       if (relayd_id != (uint64_t) -1ULL) {
+               ret = send_relayd_stream(metadata_stream, path);
+               if (ret < 0) {
+                       ERR("sending stream to relayd");
+               }
+               DBG("Stream %s sent to the relayd", metadata_stream->name);
+       } else {
+               ret = utils_create_stream_file(path, metadata_stream->name,
+                               metadata_stream->chan->tracefile_size,
+                               metadata_stream->tracefile_count_current,
+                               metadata_stream->uid, metadata_stream->gid);
+               if (ret < 0) {
+                       goto end;
+               }
+               metadata_stream->out_fd = ret;
        }
-       metadata_stream->out_fd = ret;
 
        ret = 0;
        while (ret >= 0) {
@@ -393,6 +401,18 @@ int lttng_kconsumer_snapshot_metadata(uint64_t key, char *path,
                }
        }
 
+       if (relayd_id == (uint64_t) -1ULL) {
+               ret = close(metadata_stream->out_fd);
+               if (ret < 0) {
+                       PERROR("Kernel consumer snapshot close out_fd");
+                       goto end;
+               }
+               metadata_stream->out_fd = -1;
+       } else {
+               close_relayd_stream(metadata_stream);
+               metadata_stream->net_seq_idx = (uint64_t) -1ULL;
+       }
+
        ret = 0;
 end:
        rcu_read_unlock();
@@ -619,12 +639,6 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                 */
                new_stream->hangup_flush_done = 0;
 
-               ret = send_relayd_stream(new_stream, NULL);
-               if (ret < 0) {
-                       consumer_del_stream(new_stream, NULL);
-                       goto end_nosignal;
-               }
-
                if (ctx->on_recv_stream) {
                        ret = ctx->on_recv_stream(new_stream);
                        if (ret < 0) {
@@ -647,6 +661,12 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                        break;
                }
 
+               ret = send_relayd_stream(new_stream, NULL);
+               if (ret < 0) {
+                       consumer_del_stream(new_stream, NULL);
+                       goto end_nosignal;
+               }
+
                /* Get the right pipe where the stream will be sent. */
                if (new_stream->metadata_flag) {
                        stream_pipe = ctx->consumer_metadata_pipe;
@@ -734,7 +754,8 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
        {
                if (msg.u.snapshot_channel.metadata == 1) {
                        ret = lttng_kconsumer_snapshot_metadata(msg.u.snapshot_channel.key,
-                                       msg.u.snapshot_channel.pathname, ctx);
+                                       msg.u.snapshot_channel.pathname,
+                                       msg.u.snapshot_channel.relayd_id, ctx);
                        if (ret < 0) {
                                ERR("Snapshot metadata failed");
                                ret_code = LTTNG_ERR_KERN_META_FAIL;
This page took 0.036614 seconds and 4 git commands to generate.