Verified Commit 7682954f authored by Ramon Nou's avatar Ramon Nou Committed by Marc Vef
Browse files

Add Rename tests

Comp errors

Rename Steps 2

Rename test passed
parent 7fec3e2f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ gkfs:integration:
  needs: ['gkfs']
  parallel:
    matrix:
      - SUBTEST: [ data, status, syscalls, directories, operations, position, shell ]
      - SUBTEST: [ data, status, syscalls, directories, operations, position, shell, rename ]

  script:
    ## run tests
+6 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ struct linux_dirent64;
namespace gkfs::syscall {

int
gkfs_open(const std::string& path, mode_t mode, int flags);
gkfs_open(const std::string& path, mode_t mode, int flags, bool rename = false);

int
gkfs_create(const std::string& path, mode_t mode);
@@ -149,6 +149,11 @@ gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp,
int
gkfs_rmdir(const std::string& path);


int
gkfs_rename(const std::string& old_path_resolved,
            const std::string& new_path_resolved);

} // namespace gkfs::syscall

// gkfs_getsingleserverdir is using extern "C" to demangle it for C usage
+4 −0
Original line number Diff line number Diff line
@@ -55,6 +55,10 @@ forward_create(const std::string& path, mode_t mode);
int
forward_stat(const std::string& path, std::string& attr);

int
forward_rename(const std::string& path, const std::string& path2,
               const gkfs::metadata::Metadata& md);

int
forward_remove(const std::string& path);

+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ constexpr auto use_atime = false;
constexpr auto use_ctime = false;
constexpr auto use_mtime = false;
constexpr auto use_link_cnt = false;
constexpr auto use_blocks = false;
constexpr auto use_blocks = true;
/*
 * If true, all chunks on the same host are removed during a metadata remove
 * rpc. This is a technical optimization that reduces the number of RPCs for
+54 −3
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ namespace gkfs::syscall {
 * @return 0 on success, -1 on failure
 */
int
gkfs_open(const std::string& path, mode_t mode, int flags) {
gkfs_open(const std::string& path, mode_t mode, int flags, bool rename) {

    if(flags & O_PATH) {
        LOG(ERROR, "`O_PATH` flag is not supported");
@@ -172,6 +172,12 @@ gkfs_open(const std::string& path, mode_t mode, int flags) {
                    return -1;
                }
                md = *md_;

                if(rename == false && md.blocks() == -1) {
                    LOG(ERROR, "File is renamed '{}': '{}' - rename: {}", path,
                        rename);
                    return -1;
                }
            } else {
                LOG(ERROR, "Error creating file: '{}'", strerror(errno));
                return -1;
@@ -202,8 +208,25 @@ gkfs_open(const std::string& path, mode_t mode, int flags) {
        }
        return gkfs_open(md.target_path(), mode, flags);
    }


    /// The file is a renamed file, so we need to get the metadata of the
    /// original file.
    /// This does not work as we will check that this is a -1.
    if(!md.target_path().empty()) {
        LOG(ERROR, "File '{}' is renamed, reentering with '{}'", path,
            md.target_path());
        return gkfs_open(md.target_path(), mode, flags, true);
    }

#endif

    if(rename == false && md.blocks() == -1) {
        LOG(ERROR, "File '{}' is renamed __", path);
        errno = ENOENT;
        return -1;
    }

    if(S_ISDIR(md.mode())) {
        return gkfs_opendir(path);
    }
@@ -309,6 +332,33 @@ gkfs_access(const std::string& path, const int mask, bool follow_links) {
    return 0;
}

/**
 * gkfs wrapper for rename() system calls
 * errno may be set
 * @param old_path
 * @param new_path
 * @return 0 on success, -1 on failure
 */
int
gkfs_rename(const string& old_path, const string& new_path) {
    auto md = gkfs::utils::get_metadata(old_path, false);
    if(!md) {
        return -1;
    }
    auto md2 = gkfs::utils::get_metadata(new_path, false);
    if(md2) {
        return -1;
    }

    auto err = gkfs::rpc::forward_rename(old_path, new_path, md.value());
    if(err) {
        errno = err;
        return -1;
    }

    return 0;
}

/**
 * gkfs wrapper for stat() system calls
 * errno may be set
@@ -320,7 +370,7 @@ gkfs_access(const std::string& path, const int mask, bool follow_links) {
int
gkfs_stat(const string& path, struct stat* buf, bool follow_links) {
    auto md = gkfs::utils::get_metadata(path, follow_links);
    if(!md) {
    if(!md or md.value().blocks() == -1) {
        return -1;
    }
    gkfs::utils::metadata_to_stat(path, *md, *buf);
@@ -344,7 +394,8 @@ int
gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask,
           struct statx* buf, bool follow_links) {
    auto md = gkfs::utils::get_metadata(path, follow_links);
    if(!md) {

    if(!md or md.value().blocks() == -1) {
        return -1;
    }

Loading