From e4755bfa2c4e1af1e71cc5b4031bab0275a929b4 Mon Sep 17 00:00:00 2001 From: Ramon Nou Date: Mon, 4 Nov 2024 15:09:51 +0100 Subject: [PATCH 1/2] Adding pthread_atfork to syscall --- include/client/preload.hpp | 7 +++++++ src/client/preload.cpp | 29 ++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/client/preload.hpp b/include/client/preload.hpp index afad97c68..ffc3e942d 100644 --- a/include/client/preload.hpp +++ b/include/client/preload.hpp @@ -49,4 +49,11 @@ void destroy_preload() __attribute__((destructor)); #endif +void +at_fork_syscall(); +void +at_child_syscall(); +void +at_parent_syscall(); + #endif // IOINTERCEPT_PRELOAD_HPP diff --git a/src/client/preload.cpp b/src/client/preload.cpp index 67926fbb3..6bf27d964 100644 --- a/src/client/preload.cpp +++ b/src/client/preload.cpp @@ -337,6 +337,9 @@ init_environment() { } // namespace gkfs::preload + +std::atomic init{false}; + /** * Called initially ONCE when preload library is used with the LD_PRELOAD * environment variable @@ -346,7 +349,10 @@ init_preload() { // The original errno value will be restored after initialization to not // leak internal error codes auto oerrno = errno; - + if(!init) { + init = true; + pthread_atfork(&at_fork_syscall, &at_parent_syscall, &at_child_syscall); + } CTX->enable_interception(); gkfs::preload::start_self_interception(); @@ -459,3 +465,24 @@ gkfs_end() { return 0; } + +void +at_fork_syscall() { + printf("%d ->At fork, %d\n", gettid(), CTX->interception_enabled()); + destroy_preload(); +} +void +at_parent_syscall() { + printf("%d ->At fork parent %d\n", gettid(), CTX->interception_enabled()); + init_preload(); + printf("%d -> x At fork parent %d\n", gettid(), + CTX->interception_enabled()); +} + +void +at_child_syscall() { + + printf("%d ->At fork child %d\n", gettid(), CTX->interception_enabled()); + init_preload(); + printf("%d -> x At fork child %d\n", gettid(), CTX->interception_enabled()); +} -- GitLab From f8d84e555924c50cd52c09b9be2203780b5169f0 Mon Sep 17 00:00:00 2001 From: Ramon Nou Date: Wed, 27 Nov 2024 14:56:35 +0100 Subject: [PATCH 2/2] Metrics should be nicely cleanup, add destroy_metrics function --- CHANGELOG.md | 1 + include/client/preload_context.hpp | 3 +++ src/client/preload.cpp | 8 +------- src/client/preload_context.cpp | 8 ++++++++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c329f6bbc..891b11b8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Support to print newer syscall (although not implemented). Added syscall number to log for easy capture missing ones. - Unify dependency scripts (dl and compile): Unify `-d` and `-p` flags ([!174](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/174)). - Increased merge assert for files with size 0, specific for DLIO with GekkoFS in Debug ([!208])(https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/208)). +- Added code to correct fork issues. `pthread_at_fork` cleans and starts GekkoFS ([!210](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/210)). ### Removed ### Fixed diff --git a/include/client/preload_context.hpp b/include/client/preload_context.hpp index d818ca21e..7ca56e1a2 100644 --- a/include/client/preload_context.hpp +++ b/include/client/preload_context.hpp @@ -153,6 +153,9 @@ public: bool init_metrics(); + void + destroy_metrics(); + void mountdir(const std::string& path); diff --git a/src/client/preload.cpp b/src/client/preload.cpp index 6bf27d964..ae7b03817 100644 --- a/src/client/preload.cpp +++ b/src/client/preload.cpp @@ -413,6 +413,7 @@ destroy_preload() { CTX->read_metrics()->flush_msgpack(); LOG(INFO, "Metrics flushed. Total flush operations: {}", CTX->write_metrics()->flush_count()); + CTX->destroy_metrics(); #endif CTX->clear_hosts(); LOG(DEBUG, "Peer information deleted"); @@ -468,21 +469,14 @@ gkfs_end() { void at_fork_syscall() { - printf("%d ->At fork, %d\n", gettid(), CTX->interception_enabled()); destroy_preload(); } void at_parent_syscall() { - printf("%d ->At fork parent %d\n", gettid(), CTX->interception_enabled()); init_preload(); - printf("%d -> x At fork parent %d\n", gettid(), - CTX->interception_enabled()); } void at_child_syscall() { - - printf("%d ->At fork child %d\n", gettid(), CTX->interception_enabled()); init_preload(); - printf("%d -> x At fork child %d\n", gettid(), CTX->interception_enabled()); } diff --git a/src/client/preload_context.cpp b/src/client/preload_context.cpp index a15813b25..438bf55a6 100644 --- a/src/client/preload_context.cpp +++ b/src/client/preload_context.cpp @@ -121,6 +121,14 @@ PreloadContext::init_logging() { ); } +void +PreloadContext::destroy_metrics() { +#ifdef GKFS_ENABLE_CLIENT_METRICS + write_metrics_.reset(); + read_metrics_.reset(); +#endif +} + bool PreloadContext::init_metrics() { #ifdef GKFS_ENABLE_CLIENT_METRICS -- GitLab