GekkoFS user library creation.

Build over replication/gekkofwd changes. This MR aims to create a standalone library to use inside a client application without LD_PRELOAD and syscall interception.

The user library needs some changes as some syscall_no_intercept calls are scattered through the logging and the general code of the client. Also we need to do not link syscall_intercept and to remove (or avoid) the gekkofs client constructor.

There is an example of write - read on the example directory.

The user needs to link gkfs_user_lib.so and use user_functions.hpp (installed on include/gkfs directory)

Edited by Ramon Nou

Merge request reports

Loading
+1 −1
Changes for CMake/FindMercury.cmake: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -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)
+3 −3
Changes for examples/gfind/CMakeLists.txt: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
################################################################################
# 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)
+39 −0
Changes for examples/user_library/CMakeLists.txt: 39 added lines, 0 removed lines.
Original line number Diff line number Diff line
################################################################################
# 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 <https://www.gnu.org/licenses/>.            #
#                                                                              #
# 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
+107 −0
Changes for examples/user_library/gkfs_lib_example.cpp: 107 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
  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 <https://www.gnu.org/licenses/>.

  SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <client/user_functions.hpp>

#include <cmath>
#include <cstring>
#include <iostream>
#include <string>

extern "C" {
#include <fcntl.h>
#include <stdlib.h>
}

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;
}
+30 −0
Changes for examples/CMakeLists.txt: 30 added lines, 0 removed lines.
Original line number Diff line number Diff line
################################################################################
# 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 <https://www.gnu.org/licenses/>.            #
#                                                                              #
# SPDX-License-Identifier: GPL-3.0-or-later                                    #
################################################################################

add_subdirectory(gfind)
add_subdirectory(user_library)
 No newline at end of file
Loading
Loading