Commit 6e597ac2 authored by sevenuz's avatar sevenuz Committed by sevenuz
Browse files

hybrid: optional data-only interception (LIBGKFS_DATA_ONLY)

Second split-point ablation switch. With LIBGKFS_DATA_ONLY=1 path
resolution reports every path as external, so all path-based calls (open,
stat, mkdir, unlink, rename, readdir, chdir, ...) are served by the kernel
through the FUSE mount. Only hook_openat still resolves the path of a regular
file it opens through FUSE and registers the kernel fd, so data I/O on it
(read/write/pread/pwrite/lseek/fstat) stays intercepted. Directories are
plain kernel objects. This models DAOS libioil. Default off.

Limitation: the client's cwd is not tracked for chdir into the mount, so
relative paths are resolved against the cwd at startup; IO500 uses absolute
paths.
parent cd31f8d2
Loading
Loading
Loading
Loading
+4
Changes for include/client/env.hpp: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -99,6 +99,10 @@ static constexpr auto ENABLE_FORK = ADD_PREFIX("ENABLE_FORK");
// data I/O on that fd stays intercepted. Models DAOS libpil4dfs
// D_IL_COMPATIBLE=1 (split-point ablation). Default off.
static constexpr auto OPEN_VIA_FUSE = ADD_PREFIX("OPEN_VIA_FUSE");
// hybrid only: data-only interception (models DAOS libioil). All path-based
// calls (open, stat, mkdir, unlink, rename, readdir, ...) go to the FUSE mount;
// only data I/O on files opened in the mount stays intercepted. Default off.
static constexpr auto DATA_ONLY = ADD_PREFIX("DATA_ONLY");

} // namespace gkfs::env

+7
Changes for include/client/preload_context.hpp: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -76,6 +76,13 @@ class WriteSizeCache;
} // namespace cache

namespace preload {

// Data-only interception (LIBGKFS_DATA_ONLY=1, split-point ablation): path
// resolution reports every path as external, except while hook_openat
// resolves the path of a file it opens through FUSE (resolve_for_open).
bool
metadata_via_fuse();
extern thread_local bool resolve_for_open;
/*
 * Client file system config
 */
+10 −2
Changes for src/client/hooks.cpp: 10 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -230,7 +230,10 @@ hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) {
        __func__, dirfd, cpath, flags, mode);

    std::string resolved;
    const bool data_only = gkfs::preload::metadata_via_fuse();
    gkfs::preload::resolve_for_open = data_only;
    auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved);
    gkfs::preload::resolve_for_open = false;
    switch(rstatus) {
        case gkfs::preload::RelativizeStatus::fd_unknown:
            return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
@@ -244,6 +247,11 @@ hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) {
            return -ENOTDIR;

        case gkfs::preload::RelativizeStatus::internal: {
            if(data_only && (flags & O_DIRECTORY)) {
                // data-only: directories are plain kernel (FUSE) objects
                return gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                        SYS_openat, dirfd, cpath, flags, mode));
            }
            if(flags & O_DIRECTORY) {
                // Caller explicitly requests a directory: route via FUSE.
                // No metadata RPC needed — flag is authoritative.
@@ -259,7 +267,7 @@ hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) {
                        fd, std::make_shared<gkfs::filemap::OpenDir>(resolved));
                return fd;
            }
            if(open_via_fuse()) {
            if(open_via_fuse() || data_only) {
                // Split-point ablation: create/lookup/truncate through FUSE.
                int kfd = gsl::narrow_cast<int>(syscall_no_intercept_wrapper(
                        SYS_openat, dirfd, cpath, flags, mode));
@@ -278,7 +286,7 @@ hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) {
                                         resolved, flags & ~(O_CREAT | O_EXCL |
                                                             O_TRUNC)));
                    kernel_backed_add(kfd);
                } else if(S_ISDIR(st.st_mode)) {
                } else if(S_ISDIR(st.st_mode) && !data_only) {
                    CTX->file_map()->add(
                            kfd, std::make_shared<gkfs::filemap::OpenDir>(
                                         resolved));
+24
Changes for src/client/preload_context.cpp: 24 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@
#include <cassert>
#include <filesystem>
#include <utility>
#include <cstdlib>


#include <libsyscall_intercept_hook_point.h>
@@ -306,6 +307,17 @@ PreloadContext::auto_sm(bool auto_sm) {
    PreloadContext::auto_sm_ = auto_sm;
}

thread_local bool resolve_for_open = false;

bool
metadata_via_fuse() {
    static const bool enabled = [] {
        const char* v = std::getenv(gkfs::env::DATA_ONLY);
        return v != nullptr && v[0] != '\0' && v[0] != '0';
    }();
    return enabled;
}

RelativizeStatus
PreloadContext::relativize_fd_path(int dirfd, const char* raw_path,
                                   std::string& relative_path, int flags,
@@ -317,6 +329,13 @@ PreloadContext::relativize_fd_path(int dirfd, const char* raw_path,
    // If we run the constructor we also already setup the mountdir
    assert(!mountdir_.empty());

    if(metadata_via_fuse() && !resolve_for_open) {
        // hooks pass relative_path to the kernel for external paths; the
        // kernel resolves raw_path against dirfd itself
        relative_path = raw_path != nullptr ? raw_path : "";
        return RelativizeStatus::external;
    }

    // Handle nullptr path: this is a valid POSIX scenario when AT_EMPTY_PATH is
    // set (e.g. statx/openat on a bare fd). Resolve dirfd to determine scope:
    //  - GekkoFS fd  → return its stored path as internal
@@ -414,6 +433,11 @@ PreloadContext::relativize_path(const char* raw_path,
    // We assume raw path is valid
    assert(raw_path != nullptr);

    if(metadata_via_fuse() && !resolve_for_open) {
        relative_path = raw_path != nullptr ? raw_path : "";
        return false;
    }

    std::string path;

    if(raw_path != nullptr) {