diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2845ed7d6..49c6a4617 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -196,8 +196,8 @@ endif (HAVE_NBD_NETLINK_H AND NL3_LIBRARIES) # libvitastor_kv.so add_library(vitastor_kv SHARED kv_db.cpp - kv_db.h ) +set_target_properties(vitastor_kv PROPERTIES PUBLIC_HEADER "vitastor_kv.h") target_link_libraries(vitastor_kv vitastor_client ) diff --git a/src/kv_cli.cpp b/src/kv_cli.cpp index 52d3f5427..fd3d7d0af 100644 --- a/src/kv_cli.cpp +++ b/src/kv_cli.cpp @@ -12,16 +12,17 @@ #include //#include +#include "cluster_client.h" #include "epoll_manager.h" #include "str_util.h" -#include "kv_db.h" +#include "vitastor_kv.h" const char *exe_name = NULL; class kv_cli_t { public: - json11::Json::object cfg; + std::map cfg; std::vector cli_cmd; kv_dbw_t *db = NULL; @@ -156,7 +157,7 @@ void kv_cli_t::run() if (cfg.find("db") != cfg.end()) { bool done = false; - handle_cmd({ "open", cfg.at("db").string_value() }, [&done](int res) { if (res != 0) exit(1); done = true; }); + handle_cmd({ "open", cfg.at("db") }, [&done](int res) { if (res != 0) exit(1); done = true; }); while (!done) { ringloop->loop(); diff --git a/src/kv_db.cpp b/src/kv_db.cpp index aa4ddb73a..7b0bb7db6 100644 --- a/src/kv_db.cpp +++ b/src/kv_db.cpp @@ -15,7 +15,7 @@ #include "cluster_client.h" #include "str_util.h" -#include "kv_db.h" +#include "vitastor_kv.h" // 0x VITASTOR OPTBTREE #define KV_BLOCK_MAGIC 0x761A5106097B18EE @@ -1969,12 +1969,12 @@ kv_dbw_t::~kv_dbw_t() delete db; } -void kv_dbw_t::open(inode_t inode_id, json11::Json cfg, std::function cb) +void kv_dbw_t::open(uint64_t inode_id, std::map cfg, std::function cb) { db->open(inode_id, cfg, cb); } -void kv_dbw_t::set_config(json11::Json cfg) +void kv_dbw_t::set_config(std::map cfg) { db->set_config(cfg); } diff --git a/src/kv_stress.cpp b/src/kv_stress.cpp index e90e47204..4d5fa53d5 100644 --- a/src/kv_stress.cpp +++ b/src/kv_stress.cpp @@ -12,9 +12,10 @@ #include //#include +#include "cluster_client.h" #include "epoll_manager.h" #include "str_util.h" -#include "kv_db.h" +#include "vitastor_kv.h" const char *exe_name = NULL; @@ -44,7 +45,7 @@ class kv_test_t { public: // Config - json11::Json::object kv_cfg; + std::map kv_cfg; std::string key_prefix, key_suffix; uint64_t inode_id = 0; uint64_t op_count = 1000000; @@ -238,22 +239,22 @@ void kv_test_t::parse_config(json11::Json cfg) if (!cfg["stop_on_error"].is_null()) stop_on_error = cfg["stop_on_error"].bool_value(); if (!cfg["kv_block_size"].is_null()) - kv_cfg["kv_block_size"] = cfg["kv_block_size"]; + kv_cfg["kv_block_size"] = cfg["kv_block_size"].as_string(); if (!cfg["kv_memory_limit"].is_null()) - kv_cfg["kv_memory_limit"] = cfg["kv_memory_limit"]; + kv_cfg["kv_memory_limit"] = cfg["kv_memory_limit"].as_string(); if (!cfg["kv_allocate_blocks"].is_null()) - kv_cfg["kv_allocate_blocks"] = cfg["kv_allocate_blocks"]; + kv_cfg["kv_allocate_blocks"] = cfg["kv_allocate_blocks"].as_string(); if (!cfg["kv_evict_max_misses"].is_null()) - kv_cfg["kv_evict_max_misses"] = cfg["kv_evict_max_misses"]; + kv_cfg["kv_evict_max_misses"] = cfg["kv_evict_max_misses"].as_string(); if (!cfg["kv_evict_attempts_per_level"].is_null()) - kv_cfg["kv_evict_attempts_per_level"] = cfg["kv_evict_attempts_per_level"]; + kv_cfg["kv_evict_attempts_per_level"] = cfg["kv_evict_attempts_per_level"].as_string(); if (!cfg["kv_evict_unused_age"].is_null()) - kv_cfg["kv_evict_unused_age"] = cfg["kv_evict_unused_age"]; + kv_cfg["kv_evict_unused_age"] = cfg["kv_evict_unused_age"].as_string(); if (!cfg["kv_log_level"].is_null()) { log_level = cfg["kv_log_level"].uint64_value(); trace = log_level >= 10; - kv_cfg["kv_log_level"] = cfg["kv_log_level"]; + kv_cfg["kv_log_level"] = std::to_string(log_level); } total_prob = reopen_prob+get_prob+add_prob+update_prob+del_prob+list_prob; stat.get.name = "get"; diff --git a/src/nfs_block.cpp b/src/nfs_block.cpp index de765ab93..71495839a 100644 --- a/src/nfs_block.cpp +++ b/src/nfs_block.cpp @@ -2,6 +2,8 @@ // License: VNPL-1.1 (see README.md for details) // // NFS proxy over Vitastor block images +// Presents all images as files +// Keeps image/file list in memory and is thus unsuitable for a large number of files #include diff --git a/src/nfs_block.h b/src/nfs_block.h index 7fcf9add2..f523c55ee 100644 --- a/src/nfs_block.h +++ b/src/nfs_block.h @@ -2,6 +2,8 @@ // License: VNPL-1.1 (see README.md for details) // // NFS proxy over Vitastor block images - header +// Presents all images as files +// Keeps image/file list in memory and is thus unsuitable for a large number of files #pragma once diff --git a/src/nfs_kv.cpp b/src/nfs_kv.cpp index 1598cca08..6badb5759 100644 --- a/src/nfs_kv.cpp +++ b/src/nfs_kv.cpp @@ -256,7 +256,12 @@ void kv_fs_state_t::init(nfs_proxy_t *proxy, json11::Json cfg) int open_res = 0; bool open_done = false; proxy->db = new kv_dbw_t(proxy->cli); - proxy->db->open(fs_kv_inode, cfg, [&](int res) + std::map kv_cfg; + for (auto & kv: cfg.object_items()) + { + kv_cfg[kv.first] = kv.second.as_string(); + } + proxy->db->open(fs_kv_inode, kv_cfg, [&](int res) { open_done = true; open_res = res; diff --git a/src/nfs_proxy.cpp b/src/nfs_proxy.cpp index dfbc538de..c93518ea7 100644 --- a/src/nfs_proxy.cpp +++ b/src/nfs_proxy.cpp @@ -1,9 +1,7 @@ // Copyright (c) Vitaliy Filippov, 2019+ // License: VNPL-1.1 (see README.md for details) // -// Simplified NFS proxy -// Presents all images as files -// Keeps image/file list in memory and is thus unsuitable for a large number of files +// NFS proxy entrypoint, common for both pseudo-FS and Vitastor-KV based FS #define _XOPEN_SOURCE #include diff --git a/src/nfs_proxy.h b/src/nfs_proxy.h index 816a73a82..999db70ac 100644 --- a/src/nfs_proxy.h +++ b/src/nfs_proxy.h @@ -1,10 +1,15 @@ +// Copyright (c) Vitaliy Filippov, 2019+ +// License: VNPL-1.1 (see README.md for details) +// +// Simplified NFS proxy - main entrypoint header + #pragma once #include "cluster_client.h" #include "epoll_manager.h" #include "nfs_portmap.h" #include "nfs/xdr_impl.h" -#include "kv_db.h" +#include "vitastor_kv.h" #define NFS_ROOT_HANDLE "R" #define RPC_INIT_BUF_SIZE 32768 diff --git a/src/vitastor_c.cpp b/src/vitastor_c.cpp index 7a01b3da8..8099cb741 100644 --- a/src/vitastor_c.cpp +++ b/src/vitastor_c.cpp @@ -200,6 +200,11 @@ vitastor_c *vitastor_c_create_epoll_json(const char **options, int options_len) return self; } +void* vitastor_c_get_internal_client(vitastor_c *client) +{ + return client->cli; +} + void vitastor_c_destroy(vitastor_c *client) { delete client->cli; diff --git a/src/vitastor_c.h b/src/vitastor_c.h index 258fdf857..74a1dff55 100644 --- a/src/vitastor_c.h +++ b/src/vitastor_c.h @@ -7,7 +7,7 @@ #define VITASTOR_QEMU_PROXY_H // C API wrapper version -#define VITASTOR_C_API_VERSION 3 +#define VITASTOR_C_API_VERSION 4 #ifndef POOL_ID_BITS #define POOL_ID_BITS 16 @@ -41,6 +41,7 @@ vitastor_c *vitastor_c_create_uring(const char *config_path, const char *etcd_ho int use_rdma, const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu, int log_level); vitastor_c *vitastor_c_create_uring_json(const char **options, int options_len); vitastor_c *vitastor_c_create_epoll_json(const char **options, int options_len); +void* vitastor_c_get_internal_client(vitastor_c *client); void vitastor_c_destroy(vitastor_c *client); int vitastor_c_is_ready(vitastor_c *client); int vitastor_c_uring_register_eventfd(vitastor_c *client); diff --git a/src/kv_db.h b/src/vitastor_kv.h similarity index 73% rename from src/kv_db.h rename to src/vitastor_kv.h index 79d0b97c8..97b5f0393 100644 --- a/src/kv_db.h +++ b/src/vitastor_kv.h @@ -6,17 +6,27 @@ #pragma once -#include "cluster_client.h" +#include +#include + +#include +#include +#include + +#define VITASTOR_KV_API_VERSION 1 + +class cluster_client_t; struct kv_db_t; struct kv_dbw_t { + // cli = vitastor_c_get_internal_client(client) kv_dbw_t(cluster_client_t *cli); ~kv_dbw_t(); - void open(inode_t inode_id, json11::Json cfg, std::function cb); - void set_config(json11::Json cfg); + void open(uint64_t inode_id, std::map cfg, std::function cb); + void set_config(std::map cfg); void close(std::function cb); uint64_t get_size();