Fix: sink.ctf.fs: remove spurious directory level when using assume-single-trace
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 2 Dec 2020 21:04:19 +0000 (16:04 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 9 Dec 2020 19:22:47 +0000 (14:22 -0500)
commit0bbddf6c16d140f60870ccc9442b26fed6e54dc5
tree6811fa3739b2f07979f790ba6304b977e83774ea
parente30908cfe5b1a65d01c52cf21e7134abf9697eaf
Fix: sink.ctf.fs: remove spurious directory level when using assume-single-trace

The behavior of `sink.ctf.fs` with the `assume-single-trace=true`
parameter does not match the documentation nor the comments in the code.
The man page says:

    If the assume-single-trace parameter is true, then the output trace
    path to use for the single input trace is the directory specified by
    the path parameter.

What I understand from this is that if you pass `path=/tmp/yo`, that
should produce the `/tmp/yo/metadata` file and the data files alongside
it.

The documentation on the `fs_sink_comp::assume_single_trace` says:

    /*
     * True if the component assumes that it will only write a
     * single CTF trace (which can contain one or more data
     * streams). This makes the component write the stream files
     * directly in the output directory (`output_dir_path` above).
     */
    bool assume_single_trace;

The `output_dir_path` would contain `/tmp/yo`, in the previous example,
so that confirms the previous assumption.

The actual behavior is that the sink puts the trace in an extra `trace`
directory, in `/tmp/yo/trace`.

We end up with the `trace` relative trace path (relative to the base
output directory) because `make_trace_path_rel` returns an empty string
when `assume_single_trace` is true and `sanitize_trace_path` replaces it
with `trace`.

When using `assume-single-trace=true`, we should not deal with a
relative trace path, as the trace is output directly in the base output
directory.  We also don't want to run the path in
`make_unique_trace_path`, as the trace should be output in the base
directory specified by the user, not another directory.  Anyway, if the
user specifies  an existing directory, `sink.ctf.fs` will initially
error out with:

    Single trace mode, but output path exists: output-path="/tmp/yo"

Although that's a TOCTOU bug, two babeltrace instances could both check
at the same time that the same output directory does not exist, and both
write in the same directory.  That would not be good.

Change-Id: Ib2415420eabbc096a920d113863993161105e90a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4480
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4491
src/plugins/ctf/fs-sink/fs-sink-trace.c
tests/Makefile.am
tests/data/plugins/sink.ctf.fs/assume-single-trace/bt_plugin_foo.py [new file with mode: 0644]
tests/plugins/sink.ctf.fs/Makefile.am
tests/plugins/sink.ctf.fs/test_assume_single_trace [new file with mode: 0755]
This page took 0.025081 seconds and 4 git commands to generate.