Loading include/client/open_file_map.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -147,6 +147,8 @@ public: bool exist(int fd); int add(int fd, std::shared_ptr<OpenFile>); int add(std::shared_ptr<OpenFile>); bool Loading src/client/gkfs_functions.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -1588,6 +1588,7 @@ gkfs_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) { auto open_dir = CTX->file_map()->get_dir(fd); if(open_dir == nullptr) { // Cast did not succeeded: open_file is a regular file LOG(DEBUG, "{}() tried getdents with fd: {} but now its EBADF", __func__, fd); errno = EBADF; return -1; } Loading src/client/hooks.cpp +24 −5 Original line number Diff line number Diff line Loading @@ -91,9 +91,25 @@ 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: { auto md_ = gkfs::utils::get_metadata(resolved); if(S_ISDIR(md_->mode())) { // if its a directory, it is handled without fuse // TODO this could cause problems in the filemap if a dir fd and // a file fd are overwriting each other return gkfs::syscall::gkfs_opendir(resolved); } else { // 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, "{}() relativize status unknown: {}", __func__); return -EINVAL; Loading @@ -107,9 +123,12 @@ hook_close(int fd) { auto ret = gkfs::syscall::gkfs_close(fd); if(ret == 0) return 0; if(ret < 0) LOG(DEBUG, "{}() close failed with fd: {}, errno {}", __func__, fd, errno); // we also close the fd in fuse // TODO does this make inconsistency if both use gkfs_close? return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(SYS_close, fd)); } #ifdef SYS_stat Loading src/client/open_file_map.cpp +8 −1 Original line number Diff line number Diff line Loading @@ -179,6 +179,13 @@ OpenFileMap::safe_generate_fd_idx_() { return fd; } int OpenFileMap::add(int fd, std::shared_ptr<OpenFile> open_file) { lock_guard<recursive_mutex> lock(files_mutex_); files_.insert(make_pair(fd, open_file)); return fd; } int OpenFileMap::add(std::shared_ptr<OpenFile> open_file) { auto fd = safe_generate_fd_idx_(); Loading Loading
include/client/open_file_map.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -147,6 +147,8 @@ public: bool exist(int fd); int add(int fd, std::shared_ptr<OpenFile>); int add(std::shared_ptr<OpenFile>); bool Loading
src/client/gkfs_functions.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -1588,6 +1588,7 @@ gkfs_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) { auto open_dir = CTX->file_map()->get_dir(fd); if(open_dir == nullptr) { // Cast did not succeeded: open_file is a regular file LOG(DEBUG, "{}() tried getdents with fd: {} but now its EBADF", __func__, fd); errno = EBADF; return -1; } Loading
src/client/hooks.cpp +24 −5 Original line number Diff line number Diff line Loading @@ -91,9 +91,25 @@ 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: { auto md_ = gkfs::utils::get_metadata(resolved); if(S_ISDIR(md_->mode())) { // if its a directory, it is handled without fuse // TODO this could cause problems in the filemap if a dir fd and // a file fd are overwriting each other return gkfs::syscall::gkfs_opendir(resolved); } else { // 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, "{}() relativize status unknown: {}", __func__); return -EINVAL; Loading @@ -107,9 +123,12 @@ hook_close(int fd) { auto ret = gkfs::syscall::gkfs_close(fd); if(ret == 0) return 0; if(ret < 0) LOG(DEBUG, "{}() close failed with fd: {}, errno {}", __func__, fd, errno); // we also close the fd in fuse // TODO does this make inconsistency if both use gkfs_close? return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(SYS_close, fd)); } #ifdef SYS_stat Loading
src/client/open_file_map.cpp +8 −1 Original line number Diff line number Diff line Loading @@ -179,6 +179,13 @@ OpenFileMap::safe_generate_fd_idx_() { return fd; } int OpenFileMap::add(int fd, std::shared_ptr<OpenFile> open_file) { lock_guard<recursive_mutex> lock(files_mutex_); files_.insert(make_pair(fd, open_file)); return fd; } int OpenFileMap::add(std::shared_ptr<OpenFile> open_file) { auto fd = safe_generate_fd_idx_(); Loading