* Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#define _GNU_SOURCE
#include <string.h>
#include <unistd.h>
#include "kernel.h"
#include "ust-ctl.h"
#include "utils.h"
+#include "ust-app.h"
/*
* Return allocated channel attributes.
chan = zmalloc(sizeof(struct lttng_channel));
if (chan == NULL) {
- perror("zmalloc channel init");
+ PERROR("zmalloc channel init");
goto error_alloc;
}
if (snprintf(chan->name, sizeof(chan->name), "%s",
DEFAULT_CHANNEL_NAME) < 0) {
- perror("snprintf default channel name");
+ PERROR("snprintf default channel name");
goto error;
}
goto error;
} else if (kchan->enabled == 1) {
ret = kernel_disable_channel(kchan);
- if (ret < 0) {
- if (ret != EEXIST) {
- ret = LTTCOMM_KERN_CHAN_DISABLE_FAIL;
- }
+ if (ret < 0 && ret != -EEXIST) {
+ ret = LTTCOMM_KERN_CHAN_DISABLE_FAIL;
goto error;
}
}
free(defattr);
return ret;
}
+
+/*
+ * Enable UST channel for session and domain.
+ */
+int channel_ust_enable(struct ltt_ust_session *usess, int domain,
+ struct ltt_ust_channel *uchan)
+{
+ int ret = LTTCOMM_OK;
+
+ /* If already enabled, everything is OK */
+ if (uchan->enabled) {
+ DBG3("Channel %s already enabled. Skipping", uchan->name);
+ goto end;
+ }
+
+ switch (domain) {
+ case LTTNG_DOMAIN_UST:
+ DBG2("Channel %s being enabled in UST global domain", uchan->name);
+ /* Enable channel for global domain */
+ ret = ust_app_enable_channel_glb(usess, uchan);
+ break;
+ case LTTNG_DOMAIN_UST_PID:
+ case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+ case LTTNG_DOMAIN_UST_EXEC_NAME:
+ ret = LTTCOMM_NOT_IMPLEMENTED;
+ goto error;
+ }
+
+ if (ret < 0) {
+ if (ret != -EEXIST) {
+ ret = LTTCOMM_UST_CHAN_ENABLE_FAIL;
+ goto error;
+ } else {
+ ret = LTTCOMM_OK;
+ }
+ }
+
+ uchan->enabled = 1;
+ DBG2("Channel %s enabled successfully", uchan->name);
+
+end:
+error:
+ return ret;
+}
+
+/*
+ * Create UST channel for session and domain.
+ */
+int channel_ust_create(struct ltt_ust_session *usess, int domain,
+ struct lttng_channel *attr)
+{
+ int ret = LTTCOMM_OK;
+ struct cds_lfht *chan_ht;
+ struct ltt_ust_channel *uchan = NULL;
+ struct lttng_channel *defattr = NULL;
+
+ /* Creating channel attributes if needed */
+ if (attr == NULL) {
+ defattr = channel_new_default_attr(domain);
+ if (defattr == NULL) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+ attr = defattr;
+ }
+
+ /* Create UST channel */
+ uchan = trace_ust_create_channel(attr, usess->pathname);
+ if (uchan == NULL) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ switch (domain) {
+ case LTTNG_DOMAIN_UST:
+ DBG2("Channel %s being created in UST global domain", uchan->name);
+ chan_ht = usess->domain_global.channels;
+
+ /* Enable channel for global domain */
+ ret = ust_app_create_channel_glb(usess, uchan);
+ break;
+ case LTTNG_DOMAIN_UST_PID:
+ case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+ case LTTNG_DOMAIN_UST_EXEC_NAME:
+ default:
+ ret = LTTCOMM_NOT_IMPLEMENTED;
+ goto error_free_chan;
+ }
+
+ if (ret < 0 && ret != -EEXIST) {
+ ret = LTTCOMM_UST_CHAN_ENABLE_FAIL;
+ goto error_free_chan;
+ }
+
+ uchan->enabled = 1;
+ hashtable_add_unique(chan_ht, &uchan->node);
+ DBG2("Channel %s created successfully", uchan->name);
+
+ free(defattr);
+ return LTTCOMM_OK;
+
+error_free_chan:
+ trace_ust_destroy_channel(uchan);
+error:
+ free(defattr);
+ return ret;
+}
+
+/*
+ * Disable UST channel for session and domain.
+ */
+int channel_ust_disable(struct ltt_ust_session *usess, int domain,
+ struct ltt_ust_channel *uchan)
+{
+ int ret = LTTCOMM_OK;
+ struct cds_lfht *chan_ht;
+
+ /* Already disabled */
+ if (uchan->enabled == 0) {
+ DBG2("Channel UST %s already disabled", uchan->name);
+ goto end;
+ }
+
+ /* Get the right channel's hashtable */
+ switch (domain) {
+ case LTTNG_DOMAIN_UST:
+ DBG2("Channel %s being disabled in UST global domain", uchan->name);
+ chan_ht = usess->domain_global.channels;
+
+ /* Disable channel for global domain */
+ ret = ust_app_disable_channel_glb(usess, uchan);
+ 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;
+ }
+
+ if (ret < 0 && ret != -EEXIST) {
+ ret = LTTCOMM_UST_DISABLE_FAIL;
+ goto error;
+ }
+
+ uchan->enabled = 0;
+
+ DBG2("Channel %s disabled successfully", uchan->name);
+
+ return LTTCOMM_OK;
+
+end:
+error:
+ return ret;
+}
struct lttng_channel *channel_new_default_attr(int domain);
+int channel_ust_create(struct ltt_ust_session *usess, int domain,
+ struct lttng_channel *attr);
+int channel_ust_enable(struct ltt_ust_session *usess, int domain,
+ struct ltt_ust_channel *uchan);
+int channel_ust_disable(struct ltt_ust_session *usess, int domain,
+ struct ltt_ust_channel *uchan);
+
#endif /* _LTT_CHANNEL_H */
case LTTNG_DOMAIN_UST:
{
struct ltt_ust_channel *uchan;
+ struct cds_lfht *chan_ht;
- /* Get channel in global UST domain HT */
- uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
- channel_name);
+ chan_ht = usess->domain_global.channels;
+
+ uchan = trace_ust_find_channel_by_name(chan_ht, channel_name);
if (uchan == NULL) {
ret = LTTCOMM_UST_CHAN_NOT_FOUND;
goto error;
}
- /* Already disabled */
- if (!uchan->enabled) {
- DBG2("UST channel %s already disabled", channel_name);
- break;
- }
-
- ret = ust_app_disable_channel_glb(usess, uchan);
- if (ret < 0) {
- ret = LTTCOMM_UST_DISABLE_FAIL;
+ ret = channel_ust_disable(usess, domain, uchan);
+ if (ret != LTTCOMM_OK) {
goto error;
}
-
- uchan->enabled = 0;
-
break;
}
case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
return ret;
}
-/*
- * Copy channel from attributes and set it in the application channel list.
- */
-/*
-static int copy_ust_channel_to_app(struct ltt_ust_session *usess,
- struct lttng_channel *attr, struct ust_app *app)
-{
- int ret;
- struct ltt_ust_channel *uchan, *new_chan;
-
- uchan = trace_ust_get_channel_by_key(usess->channels, attr->name);
- if (uchan == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- new_chan = trace_ust_create_channel(attr, usess->path);
- if (new_chan == NULL) {
- PERROR("malloc ltt_ust_channel");
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- ret = channel_ust_copy(new_chan, uchan);
- if (ret < 0) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
-error:
- return ret;
-}
-*/
-
/*
* Command LTTNG_ENABLE_CHANNEL processed by the client thread.
*/
{
int ret;
struct ltt_ust_session *usess = session->ust_session;
+ struct cds_lfht *chan_ht;
DBG("Enabling channel %s for session %s", attr->name, session->name);
{
struct ltt_ust_channel *uchan;
- DBG2("Enabling channel for LTTNG_DOMAIN_UST");
+ chan_ht = usess->domain_global.channels;
- /* Get channel in global UST domain HT */
- uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
- attr->name);
+ uchan = trace_ust_find_channel_by_name(chan_ht, attr->name);
if (uchan == NULL) {
- uchan = trace_ust_create_channel(attr, usess->pathname);
- if (uchan == NULL) {
- ret = LTTCOMM_UST_CHAN_FAIL;
- goto error;
- }
-
- /* Add channel to all registered applications */
- ret = ust_app_create_channel_glb(usess, uchan);
- if (ret != 0) {
- ret = LTTCOMM_UST_CHAN_FAIL;
- goto error;
- }
-
- rcu_read_lock();
- hashtable_add_unique(usess->domain_global.channels, &uchan->node);
- rcu_read_unlock();
-
- DBG2("UST channel %s added to global domain HT", attr->name);
+ ret = channel_ust_create(usess, domain, attr);
} else {
- /* If already enabled, everything is OK */
- if (uchan->enabled) {
- break;
- }
-
- ret = ust_app_enable_channel_glb(usess, uchan);
- if (ret < 0) {
- if (ret != -EEXIST) {
- ret = LTTCOMM_UST_CHAN_ENABLE_FAIL;
- goto error;
- } else {
- ret = LTTCOMM_OK;
- }
- }
+ ret = channel_ust_enable(usess, domain, uchan);
}
-
- uchan->enabled = 1;
-
break;
}
case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
goto error;
}
- ret = LTTCOMM_OK;
-
error:
return ret;
}
snprintf(attr->name, NAME_MAX, "%s", channel_name);
attr->name[NAME_MAX - 1] = '\0';
- /* Use the internal command enable channel */
- ret = cmd_enable_channel(session, domain, attr);
+ ret = channel_ust_create(usess, domain, attr);
if (ret != LTTCOMM_OK) {
free(attr);
goto error;
attr->name[NAME_MAX - 1] = '\0';
/* Use the internal command enable channel */
- ret = cmd_enable_channel(session, domain, attr);
+ ret = channel_ust_create(usess, domain, attr);
if (ret != LTTCOMM_OK) {
free(attr);
goto error;
if (ret < 0) {
goto error;
} else {
- MSG("Channel %s disabled for session %s", channel_name,
+ MSG("%s channel %s disabled for session %s",
+ opt_kernel ? "Kernel" : "UST", channel_name,
session_name);
}
if (ret < 0) {
goto error;
} else {
- MSG("Channel enabled %s for session %s",
- channel_name, session_name);
+ MSG("%s channel %s enabled for session %s",
+ opt_kernel ? "Kernel" : "UST", channel_name,
+ session_name);
}
/* Next event */