[ltt-dev] [BABELTRACE PATCH] Optionnal file pointer to metadata

Julien Desfossez julien.desfossez at polymtl.ca
Tue Sep 13 20:55:18 EDT 2011


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 at polymtl.ca>
---
 converter/babeltrace.c      |    5 +++--
 formats/bt-dummy/bt-dummy.c |    2 +-
 formats/ctf-text/ctf-text.c |    4 ++--
 formats/ctf/ctf.c           |   42 +++++++++++++++++++++++-------------------
 include/babeltrace/format.h |    2 +-
 5 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/converter/babeltrace.c b/converter/babeltrace.c
index a39c1c4..be54675 100644
--- a/converter/babeltrace.c
+++ b/converter/babeltrace.c
@@ -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>");
diff --git a/formats/bt-dummy/bt-dummy.c b/formats/bt-dummy/bt-dummy.c
index 0850abb..d7f75fb 100644
--- a/formats/bt-dummy/bt-dummy.c
+++ b/formats/bt-dummy/bt-dummy.c
@@ -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;
 
diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c
index fa46a92..f1c1f03 100644
--- a/formats/ctf-text/ctf-text.c
+++ b/formats/ctf-text/ctf-text.c
@@ -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;
diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c
index 93d13e8..d94d55e 100644
--- a/formats/ctf/ctf.c
+++ b/formats/ctf/ctf.c
@@ -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,21 +631,25 @@ 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;
+		}
 
-	if (babeltrace_debug)
-		yydebug = 1;
+		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;
+		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)) {
@@ -1142,7 +1146,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 +1174,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 +1226,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 +1239,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;
diff --git a/include/babeltrace/format.h b/include/babeltrace/format.h
index 1b45b4b..5b2f694 100644
--- a/include/babeltrace/format.h
+++ b/include/babeltrace/format.h
@@ -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);
 };
 
-- 
1.7.5.4





More information about the lttng-dev mailing list