+ }
+#endif /* DISABLED */
+
+ /* Process by command type */
+ switch (cmd_ctx->lsm->cmd_type) {
+ case LTTNG_KERNEL_ADD_CONTEXT:
+ {
+ int found = 0, no_event = 0;
+ struct ltt_kernel_channel *chan;
+ struct ltt_kernel_event *event;
+ struct lttng_kernel_context ctx;
+
+ /* Setup lttng message with no payload */
+ ret = setup_lttng_msg(cmd_ctx, 0);
+ if (ret < 0) {
+ goto setup_error;
+ }
+
+ /* Check if event name is given */
+ if (strlen(cmd_ctx->lsm->u.context.event_name) == 0) {
+ no_event = 1;
+ }
+
+ /* Create Kernel context */
+ ctx.ctx = cmd_ctx->lsm->u.context.ctx.ctx;
+ ctx.u.perf_counter.type = cmd_ctx->lsm->u.context.ctx.u.perf_counter.type;
+ ctx.u.perf_counter.config = cmd_ctx->lsm->u.context.ctx.u.perf_counter.config;
+ strncpy(ctx.u.perf_counter.name,
+ cmd_ctx->lsm->u.context.ctx.u.perf_counter.name,
+ sizeof(ctx.u.perf_counter.name));
+
+ if (strlen(cmd_ctx->lsm->u.context.channel_name) == 0) {
+ /* Go over all channels */
+ DBG("Adding context to all channels");
+ cds_list_for_each_entry(chan,
+ &cmd_ctx->session->kernel_session->channel_list.head, list) {
+ if (no_event) {
+ ret = kernel_add_channel_context(chan, &ctx);
+ if (ret < 0) {
+ continue;
+ }
+ } else {
+ event = get_kernel_event_by_name(cmd_ctx->lsm->u.context.event_name, chan);
+ if (event != NULL) {
+ ret = kernel_add_event_context(event, &ctx);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CONTEXT_FAIL;
+ goto error;
+ }
+ found = 1;
+ break;
+ }
+ }
+ }
+ } else {
+ chan = get_kernel_channel_by_name(cmd_ctx->lsm->u.context.channel_name,
+ cmd_ctx->session->kernel_session);
+ if (chan == NULL) {
+ ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
+ goto error;
+ }
+
+ if (no_event) {
+ ret = kernel_add_channel_context(chan, &ctx);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CONTEXT_FAIL;
+ goto error;
+ }
+ } else {
+ event = get_kernel_event_by_name(cmd_ctx->lsm->u.context.event_name, chan);
+ if (event != NULL) {
+ ret = kernel_add_event_context(event, &ctx);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CONTEXT_FAIL;
+ goto error;
+ }
+ }
+ }
+ }
+
+ if (!found && !no_event) {
+ ret = LTTCOMM_NO_EVENT;
+ goto error;
+ }
+
+ ret = LTTCOMM_OK;
+ break;
+ }
+ case LTTNG_KERNEL_DISABLE_CHANNEL:
+ {
+ struct ltt_kernel_channel *chan;
+
+ /* Setup lttng message with no payload */
+ ret = setup_lttng_msg(cmd_ctx, 0);
+ if (ret < 0) {
+ goto setup_error;
+ }
+
+ chan = get_kernel_channel_by_name(cmd_ctx->lsm->u.disable.channel_name,
+ cmd_ctx->session->kernel_session);
+ if (chan == NULL) {
+ ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
+ goto error;
+ } else if (chan->enabled == 1) {
+ ret = kernel_disable_channel(chan);
+ if (ret < 0) {
+ if (ret != EEXIST) {
+ ret = LTTCOMM_KERN_CHAN_DISABLE_FAIL;
+ }
+ goto error;
+ }
+ }
+
+ kernel_wait_quiescent(kernel_tracer_fd);
+ ret = LTTCOMM_OK;
+ break;
+ }
+ case LTTNG_KERNEL_DISABLE_EVENT:
+ {
+ struct ltt_kernel_channel *chan;
+ struct ltt_kernel_event *ev;
+
+ /* Setup lttng message with no payload */
+ ret = setup_lttng_msg(cmd_ctx, 0);
+ if (ret < 0) {
+ goto setup_error;
+ }
+
+ chan = get_kernel_channel_by_name(cmd_ctx->lsm->u.disable.channel_name,
+ cmd_ctx->session->kernel_session);
+ if (chan == NULL) {
+ ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
+ goto error;
+ }
+
+ ev = get_kernel_event_by_name(cmd_ctx->lsm->u.disable.name, chan);
+ if (ev != NULL) {
+ DBG("Disabling kernel event %s for channel %s.",
+ cmd_ctx->lsm->u.disable.name, cmd_ctx->lsm->u.disable.channel_name);
+ ret = kernel_disable_event(ev);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_ENABLE_FAIL;
+ goto error;
+ }
+ }