Verified Commit 44e70e78 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

deprecated *stat64 functions family

According to the glibc [1] the stat64 function family would be called only
on 32-bit machine.

To be sure we still intercept the function, but we now throw a NOTSUP
error.

In this way we can drop the adafs_stat64 function and implement just the
logic to populate the `struct stat`.

[1]: https://github.molgen.mpg.de/git-mirror/glibc/blob/20003c49884422da7ffbc459cdeee768a6fee07b/sysdeps/unix/sysv/linux/generic/xstat.c#L46
parent f0eeebcd
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -62,11 +62,8 @@ extern hg_id_t rpc_get_dirents_id;

bool is_fs_path(const char* path);

// TODO template these two suckers
int db_val_to_stat(std::string path, std::string db_val, struct stat& attr);

int db_val_to_stat64(std::string path, std::string db_val, struct stat64& attr);

int get_daemon_pid();

bool read_system_hostfile();
+0 −10
Original line number Diff line number Diff line
@@ -146,7 +146,6 @@ int adafs_access(const std::string& path, const int mask) {
#endif
}

// TODO combine adafs_stat and adafs_stat64
int adafs_stat(const string& path, struct stat* buf) {
    init_ld_env_if_needed();
    string attr = ""s;
@@ -156,15 +155,6 @@ int adafs_stat(const string& path, struct stat* buf) {
    return err;
}

int adafs_stat64(const string& path, struct stat64* buf) {
    init_ld_env_if_needed();
    string attr = ""s;
    auto err = rpc_send_stat(path, attr);
    if (err == 0)
        db_val_to_stat64(path, attr, *buf);
    return err;
}

int adafs_statfs(const string& path, struct statfs* adafs_buf, struct statfs& realfs_buf) {
    init_ld_env_if_needed();
    // Check that file path exists
+16 −21
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

using namespace std;

void inline notsup_error_32_bit_func(const char* func = __builtin_FUNCTION()) {
    CTX->log()->error("{}() is NOT SUPPORTED. According to glibc, this function should be called only on 32-bit machine", func);
}

int open(const char* path, int flags, ...) {
    init_passthrough_if_needed();

@@ -604,11 +608,9 @@ int __xstat(int ver, const char* path, struct stat* buf) __THROW {
int __xstat64(int ver, const char* path, struct stat64* buf) __THROW {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called with path {}", __func__, path);
        std::string rel_path(path);
        if (CTX->relativize_path(rel_path)) {
            return adafs_stat64(rel_path, buf);
        }
        notsup_error_32_bit_func();
        errno = ENOTSUP;
        return -1;
    }
    return (reinterpret_cast<decltype(&__xstat64)>(libc___xstat64))(ver, path, buf);
}
@@ -668,24 +670,19 @@ passthrough:
int __fxstatat64(int ver, int dirfd, const char * path, struct stat64 * buf, int flags) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called with path '{}'", __func__, path);
        std::string rel_path(path);
        if (CTX->relativize_path(rel_path)) {
            return adafs_stat64(rel_path, buf);
        }
        notsup_error_32_bit_func();
        errno = ENOTSUP;
        return -1;
    }
    return (reinterpret_cast<decltype(&__fxstatat64)>(libc___fxstatat64))(ver, dirfd, path, buf, flags);

}

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 (CTX->file_map()->exist(fd)) {
            auto path = CTX->file_map()->get(fd)->path();
            return adafs_stat64(path, buf);
        }
        notsup_error_32_bit_func();
        errno = ENOTSUP;
        return -1;
    }
    return (reinterpret_cast<decltype(&__fxstat64)>(libc___fxstat64))(ver, fd, buf);
}
@@ -705,11 +702,9 @@ int __lxstat(int ver, const char* path, struct stat* buf) __THROW {
int __lxstat64(int ver, const char* path, struct stat64* buf) __THROW {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called with path {}", __func__, path);
        std::string rel_path(path);
        if (CTX->relativize_path(rel_path)) {
            return adafs_stat64(rel_path, buf);
        }
        notsup_error_32_bit_func();
        errno = ENOTSUP;
        return -1;
    }
    return (reinterpret_cast<decltype(&__lxstat64)>(libc___lxstat64))(ver, path, buf);
}
+0 −81
Original line number Diff line number Diff line
@@ -110,87 +110,6 @@ int db_val_to_stat(const std::string path, std::string db_val, struct stat& attr
    return 0;
}

