Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/common/capio/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef CAPIO_CONFIG_HPP
#define CAPIO_CONFIG_HPP
#include "constants.hpp"
#include <cstring>

#include <filesystem>

struct CapioConfig {
std::string CAPIO_APP_NAME = CAPIO_DEFAULT_APP_NAME;
std::string CAPIO_WORKFLOW_NAME = CAPIO_DEFAULT_WORKFLOW_NAME;
std::string CAPIO_DIR = std::getenv("PWD");
std::string CAPIO_LOG_PREFIX = CAPIO_LOG_POSIX_DEFAULT_LOG_FILE_PREFIX;
std::filesystem::path CAPIO_LOG_DIR = CAPIO_DEFAULT_LOG_FOLDER;
std::filesystem::path CAPIO_METADATA_DIR = CAPIO_DIR;
size_t CAPIO_WRITE_CACHE_SIZE = CAPIO_CACHE_LINE_SIZE_DEFAULT;
size_t CAPIO_CACHE_LINES = CAPIO_CACHE_LINES_DEFAULT;
size_t CAPIO_CACHE_LINE_SIZE = CAPIO_CACHE_LINE_SIZE_DEFAULT;
size_t CAPIO_POSIX_CACHE_LINE_SIZE = CAPIO_CACHE_LINE_SIZE;
int CAPIO_LOG_LEVEL = -1;
bool CAPIO_STORE_ONLY_IN_MEMORY = false;
bool _initialized = false;
};

CapioConfig *capio_config;

void fill_capio_cofiguration() {
auto capio_app_name = std::getenv("CAPIO_APP_NAME");
auto capio_workflow_name = std::getenv("CAPIO_WORKFLOW_NAME");

capio_config->_initialized = true;
}

#endif // CAPIO_CONFIG_HPP
2 changes: 2 additions & 0 deletions src/common/capio/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ constexpr char CAPIO_SERVER_ARG_PARSER_CONFIG_NCONTINUE_ON_ERROR_HELP[] =
"specified, and a fatal termination point is reached, the behaviour of capio is undefined and "
"should not be taken as valid";

constexpr char CAPIO_SERVER_ARG_PARSER_REDIS_OPT_HELP[] = "Use redis to store configurations. pass with option <address>:<port> of redis-server instance";

constexpr char CAPIO_LOG_SERVER_CLI_CONT_ON_ERR_WARNING[] =
"[ \033[1;33m SERVER \033[0m ]\033[1;31m "
"|==================================================================|\033[0m\n"
Expand Down
99 changes: 0 additions & 99 deletions src/common/capio/env.hpp

This file was deleted.

5 changes: 2 additions & 3 deletions src/common/capio/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <sys/stat.h>

#include "env.hpp"
#include "logger.hpp"
#include "syscall.hpp"

