diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bbfc5ce0..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) @@ -169,6 +171,12 @@ endif() include_directories(${Boost_INCLUDE_DIRS}) message("Boost: ${Boost_LIBRARIES}") +# Libelf +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) set(HERMES_REQUIRED_HDF5_VERSION 1.14.0) @@ -232,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 = [] diff --git a/ci/hermes/packages/hermes_shm/package.py b/ci/hermes/packages/hermes_shm/package.py index fab60e16f..2cbe65223 100644 --- a/ci/hermes/packages/hermes_shm/package.py +++ b/ci/hermes/packages/hermes_shm/package.py @@ -4,8 +4,6 @@ class HermesShm(CMakePackage): homepage = "https://github.com/lukemartinlogan/hermes_shm/wiki" git = "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') @@ -21,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') @@ -30,7 +29,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 +system +filesystem +serialization +pic +math', when='+boost') depends_on('mpi', when='+mpiio') depends_on('hdf5@1.14.0', when='+vfd') depends_on('libzmq', '+zmq') 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/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/hermes_adapters/mpiio/CMakeLists.txt b/hermes_adapters/mpiio/CMakeLists.txt index cfd2c664a..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 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 c0e412a99..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 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/posix/posix_api.cc b/hermes_adapters/posix/posix_api.cc index a6cc7836f..5ddc29952 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,17 +77,19 @@ 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; - if (flags & O_CREAT) { + if (flags & O_CREAT || flags & O_TMPFILE) { va_list arg; va_start(arg, 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) @@ -94,17 +98,19 @@ 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); } 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..6146348cb 100644 --- a/hermes_adapters/real_api.h +++ b/hermes_adapters/real_api.h @@ -13,8 +13,13 @@ #ifndef HERMES_ADAPTER_API_H #define HERMES_ADAPTER_API_H +#undef DEPRECATED + #include #include +// #include +#include + namespace stdfs = std::filesystem; @@ -44,6 +49,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 +77,123 @@ 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) { + is_loaded_ = true; + return; + 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 +#undef DEPRECATED + #endif // HERMES_ADAPTER_API_H diff --git a/hermes_adapters/stdio/CMakeLists.txt b/hermes_adapters/stdio/CMakeLists.txt index da729b02c..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 dl ${INTERCEPTOR_DEPS}) +target_link_libraries(hermes_stdio MPI::MPI_CXX stdc++fs ${libelf_LIBRARIES} dl ${INTERCEPTOR_DEPS}) #----------------------------------------------------------------------------- # Add Target(s) to CMake Install diff --git a/include/hermes/config_client.h b/include/hermes/config_client.h index 0dddf7e89..5d512f6f6 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; } }; @@ -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); } }; 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