Copy exclusion data in shadow_copy_event
[lttng-tools.git] / src / bin / lttng-sessiond / ht-cleanup.c
CommitLineData
0b2dc8df
MD
1/*
2 * Copyright (C) 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#define _GNU_SOURCE
19#include <assert.h>
20
21#include <common/hashtable/hashtable.h>
22#include <common/common.h>
23#include <common/utils.h>
24
25#include "lttng-sessiond.h"
8782cc74 26#include "health-sessiond.h"
0b2dc8df
MD
27
28void *thread_ht_cleanup(void *data)
29{
30 int ret, i, pollfd, err = -1;
6cd525e8 31 ssize_t size_ret;
0b2dc8df
MD
32 uint32_t revents, nb_fd;
33 struct lttng_poll_event events;
34
35 DBG("[ht-thread] startup.");
36
37 rcu_register_thread();
38 rcu_thread_online();
39
6c71277b 40 health_register(health_sessiond, HEALTH_SESSIOND_TYPE_HT_CLEANUP);
0b2dc8df
MD
41
42 health_code_update();
43
44 ret = sessiond_set_thread_pollset(&events, 2);
45 if (ret < 0) {
46 goto error_poll_create;
47 }
48
49 /* Add pipe to the pollset. */
50 ret = lttng_poll_add(&events, ht_cleanup_pipe[0], LPOLLIN | LPOLLERR);
51 if (ret < 0) {
52 goto error;
53 }
54
55 health_code_update();
56
57 while (1) {
58 DBG3("[ht-thread] Polling on %d fds.",
59 LTTNG_POLL_GETNB(&events));
60
61 /* Inifinite blocking call, waiting for transmission */
62restart:
63 health_poll_entry();
64 ret = lttng_poll_wait(&events, -1);
65 health_poll_exit();
66 if (ret < 0) {
67 /*
68 * Restart interrupted system call.
69 */
70 if (errno == EINTR) {
71 goto restart;
72 }
73 goto error;
74 }
75
76 nb_fd = ret;
77
78 for (i = 0; i < nb_fd; i++) {
79 struct lttng_ht *ht;
80
81 health_code_update();
82
83 /* Fetch once the poll data */
84 revents = LTTNG_POLL_GETEV(&events, i);
85 pollfd = LTTNG_POLL_GETFD(&events, i);
86
87 /* Thread quit pipe has been closed. Killing thread. */
88 ret = sessiond_check_thread_quit_pipe(pollfd, revents);
89 if (ret) {
90 err = 0;
91 goto exit;
92 }
93 assert(pollfd == ht_cleanup_pipe[0]);
94
95 if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
96 ERR("ht cleanup pipe error");
97 goto error;
98 } else if (!(revents & LPOLLIN)) {
99 /* No POLLIN and not a catched error, stop the thread. */
100 ERR("ht cleanup failed. revent: %u", revents);
101 goto error;
102 }
103
6cd525e8
MD
104 /* Get socket from dispatch thread. */
105 size_ret = lttng_read(ht_cleanup_pipe[0], &ht,
106 sizeof(ht));
107 if (size_ret < sizeof(ht)) {
0b2dc8df
MD
108 PERROR("ht cleanup notify pipe");
109 goto error;
110 }
111 health_code_update();
112 /*
113 * The whole point of this thread is to call
114 * lttng_ht_destroy from a context that is NOT:
115 * 1) a read-side RCU lock,
116 * 2) a call_rcu thread.
117 */
118 lttng_ht_destroy(ht);
119
120 health_code_update();
121 }
122 }
123
124exit:
125error:
126 lttng_poll_clean(&events);
127error_poll_create:
128 utils_close_pipe(ht_cleanup_pipe);
129 ht_cleanup_pipe[0] = ht_cleanup_pipe[1] = -1;
130 DBG("[ust-thread] cleanup complete.");
131 if (err) {
132 health_error();
133 ERR("Health error occurred in %s", __func__);
134 }
8782cc74 135 health_unregister(health_sessiond);
0b2dc8df
MD
136 rcu_thread_offline();
137 rcu_unregister_thread();
138 return NULL;
139}
This page took 0.030263 seconds and 4 git commands to generate.