| 1 | /* |
| 2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> |
| 3 | * Copyright (C) 2013 - Raphaƫl Beamonte <raphael.beamonte@gmail.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License, version 2 only, |
| 7 | * as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef _LTT_SESSIOND_H |
| 20 | #define _LTT_SESSIOND_H |
| 21 | |
| 22 | #include <urcu.h> |
| 23 | #include <urcu/wfcqueue.h> |
| 24 | |
| 25 | #include <common/sessiond-comm/sessiond-comm.h> |
| 26 | #include <common/compat/poll.h> |
| 27 | #include <common/compat/socket.h> |
| 28 | |
| 29 | #include "session.h" |
| 30 | #include "ust-app.h" |
| 31 | #include "notification-thread.h" |
| 32 | #include "sessiond-config.h" |
| 33 | |
| 34 | /* |
| 35 | * Consumer daemon state which is changed when spawning it, killing it or in |
| 36 | * case of a fatal error. |
| 37 | */ |
| 38 | enum consumerd_state { |
| 39 | CONSUMER_STARTED = 1, |
| 40 | CONSUMER_STOPPED = 2, |
| 41 | CONSUMER_ERROR = 3, |
| 42 | }; |
| 43 | |
| 44 | /* |
| 45 | * This consumer daemon state is used to validate if a client command will be |
| 46 | * able to reach the consumer. If not, the client is informed. For instance, |
| 47 | * doing a "lttng start" when the consumer state is set to ERROR will return an |
| 48 | * error to the client. |
| 49 | * |
| 50 | * The following example shows a possible race condition of this scheme: |
| 51 | * |
| 52 | * consumer thread error happens |
| 53 | * client cmd arrives |
| 54 | * client cmd checks state -> still OK |
| 55 | * consumer thread exit, sets error |
| 56 | * client cmd try to talk to consumer |
| 57 | * ... |
| 58 | * |
| 59 | * However, since the consumer is a different daemon, we have no way of making |
| 60 | * sure the command will reach it safely even with this state flag. This is why |
| 61 | * we consider that up to the state validation during command processing, the |
| 62 | * command is safe. After that, we can not guarantee the correctness of the |
| 63 | * client request vis-a-vis the consumer. |
| 64 | */ |
| 65 | extern enum consumerd_state ust_consumerd_state; |
| 66 | extern enum consumerd_state kernel_consumerd_state; |
| 67 | |
| 68 | extern const char default_home_dir[], |
| 69 | default_tracing_group[], |
| 70 | default_ust_sock_dir[], |
| 71 | default_global_apps_pipe[]; |
| 72 | |
| 73 | /* Set in main.c at boot time of the daemon */ |
| 74 | extern int kernel_tracer_fd; |
| 75 | extern struct lttng_kernel_tracer_version kernel_tracer_version; |
| 76 | extern struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version; |
| 77 | |
| 78 | /* Notification thread handle. */ |
| 79 | extern struct notification_thread_handle *notification_thread_handle; |
| 80 | |
| 81 | /* |
| 82 | * This contains extra data needed for processing a command received by the |
| 83 | * session daemon from the lttng client. |
| 84 | */ |
| 85 | struct command_ctx { |
| 86 | int ust_sock; |
| 87 | unsigned int lttng_msg_size; |
| 88 | struct ltt_session *session; |
| 89 | struct lttcomm_lttng_msg *llm; |
| 90 | struct lttcomm_session_msg *lsm; |
| 91 | lttng_sock_cred creds; |
| 92 | }; |
| 93 | |
| 94 | struct ust_command { |
| 95 | int sock; |
| 96 | struct ust_register_msg reg_msg; |
| 97 | struct cds_wfcq_node node; |
| 98 | }; |
| 99 | |
| 100 | /* |
| 101 | * Queue used to enqueue UST registration request (ust_command) and synchronized |
| 102 | * by a futex with a scheme N wakers / 1 waiters. See futex.c/.h |
| 103 | */ |
| 104 | struct ust_cmd_queue { |
| 105 | int32_t futex; |
| 106 | struct cds_wfcq_head head; |
| 107 | struct cds_wfcq_tail tail; |
| 108 | }; |
| 109 | |
| 110 | /* |
| 111 | * This is the wait queue containing wait nodes during the application |
| 112 | * registration process. |
| 113 | */ |
| 114 | struct ust_reg_wait_queue { |
| 115 | unsigned long count; |
| 116 | struct cds_list_head head; |
| 117 | }; |
| 118 | |
| 119 | /* |
| 120 | * Use by the dispatch registration to queue UST command socket to wait for the |
| 121 | * notify socket. |
| 122 | */ |
| 123 | struct ust_reg_wait_node { |
| 124 | struct ust_app *app; |
| 125 | struct cds_list_head head; |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * Used to notify that a hash table needs to be destroyed by dedicated |
| 130 | * thread. Required by design because we don't want to move destroy |
| 131 | * paths outside of large RCU read-side lock paths, and destroy cannot |
| 132 | * be called by call_rcu thread, because it may hang (waiting for |
| 133 | * call_rcu completion). |
| 134 | */ |
| 135 | extern int ht_cleanup_pipe[2]; |
| 136 | |
| 137 | extern int kernel_poll_pipe[2]; |
| 138 | |
| 139 | /* |
| 140 | * Populated when the daemon starts with the current page size of the system. |
| 141 | * Set in main() with the current page size. |
| 142 | */ |
| 143 | extern long page_size; |
| 144 | |
| 145 | /* Application health monitoring */ |
| 146 | extern struct health_app *health_sessiond; |
| 147 | |
| 148 | extern struct sessiond_config config; |
| 149 | |
| 150 | extern int lttng_sessiond_ready; |
| 151 | |
| 152 | extern int ust_consumerd64_fd, ust_consumerd32_fd; |
| 153 | |
| 154 | /* Parent PID for --sig-parent option */ |
| 155 | extern pid_t ppid; |
| 156 | /* Internal parent PID use with daemonize. */ |
| 157 | extern pid_t child_ppid; |
| 158 | |
| 159 | /* Consumer daemon specific control data. */ |
| 160 | extern struct consumer_data ustconsumer32_data; |
| 161 | extern struct consumer_data ustconsumer64_data; |
| 162 | extern struct consumer_data kconsumer_data; |
| 163 | |
| 164 | int sessiond_init_thread_quit_pipe(void); |
| 165 | int sessiond_check_thread_quit_pipe(int fd, uint32_t events); |
| 166 | int sessiond_wait_for_quit_pipe(unsigned int timeout_us); |
| 167 | int sessiond_notify_quit_pipe(void); |
| 168 | void sessiond_close_quit_pipe(void); |
| 169 | |
| 170 | int sessiond_set_thread_pollset(struct lttng_poll_event *events, size_t size); |
| 171 | void sessiond_notify_ready(void); |
| 172 | void sessiond_signal_parents(void); |
| 173 | |
| 174 | void sessiond_set_client_thread_state(bool running); |
| 175 | void sessiond_wait_client_thread_stopped(void); |
| 176 | |
| 177 | void *thread_manage_consumer(void *data); |
| 178 | |
| 179 | #endif /* _LTT_SESSIOND_H */ |