diff --git a/CHANGELOG.md b/CHANGELOG.md index 93e0446d56f634b8b9652c0ce5839d69c6593ffc..2b55171216e3c686b04753e488dc7480f68f52fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,15 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### New +- Adding user library `gkfs_user_lib` that can be used to directly link to an application ([!171](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/171)). +- FMT10 and date removal, several dependencies updated. ([!172](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/172)). +- Fused GekkoFWD and GekkoFS. GekkoFWD is enabled with the `--enable-following` in the server configuration and the ENV variable + `LIBGKFS_FORWARDING_MAP_FILE` in the clients. ([!170](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/170)). - Replication without using the server. NUM_REPL (0 < NUM_REPL < num_servers) env variable defines the number of replicas ([!166](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/141)). -- Modified write and reads to use a bitset instead of the traditional hash per chunk in the server. -- Added reattemp support in get_fs_config to other servers, when the initial server fails. -- Fused GekkoFWD and GekkoFS. GekkoFWD is enabled with the `--enable-following` in the server configuration and the ENV variable -`LIBGKFS_FORWARDING_MAP_FILE` in the clients. ([!170](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/170)). -- FMT10 and date removal, several dependencies updated. ([!172](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_request/172)). + - Modified write and reads to use a bitset instead of the traditional hash per chunk in the server. + - Added reattemp support in get_fs_config to other servers, when the initial server fails. + -### New ### Changed ### Removed ### Fixed diff --git a/CMake/FindMercury.cmake b/CMake/FindMercury.cmake index 7eb96cde545a7ea7bb863df725f9285368c47a59..451ed6d403ab2a3d4f4f2fb6cabb351179593add 100644 --- a/CMake/FindMercury.cmake +++ b/CMake/FindMercury.cmake @@ -177,7 +177,7 @@ endmacro() include(SelectLibraryConfigurations) -set(_mercury_components na mercury_util mercury_hl) +set(_mercury_components na mercury_util) # prevent repeating work if the main CMakeLists.txt already called # find_package(PkgConfig) diff --git a/CMakeLists.txt b/CMakeLists.txt index c70d36115a34d91e11f0606ccf579efc8350c182..16f2bc3ae2a1cf6ba7136191476d17c4bd55ccd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ cmake_minimum_required(VERSION 3.13) project( GekkoFS VERSION 0.9.2 + LANGUAGES ASM CXX C ) enable_testing() @@ -305,6 +306,7 @@ include_directories( add_subdirectory(src) add_subdirectory(include) +add_subdirectory(examples) ### Mark any CMake variables imported from {fmt} and spdlog as advanced, so ### that they don't appear in cmake-gui or ccmake. Similarly for FETCHCONTENT @@ -345,7 +347,6 @@ if (GKFS_BUILD_TESTS) message(STATUS "[gekkofs] Guided distributor tests: ${GKFS_TESTS_GUIDED_DISTRIBUTION}") add_subdirectory(tests) - add_subdirectory(examples/gfind) else() unset(GKFS_TESTS_INTERFACE CACHE) endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f8a4ad5ed9450ab5f036cbc1d2cce4921fb1b876 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,30 @@ +################################################################################ +# Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain # +# Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany # +# # +# This software was partially supported by the # +# EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). # +# # +# This software was partially supported by the # +# ADA-FS project under the SPPEXA project funded by the DFG. # +# # +# This file is part of GekkoFS. # +# # +# GekkoFS is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# GekkoFS is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with GekkoFS. If not, see . # +# # +# SPDX-License-Identifier: GPL-3.0-or-later # +################################################################################ + +add_subdirectory(gfind) +add_subdirectory(user_library) \ No newline at end of file diff --git a/examples/gfind/CMakeLists.txt b/examples/gfind/CMakeLists.txt index d9e63e317b8045762757231c1196b0a973faca7a..fef70119db0db318623c714f4890deca253760af 100644 --- a/examples/gfind/CMakeLists.txt +++ b/examples/gfind/CMakeLists.txt @@ -1,6 +1,6 @@ ################################################################################ -# Copyright 2018-2021, Barcelona Supercomputing Center (BSC), Spain # -# Copyright 2015-2021, Johannes Gutenberg Universitaet Mainz, Germany # +# Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain # +# Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany # # # # This software was partially supported by the # # EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). # @@ -26,7 +26,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later # ################################################################################ -set (CMAKE_CXX_STANDARD 14) +set (CMAKE_CXX_STANDARD 17) add_executable(sfind sfind.cpp) if(GKFS_INSTALL_TESTS) diff --git a/examples/user_library/CMakeLists.txt b/examples/user_library/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ee8d915ab6bec3234bc222ab4e68de7e8537575b --- /dev/null +++ b/examples/user_library/CMakeLists.txt @@ -0,0 +1,39 @@ +################################################################################ +# Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain # +# Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany # +# # +# This software was partially supported by the # +# EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). # +# # +# This software was partially supported by the # +# ADA-FS project under the SPPEXA project funded by the DFG. # +# # +# This file is part of GekkoFS. # +# # +# GekkoFS is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# GekkoFS is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with GekkoFS. If not, see . # +# # +# SPDX-License-Identifier: GPL-3.0-or-later # +################################################################################ + +set(CMAKE_CXX_STANDARD 17) +add_executable(gkfs_lib_example gkfs_lib_example.cpp) + +target_link_libraries(gkfs_lib_example + PRIVATE gkfs_user_lib +) +if (GKFS_INSTALL_TESTS) + install(TARGETS gkfs_lib_example + DESTINATION ${CMAKE_INSTALL_BINDIR} + ) +endif () \ No newline at end of file diff --git a/examples/user_library/gkfs_lib_example.cpp b/examples/user_library/gkfs_lib_example.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3d422d2ae12e106a90a12863d22ffd626b877339 --- /dev/null +++ b/examples/user_library/gkfs_lib_example.cpp @@ -0,0 +1,107 @@ +/* + Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain + Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany + + This software was partially supported by the + EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). + + This software was partially supported by the + ADA-FS project under the SPPEXA project funded by the DFG. + + This file is part of GekkoFS. + + GekkoFS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + GekkoFS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GekkoFS. If not, see . + + SPDX-License-Identifier: GPL-3.0-or-later +*/ +#include + +#include +#include +#include +#include + +extern "C" { +#include +#include +} + +using namespace std; + +void +write_file(std::string filename) { + // Open File + int fd = gkfs::syscall::gkfs_open(filename, S_IRWXU, O_RDWR | O_CREAT); + + cout << "FD open " << fd << endl; + + char* bufwrite = (char*) malloc(10); + strncpy(bufwrite, "testing", 8); + + int size = gkfs::syscall::gkfs_write(fd, bufwrite, 7); + + cout << "Written size " << size << endl; + + free(bufwrite); + gkfs::syscall::gkfs_close(fd); +} + +void +read_file(std::string filename) { + int fdread = gkfs::syscall::gkfs_open(filename, S_IRWXU, O_RDONLY); + if(fdread == -1) + return; + char* bufread = (char*) malloc(10); + int sizeread = gkfs::syscall::gkfs_read(fdread, bufread, 7); + + cout << "Reading Size: " << sizeread << " Content: " << bufread << endl; + + free(bufread); + gkfs::syscall::gkfs_close(fdread); +} + +int +main(int argc, char** argv) { + cout << "GekkoFS Client library test" << endl; + + auto res = gkfs_init(); + + cout << "Init result " << res << endl; + + write_file("/test.tmp"); + + read_file("/test.tmp"); + + + write_file("/secondfile.tmp"); + + auto f_list = gkfs::syscall::gkfs_get_file_list("/"); + + for(auto f : f_list) { + cout << "File: " << f << endl; + struct stat buf; + memset(&buf, 0, sizeof(struct stat)); + + gkfs::syscall::gkfs_stat("/" + f, &buf, true); + + cout << "Size: " << buf.st_size << " Mode: " << buf.st_mode << endl; + cout << "Atime: " << buf.st_atime << " Mtime: " << buf.st_mtime + << " Ctime: " << buf.st_ctime << endl + << " ****** " << endl; + } + + res = gkfs_end(); + + cout << "End result " << res << endl; +} diff --git a/external/hermes b/external/hermes index 2fa83ff4787d60e2d849c227e64d1b691f8fe0e4..98272ebc24405f556b0c0d23405087976d817c7a 160000 --- a/external/hermes +++ b/external/hermes @@ -1 +1 @@ -Subproject commit 2fa83ff4787d60e2d849c227e64d1b691f8fe0e4 +Subproject commit 98272ebc24405f556b0c0d23405087976d817c7a diff --git a/include/client/CMakeLists.txt b/include/client/CMakeLists.txt index 2d12db14e2c3adedcb27147f6a2e166cab43a3a9..6815fc95321a27ecce55b407d10075cb53cad2ca 100644 --- a/include/client/CMakeLists.txt +++ b/include/client/CMakeLists.txt @@ -54,3 +54,30 @@ target_sources( syscalls/detail/syscall_info.h ) +target_sources( + gkfs_user_lib + PUBLIC gkfs_functions.hpp + env.hpp + hooks.hpp + intercept.hpp + logging.hpp + make_array.hpp + open_file_map.hpp + open_dir.hpp + path.hpp + preload.hpp + preload_context.hpp + preload_util.hpp + rpc/rpc_types.hpp + rpc/forward_management.hpp + rpc/forward_metadata.hpp + rpc/forward_data.hpp + syscalls/args.hpp + syscalls/decoder.hpp + syscalls/errno.hpp + syscalls/rets.hpp + syscalls/syscall.hpp + syscalls/detail/syscall_info.h + void_syscall_intercept.hpp + user_functions.hpp +) diff --git a/include/client/gkfs_functions.hpp b/include/client/gkfs_functions.hpp index 63b9b655f55d5851d780f0c5379b4b35d7225533..313df5fcb46339a309298237dc9bda8bd0b52e16 100644 --- a/include/client/gkfs_functions.hpp +++ b/include/client/gkfs_functions.hpp @@ -149,14 +149,22 @@ gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp, int gkfs_rmdir(const std::string& path); +int +gkfs_close(unsigned int fd); + +std::vector +gkfs_get_file_list(const std::string& path); + #ifdef HAS_RENAME int gkfs_rename(const std::string& old_path, const std::string& new_path); #endif // HAS_RENAME + } // namespace gkfs::syscall // gkfs_getsingleserverdir is using extern "C" to demangle it for C usage extern "C" int gkfs_getsingleserverdir(const char* path, struct dirent_extended* dirp, unsigned int count, int server); + #endif // GEKKOFS_GKFS_FUNCTIONS_HPP diff --git a/include/client/hooks.hpp b/include/client/hooks.hpp index e71a6a08d68b2b0875b213b7f19e260a13c73b2b..fa9ec424bc606a941650edb253a20781af54cf8d 100644 --- a/include/client/hooks.hpp +++ b/include/client/hooks.hpp @@ -36,7 +36,13 @@ extern "C" { #include #include } + +#ifndef BYPASS_SYSCALL #include +#else +#include +#endif + /* * For PowerPC, syscall_no_intercept_wrapper() is defined in the diff --git a/include/client/logging.hpp b/include/client/logging.hpp index 2f00058d0885c8e533bbdf942c5147ab4fa78aa4..9d1f464e52649e33268769b9a2cadea711b31fee 100644 --- a/include/client/logging.hpp +++ b/include/client/logging.hpp @@ -30,7 +30,11 @@ #ifndef LIBGKFS_LOGGING_HPP #define LIBGKFS_LOGGING_HPP +#ifndef BYPASS_SYSCALL #include +#else +#include +#endif #include #include diff --git a/include/client/preload.hpp b/include/client/preload.hpp index 6cae014b1d88b0445edd64b65321a9fe8f47717c..afad97c684bbb5736bceef4079e67adc7b120b3c 100644 --- a/include/client/preload.hpp +++ b/include/client/preload.hpp @@ -41,11 +41,12 @@ void init_ld_env_if_needed(); } // namespace gkfs::preload +#ifndef BYPASS_SYSCALL void init_preload() __attribute__((constructor)); void destroy_preload() __attribute__((destructor)); - +#endif #endif // IOINTERCEPT_PRELOAD_HPP diff --git a/include/client/user_functions.hpp b/include/client/user_functions.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2fb5dd7f2013289a5ed61fefdc2982e7d97200f3 --- /dev/null +++ b/include/client/user_functions.hpp @@ -0,0 +1,89 @@ +/* + Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain + Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany + + This software was partially supported by the + EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). + + This software was partially supported by the + ADA-FS project under the SPPEXA project funded by the DFG. + + This file is part of GekkoFS' POSIX interface. + + GekkoFS' POSIX interface is free software: you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GekkoFS' POSIX interface is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with GekkoFS' POSIX interface. If not, see + . + + SPDX-License-Identifier: LGPL-3.0-or-later +*/ + +#ifndef GEKKOFS_USER_FUNCTIONS_HPP +#define GEKKOFS_USER_FUNCTIONS_HPP +#include +#include +#include + +extern "C" { +#include +#include +} + +struct linux_dirent64; + +namespace gkfs::syscall { + +int +gkfs_open(const std::string& path, mode_t mode, int flags); + +int +gkfs_create(const std::string& path, mode_t mode); + +int +gkfs_remove(const std::string& path); + +ssize_t +gkfs_write(int fd, const void* buf, size_t count); + +ssize_t +gkfs_read(int fd, void* buf, size_t count); + +int +gkfs_close(unsigned int fd); + +off64_t +gkfs_lseek(unsigned int fd, off64_t offset, unsigned int whence); + +ssize_t +gkfs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset); + +ssize_t +gkfs_pread_ws(int fd, void* buf, size_t count, off64_t offset); + +int +gkfs_stat(const std::string& path, struct stat* buf, bool follow_links = true); + +int +gkfs_remove(const std::string& path); + +std::vector +gkfs_get_file_list(const std::string& path); +} // namespace gkfs::syscall + + +extern "C" int +gkfs_init(); + +extern "C" int +gkfs_end(); + +#endif // GEKKOFS_USER_FUNCTIONS_HPP diff --git a/include/client/void_syscall_intercept.hpp b/include/client/void_syscall_intercept.hpp new file mode 100644 index 0000000000000000000000000000000000000000..16cd01b5bd59da0a1e31ac831c66ed707462e488 --- /dev/null +++ b/include/client/void_syscall_intercept.hpp @@ -0,0 +1,45 @@ +/* + Copyright 2018-2022, Barcelona Supercomputing Center (BSC), Spain + Copyright 2015-2022, Johannes Gutenberg Universitaet Mainz, Germany + + This software was partially supported by the + EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). + + This software was partially supported by the + ADA-FS project under the SPPEXA project funded by the DFG. + + This file is part of GekkoFS' POSIX interface. + + GekkoFS' POSIX interface is free software: you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GekkoFS' POSIX interface is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with GekkoFS' POSIX interface. If not, see + . + + SPDX-License-Identifier: LGPL-3.0-or-later +*/ +#ifndef SYSCALL_BYPASS_HPP +#define SYSCALL_BYPASS_HPP + +static inline int +syscall_error_code(long result) { + if(result < 0 && result >= -0x1000) + return (int) -result; + + return 0; +} + +extern "C" { +long +syscall_no_intercept(long syscall_number, ...); +} + +#endif \ No newline at end of file diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index c408fc7262df42000c2abe248d8f063020b930de..db59b16f43cfc83a23ca80c32df562b82899ea26 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -31,13 +31,33 @@ # This builds the `libgkfs_intercept.so` library: the primary GekkoFS client # based on syscall interception. # ############################################################################## -add_library(gkfs_intercept SHARED) -target_sources( - gkfs_intercept - PRIVATE gkfs_functions.cpp +add_library (gkfs_intercept SHARED) +add_library (gkfs_user_lib SHARED) + + +target_sources(gkfs_intercept + PRIVATE gkfs_functions.cpp + intercept.cpp hooks.cpp + logging.cpp + open_file_map.cpp + open_dir.cpp + path.cpp + preload.cpp + preload_context.cpp + preload_util.cpp + rpc/rpc_types.cpp + rpc/forward_data.cpp + rpc/forward_management.cpp + rpc/forward_metadata.cpp + syscalls/detail/syscall_info.c) + +target_sources( + gkfs_user_lib + PRIVATE gkfs_functions.cpp intercept.cpp + hooks.cpp logging.cpp open_file_map.cpp open_dir.cpp @@ -49,19 +69,20 @@ target_sources( rpc/forward_data.cpp rpc/forward_management.cpp rpc/forward_metadata.cpp - syscalls/detail/syscall_info.c + syscalls/detail/syscall_info.c syscalls/util.S ) +target_compile_definitions(gkfs_user_lib PUBLIC BYPASS_SYSCALL) +target_link_options(gkfs_user_lib PRIVATE -z noexecstack) - if(GKFS_ENABLE_AGIOS) - target_compile_definitions(gkfs_intercept PUBLIC GKFS_ENABLE_AGIOS) - endif() +if(GKFS_ENABLE_AGIOS) + target_compile_definitions(gkfs_intercept PUBLIC GKFS_ENABLE_AGIOS) +endif() target_link_libraries( gkfs_intercept PRIVATE metadata distributor env_util arithmetic path_util rpc_utils - PUBLIC Syscall_intercept::Syscall_intercept - dl + PUBLIC dl Mercury::Mercury hermes fmt::fmt @@ -69,6 +90,16 @@ target_link_libraries( Syscall_intercept::Syscall_intercept ) +target_link_libraries( + gkfs_user_lib + PRIVATE metadata distributor env_util arithmetic path_util rpc_utils + PUBLIC dl + Mercury::Mercury + hermes + fmt::fmt + Threads::Threads +) + install( TARGETS gkfs_intercept LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -76,3 +107,17 @@ install( PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gkfs ) + +set_target_properties(gkfs_user_lib + PROPERTIES + PUBLIC_HEADER "../../include/client/void_syscall_intercept.hpp" + PUBLIC_HEADER "../../include/client/user_functions.hpp" +) + + +install( + TARGETS gkfs_user_lib + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gkfs +) diff --git a/src/client/gkfs_functions.cpp b/src/client/gkfs_functions.cpp index b03e8eaebe906bf24ffe9fdaadec01799541a4da..865d382143ccdb080a752a07a2749af680ded3ef 100644 --- a/src/client/gkfs_functions.cpp +++ b/src/client/gkfs_functions.cpp @@ -1394,6 +1394,28 @@ gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp, return written; } +/** + * @brief Closes an fd. To be used externally + * + * @param fd + * @return int + */ +int +gkfs_close(unsigned int fd) { + if(CTX->file_map()->exist(fd)) { + // No call to the daemon is required + CTX->file_map()->remove(fd); + return 0; + } + + if(CTX->is_internal_fd(fd)) { + // the client application (for some reason) is trying to close an + // internal fd: ignore it + return 0; + } + + return -1; +} #ifdef HAS_SYMLINKS #ifdef GKFS_ENABLE_UNUSED_FUNCTIONS @@ -1482,6 +1504,28 @@ gkfs_readlink(const std::string& path, char* buf, int bufsize) { #endif #endif + +std::vector +gkfs_get_file_list(const std::string& path) { + auto ret = gkfs::rpc::forward_get_dirents(path); + auto err = ret.first; + if(err) { + errno = err; + return {}; + } + + auto open_dir = ret.second; + + std::vector file_list; + unsigned int pos = 0; + + while(pos < open_dir->size()) { + auto de = open_dir->getdent(pos++); + file_list.push_back(de.name()); + } + return file_list; +} + } // namespace gkfs::syscall diff --git a/src/client/hooks.cpp b/src/client/hooks.cpp index a986d5898b12e4450a8c63d45a893f493e86cd51..9a54048c544dc1bfbcf096a448b913e52114ad0b 100644 --- a/src/client/hooks.cpp +++ b/src/client/hooks.cpp @@ -91,17 +91,10 @@ hook_close(int fd) { LOG(DEBUG, "{}() called with fd: {}", __func__, fd); - if(CTX->file_map()->exist(fd)) { - // No call to the daemon is required - CTX->file_map()->remove(fd); - return 0; - } + auto ret = gkfs::syscall::gkfs_close(fd); - if(CTX->is_internal_fd(fd)) { - // the client application (for some reason) is trying to close an - // internal fd: ignore it + if(ret == 0) return 0; - } return syscall_no_intercept_wrapper(SYS_close, fd); } diff --git a/src/client/intercept.cpp b/src/client/intercept.cpp index 316c5e398403761b00d5f32917f153cca9c22c7b..7a8a455fe4aa63f6f3eab2bec381023dfbb888f0 100644 --- a/src/client/intercept.cpp +++ b/src/client/intercept.cpp @@ -44,6 +44,24 @@ extern "C" { #include } + +#ifdef BYPASS_SYSCALL +int (*intercept_hook_point)(long syscall_number, long arg0, long arg1, + long arg2, long arg3, long arg4, long arg5, + long* result){}; + +void (*intercept_hook_point_clone_child)(unsigned long flags, void* child_stack, + int* ptid, int* ctid, long newtls){}; + +void (*intercept_hook_point_clone_parent)(unsigned long flags, + void* child_stack, int* ptid, + int* ctid, long newtls, + long returned_pid){}; + +void (*intercept_hook_point_post_kernel)(long syscall_number, long arg0, + long arg1, long arg2, long arg3, + long arg4, long arg5, long result){}; +#endif namespace { thread_local bool reentrance_guard_flag; diff --git a/src/client/path.cpp b/src/client/path.cpp index 4f72b4807c3cc09da756ab769aebe89cd9871e05..85357209a24ae47a87ed8358cd8d3cad255f232a 100644 --- a/src/client/path.cpp +++ b/src/client/path.cpp @@ -39,9 +39,14 @@ #include #include +#ifndef BYPASS_SYSCALL +#include +#else +#include +#endif + extern "C" { #include -#include } using namespace std; diff --git a/src/client/preload.cpp b/src/client/preload.cpp index 6d7a0c0e9e6416b33c1d2766b61c14232da5b8c7..652ef3580df7720c4103e12862a4f66265aa1217 100644 --- a/src/client/preload.cpp +++ b/src/client/preload.cpp @@ -67,8 +67,10 @@ exit_error_msg(int errcode, const string& msg) { // if we don't disable interception before calling ::exit() // syscall hooks may find an inconsistent in shared state // (e.g. the logger) and thus, crash - gkfs::preload::stop_interception(); - CTX->disable_interception(); + if(CTX->interception_enabled()) { + gkfs::preload::stop_interception(); + CTX->disable_interception(); + } ::exit(errcode); } @@ -314,9 +316,42 @@ destroy_preload() { ld_network_service.reset(); LOG(DEBUG, "RPC subsystem shut down"); - gkfs::preload::stop_interception(); - CTX->disable_interception(); - LOG(DEBUG, "Syscall interception stopped"); + if(CTX->interception_enabled()) { + gkfs::preload::stop_interception(); + CTX->disable_interception(); + LOG(DEBUG, "Syscall interception stopped"); + } LOG(INFO, "All subsystems shut down. Client shutdown complete."); } + + +/** + * @brief External functions to call linking the library + * + */ +extern "C" int +gkfs_init() { + CTX->init_logging(); + + // from here ownwards it is safe to print messages + LOG(DEBUG, "Logging subsystem initialized"); + + gkfs::preload::init_environment(); + + return 0; +} + + +extern "C" int +gkfs_end() { + CTX->clear_hosts(); + LOG(DEBUG, "Peer information deleted"); + + ld_network_service.reset(); + LOG(DEBUG, "RPC subsystem shut down"); + + LOG(INFO, "All subsystems shut down. Client shutdown complete."); + + return 0; +} \ No newline at end of file diff --git a/src/client/preload_context.cpp b/src/client/preload_context.cpp index 7101041dcdb77864a55ed671bdd014a250db5623..5dbc75c87c0944fb14190f4464578baa4c5483cc 100644 --- a/src/client/preload_context.cpp +++ b/src/client/preload_context.cpp @@ -37,13 +37,17 @@ #include #include #include - #include #include -extern "C" { +#ifndef BYPASS_SYSCALL #include +#else +#include +#endif + +extern "C" { #include } diff --git a/src/client/syscalls/util.S b/src/client/syscalls/util.S new file mode 100644 index 0000000000000000000000000000000000000000..67c9b279afdcad35a0409dd800c392f079029956 --- /dev/null +++ b/src/client/syscalls/util.S @@ -0,0 +1,49 @@ +/* + * Copyright 2016-2017, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.global syscall_no_intercept; +.type syscall_no_intercept, @function + +.text + +syscall_no_intercept: + movq %rdi, %rax /* convert from linux ABI calling */ + movq %rsi, %rdi /* convention to syscall calling convention */ + movq %rdx, %rsi + movq %rcx, %rdx + movq %r8, %r10 + movq %r9, %r8 + movq 8(%rsp), %r9 + syscall + ret + +.size syscall_no_intercept, .-syscall_no_intercept