Resolve "Hooks narrow cast types"

Closes #280 (closed)

Merge request reports

Loading
Changes for external/GSL: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
Subproject commit a3534567187d2edc428efd3f13466ff75fe5805c
+12 −12
Changes for include/client/hooks.hpp: 12 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -94,29 +94,29 @@ hook_fstat(unsigned int fd, struct stat* buf);
int
hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags);

int
ssize_t
hook_read(unsigned int fd, void* buf, size_t count);

int
ssize_t
hook_pread(unsigned int fd, char* buf, size_t count, loff_t pos);

int
ssize_t
hook_readv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt);

int
ssize_t
hook_preadv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt,
            unsigned long pos_l, unsigned long pos_h);

int
ssize_t
hook_write(unsigned int fd, const char* buf, size_t count);

int
ssize_t
hook_pwrite(unsigned int fd, const char* buf, size_t count, loff_t pos);

int
ssize_t
hook_writev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt);

int
ssize_t
hook_pwritev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt,
             unsigned long pos_l, unsigned long pos_h);

@@ -158,10 +158,10 @@ hook_dup2(unsigned int oldfd, unsigned int newfd);
int
hook_dup3(unsigned int oldfd, unsigned int newfd, int flags);

int
long
hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count);

int
ssize_t
hook_getdents64(unsigned int fd, struct linux_dirent64* dirp,
                unsigned int count);

@@ -183,7 +183,7 @@ hook_fchdir(unsigned int fd);
int
hook_getcwd(char* buf, unsigned long size);

int
ssize_t
hook_readlinkat(int dirfd, const char* cpath, char* buf, int bufsiz);

int
@@ -202,7 +202,7 @@ hook_fstatfs(unsigned int fd, struct statfs* buf);
int
hook_fsync(unsigned int fd);

int
ssize_t
hook_getxattr(const char* path, const char* name, void* value, size_t size);

int
+2 −0
Changes for src/client/CMakeLists.txt: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ target_link_libraries(
    fmt::fmt
    Threads::Threads
    Syscall_intercept::Syscall_intercept
    Microsoft.GSL::GSL
)
# Enable MSGPack metrics for intercept only
if (GKFS_ENABLE_CLIENT_METRICS)
@@ -116,6 +117,7 @@ target_link_libraries(
    hermes
    fmt::fmt
    Threads::Threads
    Microsoft.GSL::GSL
)

install(
+85 −70
Changes for src/client/hooks.cpp: 85 added lines, 70 removed lines.
Original line number Diff line number Diff line
@@ -37,19 +37,23 @@

#include <common/path_util.hpp>

#include <memory>
#include <string>

#include <gsl/util>

extern "C" {
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/syscall.h>
}

namespace {

// TODO replace all internal gkfs errno variable usage with LEAF
inline int
with_errno(int ret) {
template <typename T>
inline T
with_errno(T ret) {
    return (ret < 0) ? -errno : ret;
}

@@ -67,12 +71,12 @@ hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) {
    auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved);
    switch(rstatus) {
        case gkfs::preload::RelativizeStatus::fd_unknown:
            return syscall_no_intercept_wrapper(SYS_openat, dirfd, cpath, flags,
                                                mode);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_openat, dirfd, cpath, flags, mode));

        case gkfs::preload::RelativizeStatus::external:
            return syscall_no_intercept_wrapper(SYS_openat, dirfd,
                                                resolved.c_str(), flags, mode);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_openat, dirfd, resolved.c_str(), flags, mode));

        case gkfs::preload::RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;
@@ -96,7 +100,7 @@ hook_close(int fd) {
    if(ret == 0)
        return 0;

    return syscall_no_intercept_wrapper(SYS_close, fd);
    return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(SYS_close, fd));
}
#ifdef SYS_stat
int
@@ -110,7 +114,8 @@ hook_stat(const char* path, struct stat* buf) {
        return with_errno(gkfs::syscall::gkfs_stat(rel_path, buf));
    }

    return syscall_no_intercept_wrapper(SYS_stat, rel_path.c_str(), buf);
    return gsl::narrow_cast<int>(
            syscall_no_intercept_wrapper(SYS_stat, rel_path.c_str(), buf));
}
#endif

