Commit 9ea982ba authored by sevenuz's avatar sevenuz
Browse files

first hybrid stuff

parent ff27abcd
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -185,6 +185,8 @@ public:

    int add(std::shared_ptr<OpenFile>);

    int add(int fd, std::shared_ptr<OpenFile>);

    bool
    remove(int fd);

+15 −5
Original line number Diff line number Diff line
@@ -209,8 +209,16 @@ hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) {
        case gkfs::preload::RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;

        case gkfs::preload::RelativizeStatus::internal:
            return with_errno(gkfs::syscall::gkfs_open(resolved, mode, flags));
        case gkfs::preload::RelativizeStatus::internal: {
            // pass open to fuse to sync fd in file_map
            int fd = gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_openat, dirfd, cpath, flags, mode));
            LOG(DEBUG, "{}() open passed to fuse fd: {}", __func__, fd);
            // should be the same fd
            CTX->file_map()->add(fd, std::make_shared<gkfs::filemap::OpenFile>(
                                             resolved, flags));
            return with_errno(fd);
        }

        default:
            LOG(ERROR, "{}() rel_fd_path status unknown.", __func__);
@@ -235,10 +243,12 @@ hook_close(int fd) {

    LOG(DEBUG, "{}() called with fd: {}", __func__, fd);

    auto ret = gkfs::syscall::gkfs_close(fd);
    //auto ret = gkfs::syscall::gkfs_close(fd);
    CTX->file_map()->remove(fd);

    if(ret == 0)
        return 0;
    //if(ret < 0)
        //LOG(DEBUG, "{}() close failed with fd: {}, errno {}", __func__, fd,
            //errno);

    return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(SYS_close, fd));
}
+10 −1
Original line number Diff line number Diff line
@@ -247,6 +247,15 @@ OpenFileMap::add(std::shared_ptr<OpenFile> open_file) {
    return fd;
}

int
OpenFileMap::add(int fd, std::shared_ptr<OpenFile> open_file) {
    auto& shard = get_shard(fd);
    lock_guard<recursive_mutex> lock(shard.mutex);
    shard.files[fd] = open_file;
    total_files_++;
    return fd;
}

bool
OpenFileMap::remove(const int fd) {
    if(fd < 0)