From: Mathieu Desnoyers Date: Thu, 19 May 2011 02:55:16 +0000 (-0400) Subject: kprobes support: fix handling of event description X-Git-Tag: v2.0-pre1~141 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d3dbe23cbd102fb87206b6ed78aad28e042ac77e;p=lttng-modules.git kprobes support: fix handling of event description Signed-off-by: Mathieu Desnoyers --- diff --git a/ltt-debugfs-abi.c b/ltt-debugfs-abi.c index d013fa5a..9139e5a1 100644 --- a/ltt-debugfs-abi.c +++ b/ltt-debugfs-abi.c @@ -143,21 +143,15 @@ void lttng_metadata_create_events(struct file *channel_file) { struct ltt_channel *channel = channel_file->private_data; char *event_name = "lttng_metadata"; - const struct lttng_event_desc *event_desc; struct ltt_event *event; int ret; - event_desc = ltt_event_get(event_name); - if (!event_desc) { - ret = -ENOENT; - goto get_error; - } /* * We tolerate no failure path after event creation. It will stay * invariant for the rest of the session. */ event = ltt_event_create(channel, event_name, LTTNG_KERNEL_TRACEPOINTS, - event_desc, NULL); + NULL); if (!event) { goto create_error; ret = -EEXIST; @@ -165,8 +159,6 @@ void lttng_metadata_create_events(struct file *channel_file) return; create_error: - ltt_event_put(event_desc); -get_error: WARN_ON(1); return; /* not allowed to return error */ } @@ -359,7 +351,6 @@ int lttng_abi_create_event(struct file *channel_file, struct lttng_kernel_event __user *uevent_param) { struct ltt_channel *channel = channel_file->private_data; - const struct lttng_event_desc *event_desc; struct ltt_event *event; char *event_name; struct lttng_kernel_event event_param; @@ -376,12 +367,8 @@ int lttng_abi_create_event(struct file *channel_file, goto name_error; } event_name[PATH_MAX - 1] = '\0'; + event_param.u.kprobe.symbol_name[LTTNG_KPROBE_SYM_NAME_LEN - 1] = '\0'; - event_desc = ltt_event_get(event_name); - if (!event_desc) { - ret = -ENOENT; - goto get_error; - } event_fd = get_unused_fd(); if (event_fd < 0) { ret = event_fd; @@ -398,8 +385,7 @@ int lttng_abi_create_event(struct file *channel_file, * We tolerate no failure path after event creation. It will stay * invariant for the rest of the session. */ - event = ltt_event_create(channel, event_name, &event_param, - event_desc, NULL); + event = ltt_event_create(channel, event_name, &event_param, NULL); if (!event) { ret = -EEXIST; goto event_error; @@ -416,8 +402,6 @@ event_error: file_error: put_unused_fd(event_fd); fd_error: - ltt_event_put(event_desc); -get_error: name_error: kfree(event_name); return ret; diff --git a/ltt-events.c b/ltt-events.c index 29d0ed74..cf4fc8b7 100644 --- a/ltt-events.c +++ b/ltt-events.c @@ -203,7 +203,6 @@ void _ltt_channel_destroy(struct ltt_channel *chan) */ struct ltt_event *ltt_event_create(struct ltt_channel *chan, char *name, struct lttng_kernel_event *event_param, - const struct lttng_event_desc *event_desc, void *filter) { struct ltt_event *event; @@ -223,7 +222,6 @@ struct ltt_event *ltt_event_create(struct ltt_channel *chan, char *name, if (!event) goto cache_error; event->chan = chan; - event->desc = event_desc; event->filter = filter; event->id = chan->free_event_id++; event->instrumentation = event_param->instrumentation; @@ -231,8 +229,12 @@ struct ltt_event *ltt_event_create(struct ltt_channel *chan, char *name, smp_wmb(); switch (event_param->instrumentation) { case LTTNG_KERNEL_TRACEPOINTS: - ret = tracepoint_probe_register(name, event_desc->probe_callback, - event); + event->desc = ltt_event_get(name); + if (!event->desc) + goto register_error; + ret = tracepoint_probe_register(name, + event->desc->probe_callback, + event); if (ret) goto register_error; break; @@ -256,8 +258,10 @@ struct ltt_event *ltt_event_create(struct ltt_channel *chan, char *name, return event; statedump_error: - WARN_ON_ONCE(tracepoint_probe_unregister(name, event_desc->probe_callback, - event)); + WARN_ON_ONCE(tracepoint_probe_unregister(name, + event->desc->probe_callback, + event)); + ltt_event_put(event->desc); register_error: kmem_cache_free(event_cache, event); cache_error: @@ -281,6 +285,7 @@ int _ltt_event_unregister(struct ltt_event *event) event); if (ret) return ret; + ltt_event_put(event->desc); break; case LTTNG_KERNEL_KPROBES: lttng_kprobes_unregister(event); diff --git a/ltt-events.h b/ltt-events.h index a26638c4..030ffe02 100644 --- a/ltt-events.h +++ b/ltt-events.h @@ -127,7 +127,7 @@ struct lttng_probe_desc { struct ltt_event { unsigned int id; struct ltt_channel *chan; - struct lttng_event_desc *desc; + const struct lttng_event_desc *desc; void *filter; enum lttng_kernel_instrumentation instrumentation; union { @@ -217,7 +217,6 @@ void _ltt_channel_destroy(struct ltt_channel *chan); struct ltt_event *ltt_event_create(struct ltt_channel *chan, char *name, struct lttng_kernel_event *event_param, - const struct lttng_event_desc *event_desc, void *filter); int ltt_event_unregister(struct ltt_event *event); diff --git a/probes/lttng-kprobes.c b/probes/lttng-kprobes.c index bee935f7..1cffe685 100644 --- a/probes/lttng-kprobes.c +++ b/probes/lttng-kprobes.c @@ -44,18 +44,19 @@ static int lttng_create_kprobe_event(const char *name, struct ltt_event *event) { struct lttng_event_field *field; + struct lttng_event_desc *desc; int ret; - event->desc = kzalloc(sizeof(*event->desc), GFP_KERNEL); - if (!event->desc) + desc = kzalloc(sizeof(*event->desc), GFP_KERNEL); + if (!desc) return -ENOMEM; - event->desc->name = kstrdup(name, GFP_KERNEL); - if (!event->desc->name) { + desc->name = kstrdup(name, GFP_KERNEL); + if (!desc->name) { ret = -ENOMEM; goto error_str; } - event->desc->nr_fields = 1; - event->desc->fields = field = + desc->nr_fields = 1; + desc->fields = field = kzalloc(1 * sizeof(struct lttng_event_field), GFP_KERNEL); field->name = "ip"; field->type.atype = atype_integer; @@ -63,11 +64,12 @@ int lttng_create_kprobe_event(const char *name, struct ltt_event *event) field->type.u.basic.integer.alignment = ltt_alignof(unsigned long); field->type.u.basic.integer.signedness = 0; field->type.u.basic.integer.reverse_byte_order = 0; + event->desc = desc; return 0; error_str: - kfree(event->desc); + kfree(desc); return ret; }