From 4a285d7e7741348a4ba3f55fcc3e2413f039f4ed Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Tue, 20 Feb 2024 13:20:44 -0600 Subject: [PATCH 01/18] Add url --- ci/hermes/packages/hermes_shm/package.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/hermes/packages/hermes_shm/package.py b/ci/hermes/packages/hermes_shm/package.py index fab60e16f..aa005fa02 100644 --- a/ci/hermes/packages/hermes_shm/package.py +++ b/ci/hermes/packages/hermes_shm/package.py @@ -3,6 +3,7 @@ class HermesShm(CMakePackage): homepage = "https://github.com/lukemartinlogan/hermes_shm/wiki" git = "https://github.com/lukemartinlogan/hermes_shm.git" + url = "https://github.com/lukemartinlogan/hermes_shm.git" version('master', branch='master') version("1.1.0", sha256="080d5361cff22794b670e4544c532926ca8b6d6ec695af25596efe035bfffea5") version("1.0.0", sha256="a79f01d531ce89985ad59a2f62b41d74c2385e48d929e2f4ad895ae34137573b") From 3a9fa03dbb27b949f00cea9940181b59286a6a21 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Tue, 20 Feb 2024 13:21:04 -0600 Subject: [PATCH 02/18] Remove versions --- ci/hermes/packages/hermes_shm/package.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/ci/hermes/packages/hermes_shm/package.py b/ci/hermes/packages/hermes_shm/package.py index aa005fa02..596d448c1 100644 --- a/ci/hermes/packages/hermes_shm/package.py +++ b/ci/hermes/packages/hermes_shm/package.py @@ -3,10 +3,7 @@ class HermesShm(CMakePackage): homepage = "https://github.com/lukemartinlogan/hermes_shm/wiki" git = "https://github.com/lukemartinlogan/hermes_shm.git" - url = "https://github.com/lukemartinlogan/hermes_shm.git" version('master', branch='master') - version("1.1.0", sha256="080d5361cff22794b670e4544c532926ca8b6d6ec695af25596efe035bfffea5") - version("1.0.0", sha256="a79f01d531ce89985ad59a2f62b41d74c2385e48d929e2f4ad895ae34137573b") # Main variants variant('debug', default=False, description='Build shared libraries') From 5b2e0eebd8fbfc1a9a7a20237f8cb7a5365ffb40 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Thu, 22 Feb 2024 17:39:45 -0600 Subject: [PATCH 03/18] Make boost with more stuff --- ci/hermes/packages/hermes_shm/package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/hermes/packages/hermes_shm/package.py b/ci/hermes/packages/hermes_shm/package.py index 596d448c1..cafd36ceb 100644 --- a/ci/hermes/packages/hermes_shm/package.py +++ b/ci/hermes/packages/hermes_shm/package.py @@ -28,7 +28,7 @@ class HermesShm(CMakePackage): # Main dependencies depends_on('mochi-thallium+cereal@0.10.1', when='+mochi') depends_on('cereal', when='+cereal') - depends_on('boost@1.7: +context +fiber', when='+boost') + depends_on('boost@1.7: +context +fiber +coroutine +regex +filesystem +serialization +pic +math', when='+boost') depends_on('mpi', when='+mpiio') depends_on('hdf5@1.14.0', when='+vfd') depends_on('libzmq', '+zmq') From b738ad6c95096806f6b12962d72bd8cdb159cf3b Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Thu, 22 Feb 2024 17:53:48 -0600 Subject: [PATCH 04/18] Add system to boost --- ci/hermes/packages/hermes_shm/package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/hermes/packages/hermes_shm/package.py b/ci/hermes/packages/hermes_shm/package.py index cafd36ceb..0a774bd79 100644 --- a/ci/hermes/packages/hermes_shm/package.py +++ b/ci/hermes/packages/hermes_shm/package.py @@ -28,7 +28,7 @@ class HermesShm(CMakePackage): # Main dependencies depends_on('mochi-thallium+cereal@0.10.1', when='+mochi') depends_on('cereal', when='+cereal') - depends_on('boost@1.7: +context +fiber +coroutine +regex +filesystem +serialization +pic +math', when='+boost') + depends_on('boost@1.7: +context +fiber +coroutine +regex +system +filesystem +serialization +pic +math', when='+boost') depends_on('mpi', when='+mpiio') depends_on('hdf5@1.14.0', when='+vfd') depends_on('libzmq', '+zmq') From ab305bcf346a0af76f11ddda93f2fbcc4650a929 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 04:05:56 -0600 Subject: [PATCH 05/18] Verify that all libraries are loaded --- hermes_adapters/mpiio/CMakeLists.txt | 2 +- hermes_adapters/posix/CMakeLists.txt | 2 +- hermes_adapters/posix/posix_api.cc | 40 +++++---- hermes_adapters/posix/posix_api.h | 13 +++ hermes_adapters/real_api.h | 117 +++++++++++++++++++++++++++ hermes_adapters/stdio/CMakeLists.txt | 2 +- 6 files changed, 158 insertions(+), 18 deletions(-) diff --git a/hermes_adapters/mpiio/CMakeLists.txt b/hermes_adapters/mpiio/CMakeLists.txt index cfd2c664a..b7b58a3cd 100644 --- a/hermes_adapters/mpiio/CMakeLists.txt +++ b/hermes_adapters/mpiio/CMakeLists.txt @@ -18,7 +18,7 @@ set(INTERCEPTOR_DEPS add_library(hermes_mpiio SHARED ${CMAKE_CURRENT_SOURCE_DIR}/mpiio_api.cc) add_dependencies(hermes_mpiio ${INTERCEPTOR_DEPS}) -target_link_libraries(hermes_mpiio MPI::MPI_CXX stdc++fs dl ${INTERCEPTOR_DEPS}) +target_link_libraries(hermes_mpiio MPI::MPI_CXX stdc++fs elf dl ${INTERCEPTOR_DEPS}) #----------------------------------------------------------------------------- # Add Target(s) to CMake Install diff --git a/hermes_adapters/posix/CMakeLists.txt b/hermes_adapters/posix/CMakeLists.txt index c0e412a99..f9158760a 100644 --- a/hermes_adapters/posix/CMakeLists.txt +++ b/hermes_adapters/posix/CMakeLists.txt @@ -11,7 +11,7 @@ set(INTERCEPTOR_DEPS add_library(hermes_posix SHARED ${CMAKE_CURRENT_SOURCE_DIR}/posix_api.cc) add_dependencies(hermes_posix ${INTERCEPTOR_DEPS}) -target_link_libraries(hermes_posix MPI::MPI_CXX stdc++fs dl ${INTERCEPTOR_DEPS}) +target_link_libraries(hermes_posix MPI::MPI_CXX stdc++fs elf dl ${INTERCEPTOR_DEPS}) #----------------------------------------------------------------------------- # Add Target(s) to CMake Install diff --git a/hermes_adapters/posix/posix_api.cc b/hermes_adapters/posix/posix_api.cc index a6cc7836f..c6f6725cc 100644 --- a/hermes_adapters/posix/posix_api.cc +++ b/hermes_adapters/posix/posix_api.cc @@ -37,17 +37,16 @@ namespace stdfs = std::filesystem; extern "C" { -static __attribute__((constructor(101))) void init_posix(void) { - HERMES_POSIX_API; - HERMES_POSIX_FS; - TRANSPARENT_HERMES();; -}/**/ +//static __attribute__((constructor(101))) void init_posix(void) { +// HERMES_POSIX_API; +// HERMES_POSIX_FS; +// TRANSPARENT_HERMES();; +//} /** * POSIX */ int HERMES_DECL(open)(const char *path, int flags, ...) { -// TRANSPARENT_HERMES(); int mode = 0; auto real_api = HERMES_POSIX_API; auto fs_api = HERMES_POSIX_FS; @@ -57,7 +56,10 @@ int HERMES_DECL(open)(const char *path, int flags, ...) { mode = va_arg(arg, int); va_end(arg); } - if (fs_api->IsPathTracked(path)) { + if (real_api->IsInterceptorLoaded()) { + TRANSPARENT_HERMES(); + } + if (real_api->IsInterceptorLoaded() && fs_api->IsPathTracked(path)) { HILOG(kDebug, "Intercept open for filename: {}" " and mode: {}" " is tracked.", path, flags) @@ -75,7 +77,6 @@ int HERMES_DECL(open)(const char *path, int flags, ...) { } int HERMES_DECL(open64)(const char *path, int flags, ...) { -// TRANSPARENT_HERMES(); int mode = 0; auto real_api = HERMES_POSIX_API; auto fs_api = HERMES_POSIX_FS; @@ -85,7 +86,10 @@ int HERMES_DECL(open64)(const char *path, int flags, ...) { mode = va_arg(arg, int); va_end(arg); } - if (fs_api->IsPathTracked(path)) { + if (real_api->IsInterceptorLoaded()) { + TRANSPARENT_HERMES(); + } + if (real_api->IsInterceptorLoaded() && fs_api->IsPathTracked(path)) { HILOG(kDebug, "Intercept open64 for filename: {}" " and mode: {}" " is tracked.", path, flags) @@ -101,10 +105,12 @@ int HERMES_DECL(open64)(const char *path, int flags, ...) { } int HERMES_DECL(__open_2)(const char *path, int oflag) { -// TRANSPARENT_HERMES(); auto real_api = HERMES_POSIX_API; auto fs_api = HERMES_POSIX_FS; - if (fs_api->IsPathTracked(path)) { + if (real_api->IsInterceptorLoaded()) { + TRANSPARENT_HERMES(); + } + if (real_api->IsInterceptorLoaded() && fs_api->IsPathTracked(path)) { HILOG(kDebug, "Intercept __open_2 for filename: {}" " and mode: {}" " is tracked.", path, oflag) @@ -117,11 +123,13 @@ int HERMES_DECL(__open_2)(const char *path, int oflag) { } int HERMES_DECL(creat)(const char *path, mode_t mode) { -// TRANSPARENT_HERMES(); std::string path_str(path); auto real_api = HERMES_POSIX_API; auto fs_api = HERMES_POSIX_FS; - if (fs_api->IsPathTracked(path)) { + if (real_api->IsInterceptorLoaded()) { + TRANSPARENT_HERMES(); + } + if (real_api->IsInterceptorLoaded() && fs_api->IsPathTracked(path)) { HILOG(kDebug, "Intercept creat for filename: {}" " and mode: {}" " is tracked.", path, mode) @@ -134,11 +142,13 @@ int HERMES_DECL(creat)(const char *path, mode_t mode) { } int HERMES_DECL(creat64)(const char *path, mode_t mode) { -// TRANSPARENT_HERMES(); std::string path_str(path); auto real_api = HERMES_POSIX_API; auto fs_api = HERMES_POSIX_FS; - if (fs_api->IsPathTracked(path)) { + if (real_api->IsInterceptorLoaded()) { + TRANSPARENT_HERMES(); + } + if (real_api->IsInterceptorLoaded() && fs_api->IsPathTracked(path)) { HILOG(kDebug, "Intercept creat64 for filename: {}" " and mode: {}" " is tracked.", path, mode) diff --git a/hermes_adapters/posix/posix_api.h b/hermes_adapters/posix/posix_api.h index 9b8e44b66..89a032603 100644 --- a/hermes_adapters/posix/posix_api.h +++ b/hermes_adapters/posix/posix_api.h @@ -96,6 +96,9 @@ static int fxstat_to_fstat(int fd, struct stat * stbuf); /** Pointers to the real posix API */ class PosixApi : public RealApi { + public: + bool is_loaded_ = false; + public: /** open */ open_t open = nullptr; @@ -222,6 +225,15 @@ class PosixApi : public RealApi { unlink = (unlink_t)dlsym(real_lib_, "unlink"); REQUIRE_API(unlink) } + + bool IsInterceptorLoaded() { + if (is_loaded_) { + return true; + } + InterceptorApi check("open", "posix_intercepted"); + is_loaded_ = check.is_loaded_; + return is_loaded_; + } }; } // namespace hermes::adapter @@ -233,6 +245,7 @@ class PosixApi : public RealApi { hshm::EasySingleton<::hermes::adapter::PosixApi>::GetInstance() #define HERMES_POSIX_API_T hermes::adapter::PosixApi* + namespace hermes::adapter { /** Used for compatability with older kernel versions */ static int fxstat_to_fstat(int fd, struct stat *stbuf) { diff --git a/hermes_adapters/real_api.h b/hermes_adapters/real_api.h index 9aba4cb40..b130c393f 100644 --- a/hermes_adapters/real_api.h +++ b/hermes_adapters/real_api.h @@ -15,6 +15,9 @@ #include #include +#include +#include + namespace stdfs = std::filesystem; @@ -44,6 +47,7 @@ struct RealApi { static int callback(struct dl_phdr_info *info, size_t size, void *data) { auto iter = (RealApiIter*)data; auto lib = dlopen(info->dlpi_name, RTLD_GLOBAL | RTLD_NOW); + // auto lib = dlopen(info->dlpi_name, RTLD_NOLOAD | RTLD_NOW); auto exists = dlsym(lib, iter->symbol_name_); void *is_intercepted = (void*)dlsym(lib, iter->is_intercepted_); @@ -71,6 +75,119 @@ struct RealApi { } }; +template +struct InterceptorApi { + PosixT *posix_; + std::string lib_path_; + bool is_loaded_; + int lib_fd_ = -1; + Elf *lib_elf_ = nullptr; + + static int callback(struct dl_phdr_info *info, size_t size, void *data) { + auto iter = (RealApiIter*)data; + auto lib = dlopen(info->dlpi_name, RTLD_GLOBAL | RTLD_NOW); + // auto lib = dlopen(info->dlpi_name, RTLD_NOLOAD | RTLD_NOW); + auto exists = dlsym(lib, iter->symbol_name_); + void *is_intercepted = + (void*)dlsym(lib, iter->is_intercepted_); + if (is_intercepted && exists && !iter->lib_path_) { + iter->lib_path_ = info->dlpi_name; + if (iter->lib_path_ == nullptr || strlen(iter->lib_path_) == 0) { + Dl_info dl_info; + if (dladdr(is_intercepted, &dl_info) == 0) { + iter->lib_path_ = ""; + } else { + iter->lib_path_ = dl_info.dli_fname; + } + } + } + return 0; + } + + bool IsLoaded(const char *filename) { + // Open the ELF file + lib_fd_ = posix_->open(filename, O_RDONLY); + if (lib_fd_ < 0) { + return false; + } + + // Initialize libelf + if (elf_version(EV_CURRENT) == EV_NONE) { + return false; + } + + // Open ELF descriptor + lib_elf_ = elf_begin(lib_fd_, ELF_C_READ, NULL); + if (!lib_elf_) { + return false; + } + + // Get the ELF header + GElf_Ehdr ehdr; + if (!gelf_getehdr(lib_elf_, &ehdr)) { + return false; + } + + // Scan the dynamic table + Elf_Scn *scn = NULL; + while ((scn = elf_nextscn(lib_elf_, scn)) != NULL) { + GElf_Shdr shdr = {}; + if (gelf_getshdr(scn, &shdr) != &shdr) { + return false; + } + + if (shdr.sh_type == SHT_DYNAMIC) { + Elf_Data *data = NULL; + data = elf_getdata(scn, data); + if (data == NULL) { + return false; + } + + size_t sh_entsize = gelf_fsize(lib_elf_, ELF_T_DYN, 1, EV_CURRENT); + + for (size_t i = 0; i < shdr.sh_size / sh_entsize; i++) { + GElf_Dyn dyn = {}; + if (gelf_getdyn(data, i, &dyn) != &dyn) { + return false; + } + const char *lib_name = + elf_strptr(lib_elf_, shdr.sh_link, dyn.d_un.d_val); + if (lib_name) { + auto lib = dlopen(lib_name, RTLD_NOLOAD | RTLD_NOW); + if (!lib) { + return false; + } + } + } + } + } + + // Clean up + return true; + } + + void CloseElf() { + if (lib_elf_) { + elf_end(lib_elf_); + } + if (lib_fd_ > 0) { + posix_->close(lib_fd_); + } + } + + InterceptorApi(const char *symbol_name, + const char *is_intercepted) : is_loaded_(false) { + posix_ = hshm::EasySingleton::GetInstance(); + RealApiIter iter(symbol_name, is_intercepted); + dl_iterate_phdr(callback, (void*)&iter); + if (iter.lib_path_) { + lib_path_ = iter.lib_path_; + is_loaded_ = IsLoaded(iter.lib_path_); + } + CloseElf(); + } +}; + } // namespace hermes::adapter #endif // HERMES_ADAPTER_API_H diff --git a/hermes_adapters/stdio/CMakeLists.txt b/hermes_adapters/stdio/CMakeLists.txt index da729b02c..7c9e23411 100644 --- a/hermes_adapters/stdio/CMakeLists.txt +++ b/hermes_adapters/stdio/CMakeLists.txt @@ -11,7 +11,7 @@ set(INTERCEPTOR_DEPS add_library(hermes_stdio SHARED ${CMAKE_CURRENT_SOURCE_DIR}/stdio_api.cc) add_dependencies(hermes_stdio ${INTERCEPTOR_DEPS}) -target_link_libraries(hermes_stdio MPI::MPI_CXX stdc++fs dl ${INTERCEPTOR_DEPS}) +target_link_libraries(hermes_stdio MPI::MPI_CXX stdc++fs elf dl ${INTERCEPTOR_DEPS}) #----------------------------------------------------------------------------- # Add Target(s) to CMake Install From 1fe9c0e50ee952eed4b79b6053ff04f98ab2e124 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 04:08:09 -0600 Subject: [PATCH 06/18] Add gelf --- hermes_adapters/real_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hermes_adapters/real_api.h b/hermes_adapters/real_api.h index b130c393f..f32e604c0 100644 --- a/hermes_adapters/real_api.h +++ b/hermes_adapters/real_api.h @@ -15,7 +15,7 @@ #include #include -#include +// #include #include From 2d0c9f165747c65ccafae8843c9a777f215bf435 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 04:09:27 -0600 Subject: [PATCH 07/18] Add libelf as a dep of hermes --- ci/hermes/packages/hermes_shm/package.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/hermes/packages/hermes_shm/package.py b/ci/hermes/packages/hermes_shm/package.py index 0a774bd79..2cbe65223 100644 --- a/ci/hermes/packages/hermes_shm/package.py +++ b/ci/hermes/packages/hermes_shm/package.py @@ -19,6 +19,7 @@ class HermesShm(CMakePackage): depends_on('catch2@3.0.1') depends_on('yaml-cpp') depends_on('doxygen@1.9.3') + depends_on('libelf') # Machine variants variant('ares', default=False, description='Build in ares') From 3714cbb6ee5d755a81f82d57ccc4b2d76e1fe2ee Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 04:26:37 -0600 Subject: [PATCH 08/18] Find libelf --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93d9c822c..5b0c831af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,6 +169,12 @@ endif() include_directories(${Boost_INCLUDE_DIRS}) message("Boost: ${Boost_LIBRARIES}") +# Libelf +find_package(LibElf REQUIRED) +if(LibElf_FOUND) + message(STATUS "found libelf at ${LibElf_INCLUDE_DIRS}") +endif() + # HDF5 if(HERMES_ENABLE_VFD) set(HERMES_REQUIRED_HDF5_VERSION 1.14.0) From 9f4e8e76541bb097babd7d7769fe27274d340705 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 04:36:30 -0600 Subject: [PATCH 09/18] Use pkgconfig libelf --- CMakeLists.txt | 7 +++---- hermes_adapters/mpiio/CMakeLists.txt | 3 ++- hermes_adapters/posix/CMakeLists.txt | 2 +- hermes_adapters/stdio/CMakeLists.txt | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b0c831af..fa9839bf6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,10 +170,9 @@ include_directories(${Boost_INCLUDE_DIRS}) message("Boost: ${Boost_LIBRARIES}") # Libelf -find_package(LibElf REQUIRED) -if(LibElf_FOUND) - message(STATUS "found libelf at ${LibElf_INCLUDE_DIRS}") -endif() +pkg_check_modules(libelf REQUIRED libelf) +message(STATUS "found libelf at ${libelf_INCLUDE_DIRS}") +include_directories(${libelf_INCLUDE_DIRS}) # HDF5 if(HERMES_ENABLE_VFD) diff --git a/hermes_adapters/mpiio/CMakeLists.txt b/hermes_adapters/mpiio/CMakeLists.txt index b7b58a3cd..b6430fceb 100644 --- a/hermes_adapters/mpiio/CMakeLists.txt +++ b/hermes_adapters/mpiio/CMakeLists.txt @@ -18,7 +18,8 @@ set(INTERCEPTOR_DEPS add_library(hermes_mpiio SHARED ${CMAKE_CURRENT_SOURCE_DIR}/mpiio_api.cc) add_dependencies(hermes_mpiio ${INTERCEPTOR_DEPS}) -target_link_libraries(hermes_mpiio MPI::MPI_CXX stdc++fs elf dl ${INTERCEPTOR_DEPS}) +target_link_libraries(hermes_mpiio + MPI::MPI_CXX stdc++fs ${libelf_LIBRARIES} dl ${INTERCEPTOR_DEPS}) #----------------------------------------------------------------------------- # Add Target(s) to CMake Install diff --git a/hermes_adapters/posix/CMakeLists.txt b/hermes_adapters/posix/CMakeLists.txt index f9158760a..d51640f46 100644 --- a/hermes_adapters/posix/CMakeLists.txt +++ b/hermes_adapters/posix/CMakeLists.txt @@ -11,7 +11,7 @@ set(INTERCEPTOR_DEPS add_library(hermes_posix SHARED ${CMAKE_CURRENT_SOURCE_DIR}/posix_api.cc) add_dependencies(hermes_posix ${INTERCEPTOR_DEPS}) -target_link_libraries(hermes_posix MPI::MPI_CXX stdc++fs elf dl ${INTERCEPTOR_DEPS}) +target_link_libraries(hermes_posix MPI::MPI_CXX stdc++fs ${libelf_LIBRARIES} dl ${INTERCEPTOR_DEPS}) #----------------------------------------------------------------------------- # Add Target(s) to CMake Install diff --git a/hermes_adapters/stdio/CMakeLists.txt b/hermes_adapters/stdio/CMakeLists.txt index 7c9e23411..38e981fdd 100644 --- a/hermes_adapters/stdio/CMakeLists.txt +++ b/hermes_adapters/stdio/CMakeLists.txt @@ -11,7 +11,7 @@ set(INTERCEPTOR_DEPS add_library(hermes_stdio SHARED ${CMAKE_CURRENT_SOURCE_DIR}/stdio_api.cc) add_dependencies(hermes_stdio ${INTERCEPTOR_DEPS}) -target_link_libraries(hermes_stdio MPI::MPI_CXX stdc++fs elf dl ${INTERCEPTOR_DEPS}) +target_link_libraries(hermes_stdio MPI::MPI_CXX stdc++fs ${libelf_LIBRARIES} dl ${INTERCEPTOR_DEPS}) #----------------------------------------------------------------------------- # Add Target(s) to CMake Install From 433be96db7a4319cb535c6ba8c442aabf491a583 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 04:52:37 -0600 Subject: [PATCH 10/18] Undef deprecated --- hermes_adapters/real_api.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hermes_adapters/real_api.h b/hermes_adapters/real_api.h index f32e604c0..2941ddce2 100644 --- a/hermes_adapters/real_api.h +++ b/hermes_adapters/real_api.h @@ -190,4 +190,6 @@ struct InterceptorApi { } // namespace hermes::adapter +#undef DEPRECATED + #endif // HERMES_ADAPTER_API_H From f9ca8babfabfa65f845d3c5eb2e8456f9a31416c Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 04:58:11 -0600 Subject: [PATCH 11/18] library dirs --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa9839bf6..a34069e8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,7 @@ message("Boost: ${Boost_LIBRARIES}") pkg_check_modules(libelf REQUIRED libelf) message(STATUS "found libelf at ${libelf_INCLUDE_DIRS}") include_directories(${libelf_INCLUDE_DIRS}) +link_directories(${libelf_LIBRARY_DIRS}) # HDF5 if(HERMES_ENABLE_VFD) From 6f490cf716cd10f3b6fbd7d09731afea0c910718 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 04:59:49 -0600 Subject: [PATCH 12/18] Undef deprecated --- hermes_adapters/real_api.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hermes_adapters/real_api.h b/hermes_adapters/real_api.h index 2941ddce2..f2529058a 100644 --- a/hermes_adapters/real_api.h +++ b/hermes_adapters/real_api.h @@ -13,6 +13,8 @@ #ifndef HERMES_ADAPTER_API_H #define HERMES_ADAPTER_API_H +#undef DEPRECATED + #include #include // #include From 121f60dc643ad6619389938f3d120a17cdd49708 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 05:23:15 -0600 Subject: [PATCH 13/18] Is loaded true --- hermes_adapters/real_api.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hermes_adapters/real_api.h b/hermes_adapters/real_api.h index f2529058a..6146348cb 100644 --- a/hermes_adapters/real_api.h +++ b/hermes_adapters/real_api.h @@ -179,6 +179,8 @@ struct InterceptorApi { InterceptorApi(const char *symbol_name, const char *is_intercepted) : is_loaded_(false) { + is_loaded_ = true; + return; posix_ = hshm::EasySingleton::GetInstance(); RealApiIter iter(symbol_name, is_intercepted); dl_iterate_phdr(callback, (void*)&iter); From 43ea7ad90198e015c9bea13d9ddd4c2edda4ff62 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 05:27:53 -0600 Subject: [PATCH 14/18] Use new inclusion naming scheme --- config/hermes_client_default.yaml | 6 +++--- include/hermes/config_client_default.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/hermes_client_default.yaml b/config/hermes_client_default.yaml index fb5bee72e..4771bbc91 100644 --- a/config/hermes_client_default.yaml +++ b/config/hermes_client_default.yaml @@ -1,10 +1,10 @@ stop_daemon: false -path_inclusions: ["/tmp/test_hermes"] -path_exclusions: ["/"] +path_inclusions: ["/tmp/test_hermes/*"] +path_exclusions: ["/*"] file_page_size: 1024KB base_adapter_mode: kDefault flushing_mode: kAsync file_adapter_configs: - - path: "/" + - path: "/*" page_size: 1MB mode: kDefault \ No newline at end of file diff --git a/include/hermes/config_client_default.h b/include/hermes/config_client_default.h index aff693b94..0a54e592d 100644 --- a/include/hermes/config_client_default.h +++ b/include/hermes/config_client_default.h @@ -2,13 +2,13 @@ #define HRUN_SRC_CONFIG_HERMES_CLIENT_DEFAULT_H_ const inline char* kHermesClientDefaultConfigStr = "stop_daemon: false\n" -"path_inclusions: [\"/tmp/test_hermes\"]\n" -"path_exclusions: [\"/\"]\n" +"path_inclusions: [\"/tmp/test_hermes/*\"]\n" +"path_exclusions: [\"/*\"]\n" "file_page_size: 1024KB\n" "base_adapter_mode: kDefault\n" "flushing_mode: kAsync\n" "file_adapter_configs:\n" -" - path: \"/\"\n" +" - path: \"/*\"\n" " page_size: 1MB\n" " mode: kDefault\n"; #endif // HRUN_SRC_CONFIG_HERMES_CLIENT_DEFAULT_H_ \ No newline at end of file From 34873c26a1c525d3f92482a945cae12860909844 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 05:31:59 -0600 Subject: [PATCH 15/18] Do two path checks --- include/hermes/config_client.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/hermes/config_client.h b/include/hermes/config_client.h index 0dddf7e89..1890769e3 100644 --- a/include/hermes/config_client.h +++ b/include/hermes/config_client.h @@ -70,8 +70,8 @@ struct UserPathInfo { /** Detect if a path matches the input path */ bool Match(const std::string &abs_path) { - return std::regex_match(abs_path, regex_); - // return abs_path.rfind(path_) != std::string::npos; + return std::regex_match(abs_path, regex_) || + abs_path.rfind(path_) != std::string::npos; } }; From e28a35daf57ce2a840a2ab0defd77100dd0961c7 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Fri, 23 Feb 2024 05:43:20 -0600 Subject: [PATCH 16/18] Add otmpfile opt too --- hermes_adapters/posix/posix_api.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hermes_adapters/posix/posix_api.cc b/hermes_adapters/posix/posix_api.cc index c6f6725cc..5ddc29952 100644 --- a/hermes_adapters/posix/posix_api.cc +++ b/hermes_adapters/posix/posix_api.cc @@ -80,7 +80,7 @@ int HERMES_DECL(open64)(const char *path, int flags, ...) { int mode = 0; auto real_api = HERMES_POSIX_API; auto fs_api = HERMES_POSIX_FS; - if (flags & O_CREAT) { + if (flags & O_CREAT || flags & O_TMPFILE) { va_list arg; va_start(arg, flags); mode = va_arg(arg, int); @@ -98,7 +98,7 @@ int HERMES_DECL(open64)(const char *path, int flags, ...) { stat.st_mode_ = mode; return fs_api->Open(stat, path).hermes_fd_; } - if (flags & O_CREAT) { + if (flags & O_CREAT || flags & O_TMPFILE) { return real_api->open64(path, flags, mode); } return real_api->open64(path, flags); From 46616b852160862fa84e5e82d6de16fadca7ce1f Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Thu, 15 Aug 2024 15:40:05 -0500 Subject: [PATCH 17/18] Add libelf as dependency --- CMakeLists.txt | 3 ++- ci/hermes/packages/hermes/package.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cdf991c03..1d67a9980 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,8 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # HermesShm find_package(HermesShm CONFIG REQUIRED) message(STATUS "found hermes_shm.h at ${HermesShm_INCLUDE_DIRS}") +include_directories(${HermesShm_INCLUDE_DIRS}) +link_directories(${HermesShm_LIBRARY_DIRS}) # YAML-CPP find_package(yaml-cpp REQUIRED) @@ -238,7 +240,6 @@ endif() # Build Hermes Main Packages #----------------------------------------------------------------------------- # Main includes -include_directories(${HermesShm_INCLUDE_DIRS}) include_directories(${CMAKE_SOURCE_DIR}) include_directories(${CMAKE_SOURCE_DIR}/include) # Required Task includes diff --git a/ci/hermes/packages/hermes/package.py b/ci/hermes/packages/hermes/package.py index 631a1f5df..d15e39ec4 100644 --- a/ci/hermes/packages/hermes/package.py +++ b/ci/hermes/packages/hermes/package.py @@ -53,6 +53,7 @@ class Hermes(CMakePackage): depends_on('hermes_shm+adios', when='+adios') depends_on('hermes_shm+encrypt', when='+encrypt') depends_on('hermes_shm+compress', when='+compress') + depends_on('libelf') def cmake_args(self): args = [] From b8f507e5bf5c6615b6a88ad821065d4d2a0474b6 Mon Sep 17 00:00:00 2001 From: lukemartinlogan Date: Thu, 15 Aug 2024 15:45:04 -0500 Subject: [PATCH 18/18] Add try-catch around every stdfs::absolute --- hermes_adapters/filesystem/filesystem.h | 159 +++++++++++--------- hermes_adapters/filesystem/filesystem_mdm.h | 17 ++- include/hermes/config_client.h | 49 +++--- 3 files changed, 127 insertions(+), 98 deletions(-) diff --git a/hermes_adapters/filesystem/filesystem.h b/hermes_adapters/filesystem/filesystem.h index ea6a0c433..2d73cc981 100644 --- a/hermes_adapters/filesystem/filesystem.h +++ b/hermes_adapters/filesystem/filesystem.h @@ -78,50 +78,55 @@ class Filesystem : public FilesystemIoClient { ctx.flags_.SetBits(HERMES_SHOULD_STAGE); std::shared_ptr exists = mdm->Find(f); - if (!exists) { - HILOG(kDebug, "File not opened before by adapter") - // Normalize path strings - stat.path_ = stdfs::absolute(path).string(); - auto path_shm = hipc::make_uptr(stat.path_); - // Verify the bucket exists if not in CREATE mode - if (stat.adapter_mode_ == AdapterMode::kScratch && - !stat.hflags_.Any(HERMES_FS_EXISTS) && - !stat.hflags_.Any(HERMES_FS_CREATE)) { - TagId bkt_id = HERMES->GetTagId(stat.path_); - if (bkt_id.IsNull()) { - f.status_ = false; - return; + try { + if (!exists) { + HILOG(kDebug, "File not opened before by adapter") + // Normalize path strings + stat.path_ = stdfs::absolute(path).string(); + auto path_shm = hipc::make_uptr(stat.path_); + // Verify the bucket exists if not in CREATE mode + if (stat.adapter_mode_ == AdapterMode::kScratch && + !stat.hflags_.Any(HERMES_FS_EXISTS) && + !stat.hflags_.Any(HERMES_FS_CREATE)) { + TagId bkt_id = HERMES->GetTagId(stat.path_); + if (bkt_id.IsNull()) { + f.status_ = false; + return; + } } - } - // Update page size - stat.page_size_ = mdm->GetAdapterPageSize(path); - // Bucket parameters - ctx.bkt_params_ = hermes::data_stager::BinaryFileStager::BuildFileParams(stat.page_size_); - // Get or create the bucket - if (stat.hflags_.Any(HERMES_FS_TRUNC)) { - // The file was opened with TRUNCATION - stat.bkt_id_ = HERMES->GetBucket(stat.path_, ctx, 0, HERMES_SHOULD_STAGE); - stat.bkt_id_.Clear(); - } else { - // The file was opened regularly - stat.file_size_ = GetBackendSize(*path_shm); - stat.bkt_id_ = HERMES->GetBucket(stat.path_, ctx, stat.file_size_, HERMES_SHOULD_STAGE); - } - HILOG(kDebug, "BKT vs file size: {} {}", stat.bkt_id_.GetSize(), stat.file_size_); - // Update file position pointer - if (stat.hflags_.Any(HERMES_FS_APPEND)) { - stat.st_ptr_ = std::numeric_limits::max(); + // Update page size + stat.page_size_ = mdm->GetAdapterPageSize(path); + // Bucket parameters + ctx.bkt_params_ = hermes::data_stager::BinaryFileStager::BuildFileParams(stat.page_size_); + // Get or create the bucket + if (stat.hflags_.Any(HERMES_FS_TRUNC)) { + // The file was opened with TRUNCATION + stat.bkt_id_ = HERMES->GetBucket(stat.path_, ctx, 0, HERMES_SHOULD_STAGE); + stat.bkt_id_.Clear(); + } else { + // The file was opened regularly + stat.file_size_ = GetBackendSize(*path_shm); + stat.bkt_id_ = HERMES->GetBucket(stat.path_, ctx, stat.file_size_, HERMES_SHOULD_STAGE); + } + HILOG(kDebug, "BKT vs file size: {} {}", stat.bkt_id_.GetSize(), stat.file_size_); + // Update file position pointer + if (stat.hflags_.Any(HERMES_FS_APPEND)) { + stat.st_ptr_ = std::numeric_limits::max(); + } else { + stat.st_ptr_ = 0; + } + // Allocate internal hermes data + auto stat_ptr = std::make_shared(stat); + FilesystemIoClientState fs_ctx(&mdm->fs_mdm_, (void *) stat_ptr.get()); + HermesOpen(f, stat, fs_ctx); + mdm->Create(f, stat_ptr); } else { - stat.st_ptr_ = 0; + HILOG(kDebug, "File already opened by adapter") + exists->UpdateTime(); } - // Allocate internal hermes data - auto stat_ptr = std::make_shared(stat); - FilesystemIoClientState fs_ctx(&mdm->fs_mdm_, (void*)stat_ptr.get()); - HermesOpen(f, stat, fs_ctx); - mdm->Create(f, stat_ptr); - } else { - HILOG(kDebug, "File already opened by adapter") - exists->UpdateTime(); + } catch (const std::exception &e) { + HILOG(kError, "Error opening file: {}", e.what()) + f.status_ = false; } } @@ -430,28 +435,33 @@ class Filesystem : public FilesystemIoClient { auto mdm = HERMES_FS_METADATA_MANAGER; int ret = RealRemove(pathname); // Destroy the bucket - std::string canon_path = stdfs::absolute(pathname).string(); - Bucket bkt = HERMES->GetBucket(canon_path); - bkt.Destroy(); - // Destroy all file descriptors - std::list* filesp = mdm->Find(pathname); - if (filesp == nullptr) { - return ret; - } - HILOG(kDebug, "Destroying the file descriptors: {}", pathname); - std::list files = *filesp; - for (File &f : files) { - std::shared_ptr stat = mdm->Find(f); - if (stat == nullptr) { continue; } - FilesystemIoClientState fs_ctx(&mdm->fs_mdm_, (void *)&stat); - HermesClose(f, *stat, fs_ctx); - RealClose(f, *stat); - mdm->Delete(stat->path_, f); - if (stat->adapter_mode_ == AdapterMode::kScratch) { - ret = 0; + try { + std::string canon_path = stdfs::absolute(pathname).string(); + Bucket bkt = HERMES->GetBucket(canon_path); + bkt.Destroy(); + // Destroy all file descriptors + std::list *filesp = mdm->Find(pathname); + if (filesp == nullptr) { + return ret; + } + HILOG(kDebug, "Destroying the file descriptors: {}", pathname); + std::list files = *filesp; + for (File &f : files) { + std::shared_ptr stat = mdm->Find(f); + if (stat == nullptr) { continue; } + FilesystemIoClientState fs_ctx(&mdm->fs_mdm_, (void *) &stat); + HermesClose(f, *stat, fs_ctx); + RealClose(f, *stat); + mdm->Delete(stat->path_, f); + if (stat->adapter_mode_ == AdapterMode::kScratch) { + ret = 0; + } } + return ret; + } catch (const std::exception &e) { + HILOG(kError, "Error removing path: {}", e.what()) + return -1; } - return ret; } /** @@ -688,20 +698,25 @@ class Filesystem : public FilesystemIoClient { if (!HERMES_CONF->is_initialized_) { return false; } - std::string abs_path = stdfs::absolute(path).string(); - auto &paths = HERMES_CLIENT_CONF.path_list_; - // Check if path is included or excluded - for (config::UserPathInfo &pth : paths) { - if (pth.Match(abs_path)) { - if (abs_path == pth.path_ && pth.is_directory_) { - // Do not include if path is a tracked directory - return false; + try { + std::string abs_path = stdfs::absolute(path).string(); + auto &paths = HERMES_CLIENT_CONF.path_list_; + // Check if path is included or excluded + for (config::UserPathInfo &pth : paths) { + if (pth.Match(abs_path)) { + if (abs_path == pth.path_ && pth.is_directory_) { + // Do not include if path is a tracked directory + return false; + } + return pth.include_; } - return pth.include_; } + // Assume it is excluded + return false; + } catch (const std::exception &e) { + HILOG(kError, "Error checking path: {}", e.what()) + return false; } - // Assume it is excluded - return false; } }; diff --git a/hermes_adapters/filesystem/filesystem_mdm.h b/hermes_adapters/filesystem/filesystem_mdm.h index 06cf65784..1cc870f4a 100644 --- a/hermes_adapters/filesystem/filesystem_mdm.h +++ b/hermes_adapters/filesystem/filesystem_mdm.h @@ -124,13 +124,18 @@ class MetadataManager { * @return The hermes file. * */ std::list* Find(const std::string &path) { - std::string canon_path = stdfs::absolute(path).string(); - ScopedRwReadLock md_lock(lock_, kMDM_Find); - auto iter = path_to_hermes_file_.find(canon_path); - if (iter == path_to_hermes_file_.end()) + try { + std::string canon_path = stdfs::absolute(path).string(); + ScopedRwReadLock md_lock(lock_, kMDM_Find); + auto iter = path_to_hermes_file_.find(canon_path); + if (iter == path_to_hermes_file_.end()) + return nullptr; + else + return &iter->second; + } catch(const std::exception &e) { + HILOG(kError, "Error finding path: {}", e.what()) return nullptr; - else - return &iter->second; + } } /** diff --git a/include/hermes/config_client.h b/include/hermes/config_client.h index 1890769e3..5d512f6f6 100644 --- a/include/hermes/config_client.h +++ b/include/hermes/config_client.h @@ -118,15 +118,19 @@ class ClientConfig : public BaseConfig { } void CreateAdapterPathTracking(const std::string &path, bool include) { - bool is_dir = stdfs::is_directory(path); - path_list_.emplace_back( - stdfs::absolute(path).string(), include, is_dir); - std::sort(path_list_.begin(), - path_list_.end(), - [](const UserPathInfo &a, - const UserPathInfo &b) { - return a.path_.size() > b.path_.size(); - }); + try { + bool is_dir = stdfs::is_directory(path); + path_list_.emplace_back( + stdfs::absolute(path).string(), include, is_dir); + std::sort(path_list_.begin(), + path_list_.end(), + [](const UserPathInfo &a, + const UserPathInfo &b) { + return a.path_.size() > b.path_.size(); + }); + } catch (const std::exception &e) { + HILOG(kError, "Error checking path: {}", e.what()) + } } void SetAdapterPathTracking(const std::string &path, bool include) { @@ -214,18 +218,23 @@ class ClientConfig : public BaseConfig { void ParseAdapterConfig(YAML::Node &yaml_conf, AdapterObjectConfig &conf) { - std::string path = yaml_conf["path"].as(); - path = hshm::ConfigParse::ExpandPath(path); - path = stdfs::absolute(path).string(); - if (yaml_conf["mode"]) { - conf.mode_ = AdapterModeConv::to_enum( - yaml_conf["mode"].as()); - } - if (yaml_conf["page_size"]) { - conf.page_size_ = hshm::ConfigParse::ParseSize( - yaml_conf["page_size"].as()); + try { + std::string path = yaml_conf["path"].as(); + path = hshm::ConfigParse::ExpandPath(path); + path = stdfs::absolute(path).string(); + if (yaml_conf["mode"]) { + conf.mode_ = AdapterModeConv::to_enum( + yaml_conf["mode"].as()); + } + if (yaml_conf["page_size"]) { + conf.page_size_ = hshm::ConfigParse::ParseSize( + yaml_conf["page_size"].as()); + } + SetAdapterConfig(path, conf); + } catch (const std::exception &e) { + HILOG(kError, "Error checking path: {}", e.what()) + return; } - SetAdapterConfig(path, conf); } };