Verified Commit b5bfc627 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

preload library use global Metadata class

parent 9de59c8c
Loading
Loading
Loading
Loading
+2 −16
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
#define IFS_PRELOAD_UTIL_HPP

#include <preload/preload.hpp>
#include <global/metadata.hpp>
// third party libs
#include <string>
#include <iostream>
@@ -11,21 +12,6 @@ extern "C" {
#include <margo.h>
}

// Used to bundle metadata into one place
struct Metadentry {
    time_t atime;
    time_t mtime;
    time_t ctime;
    uid_t uid;
    gid_t gid;
    mode_t mode;
    uint64_t inode_no;
    nlink_t link_count;
    off_t size;
    blkcnt_t blocks;

    std::string path;
};
struct MetadentryUpdateFlags {
    bool atime = false;
    bool mtime = false;
@@ -83,7 +69,7 @@ extern std::map<uint64_t, hg_addr_t> rpc_addresses;

bool is_fs_path(const char* path);

int db_val_to_stat(const std::string& path, std::string db_val, struct stat& attr);
int metadata_to_stat(const std::string& path, const Metadata& md, struct stat& attr);

int get_daemon_pid();

+2 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
#include <preload/preload_util.hpp>
#include <global/rpc/rpc_types.hpp>
#include <preload/open_dir.hpp>
#include <global/metadata.hpp>
#include <iostream>

inline hg_return_t margo_forward_timed_wrap_timer(hg_handle_t& handle, void* in_struct, const char* func);
@@ -24,7 +25,7 @@ int rpc_send_rm_node(const std::string& path, const bool remove_metadentry_only)

int rpc_send_decr_size(const std::string& path, size_t length);

int rpc_send_update_metadentry(const std::string& path, const Metadentry& md, const MetadentryUpdateFlags& md_flags);
int rpc_send_update_metadentry(const std::string& path, const Metadata& md, const MetadentryUpdateFlags& md_flags);

int rpc_send_update_metadentry_size(const std::string& path, size_t size, off64_t offset, bool append_flag,
                                    off64_t& ret_size);
+2 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ set(PRELOAD_SRC
    ../global/rpc/rpc_utils.cpp
    ../global/global_func.cpp
    ../global/path_util.cpp
    ../global/metadata.cpp
    )
set(PRELOAD_HEADERS
    ../../configure_public.hpp
@@ -25,6 +26,7 @@ set(PRELOAD_HEADERS
    ../../include/global/rpc/rpc_utils.hpp
    ../../include/global/path_util.hpp
    ../../include/global/chunk_calc_util.hpp
    ../../include/global/metadata.hpp
    ../../include/preload/preload_context.hpp
    ../../include/preload/adafs_functions.hpp
    ../../include/preload/intercept.hpp
+6 −3
Original line number Diff line number Diff line
@@ -163,10 +163,13 @@ int adafs_access(const std::string& path, const int mask) {
}

int adafs_stat(const string& path, struct stat* buf) {
    string attr = ""s;
    std::string attr;
    auto err = rpc_send_stat(path, attr);
    if (err == 0)
        db_val_to_stat(path, attr, *buf);
    if (err) {
        return err;
    }
    Metadata md(attr);
    metadata_to_stat(path, md, *buf);
    return err;
}

+14 −54
Original line number Diff line number Diff line
@@ -13,21 +13,18 @@

using namespace std;

static const char MSP = '|';

bool is_fs_path(const char* path) {
    return strstr(path, CTX->mountdir().c_str()) == path;
}

// TODO merge the two stat functions
/**
 * Converts the dentry db value into a stat struct, which is needed by Linux
 * Converts the Metadata object into a stat struct, which is needed by Linux
 * @param path
 * @param db_val
 * @param md
 * @param attr
 * @return
 */
int db_val_to_stat(const std::string& path, std::string db_val, struct stat& attr) {
int metadata_to_stat(const std::string& path, const Metadata& md, struct stat& attr) {

    /* Populate default values */
    attr.st_dev = makedev(0, 0);
@@ -43,69 +40,32 @@ int db_val_to_stat(const std::string& path, std::string db_val, struct stat& att
    memset(&attr.st_mtim, 0, sizeof(timespec));
    memset(&attr.st_ctim, 0, sizeof(timespec));

    auto pos = db_val.find(MSP);
    if (pos == std::string::npos) { // no delimiter found => no metadata enabled. fill with dummy values
        attr.st_mode = static_cast<unsigned int>(stoul(db_val));
        attr.st_nlink = 1;
        attr.st_uid = CTX->fs_conf()->uid;
        attr.st_gid = CTX->fs_conf()->gid;
        attr.st_size = 0;
        attr.st_blksize = BLOCKSIZE;
        attr.st_blocks = 0;
        attr.st_atim.tv_sec = 0;
        attr.st_mtim.tv_sec = 0;
        attr.st_ctim.tv_sec = 0;
        return 0;
    }
    // some metadata is enabled: mode is always there
    attr.st_mode = static_cast<unsigned int>(stoul(db_val.substr(0, pos)));
    db_val.erase(0, pos + 1);
    // size is also there XXX
    pos = db_val.find(MSP);
    if (pos != std::string::npos) {  // delimiter found. more metadata is coming
        attr.st_size = stol(db_val.substr(0, pos));
        db_val.erase(0, pos + 1);
    } else {
        attr.st_size = stol(db_val);
    }
    // The order is important. don't change.
    attr.st_mode = md.mode();
    attr.st_size = md.size();

    if (CTX->fs_conf()->atime_state) {
        pos = db_val.find(MSP);
        attr.st_atim.tv_sec = static_cast<time_t>(stol(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
        attr.st_atim.tv_sec = md.atime();
    }
    if (CTX->fs_conf()->mtime_state) {
        pos = db_val.find(MSP);
        attr.st_mtim.tv_sec = static_cast<time_t>(stol(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
        attr.st_mtim.tv_sec = md.mtime();
    }
    if (CTX->fs_conf()->ctime_state) {
        pos = db_val.find(MSP);
        attr.st_ctim.tv_sec = static_cast<time_t>(stol(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
        attr.st_ctim.tv_sec = md.ctime();
    }
    if (CTX->fs_conf()->uid_state) {
        pos = db_val.find(MSP);
        attr.st_uid = static_cast<uid_t>(stoul(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
        attr.st_uid = md.uid();
    }
    if (CTX->fs_conf()->gid_state) {
        pos = db_val.find(MSP);
        attr.st_gid = static_cast<uid_t>(stoul(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
        attr.st_gid = md.gid();
    }
    if (CTX->fs_conf()->inode_no_state) {
        pos = db_val.find(MSP);
        attr.st_ino = static_cast<ino_t>(stoul(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
        attr.st_ino = md.inode_no();
    }
    if (CTX->fs_conf()->link_cnt_state) {
        pos = db_val.find(MSP);
        attr.st_nlink = static_cast<nlink_t>(stoul(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
        attr.st_nlink = md.link_count();
    }
    if (CTX->fs_conf()->blocks_state) { // last one will not encounter a delimiter anymore
        attr.st_blocks = static_cast<blkcnt_t>(stoul(db_val));
        attr.st_blocks = md.blocks();
    }
    return 0;
}
Loading