Refactoring: combine event enabler destroy for notifier and recorder
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 1 Nov 2021 18:47:24 +0000 (14:47 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 1 Nov 2021 19:04:35 +0000 (15:04 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I39ed3d9046604e5ab16f3e565ba72460348f54f5

include/lttng/events-internal.h
src/lttng-abi.c
src/lttng-events.c
src/lttng-syscalls.c

index 8ac1b01b6f61ca9aed4dfb0878f81eef6424d703..416e0fea0839e08af70280387fd523dec1ca3c68 100644 (file)
@@ -785,22 +785,21 @@ struct lttng_event_recorder_enabler *lttng_event_recorder_enabler_create(
                struct lttng_kernel_channel_buffer *chan);
 void lttng_event_enabler_session_add(struct lttng_kernel_session *session,
                struct lttng_event_recorder_enabler *event_enabler);
-void lttng_event_enabler_destroy(struct lttng_event_recorder_enabler *event_enabler);
-
-int lttng_event_enabler_enable(struct lttng_event_enabler_common *event_enabler);
-int lttng_event_enabler_disable(struct lttng_event_enabler_common *event_enabler);
 
 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
                struct lttng_event_notifier_group *event_notifier_group,
                enum lttng_enabler_format_type format_type,
                struct lttng_kernel_abi_event_notifier *event_notifier_param);
-
-int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler_common *event_enabler,
-               struct lttng_kernel_abi_filter_bytecode __user *bytecode);
 int lttng_event_notifier_enabler_attach_capture_bytecode(
                struct lttng_event_notifier_enabler *event_notifier_enabler,
                struct lttng_kernel_abi_capture_bytecode __user *bytecode);
 
+int lttng_event_enabler_enable(struct lttng_event_enabler_common *event_enabler);
+int lttng_event_enabler_disable(struct lttng_event_enabler_common *event_enabler);
+int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler_common *event_enabler,
+               struct lttng_kernel_abi_filter_bytecode __user *bytecode);
+void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enabler);
+
 int lttng_desc_match_enabler(const struct lttng_kernel_event_desc *desc,
                struct lttng_event_enabler_common *enabler);
 
index 8eeb632a227c0c24f9fab902dbc386b2c4b12715..7eafe2d09ff1403738ce00442ac18f458dd73606 100644 (file)
@@ -1927,7 +1927,7 @@ int lttng_abi_create_event(struct file *channel_file,
                 */
                event = lttng_kernel_event_recorder_create(event_enabler, NULL);
                WARN_ON_ONCE(!event);
-               lttng_event_enabler_destroy(event_enabler);
+               lttng_event_enabler_destroy(&event_enabler->parent);
                if (IS_ERR(event)) {
                        ret = PTR_ERR(event);
                        goto event_error;
index f864eaba57db0d881f916eba7a49b6254b3ca6fe..f5c0fa95a5233e604e4312c2b6c773dc6a87960f 100644 (file)
@@ -66,7 +66,6 @@ static struct kmem_cache *event_notifier_private_cache;
 
 static void lttng_session_lazy_sync_event_enablers(struct lttng_kernel_session *session);
 static void lttng_session_sync_event_enablers(struct lttng_kernel_session *session);
-static void lttng_event_notifier_enabler_destroy(struct lttng_event_notifier_enabler *event_notifier_enabler);
 static void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group *event_notifier_group);
 static void lttng_event_enabler_sync(struct lttng_event_enabler_common *event_enabler);
 
@@ -355,7 +354,7 @@ void lttng_session_destroy(struct lttng_kernel_session *session)
        struct lttng_kernel_channel_buffer_private *chan_priv, *tmpchan_priv;
        struct lttng_kernel_event_recorder_private *event_recorder_priv, *tmpevent_recorder_priv;
        struct lttng_metadata_stream *metadata_stream;
-       struct lttng_event_recorder_enabler *event_enabler, *tmp_event_enabler;
+       struct lttng_event_recorder_enabler *event_recorder_enabler, *tmp_event_recorder_enabler;
        int ret;
 
        mutex_lock(&sessions_mutex);
@@ -373,9 +372,9 @@ void lttng_session_destroy(struct lttng_kernel_session *session)
                ret = lttng_syscalls_destroy_event(chan_priv->pub);
                WARN_ON(ret);
        }
