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/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..0fc3af5fd 100644 --- a/src/posix/handlers/access.hpp +++ b/src/posix/handlers/access.hpp @@ -19,7 +19,11 @@ int access_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a path = capio_posix_realpath(pathname); } - consent_request_cache_fs->consent_request(path, tid, __FUNCTION__); + char resolved_path[PATH_MAX]; + syscall_no_intercept(SYS_readlink, path.c_str(), resolved_path, PATH_MAX); + LOG("Resolved symlink path: %s", resolved_path); + + consent_request_cache_fs->consent_request(resolved_path, tid, __FUNCTION__); return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } #endif // SYS_access @@ -32,8 +36,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; } @@ -58,7 +62,11 @@ int faccessat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, lon } } - consent_request_cache_fs->consent_request(path, tid, __FUNCTION__); + char resolved_path[PATH_MAX]; + syscall_no_intercept(SYS_readlink, path.c_str(), resolved_path, PATH_MAX); + LOG("Resolved symlink path: %s", resolved_path); + + consent_request_cache_fs->consent_request(resolved_path, tid, __FUNCTION__); return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } #endif // SYS_faccessat diff --git a/src/posix/handlers/chdir.hpp b/src/posix/handlers/chdir.hpp index 30cd69a71..a8c52823a 100644 --- a/src/posix/handlers/chdir.hpp +++ b/src/posix/handlers/chdir.hpp @@ -11,11 +11,9 @@ int chdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar auto tid = static_cast(syscall_no_intercept(SYS_gettid)); START_LOG(tid, "call(path=%s)", pathname.data()); - - syscall_no_intercept_flag = true; + if (is_forbidden_path(pathname) || !is_capio_path(pathname)) { LOG("Path %s is forbidden: skip", pathname.data()); - syscall_no_intercept_flag = false; return CAPIO_POSIX_SYSCALL_SKIP; } @@ -23,10 +21,12 @@ int chdir_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long ar if (path.is_relative()) { path = capio_posix_realpath(path); } + char resolved_path[PATH_MAX]; + syscall_no_intercept(SYS_readlink, path.c_str(), resolved_path, PATH_MAX); + LOG("Resolved symlink path: %s", resolved_path); - consent_request_cache_fs->consent_request(path, tid, __FUNCTION__); + consent_request_cache_fs->consent_request(resolved_path, tid, __FUNCTION__); - syscall_no_intercept_flag = false; // if not a capio path, then control is given to kernel return CAPIO_POSIX_SYSCALL_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/handlers/mkdir.hpp b/src/posix/handlers/mkdir.hpp index 4ec036422..3c49902c6 100644 --- a/src/posix/handlers/mkdir.hpp +++ b/src/posix/handlers/mkdir.hpp @@ -33,7 +33,11 @@ inline off64_t capio_mkdirat(int dirfd, const std::string_view &pathname, mode_t if (is_capio_path(path)) { - create_request(-1, path, tid); + char resolved_path[PATH_MAX]; + syscall_no_intercept(SYS_readlink, path.c_str(), resolved_path, PATH_MAX); + LOG("Resolved symlink path: %s", resolved_path); + + create_request(-1, resolved_path, tid); } return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } diff --git a/src/posix/handlers/open.hpp b/src/posix/handlers/open.hpp index f62d7cf6c..dc5138a37 100644 --- a/src/posix/handlers/open.hpp +++ b/src/posix/handlers/open.hpp @@ -87,18 +87,30 @@ int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg create_request(-1, path.data(), tid); } else { LOG("not O_CREAT"); - open_request(-1, path.data(), tid); + open_request(-1, path, tid); } } else { LOG("Not a CAPIO path. skipping..."); return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } - int fd = static_cast(syscall_no_intercept(SYS_open, arg0, arg1, arg2, arg3, arg4, arg5)); + char resolved_path[PATH_MAX]; + syscall_no_intercept(SYS_readlink, path.c_str(), resolved_path, PATH_MAX); + LOG("Resolved symlink path: %s", resolved_path); + + /* + * Here it might happen that we try to open a symbolic link. instead of opening the link, we + * open the resolved link. in this way, when we get the associated path from the File + * descriptor, we ensure that the file descriptor is associated to the real file. This way the + * server always check on the real file and not on the link + */ + + int fd = static_cast(syscall_no_intercept(SYS_open, reinterpret_cast(resolved_path), + arg1, arg2, arg3, arg4, arg5)); if (is_capio_path(path) && fd >= 0) { LOG("Adding capio path"); - add_capio_fd(tid, path, fd, 0, (flags & O_CLOEXEC) == O_CLOEXEC); + add_capio_fd(tid, resolved_path, fd, 0, (flags & O_CLOEXEC) == O_CLOEXEC); } *result = fd; @@ -136,12 +148,20 @@ int openat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } - int fd = static_cast(syscall_no_intercept(SYS_openat, arg0, arg1, arg2, arg3, arg4, arg5)); + char resolved_path[PATH_MAX]; + syscall_no_intercept(SYS_readlinkat, arg0, path.c_str(), resolved_path, PATH_MAX); + LOG("Resolved symlink path: %s", resolved_path); + + /** + * Using readlinkat, we have the realpath of the symbolic link, and we can perform a normal open + */ + int fd = static_cast(syscall_no_intercept(SYS_open, reinterpret_cast(resolved_path), + arg1, arg2, arg3, arg4, arg5)); LOG("fd=%d", fd); if (is_capio_path(path) && fd >= 0) { LOG("Adding capio path"); - add_capio_fd(tid, path, fd, 0, (flags & O_CLOEXEC) == O_CLOEXEC); + add_capio_fd(tid, resolved_path, fd, 0, (flags & O_CLOEXEC) == O_CLOEXEC); } *result = fd; diff --git a/src/posix/handlers/posix_readdir.hpp b/src/posix/handlers/posix_readdir.hpp index 9a852596e..347ebb63b 100644 --- a/src/posix/handlers/posix_readdir.hpp +++ b/src/posix/handlers/posix_readdir.hpp @@ -202,7 +202,12 @@ DIR *opendir(const char *name) { } LOG("Performing consent request to open directory %s", absolute_path.c_str()); - consent_request_cache_fs->consent_request(absolute_path.c_str(), gettid(), __FUNCTION__); + + char resolved_path[PATH_MAX]; + syscall_no_intercept(SYS_readlink, absolute_path.c_str(), resolved_path, PATH_MAX); + LOG("Resolved symlink path: %s", resolved_path); + + consent_request_cache_fs->consent_request(resolved_path, gettid(), __FUNCTION__); syscall_no_intercept_flag = true; auto dir = real_opendir(absolute_path.c_str()); @@ -211,7 +216,7 @@ DIR *opendir(const char *name) { if (directory_commit_token_path.find(absolute_path) == directory_commit_token_path.end()) { LOG("Commit token path was not found for path %s", absolute_path.c_str()); auto token_path = new char[PATH_MAX]{0}; - posix_directory_committed_request(capio_syscall(SYS_gettid), absolute_path, token_path); + posix_directory_committed_request(capio_syscall(SYS_gettid), resolved_path, token_path); LOG("Inserting token path %s", token_path); directory_commit_token_path.insert({absolute_path, token_path}); } @@ -222,7 +227,7 @@ DIR *opendir(const char *name) { directory_items->emplace(std::string(absolute_path), new std::vector()); auto fd = dirfd(dir); - LOG("File descriptor for directory %s is %d", absolute_path.c_str(), fd); + LOG("File descriptor for directory %s is %d", resolved_path, fd); add_capio_fd(capio_syscall(SYS_gettid), absolute_path.c_str(), fd, 0, 0); diff --git a/src/posix/handlers/stat.hpp b/src/posix/handlers/stat.hpp index 76e8ffd73..733c50a58 100644 --- a/src/posix/handlers/stat.hpp +++ b/src/posix/handlers/stat.hpp @@ -28,7 +28,11 @@ inline int capio_lstat(const std::string_view &pathname, struct stat *statbuf, p const std::filesystem::path absolute_path(pathname); if (is_capio_path(absolute_path)) { - consent_request_cache_fs->consent_request(pathname, tid, __FUNCTION__); + char resolved_path[PATH_MAX]; + syscall_no_intercept(SYS_readlink, absolute_path.c_str(), resolved_path, PATH_MAX); + LOG("Resolved symlink path: %s", resolved_path); + + consent_request_cache_fs->consent_request(resolved_path, tid, __FUNCTION__); } return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } diff --git a/src/posix/handlers/statx.hpp b/src/posix/handlers/statx.hpp index 86abbb9f6..16d9bb764 100644 --- a/src/posix/handlers/statx.hpp +++ b/src/posix/handlers/statx.hpp @@ -18,7 +18,11 @@ inline int capio_statx(int dirfd, const std::string_view &pathname, int flags, i std::filesystem::path path(pathname); if (is_capio_path(path)) { - consent_request_cache_fs->consent_request(path, tid, __FUNCTION__); + char resolved_path[PATH_MAX]; + syscall_no_intercept(SYS_readlink, path.c_str(), resolved_path, PATH_MAX); + LOG("Resolved symlink path: %s", resolved_path); + + consent_request_cache_fs->consent_request(resolved_path, tid, __FUNCTION__); } return CAPIO_POSIX_SYSCALL_REQUEST_SKIP; } 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..9727d37f9 100644 --- a/src/posix/utils/cache/consent_request_cache.hpp +++ b/src/posix/utils/cache/consent_request_cache.hpp @@ -5,9 +5,9 @@ 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, - const long tid, - const std::string &source_func) { + 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(), tid, source_func.c_str()); char req[CAPIO_REQ_MAX_SIZE]; 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/capio-cl-engine/json_parser.hpp b/src/server/capio-cl-engine/json_parser.hpp index a6d5a4891..3fa26ae28 100644 --- a/src/server/capio-cl-engine/json_parser.hpp +++ b/src/server/capio-cl-engine/json_parser.hpp @@ -48,17 +48,21 @@ class JsonParser { * @param source * @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()); + 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()); + + /* + * 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 = resolve_prexix / 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 = resolve_prexix / 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 = resolve_prexix / 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 = resolve_prexix / 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 = resolve_prexix / 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 = resolve_prexix / 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 = resolve_prexix / path; } // TODO: check for globs - if (first_is_subpath_of_second(path, get_capio_dir())) { - 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/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..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"}); @@ -125,9 +129,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 << " ] " @@ -174,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); }