Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/common/capio/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: <multicast | fs>. Defaults to <multicast>";

Expand Down
1 change: 0 additions & 1 deletion src/posix/handlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/posix/handlers/access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ int faccessat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, lon
auto tid = static_cast<pid_t>(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;
}

Expand Down
34 changes: 0 additions & 34 deletions src/posix/handlers/getdents.hpp

This file was deleted.

6 changes: 0 additions & 6 deletions src/posix/libcapio_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,6 @@ static constexpr std::array<CPHandler_t, CAPIO_NR_SYSCALLS> 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
Expand Down
6 changes: 3 additions & 3 deletions src/posix/utils/cache/consent_request_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class ConsentRequestCache {
std::unordered_map<std::string, capio_off64_t> *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];
Expand Down
9 changes: 9 additions & 0 deletions src/posix/utils/requests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ inline std::vector<std::regex> *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;
}
Expand Down
15 changes: 0 additions & 15 deletions src/server/capio-cl-engine/capio_cl_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
122 changes: 76 additions & 46 deletions src/server/capio-cl-engine/json_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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 << " ] "
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/server/capio_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions src/server/client-manager/handlers/close.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/server/client-manager/handlers/consent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions src/server/client-manager/handlers/read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/server/client-manager/handlers/write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/server/file-manager/file_manager_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/**
Expand Down
Loading