relayd: track stdio output file descriptors
[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>
5312a3ed
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
5312a3ed
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;
7591bab1
MD
112
113 bool version_check_done;
cd2ef1ef
DG
114
115 /*
7591bab1 116 * Node member of connection within global socket hash table.
cd2ef1ef 117 */
7591bab1
MD
118 struct lttng_ht_node_ulong sock_n;
119 bool in_socket_ht;
120 struct lttng_ht *socket_ht; /* HACK: Contained within this hash table. */
121 struct rcu_head rcu_node; /* For call_rcu teardown. */
5312a3ed
JG
122
123 union {
124 struct {
125 enum data_connection_state state_id;
126 union {
127 struct data_connection_state_receive_header receive_header;
128 struct data_connection_state_receive_payload receive_payload;
129 } state;
130 } data;
131 struct {
132 enum ctrl_connection_state state_id;
133 union {
134 struct ctrl_connection_state_receive_header receive_header;
135 struct ctrl_connection_state_receive_payload receive_payload;
136 } state;
137 struct lttng_dynamic_buffer reception_buffer;
138 } ctrl;
139 } protocol;
58eb9381
DG
140};
141
7591bab1
MD
142struct relay_connection *connection_create(struct lttcomm_sock *sock,
143 enum connection_type type);
144struct relay_connection *connection_get_by_sock(struct lttng_ht *relay_connections_ht,
58eb9381 145 int sock);
5312a3ed 146int connection_reset_protocol_state(struct relay_connection *connection);
7591bab1
MD
147bool connection_get(struct relay_connection *connection);
148void connection_put(struct relay_connection *connection);
149void connection_ht_add(struct lttng_ht *relay_connections_ht,
150 struct relay_connection *conn);
fd0f1e3e
JR
151int connection_set_session(struct relay_connection *conn,
152 struct relay_session *session);
58eb9381
DG
153
154#endif /* _CONNECTION_H */
This page took 0.046257 seconds and 4 git commands to generate.