Commit 74014e85 authored by Marc Vef's avatar Marc Vef
Browse files

PoC: stat optimization

parent f44327e1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ constexpr typename std::underlying_type<E>::type to_underlying(E e) {

std::shared_ptr<gkfs::metadata::Metadata> get_metadata(const std::string& path, bool follow_links = false);

std::string get_metadata_no_shared(const std::string& path, bool follow_links = false);

int metadata_to_stat(const std::string& path, const gkfs::metadata::Metadata& md, struct stat& attr);

void load_hosts();
+14 −3
Original line number Diff line number Diff line
@@ -274,12 +274,23 @@ int gkfs_access(const std::string& path, const int mask, bool follow_links) {
 * @return 0 on success, -1 on failure
 */
int gkfs_stat(const string& path, struct stat* buf, bool follow_links) {
    auto md = gkfs::util::get_metadata(path, follow_links);
    if (!md) {
    auto attr = gkfs::util::get_metadata_no_shared(path, follow_links);
    if (attr.empty()) {
        return -1;
    }
    gkfs::util::metadata_to_stat(path, *md, *buf);
    gkfs::metadata::Metadata md{attr};
    gkfs::util::metadata_to_stat(path, md, *buf);
    return 0;




//    auto md = gkfs::util::get_metadata(path, follow_links);
//    if (!md) {
//        return -1;
//    }
//    gkfs::util::metadata_to_stat(path, *md, *buf);
//    return 0;
}

#ifdef STATX_TYPE
+10 −0
Original line number Diff line number Diff line
@@ -186,6 +186,16 @@ std::shared_ptr<gkfs::metadata::Metadata> get_metadata(const string& path, bool
    return make_shared<gkfs::metadata::Metadata>(attr);
}

string get_metadata_no_shared(const string& path, bool follow_links) {
    std::string attr;
    auto err = gkfs::rpc::forward_stat(path, attr);
    if (err) {
        errno = err;
        return ""s;
    }
    return attr;
}

/**
 * Converts the Metadata object into a stat struct, which is needed by Linux
 * @param path