Fix: post-clear trace chunk has a late beginning packet
[lttng-tools.git] / src / bin / lttng-relayd / connection.h
CommitLineData
7591bab1
MD
1#ifndef _CONNECTION_H
2#define _CONNECTION_H
3
58eb9381 4/*
ab5be9fa
MJ
5 * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
6 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
7 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
58eb9381 8 *
ab5be9fa 9 * SPDX-License-Identifier: GPL-2.0-only
58eb9381 10 *
58eb9381
DG
11 */
12
58eb9381
DG
13#include <limits.h>
14#include <inttypes.h>
15#include <pthread.h>
16#include <urcu.h>
8bdee6e2 17#include <urcu/wfcqueue.h>
58eb9381
DG
18#include <urcu/list.h>
19
20#include <common/hashtable/hashtable.h>
21#include <common/sessiond-comm/sessiond-comm.h>
5312a3ed
JG
22#include <common/sessiond-comm/relayd.h>
23#include <common/dynamic-buffer.h>
58eb9381
DG
24
25#include "session.h"
26
27enum connection_type {
7591bab1 28 RELAY_CONNECTION_UNKNOWN = 0,
58eb9381
DG
29 RELAY_DATA = 1,
30 RELAY_CONTROL = 2,
31 RELAY_VIEWER_COMMAND = 3,
32 RELAY_VIEWER_NOTIFICATION = 4,
33};
34
5312a3ed
JG
35enum data_connection_state {
36 DATA_CONNECTION_STATE_RECEIVE_HEADER = 0,
37 DATA_CONNECTION_STATE_RECEIVE_PAYLOAD = 1,
38};
39
40enum ctrl_connection_state {
41 CTRL_CONNECTION_STATE_RECEIVE_HEADER = 0,
42 CTRL_CONNECTION_STATE_RECEIVE_PAYLOAD = 1,
43};
44
45struct data_connection_state_receive_header {
46 uint64_t received, left_to_receive;
47 char header_reception_buffer[sizeof(struct lttcomm_relayd_data_hdr)];
48};
49
50struct data_connection_state_receive_payload {
51 uint64_t received, left_to_receive;
52 struct lttcomm_relayd_data_hdr header;
53 bool rotate_index;
54};
55
56struct ctrl_connection_state_receive_header {
57 uint64_t received, left_to_receive;
58};
59
60struct ctrl_connection_state_receive_payload {
61 uint64_t received, left_to_receive;
62 struct lttcomm_relayd_hdr header;
63};
64
58eb9381
DG
65/*
66 * Internal structure to map a socket with the corresponding session.
67 * A hashtable indexed on the socket FD is used for the lookups.
7591bab1
MD
68 *
69 * Connections are assumed to be accessed from a single thread. Live
70 * connections between the relay and a live client are only accessed
71 * from the live worker thread.
72 *
73 * The connections between the consumerd/sessiond and the relayd are only
74 * handled by the "main" worker thread (as in, the worker thread in main.c).
75 *
76 * This is why there are no back references to connections from the
77 * sessions and session list.
58eb9381
DG
78 */
79struct relay_connection {
80 struct lttcomm_sock *sock;
8bdee6e2 81 struct cds_wfcq_node qnode;
7591bab1 82
58eb9381 83 enum connection_type type;
7591bab1
MD
84 /*
85 * session is only ever set for RELAY_CONTROL connection type.
86 */
87 struct relay_session *session;
88 /*
89 * viewer_session is only ever set for RELAY_VIEWER_COMMAND
90 * connection type.
91 */
92 struct relay_viewer_session *viewer_session;
93
94 /*
95 * Protocol version to use for this connection. Only valid for
96 * RELAY_CONTROL connection type.
97 */
58eb9381
DG
98 uint32_t major;
99 uint32_t minor;
7591bab1
MD
100
101 struct urcu_ref ref;
7591bab1
MD
102
103 bool version_check_done;
cd2ef1ef
DG
104
105 /*
7591bab1 106 * Node member of connection within global socket hash table.
cd2ef1ef 107 */
7591bab1
MD
108 struct lttng_ht_node_ulong sock_n;
109 bool in_socket_ht;
110 struct lttng_ht *socket_ht; /* HACK: Contained within this hash table. */
111 struct rcu_head rcu_node; /* For call_rcu teardown. */
5312a3ed
JG
112
113 union {
114 struct {
115 enum data_connection_state state_id;
116 union {
117 struct data_connection_state_receive_header receive_header;
118 struct data_connection_state_receive_payload receive_payload;
119 } state;
120 } data;
121 struct {
122 enum ctrl_connection_state state_id;
123 union {
124 struct ctrl_connection_state_receive_header receive_header;
125 struct ctrl_connection_state_receive_payload receive_payload;
126 } state;
127 struct lttng_dynamic_buffer reception_buffer;
128 } ctrl;
129 } protocol;
58eb9381
DG
130};
131
7591bab1
MD
132struct relay_connection *connection_create(struct lttcomm_sock *sock,
133 enum connection_type type);
134struct relay_connection *connection_get_by_sock(struct lttng_ht *relay_connections_ht,
58eb9381 135 int sock);
5312a3ed 136int connection_reset_protocol_state(struct relay_connection *connection);
7591bab1
MD
137bool connection_get(struct relay_connection *connection);
138void connection_put(struct relay_connection *connection);
139void connection_ht_add(struct lttng_ht *relay_connections_ht,
140 struct relay_connection *conn);
fd0f1e3e
JR
141int connection_set_session(struct relay_connection *conn,
142 struct relay_session *session);
58eb9381
DG
143
144#endif /* _CONNECTION_H */
This page took 0.052825 seconds and 4 git commands to generate.