Commit f54c7cd9 authored by Marc Vef's avatar Marc Vef
Browse files

Preload lib: RPC/IPC Mercury/Margo environments are only initialized if the...

Preload lib: RPC/IPC Mercury/Margo environments are only initialized if the mountdir path is used by the application
For that, the daemon writes the mountdir (it was started with) to a configurable path to disk.
The libraries read this value and only the process that uses part of this path will actually trigger the environment initialization.
This forbids prior behavior where applications initialize the whole environment numerous times, although unused.
For example, any MPI program will spawn multiple processes, all with the LD_PRELOAD environment variable set.
parent 6299d70d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3,6 +3,9 @@
#ifndef FS_CONFIGURE_H
#define FS_CONFIGURE_H

// Daemon path to auxiliary files
#define DAEMON_AUX_PATH "/tmp/adafs"

// If ACM time should be considered
#define ACMtime //unused
#define BLOCKSIZE 4 // in kilobytes
+4 −2
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
#include <cerrno>
#include <unistd.h>

#include "configure.hpp"
#include <configure.hpp>
#include <global_defs.hpp>

extern "C" {
@@ -26,7 +26,9 @@ extern "C" {

#define EUNKNOWN (-1)

bool ld_is_env_initialized();
bool ld_is_aux_loaded();

void init_ld_env_if_needed();

void init_preload() __attribute__((constructor));

+4 −0
Original line number Diff line number Diff line
@@ -110,6 +110,10 @@ int db_val_to_stat64(std::string path, std::string db_val, struct stat64& attr);

int getProcIdByName(std::string procName);

std::string daemon_register_path(int pid);

bool get_daemon_auxiliaries();

bool get_addr_by_hostid(uint64_t hostid, hg_addr_t& svr_addr);

size_t get_rpc_node(const std::string& to_hash);
+2 −4
Original line number Diff line number Diff line
@@ -6,9 +6,6 @@
#include <preload/ipc_types.hpp>
#include <adafs_ops/metadentry.hpp>

static const string daemon_aux_path = "/tmp/adafs"s;


bool init_environment() {
    // Initialize rocksdb
    if (!init_rocksdb()) {
@@ -191,7 +188,7 @@ void register_server_rpcs(margo_instance_id mid) {
 * @return string
 */
string daemon_register_path() {
    return ("/tmp/adafs/daemon_"s + to_string(getpid()) + ".run"s);
    return (DAEMON_AUX_PATH + "/daemon_"s + to_string(getpid()) + ".run"s);
}

/**
@@ -201,6 +198,7 @@ string daemon_register_path() {
 */
bool register_daemon_proc() {
    auto ret = false;
    auto daemon_aux_path = DAEMON_AUX_PATH;
    if (!bfs::exists(daemon_aux_path) && !bfs::create_directories(daemon_aux_path)) {
        ADAFS_DATA->spdlogger()->error("{}() Unable to create adafs auxiliary directory in {}", __func__,
                                       daemon_aux_path);
+8 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ using namespace std;


int adafs_open(const std::string& path, mode_t mode, int flags) {
    init_ld_env_if_needed();
    auto err = 1;
    auto fd = file_map.add(path, (flags & O_APPEND) != 0);
    // TODO look up if file exists configurable
@@ -39,14 +40,17 @@ int adafs_open(const std::string& path, mode_t mode, int flags) {
}

int adafs_mk_node(const std::string& path, const mode_t mode) {
    init_ld_env_if_needed();
    return rpc_send_mk_node(path, mode);
}

int adafs_rm_node(const std::string& path) {
    init_ld_env_if_needed();
    return rpc_send_rm_node(path);
}

int adafs_access(const std::string& path, const int mask) {
    init_ld_env_if_needed();
#if !defined(DO_LOOKUP)
    // object is assumed to be existing, even though it might not
    return 0;
@@ -60,6 +64,7 @@ int adafs_access(const std::string& path, const int mask) {

// TODO combine adafs_stat and adafs_stat64
int adafs_stat(const std::string& path, struct stat* buf) {
    init_ld_env_if_needed();
    string attr = ""s;
    auto err = rpc_send_stat(path, attr);
    if (err == 0)
@@ -68,6 +73,7 @@ int adafs_stat(const std::string& path, struct stat* buf) {
}

int adafs_stat64(const std::string& path, struct stat64* buf) {
    init_ld_env_if_needed();
    string attr = ""s;
    auto err = rpc_send_stat(path, attr);
    if (err == 0)
@@ -76,6 +82,7 @@ int adafs_stat64(const std::string& path, struct stat64* buf) {
}

ssize_t adafs_pread_ws(int fd, void* buf, size_t count, off_t offset) {
    init_ld_env_if_needed();
    auto adafs_fd = file_map.get(fd);
    auto path = make_shared<string>(adafs_fd->path());
    auto read_size = static_cast<size_t>(0);
@@ -159,6 +166,7 @@ ssize_t adafs_pread_ws(int fd, void* buf, size_t count, off_t offset) {
}

ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off_t offset) {
    init_ld_env_if_needed();
    auto adafs_fd = file_map.get(fd);
    auto path = make_shared<string>(adafs_fd->path());
    auto append_flag = adafs_fd->append_flag();
Loading