Merge branch 'master' of git://git.lttng.org/lttng-tools
authorDavid Goulet <david.goulet@polymtl.ca>
Tue, 29 Nov 2011 23:18:13 +0000 (18:18 -0500)
committerDavid Goulet <david.goulet@polymtl.ca>
Tue, 29 Nov 2011 23:18:13 +0000 (18:18 -0500)
16 files changed:
include/lttng-sessiond-comm.h
liblttng-sessiond-comm/lttng-sessiond-comm.c
lttng-sessiond/Makefile.am
lttng-sessiond/channel.c
lttng-sessiond/channel.h
lttng-sessiond/context.c
lttng-sessiond/event.c
lttng-sessiond/event.h
lttng-sessiond/kernel-ctl.c [deleted file]
lttng-sessiond/kernel-ctl.h [deleted file]
lttng-sessiond/kernel.c [new file with mode: 0644]
lttng-sessiond/kernel.h [new file with mode: 0644]
lttng-sessiond/main.c
lttng-sessiond/ust-app.c
lttng-sessiond/ust-app.h
lttng-sessiond/ust-ctl.c [deleted file]

index d282f77dea2cb485f964b56740a1822998339aa9..90ff062334c789c30e368b2bb17b48c770f71771 100644 (file)
@@ -132,6 +132,8 @@ enum lttcomm_return_code {
        LTTCOMM_UST_DIR_EXIST,                  /* UST trace directory exist */
        LTTCOMM_UST_NO_SESSION,         /* No UST session found */
        LTTCOMM_UST_LIST_FAIL,                  /* UST listing events failed */
+       LTTCOMM_UST_EVENT_EXIST,        /* UST event exist */
+       LTTCOMM_UST_EVENT_NOT_FOUND,    /* UST event not found */
 
        CONSUMERD_COMMAND_SOCK_READY,           /* when consumerd command socket ready */
        CONSUMERD_SUCCESS_RECV_FD,              /* success on receiving fds */
index 31e43de102b924a789889be0e2d5284c0fee85b8..5fe26f3a09eb69f4a1a53cd0fc6917658fe0d116 100644 (file)
@@ -92,6 +92,8 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_DIR_EXIST) ] = "UST trace directory already exist",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_NO_SESSION) ] = "No UST session found",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_LIST_FAIL) ] = "Listing UST events failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_EVENT_EXIST) ] = "UST event already exist",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_EVENT_NOT_FOUND)] = "UST event not found",
        [ LTTCOMM_ERR_INDEX(CONSUMERD_COMMAND_SOCK_READY) ] = "consumerd command socket ready",
        [ LTTCOMM_ERR_INDEX(CONSUMERD_SUCCESS_RECV_FD) ] = "consumerd success on receiving fds",
        [ LTTCOMM_ERR_INDEX(CONSUMERD_ERROR_RECV_FD) ] = "consumerd error on receiving fds",
index 755bee4fbc524c5dda35b059d1e56c29412e4bfd..7f97d9d2f7e5486c506346320745cefde6453e47 100644 (file)
@@ -16,7 +16,7 @@ lttng_sessiond_SOURCES = utils.c utils.h \
                        hashtable.c hashtable.h \
                        compat/poll.h $(COMPAT) \
                        trace-kernel.c trace-kernel.h \
-                       kernel-ctl.c kernel-ctl.h \
+                       kernel.c kernel.h \
                        ust-ctl.h ust-app.h trace-ust.h \
                        context.c context.h \
                        channel.c channel.h \
index 6b3329edd301f247a0ed1f641ee829f2f0a065c5..146807cb21ccedc491734cc3572099e844f47c95 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "channel.h"
 #include "hashtable.h"
-#include "kernel-ctl.h"
+#include "kernel.h"
 #include "ust-ctl.h"
 #include "utils.h"
 
@@ -75,37 +75,6 @@ error_alloc:
        return NULL;
 }
 
-/*
- * Copy two ltt ust channel. Dst and src must be already allocated.
- */
-int channel_ust_copy(struct ltt_ust_channel *dst,
-               struct ltt_ust_channel *src)
-{
-       //struct ltt_ust_event *uevent, *new_uevent;
-
-       memcpy(dst, src, sizeof(struct ltt_ust_channel));
-       dst->events = hashtable_new_str(0);
-
-       /*
-       cds_list_for_each_entry(uevent, &src->events.head, list) {
-               new_uevent = zmalloc(sizeof(struct ltt_ust_event));
-               if (new_uevent == NULL) {
-                       perror("zmalloc ltt_ust_event");
-                       goto error;
-               }
-
-               memcpy(new_uevent, uevent, sizeof(struct ltt_ust_event));
-               cds_list_add(&new_uevent->list, &dst->events.head);
-               dst->events.count++;
-       }
-       */
-
-       return 0;
-
-//error:
-//     return -1;
-}
-
 /*
  * Disable kernel channel of the kernel session.
  */
@@ -195,115 +164,3 @@ error:
        free(defattr);
        return ret;
 }
