Commit 0f007003 authored by Ramon Nou's avatar Ramon Nou Committed by Ramon Nou
Browse files

Trying fd workaround

parent 6f4a461c
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ private:
    std::bitset<MAX_USER_FDS> protected_fds_;
    std::string hostname;
    int replicas_;
    bool protect_fds_{false};

    std::shared_ptr<gkfs::messagepack::ClientMetrics> write_metrics_;
    std::shared_ptr<gkfs::messagepack::ClientMetrics> read_metrics_;
@@ -301,6 +302,10 @@ public:
    int
    get_replicas();

    bool protect_fds() const;

    void protect_fds(bool protect);

    const std::shared_ptr<gkfs::messagepack::ClientMetrics>
    write_metrics();

+9 −1
Original line number Diff line number Diff line
@@ -132,7 +132,9 @@ OpenFileMap::exist(const int fd) {

int
OpenFileMap::safe_generate_fd_idx_() {
    auto fd = generate_fd_idx();
    int fd = 0;
    if (CTX->protect_fds()) {
    fd = generate_fd_idx();
    /*
     * Check if fd is still in use and generate another if yes
     * Note that this can only happen once the all fd indices within the int has
@@ -149,6 +151,12 @@ OpenFileMap::safe_generate_fd_idx_() {
            fd = generate_fd_idx();
        }
    }
    }
    else {
        fd = syscall_no_intercept(
                    SYS_open, "/dev/null",
                    O_RDWR, S_IRUSR | S_IWUSR);
    }
    return fd;
}

+5 −2
Original line number Diff line number Diff line
@@ -364,7 +364,9 @@ init_preload() {
    // To prevent this for our internal
    // initialization code, we forcefully occupy the user fd range to force
    // such modules to create fds in our private range.
    if (CTX->protect_fds()) {
        CTX->protect_user_fds();
    }

    log_prog_name();
    gkfs::path::init_cwd();
@@ -374,6 +376,7 @@ init_preload() {
    gkfs::preload::init_environment();
    CTX->enable_interception();

    if(CTX->protect_fds())
        CTX->unprotect_user_fds();

    auto forwarding_map_file = gkfs::env::get_var(
+11 −1
Original line number Diff line number Diff line
@@ -469,11 +469,19 @@ PreloadContext::interception_enabled() const {
    return interception_enabled_;
}

bool PreloadContext::protect_fds() const {
    return protect_fds_;
};

void PreloadContext::protect_fds(bool protect) {
    protect_fds_ = protect;
}

int
PreloadContext::register_internal_fd(int fd) {

    assert(fd >= 0);

    if (!protect_fds()) return fd;
    if(!internal_fds_must_relocate_) {
        LOG(DEBUG, "registering fd {} as internal (no relocation needed)", fd);
        assert(fd >= MIN_INTERNAL_FD);
@@ -541,6 +549,8 @@ PreloadContext::register_internal_fd(int fd) {
void
PreloadContext::unregister_internal_fd(int fd) {

    if (!protect_fds()) return;
    
    LOG(DEBUG, "unregistering internal fd {} >= {} -> {}'", fd, MIN_INTERNAL_FD,
        fd >= MIN_INTERNAL_FD);