| 1 | /* |
| 2 | * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License, version 2 only, as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
| 15 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | */ |
| 17 | |
| 18 | #ifndef LTTNG_SESSIOND_AGENT_H |
| 19 | #define LTTNG_SESSIOND_AGENT_H |
| 20 | |
| 21 | #define _GNU_SOURCE |
| 22 | #include <inttypes.h> |
| 23 | |
| 24 | #include <common/hashtable/hashtable.h> |
| 25 | #include <lttng/lttng.h> |
| 26 | |
| 27 | /* Agent protocol version that is verified during the agent registration. */ |
| 28 | #define AGENT_MAJOR_VERSION 1 |
| 29 | #define AGENT_MINOR_VERSION 0 |
| 30 | |
| 31 | /* |
| 32 | * Hash table that contains the agent app created upon registration indexed by |
| 33 | * socket. |
| 34 | */ |
| 35 | struct lttng_ht *agent_apps_ht_by_sock; |
| 36 | |
| 37 | struct agent_ht_key { |
| 38 | const char *name; |
| 39 | int loglevel; |
| 40 | }; |
| 41 | |
| 42 | /* |
| 43 | * Registration message payload from an agent application. The PID is used to |
| 44 | * find back the corresponding UST app object so both socket can be linked. |
| 45 | */ |
| 46 | struct agent_register_msg { |
| 47 | /* This maps to a lttng_domain_type. */ |
| 48 | uint32_t domain; |
| 49 | uint32_t pid; |
| 50 | uint32_t major_version; |
| 51 | uint32_t minor_version; |
| 52 | }; |
| 53 | |
| 54 | /* |
| 55 | * Agent application object created after a successful registration. This |
| 56 | * object is linked to its associated UST app by their PID through hash table |
| 57 | * lookups. |
| 58 | */ |
| 59 | struct agent_app { |
| 60 | /* |
| 61 | * PID sent during registration of a AGENT application. |
| 62 | */ |
| 63 | pid_t pid; |
| 64 | |
| 65 | /* Domain of the application. */ |
| 66 | enum lttng_domain_type domain; |
| 67 | |
| 68 | /* |
| 69 | * AGENT TCP socket that was created upon registration. |
| 70 | */ |
| 71 | struct lttcomm_sock *sock; |
| 72 | |
| 73 | /* Initialized with the AGENT sock value. */ |
| 74 | struct lttng_ht_node_ulong node; |
| 75 | }; |
| 76 | |
| 77 | /* |
| 78 | * Agent event representation. |
| 79 | */ |
| 80 | struct agent_event { |
| 81 | /* Name of the event. */ |
| 82 | char name[LTTNG_SYMBOL_NAME_LEN]; |
| 83 | int loglevel; |
| 84 | enum lttng_loglevel_type loglevel_type; |
| 85 | |
| 86 | /* |
| 87 | * Tells if the event is enabled or not on the agent. |
| 88 | */ |
| 89 | unsigned int enabled:1; |
| 90 | |
| 91 | /* Hash table node of the agent domain object. */ |
| 92 | struct lttng_ht_node_str node; |
| 93 | |
| 94 | /* Bytecode filter associated with the event . NULL if none. */ |
| 95 | struct lttng_filter_bytecode *filter; |
| 96 | }; |
| 97 | |
| 98 | /* |
| 99 | * Agent object containing events enabled/disabled for it. |
| 100 | */ |
| 101 | struct agent { |
| 102 | /* |
| 103 | * This indicates if that domain is being used meaning if at least one |
| 104 | * event has been at some point in time added to it. This is used so when |
| 105 | * listing domains for a session, we can tell or not if the agent is |
| 106 | * actually enabled. |
| 107 | */ |
| 108 | unsigned int being_used:1; |
| 109 | |
| 110 | /* What domain this agent is. */ |
| 111 | enum lttng_domain_type domain; |
| 112 | |
| 113 | /* Contains event indexed by name. */ |
| 114 | struct lttng_ht *events; |
| 115 | |
| 116 | /* Node used for the hash table indexed by domain type. */ |
| 117 | struct lttng_ht_node_u64 node; |
| 118 | }; |
| 119 | |
| 120 | /* Allocate agent apps hash table */ |
| 121 | int agent_app_ht_alloc(void); |
| 122 | /* Clean-up agent apps hash table */ |
| 123 | void agent_app_ht_clean(void); |
| 124 | |
| 125 | /* Initialize an already allocated agent domain. */ |
| 126 | int agent_init(struct agent *agt); |
| 127 | struct agent *agent_create(enum lttng_domain_type domain); |
| 128 | void agent_destroy(struct agent *agt); |
| 129 | void agent_add(struct agent *agt, struct lttng_ht *ht); |
| 130 | |
| 131 | /* Agent event API. */ |
| 132 | struct agent_event *agent_create_event(const char *name, |
| 133 | struct lttng_filter_bytecode *filter); |
| 134 | void agent_add_event(struct agent_event *event, struct agent *agt); |
| 135 | |
| 136 | struct agent_event *agent_find_event(const char *name, int loglevel, |
| 137 | struct agent *agt); |
| 138 | struct agent_event *agent_find_event_by_name(const char *name, |
| 139 | struct agent *agt); |
| 140 | void agent_delete_event(struct agent_event *event, struct agent *agt); |
| 141 | void agent_destroy_event(struct agent_event *event); |
| 142 | |
| 143 | /* Agent app API. */ |
| 144 | struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain, |
| 145 | struct lttcomm_sock *sock); |
| 146 | void agent_add_app(struct agent_app *app); |
| 147 | void agent_delete_app(struct agent_app *app); |
| 148 | struct agent_app *agent_find_app_by_sock(int sock); |
| 149 | void agent_destroy_app(struct agent_app *app); |
| 150 | void agent_destroy_app_by_sock(int sock); |
| 151 | int agent_send_registration_done(struct agent_app *app); |
| 152 | |
| 153 | /* Agent action API */ |
| 154 | int agent_enable_event(struct agent_event *event, |
| 155 | enum lttng_domain_type domain); |
| 156 | int agent_disable_event(struct agent_event *event, |
| 157 | enum lttng_domain_type domain); |
| 158 | void agent_update(struct agent *agt, int sock); |
| 159 | int agent_list_events(struct lttng_event **events, |
| 160 | enum lttng_domain_type domain); |
| 161 | |
| 162 | #endif /* LTTNG_SESSIOND_AGENT_H */ |