From 0da00a0a206a400264c9c1f3e7c0590d15d61970 Mon Sep 17 00:00:00 2001 From: Julian Benda Date: Sat, 7 May 2022 18:23:35 +0200 Subject: [PATCH] Add object backend management configuration --- include/core/jconfiguration.h | 14 +++++++ include/core/jmanagedbackends.h | 3 +- lib/core/jconfiguration.c | 74 ++++++++++++++++++++++++++++++++- lib/core/jmanagedbackends.c | 23 ++++++---- tools/config.c | 15 +++++++ 5 files changed, 119 insertions(+), 10 deletions(-) diff --git a/include/core/jconfiguration.h b/include/core/jconfiguration.h index d6fc1887e..a31edef8c 100644 --- a/include/core/jconfiguration.h +++ b/include/core/jconfiguration.h @@ -30,6 +30,7 @@ #include #include +#include G_BEGIN_DECLS @@ -43,6 +44,15 @@ struct JConfiguration; typedef struct JConfiguration JConfiguration; +struct JStorageTier { + guint64 bandwidth; ///< bandwidth in byte ber second + guint64 latency; ///< latency in ns + guint64 capacity; ///< capacity in byte +}; +typedef struct JStorageTier JStorageTier; + + + /** * Returns the configuration. * @@ -114,6 +124,10 @@ guint16 j_configuration_get_port(JConfiguration*); guint32 j_configuration_get_max_connections(JConfiguration*); guint64 j_configuration_get_stripe_size(JConfiguration*); +gchar const* j_configuration_get_object_policy_kv_backend(JConfiguration*); +gchar const* j_configuration_get_object_policy_kv_path(JConfiguration*); +gchar const* j_configuration_get_object_policy(JConfiguration*); +gchar const*const* j_configuration_get_object_policy_args(JConfiguration*); G_END_DECLS /** diff --git a/include/core/jmanagedbackends.h b/include/core/jmanagedbackends.h index 6f307a355..f4c718ba5 100644 --- a/include/core/jmanagedbackends.h +++ b/include/core/jmanagedbackends.h @@ -143,9 +143,10 @@ typedef struct * \param[out] policy_data a pointer to store address of policy internal data * \param[in] args a list of strings passed from the configuration file * which may used to parametrise the policy. + * The list is like the strings NULL terminated * \param[in] backends access to the object backend instances. **/ - gboolean (*init)(gpointer* policy_data, const JList* args, JManagedBackends* backends); + gboolean (*init)(gpointer* policy_data, gchar const*const* args, JManagedBackends* backends); /** * \param[in] policy_data data at address assigned in init diff --git a/lib/core/jconfiguration.c b/lib/core/jconfiguration.c index 2e6e646d5..54d971de6 100644 --- a/lib/core/jconfiguration.c +++ b/lib/core/jconfiguration.c @@ -140,6 +140,14 @@ struct JConfiguration gchar* path; } db; + struct + { + gchar* policy; + gchar** args; + gchar* kv_backend; + gchar* kv_path; + gchar const* log_file; + } object_hsm_policy; guint64 max_operation_size; guint64 max_inject_size; guint16 port; @@ -282,6 +290,10 @@ j_configuration_new_for_data(GKeyFile* key_file) gchar* db_backend; gchar* db_component; gchar* db_path; + gchar* object_policy_kv_backend; + gchar* object_policy_kv_path; + gchar* object_policy; + gchar** object_policy_args; guint64 max_operation_size; guint64 max_inject_size; guint32 port; @@ -307,6 +319,10 @@ j_configuration_new_for_data(GKeyFile* key_file) db_backend = g_key_file_get_string(key_file, "db", "backend", NULL); db_component = g_key_file_get_string(key_file, "db", "component", NULL); db_path = g_key_file_get_string(key_file, "db", "path", NULL); + object_policy_kv_backend = g_key_file_get_string(key_file, "object.hsm-policy", "kv_backend", NULL); + object_policy_kv_path = g_key_file_get_string(key_file, "object.hsm-policy", "kv_path", NULL); + object_policy = g_key_file_get_string(key_file, "object.hsm-policy", "policy", NULL); + object_policy_args = g_key_file_get_string_list(key_file, "object.hsm-policy", "args", NULL, NULL); /// \todo check value ranges (max_operation_size, port, max_connections, stripe_size) // configuration->port < 0 || configuration->port > 65535 @@ -322,7 +338,10 @@ j_configuration_new_for_data(GKeyFile* key_file) || kv_path == NULL || db_backend == NULL || db_component == NULL - || db_path == NULL) + || db_path == NULL + || object_policy_kv_backend == NULL + || object_policy_kv_path == NULL + || object_policy == NULL) { g_free(db_backend); g_free(db_component); @@ -336,6 +355,10 @@ j_configuration_new_for_data(GKeyFile* key_file) g_strfreev(servers_object); g_strfreev(servers_kv); g_strfreev(servers_db); + g_free(object_policy_kv_backend); + g_free(object_policy_kv_path); + g_free(object_policy); + g_strfreev(object_policy_args); return NULL; } @@ -356,6 +379,12 @@ j_configuration_new_for_data(GKeyFile* key_file) configuration->db.backend = db_backend; configuration->db.component = db_component; configuration->db.path = db_path; + + configuration->object_hsm_policy.kv_backend = object_policy_kv_backend; + configuration->object_hsm_policy.kv_path = object_policy_kv_path; + configuration->object_hsm_policy.policy = object_policy; + configuration->object_hsm_policy.args = object_policy_args; + configuration->max_operation_size = max_operation_size; configuration->port = port; configuration->max_inject_size = max_inject_size; @@ -430,6 +459,10 @@ j_configuration_unref(JConfiguration* configuration) g_strfreev(configuration->servers.kv); g_strfreev(configuration->servers.db); + g_free(configuration->object_hsm_policy.kv_backend); + g_free(configuration->object_hsm_policy.kv_path); + g_free(configuration->object_hsm_policy.policy); + g_strfreev(configuration->object_hsm_policy.args); g_slice_free(JConfiguration, configuration); } } @@ -597,6 +630,45 @@ j_configuration_get_port(JConfiguration* configuration) return configuration->port; } +gchar const* +j_configuration_get_object_policy_kv_backend(JConfiguration* configuration) +{ + J_TRACE_FUNCTION(NULL); + + g_return_val_if_fail(configuration != NULL, NULL); + + return configuration->object_hsm_policy.kv_backend; +} + +gchar const* +j_configuration_get_object_policy_kv_path(JConfiguration* configuration) +{ + J_TRACE_FUNCTION(NULL); + + g_return_val_if_fail(configuration != NULL, NULL); + + return configuration->object_hsm_policy.kv_path; +} + +gchar const* +j_configuration_get_object_policy(JConfiguration* configuration) +{ + J_TRACE_FUNCTION(NULL); + + g_return_val_if_fail(configuration != NULL, NULL); + + return configuration->object_hsm_policy.policy; +} + +JList const* +j_configuration_get_object_policy_args(JConfiguration* configuration) +{ + J_TRACE_FUNCTION(NULL); + + g_return_val_if_fail(configuration != NULL, NULL); + + return configuration->object_hsm_policy.args; +} /** * @} **/ diff --git a/lib/core/jmanagedbackends.c b/lib/core/jmanagedbackends.c index e26d63e15..ff921d1a9 100644 --- a/lib/core/jmanagedbackends.c +++ b/lib/core/jmanagedbackends.c @@ -274,16 +274,23 @@ write_unlock(RWSpinLock* this) g_atomic_int_set(&this->write_access, 0); } +/// proxy function +gchar const*const* j_configuration_get_object_tiers(JConfiguration* config); +gchar const*const* j_configuration_get_object_tiers(JConfiguration* config) { + (void) config; + return NULL; +} + gboolean j_backend_managed_init(JConfiguration* config, JList* object_backends, JManagedBackends** instance_ptr) { JListIterator* itr; - JListIterator* tier_itr; + gchar const*const* tier_itr; JManagedBackends* this; struct JBackendWrapper** b_itr; struct JStorageTier** t_itr; const gchar* policy_name = j_configuration_get_object_policy(config); - const JList* policy_args = j_configuration_get_object_policy_args(config); + char const*const* policy_args = j_configuration_get_object_policy_args(config); JObjectBackendPolicy* (*module_backend_policy_info)(void) = NULL; JObjectBackendPolicy* tmp_policy; *instance_ptr = malloc(sizeof(JManagedBackends)); @@ -298,7 +305,7 @@ j_backend_managed_init(JConfiguration* config, JList* object_backends, JManagedB this->object_backend = malloc(sizeof(struct JBackendWrapper*) * this->object_backend_length); this->object_tier_data = malloc(sizeof(JStorageTier*) * this->object_backend_length); itr = j_list_iterator_new(object_backends); - tier_itr = j_list_iterator_new(j_configuration_get_object_tiers(config)); + tier_itr = j_configuration_get_object_tiers(config); b_itr = this->object_backend; t_itr = this->object_tier_data; while (j_list_iterator_next(itr)) @@ -313,8 +320,8 @@ j_backend_managed_init(JConfiguration* config, JList* object_backends, JManagedB (*b_itr)->orig = j_list_iterator_get(itr); (*b_itr)->scope = (struct JManagedBackendScope){ 0 }; (*b_itr)->tier_data = malloc(sizeof(JStorageTier)); - if (j_list_iterator_next(tier_itr)) - memcpy((*b_itr)->tier_data, j_list_iterator_get(tier_itr), sizeof(JStorageTier)); + if (tier_itr && *tier_itr) + memcpy((*b_itr)->tier_data, tier_itr++, sizeof(JStorageTier)); else memset((*b_itr)->tier_data, 0, sizeof(JStorageTier)); @@ -322,9 +329,8 @@ j_backend_managed_init(JConfiguration* config, JList* object_backends, JManagedB ++t_itr; ++b_itr; } - g_assert_true(j_list_iterator_next(tier_itr) == FALSE); + g_assert_true(tier_itr == FALSE || *tier_itr == FALSE); j_list_iterator_free(itr); - j_list_iterator_free(tier_itr); // load policy this->module = NULL; @@ -363,6 +369,7 @@ j_backend_managed_init(JConfiguration* config, JList* object_backends, JManagedB this->policy = malloc(sizeof(JObjectBackendPolicy)); memcpy(this->policy, tmp_policy, sizeof(JObjectBackendPolicy)); + /// \todo use helper list this->policy->init(&this->policy->data, policy_args, this); // setup kv @@ -377,7 +384,7 @@ j_backend_managed_init(JConfiguration* config, JList* object_backends, JManagedB "failed to init kv for backend manager!"); this->kv_semantics = j_semantics_new(J_SEMANTICS_TEMPLATE_DEFAULT); - this->log.filename = j_configuration_get_object_policy_log_file(config); + // this->log.filename = j_configuration_get_object_policy_log_file(config); this->log.length = 0; return TRUE; diff --git a/tools/config.c b/tools/config.c index 502a619b1..da172368f 100644 --- a/tools/config.c +++ b/tools/config.c @@ -46,6 +46,10 @@ static gint64 opt_max_inject_size = 0; static gint opt_port = 0; static gint opt_max_connections = 0; static gint64 opt_stripe_size = 0; +static gchar const* opt_object_policy_kv_backend = NULL; +static gchar const* opt_object_policy_kv_path = NULL; +static gchar const* opt_object_policy = NULL; +static gchar const* opt_object_policy_args = NULL; static gchar** string_split(gchar const* string) @@ -100,10 +104,13 @@ write_config(gchar* path) g_auto(GStrv) servers_object = NULL; g_auto(GStrv) servers_kv = NULL; g_auto(GStrv) servers_db = NULL; + g_auto(GStrv) object_policy_args = NULL; servers_object = string_split(opt_servers_object); servers_kv = string_split(opt_servers_kv); servers_db = string_split(opt_servers_db); + object_policy_args = string_split(opt_object_policy_args); + key_file = g_key_file_new(); g_key_file_set_int64(key_file, "core", "max-operation-size", opt_max_operation_size); @@ -123,6 +130,10 @@ write_config(gchar* path) g_key_file_set_string(key_file, "db", "backend", opt_db_backend); g_key_file_set_string(key_file, "db", "component", opt_db_component); g_key_file_set_string(key_file, "db", "path", opt_db_path); + g_key_file_set_string(key_file, "object.hsm-policy", "kv_backend", opt_object_policy_kv_backend); + g_key_file_set_string(key_file, "object.hsm-policy", "kv_path", opt_object_policy_kv_path); + g_key_file_set_string(key_file, "object.hsm-policy", "policy", opt_object_policy); + g_key_file_set_string_list(key_file, "object.hsm-policy", "args", (gchar const*const*)object_policy_args, g_strv_length(object_policy_args)); key_file_data = g_key_file_to_data(key_file, &key_file_data_len, NULL); if (path != NULL) @@ -173,6 +184,10 @@ main(gint argc, gchar** argv) { "port", 0, 0, G_OPTION_ARG_INT, &opt_port, "Default network port", "0" }, { "max-connections", 0, 0, G_OPTION_ARG_INT, &opt_max_connections, "Maximum number of connections", "0" }, { "stripe-size", 0, 0, G_OPTION_ARG_INT64, &opt_stripe_size, "Default stripe size", "0" }, + { "object-policy-kv-backend", 0, 0, G_OPTION_ARG_STRING, &opt_object_policy_kv_backend, "Key-value backend to use managed object backends.", "leveldb" }, + { "object-policy-kv_path", 0, 0, G_OPTION_ARG_STRING, &opt_object_policy_kv_path, "Key-value path to use", "/path/to/storage" }, + { "object-policy", 0, 0, G_OPTION_ARG_STRING, &opt_object_policy, "Policy for managed object backends", "dummy" }, + { "object-policy-args", 0, 0, G_OPTION_ARG_STRING, &opt_object_policy_args, "Arguments passed to policy for initialisation", "arg1;arg2;arg3;" }, { NULL, 0, 0, 0, NULL, NULL, NULL } };