From 1d22618b49b54056bc953ba53e8e29b5550b6d92 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Thu, 16 Feb 2023 10:18:32 +0100 Subject: [PATCH 1/2] Adding interception of fallocate and fadvise64 syscall. Not supported by GekkoFS at this time --- include/client/hooks.hpp | 6 ++++++ src/client/hooks.cpp | 24 ++++++++++++++++++++++++ src/client/intercept.cpp | 12 ++++++++++++ 3 files changed, 42 insertions(+) diff --git a/include/client/hooks.hpp b/include/client/hooks.hpp index fa9ec424b..a287f6d3c 100644 --- a/include/client/hooks.hpp +++ b/include/client/hooks.hpp @@ -205,6 +205,12 @@ hook_fsync(unsigned int fd); int hook_getxattr(const char* path, const char* name, void* value, size_t size); +int +hook_fallocate(int fd, int mode, off_t offset, off_t len); + +int +hook_fadvise64(int fd, off_t offset, off_t len, int advice); + } // namespace gkfs::hook #endif diff --git a/src/client/hooks.cpp b/src/client/hooks.cpp index 9a54048c5..020d5040c 100644 --- a/src/client/hooks.cpp +++ b/src/client/hooks.cpp @@ -983,4 +983,28 @@ hook_getxattr(const char* path, const char* name, void* value, size_t size) { return syscall_no_intercept_wrapper(SYS_getxattr, path, name, value, size); } + +int +hook_fallocate(int fd, int mode, off_t offset, off_t len) { + LOG(DEBUG, "{}() called with fd '{}' mode '{}' offset '{}' len '{}'", + __func__, fd, mode, offset, len); + + if(CTX->file_map()->exist(fd)) { + return -ENOTSUP; + } + return syscall_no_intercept_wrapper(SYS_fallocate, fd, mode, offset, len); +} + +int +hook_fadvise64(int fd, off_t offset, off_t len, int advice) { + LOG(DEBUG, "{}() called with fd '{}' offset '{}' len '{}' advice '{}'", + __func__, fd, offset, len, advice); + + if(CTX->file_map()->exist(fd)) { + return -ENOTSUP; + } + return syscall_no_intercept_wrapper(SYS_fadvise64, fd, offset, len, advice); +} + + } // namespace gkfs::hook diff --git a/src/client/intercept.cpp b/src/client/intercept.cpp index 7a8a455fe..87792bfbd 100644 --- a/src/client/intercept.cpp +++ b/src/client/intercept.cpp @@ -785,6 +785,18 @@ hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, reinterpret_cast(arg2), static_cast(arg4)); break; + case SYS_fallocate: + *result = gkfs::hook::hook_fallocate( + static_cast(arg0), static_cast(arg1), + static_cast(arg2), static_cast(arg3)); + break; + + case SYS_fadvise64: + *result = gkfs::hook::hook_fadvise64( + static_cast(arg0), static_cast(arg1), + static_cast(arg2), static_cast(arg4)); + break; + default: // ignore any other syscalls, i.e.: pass them on to the kernel // (syscalls forwarded to the kernel that return are logged in -- GitLab From 7cf9413bc8e28dc7b4349141995a676f003b25c8 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Sun, 9 Jun 2024 23:59:24 +0200 Subject: [PATCH 2/2] Update Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2148a4f4..b84153468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ### New +- Added intercepton of `fadvise64()` and + `fallocate()` ([!161](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/161)). - Added user library `gkfs_user_lib` that can be used to directly link to an application ([!171](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/171)). - FMT10 and date removal, several dependencies updated. ([!172](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/172)). -- GitLab