From 0a94076834f77537007f62f4cb7c9bb77b7d8a16 Mon Sep 17 00:00:00 2001 From: Liss Heidrich Date: Mon, 2 Sep 2024 09:41:19 +0200 Subject: [PATCH] add capacity param --- src/dice/ffi/metall.cpp | 4 ++-- src/dice/ffi/metall.h | 5 ++++- tests/tests_Sanity.cpp | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/dice/ffi/metall.cpp b/src/dice/ffi/metall.cpp index cb8edcb..2cbb23f 100644 --- a/src/dice/ffi/metall.cpp +++ b/src/dice/ffi/metall.cpp @@ -30,14 +30,14 @@ metall_manager *metall_open_read_only(char const *path) { return open_impl(path); } -metall_manager *metall_create(char const *path) { +metall_manager *metall_create(char const *path, size_t capacity) { if (std::filesystem::exists(path)) { // prevent accidental overwrite errno = EEXIST; return nullptr; } - auto *manager = new metall_manager_t{metall::create_only, path}; + auto *manager = new metall_manager_t{metall::create_only, path, capacity}; if (!manager->check_sanity()) { delete manager; errno = ENOTRECOVERABLE; diff --git a/src/dice/ffi/metall.h b/src/dice/ffi/metall.h index c84d152..6b44af0 100644 --- a/src/dice/ffi/metall.h +++ b/src/dice/ffi/metall.h @@ -5,11 +5,13 @@ #include #include +#include #ifdef __cplusplus extern "C" { #endif + typedef struct metall_manager metall_manager; /** @@ -31,11 +33,12 @@ metall_manager *metall_open_read_only(char const *path); /** * @brief Attempts to create a metall datastore at path * @param path path at which to create a datastore + * @param capacity maximum capacity for metall manager, for default value use METALL_DEFAULT_CAPACITY * @return true on success, false on failure. On failure, sets errno to one of the following values: * - EEXIST if the given path already exists * - ENOTRECOVERABLE if the datastore could not be created for some other reason */ -metall_manager *metall_create(char const *path); +metall_manager *metall_create(char const *path, size_t capacity); /** * @brief Returns true if the metall manager was opened as read-only diff --git a/tests/tests_Sanity.cpp b/tests/tests_Sanity.cpp index ac9394f..bba2ddb 100644 --- a/tests/tests_Sanity.cpp +++ b/tests/tests_Sanity.cpp @@ -17,7 +17,7 @@ TEST_SUITE("metall-ffi") { std::string const snap_path = path + "-snap"; { - metall_manager *manager = metall_create(path.c_str()); + metall_manager *manager = metall_create(path.c_str(), METALL_DEFAULT_CAPACITY); if (manager == nullptr) { FAIL("failed to create: ", strerror(errno)); } @@ -96,7 +96,7 @@ TEST_SUITE("metall-ffi") { TEST_CASE("prevent open same datastore twice") { std::string const path = "/tmp/" + std::to_string(std::random_device{}()); - metall_manager *manager = metall_create(path.c_str()); + metall_manager *manager = metall_create(path.c_str(), METALL_DEFAULT_CAPACITY); if (manager == nullptr) { FAIL("failed to create datastore: ", strerror(errno)); }