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
16 changes: 12 additions & 4 deletions capio-posix/handlers/open.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ int open_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long arg
create_request(-1, resolved_path.data(), tid);
} else {
LOG("not O_CREAT");
open_request(-1, resolved_path.data(), tid);
if (open_request(-1, resolved_path.data(), tid) == 0) {
LOG("File is excluded! Skipping open of file!");
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
}
}

int fd = static_cast<int>(syscall_no_intercept(SYS_open, arg0, arg1, arg2, arg3, arg4, arg5));
const int fd =
static_cast<int>(syscall_no_intercept(SYS_open, arg0, arg1, arg2, arg3, arg4, arg5));

LOG("Adding capio path");
add_capio_fd(tid, resolved_path, fd, 0, (flags & O_CLOEXEC) == O_CLOEXEC);
Expand Down Expand Up @@ -124,10 +128,14 @@ int openat_handler(long arg0, long arg1, long arg2, long arg3, long arg4, long a
create_request(-1, resolved_path.data(), tid);
} else {
LOG("not O_CREAT");
open_request(-1, resolved_path.data(), tid);
if (open_request(-1, resolved_path.data(), tid) == 0) {
LOG("File is excluded! Skipping open of file!");
return CAPIO_POSIX_SYSCALL_REQUEST_SKIP;
}
}

int fd = static_cast<int>(syscall_no_intercept(SYS_openat, arg0, arg1, arg2, arg3, arg4, arg5));
const int fd =
static_cast<int>(syscall_no_intercept(SYS_openat, arg0, arg1, arg2, arg3, arg4, arg5));
LOG("fd=%d", fd);

LOG("Adding resolved capio path (%s)", resolved_path.c_str());
Expand Down
2 changes: 1 addition & 1 deletion capio-posix/utils/cache/consent_request_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ConsentRequestCache {
std::unordered_map<std::string, capio_off64_t> *available_consent;

// Block until server allows for proceeding to a generic request
// Block until the 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) {
Expand Down
8 changes: 5 additions & 3 deletions capio-posix/utils/requests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,17 @@ inline void exit_group_request(const long tid) {
}

// block until open is possible
inline void open_request(const int fd, const std::filesystem::path &path, const long tid) {
[[nodiscard]] inline capio_off64_t open_request(const int fd, const std::filesystem::path &path,
const long tid) {
START_LOG(capio_syscall(SYS_gettid), "call(fd=%ld, path=%s, tid=%ld)", fd, path.c_str(), tid);
write_request_cache_fs->flush(tid);

char req[CAPIO_REQ_MAX_SIZE];
sprintf(req, "%04d %ld %d %s", CAPIO_REQUEST_OPEN, tid, fd, path.c_str());
buf_requests->write(req, CAPIO_REQ_MAX_SIZE);
capio_off64_t res = bufs_response->at(tid)->read();
LOG("Obtained from server %llu", res);
const capio_off64_t res = bufs_response->at(tid)->read();
LOG("Obtained from server %llu. File is %s exclude", res, res == 0 ? "" : "NOT");
return res;
}

// non blocking
Expand Down
1 change: 1 addition & 0 deletions capio-server/include/capio-cl-engine/capio_cl_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class CapioCLEngine {
void setDirectory(const std::string &path);
void setFile(const std::string &path);
bool isFile(const std::string &path) const;
bool isExcluded(const std::string &path) const;
bool isDirectory(const std::string &path) const;
void setCommitedNumber(const std::string &path, int num);
void setDirectoryFileCount(const std::string &path, long num);
Expand Down
18 changes: 17 additions & 1 deletion capio-server/src/capio-cl-engine/capio_cl_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void CapioCLEngine::print() const {
if (i == 0) {
std::string commit_rule = std::get<2>(itm.second),
fire_rule = std::get<3>(itm.second);
bool exclude = std::get<4>(itm.second), permanent = std::get<5>(itm.second);
bool exclude = std::get<5>(itm.second), permanent = std::get<4>(itm.second);

line << " " << commit_rule << std::setfill(' ')
<< std::setw(20 - commit_rule.length()) << " | " << fire_rule
Expand Down Expand Up @@ -431,3 +431,19 @@ auto CapioCLEngine::get_home_node(const std::string &path) {
}
return capio_global_configuration->node_name;
}

bool CapioCLEngine::isExcluded(const std::string &path) const {
START_LOG(gettid(), "call(path=%s)", path.c_str());
if (const auto itm = _locations.find(path); itm != _locations.end()) {
return std::get<5>(itm->second);
}
LOG("Checking against REGEX");
return std::any_of(_locations.begin(), _locations.end(), [&](auto &itm) {
LOG("Checking against %s", itm.first.c_str());
if (std::regex_match(path.c_str(), std::get<10>(itm.second))) {
LOG("Found match. Is excluded: %s", std::get<5>(itm.second) ? "YES" : "NO");
return std::get<5>(itm.second);
}
return false;
});
}
2 changes: 1 addition & 1 deletion capio-server/src/capio-cl-engine/json_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ CapioCLEngine *JsonParser::parse(const std::filesystem::path &source,
" IS RELATIVE! using cwd() of server to compute abs path.");
path = resolve_prexix / path;
}
// TODO: check for globs
locations->newFile(path);
locations->setExclude(path, true);
}

Expand Down
6 changes: 6 additions & 0 deletions capio-server/src/client-manager/handlers/consent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ void consent_to_proceed_handler(const char *const str) {
return;
}

if (capio_cl_engine->isExcluded(path)) {
LOG("File should NOT be handled by CAPIO as it is marked as EXCLUDED");
client_manager->reply_to_client(tid, 1);
return;
}

if (capio_cl_engine->isProducer(path, tid)) {
LOG("Application is producer. continuing");
client_manager->reply_to_client(tid, 1);
Expand Down
6 changes: 6 additions & 0 deletions capio-server/src/client-manager/handlers/open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ void open_handler(const char *const str) {
sscanf(str, "%d %d %s", &tid, &fd, path);
START_LOG(gettid(), "call(tid=%d, fd=%d, path=%s", tid, fd, path);

if (capio_cl_engine->isExcluded(path)) {
LOG("File should not be handled as it is excluded!");
client_manager->reply_to_client(tid, 0);
return;
}

if (capio_cl_engine->isProducer(path, tid)) {
LOG("Thread is producer. allowing to continue with open");
client_manager->reply_to_client(tid, 1);
Expand Down
7 changes: 6 additions & 1 deletion capio-server/src/client-manager/handlers/posix_readdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ void posix_readdir_handler(const char *const str) {
sscanf(str, "%d %s", &pid, path);
START_LOG(gettid(), "call(pid=%d, path=%s", pid, path);

auto metadata_token = file_manager->getMetadataPath(path);
if (capio_cl_engine->isExcluded(path)) {
LOG("Path is excluded. Creating commit token to avoid starvation");
CapioFileManager::setCommitted(path);
}

const auto metadata_token = CapioFileManager::getMetadataPath(path);
LOG("sending to pid %ld token path of %s", pid, metadata_token.c_str());

client_manager->reply_to_client(pid, metadata_token.length());
Expand Down
Loading