Expand Down Expand Up @@ -61,7 +60,7 @@ inline bool is_forbidden_path(const std::string_view &path) {
inline bool is_capio_dir(const std::filesystem::path &path_to_check) {
START_LOG(capio_syscall(SYS_gettid), "call(path_to_check=%s)", path_to_check.c_str());

const auto res = get_capio_dir().compare(path_to_check) == 0;
const auto res = capio_config->CAPIO_DIR.compare(path_to_check) == 0;
LOG("is_capio_dir:%s", res ? "yes" : "no");
return res;
}
Expand All @@ -70,7 +69,7 @@ inline bool is_capio_path(const std::filesystem::path &path_to_check) {
START_LOG(capio_syscall(SYS_gettid), "call(path_to_check=%s)", path_to_check.c_str());

// check if path_to_check begins with CAPIO_DIR
const auto res = is_prefix(get_capio_dir(), path_to_check);
const auto res = is_prefix(capio_config->CAPIO_DIR, path_to_check);
LOG("is_capio_path:%s", res ? "yes" : "no");
return res;
}
Expand Down
48 changes: 11 additions & 37 deletions src/common/capio/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <sys/mman.h>
#include <unistd.h>

#include "capio/config.hpp"

#include "constants.hpp"
#include "syscall.hpp"

Expand Down Expand Up @@ -39,8 +41,6 @@ inline thread_local bool logging_syscall =
#define CAPIO_MAX_LOG_LEVEL -1
#endif

inline int CAPIO_LOG_LEVEL = CAPIO_MAX_LOG_LEVEL;

#ifndef __CAPIO_POSIX
inline auto open_server_logfile() {
auto hostname = new char[HOST_NAME_MAX];
Expand Down Expand Up @@ -70,39 +70,14 @@ inline auto get_hostname() {
return hostname_prefix;
}

inline auto get_log_dir() {
static char *posix_log_master_dir_name = nullptr;
if (posix_log_master_dir_name == nullptr) {
posix_log_master_dir_name = std::getenv("CAPIO_LOG_DIR");
if (posix_log_master_dir_name == nullptr) {
posix_log_master_dir_name = new char[strlen(CAPIO_DEFAULT_LOG_FOLDER)];
strcpy(posix_log_master_dir_name, CAPIO_DEFAULT_LOG_FOLDER);
}
}
return posix_log_master_dir_name;
}

inline auto get_log_prefix() {
static char *posix_logfile_prefix = nullptr;
if (posix_logfile_prefix == nullptr) {
posix_logfile_prefix = std::getenv("CAPIO_LOG_PREFIX");
if (posix_logfile_prefix == nullptr) {
posix_logfile_prefix = new char[strlen(CAPIO_LOG_POSIX_DEFAULT_LOG_FILE_PREFIX)];
strcpy(posix_logfile_prefix, CAPIO_LOG_POSIX_DEFAULT_LOG_FILE_PREFIX);
}
}
return posix_logfile_prefix;
}

inline auto get_posix_log_dir() {
static char *posix_log_dir_path = nullptr;
if (posix_log_dir_path == nullptr) {
// allocate space for a path in the following structure (including 10 digits for thread id
// max
// log_master_dir_name/posix/hostname/logfile_prefix_<tid>.log
auto len = strlen(get_log_dir()) + 7;
// max log_master_dir_name/posix/hostname/logfile_prefix_<tid>.log
auto len = strlen(capio_config->CAPIO_LOG_DIR.c_str()) + 7;
posix_log_dir_path = new char[len]{0};
sprintf(posix_log_dir_path, "%s/posix", get_log_dir());
sprintf(posix_log_dir_path, "%s/posix", capio_config->CAPIO_LOG_DIR.c_str());
}
return posix_log_dir_path;
}
Expand All @@ -111,8 +86,7 @@ inline auto get_host_log_dir() {
static char *host_log_dir_path = nullptr;
if (host_log_dir_path == nullptr) {
// allocate space for a path in the following structure (including 10 digits for thread id
// max
// log_master_dir_name/posix/hostname/logfile_prefix_<tid>.log
// max log_master_dir_name/posix/hostname/logfile_prefix_<tid>.log
auto len = strlen(get_posix_log_dir()) + HOST_NAME_MAX;
host_log_dir_path = new char[len]{0};
sprintf(host_log_dir_path, "%s/%s", get_posix_log_dir(), get_hostname());
Expand All @@ -122,8 +96,8 @@ inline auto get_host_log_dir() {

inline void setup_posix_log_filename() {
if (logfile_path[0] == '\0') {
sprintf(logfile_path, "%s/%s%ld.log", get_host_log_dir(), get_log_prefix(),
capio_syscall(SYS_gettid));
sprintf(logfile_path, "%s/%s%ld.log", get_host_log_dir(),
capio_config->CAPIO_LOG_PREFIX.c_str(), capio_syscall(SYS_gettid));
}
}
#endif
Expand All @@ -147,7 +121,7 @@ inline void log_write_to(char *buffer, size_t bufflen) {
capio_syscall(SYS_write, logfileFD, "\n", 1);
}
#else
if (current_log_level < CAPIO_LOG_LEVEL || CAPIO_LOG_LEVEL < 0) {
if (current_log_level < capio_config->CAPIO_LOG_LEVEL || capio_config->CAPIO_LOG_LEVEL < 0) {
logfile << buffer << std::endl;
logfile.flush();
}
Expand Down Expand Up @@ -191,11 +165,11 @@ class Logger {
setup_posix_log_filename();
current_log_level = 0; // reset after clone log level, so to not inherit it
#if defined(SYS_mkdir)
capio_syscall(SYS_mkdir, get_log_dir(), 0755);
capio_syscall(SYS_mkdir, capio_config->CAPIO_LOG_DIR.c_str(), 0755);
capio_syscall(SYS_mkdir, get_posix_log_dir(), 0755);
capio_syscall(SYS_mkdir, get_host_log_dir(), 0755);
#elif defined(SYS_mkdirat)
capio_syscall(SYS_mkdirat, AT_FDCWD, get_log_dir(), 0755);
capio_syscall(SYS_mkdirat, AT_FDCWD, capio_config->CAPIO_LOG_DIR.c_str(), 0755);
capio_syscall(SYS_mkdirat, AT_FDCWD, get_posix_log_dir(), 0755);
capio_syscall(SYS_mkdirat, AT_FDCWD, get_host_log_dir(), 0755);
#endif
Expand Down
3 changes: 1 addition & 2 deletions src/common/capio/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <semaphore.h>

#include "capio/env.hpp"
#include "capio/logger.hpp"
#include "capio/semaphore.hpp"
#include "capio/shm.hpp"
Expand Down Expand Up @@ -52,7 +51,7 @@ template <class T, class Mutex> class Queue {

public:
Queue(const std::string &shm_name, const long int max_num_elems, const long int elem_size,
const std::string &workflow_name = get_capio_workflow_name(), bool cleanup = true)
const std::string &workflow_name = capio_config->CAPIO_WORKFLOW_NAME, bool cleanup = true)
: _max_num_elems(max_num_elems), _elem_size(elem_size),
_buff_size(_max_num_elems * _elem_size), _shm_name(workflow_name + "_" + shm_name),
_first_elem_name(workflow_name + SHM_FIRST_ELEM + shm_name),
Expand Down
2 changes: 1 addition & 1 deletion src/common/capio/shm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CapioShmCanary {
explicit CapioShmCanary(std::string capio_workflow_name) : _canary_name(capio_workflow_name) {
START_LOG(capio_syscall(SYS_gettid), "call(capio_workflow_name: %s)", _canary_name.data());
if (_canary_name.empty()) {
_canary_name = get_capio_workflow_name();
_canary_name = capio_config->CAPIO_WORKFLOW_NAME;
}
_shm_id = shm_open(_canary_name.data(), O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
if (_shm_id == -1) {
Expand Down
1 change: 0 additions & 1 deletion src/posix/handlers/stat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <sys/vfs.h>

#include "capio/env.hpp"

#include "utils/common.hpp"
#include "utils/filesystem.hpp"
Expand Down
9 changes: 5 additions & 4 deletions src/posix/libcapio_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <array>
#include <string>

#include "capio/config.hpp"

#include "capio/syscall.hpp"

#include "utils/clone.hpp"
Expand Down Expand Up @@ -389,10 +391,6 @@ static int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3,
return 1;
}

#ifdef CAPIO_LOG
CAPIO_LOG_LEVEL = get_capio_log_level();
#endif

START_LOG(syscall_no_intercept(SYS_gettid), "call(syscall_number=%ld)", syscall_number);

// If the syscall_number is higher than the maximum
Expand All @@ -413,6 +411,9 @@ static int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3,
}

static __attribute__((constructor)) void init() {

capio_config = new CapioConfig();

init_client();
init_filesystem();
init_threading_support();
Expand Down
1 change: 0 additions & 1 deletion src/posix/utils/cache.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CAPIO_CACHE_HPP
#define CAPIO_CACHE_HPP
#include "capio/requests.hpp"
#include "env.hpp"

#include "cache/consent_request_cache.hpp"
#include "cache/read_request_cache_fs.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/posix/utils/cache/read_request_cache_mem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ReadRequestCacheMEM {
}

public:
explicit ReadRequestCacheMEM(const long line_size = get_posix_read_cache_line_size())
explicit ReadRequestCacheMEM(const long line_size = capio_config->CAPIO_POSIX_CACHE_LINE_SIZE)
: _cache(nullptr), _tid(capio_syscall(SYS_gettid)), _fd(-1), _max_line_size(line_size),
_actual_size(0), _cache_offset(0), _last_read_end(-1) {
_cache = new char[_max_line_size];
Expand Down
2 changes: 1 addition & 1 deletion src/posix/utils/cache/write_request_cache_fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WriteRequestCacheFS {
}

public:
explicit WriteRequestCacheFS() : _max_size(get_capio_write_cache_size()) {}
explicit WriteRequestCacheFS() : _max_size(capio_config->CAPIO_WRITE_CACHE_SIZE) {}

~WriteRequestCacheFS() { this->flush(capio_syscall(SYS_gettid)); }

Expand Down
2 changes: 1 addition & 1 deletion src/posix/utils/cache/write_request_cache_mem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class WriteRequestCacheMEM {
}

public:
explicit WriteRequestCacheMEM(off64_t line_size = get_cache_line_size())
explicit WriteRequestCacheMEM(off64_t line_size = capio_config->CAPIO_CACHE_LINE_SIZE)
: _cache(nullptr), _tid(capio_syscall(SYS_gettid)), _fd(-1), _max_line_size(line_size),
_actual_size(0), _last_write_end(-1), _last_write_begin(0) {}

Expand Down
2 changes: 1 addition & 1 deletion src/posix/utils/clone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ inline void init_process(pid_t tid) {
LOG("Created request response buffer with name: %s",
(SHM_COMM_CHAN_NAME_RESP + std::to_string(tid)).c_str());

const char *capio_app_name = get_capio_app_name();
const char *capio_app_name = capio_config->CAPIO_APP_NAME.c_str();
auto pid = static_cast<pid_t>(syscall_no_intercept(SYS_gettid));

/**
Expand Down
Loading
Loading