Unverified Commit 4077fcf1 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Refactor daemon handler for stat

The rpc stat handler was the only one calling directly a db function,
bypassing the intermediate adafs_ops interface.

A new function on the adafs_ops interface has been added to be used by
the rpc stat handler.
parent 61524cf0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ int create_metadentry(const std::string& path, mode_t mode);

int db_val_to_stat(const std::string& path, std::string db_val, struct stat& attr);

int get_metadentry(const std::string& path, std::string& val);

int get_metadentry(const std::string& path, Metadata& md);

int remove_metadentry(const std::string& path);
+10 −2
Original line number Diff line number Diff line
@@ -42,6 +42,14 @@ int create_metadentry(const std::string& path, mode_t mode) {
    return db_put_metadentry(path, md.to_KVentry()) ? 0 : -1;
}

int get_metadentry(const std::string& path, std::string& val) {
    auto ok = db_get_metadentry(path, val);
    if (!ok || val.size() == 0) {
        return -1;
    }
    return 0;
}

/**
 * Returns the metadata of an object at a specific path. The metadata can be of dummy values if configured
 * @param path
@@ -50,8 +58,8 @@ int create_metadentry(const std::string& path, mode_t mode) {
 */
int get_metadentry(const std::string& path, Metadata& md) {
    string val;
    auto err = db_get_metadentry(path, val);
    if (!err || val.size() == 0) {
    auto err = get_metadentry(path, val);
    if (err) {
        return -1;
    }
    Metadata mdi{path, val};
+2 −2
Original line number Diff line number Diff line
@@ -7,10 +7,10 @@ using namespace std;

bool db_get_metadentry(const std::string& key, std::string& val) {
    auto db = ADAFS_DATA->rdb();
    auto err = db->Get(ReadOptions(), key, &val).ok();
    auto ok = db->Get(ReadOptions(), key, &val).ok();
    // TODO check what happens if nothing could have been found. Will val be NULL, nullptr, ""?
    // It matters because the client RPC is checking for an empty string to see if get_attr was successful or not
    return err;
    return ok;
}

bool db_put_metadentry(const std::string& key, const std::string& val) {
+8 −7
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@

#include <daemon/adafs_ops/metadentry.hpp>

#include <daemon/db/db_ops.hpp>

using namespace std;

static hg_return_t rpc_minimal(hg_handle_t handle) {
@@ -97,14 +95,17 @@ static hg_return_t rpc_srv_stat(hg_handle_t handle) {
    ADAFS_DATA->spdlogger()->debug("Got srv stat RPC for path {}", in.path);
    // get the metadata
    string val;
    auto err = db_get_metadentry(in.path, val);
    // TODO set return values proper with errorcodes the whole way
    auto err = get_metadentry(in.path, val);
    if (err) {
        // DB operations failed
        if(val.size() == 0){
            out.err = ENOENT;
        } else {
            out.err = EBUSY;
        }
    } else {
        out.err = 0;
        out.db_val = val.c_str();
    } else {
        // if db_get_metadentry didn't return anything we set the errno to ENOENT
        out.err = ENOENT;
    }

    ADAFS_DATA->spdlogger()->debug("Sending output mode {}", out.db_val);