@@ -128,12 +133,12 @@ hook_statx(int dirfd, const char* path, int flags, unsigned int mask,
    auto rstatus = CTX->relativize_fd_path(dirfd, path, resolved);
    switch(rstatus) {
        case gkfs::preload::RelativizeStatus::fd_unknown:
            return syscall_no_intercept_wrapper(SYS_statx, dirfd, path, flags,
                                                mask, buf);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_statx, dirfd, path, flags, mask, buf));

        case gkfs::preload::RelativizeStatus::external:
            return syscall_no_intercept_wrapper(
                    SYS_statx, dirfd, resolved.c_str(), flags, mask, buf);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_statx, dirfd, resolved.c_str(), flags, mask, buf));

        case gkfs::preload::RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;
@@ -146,8 +151,6 @@ hook_statx(int dirfd, const char* path, int flags, unsigned int mask,
            LOG(ERROR, "{}() relativize status unknown: {}", __func__);
            return -EINVAL;
    }

    return syscall_no_intercept(SYS_statx, dirfd, path, flags, mask, buf);
}

#endif
@@ -163,7 +166,8 @@ hook_lstat(const char* path, struct stat* buf) {
    if(CTX->relativize_path(path, rel_path)) {
        return with_errno(gkfs::syscall::gkfs_stat(rel_path, buf));
    }
    return syscall_no_intercept_wrapper(SYS_lstat, rel_path.c_str(), buf);
    return gsl::narrow_cast<int>(
            syscall_no_intercept_wrapper(SYS_lstat, rel_path.c_str(), buf));
}
#endif

@@ -184,7 +188,8 @@ hook_fstat(unsigned int fd, struct stat* buf) {
#endif
        return with_errno(gkfs::syscall::gkfs_stat(path, buf));
    }
    return syscall_no_intercept_wrapper(SYS_fstat, fd, buf);
    return gsl::narrow_cast<int>(
            syscall_no_intercept_wrapper(SYS_fstat, fd, buf));
}

int
@@ -197,12 +202,12 @@ hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags) {
    auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved, flags);
    switch(rstatus) {
        case gkfs::preload::RelativizeStatus::fd_unknown:
            return syscall_no_intercept_wrapper(SYS_newfstatat, dirfd, cpath,
                                                buf, flags);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_newfstatat, dirfd, cpath, buf, flags));

        case gkfs::preload::RelativizeStatus::external:
            return syscall_no_intercept_wrapper(SYS_newfstatat, dirfd,
                                                resolved.c_str(), buf, flags);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_newfstatat, dirfd, resolved.c_str(), buf, flags));

        case gkfs::preload::RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;
@@ -216,7 +221,7 @@ hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags) {
    }
}

