X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fkernel.c;h=32c40531d21b3e50f4d7b1851594b2ad1090ea4f;hp=d52d9aa62f4e997b327fe2d1ec336ed5414392f8;hb=0525e9ae15d215943d8187e7f190d5a45e723085;hpb=2f77fc4b3720dc8f75847130498c2d4aad7c03ec diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index d52d9aa62..32c40531d 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -40,6 +40,9 @@ int kernel_add_channel_context(struct ltt_kernel_channel *chan, { int ret; + assert(chan); + assert(ctx); + DBG("Adding context to channel %s", chan->channel->name); ret = kernctl_add_context(chan->fd, ctx); if (ret < 0) { @@ -66,35 +69,6 @@ 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. @@ -104,6 +78,8 @@ int kernel_create_session(struct ltt_session *session, int tracer_fd) int ret; struct ltt_kernel_session *lks; + assert(session); + /* Allocate data structure */ lks = trace_kernel_create_session(session->path); if (lks == NULL) { @@ -125,6 +101,7 @@ int kernel_create_session(struct ltt_session *session, int tracer_fd) PERROR("fcntl session fd"); } + lks->id = session->id; lks->consumer_fds_sent = 0; session->kernel_session = lks; @@ -146,6 +123,10 @@ int kernel_create_channel(struct ltt_kernel_session *session, int ret; struct ltt_kernel_channel *lkc; + assert(session); + assert(chan); + assert(path); + /* Allocate kernel channel */ lkc = trace_kernel_create_channel(chan, path); if (lkc == NULL) { @@ -176,6 +157,7 @@ int kernel_create_channel(struct ltt_kernel_session *session, /* Add channel to session */ cds_list_add(&lkc->list, &session->channel_list.head); session->channel_count++; + lkc->session = session; DBG("Kernel channel %s created (fd: %d)", lkc->channel->name, lkc->fd); @@ -195,6 +177,9 @@ int kernel_create_event(struct lttng_event *ev, int ret; struct ltt_kernel_event *event; + assert(ev); + assert(channel); + event = trace_kernel_create_event(ev); if (event == NULL) { ret = -1; @@ -258,6 +243,8 @@ int kernel_disable_channel(struct ltt_kernel_channel *chan) { int ret; + assert(chan); + ret = kernctl_disable(chan->fd); if (ret < 0) { PERROR("disable chan ioctl"); @@ -281,6 +268,8 @@ int kernel_enable_channel(struct ltt_kernel_channel *chan) { int ret; + assert(chan); + ret = kernctl_enable(chan->fd); if (ret < 0 && errno != EEXIST) { PERROR("Enable kernel chan"); @@ -303,11 +292,13 @@ int kernel_enable_event(struct ltt_kernel_event *event) { int ret; + assert(event); + ret = kernctl_enable(event->fd); if (ret < 0) { switch (errno) { case EEXIST: - ret = LTTCOMM_KERN_EVENT_EXIST; + ret = LTTNG_ERR_KERN_EVENT_EXIST; break; default: PERROR("enable kernel event"); @@ -332,11 +323,13 @@ int kernel_disable_event(struct ltt_kernel_event *event) { int ret; + assert(event); + ret = kernctl_disable(event->fd); if (ret < 0) { switch (errno) { case EEXIST: - ret = LTTCOMM_KERN_EVENT_EXIST; + ret = LTTNG_ERR_KERN_EVENT_EXIST; break; default: PERROR("disable kernel event"); @@ -363,6 +356,8 @@ int kernel_open_metadata(struct ltt_kernel_session *session) int ret; struct ltt_kernel_metadata *lkm; + assert(session); + /* Allocate kernel metadata */ lkm = trace_kernel_create_metadata(); if (lkm == NULL) { @@ -399,6 +394,8 @@ int kernel_start_session(struct ltt_kernel_session *session) { int ret; + assert(session); + ret = kernctl_start_session(session->fd); if (ret < 0) { PERROR("ioctl start session"); @@ -436,6 +433,8 @@ int kernel_calibrate(int fd, struct lttng_kernel_calibrate *calibrate) { int ret; + assert(calibrate); + ret = kernctl_calibrate(fd, calibrate); if (ret < 0) { PERROR("calibrate ioctl"); @@ -469,6 +468,8 @@ int kernel_flush_buffer(struct ltt_kernel_channel *channel) int ret; struct ltt_kernel_stream *stream; + assert(channel); + DBG("Flush buffer for channel %s", channel->channel->name); cds_list_for_each_entry(stream, &channel->stream_list.head, list) { @@ -491,6 +492,8 @@ int kernel_stop_session(struct ltt_kernel_session *session) { int ret; + assert(session); + ret = kernctl_stop_session(session->fd); if (ret < 0) { goto error; @@ -515,6 +518,8 @@ int kernel_open_channel_stream(struct ltt_kernel_channel *channel) int ret, count = 0; struct ltt_kernel_stream *lks; + assert(channel); + while ((ret = kernctl_create_stream(channel->fd)) >= 0) { lks = trace_kernel_create_stream(channel->channel->name, count); if (lks == NULL) { @@ -556,6 +561,8 @@ int kernel_open_metadata_stream(struct ltt_kernel_session *session) { int ret; + assert(session); + ret = kernctl_create_stream(session->metadata->fd); if (ret < 0) { PERROR("kernel create metadata stream"); @@ -584,10 +591,11 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events) int fd, pos, ret; char *event; size_t nbmem, count = 0; - ssize_t size; FILE *fp; struct lttng_event *elist; + assert(events); + fd = kernctl_tracepoint_list(tracer_fd); if (fd < 0) { PERROR("kernel tracepoint list"); @@ -612,7 +620,7 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events) goto end; } - while ((size = fscanf(fp, "event { name = %m[^;]; };%n\n", &event, &pos)) == 1) { + while (fscanf(fp, "event { name = %m[^;]; };%n\n", &event, &pos) == 1) { if (count >= nbmem) { struct lttng_event *new_elist; @@ -737,3 +745,33 @@ void kernel_destroy_session(struct ltt_kernel_session *ksess) trace_kernel_destroy_session(ksess); } + +/* + * Destroy a kernel channel object. It does not do anything on the tracer side. + */ +void kernel_destroy_channel(struct ltt_kernel_channel *kchan) +{ + struct ltt_kernel_session *ksess = NULL; + + assert(kchan); + assert(kchan->channel); + + DBG3("Kernel destroy channel %s", kchan->channel->name); + + /* Update channel count of associated session. */ + if (kchan->session) { + /* Keep pointer reference so we can update it after the destroy. */ + ksess = kchan->session; + } + + trace_kernel_destroy_channel(kchan); + + /* + * At this point the kernel channel is not visible anymore. This is safe + * since in order to work on a visible kernel session, the tracing session + * lock (ltt_session.lock) MUST be acquired. + */ + if (ksess) { + ksess->channel_count--; + } +}