Commit 6ef95341 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add support for storage backends and stubs for nvml-dax and posix-fs

parent 4ac83f1b
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -31,11 +31,19 @@ bin_PROGRAMS = src/urd

src_urd_SOURCES = 			\
	src/ipc-listener.hpp	\
	src/backends.cpp        \
	src/backends.hpp        \
	src/nvml-dax.cpp        \
	src/nvml-dax.hpp        \
	src/main.cpp			\
	src/posix-fs.cpp		\
	src/posix-fs.hpp		\
	src/settings.cpp		\
	src/settings.hpp		\
	src/urd.cpp				\
	src/urd.hpp
	src/urd.hpp				\
	src/utils.cpp			\
	src/utils.hpp

src_urd_CXXFLAGS = 				\
	@TBB_CFLAGS@ 				\
+10 −6
Original line number Diff line number Diff line
@@ -9,14 +9,18 @@
    "backends" : 
    [ 
        {
            "name" : "NVM",
            "path" : "/foo/bar/nvm",
            "capacity" : "2GB"
            "name" : "3DXPoint_mount0",
            "type" : "nvml-dax",
            "description" : "Intel's 3DXPoint NVM",
            "capacity" : "2GB",
            "path" : "/foo/bar/nvm"
        },
        {
            "name" : "Lustre",
            "path" : "/foo/bar/lustre",
            "capacity" : "2GB"
            "name" : "Lustre_mount0",
            "type" : "posix-fs",
            "description" : "Lustre",
            "capacity" : "2GB",
            "path" : "/foo/bar/lustre"
        }
    ]
}

src/backends.cpp

0 → 100644
+49 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2017 Barcelona Supercomputing Center
//                    Centro Nacional de Supercomputacion
//
// This file is part of the Data Scheduler, a daemon for tracking and managing
// requests for asynchronous data transfer in a hierarchical storage environment.
//
// See AUTHORS file in the top level directory for information
// regarding developers and contributors.
//
// The Data Scheduler 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.
//
// Data Scheduler 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 Data Scheduler.  If not, see <http://www.gnu.org/licenses/>.
//

#include "backends.hpp"

namespace bpt = boost::property_tree;

namespace storage {

    backend_factory& backend_factory::get_instance() {
        static backend_factory _;
        return _;
    }

    std::shared_ptr<backend> backend_factory::create(const std::string& backend_type, const bpt::ptree& options) const {

        // find backend_type in the registry and call the registered construction method
        const auto& it = m_registrar.find(backend_type);

        if(it != m_registrar.end()){
            return std::shared_ptr<backend>(it->second(options));
        }
        else{
            throw std::invalid_argument("Unrecognized backend type!");
        }
    }

}

src/backends.hpp

0 → 100644
+89 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2017 Barcelona Supercomputing Center
//                    Centro Nacional de Supercomputacion
//
// This file is part of the Data Scheduler, a daemon for tracking and managing
// requests for asynchronous data transfer in a hierarchical storage environment.
//
// See AUTHORS file in the top level directory for information
// regarding developers and contributors.
//
// The Data Scheduler 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.
//
// Data Scheduler 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 Data Scheduler.  If not, see <http://www.gnu.org/licenses/>.
//

#ifndef __BACKENDS_HPP__
#define __BACKENDS_HPP__

#include <functional>
#include <unordered_map>
#include <memory>
#include <boost/preprocessor/cat.hpp>
#include <boost/property_tree/ptree.hpp>

namespace bpt = boost::property_tree;

namespace storage {

class backend {
public:
    virtual ~backend() {};
    virtual const std::string& get_name() const = 0;
    virtual const std::string& get_type() const = 0;
    virtual const std::string& get_description() const = 0;
    virtual uint64_t get_capacity() const = 0;
    virtual void read_data() const = 0;
    virtual void write_data() const = 0;
}; // class backend

#define REGISTER_BACKEND(name, T)                                                       \
    static bool BOOST_PP_CAT(T, __regged) =                                             \
        storage::backend_factory::get_instance().register_backend<T>(name,              \
                [](const bpt::ptree& options) {                                         \
                    return std::shared_ptr<T>(new T(options)); \
                });

class backend_factory {

    using creatorfn_t = std::function<std::shared_ptr<backend>(const bpt::ptree&)>;


public:
    static backend_factory& get_instance();
    std::shared_ptr<backend> create(const std::string& name, const bpt::ptree& options) const;

    template <typename T>
    bool register_backend(const std::string& name, creatorfn_t fn) {

        if(m_registrar.find(name) != m_registrar.end()){
            throw std::invalid_argument("A storage backend with that name already exists!");
        }

        m_registrar.insert({name, fn});
        return true;
    }

protected:
    backend_factory() {}
    backend_factory(const backend_factory&) {}
    backend_factory& operator=(const backend_factory&); //{}
    ~backend_factory() {}

private:
    std::unordered_map<std::string, creatorfn_t> m_registrar;

}; // class factory

} // namespace storage

#endif // __BACKENDS_HPP__
+10 −1
Original line number Diff line number Diff line
@@ -36,11 +36,15 @@ public:
    logger(const std::string& ident, const std::string& type) {

        try {
//            spdlog::set_async_mode(queue_size);

            if(type == "stdout") {
                spdlog::set_async_mode(queue_size);
                m_internal_logger = spdlog::stdout_logger_mt(ident);
            }
            else if(type == "stdout color") {
                spdlog::set_async_mode(queue_size);
                m_internal_logger = spdlog::stdout_color_mt(ident);
            }
#ifdef SPDLOG_ENABLE_SYSLOG 
            else if(type == "syslog") {
                m_internal_logger = spdlog::syslog_logger("syslog", ident, LOG_PID);
@@ -67,6 +71,11 @@ public:
        }
    }

    ~logger(){
        std::cerr << "XXXXXXXXXX called!\n";
        spdlog::drop_all();
    }

    template <typename... Args>
    inline void info(const char* fmt, const Args&... args) {
        m_internal_logger->info(fmt, args...);
Loading