Notify java agent of enabled application contexts
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 28 Jan 2016 21:39:33 +0000 (16:39 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 12 Feb 2016 22:54:03 +0000 (17:54 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
12 files changed:
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/context.c
src/bin/lttng-sessiond/lttng-ust-abi.h
src/bin/lttng-sessiond/lttng-ust-ctl.h
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
src/common/sessiond-comm/agent.h

index f6f2f772e08af693c26268e10b0dfda5bed08d09..b2608a186f83095b9faf20fd58a222eb4f2b0283 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License, version 2 only, as
@@ -18,6 +19,7 @@
 #define _LGPL_SOURCE
 #include <assert.h>
 #include <urcu/uatomic.h>
+#include <urcu/rculist.h>
 
 #include <common/common.h>
 #include <common/sessiond-comm/agent.h>
 
 #define AGENT_RET_CODE_INDEX(code) (code - AGENT_RET_CODE_SUCCESS)
 
+/*
+ * Agent application context representation.
+ */
+struct agent_app_ctx {
+       char *provider_name;
+       char *ctx_name;
+
+       /* agent_app_ctx are part of the agent app_ctx_list. */
+       struct cds_list_head list_node;
+
+       /* For call_rcu teardown. */
+       struct rcu_head rcu_node;
+};
+
 /*
  * Human readable agent return code.
  */
@@ -225,7 +241,7 @@ error:
  *
  * Return 0 on success or else a negative errno value of sendmsg() op.
  */
-static int send_payload(struct lttcomm_sock *sock, void *data,
+static int send_payload(struct lttcomm_sock *sock, const void *data,
                size_t size)
 {
        int ret;
@@ -371,7 +387,7 @@ static int enable_event(struct agent_app *app, struct agent_event *event)
        uint64_t data_size;
        size_t filter_expression_length;
        uint32_t reply_ret_code;
-       struct lttcomm_agent_enable msg;
+       struct lttcomm_agent_enable_event msg;
        struct lttcomm_agent_generic_reply reply;
 
        assert(app);
@@ -447,6 +463,112 @@ error:
        return ret;
 }
 
+/*
+ * Send Pascal-style string. Size is sent as a 32-bit big endian integer.
+ */
+static
+int send_pstring(struct lttcomm_sock *sock, const char *str, uint32_t len)
+{
+       int ret;
+       uint32_t len_be;
+
+       len_be = htobe32(len);
+       ret = send_payload(sock, &len_be, sizeof(len_be));
+       if (ret) {
+               goto end;
+       }
+
+       ret = send_payload(sock, str, len);
+       if (ret) {
+               goto end;
+       }
+end:
+       return ret;
+}
+
+/*
+ * Internal enable application context on an agent application. This function
+ * communicates with the agent to enable a given application context.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+static int app_context_op(struct agent_app *app,
+               struct agent_app_ctx *ctx, enum lttcomm_agent_command cmd)
+{
+       int ret;
+       uint32_t reply_ret_code;
+       struct lttcomm_agent_generic_reply reply;
+       size_t app_ctx_provider_name_len, app_ctx_name_len, data_size;
+
+       assert(app);
+       assert(app->sock);
+       assert(ctx);
+       assert(cmd == AGENT_CMD_APP_CTX_ENABLE ||
+                       cmd == AGENT_CMD_APP_CTX_DISABLE);
+
+       DBG2("Agent %s application %s:%s for app pid: %d and socket %d",
+                       cmd == AGENT_CMD_APP_CTX_ENABLE ? "enabling" : "disabling",
+                       ctx->provider_name, ctx->ctx_name,
+                       app->pid, app->sock->fd);
+
+       /*
+        * Calculate the payload's size, which consists of the size (u32, BE)
+        * of the provider name, the NULL-terminated provider name string, the
+        * size (u32, BE) of the context name, followed by the NULL-terminated
+        * context name string.
+        */
+       app_ctx_provider_name_len = strlen(ctx->provider_name) + 1;
+       app_ctx_name_len = strlen(ctx->ctx_name) + 1;
+       data_size = sizeof(uint32_t) + app_ctx_provider_name_len +
+                       sizeof(uint32_t) + app_ctx_name_len;
+
+       ret = send_header(app->sock, data_size, cmd, 0);
+       if (ret < 0) {
+               goto error_io;
+       }
+
+       if (app_ctx_provider_name_len > UINT32_MAX ||
+                       app_ctx_name_len > UINT32_MAX) {
+               ERR("Application context name > MAX_UINT32");
+               ret = LTTNG_ERR_INVALID;
+               goto error;
+       }
+
+       ret = send_pstring(app->sock, ctx->provider_name,
+                       (uint32_t) app_ctx_provider_name_len);
+       if (ret < 0) {
+               goto error_io;
+       }
+
+       ret = send_pstring(app->sock, ctx->ctx_name,
+                       (uint32_t) app_ctx_name_len);
+       if (ret < 0) {
+               goto error_io;
+       }
+
+       ret = recv_reply(app->sock, &reply, sizeof(reply));
+       if (ret < 0) {
+               goto error_io;
+       }
+
+       reply_ret_code = be32toh(reply.ret_code);
+       log_reply_code(reply_ret_code);
+       switch (reply_ret_code) {
+       case AGENT_RET_CODE_SUCCESS:
+               break;
+       default:
+               ret = LTTNG_ERR_UNK;
+               goto error;
+       }
+
+       return LTTNG_OK;
+
+error_io:
+       ret = LTTNG_ERR_UST_ENABLE_FAIL;
+error:
+       return ret;
+}
+
 /*
  * Internal disable agent event call on a agent application. This function
  * communicates with the agent to disable a given event.
@@ -458,7 +580,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_disable_event msg;
        struct lttcomm_agent_generic_reply reply;
 
        assert(app);
@@ -561,8 +683,91 @@ error:
        return ret;
 }
 
+static
+void destroy_app_ctx(struct agent_app_ctx *ctx)
+{
+       free(ctx->provider_name);
+       free(ctx->ctx_name);
+       free(ctx);
+}
+
+static
+struct agent_app_ctx *create_app_ctx(struct lttng_event_context *ctx)
+{
+       struct agent_app_ctx *agent_ctx = NULL;
+
+       if (!ctx) {
+               goto end;
+       }
+
+       assert(ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT);
+       agent_ctx = zmalloc(sizeof(*ctx));
+       if (!agent_ctx) {
+               goto end;
+       }
+
+       agent_ctx->provider_name = strdup(ctx->u.app_ctx.provider_name);
+       agent_ctx->ctx_name = strdup(ctx->u.app_ctx.ctx_name);
+       if (!agent_ctx->provider_name || !agent_ctx->ctx_name) {
+               destroy_app_ctx(agent_ctx);
+               agent_ctx = NULL;
+       }
+end:
+       return agent_ctx;
+}
+
+/*
+ * Enable agent context on every agent applications registered with the session
+ * daemon.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int agent_enable_context(struct lttng_event_context *ctx,
+               enum lttng_domain_type domain)
+{
+       int ret;
+       struct agent_app *app;
+       struct lttng_ht_iter iter;
+
+       assert(ctx);
+       if (ctx->ctx != LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
+               ret = LTTNG_ERR_INVALID;
+               goto error;
+       }
+
+       rcu_read_lock();
+
+       cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app,
+                       node.node) {
+               struct agent_app_ctx *agent_ctx;
+
+               if (app->domain != domain) {
+                       continue;
+               }
+
+               agent_ctx = create_app_ctx(ctx);
+               if (!agent_ctx) {
+                       goto error_unlock;
+               }
+
+               /* Enable event on agent application through TCP socket. */
+               ret = app_context_op(app, agent_ctx, AGENT_CMD_APP_CTX_ENABLE);
+               if (ret != LTTNG_OK) {
+                       destroy_app_ctx(agent_ctx);
+                       goto error_unlock;
+               }
+       }
+
+       ret = LTTNG_OK;
+
+error_unlock:
+       rcu_read_unlock();
+error:
+       return ret;
+}
+
 /*
- * Disable agent event on every agent applications registered with the session
+ * Disable agent event on every agent application registered with the session
  * daemon.
  *
  * Return LTTNG_OK on success or else a LTTNG_ERR* code.
@@ -602,6 +807,39 @@ end:
        return ret;
 }
 
+/*
+ * Disable agent context on every agent application registered with the session
+ * daemon.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int disable_context(struct agent_app_ctx *ctx, enum lttng_domain_type domain)
+{
+       int ret = LTTNG_OK;
+       struct agent_app *app;
+       struct lttng_ht_iter iter;
+
+       assert(ctx);
+
+       rcu_read_lock();
+       DBG2("Disabling agent application context %s:%s",
+                       ctx->provider_name, ctx->ctx_name);
+       cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app,
+                       node.node) {
+               if (app->domain != domain) {
+                       continue;
+               }
+
+               ret = app_context_op(app, ctx, AGENT_CMD_APP_CTX_DISABLE);
+               if (ret != LTTNG_OK) {
+                       goto end;
+               }
+       }
+end:
+       rcu_read_unlock();
+       return ret;
+}
+
 /*
  * Ask every agent for the list of possible event. Events is allocated with the
  * events of every agent application.
@@ -808,6 +1046,7 @@ int agent_init(struct agent *agt)
        }
        lttng_ht_node_init_u64(&agt->node, agt->domain);
 
+       CDS_INIT_LIST_HEAD(&agt->app_ctx_list);
        return 0;
 
 error:
@@ -907,6 +1146,32 @@ void agent_add_event(struct agent_event *event, struct agent *agt)
        agt->being_used = 1;
 }
 
+/*
+ * Unique add of a agent context to an agent object.
+ */
+int agent_add_context(struct lttng_event_context *ctx, struct agent *agt)
+{
+       int ret = LTTNG_OK;
+       struct agent_app_ctx *agent_ctx = NULL;
+
+       assert(ctx);
+       assert(agt);
+       assert(agt->events);
+       assert(ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT);
+
+       agent_ctx = create_app_ctx(ctx);
+       if (!agent_ctx) {
+               ret = LTTNG_ERR_NOMEM;
+               goto end;
+       }
+
+       DBG3("Agent adding context %s:%s", ctx->u.app_ctx.provider_name,
+                       ctx->u.app_ctx.ctx_name);
+       cds_list_add_tail_rcu(&agent_ctx->list_node, &agt->app_ctx_list);
+end:
+       return ret;
+}
+
 /*
  * Find multiple agent events sharing the given name.
  *
@@ -1008,6 +1273,15 @@ void agent_destroy_event(struct agent_event *event)
        free(event);
 }
 
+static
+void destroy_app_ctx_rcu(struct rcu_head *head)
+{
+       struct agent_app_ctx *ctx =
+                       caa_container_of(head, struct agent_app_ctx, rcu_node);
+
+       destroy_app_ctx(ctx);
+}
+
 /*
  * Destroy an agent completely.
  */
