Commit 95e55b9e authored by sevenuz's avatar sevenuz
Browse files

open file map id generator fix for hybrid

parent 9ea982ba
Loading
Loading
Loading
Loading
Loading
+4 −47
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ OpenFile::OpenFile(const string& path, const int flags, FileType type)
    pos_ = 0; // If O_APPEND flag is used, it will be used before each write.
}

OpenFileMap::OpenFileMap() : fd_idx(10000), fd_validation_needed(false) {}
OpenFileMap::OpenFileMap() : fd_idx(1), fd_validation_needed(false) {}

const string&
OpenFile::path() const {
@@ -188,51 +188,8 @@ OpenFileMap::exist(const int fd) {

int
OpenFileMap::safe_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 been used to the int::max Once this limit is exceeded, we set
         * fd_idx back to 3 and begin anew. Only then, if a file was open for a
         * long time will we have to generate another index.
         *
         * This situation can only occur when all fd indices have been given
         * away once and we start again, in which case the fd_validation_needed
         * flag is set. fd_validation is set to false, if
         */
        if(fd_validation_needed) {
            while(exist(fd)) {
                fd = generate_fd_idx();
            }
        }
    } else {
        // Return a virtual fd from 10000, but avoid doing all the FD movements
        if(CTX->range_fd()) {
            fd = generate_fd_idx();
            if(fd_validation_needed) {
                while(exist(fd)) {
                    fd = generate_fd_idx();
                }
            }
            return fd;
        }

        fd = syscall_no_intercept(SYS_openat, AT_FDCWD, "/dev/null", O_RDWR,
                                  S_IRUSR | S_IWUSR);
        if(fd >= 0 && fd < 3) {
            // We want to avoid using standard file descriptors for internal use
            // as this can cause issues with applications that expect them later
            // (e.g. ls)
            int new_fd = syscall_no_intercept(SYS_fcntl, fd, F_DUPFD, 3);
            if(new_fd >= 0) {
                syscall_no_intercept(SYS_close, fd);
                fd = new_fd;
            }
        }
    }
    return fd;
    std::lock_guard<std::mutex> inode_lock(fd_idx_mutex);
    return fd_idx++;
}

int
@@ -272,7 +229,7 @@ OpenFileMap::remove(const int fd) {
    if(!CTX->protect_fds()) {
        if(!CTX->range_fd()) {
            // We close the dev null fd
            close(fd);
            // close(fd);
            return true;
        }
    }