Unverified Commit 52269a81 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Introduce preload context

The new PreloadContext class is used as singleton to store the general context
information of the interception library.

The plan is to move global accessed variables into this sigleton.

At the moment just the logger object has been moved into it.
parent 00b7d31c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -23,9 +23,12 @@ extern "C" {
}

#include <preload/preload_util.hpp>
#include <preload/preload_context.hpp>

#define EUNKNOWN (-1)

#define CTX PreloadContext::getInstance()

bool ld_is_aux_loaded();

void init_ld_env_if_needed();
+31 −0
Original line number Diff line number Diff line
#ifndef IFS_PRELOAD_CTX_HPP
#define IFS_PRELOAD_CTX_HPP

#include <extern/spdlog/spdlog.h>
#include <memory>
#include <string>


class PreloadContext {
    private:
    PreloadContext() = default;

    std::shared_ptr<spdlog::logger> log_;
    std::string mountdir_;

    public:
    static PreloadContext* getInstance() {
        static PreloadContext instance;
        return &instance;
    }

    PreloadContext(PreloadContext const&) = delete;
    void operator=(PreloadContext const&) = delete;

    void log(std::shared_ptr<spdlog::logger> logger);
    std::shared_ptr<spdlog::logger> log() const;
};


#endif //IFS_PRELOAD_CTX_HPP
+0 −3
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
#include <preload/preload.hpp>
#include <preload/open_file_map.hpp>
// third party libs
#include <extern/spdlog/spdlog.h>
#include <string>

// TODO singleton this stuff away
@@ -95,8 +94,6 @@ extern hg_id_t rpc_write_data_id;
extern hg_id_t rpc_read_data_id;
// fs_config is set ONCE in the beginning. It shall not be modified afterwards
extern std::shared_ptr<struct FsConfig> fs_config;
// global logger instance
extern std::shared_ptr<spdlog::logger> ld_logger;
// rpc addresses. Populated when environment is initialized. After that it is read-only accessed
extern std::map<uint64_t, hg_addr_t> rpc_addresses;
// file descriptor index validation flag
+2 −0
Original line number Diff line number Diff line
set(PRELOAD_SRC
    preload_context.cpp
    adafs_functions.cpp
    intcp_functions.cpp
    margo_ipc.cpp
@@ -20,6 +21,7 @@ set(PRELOAD_HEADERS
    ../../include/global/rpc/rpc_types.hpp
    ../../include/global/rpc/rpc_utils.hpp
    ../../include/global/chunk_calc_util.hpp
    ../../include/preload/preload_context.hpp
    ../../include/preload/adafs_functions.hpp
    ../../include/preload/margo_ipc.hpp
    ../../include/preload/open_file_map.hpp
+4 −3
Original line number Diff line number Diff line
#include <preload/preload.hpp>
#include <preload/adafs_functions.hpp>
#include <preload/rpc/ld_rpc_metadentry.hpp>
#include <preload/rpc/ld_rpc_data_ws.hpp>
@@ -186,12 +187,12 @@ ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset) {

    ret = rpc_send_update_metadentry_size(*path, count, offset, append_flag, updated_size);
    if (ret != 0) {
        ld_logger->error("{}() update_metadentry_size failed with ret {}", __func__, ret);
        CTX->log()->error("{}() update_metadentry_size failed with ret {}", __func__, ret);
        return 0; // ERR
    }
    ret = rpc_send_write(*path, buf, append_flag, offset, count, updated_size);
    if (ret < 0) {
        ld_logger->warn("{}() rpc_send_write failed with ret {}", __func__, ret);
        CTX->log()->warn("{}() rpc_send_write failed with ret {}", __func__, ret);
    }
    return ret; // return written size or -1 as error
}
@@ -206,7 +207,7 @@ ssize_t adafs_pread_ws(int fd, void* buf, size_t count, off64_t offset) {
#endif
    auto ret = rpc_send_read(*path, buf, offset, count);
    if (ret < 0) {
        ld_logger->warn("{}() rpc_send_read failed with ret {}", __func__, ret);
        CTX->log()->warn("{}() rpc_send_read failed with ret {}", __func__, ret);
    }
    // XXX check that we don't try to read past end of the file
    return ret; // return read size or -1 as error
Loading