int
ssize_t
hook_read(unsigned int fd, void* buf, size_t count) {

    LOG(DEBUG, "{}() called with fd: {}, buf: {} count: {}", __func__, fd,
@@ -228,7 +233,7 @@ hook_read(unsigned int fd, void* buf, size_t count) {
    return syscall_no_intercept_wrapper(SYS_read, fd, buf, count);
}

int
ssize_t
hook_pread(unsigned int fd, char* buf, size_t count, loff_t pos) {

    LOG(DEBUG, "{}() called with fd: {}, buf: {}, count: {}, pos: {}", __func__,
@@ -242,7 +247,7 @@ hook_pread(unsigned int fd, char* buf, size_t count, loff_t pos) {
    return syscall_no_intercept_wrapper(SYS_pread64, fd, buf, count, pos);
}

int
ssize_t
hook_readv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt) {

    LOG(DEBUG, "{}() called with fd: {}, iov: {}, iovcnt: {}", __func__, fd,
@@ -254,7 +259,7 @@ hook_readv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt) {
    return syscall_no_intercept_wrapper(SYS_readv, fd, iov, iovcnt);
}

int
ssize_t
hook_preadv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt,
            unsigned long pos_l, unsigned long pos_h) {

@@ -270,7 +275,7 @@ hook_preadv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt,
    return syscall_no_intercept_wrapper(SYS_preadv, fd, iov, iovcnt, pos_l);
}

int
ssize_t
hook_write(unsigned int fd, const char* buf, size_t count) {

    LOG(DEBUG, "{}() called with fd: {}, buf: {}, count {}", __func__, fd,
@@ -282,7 +287,7 @@ hook_write(unsigned int fd, const char* buf, size_t count) {
    return syscall_no_intercept_wrapper(SYS_write, fd, buf, count);
}

int
ssize_t
hook_pwrite(unsigned int fd, const char* buf, size_t count, loff_t pos) {

    LOG(DEBUG, "{}() called with fd: {}, buf: {}, count: {}, pos: {}", __func__,
@@ -296,7 +301,7 @@ hook_pwrite(unsigned int fd, const char* buf, size_t count, loff_t pos) {
    return syscall_no_intercept_wrapper(SYS_pwrite64, fd, buf, count, pos);
}

int
ssize_t
hook_writev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt) {

    LOG(DEBUG, "{}() called with fd: {}, iov: {}, iovcnt: {}", __func__, fd,
@@ -308,7 +313,7 @@ hook_writev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt) {
    return syscall_no_intercept_wrapper(SYS_writev, fd, iov, iovcnt);
}

int
ssize_t
hook_pwritev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt,
             unsigned long pos_l, unsigned long pos_h) {

@@ -339,12 +344,12 @@ hook_unlinkat(int dirfd, const char* cpath, int flags) {
    auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved, false);
    switch(rstatus) {
        case gkfs::preload::RelativizeStatus::fd_unknown:
            return syscall_no_intercept_wrapper(SYS_unlinkat, dirfd, cpath,
                                                flags);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_unlinkat, dirfd, cpath, flags));

        case gkfs::preload::RelativizeStatus::external:
            return syscall_no_intercept_wrapper(SYS_unlinkat, dirfd,
                                                resolved.c_str(), flags);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_unlinkat, dirfd, resolved.c_str(), flags));

        case gkfs::preload::RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;
@@ -379,12 +384,12 @@ hook_symlinkat(const char* oldname, int newdfd, const char* newname) {
            CTX->relativize_fd_path(newdfd, newname, newname_resolved, false);
    switch(rstatus) {
        case gkfs::preload::RelativizeStatus::fd_unknown:
            return syscall_no_intercept_wrapper(SYS_symlinkat, oldname, newdfd,
                                                newname);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_symlinkat, oldname, newdfd, newname));

        case gkfs::preload::RelativizeStatus::external:
            return syscall_no_intercept_wrapper(SYS_symlinkat, oldname, newdfd,
                                                newname_resolved.c_str());
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_symlinkat, oldname, newdfd, newname_resolved.c_str()));

        case gkfs::preload::RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;
@@ -424,7 +429,8 @@ hook_access(const char* path, int mask) {
        }
        return ret;
    }
    return syscall_no_intercept_wrapper(SYS_access, rel_path.c_str(), mask);
    return gsl::narrow_cast<int>(
            syscall_no_intercept_wrapper(SYS_access, rel_path.c_str(), mask));
}
#endif

@@ -438,12 +444,12 @@ hook_faccessat(int dirfd, const char* cpath, int mode) {
    auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved);
    switch(rstatus) {
        case gkfs::preload::RelativizeStatus::fd_unknown:
            return syscall_no_intercept_wrapper(SYS_faccessat, dirfd, cpath,
                                                mode);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_faccessat, dirfd, cpath, mode));

        case gkfs::preload::RelativizeStatus::external:
            return syscall_no_intercept_wrapper(SYS_faccessat, dirfd,
                                                resolved.c_str(), mode);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_faccessat, dirfd, resolved.c_str(), mode));

        case gkfs::preload::RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;
