Optional file pointer to metadata
authorJulien Desfossez <julien.desfossez@polymtl.ca>
Wed, 14 Sep 2011 02:48:18 +0000 (22:48 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 14 Sep 2011 02:48:18 +0000 (22:48 -0400)
For some use-cases it may be useful to control the file pointer to the
metadata instead of lookup absolutely for a file named "metadata" in the
trace directory. If the pointer is NULL, we fallback to the original
mode.

Signed-off-by: Julien Desfossez <julien.desfossez@polymtl.ca>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/babeltrace.c
formats/bt-dummy/bt-dummy.c
formats/ctf-text/ctf-text.c
formats/ctf/ctf.c
include/babeltrace/format.h

index a39c1c452e0222c10db118ad19ffb3b4695d933c..be546750e96921b55fb871ae8aa70ddd7c6f3f76 100644 (file)
@@ -212,7 +212,8 @@ static int traverse_dir(const char *fpath, const struct stat *sb,
        } else {
                close(fd);
                close(dirfd);
-               td_read = fmt_read->open_trace(fpath, O_RDONLY, ctf_move_pos_slow);
+               td_read = fmt_read->open_trace(fpath, O_RDONLY, ctf_move_pos_slow,
+                               NULL);
                if (!td_read) {
                        fprintf(stdout, "Error opening trace \"%s\" "
                                        "for reading.\n\n", fpath);
@@ -290,7 +291,7 @@ int main(int argc, char **argv)
                return 0;
        }
 
-       td_write = fmt_write->open_trace(opt_output_path, O_RDWR, NULL);
+       td_write = fmt_write->open_trace(opt_output_path, O_RDWR, NULL, NULL);
        if (!td_write) {
                fprintf(stdout, "Error opening trace \"%s\" for writing.\n\n",
                        opt_output_path ? : "<none>");
index 0850abba8433986cbd1c6632ec6c63a006c02dcd..d7f75fb1a9c2f8d83fbb2866d3f21b640ab0002e 100644 (file)
@@ -41,7 +41,7 @@ int bt_dummy_write_event(struct stream_pos *ppos,
 static
 struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
-                       int whence))
+                       int whence), FILE *metadata_fp)
 {
        struct ctf_text_stream_pos *pos;
 
index fa46a9262a184293aa396c37f3b094aef565e95d..f1c1f037a1e979d5301650bae1b39f805a9b44de 100644 (file)
@@ -36,7 +36,7 @@
 
 struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
-                       int whence));
+                       int whence), FILE *metadata_fp);
 void ctf_text_close_trace(struct trace_descriptor *descriptor);
 
 static
@@ -229,7 +229,7 @@ error:
 
 struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
-                       int whence))
+                       int whence), FILE *metadata_fp)
 {
        struct ctf_text_stream_pos *pos;
        FILE *fp;
index 93d13e8a5bc5bfcbfefe75529181fe5d41ab8fc0..f9f9e47fde8947812b40034077431f04584a7000 100644 (file)
@@ -57,7 +57,7 @@ extern int yydebug;
 static
 struct trace_descriptor *ctf_open_trace(const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
-                       int whence));
+                       int whence), FILE *metadata_fp);
 static
 void ctf_close_trace(struct trace_descriptor *descriptor);
 
@@ -613,7 +613,7 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp,
 static
 int ctf_open_trace_metadata_read(struct ctf_trace *td,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
-                       int whence))
+                       int whence), FILE *metadata_fp)
 {
        struct ctf_scanner *scanner;
        struct ctf_file_stream *metadata_stream;
@@ -631,23 +631,26 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td,
                goto end_stream;
        }
 
-       td->metadata = &metadata_stream->parent;
-       metadata_stream->pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
-       if (metadata_stream->pos.fd < 0) {
-               fprintf(stdout, "Unable to open metadata.\n");
-               return metadata_stream->pos.fd;
-       }
+       if (metadata_fp) {
+               fp = metadata_fp;
+       } else {
+               td->metadata = &metadata_stream->parent;
+               metadata_stream->pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
+               if (metadata_stream->pos.fd < 0) {
+                       fprintf(stdout, "Unable to open metadata.\n");
+                       return metadata_stream->pos.fd;
+               }
 
+               fp = fdopen(metadata_stream->pos.fd, "r");
+               if (!fp) {
+                       fprintf(stdout, "[error] Unable to open metadata stream.\n");
+                       ret = -errno;
+                       goto end_stream;
+               }
+       }
        if (babeltrace_debug)
                yydebug = 1;
 
-       fp = fdopen(metadata_stream->pos.fd, "r");
-       if (!fp) {
-               fprintf(stdout, "[error] Unable to open metadata stream.\n");
-               ret = -errno;
-               goto end_stream;
-       }
-
        if (packet_metadata(td, fp)) {
                ret = ctf_open_trace_metadata_stream_read(td, &fp, &buf);
                if (ret)
@@ -1142,7 +1145,7 @@ error:
 static
 int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
-                       int whence))
+                       int whence), FILE *metadata_fp)
 {
        int ret;
        struct dirent *dirent;
@@ -1170,7 +1173,7 @@ int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags,
         * Keep the metadata file separate.
         */
 
-       ret = ctf_open_trace_metadata_read(td, move_pos_slow);
+       ret = ctf_open_trace_metadata_read(td, move_pos_slow, metadata_fp);
        if (ret) {
                goto error_metadata;
        }
@@ -1222,7 +1225,7 @@ error:
 static
 struct trace_descriptor *ctf_open_trace(const char *path, int flags,
                void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
-                       int whence))
+                       int whence), FILE *metadata_fp)
 {
        struct ctf_trace *td;
        int ret;
@@ -1235,7 +1238,7 @@ struct trace_descriptor *ctf_open_trace(const char *path, int flags,
                        fprintf(stdout, "[error] Path missing for input CTF trace.\n");
                        goto error;
                }
-               ret = ctf_open_trace_read(td, path, flags, move_pos_slow);
+               ret = ctf_open_trace_read(td, path, flags, move_pos_slow, metadata_fp);
                if (ret)
                        goto error;
                break;
index 1b45b4ba8dfe6c9c73c2cd1e260b5e80ded03916..5b2f694573b65caf00df81ba17a3f4ad912d6999 100644 (file)
@@ -36,7 +36,7 @@ struct format {
 
        struct trace_descriptor *(*open_trace)(const char *path, int flags,
                        void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
-                               int whence));
+                               int whence), FILE *metadata_fp);
        void (*close_trace)(struct trace_descriptor *descriptor);
 };
 
This page took 0.029636 seconds and 4 git commands to generate.