@@ -1015,6 +1289,7 @@ void agent_destroy(struct agent *agt)
 {
        struct lttng_ht_node_str *node;
        struct lttng_ht_iter iter;
+       struct agent_app_ctx *ctx;
 
        assert(agt);
 
@@ -1026,9 +1301,10 @@ void agent_destroy(struct agent *agt)
                struct agent_event *event;
 
                /*
-                * When destroying an event, we have to try to disable it on the agent
-                * side so the event stops generating data. The return value is not
-                * important since we have to continue anyway destroying the object.
+                * When destroying an event, we have to try to disable it on the
+                * agent side so the event stops generating data. The return
+                * value is not important since we have to continue anyway
+                * destroying the object.
                 */
                event = caa_container_of(node, struct agent_event, node);
                (void) agent_disable_event(event, agt->domain);
@@ -1037,8 +1313,13 @@ void agent_destroy(struct agent *agt)
                assert(!ret);
                call_rcu(&node->head, destroy_event_agent_rcu);
        }
-       rcu_read_unlock();
 
+       cds_list_for_each_entry_rcu(ctx, &agt->app_ctx_list, list_node) {
+               (void) disable_context(ctx, agt->domain);
+               cds_list_del(&ctx->list_node);
+               call_rcu(&ctx->rcu_node, destroy_app_ctx_rcu);
+       }
+       rcu_read_unlock();
        ht_cleanup_push(agt->events);
        free(agt);
 }
