Skip to content

Commit

Permalink
Merge pull request #685 from lukemartinlogan/master
Browse files Browse the repository at this point in the history
Add libelf to hermes CI and add try-catch around paths
  • Loading branch information
lukemartinlogan authored Aug 15, 2024
2 parents accec29 + b8f507e commit a95c754
Show file tree
Hide file tree
Showing 14 changed files with 313 additions and 130 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ci/hermes/packages/hermes/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
5 changes: 2 additions & 3 deletions ci/hermes/packages/hermes_shm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -21,6 +19,7 @@ class HermesShm(CMakePackage):
depends_on('[email protected]')
depends_on('yaml-cpp')
depends_on('[email protected]')
depends_on('libelf')

# Machine variants
variant('ares', default=False, description='Build in ares')
Expand All @@ -30,7 +29,7 @@ class HermesShm(CMakePackage):
# Main dependencies
depends_on('[email protected]', when='+mochi')
depends_on('cereal', when='+cereal')
depends_on('[email protected]: +context +fiber', when='+boost')
depends_on('[email protected]: +context +fiber +coroutine +regex +system +filesystem +serialization +pic +math', when='+boost')
depends_on('mpi', when='+mpiio')
depends_on('[email protected]', when='+vfd')
depends_on('libzmq', '+zmq')
Expand Down
6 changes: 3 additions & 3 deletions config/hermes_client_default.yaml
Original file line number Diff line number Diff line change
@@ -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
159 changes: 87 additions & 72 deletions hermes_adapters/filesystem/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,50 +78,55 @@ class Filesystem : public FilesystemIoClient {
ctx.flags_.SetBits(HERMES_SHOULD_STAGE);

std::shared_ptr<AdapterStat> 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<hipc::charbuf>(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<hipc::charbuf>(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<size_t>::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<size_t>::max();
} else {
stat.st_ptr_ = 0;
}
// Allocate internal hermes data
auto stat_ptr = std::make_shared<AdapterStat>(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<AdapterStat>(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;
}
}

Expand Down Expand Up @@ -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<File>* filesp = mdm->Find(pathname);
if (filesp == nullptr) {
return ret;
}
HILOG(kDebug, "Destroying the file descriptors: {}", pathname);
std::list<File> files = *filesp;
for (File &f : files) {
std::shared_ptr<AdapterStat> 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<File> *filesp = mdm->Find(pathname);
if (filesp == nullptr) {
return ret;
}
HILOG(kDebug, "Destroying the file descriptors: {}", pathname);
std::list<File> files = *filesp;
for (File &f : files) {
std::shared_ptr<AdapterStat> 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;
}

/**
Expand Down Expand Up @@ -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;
}
};

Expand Down
17 changes: 11 additions & 6 deletions hermes_adapters/filesystem/filesystem_mdm.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,18 @@ class MetadataManager {
* @return The hermes file.
* */
std::list<File>* 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;
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion hermes_adapters/mpiio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hermes_adapters/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit a95c754

Please sign in to comment.