From 2d141b99e74b5aace34d6a34bea7d49d22a79abf Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Fri, 1 Aug 2025 12:35:22 +0000 Subject: [PATCH 1/3] Removed get_capio_dir() from server component, except from parser --- src/posix/handlers.hpp | 1 - src/posix/handlers/access.hpp | 4 +-- src/posix/handlers/getdents.hpp | 34 ------------------- src/posix/libcapio_posix.cpp | 6 ---- .../utils/cache/consent_request_cache.hpp | 2 +- src/posix/utils/requests.hpp | 9 +++++ .../capio-cl-engine/capio_cl_engine.hpp | 15 -------- src/server/client-manager/handlers/close.hpp | 5 --- .../client-manager/handlers/consent.hpp | 2 +- src/server/client-manager/handlers/read.hpp | 6 ---- src/server/client-manager/handlers/write.hpp | 5 --- src/server/file-manager/file_manager_impl.hpp | 2 +- .../storage-service/capio_storage_service.hpp | 4 +-- src/server/utils/parser.hpp | 3 -- 14 files changed, 15 insertions(+), 83 deletions(-) delete mode 100644 src/posix/handlers/getdents.hpp diff --git a/src/posix/handlers.hpp b/src/posix/handlers.hpp index 6cbd7172d..6f994c28f 100644 --- a/src/posix/handlers.hpp +++ b/src/posix/handlers.hpp @@ -17,7 +17,6 @@ #include "handlers/fgetxattr.hpp" #include "handlers/fork.hpp" #include "handlers/getcwd.hpp" -#include "handlers/getdents.hpp" #include "handlers/ioctl.hpp" #include "handlers/lseek.hpp" #include "handlers/mkdir.hpp" diff --git a/src/posix/handlers/access.hpp b/src/posix/handlers/access.hpp index 56c48eabc..3990e883d 100644 --- a/src/posix/handlers/access.hpp +++ b/src/posix/handlers/access.hpp @@ -32,8 +32,8 @@ int faccessat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, lon auto tid = static_cast(syscall_no_intercept(SYS_gettid)); START_LOG(tid, "call()"); - if (is_forbidden_path(pathname)) { - LOG("Path %s is forbidden: skip", pathname.data()); + if (is_forbidden_path(pathname) || !is_capio_path(pathname)) { + LOG("Path %s is forbidden or is not a capio path: skip", pathname.data()); return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } diff --git a/src/posix/handlers/getdents.hpp b/src/posix/handlers/getdents.hpp deleted file mode 100644 index a98977c9c..000000000 --- a/src/posix/handlers/getdents.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CAPIO_POSIX_HANDLERS_GETDENTS_HPP -#define CAPIO_POSIX_HANDLERS_GETDENTS_HPP - -// TODO: too similar to capio_read, refactoring needed -inline int getdents_handler_impl(long arg0, long arg1, long arg2, long *result, bool is64bit) { - auto fd = static_cast(arg0); - auto *buffer = reinterpret_cast(arg1); - auto count = static_cast(arg2); - auto tid = static_cast(syscall_no_intercept(SYS_gettid)); - - START_LOG(tid, "call(fd=%d, dirp=0x%08x, count=%ld, is64bit=%s)", fd, buffer, count, - is64bit ? "true" : "false"); - - if (exists_capio_fd(fd)) { - consent_request_cache_fs->consent_request(get_capio_fd_path(fd), tid, __FUNCTION__); - } - return CAPIO_POSIX_SYSCALL_SKIP; -} - -#if defined(SYS_getdents) -inline int getdents_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { - return getdents_handler_impl(arg0, arg1, arg2, result, false); -} -#endif // SYS_getdents - -#if defined(SYS_getdents64) -inline int getdents64_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, - long *result) { - return getdents_handler_impl(arg0, arg1, arg2, result, true); -} -#endif // SYS_getdents64 - -#endif // CAPIO_POSIX_HANDLERS_GETDENTS_HPP diff --git a/src/posix/libcapio_posix.cpp b/src/posix/libcapio_posix.cpp index 4676ee24f..0e055fad2 100644 --- a/src/posix/libcapio_posix.cpp +++ b/src/posix/libcapio_posix.cpp @@ -287,12 +287,6 @@ static constexpr std::array build_syscall_table( #ifdef SYS_getcwd _syscallTable[SYS_getcwd] = getcwd_handler; #endif -#ifdef SYS_getdents - _syscallTable[SYS_getdents] = getdents_handler; -#endif -#ifdef SYS_getdents64 - _syscallTable[SYS_getdents64] = getdents64_handler; -#endif #ifdef SYS_getxattr _syscallTable[SYS_getxattr] = not_implemented_handler; #endif diff --git a/src/posix/utils/cache/consent_request_cache.hpp b/src/posix/utils/cache/consent_request_cache.hpp index bf5cced10..bf3f6033f 100644 --- a/src/posix/utils/cache/consent_request_cache.hpp +++ b/src/posix/utils/cache/consent_request_cache.hpp @@ -5,7 +5,7 @@ class ConsentRequestCache { std::unordered_map *available_consent; // Block until server allows for proceeding to a generic request - static inline capio_off64_t _consent_to_proceed_request(const std::filesystem::path &path, + static capio_off64_t _consent_to_proceed_request(const std::filesystem::path &path, const long tid, const std::string &source_func) { START_LOG(capio_syscall(SYS_gettid), "call(path=%s, tid=%ld, source_func=%s)", path.c_str(), diff --git a/src/posix/utils/requests.hpp b/src/posix/utils/requests.hpp index 4390c7651..2f7847b10 100644 --- a/src/posix/utils/requests.hpp +++ b/src/posix/utils/requests.hpp @@ -69,6 +69,15 @@ inline std::vector *file_in_memory_request(const long pid) { auto file = new char[PATH_MAX]{}; stc_queue->read(file, PATH_MAX); LOG("Obtained path %s", file); + + if (file[0] == '*') { + LOG("Obtained all file regex. converting it to be coherent with CAPIO paths"); + auto c_dir = get_capio_dir().string(); + memcpy(file, c_dir.c_str(), c_dir.length()); + memcpy(file + c_dir.size(), "/*", 2); + LOG("Generated path relative to CAPIO_DIR: %s", file); + } + regex_vector->emplace_back(generateCapioRegex(file)); delete[] file; } diff --git a/src/server/capio-cl-engine/capio_cl_engine.hpp b/src/server/capio-cl-engine/capio_cl_engine.hpp index 2f56bc5de..37beec325 100644 --- a/src/server/capio-cl-engine/capio_cl_engine.hpp +++ b/src/server/capio-cl-engine/capio_cl_engine.hpp @@ -122,21 +122,6 @@ class CapioCLEngine { std::cout << std::endl; }; - // TODO: might need to be improved - static bool fileToBeHandled(std::filesystem::path::iterator::reference path) { - START_LOG(gettid(), "call(path=%s)", path.c_str()); - - if (path == get_capio_dir()) { - LOG("Path is capio_dir. Ignoring."); - return false; - } - - LOG("Parent path=%s", path.parent_path().c_str()); - LOG("Path %s be handled by CAPIO", - path.parent_path().string().rfind(get_capio_dir(), 0) == 0 ? "SHOULD" : "SHOULD NOT"); - return path.parent_path().string().rfind(get_capio_dir(), 0) == 0; - }; - /** * Check whether the file is contained inside the location, either by direct name or by glob * @param file diff --git a/src/server/client-manager/handlers/close.hpp b/src/server/client-manager/handlers/close.hpp index 12fd6b476..86fb6f731 100644 --- a/src/server/client-manager/handlers/close.hpp +++ b/src/server/client-manager/handlers/close.hpp @@ -16,11 +16,6 @@ inline void close_handler(const char *const str) { const std::filesystem::path filename(path); - if (!CapioCLEngine::fileToBeHandled(filename)) { - LOG("File should not be handled"); - return; - } - LOG("File needs handling"); // Call the set_committed method only if the commit rule is on_close and calling thread is a diff --git a/src/server/client-manager/handlers/consent.hpp b/src/server/client-manager/handlers/consent.hpp index da537931a..e306a7fdc 100644 --- a/src/server/client-manager/handlers/consent.hpp +++ b/src/server/client-manager/handlers/consent.hpp @@ -15,7 +15,7 @@ inline void consent_to_proceed_handler(const char *const str) { START_LOG(gettid(), "call(tid=%d, path=%s, source=%s)", tid, path, source_func); // Skip operations on CAPIO_DIR - if (!CapioCLEngine::fileToBeHandled(path) || !capio_cl_engine->contains(path)) { + if (!capio_cl_engine->contains(path)) { LOG("Ignore calls as file should not be treated by CAPIO"); client_manager->reply_to_client(tid, 1); return; diff --git a/src/server/client-manager/handlers/read.hpp b/src/server/client-manager/handlers/read.hpp index befba4f5a..7d2cc1204 100644 --- a/src/server/client-manager/handlers/read.hpp +++ b/src/server/client-manager/handlers/read.hpp @@ -17,12 +17,6 @@ inline void read_handler(const char *const str) { START_LOG(gettid(), "call(path=%s, tid=%ld, end_of_read=%llu)", path, tid, end_of_read); const std::filesystem::path path_fs(path); - // Skip operations on CAPIO_DIR - if (!CapioCLEngine::fileToBeHandled(path_fs)) { - LOG("Ignore calls as file should not be treated by CAPIO"); - client_manager->reply_to_client(tid, 1); - return; - } /** * If process is producer OR fire rule is no update and there is enough data, allow the process diff --git a/src/server/client-manager/handlers/write.hpp b/src/server/client-manager/handlers/write.hpp index 78ec1c7ad..d02ea615c 100644 --- a/src/server/client-manager/handlers/write.hpp +++ b/src/server/client-manager/handlers/write.hpp @@ -16,11 +16,6 @@ inline void write_handler(const char *const str) { char path[PATH_MAX]; sscanf(str, "%d %d %s %llu", &tid, &fd, path, &write_size); START_LOG(gettid(), "call(tid=%d, fd=%d, path=%s, count=%llu)", tid, fd, path, write_size); - std::filesystem::path filename(path); - - if (!CapioCLEngine::fileToBeHandled(filename)) { - return; - } /** * File needs to be handled, however, to not overload the client manager thread, on which diff --git a/src/server/file-manager/file_manager_impl.hpp b/src/server/file-manager/file_manager_impl.hpp index dc8b4ca0d..c10d222bd 100644 --- a/src/server/file-manager/file_manager_impl.hpp +++ b/src/server/file-manager/file_manager_impl.hpp @@ -7,7 +7,7 @@ #include "utils/distributed_semaphore.hpp" inline std::string CapioFileManager::getMetadataPath(const std::string &path) { - return get_capio_metadata_path() / (path.substr(path.find(get_capio_dir()) + 1) + ".capio"); + return get_capio_metadata_path() / (path + ".capio"); } /** diff --git a/src/server/storage-service/capio_storage_service.hpp b/src/server/storage-service/capio_storage_service.hpp index 27b0b672d..d5722617d 100644 --- a/src/server/storage-service/capio_storage_service.hpp +++ b/src/server/storage-service/capio_storage_service.hpp @@ -198,9 +198,7 @@ class CapioStorageService { if (StoreOnlyInMemory) { LOG("All files should be handled in memory. sending * wildcard"); char f[PATH_MAX + 1]{0}; - auto c_dir = get_capio_dir().string(); - memcpy(f, c_dir.c_str(), c_dir.length()); - memcpy(f + c_dir.size(), "/*", 2); + f[0] = '*'; _server_to_client_queue->at(pid)->write(f, PATH_MAX); LOG("Return value=%llu", 1); return 1; diff --git a/src/server/utils/parser.hpp b/src/server/utils/parser.hpp index cfa40f38b..7ec7bc01f 100644 --- a/src/server/utils/parser.hpp +++ b/src/server/utils/parser.hpp @@ -125,9 +125,6 @@ std::string parseCLI(int argc, char **argv) { ERR_EXIT("no config file provided, and --no-config not provided"); } - std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_INFO << " [ " << node_name << " ] " - << "CAPIO_DIR=" << get_capio_dir().c_str() << std::endl; - #ifdef CAPIO_LOG CAPIO_LOG_LEVEL = get_capio_log_level(); std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_INFO << " [ " << node_name << " ] " From 5a07a4819aa188db832eb6d73e145004904df338 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Fri, 1 Aug 2025 12:54:53 +0000 Subject: [PATCH 2/3] Removed get_capio_dir() from parser --- .../utils/cache/consent_request_cache.hpp | 4 +- src/server/capio-cl-engine/json_parser.hpp | 120 +++++++++++------- 2 files changed, 77 insertions(+), 47 deletions(-) diff --git a/src/posix/utils/cache/consent_request_cache.hpp b/src/posix/utils/cache/consent_request_cache.hpp index bf3f6033f..9727d37f9 100644 --- a/src/posix/utils/cache/consent_request_cache.hpp +++ b/src/posix/utils/cache/consent_request_cache.hpp @@ -6,8 +6,8 @@ class ConsentRequestCache { // Block until server allows for proceeding to a generic request static capio_off64_t _consent_to_proceed_request(const std::filesystem::path &path, - const long tid, - const std::string &source_func) { + const long tid, + const std::string &source_func) { START_LOG(capio_syscall(SYS_gettid), "call(path=%s, tid=%ld, source_func=%s)", path.c_str(), tid, source_func.c_str()); char req[CAPIO_REQ_MAX_SIZE]; diff --git a/src/server/capio-cl-engine/json_parser.hpp b/src/server/capio-cl-engine/json_parser.hpp index a6d5a4891..2f84de95f 100644 --- a/src/server/capio-cl-engine/json_parser.hpp +++ b/src/server/capio-cl-engine/json_parser.hpp @@ -49,16 +49,20 @@ class JsonParser { * @return CapioCLEngine instance with the information provided by the config file */ static CapioCLEngine *parse(const std::filesystem::path &source) { - auto locations = new CapioCLEngine(); - const auto &capio_dir = get_capio_dir(); - - START_LOG(gettid(), "call(config_file='%s', capio_dir='%s')", source.c_str(), - capio_dir.c_str()); - - locations->newFile(get_capio_dir()); - locations->setDirectory(get_capio_dir()); + auto locations = new CapioCLEngine(); + + START_LOG(gettid(), "call(config_file='%s')", source.c_str()); + + /* + * Before here a call to get_capio_dir() was issued. However, to support multiple CAPIO_DIRs + * there is no difference to use the wildcard * instead of CAPIO_DIR. This is true as only + * paths relative to the capio_dir directory are forwarded to the server, and as such, there + * is no difference that to create a ROOT dir equal to CAPIO_DIR compared to the wildcard *. + */ + locations->newFile("*"); + locations->setDirectory("*"); if (StoreOnlyInMemory) { - locations->setStoreFileInMemory(get_capio_dir()); + locations->setStoreFileInMemory("*"); } if (source.empty()) { @@ -117,22 +121,20 @@ class JsonParser { std::filesystem::path file(itm.get_string().take_value()); std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " << "Found file : " << file << std::endl; - if (file.is_relative() || first_is_subpath_of_second(file, get_capio_dir())) { - std::string appname(app_name); - std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " - << "File : " << file << " added to app: " << app_name - << std::endl; - if (file.is_relative()) { - file = capio_dir / file; - } - locations->newFile(file.c_str()); - locations->addConsumer(file, appname); - } else { + if (file.is_relative()) { std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << " [ " << node_name << " ] " << "File : " << file - << " is not relative to CAPIO_DIR. Ignoring..." << std::endl; + << " IS RELATIVE! using cwd() of server to compute abs path." + << std::endl; + file = std::filesystem::current_path() / file; } + std::string appname(app_name); + std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " + << "File : " << file << " added to app: " << app_name << std::endl; + + locations->newFile(file.c_str()); + locations->addConsumer(file, appname); } std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " @@ -148,17 +150,22 @@ class JsonParser { } else { for (auto itm : output_stream) { std::filesystem::path file(itm.get_string().take_value()); - if (file.is_relative() || first_is_subpath_of_second(file, get_capio_dir())) { - std::string appname(app_name); - std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " - << "Adding file: " << file << " to app: " << app_name - << std::endl; + if (file.is_relative()) { if (file.is_relative()) { - file = capio_dir / file; + std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << " [ " << node_name + << " ] " + << "File : " << file + << " IS RELATIVE! using cwd() of server to compute abs path." + << std::endl; + file = std::filesystem::current_path() / file; } - locations->newFile(file); - locations->addProducer(file, appname); } + std::string appname(app_name); + std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " + << "Adding file: " << file << " to app: " << app_name << std::endl; + + locations->newFile(file); + locations->addProducer(file, appname); } std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " << "Completed output_stream parsing for app: " << app_name << std::endl; @@ -199,11 +206,16 @@ class JsonParser { std::string_view elem = item.get_string().value(); LOG("Found name: %s", std::string(elem).c_str()); std::filesystem::path file_fs(elem); - if (file_fs.is_relative() || - first_is_subpath_of_second(file_fs, get_capio_dir())) { - LOG("Saving file %s to locations", std::string(elem).c_str()); - streaming_names.emplace_back(elem); + if (file_fs.is_relative()) { + std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << " [ " << node_name + << " ] " + << "File : " << file_fs + << " IS RELATIVE! using cwd() of server to compute abs path." + << std::endl; + file_fs = std::filesystem::current_path() / file_fs; } + LOG("Saving file %s to locations", std::string(elem).c_str()); + streaming_names.emplace_back(elem); } // PARSING COMMITTED @@ -254,9 +266,15 @@ class JsonParser { for (auto itm : file_deps_tmp) { name_tmp = itm.get_string().value(); std::filesystem::path computed_path(name_tmp); - computed_path = computed_path.is_relative() - ? (get_capio_dir() / computed_path) - : computed_path; + if (computed_path.is_relative()) { + std::cout + << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << " [ " << node_name + << " ] " + << "File : " << computed_path + << " IS RELATIVE! using cwd() of server to compute abs path." + << std::endl; + computed_path = std::filesystem::current_path() / computed_path; + } std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " << "Adding file: " << computed_path @@ -289,8 +307,14 @@ class JsonParser { std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " << " [ " << node_name << " ] " << "Updating metadata for path: " << path << std::endl; + if (path.is_relative()) { - path = (capio_dir / path).lexically_normal(); + std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << " [ " << node_name + << " ] " + << "Path : " << path + << " IS RELATIVE! using cwd() of server to compute abs path." + << std::endl; + path = std::filesystem::current_path() / path; } LOG("path: %s", path.c_str()); @@ -343,12 +367,16 @@ class JsonParser { std::filesystem::path path(name); if (path.is_relative()) { - path = (capio_dir / path).lexically_normal(); + std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << " [ " << node_name << " ] " + << "Path : " << path + << " IS RELATIVE! using cwd() of server to compute abs path." + << std::endl; + path = std::filesystem::current_path() / path; } + // TODO: check for globs - if (first_is_subpath_of_second(path, get_capio_dir())) { - locations->setPermanent(name.data(), true); - } + // TODO: improve this + locations->setPermanent(name.data(), true); } std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " << "Completed parsing of permanent files" << std::endl; @@ -374,12 +402,14 @@ class JsonParser { std::filesystem::path path(name); if (path.is_relative()) { - path = (capio_dir / path).lexically_normal(); + std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << " [ " << node_name << " ] " + << "Path : " << path + << " IS RELATIVE! using cwd() of server to compute abs path." + << std::endl; + path = std::filesystem::current_path() / path; } // TODO: check for globs - if (first_is_subpath_of_second(path, get_capio_dir())) { - locations->setExclude(name.data(), true); - } + locations->setExclude(name.data(), true); } std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " << "Completed parsing of exclude files" << std::endl; From e821427d773bc6adb052289a66a88b3ffc1830c4 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Fri, 1 Aug 2025 13:14:18 +0000 Subject: [PATCH 3/3] Added flag to provide a path to resolve capio-cl configuration files when paths are relative. --- src/common/capio/constants.hpp | 4 ++++ src/server/capio-cl-engine/json_parser.hpp | 20 ++++++++++---------- src/server/capio_server.cpp | 6 ++++-- src/server/utils/parser.hpp | 16 +++++++++++++++- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/common/capio/constants.hpp b/src/common/capio/constants.hpp index e07920bcf..fffa1502c 100644 --- a/src/common/capio/constants.hpp +++ b/src/common/capio/constants.hpp @@ -155,6 +155,10 @@ 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_CONFIG_RESOLVE_RELATIVE_TO_HELP[] = + "When finding relative paths in the CAPIO-CL configuration file, resolve them relative to the " + "provided path"; + constexpr char CAPIO_SERVER_ARG_PARSER_CONFIG_CONTROL_PLANE_BACKEND[] = "Which control plane backend to used. Options: . Defaults to "; diff --git a/src/server/capio-cl-engine/json_parser.hpp b/src/server/capio-cl-engine/json_parser.hpp index 2f84de95f..3fa26ae28 100644 --- a/src/server/capio-cl-engine/json_parser.hpp +++ b/src/server/capio-cl-engine/json_parser.hpp @@ -48,9 +48,9 @@ class JsonParser { * @param source * @return CapioCLEngine instance with the information provided by the config file */ - static CapioCLEngine *parse(const std::filesystem::path &source) { + static CapioCLEngine *parse(const std::filesystem::path &source, + const std::filesystem::path resolve_prexix) { auto locations = new CapioCLEngine(); - START_LOG(gettid(), "call(config_file='%s')", source.c_str()); /* @@ -127,7 +127,7 @@ class JsonParser { << "File : " << file << " IS RELATIVE! using cwd() of server to compute abs path." << std::endl; - file = std::filesystem::current_path() / file; + file = resolve_prexix / file; } std::string appname(app_name); std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " @@ -157,7 +157,7 @@ class JsonParser { << "File : " << file << " IS RELATIVE! using cwd() of server to compute abs path." << std::endl; - file = std::filesystem::current_path() / file; + file = resolve_prexix / file; } } std::string appname(app_name); @@ -212,7 +212,7 @@ class JsonParser { << "File : " << file_fs << " IS RELATIVE! using cwd() of server to compute abs path." << std::endl; - file_fs = std::filesystem::current_path() / file_fs; + file_fs = resolve_prexix / file_fs; } LOG("Saving file %s to locations", std::string(elem).c_str()); streaming_names.emplace_back(elem); @@ -273,7 +273,7 @@ class JsonParser { << "File : " << computed_path << " IS RELATIVE! using cwd() of server to compute abs path." << std::endl; - computed_path = std::filesystem::current_path() / computed_path; + computed_path = resolve_prexix / computed_path; } std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " @@ -314,7 +314,7 @@ class JsonParser { << "Path : " << path << " IS RELATIVE! using cwd() of server to compute abs path." << std::endl; - path = std::filesystem::current_path() / path; + path = resolve_prexix / path; } LOG("path: %s", path.c_str()); @@ -371,7 +371,7 @@ class JsonParser { << "Path : " << path << " IS RELATIVE! using cwd() of server to compute abs path." << std::endl; - path = std::filesystem::current_path() / path; + path = resolve_prexix / path; } // TODO: check for globs @@ -406,10 +406,10 @@ class JsonParser { << "Path : " << path << " IS RELATIVE! using cwd() of server to compute abs path." << std::endl; - path = std::filesystem::current_path() / path; + path = resolve_prexix / path; } // TODO: check for globs - locations->setExclude(name.data(), true); + locations->setExclude(path, true); } std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] " << "Completed parsing of exclude files" << std::endl; diff --git a/src/server/capio_server.cpp b/src/server/capio_server.cpp index 835902552..d5fc87afc 100644 --- a/src/server/capio_server.cpp +++ b/src/server/capio_server.cpp @@ -53,12 +53,14 @@ int main(int argc, char **argv) { CAPIO_SERVER_MAIN_PID = gettid(); std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_INFO << " [ " << node_name << " ] " << "Started server with PID: " << CAPIO_SERVER_MAIN_PID << std::endl; - const std::string config_path = parseCLI(argc, argv); + + char resolve_prefix[PATH_MAX]{0}; + const std::string config_path = parseCLI(argc, argv, resolve_prefix); START_LOG(gettid(), "call()"); setup_signal_handlers(); - capio_cl_engine = JsonParser::parse(config_path); + capio_cl_engine = JsonParser::parse(config_path, std::filesystem::path(resolve_prefix)); shm_canary = new CapioShmCanary(workflow_name); file_manager = new CapioFileManager(); fs_monitor = new FileSystemMonitor(); diff --git a/src/server/utils/parser.hpp b/src/server/utils/parser.hpp index 7ec7bc01f..52e617a02 100644 --- a/src/server/utils/parser.hpp +++ b/src/server/utils/parser.hpp @@ -1,7 +1,7 @@ #ifndef PARSER_HPP #define PARSER_HPP -std::string parseCLI(int argc, char **argv) { +std::string parseCLI(int argc, char **argv, char *resolve_prefix) { Logger *log; args::ArgumentParser parser(CAPIO_SERVER_ARG_PARSER_PRE, CAPIO_SERVER_ARG_PARSER_EPILOGUE); @@ -33,6 +33,10 @@ std::string parseCLI(int argc, char **argv) { args::Flag memStorageOnly(arguments, "mem-storage-only", CAPIO_SERVER_ARG_PARSER_CONFIG_NCONTINUE_ON_ERROR_HELP, {"mem-only"}); + args::ValueFlag capio_cl_resolve_path( + arguments, "capio-cl-relative-to", CAPIO_SERVER_ARG_PARSER_CONFIG_RESOLVE_RELATIVE_TO_HELP, + {"resolve-capiocl-to"}); + args::ValueFlag controlPlaneBackend( arguments, "backend", CAPIO_SERVER_ARG_PARSER_CONFIG_CONTROL_PLANE_BACKEND, {"control-backend"}); @@ -171,6 +175,16 @@ std::string parseCLI(int argc, char **argv) { capio_backend = new NoBackend(); } + if (capio_cl_resolve_path) { + auto path = args::get(capio_cl_resolve_path); + memcpy(resolve_prefix, path.c_str(), PATH_MAX); + std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_INFO << " [ " << node_name << " ] " + << "CAPIO-CL relative file prefix: " << resolve_prefix << std::endl; + } else { + std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << " [ " << node_name << " ] " + << "No CAPIO-CL resolve file prefix provided" << std::endl; + } + if (config) { return args::get(config); }