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