+ if (stream->is_metadata && stream->trace->viewer_metadata_stream) {
+ ERR("Cannot attach viewer metadata stream to trace (busy).");
+ goto error_unlock;
+ }
+
+ switch (seek_t) {
+ case LTTNG_VIEWER_SEEK_BEGINNING:
+ {
+ uint64_t seq_tail = tracefile_array_get_seq_tail(stream->tfa);
+
+ if (seq_tail == -1ULL) {
+ /*
+ * Tail may not be initialized yet. Nonetheless, we know
+ * we want to send the first index once it becomes
+ * available.
+ */
+ seq_tail = 0;
+ }
+ vstream->current_tracefile_id =
+ tracefile_array_get_file_index_tail(stream->tfa);
+ vstream->index_sent_seqcount = seq_tail;
+ break;
+ }
+ case LTTNG_VIEWER_SEEK_LAST:
+ vstream->current_tracefile_id =
+ tracefile_array_get_read_file_index_head(stream->tfa);
+ /*
+ * We seek at the very end of each stream, awaiting for
+ * a future packet to eventually come in.
+ *
+ * We don't need to check the head position for -1ULL since the
+ * increment will set it to 0.
+ */
+ vstream->index_sent_seqcount =
+ tracefile_array_get_seq_head(stream->tfa) + 1;
+ break;
+ default:
+ goto error_unlock;
+ }