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

Merge branch 'seek'

- lseek() added
- OpenFileMap rebuild with tmpfile syscall removed. Flag handling improved
- dup() and dup2() added
- read/write is now using Argobots ES for each thread
- Mercury version bump for local I/O to work with eager mode
parents 1945731b fbbf1309
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ int remove_metadentry(const std::string& path);

int remove_node(const std::string& path);

int get_metadentry_size(const std::string& path, size_t& ret_size);

int update_metadentry_size(const std::string& path, size_t io_size, off_t offset, bool append, size_t& read_size);

int update_metadentry(const std::string& path, Metadata& md);
+0 −17
Original line number Diff line number Diff line
@@ -6,11 +6,6 @@

using namespace std;

template<typename E>
constexpr typename std::underlying_type<E>::type to_underlying(E e) {
    return static_cast<typename std::underlying_type<E>::type>(e);
}

// mapping of enum to string to get the db_keys for metadata
enum class Md_fields {
    atime, mtime, ctime, uid, gid, mode, inode_no, link_count, size, blocks
@@ -27,16 +22,4 @@ void optimize_rocksdb(rocksdb::Options& options);
std::string
db_build_metadentry_value(); // TODO this would build a value based on the number of metadata fields that are used in the fs configuration

//std::string db_build_dentry_key(const fuse_ino_t inode, const std::string& name);
//
//std::string db_build_dentry_prefix(const fuse_ino_t inode);
//
//std::string db_build_dentry_value(const fuse_ino_t inode, const mode_t mode);
//
//std::string db_build_mdata_key(const fuse_ino_t inode, const std::string& field);
//
//string db_build_mdata_key(const string& inode, const string& field);
//
//std::vector<std::string> db_build_all_mdata_keys(const fuse_ino_t inode);

#endif //LFS_DB_UTIL_HPP
+6 −0
Original line number Diff line number Diff line
@@ -10,9 +10,15 @@ namespace hg_tag {
    constexpr auto stat = "rpc_srv_stat";
    constexpr auto remove = "rpc_srv_rm_node";
    constexpr auto update_metadentry = "rpc_srv_update_metadentry";
    constexpr auto get_metadentry_size = "rpc_srv_get_metadentry_size";
    constexpr auto update_metadentry_size = "rpc_srv_update_metadentry_size";
    constexpr auto write_data = "rpc_srv_write_data";
    constexpr auto read_data = "rpc_srv_read_data";
}

template<typename E>
constexpr typename std::underlying_type<E>::type to_underlying(E e) {
    return static_cast<typename std::underlying_type<E>::type>(e);
}

#endif //IFS_GLOBAL_DEFS_HPP
+12 −4
Original line number Diff line number Diff line
@@ -5,19 +5,27 @@

int adafs_open(const std::string& path, mode_t mode, int flags);

int adafs_mk_node(const std::string& path, const mode_t mode);
int adafs_mk_node(const std::string& path, mode_t mode);

int adafs_rm_node(const std::string& path);

int adafs_access(const std::string& path, const int mask);
int adafs_access(const std::string& path, int mask);

int adafs_stat(const std::string& path, struct stat* buf);

int adafs_stat64(const std::string& path, struct stat64* buf);

ssize_t adafs_pread_ws(int fd, void* buf, size_t count, off_t offset);
off64_t adafs_lseek(int fd, off64_t offset, int whence);

ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off_t offset);
off64_t adafs_lseek(std::shared_ptr<OpenFile> adafs_fd, off64_t offset, int whence);

int adafs_dup(int oldfd);

int adafs_dup2(int oldfd, int newfd);

ssize_t adafs_pread_ws(int fd, void* buf, size_t count, off64_t offset);

ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset);


#endif //IFS_ADAFS_FUNCTIONS_HPP
+29 −19
Original line number Diff line number Diff line
@@ -6,38 +6,43 @@
#include <mutex>
#include <memory>

enum class OpenFile_flags {
    append = 0,
    creat,
    trunc,
    rdonly,
    wronly,
    rdwr,
    flag_count // this is purely used as a size variable of this enum class
};

class OpenFile {
private:
    std::string path_;
    bool append_flag_;

    int fd_;
    off_t pos_;
    FILE* tmp_file_;
    std::array<bool, static_cast<int>(OpenFile_flags::flag_count)> flags_ = {false};
    off64_t pos_;
    std::mutex pos_mutex_;
    std::mutex flag_mutex_;

public:
    OpenFile(const std::string& path, bool append_flag);
    // multiple threads may want to update the file position if fd has been duplicated by dup()

    ~OpenFile();
    OpenFile(const std::string& path, int flags);

    void annul_fd();
    ~OpenFile();

    // getter/setter
    std::string path() const;

    void path(const std::string& path_);

    int fd() const;
    off64_t pos();

    void fd(int fd_);
    void pos(off64_t pos_);

    off_t pos() const;
    const bool get_flag(OpenFile_flags flag);

    void pos(off_t pos_);

    bool append_flag() const;

    void append_flag(bool append_flag);
    void set_flag(OpenFile_flags flag, bool value);

};

@@ -46,20 +51,25 @@ class OpenFileMap {

private:
    std::map<int, std::shared_ptr<OpenFile>> files_;
    std::mutex files_mutex_;
    std::recursive_mutex files_mutex_;

    int safe_generate_fd_idx_();

public:
    OpenFileMap();

    OpenFile* get(int fd);
    std::shared_ptr<OpenFile> get(int fd);

    bool exist(int fd);

    int add(std::string path, bool append);
    int add(std::string path, int flags);

    bool remove(int fd);

    int dup(int oldfd);

    int dup2(int oldfd, int newfd);

};


Loading