diff --git a/include/client/hooks.hpp b/include/client/hooks.hpp index 6871d8b798f9c7a4e47e7bcc1988c0478552c608..805d21f9e38440047a77933fc5ae436f0fe15a50 100644 --- a/include/client/hooks.hpp +++ b/include/client/hooks.hpp @@ -196,6 +196,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 49a166ce1988ff3f605b75b8da10c124290c116b..9451ca4181d16f1dd7d4b6b526b04abb619533e7 100644 --- a/src/client/hooks.cpp +++ b/src/client/hooks.cpp @@ -954,4 +954,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 fce6e79c6dc26093d1a0906d6adebcdb11a3b44c..678d8928244bdb7286193df7f47db11f88611948 100644 --- a/src/client/intercept.cpp +++ b/src/client/intercept.cpp @@ -758,6 +758,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