Fix: HT must not be destroyed with a rcu_read_lock held
[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
34struct relay_connection *connection_find_by_sock(struct lttng_ht *ht, int sock)
35{
36 struct lttng_ht_node_ulong *node;
37 struct lttng_ht_iter iter;
38 struct relay_connection *conn = NULL;
39
40 assert(ht);
41 assert(sock >= 0);
42
43 lttng_ht_lookup(ht, (void *)((unsigned long) sock), &iter);
44 node = lttng_ht_iter_get_node_ulong(&iter);
45 if (!node) {
46 DBG2("Relay connection by sock %d not found", sock);
47 goto end;
48 }
49 conn = caa_container_of(node, struct relay_connection, sock_n);
50
51end:
52 return conn;
53}
54
55void connection_delete(struct lttng_ht *ht, struct relay_connection *conn)
56{
57 int ret;
58 struct lttng_ht_iter iter;
59
60 assert(ht);
61 assert(conn);
62
63 iter.iter.node = &conn->sock_n.node;
64 ret = lttng_ht_del(ht, &iter);
65 assert(!ret);
66}
67
68void connection_destroy(struct relay_connection *conn)
69{
58eb9381
DG
70 assert(conn);
71
58eb9381
DG
72 call_rcu(&conn->rcu_node, rcu_free_connection);
73}
74
75struct relay_connection *connection_create(void)
76{
77 struct relay_connection *conn;
78
79 conn = zmalloc(sizeof(*conn));
80 if (!conn) {
81 PERROR("zmalloc relay connection");
82 goto error;
83 }
84
85error:
86 return conn;
87}
88
89void connection_init(struct relay_connection *conn)
90{
91 assert(conn);
92 assert(conn->sock);
93
94 CDS_INIT_LIST_HEAD(&conn->recv_head);
95 lttng_ht_node_init_ulong(&conn->sock_n, (unsigned long) conn->sock->fd);
96}
97
98void connection_free(struct relay_connection *conn)
99{
100 assert(conn);
101
ca741d24 102 free(conn->viewer_session);
58eb9381
DG
103 free(conn);
104}
This page took 0.027498 seconds and 4 git commands to generate.