@@ -469,12 +475,12 @@ hook_faccessat2(int dirfd, const char* cpath, int mode, int flags) {
    auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved);
    switch(rstatus) {
        case gkfs::preload::RelativizeStatus::fd_unknown:
            return syscall_no_intercept_wrapper(SYS_faccessat2, dirfd, cpath,
                                                mode, flags);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_faccessat2, dirfd, cpath, mode, flags));

        case gkfs::preload::RelativizeStatus::external:
            return syscall_no_intercept_wrapper(SYS_faccessat2, dirfd,
                                                resolved.c_str(), mode, flags);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_faccessat2, dirfd, resolved.c_str(), mode, flags));

        case gkfs::preload::RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;
@@ -520,7 +526,8 @@ hook_truncate(const char* path, long length) {
    if(CTX->relativize_path(path, rel_path)) {
        return with_errno(gkfs::syscall::gkfs_truncate(rel_path, length));
    }
    return syscall_no_intercept_wrapper(SYS_truncate, rel_path.c_str(), length);
    return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
            SYS_truncate, rel_path.c_str(), length));
}

int
@@ -532,7 +539,8 @@ hook_ftruncate(unsigned int fd, unsigned long length) {
        auto path = CTX->file_map()->get(fd)->path();
        return with_errno(gkfs::syscall::gkfs_truncate(path, length));
    }
    return syscall_no_intercept_wrapper(SYS_ftruncate, fd, length);
    return gsl::narrow_cast<int>(
            syscall_no_intercept_wrapper(SYS_ftruncate, fd, length));
}

int
@@ -543,7 +551,7 @@ hook_dup(unsigned int fd) {
    if(CTX->file_map()->exist(fd)) {
        return with_errno(gkfs::syscall::gkfs_dup(fd));
    }
    return syscall_no_intercept_wrapper(SYS_dup, fd);
    return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(SYS_dup, fd));
}
#ifdef SYS_dup2
int
@@ -554,7 +562,8 @@ hook_dup2(unsigned int oldfd, unsigned int newfd) {
    if(CTX->file_map()->exist(oldfd)) {
        return with_errno(gkfs::syscall::gkfs_dup2(oldfd, newfd));
    }
    return syscall_no_intercept_wrapper(SYS_dup2, oldfd, newfd);
    return gsl::narrow_cast<int>(
            syscall_no_intercept_wrapper(SYS_dup2, oldfd, newfd));
}
#endif
int
@@ -569,10 +578,11 @@ hook_dup3(unsigned int oldfd, unsigned int newfd, int flags) {
        LOG(WARNING, "{}() Not supported", __func__);
        return -ENOTSUP;
    }
    return syscall_no_intercept_wrapper(SYS_dup3, oldfd, newfd, flags);
    return gsl::narrow_cast<int>(
            syscall_no_intercept_wrapper(SYS_dup3, oldfd, newfd, flags));
}
#ifdef SYS_getdents
int
long
hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) {

    LOG(DEBUG, "{}() called with fd: {}, dirp: {}, count: {}", __func__, fd,
@@ -585,7 +595,7 @@ hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) {
}
#endif

int
ssize_t
hook_getdents64(unsigned int fd, struct linux_dirent64* dirp,
                unsigned int count) {

@@ -609,12 +619,12 @@ hook_mkdirat(int dirfd, const char* cpath, mode_t mode) {
    auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved);
    switch(rstatus) {
        case gkfs::preload::RelativizeStatus::external:
            return syscall_no_intercept_wrapper(SYS_mkdirat, dirfd,
                                                resolved.c_str(), mode);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_mkdirat, dirfd, resolved.c_str(), mode));

        case gkfs::preload::RelativizeStatus::fd_unknown:
            return syscall_no_intercept_wrapper(SYS_mkdirat, dirfd, cpath,
                                                mode);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_mkdirat, dirfd, cpath, mode));

        case gkfs::preload::RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;
