Fix: lttng_directory_handle_init fails on opening base relayd output
[lttng-tools.git] / src / bin / lttng-relayd / session.h
CommitLineData
7591bab1
MD
1#ifndef _SESSION_H
2#define _SESSION_H
3
2f8f53af
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>
2f8f53af
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
2f8f53af
DG
23#include <limits.h>
24#include <inttypes.h>
25#include <pthread.h>
c3b7390b 26#include <urcu/list.h>
7591bab1 27#include <urcu/ref.h>
2f8f53af 28
36d2e35d 29#include <lttng/constant.h>
2f8f53af 30#include <common/hashtable/hashtable.h>
23c8ff50 31#include <common/compat/uuid.h>
639ddf68 32#include <common/trace-chunk.h>
1e791a74 33#include <common/optional.h>
2f8f53af
DG
34
35/*
36 * Represents a session for the relay point of view
37 */
38struct relay_session {
39 /*
7591bab1
MD
40 * This session id is generated by the relay daemon to guarantee
41 * its uniqueness even when serving multiple session daemons.
42 * It is used to match a set of streams to their session.
2f8f53af
DG
43 */
44 uint64_t id;
1e791a74
JG
45 /*
46 * ID of the session in the session daemon's domain.
47 * This information is only provided by 2.11+ peers.
48 */
49 LTTNG_OPTIONAL(uint64_t) id_sessiond;
50 /*
51 * Only provided by 2.11+ peers. However, the UUID is set to 'nil' in
52 * the other cases.
53 */
23c8ff50 54 lttng_uuid sessiond_uuid;
db1da059 55 LTTNG_OPTIONAL(time_t) creation_time;
36d2e35d 56 char session_name[LTTNG_NAME_MAX];
9cf3eb20 57 char hostname[LTTNG_HOST_NAME_MAX];
6fa5fe7c 58 char base_path[LTTNG_PATH_MAX];
ecd1a12f
MD
59 /*
60 * Session output path relative to relayd's output path.
61 * Will be empty when interacting with peers < 2.11 since their
62 * streams' path are expressed relative to the relay daemon's
63 * output path.
64 */
65 char output_path[LTTNG_PATH_MAX];
2f8f53af 66 uint32_t live_timer;
2a174661 67
7591bab1
MD
68 /* Session in snapshot mode. */
69 bool snapshot;
70
71 /*
72 * Session has no back reference to its connection because it
73 * has a life-time that can be longer than the consumer connection's
74 * life-time; a reference can still be held by the viewer
75 * connection through the viewer streams.
76 */
77
78 struct urcu_ref ref;
7591bab1
MD
79
80 pthread_mutex_t lock;
81
82 /* major/minor version used for this session. */
83 uint32_t major;
84 uint32_t minor;
85
86 bool viewer_attached;
87 /* Tell if the session connection has been closed on the streaming side. */
88 bool connection_closed;
2a174661 89
98ba050e
JR
90 /*
91 * Tell if the session is currently living in a exiting relayd and
92 * should be cleaned forcefully without waiting for pending data or
93 * pending ctrl data.
94 */
95 bool aborted;
96
46ef2188 97 bool session_name_contains_creation_time;
ecd1a12f
MD
98 /* Whether session has performed an explicit rotation. */
99 bool has_rotated;
46ef2188 100
2a174661
DG
101 /* Contains ctf_trace object of that session indexed by path name. */
102 struct lttng_ht *ctf_traces_ht;
2f8f53af
DG
103
104 /*
7591bab1
MD
105 * This contains streams that are received on that connection.
106 * It's used to store them until we get the streams sent
107 * command. When this is received, we remove those streams from
108 * the list and publish them.
109 *
110 * Updates are protected by the recv_list_lock.
111 * Traversals are protected by RCU.
112 * recv_list_lock also protects stream_count.
2f8f53af 113 */
7591bab1
MD
114 struct cds_list_head recv_list; /* RCU list. */
115 uint32_t stream_count;
116 pthread_mutex_t recv_list_lock;
117
2f8f53af
DG
118 /*
119 * Flag checked and exchanged with uatomic_cmpxchg to tell the
120 * viewer-side if new streams got added since the last check.
121 */
122 unsigned long new_streams;
123
124 /*
7591bab1 125 * Node in the global session hash table.
2f8f53af 126 */
7591bab1 127 struct lttng_ht_node_u64 session_n;
c3b7390b
JD
128 /*
129 * Member of the session list in struct relay_viewer_session.
7591bab1
MD
130 * Updates are protected by the relay_viewer_session
131 * session_list_lock. Traversals are protected by RCU.
c3b7390b 132 */
7591bab1 133 struct cds_list_head viewer_session_node;
639ddf68 134 struct lttng_trace_chunk *current_trace_chunk;
62bad3bf 135 struct lttng_trace_chunk *pending_closure_trace_chunk;
7591bab1 136 struct rcu_head rcu_node; /* For call_rcu teardown. */
2f8f53af
DG
137};
138
7591bab1 139struct relay_session *session_create(const char *session_name,
6fa5fe7c 140 const char *hostname, const char *base_path,
db1da059
JG
141 uint32_t live_timer,
142 bool snapshot,
143 const lttng_uuid sessiond_uuid,
144 const uint64_t *id_sessiond,
145 const uint64_t *current_chunk_id,
146 const time_t *creation_time,
147 uint32_t major,
46ef2188
MD
148 uint32_t minor,
149 bool session_name_contains_creation_timestamp);
7591bab1
MD
150struct relay_session *session_get_by_id(uint64_t id);
151bool session_get(struct relay_session *session);
152void session_put(struct relay_session *session);
2a174661 153
7591bab1 154int session_close(struct relay_session *session);
98ba050e
JR
155int session_abort(struct relay_session *session);
156
d37856b8
JR
157int session_init_output_directory_handle(struct relay_session *session,
158 struct lttng_directory_handle *handle);
159
7591bab1 160void print_sessions(void);
2f8f53af
DG
161
162#endif /* _SESSION_H */
This page took 0.04531 seconds and 4 git commands to generate.