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)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 3 Dec 2020 20:08:27 +0000 (15:08 -0500)
commit72d458a311ee9b8c2cc84d8ade5754e5ea517fcb
tree59b8491d09a2e12d269934a18208cb6471bf83d9
parentc20049fd0678f462f621c80f9e91c1ba16e6b656
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>
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.02893 seconds and 4 git commands to generate.