diff --git a/CHANGELOG.md b/CHANGELOG.md index c2148a4f4750702057aaa61c726f99baf5e278ee..b84153468c6303d380a7c6ae57b7b7007151c6b6 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)). diff --git a/include/client/hooks.hpp b/include/client/hooks.hpp index fa9ec424bc606a941650edb253a20781af54cf8d..a287f6d3cbd8a646b10cc6981d16ad8b62b9397d 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 9a54048c544dc1bfbcf096a448b913e52114ad0b..020d5040c112985950c16623a13942137ffe1da3 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 7a8a455fe4aa63f6f3eab2bec381023dfbb888f0..87792bfbdb3722c57ebe11a49a7f1853cea23e8a 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