Refactoring: combine event notifier notifier and recorder enable/disable
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 1 Nov 2021 18:31:51 +0000 (14:31 -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: Ia6cffc5bb36b91c5a5c289c1d1b13accb55dcce3

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

index a9121a1b8c4f5d1470986f3fbf6072e82830cee5..8ac1b01b6f61ca9aed4dfb0878f81eef6424d703 100644 (file)
@@ -787,18 +787,14 @@ 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_recorder_enabler *event_enabler);
-int lttng_event_enabler_disable(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_notifier_enabler_enable(
-               struct lttng_event_notifier_enabler *event_notifier_enabler);
-int lttng_event_notifier_enabler_disable(
-               struct lttng_event_notifier_enabler *event_notifier_enabler);
-
 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(
index 6a1954d3e918c6be6b5a2317459bf15fbc20cb26..8eeb632a227c0c24f9fab902dbc386b2c4b12715 100644 (file)
@@ -1987,9 +1987,9 @@ long lttng_event_notifier_enabler_ioctl(struct file *file, unsigned int cmd, uns
 
        switch (cmd) {
        case LTTNG_KERNEL_ABI_ENABLE:
-               return lttng_event_notifier_enabler_enable(event_notifier_enabler);
+               return lttng_event_enabler_enable(&event_notifier_enabler->parent);
        case LTTNG_KERNEL_ABI_DISABLE:
-               return lttng_event_notifier_enabler_disable(event_notifier_enabler);
+               return lttng_event_enabler_disable(&event_notifier_enabler->parent);
        case LTTNG_KERNEL_ABI_FILTER:
                return lttng_event_enabler_attach_filter_bytecode(&event_notifier_enabler->parent,
                        (struct lttng_kernel_abi_filter_bytecode __user *) arg);
@@ -2714,10 +2714,10 @@ long lttng_event_recorder_enabler_ioctl(struct file *file, unsigned int cmd, uns
        }
        case LTTNG_KERNEL_ABI_OLD_ENABLE:
        case LTTNG_KERNEL_ABI_ENABLE:
-               return lttng_event_enabler_enable(event_enabler);
+               return lttng_event_enabler_enable(&event_enabler->parent);
        case LTTNG_KERNEL_ABI_OLD_DISABLE:
        case LTTNG_KERNEL_ABI_DISABLE:
-               return lttng_event_enabler_disable(event_enabler);
+               return lttng_event_enabler_disable(&event_enabler->parent);
        case LTTNG_KERNEL_ABI_FILTER:
                return lttng_event_enabler_attach_filter_bytecode(&event_enabler->parent,
                        (struct lttng_kernel_abi_filter_bytecode __user *) arg);
index ffec2b85b24cc319f9efc1007106dd21527aff2b..f864eaba57db0d881f916eba7a49b6254b3ca6fe 100644 (file)
@@ -68,6 +68,7 @@ static void lttng_session_lazy_sync_event_enablers(struct lttng_kernel_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);
 
 static void _lttng_event_destroy(struct lttng_kernel_event_common *event);
 static void _lttng_channel_destroy(struct lttng_kernel_channel_buffer *chan);
@@ -2503,20 +2504,20 @@ void lttng_event_enabler_session_add(struct lttng_kernel_session *session,
        mutex_unlock(&sessions_mutex);
 }
 
-int lttng_event_enabler_enable(struct lttng_event_recorder_enabler *event_enabler)
+int lttng_event_enabler_enable(struct lttng_event_enabler_common *event_enabler)
 {
        mutex_lock(&sessions_mutex);
-       lttng_event_recorder_enabler_as_enabler(event_enabler)->enabled = 1;
-       lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent.session);
+       event_enabler->enabled = 1;
+       lttng_event_enabler_sync(event_enabler);
        mutex_unlock(&sessions_mutex);
        return 0;
 }
 
-int lttng_event_enabler_disable(struct lttng_event_recorder_enabler *event_enabler)
+int lttng_event_enabler_disable(struct lttng_event_enabler_common *event_enabler)
 {
        mutex_lock(&sessions_mutex);
-       lttng_event_recorder_enabler_as_enabler(event_enabler)->enabled = 0;
-       lttng_session_lazy_sync_event_enablers(event_enabler->chan->parent.session);
+       event_enabler->enabled = 0;
+       lttng_event_enabler_sync(event_enabler);
        mutex_unlock(&sessions_mutex);
        return 0;
 }
@@ -2561,26 +2562,7 @@ int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler_common
        ret = lttng_enabler_attach_filter_bytecode(event_enabler, bytecode);
        if (ret)
                goto error;
-
-       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);
-               lttng_session_lazy_sync_event_enablers(event_recorder_enabler->chan->parent.session);
-               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);
-               lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group);
-               break;
-       }
-       default:
-               WARN_ON_ONCE(1);
-               return -ENOSYS;
-       }
+       lttng_event_enabler_sync(event_enabler);
        return 0;
 
 error:
@@ -2914,6 +2896,29 @@ void lttng_event_notifier_group_sync_enablers(struct lttng_event_notifier_group
        }
 }
 
+static
+void lttng_event_enabler_sync(struct lttng_event_enabler_common *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);
+               lttng_session_lazy_sync_event_enablers(event_recorder_enabler->chan->parent.session);
+               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);
+               lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group);
+               break;
+       }
+       default:
+               WARN_ON_ONCE(1);
+       }
+}
+
 /*
  * Serialize at most one packet worth of metadata into a metadata
  * channel.
This page took 0.030726 seconds and 4 git commands to generate.