Refactoring: add/remove to/from dispatch list on enable/disable event for event recorder
[lttng-modules.git] / src / lttng-syscalls.c
index af81267138c2b27569bac38ea7c7a14376b72545..6f5215f281d2785a6178f07cfb34dca3614946bd 100644 (file)
@@ -577,8 +577,9 @@ void lttng_syscall_event_enabler_create_event(struct lttng_event_enabler_common
                        printk(KERN_INFO "Unable to create event recorder %s\n", desc->event_name);
                        return;
                }
+               event->priv->u.syscall.syscall_id = syscall_nr;
                if (dispatch_table)
-                       hlist_add_head_rcu(&event->priv->u.syscall.node, &dispatch_table[syscall_nr]);
+                       hlist_add_head_rcu(&event->priv->u.syscall.node, dispatch_table);
                break;
        }
        case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
@@ -647,6 +648,9 @@ void lttng_syscall_event_enabler_create_matching_events(struct lttng_event_enabl
        const struct lttng_kernel_event_desc *desc;
        unsigned int i;
 
+       if (!IS_ENABLED(CONFIG_COMPAT) && (type == SC_TYPE_COMPAT_ENTRY || type == SC_TYPE_COMPAT_EXIT))
+               return;
+
        /* iterate over all syscall and create event_notifier that match */
        for (i = 0; i < table_len; i++) {
                struct lttng_kernel_event_common_private *event_priv;
@@ -702,6 +706,9 @@ void create_unknown_syscall_event(struct lttng_event_enabler_common *event_enabl
        bool found = false;
        struct hlist_head *head;
 
+       if (!IS_ENABLED(CONFIG_COMPAT) && (type == SC_TYPE_COMPAT_ENTRY || type == SC_TYPE_COMPAT_EXIT))
+               return;
+
        /*
         * Considering that currently system calls can only be enabled on a per
         * name basis (or wildcard based on a name), unknown syscall events are
@@ -750,7 +757,6 @@ void create_unknown_syscall_event(struct lttng_event_enabler_common *event_enabl
 static
 int lttng_syscalls_populate_events(struct lttng_event_enabler_common *syscall_event_enabler)
 {
-       struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_enabler(syscall_event_enabler);
        struct lttng_event_recorder_enabler *event_recorder_enabler;
        struct lttng_kernel_channel_buffer *chan;
        int ret;
@@ -761,20 +767,19 @@ int lttng_syscalls_populate_events(struct lttng_event_enabler_common *syscall_ev
        chan = event_recorder_enabler->chan;
 
        lttng_syscall_event_enabler_create_matching_events(&event_recorder_enabler->parent, sc_table.table, sc_table.len,
-                       syscall_table->syscall_dispatch, SC_TYPE_ENTRY);
+                       NULL, SC_TYPE_ENTRY);
        lttng_syscall_event_enabler_create_matching_events(&event_recorder_enabler->parent, sc_exit_table.table, sc_exit_table.len,
-                       syscall_table->syscall_exit_dispatch, SC_TYPE_EXIT);
+                       NULL, SC_TYPE_EXIT);
        create_unknown_syscall_event(syscall_event_enabler, SC_TYPE_ENTRY);
        create_unknown_syscall_event(syscall_event_enabler, SC_TYPE_EXIT);
 
-#ifdef CONFIG_COMPAT
        lttng_syscall_event_enabler_create_matching_events(&event_recorder_enabler->parent, compat_sc_table.table, compat_sc_table.len,
-                       syscall_table->compat_syscall_dispatch, SC_TYPE_COMPAT_ENTRY);
+                       NULL, SC_TYPE_COMPAT_ENTRY);
        lttng_syscall_event_enabler_create_matching_events(&event_recorder_enabler->parent, compat_sc_exit_table.table, compat_sc_exit_table.len,
-                       syscall_table->compat_syscall_exit_dispatch, SC_TYPE_COMPAT_EXIT);
+                       NULL, SC_TYPE_COMPAT_EXIT);
        create_unknown_syscall_event(syscall_event_enabler, SC_TYPE_COMPAT_ENTRY);
        create_unknown_syscall_event(syscall_event_enabler, SC_TYPE_COMPAT_EXIT);
-#endif
+
        return ret;
 }
 
@@ -799,7 +804,6 @@ int lttng_event_enabler_create_syscall_events_if_missing(struct lttng_event_enab
                        return -ENOMEM;
        }
 
-
 #ifdef CONFIG_COMPAT
        if (!syscall_table->compat_syscall_dispatch) {
                /* create syscall table mapping compat syscall to events */
@@ -1066,6 +1070,8 @@ int lttng_syscall_filter_enable(
 int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event)
 {
        struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_event(event);
+       unsigned int syscall_id = event->priv->u.syscall.syscall_id;
+       struct hlist_head *dispatch_list;
        int ret;
 
        WARN_ON_ONCE(event->priv->instrumentation != LTTNG_KERNEL_ABI_SYSCALL);
@@ -1076,53 +1082,39 @@ int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event)
        if (ret)
                return ret;
 
-       switch (event->type) {
-       case LTTNG_KERNEL_EVENT_TYPE_RECORDER:
+       switch (event->priv->u.syscall.entryexit) {
+       case LTTNG_SYSCALL_ENTRY:
+               switch (event->priv->u.syscall.abi) {
+               case LTTNG_SYSCALL_ABI_NATIVE:
+                       dispatch_list = &syscall_table->syscall_dispatch[syscall_id];
+                       break;
+               case LTTNG_SYSCALL_ABI_COMPAT:
+                       dispatch_list = &syscall_table->compat_syscall_dispatch[syscall_id];
+                       break;
+               default:
+                       ret = -EINVAL;
+                       goto end;
+               }
                break;
-       case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER:
-       {
-               unsigned int syscall_id = event->priv->u.syscall.syscall_id;
-               struct hlist_head *dispatch_list;
-
-               switch (event->priv->u.syscall.entryexit) {
-               case LTTNG_SYSCALL_ENTRY:
-                       switch (event->priv->u.syscall.abi) {
-                       case LTTNG_SYSCALL_ABI_NATIVE:
-                               dispatch_list = &syscall_table->syscall_dispatch[syscall_id];
-                               break;
-                       case LTTNG_SYSCALL_ABI_COMPAT:
-                               dispatch_list = &syscall_table->compat_syscall_dispatch[syscall_id];
-                               break;
-                       default:
-                               ret = -EINVAL;
-                               goto end;
-                       }
+       case LTTNG_SYSCALL_EXIT:
+               switch (event->priv->u.syscall.abi) {
+               case LTTNG_SYSCALL_ABI_NATIVE:
+                       dispatch_list = &syscall_table->syscall_exit_dispatch[syscall_id];
                        break;
-               case LTTNG_SYSCALL_EXIT:
-                       switch (event->priv->u.syscall.abi) {
-                       case LTTNG_SYSCALL_ABI_NATIVE:
-                               dispatch_list = &syscall_table->syscall_exit_dispatch[syscall_id];
-                               break;
-                       case LTTNG_SYSCALL_ABI_COMPAT:
-                               dispatch_list = &syscall_table->compat_syscall_exit_dispatch[syscall_id];
-                               break;
-                       default:
-                               ret = -EINVAL;
-                               goto end;
-                       }
+               case LTTNG_SYSCALL_ABI_COMPAT:
+                       dispatch_list = &syscall_table->compat_syscall_exit_dispatch[syscall_id];
                        break;
                default:
                        ret = -EINVAL;
                        goto end;
                }
-
-               hlist_add_head_rcu(&event->priv->u.syscall.node, dispatch_list);
                break;
-       }
        default:
-               WARN_ON_ONCE(1);
-               return -ENOSYS;
+               ret = -EINVAL;
+               goto end;
        }
+
+       hlist_add_head_rcu(&event->priv->u.syscall.node, dispatch_list);
 end:
        return ret;
 }
@@ -1196,19 +1188,7 @@ int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common *event)
                event->priv->u.syscall.entryexit);
        if (ret)
                return ret;
-
-       switch (event->type) {
-       case LTTNG_KERNEL_EVENT_TYPE_RECORDER:
-               break;
-       case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER:
-       {
-               hlist_del_rcu(&event->priv->u.syscall.node);
-               break;
-       }
-       default:
-               WARN_ON_ONCE(1);
-               return -ENOSYS;
-       }
+       hlist_del_rcu(&event->priv->u.syscall.node);
        return 0;
 }
 
This page took 0.030424 seconds and 4 git commands to generate.