Loading src/client/hooks.cpp +32 −13 Original line number Diff line number Diff line Loading @@ -210,14 +210,25 @@ hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) { return -ENOTDIR; case gkfs::preload::RelativizeStatus::internal: { // pass open to fuse to sync fd in file_map auto md_ = gkfs::utils::get_metadata(resolved); if(md_ && 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); 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); if(fd < 0) { return fd; } CTX->file_map()->add( fd, std::make_shared<gkfs::filemap::OpenFile>(resolved, flags)); return fd; } else { return with_errno( gkfs::syscall::gkfs_open(resolved, mode, flags)); } } default: Loading @@ -243,12 +254,16 @@ hook_close(int fd) { LOG(DEBUG, "{}() called with fd: {}", __func__, fd); //auto ret = gkfs::syscall::gkfs_close(fd); auto f = CTX->file_map()->get(fd); if(f != nullptr && f->type() == filemap::FileType::directory) { CTX->file_map()->remove(fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_close, fd)); } auto ret = gkfs::syscall::gkfs_close(fd); //if(ret < 0) //LOG(DEBUG, "{}() close failed with fd: {}, errno {}", __func__, fd, //errno); if(ret == 0) return 0; return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(SYS_close, fd)); } Loading Loading @@ -863,9 +878,11 @@ hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) { return -EFAULT; } /* if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_getdents(fd, dirp, count)); } */ return syscall_no_intercept_wrapper(SYS_getdents, fd, dirp, count); } #endif Loading @@ -880,10 +897,12 @@ hook_getdents64(unsigned int fd, struct linux_dirent64* dirp, return -EFAULT; } /* if(CTX->file_map()->exist(fd)) { LOG(WARNING, "DEBUG: hook_getdents64 fd {} exists in filemap", fd); return with_errno(gkfs::syscall::gkfs_getdents64(fd, dirp, count)); } */ LOG(WARNING, "DEBUG: hook_getdents64 fd {} does NOT exist in filemap", fd); return syscall_no_intercept_wrapper(SYS_getdents64, fd, dirp, count); } Loading Loading
src/client/hooks.cpp +32 −13 Original line number Diff line number Diff line Loading @@ -210,14 +210,25 @@ hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) { return -ENOTDIR; case gkfs::preload::RelativizeStatus::internal: { // pass open to fuse to sync fd in file_map auto md_ = gkfs::utils::get_metadata(resolved); if(md_ && 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); 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); if(fd < 0) { return fd; } CTX->file_map()->add( fd, std::make_shared<gkfs::filemap::OpenFile>(resolved, flags)); return fd; } else { return with_errno( gkfs::syscall::gkfs_open(resolved, mode, flags)); } } default: Loading @@ -243,12 +254,16 @@ hook_close(int fd) { LOG(DEBUG, "{}() called with fd: {}", __func__, fd); //auto ret = gkfs::syscall::gkfs_close(fd); auto f = CTX->file_map()->get(fd); if(f != nullptr && f->type() == filemap::FileType::directory) { CTX->file_map()->remove(fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_close, fd)); } auto ret = gkfs::syscall::gkfs_close(fd); //if(ret < 0) //LOG(DEBUG, "{}() close failed with fd: {}, errno {}", __func__, fd, //errno); if(ret == 0) return 0; return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(SYS_close, fd)); } Loading Loading @@ -863,9 +878,11 @@ hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) { return -EFAULT; } /* if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_getdents(fd, dirp, count)); } */ return syscall_no_intercept_wrapper(SYS_getdents, fd, dirp, count); } #endif Loading @@ -880,10 +897,12 @@ hook_getdents64(unsigned int fd, struct linux_dirent64* dirp, return -EFAULT; } /* if(CTX->file_map()->exist(fd)) { LOG(WARNING, "DEBUG: hook_getdents64 fd {} exists in filemap", fd); return with_errno(gkfs::syscall::gkfs_getdents64(fd, dirp, count)); } */ LOG(WARNING, "DEBUG: hook_getdents64 fd {} does NOT exist in filemap", fd); return syscall_no_intercept_wrapper(SYS_getdents64, fd, dirp, count); } Loading