| 1 | /* |
| 2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> |
| 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 | #ifndef _LTT_TRACE_UST_H |
| 19 | #define _LTT_TRACE_UST_H |
| 20 | |
| 21 | #include <config.h> |
| 22 | #include <limits.h> |
| 23 | #include <urcu.h> |
| 24 | #include <urcu/list.h> |
| 25 | |
| 26 | #include <lttng/lttng.h> |
| 27 | #include <common/hashtable/hashtable.h> |
| 28 | |
| 29 | #include "ust-ctl.h" |
| 30 | |
| 31 | /* UST Stream list */ |
| 32 | struct ltt_ust_stream_list { |
| 33 | unsigned int count; |
| 34 | struct cds_list_head head; |
| 35 | }; |
| 36 | |
| 37 | /* Context hash table nodes */ |
| 38 | struct ltt_ust_context { |
| 39 | struct lttng_ust_context ctx; |
| 40 | struct lttng_ht_node_ulong node; |
| 41 | }; |
| 42 | |
| 43 | /* UST event */ |
| 44 | struct ltt_ust_event { |
| 45 | unsigned int enabled; |
| 46 | struct lttng_ust_event attr; |
| 47 | struct lttng_ht *ctx; |
| 48 | struct lttng_ht_node_str node; |
| 49 | }; |
| 50 | |
| 51 | /* UST stream */ |
| 52 | struct ltt_ust_stream { |
| 53 | int handle; |
| 54 | char pathname[PATH_MAX]; |
| 55 | struct lttng_ust_object_data *obj; |
| 56 | /* Using a list of streams to keep order. */ |
| 57 | struct cds_list_head list; |
| 58 | }; |
| 59 | |
| 60 | /* UST channel */ |
| 61 | struct ltt_ust_channel { |
| 62 | unsigned int enabled; |
| 63 | char name[LTTNG_UST_SYM_NAME_LEN]; |
| 64 | char pathname[PATH_MAX]; |
| 65 | struct lttng_ust_channel attr; |
| 66 | struct lttng_ht *ctx; |
| 67 | struct lttng_ht *events; |
| 68 | struct lttng_ht_node_str node; |
| 69 | }; |
| 70 | |
| 71 | /* UST Metadata */ |
| 72 | struct ltt_ust_metadata { |
| 73 | int handle; |
| 74 | struct lttng_ust_object_data *obj; |
| 75 | char pathname[PATH_MAX]; /* Trace file path name */ |
| 76 | struct lttng_ust_channel attr; |
| 77 | struct lttng_ust_object_data *stream_obj; |
| 78 | }; |
| 79 | |
| 80 | /* UST domain global (LTTNG_DOMAIN_UST) */ |
| 81 | struct ltt_ust_domain_global { |
| 82 | struct lttng_ht *channels; |
| 83 | }; |
| 84 | |
| 85 | /* UST domain pid (LTTNG_DOMAIN_UST_PID) */ |
| 86 | struct ltt_ust_domain_pid { |
| 87 | pid_t pid; |
| 88 | struct lttng_ht *channels; |
| 89 | struct lttng_ht_node_ulong node; |
| 90 | }; |
| 91 | |
| 92 | /* UST domain exec name (LTTNG_DOMAIN_UST_EXEC_NAME) */ |
| 93 | struct ltt_ust_domain_exec { |
| 94 | char exec_name[LTTNG_UST_SYM_NAME_LEN]; |
| 95 | struct lttng_ht *channels; |
| 96 | struct lttng_ht_node_str node; |
| 97 | }; |
| 98 | |
| 99 | /* UST session */ |
| 100 | struct ltt_ust_session { |
| 101 | int id; /* Unique identifier of session */ |
| 102 | int start_trace; |
| 103 | char pathname[PATH_MAX]; |
| 104 | struct ltt_ust_domain_global domain_global; |
| 105 | /* |
| 106 | * Those two hash tables contains data for a specific UST domain and each |
| 107 | * contains a HT of channels. See ltt_ust_domain_exec and |
| 108 | * ltt_ust_domain_pid data structures. |
| 109 | */ |
| 110 | struct lttng_ht *domain_pid; |
| 111 | struct lttng_ht *domain_exec; |
| 112 | /* UID/GID of the user owning the session */ |
| 113 | uid_t uid; |
| 114 | gid_t gid; |
| 115 | }; |
| 116 | |
| 117 | #ifdef HAVE_LIBLTTNG_UST_CTL |
| 118 | |
| 119 | /* |
| 120 | * Lookup functions. NULL is returned if not found. |
| 121 | */ |
| 122 | struct ltt_ust_event *trace_ust_find_event_by_name(struct lttng_ht *ht, |
| 123 | char *name); |
| 124 | struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, |
| 125 | char *name); |
| 126 | |
| 127 | /* |
| 128 | * Create functions malloc() the data structure. |
| 129 | */ |
| 130 | struct ltt_ust_session *trace_ust_create_session(char *path, int session_id, |
| 131 | struct lttng_domain *domain); |
| 132 | struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, |
| 133 | char *path); |
| 134 | struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev); |
| 135 | struct ltt_ust_metadata *trace_ust_create_metadata(char *path); |
| 136 | struct ltt_ust_context *trace_ust_create_context( |
| 137 | struct lttng_event_context *ctx); |
| 138 | |
| 139 | /* |
| 140 | * Destroy functions free() the data structure and remove from linked list if |
| 141 | * it's applies. |
| 142 | */ |
| 143 | void trace_ust_destroy_session(struct ltt_ust_session *session); |
| 144 | void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata); |
| 145 | void trace_ust_destroy_channel(struct ltt_ust_channel *channel); |
| 146 | void trace_ust_destroy_event(struct ltt_ust_event *event); |
| 147 | |
| 148 | #else /* HAVE_LIBLTTNG_UST_CTL */ |
| 149 | |
| 150 | static inline |
| 151 | struct ltt_ust_event *trace_ust_find_event_by_name(struct lttng_ht *ht, |
| 152 | char *name) |
| 153 | { |
| 154 | return NULL; |
| 155 | } |
| 156 | |
| 157 | static inline |
| 158 | struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, |
| 159 | char *name) |
| 160 | { |
| 161 | return NULL; |
| 162 | } |
| 163 | |
| 164 | static inline |
| 165 | struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid, |
| 166 | struct lttng_domain *domain) |
| 167 | { |
| 168 | return NULL; |
| 169 | } |
| 170 | static inline |
| 171 | struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, |
| 172 | char *path) |
| 173 | { |
| 174 | return NULL; |
| 175 | } |
| 176 | static inline |
| 177 | struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev) |
| 178 | { |
| 179 | return NULL; |
| 180 | } |
| 181 | static inline |
| 182 | struct ltt_ust_metadata *trace_ust_create_metadata(char *path) |
| 183 | { |
| 184 | return NULL; |
| 185 | } |
| 186 | |
| 187 | static inline |
| 188 | void trace_ust_destroy_session(struct ltt_ust_session *session) |
| 189 | { |
| 190 | } |
| 191 | |
| 192 | static inline |
| 193 | void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata) |
| 194 | { |
| 195 | } |
| 196 | |
| 197 | static inline |
| 198 | void trace_ust_destroy_channel(struct ltt_ust_channel *channel) |
| 199 | { |
| 200 | } |
| 201 | |
| 202 | static inline |
| 203 | void trace_ust_destroy_event(struct ltt_ust_event *event) |
| 204 | { |
| 205 | } |
| 206 | static inline |
| 207 | struct ltt_ust_context *trace_ust_create_context( |
| 208 | struct lttng_event_context *ctx) |
| 209 | { |
| 210 | return NULL; |
| 211 | } |
| 212 | |
| 213 | #endif /* HAVE_LIBLTTNG_UST_CTL */ |
| 214 | |
| 215 | #endif /* _LTT_TRACE_UST_H */ |