-       list_for_each_entry_safe(event_enabler, tmp_event_enabler,
+       list_for_each_entry_safe(event_recorder_enabler, tmp_event_recorder_enabler,
                        &session->priv->enablers_head, node)
-               lttng_event_enabler_destroy(event_enabler);
+               lttng_event_enabler_destroy(&event_recorder_enabler->parent);
        list_for_each_entry_safe(event_recorder_priv, tmpevent_recorder_priv, &session->priv->events, node)
                _lttng_event_destroy(&event_recorder_priv->pub->parent);
        list_for_each_entry_safe(chan_priv, tmpchan_priv, &session->priv->chan, node) {
@@ -429,7 +428,7 @@ void lttng_event_notifier_group_destroy(
 
        list_for_each_entry_safe(event_notifier_enabler, tmp_event_notifier_enabler,
                        &event_notifier_group->enablers_head, node)
-               lttng_event_notifier_enabler_destroy(event_notifier_enabler);
+               lttng_event_enabler_destroy(&event_notifier_enabler->parent);
 
        list_for_each_entry_safe(event_notifier_priv, tmpevent_notifier_priv,
                        &event_notifier_group->event_notifiers_head, node)
@@ -2593,13 +2592,33 @@ void lttng_enabler_destroy(struct lttng_event_enabler_common *enabler)
        }
 }
 
-void lttng_event_enabler_destroy(struct lttng_event_recorder_enabler *event_enabler)
+void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enabler)
 {
-       lttng_enabler_destroy(lttng_event_recorder_enabler_as_enabler(event_enabler));
+       switch (event_enabler->enabler_type) {
+       case LTTNG_EVENT_ENABLER_TYPE_RECORDER:
+       {
+               struct lttng_event_recorder_enabler *event_recorder_enabler =
+                       container_of(event_enabler, struct lttng_event_recorder_enabler, parent);
 
-       if (event_enabler->published)
-               list_del(&event_enabler->node);
-       kfree(event_enabler);
+               lttng_enabler_destroy(event_enabler);
+               if (event_recorder_enabler->published)
+                       list_del(&event_recorder_enabler->node);
+               kfree(event_recorder_enabler);
+               break;
+       }
+       case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
+       {
+               struct lttng_event_notifier_enabler *event_notifier_enabler =
+                       container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
+
+               list_del(&event_notifier_enabler->node);
+               lttng_enabler_destroy(event_enabler);
+               kfree(event_notifier_enabler);
+               break;
+       }
+       default:
+               WARN_ON_ONCE(1);
+       }
 }
 
 struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
@@ -2699,20 +2718,6 @@ end:
        return ret;
 }
 
-static
-void lttng_event_notifier_enabler_destroy(
-               struct lttng_event_notifier_enabler *event_notifier_enabler)
-{
-       if (!event_notifier_enabler) {
-               return;
-       }
-
-       list_del(&event_notifier_enabler->node);
-
-       lttng_enabler_destroy(lttng_event_notifier_enabler_as_enabler(event_notifier_enabler));
-       kfree(event_notifier_enabler);
-}
-
 /*
  * lttng_session_sync_event_enablers should be called just before starting a
  * session.
index 34dc138e41718968cc2a7c06e7802e583fb8977d..c68baab785b43aac6c1ae81a6d05c0af95a797f0 100644 (file)
@@ -598,7 +598,7 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl
                }
                event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc);
                WARN_ON_ONCE(!event_recorder);
-               lttng_event_enabler_destroy(event_enabler);
+               lttng_event_enabler_destroy(&event_enabler->parent);
                if (IS_ERR(event_recorder)) {
                        /*
                         * If something goes wrong in event registration
@@ -670,7 +670,7 @@ int lttng_syscalls_register_event(struct lttng_event_recorder_enabler *syscall_e
                        return -ENOMEM;
                }
                event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc);
-               lttng_event_enabler_destroy(event_enabler);
+               lttng_event_enabler_destroy(&event_enabler->parent);
                WARN_ON_ONCE(!event_recorder);
                if (IS_ERR(event_recorder)) {
                        return PTR_ERR(event_recorder);
@@ -696,7 +696,7 @@ int lttng_syscalls_register_event(struct lttng_event_recorder_enabler *syscall_e
                }
                event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc);
                WARN_ON_ONCE(!event_recorder);
-               lttng_event_enabler_destroy(event_enabler);
+               lttng_event_enabler_destroy(&event_enabler->parent);
                if (IS_ERR(event_recorder)) {
                        return PTR_ERR(event_recorder);
                }
@@ -721,7 +721,7 @@ int lttng_syscalls_register_event(struct lttng_event_recorder_enabler *syscall_e
                }
                event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc);
                WARN_ON_ONCE(!event_recorder);
-               lttng_event_enabler_destroy(event_enabler);
+               lttng_event_enabler_destroy(&event_enabler->parent);
                if (IS_ERR(event_recorder)) {
                        return PTR_ERR(event_recorder);
                }
@@ -746,7 +746,7 @@ int lttng_syscalls_register_event(struct lttng_event_recorder_enabler *syscall_e
                }
                event_recorder = _lttng_kernel_event_recorder_create(event_enabler, desc);
                WARN_ON_ONCE(!event_recorder);
-               lttng_event_enabler_destroy(event_enabler);
+               lttng_event_enabler_destroy(&event_enabler->parent);
                if (IS_ERR(event_recorder)) {
                        return PTR_ERR(event_recorder);
                }
This page took 0.031939 seconds and 4 git commands to generate.