projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
relayd: rename stream prev_seq to prev_data_seq
[lttng-tools.git]
/
src
/
bin
/
lttng-relayd
/
live.c
diff --git
a/src/bin/lttng-relayd/live.c
b/src/bin/lttng-relayd/live.c
index 9e1085f33615018237a4acd2abd434c2362c265b..9efab8a73d8e3b4932122d3d425a8d588d286e0d 100644
(file)
--- a/
src/bin/lttng-relayd/live.c
+++ b/
src/bin/lttng-relayd/live.c
@@
-358,7
+358,7
@@
int make_viewer_streams(struct relay_session *session,
}
} else {
if (!stream->closed ||
}
} else {
if (!stream->closed ||
- !(((int64_t) (stream->prev_seq - stream->last_net_seq_num)) >= 0)) {
+ !(((int64_t) (stream->prev_
data_
seq - stream->last_net_seq_num)) >= 0)) {
(*nb_total)++;
}
(*nb_total)++;
}
@@
-452,10
+452,11
@@
struct lttcomm_sock *init_socket(struct lttng_uri *uri)
if (ret < 0) {
goto error;
}
if (ret < 0) {
goto error;
}
- DBG("Listening on sock %d for live", sock->fd);
+ DBG("Listening on sock %d for l
ttng-l
ive", sock->fd);
ret = sock->ops->bind(sock);
if (ret < 0) {
ret = sock->ops->bind(sock);
if (ret < 0) {
+ PERROR("Failed to bind lttng-live socket");
goto error;
}
goto error;
}
@@
-654,12
+655,16
@@
void *thread_dispatcher(void *data)
health_code_update();
health_code_update();
-
while (!CMM_LOAD_SHARED(live_dispatch_thread_exit)
) {
+
for (;;
) {
health_code_update();
/* Atomically prepare the queue futex */
futex_nto1_prepare(&viewer_conn_queue.futex);
health_code_update();
/* Atomically prepare the queue futex */
futex_nto1_prepare(&viewer_conn_queue.futex);
+ if (CMM_LOAD_SHARED(live_dispatch_thread_exit)) {
+ break;
+ }
+
do {
health_code_update();
do {
health_code_update();
@@
-830,6
+835,11
@@
int viewer_list_sessions(struct relay_connection *conn)
health_code_update();
health_code_update();
+ if (session->connection_closed) {
+ /* Skip closed session */
+ continue;
+ }
+
if (count >= buf_count) {
struct lttng_viewer_session *newbuf;
uint32_t new_buf_count = buf_count << 1;
if (count >= buf_count) {
struct lttng_viewer_session *newbuf;
uint32_t new_buf_count = buf_count << 1;
@@
-1034,12
+1044,12
@@
int viewer_attach_session(struct relay_connection *conn)
session = session_get_by_id(be64toh(request.session_id));
if (!session) {
DBG("Relay session %" PRIu64 " not found",
session = session_get_by_id(be64toh(request.session_id));
if (!session) {
DBG("Relay session %" PRIu64 " not found",
- be64toh(request.session_id));
+
(uint64_t)
be64toh(request.session_id));
response.status = htobe32(LTTNG_VIEWER_ATTACH_UNK);
goto send_reply;
}
DBG("Attach session ID %" PRIu64 " received",
response.status = htobe32(LTTNG_VIEWER_ATTACH_UNK);
goto send_reply;
}
DBG("Attach session ID %" PRIu64 " received",
- be64toh(request.session_id));
+
(uint64_t)
be64toh(request.session_id));
if (session->live_timer == 0) {
DBG("Not live session");
if (session->live_timer == 0) {
DBG("Not live session");
@@
-1084,7
+1094,7
@@
int viewer_attach_session(struct relay_connection *conn)
if (closed) {
send_streams = 0;
response.streams_count = 0;
if (closed) {
send_streams = 0;
response.streams_count = 0;
- response.status = htobe32(LTTNG_VIEWER_
NEW_STREAMS_HUP
);
+ response.status = htobe32(LTTNG_VIEWER_
ATTACH_UNK
);
goto send_reply;
}
goto send_reply;
}
@@
-1174,10
+1184,13
@@
static int check_index_status(struct relay_viewer_stream *vstream,
{
int ret;
{
int ret;
- if (
trace->session->connection_closed
+ if (
(trace->session->connection_closed || rstream->closed)
&& rstream->index_received_seqcount
== vstream->index_sent_seqcount) {
&& rstream->index_received_seqcount
== vstream->index_sent_seqcount) {
- /* Last index sent and session connection is closed. */
+ /*
+ * Last index sent and session connection or relay
+ * stream are closed.
+ */
index->status = htobe32(LTTNG_VIEWER_INDEX_HUP);
goto hup;
} else if (rstream->beacon_ts_end != -1ULL &&
index->status = htobe32(LTTNG_VIEWER_INDEX_HUP);
goto hup;
} else if (rstream->beacon_ts_end != -1ULL &&
@@
-1293,7
+1306,7
@@
int viewer_get_next_index(struct relay_connection *conn)
vstream = viewer_stream_get_by_id(be64toh(request_index.stream_id));
if (!vstream) {
DBG("Client requested index of unknown stream id %" PRIu64,
vstream = viewer_stream_get_by_id(be64toh(request_index.stream_id));
if (!vstream) {
DBG("Client requested index of unknown stream id %" PRIu64,
- be64toh(request_index.stream_id));
+
(uint64_t)
be64toh(request_index.stream_id));
viewer_index.status = htobe32(LTTNG_VIEWER_INDEX_ERR);
goto send_reply;
}
viewer_index.status = htobe32(LTTNG_VIEWER_INDEX_ERR);
goto send_reply;
}
@@
-1407,7
+1420,7
@@
int viewer_get_next_index(struct relay_connection *conn)
*/
DBG("Sending viewer index for stream %" PRIu64 " offset %" PRIu64,
rstream->stream_handle,
*/
DBG("Sending viewer index for stream %" PRIu64 " offset %" PRIu64,
rstream->stream_handle,
- be64toh(packet_index.offset));
+
(uint64_t)
be64toh(packet_index.offset));
viewer_index.offset = packet_index.offset;
viewer_index.packet_size = packet_index.packet_size;
viewer_index.content_size = packet_index.content_size;
viewer_index.offset = packet_index.offset;
viewer_index.packet_size = packet_index.packet_size;
viewer_index.content_size = packet_index.content_size;
@@
-1475,13
+1488,15
@@
error_put:
static
int viewer_get_packet(struct relay_connection *conn)
{
static
int viewer_get_packet(struct relay_connection *conn)
{
- int ret, send_data = 0;
- char *data = NULL;
- uint32_t len = 0;
- ssize_t read_len;
+ int ret;
+ off_t lseek_ret;
+ char *reply = NULL;
struct lttng_viewer_get_packet get_packet_info;
struct lttng_viewer_get_packet get_packet_info;
- struct lttng_viewer_trace_packet reply;
+ struct lttng_viewer_trace_packet reply
_header
;
struct relay_viewer_stream *vstream = NULL;
struct relay_viewer_stream *vstream = NULL;
+ uint32_t reply_size = sizeof(reply_header);
+ uint32_t packet_data_len = 0;
+ ssize_t read_len;
DBG2("Relay get data packet");
DBG2("Relay get data packet");
@@
-1495,76
+1510,78
@@
int viewer_get_packet(struct relay_connection *conn)
health_code_update();
/* From this point on, the error label can be reached. */
health_code_update();
/* From this point on, the error label can be reached. */
- memset(&reply
, 0, sizeof(reply
));
+ memset(&reply
_header, 0, sizeof(reply_header
));
vstream = viewer_stream_get_by_id(be64toh(get_packet_info.stream_id));
if (!vstream) {
DBG("Client requested packet of unknown stream id %" PRIu64,
vstream = viewer_stream_get_by_id(be64toh(get_packet_info.stream_id));
if (!vstream) {
DBG("Client requested packet of unknown stream id %" PRIu64,
- be64toh(get_packet_info.stream_id));
- reply.status = htobe32(LTTNG_VIEWER_GET_PACKET_ERR);
+
(uint64_t)
be64toh(get_packet_info.stream_id));
+ reply
_header
.status = htobe32(LTTNG_VIEWER_GET_PACKET_ERR);
goto send_reply_nolock;
goto send_reply_nolock;
+ } else {
+ packet_data_len = be32toh(get_packet_info.len);
+ reply_size += packet_data_len;
}
}
- pthread_mutex_lock(&vstream->stream->lock);
-
- len = be32toh(get_packet_info.len);
- data = zmalloc(len);
- if (!data) {
- PERROR("relay data zmalloc");
+ reply = zmalloc(reply_size);
+ if (!reply) {
+ PERROR("packet reply zmalloc");
+ reply_size = sizeof(reply_header);
goto error;
}
goto error;
}
- ret = lseek(vstream->stream_fd->fd, be64toh(get_packet_info.offset),
+ pthread_mutex_lock(&vstream->stream->lock);
+ lseek_ret = lseek(vstream->stream_fd->fd, be64toh(get_packet_info.offset),
SEEK_SET);
SEEK_SET);
- if (ret < 0) {
+ if (
lseek_
ret < 0) {
PERROR("lseek fd %d to offset %" PRIu64, vstream->stream_fd->fd,
PERROR("lseek fd %d to offset %" PRIu64, vstream->stream_fd->fd,
- be64toh(get_packet_info.offset));
+
(uint64_t)
be64toh(get_packet_info.offset));
goto error;
}
goto error;
}
- read_len = lttng_read(vstream->stream_fd->fd, data, len);
- if (read_len < len) {
+ read_len = lttng_read(vstream->stream_fd->fd,
+ reply + sizeof(reply_header),
+ packet_data_len);
+ if (read_len < packet_data_len) {
PERROR("Relay reading trace file, fd: %d, offset: %" PRIu64,
vstream->stream_fd->fd,
PERROR("Relay reading trace file, fd: %d, offset: %" PRIu64,
vstream->stream_fd->fd,
- be64toh(get_packet_info.offset));
+
(uint64_t)
be64toh(get_packet_info.offset));
goto error;
}
goto error;
}
- reply.status = htobe32(LTTNG_VIEWER_GET_PACKET_OK);
- reply.len = htobe32(len);
- send_data = 1;
+ reply_header.status = htobe32(LTTNG_VIEWER_GET_PACKET_OK);
+ reply_header.len = htobe32(packet_data_len);
goto send_reply;
error:
goto send_reply;
error:
- reply.status = htobe32(LTTNG_VIEWER_GET_PACKET_ERR);
+ reply
_header
.status = htobe32(LTTNG_VIEWER_GET_PACKET_ERR);
send_reply:
if (vstream) {
pthread_mutex_unlock(&vstream->stream->lock);
}
send_reply_nolock:
send_reply:
if (vstream) {
pthread_mutex_unlock(&vstream->stream->lock);
}
send_reply_nolock:
- reply.flags = htobe32(reply.flags);
health_code_update();
health_code_update();
- ret = send_response(conn->sock, &reply, sizeof(reply));
- if (ret < 0) {
- goto end_free;
+ if (reply) {
+ memcpy(reply, &reply_header, sizeof(reply_header));
+ ret = send_response(conn->sock, reply, reply_size);
+ } else {
+ /* No reply to send. */
+ ret = send_response(conn->sock, &reply_header,
+ reply_size);
}
}
- health_code_update();
- if (send_data) {
- health_code_update();
- ret = send_response(conn->sock, data, len);
- if (ret < 0) {
- goto end_free;
- }
- health_code_update();
+ health_code_update();
+ if (ret < 0) {
+ PERROR("sendmsg of packet data failed");
+ goto end_free;
}
}
- DBG("Sent %u bytes for stream %" PRIu64,
len
,
- be64toh(get_packet_info.stream_id));
+ DBG("Sent %u bytes for stream %" PRIu64,
reply_size
,
+
(uint64_t)
be64toh(get_packet_info.stream_id));
end_free:
end_free:
- free(
data
);
+ free(
reply
);
end:
if (vstream) {
viewer_stream_put(vstream);
end:
if (vstream) {
viewer_stream_put(vstream);
@@
-1613,7
+1630,7
@@
int viewer_get_metadata(struct relay_connection *conn)
* find it.
*/
DBG("Client requested metadata of unknown stream id %" PRIu64,
* find it.
*/
DBG("Client requested metadata of unknown stream id %" PRIu64,
- be64toh(request.stream_id));
+
(uint64_t)
be64toh(request.stream_id));
reply.status = htobe32(LTTNG_VIEWER_METADATA_ERR);
goto send_reply;
}
reply.status = htobe32(LTTNG_VIEWER_METADATA_ERR);
goto send_reply;
}
@@
-1699,7
+1716,7
@@
send_reply:
}
DBG("Sent %" PRIu64 " bytes of metadata for stream %" PRIu64, len,
}
DBG("Sent %" PRIu64 " bytes of metadata for stream %" PRIu64, len,
- be64toh(request.stream_id));
+
(uint64_t)
be64toh(request.stream_id));
DBG("Metadata sent");
DBG("Metadata sent");
@@
-1788,7
+1805,7
@@
int viewer_detach_session(struct relay_connection *conn)
session = session_get_by_id(be64toh(request.session_id));
if (!session) {
DBG("Relay session %" PRIu64 " not found",
session = session_get_by_id(be64toh(request.session_id));
if (!session) {
DBG("Relay session %" PRIu64 " not found",
- be64toh(request.session_id));
+
(uint64_t)
be64toh(request.session_id));
response.status = htobe32(LTTNG_VIEWER_DETACH_SESSION_UNK);
goto send_reply;
}
response.status = htobe32(LTTNG_VIEWER_DETACH_SESSION_UNK);
goto send_reply;
}
@@
-2063,7
+2080,7
@@
exit:
error:
lttng_poll_clean(&events);
error:
lttng_poll_clean(&events);
- /* Cleanup re
a
maining connection object. */
+ /* Cleanup remaining connection object. */
rcu_read_lock();
cds_lfht_for_each_entry(viewer_connections_ht->ht, &iter.iter,
destroy_conn,
rcu_read_lock();
cds_lfht_for_each_entry(viewer_connections_ht->ht, &iter.iter,
destroy_conn,
This page took
0.027921 seconds
and
4
git commands to generate.