Loading examples/gfind/CMakeLists.txt +8 −0 Original line number Diff line number Diff line Loading @@ -28,9 +28,17 @@ set (CMAKE_CXX_STANDARD 14) add_executable(sfind sfind.cpp) add_executable(gkfs_lib_example gkfs_lib_example.cpp) target_link_libraries(gkfs_lib_example PRIVATE gkfs_intercept ) if(GKFS_INSTALL_TESTS) install(TARGETS sfind DESTINATION ${CMAKE_INSTALL_BINDIR} ) install(TARGETS gkfs_lib_example DESTINATION ${CMAKE_INSTALL_BINDIR} ) endif() examples/gfind/gkfs_lib_example.cpp 0 → 100644 +102 −0 Original line number Diff line number Diff line /* 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. 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 <https://www.gnu.org/licenses/>. SPDX-License-Identifier: GPL-3.0-or-later */ #include <cmath> #include <cstring> #include <getopt.h> #include <iostream> #include <queue> #include <regex.h> #include <stdio.h> #include <string> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <limits> #include <cstdint> #include <client/gkfs_functions.hpp> using namespace std; /* Function exported from GekkoFS LD_PRELOAD, code needs to be compiled with * -fPIC */ extern "C" int gkfs_init() __attribute__((weak)); extern "C" int gkfs_end() __attribute__((weak)); void init_preload() {}; void destroy_preload() {}; void write_file(std::string filename){ // Opem File int fd = gkfs::syscall::gkfs_open(filename,S_IRWXU,O_RDWR|O_CREAT); cout << "FD open " << fd << endl; char *buf = "testing"; // int size = gkfs::syscall::gkfs_write(fd, buf, 7); // cout << "FD size" << size << endl; gkfs::syscall::gkfs_close(fd); } void read_file(std::string filename){ int fdread = gkfs::syscall::gkfs_open(filename,S_IRWXU,O_RDONLY); char *bufread = "TESTING\0"; int sizeread = gkfs::syscall::gkfs_read(fdread, bufread, 7); cout << "Reading : " << sizeread << " --> " << bufread << endl; 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"); res = gkfs_end(); cout << "End result " << res << endl; } include/client/gkfs_functions.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -149,6 +149,9 @@ gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp, int gkfs_rmdir(const std::string& path); int gkfs_close(unsigned int fd); #ifdef HAS_RENAME int gkfs_rename(const std::string& old_path, const std::string& new_path); Loading include/client/preload.hpp +5 −0 Original line number Diff line number Diff line Loading @@ -47,5 +47,10 @@ init_preload() __attribute__((constructor)); void destroy_preload() __attribute__((destructor)); extern "C" int gkfs_init(); extern "C" int gkfs_end(); #endif // IOINTERCEPT_PRELOAD_HPP src/client/gkfs_functions.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -1394,6 +1394,27 @@ 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 Loading Loading
examples/gfind/CMakeLists.txt +8 −0 Original line number Diff line number Diff line Loading @@ -28,9 +28,17 @@ set (CMAKE_CXX_STANDARD 14) add_executable(sfind sfind.cpp) add_executable(gkfs_lib_example gkfs_lib_example.cpp) target_link_libraries(gkfs_lib_example PRIVATE gkfs_intercept ) if(GKFS_INSTALL_TESTS) install(TARGETS sfind DESTINATION ${CMAKE_INSTALL_BINDIR} ) install(TARGETS gkfs_lib_example DESTINATION ${CMAKE_INSTALL_BINDIR} ) endif()
examples/gfind/gkfs_lib_example.cpp 0 → 100644 +102 −0 Original line number Diff line number Diff line /* 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. 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 <https://www.gnu.org/licenses/>. SPDX-License-Identifier: GPL-3.0-or-later */ #include <cmath> #include <cstring> #include <getopt.h> #include <iostream> #include <queue> #include <regex.h> #include <stdio.h> #include <string> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <limits> #include <cstdint> #include <client/gkfs_functions.hpp> using namespace std; /* Function exported from GekkoFS LD_PRELOAD, code needs to be compiled with * -fPIC */ extern "C" int gkfs_init() __attribute__((weak)); extern "C" int gkfs_end() __attribute__((weak)); void init_preload() {}; void destroy_preload() {}; void write_file(std::string filename){ // Opem File int fd = gkfs::syscall::gkfs_open(filename,S_IRWXU,O_RDWR|O_CREAT); cout << "FD open " << fd << endl; char *buf = "testing"; // int size = gkfs::syscall::gkfs_write(fd, buf, 7); // cout << "FD size" << size << endl; gkfs::syscall::gkfs_close(fd); } void read_file(std::string filename){ int fdread = gkfs::syscall::gkfs_open(filename,S_IRWXU,O_RDONLY); char *bufread = "TESTING\0"; int sizeread = gkfs::syscall::gkfs_read(fdread, bufread, 7); cout << "Reading : " << sizeread << " --> " << bufread << endl; 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"); res = gkfs_end(); cout << "End result " << res << endl; }
include/client/gkfs_functions.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -149,6 +149,9 @@ gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp, int gkfs_rmdir(const std::string& path); int gkfs_close(unsigned int fd); #ifdef HAS_RENAME int gkfs_rename(const std::string& old_path, const std::string& new_path); Loading
include/client/preload.hpp +5 −0 Original line number Diff line number Diff line Loading @@ -47,5 +47,10 @@ init_preload() __attribute__((constructor)); void destroy_preload() __attribute__((destructor)); extern "C" int gkfs_init(); extern "C" int gkfs_end(); #endif // IOINTERCEPT_PRELOAD_HPP
src/client/gkfs_functions.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -1394,6 +1394,27 @@ 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 Loading