From 78f0bacd8f9b34beef70d79a4048ba9e1a718db8 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Wed, 23 Nov 2011 15:49:56 -0500 Subject: [PATCH] Add disable-channel support for UST The enable channel command (for UST) was not working for already created channel so this commit fix it by adding an enable function call when the UST channel already exist onto the session. Signed-off-by: David Goulet --- lttng-sessiond/main.c | 121 +++++++++--------- lttng-sessiond/ust-app.c | 199 ++++++++++++++++++++++++++++++ lttng-sessiond/ust-app.h | 4 + lttng/commands/disable_channels.c | 48 +++---- 4 files changed, 288 insertions(+), 84 deletions(-) diff --git a/lttng-sessiond/main.c b/lttng-sessiond/main.c index bca057543..e079afb7d 100644 --- a/lttng-sessiond/main.c +++ b/lttng-sessiond/main.c @@ -2073,22 +2073,52 @@ static int cmd_disable_channel(struct ltt_session *session, int domain, char *channel_name) { int ret; + struct ltt_ust_session *usess; + + usess = session->ust_session; switch (domain) { - case LTTNG_DOMAIN_KERNEL: - ret = channel_kernel_disable(session->kernel_session, - channel_name); - if (ret != LTTCOMM_OK) { - goto error; - } + case LTTNG_DOMAIN_KERNEL: + { + ret = channel_kernel_disable(session->kernel_session, + channel_name); + if (ret != LTTCOMM_OK) { + goto error; + } - kernel_wait_quiescent(kernel_tracer_fd); - break; - case LTTNG_DOMAIN_UST_PID: - break; - default: - ret = LTTCOMM_UNKNOWN_DOMAIN; + kernel_wait_quiescent(kernel_tracer_fd); + break; + } + case LTTNG_DOMAIN_UST: + { + struct ltt_ust_channel *uchan; + + /* Get channel in global UST domain HT */ + uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, + channel_name); + if (uchan == NULL) { + ret = LTTCOMM_UST_CHAN_NOT_FOUND; goto error; + } + + ret = ust_app_disable_channel_all(usess, uchan); + if (ret < 0) { + ret = LTTCOMM_UST_DISABLE_FAIL; + goto error; + } + + uchan->enabled = 0; + + break; + } + case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: + case LTTNG_DOMAIN_UST_EXEC_NAME: + case LTTNG_DOMAIN_UST_PID: + ret = LTTCOMM_NOT_IMPLEMENTED; + goto error; + default: + ret = LTTCOMM_UNKNOWN_DOMAIN; + goto error; } ret = LTTCOMM_OK; @@ -2183,65 +2213,36 @@ static int cmd_enable_channel(struct ltt_session *session, hashtable_add_unique(usess->domain_global.channels, &uchan->node); rcu_read_unlock(); DBG2("UST channel %s added to global domain HT", attr->name); + + /* Add channel to all registered applications */ + ret = ust_app_create_channel_all(usess, uchan); + if (ret != 0) { + ret = LTTCOMM_UST_CHAN_FAIL; + goto error; + } } else { - ret = LTTCOMM_UST_CHAN_EXIST; - goto error; - } + /* If already enabled, everything is OK */ + if (uchan->enabled) { + ret = LTTCOMM_OK; + goto error; + } - /* Add channel to all registered applications */ - ret = ust_app_create_channel_all(usess, uchan); - if (ret != 0) { - goto error; + ret = ust_app_enable_channel_all(usess, uchan); + if (ret < 0) { + ret = LTTCOMM_UST_ENABLE_FAIL; + goto error; + } } uchan->enabled = 1; break; } + case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: + case LTTNG_DOMAIN_UST_EXEC_NAME: case LTTNG_DOMAIN_UST_PID: - { - /* - int sock; - struct ltt_ust_channel *uchan; - struct ltt_ust_session *usess; - struct ust_app *app; - - usess = trace_ust_get_session_by_pid(&session->ust_session_list, - domain->attr.pid); - if (usess == NULL) { - ret = LTTCOMM_UST_CHAN_NOT_FOUND; - goto error; - } - - app = ust_app_get_by_pid(domain->attr.pid); - if (app == NULL) { - ret = LTTCOMM_APP_NOT_FOUND; - goto error; - } - sock = app->sock; - - uchan = trace_ust_get_channel_by_name(attr->name, usess); - if (uchan == NULL) { - ret = channel_ust_create(usess, attr, sock); - } else { - ret = channel_ust_enable(usess, uchan, sock); - } - - if (ret != LTTCOMM_OK) { - goto error; - } - - ret = copy_ust_channel_to_app(usess, attr, app); - if (ret != LTTCOMM_OK) { - goto error; - } - - DBG("UST channel %s created for app sock %d with pid %d", - attr->name, app->sock, domain->attr.pid); - */ ret = LTTCOMM_NOT_IMPLEMENTED; goto error; - } default: ret = LTTCOMM_UNKNOWN_DOMAIN; goto error; diff --git a/lttng-sessiond/ust-app.c b/lttng-sessiond/ust-app.c index cd5829cb6..e5bd47c7d 100644 --- a/lttng-sessiond/ust-app.c +++ b/lttng-sessiond/ust-app.c @@ -244,6 +244,56 @@ error: return NULL; } +/* + * Disable the specified channel on to UST tracer for the UST session. + */ +static int disable_ust_channel(struct ust_app *app, + struct ust_app_session *ua_sess, struct ust_app_channel *ua_chan) +{ + int ret; + + ret = ustctl_disable(app->key.sock, ua_chan->obj); + if (ret < 0) { + ERR("UST app channel %s disable failed for app (pid: %d) " + "and session handle %d with ret %d", + ua_chan->name, app->key.pid, ua_sess->handle, ret); + goto error; + } + + ua_chan->enabled = 0; + + DBG2("UST app channel %s disabled successfully for app (pid: %d)", + ua_chan->name, app->key.pid); + +error: + return ret; +} + +/* + * Enable the specified channel on to UST tracer for the UST session. + */ +static int enable_ust_channel(struct ust_app *app, + struct ust_app_session *ua_sess, struct ust_app_channel *ua_chan) +{ + int ret; + + ret = ustctl_enable(app->key.sock, ua_chan->obj); + if (ret < 0) { + ERR("UST app channel %s enable failed for app (pid: %d) " + "and session handle %d with ret %d", + ua_chan->name, app->key.pid, ua_sess->handle, ret); + goto error; + } + + ua_chan->enabled = 1; + + DBG2("UST app channel %s enabled successfully for app (pid: %d)", + ua_chan->name, app->key.pid); + +error: + return ret; +} + /* * Open metadata onto the UST tracer for a UST session. */ @@ -569,6 +619,9 @@ static void shadow_copy_session(struct ust_app_session *ua_sess, } } +/* + * Lookup sesison wrapper. + */ static void __lookup_session_by_app(struct ltt_ust_session *usess, struct ust_app *app, struct cds_lfht_iter *iter) @@ -651,6 +704,66 @@ error: return NULL; } +/* + * Lookup ust app channel for session and disable it on the tracer side. + */ +static int disable_ust_app_channel(struct ust_app_session *ua_sess, + struct ltt_ust_channel *uchan, struct ust_app *app) +{ + int ret = 0; + struct cds_lfht_iter iter; + struct cds_lfht_node *ua_chan_node; + struct ust_app_channel *ua_chan; + + ua_chan_node = hashtable_lookup(ua_sess->channels, + (void *)uchan->name, strlen(uchan->name), &iter); + if (ua_chan_node == NULL) { + DBG2("Unable to find channel %s in ust session uid %u", + uchan->name, ua_sess->uid); + goto error; + } + + ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); + + ret = disable_ust_channel(app, ua_sess, ua_chan); + if (ret < 0) { + goto error; + } + +error: + return ret; +} + +/* + * Lookup ust app channel for session and enable it on the tracer side. + */ +static int enable_ust_app_channel(struct ust_app_session *ua_sess, + struct ltt_ust_channel *uchan, struct ust_app *app) +{ + int ret = 0; + struct cds_lfht_iter iter; + struct cds_lfht_node *ua_chan_node; + struct ust_app_channel *ua_chan; + + ua_chan_node = hashtable_lookup(ua_sess->channels, + (void *)uchan->name, strlen(uchan->name), &iter); + if (ua_chan_node == NULL) { + DBG2("Unable to find channel %s in ust session uid %u", + uchan->name, ua_sess->uid); + goto error; + } + + ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node); + + ret = enable_ust_channel(app, ua_sess, ua_chan); + if (ret < 0) { + goto error; + } + +error: + return ret; +} + /* * Create UST app channel and create it on the tracer. */ @@ -1028,6 +1141,92 @@ void ust_app_ht_alloc(void) ust_app_sock_key_map = hashtable_new(0); } +/* + * For a specific UST session, disable the channel for all registered apps. + */ +int ust_app_disable_channel_all(struct ltt_ust_session *usess, + struct ltt_ust_channel *uchan) +{ + int ret = 0; + struct cds_lfht_iter iter; + struct ust_app *app; + struct ust_app_session *ua_sess; + + if (usess == NULL || uchan == NULL) { + ERR("Disabling UST global channel with NULL values"); + ret = -1; + goto error; + } + + DBG2("UST app disablling channel %s from global domain for session uid %d", + uchan->name, usess->uid); + + rcu_read_lock(); + + /* For every registered applications */ + cds_lfht_for_each_entry(ust_app_ht, &iter, app, node) { + ua_sess = lookup_session_by_app(usess, app); + if (ua_sess == NULL) { + continue; + } + + /* Create channel onto application */ + ret = disable_ust_app_channel(ua_sess, uchan, app); + if (ret < 0) { + /* XXX: We might want to report this error at some point... */ + continue; + } + } + + rcu_read_unlock(); + +error: + return ret; +} + +/* + * For a specific UST session, enable the channel for all registered apps. + */ +int ust_app_enable_channel_all(struct ltt_ust_session *usess, + struct ltt_ust_channel *uchan) +{ + int ret = 0; + struct cds_lfht_iter iter; + struct ust_app *app; + struct ust_app_session *ua_sess; + + if (usess == NULL || uchan == NULL) { + ERR("Adding UST global channel to NULL values"); + ret = -1; + goto error; + } + + DBG2("UST app enabling channel %s to global domain for session uid %d", + uchan->name, usess->uid); + + rcu_read_lock(); + + /* For every registered applications */ + cds_lfht_for_each_entry(ust_app_ht, &iter, app, node) { + ua_sess = lookup_session_by_app(usess, app); + if (ua_sess == NULL) { + continue; + } + + /* Enable channel onto application */ + ret = enable_ust_app_channel(ua_sess, uchan, app); + if (ret < 0) { + /* XXX: We might want to report this error at some point... */ + continue; + } + } + + rcu_read_unlock(); + +error: + return ret; +} + /* * For a specific UST session, create the channel for all registered apps. */ diff --git a/lttng-sessiond/ust-app.h b/lttng-sessiond/ust-app.h index 657ca4a12..0446363c3 100644 --- a/lttng-sessiond/ust-app.h +++ b/lttng-sessiond/ust-app.h @@ -122,6 +122,10 @@ int ust_app_stop_trace_all(struct ltt_ust_session *usess); int ust_app_destroy_trace(struct ltt_ust_session *usess, struct ust_app *app); int ust_app_destroy_trace_all(struct ltt_ust_session *usess); int ust_app_list_events(struct lttng_event **events); +int ust_app_disable_channel_all(struct ltt_ust_session *usess, + struct ltt_ust_channel *uchan); +int ust_app_enable_channel_all(struct ltt_ust_session *usess, + struct ltt_ust_channel *uchan); void ust_app_global_update(struct ltt_ust_session *usess, int sock); void ust_app_clean_list(void); diff --git a/lttng/commands/disable_channels.c b/lttng/commands/disable_channels.c index a45f3ef09..9ad5eb6c2 100644 --- a/lttng/commands/disable_channels.c +++ b/lttng/commands/disable_channels.c @@ -62,12 +62,12 @@ static void usage(FILE *ofp) { fprintf(ofp, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n"); fprintf(ofp, "\n"); - fprintf(ofp, " -h, --help Show this help\n"); + fprintf(ofp, " -h, --help Show this help\n"); fprintf(ofp, " -s, --session Apply on session name\n"); - fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); - fprintf(ofp, " -u, --userspace Apply for the user-space tracer\n"); - fprintf(ofp, " --all If -u, apply on all traceable apps\n"); - fprintf(ofp, " -p, --pid PID If -u, apply on a specific PID\n"); + fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); + fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n"); + fprintf(ofp, " --all If -u, apply on all traceable apps\n"); + fprintf(ofp, " -p, --pid PID If -u, apply on a specific PID\n"); fprintf(ofp, "\n"); } @@ -82,6 +82,19 @@ static int disable_channels(char *session_name) if (opt_kernel) { dom.type = LTTNG_DOMAIN_KERNEL; + } else if (opt_pid != 0) { + dom.type = LTTNG_DOMAIN_UST_PID; + dom.attr.pid = opt_pid; + DBG("PID %d set to lttng handle", opt_pid); + } else if (opt_userspace && opt_cmd_name == NULL) { + dom.type = LTTNG_DOMAIN_UST; + } else if (opt_userspace && opt_cmd_name != NULL) { + dom.type = LTTNG_DOMAIN_UST_EXEC_NAME; + strncpy(dom.attr.exec_name, opt_cmd_name, NAME_MAX); + } else { + ERR("Please specify a tracer (--kernel or --userspace)"); + ret = CMD_NOT_IMPLEMENTED; + goto error; } handle = lttng_create_handle(session_name, &dom); @@ -93,27 +106,14 @@ static int disable_channels(char *session_name) /* Strip channel list */ channel_name = strtok(opt_channels, ","); while (channel_name != NULL) { - /* Kernel tracer action */ - if (opt_kernel) { - DBG("Disabling kernel channel %s", channel_name); - ret = lttng_disable_channel(handle, channel_name); - if (ret < 0) { - goto error; - } else { - MSG("Kernel channel disabled %s", channel_name); - } - } else if (opt_userspace) { /* User-space tracer action */ - /* - * TODO: Waiting on lttng UST 2.0 - */ - if (opt_pid_all) { - } else if (opt_pid != 0) { - } - ret = CMD_NOT_IMPLEMENTED; + DBG("Disabling channel %s", channel_name); + + ret = lttng_disable_channel(handle, channel_name); + if (ret < 0) { goto error; } else { - ERR("Please specify a tracer (--kernel or --userspace)"); - goto error; + MSG("Channel %s disabled for session %s", channel_name, + session_name); } /* Next channel */ -- 2.34.1