Commit 3dfb2558 authored by Ramon Nou's avatar Ramon Nou
Browse files

Merge branch 'rnou/319-add-pthread_at_fork-in-syscall-interception' into 'master'

Resolve "Add pthread_at_fork in syscall interception"

Closes #319

Closes #319

See merge request !210
parents 8dcb2dab f8d84e55
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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

+7 −0
Original line number Diff line number Diff line
@@ -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
+3 −0
Original line number Diff line number Diff line
@@ -153,6 +153,9 @@ public:
    bool
    init_metrics();

    void
    destroy_metrics();

    void
    mountdir(const std::string& path);

+22 −1
Original line number Diff line number Diff line
@@ -337,6 +337,9 @@ init_environment() {

} // namespace gkfs::preload


std::atomic<bool> 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();

@@ -407,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");
@@ -459,3 +466,17 @@ gkfs_end() {

    return 0;
}

void
at_fork_syscall() {
    destroy_preload();
}
void
at_parent_syscall() {
    init_preload();
}

void
at_child_syscall() {
    init_preload();
}
+8 −0
Original line number Diff line number Diff line
@@ -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