@@ -1119,6 +1400,7 @@ void agent_update(struct agent *agt, int sock)
        struct agent_app *app;
        struct agent_event *event;
        struct lttng_ht_iter iter;
+       struct agent_app_ctx *ctx;
 
        assert(agt);
        assert(sock >= 0);
@@ -1126,19 +1408,18 @@ void agent_update(struct agent *agt, int sock)
        DBG("Agent updating app socket %d", sock);
 
        rcu_read_lock();
+       app = agent_find_app_by_sock(sock);
+       /*
+        * We are in the registration path thus if the application is gone,
+        * there is a serious code flow error.
+        */
+       assert(app);
        cds_lfht_for_each_entry(agt->events->ht, &iter.iter, event, node.node) {
                /* Skip event if disabled. */
                if (!event->enabled) {
                        continue;
                }
 
-               app = agent_find_app_by_sock(sock);
-               /*
-                * We are in the registration path thus if the application is gone,
-                * there is a serious code flow error.
-                */
-               assert(app);
-
                ret = enable_event(app, event);
                if (ret != LTTNG_OK) {
                        DBG2("Agent update unable to enable event %s on app pid: %d sock %d",
@@ -1147,5 +1428,16 @@ void agent_update(struct agent *agt, int sock)
                        continue;
                }
        }
+
+       cds_list_for_each_entry_rcu(ctx, &agt->app_ctx_list, list_node) {
+               ret = app_context_op(app, ctx, AGENT_CMD_APP_CTX_ENABLE);
+               if (ret != LTTNG_OK) {
+                       DBG2("Agent update unable to add application context %s:%s on app pid: %d sock %d",
+                                       ctx->provider_name, ctx->ctx_name,
+                                       app->pid, app->sock->fd);
+                       continue;
+               }
+       }
+
        rcu_read_unlock();
 }
