Commit 756af21d authored by Marc Vef's avatar Marc Vef
Browse files

Complete rewrite of global storage factility with a singleton.

Private data of fuse is still used for inode and will be moved later to the singleton.
parent 6e447a6e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ find_package(Boost 1.56.0 COMPONENTS system filesystem serialization)

include_directories(${FUSE3_INCLUDE_DIR} include/)
set(SOURCE_FILES src/main.cpp src/main.h src/fuse_ops.h src/configure.h
        src/classes/metadata.h src/classes/metadata.cpp
        src/classes/metadata.h src/classes/metadata.cpp src/classes/fs_data.h src/classes/fs_data.cpp
        src/adafs_ops/metadata_ops.h #src/adafs_ops/dentry_ops.h

        src/util.cpp
+3 −37
Original line number Diff line number Diff line
@@ -5,8 +5,7 @@
#include "metadata_ops.h"
#include "dentry_ops.h"

#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>


// TODO error handling. Each read_metadata_field should check for boolean, i.e., if I/O failed.
bool write_all_metadata(const Metadata& md, const uint64_t inode) {
@@ -24,22 +23,6 @@ bool write_all_metadata(const Metadata& md, const uint64_t inode) {
    return true;
}

// TODO error handling.
template<typename T>
bool write_metadata_field(const T& field, const string& field_name, const uint64_t inode) {
    auto i_path = bfs::path(Fs_paths::inode_path);
    i_path /= to_string(inode);
    bfs::create_directories(i_path);
    i_path /= field_name;

    bfs::ofstream ofs{i_path};
    // write to disk in binary form
    boost::archive::binary_oarchive ba(ofs);
    ba << field;

    return true;
}

// TODO error handling. Each read_metadata_field should check for nullptr, i.e., if I/O failed.
bool read_all_metadata(Metadata& md, const uint64_t inode) {
    md.atime(*read_metadata_field<time_t>(md_field_map.at(Md_fields::atime), inode));
@@ -55,25 +38,8 @@ bool read_all_metadata(Metadata& md, const uint64_t inode) {
    return true;
}


template<typename T>
unique_ptr<T> read_metadata_field(const string& field_name, const uint64_t inode) {
    auto path = bfs::path(Fs_paths::inode_path);
    path /= to_string(inode);
    path /= field_name;
    if (!bfs::exists(path)) return nullptr;

    bfs::ifstream ifs{path};
    //fast error checking
    //ifs.good()
    boost::archive::binary_iarchive ba(ifs);
    auto field = make_unique<T>();
    ba >> *field;
    return field;
}

int get_metadata(Metadata& md, const uint64_t inode) {
    spdlogger->debug("get_metadata() enter for inode {}", inode);
    ADAFS_DATA->spdlogger()->debug("get_metadata() enter for inode {}", inode);
    // Verify that the file is a valid dentry of the parent dir XXX put back in later when we have dentry ops
//    if (verify_dentry(inode)) {
//        // Metadata for file exists
@@ -82,7 +48,7 @@ int get_metadata(Metadata& md, const uint64_t inode) {
//    } else {
//        return -ENOENT;
//    }
    auto path = bfs::path(Fs_paths::inode_path);
    auto path = bfs::path(ADAFS_DATA->inode_path());
    path /= to_string(inode);
    if (bfs::exists(path)) {
        read_all_metadata(md, inode);
+32 −2
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@
#include "../main.h"
#include "../classes/metadata.h"

#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>

using namespace std;

// mapping of enum to string to get the file names for metadata
@@ -29,13 +32,40 @@ const std::map<Md_fields, std::string> md_field_map = {

bool write_all_metadata(const Metadata& md, const uint64_t inode);

// TODO error handling.
template<typename T>
bool write_metadata_field(const T& field, const string& field_name, const uint64_t inode);
bool write_metadata_field(const T& field, const string& field_name, const uint64_t inode) {
    auto i_path = bfs::path(ADAFS_DATA->inode_path());
    i_path /= to_string(inode);
    bfs::create_directories(i_path);
    i_path /= field_name;

    bfs::ofstream ofs{i_path};
    // write to disk in binary form
    boost::archive::binary_oarchive ba(ofs);
    ba << field;

    return true;
}

bool read_all_metadata(Metadata& md, const uint64_t inode);

// TODO error handling
template<typename T>
unique_ptr<T> read_metadata_field(const string& field_name, const uint64_t inode);
unique_ptr<T> read_metadata_field(const string& field_name, const uint64_t inode) {
    auto path = bfs::path(ADAFS_DATA->inode_path());
    path /= to_string(inode);
    path /= field_name;
    if (!bfs::exists(path)) return nullptr;

    bfs::ifstream ifs{path};
    //fast error checking
    //ifs.good()
    boost::archive::binary_iarchive ba(ifs);
    auto field = make_unique<T>();
    ba >> *field;
    return field;
}

int get_metadata(Metadata& md, const uint64_t inode);

+78 −0
Original line number Diff line number Diff line
//
// Created by evie on 4/18/17.
//

#include "fs_data.h"

const std::unordered_map<std::string, std::string>& FsData::hashmap() const {
    return hashmap_;
}

void FsData::hashmap(const std::unordered_map<std::string, std::string>& hashmap_) {
    FsData::hashmap_ = hashmap_;
}

const std::hash<std::string>& FsData::hashf() const {
    return hashf_;
}

void FsData::hashf(const std::hash<std::string>& hashf_) {
    FsData::hashf_ = hashf_;
}

int32_t FsData::blocksize() const {
    return blocksize_;
}

void FsData::blocksize(int32_t blocksize_) {
    FsData::blocksize_ = blocksize_;
}

const std::shared_ptr<spdlog::logger>& FsData::spdlogger() const {
    return spdlogger_;
}

void FsData::spdlogger(const std::shared_ptr<spdlog::logger>& spdlogger_) {
    FsData::spdlogger_ = spdlogger_;
}

const std::string& FsData::rootdir() const {
    return rootdir_;
}

void FsData::rootdir(const std::string& rootdir_) {
    FsData::rootdir_ = rootdir_;
}

const std::string& FsData::inode_path() const {
    return inode_path_;
}

void FsData::inode_path(const std::string& inode_path_) {
    FsData::inode_path_ = inode_path_;
}

const std::string& FsData::dentry_path() const {
    return dentry_path_;
}

void FsData::dentry_path(const std::string& dentry_path_) {
    FsData::dentry_path_ = dentry_path_;
}

const std::string& FsData::chunk_path() const {
    return chunk_path_;
}

void FsData::chunk_path(const std::string& chunk_path_) {
    FsData::chunk_path_ = chunk_path_;
}

const std::string& FsData::mgmt_path() const {
    return mgmt_path_;
}

void FsData::mgmt_path(const std::string& mgmt_path_) {
    FsData::mgmt_path_ = mgmt_path_;
}
+83 −0
Original line number Diff line number Diff line
//
// Created by evie on 4/18/17.
//

#ifndef LFS_FS_DATA_H
#define LFS_FS_DATA_H

#include "../main.h"

class FsData {

private:
    FsData() {}

    // Caching
    std::unordered_map<std::string, std::string> hashmap_;
    std::hash<std::string> hashf_;

    // Later the blocksize will likely be coupled to the chunks to allow individually big chunk sizes.
    int32_t blocksize_;

    //logger
    std::shared_ptr<spdlog::logger> spdlogger_;

    // paths
    std::string rootdir_;
    std::string inode_path_;
    std::string dentry_path_;
    std::string chunk_path_;
    std::string mgmt_path_;


public:
    static FsData* getInstance() {
        static FsData instance;
        return &instance;
    }

    FsData(FsData const&) = delete;

    void operator=(FsData const&) = delete;

    // getter/setter
    const std::unordered_map<std::string, std::string>& hashmap() const;

    void hashmap(const std::unordered_map<std::string, std::string>& hashmap_);

    const std::hash<std::string>& hashf() const;

    void hashf(const std::hash<std::string>& hashf_);

    int32_t blocksize() const;

    void blocksize(int32_t blocksize_);

    const std::shared_ptr<spdlog::logger>& spdlogger() const;

    void spdlogger(const std::shared_ptr<spdlog::logger>& spdlogger_);

    const std::string& rootdir() const;

    void rootdir(const std::string& rootdir_);

    const std::string& inode_path() const;

    void inode_path(const std::string& inode_path_);

    const std::string& dentry_path() const;

    void dentry_path(const std::string& dentry_path_);

    const std::string& chunk_path() const;

    void chunk_path(const std::string& chunk_path_);

    const std::string& mgmt_path() const;

    void mgmt_path(const std::string& mgmt_path_);

};


#endif //LFS_FS_DATA_H
Loading