From 9325e8154ca531b814748201e7b5d2c559b1c26b Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 17 Feb 2026 10:36:24 +0100 Subject: [PATCH 1/4] Fixed bug in CapioFile class --- capio/server/include/handlers/unlink.hpp | 5 +++++ capio/server/include/storage/manager.hpp | 4 +++- capio/server/include/utils/capio_file.hpp | 14 ++++++++++++-- capio/server/src/storage_manager.cpp | 11 +++++++---- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/capio/server/include/handlers/unlink.hpp b/capio/server/include/handlers/unlink.hpp index 22b670001..9674e146d 100644 --- a/capio/server/include/handlers/unlink.hpp +++ b/capio/server/include/handlers/unlink.hpp @@ -10,19 +10,24 @@ void unlink_handler(const char *const str) { char path[PATH_MAX]; int tid; sscanf(str, "%d %s", &tid, path); + START_LOG(gettid(), "call(tid=%d, path=%s)", tid, path); if (CapioCLEngine::get().isExcluded(path)) { + LOG("File is excluded. Skipping removal"); client_manager->replyToClient(tid, CAPIO_POSIX_SYSCALL_REQUEST_SKIP); return; } const auto c_file_opt = storage_manager->tryGet(path); if (c_file_opt) { // TODO: it works only in the local case + LOG("Found local path"); CapioFile &c_file = c_file_opt->get(); if (c_file.is_deletable()) { + LOG("File is deletable!"); storage_manager->remove(path); delete_from_files_location(path); } client_manager->replyToClient(tid, 0); } else { + LOG("File not found"); client_manager->replyToClient(tid, -1); } } diff --git a/capio/server/include/storage/manager.hpp b/capio/server/include/storage/manager.hpp index d2fc927c1..624312477 100644 --- a/capio/server/include/storage/manager.hpp +++ b/capio/server/include/storage/manager.hpp @@ -96,8 +96,10 @@ class StorageManager { * @param tid The thread ID. * @param fd The file descriptor number. * @param path The path of the file being opened. + * @param register_open Whether this operation should also call open() on the CapioFile instance */ - void _addNewFdToStorage(pid_t tid, int fd, const std::filesystem::path &path); + void _addNewFdToStorage(pid_t tid, int fd, const std::filesystem::path &path, + bool register_open); public: /** diff --git a/capio/server/include/utils/capio_file.hpp b/capio/server/include/utils/capio_file.hpp index ed68732ff..21954151f 100644 --- a/capio/server/include/utils/capio_file.hpp +++ b/capio/server/include/utils/capio_file.hpp @@ -147,8 +147,10 @@ class CapioFile { } inline void close() { + START_LOG(gettid(), "call()"); _n_close++; _n_opens--; + LOG("after: _n_close=%d, n_opens=%d", _n_close, _n_opens); } void commit() { @@ -369,11 +371,19 @@ class CapioFile { return _n_close_expected == -1 || _n_close == _n_close_expected; } - [[nodiscard]] inline bool is_deletable() const { return _n_opens <= 0; } + [[nodiscard]] inline bool is_deletable() const { + START_LOG(gettid(), "call()"); + LOG("_n_opens=%d", _n_opens); + return _n_opens <= 0; + } [[nodiscard]] inline bool is_dir() const { return _directory; } - inline void open() { _n_opens++; } + inline void open() { + START_LOG(gettid(), "call()"); + _n_opens++; + LOG("after: _n_opens=%d", _n_opens); + } /* * From the manual: diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index 75267cfa4..1031307f5 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -221,7 +221,7 @@ void StorageManager::clone(const pid_t parent_tid, const pid_t child_tid) { const auto path = _opened_fd_map[parent_tid][fd]._path; const auto offset = *_opened_fd_map[parent_tid][fd]._offset; - _addNewFdToStorage(child_tid, fd, path); + _addNewFdToStorage(child_tid, fd, path, false); _addNewFdToMap(child_tid, fd, path, offset); } } @@ -276,8 +276,11 @@ void StorageManager::_addNewFdToMap(const pid_t tid, const int fd, } void StorageManager::_addNewFdToStorage(const pid_t tid, const int fd, - const std::filesystem::path &path) { - _storage[path].open(); + const std::filesystem::path &path, + const bool register_open) { + if (register_open) { + _storage[path].open(); + } _storage[path].add_fd(tid, fd); } @@ -287,7 +290,7 @@ void StorageManager::addFileToTid(const pid_t tid, const int fd, const std::file { const std::lock_guard lg(_mutex_storage); - _addNewFdToStorage(tid, fd, path); + _addNewFdToStorage(tid, fd, path, true); } { From e22b13d7feafb94dcd0c9ed4a36a8c6de20921eb Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 18 Feb 2026 11:34:08 +0000 Subject: [PATCH 2/4] cleanup --- capio/server/include/handlers/unlink.hpp | 5 ----- capio/server/include/storage/manager.hpp | 3 ++- capio/server/include/utils/capio_file.hpp | 14 ++------------ capio/server/src/storage_manager.cpp | 4 ++-- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/capio/server/include/handlers/unlink.hpp b/capio/server/include/handlers/unlink.hpp index 9674e146d..22b670001 100644 --- a/capio/server/include/handlers/unlink.hpp +++ b/capio/server/include/handlers/unlink.hpp @@ -10,24 +10,19 @@ void unlink_handler(const char *const str) { char path[PATH_MAX]; int tid; sscanf(str, "%d %s", &tid, path); - START_LOG(gettid(), "call(tid=%d, path=%s)", tid, path); if (CapioCLEngine::get().isExcluded(path)) { - LOG("File is excluded. Skipping removal"); client_manager->replyToClient(tid, CAPIO_POSIX_SYSCALL_REQUEST_SKIP); return; } const auto c_file_opt = storage_manager->tryGet(path); if (c_file_opt) { // TODO: it works only in the local case - LOG("Found local path"); CapioFile &c_file = c_file_opt->get(); if (c_file.is_deletable()) { - LOG("File is deletable!"); storage_manager->remove(path); delete_from_files_location(path); } client_manager->replyToClient(tid, 0); } else { - LOG("File not found"); client_manager->replyToClient(tid, -1); } } diff --git a/capio/server/include/storage/manager.hpp b/capio/server/include/storage/manager.hpp index 624312477..7152b5bb6 100644 --- a/capio/server/include/storage/manager.hpp +++ b/capio/server/include/storage/manager.hpp @@ -96,7 +96,8 @@ class StorageManager { * @param tid The thread ID. * @param fd The file descriptor number. * @param path The path of the file being opened. - * @param register_open Whether this operation should also call open() on the CapioFile instance + * @param register_open Whether this operation should also call open() on the CapioFile + * instance. defaults to true */ void _addNewFdToStorage(pid_t tid, int fd, const std::filesystem::path &path, bool register_open); diff --git a/capio/server/include/utils/capio_file.hpp b/capio/server/include/utils/capio_file.hpp index 21954151f..ed68732ff 100644 --- a/capio/server/include/utils/capio_file.hpp +++ b/capio/server/include/utils/capio_file.hpp @@ -147,10 +147,8 @@ class CapioFile { } inline void close() { - START_LOG(gettid(), "call()"); _n_close++; _n_opens--; - LOG("after: _n_close=%d, n_opens=%d", _n_close, _n_opens); } void commit() { @@ -371,19 +369,11 @@ class CapioFile { return _n_close_expected == -1 || _n_close == _n_close_expected; } - [[nodiscard]] inline bool is_deletable() const { - START_LOG(gettid(), "call()"); - LOG("_n_opens=%d", _n_opens); - return _n_opens <= 0; - } + [[nodiscard]] inline bool is_deletable() const { return _n_opens <= 0; } [[nodiscard]] inline bool is_dir() const { return _directory; } - inline void open() { - START_LOG(gettid(), "call()"); - _n_opens++; - LOG("after: _n_opens=%d", _n_opens); - } + inline void open() { _n_opens++; } /* * From the manual: diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index 1031307f5..d4f7eb55a 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -277,7 +277,7 @@ void StorageManager::_addNewFdToMap(const pid_t tid, const int fd, void StorageManager::_addNewFdToStorage(const pid_t tid, const int fd, const std::filesystem::path &path, - const bool register_open) { + const bool register_open = true) { if (register_open) { _storage[path].open(); } @@ -290,7 +290,7 @@ void StorageManager::addFileToTid(const pid_t tid, const int fd, const std::file { const std::lock_guard lg(_mutex_storage); - _addNewFdToStorage(tid, fd, path, true); + _addNewFdToStorage(tid, fd, path); } { From 7b9ab7400415e043035c92c5ed71c1c01b9178a6 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria <39337626+marcoSanti@users.noreply.github.com> Date: Thu, 19 Feb 2026 10:04:54 +0000 Subject: [PATCH 3/4] Add TODO for CLONE_FILES support in manager.hpp Add TODO for supporting CLONE_FILES flag in _addNewFdToStorage --- capio/server/include/storage/manager.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/capio/server/include/storage/manager.hpp b/capio/server/include/storage/manager.hpp index 7152b5bb6..12bc044b3 100644 --- a/capio/server/include/storage/manager.hpp +++ b/capio/server/include/storage/manager.hpp @@ -98,6 +98,8 @@ class StorageManager { * @param path The path of the file being opened. * @param register_open Whether this operation should also call open() on the CapioFile * instance. defaults to true + * TODO: support flag CLONE_FILES which will directly affect directly the behaviour of + * register_open. */ void _addNewFdToStorage(pid_t tid, int fd, const std::filesystem::path &path, bool register_open); @@ -303,4 +305,4 @@ class StorageManager { void updateDirectory(pid_t tid, const std::filesystem::path &file_path); }; -#endif // CAPIO_STORAGE_MANAGER_HPP \ No newline at end of file +#endif // CAPIO_STORAGE_MANAGER_HPP From ed5827385e707ec0e49abcdeaa5126fa482b53c7 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria <39337626+marcoSanti@users.noreply.github.com> Date: Thu, 19 Feb 2026 10:06:56 +0000 Subject: [PATCH 4/4] Correct TODO comment in manager.hpp Fix typo in TODO comment regarding CLONE_FILES flag. --- capio/server/include/storage/manager.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/capio/server/include/storage/manager.hpp b/capio/server/include/storage/manager.hpp index 12bc044b3..069c99132 100644 --- a/capio/server/include/storage/manager.hpp +++ b/capio/server/include/storage/manager.hpp @@ -98,7 +98,7 @@ class StorageManager { * @param path The path of the file being opened. * @param register_open Whether this operation should also call open() on the CapioFile * instance. defaults to true - * TODO: support flag CLONE_FILES which will directly affect directly the behaviour of + * TODO: support flag CLONE_FILES which will directly affect the behaviour of * register_open. */ void _addNewFdToStorage(pid_t tid, int fd, const std::filesystem::path &path,