index 2b3d864a6515b54ff5cf817ab818d2da3e66c8da..c0808c48fe50ab0845aba4572d3607b576446f4e 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License, version 2 only, as
@@ -116,6 +117,9 @@ struct agent {
        /* Contains event indexed by name. */
        struct lttng_ht *events;
 
+       /* Application context list (struct agent_app_ctx). */
+       struct cds_list_head app_ctx_list;
+
        /* Node used for the hash table indexed by domain type. */
        struct lttng_ht_node_u64 node;
 };
@@ -148,6 +152,11 @@ void agent_event_next_duplicate(const char *name,
 void agent_delete_event(struct agent_event *event, struct agent *agt);
 void agent_destroy_event(struct agent_event *event);
 
+/* Agent context API.*/
+int agent_enable_context(struct lttng_event_context *ctx,
+               enum lttng_domain_type domain);
+int agent_add_context(struct lttng_event_context *ctx, struct agent *agt);
+
 /* Agent app API. */
 struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain,
                struct lttcomm_sock *sock);
index 06a6d616af7a01d4c9207e6d7b86156e2d3b499e..7c95a0d2194d4e6de2e43e726b98ee05fcb2d2cd 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 2 only,
@@ -38,6 +39,7 @@ struct lttng_channel *channel_new_default_attr(int dom,
                enum lttng_buffer_type type)
 {
        struct lttng_channel *chan;
+       const char *channel_name = DEFAULT_CHANNEL_NAME;
 
        chan = zmalloc(sizeof(struct lttng_channel));
        if (chan == NULL) {
@@ -45,12 +47,6 @@ struct lttng_channel *channel_new_default_attr(int dom,
                goto error_alloc;
        }
 
-       if (snprintf(chan->name, sizeof(chan->name), "%s",
-                               DEFAULT_CHANNEL_NAME) < 0) {
-               PERROR("snprintf default channel name");
-               goto error;
-       }
-
        /* Same for all domains. */
        chan->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
        chan->attr.tracefile_size = DEFAULT_CHANNEL_TRACEFILE_SIZE;
@@ -67,7 +63,17 @@ struct lttng_channel *channel_new_default_attr(int dom,
                chan->attr.read_timer_interval = DEFAULT_KERNEL_CHANNEL_READ_TIMER;
                chan->attr.live_timer_interval = DEFAULT_KERNEL_CHANNEL_LIVE_TIMER;
                break;
+       case LTTNG_DOMAIN_JUL:
+               channel_name = DEFAULT_JUL_CHANNEL_NAME;
+               goto common_ust;
+       case LTTNG_DOMAIN_LOG4J:
+               channel_name = DEFAULT_LOG4J_CHANNEL_NAME;
+               goto common_ust;
+       case LTTNG_DOMAIN_PYTHON:
+               channel_name = DEFAULT_PYTHON_CHANNEL_NAME;
+               goto common_ust;
        case LTTNG_DOMAIN_UST:
+common_ust:
                switch (type) {
                case LTTNG_BUFFER_PER_UID:
                        chan->attr.subbuf_size = default_get_ust_uid_channel_subbuf_size();
@@ -98,6 +104,11 @@ struct lttng_channel *channel_new_default_attr(int dom,
                goto error;     /* Not implemented */
        }
 
+       if (snprintf(chan->name, sizeof(chan->name), "%s",
+                       channel_name) < 0) {
+               PERROR("snprintf default channel name");
+               goto error;
+       }
        return chan;
 
 error:
index 33e301c87fb20850d536e5637b3ddb7a4420b0c7..eca3cf439c0ced16022d65e4dd44645c6d63cb6b 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License, version 2 only, as
@@ -1359,6 +1360,12 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                char *channel_name, struct lttng_event_context *ctx, int kwpipe)
 {
        int ret, chan_kern_created = 0, chan_ust_created = 0;
+       char *app_ctx_provider_name = NULL, *app_ctx_name = NULL;
+
+       if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
+               app_ctx_provider_name = ctx->u.app_ctx.provider_name;
+               app_ctx_name = ctx->u.app_ctx.ctx_name;
+       }
 
        switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
@@ -1378,6 +1385,28 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                        goto error;
                }
                break;
+       case LTTNG_DOMAIN_JUL:
+       case LTTNG_DOMAIN_LOG4J:
+       {
+               /*
+                * Validate channel name.
+                * If no channel name is given and the domain is JUL or LOG4J,
+                * set it to the appropriate domain-specific channel name. If
+                * a name is provided but does not match the expexted channel
+                * name, return an error.
+                */
+               if (domain == LTTNG_DOMAIN_JUL && *channel_name &&
+                               strcmp(channel_name,
+                               DEFAULT_JUL_CHANNEL_NAME)) {
+                       ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
+                       goto error;
+               } else if (domain == LTTNG_DOMAIN_LOG4J && *channel_name &&
+                               strcmp(channel_name,
+                               DEFAULT_LOG4J_CHANNEL_NAME)) {
+                       ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
+                       goto error;
+               }
+       }
        case LTTNG_DOMAIN_UST:
        {
                struct ltt_ust_session *usess = session->ust_session;
@@ -1405,6 +1434,10 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                }
 
                ret = context_ust_add(usess, domain, ctx, channel_name);
+               free(app_ctx_provider_name);
+               free(app_ctx_name);
+               app_ctx_name = NULL;
+               app_ctx_provider_name = NULL;
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -1415,7 +1448,8 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain,
                goto error;
        }
 
-       return LTTNG_OK;
+       ret = LTTNG_OK;
+       goto end;
 
 error:
        if (chan_kern_created) {
@@ -1439,6 +1473,9 @@ error:
                                uchan);
                trace_ust_destroy_channel(uchan);
        }
