Verified Commit cfda3081 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Remove the auxiliary loaded check

Since we introduced the `initialized` flag in the preload context, it is
not needed anymore to check for ld_is_aux_loaded flag.
In fact ld_is_aux_loaded is true if and only if the `initialized` flag
is true.
parent 99805139
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -8,8 +8,6 @@

#define CTX PreloadContext::getInstance()

bool ld_is_aux_loaded();

void init_ld_env_if_needed();

void init_preload() __attribute__((constructor));
+35 −37
Original line number Diff line number Diff line
@@ -140,13 +140,11 @@ int rmdir(const char* path) __THROW {

int close(int fd) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
    if(CTX->initialized() && CTX->file_map()->exist(fd)) {
        // No call to the daemon is required
        CTX->file_map()->remove(fd);
        return 0;
    }
    }
    return (reinterpret_cast<decltype(&close)>(libc_close))(fd);
}

@@ -201,7 +199,7 @@ int fstat(int fd, struct stat* buf) __THROW {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called with fd {}", __func__, fd);
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        if (CTX->file_map()->exist(fd)) {
            auto path = CTX->file_map()->get(fd)->path();
            return adafs_stat(path, buf);
        }
@@ -250,7 +248,7 @@ int __fxstat(int ver, int fd, struct stat* buf) __THROW {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called with fd {}", __func__, fd);
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        if (CTX->file_map()->exist(fd)) {
            auto path = CTX->file_map()->get(fd)->path();
            return adafs_stat(path, buf);
        }
@@ -262,7 +260,7 @@ int __fxstat64(int ver, int fd, struct stat64* buf) __THROW {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called with fd {}", __func__, fd);
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        if (CTX->file_map()->exist(fd)) {
            auto path = CTX->file_map()->get(fd)->path();
            return adafs_stat64(path, buf);
        }
@@ -316,7 +314,7 @@ int fstatfs(int fd, struct statfs* buf) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called with fd {}", __func__, fd);
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        if (CTX->file_map()->exist(fd)) {
            auto adafs_fd = CTX->file_map()->get(fd);
            // get information of the underlying fs
            // Note, we explicitely call the real glibc statfs function to not intercept it again on the mountdir path
@@ -337,8 +335,8 @@ int puts(const char* str) {
ssize_t write(int fd, const void* buf, size_t count) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        CTX->log()->trace("{}() called with fd {}", __func__, fd);
        if (CTX->file_map()->exist(fd)) {
            auto adafs_fd = CTX->file_map()->get(fd);
            auto pos = adafs_fd->pos(); // retrieve the current offset
            if (adafs_fd->get_flag(OpenFile_flags::append))
@@ -357,8 +355,8 @@ ssize_t write(int fd, const void* buf, size_t count) {
ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        CTX->log()->trace("{}() called with fd {}", __func__, fd);
        if (CTX->file_map()->exist(fd)) {
            return adafs_pwrite_ws(fd, buf, count, offset);
        }
    }
@@ -368,8 +366,8 @@ ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) {
ssize_t pwrite64(int fd, const void* buf, size_t count, __off64_t offset) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        CTX->log()->trace("{}() called with fd {}", __func__, fd);
        if (CTX->file_map()->exist(fd)) {
            return adafs_pwrite_ws(fd, buf, count, offset);
        }
    }
@@ -379,10 +377,10 @@ ssize_t pwrite64(int fd, const void* buf, size_t count, __off64_t offset) {
ssize_t read(int fd, void* buf, size_t count) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        CTX->log()->trace("{}() called with fd {}", __func__, fd);
        if (CTX->file_map()->exist(fd)) {
            auto adafs_fd = CTX->file_map()->get(fd);
            auto pos = adafs_fd->pos(); //retrieve the current offset
            CTX->log()->trace("{}() called with fd {}", __func__, fd);
            auto ret = adafs_pread_ws(fd, buf, count, pos);
            // Update offset in file descriptor in the file map
            if (ret > 0) {
@@ -397,8 +395,8 @@ ssize_t read(int fd, void* buf, size_t count) {
ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        CTX->log()->trace("{}() called with fd {}", __func__, fd);
        if (CTX->file_map()->exist(fd)) {
            return adafs_pread_ws(fd, buf, count, offset);
        }
    }
@@ -408,8 +406,8 @@ ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
ssize_t pread64(int fd, void* buf, size_t count, __off64_t offset) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        CTX->log()->trace("{}() called with fd {}", __func__, fd);
        if (CTX->file_map()->exist(fd)) {
            return adafs_pread_ws(fd, buf, count, offset);
        }
    }
@@ -419,8 +417,8 @@ ssize_t pread64(int fd, void* buf, size_t count, __off64_t offset) {
off_t lseek(int fd, off_t offset, int whence) __THROW {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        CTX->log()->trace("{}() called with path {} with mode {}", __func__, fd, offset, whence);
        if (CTX->file_map()->exist(fd)) {
            auto off_ret = adafs_lseek(fd, static_cast<off64_t>(offset), whence);
            if (off_ret > std::numeric_limits<off_t>::max()) {
                errno = EOVERFLOW;
@@ -437,8 +435,8 @@ off_t lseek(int fd, off_t offset, int whence) __THROW {
off64_t lseek64(int fd, off64_t offset, int whence) __THROW {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        CTX->log()->trace("{}() called with path {} with mode {}", __func__, fd, offset, whence);
        if (CTX->file_map()->exist(fd)) {
            return adafs_lseek(fd, offset, whence);
        }
    }
@@ -448,8 +446,8 @@ off64_t lseek64(int fd, off64_t offset, int whence) __THROW {
int fsync(int fd) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        CTX->log()->trace("{}() called with fd {} path {}", __func__, fd, CTX->file_map()->get(fd)->path());
        if (CTX->file_map()->exist(fd)) {
            return 0; // This is a noop for us atm. fsync is called implicitly because each chunk is closed after access
        }
    }
@@ -459,8 +457,8 @@ int fsync(int fd) {
int fdatasync(int fd) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        CTX->log()->trace("{}() called with fd {} path {}", __func__, fd, CTX->file_map()->get(fd)->path());
        if (CTX->file_map()->exist(fd)) {
            return 0; // This is a noop for us atm. fsync is called implicitly because each chunk is closed after access
        }
    }
@@ -480,8 +478,8 @@ int ftruncate(int fd, off_t length) __THROW {
int dup(int oldfd) __THROW {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(oldfd)) {
        CTX->log()->trace("{}() called with oldfd {}", __func__, oldfd);
        if (CTX->file_map()->exist(oldfd)) {
            return adafs_dup(oldfd);
        }
    }
@@ -491,8 +489,8 @@ int dup(int oldfd) __THROW {
int dup2(int oldfd, int newfd) __THROW {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(oldfd)) {
        CTX->log()->trace("{}() called with oldfd {} newfd {}", __func__, oldfd, newfd);
        if (CTX->file_map()->exist(oldfd)) {
            return adafs_dup2(oldfd, newfd);
        }
    }
@@ -502,7 +500,7 @@ int dup2(int oldfd, int newfd) __THROW {
int dup3(int oldfd, int newfd, int flags) __THROW {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        if (ld_is_aux_loaded() && CTX->file_map()->exist(oldfd)) {
        if (CTX->file_map()->exist(oldfd)) {
            // TODO implement O_CLOEXEC flag first which is used with fcntl(2)
            // It is in glibc since kernel 2.9. So maybe not that important :)
            CTX->log()->error("{}() Not implemented.", __func__);
@@ -549,7 +547,7 @@ struct dirent* intcp_readdir(DIR* dirp){
            return nullptr;
        }
        auto fd = dirp_to_fd(dirp);
        if(ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        if(CTX->file_map()->exist(fd)) {
            return adafs_readdir(fd);
        }
    }
@@ -564,7 +562,7 @@ int intcp_closedir(DIR* dirp) {
            return -1;
        }
        auto fd = dirp_to_fd(dirp);
        if (ld_is_aux_loaded() && CTX->file_map()->exist(fd)) {
        if (CTX->file_map()->exist(fd)) {
            // No call to the daemon is required
            CTX->file_map()->remove(fd);
            return 0;
+0 −11
Original line number Diff line number Diff line
@@ -12,8 +12,6 @@ enum class Margo_mode {
    RPC, IPC
};

// atomic bool to check if auxiliary files from daemon are loaded
std::atomic<bool> is_aux_loaded_(false);
// thread to initialize the whole margo shazaam only once per process
static pthread_once_t init_env_thread = PTHREAD_ONCE_INIT;

@@ -212,14 +210,6 @@ bool init_margo_client(Margo_mode mode, const string na_plugin) {
    return true;
}

/**
 * Returns atomic bool, if Margo is running
 * @return
 */
bool ld_is_aux_loaded() {
    return is_aux_loaded_;
}

/**
 * This function is only called in the preload constructor and initializes Argobots and Margo clients
 */
@@ -289,7 +279,6 @@ void init_preload() {
        exit(EXIT_FAILURE);
    } else {
        CTX->log()->info("{}() mountdir \"{}\" loaded", __func__, CTX->mountdir());
        is_aux_loaded_ = true;
    }
    CTX->initialized(true);
    CTX->log()->debug("{}() exit", __func__);