From: Mathieu Desnoyers Date: Wed, 5 Nov 2014 00:14:19 +0000 (-0500) Subject: Support lttng-modules syscall wildcards X-Git-Tag: v2.7.0-rc1~55 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d0ae4ea864f84fa2456563abb20fe42e5cc29625;p=lttng-tools.git Support lttng-modules syscall wildcards While we are there, fix semantic issues with disable-event and various types of instrumentation. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 31c3aff77..7eea28121 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1167,23 +1167,28 @@ int cmd_disable_event(struct ltt_session *session, int domain, switch (event->type) { case LTTNG_EVENT_ALL: - ret = event_kernel_disable_all(kchan); + ret = event_kernel_disable_event_all(kchan); if (ret != LTTNG_OK) { goto error; } break; - case LTTNG_EVENT_TRACEPOINT: + case LTTNG_EVENT_TRACEPOINT: /* fall-through */ + case LTTNG_EVENT_SYSCALL: if (!strcmp(event_name, "*")) { - ret = event_kernel_disable_all_tracepoints(kchan); + ret = event_kernel_disable_event_type(kchan, + event->type); } else { - ret = event_kernel_disable_tracepoint(kchan, event_name); + ret = event_kernel_disable_event(kchan, + event_name); } if (ret != LTTNG_OK) { goto error; } break; - case LTTNG_EVENT_SYSCALL: - ret = event_kernel_disable_syscall(kchan, event_name); + case LTTNG_EVENT_PROBE: + case LTTNG_EVENT_FUNCTION: + case LTTNG_EVENT_FUNCTION_ENTRY: + ret = event_kernel_disable_event(kchan, event_name); if (ret != LTTNG_OK) { goto error; } @@ -1481,7 +1486,7 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, case LTTNG_EVENT_ALL: { event->type = LTTNG_EVENT_TRACEPOINT; /* Hack */ - ret = event_kernel_enable_tracepoint(kchan, event); + ret = event_kernel_enable_event(kchan, event); if (ret != LTTNG_OK) { if (channel_created) { /* Let's not leak a useless channel. */ @@ -1490,7 +1495,7 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, goto error; } event->type = LTTNG_EVENT_SYSCALL; /* Hack */ - ret = event_kernel_enable_syscall(kchan, event->name); + ret = event_kernel_enable_event(kchan, event); if (ret != LTTNG_OK) { goto error; } @@ -1500,7 +1505,7 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, case LTTNG_EVENT_FUNCTION: case LTTNG_EVENT_FUNCTION_ENTRY: case LTTNG_EVENT_TRACEPOINT: - ret = event_kernel_enable_tracepoint(kchan, event); + ret = event_kernel_enable_event(kchan, event); if (ret != LTTNG_OK) { if (channel_created) { /* Let's not leak a useless channel. */ @@ -1510,7 +1515,7 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain, } break; case LTTNG_EVENT_SYSCALL: - ret = event_kernel_enable_syscall(kchan, event->name); + ret = event_kernel_enable_event(kchan, event); if (ret != LTTNG_OK) { goto error; } diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index 564cbb784..0efdc9253 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -61,7 +61,7 @@ static void add_unique_ust_event(struct lttng_ht *ht, /* * Disable kernel tracepoint event for a channel from the kernel session. */ -int event_kernel_disable_tracepoint(struct ltt_kernel_channel *kchan, +int event_kernel_disable_event(struct ltt_kernel_channel *kchan, char *event_name) { int ret; @@ -69,7 +69,8 @@ int event_kernel_disable_tracepoint(struct ltt_kernel_channel *kchan, assert(kchan); - kevent = trace_kernel_get_event_by_name(event_name, kchan); + kevent = trace_kernel_get_event_by_name(event_name, kchan, + LTTNG_EVENT_ALL); if (kevent == NULL) { ret = LTTNG_ERR_NO_EVENT; goto error; @@ -90,61 +91,11 @@ error: return ret; } -/* - * Enable kernel system call for a channel from the kernel session. - */ -int event_kernel_enable_syscall(struct ltt_kernel_channel *kchan, - char *syscall_name) -{ - int ret; - - assert(kchan); - - ret = kernel_enable_syscall(syscall_name, kchan); - if (ret < 0) { - ret = LTTNG_ERR_KERN_ENABLE_FAIL; - goto error; - } - - DBG("Kernel syscall %s enable for channel %s.", - syscall_name, kchan->channel->name); - - ret = LTTNG_OK; - -error: - return ret; -} - -/* - * Disable kernel system call for a channel from the kernel session. - */ -int event_kernel_disable_syscall(struct ltt_kernel_channel *kchan, - char *syscall_name) -{ - int ret; - - assert(kchan); - - ret = kernel_disable_syscall(syscall_name, kchan); - if (ret < 0) { - ret = LTTNG_ERR_KERN_DISABLE_FAIL; - goto error; - } - - DBG("Kernel syscall %s disable for channel %s.", - !strcmp(syscall_name, "*") ? "" : syscall_name, - kchan->channel->name); - - ret = LTTNG_OK; - -error: - return ret; -} - /* * Disable kernel tracepoint events for a channel from the kernel session. */ -int event_kernel_disable_all_tracepoints(struct ltt_kernel_channel *kchan) +int event_kernel_disable_event_type(struct ltt_kernel_channel *kchan, + enum lttng_event_type type) { int ret; struct ltt_kernel_event *kevent; @@ -153,6 +104,8 @@ int event_kernel_disable_all_tracepoints(struct ltt_kernel_channel *kchan) /* For each event in the kernel session */ cds_list_for_each_entry(kevent, &kchan->events_list.head, list) { + if (type != LTTNG_EVENT_ALL && kevent->type != type) + continue; ret = kernel_disable_event(kevent); if (ret < 0) { /* We continue disabling the rest */ @@ -166,24 +119,16 @@ int event_kernel_disable_all_tracepoints(struct ltt_kernel_channel *kchan) /* * Disable all kernel event for a channel from the kernel session. */ -int event_kernel_disable_all(struct ltt_kernel_channel *kchan) +int event_kernel_disable_event_all(struct ltt_kernel_channel *kchan) { - int ret; - - assert(kchan); - - ret = event_kernel_disable_all_tracepoints(kchan); - if (ret != LTTNG_OK) - return ret; - ret = event_kernel_disable_syscall(kchan, "*"); - return ret; + return event_kernel_disable_event_type(kchan, LTTNG_EVENT_ALL); } /* * Enable kernel tracepoint event for a channel from the kernel session. * We own filter_expression and filter. */ -int event_kernel_enable_tracepoint(struct ltt_kernel_channel *kchan, +int event_kernel_enable_event(struct ltt_kernel_channel *kchan, struct lttng_event *event) { int ret; @@ -192,7 +137,8 @@ int event_kernel_enable_tracepoint(struct ltt_kernel_channel *kchan, assert(kchan); assert(event); - kevent = trace_kernel_get_event_by_name(event->name, kchan); + kevent = trace_kernel_get_event_by_name(event->name, kchan, + event->type); if (kevent == NULL) { ret = kernel_create_event(event, kchan); if (ret < 0) { diff --git a/src/bin/lttng-sessiond/event.h b/src/bin/lttng-sessiond/event.h index 4fa44560e..536b2be70 100644 --- a/src/bin/lttng-sessiond/event.h +++ b/src/bin/lttng-sessiond/event.h @@ -21,17 +21,14 @@ #include "agent.h" #include "trace-kernel.h" -int event_kernel_disable_tracepoint(struct ltt_kernel_channel *kchan, +int event_kernel_disable_event(struct ltt_kernel_channel *kchan, char *event_name); -int event_kernel_disable_syscall(struct ltt_kernel_channel *kchan, - char *syscall_name); -int event_kernel_disable_all_tracepoints(struct ltt_kernel_channel *kchan); -int event_kernel_disable_all(struct ltt_kernel_channel *kchan); +int event_kernel_disable_event_type(struct ltt_kernel_channel *kchan, + enum lttng_event_type type); +int event_kernel_disable_event_all(struct ltt_kernel_channel *kchan); -int event_kernel_enable_tracepoint(struct ltt_kernel_channel *kchan, +int event_kernel_enable_event(struct ltt_kernel_channel *kchan, struct lttng_event *event); -int event_kernel_enable_syscall(struct ltt_kernel_channel *kchan, - char *syscall_name); int event_ust_enable_tracepoint(struct ltt_ust_session *usess, struct ltt_ust_channel *uchan, struct lttng_event *event, diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 59d86f45a..bf9f8b623 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -209,19 +209,7 @@ int kernel_create_event(struct lttng_event *ev, goto free_event; } - /* - * LTTNG_KERNEL_SYSCALL event creation will return 0 on success. - */ - if (ret == 0 && event->event->instrumentation == LTTNG_KERNEL_SYSCALL) { - DBG2("Kernel event syscall creation success"); - /* - * We use fd == -1 to ensure that we never trigger a close of fd - * 0. - */ - event->fd = -1; - goto add_list; - } - + event->type = ev->type; event->fd = ret; /* Prevent fd duplication after execlp() */ ret = fcntl(event->fd, F_SETFD, FD_CLOEXEC); @@ -229,7 +217,6 @@ int kernel_create_event(struct lttng_event *ev, PERROR("fcntl session fd"); } -add_list: /* Add event to event list */ cds_list_add(&event->list, &channel->events_list.head); channel->event_count++; @@ -355,17 +342,6 @@ error: return ret; } -int kernel_enable_syscall(const char *syscall_name, - struct ltt_kernel_channel *channel) -{ - return kernctl_enable_syscall(channel->fd, syscall_name); -} - -int kernel_disable_syscall(const char *syscall_name, - struct ltt_kernel_channel *channel) -{ - return kernctl_disable_syscall(channel->fd, syscall_name); -} int kernel_track_pid(struct ltt_kernel_session *session, int pid) { diff --git a/src/bin/lttng-sessiond/kernel.h b/src/bin/lttng-sessiond/kernel.h index a2d19f143..2f7cc15fb 100644 --- a/src/bin/lttng-sessiond/kernel.h +++ b/src/bin/lttng-sessiond/kernel.h @@ -42,10 +42,6 @@ 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_enable_syscall(const char *syscall_name, - struct ltt_kernel_channel *channel); -int kernel_disable_syscall(const char *syscall_name, - struct ltt_kernel_channel *channel); int kernel_track_pid(struct ltt_kernel_session *session, int pid); int kernel_untrack_pid(struct ltt_kernel_session *session, int pid); int kernel_open_metadata(struct ltt_kernel_session *session); diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index 1069d1f8f..ab3282a17 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.c @@ -62,7 +62,8 @@ struct ltt_kernel_channel *trace_kernel_get_channel_by_name( * Find the event name for the given channel. */ struct ltt_kernel_event *trace_kernel_get_event_by_name( - char *name, struct ltt_kernel_channel *channel) + char *name, struct ltt_kernel_channel *channel, + enum lttng_event_type type) { struct ltt_kernel_event *ev; @@ -70,6 +71,8 @@ struct ltt_kernel_event *trace_kernel_get_event_by_name( assert(channel); cds_list_for_each_entry(ev, &channel->events_list.head, list) { + if (type != LTTNG_EVENT_ALL && ev->type != type) + continue; if (strcmp(name, ev->event->name) == 0) { DBG("Found event by name %s for channel %s", name, channel->channel->name); diff --git a/src/bin/lttng-sessiond/trace-kernel.h b/src/bin/lttng-sessiond/trace-kernel.h index db91b2ed2..5c518135d 100644 --- a/src/bin/lttng-sessiond/trace-kernel.h +++ b/src/bin/lttng-sessiond/trace-kernel.h @@ -51,6 +51,7 @@ struct ltt_kernel_context { struct ltt_kernel_event { int fd; int enabled; + enum lttng_event_type type; struct lttng_kernel_event *event; struct cds_list_head list; }; @@ -122,7 +123,8 @@ struct ltt_kernel_session { * Lookup functions. NULL is returned if not found. */ struct ltt_kernel_event *trace_kernel_get_event_by_name( - char *name, struct ltt_kernel_channel *channel); + char *name, struct ltt_kernel_channel *channel, + enum lttng_event_type type); struct ltt_kernel_channel *trace_kernel_get_channel_by_name( char *name, struct ltt_kernel_session *session); diff --git a/src/common/kernel-ctl/kernel-ctl.c b/src/common/kernel-ctl/kernel-ctl.c index c6ff5c445..51d013413 100644 --- a/src/common/kernel-ctl/kernel-ctl.c +++ b/src/common/kernel-ctl/kernel-ctl.c @@ -142,30 +142,6 @@ int kernctl_create_channel(int fd, struct lttng_channel_attr *chops) return ioctl(fd, LTTNG_KERNEL_CHANNEL, &channel); } -int kernctl_enable_syscall(int fd, const char *syscall_name) -{ - struct lttng_kernel_event event; - - memset(&event, 0, sizeof(event)); - strncpy(event.name, syscall_name, sizeof(event.name)); - event.name[sizeof(event.name) - 1] = '\0'; - event.instrumentation = LTTNG_KERNEL_SYSCALL; - event.u.syscall.enable = 1; - return ioctl(fd, LTTNG_KERNEL_EVENT, &event); -} - -int kernctl_disable_syscall(int fd, const char *syscall_name) -{ - struct lttng_kernel_event event; - - memset(&event, 0, sizeof(event)); - strncpy(event.name, syscall_name, sizeof(event.name)); - event.name[sizeof(event.name) - 1] = '\0'; - event.instrumentation = LTTNG_KERNEL_SYSCALL; - event.u.syscall.enable = 0; - return ioctl(fd, LTTNG_KERNEL_EVENT, &event); -} - int kernctl_syscall_mask(int fd, char **syscall_mask, uint32_t *nr_bits) { struct lttng_kernel_syscall_mask kmask_len, *kmask = NULL; diff --git a/src/common/kernel-ctl/kernel-ctl.h b/src/common/kernel-ctl/kernel-ctl.h index 5f2e014d1..d8e69809e 100644 --- a/src/common/kernel-ctl/kernel-ctl.h +++ b/src/common/kernel-ctl/kernel-ctl.h @@ -42,9 +42,6 @@ int kernctl_tracer_abi_version(int fd, struct lttng_kernel_tracer_abi_version *v int kernctl_wait_quiescent(int fd); int kernctl_calibrate(int fd, struct lttng_kernel_calibrate *calibrate); -int kernctl_enable_syscall(int fd, const char *syscall_name); -int kernctl_disable_syscall(int fd, const char *syscall_name); - /* * kernctl_syscall_mask - Get syscall mask associated to a channel FD. * diff --git a/src/common/lttng-kernel.h b/src/common/lttng-kernel.h index abd22c99b..833624842 100644 --- a/src/common/lttng-kernel.h +++ b/src/common/lttng-kernel.h @@ -97,10 +97,6 @@ struct lttng_kernel_function { char symbol_name[LTTNG_KERNEL_SYM_NAME_LEN]; } LTTNG_PACKED; -struct lttng_kernel_syscall { - char enable; -} __attribute__((packed)); - #define LTTNG_KERNEL_EVENT_PADDING1 16 #define LTTNG_KERNEL_EVENT_PADDING2 LTTNG_KERNEL_SYM_NAME_LEN + 32 struct lttng_kernel_event { @@ -113,7 +109,6 @@ struct lttng_kernel_event { struct lttng_kernel_kretprobe kretprobe; struct lttng_kernel_kprobe kprobe; struct lttng_kernel_function ftrace; - struct lttng_kernel_syscall syscall; char padding[LTTNG_KERNEL_EVENT_PADDING2]; } u; } LTTNG_PACKED;