+ /* Not a fatal error. */
+ ERR("[rotation-thread] Encountered an error when checking if local rotation of trace archive %" PRIu64 " of session \"%s\" is pending on the %s consumer",
+ session->current_archive_id - 1,
+ session->name,
+ lttng_consumer_type_str(socket->type));
+ *rotation_completed = false;
+ }
+ return ret;
+}
+
+static
+int check_session_rotation_pending_local(struct ltt_session *session)
+{
+ int ret;
+ struct consumer_socket *socket;
+ struct cds_lfht_iter iter;
+ bool rotation_completed = true;
+
+ /*
+ * Check for a local pending rotation on all consumers (32-bit
+ * user space, 64-bit user space, and kernel).
+ */
+ DBG("[rotation-thread] Checking for pending local rotation on session \"%s\", trace archive %" PRIu64,
+ session->name, session->current_archive_id - 1);
+
+ rcu_read_lock();
+ if (!session->ust_session) {
+ goto skip_ust;
+ }
+ cds_lfht_for_each_entry(session->ust_session->consumer->socks->ht,
+ &iter, socket, node.node) {
+ ret = check_session_rotation_pending_local_on_consumer(session,
+ socket, &rotation_completed);
+ if (ret || !rotation_completed) {
+ goto end;
+ }
+ }
+
+skip_ust:
+ if (!session->kernel_session) {
+ goto skip_kernel;
+ }
+ cds_lfht_for_each_entry(session->kernel_session->consumer->socks->ht,
+ &iter, socket, node.node) {
+ ret = check_session_rotation_pending_local_on_consumer(session,
+ socket, &rotation_completed);
+ if (ret || !rotation_completed) {
+ goto end;
+ }
+ }
+skip_kernel:
+end:
+ rcu_read_unlock();
+
+ if (rotation_completed) {
+ DBG("[rotation-thread] Local rotation of trace archive %" PRIu64 " of session \"%s\" is complete on all consumers",
+ session->current_archive_id - 1,
+ session->name);
+ session->rotation_pending_local = false;
+ }
+ if (ret) {
+ session->rotation_state = LTTNG_ROTATION_STATE_ERROR;
+ }
+ return 0;
+}
+
+static
+int check_session_rotation_pending_relay(struct ltt_session *session)
+{
+ int ret;
+ struct consumer_socket *socket;
+ struct cds_lfht_iter iter;
+ bool rotation_completed = true;
+ const struct consumer_output *output;
+
+ /*
+ * Check for a pending rotation on any consumer as we only use
+ * it as a "tunnel" to the relayd.
+ */
+
+ rcu_read_lock();
+ if (session->ust_session) {
+ cds_lfht_first(session->ust_session->consumer->socks->ht,
+ &iter);
+ output = session->ust_session->consumer;
+ } else {
+ cds_lfht_first(session->kernel_session->consumer->socks->ht,
+ &iter);
+ output = session->kernel_session->consumer;
+ }
+ assert(cds_lfht_iter_get_node(&iter));
+
+ socket = caa_container_of(cds_lfht_iter_get_node(&iter),
+ typeof(*socket), node.node);
+
+ pthread_mutex_lock(socket->lock);
+ DBG("[rotation-thread] Checking for pending relay rotation on session \"%s\", trace archive %" PRIu64 " through the %s consumer",
+ session->name, session->current_archive_id - 1,
+ lttng_consumer_type_str(socket->type));
+ ret = consumer_check_rotation_pending_relay(socket,
+ output,
+ session->id,
+ session->current_archive_id - 1);
+ pthread_mutex_unlock(socket->lock);
+
+ if (ret == 0) {
+ /* Rotation was completed on the relay. */
+ DBG("[rotation-thread] Relay rotation of trace archive %" PRIu64 " of session \"%s\" was completed",
+ session->current_archive_id - 1,
+ session->name);
+ } else if (ret == 1) {
+ /* Rotation pending on relay. */
+ DBG("[rotation-thread] Relay rotation of trace archive %" PRIu64 " of session \"%s\" is pending",
+ session->current_archive_id - 1,
+ session->name);
+ rotation_completed = false;
+ } else {
+ /* Not a fatal error. */
+ ERR("[rotation-thread] Encountered an error when checking if rotation of trace archive %" PRIu64 " of session \"%s\" is pending on the relay",
+ session->current_archive_id - 1,
+ session->name);
+ session->rotation_state = LTTNG_ROTATION_STATE_ERROR;
+ rotation_completed = false;
+ }
+
+ rcu_read_unlock();
+
+ if (rotation_completed) {
+ DBG("[rotation-thread] Totation of trace archive %" PRIu64 " of session \"%s\" is complete on the relay",
+ session->current_archive_id - 1,
+ session->name);
+ session->rotation_pending_relay = false;