-
-/*
- * Create UST channel and enable it on the tracer.
- */
-int channel_ust_create(struct ltt_ust_session *usess,
-               struct lttng_channel *attr)
-{
-       int ret;
-       struct ltt_ust_channel *uchan;
-       //struct lttng_ust_channel_attr uattr;
-       //struct object_data *obj;
-
-       uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
-                       attr->name);
-       if (uchan == NULL) {
-               uchan = trace_ust_create_channel(attr, usess->pathname);
-               if (uchan == NULL) {
-                       ret = LTTCOMM_UST_CHAN_FAIL;
-                       goto error;
-               }
-               rcu_read_lock();
-               hashtable_add_unique(usess->domain_global.channels, &uchan->node);
-               rcu_read_unlock();
-       } else {
-               ret = LTTCOMM_UST_CHAN_EXIST;
-               goto error;
-       }
-
-       /* TODO: NOTIFY ust application to update */
-       /*
-       ret = ustctl_create_channel(sock, usession->handle, &uattr, &obj);
-       if (ret < 0) {
-               ret = LTTCOMM_UST_CHAN_FAIL;
-               goto error;
-       }
-       */
-
-       /*
-       uchan->attr.overwrite = uattr.overwrite;
-       uchan->attr.subbuf_size = uattr.subbuf_size;
-       uchan->attr.num_subbuf = uattr.num_subbuf;
-       uchan->attr.switch_timer_interval = uattr.switch_timer_interval;
-       uchan->attr.read_timer_interval = uattr.read_timer_interval;
-       uchan->attr.output = uattr.output;
-       uchan->handle = obj->handle;
-       uchan->attr.shm_fd = obj->shm_fd;
-       uchan->attr.wait_fd = obj->wait_fd;
-       uchan->attr.memory_map_size = obj->memory_map_size;
-       uchan->obj = obj;
-       */
-
-       /* Add channel to session */
-       //rcu_read_lock();
-       //cds_list_add(&uchan->list, &usession->channels.head);
-       //usession->channels.count++;
-       //rcu_read_unlock();
-
-       //DBG2("Channel %s UST create successfully for sock:%d", uchan->name, sock);
-
-       ret = LTTCOMM_OK;
-
-error:
-       return ret;
-}
-
-/*
- * Enable UST channel on the tracer.
- */
-int channel_ust_enable(struct ltt_ust_session *usession,
-               struct ltt_ust_channel *uchan, int sock)
-{
-       int ret = LTTCOMM_OK;
-#ifdef DISABLE
-       struct object_data obj;
-
-       obj.shm_fd = uchan->attr.shm_fd;
-       obj.wait_fd = uchan->attr.wait_fd;
-       obj.memory_map_size = uchan->attr.memory_map_size;
-       ret = ustctl_enable(sock, &obj);
-       if (ret < 0) {
-               ret = LTTCOMM_UST_CHAN_FAIL;
-               goto end;
-       }
-       ret = LTTCOMM_OK;
-end:
-#endif
-       return ret;
-}
-
-/*
- * Disable UST channel on the tracer.
- */
-int channel_ust_disable(struct ltt_ust_session *usession,
-               struct ltt_ust_channel *uchan, int sock)
-{
-       int ret = LTTCOMM_OK;
-#ifdef DISABLE
-       struct object_data obj;
-
-       obj.shm_fd = uchan->attr.shm_fd;
-       obj.wait_fd = uchan->attr.wait_fd;
-       obj.memory_map_size = uchan->attr.memory_map_size;
-       ret = ustctl_disable(sock, &obj);
-       if (ret < 0) {
-               ret = LTTCOMM_UST_CHAN_FAIL;
-               goto end;
-       }
-       ret = LTTCOMM_OK;
-end:
-#endif
-       return ret;
-}
index 37c1b8c0ac0bfb63b21aca43daca275b42721123..656a1d5266cfa4fceff7ff2a7279eebc5494b795 100644 (file)
@@ -30,15 +30,6 @@ int channel_kernel_enable(struct ltt_kernel_session *ksession,
 int channel_kernel_create(struct ltt_kernel_session *ksession,
                struct lttng_channel *chan, int kernel_pipe);
 
-int channel_ust_create(struct ltt_ust_session *usession,
-               struct lttng_channel *chan);
-int channel_ust_copy(struct ltt_ust_channel *dst,
-               struct ltt_ust_channel *src);
-int channel_ust_disable(struct ltt_ust_session *usession,
-               struct ltt_ust_channel *uchan, int sock);
-int channel_ust_enable(struct ltt_ust_session *usession,
-               struct ltt_ust_channel *uchan, int sock);
-
 struct lttng_channel *channel_new_default_attr(int domain);
 
 #endif /* _LTT_CHANNEL_H */
index d36b3de80fe318b2b72eceb4ba3064cd6489639b..c7c902197df34fa54143bec06dd437f8db5bf017 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "context.h"
 #include "hashtable.h"
-#include "kernel-ctl.h"
+#include "kernel.h"
 
 /*
  * Add kernel context to an event of a specific channel.
index 31f7872b66bc39675b939b734eb2e13810880138..c7331956f91e486a5f2a06caf3f8b20f71d53f26 100644 (file)
 #include "channel.h"
 #include "event.h"
 #include "hashtable.h"
-#include "kernel-ctl.h"
+#include "kernel.h"
 #include "ust-ctl.h"
+#include "ust-app.h"
+#include "trace-kernel.h"
+#include "trace-ust.h"
 
 /*
  * Setup a lttng_event used to enable *all* syscall tracing.
@@ -236,35 +239,66 @@ end:
 /*
  * Enable UST tracepoint event for a channel from a UST session.
  */
-#ifdef DISABLE
-int event_ust_enable_tracepoint(struct ltt_ust_session *usess,
-               struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
+int event_ust_enable_tracepoint(struct ltt_ust_session *usess, int domain,
+               struct ltt_ust_channel *uchan, struct lttng_event *event)
 {
-       int ret;
-       struct lttng_ust_event ltt_uevent;
-       struct object_data *obj_event;
+       int ret, to_create = 0;
+       struct ltt_ust_event *uevent;
+
+       uevent = trace_ust_find_event_by_name(uchan->events, event->name);
+       if (uevent == NULL) {
+               uevent = trace_ust_create_event(event);
+               if (uevent == NULL) {
+                       ret = LTTCOMM_FATAL;
+                       goto error;
+               }
+               to_create = 1;
+       }
 
-       strncpy(ltt_uevent.name, uevent->attr.name, sizeof(ltt_uevent.name));
-       ltt_uevent.name[sizeof(ltt_uevent.name) - 1] = '\0';
-       /* TODO: adjust to other instrumentation types */
-       ltt_uevent.instrumentation = LTTNG_UST_TRACEPOINT;
+       switch (domain) {
+       case LTTNG_DOMAIN_UST:
+       {
+               if (to_create) {
+                       /* Create event on all UST registered apps for session */
+                       ret = ust_app_create_event_glb(usess, uchan, uevent);
+               } else {
+                       /* Enable event on all UST registered apps for session */
+                       ret = ust_app_enable_event_glb(usess, uchan, uevent);
+               }
 
-       ret = ustctl_create_event(app->key.sock, &ltt_uevent,
-                       uchan->obj, &obj_event);
-       if (ret < 0) {
-               DBG("Error ustctl create event %s for app pid: %d, sock: %d ret %d",
-                               uevent->attr.name, app->key.pid, app->key.sock, ret);
-               goto next;
+               if (ret < 0) {
+                       if (ret == -EEXIST) {
+                               ret = LTTCOMM_UST_EVENT_EXIST;
+                       } else {
+                               ret = LTTCOMM_UST_ENABLE_FAIL;
+                       }
+                       goto error;
+               }
+
+               DBG("Event UST %s added to channel %s", uevent->attr.name,
+                               uchan->name);
+               break;
+       }
+       case LTTNG_DOMAIN_UST_EXEC_NAME:
+       case LTTNG_DOMAIN_UST_PID:
+       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+       default:
+               ret = LTTCOMM_NOT_IMPLEMENTED;
+               goto error;
        }
 
-       uevent->obj = obj_event;
-       uevent->handle = obj_event->handle;
        uevent->enabled = 1;
-       ret = LTTCOMM_OK;
-end:
+       /* Add ltt ust event to channel */
+       rcu_read_lock();
+       hashtable_add_unique(uchan->events, &uevent->node);
+       rcu_read_unlock();
+
+       return LTTCOMM_OK;
+
+error:
+       trace_ust_destroy_event(uevent);
        return ret;
 }
-#endif
 
 #ifdef DISABLE
 int event_ust_disable_tracepoint(struct ltt_ust_session *ustsession,
index 2852b3535c19f37ecee88e4a591913cd8124d614..2a7d8c2c3e867e4211d34c3b73976cc3236c09d1 100644 (file)
@@ -40,8 +40,8 @@ int event_kernel_enable_all_syscalls(struct ltt_kernel_session *ksession,
 int event_kernel_enable_all(struct ltt_kernel_session *ksession,
                struct ltt_kernel_channel *kchan, int kernel_tracer_fd);
 
-int event_ust_enable_tracepoint(struct ltt_ust_session *ustsession,
-               struct ltt_ust_channel *ustchan, struct ltt_ust_event *uevent);
+int event_ust_enable_tracepoint(struct ltt_ust_session *usess, int domain,
+               struct ltt_ust_channel *uchan, struct lttng_event *event);
 int event_ust_disable_tracepoint(struct ltt_ust_session *ustsession,
                struct ltt_ust_channel *ustchan, char *event_name);
 
diff --git a/lttng-sessiond/kernel-ctl.c b/lttng-sessiond/kernel-ctl.c
deleted file mode 100644 (file)
index 52d60f0..0000000
+++ /dev/null
@@ -1,607 +0,0 @@
-/*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#define _GNU_SOURCE
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <lttng-kernel-ctl.h>
-#include <lttngerr.h>
-
-#include "kernel-ctl.h"
-
-/*
- * Add context on a kernel channel.
- */
-int kernel_add_channel_context(struct ltt_kernel_channel *chan,
-               struct lttng_kernel_context *ctx)
-{
-       int ret;
-
-       DBG("Adding context to channel %s", chan->channel->name);
-       ret = kernctl_add_context(chan->fd, ctx);
-       if (ret < 0) {
-               if (errno != EEXIST) {
-                       perror("add context ioctl");
-               } else {
-                       /* If EEXIST, we just ignore the error */
-                       ret = 0;
-               }
-               goto error;
-       }
-
-       chan->ctx = zmalloc(sizeof(struct lttng_kernel_context));
-       if (chan->ctx == NULL) {
-               perror("zmalloc event context");
-               goto error;
-       }
-
-       memcpy(chan->ctx, ctx, sizeof(struct lttng_kernel_context));
-
-       return 0;
-
-error:
-       return ret;
-}
-
-/*
- * Add context on a kernel event.
- */
-int kernel_add_event_context(struct ltt_kernel_event *event,
-               struct lttng_kernel_context *ctx)
-{
-       int ret;
-
-       DBG("Adding context to event %s", event->event->name);
-       ret = kernctl_add_context(event->fd, ctx);
-       if (ret < 0) {
-               perror("add context ioctl");
-               goto error;
-       }
-
-       event->ctx = zmalloc(sizeof(struct lttng_kernel_context));
-       if (event->ctx == NULL) {
-               perror("zmalloc event context");
-               goto error;
-       }
-
-       memcpy(event->ctx, ctx, sizeof(struct lttng_kernel_context));
-
-       return 0;
-
-error:
-       return ret;
-}
-
-/*
- * Create a new kernel session, register it to the kernel tracer and add it to
- * the session daemon session.
- */
-int kernel_create_session(struct ltt_session *session, int tracer_fd)
-{
-       int ret;
-       struct ltt_kernel_session *lks;
-
-       /* Allocate data structure */
-       lks = trace_kernel_create_session(session->path);
-       if (lks == NULL) {
-               ret = -1;
-               goto error;
-       }
-
-       /* Kernel tracer session creation */
-       ret = kernctl_create_session(tracer_fd);
-       if (ret < 0) {
-               perror("ioctl kernel create session");
-               goto error;
-       }
-
-       lks->fd = ret;
-       /* Prevent fd duplication after execlp() */
-       ret = fcntl(lks->fd, F_SETFD, FD_CLOEXEC);
-       if (ret < 0) {
-               perror("fcntl session fd");
-       }
-
-       lks->consumer_fds_sent = 0;
-       session->kernel_session = lks;
-
-       DBG("Kernel session created (fd: %d)", lks->fd);
-
-       return 0;
-
-error:
-       return ret;
-}
-
-/*
- * Create a kernel channel, register it to the kernel tracer and add it to the
- * kernel session.
- */
-int kernel_create_channel(struct ltt_kernel_session *session,
-               struct lttng_channel *chan, char *path)
-{
-       int ret;
-       struct ltt_kernel_channel *lkc;
-
-       /* Allocate kernel channel */
-       lkc = trace_kernel_create_channel(chan, path);
-       if (lkc == NULL) {
-               goto error;
-       }
-
-       /* Kernel tracer channel creation */
-       ret = kernctl_create_channel(session->fd, &lkc->channel->attr);
-       if (ret < 0) {
-               perror("ioctl kernel create channel");
-               goto error;
-       }
-
-       /* Setup the channel fd */
-       lkc->fd = ret;
-       /* Prevent fd duplication after execlp() */
-       ret = fcntl(lkc->fd, F_SETFD, FD_CLOEXEC);
-       if (ret < 0) {
-               perror("fcntl session fd");
-       }
-
-       /* Add channel to session */
-       cds_list_add(&lkc->list, &session->channel_list.head);
-       session->channel_count++;
-
-       DBG("Kernel channel %s created (fd: %d and path: %s)",
-                       lkc->channel->name, lkc->fd, lkc->pathname);
-
-       return 0;
-
-error:
-       return -1;
-}
-
-/*
- * Create a kernel event, enable it to the kernel tracer and add it to the
- * channel event list of the kernel session.
- */
-int kernel_create_event(struct lttng_event *ev,
-               struct ltt_kernel_channel *channel)
-{
-       int ret;
-       struct ltt_kernel_event *event;
-
-       event = trace_kernel_create_event(ev);
-       if (event == NULL) {
-               ret = -1;
-               goto error;
-       }
-
-       ret = kernctl_create_event(channel->fd, event->event);
-       if (ret < 0) {
-               if (errno != EEXIST) {
-                       PERROR("create event ioctl");
-               }
-               ret = -errno;
-               goto free_event;
-       }
-
-       /*
-        * LTTNG_KERNEL_SYSCALL event creation will return 0 on success. However
-        * this FD must not be added to the event list.
-        */
-       if (ret == 0 && event->event->instrumentation == LTTNG_KERNEL_SYSCALL) {
-               DBG2("Kernel event syscall creation success");
-               goto end;
-       }
-
-       event->fd = ret;
-       /* Prevent fd duplication after execlp() */
-       ret = fcntl(event->fd, F_SETFD, FD_CLOEXEC);
-       if (ret < 0) {
-               perror("fcntl session fd");
-       }
-
-       /* Add event to event list */
-       cds_list_add(&event->list, &channel->events_list.head);
-       channel->event_count++;
-
-       DBG("Event %s created (fd: %d)", ev->name, event->fd);
-
-end:
-       return 0;
-
-free_event:
-       free(event);
-error:
-       return ret;
-}
-
-/*
- * Disable a kernel channel.
- */
-int kernel_disable_channel(struct ltt_kernel_channel *chan)
-{
-       int ret;
-
-       ret = kernctl_disable(chan->fd);
-       if (ret < 0) {
-               perror("disable chan ioctl");
-               ret = errno;
-               goto error;
-       }
-
-       chan->enabled = 0;
-       DBG("Kernel channel %s disabled (fd: %d)", chan->channel->name, chan->fd);
-
-       return 0;
-
-error:
-       return ret;
-}
-
-/*
- * Enable a kernel channel.
- */
-int kernel_enable_channel(struct ltt_kernel_channel *chan)
-{
-       int ret;
-
-       ret = kernctl_enable(chan->fd);
-       if (ret < 0 && errno != EEXIST) {
-               perror("Enable kernel chan");
-               goto error;
-       }
-
-       chan->enabled = 1;
-       DBG("Kernel channel %s enabled (fd: %d)", chan->channel->name, chan->fd);
-
-       return 0;
-
-error:
-       return ret;
-}
-
-/*
- * Enable a kernel event.
- */
-int kernel_enable_event(struct ltt_kernel_event *event)
-{
-       int ret;
-
-       ret = kernctl_enable(event->fd);
-       if (ret < 0 && errno != EEXIST) {
-               perror("enable kernel event");
-               goto error;
-       }
-
-       event->enabled = 1;
-       DBG("Kernel event %s enabled (fd: %d)", event->event->name, event->fd);
-
-       return 0;
-
-error:
-       return ret;
-}
-
-/*
- * Disable a kernel event.
- */
-int kernel_disable_event(struct ltt_kernel_event *event)
-{
-       int ret;
-
-       ret = kernctl_disable(event->fd);
-       if (ret < 0 && errno != EEXIST) {
-               perror("disable kernel event");
-               goto error;
-       }
-
-       event->enabled = 0;
-       DBG("Kernel event %s disabled (fd: %d)", event->event->name, event->fd);
-
-       return 0;
-
-error:
-       return ret;
-}
-
-/*
- * Create kernel metadata, open from the kernel tracer and add it to the
- * kernel session.
- */
-int kernel_open_metadata(struct ltt_kernel_session *session, char *path)
-{
-       int ret;
-       struct ltt_kernel_metadata *lkm;
-
-       /* Allocate kernel metadata */
-       lkm = trace_kernel_create_metadata(path);
-       if (lkm == NULL) {
-               goto error;
-       }
-
-       /* Kernel tracer metadata creation */
-       ret = kernctl_open_metadata(session->fd, &lkm->conf->attr);
-       if (ret < 0) {
-               goto error;
-       }
-
-       lkm->fd = ret;
-       /* Prevent fd duplication after execlp() */
-       ret = fcntl(lkm->fd, F_SETFD, FD_CLOEXEC);
-       if (ret < 0) {
-               perror("fcntl session fd");
-       }
-
-       session->metadata = lkm;
-
-       DBG("Kernel metadata opened (fd: %d and path: %s)", lkm->fd, lkm->pathname);
-
-       return 0;
-
-error:
-       return -1;
-}
-
-/*
- * Start tracing session.
- */
-int kernel_start_session(struct ltt_kernel_session *session)
-{
-       int ret;
-
-       ret = kernctl_start_session(session->fd);
-       if (ret < 0) {
-               perror("ioctl start session");
-               goto error;
-       }
-
-       DBG("Kernel session started");
-
-       return 0;
-
-error:
-       return ret;
-}
-
-/*
- * Make a kernel wait to make sure in-flight probe have completed.
- */
-void kernel_wait_quiescent(int fd)
-{
-       int ret;
-
-       DBG("Kernel quiescent wait on %d", fd);
-
-       ret = kernctl_wait_quiescent(fd);
-       if (ret < 0) {
-               perror("wait quiescent ioctl");
-               ERR("Kernel quiescent wait failed");
-       }
-}
-
-/*
- * Kernel calibrate
- */
-int kernel_calibrate(int fd, struct lttng_kernel_calibrate *calibrate)
-{
-       int ret;
-
-       ret = kernctl_calibrate(fd, calibrate);
-       if (ret < 0) {
-               perror("calibrate ioctl");
-               return -1;
-       }
-
-       return 0;
-}
-
-
-/*
- *  Force flush buffer of metadata.
- */
-int kernel_metadata_flush_buffer(int fd)
-{
-       int ret;
-
-       ret = kernctl_buffer_flush(fd);
-       if (ret < 0) {
-               ERR("Fail to flush metadata buffers %d (ret: %d", fd, ret);
-       }
-
-       return 0;
-}
-
-/*
- * Force flush buffer for channel.
- */
-int kernel_flush_buffer(struct ltt_kernel_channel *channel)
-{
-       int ret;
-       struct ltt_kernel_stream *stream;
-
-       DBG("Flush buffer for channel %s", channel->channel->name);
-
-       cds_list_for_each_entry(stream, &channel->stream_list.head, list) {
-               DBG("Flushing channel stream %d", stream->fd);
-               ret = kernctl_buffer_flush(stream->fd);
-               if (ret < 0) {
-                       perror("ioctl");
-                       ERR("Fail to flush buffer for stream %d (ret: %d)",
-                                       stream->fd, ret);
-               }
-       }
-
-       return 0;
-}
-
-/*
- * Stop tracing session.
- */
-int kernel_stop_session(struct ltt_kernel_session *session)
-{
-       int ret;
-
-       ret = kernctl_stop_session(session->fd);
-       if (ret < 0) {
-               goto error;
-       }
-
-       DBG("Kernel session stopped");
-
-       return 0;
-
-error:
-       return ret;
-}
-
-/*
- * Open stream of channel, register it to the kernel tracer and add it
- * to the stream list of the channel.
- *
- * Return the number of created stream. Else, a negative value.
- */
-int kernel_open_channel_stream(struct ltt_kernel_channel *channel)
-{
-       int ret;
-       struct ltt_kernel_stream *lks;
-
-       while ((ret = kernctl_create_stream(channel->fd)) > 0) {
-               lks = trace_kernel_create_stream();
-               if (lks == NULL) {
-                       close(ret);
-                       goto error;
-               }
-
-               lks->fd = ret;
-               /* Prevent fd duplication after execlp() */
-               ret = fcntl(lks->fd, F_SETFD, FD_CLOEXEC);
-               if (ret < 0) {
-                       perror("fcntl session fd");
-               }
-
-               ret = asprintf(&lks->pathname, "%s/%s_%d",
-                               channel->pathname, channel->channel->name, channel->stream_count);
-               if (ret < 0) {
-                       perror("asprintf kernel create stream");
-                       goto error;
-               }
-
-               /* Add stream to channe stream list */
-               cds_list_add(&lks->list, &channel->stream_list.head);
-               channel->stream_count++;
-
-               DBG("Kernel stream %d created (fd: %d, state: %d, path: %s)",
-                               channel->stream_count, lks->fd, lks->state, lks->pathname);
-       }
-
-       return channel->stream_count;
-
-error:
-       return -1;
-}
-
-/*
- * Open the metadata stream and set it to the kernel session.
- */
-int kernel_open_metadata_stream(struct ltt_kernel_session *session)
-{
-       int ret;
-
-       ret = kernctl_create_stream(session->metadata->fd);
-       if (ret < 0) {
-               perror("kernel create metadata stream");
-               goto error;
-       }
-
-       DBG("Kernel metadata stream created (fd: %d)", ret);
-       session->metadata_stream_fd = ret;
-       /* Prevent fd duplication after execlp() */
-       ret = fcntl(session->metadata_stream_fd, F_SETFD, FD_CLOEXEC);
-       if (ret < 0) {
-               perror("fcntl session fd");
-       }
-
-       return 0;
-
-error:
-       return -1;
-}
-
-/*
- * Get the event list from the kernel tracer and return the number of elements.
- */
-ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
-{
-       int fd, pos;
-       char *event;
-       size_t nbmem, count = 0;
-       ssize_t size;
-       FILE *fp;
-       struct lttng_event *elist;
-
-       fd = kernctl_tracepoint_list(tracer_fd);
-       if (fd < 0) {
-               perror("kernel tracepoint list");
-               goto error;
-       }
-
-       fp = fdopen(fd, "r");
-       if (fp == NULL) {
-               perror("kernel tracepoint list fdopen");
-               goto error_fp;
-       }
-
-       /*
-        * Init memory size counter
-        * See kernel-ctl.h for explanation of this value
-        */
-       nbmem = KERNEL_EVENT_LIST_SIZE;
-       elist = zmalloc(sizeof(struct lttng_event) * nbmem);
-
-       while ((size = fscanf(fp, "event { name = %m[^;]; };%n\n", &event, &pos)) == 1) {
-               if (count > nbmem) {
-                       DBG("Reallocating event list from %zu to %zu bytes", nbmem,
-                                       nbmem + KERNEL_EVENT_LIST_SIZE);
-                       /* Adding the default size again */
-                       nbmem += KERNEL_EVENT_LIST_SIZE;
-                       elist = realloc(elist, nbmem);
-                       if (elist == NULL) {
-                               perror("realloc list events");
-                               count = -ENOMEM;
-                               goto end;
-                       }
-               }
-               strncpy(elist[count].name, event, LTTNG_SYMBOL_NAME_LEN);
-               elist[count].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
-               count++;
-       }
-
-       *events = elist;
-       DBG("Kernel list events done (%zu events)", count);
-end:
-       fclose(fp);     /* closes both fp and fd */
-       return count;
-
-error_fp:
-       close(fd);
-error:
-       return -1;
-}
diff --git a/lttng-sessiond/kernel-ctl.h b/lttng-sessiond/kernel-ctl.h
deleted file mode 100644 (file)
index 2fbaca9..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#ifndef _LTT_KERNEL_CTL_H
-#define _LTT_KERNEL_CTL_H
-
-#include "session.h"
-#include "trace-kernel.h"
-
-/*
- * Default size for the event list when kernel_list_events is called. This size
- * value is based on the initial LTTng 2.0 version set of tracepoints.
- *
- * This is NOT an upper bound because if the real event list size is bigger,
- * dynamic reallocation is performed.
- */
-#define KERNEL_EVENT_LIST_SIZE 80
-
-int kernel_add_channel_context(struct ltt_kernel_channel *chan,
-               struct lttng_kernel_context *ctx);
-int kernel_add_event_context(struct ltt_kernel_event *event,
-               struct lttng_kernel_context *ctx);
-int kernel_create_session(struct ltt_session *session, int tracer_fd);
-int kernel_create_channel(struct ltt_kernel_session *session,
-               struct lttng_channel *chan, char *path);
-int kernel_create_event(struct lttng_event *ev, struct ltt_kernel_channel *channel);
-int kernel_disable_channel(struct ltt_kernel_channel *chan);
-int kernel_disable_event(struct ltt_kernel_event *event);
-int kernel_enable_event(struct ltt_kernel_event *event);
-int kernel_enable_channel(struct ltt_kernel_channel *chan);
-int kernel_open_metadata(struct ltt_kernel_session *session, char *path);
-int kernel_open_metadata_stream(struct ltt_kernel_session *session);
-int kernel_open_channel_stream(struct ltt_kernel_channel *channel);
-int kernel_flush_buffer(struct ltt_kernel_channel *channel);
-int kernel_metadata_flush_buffer(int fd);
-int kernel_start_session(struct ltt_kernel_session *session);
-int kernel_stop_session(struct ltt_kernel_session *session);
-ssize_t kernel_list_events(int tracer_fd, struct lttng_event **event_list);
-void kernel_wait_quiescent(int fd);
-int kernel_calibrate(int fd, struct lttng_kernel_calibrate *calibrate);
-
-#endif /* _LTT_KERNEL_CTL_H */
diff --git a/lttng-sessiond/kernel.c b/lttng-sessiond/kernel.c
new file mode 100644 (file)
index 0000000..c734e88
--- /dev/null
@@ -0,0 +1,607 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; only version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <lttng-kernel-ctl.h>
+#include <lttngerr.h>
+
+#include "kernel.h"
+
+/*
+ * Add context on a kernel channel.
+ */
+int kernel_add_channel_context(struct ltt_kernel_channel *chan,
+               struct lttng_kernel_context *ctx)
+{
+       int ret;
+
+       DBG("Adding context to channel %s", chan->channel->name);
+       ret = kernctl_add_context(chan->fd, ctx);
+       if (ret < 0) {
+               if (errno != EEXIST) {
+                       perror("add context ioctl");
+               } else {
+                       /* If EEXIST, we just ignore the error */
+                       ret = 0;
+               }
+               goto error;
+       }
+
+       chan->ctx = zmalloc(sizeof(struct lttng_kernel_context));
+       if (chan->ctx == NULL) {
+               perror("zmalloc event context");
+               goto error;
+       }
+
+       memcpy(chan->ctx, ctx, sizeof(struct lttng_kernel_context));
+
+       return 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Add context on a kernel event.
+ */
+int kernel_add_event_context(struct ltt_kernel_event *event,
+               struct lttng_kernel_context *ctx)
+{
+       int ret;
+
+       DBG("Adding context to event %s", event->event->name);
+       ret = kernctl_add_context(event->fd, ctx);
+       if (ret < 0) {
+               perror("add context ioctl");
+               goto error;
+       }
+
+       event->ctx = zmalloc(sizeof(struct lttng_kernel_context));
+       if (event->ctx == NULL) {
+               perror("zmalloc event context");
+               goto error;
+       }
+
+       memcpy(event->ctx, ctx, sizeof(struct lttng_kernel_context));
+
+       return 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Create a new kernel session, register it to the kernel tracer and add it to
+ * the session daemon session.
+ */
+int kernel_create_session(struct ltt_session *session, int tracer_fd)
+{
+       int ret;
+       struct ltt_kernel_session *lks;
+
+       /* Allocate data structure */
+       lks = trace_kernel_create_session(session->path);
+       if (lks == NULL) {
+               ret = -1;
+               goto error;
+       }
+
+       /* Kernel tracer session creation */
+       ret = kernctl_create_session(tracer_fd);
+       if (ret < 0) {
+               perror("ioctl kernel create session");
+               goto error;
+       }
+
+       lks->fd = ret;
+       /* Prevent fd duplication after execlp() */
+       ret = fcntl(lks->fd, F_SETFD, FD_CLOEXEC);
+       if (ret < 0) {
+               perror("fcntl session fd");
+       }
+
+       lks->consumer_fds_sent = 0;
+       session->kernel_session = lks;
+
+       DBG("Kernel session created (fd: %d)", lks->fd);
+
+       return 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Create a kernel channel, register it to the kernel tracer and add it to the
+ * kernel session.
+ */
+int kernel_create_channel(struct ltt_kernel_session *session,
+               struct lttng_channel *chan, char *path)
+{
+       int ret;
+       struct ltt_kernel_channel *lkc;
+
+       /* Allocate kernel channel */
+       lkc = trace_kernel_create_channel(chan, path);
+       if (lkc == NULL) {
+               goto error;
+       }
+
+       /* Kernel tracer channel creation */
+       ret = kernctl_create_channel(session->fd, &lkc->channel->attr);
+       if (ret < 0) {
+               perror("ioctl kernel create channel");
+               goto error;
+       }
+
+       /* Setup the channel fd */
+       lkc->fd = ret;
+       /* Prevent fd duplication after execlp() */
+       ret = fcntl(lkc->fd, F_SETFD, FD_CLOEXEC);
+       if (ret < 0) {
+               perror("fcntl session fd");
+       }
+
+       /* Add channel to session */
+       cds_list_add(&lkc->list, &session->channel_list.head);
+       session->channel_count++;
+
+       DBG("Kernel channel %s created (fd: %d and path: %s)",
+                       lkc->channel->name, lkc->fd, lkc->pathname);
+
+       return 0;
+
+error:
+       return -1;
+}
+
+/*
+ * Create a kernel event, enable it to the kernel tracer and add it to the
+ * channel event list of the kernel session.
+ */
+int kernel_create_event(struct lttng_event *ev,
+               struct ltt_kernel_channel *channel)
+{
+       int ret;
+       struct ltt_kernel_event *event;
+
+       event = trace_kernel_create_event(ev);
+       if (event == NULL) {
+               ret = -1;
+               goto error;
+       }
+
+       ret = kernctl_create_event(channel->fd, event->event);
+       if (ret < 0) {
+               if (errno != EEXIST) {
+                       PERROR("create event ioctl");
+               }
+               ret = -errno;
+               goto free_event;
+       }
+
+       /*
+        * LTTNG_KERNEL_SYSCALL event creation will return 0 on success. However
+        * this FD must not be added to the event list.
+        */
+       if (ret == 0 && event->event->instrumentation == LTTNG_KERNEL_SYSCALL) {
+               DBG2("Kernel event syscall creation success");
+               goto end;
+       }
+
+       event->fd = ret;
+       /* Prevent fd duplication after execlp() */
+       ret = fcntl(event->fd, F_SETFD, FD_CLOEXEC);
+       if (ret < 0) {
+               perror("fcntl session fd");
+       }
+
+       /* Add event to event list */
+       cds_list_add(&event->list, &channel->events_list.head);
+       channel->event_count++;
+
+       DBG("Event %s created (fd: %d)", ev->name, event->fd);
+
+end:
+       return 0;
+
+free_event:
+       free(event);
+error:
+       return ret;
+}
+
+/*
+ * Disable a kernel channel.
+ */
+int kernel_disable_channel(struct ltt_kernel_channel *chan)
+{
+       int ret;
+
+       ret = kernctl_disable(chan->fd);
+       if (ret < 0) {
+               perror("disable chan ioctl");
+               ret = errno;
+               goto error;
+       }
+
+       chan->enabled = 0;
+       DBG("Kernel channel %s disabled (fd: %d)", chan->channel->name, chan->fd);
+
+       return 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Enable a kernel channel.
+ */
+int kernel_enable_channel(struct ltt_kernel_channel *chan)
+{
+       int ret;
+
+       ret = kernctl_enable(chan->fd);
+       if (ret < 0 && errno != EEXIST) {
+               perror("Enable kernel chan");
+               goto error;
+       }
+
+       chan->enabled = 1;
+       DBG("Kernel channel %s enabled (fd: %d)", chan->channel->name, chan->fd);
+
+       return 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Enable a kernel event.
+ */
+int kernel_enable_event(struct ltt_kernel_event *event)
+{
+       int ret;
+
+       ret = kernctl_enable(event->fd);
+       if (ret < 0 && errno != EEXIST) {
+               perror("enable kernel event");
+               goto error;
+       }
+
+       event->enabled = 1;
+       DBG("Kernel event %s enabled (fd: %d)", event->event->name, event->fd);
+
+       return 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Disable a kernel event.
+ */
+int kernel_disable_event(struct ltt_kernel_event *event)
+{
+       int ret;
+
+       ret = kernctl_disable(event->fd);
+       if (ret < 0 && errno != EEXIST) {
+               perror("disable kernel event");
+               goto error;
+       }
+
+       event->enabled = 0;
+       DBG("Kernel event %s disabled (fd: %d)", event->event->name, event->fd);
+
+       return 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Create kernel metadata, open from the kernel tracer and add it to the
+ * kernel session.
+ */
+int kernel_open_metadata(struct ltt_kernel_session *session, char *path)
+{
+       int ret;
+       struct ltt_kernel_metadata *lkm;
+
+       /* Allocate kernel metadata */
+       lkm = trace_kernel_create_metadata(path);
+       if (lkm == NULL) {
+               goto error;
+       }
+
+       /* Kernel tracer metadata creation */
+       ret = kernctl_open_metadata(session->fd, &lkm->conf->attr);
+       if (ret < 0) {
+               goto error;
+       }
+
+       lkm->fd = ret;
+       /* Prevent fd duplication after execlp() */
+       ret = fcntl(lkm->fd, F_SETFD, FD_CLOEXEC);
+       if (ret < 0) {
+               perror("fcntl session fd");
+       }
+
+       session->metadata = lkm;
+
+       DBG("Kernel metadata opened (fd: %d and path: %s)", lkm->fd, lkm->pathname);
+
+       return 0;
+
+error:
+       return -1;
+}
+
+/*
+ * Start tracing session.
+ */
+int kernel_start_session(struct ltt_kernel_session *session)
+{
+       int ret;
+
+       ret = kernctl_start_session(session->fd);
+       if (ret < 0) {
+               perror("ioctl start session");
+               goto error;
+       }
+
+       DBG("Kernel session started");
+
+       return 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Make a kernel wait to make sure in-flight probe have completed.
+ */
+void kernel_wait_quiescent(int fd)
+{
+       int ret;
+
+       DBG("Kernel quiescent wait on %d", fd);
+
+       ret = kernctl_wait_quiescent(fd);
+       if (ret < 0) {
+               perror("wait quiescent ioctl");
+               ERR("Kernel quiescent wait failed");
+       }
+}
+
+/*
+ * Kernel calibrate
+ */
+int kernel_calibrate(int fd, struct lttng_kernel_calibrate *calibrate)
+{
+       int ret;
+
+       ret = kernctl_calibrate(fd, calibrate);
+       if (ret < 0) {
+               perror("calibrate ioctl");
+               return -1;
+       }
+
+       return 0;
+}
+
+
+/*
+ *  Force flush buffer of metadata.
+ */
+int kernel_metadata_flush_buffer(int fd)
+{
+       int ret;
+
+       ret = kernctl_buffer_flush(fd);
+       if (ret < 0) {
+               ERR("Fail to flush metadata buffers %d (ret: %d", fd, ret);
+       }
+
+       return 0;
+}
+
+/*
+ * Force flush buffer for channel.
+ */
+int kernel_flush_buffer(struct ltt_kernel_channel *channel)
+{
+       int ret;
+       struct ltt_kernel_stream *stream;
+
+       DBG("Flush buffer for channel %s", channel->channel->name);
+
+       cds_list_for_each_entry(stream, &channel->stream_list.head, list) {
+               DBG("Flushing channel stream %d", stream->fd);
+               ret = kernctl_buffer_flush(stream->fd);
+               if (ret < 0) {
+                       perror("ioctl");
+                       ERR("Fail to flush buffer for stream %d (ret: %d)",
+                                       stream->fd, ret);
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * Stop tracing session.
+ */
+int kernel_stop_session(struct ltt_kernel_session *session)
+{
+       int ret;
+
+       ret = kernctl_stop_session(session->fd);
+       if (ret < 0) {
+               goto error;
+       }
+
+       DBG("Kernel session stopped");
+
+       return 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Open stream of channel, register it to the kernel tracer and add it
+ * to the stream list of the channel.
+ *
+ * Return the number of created stream. Else, a negative value.
+ */
+int kernel_open_channel_stream(struct ltt_kernel_channel *channel)
+{
+       int ret;
+       struct ltt_kernel_stream *lks;
+
+       while ((ret = kernctl_create_stream(channel->fd)) > 0) {
+               lks = trace_kernel_create_stream();
+               if (lks == NULL) {
+                       close(ret);
+                       goto error;
+               }
+
+               lks->fd = ret;
+               /* Prevent fd duplication after execlp() */
+               ret = fcntl(lks->fd, F_SETFD, FD_CLOEXEC);
+               if (ret < 0) {
+                       perror("fcntl session fd");
+               }
+
+               ret = asprintf(&lks->pathname, "%s/%s_%d",
+                               channel->pathname, channel->channel->name, channel->stream_count);
+               if (ret < 0) {
+                       perror("asprintf kernel create stream");
+                       goto error;
+               }
+
+               /* Add stream to channe stream list */
+               cds_list_add(&lks->list, &channel->stream_list.head);
+               channel->stream_count++;
+
+               DBG("Kernel stream %d created (fd: %d, state: %d, path: %s)",
+                               channel->stream_count, lks->fd, lks->state, lks->pathname);
+       }
+
+       return channel->stream_count;
+
+error:
+       return -1;
+}
+
+/*
+ * Open the metadata stream and set it to the kernel session.
+ */
+int kernel_open_metadata_stream(struct ltt_kernel_session *session)
+{
+       int ret;
+
+       ret = kernctl_create_stream(session->metadata->fd);
+       if (ret < 0) {
+               perror("kernel create metadata stream");
+               goto error;
+       }
+
+       DBG("Kernel metadata stream created (fd: %d)", ret);
+       session->metadata_stream_fd = ret;
+       /* Prevent fd duplication after execlp() */
+       ret = fcntl(session->metadata_stream_fd, F_SETFD, FD_CLOEXEC);
+       if (ret < 0) {
+               perror("fcntl session fd");
+       }
+
+       return 0;
+
+error:
+       return -1;
+}
+
+/*
+ * Get the event list from the kernel tracer and return the number of elements.
+ */
+ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
+{
+       int fd, pos;
+       char *event;
+       size_t nbmem, count = 0;
+       ssize_t size;
+       FILE *fp;
+       struct lttng_event *elist;
+
+       fd = kernctl_tracepoint_list(tracer_fd);
+       if (fd < 0) {
+               perror("kernel tracepoint list");
+               goto error;
+       }
+
+       fp = fdopen(fd, "r");
+       if (fp == NULL) {
+               perror("kernel tracepoint list fdopen");
+               goto error_fp;
+       }
+
+       /*
+        * Init memory size counter
+        * See kernel-ctl.h for explanation of this value
+        */
+       nbmem = KERNEL_EVENT_LIST_SIZE;
+       elist = zmalloc(sizeof(struct lttng_event) * nbmem);
+
+       while ((size = fscanf(fp, "event { name = %m[^;]; };%n\n", &event, &pos)) == 1) {
+               if (count > nbmem) {
+                       DBG("Reallocating event list from %zu to %zu bytes", nbmem,
+                                       nbmem + KERNEL_EVENT_LIST_SIZE);
+                       /* Adding the default size again */
+                       nbmem += KERNEL_EVENT_LIST_SIZE;
+                       elist = realloc(elist, nbmem);
+                       if (elist == NULL) {
+                               perror("realloc list events");
+                               count = -ENOMEM;
+                               goto end;
+                       }
+               }
+               strncpy(elist[count].name, event, LTTNG_SYMBOL_NAME_LEN);
+               elist[count].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+               count++;
+       }
+
+       *events = elist;
+       DBG("Kernel list events done (%zu events)", count);
+end:
+       fclose(fp);     /* closes both fp and fd */
+       return count;
+
+error_fp:
+       close(fd);
+error:
+       return -1;
+}
diff --git a/lttng-sessiond/kernel.h b/lttng-sessiond/kernel.h
new file mode 100644 (file)
index 0000000..2fbaca9
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; only version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef _LTT_KERNEL_CTL_H
+#define _LTT_KERNEL_CTL_H
+
+#include "session.h"
+#include "trace-kernel.h"
+
+/*
+ * Default size for the event list when kernel_list_events is called. This size
+ * value is based on the initial LTTng 2.0 version set of tracepoints.
+ *
+ * This is NOT an upper bound because if the real event list size is bigger,
+ * dynamic reallocation is performed.
+ */
+#define KERNEL_EVENT_LIST_SIZE 80
+
+int kernel_add_channel_context(struct ltt_kernel_channel *chan,
+               struct lttng_kernel_context *ctx);
+int kernel_add_event_context(struct ltt_kernel_event *event,
+               struct lttng_kernel_context *ctx);
+int kernel_create_session(struct ltt_session *session, int tracer_fd);
+int kernel_create_channel(struct ltt_kernel_session *session,
+               struct lttng_channel *chan, char *path);
+int kernel_create_event(struct lttng_event *ev, struct ltt_kernel_channel *channel);
+int kernel_disable_channel(struct ltt_kernel_channel *chan);
+int kernel_disable_event(struct ltt_kernel_event *event);
+int kernel_enable_event(struct ltt_kernel_event *event);
+int kernel_enable_channel(struct ltt_kernel_channel *chan);
+int kernel_open_metadata(struct ltt_kernel_session *session, char *path);
+int kernel_open_metadata_stream(struct ltt_kernel_session *session);
+int kernel_open_channel_stream(struct ltt_kernel_channel *channel);
+int kernel_flush_buffer(struct ltt_kernel_channel *channel);
+int kernel_metadata_flush_buffer(int fd);
+int kernel_start_session(struct ltt_kernel_session *session);
+int kernel_stop_session(struct ltt_kernel_session *session);
+ssize_t kernel_list_events(int tracer_fd, struct lttng_event **event_list);
+void kernel_wait_quiescent(int fd);
+int kernel_calibrate(int fd, struct lttng_kernel_calibrate *calibrate);
+
+#endif /* _LTT_KERNEL_CTL_H */
index f7505849bdeb9bcb6681a46e77214292efabce97..ff096e1b90db47940a5c11092e785fd7b67724f9 100644 (file)
@@ -50,7 +50,7 @@
 #include "event.h"
 #include "futex.h"
 #include "hashtable.h"
-#include "kernel-ctl.h"
+#include "kernel.h"
 #include "lttng-sessiond.h"
 #include "shm.h"
 #include "ust-app.h"
@@ -2191,7 +2191,13 @@ static int cmd_disable_channel(struct ltt_session *session,
                        goto error;
                }
 
-               ret = ust_app_disable_channel_all(usess, uchan);
+               /* 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;
                        goto error;
@@ -2299,28 +2305,32 @@ static int cmd_enable_channel(struct ltt_session *session,
                                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);
-
                        /* Add channel to all registered applications */
-                       ret = ust_app_create_channel_all(usess, uchan);
+                       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);
                } else {
                        /* If already enabled, everything is OK */
                        if (uchan->enabled) {
-                               ret = LTTCOMM_OK;
-                               goto error;
+                               break;
                        }
 
-                       ret = ust_app_enable_channel_all(usess, uchan);
+                       ret = ust_app_enable_channel_glb(usess, uchan);
                        if (ret < 0) {
-                               ret = LTTCOMM_UST_ENABLE_FAIL;
-                               goto error;
+                               if (ret != -EEXIST) {
+                                       ret = LTTCOMM_UST_CHAN_ENABLE_FAIL;
+                                       goto error;
+                               } else {
+                                       ret = LTTCOMM_OK;
+                               }
                        }
                }
 
@@ -2378,6 +2388,7 @@ static int cmd_disable_event(struct ltt_session *session, int domain,
        {
                struct ltt_ust_session *usess;
                struct ltt_ust_channel *uchan;
+               struct ltt_ust_event *uevent;
 
                usess = session->ust_session;
 
@@ -2388,12 +2399,20 @@ static int cmd_disable_event(struct ltt_session *session, int domain,
                        goto error;
                }
 
-               ret = ust_app_disable_event(usess, uchan, event_name);
+               uevent = trace_ust_find_event_by_name(uchan->events, event_name);
+               if (uevent == NULL) {
+                       ret = LTTCOMM_UST_EVENT_NOT_FOUND;
+                       goto error;
+               }
+
+               ret = ust_app_disable_event_glb(usess, uchan, uevent);
                if (ret < 0) {
                        ret = LTTCOMM_UST_DISABLE_FAIL;
                        goto error;
                }
 
+               uevent->enabled = 0;
+
                DBG2("Disable UST event %s in channel %s completed", event_name,
                                channel_name);
 
@@ -2457,7 +2476,7 @@ static int cmd_disable_event_all(struct ltt_session *session, int domain,
                        goto error;
                }
 
-               ret = ust_app_disable_event_all(usess, uchan);
+               ret = ust_app_disable_all_event_glb(usess, uchan);
                if (ret < 0) {
                        ret = LTTCOMM_UST_DISABLE_FAIL;
                        goto error;
@@ -2580,10 +2599,10 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
        }
        case LTTNG_DOMAIN_UST:
        {
-               struct ltt_ust_channel *uchan;
-               struct ltt_ust_event *uevent;
                struct lttng_channel *attr;
+               struct ltt_ust_channel *uchan;
 
+               /* Get channel from global UST domain */
                uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
                                channel_name);
                if (uchan == NULL) {
@@ -2594,14 +2613,14 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
                                goto error;
                        }
                        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);
-                       if (ret < 0) {
+                       if (ret != LTTCOMM_OK) {
                                free(attr);
                                goto error;
                        }
-
                        free(attr);
 
                        /* Get the newly created channel reference back */
@@ -2614,31 +2633,12 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
                        }
                }
 
-               uevent = trace_ust_find_event_by_name(uchan->events, event->name);
-               if (uevent == NULL) {
-                       uevent = trace_ust_create_event(event);
-                       if (uevent == NULL) {
-                               ret = LTTCOMM_FATAL;
-                               goto error;
-                       }
-
-               }
+               /* At this point, the session and channel exist on the tracer */
 
-               ret = ust_app_create_event_all(usess, uchan, uevent);
-               if (ret < 0) {
-                       ret = LTTCOMM_UST_ENABLE_FAIL;
+               ret = event_ust_enable_tracepoint(usess, domain, uchan, event);
+               if (ret != LTTCOMM_OK) {
                        goto error;
                }
-
-               /* Add ltt ust event to channel */
-               rcu_read_lock();
-               hashtable_add_unique(uchan->events, &uevent->node);
-               rcu_read_unlock();
-
-               uevent->enabled = 1;
-
-               DBG3("UST ltt event %s added to channel %s", uevent->attr.name,
-                               uchan->name);
                break;
        }
        case LTTNG_DOMAIN_UST_EXEC_NAME:
index 51ae71c4f1f0c94319d7b0edad7bf99881d46386..b6dd76ae9c0fec891f8ce2f3c3f5af6b6bb5b8d9 100644 (file)
@@ -47,8 +47,10 @@ static void delete_ust_app_event(int sock, struct ust_app_event *ua_event)
        //      delete_ust_app_ctx(sock, ltctx);
        //}
 
-       ustctl_release_object(sock, ua_event->obj);
-       free(ua_event->obj);
+       if (ua_event->obj != NULL) {
+               ustctl_release_object(sock, ua_event->obj);
+               free(ua_event->obj);
+       }
        free(ua_event);
 }
 
@@ -96,8 +98,11 @@ static void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan)
                ERR("UST app destroy session hashtable failed");
                goto error;
        }
-       ustctl_release_object(sock, ua_chan->obj);
-       free(ua_chan->obj);
+
+       if (ua_chan->obj != NULL) {
+               ustctl_release_object(sock, ua_chan->obj);
+               free(ua_chan->obj);
+       }
        free(ua_chan);
 
 error:
@@ -283,8 +288,6 @@ static int disable_ust_channel(struct ust_app *app,
                goto error;
        }
 
-       ua_chan->enabled = 0;
-
        DBG2("UST app channel %s disabled successfully for app (pid: %d)",
                        ua_chan->name, app->key.pid);
 
@@ -317,6 +320,29 @@ error:
        return ret;
 }
 
+/*
+ * Enable the specified event on to UST tracer for the UST session.
+ */
+static int enable_ust_event(struct ust_app *app,
+               struct ust_app_session *ua_sess, struct ust_app_event *ua_event)
+{
+       int ret;
+
+       ret = ustctl_enable(app->key.sock, ua_event->obj);
+       if (ret < 0) {
+               ERR("UST app event %s enable failed for app (pid: %d) "
+                               "and session handle %d with ret %d",
+                               ua_event->attr.name, app->key.pid, ua_sess->handle, ret);
+               goto error;
+       }
+
+       DBG2("UST app event %s enabled successfully for app (pid: %d)",
+                       ua_event->attr.name, app->key.pid);
+
+error:
+       return ret;
+}
+
 /*
  * Open metadata onto the UST tracer for a UST session.
  */
@@ -394,6 +420,14 @@ static int create_ust_channel(struct ust_app *app,
        DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
                        ua_chan->name, app->key.pid, app->key.sock);
 
+       /* If channel is not enabled, disable it on the tracer */
+       if (!ua_chan->enabled) {
+               ret = disable_ust_channel(app, ua_sess, ua_chan);
+               if (ret < 0) {
+                       goto error;
+               }
+       }
+
 error:
        return ret;
 }
@@ -401,9 +435,9 @@ error:
 /*
  * Create the specified event onto the UST tracer for a UST session.
  */
-static int create_ust_event(struct ust_app *app,
-               struct ust_app_session *ua_sess, struct ust_app_channel *ua_chan,
-               struct ust_app_event *ua_event)
+static
+int create_ust_event(struct ust_app *app, struct ust_app_session *ua_sess,
+               struct ust_app_channel *ua_chan, struct ust_app_event *ua_event)
 {
        int ret = 0;
 
@@ -417,11 +451,18 @@ static int create_ust_event(struct ust_app *app,
        }
 
        ua_event->handle = ua_event->obj->handle;
-       ua_event->enabled = 1;
 
        DBG2("UST app event %s created successfully for pid:%d",
                        ua_event->attr.name, app->key.pid);
 
+       /* If event not enabled, disable it on the tracer */
+       if (!ua_event->enabled) {
+               ret = disable_ust_event(app, ua_sess, ua_event);
+               if (ret < 0) {
+                       goto error;
+               }
+       }
+
 error:
        return ret;
 }
@@ -468,6 +509,7 @@ static struct ust_app_channel *alloc_ust_app_channel(char *name,
        strncpy(ua_chan->name, name, sizeof(ua_chan->name));
        ua_chan->name[sizeof(ua_chan->name) - 1] = '\0';
 
+       ua_chan->enabled = 1;
        ua_chan->handle = -1;
        ua_chan->ctx = hashtable_new(0);
        ua_chan->events = hashtable_new_str(0);
@@ -504,6 +546,7 @@ static struct ust_app_event *alloc_ust_app_event(char *name,
                goto error;
        }
 
+       ua_event->enabled = 1;
        strncpy(ua_event->name, name, sizeof(ua_event->name));
        ua_event->name[sizeof(ua_event->name) - 1] = '\0';
        ua_event->ctx = hashtable_new(0);
@@ -727,6 +770,26 @@ error:
        return NULL;
 }
 
+/*
+ * Enable on the tracer side a ust app event for the session and channel.
+ */
+static
+int enable_ust_app_event(struct ust_app_session *ua_sess,
+               struct ust_app_event *ua_event, struct ust_app *app)
+{
+       int ret;
+
+       ret = enable_ust_event(app, ua_sess, ua_event);
+       if (ret < 0) {
+               goto error;
+       }
+
+       ua_event->enabled = 1;
+
+error:
+       return ret;
+}
+
 /*
  * Disable on the tracer side a ust app event for the session and channel.
  */
@@ -750,29 +813,19 @@ error:
 /*
  * 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)
+static
+int disable_ust_app_channel(struct ust_app_session *ua_sess,
+               struct ust_app_channel *ua_chan, 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);
+       int ret;
 
        ret = disable_ust_channel(app, ua_sess, ua_chan);
        if (ret < 0) {
                goto error;
        }
 
+       ua_chan->enabled = 0;
+
 error:
        return ret;
 }
@@ -850,11 +903,12 @@ error:
 /*
  * Create UST app event and create it on the tracer side.
  */
-static struct ust_app_event *create_ust_app_event(
-               struct ust_app_session *ua_sess, struct ust_app_channel *ua_chan,
-               struct ltt_ust_event *uevent, struct ust_app *app)
+static
+int create_ust_app_event(struct ust_app_session *ua_sess,
+               struct ust_app_channel *ua_chan, struct ltt_ust_event *uevent,
+               struct ust_app *app)
 {
-       int ret;
+       int ret = 0;
        struct cds_lfht_iter iter;
        struct cds_lfht_node *ua_event_node;
        struct ust_app_event *ua_event;
@@ -862,30 +916,35 @@ static struct ust_app_event *create_ust_app_event(
        /* Get event node */
        ua_event_node = hashtable_lookup(ua_chan->events,
                        (void *)uevent->attr.name, strlen(uevent->attr.name), &iter);
-       if (ua_event_node == NULL) {
-               DBG2("UST app event %s not found, creating it", uevent->attr.name);
-               /* Does not exist so create one */
-               ua_event = alloc_ust_app_event(uevent->attr.name, &uevent->attr);
-               if (ua_event == NULL) {
-                       /* Only malloc can failed so something is really wrong */
-                       goto error;
-               }
-               shadow_copy_event(ua_event, uevent);
+       if (ua_event_node != NULL) {
+               ERR("UST app event %s already exist. Stopping creation.",
+                               uevent->attr.name);
+               goto end;
+       }
 
-               hashtable_add_unique(ua_chan->events, &ua_event->node);
-       } else {
-               ua_event = caa_container_of(ua_event_node, struct ust_app_event, node);
+       /* Does not exist so create one */
+       ua_event = alloc_ust_app_event(uevent->attr.name, &uevent->attr);
+       if (ua_event == NULL) {
+               /* Only malloc can failed so something is really wrong */
+               ret = -ENOMEM;
+               goto error;
        }
+       shadow_copy_event(ua_event, uevent);
 
+       /* Create it on the tracer side */
        ret = create_ust_event(app, ua_sess, ua_chan, ua_event);
        if (ret < 0) {
+               delete_ust_app_event(app->key.sock, ua_event);
                goto error;
        }
 
-       return ua_event;
+       ua_event->enabled = 1;
+
+       hashtable_add_unique(ua_chan->events, &ua_event->node);
 
+end:
 error:
-       return NULL;
+       return ret;
 }
 
 /*
@@ -1185,13 +1244,15 @@ void ust_app_ht_alloc(void)
 /*
  * For a specific UST session, disable the channel for all registered apps.
  */
-int ust_app_disable_channel_all(struct ltt_ust_session *usess,
+int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan)
 {
        int ret = 0;
        struct cds_lfht_iter iter;
+       struct cds_lfht_node *ua_chan_node;
        struct ust_app *app;
        struct ust_app_session *ua_sess;
+       struct ust_app_channel *ua_chan;
 
        if (usess == NULL || uchan == NULL) {
                ERR("Disabling UST global channel with NULL values");
@@ -1199,7 +1260,7 @@ int ust_app_disable_channel_all(struct ltt_ust_session *usess,
                goto error;
        }
 
-       DBG2("UST app disablling channel %s from global domain for session uid %d",
+       DBG2("UST app disabling channel %s from global domain for session uid %d",
                        uchan->name, usess->uid);
 
        rcu_read_lock();
@@ -1211,8 +1272,18 @@ int ust_app_disable_channel_all(struct ltt_ust_session *usess,
                        continue;
                }
 
-               /* Create channel onto application */
-               ret = disable_ust_app_channel(ua_sess, uchan, app);
+               /* Get channel */
+               ua_chan_node = hashtable_lookup(ua_sess->channels,
+                               (void *)uchan->name, strlen(uchan->name), &iter);
+               /* If the session if found for the app, the channel must be there */
+               assert(ua_chan_node);
+
+               ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+               /* The channel must not be already disabled */
+               assert(ua_chan->enabled == 1);
+
+               /* Disable channel onto application */
+               ret = disable_ust_app_channel(ua_sess, ua_chan, app);
                if (ret < 0) {
                        /* XXX: We might want to report this error at some point... */
                        continue;
@@ -1228,7 +1299,7 @@ error:
 /*
  * For a specific UST session, enable the channel for all registered apps.
  */
-int ust_app_enable_channel_all(struct ltt_ust_session *usess,
+int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan)
 {
        int ret = 0;
@@ -1271,8 +1342,8 @@ error:
 /*
  * Disable an event in a channel and for a specific session.
  */
-int ust_app_disable_event(struct ltt_ust_session *usess,
-               struct ltt_ust_channel *uchan, char *event_name)
+int ust_app_disable_event_glb(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
 {
        int ret = 0;
        struct cds_lfht_iter iter, uiter;
@@ -1283,7 +1354,7 @@ int ust_app_disable_event(struct ltt_ust_session *usess,
        struct ust_app_event *ua_event;
 
        DBG("UST app disabling event %s for all apps in channel "
-                       "%s for session uid %d", event_name, uchan->name, usess->uid);
+                       "%s for session uid %d", uevent->attr.name, uchan->name, usess->uid);
 
        rcu_read_lock();
 
@@ -1306,10 +1377,10 @@ int ust_app_disable_event(struct ltt_ust_session *usess,
                ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
 
                ua_event_node = hashtable_lookup(ua_chan->events,
-                               (void *) event_name, strlen(event_name), &uiter);
+                               (void *)uevent->attr.name, strlen(uevent->attr.name), &uiter);
                if (ua_event_node == NULL) {
                        DBG2("Event %s not found in channel %s for app pid %d."
-                                       "Skipping", event_name, uchan->name, app->key.pid);
+                                       "Skipping", uevent->attr.name, uchan->name, app->key.pid);
                        continue;
                }
                ua_event = caa_container_of(ua_event_node, struct ust_app_event, node);
@@ -1327,10 +1398,10 @@ int ust_app_disable_event(struct ltt_ust_session *usess,
 }
 
 /*
- * For a specific UST session and UST channel, create the event for all
+ * For a specific UST session and UST channel, the event for all
  * registered apps.
  */
-int ust_app_disable_event_all(struct ltt_ust_session *usess,
+int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan)
 {
        int ret = 0;
@@ -1349,20 +1420,15 @@ int ust_app_disable_event_all(struct ltt_ust_session *usess,
        /* For all 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) {
-                       /* Next app */
-                       continue;
-               }
+               /* If ua_sess is NULL, there is a code flow error */
+               assert(ua_sess);
 
                /* Lookup channel in the ust app session */
-               ua_chan_node = hashtable_lookup(ua_sess->channels,
-                               (void *)uchan->name, strlen(uchan->name),
-                               &uiter);
-               if (ua_chan_node == NULL) {
-                       DBG2("Channel %s not found in session uid %d for app pid %d."
-                                       "Skipping", uchan->name, app->key.pid, usess->uid);
-                       continue;
-               }
+               ua_chan_node = hashtable_lookup(ua_sess->channels, (void *)uchan->name,
+                               strlen(uchan->name), &uiter);
+               /* If the channel is not found, there is a code flow error */
+               assert(ua_chan_node);
+
                ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
 
                /* Disable each events of channel */
@@ -1383,7 +1449,7 @@ int ust_app_disable_event_all(struct ltt_ust_session *usess,
 /*
  * For a specific UST session, create the channel for all registered apps.
  */
-int ust_app_create_channel_all(struct ltt_ust_session *usess,
+int ust_app_create_channel_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan)
 {
        int ret = 0;
@@ -1405,7 +1471,11 @@ int ust_app_create_channel_all(struct ltt_ust_session *usess,
 
        /* For every registered applications */
        cds_lfht_for_each_entry(ust_app_ht, &iter, app, node) {
-               /* Create session on the tracer side and add it to app session HT */
+               /*
+                * Create session on the tracer side and add it to app session HT. Note
+                * that if session exist, it will simply return a pointer to the ust
+                * app session.
+                */
                ua_sess = create_ust_app_session(usess, app);
                if (ua_sess == NULL) {
                        continue;
@@ -1425,48 +1495,106 @@ error:
 }
 
 /*
- * For a specific UST session and UST channel, create the event for all
- * registered apps.
+ * Enable event for a specific session and channel on the tracer.
  */
-int ust_app_create_event_all(struct ltt_ust_session *usess,
+int ust_app_enable_event_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
 {
        int ret = 0;
-       struct cds_lfht_iter iter;
-       struct cds_lfht_node *ua_chan_node;
+       struct cds_lfht_iter iter, uiter;
+       struct cds_lfht_node *ua_chan_node, *ua_event_node;
        struct ust_app *app;
        struct ust_app_session *ua_sess;
        struct ust_app_channel *ua_chan;
        struct ust_app_event *ua_event;
 
-       DBG("UST app creating event %s for all apps for session uid %d",
+       DBG("UST app enabling event %s for all apps for session uid %d",
                        uevent->attr.name, usess->uid);
 
+       /*
+        * NOTE: At this point, this function is called only if the session and
+        * channel passed are already created for all apps. and enabled on the
+        * tracer also.
+        */
+
        rcu_read_lock();
 
        /* For all registered applications */
        cds_lfht_for_each_entry(ust_app_ht, &iter, app, node) {
-               struct cds_lfht_iter uiter;
+               ua_sess = lookup_session_by_app(usess, app);
+               /* If ua_sess is NULL, there is a code flow error */
+               assert(ua_sess);
 
-               /* Create session on the tracer side and add it to app session HT */
-               ua_sess = create_ust_app_session(usess, app);
-               if (ua_sess == NULL) {
+               /* Lookup channel in the ust app session */
+               ua_chan_node = hashtable_lookup(ua_sess->channels, (void *)uchan->name,
+                               strlen(uchan->name), &uiter);
+               /* If the channel is not found, there is a code flow error */
+               assert(ua_chan_node);
+
+               ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+
+               ua_event_node = hashtable_lookup(ua_sess->channels,
+                               (void*)uevent->attr.name, strlen(uevent->attr.name), &uiter);
+               if (ua_event_node == NULL) {
+                       DBG3("UST app enable event %s not found. Skipping app",
+                                       uevent->attr.name);
                        continue;
                }
+               ua_event = caa_container_of(ua_event_node, struct ust_app_event, node);
 
-               /* Lookup channel in the ust app session */
-               ua_chan_node = hashtable_lookup(ua_sess->channels,
-                               (void *)uchan->name, strlen(uchan->name),
-                               &uiter);
-               if (ua_chan_node == NULL) {
-                       ERR("Channel %s not found in session uid %d. Skipping",
-                                       uchan->name, usess->uid);
+               ret = enable_ust_app_event(ua_sess, ua_event, app);
+               if (ret < 0) {
+                       /* XXX: Report error someday... */
                        continue;
                }
+       }
+
+       rcu_read_unlock();
+
+       return ret;
+}
+
+/*
+ * For a specific existing UST session and UST channel, creates the event for
+ * all registered apps.
+ */
+int ust_app_create_event_glb(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
+{
+       int ret = 0;
+       struct cds_lfht_iter iter, uiter;
+       struct cds_lfht_node *ua_chan_node;
+       struct ust_app *app;
+       struct ust_app_session *ua_sess;
+       struct ust_app_channel *ua_chan;
+
+       DBG("UST app creating event %s for all apps for session uid %d",
+                       uevent->attr.name, usess->uid);
+
+       /*
+        * NOTE: At this point, this function is called only if the session and
+        * channel passed are already created for all apps. and enabled on the
+        * tracer also.
+        */
+
+       rcu_read_lock();
+
+       /* For all registered applications */
+       cds_lfht_for_each_entry(ust_app_ht, &iter, app, node) {
+               ua_sess = lookup_session_by_app(usess, app);
+               /* If ua_sess is NULL, there is a code flow error */
+               assert(ua_sess);
+
+               /* Lookup channel in the ust app session */
+               ua_chan_node = hashtable_lookup(ua_sess->channels, (void *)uchan->name,
+                               strlen(uchan->name), &uiter);
+               /* If the channel is not found, there is a code flow error */
+               assert(ua_chan_node);
+
                ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
 
-               ua_event = create_ust_app_event(ua_sess, ua_chan, uevent, app);
-               if (ua_event == NULL) {
+               ret = create_ust_app_event(ua_sess, ua_chan, uevent, app);
+               if (ret < 0) {
                        continue;
                }
        }
@@ -1494,7 +1622,6 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
 
        ua_sess = lookup_session_by_app(usess, app);
        if (ua_sess == NULL) {
-               /* Only malloc can failed so something is really wrong */
                goto error_rcu_unlock;
        }
 
index 2e8ce58da28f0cab9ecc1a8a194bad49c88be2c6..8a0130f0724927f33cf986e58feb37ba01cc25f0 100644 (file)
@@ -110,10 +110,6 @@ struct ust_app {
 
 int ust_app_register(struct ust_register_msg *msg, int sock);
 void ust_app_unregister(int sock);
-int ust_app_create_channel_all(struct ltt_ust_session *usess,
-               struct ltt_ust_channel *uchan);
-int ust_app_create_event_all(struct ltt_ust_session *usess,
-               struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
 unsigned long ust_app_list_count(void);
 int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app);
 int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app);
@@ -122,14 +118,22 @@ 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,
+int ust_app_create_channel_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan);
-int ust_app_enable_channel_all(struct ltt_ust_session *usess,
+int ust_app_create_event_glb(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
+int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan);
-int ust_app_disable_event_all(struct ltt_ust_session *usess,
+int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan);
-int ust_app_disable_event(struct ltt_ust_session *usess,
-               struct ltt_ust_channel *uchan, char *event_name);
+int ust_app_enable_event_glb(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
+int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan);
+int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan);
+int ust_app_disable_event_glb(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
 void ust_app_global_update(struct ltt_ust_session *usess, int sock);
 
 void ust_app_clean_list(void);
@@ -201,18 +205,6 @@ struct ust_app *ust_app_get_by_pid(pid_t pid)
        return NULL;
 }
 static inline
-int ust_app_add_channel_all(struct ltt_ust_session *usess,
-               struct ltt_ust_channel *uchan)
-{
-       return 0;
-}
-static inline
-int ust_app_add_event_all(struct ltt_ust_session *usess,
-               struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
-{
-       return 0;
-}
-static inline
 struct cds_lfht *ust_app_get_ht(void)
 {
        return NULL;
@@ -224,37 +216,49 @@ static inline
 void ust_app_global_update(struct ltt_ust_session *usess, int sock)
 {}
 static inline
-int ust_app_disable_channel_all(struct ltt_ust_session *usess,
+int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan)
 {
        return 0;
 }
 static inline
-int ust_app_enable_channel_all(struct ltt_ust_session *usess,
+int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan)
 {
        return 0;
 }
 static inline
-int ust_app_disable_event_all(struct ltt_ust_session *usess,
+int ust_app_create_channel_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan)
 {
        return 0;
 }
 static inline
-int ust_app_disable_event(struct ltt_ust_session *usess,
-               struct ltt_ust_channel *uchan, char *event_name)
+int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan)
 {
        return 0;
 }
 static inline
-int ust_app_create_channel_all(struct ltt_ust_session *usess,
+int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan)
 {
        return 0;
 }
 static inline
-int ust_app_create_event_all(struct ltt_ust_session *usess,
+int ust_app_create_event_glb(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
+{
+       return 0;
+}
+static inline
+int ust_app_disable_event_glb(struct ltt_ust_session *usess,
+               struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
+{
+       return 0;
+}
+static inline
+int ust_app_enable_event_glb(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
 {
        return 0;
diff --git a/lttng-sessiond/ust-ctl.c b/lttng-sessiond/ust-ctl.c
deleted file mode 100644 (file)
index 6f73bfc..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#define _GNU_SOURCE
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <lttng-sessiond-comm.h>
-#include <lttngerr.h>
-
-#include "ust-comm.h"
-#include "ust-ctl.h"
-#include "../hashtable/hash.h"
-
-/*
- * Init command for tracer with cmd type and correct handle.
- */
-static void init_command(int cmd, int handle, struct lttcomm_ust_msg *command)
-{
-       memset(command, 0, sizeof(struct lttcomm_ust_msg));
-
-       command->cmd = cmd;
-       command->handle = handle;
-}
-
-/*
- * Generic send command to ust tracer. Caller must free reply.
- */
-static struct lttcomm_ust_reply *send_command(int sock,
-               struct lttcomm_ust_msg *command)
-{
-       struct lttcomm_ust_reply *reply;
-
-       reply = ustcomm_send_command(sock, command);
-       if (reply == NULL) {
-               goto error;
-       }
-
-       if (reply->ret_code != LTTCOMM_OK) {
-               ERR("Return code (%d): %s", reply->ret_code,
-                               lttcomm_get_readable_code(reply->ret_code));
-               goto error;
-       }
-
-       return reply;
-
-error:
-       return NULL;
-}
-
-/*
- * Send registration done packet to the application.
- */
-int ustctl_register_done(int sock)
-{
-       struct lttcomm_ust_msg command;
-       struct lttcomm_ust_reply *reply;
-
-       DBG("Sending register done command to %d", sock);
-
-       command.cmd = LTTNG_UST_REGISTER_DONE;
-       command.handle = LTTNG_UST_ROOT_HANDLE;
-
-       reply = ustcomm_send_command(sock, &command);
-       if (reply == NULL) {
-               goto error;
-       }
-
-       if (reply->ret_code != LTTCOMM_OK) {
-               DBG("Return code: %s", lttcomm_get_readable_code(reply->ret_code));
-               goto error;
-       }
-
-       return 0;
-
-error:
-       return -1;
-}
-
-/*
- * Create an UST session on the tracer.
- *
- * Return handle if success else negative value.
- */
-int ustctl_create_session(int sock, struct ltt_ust_session *session)
-{
-       int ret;
-       struct lttcomm_ust_msg command;
-       struct lttcomm_ust_reply *reply = NULL;
-
-       command.cmd = LTTNG_UST_SESSION;
-       command.handle = LTTNG_UST_ROOT_HANDLE;
-
-       reply = ustcomm_send_command(sock, &command);
-       if (reply == NULL) {
-               goto error;
-       }
-
-       /* Save session handle */
-       ret = reply->ret_val;
-       free(reply);
-
-       DBG2("ustctl create session command successful with handle %d", ret);
-
-       return ret;
-
-error:
-       free(reply);
-       return -1;
-}
-
-/*
- * Create UST channel to the tracer.
- *
- * Return handle if success else negative value.
- */
-int ustctl_create_channel(int sock, struct ltt_ust_session *session,
-               struct lttng_ust_channel *channel)
-{
-       int ret;
-       struct lttcomm_ust_msg command;
-       struct lttcomm_ust_reply *reply = NULL;
-
-       init_command(LTTNG_UST_CHANNEL, session->handle, &command);
-       /* Copy channel attributes to command */
-       memcpy(&command.u.channel, channel, sizeof(command.u.channel));
-
-       /* Send command to tracer */
-       reply = send_command(sock, &command);
-       if (reply == NULL) {
-               goto error;
-       }
-
-       ret = reply->ret_val;
-       free(reply);
-
-       return ret;
-
-error:
-       free(reply);
-       return -1;
-}
-
-/*
- * Enable UST channel.
- */
-int ustctl_enable_channel(int sock, struct ltt_ust_session *session,
-               struct ltt_ust_channel *chan)
-{
-       struct lttcomm_ust_msg command;
-       struct lttcomm_ust_reply *reply = NULL;
-
-       init_command(LTTNG_UST_ENABLE, chan->handle, &command);
-
-       reply = ustcomm_send_command(sock, &command);
-       if (reply == NULL) {
-               goto error;
-       }
-
-       if (reply->handle != chan->handle) {
-               ERR("Receive wrong handle from UST reply on enable channel");
-               goto error;
-       }
-
-       chan->enabled = 1;
-       free(reply);
-
-       DBG2("ustctl enable channel successful for sock %d", sock);
-       return 0;
-
-error:
-       free(reply);
-       return -1;
-}
-
-/*
- * Disable UST channel.
- */
-int ustctl_disable_channel(int sock, struct ltt_ust_session *session,
-               struct ltt_ust_channel *chan)
-{
-       struct lttcomm_ust_msg command;
-       struct lttcomm_ust_reply *reply = NULL;
-
-       memset(&command, 0, sizeof(command));
-
-       command.cmd = LTTNG_UST_DISABLE;
-       command.handle = chan->handle;
-
-       reply = ustcomm_send_command(sock, &command);
-       if (reply == NULL) {
-               goto error;
-       }
-
-       if (reply->handle != chan->handle) {
-               ERR("Receive wrong handle from UST reply on enable channel");
-               goto error;
-       }
-
-       chan->enabled = 1;
-       free(reply);
-
-       DBG2("ustctl disable channel successful for sock %d", sock);
-       return 0;
-
-error:
-       free(reply);
-       return -1;
-}
This page took 0.057131 seconds and 4 git commands to generate.