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>
} else {
close(fd);
close(dirfd);
} 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);
if (!td_read) {
fprintf(stdout, "Error opening trace \"%s\" "
"for reading.\n\n", fpath);
- 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>");
if (!td_write) {
fprintf(stdout, "Error opening trace \"%s\" for writing.\n\n",
opt_output_path ? : "<none>");
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,
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), FILE *metadata_fp)
{
struct ctf_text_stream_pos *pos;
{
struct ctf_text_stream_pos *pos;
struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
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), FILE *metadata_fp);
void ctf_text_close_trace(struct trace_descriptor *descriptor);
static
void ctf_text_close_trace(struct trace_descriptor *descriptor);
static
struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
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), FILE *metadata_fp)
{
struct ctf_text_stream_pos *pos;
FILE *fp;
{
struct ctf_text_stream_pos *pos;
FILE *fp;
static
struct trace_descriptor *ctf_open_trace(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
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), FILE *metadata_fp);
static
void ctf_close_trace(struct trace_descriptor *descriptor);
static
void ctf_close_trace(struct trace_descriptor *descriptor);
static
int ctf_open_trace_metadata_read(struct ctf_trace *td,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
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), FILE *metadata_fp)
{
struct ctf_scanner *scanner;
struct ctf_file_stream *metadata_stream;
{
struct ctf_scanner *scanner;
struct ctf_file_stream *metadata_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;
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)
if (packet_metadata(td, fp)) {
ret = ctf_open_trace_metadata_stream_read(td, &fp, &buf);
if (ret)
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,
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), FILE *metadata_fp)
{
int ret;
struct dirent *dirent;
{
int ret;
struct dirent *dirent;
* Keep the metadata file separate.
*/
* 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;
}
if (ret) {
goto error_metadata;
}
static
struct trace_descriptor *ctf_open_trace(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
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), FILE *metadata_fp)
{
struct ctf_trace *td;
int ret;
{
struct ctf_trace *td;
int ret;
fprintf(stdout, "[error] Path missing for input CTF trace.\n");
goto error;
}
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;
if (ret)
goto error;
break;
struct trace_descriptor *(*open_trace)(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
struct trace_descriptor *(*open_trace)(const char *path, int flags,
void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+ int whence), FILE *metadata_fp);
void (*close_trace)(struct trace_descriptor *descriptor);
};
void (*close_trace)(struct trace_descriptor *descriptor);
};