@@ -639,12 +649,12 @@ hook_fchmodat(int dirfd, const char* cpath, mode_t mode) {
    auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved);
    switch(rstatus) {
        case gkfs::preload::RelativizeStatus::fd_unknown:
            return syscall_no_intercept_wrapper(SYS_fchmodat, dirfd, cpath,
                                                mode);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_fchmodat, dirfd, cpath, mode));

        case gkfs::preload::RelativizeStatus::external:
            return syscall_no_intercept_wrapper(SYS_fchmodat, dirfd,
                                                resolved.c_str(), mode);
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                    SYS_fchmodat, dirfd, resolved.c_str(), mode));

        case gkfs::preload::RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;
@@ -668,7 +678,8 @@ hook_fchmod(unsigned int fd, mode_t mode) {
        LOG(WARNING, "{}() operation not supported", __func__);
        return -ENOTSUP;
    }
    return syscall_no_intercept_wrapper(SYS_fchmod, fd, mode);
    return gsl::narrow_cast<int>(
            syscall_no_intercept_wrapper(SYS_fchmod, fd, mode));
}

int
@@ -759,7 +770,7 @@ hook_getcwd(char* buf, unsigned long size) {
    return (CTX->cwd().size() + 1);
}

int
ssize_t
hook_readlinkat(int dirfd, const char* cpath, char* buf, int bufsiz) {

    LOG(DEBUG, "{}() called with dirfd: {}, path \"{}\", buf: {}, bufsize: {}",
@@ -796,7 +807,8 @@ hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) {
        arg);

    if(!CTX->file_map()->exist(fd)) {
        return syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg);
        return gsl::narrow_cast<int>(
                syscall_no_intercept_wrapper(SYS_fcntl, fd, cmd, arg));
    }
    int ret;
    switch(cmd) {
@@ -927,8 +939,8 @@ hook_renameat(int olddfd, const char* oldname, int newdfd, const char* newname,
            return -EINVAL;
    }

    return syscall_no_intercept_wrapper(SYS_renameat2, olddfd, oldpath_pass,
                                        newdfd, newpath_pass, flags);
    return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
            SYS_renameat2, olddfd, oldpath_pass, newdfd, newpath_pass, flags));
}

int
@@ -941,7 +953,8 @@ hook_statfs(const char* path, struct statfs* buf) {
    if(CTX->relativize_path(path, rel_path)) {
        return with_errno(gkfs::syscall::gkfs_statfs(buf));
    }
    return syscall_no_intercept_wrapper(SYS_statfs, rel_path.c_str(), buf);
    return gsl::narrow_cast<int>(
            syscall_no_intercept_wrapper(SYS_statfs, rel_path.c_str(), buf));
}

int
@@ -952,7 +965,8 @@ hook_fstatfs(unsigned int fd, struct statfs* buf) {
    if(CTX->file_map()->exist(fd)) {
        return with_errno(gkfs::syscall::gkfs_statfs(buf));
    }
    return syscall_no_intercept_wrapper(SYS_fstatfs, fd, buf);
    return gsl::narrow_cast<int>(
            syscall_no_intercept_wrapper(SYS_fstatfs, fd, buf));
}

/* The function should broadcast a flush message (pmem_persist i.e.) if the
@@ -964,10 +978,11 @@ hook_fsync(unsigned int fd) {
    if(CTX->file_map()->exist(fd)) {
        return with_errno(gkfs::syscall::gkfs_fsync(fd));
    }
    return syscall_no_intercept_wrapper(SYS_fsync, fd);

    return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(SYS_fsync, fd));
}

int
ssize_t
hook_getxattr(const char* path, const char* name, void* value, size_t size) {

    LOG(DEBUG, "{}() called with path '{}' name '{}' value '{}' size '{}'",
+3 −0
Changes for .gitmodules: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -25,3 +25,6 @@
[submodule "external/MessagePack"]
	path = external/MessagePack
	url = https://github.com/GekkoFS/MessagePackCPP.git
[submodule "external/GSL"]
	path = external/GSL
	url = https://github.com/microsoft/GSL
Loading
Loading