/**
 * Converts the dentry db value into a stat64 struct, which is needed by Linux
 * @param path
 * @param db_val
 * @param attr
 * @return
 */
int db_val_to_stat64(const std::string path, std::string db_val, struct stat64& attr) {

    auto pos = db_val.find(dentry_val_delim);
    if (pos == std::string::npos) { // no delimiter found => no metadata enabled. fill with dummy values
        attr.st_ino = std::hash<std::string>{}(path);
        attr.st_mode = static_cast<unsigned int>(stoul(db_val));
        attr.st_nlink = 1;
        attr.st_uid = CTX->fs_conf()->uid;
        attr.st_gid = CTX->fs_conf()->gid;
        attr.st_size = 0;
        attr.st_blksize = BLOCKSIZE;
        attr.st_blocks = 0;
        attr.st_atim.tv_sec = 0;
        attr.st_mtim.tv_sec = 0;
        attr.st_ctim.tv_sec = 0;
        return 0;
    }
    // some metadata is enabled: mode is always there
    attr.st_mode = static_cast<unsigned int>(stoul(db_val.substr(0, pos)));
    db_val.erase(0, pos + 1);
    // size is also there XXX
    pos = db_val.find(dentry_val_delim);
    if (pos != std::string::npos) {  // delimiter found. more metadata is coming
        attr.st_size = stol(db_val.substr(0, pos));
        db_val.erase(0, pos + 1);
    } else {
        attr.st_size = stol(db_val);
    }
    // The order is important. don't change.
    if (CTX->fs_conf()->atime_state) {
        pos = db_val.find(dentry_val_delim);
        attr.st_atim.tv_sec = static_cast<time_t>(stol(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
    }
    if (CTX->fs_conf()->mtime_state) {
        pos = db_val.find(dentry_val_delim);
        attr.st_mtim.tv_sec = static_cast<time_t>(stol(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
    }
    if (CTX->fs_conf()->ctime_state) {
        pos = db_val.find(dentry_val_delim);
        attr.st_ctim.tv_sec = static_cast<time_t>(stol(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
    }
    if (CTX->fs_conf()->uid_state) {
        pos = db_val.find(dentry_val_delim);
        attr.st_uid = static_cast<uid_t>(stoul(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
    } else {
        attr.st_uid = CTX->fs_conf()->gid;
    }
    if (CTX->fs_conf()->gid_state) {
        pos = db_val.find(dentry_val_delim);
        attr.st_gid = static_cast<uid_t>(stoul(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
    } else {
        attr.st_gid = CTX->fs_conf()->gid;
    }
    if (CTX->fs_conf()->inode_no_state) {
        pos = db_val.find(dentry_val_delim);
        attr.st_ino = static_cast<ino_t>(stoul(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
    }
    if (CTX->fs_conf()->link_cnt_state) {
        pos = db_val.find(dentry_val_delim);
        attr.st_nlink = static_cast<nlink_t>(stoul(db_val.substr(0, pos)));
        db_val.erase(0, pos + 1);
    }
    if (CTX->fs_conf()->blocks_state) { // last one will not encounter a delimiter anymore
        attr.st_blocks = static_cast<blkcnt_t>(stoul(db_val));
    }
    return 0;
}

/**
 * @return daemon pid. If not running @return -1.
 * Loads set deamon mountdir set in daemon.pid file