Save filter expression as part of agent events and save them
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 30 Aug 2015 21:44:41 +0000 (17:44 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 8 Sep 2015 13:03:15 +0000 (09:03 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/agent.c
src/bin/lttng-sessiond/agent.h
src/bin/lttng-sessiond/channel.c
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/event.c
src/bin/lttng-sessiond/save.c
src/bin/lttng-sessiond/trace-ust.c
src/bin/lttng-sessiond/trace-ust.h
src/bin/lttng-sessiond/ust-app.c
src/bin/lttng-sessiond/ust-app.h
tests/unit/test_ust_data.c

index 4a8473ebbe901ac147e15dbc2101edd6bd823362..4342c94db96adc2955c1070d92cf8d6e81592dd6 100644 (file)
@@ -784,33 +784,37 @@ 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)
+               int loglevel, enum lttng_loglevel_type loglevel_type,
+               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);
 
-       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 = loglevel;
+       event->loglevel_type = loglevel_type;
+       event->filter = filter;
+       event->filter_expression = filter_expression;
 error:
        return event;
 }
@@ -918,6 +922,7 @@ void agent_destroy_event(struct agent_event *event)
 
        free(event->filter);
        free(event->filter_expression);
+       free(event->exclusion);
        free(event);
 }
 
index de95b31d90ed998c8393a148af1dd0fe4eb67ec9..293426e0ef783ca5577997a3582e98b62127497a 100644 (file)
@@ -91,9 +91,10 @@ struct agent_event {
        /* Hash table node of the agent domain object. */
        struct lttng_ht_node_str node;
 
-       /* Bytecode filter associated with the event . NULL if none. */
-       char *filter_expression;
+       /* Filter associated with the event. NULL if none. */
        struct lttng_filter_bytecode *filter;
+       char *filter_expression;
+       struct lttng_event_exclusion *exclusion;
 };
 
 /*
@@ -130,8 +131,10 @@ void agent_destroy(struct agent *agt);
 void agent_add(struct agent *agt, struct lttng_ht *ht);
 
 /* Agent event API. */