+end:
+       free(app_ctx_provider_name);
+       free(app_ctx_name);
        return ret;
 }
 
index ffd6e3ad50f3d3702da54903c6b7afc703360494..1725c6a107d429616b09dab83d01623ba722ad2a 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 2 only,
@@ -29,6 +30,7 @@
 #include "kernel.h"
 #include "ust-app.h"
 #include "trace-ust.h"
+#include "agent.h"
 
 /*
  * Add kernel context to all channel.
@@ -92,12 +94,11 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan, struct lttng_event_context *ctx)
 {
        int ret;
-       struct ltt_ust_context *uctx;
+       struct ltt_ust_context *uctx = NULL;
 
        assert(usess);
        assert(uchan);
        assert(ctx);
-       assert(domain == LTTNG_DOMAIN_UST);
 
        /* Check if context is duplicate */
        cds_list_for_each_entry(uctx, &uchan->ctx_list, list) {
@@ -106,6 +107,38 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess,
                        goto duplicate;
                }
        }
+       uctx = NULL;
+
+       switch (domain) {
+       case LTTNG_DOMAIN_JUL:
+       case LTTNG_DOMAIN_LOG4J:
+       {
+               struct agent *agt = trace_ust_find_agent(usess, domain);
+
+               if (!agt) {
+                       agt = agent_create(domain);
+                       if (!agt) {
+                               ret = LTTNG_ERR_NOMEM;
+                               goto error;
+                       }
+                       agent_add(agt, usess->agents);
+               }
+               ret = agent_add_context(ctx, agt);
+               if (ret != LTTNG_OK) {
+                       goto error;
+               }
+
+               ret = agent_enable_context(ctx, domain);
+               if (ret != LTTNG_OK) {
+                       goto error;
+               }
+               break;
+       }
+       case LTTNG_DOMAIN_UST:
+               break;
+       default:
+               assert(0);
+       }
 
        /* Create ltt UST context */
        uctx = trace_ust_create_context(ctx);
