Port: Add Solaris support to socket compat
[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
DG
28
29#include <common/hashtable/hashtable.h>
30
31/*
32 * Represents a session for the relay point of view
33 */
34struct relay_session {
35 /*
7591bab1
MD
36 * This session id is generated by the relay daemon to guarantee
37 * its uniqueness even when serving multiple session daemons.
38 * It is used to match a set of streams to their session.
2f8f53af
DG
39 */
40 uint64_t id;
2f8f53af
DG
41 char session_name[NAME_MAX];
42 char hostname[HOST_NAME_MAX];
43 uint32_t live_timer;
2a174661 44
7591bab1
MD
45 /* Session in snapshot mode. */
46 bool snapshot;
47
48 /*
49 * Session has no back reference to its connection because it
50 * has a life-time that can be longer than the consumer connection's
51 * life-time; a reference can still be held by the viewer
52 * connection through the viewer streams.
53 */
54
55 struct urcu_ref ref;
56 /* session reflock nests inside ctf_trace reflock. */
57 pthread_mutex_t reflock;
58
59 pthread_mutex_t lock;
60
61 /* major/minor version used for this session. */
62 uint32_t major;
63 uint32_t minor;
64
65 bool viewer_attached;
66 /* Tell if the session connection has been closed on the streaming side. */
67 bool connection_closed;
2a174661
DG
68
69 /* Contains ctf_trace object of that session indexed by path name. */
70 struct lttng_ht *ctf_traces_ht;
2f8f53af
DG
71
72 /*
7591bab1
MD
73 * This contains streams that are received on that connection.
74 * It's used to store them until we get the streams sent
75 * command. When this is received, we remove those streams from
76 * the list and publish them.
77 *
78 * Updates are protected by the recv_list_lock.
79 * Traversals are protected by RCU.
80 * recv_list_lock also protects stream_count.
2f8f53af 81 */
7591bab1
MD
82 struct cds_list_head recv_list; /* RCU list. */
83 uint32_t stream_count;
84 pthread_mutex_t recv_list_lock;
85
2f8f53af
DG
86 /*
87 * Flag checked and exchanged with uatomic_cmpxchg to tell the
88 * viewer-side if new streams got added since the last check.
89 */
90 unsigned long new_streams;
91
92 /*
7591bab1 93 * Node in the global session hash table.
2f8f53af 94 */
7591bab1 95 struct lttng_ht_node_u64 session_n;
c3b7390b
JD
96 /*
97 * Member of the session list in struct relay_viewer_session.
7591bab1
MD
98 * Updates are protected by the relay_viewer_session
99 * session_list_lock. Traversals are protected by RCU.
c3b7390b 100 */
7591bab1
MD
101 struct cds_list_head viewer_session_node;
102 struct rcu_head rcu_node; /* For call_rcu teardown. */
2f8f53af
DG
103};
104
7591bab1
MD
105struct relay_session *session_create(const char *session_name,
106 const char *hostname, uint32_t live_timer,
107 bool snapshot, uint32_t major, uint32_t minor);
108struct relay_session *session_get_by_id(uint64_t id);
109bool session_get(struct relay_session *session);
110void session_put(struct relay_session *session);
2a174661 111
7591bab1
MD
112int session_close(struct relay_session *session);
113void print_sessions(void);
2f8f53af
DG
114
115#endif /* _SESSION_H */
This page took 0.045019 seconds and 4 git commands to generate.