+LTTNG_HIDDEN
+void utils_stream_file_rotation_get_new_count(uint64_t count,
+ uint64_t *new_count, bool *should_unlink)
+{
+ if (count > 0) {
+ /*
+ * In tracefile rotation, for the relay daemon we need
+ * to unlink the old file if present, because it may
+ * still be open in reading by the live thread, and we
+ * need to ensure that we do not overwrite the content
+ * between get_index and get_packet. Since we have no
+ * way to verify integrity of the data content compared
+ * to the associated index, we need to ensure the reader
+ * has exclusive access to the file content, and that
+ * the open of the data file is performed in get_index.
+ * Unlinking the old file rather than overwriting it
+ * achieves this.
+ */
+ if (new_count) {
+ *new_count = (*new_count + 1) % count;
+ }
+ *should_unlink = true;
+ } else {
+ if (new_count) {
+ (*new_count)++;
+ }
+ *should_unlink = false;
+ }
+}
+