Unverified Commit 4ba3c5e7 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

bugfix: get_dirents RPC has no error propagation

Implement proper error propagation and handling on get_dirents RPC.
Error happening on the deamon are now embedded on the returned response
and the client throws an exception once he receives the response.
parent 791913f0
Loading
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -446,6 +446,11 @@ void get_dirents(OpenDir& open_dir){
            throw std::runtime_error(fmt::format("Failed to get rpc output.. [path: {}, target host: {}]", root_dir, target_host));
        }

        if (out.err) {
            CTX->log()->error("{}() Sending RPC to host: {}", __func__, target_host);
            throw std::runtime_error(fmt::format("Failed to retrieve dir entries from host '{}'. "
                                                 "Error '{}', path '{}'", target_host, strerror(out.err), root_dir));
        }
        bool* bool_ptr = reinterpret_cast<bool*>(recv_buffers[target_host]);
        char* names_ptr = recv_buffers[target_host] + (out.dirents_size * sizeof(bool));

+7 −3
Original line number Diff line number Diff line
@@ -300,8 +300,9 @@ static hg_return_t rpc_srv_get_dirents(hg_handle_t handle) {
    // Get input parmeters
    auto ret = margo_get_input(handle, &in);
    if (ret != HG_SUCCESS) {
        ADAFS_DATA->spdlogger()->error("{}() Could not get RPC input data with err {}", __func__, ret);
        return rpc_cleanup_respond(&handle, &in, &out, &bulk_handle);
        ADAFS_DATA->spdlogger()->error(
                "{}() Could not get RPC input data with err {}", __func__, ret);
        return ret;
    }

    // Retrieve size of source buffer
@@ -318,6 +319,7 @@ static hg_return_t rpc_srv_get_dirents(hg_handle_t handle) {
    out.dirents_size = entries.size();

    if(entries.size() == 0){
        out.err = 0;
        return rpc_cleanup_respond(&handle, &in, &out, &bulk_handle);
    }

@@ -332,6 +334,7 @@ static hg_return_t rpc_srv_get_dirents(hg_handle_t handle) {
    if(bulk_size < out_size){
        //Source buffer is smaller than total output size
        ADAFS_DATA->spdlogger()->error("{}() Entries do not fit source buffer", __func__);
        out.err = ENOBUFS;
        return rpc_cleanup_respond(&handle, &in, &out, &bulk_handle);
    }

@@ -353,6 +356,7 @@ static hg_return_t rpc_srv_get_dirents(hg_handle_t handle) {
    ret = margo_bulk_create(mid, 1, reinterpret_cast<void**>(&out_buff_ptr), &out_size, HG_BULK_READ_ONLY, &bulk_handle);
    if (ret != HG_SUCCESS) {
        ADAFS_DATA->spdlogger()->error("{}() Failed to create bulk handle", __func__);
        out.err = EBUSY;
        return rpc_cleanup_respond(&handle, &in, &out, &bulk_handle);
    }

@@ -369,9 +373,9 @@ static hg_return_t rpc_srv_get_dirents(hg_handle_t handle) {
    }

    out.dirents_size = entries.size();
    out.err = 0;
    ADAFS_DATA->spdlogger()->debug(
            "{}() Sending output response", __func__);

    return rpc_cleanup_respond(&handle, &in, &out, &bulk_handle);
}