X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fagent.c;h=0b8bc0251ce2f8976de7a93a62b6ed8c194605e3;hp=b69e929ca0eda857aaa233e483df05b6191e085b;hb=a93196248ad6f88aacce3d265da09c99321376ca;hpb=d84af1a45c66fbc18195693baeb5aa7ad724c297 diff --git a/src/bin/lttng-sessiond/agent.c b/src/bin/lttng-sessiond/agent.c index b69e929ca..0b8bc0251 100644 --- a/src/bin/lttng-sessiond/agent.c +++ b/src/bin/lttng-sessiond/agent.c @@ -117,14 +117,23 @@ static int ht_match_event(struct cds_lfht_node *node, goto no_match; } - if (event->loglevel != key->loglevel) { - if (event->loglevel_type == LTTNG_EVENT_LOGLEVEL_ALL && - key->loglevel == 0 && event->loglevel == -1) { - goto match; + /* Event loglevel value and type. */ + if (event->loglevel_type == key->loglevel_type) { + /* Same loglevel type. */ + if (key->loglevel_type != LTTNG_EVENT_LOGLEVEL_ALL) { + /* + * Loglevel value must also match since the loglevel + * type is not all. + */ + if (event->loglevel_value != key->loglevel_value) { + goto no_match; + } } + } else { + /* Loglevel type is different: no match. */ goto no_match; } -match: + return 1; no_match: @@ -145,7 +154,8 @@ static void add_unique_agent_event(struct lttng_ht *ht, assert(event); key.name = event->name; - key.loglevel = event->loglevel; + key.loglevel_value = event->loglevel_value; + key.loglevel_type = event->loglevel_type; node_ptr = cds_lfht_add_unique(ht->ht, ht->hash_fct(event->node.key, lttng_ht_seed), @@ -163,7 +173,7 @@ static void destroy_event_agent_rcu(struct rcu_head *head) struct agent_event *event = caa_container_of(node, struct agent_event, node); - free(event); + agent_destroy_event(event); } /* @@ -303,9 +313,7 @@ static ssize_t list_events(struct agent_app *app, struct lttng_event **events) data_size = be32toh(reply_hdr.data_size) + sizeof(*reply); break; default: - ERR("Agent returned an unknown code: %" PRIu32, - be32toh(reply_hdr.ret_code)); - ret = LTTNG_ERR_FATAL; + ret = LTTNG_ERR_UNK; goto error; } @@ -361,6 +369,7 @@ static int enable_event(struct agent_app *app, struct agent_event *event) { int ret; uint64_t data_size; + uint32_t reply_ret_code; struct lttcomm_agent_enable msg; struct lttcomm_agent_generic_reply reply; @@ -379,7 +388,7 @@ static int enable_event(struct agent_app *app, struct agent_event *event) } memset(&msg, 0, sizeof(msg)); - msg.loglevel = event->loglevel; + msg.loglevel_value = event->loglevel_value; msg.loglevel_type = event->loglevel_type; strncpy(msg.name, event->name, sizeof(msg.name)); ret = send_payload(app->sock, &msg, sizeof(msg)); @@ -392,16 +401,16 @@ static int enable_event(struct agent_app *app, struct agent_event *event) goto error_io; } - switch (be32toh(reply.ret_code)) { + reply_ret_code = be32toh(reply.ret_code); + log_reply_code(reply_ret_code); + switch (reply_ret_code) { case AGENT_RET_CODE_SUCCESS: break; case AGENT_RET_CODE_UNKNOWN_NAME: ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; goto error; default: - ERR("Agent returned an unknown code: %" PRIu32, - be32toh(reply.ret_code)); - ret = LTTNG_ERR_FATAL; + ret = LTTNG_ERR_UNK; goto error; } @@ -423,6 +432,7 @@ static int disable_event(struct agent_app *app, struct agent_event *event) { int ret; uint64_t data_size; + uint32_t reply_ret_code; struct lttcomm_agent_disable msg; struct lttcomm_agent_generic_reply reply; @@ -452,16 +462,16 @@ static int disable_event(struct agent_app *app, struct agent_event *event) goto error_io; } - switch (be32toh(reply.ret_code)) { + reply_ret_code = be32toh(reply.ret_code); + log_reply_code(reply_ret_code); + switch (reply_ret_code) { case AGENT_RET_CODE_SUCCESS: break; case AGENT_RET_CODE_UNKNOWN_NAME: ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; goto error; default: - ERR("Agent returned an unknown code: %" PRIu32, - be32toh(reply.ret_code)); - ret = LTTNG_ERR_FATAL; + ret = LTTNG_ERR_UNK; goto error; } @@ -716,10 +726,7 @@ void agent_add_app(struct agent_app *app) assert(app); DBG3("Agent adding app sock: %d and pid: %d to ht", app->sock->fd, app->pid); - - rcu_read_lock(); lttng_ht_add_unique_ulong(agent_apps_ht_by_sock, &app->node); - rcu_read_unlock(); } /* @@ -792,9 +799,7 @@ void agent_add(struct agent *agt, struct lttng_ht *ht) DBG3("Agent adding from domain %d", agt->domain); - rcu_read_lock(); lttng_ht_add_unique_u64(ht, &agt->node); - rcu_read_unlock(); } /* @@ -807,7 +812,7 @@ struct agent *agent_create(enum lttng_domain_type domain) int ret; struct agent *agt; - agt = zmalloc(sizeof(*agt)); + agt = zmalloc(sizeof(struct agent)); if (!agt) { goto error; } @@ -825,33 +830,38 @@ error: } /* - * Create a newly allocated agent event data structure. If name is valid, it's - * copied into the created event. + * Create a newly allocated agent event data structure. + * Ownership of filter_expression is taken. * * Return a new object else NULL on error. */ struct agent_event *agent_create_event(const char *name, - struct lttng_filter_bytecode *filter) + enum lttng_loglevel_type loglevel_type, int loglevel_value, + struct lttng_filter_bytecode *filter, char *filter_expression) { - struct agent_event *event; + struct agent_event *event = NULL; - DBG3("Agent create new event with name %s", name); + DBG3("Agent create new event with name %s, loglevel type %d and loglevel value %d", + name, loglevel_type, loglevel_value); - event = zmalloc(sizeof(*event)); - if (!event) { + if (!name) { + ERR("Failed to create agent event; no name provided."); goto error; } - if (name) { - strncpy(event->name, name, sizeof(event->name)); - event->name[sizeof(event->name) - 1] = '\0'; - lttng_ht_node_init_str(&event->node, event->name); + event = zmalloc(sizeof(*event)); + if (!event) { + goto error; } - if (filter) { - event->filter = filter; - } + strncpy(event->name, name, sizeof(event->name)); + event->name[sizeof(event->name) - 1] = '\0'; + lttng_ht_node_init_str(&event->node, event->name); + event->loglevel_value = loglevel_value; + event->loglevel_type = loglevel_type; + event->filter = filter; + event->filter_expression = filter_expression; error: return event; } @@ -866,10 +876,7 @@ void agent_add_event(struct agent_event *event, struct agent *agt) assert(agt->events); DBG3("Agent adding event %s", event->name); - - rcu_read_lock(); add_unique_agent_event(agt->events, event); - rcu_read_unlock(); agt->being_used = 1; } @@ -917,7 +924,8 @@ error: * * Return object if found else NULL. */ -struct agent_event *agent_find_event(const char *name, int loglevel, +struct agent_event *agent_find_event(const char *name, + enum lttng_loglevel_type loglevel_type, int loglevel_value, struct agent *agt) { struct lttng_ht_node_str *node; @@ -931,7 +939,8 @@ struct agent_event *agent_find_event(const char *name, int loglevel, ht = agt->events; key.name = name; - key.loglevel = loglevel; + key.loglevel_value = loglevel_value; + key.loglevel_type = loglevel_type; cds_lfht_lookup(ht->ht, ht->hash_fct((void *) name, lttng_ht_seed), ht_match_event, &key, &iter.iter); @@ -958,12 +967,13 @@ void agent_destroy_event(struct agent_event *event) assert(event); free(event->filter); + free(event->filter_expression); + free(event->exclusion); free(event); } /* - * Destroy an agent completely. Note that the given pointer is NOT freed - * thus a reference to static or stack data can be passed to this function. + * Destroy an agent completely. */ void agent_destroy(struct agent *agt) { @@ -974,14 +984,6 @@ void agent_destroy(struct agent *agt) DBG3("Agent destroy"); - /* - * Just ignore if no events hash table exists. This is possible if for - * instance an agent object was allocated but not initialized. - */ - if (!agt->events) { - return; - } - rcu_read_lock(); cds_lfht_for_each_entry(agt->events->ht, &iter.iter, node, node) { int ret; @@ -1002,6 +1004,7 @@ void agent_destroy(struct agent *agt) rcu_read_unlock(); ht_cleanup_push(agt->events); + free(agt); } /*