Add run_as_unlink implementation
[lttng-tools.git] / src / bin / lttng-relayd / connection.c
CommitLineData
58eb9381
DG
1/*
2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#define _GNU_SOURCE
20#include <common/common.h>
21
22#include "connection.h"
23#include "stream.h"
24
25static void rcu_free_connection(struct rcu_head *head)
26{
27 struct relay_connection *conn =
28 caa_container_of(head, struct relay_connection, rcu_node);
29
30 lttcomm_destroy_sock(conn->sock);
ca741d24 31 connection_free(conn);
58eb9381
DG
32}
33
7c29c899
JG
34/*
35 * Must be called with a read side lock held. The read side lock must be
36 * kept until the returned relay_connection is no longer in use.
37 */
58eb9381
DG
38struct relay_connection *connection_find_by_sock(struct lttng_ht *ht, int sock)
39{
40 struct lttng_ht_node_ulong *node;
41 struct lttng_ht_iter iter;
42 struct relay_connection *conn = NULL;
43
44 assert(ht);
45 assert(sock >= 0);
46
47 lttng_ht_lookup(ht, (void *)((unsigned long) sock), &iter);
48 node = lttng_ht_iter_get_node_ulong(&iter);
49 if (!node) {
50 DBG2("Relay connection by sock %d not found", sock);
51 goto end;
52 }
53 conn = caa_container_of(node, struct relay_connection, sock_n);
54
55end:
56 return conn;
57}
58
59void connection_delete(struct lttng_ht *ht, struct relay_connection *conn)
60{
61 int ret;
62 struct lttng_ht_iter iter;
63
64 assert(ht);
65 assert(conn);
66
67 iter.iter.node = &conn->sock_n.node;
68 ret = lttng_ht_del(ht, &iter);
69 assert(!ret);
70}
71
72void connection_destroy(struct relay_connection *conn)
73{
58eb9381
DG
74 assert(conn);
75
58eb9381
DG
76 call_rcu(&conn->rcu_node, rcu_free_connection);
77}
78
79struct relay_connection *connection_create(void)
80{
81 struct relay_connection *conn;
82
83 conn = zmalloc(sizeof(*conn));
84 if (!conn) {
85 PERROR("zmalloc relay connection");
86 goto error;
87 }
88
89error:
90 return conn;
91}
92
93void connection_init(struct relay_connection *conn)
94{
95 assert(conn);
96 assert(conn->sock);
97
98 CDS_INIT_LIST_HEAD(&conn->recv_head);
99 lttng_ht_node_init_ulong(&conn->sock_n, (unsigned long) conn->sock->fd);
100}
101
102void connection_free(struct relay_connection *conn)
103{
104 assert(conn);
105
ca741d24 106 free(conn->viewer_session);
58eb9381
DG
107 free(conn);
108}
This page took 0.031537 seconds and 4 git commands to generate.