summaryrefslogtreecommitdiffstats
path: root/collectors/ebpf.plugin/ebpf_mount.c
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/ebpf.plugin/ebpf_mount.c')
-rw-r--r--collectors/ebpf.plugin/ebpf_mount.c85
1 files changed, 48 insertions, 37 deletions
diff --git a/collectors/ebpf.plugin/ebpf_mount.c b/collectors/ebpf.plugin/ebpf_mount.c
index bca467bce..ec1f07a65 100644
--- a/collectors/ebpf.plugin/ebpf_mount.c
+++ b/collectors/ebpf.plugin/ebpf_mount.c
@@ -22,14 +22,20 @@ static netdata_idx_t *mount_values = NULL;
static netdata_idx_t mount_hash_values[NETDATA_MOUNT_END];
-struct netdata_static_thread mount_thread = {"MOUNT KERNEL",
- NULL, NULL, 1, NULL,
- NULL, NULL};
+struct netdata_static_thread mount_thread = {
+ .name = "MOUNT KERNEL",
+ .config_section = NULL,
+ .config_name = NULL,
+ .env_name = NULL,
+ .enabled = 1,
+ .thread = NULL,
+ .init_routine = NULL,
+ .start_routine = NULL
+};
netdata_ebpf_targets_t mount_targets[] = { {.name = "mount", .mode = EBPF_LOAD_TRAMPOLINE},
{.name = "umount", .mode = EBPF_LOAD_TRAMPOLINE},
{.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}};
-static enum ebpf_threads_status ebpf_mount_exited = NETDATA_THREAD_EBPF_RUNNING;
#ifdef LIBBPF_MAJOR_VERSION
#include "includes/mount.skel.h" // BTF code
@@ -224,6 +230,36 @@ static inline int ebpf_mount_load_and_attach(struct mount_bpf *obj, ebpf_module_
*****************************************************************/
/**
+ * Mount Free
+ *
+ * Cleanup variables after child threads to stop
+ *
+ * @param ptr thread data.
+ */
+static void ebpf_mount_free(ebpf_module_t *em)
+{
+ pthread_mutex_lock(&ebpf_exit_cleanup);
+ if (em->thread->enabled == NETDATA_THREAD_EBPF_RUNNING) {
+ em->thread->enabled = NETDATA_THREAD_EBPF_STOPPING;
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
+ return;
+ }
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
+
+ freez(mount_thread.thread);
+ freez(mount_values);
+
+#ifdef LIBBPF_MAJOR_VERSION
+ if (bpf_obj)
+ mount_bpf__destroy(bpf_obj);
+#endif
+
+ pthread_mutex_lock(&ebpf_exit_cleanup);
+ em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
+ pthread_mutex_unlock(&ebpf_exit_cleanup);
+}
+
+/**
* Mount Exit
*
* Cancel child thread.
@@ -233,12 +269,8 @@ static inline int ebpf_mount_load_and_attach(struct mount_bpf *obj, ebpf_module_
static void ebpf_mount_exit(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
- if (!em->enabled) {
- em->enabled = NETDATA_MAIN_THREAD_EXITED;
- return;
- }
-
- ebpf_mount_exited = NETDATA_THREAD_EBPF_STOPPING;
+ netdata_thread_cancel(*mount_thread.thread);
+ ebpf_mount_free(em);
}
/**
@@ -251,19 +283,7 @@ static void ebpf_mount_exit(void *ptr)
static void ebpf_mount_cleanup(void *ptr)
{
ebpf_module_t *em = (ebpf_module_t *)ptr;
- if (ebpf_mount_exited != NETDATA_THREAD_EBPF_STOPPED)
- return;
-
- freez(mount_thread.thread);
- freez(mount_values);
-
-#ifdef LIBBPF_MAJOR_VERSION
- if (bpf_obj)
- mount_bpf__destroy(bpf_obj);
-#endif
-
- mount_thread.enabled = NETDATA_MAIN_THREAD_EXITED;
- em->enabled = NETDATA_MAIN_THREAD_EXITED;
+ ebpf_mount_free(em);
}
/*****************************************************************
@@ -317,17 +337,12 @@ void *ebpf_mount_read_hash(void *ptr)
usec_t step = NETDATA_LATENCY_MOUNT_SLEEP_MS * em->update_every;
//This will be cancelled by its parent
- while (ebpf_mount_exited == NETDATA_THREAD_EBPF_RUNNING) {
- usec_t dt = heartbeat_next(&hb, step);
- (void)dt;
- if (ebpf_mount_exited == NETDATA_THREAD_EBPF_STOPPING)
- break;
+ while (!ebpf_exit_plugin) {
+ (void)heartbeat_next(&hb, step);
read_global_table();
}
- ebpf_mount_exited = NETDATA_THREAD_EBPF_STOPPED;
-
netdata_thread_cleanup_pop(1);
return NULL;
}
@@ -435,7 +450,7 @@ static void ebpf_create_mount_charts(int update_every)
static int ebpf_mount_load_bpf(ebpf_module_t *em)
{
int ret = 0;
- if (em->load == EBPF_LOAD_LEGACY) {
+ if (em->load & EBPF_LOAD_LEGACY) {
em->probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &em->objects);
if (!em->probe_links) {
em->enabled = CONFIG_BOOLEAN_NO;
@@ -474,14 +489,11 @@ void *ebpf_mount_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = mount_maps;
- if (!em->enabled)
- goto endmount;
-
#ifdef LIBBPF_MAJOR_VERSION
ebpf_adjust_thread_load(em, default_btf);
#endif
if (ebpf_mount_load_bpf(em)) {
- em->enabled = CONFIG_BOOLEAN_NO;
+ em->thread->enabled = NETDATA_THREAD_EBPF_STOPPED;
goto endmount;
}
@@ -498,8 +510,7 @@ void *ebpf_mount_thread(void *ptr)
mount_collector(em);
endmount:
- if (!em->enabled)
- ebpf_update_disabled_plugin_stats(em);
+ ebpf_update_disabled_plugin_stats(em);
netdata_thread_cleanup_pop(1);
return NULL;