-struct agent_event *agent_create_event(const char *name,
-               struct lttng_filter_bytecode *filter);
+struct agent_event *agent_create_event(const char *name, int loglevel,
+               enum lttng_loglevel_type loglevel_type,
+               struct lttng_filter_bytecode *filter,
+               char *filter_expression);
 void agent_add_event(struct agent_event *event, struct agent *agt);
 
 struct agent_event *agent_find_event(const char *name, int loglevel,
index 7ea43b8f39c5b6f0ba5253f018d40dc6fa72f821..69498050ede41639cfc283f4288371834dfccc2d 100644 (file)
@@ -333,11 +333,24 @@ int channel_ust_create(struct ltt_ust_session *usess,
        }
 
        /* Create UST channel */
-       uchan = trace_ust_create_channel(attr);
+       uchan = trace_ust_create_channel(attr, LTTNG_DOMAIN_UST);
        if (uchan == NULL) {
                ret = LTTNG_ERR_FATAL;
                goto error;
        }
+
+       /*
+        * HACK: Set the channel's subdomain (JUL, Log4j, Python, etc.)
+        * based on the default name.
+        */
+       if (!strcmp(uchan->name, DEFAULT_JUL_CHANNEL_NAME)) {
+               uchan->domain = LTTNG_DOMAIN_JUL;
+       } else if (!strcmp(uchan->name, DEFAULT_LOG4J_CHANNEL_NAME)) {
+               uchan->domain = LTTNG_DOMAIN_LOG4J;
+       } else if (!strcmp(uchan->name, DEFAULT_PYTHON_CHANNEL_NAME)) {
+               uchan->domain = LTTNG_DOMAIN_PYTHON;
+       }
+
        uchan->enabled = 1;
        if (trace_ust_is_max_id(usess->used_channel_id)) {
                ret = LTTNG_ERR_UST_CHAN_FAIL;
index 63d91f53d197ecc4b54d19a00dafee24668011f5..6259ed089baa5f401990e90cb5034b3a048f1109 100644 (file)
@@ -1737,7 +1737,8 @@ static int _cmd_enable_event(struct ltt_session *session,
                memset(&uevent, 0, sizeof(uevent));
                uevent.type = LTTNG_EVENT_TRACEPOINT;
                uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
-               default_event_name = event_get_default_agent_ust_name(domain->type);
+               default_event_name = event_get_default_agent_ust_name(
+                               domain->type);
                if (!default_event_name) {
                        ret = LTTNG_ERR_FATAL;
                        goto error;
@@ -1769,29 +1770,30 @@ static int _cmd_enable_event(struct ltt_session *session,
                }
 
                {
-                       struct lttng_filter_bytecode *filter_copy = NULL;
                        char *filter_expression_copy = NULL;
+                       struct lttng_filter_bytecode *filter_copy = NULL;
 
                        if (filter) {
-                               filter_copy = zmalloc(
-                                       sizeof(struct lttng_filter_bytecode)
-                                       + filter->len);
+                               const size_t filter_size = sizeof(
+                                               struct lttng_filter_bytecode)
+                                               + filter->len;
+
+                               filter_copy = zmalloc(filter_size);
                                if (!filter_copy) {
                                        ret = LTTNG_ERR_NOMEM;
-                                       goto error;
                                }
+                               memcpy(filter_copy, filter, filter_size);
 
-                               memcpy(filter_copy, filter,
-                                      sizeof(struct lttng_filter_bytecode)
-                                      + filter->len);
-                       }
-
-                       if (filter_expression) {
                                filter_expression_copy =
                                                strdup(filter_expression);
                                if (!filter_expression) {
                                        ret = LTTNG_ERR_NOMEM;
-                                       goto error_free_copy;
+                               }
+
+                               if (!filter_expression_copy || !filter_copy) {
+                                       free(filter_expression_copy);
+                                       free(filter_copy);
+                                       goto error;
                                }
                        }
 
@@ -1799,11 +1801,6 @@ static int _cmd_enable_event(struct ltt_session *session,
                                        (char *) default_chan_name,
                                        &uevent, filter_expression_copy,
                                        filter_copy, NULL, wpipe);
-                       filter_copy = NULL;
-                       filter_expression_copy = NULL;
-error_free_copy:
-                       free(filter_copy);
-                       free(filter_expression_copy);
                }
 
                if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
@@ -1814,12 +1811,12 @@ error_free_copy:
                if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) {
                        ret = event_agent_enable_all(usess, agt, event, filter,
                                        filter_expression);
-                       filter = NULL;
                } else {
                        ret = event_agent_enable(usess, agt, event, filter,
                                        filter_expression);
-                       filter = NULL;
                }
+               filter = NULL;
+               filter_expression = NULL;
                if (ret != LTTNG_OK) {
                        goto error;
                }
index a5b4774ca623443788712138eb5a1dac89479bd2..223a13d0e92eceff598fd59363fc3c2753deaa6a 100644 (file)
@@ -509,8 +509,7 @@ error:
  */
 int event_agent_enable_all(struct ltt_ust_session *usess,
                struct agent *agt, struct lttng_event *event,
-               struct lttng_filter_bytecode *filter,
-               char *filter_expression)
+               struct lttng_filter_bytecode *filter ,char *filter_expression)
 {
        int ret;
        struct agent_event *aevent;
@@ -558,18 +557,19 @@ int event_agent_enable(struct ltt_ust_session *usess,
        assert(agt);
 
        DBG("Event agent enabling %s for session %" PRIu64 " with loglevel type %d "
-                       "and loglevel %d", event->name, usess->id, event->loglevel_type,
-                       event->loglevel);
+                       ", loglevel %d and filter \"%s\"", event->name,
+                       usess->id, event->loglevel_type, event->loglevel,
+                       filter_expression ? filter_expression : "NULL");
 
        aevent = agent_find_event(event->name, event->loglevel, agt);
        if (!aevent) {
-               aevent = agent_create_event(event->name, filter);
+               aevent = agent_create_event(event->name, event->loglevel,
+                               event->loglevel_type, filter,
+                               filter_expression);
                if (!aevent) {
                        ret = LTTNG_ERR_NOMEM;
                        goto error;
                }
-               aevent->loglevel = event->loglevel;
-               aevent->loglevel_type = event->loglevel_type;
                created = 1;
        }
 
index 8c35d749e5272539c4703a5b8b104ab6c3a62a8c..8558b52195b9e3ac13720c6a7b5d4568989492a7 100644 (file)
@@ -35,6 +35,7 @@
 #include "session.h"
 #include "syscall.h"
 #include "trace-ust.h"
+#include "agent.h"
 
 static
 int save_kernel_channel_attributes(struct config_writer *writer,
@@ -740,6 +741,68 @@ end:
        return ret;
 }
 
+static
+void init_ust_event_from_agent_event(struct ltt_ust_event *ust_event,
+               struct agent_event *agent_event)
+{
+       ust_event->enabled = agent_event->enabled;
+       ust_event->attr.instrumentation = LTTNG_UST_TRACEPOINT;
+       strncpy(ust_event->attr.name, agent_event->name, LTTNG_SYMBOL_NAME_LEN);
+       ust_event->attr.loglevel_type = agent_event->loglevel_type;
+       ust_event->attr.loglevel = agent_event->loglevel;
+       ust_event->filter_expression = agent_event->filter_expression;
+       ust_event->exclusion = agent_event->exclusion;
+}
+
+static
+int save_agent_events(struct config_writer *writer,
+               struct ltt_ust_channel *chan,
+               struct agent *agent)
+{
+       int ret;
+       struct lttng_ht_iter iter;
+       struct lttng_ht_node_str *node;
+
+       ret = config_writer_open_element(writer, config_element_events);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       rcu_read_lock();
+       cds_lfht_for_each_entry(agent->events->ht, &iter.iter, node, node) {
+               int ret;
+               struct agent_event *agent_event;
+               struct ltt_ust_event fake_event;
+
+               memset(&fake_event, 0, sizeof(fake_event));
+               agent_event = caa_container_of(node, struct agent_event, node);
+
+               /*
+                * Initialize a fake ust event to reuse the same serialization
+                * function since UST and agent events contain the same info
+                * (and one could wonder why they don't reuse the same
+                * structures...).
+                */
+               init_ust_event_from_agent_event(&fake_event, agent_event);
+               ret = save_ust_event(writer, &fake_event);
+               if (ret) {
+                       rcu_read_unlock();
+                       goto end;
+               }
+       }
+       rcu_read_unlock();
+
+       /* /events */
+       ret = config_writer_close_element(writer);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+end:
+       return ret;
+}
+
 static
 int save_kernel_context(struct config_writer *writer,
        struct lttng_kernel_context *ctx)
@@ -1068,10 +1131,31 @@ int save_ust_channel(struct config_writer *writer,
                goto end;
        }
 
-       ret = save_ust_events(writer, ust_chan->events);
-       if (ret) {
-               ret = LTTNG_ERR_SAVE_IO_FAIL;
-               goto end;
+       if (ust_chan->domain == LTTNG_DOMAIN_UST) {
+               ret = save_ust_events(writer, ust_chan->events);
+               if (ret) {
+                       goto end;
+               }
+       } else {
+               struct agent *agent = NULL;
+
+               agent = trace_ust_find_agent(session, ust_chan->domain);
+               if (!agent) {
+                       ret = LTTNG_ERR_SAVE_IO_FAIL;
+                       ERR("Could not find agent associated to UST subdomain");
+                       goto end;
+               }
+
+               /*
+                * Channels associated with a UST sub-domain (such as JUL, Log4j
+                * or Python) don't have any non-internal events. We retrieve
+                * the "agent" events associated with this channel and serialize
+                * them.
+                */
+               ret = save_agent_events(writer, ust_chan, agent);
+               if (ret) {
+                       goto end;
+               }
        }
 
        ret = save_ust_context(writer, &ust_chan->ctx_list);
@@ -1139,20 +1223,62 @@ end:
 }
 
 static
-int save_ust_session(struct config_writer *writer,
-       struct ltt_session *session, int save_agent)
+const char *get_config_domain_str(enum lttng_domain_type domain)
+{
+       const char *str_dom;
+
+       switch (domain) {
+       case LTTNG_DOMAIN_KERNEL:
+               str_dom = config_domain_type_kernel;
+               break;
+       case LTTNG_DOMAIN_UST:
+               str_dom = config_domain_type_ust;
+               break;
+       case LTTNG_DOMAIN_JUL:
+               str_dom = config_domain_type_jul;
+               break;
+       case LTTNG_DOMAIN_LOG4J:
+               str_dom = config_domain_type_log4j;
+               break;
+       case LTTNG_DOMAIN_PYTHON:
+               str_dom = config_domain_type_python;
+               break;
+       default:
+               assert(0);
+       }
+
+       return str_dom;
+}
+
+static
+int save_ust_domain(struct config_writer *writer,
+       struct ltt_session *session, enum lttng_domain_type domain)
 {
        int ret;
        struct ltt_ust_channel *ust_chan;
        const char *buffer_type_string;
        struct lttng_ht_node_str *node;
        struct lttng_ht_iter iter;
+       const char *config_domain_name;
 
        assert(writer);
        assert(session);
 
-       ret = config_writer_write_element_string(writer, config_element_type,
-                       save_agent ? config_domain_type_jul : config_domain_type_ust);
+       ret = config_writer_open_element(writer,
+                       config_element_domain);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       config_domain_name = get_config_domain_str(domain);
+       if (!config_domain_name) {
+               ret = LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       ret = config_writer_write_element_string(writer,
+                       config_element_type, config_domain_name);
        if (ret) {
                ret = LTTNG_ERR_SAVE_IO_FAIL;
                goto end;
@@ -1182,13 +1308,8 @@ int save_ust_session(struct config_writer *writer,
        rcu_read_lock();
        cds_lfht_for_each_entry(session->ust_session->domain_global.channels->ht,
                        &iter.iter, node, node) {
-               int agent_channel;
-
                ust_chan = caa_container_of(node, struct ltt_ust_channel, node);
-               agent_channel = !strcmp(DEFAULT_JUL_CHANNEL_NAME, ust_chan->name) ||
-                       !strcmp(DEFAULT_LOG4J_CHANNEL_NAME, ust_chan->name) ||
-                       !strcmp(DEFAULT_PYTHON_CHANNEL_NAME, ust_chan->name);
-               if (!(save_agent ^ agent_channel)) {
+               if (domain == ust_chan->domain) {
                        ret = save_ust_channel(writer, ust_chan, session->ust_session);
                        if (ret) {
                                rcu_read_unlock();
@@ -1204,6 +1325,14 @@ int save_ust_session(struct config_writer *writer,
                ret = LTTNG_ERR_SAVE_IO_FAIL;
                goto end;
        }
+
+       /* /domain */
+       ret = config_writer_close_element(writer);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
 end:
        return ret;
 }
@@ -1360,22 +1489,13 @@ int save_domains(struct config_writer *writer, struct ltt_session *session)
        }
 
        if (session->ust_session) {
-               unsigned long agent_count;
-
-               ret = config_writer_open_element(writer,
-                       config_element_domain);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end;
-               }
-
-               ret = save_ust_session(writer, session, 0);
+               ret = save_ust_domain(writer, session, LTTNG_DOMAIN_UST);
                if (ret) {
                        goto end;
                }
 
                ret = config_writer_open_element(writer,
-                       config_element_trackers);
+                               config_element_trackers);
                if (ret) {
                        ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
@@ -1389,40 +1509,22 @@ int save_domains(struct config_writer *writer, struct ltt_session *session)
                /* /trackers */
                ret = config_writer_close_element(writer);
                if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
                }
-               /* /domain */
-               ret = config_writer_close_element(writer);
+
+               ret = save_ust_domain(writer, session, LTTNG_DOMAIN_JUL);
                if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
                }
 
-               rcu_read_lock();
-               agent_count =
-                       lttng_ht_get_count(session->ust_session->agents);
-               rcu_read_unlock();
-
-               if (agent_count > 0) {
-                       ret = config_writer_open_element(writer,
-                               config_element_domain);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       ret = save_ust_session(writer, session, 1);
-                       if (ret) {
-                               goto end;
-                       }
+               ret = save_ust_domain(writer, session, LTTNG_DOMAIN_LOG4J);
+               if (ret) {
+                       goto end;
+               }
 
-                       /* /domain */
-                       ret = config_writer_close_element(writer);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
+               ret = save_ust_domain(writer, session, LTTNG_DOMAIN_PYTHON);
+               if (ret) {
+                       goto end;
                }
        }
 
index f8064a4c956fdc2e3d3d3bac337ed8d95e18e705..8ae8dfdb1a91bb69b43ccb54747cee8a91d76fa8 100644 (file)
@@ -308,7 +308,8 @@ error:
  *
  * Return pointer to structure or NULL.
  */
-struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan)
+struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan,
+               enum lttng_domain_type domain)
 {
        struct ltt_ust_channel *luc;
 
@@ -320,6 +321,8 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan)
                goto error;
        }
 
+       luc->domain = domain;
+
        /* Copy UST channel attributes */
        luc->attr.overwrite = chan->attr.overwrite;
        luc->attr.subbuf_size = chan->attr.subbuf_size;
@@ -431,8 +434,8 @@ struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
 
        /* Same layout. */
        lue->filter_expression = filter_expression;
-       lue->filter = (struct lttng_ust_filter_bytecode *) filter;
-       lue->exclusion = (struct lttng_event_exclusion *) exclusion;
+       lue->filter = filter;
+       lue->exclusion = exclusion;
 
        /* Init node */
        lttng_ht_node_init_str(&lue->node, lue->attr.name);
index 121d3b0ccc06c471a130aa040a77f74143dffb09..343ce3e49b84f2a000dc5f67b9f5d8d138e911f7 100644 (file)
@@ -50,7 +50,7 @@ struct ltt_ust_event {
        struct lttng_ust_event attr;
        struct lttng_ht_node_str node;
        char *filter_expression;
-       struct lttng_ust_filter_bytecode *filter;
+       struct lttng_filter_bytecode *filter;
        struct lttng_event_exclusion *exclusion;
        bool internal;
 };
@@ -59,6 +59,11 @@ struct ltt_ust_event {
 struct ltt_ust_channel {
        uint64_t id;    /* unique id per session. */
        unsigned int enabled;
+       /*
+        * A UST channel can be part of a userspace sub-domain such as JUL,
+        * Log4j, Python.
+        */
+       enum lttng_domain_type domain;
        char name[LTTNG_UST_SYM_NAME_LEN];
        struct lttng_ust_channel_attr attr;
        struct lttng_ht *ctx;
@@ -182,7 +187,8 @@ struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
  * Create functions malloc() the data structure.
  */
 struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
-struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr);
+struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
+               enum lttng_domain_type domain);
 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
                char *filter_expression,
                struct lttng_filter_bytecode *filter,
@@ -236,7 +242,8 @@ struct ltt_ust_session *trace_ust_create_session(unsigned int session_id)
        return NULL;
 }
 static inline
-struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr)
+struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
+               enum lttng_domain_type domain)
 {
        return NULL;
 }
index 6f032da112baae7a9a97af061f4388bc621b6d6d..5cc9622f4c444aa41994cf2de22f1fa907731dcf 100644 (file)
@@ -980,15 +980,15 @@ error:
  *
  * Return allocated filter or NULL on error.
  */
-static struct lttng_ust_filter_bytecode *alloc_copy_ust_app_filter(
-               struct lttng_ust_filter_bytecode *orig_f)
+static struct lttng_filter_bytecode *copy_filter_bytecode(
+               struct lttng_filter_bytecode *orig_f)
 {
-       struct lttng_ust_filter_bytecode *filter = NULL;
+       struct lttng_filter_bytecode *filter = NULL;
 
        /* Copy filter bytecode */
        filter = zmalloc(sizeof(*filter) + orig_f->len);
        if (!filter) {
-               PERROR("zmalloc alloc ust app filter");
+               PERROR("zmalloc alloc filter bytecode");
                goto error;
        }
 
@@ -998,6 +998,30 @@ error:
        return filter;
 }
 
+/*
+ * Create a liblttng-ust filter bytecode from given bytecode.
+ *
+ * Return allocated filter or NULL on error.
+ */
+static struct lttng_ust_filter_bytecode *create_ust_bytecode_from_bytecode(
+               struct lttng_filter_bytecode *orig_f)
+{
+       struct lttng_ust_filter_bytecode *filter = NULL;
+
+       /* Copy filter bytecode */
+       filter = zmalloc(sizeof(*filter) + orig_f->len);
+       if (!filter) {
+               PERROR("zmalloc alloc ust filter bytecode");
+               goto error;
+       }
+
+       assert(sizeof(struct lttng_filter_bytecode) ==
+                       sizeof(struct lttng_ust_filter_bytecode));
+       memcpy(filter, orig_f, sizeof(*filter) + orig_f->len);
+error:
+       return filter;
+}
+
 /*
  * Find an ust_app using the sock and return it. RCU read side lock must be
  * held before calling this helper function.
@@ -1050,7 +1074,7 @@ error:
  * Return an ust_app_event object or NULL on error.
  */
 static struct ust_app_event *find_ust_app_event(struct lttng_ht *ht,
-               char *name, struct lttng_ust_filter_bytecode *filter, int loglevel,
+               char *name, struct lttng_filter_bytecode *filter, int loglevel,
                const struct lttng_event_exclusion *exclusion)
 {
        struct lttng_ht_iter iter;
@@ -1066,7 +1090,7 @@ static struct ust_app_event *find_ust_app_event(struct lttng_ht *ht,
        key.filter = filter;
        key.loglevel = loglevel;
        /* lttng_event_exclusion and lttng_ust_event_exclusion structures are similar */
-       key.exclusion = (struct lttng_ust_event_exclusion *)exclusion;
+       key.exclusion = exclusion;
 
        /* Lookup using the event name as hash and a custom match fct. */
        cds_lfht_lookup(ht->ht, ht->hash_fct((void *) name, lttng_ht_seed),
@@ -1131,6 +1155,7 @@ int set_ust_event_filter(struct ust_app_event *ua_event,
                struct ust_app *app)
 {
        int ret;
+       struct lttng_ust_filter_bytecode *ust_bytecode = NULL;
 
        health_code_update();
 
@@ -1139,7 +1164,12 @@ int set_ust_event_filter(struct ust_app_event *ua_event,
                goto error;
        }
 
-       ret = ustctl_set_filter(app->sock, ua_event->filter,
+       ust_bytecode = create_ust_bytecode_from_bytecode(ua_event->filter);
+       if (!ust_bytecode) {
+               ret = -LTTNG_ERR_NOMEM;
+               goto error;
+       }
+       ret = ustctl_set_filter(app->sock, ust_bytecode,
                        ua_event->obj);
        if (ret < 0) {
                if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) {
@@ -1161,9 +1191,31 @@ int set_ust_event_filter(struct ust_app_event *ua_event,
 
 error:
        health_code_update();
+       free(ust_bytecode);
        return ret;
 }
 
+static
+struct lttng_ust_event_exclusion *create_ust_exclusion_from_exclusion(
+               struct lttng_event_exclusion *exclusion)
+{
+       struct lttng_ust_event_exclusion *ust_exclusion = NULL;
+       size_t exclusion_alloc_size = sizeof(struct lttng_ust_event_exclusion) +
+               LTTNG_UST_SYM_NAME_LEN * exclusion->count;
+
+       ust_exclusion = zmalloc(exclusion_alloc_size);
+       if (!ust_exclusion) {
+               PERROR("malloc");
+               goto end;
+       }
+
+       assert(sizeof(struct lttng_event_exclusion) ==
+                       sizeof(struct lttng_ust_event_exclusion));
+       memcpy(ust_exclusion, exclusion, exclusion_alloc_size);
+end:
+       return ust_exclusion;
+}
+
 /*
  * Set event exclusions on the tracer.
  */
@@ -1172,6 +1224,7 @@ int set_ust_event_exclusion(struct ust_app_event *ua_event,
                struct ust_app *app)
 {
        int ret;
+       struct lttng_ust_event_exclusion *ust_exclusion = NULL;
 
        health_code_update();
 
@@ -1180,8 +1233,13 @@ int set_ust_event_exclusion(struct ust_app_event *ua_event,
                goto error;
        }
 
-       ret = ustctl_set_exclusion(app->sock, ua_event->exclusion,
-                       ua_event->obj);
+       ust_exclusion = create_ust_exclusion_from_exclusion(
+                       ua_event->exclusion);
+       if (!ust_exclusion) {
+               ret = -LTTNG_ERR_NOMEM;
+               goto error;
+       }
+       ret = ustctl_set_exclusion(app->sock, ust_exclusion, ua_event->obj);
        if (ret < 0) {
                if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) {
                        ERR("UST app event %s exclusions failed for app (pid: %d) "
@@ -1202,6 +1260,7 @@ int set_ust_event_exclusion(struct ust_app_event *ua_event,
 
 error:
        health_code_update();
+       free(ust_exclusion);
        return ret;
 }
 
@@ -1503,13 +1562,13 @@ static void shadow_copy_event(struct ust_app_event *ua_event,
 
        /* Copy filter bytecode */
        if (uevent->filter) {
-               ua_event->filter = alloc_copy_ust_app_filter(uevent->filter);
+               ua_event->filter = copy_filter_bytecode(uevent->filter);
                /* Filter might be NULL here in case of ENONEM. */
        }
 
        /* Copy exclusion data */
        if (uevent->exclusion) {
-               exclusion_alloc_size = sizeof(struct lttng_ust_event_exclusion) +
+               exclusion_alloc_size = sizeof(struct lttng_event_exclusion) +
                                LTTNG_UST_SYM_NAME_LEN * uevent->exclusion->count;
                ua_event->exclusion = zmalloc(exclusion_alloc_size);
                if (ua_event->exclusion == NULL) {
index 66cda8c081518024feb120fdbf7b2f33be54ff03..37ced6765b4f45ecb1bcc2f566bb93585b32193d 100644 (file)
@@ -48,9 +48,9 @@ struct ust_app_notify_sock_obj {
 
 struct ust_app_ht_key {
        const char *name;
-       const struct lttng_ust_filter_bytecode *filter;
+       const struct lttng_filter_bytecode *filter;
        enum lttng_ust_loglevel_type loglevel;
-       const struct lttng_ust_event_exclusion *exclusion;
+       const struct lttng_event_exclusion *exclusion;
 };
 
 /*
@@ -115,8 +115,8 @@ struct ust_app_event {
        struct lttng_ust_event attr;
        char name[LTTNG_UST_SYM_NAME_LEN];
        struct lttng_ht_node_str node;
-       struct lttng_ust_filter_bytecode *filter;
-       struct lttng_ust_event_exclusion *exclusion;
+       struct lttng_filter_bytecode *filter;
+       struct lttng_event_exclusion *exclusion;
 };
 
 struct ust_app_stream {
index d83b8b5e346a5644aa5e9782828dd6161bdbab30..f945aef8f912d850bb390ea50bdd7a0c1c7843a6 100644 (file)
@@ -101,7 +101,7 @@ static void test_create_ust_channel(void)
 
        strncpy(attr.name, "channel0", 8);
 
-       uchan = trace_ust_create_channel(&attr);
+       uchan = trace_ust_create_channel(&attr, LTTNG_DOMAIN_UST);
        ok(uchan != NULL, "Create UST channel");
 
        ok(uchan->enabled == 0 &&
This page took 0.037765 seconds and 4 git commands to generate.