Commit 2f02b026 authored by Marc Vef's avatar Marc Vef
Browse files

splitting up create rpc into two rpcs

parent df84e8ff
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ pair<int, fuse_ino_t> do_lookup(fuse_req_t& req, const fuse_ino_t p_inode, const
 * @param name
 * @return
 */
int create_dentry(const fuse_ino_t p_inode, const fuse_ino_t inode, const string& name, mode_t mode) {
bool create_dentry(const fuse_ino_t p_inode, const fuse_ino_t inode, const string& name, mode_t mode) {
    // XXX check later if we need to check if dentry of father already exists
    // put dentry for key, value
    return db_put_dentry(db_build_dentry_key(p_inode, name), db_build_dentry_value(inode, mode));
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ void get_dentries(std::vector<Dentry>& dentries, const fuse_ino_t dir_inode);

std::pair<int, fuse_ino_t> do_lookup(fuse_req_t& req, const fuse_ino_t p_inode, const std::string& name);

int create_dentry(const fuse_ino_t p_inode, const fuse_ino_t inode, const std::string& name, mode_t mode);
bool create_dentry(const fuse_ino_t p_inode, const fuse_ino_t inode, const std::string& name, mode_t mode);

std::pair<int, fuse_ino_t> remove_dentry(const fuse_ino_t p_inode, const std::string& name);

+55 −22
Original line number Diff line number Diff line
@@ -8,8 +8,8 @@
using namespace std;

// TODO error handling.
int write_all_metadata(const Metadata& md, const fuse_ino_t inode) {
    auto inode_key = fmt::FormatInt(inode).str();
int write_all_metadata(const Metadata& md) {
    auto inode_key = fmt::FormatInt(md.inode_no()).str();
    db_put_mdata(db_build_mdata_key(
            inode_key, std::get<to_underlying(Md_fields::atime)>(md_field_map)), md.atime());
    db_put_mdata(db_build_mdata_key(
@@ -133,35 +133,68 @@ void metadata_to_stat(const Metadata& md, struct stat& attr) {
}

/**
 * Creates a new node (file or directory) in the file system. Fills given fuse_entry_param.
 * @param req
 * @param fep
 * @param parent
 * @param name
 * Initializes the metadata for the given parameters. Return value not returning the state yet.
 * Function will additionally return filled fuse_entry_param
 * @param inode
 * @param uid
 * @param gid
 * @param mode
 * @return err
 * @return always 0
 */
int create_node(struct fuse_entry_param& fep, fuse_ino_t parent, const string& name, const uid_t uid, const gid_t gid,
int init_metadata_fep(struct fuse_entry_param& fep, const fuse_ino_t inode, const uid_t uid, const gid_t gid,
                      mode_t mode) {
    // create metadata of new file (this will also create a new inode number)
    // mode is used here to init metadata
    auto md = make_shared<Metadata>(mode, uid, gid);
    Metadata md{mode, uid, gid, inode};
    if ((mode & S_IFDIR) == S_IFDIR) {
        md->size(
                ADAFS_DATA->blocksize()); // XXX just visual. size computation of directory should be done properly at some point
        // XXX just visual. size computation of directory should be done properly at some point
        md.size(ADAFS_DATA->blocksize());
    }
    // create directory entry (can fail) in adafs
    create_dentry(parent, md->inode_no(), name, mode);

    // write metadata
    write_all_metadata(*md, md->inode_no());
    write_all_metadata(md);

    // create dentry for Linux
    fep.entry_timeout = 1.0;
    fep.attr_timeout = 1.0;
    fep.ino = md->inode_no();
    //fill fep->attr with the metadata information
    metadata_to_stat(*md, fep.attr);
    fep.ino = md.inode_no();
    //fill fep.attr with the metadata information
    metadata_to_stat(md, fep.attr);
    return 0;
}

/**
 * Initializes the metadata for the given parameters. Return value not returning the state yet.
 * @param inode
 * @param uid
 * @param gid
 * @param mode
 * @return always 0
 */
int init_metadata(const fuse_ino_t inode, const uid_t uid, const gid_t gid, mode_t mode) {
    Metadata md{mode, uid, gid, inode};
    if ((mode & S_IFDIR) == S_IFDIR) {
        // XXX just visual. size computation of directory should be done properly at some point
        md.size(ADAFS_DATA->blocksize());
    }
    write_all_metadata(md);

    return 0;
}

/**
 * Creates a new node (file or directory) in the file system. Fills given fuse_entry_param. This function is only called locally
 * @param req
 * @param fep
 * @param parent
 * @param name
 * @param mode
 * @return err
 */
int create_node(struct fuse_entry_param& fep, fuse_ino_t parent, const string& name, const uid_t uid, const gid_t gid,
                mode_t mode) {
    // create inode number
    auto new_inode = Util::generate_inode_no();
    // create dentry
    create_dentry(parent, new_inode, name, mode);
    // create metadata and fill fuse entry param
    init_metadata_fep(fep, new_inode, uid, gid, mode);

    return 0;
}
+6 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@

using namespace std;

int write_all_metadata(const Metadata& md, const fuse_ino_t inode);
int write_all_metadata(const Metadata& md);

int read_all_metadata(Metadata& md, const fuse_ino_t inode);

@@ -25,6 +25,11 @@ int get_attr(struct stat& attr, const fuse_ino_t inode);

void metadata_to_stat(const Metadata& md, struct stat& attr);

int init_metadata_fep(struct fuse_entry_param& fep, const fuse_ino_t inode, const uid_t uid, const gid_t gid,
                      mode_t mode);

int init_metadata(const fuse_ino_t inode, const uid_t uid, const gid_t gid, mode_t mode);

int create_node(struct fuse_entry_param& fep, fuse_ino_t parent, const string& name, const uid_t uid, const gid_t gid,
                mode_t mode);

+45 −27
Original line number Diff line number Diff line
@@ -5,6 +5,38 @@
#include "rpc_data.hpp"


// Utility functions

bool RPCData::get_addr_by_hostid(const uint64_t hostid, hg_addr_t& svr_addr) {

    if (address_cache_.tryGet(hostid, svr_addr)) {
        ADAFS_DATA->spdlogger()->debug("tryGet successful and put in svr_addr ");
        //found
        return true;
    } else {
        ADAFS_DATA->spdlogger()->debug("not found in lrucache");
        // not found, manual lookup and add address mapping to LRU cache
        auto hostname = "cci+tcp://" + ADAFS_DATA->hosts().at(hostid) + ":" +
                        ADAFS_DATA->rpc_port(); // convert hostid to hostname and port
        ADAFS_DATA->spdlogger()->debug("generated hostid {}", hostname);
        margo_addr_lookup(RPC_DATA->client_mid(), hostname.c_str(), &svr_addr);
        if (svr_addr == HG_ADDR_NULL)
            return false;
        address_cache_.insert(hostid, svr_addr);
        return true;
    }
}

size_t RPCData::get_rpc_node(std::string to_hash) {
    return ADAFS_DATA->hashf()(to_hash) % ADAFS_DATA->host_size();
}

std::string RPCData::get_dentry_hashable(const fuse_ino_t parent, const char* name) {
    return fmt::FormatInt(parent).str() + "_" + name;
}

// Getter/Setter

hg_class_t* RPCData::server_hg_class() const {
    return server_hg_class_;
}
@@ -65,14 +97,6 @@ lru11::Cache<uint64_t, hg_addr_t>& RPCData::address_cache() {
    return address_cache_;
}

hg_id_t RPCData::rpc_srv_create_id() const {
    return rpc_srv_create_id_;
}

void RPCData::rpc_srv_create_id(hg_id_t rpc_srv_create_id) {
    RPCData::rpc_srv_create_id_ = rpc_srv_create_id;
}

hg_id_t RPCData::rpc_srv_attr_id() const {
    return rpc_srv_attr_id_;
}
@@ -81,32 +105,26 @@ void RPCData::rpc_srv_attr_id(hg_id_t rpc_srv_attr_id) {
    RPCData::rpc_srv_attr_id_ = rpc_srv_attr_id;
}

// Utility functions

bool RPCData::get_addr_by_hostid(const uint64_t hostid, hg_addr_t& svr_addr) {
    if (address_cache_.tryGet(hostid, svr_addr)) {
        //found
        return true;
    } else {
        // not found, manual lookup and add address mapping to LRU cache
        auto hostname = "cci+tcp://" + ADAFS_DATA->hosts().at(hostid) + ":" +
                        ADAFS_DATA->rpc_port(); // convert hostid to hostname and port
        margo_addr_lookup(RPC_DATA->client_mid(), hostname.c_str(), &svr_addr);
        if (svr_addr == HG_ADDR_NULL)
            return false;
        address_cache_.insert(hostid, svr_addr);
        return true;
hg_id_t RPCData::rpc_srv_create_dentry_id() const {
    return rpc_srv_create_dentry_id_;
}

void RPCData::rpc_srv_create_dentry_id(hg_id_t rpc_srv_create_dentry_id) {
    RPCData::rpc_srv_create_dentry_id_ = rpc_srv_create_dentry_id;
}

size_t RPCData::get_rpc_node(std::string to_hash) {
    return ADAFS_DATA->hashf()(to_hash) % ADAFS_DATA->host_size();
hg_id_t RPCData::rpc_srv_create_mdata_id() const {
    return rpc_srv_create_mdata_id_;
}

std::string RPCData::get_dentry_hashable(const fuse_ino_t parent, const char* name) {
    return fmt::FormatInt(parent).str() + "_" + name;
void RPCData::rpc_srv_create_mdata_id(hg_id_t rpc_srv_create_mdata_id) {
    RPCData::rpc_srv_create_mdata_id_ = rpc_srv_create_mdata_id;
}







Loading