Commit e39eeee2 authored by Marc Vef's avatar Marc Vef
Browse files

Added errorhandling, skeleton for IO

parent 900860a3
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ set(SOURCE_FILES src/main.cpp src/main.hpp src/fuse_ops.hpp src/configure.hpp
        # classes header
        src/classes/metadata.hpp src/classes/fs_data.hpp src/classes/dentry.hpp src/classes/rpc_data.hpp
        # adafs_ops header
        src/adafs_ops/mdata_ops.hpp src/adafs_ops/dentry_ops.hpp src/adafs_ops/access.hpp
        src/adafs_ops/mdata_ops.hpp src/adafs_ops/dentry_ops.hpp src/adafs_ops/access.hpp src/adafs_ops/io.hpp
        # db header
        src/db/db_ops.hpp src/db/db_txn_ops.hpp src/db/db_util.hpp
        # rpc header
@@ -65,11 +65,11 @@ set(SOURCE_FILES src/main.cpp src/main.hpp src/fuse_ops.hpp src/configure.hpp
        # util
        src/util.cpp
        # fuse ops
        src/fuse_ops/file.cpp src/fuse_ops/directory.cpp src/fuse_ops/sync.cpp src/fuse_ops/access.cpp
        src/fuse_ops/file.cpp src/fuse_ops/directory.cpp src/fuse_ops/sync.cpp src/fuse_ops/access.cpp src/fuse_ops/io.cpp
        # classes
        src/classes/metadata.cpp src/classes/fs_data.cpp src/classes/dentry.cpp src/classes/rpc_data.cpp
        # adafs_ops
        src/adafs_ops/mdata_ops.cpp src/adafs_ops/dentry_ops.cpp src/adafs_ops/access.cpp
        src/adafs_ops/mdata_ops.cpp src/adafs_ops/dentry_ops.cpp src/adafs_ops/access.cpp src/adafs_ops/io.cpp
        # db src
        src/db/db_ops.cpp src/db/db_txn_ops.cpp src/db/db_util.cpp
        # rpc src
+12 −10
Original line number Diff line number Diff line
@@ -8,14 +8,14 @@ using namespace std;

/**
 * Creates the directory in the chunk dir for a file to hold data
 * @param hash
 * @param inode
 * @return
 */
// XXX this might be just a temp function as long as we don't use chunks
// XXX this function creates not only the chunk folder but also a single file which holds the data of the 'real' file
int init_chunk_space(const unsigned long hash) {
    auto chnk_path = bfs::path(ADAFS_DATA->chunk_path);
    chnk_path /= to_string(hash);
int init_chunk_space(const fuse_ino_t inode) {
    auto chnk_path = bfs::path(ADAFS_DATA->chunk_path());
    chnk_path /= to_string(inode);

    // create chunk dir
    bfs::create_directories(chnk_path);
@@ -24,20 +24,22 @@ int init_chunk_space(const unsigned long hash) {
    chnk_path /= "data"s;
    bfs::ofstream ofs{chnk_path};

    return static_cast<int>(bfs::exists(chnk_path));
//    return static_cast<int>(bfs::exists(chnk_path));
    return 0;
}
/**
 * Remove the directory in the chunk dir of a file.
 * @param hash
 * @param inode
 * @return
 */
// XXX this might be just a temp function as long as we don't use chunks
int destroy_chunk_space(const unsigned long hash) {
    auto chnk_path = bfs::path(ADAFS_DATA->chunk_path);
    chnk_path /= to_string(hash);
int destroy_chunk_space(const fuse_ino_t inode) {
    auto chnk_path = bfs::path(ADAFS_DATA->chunk_path());
    chnk_path /= to_string(inode);

    // create chunk dir
    bfs::remove_all(chnk_path);

    return static_cast<int>(!bfs::exists(chnk_path));
//    return static_cast<int>(!bfs::exists(chnk_path));
    return 0;
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -7,8 +7,8 @@

#include "../main.hpp"

int init_chunk_space(const unsigned long hash);
int init_chunk_space(const fuse_ino_t inode);

int destroy_chunk_space(const unsigned long hash);
int destroy_chunk_space(const fuse_ino_t inode);

#endif //FS_IO_H
+13 −11
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
#include "dentry_ops.hpp"
#include "../rpc/client/c_dentry.hpp"
#include "../rpc/client/c_metadata.hpp"
#include "io.hpp"

using namespace std;

@@ -185,7 +186,7 @@ int init_metadata_fep(struct fuse_entry_param& fep, const fuse_ino_t inode, cons
        // XXX just visual. size computation of directory should be done properly at some point
        md.size(ADAFS_DATA->blocksize());
    }
    write_all_metadata(md);
    auto err = write_all_metadata(md);

    // create dentry for Linux
    fep.entry_timeout = 1.0;
@@ -193,7 +194,7 @@ int init_metadata_fep(struct fuse_entry_param& fep, const fuse_ino_t inode, cons
    fep.ino = md.inode_no();
    //fill fep.attr with the metadata information
    metadata_to_stat(md, fep.attr);
    return 0;
    return err;
}

/**
@@ -210,9 +211,9 @@ int init_metadata(const fuse_ino_t inode, const uid_t uid, const gid_t gid, mode
        // XXX just visual. size computation of directory should be done properly at some point
        md.size(ADAFS_DATA->blocksize());
    }
    write_all_metadata(md);
    auto err = write_all_metadata(md);

    return 0;
    return err;
}

/**
@@ -226,13 +227,6 @@ int init_metadata(const fuse_ino_t inode, const uid_t uid, const gid_t gid, mode
 */
int create_node(struct fuse_entry_param& fep, fuse_ino_t parent, const char* 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);

    int err;
    // create new inode number
    fuse_ino_t new_inode = Util::generate_inode_no();
@@ -251,6 +245,8 @@ int create_node(struct fuse_entry_param& fep, fuse_ino_t parent, const char* nam
        recipient = RPC_DATA->get_rpc_node(fmt::FormatInt(new_inode).str());
        if (ADAFS_DATA->is_local_op(recipient)) { // local metadata init
            err = init_metadata_fep(fep, new_inode, uid, gid, mode);
            if (err == 0)
                init_chunk_space(new_inode);
        } else { // remote metadata init
            err = rpc_send_create_mdata(recipient, uid, gid, mode, new_inode);
            if (err == 0) {
@@ -280,6 +276,8 @@ int create_node(struct fuse_entry_param& fep, fuse_ino_t parent, const char* nam
        }
        // create metadata and fill fuse entry param
        err = init_metadata_fep(fep, new_inode, uid, gid, mode);
        if (err == 0)
            init_chunk_space(new_inode);
    }
    if (err != 0)
        ADAFS_DATA->spdlogger()->error("Failed to create metadata");
@@ -309,6 +307,8 @@ int remove_node(fuse_ino_t parent, const char* name) {
        recipient = RPC_DATA->get_rpc_node(fmt::FormatInt(del_inode).str());
        if (ADAFS_DATA->is_local_op(recipient)) { // local metadata removal
            err = remove_all_metadata(del_inode);
            if (err == 0)
                destroy_chunk_space(del_inode);
        } else { // remote metadata removal
            err = rpc_send_remove_mdata(recipient, del_inode);
        }
@@ -321,6 +321,8 @@ int remove_node(fuse_ino_t parent, const char* name) {
        }
        // Remove inode
        err = remove_all_metadata(del_inode);
        if (err == 0)
            destroy_chunk_space(del_inode);
    }

    if (err != 0)
+2 −0
Original line number Diff line number Diff line
@@ -27,7 +27,9 @@ void adafs_ll_mkdir(fuse_req_t req, fuse_ino_t parent, const char* name, mode_t
void adafs_ll_rmdir(fuse_req_t req, fuse_ino_t parent, const char* name);
void adafs_ll_releasedir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info* fi);
// I/O
void adafs_ll_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info* fi);

void adafs_ll_write(fuse_req_t req, fuse_ino_t ino, const char* buf, size_t size, off_t off, struct fuse_file_info* fi);


// sync
Loading