@@ -246,7 +279,6 @@ int context_ust_add(struct ltt_ust_session *usess,
        assert(usess);
        assert(ctx);
        assert(channel_name);
-       assert(domain == LTTNG_DOMAIN_UST);
 
        rcu_read_lock();
 
index d4c3b60aa79508efe50c0433583ab64a8a86afe5..7bec0c961f09475a27b754ef81ae03e43f8c1fe7 100644 (file)
@@ -142,6 +142,7 @@ enum lttng_ust_context_type {
        LTTNG_UST_CONTEXT_IP                    = 4,
        LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER   = 5,
        LTTNG_UST_CONTEXT_CPU_ID                = 6,
+       LTTNG_UST_CONTEXT_APP_CONTEXT           = 7,
 };
 
 struct lttng_ust_perf_counter_ctx {
@@ -158,6 +159,11 @@ struct lttng_ust_context {
 
        union {
                struct lttng_ust_perf_counter_ctx perf_counter;
+               struct {
+                       /* Includes trailing '\0'. */
+                       uint32_t provider_name_len;
+                       uint32_t ctx_name_len;
+               } app_ctx;
                char padding[LTTNG_UST_CONTEXT_PADDING2];
        } u;
 } LTTNG_PACKED;
index 73a9244187aa9c6aef8536749439cd6482e6228b..1ea7b938a309aefd57f870b370a3d9d61f5296c2 100644 (file)
@@ -59,6 +59,17 @@ struct ustctl_consumer_channel_attr {
  * API used by sessiond.
  */
 
+struct lttng_ust_context_attr {
+       enum lttng_ust_context_type ctx;
+       union {
+               struct lttng_ust_perf_counter_ctx perf_counter;
+               struct {
+                       char *provider_name;
+                       char *ctx_name;
+               } app_ctx;
+       } u;
+};
+
 /*
  * Error values: all the following functions return:
  * >= 0: Success (LTTNG_UST_OK)
@@ -69,7 +80,7 @@ int ustctl_create_session(int sock);
 int ustctl_create_event(int sock, struct lttng_ust_event *ev,
                struct lttng_ust_object_data *channel_data,
                struct lttng_ust_object_data **event_data);
-int ustctl_add_context(int sock, struct lttng_ust_context *ctx,
+int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx,
                struct lttng_ust_object_data *obj_data,
                struct lttng_ust_object_data **context_data);
 int ustctl_set_filter(int sock, struct lttng_ust_filter_bytecode *bytecode,
index 4d39e213326b6ce903e459b6bb243d807051696a..4ed8fb1a554868c10fa17f150f561f3eae808ee9 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 2 only,
@@ -518,7 +519,8 @@ error:
 }
 
 static
-int trace_ust_context_type_event_to_ust(enum lttng_event_context_type type)
+int trace_ust_context_type_event_to_ust(
+               enum lttng_event_context_type type)
 {
        int utype;
 
@@ -546,6 +548,9 @@ int trace_ust_context_type_event_to_ust(enum lttng_event_context_type type)
                        utype = LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER;
                }
                break;
+       case LTTNG_EVENT_CONTEXT_APP_CONTEXT:
+               utype = LTTNG_UST_CONTEXT_APP_CONTEXT;
+               break;
        default:
                utype = -1;
                break;
@@ -599,7 +604,7 @@ int trace_ust_match_context(struct ltt_ust_context *uctx,
 struct ltt_ust_context *trace_ust_create_context(
                struct lttng_event_context *ctx)
 {
-       struct ltt_ust_context *uctx;
+       struct ltt_ust_context *uctx = NULL;
        int utype;
 
        assert(ctx);
@@ -607,13 +612,13 @@ struct ltt_ust_context *trace_ust_create_context(
        utype = trace_ust_context_type_event_to_ust(ctx->ctx);
        if (utype < 0) {
                ERR("Invalid UST context");
-               return NULL;
+               goto end;
        }
 
        uctx = zmalloc(sizeof(struct ltt_ust_context));
-       if (uctx == NULL) {
+       if (!uctx) {
                PERROR("zmalloc ltt_ust_context");
-               goto error;
+               goto end;
        }
 
        uctx->ctx.ctx = (enum lttng_ust_context_type) utype;
@@ -625,14 +630,31 @@ struct ltt_ust_context *trace_ust_create_context(
                                LTTNG_UST_SYM_NAME_LEN);
                uctx->ctx.u.perf_counter.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
                break;
+       case LTTNG_UST_CONTEXT_APP_CONTEXT:
+       {
+               char *provider_name = NULL, *ctx_name = NULL;
+
+               provider_name = strdup(ctx->u.app_ctx.provider_name);
+               if (!provider_name) {
+                       goto error;
+               }
+               uctx->ctx.u.app_ctx.provider_name = provider_name;
+
+               ctx_name = strdup(ctx->u.app_ctx.ctx_name);
+               if (!ctx_name) {
+                       goto error;
+               }
+               uctx->ctx.u.app_ctx.ctx_name = ctx_name;
+               break;
+       }
        default:
                break;
        }
        lttng_ht_node_init_ulong(&uctx->node, (unsigned long) uctx->ctx.ctx);
-
+end:
        return uctx;
-
 error:
+       trace_ust_destroy_context(uctx);
        return NULL;
 }
 
@@ -931,7 +953,7 @@ static void destroy_context_rcu(struct rcu_head *head)
        struct ltt_ust_context *ctx =
                caa_container_of(node, struct ltt_ust_context, node);
 
-       free(ctx);
+       trace_ust_destroy_context(ctx);
 }
 
 /*
@@ -976,6 +998,20 @@ void trace_ust_destroy_event(struct ltt_ust_event *event)
        free(event);
 }
 
+/*
+ * Cleanup ust context structure.
+ */
+void trace_ust_destroy_context(struct ltt_ust_context *ctx)
+{
+       assert(ctx);
+
+       if (ctx->ctx.ctx == LTTNG_UST_CONTEXT_APP_CONTEXT) {
+               free(ctx->ctx.u.app_ctx.provider_name);
+               free(ctx->ctx.u.app_ctx.ctx_name);
+       }
+       free(ctx);
+}
+
 /*
  * URCU intermediate call to complete destroy event.
  */
index 04b3e027c2781eb4c2d979b9d15ebd5998df1299..5a48885d8f0a386d398d2afe4336a364b3d03452 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 2 only,
@@ -40,7 +41,7 @@ struct ltt_ust_ht_key {
 
 /* Context hash table nodes */
 struct ltt_ust_context {
-       struct lttng_ust_context ctx;
+       struct lttng_ust_context_attr ctx;
        struct lttng_ht_node_ulong node;
        struct cds_list_head list;
 };
@@ -209,6 +210,7 @@ void trace_ust_delete_channel(struct lttng_ht *ht,
 void trace_ust_destroy_session(struct ltt_ust_session *session);
 void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
 void trace_ust_destroy_event(struct ltt_ust_event *event);
+void trace_ust_destroy_context(struct ltt_ust_context *ctx);
 
 int trace_ust_track_pid(struct ltt_ust_session *session, int pid);
 int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid);
index 2bd48c7f30cf4e4552d7eb85b0ef6b6b557109f3..8c45a89a5f82410e752bf865bbfe889020551ddf 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 2 only,
@@ -1037,7 +1038,7 @@ error:
  * Alloc new UST app context.
  */
 static
-struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context *uctx)
+struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context_attr *uctx)
 {
        struct ust_app_ctx *ua_ctx;
 
@@ -1050,12 +1051,27 @@ struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context *uctx)
 
        if (uctx) {
                memcpy(&ua_ctx->ctx, uctx, sizeof(ua_ctx->ctx));
+               if (uctx->ctx == LTTNG_UST_CONTEXT_APP_CONTEXT) {
+                       char *provider_name = NULL, *ctx_name = NULL;
+
+                       provider_name = strdup(uctx->u.app_ctx.provider_name);
+                       ctx_name = strdup(uctx->u.app_ctx.ctx_name);
+                       if (!provider_name || !ctx_name) {
+                               free(provider_name);
+                               free(ctx_name);
+                               goto error;
+                       }
+
+                       ua_ctx->ctx.u.app_ctx.provider_name = provider_name;
+                       ua_ctx->ctx.u.app_ctx.ctx_name = ctx_name;
+               }
        }
 
        DBG3("UST app context %d allocated", ua_ctx->ctx.ctx);
-
-error:
        return ua_ctx;
+error:
+       free(ua_ctx);
+       return NULL;
 }
 
 /*
@@ -1696,7 +1712,6 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan,
        struct ltt_ust_event *uevent;
        struct ltt_ust_context *uctx;
        struct ust_app_event *ua_event;
-       struct ust_app_ctx *ua_ctx;
 
        DBG2("UST app shadow copy of channel %s started", ua_chan->name);
 
@@ -1722,7 +1737,8 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan,
        ua_chan->tracing_channel_id = uchan->id;
 
        cds_list_for_each_entry(uctx, &uchan->ctx_list, list) {
-               ua_ctx = alloc_ust_app_ctx(&uctx->ctx);
+               struct ust_app_ctx *ua_ctx = alloc_ust_app_ctx(&uctx->ctx);
+
                if (ua_ctx == NULL) {
                        continue;
                }
@@ -2173,7 +2189,7 @@ error:
 static int ht_match_ust_app_ctx(struct cds_lfht_node *node, const void *_key)
 {
        struct ust_app_ctx *ctx;
-       const struct lttng_ust_context *key;
+       const struct lttng_ust_context_attr *key;
 
        assert(node);
        assert(_key);
@@ -2186,13 +2202,24 @@ static int ht_match_ust_app_ctx(struct cds_lfht_node *node, const void *_key)
                goto no_match;
        }
 
-       /* Check the name in the case of perf thread counters. */
-       if (key->ctx == LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER) {
+       switch(key->ctx) {
+       case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
                if (strncmp(key->u.perf_counter.name,
-                       ctx->ctx.u.perf_counter.name,
-                       sizeof(key->u.perf_counter.name))) {
+                               ctx->ctx.u.perf_counter.name,
+                               sizeof(key->u.perf_counter.name))) {
+                       goto no_match;
+               }
+               break;
+       case LTTNG_UST_CONTEXT_APP_CONTEXT:
+               if (strcmp(key->u.app_ctx.provider_name,
+                               ctx->ctx.u.app_ctx.provider_name) ||
+                               strcmp(key->u.app_ctx.ctx_name,
+                               ctx->ctx.u.app_ctx.ctx_name)) {
                        goto no_match;
                }
+               break;
+       default:
+               break;
        }
 
        /* Match. */
@@ -2210,7 +2237,7 @@ no_match:
  */
 static
 struct ust_app_ctx *find_ust_app_context(struct lttng_ht *ht,
-               struct lttng_ust_context *uctx)
+               struct lttng_ust_context_attr *uctx)
 {
        struct lttng_ht_iter iter;
        struct lttng_ht_node_ulong *node;
@@ -2240,7 +2267,8 @@ end:
  */
 static
 int create_ust_app_channel_context(struct ust_app_session *ua_sess,
-               struct ust_app_channel *ua_chan, struct lttng_ust_context *uctx,
+               struct ust_app_channel *ua_chan,
+               struct lttng_ust_context_attr *uctx,
                struct ust_app *app)
 {
        int ret = 0;
index 3daccba8622bd96a603a895b86d551ff98e2b57e..4398fe2414a68707f5fc9352b1b5eab0cfb0214c 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 2 only,
@@ -101,7 +102,7 @@ struct ust_app_stream_list {
 
 struct ust_app_ctx {
        int handle;
-       struct lttng_ust_context ctx;
+       struct lttng_ust_context_attr ctx;
        struct lttng_ust_object_data *obj;
        struct lttng_ht_node_ulong node;
        struct cds_list_head list;
index e8d182515888cd0273ec8622eb8f47861ec8fc90..11acc52f9206cead181383771830ee2a9f9535c3 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License, version 2 only, as
  * Command value passed in the header.
  */
 enum lttcomm_agent_command {
-       AGENT_CMD_LIST       = 1,
-       AGENT_CMD_ENABLE     = 2,
-       AGENT_CMD_DISABLE    = 3,
-       AGENT_CMD_REG_DONE   = 4,       /* End registration process. */
+       AGENT_CMD_LIST                  = 1,
+       AGENT_CMD_ENABLE                = 2,
+       AGENT_CMD_DISABLE               = 3,
+       AGENT_CMD_REG_DONE              = 4,    /* End registration process. */
+       AGENT_CMD_APP_CTX_ENABLE        = 5,
+       AGENT_CMD_APP_CTX_DISABLE       = 6,
 };
 
 /*
@@ -37,11 +40,11 @@ enum lttcomm_agent_command {
  */
 enum lttcomm_agent_ret_code {
        /* Success, assumed to be the first entry */
-       AGENT_RET_CODE_SUCCESS      = 1,
+       AGENT_RET_CODE_SUCCESS          = 1,
        /* Invalid command */
-       AGENT_RET_CODE_INVALID      = 2,
+       AGENT_RET_CODE_INVALID          = 2,
        /* Unknown logger name */
-       AGENT_RET_CODE_UNKNOWN_NAME = 3,
+       AGENT_RET_CODE_UNKNOWN_NAME     = 3,
        AGENT_RET_CODE_NR,
 };
 
@@ -58,7 +61,7 @@ struct lttcomm_agent_hdr {
  * Enable event command payload. Will be immediately followed by the
  * variable-length string representing the filter expression.
  */
-struct lttcomm_agent_enable {
+struct lttcomm_agent_enable_event {
        uint32_t loglevel_value;
        uint32_t loglevel_type;
        char name[LTTNG_SYMBOL_NAME_LEN];
@@ -68,7 +71,7 @@ struct lttcomm_agent_enable {
 /*
  * Disable event command payload.
  */
-struct lttcomm_agent_disable {
+struct lttcomm_agent_disable_event {
        char name[LTTNG_SYMBOL_NAME_LEN];
 } LTTNG_PACKED;
 
This page took 0.04103 seconds and 4 git commands to generate.