LCOV - code coverage report
Current view: top level - include/client - preload_context.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 4 100.0 %
Date: 2024-04-23 00:09:24 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain
       3             :   Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany
       4             : 
       5             :   This software was partially supported by the
       6             :   EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
       7             : 
       8             :   This software was partially supported by the
       9             :   ADA-FS project under the SPPEXA project funded by the DFG.
      10             : 
      11             :   This file is part of GekkoFS' POSIX interface.
      12             : 
      13             :   GekkoFS' POSIX interface is free software: you can redistribute it and/or
      14             :   modify it under the terms of the GNU Lesser General Public License as
      15             :   published by the Free Software Foundation, either version 3 of the License,
      16             :   or (at your option) any later version.
      17             : 
      18             :   GekkoFS' POSIX interface is distributed in the hope that it will be useful,
      19             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      20             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      21             :   GNU Lesser General Public License for more details.
      22             : 
      23             :   You should have received a copy of the GNU Lesser General Public License
      24             :   along with GekkoFS' POSIX interface.  If not, see
      25             :   <https://www.gnu.org/licenses/>.
      26             : 
      27             :   SPDX-License-Identifier: LGPL-3.0-or-later
      28             : */
      29             : 
      30             : #ifndef GEKKOFS_PRELOAD_CTX_HPP
      31             : #define GEKKOFS_PRELOAD_CTX_HPP
      32             : 
      33             : #include <hermes.hpp>
      34             : #include <map>
      35             : #include <mercury.h>
      36             : #include <memory>
      37             : #include <vector>
      38             : #include <string>
      39             : #include <config.hpp>
      40             : 
      41             : #include <bitset>
      42             : 
      43             : /* Forward declarations */
      44             : namespace gkfs {
      45             : namespace filemap {
      46             : class OpenFileMap;
      47             : }
      48             : namespace rpc {
      49             : class Distributor;
      50             : }
      51             : namespace log {
      52             : struct logger;
      53             : }
      54             : 
      55             : namespace preload {
      56             : /*
      57             :  * Client file system config
      58             :  */
      59         544 : struct FsConfig {
      60             :     // configurable metadata
      61             :     bool atime_state;
      62             :     bool mtime_state;
      63             :     bool ctime_state;
      64             :     bool link_cnt_state;
      65             :     bool blocks_state;
      66             : 
      67             :     uid_t uid;
      68             :     gid_t gid;
      69             : 
      70             :     std::string rootdir;
      71             : };
      72             : 
      73             : enum class RelativizeStatus { internal, external, fd_unknown, fd_not_a_dir };
      74             : 
      75             : /**
      76             :  * Singleton class of the client context with all relevant global data
      77             :  */
      78             : class PreloadContext {
      79             : 
      80             :     static auto constexpr MIN_INTERNAL_FD =
      81             :             GKFS_MAX_OPEN_FDS - GKFS_MAX_INTERNAL_FDS;
      82             :     static auto constexpr MAX_USER_FDS = MIN_INTERNAL_FD;
      83             : 
      84             : private:
      85             :     PreloadContext();
      86             : 
      87             :     std::shared_ptr<gkfs::filemap::OpenFileMap> ofm_;
      88             :     std::shared_ptr<gkfs::rpc::Distributor> distributor_;
      89             :     std::shared_ptr<FsConfig> fs_conf_;
      90             : 
      91             :     std::string cwd_;
      92             :     std::vector<std::string> mountdir_components_;
      93             :     std::string mountdir_;
      94             : 
      95             :     std::vector<hermes::endpoint> hosts_;
      96             :     uint64_t local_host_id_;
      97             :     uint64_t fwd_host_id_;
      98             :     std::string rpc_protocol_;
      99             :     bool auto_sm_{false};
     100             : 
     101             :     bool interception_enabled_;
     102             : 
     103             :     std::bitset<GKFS_MAX_INTERNAL_FDS> internal_fds_;
     104             :     mutable std::mutex internal_fds_mutex_;
     105             :     bool internal_fds_must_relocate_;
     106             :     std::bitset<MAX_USER_FDS> protected_fds_;
     107             :     std::string hostname;
     108             :     int replicas_;
     109             : 
     110             : public:
     111             :     static PreloadContext*
     112    15025225 :     getInstance() {
     113    15025225 :         static PreloadContext instance;
     114    15025225 :         return &instance;
     115             :     }
     116             : 
     117             :     PreloadContext(PreloadContext const&) = delete;
     118             : 
     119             :     void
     120             :     operator=(PreloadContext const&) = delete;
     121             : 
     122             :     void
     123             :     init_logging();
     124             : 
     125             :     void
     126             :     mountdir(const std::string& path);
     127             : 
     128             :     const std::string&
     129             :     mountdir() const;
     130             : 
     131             :     const std::vector<std::string>&
     132             :     mountdir_components() const;
     133             : 
     134             :     void
     135             :     cwd(const std::string& path);
     136             : 
     137             :     const std::string&
     138             :     cwd() const;
     139             : 
     140             :     const std::vector<hermes::endpoint>&
     141             :     hosts() const;
     142             : 
     143             :     void
     144             :     hosts(const std::vector<hermes::endpoint>& addrs);
     145             : 
     146             :     void
     147             :     clear_hosts();
     148             : 
     149             :     uint64_t
     150             :     local_host_id() const;
     151             : 
     152             :     void
     153             :     local_host_id(uint64_t id);
     154             : 
     155             :     uint64_t
     156             :     fwd_host_id() const;
     157             : 
     158             :     void
     159             :     fwd_host_id(uint64_t id);
     160             : 
     161             :     const std::string&
     162             :     rpc_protocol() const;
     163             : 
     164             :     void
     165             :     rpc_protocol(const std::string& rpc_protocol);
     166             : 
     167             :     bool
     168             :     auto_sm() const;
     169             : 
     170             :     void
     171             :     auto_sm(bool auto_sm);
     172             : 
     173             :     RelativizeStatus
     174             :     relativize_fd_path(int dirfd, const char* raw_path,
     175             :                        std::string& relative_path, int flags = 0,
     176             :                        bool resolve_last_link = true) const;
     177             : 
     178             :     bool
     179             :     relativize_path(const char* raw_path, std::string& relative_path,
     180             :                     bool resolve_last_link = true) const;
     181             : 
     182             :     const std::shared_ptr<gkfs::filemap::OpenFileMap>&
     183             :     file_map() const;
     184             : 
     185             :     void
     186             :     distributor(std::shared_ptr<gkfs::rpc::Distributor> distributor);
     187             : 
     188             :     std::shared_ptr<gkfs::rpc::Distributor>
     189             :     distributor() const;
     190             : 
     191             :     const std::shared_ptr<FsConfig>&
     192             :     fs_conf() const;
     193             : 
     194             :     void
     195             :     enable_interception();
     196             : 
     197             :     void
     198             :     disable_interception();
     199             : 
     200             :     bool
     201             :     interception_enabled() const;
     202             : 
     203             :     int
     204             :     register_internal_fd(int fd);
     205             : 
     206             :     void
     207             :     unregister_internal_fd(int fd);
     208             : 
     209             :     bool
     210             :     is_internal_fd(int fd) const;
     211             : 
     212             :     void
     213             :     protect_user_fds();
     214             : 
     215             :     void
     216             :     unprotect_user_fds();
     217             : 
     218             :     std::string
     219             :     get_hostname();
     220             : 
     221             :     void
     222             :     set_replicas(const int repl);
     223             : 
     224             :     int
     225             :     get_replicas();
     226             : };
     227             : 
     228             : } // namespace preload
     229             : } // namespace gkfs
     230             : 
     231             : 
     232             : #endif // GEKKOFS_PRELOAD_CTX_HPP

Generated by: LCOV version 1.16