Loading src/client/gkfs_libc.cpp +48 −10 Original line number Diff line number Diff line Loading @@ -49,9 +49,15 @@ std::atomic<bool> activated{false}; std::atomic<bool> initializing{false}; /** * @brief Notes: we should return -1, and set up errno correctly on libc * interception Actually it is done fine on nearly all operations, but we should * take care */ // Define a debug macro, can be easily disabled // #define GKFS_TRACE #define GKFS_TRACE // #define PATH_SHORTCUT #ifdef GKFS_DEBUG_BUILD Loading Loading @@ -565,7 +571,7 @@ is_gkfs_fd(int fd) { DEBUG_INFO("[GKFS] {}", resolved); \ return gkfs::syscall::gkfs_##name(resolved, __VA_ARGS__); \ case PathStatus::Error: \ return -errno; \ return -1; \ default: \ break; \ } \ Loading @@ -580,7 +586,7 @@ is_gkfs_fd(int fd) { return gkfs::syscall::gkfs_##name(dirfd, resolved, \ __VA_ARGS__); \ case PathStatus::Error: \ return -errno; \ return -1; \ default: \ break; \ } \ Loading @@ -594,7 +600,7 @@ is_gkfs_fd(int fd) { DEBUG_INFO("[GKFS] {}", resolved); \ return gkfs::syscall::gkfs_##name(resolved); \ case PathStatus::Error: \ return -errno; \ return -1; \ default: \ break; \ } \ Loading Loading @@ -1303,7 +1309,7 @@ fcntl(int fd, int cmd, ...) // TODO DEBUG_INFO("[GKFS] F_DUPFD_CLOEXEC {}", fd); ret = gkfs::syscall::gkfs_dup(fd); if(ret == -1) { return -errno; return -1; } CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::cloexec, true); Loading Loading @@ -1336,8 +1342,27 @@ fcntl(int fd, int cmd, ...) // TODO case F_SETFL: DEBUG_INFO("[GKFS] F_SETFL {}", fd); ret = 0; // get flags from arg and setup if(arg & O_RDONLY) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::rdonly, true); } if(arg & O_WRONLY) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::wronly, true); } if(arg & O_RDWR) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::rdwr, true); } if(arg & O_APPEND) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::append, true); } if(arg & O_NONBLOCK) { DEBUG_INFO("[GKFS] F_SETFL {} NONBLOCK", fd); } return ret; case F_SETFD: Loading @@ -1363,9 +1388,22 @@ fcntl(int fd, int cmd, ...) // TODO auto res = real_fcntl(fd, cmd, arg); return res; } case F_GETOWN: { DEBUG_INFO("[GKFS] F_GETOWN {}", fd); auto res = real_fcntl(fd, cmd, arg); return res; } case F_SETOWN: // Used on S3D-IO { DEBUG_INFO("[GKFS] F_SETOWN {}", fd); auto res = real_fcntl(fd, cmd, arg); return res; } default: DEBUG_INFO("[GKFS] NOTSUPPORTED {}", fd); return -ENOTSUP; errno = ENOTSUP; return -1; } } Loading Loading @@ -2032,10 +2070,10 @@ lstat64(const char* path, struct stat64* buf) { if(CTX->interception_enabled()) { std::string resolved; struct stat st; if(resolve_gkfs_path(AT_FDCWD, path, resolved) == if(resolve_gkfs_path(AT_FDCWD, path, resolved, 0, false) == PathStatus::Internal) { DEBUG_INFO("[GKFS] {}", resolved); auto res = gkfs::syscall::gkfs_stat(resolved, &st); auto res = gkfs::syscall::gkfs_stat(resolved, &st, false); convert(&st, buf); return res; } Loading src/client/hooks.cpp +60 −4 Original line number Diff line number Diff line Loading @@ -880,7 +880,38 @@ hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) { ret |= O_RDWR; } return ret; case F_SETFL: LOG(DEBUG, "{}() F_SETFL on fd {}", __func__, fd); // get flags from arg and setup if(arg & O_RDONLY) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::rdonly, true); } if(arg & O_WRONLY) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::wronly, true); } if(arg & O_RDWR) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::rdwr, true); } if(arg & O_APPEND) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::append, true); } if(arg & O_NONBLOCK) { LOG(DEBUG, "[GKFS] F_SETFL {} NONBLOCK", fd); } if(arg & O_ASYNC) { LOG(DEBUG, "[GKFS] F_SETFL {} ASYNC", fd); } if(arg & O_CLOEXEC) { LOG(DEBUG, "[GKFS] F_SETFL {} CLOEXEC", fd); CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::cloexec, true); } return 0; case F_SETFD: LOG(DEBUG, "{}() [fd: {}, cmd: F_SETFD, FD_CLOEXEC: {}]", __func__, fd, (arg & FD_CLOEXEC)); Loading @@ -889,12 +920,37 @@ hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) { return 0; case F_GETLK: LOG(ERROR, "{}() F_GETLK on fd (Not Supported) {}", __func__, fd); return 0; LOG(ERROR, "{}() F_GETLK on fd (on underlying fd) {}", __func__, fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg)); case F_SETLK: LOG(ERROR, "{}() F_SETLK on fd (Not Supported) {}", __func__, fd); return 0; LOG(ERROR, "{}() F_SETLK on fd (on underlying fd) {}", __func__, fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg)); case F_SETLKW: LOG(ERROR, "{}() F_SETLKW on fd (on underlying fd) {}", __func__, fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg)); case F_GETOWN: case __F_GETOWN_EX: LOG(ERROR, "{}() F_GETOWN on fd (on underlying fd) {}", __func__, fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg)); case F_SETOWN: case __F_SETOWN_EX: LOG(ERROR, "{}() F_SETOWN on fd (on underlying fd) {}", __func__, fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg)); default: LOG(ERROR, "{}() unrecognized command {} on fd {}", __func__, cmd, Loading Loading
src/client/gkfs_libc.cpp +48 −10 Original line number Diff line number Diff line Loading @@ -49,9 +49,15 @@ std::atomic<bool> activated{false}; std::atomic<bool> initializing{false}; /** * @brief Notes: we should return -1, and set up errno correctly on libc * interception Actually it is done fine on nearly all operations, but we should * take care */ // Define a debug macro, can be easily disabled // #define GKFS_TRACE #define GKFS_TRACE // #define PATH_SHORTCUT #ifdef GKFS_DEBUG_BUILD Loading Loading @@ -565,7 +571,7 @@ is_gkfs_fd(int fd) { DEBUG_INFO("[GKFS] {}", resolved); \ return gkfs::syscall::gkfs_##name(resolved, __VA_ARGS__); \ case PathStatus::Error: \ return -errno; \ return -1; \ default: \ break; \ } \ Loading @@ -580,7 +586,7 @@ is_gkfs_fd(int fd) { return gkfs::syscall::gkfs_##name(dirfd, resolved, \ __VA_ARGS__); \ case PathStatus::Error: \ return -errno; \ return -1; \ default: \ break; \ } \ Loading @@ -594,7 +600,7 @@ is_gkfs_fd(int fd) { DEBUG_INFO("[GKFS] {}", resolved); \ return gkfs::syscall::gkfs_##name(resolved); \ case PathStatus::Error: \ return -errno; \ return -1; \ default: \ break; \ } \ Loading Loading @@ -1303,7 +1309,7 @@ fcntl(int fd, int cmd, ...) // TODO DEBUG_INFO("[GKFS] F_DUPFD_CLOEXEC {}", fd); ret = gkfs::syscall::gkfs_dup(fd); if(ret == -1) { return -errno; return -1; } CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::cloexec, true); Loading Loading @@ -1336,8 +1342,27 @@ fcntl(int fd, int cmd, ...) // TODO case F_SETFL: DEBUG_INFO("[GKFS] F_SETFL {}", fd); ret = 0; // get flags from arg and setup if(arg & O_RDONLY) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::rdonly, true); } if(arg & O_WRONLY) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::wronly, true); } if(arg & O_RDWR) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::rdwr, true); } if(arg & O_APPEND) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::append, true); } if(arg & O_NONBLOCK) { DEBUG_INFO("[GKFS] F_SETFL {} NONBLOCK", fd); } return ret; case F_SETFD: Loading @@ -1363,9 +1388,22 @@ fcntl(int fd, int cmd, ...) // TODO auto res = real_fcntl(fd, cmd, arg); return res; } case F_GETOWN: { DEBUG_INFO("[GKFS] F_GETOWN {}", fd); auto res = real_fcntl(fd, cmd, arg); return res; } case F_SETOWN: // Used on S3D-IO { DEBUG_INFO("[GKFS] F_SETOWN {}", fd); auto res = real_fcntl(fd, cmd, arg); return res; } default: DEBUG_INFO("[GKFS] NOTSUPPORTED {}", fd); return -ENOTSUP; errno = ENOTSUP; return -1; } } Loading Loading @@ -2032,10 +2070,10 @@ lstat64(const char* path, struct stat64* buf) { if(CTX->interception_enabled()) { std::string resolved; struct stat st; if(resolve_gkfs_path(AT_FDCWD, path, resolved) == if(resolve_gkfs_path(AT_FDCWD, path, resolved, 0, false) == PathStatus::Internal) { DEBUG_INFO("[GKFS] {}", resolved); auto res = gkfs::syscall::gkfs_stat(resolved, &st); auto res = gkfs::syscall::gkfs_stat(resolved, &st, false); convert(&st, buf); return res; } Loading
src/client/hooks.cpp +60 −4 Original line number Diff line number Diff line Loading @@ -880,7 +880,38 @@ hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) { ret |= O_RDWR; } return ret; case F_SETFL: LOG(DEBUG, "{}() F_SETFL on fd {}", __func__, fd); // get flags from arg and setup if(arg & O_RDONLY) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::rdonly, true); } if(arg & O_WRONLY) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::wronly, true); } if(arg & O_RDWR) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::rdwr, true); } if(arg & O_APPEND) { CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::append, true); } if(arg & O_NONBLOCK) { LOG(DEBUG, "[GKFS] F_SETFL {} NONBLOCK", fd); } if(arg & O_ASYNC) { LOG(DEBUG, "[GKFS] F_SETFL {} ASYNC", fd); } if(arg & O_CLOEXEC) { LOG(DEBUG, "[GKFS] F_SETFL {} CLOEXEC", fd); CTX->file_map()->get(fd)->set_flag( gkfs::filemap::OpenFile_flags::cloexec, true); } return 0; case F_SETFD: LOG(DEBUG, "{}() [fd: {}, cmd: F_SETFD, FD_CLOEXEC: {}]", __func__, fd, (arg & FD_CLOEXEC)); Loading @@ -889,12 +920,37 @@ hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) { return 0; case F_GETLK: LOG(ERROR, "{}() F_GETLK on fd (Not Supported) {}", __func__, fd); return 0; LOG(ERROR, "{}() F_GETLK on fd (on underlying fd) {}", __func__, fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg)); case F_SETLK: LOG(ERROR, "{}() F_SETLK on fd (Not Supported) {}", __func__, fd); return 0; LOG(ERROR, "{}() F_SETLK on fd (on underlying fd) {}", __func__, fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg)); case F_SETLKW: LOG(ERROR, "{}() F_SETLKW on fd (on underlying fd) {}", __func__, fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg)); case F_GETOWN: case __F_GETOWN_EX: LOG(ERROR, "{}() F_GETOWN on fd (on underlying fd) {}", __func__, fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg)); case F_SETOWN: case __F_SETOWN_EX: LOG(ERROR, "{}() F_SETOWN on fd (on underlying fd) {}", __func__, fd); return gsl::narrow_cast<int>( syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg)); default: LOG(ERROR, "{}() unrecognized command {} on fd {}", __func__, cmd, Loading