Support capture for kernel tracer
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 13 May 2020 23:02:43 +0000 (19:02 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 16 Mar 2021 20:40:01 +0000 (16:40 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I26167d259daa8e356a1bb03831ccf6e570b8e305
Depends-on: lttng-ust: I8423c510bf6af2f9bf85256e8d6f931d36f7054b

src/bin/lttng-sessiond/kernel.c
src/bin/lttng-sessiond/notification-thread-events.c
src/common/kernel-ctl/kernel-ctl.c
src/common/kernel-ctl/kernel-ctl.h
src/common/kernel-ctl/kernel-ioctl.h
src/common/lttng-kernel.h

index 23e8eac2a9f82ee12ea57f879b9df4481a177af3..54e745474d89c8c891bc78f8a35b8ce742f53cd0 100644 (file)
@@ -2299,8 +2299,10 @@ static enum lttng_error_code kernel_create_event_notifier_rule(
        enum lttng_event_rule_type event_rule_type;
        struct ltt_kernel_event_notifier_rule *event_notifier_rule;
        struct lttng_kernel_event_notifier kernel_event_notifier = {};
+       unsigned int capture_bytecode_count = 0, i;
        const struct lttng_condition *condition = NULL;
        const struct lttng_event_rule *event_rule = NULL;
+       enum lttng_condition_status cond_status;
 
        assert(trigger);
 
@@ -2393,6 +2395,31 @@ static enum lttng_error_code kernel_create_event_notifier_rule(
                }
        }
 
+       /* Set the capture bytecode, if any. */
+       cond_status = lttng_condition_event_rule_get_capture_descriptor_count(
+                       condition, &capture_bytecode_count);
+       assert(cond_status == LTTNG_CONDITION_STATUS_OK);
+
+       for (i = 0; i < capture_bytecode_count; i++) {
+               const struct lttng_bytecode *capture_bytecode =
+                               lttng_condition_event_rule_get_capture_bytecode_at_index(
+                                               condition, i);
+
+               if (capture_bytecode == NULL) {
+                       ERR("Unexpected NULL capture bytecode on condition");
+                       error_code_ret = LTTNG_ERR_KERN_ENABLE_FAIL;
+                       goto error;
+               }
+
+               ret = kernctl_capture(event_notifier_rule->fd, capture_bytecode);
+               if (ret < 0) {
+                       ERR("Failed to set capture bytecode on event notifier rule fd: fd = %d",
+                                       event_notifier_rule->fd);
+                       error_code_ret = LTTNG_ERR_KERN_ENABLE_FAIL;
+                       goto error;
+               }
+       }
+
        err = kernctl_enable(event_notifier_rule->fd);
        if (err < 0) {
                switch (-err) {
index ccd285a8103d6a344bcb3344abbd982f079a0c13..413f1848b44f1fa7986db6aa023661c9f06c305c 100644 (file)
@@ -4291,7 +4291,7 @@ struct lttng_event_notifier_notification *recv_one_event_notifier_notification(
                break;
        case LTTNG_DOMAIN_KERNEL:
                token = kernel_notification.token;
-               capture_buffer_size = 0;
+               capture_buffer_size = kernel_notification.capture_buf_size;
                break;
        default:
                abort();
index bb6602e2bffb57f676514313b462b5e8b62645e6..94e22ff0691170ad5db2f856b4bd512cd9f7e9d7 100644 (file)
@@ -437,6 +437,28 @@ int kernctl_create_event_notifier(int group_fd,
                        LTTNG_KERNEL_EVENT_NOTIFIER_CREATE, event_notifier);
 }
 
+int kernctl_capture(int fd, const struct lttng_bytecode *capture)
+{
+       int ret;
+       struct lttng_kernel_capture_bytecode *kb;
+
+       /* Translate bytecode to kernel bytecode. */
+       kb = zmalloc(sizeof(*kb) + capture->len);
+       if (!kb) {
+               ret = -ENOMEM;
+               goto end;
+       }
+
+       kb->len = capture->len;
+       kb->reloc_offset = capture->reloc_table_offset;
+       kb->seqnum = capture->seqnum;
+       memcpy(kb->data, capture->data, capture->len);
+       ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_CAPTURE, kb);
+       free(kb);
+end:
+       return ret;
+}
+
 int kernctl_filter(int fd, const struct lttng_bytecode *filter)
 {
        struct lttng_kernel_filter_bytecode *kb;
index 3bbe69f48ce41c9d8b163dc3d8032fed27133406..25cb3b52b57df1e61c0ba58cdc562b3b522efa8e 100644 (file)
@@ -38,6 +38,7 @@ int kernctl_create_event_notifier(int fd,
 /* Apply on event file descriptor. */
 int kernctl_filter(int fd, const struct lttng_bytecode *filter);
 int kernctl_add_callsite(int fd, struct lttng_kernel_event_callsite *callsite);
+int kernctl_capture(int fd, const struct lttng_bytecode *capture);
 
 int kernctl_tracepoint_list(int fd);
 int kernctl_syscall_list(int fd);
index 8fa0a7d100c480ad8416ce06395d1fee2146fe73..f68d5d156ca5af9cba4d296de23065cf9f0a7658 100644 (file)
 #define LTTNG_KERNEL_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD      \
        _IO(0xF6, 0xB1)
 
+/* Trigger file descriptor ioctl */
+#define LTTNG_KERNEL_CAPTURE                   _IO(0xF6, 0xB8)
+
 #endif /* _LTT_KERNEL_IOCTL_H */
index cd343bb766c81ea39f7f2ae8dbcd6de058954679..e8647f439fcdd0dc7c638899504b8978179a750f 100644 (file)
@@ -184,12 +184,21 @@ struct lttng_kernel_event_notifier {
        char padding[LTTNG_KERNEL_EVENT_NOTIFIER_PADDING];
 } LTTNG_PACKED;
 
-#define LTTNG_KERNEL_EVENT_NOTIFIER_NOTIFICATION_PADDING 34
+#define LTTNG_KERNEL_EVENT_NOTIFIER_NOTIFICATION_PADDING 32
 struct lttng_kernel_event_notifier_notification {
        uint64_t token;
+       uint16_t capture_buf_size;
        char padding[LTTNG_KERNEL_EVENT_NOTIFIER_NOTIFICATION_PADDING];
 } LTTNG_PACKED;
 
+#define LTTNG_KERNEL_CAPTURE_BYTECODE_MAX_LEN          65536
+struct lttng_kernel_capture_bytecode {
+       uint32_t len;
+       uint32_t reloc_offset;
+       uint64_t seqnum;
+       char data[0];
+} LTTNG_PACKED;
+
 struct lttng_kernel_tracer_version {
        uint32_t major;
        uint32_t minor;
This page took 0.038755 seconds and 4 git commands to generate.