| 1 | /* |
| 2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> |
| 3 | * Julien Desfossez <julien.desfossez@polymtl.ca> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #ifndef _LIBLTTSESSIONDCOMM_H |
| 22 | #define _LIBLTTSESSIONDCOMM_H |
| 23 | |
| 24 | #include <limits.h> |
| 25 | #include <uuid/uuid.h> |
| 26 | |
| 27 | #include "lttng-share.h" |
| 28 | |
| 29 | #define LTTNG_RUNDIR "/var/run/lttng" |
| 30 | |
| 31 | /* Default unix socket path */ |
| 32 | #define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK LTTNG_RUNDIR "/client-ltt-sessiond" |
| 33 | #define DEFAULT_GLOBAL_APPS_UNIX_SOCK LTTNG_RUNDIR "/apps-ltt-sessiond" |
| 34 | #define DEFAULT_HOME_APPS_UNIX_SOCK "%s/.apps-ltt-sessiond" |
| 35 | #define DEFAULT_HOME_CLIENT_UNIX_SOCK "%s/.client-ltt-sessiond" |
| 36 | |
| 37 | /* Kernel consumer path */ |
| 38 | #define KCONSUMERD_PATH LTTNG_RUNDIR "/kconsumerd" |
| 39 | #define KCONSUMERD_CMD_SOCK_PATH KCONSUMERD_PATH "/command" |
| 40 | #define KCONSUMERD_ERR_SOCK_PATH KCONSUMERD_PATH "/error" |
| 41 | |
| 42 | /* Queue size of listen(2) */ |
| 43 | #define MAX_LISTEN 10 |
| 44 | |
| 45 | /* Get the error code index from 0 since |
| 46 | * LTTCOMM_OK start at 1000 |
| 47 | */ |
| 48 | #define LTTCOMM_ERR_INDEX(code) (code - LTTCOMM_OK) |
| 49 | |
| 50 | enum lttcomm_sessiond_command { |
| 51 | KERNEL_CREATE_CHANNEL, |
| 52 | KERNEL_CREATE_SESSION, |
| 53 | KERNEL_CREATE_STREAM, |
| 54 | KERNEL_DISABLE_EVENT, |
| 55 | KERNEL_ENABLE_EVENT, |
| 56 | KERNEL_OPEN_METADATA, |
| 57 | KERNEL_START_TRACE, |
| 58 | KERNEL_STOP_TRACE, |
| 59 | LTTNG_CREATE_SESSION, |
| 60 | LTTNG_DESTROY_SESSION, |
| 61 | LTTNG_FORCE_SUBBUF_SWITCH, |
| 62 | LTTNG_GET_ALL_SESSION, |
| 63 | LTTNG_GET_SOCK_PATH, |
| 64 | LTTNG_GET_SUBBUF_NUM_SIZE, |
| 65 | LTTNG_LIST_MARKERS, |
| 66 | LTTNG_LIST_SESSIONS, |
| 67 | LTTNG_LIST_TRACES, |
| 68 | LTTNG_LIST_TRACE_EVENTS, |
| 69 | LTTNG_SETUP_TRACE, |
| 70 | LTTNG_SET_SOCK_PATH, |
| 71 | LTTNG_SET_SUBBUF_NUM, |
| 72 | LTTNG_SET_SUBBUF_SIZE, |
| 73 | UST_ALLOC_TRACE, |
| 74 | UST_CREATE_TRACE, |
| 75 | UST_DESTROY_TRACE, |
| 76 | UST_DISABLE_MARKER, |
| 77 | UST_ENABLE_MARKER, |
| 78 | UST_LIST_APPS, |
| 79 | UST_START_TRACE, |
| 80 | UST_STOP_TRACE, |
| 81 | }; |
| 82 | |
| 83 | /* |
| 84 | * lttcomm error code. |
| 85 | */ |
| 86 | enum lttcomm_return_code { |
| 87 | LTTCOMM_OK = 1000, /* Ok */ |
| 88 | LTTCOMM_ERR, /* Unknown Error */ |
| 89 | LTTCOMM_UND, /* Undefine command */ |
| 90 | LTTCOMM_ALLOC_FAIL, /* Trace allocation fail */ |
| 91 | LTTCOMM_NO_SESSION, /* No session found */ |
| 92 | LTTCOMM_CREATE_FAIL, /* Create trace fail */ |
| 93 | LTTCOMM_SESSION_FAIL, /* Create session fail */ |
| 94 | LTTCOMM_START_FAIL, /* Start tracing fail */ |
| 95 | LTTCOMM_STOP_FAIL, /* Stop tracing fail */ |
| 96 | LTTCOMM_LIST_FAIL, /* Listing apps fail */ |
| 97 | LTTCOMM_NO_APPS, /* No traceable application */ |
| 98 | LTTCOMM_NO_SESS, /* No sessions available */ |
| 99 | LTTCOMM_NO_TRACE, /* No trace exist */ |
| 100 | LTTCOMM_FATAL, /* Session daemon had a fatal error */ |
| 101 | LTTCOMM_NO_TRACEABLE, /* Error for non traceable app */ |
| 102 | LTTCOMM_SELECT_SESS, /* Must select a session */ |
| 103 | LTTCOMM_EXIST_SESS, /* Session name already exist */ |
| 104 | LTTCOMM_NO_EVENT, /* No event found */ |
| 105 | LTTCOMM_KERN_NA, /* Kernel tracer unavalable */ |
| 106 | LTTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */ |
| 107 | LTTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */ |
| 108 | LTTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */ |
| 109 | LTTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */ |
| 110 | LTTCOMM_KERN_META_FAIL, /* Kernel open metadata failed */ |
| 111 | LTTCOMM_KERN_START_FAIL, /* Kernel start trace failed */ |
| 112 | LTTCOMM_KERN_STOP_FAIL, /* Kernel stop trace failed */ |
| 113 | LTTCOMM_KERN_CONSUMER_FAIL, /* Kernel consumer start failed */ |
| 114 | LTTCOMM_KERN_STREAM_FAIL, /* Kernel create stream failed */ |
| 115 | LTTCOMM_KERN_DIR_FAIL, /* Kernel trace directory creation failed */ |
| 116 | LTTCOMM_KERN_DIR_EXIST, /* Kernel trace directory exist */ |
| 117 | LTTCOMM_KERN_NO_SESSION, /* No kernel session found */ |
| 118 | KCONSUMERD_COMMAND_SOCK_READY, /* when kconsumerd command socket ready */ |
| 119 | KCONSUMERD_SUCCESS_RECV_FD, /* success on receiving fds */ |
| 120 | KCONSUMERD_ERROR_RECV_FD, /* error on receiving fds */ |
| 121 | KCONSUMERD_POLL_ERROR, /* Error in polling thread in kconsumerd */ |
| 122 | KCONSUMERD_POLL_NVAL, /* Poll on closed fd */ |
| 123 | KCONSUMERD_POLL_HUP, /* All fds have hungup */ |
| 124 | KCONSUMERD_EXIT_SUCCESS, /* kconsumerd exiting normally */ |
| 125 | KCONSUMERD_EXIT_FAILURE, /* kconsumerd exiting on error */ |
| 126 | KCONSUMERD_OUTFD_ERROR, /* error opening the tracefile */ |
| 127 | KCONSUMERD_SPLICE_EBADF, /* EBADF from splice(2) */ |
| 128 | KCONSUMERD_SPLICE_EINVAL, /* EINVAL from splice(2) */ |
| 129 | KCONSUMERD_SPLICE_ENOMEM, /* ENOMEM from splice(2) */ |
| 130 | KCONSUMERD_SPLICE_ESPIPE, /* ESPIPE from splice(2) */ |
| 131 | /* MUST be last element */ |
| 132 | LTTCOMM_NR, /* Last element */ |
| 133 | }; |
| 134 | |
| 135 | /* commands for kconsumerd */ |
| 136 | enum lttcomm_consumerd_command { |
| 137 | LTTCOMM_ADD_STREAM = 1100, |
| 138 | LTTCOMM_UPDATE_STREAM, /* pause, delete, start depending on fd state */ |
| 139 | LTTCOMM_STOP, /* delete all */ |
| 140 | }; |
| 141 | |
| 142 | /* state of each fd in consumerd */ |
| 143 | enum lttcomm_kconsumerd_fd_state { |
| 144 | ACTIVE_FD, |
| 145 | PAUSE_FD, |
| 146 | DELETE_FD, |
| 147 | }; |
| 148 | |
| 149 | /* |
| 150 | * Data structure received from lttng client to session daemon. |
| 151 | */ |
| 152 | struct lttcomm_session_msg { |
| 153 | u32 cmd_type; /* enum lttcomm_sessiond_command */ |
| 154 | uuid_t session_uuid; |
| 155 | char trace_name[NAME_MAX]; |
| 156 | char session_name[NAME_MAX]; |
| 157 | u32 pid; /* pid_t */ |
| 158 | union { |
| 159 | struct { |
| 160 | int auto_session; |
| 161 | } create_session; |
| 162 | /* Marker data */ |
| 163 | struct { |
| 164 | char event_name[NAME_MAX]; |
| 165 | } event; |
| 166 | } u; |
| 167 | }; |
| 168 | |
| 169 | /* |
| 170 | * Data structure for the response from sessiond to the lttng client. |
| 171 | */ |
| 172 | struct lttcomm_lttng_msg { |
| 173 | u32 cmd_type; /* enum lttcomm_sessiond_command */ |
| 174 | u32 ret_code; /* enum lttcomm_return_code */ |
| 175 | u32 pid; /* pid_t */ |
| 176 | u32 trace_name_offset; |
| 177 | u32 data_size; |
| 178 | uuid_t session_uuid; |
| 179 | /* Contains: trace_name + data */ |
| 180 | char payload[]; |
| 181 | }; |
| 182 | |
| 183 | /* |
| 184 | * Data structures for the kconsumerd communications |
| 185 | * |
| 186 | * The header structure is sent to the kconsumerd daemon to inform |
| 187 | * how many lttcomm_kconsumerd_msg it is about to receive |
| 188 | */ |
| 189 | struct lttcomm_kconsumerd_header { |
| 190 | u32 payload_size; |
| 191 | u32 cmd_type; /* enum lttcomm_consumerd_command */ |
| 192 | u32 ret_code; /* enum lttcomm_return_code */ |
| 193 | }; |
| 194 | |
| 195 | /* lttcomm_kconsumerd_msg represents a file descriptor to consume the |
| 196 | * data and a path name to write it |
| 197 | */ |
| 198 | struct lttcomm_kconsumerd_msg { |
| 199 | char path_name[PATH_MAX]; |
| 200 | int fd; |
| 201 | u32 state; /* enum lttcomm_kconsumerd_fd_state */ |
| 202 | unsigned long max_sb_size; /* the subbuffer size for this channel */ |
| 203 | }; |
| 204 | |
| 205 | extern int lttcomm_create_unix_sock(const char *pathname); |
| 206 | extern int lttcomm_connect_unix_sock(const char *pathname); |
| 207 | extern int lttcomm_accept_unix_sock(int sock); |
| 208 | extern int lttcomm_listen_unix_sock(int sock); |
| 209 | extern int lttcomm_close_unix_sock(int sock); |
| 210 | extern ssize_t lttcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, size_t len); |
| 211 | extern ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len); |
| 212 | extern ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len); |
| 213 | extern const char *lttcomm_get_readable_code(enum lttcomm_return_code code); |
| 214 | |
| 215 | #endif /* _LIBLTTSESSIONDCOMM_H */ |