Skip to content

Commit

Permalink
Add object backend management configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
JBenda committed May 7, 2022
1 parent 87ae812 commit 0da00a0
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 10 deletions.
14 changes: 14 additions & 0 deletions include/core/jconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <glib.h>

#include <core/jbackend.h>
#include <core/jlist.h>

G_BEGIN_DECLS

Expand All @@ -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.
*
Expand Down Expand Up @@ -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

/**
Expand Down
3 changes: 2 additions & 1 deletion include/core/jmanagedbackends.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 73 additions & 1 deletion lib/core/jconfiguration.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
/**
* @}
**/
23 changes: 15 additions & 8 deletions lib/core/jmanagedbackends.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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))
Expand All @@ -313,18 +320,17 @@ 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));

*t_itr = (*b_itr)->tier_data;
++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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions tools/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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 }
};

Expand Down

0 comments on commit 0da00a0

Please sign in to comment.