Commit 9ecd4e05 authored by Matthieu Dorier's avatar Matthieu Dorier

added an API to query the size of a fileset

parent d50f9bf7
......@@ -89,6 +89,11 @@ int main(int argc, char** argv)
}
remi_fileset_register_metadata(fileset, "AERED", "qerqwer");
// check if we can compute the size of the fileset
size_t size = 0;
ret = remi_fileset_compute_size(fileset, 1, &size);
fprintf(stdout, "Transferring a fileset of size %ld\n", size);
remi_fileset_set_xfer_size(fileset, 4);
// migrate the fileset
int status = 0;
......
......@@ -298,6 +298,22 @@ int remi_fileset_foreach_metadata(
remi_metadata_callback_t callback,
void* uargs);
/**
* @brief Walk through the files pointed to by this fileset and
* compute the total size of the fileset.
*
* @param fileset Fileset on which to compute the size.
* @param include_metadata Whether to include metadata or not.
* @param size Resulting size.
*
* @return REMI_SUCCESS or error code defined in remi-common.h.
*/
int remi_fileset_compute_size(
remi_fileset_t fileset,
int include_metadata,
size_t* size);
#if defined(__cplusplus)
}
#endif
......
......@@ -58,7 +58,7 @@ extern "C" int remi_client_init(
abt_io_instance_id abtio,
remi_client_t* client)
{
auto theEngine = new tl::engine(mid, THALLIUM_CLIENT_MODE);
auto theEngine = new tl::engine(mid);
remi_client_t theClient = new remi_client(theEngine, abtio);
theClient->m_mid = mid;
*client = theClient;
......
......@@ -3,6 +3,15 @@
*
* See COPYRIGHT in top-level directory.
*/
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <cstring>
#include "remi/remi-common.h"
#include "fs-util.hpp"
......@@ -236,3 +245,56 @@ extern "C" int remi_fileset_foreach_metadata(
}
return REMI_SUCCESS;
}
struct add_size_args {
size_t size;
remi_fileset_t fileset;
int ret;
};
static void add_metadata_size(const char* key, const char* value, void* uargs) {
add_size_args* args = static_cast<add_size_args*>(uargs);
args->size += strlen(key) + strlen(value) + 2;
}
static void add_file_size(const char* filename, void* uargs) {
add_size_args* args = static_cast<add_size_args*>(uargs);
if(args->ret != 0) return;
std::string theFilename = args->fileset->m_root + filename;
int fd = open(theFilename.c_str(), O_RDONLY, 0);
if(fd == -1) {
args->ret = -1;
return;
}
struct stat st;
if(0 != fstat(fd, &st)) {
close(fd);
args->ret = -1;
return;
}
args->size += st.st_size;
}
extern "C" int remi_fileset_compute_size(
remi_fileset_t fileset,
int include_metadata,
size_t* size)
{
add_size_args args;
args.size = 0;
args.ret = 0;
args.fileset = fileset;
int ret = remi_fileset_walkthrough(fileset, add_file_size, static_cast<void*>(&args));
if(ret != REMI_SUCCESS)
return ret;
if(args.ret != 0) {
return REMI_ERR_IO;
}
if(include_metadata) {
ret = remi_fileset_foreach_metadata(fileset, add_metadata_size, static_cast<void*>(&args));
}
if(ret != REMI_SUCCESS)
return ret;
*size = args.size;
return REMI_SUCCESS;
}
......@@ -420,7 +420,7 @@ extern "C" int remi_provider_register(
remi_provider_t* provider)
{
auto thePool = tl::pool(pool);
auto theEngine = new tl::engine(mid, THALLIUM_SERVER_MODE);
auto theEngine = new tl::engine(mid);
auto theProvider = new remi_provider(theEngine, abtio, provider_id, thePool);
margo_push_finalize_callback(mid, on_finalize, theProvider);
*provider = theProvider;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment