Revert "Fix: get_new_metadata receive all the metadata"
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 20 Feb 2014 03:20:43 +0000 (22:20 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 20 Feb 2014 03:20:43 +0000 (22:20 -0500)
This reverts commit bb17fa55a7694db83af6f00b16b3e545712662f7.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/lttng-live/lttng-live-comm.c

index 1266a95dd549340864c4438b7da272a641caee02..f9ed51e1b3a1aaa9829309e01ce10aac5649e2f7 100644 (file)
@@ -66,8 +66,6 @@ static void ctf_live_packet_seek(struct bt_stream_pos *stream_pos,
                size_t index, int whence);
 static void add_traces(gpointer key, gpointer value, gpointer user_data);
 static int del_traces(gpointer key, gpointer value, gpointer user_data);
-static int get_new_metadata(struct lttng_live_ctx *ctx,
-               struct lttng_live_viewer_stream *viewer_stream);
 
 int lttng_live_connect_viewer(struct lttng_live_ctx *ctx)
 {
@@ -633,10 +631,6 @@ int get_data_packet(struct lttng_live_ctx *ctx,
        case LTTNG_VIEWER_GET_PACKET_ERR:
                if (rp.flags & LTTNG_VIEWER_FLAG_NEW_METADATA) {
                        printf_verbose("get_data_packet: new metadata needed\n");
-                       ret = get_new_metadata(ctx, stream);
-                       if (ret < 0) {
-                               goto error;
-                       }
                        ret = 0;
                        goto end;
                }
@@ -716,23 +710,30 @@ error:
        return ret;
 }
 
+/*
+ * Return number of metadata bytes written or a negative value on error.
+ */
 static
-int get_one_metadata_packet(struct lttng_live_ctx *ctx,
-               struct lttng_live_viewer_stream *metadata_stream)
+int get_new_metadata(struct lttng_live_ctx *ctx,
+               struct lttng_live_viewer_stream *viewer_stream,
+               uint64_t *metadata_len)
 {
        uint64_t len = 0;
        int ret;
        struct lttng_viewer_cmd cmd;
        struct lttng_viewer_get_metadata rq;
        struct lttng_viewer_metadata_packet rp;
+       struct lttng_live_viewer_stream *metadata_stream;
        char *data = NULL;
        ssize_t ret_len;
 
-       rq.stream_id = htobe64(metadata_stream->id);
        cmd.cmd = htobe32(LTTNG_VIEWER_GET_METADATA);
        cmd.data_size = sizeof(rq);
        cmd.cmd_version = 0;
 
+       metadata_stream = viewer_stream->ctf_trace->metadata_stream;
+       rq.stream_id = htobe64(metadata_stream->id);
+
        do {
                ret_len = send(ctx->control_sock, &cmd, sizeof(cmd), 0);
        } while (ret_len < 0 && errno == EINTR);
@@ -774,7 +775,7 @@ int get_one_metadata_packet(struct lttng_live_ctx *ctx,
                        break;
                case LTTNG_VIEWER_NO_NEW_METADATA:
                        printf_verbose("get_metadata : NO NEW\n");
-                       ret = 0;
+                       ret = -1;
                        goto end;
                case LTTNG_VIEWER_METADATA_ERR:
                        printf_verbose("get_metadata : ERR\n");
@@ -825,43 +826,16 @@ int get_one_metadata_packet(struct lttng_live_ctx *ctx,
                goto error;
        }
        assert(ret_len == len);
-       ret = len;
 
        free(data);
 
+       *metadata_len = len;
+       ret = 0;
 end:
 error:
        return ret;
 }
 
-/*
- * Return 0 on success, a negative value on error.
- */
-static
-int get_new_metadata(struct lttng_live_ctx *ctx,
-               struct lttng_live_viewer_stream *viewer_stream)
-{
-       int ret = 0;
-       struct lttng_live_viewer_stream *metadata_stream;
-
-       metadata_stream = viewer_stream->ctf_trace->metadata_stream;
-
-       do {
-               /*
-                * get_one_metadata_packet returns the number of bytes
-                * received, 0 when we have received everything, a
-                * negative value on error.
-                */
-               ret = get_one_metadata_packet(ctx, metadata_stream);
-       } while (ret > 0);
-
-       fclose(metadata_stream->metadata_fp_write);
-       metadata_stream->metadata_fp_write = NULL;
-
-error:
-       return ret;
-}
-
 /*
  * Get one index for a stream.
  *
@@ -876,6 +850,7 @@ int get_next_index(struct lttng_live_ctx *ctx,
        struct lttng_viewer_get_next_index rq;
        struct lttng_viewer_index rp;
        int ret;
+       uint64_t metadata_len;
        ssize_t ret_len;
 
        cmd.cmd = htobe32(LTTNG_VIEWER_GET_NEXT_INDEX);
@@ -941,7 +916,8 @@ retry:
 
                if (rp.flags & LTTNG_VIEWER_FLAG_NEW_METADATA) {
                        printf_verbose("get_next_index: new metadata needed\n");
-                       ret = get_new_metadata(ctx, viewer_stream);
+                       ret = get_new_metadata(ctx, viewer_stream,
+                                       &metadata_len);
                        if (ret < 0) {
                                goto error;
                        }
@@ -1180,7 +1156,8 @@ int del_traces(gpointer key, gpointer value, gpointer user_data)
 static
 void add_traces(gpointer key, gpointer value, gpointer user_data)
 {
-       int i, ret;
+       int i, ret, total_metadata = 0;
+       uint64_t metadata_len;
        struct bt_context *bt_ctx = user_data;
        struct lttng_live_ctf_trace *trace = value;
        struct lttng_live_viewer_stream *stream;
@@ -1213,9 +1190,13 @@ void add_traces(gpointer key, gpointer value, gpointer user_data)
                        bt_list_add(&new_mmap_stream->list, &mmap_list.head);
                } else {
                        /* Get all possible metadata before starting */
-                       ret = get_new_metadata(ctx, stream);
-                       if (ret)
-                               goto end_free;
+                       do {
+                               ret = get_new_metadata(ctx, stream,
+                                               &metadata_len);
+                               if (ret == 0) {
+                                       total_metadata += metadata_len;
+                               }
+                       } while (ret == 0 || total_metadata == 0);
                        trace->metadata_fp = fopen(stream->path, "r");
                }
        }
This page took 0.027203 seconds and 4 git commands to generate.