Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 58 additions & 59 deletions src/ctl/ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,50 +247,49 @@ static void ctl_query_cleanup_real_args(const umf_ctl_node_t *n, void *real_arg,
/*
* ctl_exec_query_read -- (internal) calls the read callback of a node
*/
static int ctl_exec_query_read(void *ctx, const umf_ctl_node_t *n,
umf_ctl_query_source_t source, void *arg,
size_t size, umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type) {
static umf_result_t ctl_exec_query_read(void *ctx, const umf_ctl_node_t *n,
umf_ctl_query_source_t source,
void *arg, size_t size,
umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type) {
(void)query_type;
assert(n != NULL);
assert(n->cb[CTL_QUERY_READ] != NULL);
assert(MAX_CTL_QUERY_TYPE != query_type);

if (arg == NULL) {
errno = EINVAL;
return -1;
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

return n->cb[CTL_QUERY_READ](ctx, source, arg, size, indexes, extra_name,
MAX_CTL_QUERY_TYPE);
}

/*
* ctl_exec_query_write -- (internal) calls the write callback of a node
*/
static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
umf_ctl_query_source_t source, void *arg,
size_t size, umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type) {
static umf_result_t ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
umf_ctl_query_source_t source,
void *arg, size_t size,
umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type) {
(void)query_type;
assert(n != NULL);
assert(n->cb[CTL_QUERY_WRITE] != NULL);
assert(MAX_CTL_QUERY_TYPE != query_type);

if (arg == NULL) {
errno = EINVAL;
return -1;
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

void *real_arg = ctl_query_get_real_args(n, arg, source);
if (real_arg == NULL) {
return -1;
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

int ret = n->cb[CTL_QUERY_WRITE](ctx, source, real_arg, size, indexes,
extra_name, MAX_CTL_QUERY_TYPE);
umf_result_t ret = n->cb[CTL_QUERY_WRITE](
ctx, source, real_arg, size, indexes, extra_name, MAX_CTL_QUERY_TYPE);
ctl_query_cleanup_real_args(n, real_arg, source);

return ret;
Expand All @@ -299,11 +298,12 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
/*
* ctl_exec_query_runnable -- (internal) calls the run callback of a node
*/
static int ctl_exec_query_runnable(void *ctx, const umf_ctl_node_t *n,
umf_ctl_query_source_t source, void *arg,
size_t size, umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type) {
static umf_result_t ctl_exec_query_runnable(void *ctx, const umf_ctl_node_t *n,
umf_ctl_query_source_t source,
void *arg, size_t size,
umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type) {
(void)query_type;
assert(n != NULL);
assert(n->cb[CTL_QUERY_RUNNABLE] != NULL);
Expand All @@ -312,24 +312,25 @@ static int ctl_exec_query_runnable(void *ctx, const umf_ctl_node_t *n,
extra_name, MAX_CTL_QUERY_TYPE);
}

static int ctl_exec_query_subtree(void *ctx, const umf_ctl_node_t *n,
umf_ctl_query_source_t source, void *arg,
size_t size, umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type) {
static umf_result_t ctl_exec_query_subtree(void *ctx, const umf_ctl_node_t *n,
umf_ctl_query_source_t source,
void *arg, size_t size,
umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type) {
assert(n != NULL);
assert(n->cb[CTL_QUERY_SUBTREE] != NULL);
assert(MAX_CTL_QUERY_TYPE != query_type);
return n->cb[CTL_QUERY_SUBTREE](ctx, source, arg, size, indexes, extra_name,
query_type);
}

typedef int (*umf_ctl_exec_query_t)(void *ctx, const umf_ctl_node_t *n,
umf_ctl_query_source_t source, void *arg,
size_t size,
umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type);
typedef umf_result_t (*umf_ctl_exec_query_t)(void *ctx, const umf_ctl_node_t *n,
umf_ctl_query_source_t source,
void *arg, size_t size,
umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type);

static umf_ctl_exec_query_t ctl_exec_query[MAX_CTL_QUERY_TYPE] = {
ctl_exec_query_read,
Expand All @@ -342,12 +343,11 @@ static umf_ctl_exec_query_t ctl_exec_query[MAX_CTL_QUERY_TYPE] = {
* ctl_query -- (internal) parses the name and calls the appropriate methods
* from the ctl tree
*/
int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
const char *name, umf_ctl_query_type_t type, void *arg,
size_t size) {
umf_result_t ctl_query(struct ctl *ctl, void *ctx,
umf_ctl_query_source_t source, const char *name,
umf_ctl_query_type_t type, void *arg, size_t size) {
if (name == NULL) {
errno = EINVAL;
return -1;
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

/*
Expand All @@ -358,10 +358,10 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
umf_ctl_index_utlist_t *indexes = NULL;
indexes = Zalloc(sizeof(*indexes));
if (!indexes) {
return -1;
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}

int ret = -1;
umf_result_t ret = UMF_RESULT_ERROR_UNKNOWN;
size_t name_offset = 0;

const umf_ctl_node_t *n =
Expand All @@ -377,7 +377,7 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
if (n == NULL ||
(n->type != CTL_NODE_LEAF && n->type != CTL_NODE_SUBTREE) ||
n->cb[n->type == CTL_NODE_SUBTREE ? CTL_QUERY_SUBTREE : type] == NULL) {
errno = EINVAL;
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
goto out;
}

Expand Down Expand Up @@ -436,24 +436,24 @@ static int ctl_parse_query(char *qbuf, char **name, char **value) {
/*
* ctl_load_config -- executes the entire query collection from a provider
*/
static int ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
int r = 0;
static umf_result_t ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
umf_result_t ret = UMF_RESULT_SUCCESS;
char *sptr = NULL; /* for internal use of strtok */
char *name;
char *value;
char *qbuf = strtok_r(buf, CTL_STRING_QUERY_SEPARATOR, &sptr);

while (qbuf != NULL) {
r = ctl_parse_query(qbuf, &name, &value);
if (r != 0) {
return -1;
int parse_res = ctl_parse_query(qbuf, &name, &value);
if (parse_res != 0) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

r = ctl_query(ctl, ctx, CTL_QUERY_CONFIG_INPUT, name, CTL_QUERY_WRITE,
value, 0);
ret = ctl_query(ctl, ctx, CTL_QUERY_CONFIG_INPUT, name, CTL_QUERY_WRITE,
value, 0);

if (r < 0 && ctx != NULL) {
return -1;
if (ret != UMF_RESULT_SUCCESS && ctx != NULL) {
return ret;
}

qbuf = strtok_r(NULL, CTL_STRING_QUERY_SEPARATOR, &sptr);
Expand All @@ -465,14 +465,14 @@ static int ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
/*
* ctl_load_config_from_string -- loads obj configuration from string
*/
int ctl_load_config_from_string(struct ctl *ctl, void *ctx,
const char *cfg_string) {
umf_result_t ctl_load_config_from_string(struct ctl *ctl, void *ctx,
const char *cfg_string) {
char *buf = Strdup(cfg_string);
if (buf == NULL) {
return -1;
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}

int ret = ctl_load_config(ctl, ctx, buf);
umf_result_t ret = ctl_load_config(ctl, ctx, buf);

umf_ba_global_free(buf);
return ret;
Expand All @@ -485,9 +485,9 @@ int ctl_load_config_from_string(struct ctl *ctl, void *ctx,
* the size of the file, reads its content and sanitizes it for ctl_load_config.
*/
#ifndef _WIN32 // TODO: implement for Windows
int ctl_load_config_from_file(struct ctl *ctl, void *ctx,
const char *cfg_file) {
int ret = -1;
umf_result_t ctl_load_config_from_file(struct ctl *ctl, void *ctx,
const char *cfg_file) {
umf_result_t ret = UMF_RESULT_ERROR_UNKNOWN;
long fsize = 0;
char *buf = NULL;

Expand Down Expand Up @@ -608,7 +608,6 @@ int ctl_arg_integer(const void *arg, void *dest, size_t dest_size) {
*(uint8_t *)dest = (uint8_t)val;
break;
default:
errno = EINVAL;
return -1;
}

Expand Down
22 changes: 12 additions & 10 deletions src/ctl/ctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ typedef enum ctl_query_source {
MAX_CTL_QUERY_SOURCE
} umf_ctl_query_source_t;

typedef int (*node_callback)(void *ctx, umf_ctl_query_source_t type, void *arg,
size_t size, umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type);
typedef umf_result_t (*node_callback)(void *ctx, umf_ctl_query_source_t type,
void *arg, size_t size,
umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type);

enum ctl_node_type {
CTL_NODE_UNKNOWN,
Expand Down Expand Up @@ -115,9 +116,10 @@ struct ctl {

void initialize_global_ctl(void);

int ctl_load_config_from_string(struct ctl *ctl, void *ctx,
const char *cfg_string);
int ctl_load_config_from_file(struct ctl *ctl, void *ctx, const char *cfg_file);
umf_result_t ctl_load_config_from_string(struct ctl *ctl, void *ctx,
const char *cfg_string);
umf_result_t ctl_load_config_from_file(struct ctl *ctl, void *ctx,
const char *cfg_file);

/* Use through CTL_REGISTER_MODULE, never directly */
void ctl_register_module_node(struct ctl *c, const char *name,
Expand Down Expand Up @@ -149,9 +151,9 @@ int ctl_arg_string(const void *arg, void *dest, size_t dest_size);

#define CTL_NODE(name, ...) ctl_node_##__VA_ARGS__##_##name

int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
const char *name, umf_ctl_query_type_t type, void *arg,
size_t size);
umf_result_t ctl_query(struct ctl *ctl, void *ctx,
umf_ctl_query_source_t source, const char *name,
umf_ctl_query_type_t type, void *arg, size_t size);

/* Declaration of a new child node */
#define CTL_CHILD(name, ...) \
Expand Down
8 changes: 2 additions & 6 deletions src/libumf.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ umf_result_t umfCtlSet(const char *name, void *ctx, void *arg, size_t size) {
}

return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_WRITE,
arg, size)
? UMF_RESULT_ERROR_UNKNOWN
: UMF_RESULT_SUCCESS;
arg, size);
}

umf_result_t umfCtlExec(const char *name, void *ctx, void *arg, size_t size) {
Expand All @@ -133,7 +131,5 @@ umf_result_t umfCtlExec(const char *name, void *ctx, void *arg, size_t size) {
}

return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name,
CTL_QUERY_RUNNABLE, arg, size)
? UMF_RESULT_ERROR_UNKNOWN
: UMF_RESULT_SUCCESS;
CTL_QUERY_RUNNABLE, arg, size);
}
47 changes: 20 additions & 27 deletions src/memory_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,27 @@ static struct ctl umf_pool_ctl_root;

static void ctl_init(void);

static int CTL_SUBTREE_HANDLER(by_handle_pool)(void *ctx,
umf_ctl_query_source_t source,
void *arg, size_t size,
umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t queryType) {
static umf_result_t CTL_SUBTREE_HANDLER(by_handle_pool)(
void *ctx, umf_ctl_query_source_t source, void *arg, size_t size,
umf_ctl_index_utlist_t *indexes, const char *extra_name,
umf_ctl_query_type_t queryType) {
(void)indexes, (void)source;
umf_memory_pool_handle_t hPool = (umf_memory_pool_handle_t)ctx;
int ret = ctl_query(&umf_pool_ctl_root, hPool, source, extra_name,
queryType, arg, size);
if (ret == -1 &&
errno == EINVAL) { // node was not found in pool_ctl_root, try to
// query the specific pool directly
hPool->ops.ext_ctl(hPool->pool_priv, source, extra_name, arg, size,
queryType);
umf_result_t ret = ctl_query(&umf_pool_ctl_root, hPool, source, extra_name,
queryType, arg, size);
if (ret == UMF_RESULT_ERROR_INVALID_ARGUMENT) {
// Node was not found in pool_ctl_root, try to query the specific pool
ret = hPool->ops.ext_ctl(hPool->pool_priv, source, extra_name, arg,
size, queryType);
}

return 0;
return ret;
}

static int CTL_SUBTREE_HANDLER(default)(void *ctx,
umf_ctl_query_source_t source,
void *arg, size_t size,
umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t queryType) {
static umf_result_t CTL_SUBTREE_HANDLER(default)(
void *ctx, umf_ctl_query_source_t source, void *arg, size_t size,
umf_ctl_index_utlist_t *indexes, const char *extra_name,
umf_ctl_query_type_t queryType) {
(void)indexes, (void)source, (void)ctx;
utils_init_once(&mem_pool_ctl_initialized, ctl_init);
utils_mutex_lock(&ctl_mtx);
Expand Down Expand Up @@ -101,15 +96,13 @@ static int CTL_SUBTREE_HANDLER(default)(void *ctx,

utils_mutex_unlock(&ctl_mtx);

return 0;
return UMF_RESULT_SUCCESS;
}

static int CTL_READ_HANDLER(alloc_count)(void *ctx,
umf_ctl_query_source_t source,
void *arg, size_t size,
umf_ctl_index_utlist_t *indexes,
const char *extra_name,
umf_ctl_query_type_t query_type) {
static umf_result_t CTL_READ_HANDLER(alloc_count)(
void *ctx, umf_ctl_query_source_t source, void *arg, size_t size,
umf_ctl_index_utlist_t *indexes, const char *extra_name,
umf_ctl_query_type_t query_type) {
/* suppress unused-parameter errors */
(void)source, (void)size, (void)indexes, (void)extra_name, (void)query_type;

Expand Down
4 changes: 2 additions & 2 deletions src/memory_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
#include "umf/base.h"
#include "utils_assert.h"

static int CTL_SUBTREE_HANDLER(by_handle_provider)(
static umf_result_t CTL_SUBTREE_HANDLER(by_handle_provider)(
void *ctx, umf_ctl_query_source_t source, void *arg, size_t size,
umf_ctl_index_utlist_t *indexes, const char *extra_name,
umf_ctl_query_type_t queryType) {
(void)indexes, (void)source;
umf_memory_provider_handle_t hProvider = (umf_memory_provider_handle_t)ctx;
hProvider->ops.ext_ctl(hProvider->provider_priv, /*unused*/ 0, extra_name,
arg, size, queryType);
return 0;
return UMF_RESULT_SUCCESS;
}

umf_ctl_node_t CTL_NODE(provider)[] = {
Expand Down
Loading