From be05e78e6d89cd2fca65be43fc8b7afe19a1d6c2 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 8 Nov 2021 11:27:22 -0500 Subject: [PATCH] Refactoring: combine event enabler enabler/disable common code Introduce lttng_event_enabler_sync(). Signed-off-by: Mathieu Desnoyers Change-Id: Id7c65f517dec9611f9e3b85355b47441fb082479 --- src/lib/lttng-ust/events.h | 24 +++---------- src/lib/lttng-ust/lttng-events.c | 58 +++++++++++++++++-------------- src/lib/lttng-ust/lttng-ust-abi.c | 8 ++--- 3 files changed, 40 insertions(+), 50 deletions(-) diff --git a/src/lib/lttng-ust/events.h b/src/lib/lttng-ust/events.h index 3fd58aa4..ea985127 100644 --- a/src/lib/lttng-ust/events.h +++ b/src/lib/lttng-ust/events.h @@ -41,17 +41,17 @@ void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enable __attribute__((visibility("hidden"))); /* - * Enable a `struct lttng_event_enabler` object and all events related to this + * Enable a `struct lttng_event_enabler_common` object and all events related to this * enabler. */ -int lttng_event_enabler_enable(struct lttng_event_enabler_session_common *enabler) +int lttng_event_enabler_enable(struct lttng_event_enabler_common *enabler) __attribute__((visibility("hidden"))); /* - * Disable a `struct lttng_event_enabler` object and all events related to this + * Disable a `struct lttng_event_enabler_common` object and all events related to this * enabler. */ -int lttng_event_enabler_disable(struct lttng_event_enabler_session_common *enabler) +int lttng_event_enabler_disable(struct lttng_event_enabler_common *enabler) __attribute__((visibility("hidden"))); /* @@ -121,22 +121,6 @@ struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( struct lttng_ust_abi_event_notifier *event_notifier_param) __attribute__((visibility("hidden"))); -/* - * Enable a `struct lttng_event_notifier_enabler` object and all event - * notifiers related to this enabler. - */ -int lttng_event_notifier_enabler_enable( - struct lttng_event_notifier_enabler *event_notifier_enabler) - __attribute__((visibility("hidden"))); - -/* - * Disable a `struct lttng_event_notifier_enabler` object and all event - * notifiers related to this enabler. - */ -int lttng_event_notifier_enabler_disable( - struct lttng_event_notifier_enabler *event_notifier_enabler) - __attribute__((visibility("hidden"))); - /* * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and * all event notifiers related to this enabler. diff --git a/src/lib/lttng-ust/lttng-events.c b/src/lib/lttng-ust/lttng-events.c index 82da68f6..25b86fbf 100644 --- a/src/lib/lttng-ust/lttng-events.c +++ b/src/lib/lttng-ust/lttng-events.c @@ -79,6 +79,8 @@ void lttng_session_sync_event_enablers(struct lttng_ust_session *session); 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); bool lttng_ust_validate_event_name(const struct lttng_ust_event_desc *desc) { @@ -1792,19 +1794,17 @@ struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( return event_notifier_enabler; } -int lttng_event_enabler_enable(struct lttng_event_enabler_session_common *event_enabler) +int lttng_event_enabler_enable(struct lttng_event_enabler_common *event_enabler) { - event_enabler->parent.enabled = 1; - lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); - + event_enabler->enabled = 1; + lttng_event_enabler_sync(event_enabler); return 0; } -int lttng_event_enabler_disable(struct lttng_event_enabler_session_common *event_enabler) +int lttng_event_enabler_disable(struct lttng_event_enabler_common *event_enabler) { - event_enabler->parent.enabled = 0; - lttng_session_lazy_sync_event_enablers(event_enabler->chan->session); - + event_enabler->enabled = 0; + lttng_event_enabler_sync(event_enabler); return 0; } @@ -1846,24 +1846,6 @@ int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler_session_comm return 0; } -int lttng_event_notifier_enabler_enable( - struct lttng_event_notifier_enabler *event_notifier_enabler) -{ - lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)->enabled = 1; - lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group); - - return 0; -} - -int lttng_event_notifier_enabler_disable( - struct lttng_event_notifier_enabler *event_notifier_enabler) -{ - lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)->enabled = 0; - lttng_event_notifier_group_sync_enablers(event_notifier_enabler->group); - - return 0; -} - int lttng_event_notifier_enabler_attach_filter_bytecode( struct lttng_event_notifier_enabler *event_notifier_enabler, struct lttng_ust_bytecode_node **bytecode) @@ -2347,6 +2329,30 @@ void lttng_session_lazy_sync_event_enablers(struct lttng_ust_session *session) lttng_session_sync_event_enablers(session); } +static +void lttng_event_enabler_sync(struct lttng_event_enabler_common *event_enabler) +{ + switch (event_enabler->enabler_type) { + case LTTNG_EVENT_ENABLER_TYPE_RECORDER: /* Fall-through */ + case LTTNG_EVENT_ENABLER_TYPE_COUNTER: + { + struct lttng_event_enabler_session_common *event_enabler_session = + caa_container_of(event_enabler, struct lttng_event_enabler_session_common, parent); + lttng_session_lazy_sync_event_enablers(event_enabler_session->chan->session); + break; + } + case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER: + { + struct lttng_event_notifier_enabler *event_notifier_enabler = + caa_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); + } +} + /* * Update all sessions with the given app context. * Called with ust lock held. diff --git a/src/lib/lttng-ust/lttng-ust-abi.c b/src/lib/lttng-ust/lttng-ust-abi.c index d327cd91..390e291f 100644 --- a/src/lib/lttng-ust/lttng-ust-abi.c +++ b/src/lib/lttng-ust/lttng-ust-abi.c @@ -869,9 +869,9 @@ long lttng_event_notifier_enabler_cmd(int objd, unsigned int cmd, unsigned long event_notifier_enabler, (struct lttng_ust_bytecode_node **) arg); case LTTNG_UST_ABI_ENABLE: - return lttng_event_notifier_enabler_enable(event_notifier_enabler); + return lttng_event_enabler_enable(&event_notifier_enabler->parent); case LTTNG_UST_ABI_DISABLE: - return lttng_event_notifier_enabler_disable(event_notifier_enabler); + return lttng_event_enabler_disable(&event_notifier_enabler->parent); default: return -EINVAL; } @@ -1769,9 +1769,9 @@ long lttng_event_enabler_cmd(int objd, unsigned int cmd, unsigned long arg, return lttng_event_enabler_attach_context(enabler, (struct lttng_ust_abi_context *) arg); case LTTNG_UST_ABI_ENABLE: - return lttng_event_enabler_enable(enabler); + return lttng_event_enabler_enable(&enabler->parent); case LTTNG_UST_ABI_DISABLE: - return lttng_event_enabler_disable(enabler); + return lttng_event_enabler_disable(&enabler->parent); case LTTNG_UST_ABI_FILTER: { int ret; -- 2.39.5