relayd: do not prioritize control events over data.
[lttng-tools.git] / src / bin / lttng-relayd / connection.h
CommitLineData
7591bab1
MD
1#ifndef _CONNECTION_H
2#define _CONNECTION_H
3
58eb9381
DG
4/*
5 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
6 * David Goulet <dgoulet@efficios.com>
7591bab1 7 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
58eb9381
DG
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License, version 2 only, as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
58eb9381
DG
23#include <limits.h>
24#include <inttypes.h>
25#include <pthread.h>
26#include <urcu.h>
8bdee6e2 27#include <urcu/wfcqueue.h>
58eb9381
DG
28#include <urcu/list.h>
29
30#include <common/hashtable/hashtable.h>
31#include <common/sessiond-comm/sessiond-comm.h>
44a2fbf1
JG
32#include <common/sessiond-comm/relayd.h>
33#include <common/dynamic-buffer.h>
58eb9381
DG
34
35#include "session.h"
36
37enum connection_type {
7591bab1 38 RELAY_CONNECTION_UNKNOWN = 0,
58eb9381
DG
39 RELAY_DATA = 1,
40 RELAY_CONTROL = 2,
41 RELAY_VIEWER_COMMAND = 3,
42 RELAY_VIEWER_NOTIFICATION = 4,
43};
44
44a2fbf1
JG
45enum data_connection_state {
46 DATA_CONNECTION_STATE_RECEIVE_HEADER = 0,
47 DATA_CONNECTION_STATE_RECEIVE_PAYLOAD = 1,
48};
49
50enum ctrl_connection_state {
51 CTRL_CONNECTION_STATE_RECEIVE_HEADER = 0,
52 CTRL_CONNECTION_STATE_RECEIVE_PAYLOAD = 1,
53};
54
55struct data_connection_state_receive_header {
56 uint64_t received, left_to_receive;
57 char header_reception_buffer[sizeof(struct lttcomm_relayd_data_hdr)];
58};
59
60struct data_connection_state_receive_payload {
61 uint64_t received, left_to_receive;
62 struct lttcomm_relayd_data_hdr header;
63 bool rotate_index;
64};
65
66struct ctrl_connection_state_receive_header {
67 uint64_t received, left_to_receive;
68};
69
70struct ctrl_connection_state_receive_payload {
71 uint64_t received, left_to_receive;
72 struct lttcomm_relayd_hdr header;
73};
74
58eb9381
DG
75/*
76 * Internal structure to map a socket with the corresponding session.
77 * A hashtable indexed on the socket FD is used for the lookups.
7591bab1
MD
78 *
79 * Connections are assumed to be accessed from a single thread. Live
80 * connections between the relay and a live client are only accessed
81 * from the live worker thread.
82 *
83 * The connections between the consumerd/sessiond and the relayd are only
84 * handled by the "main" worker thread (as in, the worker thread in main.c).
85 *
86 * This is why there are no back references to connections from the
87 * sessions and session list.
58eb9381
DG
88 */
89struct relay_connection {
90 struct lttcomm_sock *sock;
8bdee6e2 91 struct cds_wfcq_node qnode;
7591bab1 92
58eb9381 93 enum connection_type type;
7591bab1
MD
94 /*
95 * session is only ever set for RELAY_CONTROL connection type.
96 */
97 struct relay_session *session;
98 /*
99 * viewer_session is only ever set for RELAY_VIEWER_COMMAND
100 * connection type.
101 */
102 struct relay_viewer_session *viewer_session;
103
104 /*
105 * Protocol version to use for this connection. Only valid for
106 * RELAY_CONTROL connection type.
107 */
58eb9381
DG
108 uint32_t major;
109 uint32_t minor;
7591bab1
MD
110
111 struct urcu_ref ref;
112 pthread_mutex_t reflock;
113
114 bool version_check_done;
cd2ef1ef
DG
115
116 /*
7591bab1 117 * Node member of connection within global socket hash table.
cd2ef1ef 118 */
7591bab1
MD
119 struct lttng_ht_node_ulong sock_n;
120 bool in_socket_ht;
121 struct lttng_ht *socket_ht; /* HACK: Contained within this hash table. */
122 struct rcu_head rcu_node; /* For call_rcu teardown. */
44a2fbf1
JG
123
124 union {
125 struct {
126 enum data_connection_state state_id;
127 union {
128 struct data_connection_state_receive_header receive_header;
129 struct data_connection_state_receive_payload receive_payload;
130 } state;
131 } data;
132 struct {
133 enum ctrl_connection_state state_id;
134 union {
135 struct ctrl_connection_state_receive_header receive_header;
136 struct ctrl_connection_state_receive_payload receive_payload;
137 } state;
138 struct lttng_dynamic_buffer reception_buffer;
139 } ctrl;
140 } protocol;
d9b9088d
JR
141 /*
142 * The activity phase for which the connection was last active.
143 * This is used to ensure fairness across connections.
144 */
145 uint64_t activity_phase;
58eb9381
DG
146};
147
7591bab1
MD
148struct relay_connection *connection_create(struct lttcomm_sock *sock,
149 enum connection_type type);
150struct relay_connection *connection_get_by_sock(struct lttng_ht *relay_connections_ht,
58eb9381 151 int sock);
44a2fbf1 152int connection_reset_protocol_state(struct relay_connection *connection);
7591bab1
MD
153bool connection_get(struct relay_connection *connection);
154void connection_put(struct relay_connection *connection);
155void connection_ht_add(struct lttng_ht *relay_connections_ht,
156 struct relay_connection *conn);
44a2fbf1
JG
157int connection_set_session(struct relay_connection *conn,
158 struct relay_session *session);
58eb9381
DG
159
160#endif /* _CONNECTION_H */
This page took 0.04765 seconds and 5 git commands to generate.