From 842efd95f2b2723de79cb70d4f6203d51e6e7ff5 Mon Sep 17 00:00:00 2001 From: Ramon Nou Date: Mon, 27 Jun 2022 12:09:40 +0200 Subject: [PATCH 1/3] Solved fstatat bug with AT_EMPTY_FLAG --- include/client/preload_context.hpp | 2 +- src/client/hooks.cpp | 2 +- src/client/preload_context.cpp | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/client/preload_context.hpp b/include/client/preload_context.hpp index bfdaacadf..26875435b 100644 --- a/include/client/preload_context.hpp +++ b/include/client/preload_context.hpp @@ -170,7 +170,7 @@ public: RelativizeStatus relativize_fd_path(int dirfd, const char* raw_path, - std::string& relative_path, + std::string& relative_path, int flags = 0, bool resolve_last_link = true) const; bool diff --git a/src/client/hooks.cpp b/src/client/hooks.cpp index 5917b80a7..a476c2dce 100644 --- a/src/client/hooks.cpp +++ b/src/client/hooks.cpp @@ -203,7 +203,7 @@ hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags) { __func__, cpath, dirfd, fmt::ptr(buf), flags); std::string resolved; - auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved); + auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved, flags); switch(rstatus) { case gkfs::preload::RelativizeStatus::fd_unknown: return syscall_no_intercept_wrapper(SYS_newfstatat, dirfd, cpath, diff --git a/src/client/preload_context.cpp b/src/client/preload_context.cpp index 9a1f9f27d..986f065f7 100644 --- a/src/client/preload_context.cpp +++ b/src/client/preload_context.cpp @@ -185,7 +185,7 @@ PreloadContext::auto_sm(bool auto_sm) { RelativizeStatus PreloadContext::relativize_fd_path(int dirfd, const char* raw_path, - std::string& relative_path, + std::string& relative_path, int flags, bool resolve_last_link) const { // Relativize path should be called only after the library constructor has @@ -207,6 +207,11 @@ PreloadContext::relativize_fd_path(int dirfd, const char* raw_path, } else { if(!ofm_->exist(dirfd)) { return RelativizeStatus::fd_unknown; + } else { + if(flags & AT_EMPTY_PATH) { + relative_path = ofm_->get(dirfd)->path(); + return RelativizeStatus::internal; + } } // path is relative to fd auto dir = ofm_->get_dir(dirfd); -- GitLab From dbca1965b0954a050d4eede222254efd55500ebf Mon Sep 17 00:00:00 2001 From: Ramon Nou Date: Tue, 28 Jun 2022 05:56:31 +0000 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c93c2d17..30582c1c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Fixed - Using `unlink` now fails if it is a directory unless the `AT_REMOVEDIR` flag is used (POSIX compliance) ([!139](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/139)). - fchdir generate a SIGSEV in debug mode (due to log) ([!141](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/141)) +- Fix fstatat to be able to understand `AT_EMPTY_PATH` flag used in coreutils (`cat` ...) ([!149](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/149)). + ## [0.9.1] - 2022-04-29 ### New -- GitLab From 1ce52b8d7ac4210d632fcf19188c70e7debfc10f Mon Sep 17 00:00:00 2001 From: Ramon Nou Date: Tue, 28 Jun 2022 09:26:00 +0000 Subject: [PATCH 3/3] Added comment for fstatat case --- src/client/preload_context.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/preload_context.cpp b/src/client/preload_context.cpp index 986f065f7..03284be04 100644 --- a/src/client/preload_context.cpp +++ b/src/client/preload_context.cpp @@ -208,6 +208,8 @@ PreloadContext::relativize_fd_path(int dirfd, const char* raw_path, if(!ofm_->exist(dirfd)) { return RelativizeStatus::fd_unknown; } else { + // check if we have the AT_EMPTY_PATH flag + // for fstatat. if(flags & AT_EMPTY_PATH) { relative_path = ofm_->get(dirfd)->path(); return RelativizeStatus::internal; -- GitLab