Unverified Commit ea945910 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

avoids checks on environment initialization

parent 1963eee8
Loading
Loading
Loading
Loading
+0 −19
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
using namespace std;

int adafs_open(const std::string& path, mode_t mode, int flags) {
    init_ld_env_if_needed();

    if(flags & O_PATH){
        CTX->log()->error("{}() `O_PATH` flag is not supported", __func__);
@@ -112,7 +111,6 @@ int adafs_open(const std::string& path, mode_t mode, int flags) {
}

int adafs_mk_node(const std::string& path, mode_t mode) {
    init_ld_env_if_needed();

    //file type must be set
    switch (mode & S_IFMT) {
@@ -156,7 +154,6 @@ int adafs_mk_node(const std::string& path, mode_t mode) {
 * @return
 */
int adafs_rm_node(const std::string& path) {
    init_ld_env_if_needed();
    auto md = adafs_metadata(path);
    if (!md) {
        return -1;
@@ -166,7 +163,6 @@ int adafs_rm_node(const std::string& path) {
}

int adafs_access(const std::string& path, const int mask, bool follow_links) {
    init_ld_env_if_needed();
    auto md = adafs_metadata(path, follow_links);
    if (!md) {
        errno = ENOENT;
@@ -176,7 +172,6 @@ int adafs_access(const std::string& path, const int mask, bool follow_links) {
}

int adafs_stat(const string& path, struct stat* buf, bool follow_links) {
    init_ld_env_if_needed();
    auto md = adafs_metadata(path, follow_links);
    if (!md) {
        return -1;
@@ -207,7 +202,6 @@ std::shared_ptr<Metadata> adafs_metadata(const string& path, bool follow_links)
}

int adafs_statfs(struct statfs* buf) {
    init_ld_env_if_needed();
    CTX->log()->trace("{}() called", __func__);
    auto blk_stat = rpc_send::chunk_stat();
    buf->f_type = 0;
@@ -244,12 +238,10 @@ int adafs_statvfs(struct statvfs* buf) {
}

off64_t adafs_lseek(int fd, off64_t offset, int whence) {
    init_ld_env_if_needed();
    return adafs_lseek(CTX->file_map()->get(fd), offset, whence);
}

off64_t adafs_lseek(shared_ptr<OpenFile> adafs_fd, off64_t offset, int whence) {
    init_ld_env_if_needed();
    switch (whence) {
        case SEEK_SET:
            adafs_fd->pos(offset);
@@ -311,7 +303,6 @@ int adafs_truncate(const std::string& path, off_t length) {
     * adafs_trunc_data, some more data could have been added to the file and the
     * length increased.
     */
    init_ld_env_if_needed();
    if(length < 0) {
        CTX->log()->debug("{}() length is negative: {}", __func__, length);
        errno = EINVAL;
@@ -341,7 +332,6 @@ int adafs_dup2(const int oldfd, const int newfd) {
}

ssize_t adafs_pwrite(std::shared_ptr<OpenFile> file, const char * buf, size_t count, off64_t offset) {
    init_ld_env_if_needed();
    if (file->type() != FileType::regular) {
        assert(file->type() == FileType::directory);
        CTX->log()->warn("{}() cannot read from directory", __func__);
@@ -367,7 +357,6 @@ ssize_t adafs_pwrite(std::shared_ptr<OpenFile> file, const char * buf, size_t co
}

ssize_t adafs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset) {
    init_ld_env_if_needed();
    auto file = CTX->file_map()->get(fd);
    return adafs_pwrite(file, reinterpret_cast<const char*>(buf), count, offset);
}
@@ -391,7 +380,6 @@ ssize_t adafs_write(int fd, const void * buf, size_t count) {
}

ssize_t adafs_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset) {
    init_ld_env_if_needed();
    CTX->log()->trace("{}() called with fd {}, op num {}, offset {}",
                      __func__, fd, iovcnt, offset);

@@ -438,7 +426,6 @@ ssize_t adafs_writev(int fd, const struct iovec * iov, int iovcnt) {
}

ssize_t adafs_pread(std::shared_ptr<OpenFile> file, char * buf, size_t count, off64_t offset) {
    init_ld_env_if_needed();
    if (file->type() != FileType::regular) {
        assert(file->type() == FileType::directory);
        CTX->log()->warn("{}() cannot read from directory", __func__);
@@ -459,7 +446,6 @@ ssize_t adafs_pread(std::shared_ptr<OpenFile> file, char * buf, size_t count, of
}

ssize_t adafs_read(int fd, void* buf, size_t count) {
    init_ld_env_if_needed();
    auto adafs_fd = CTX->file_map()->get(fd);
    auto pos = adafs_fd->pos(); //retrieve the current offset
    auto ret = adafs_pread(adafs_fd, reinterpret_cast<char*>(buf), count, pos);
@@ -471,13 +457,11 @@ ssize_t adafs_read(int fd, void* buf, size_t count) {
}

ssize_t adafs_pread_ws(int fd, void* buf, size_t count, off64_t offset) {
    init_ld_env_if_needed();
    auto adafs_fd = CTX->file_map()->get(fd);
    return adafs_pread(adafs_fd, reinterpret_cast<char*>(buf), count, offset);
}

int adafs_opendir(const std::string& path) {
    init_ld_env_if_needed();

    auto md = adafs_metadata(path);
    if (!md) {
@@ -495,8 +479,6 @@ int adafs_opendir(const std::string& path) {
}

int adafs_rmdir(const std::string& path) {
    init_ld_env_if_needed();

    auto md = adafs_metadata(path);
    if (!md) {
        CTX->log()->debug("{}() path does not exists: '{}'", __func__, path);
@@ -519,7 +501,6 @@ int adafs_rmdir(const std::string& path) {
}

struct dirent * adafs_readdir(int fd){
    init_ld_env_if_needed();
    CTX->log()->trace("{}() called on fd: {}", __func__, fd);
    auto open_file = CTX->file_map()->get(fd);
    assert(open_file != nullptr);