}
/*
- * Update the end point status of all streams having the given network sequence
- * index (relayd index).
+ * Update the end point status of all streams having the given relayd id.
*
* It's atomically set without having the stream mutex locked which is fine
* because we handle the write/read race with a pipe wakeup for each thread.
*/
-static void update_endpoint_status_by_netidx(uint64_t net_seq_idx,
+static void update_endpoint_status_by_netidx(uint64_t relayd_id,
enum consumer_endpoint_status status)
{
struct lttng_ht_iter iter;
struct lttng_consumer_stream *stream;
- DBG("Consumer set delete flag on stream by idx %" PRIu64, net_seq_idx);
+ DBG("Consumer set delete flag on stream by idx %" PRIu64, relayd_id);
rcu_read_lock();
/* Let's begin with metadata */
cds_lfht_for_each_entry(metadata_ht->ht, &iter.iter, stream, node.node) {
- if (stream->net_seq_idx == net_seq_idx) {
+ if (stream->relayd_id == relayd_id) {
uatomic_set(&stream->endpoint_status, status);
DBG("Delete flag set to metadata stream %d", stream->wait_fd);
}
/* Follow up by the data streams */
cds_lfht_for_each_entry(data_ht->ht, &iter.iter, stream, node.node) {
- if (stream->net_seq_idx == net_seq_idx) {
+ if (stream->relayd_id == relayd_id) {
uatomic_set(&stream->endpoint_status, status);
DBG("Delete flag set to data stream %d", stream->wait_fd);
}
assert(relayd);
- DBG("Cleaning up relayd object ID %"PRIu64, relayd->net_seq_idx);
+ DBG("Cleaning up relayd object ID %"PRIu64, relayd->id);
/* Save the net sequence index before destroying the object */
- netidx = relayd->net_seq_idx;
+ netidx = relayd->id;
/*
* Delete the relayd from the relayd hash table, close the sockets and free
stream->state = state;
stream->uid = uid;
stream->gid = gid;
- stream->net_seq_idx = relayd_id;
+ stream->relayd_id = relayd_id;
stream->session_id = session_id;
stream->monitor = monitor;
stream->endpoint_status = CONSUMER_ENDPOINT_ACTIVE;
DBG3("Allocated stream %s (key %" PRIu64 ", chan_key %" PRIu64
" relayd_id %" PRIu64 ", session_id %" PRIu64,
stream->name, stream->key, channel_key,
- stream->net_seq_idx, stream->session_id);
+ stream->relayd_id, stream->session_id);
rcu_read_unlock();
return stream;
assert(relayd);
lttng_ht_lookup(consumer_data.relayd_ht,
- &relayd->net_seq_idx, &iter);
+ &relayd->id, &iter);
node = lttng_ht_iter_get_node_u64(&iter);
if (node != NULL) {
goto end;
* Allocate and return a consumer relayd socket.
*/
static struct consumer_relayd_sock_pair *consumer_allocate_relayd_sock_pair(
- uint64_t net_seq_idx)
+ uint64_t relayd_id)
{
struct consumer_relayd_sock_pair *obj = NULL;
/* net sequence index of -1 is a failure */
- if (net_seq_idx == (uint64_t) -1ULL) {
+ if (relayd_id == (uint64_t) -1ULL) {
goto error;
}
goto error;
}
- obj->net_seq_idx = net_seq_idx;
+ obj->id = relayd_id;
obj->refcount = 0;
obj->destroy_flag = 0;
obj->control_sock.sock.fd = -1;
obj->data_sock.sock.fd = -1;
- lttng_ht_node_init_u64(&obj->node, obj->net_seq_idx);
+ lttng_ht_node_init_u64(&obj->node, obj->id);
pthread_mutex_init(&obj->ctrl_sock_mutex, NULL);
error:
struct consumer_relayd_sock_pair *relayd;
assert(stream);
- assert(stream->net_seq_idx != -1ULL);
+ assert(stream->relayd_id != -1ULL);
assert(path);
/* The stream is not metadata. Get relayd reference if exists. */
rcu_read_lock();
- relayd = consumer_find_relayd(stream->net_seq_idx);
+ relayd = consumer_find_relayd(stream->relayd_id);
if (relayd != NULL) {
/* Add stream on the relayd */
pthread_mutex_lock(&relayd->ctrl_sock_mutex);
ret = relayd_add_stream(&relayd->control_sock, stream->name,
path, &stream->relayd_stream_id,
stream->chan->tracefile_size, stream->chan->tracefile_count);
+ pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
if (ret < 0) {
- ERR("Relayd add stream failed. Cleaning up relayd %" PRIu64".", relayd->net_seq_idx);
+ ERR("Relayd add stream failed. Cleaning up relayd %" PRIu64".", relayd->id);
lttng_consumer_cleanup_relayd(relayd);
- pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
goto end;
}
- pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
uatomic_inc(&relayd->refcount);
stream->sent_to_relayd = 1;
} else {
ERR("Stream %" PRIu64 " relayd ID %" PRIu64 " unknown. Can't send it.",
- stream->key, stream->net_seq_idx);
+ stream->key, stream->relayd_id);
ret = -1;
goto end;
}
DBG("Stream %s with key %" PRIu64 " sent to relayd id %" PRIu64,
- stream->name, stream->key, stream->net_seq_idx);
+ stream->name, stream->key, stream->relayd_id);
end:
rcu_read_unlock();
*
* Returns 0 on success, < 0 on error
*/
-int consumer_send_relayd_streams_sent(uint64_t net_seq_idx)
+int consumer_send_relayd_streams_sent(uint64_t relayd_id)
{
int ret = 0;
struct consumer_relayd_sock_pair *relayd;
- assert(net_seq_idx != -1ULL);
+ assert(relayd_id != -1ULL);
/* The stream is not metadata. Get relayd reference if exists. */
rcu_read_lock();
- relayd = consumer_find_relayd(net_seq_idx);
+ relayd = consumer_find_relayd(relayd_id);
if (relayd != NULL) {
/* Add stream on the relayd */
pthread_mutex_lock(&relayd->ctrl_sock_mutex);
ret = relayd_streams_sent(&relayd->control_sock);
+ pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
if (ret < 0) {
- ERR("Relayd streams sent failed. Cleaning up relayd %" PRIu64".", relayd->net_seq_idx);
+ ERR("Relayd streams sent failed. Cleaning up relayd %" PRIu64".", relayd->id);
lttng_consumer_cleanup_relayd(relayd);
- pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
goto end;
}
- pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
} else {
ERR("Relayd ID %" PRIu64 " unknown. Can't send streams_sent.",
- net_seq_idx);
+ relayd_id);
ret = -1;
goto end;
}
ret = 0;
- DBG("All streams sent relayd id %" PRIu64, net_seq_idx);
+ DBG("All streams sent relayd id %" PRIu64, relayd_id);
end:
rcu_read_unlock();
/* The stream is not metadata. Get relayd reference if exists. */
rcu_read_lock();
- relayd = consumer_find_relayd(stream->net_seq_idx);
+ relayd = consumer_find_relayd(stream->relayd_id);
if (relayd) {
consumer_stream_relayd_close(stream, relayd);
}
rcu_read_lock();
/* Flag that the current stream if set for network streaming. */
- if (stream->net_seq_idx != (uint64_t) -1ULL) {
- relayd = consumer_find_relayd(stream->net_seq_idx);
+ if (stream->relayd_id != (uint64_t) -1ULL) {
+ relayd = consumer_find_relayd(stream->relayd_id);
if (relayd == NULL) {
ret = -EPIPE;
goto end;
* cleanup the relayd object and all associated streams.
*/
if (relayd && relayd_hang_up) {
- ERR("Relayd hangup. Cleaning up relayd %" PRIu64".", relayd->net_seq_idx);
+ ERR("Relayd hangup. Cleaning up relayd %" PRIu64".", relayd->id);
lttng_consumer_cleanup_relayd(relayd);
}
rcu_read_lock();
/* Flag that the current stream if set for network streaming. */
- if (stream->net_seq_idx != (uint64_t) -1ULL) {
- relayd = consumer_find_relayd(stream->net_seq_idx);
+ if (stream->relayd_id != (uint64_t) -1ULL) {
+ relayd = consumer_find_relayd(stream->relayd_id);
if (relayd == NULL) {
written = -ret;
goto end;
* cleanup the relayd object and all associated streams.
*/
if (relayd && relayd_hang_up) {
- ERR("Relayd hangup. Cleaning up relayd %" PRIu64".", relayd->net_seq_idx);
+ ERR("Relayd hangup. Cleaning up relayd %" PRIu64".", relayd->id);
lttng_consumer_cleanup_relayd(relayd);
/* Skip splice error so the consumer does not fail */
goto end;
* This will create a relayd socket pair and add it to the relayd hash table.
* The caller MUST acquire a RCU read side lock before calling it.
*/
-int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
+ void consumer_add_relayd_socket(uint64_t relayd_id, int sock_type,
struct lttng_consumer_local_data *ctx, int sock,
struct pollfd *consumer_sockpoll,
struct lttcomm_relayd_sock *relayd_sock, uint64_t sessiond_id,
assert(ctx);
assert(relayd_sock);
- DBG("Consumer adding relayd socket (idx: %" PRIu64 ")", net_seq_idx);
+ DBG("Consumer adding relayd socket (idx: %" PRIu64 ")", relayd_id);
/* Get relayd reference if exists. */
- relayd = consumer_find_relayd(net_seq_idx);
+ relayd = consumer_find_relayd(relayd_id);
if (relayd == NULL) {
assert(sock_type == LTTNG_STREAM_CONTROL);
/* Not found. Allocate one. */
- relayd = consumer_allocate_relayd_sock_pair(net_seq_idx);
+ relayd = consumer_allocate_relayd_sock_pair(relayd_id);
if (relayd == NULL) {
ret = -ENOMEM;
ret_code = LTTCOMM_CONSUMERD_ENOMEM;
DBG("Consumer %s socket created successfully with net idx %" PRIu64 " (fd: %d)",
sock_type == LTTNG_STREAM_CONTROL ? "control" : "data",
- relayd->net_seq_idx, fd);
+ relayd->id, fd);
/* We successfully added the socket. Send status back. */
ret = consumer_send_status_msg(sock, ret_code);
add_relayd(relayd);
/* All good! */
- return 0;
+ return;
error:
if (consumer_send_status_msg(sock, ret_code) < 0) {
if (relayd_created) {
free(relayd);
}
-
- return ret;
-}
-
-/*
- * Try to lock the stream mutex.
- *
- * On success, 1 is returned else 0 indicating that the mutex is NOT lock.
- */
-static int stream_try_lock(struct lttng_consumer_stream *stream)
-{
- int ret;
-
- assert(stream);
-
- /*
- * Try to lock the stream mutex. On failure, we know that the stream is
- * being used else where hence there is data still being extracted.
- */
- ret = pthread_mutex_trylock(&stream->lock);
- if (ret) {
- /* For both EBUSY and EINVAL error, the mutex is NOT locked. */
- ret = 0;
- goto end;
- }
-
- ret = 1;
-
-end:
- return ret;
}
/*
struct lttng_ht_iter iter;
struct consumer_relayd_sock_pair *relayd = NULL;
- /* Iterate over all relayd since they are indexed by net_seq_idx. */
+ /* Iterate over all relayd since they are indexed by relayd_id. */
cds_lfht_for_each_entry(consumer_data.relayd_ht->ht, &iter.iter, relayd,
node.node) {
/*
/* Ease our life a bit */
ht = consumer_data.stream_list_ht;
- relayd = find_relayd_by_session_id(id);
- if (relayd) {
- /* Send init command for data pending. */
- pthread_mutex_lock(&relayd->ctrl_sock_mutex);
- ret = relayd_begin_data_pending(&relayd->control_sock,
- relayd->relayd_session_id);
- if (ret < 0) {
- /* Communication error thus the relayd so no data pending. */
- ERR("Relayd begin data pending failed. Cleaning up relayd %" PRIu64".", relayd->net_seq_idx);
- lttng_consumer_cleanup_relayd(relayd);
- pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
- goto data_not_pending;
- }
- pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
- }
-
cds_lfht_for_each_entry_duplicate(ht->ht,
ht->hash_fct(&id, lttng_ht_seed),
ht->match_fct, &id,
&iter.iter, stream, node_session_id.node) {
- /* If this call fails, the stream is being used hence data pending. */
- ret = stream_try_lock(stream);
- if (!ret) {
- goto data_pending;
- }
+ pthread_mutex_lock(&stream->lock);
/*
* A removed node from the hash table indicates that the stream has
}
}
- /* Relayd check */
- if (relayd) {
- pthread_mutex_lock(&relayd->ctrl_sock_mutex);
+ pthread_mutex_unlock(&stream->lock);
+ }
+
+ relayd = find_relayd_by_session_id(id);
+ if (relayd) {
+ unsigned int is_data_inflight = 0;
+
+ /* Send init command for data pending. */
+ pthread_mutex_lock(&relayd->ctrl_sock_mutex);
+ ret = relayd_begin_data_pending(&relayd->control_sock,
+ relayd->relayd_session_id);
+ if (ret < 0) {
+ /* Communication error thus the relayd so no data pending. */
+ pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
+ ERR("Relayd begin data pending failed. Cleaning up relayd %" PRIu64".", relayd->id);
+ lttng_consumer_cleanup_relayd(relayd);
+ goto data_not_pending;
+ }
+
+ cds_lfht_for_each_entry_duplicate(ht->ht,
+ ht->hash_fct(&id, lttng_ht_seed),
+ ht->match_fct, &id,
+ &iter.iter, stream, node_session_id.node) {
if (stream->metadata_flag) {
ret = relayd_quiescent_control(&relayd->control_sock,
stream->relayd_stream_id);
stream->relayd_stream_id,
stream->next_net_seq_num - 1);
}
+ if (ret == 1) {
+ pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
+ pthread_mutex_unlock(&stream->lock);
+ goto data_pending;
+ }
if (ret < 0) {
- ERR("Relayd data pending failed. Cleaning up relayd %" PRIu64".", relayd->net_seq_idx);
+ ERR("Relayd data pending failed. Cleaning up relayd %" PRIu64".", relayd->id);
lttng_consumer_cleanup_relayd(relayd);
pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
pthread_mutex_unlock(&stream->lock);
goto data_not_pending;
}
- pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
- if (ret == 1) {
- pthread_mutex_unlock(&stream->lock);
- goto data_pending;
- }
}
- pthread_mutex_unlock(&stream->lock);
- }
-
- if (relayd) {
- unsigned int is_data_inflight = 0;
- /* Send init command for data pending. */
- pthread_mutex_lock(&relayd->ctrl_sock_mutex);
+ /* Send end command for data pending. */
ret = relayd_end_data_pending(&relayd->control_sock,
relayd->relayd_session_id, &is_data_inflight);
+ pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
if (ret < 0) {
- ERR("Relayd end data pending failed. Cleaning up relayd %" PRIu64".", relayd->net_seq_idx);
+ ERR("Relayd end data pending failed. Cleaning up relayd %" PRIu64".", relayd->id);
lttng_consumer_cleanup_relayd(relayd);
- pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
goto data_not_pending;
}
- pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
if (is_data_inflight) {
goto data_pending;
}