From 58029802e1b247f9fcbb1f4cccb9156fbf1fb84b Mon Sep 17 00:00:00 2001 From: Julius Athenstaedt Date: Wed, 15 May 2024 15:19:24 +0200 Subject: [PATCH 1/3] Add system call: listxattr family --- include/client/hooks.hpp | 8 ++++++++ src/client/hooks.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/client/intercept.cpp | 21 +++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/include/client/hooks.hpp b/include/client/hooks.hpp index 4f21d0563..da112b983 100644 --- a/include/client/hooks.hpp +++ b/include/client/hooks.hpp @@ -214,6 +214,14 @@ 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); +// char * list is nullable (_Nullable - Clang extension) +ssize_t +hook_listxattr(const char* path, char* list, size_t size); +ssize_t +hook_llistxattr(const char* path, char* list, size_t size); +ssize_t +hook_flistxattr(int fd, char* list, size_t size); + } // namespace gkfs::hook #endif diff --git a/src/client/hooks.cpp b/src/client/hooks.cpp index 5ae152c88..7eac0e93c 100644 --- a/src/client/hooks.cpp +++ b/src/client/hooks.cpp @@ -1019,5 +1019,45 @@ hook_fadvise64(int fd, off_t offset, off_t len, int advice) { return syscall_no_intercept_wrapper(SYS_fadvise64, fd, offset, len, advice); } +ssize_t +hook_listxattr(const char* path, char* list, size_t size) { + LOG(DEBUG, "{}() called with path '{}' list '{}' size '{}'", __func__, path, + list, size); + + std::string rel_path; + if(CTX->relativize_path(path, rel_path)) { + return -ENOTSUP; + } + return syscall_no_intercept_wrapper(SYS_listxattr, path, list, size); +} + +ssize_t +hook_llistxattr(const char* path, char* list, size_t size) { + + LOG(DEBUG, "{}() called with path '{}' list '{}' size '{}'", __func__, path, + list, size); + + std::string rel_path; + if(CTX->relativize_path(path, rel_path)) { + return -ENOTSUP; + } + return syscall_no_intercept_wrapper(SYS_llistxattr, path, list, size); +} + +ssize_t +hook_flistxattr(int fd, char* list, size_t size) { + + LOG(DEBUG, "{}() called with filedescriptor '{}' list '{}' size '{}'", + __func__, fd, list, size); + + const char* newpath_path; + std::string newpath_resolved; + auto newpath_status = + CTX->relativize_fd_path(fd, newpath_path, newpath_resolved); + if(newpath_status == gkfs::preload::RelativizeStatus::internal) { + return -ENOTSUP; + } + return syscall_no_intercept_wrapper(SYS_flistxattr, fd, list, size); +} } // namespace gkfs::hook diff --git a/src/client/intercept.cpp b/src/client/intercept.cpp index ba35eb080..1086010e8 100644 --- a/src/client/intercept.cpp +++ b/src/client/intercept.cpp @@ -784,6 +784,27 @@ hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, reinterpret_cast(arg1), reinterpret_cast(arg2), static_cast(arg4)); break; +#ifdef SYS_listxattr + case SYS_listxattr: + *result = gkfs::hook::hook_listxattr( + reinterpret_cast(arg0), + reinterpret_cast(arg1), static_cast(arg2)); + break; +#endif +#ifdef SYS_llistxattr + case SYS_llistxattr: + *result = gkfs::hook::hook_llistxattr( + reinterpret_cast(arg0), + reinterpret_cast(arg1), static_cast(arg2)); + break; +#endif +#ifdef SYS_flistxattr + case SYS_flistxattr: + *result = gkfs::hook::hook_flistxattr(reinterpret_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2)); + break; +#endif case SYS_lgetxattr: *result = gkfs::hook::hook_lgetxattr( -- GitLab From 1d873b8b247c3c3e2de2d0d6dfaf628df48793d5 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Wed, 3 Jul 2024 18:11:05 +0200 Subject: [PATCH 2/3] Review --- include/client/hooks.hpp | 15 +++++------ src/client/hooks.cpp | 54 ++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/include/client/hooks.hpp b/include/client/hooks.hpp index da112b983..7044caffd 100644 --- a/include/client/hooks.hpp +++ b/include/client/hooks.hpp @@ -208,20 +208,21 @@ hook_getxattr(const char* path, const char* name, void* value, size_t size); int hook_lgetxattr(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); - -// char * list is nullable (_Nullable - Clang extension) ssize_t hook_listxattr(const char* path, char* list, size_t size); + ssize_t hook_llistxattr(const char* path, char* list, size_t size); + ssize_t hook_flistxattr(int fd, char* list, 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 7eac0e93c..7fa37f820 100644 --- a/src/client/hooks.cpp +++ b/src/client/hooks.cpp @@ -996,29 +996,6 @@ hook_lgetxattr(const char* path, const char* name, void* value, size_t size) { return syscall_no_intercept_wrapper(SYS_lgetxattr, 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); -} - ssize_t hook_listxattr(const char* path, char* list, size_t size) { @@ -1048,16 +1025,33 @@ hook_llistxattr(const char* path, char* list, size_t size) { ssize_t hook_flistxattr(int fd, char* list, size_t size) { - LOG(DEBUG, "{}() called with filedescriptor '{}' list '{}' size '{}'", - __func__, fd, list, size); + LOG(DEBUG, "{}() called with fd '{}' list '{}' size '{}'", __func__, fd, list, size); - const char* newpath_path; - std::string newpath_resolved; - auto newpath_status = - CTX->relativize_fd_path(fd, newpath_path, newpath_resolved); - if(newpath_status == gkfs::preload::RelativizeStatus::internal) { + if(CTX->file_map()->exist(fd)) { return -ENOTSUP; } return syscall_no_intercept_wrapper(SYS_flistxattr, fd, list, 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 -- GitLab From 2ce743dfa8de1de689d2c0cda5c34e30b089779e Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Wed, 3 Jul 2024 18:12:36 +0200 Subject: [PATCH 3/3] Reformat code and Changelog --- CHANGELOG.md | 1 + src/client/hooks.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa8775d9f..8371ec332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ### New +- Added syscall support for listxattr family ([!186](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/186)). - Remove optimization, removing one RPC per operation ([!195](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/195)). - Added the GekkoFS proxy as an optional gateway between client and daemon. The proxy is started on each compute node that houses clients ([!191](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/191)). diff --git a/src/client/hooks.cpp b/src/client/hooks.cpp index 7fa37f820..565f1e9d1 100644 --- a/src/client/hooks.cpp +++ b/src/client/hooks.cpp @@ -1025,7 +1025,8 @@ hook_llistxattr(const char* path, char* list, size_t size) { ssize_t hook_flistxattr(int fd, char* list, size_t size) { - LOG(DEBUG, "{}() called with fd '{}' list '{}' size '{}'", __func__, fd, list, size); + LOG(DEBUG, "{}() called with fd '{}' list '{}' size '{}'", __func__, fd, + list, size); if(CTX->file_map()->exist(fd)) { return -ENOTSUP; -- GitLab