bytecode: generalize `struct lttng_filter_bytecode_node`
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 12 May 2020 19:52:41 +0000 (15:52 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 Nov 2020 18:13:35 +0000 (13:13 -0500)
Rename `struct lttng_filter_bytecode_node` to `struct
lttng_bytecode_node` so it can be used by capture bytecode as well.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I27162522bb20d0fdce6af551fbd982a791d1067c

include/lttng/events.h
src/lttng-events.c
src/lttng-filter.c

index 194e89004cb3b451c17719990c3266e9deb9f139..517d689b049f05d679fa4a205da31d2b20cb1e10 100644 (file)
@@ -232,14 +232,20 @@ enum lttng_event_type {
        LTTNG_TYPE_ENABLER = 1,
 };
 
-struct lttng_filter_bytecode_node {
+enum lttng_bytecode_node_type {
+       LTTNG_BYTECODE_NODE_TYPE_FILTER,
+};
+
+struct lttng_bytecode_node {
+       enum lttng_bytecode_node_type type;
        struct list_head node;
        struct lttng_enabler *enabler;
-       /*
-        * struct lttng_kernel_filter_bytecode has var. sized array, must be
-        * last field.
-        */
-       struct lttng_kernel_filter_bytecode bc;
+       struct {
+               uint32_t len;
+               uint32_t reloc_offset;
+               uint64_t seqnum;
+               char data[];
+       } bc;
 };
 
 /*
@@ -253,8 +259,9 @@ enum lttng_filter_ret {
 
 struct lttng_bytecode_runtime {
        /* Associated bytecode */
-       struct lttng_filter_bytecode_node *bc;
-       uint64_t (*filter)(void *filter_data, struct lttng_probe_ctx *lttng_probe_ctx,
+       struct lttng_bytecode_node *bc;
+       uint64_t (*filter)(void *filter_data,
+                       struct lttng_probe_ctx *lttng_probe_ctx,
                        const char *filter_stack_data);
        int link_failed;
        struct list_head node;  /* list of bytecode runtime in event */
index 85a064fc686cc1d13cd4bf3a9775a36a9820b5e4..c8cf7621a95c35eb70bbc9f99f195fa38d7de264 100644 (file)
@@ -2217,7 +2217,7 @@ static
 int lttng_enabler_attach_filter_bytecode(struct lttng_enabler *enabler,
                struct lttng_kernel_filter_bytecode __user *bytecode)
 {
-       struct lttng_filter_bytecode_node *bytecode_node;
+       struct lttng_bytecode_node *bytecode_node;
        uint32_t bytecode_len;
        int ret;
 
@@ -2233,6 +2233,7 @@ int lttng_enabler_attach_filter_bytecode(struct lttng_enabler *enabler,
        if (ret)
                goto error_free;
 
+       bytecode_node->type = LTTNG_BYTECODE_NODE_TYPE_FILTER;
        bytecode_node->enabler = enabler;
        /* Enforce length based on allocated size */
        bytecode_node->bc.len = bytecode_len;
@@ -2282,7 +2283,7 @@ int lttng_event_enabler_attach_context(struct lttng_event_enabler *event_enabler
 static
 void lttng_enabler_destroy(struct lttng_enabler *enabler)
 {
-       struct lttng_filter_bytecode_node *filter_node, *tmp_filter_node;
+       struct lttng_bytecode_node *filter_node, *tmp_filter_node;
 
        /* Destroy filter bytecode */
        list_for_each_entry_safe(filter_node, tmp_filter_node,
index e24202408715a8e16f08a0e249af68fc1f0f44ba..a0ad3085611f76d841313c161bcfddd30ee54734 100644 (file)
@@ -378,13 +378,13 @@ int apply_reloc(const struct lttng_event_desc *event_desc,
 }
 
 static
-int bytecode_is_linked(struct lttng_filter_bytecode_node *filter_bytecode,
+int bytecode_is_linked(struct lttng_bytecode_node *bytecode,
                struct list_head *bytecode_runtime_head)
 {
        struct lttng_bytecode_runtime *bc_runtime;
 
        list_for_each_entry(bc_runtime, bytecode_runtime_head, node) {
-               if (bc_runtime->bc == filter_bytecode)
+               if (bc_runtime->bc == bytecode)
                        return 1;
        }
        return 0;
@@ -397,44 +397,44 @@ int bytecode_is_linked(struct lttng_filter_bytecode_node *filter_bytecode,
 static
 int _lttng_filter_link_bytecode(const struct lttng_event_desc *event_desc,
                struct lttng_ctx *ctx,
-               struct lttng_filter_bytecode_node *filter_bytecode,
+               struct lttng_bytecode_node *bytecode,
                struct list_head *insert_loc)
 {
        int ret, offset, next_offset;
        struct bytecode_runtime *runtime = NULL;
        size_t runtime_alloc_len;
 
-       if (!filter_bytecode)
+       if (!bytecode)
                return 0;
        /* Bytecode already linked */
-       if (bytecode_is_linked(filter_bytecode, insert_loc))
+       if (bytecode_is_linked(bytecode, insert_loc))
                return 0;
 
        dbg_printk("Linking...\n");
 
        /* We don't need the reloc table in the runtime */
-       runtime_alloc_len = sizeof(*runtime) + filter_bytecode->bc.reloc_offset;
+       runtime_alloc_len = sizeof(*runtime) + bytecode->bc.reloc_offset;
        runtime = kzalloc(runtime_alloc_len, GFP_KERNEL);
        if (!runtime) {
                ret = -ENOMEM;
                goto alloc_error;
        }
-       runtime->p.bc = filter_bytecode;
+       runtime->p.bc = bytecode;
        runtime->p.ctx = ctx;
-       runtime->len = filter_bytecode->bc.reloc_offset;
+       runtime->len = bytecode->bc.reloc_offset;
        /* copy original bytecode */
-       memcpy(runtime->code, filter_bytecode->bc.data, runtime->len);
+       memcpy(runtime->code, bytecode->bc.data, runtime->len);
        /*
         * apply relocs. Those are a uint16_t (offset in bytecode)
         * followed by a string (field name).
         */
-       for (offset = filter_bytecode->bc.reloc_offset;
-                       offset < filter_bytecode->bc.len;
+       for (offset = bytecode->bc.reloc_offset;
+                       offset < bytecode->bc.len;
                        offset = next_offset) {
                uint16_t reloc_offset =
-                       *(uint16_t *) &filter_bytecode->bc.data[offset];
+                       *(uint16_t *) &bytecode->bc.data[offset];
                const char *name =
-                       (const char *) &filter_bytecode->bc.data[offset + sizeof(uint16_t)];
+                       (const char *) &bytecode->bc.data[offset + sizeof(uint16_t)];
 
                ret = apply_reloc(event_desc, runtime, runtime->len, reloc_offset, name);
                if (ret) {
@@ -469,7 +469,7 @@ alloc_error:
 
 void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime)
 {
-       struct lttng_filter_bytecode_node *bc = runtime->bc;
+       struct lttng_bytecode_node *bc = runtime->bc;
 
        if (!bc->enabler->enabled || runtime->link_failed)
                runtime->filter = lttng_filter_interpret_bytecode_false;
@@ -485,7 +485,7 @@ void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc,
                struct list_head *bytecode_runtime_head,
                struct lttng_enabler *enabler)
 {
-       struct lttng_filter_bytecode_node *bc;
+       struct lttng_bytecode_node *bc;
        struct lttng_bytecode_runtime *runtime;
 
        /* Can only be called for events with desc attached */
@@ -536,7 +536,7 @@ void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc,
  * We own the filter_bytecode if we return success.
  */
 int lttng_filter_enabler_attach_bytecode(struct lttng_enabler *enabler,
-               struct lttng_filter_bytecode_node *filter_bytecode)
+               struct lttng_bytecode_node *filter_bytecode)
 {
        list_add(&filter_bytecode->node, &enabler->filter_bytecode_head);
        return 0;
@@ -544,7 +544,7 @@ int lttng_filter_enabler_attach_bytecode(struct lttng_enabler *enabler,
 
 void lttng_free_enabler_filter_bytecode(struct lttng_enabler *enabler)
 {
-       struct lttng_filter_bytecode_node *filter_bytecode, *tmp;
+       struct lttng_bytecode_node *filter_bytecode, *tmp;
 
        list_for_each_entry_safe(filter_bytecode, tmp,
                        &enabler->filter_bytecode_head, node) {
This page took 0.030563 seconds and 4 git commands to generate.