Commit 1d22618b authored by Marc Vef's avatar Marc Vef
Browse files

Adding interception of fallocate and fadvise64 syscall. Not supported by GekkoFS at this time

parent 2ae7ca40
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -205,6 +205,12 @@ hook_fsync(unsigned int fd);
int
hook_getxattr(const char* path, const char* name, void* value, size_t size);

int
hook_fallocate(int fd, int mode, off_t offset, off_t len);

int
hook_fadvise64(int fd, off_t offset, off_t len, int advice);

} // namespace gkfs::hook

#endif
+24 −0
Original line number Diff line number Diff line
@@ -983,4 +983,28 @@ hook_getxattr(const char* path, const char* name, void* value, size_t size) {
    return syscall_no_intercept_wrapper(SYS_getxattr, path, name, value, size);
}


int
hook_fallocate(int fd, int mode, off_t offset, off_t len) {
    LOG(DEBUG, "{}() called with fd '{}' mode '{}' offset '{}' len '{}'",
        __func__, fd, mode, offset, len);

    if(CTX->file_map()->exist(fd)) {
        return -ENOTSUP;
    }
    return syscall_no_intercept_wrapper(SYS_fallocate, fd, mode, offset, len);
}

int
hook_fadvise64(int fd, off_t offset, off_t len, int advice) {
    LOG(DEBUG, "{}() called with fd '{}' offset '{}' len '{}' advice '{}'",
        __func__, fd, offset, len, advice);

    if(CTX->file_map()->exist(fd)) {
        return -ENOTSUP;
    }
    return syscall_no_intercept_wrapper(SYS_fadvise64, fd, offset, len, advice);
}


} // namespace gkfs::hook
+12 −0
Original line number Diff line number Diff line
@@ -785,6 +785,18 @@ hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4,
                    reinterpret_cast<void*>(arg2), static_cast<size_t>(arg4));
            break;

        case SYS_fallocate:
            *result = gkfs::hook::hook_fallocate(
                    static_cast<int>(arg0), static_cast<int>(arg1),
                    static_cast<off_t>(arg2), static_cast<off_t>(arg3));
            break;

        case SYS_fadvise64:
            *result = gkfs::hook::hook_fadvise64(
                    static_cast<int>(arg0), static_cast<off_t>(arg1),
                    static_cast<off_t>(arg2), static_cast<int>(arg4));
            break;

        default:
            // ignore any other syscalls, i.e.: pass them on to the kernel
            // (syscalls forwarded to the kernel that return are logged in