Skip to content

Commit 228d90a

Browse files
committed
add new error to indicate unknown/unsuported path in ctl
1 parent 6bfdb7d commit 228d90a

File tree

13 files changed

+48
-46
lines changed

13 files changed

+48
-46
lines changed

include/umf/base.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ typedef enum umf_result_t {
4848
UMF_RESULT_ERROR_DEPENDENCY_UNAVAILABLE =
4949
7, ///< External required dependency is unavailable or missing
5050
UMF_RESULT_ERROR_OUT_OF_RESOURCES = 8, ///< Out of internal resources
51-
UMF_RESULT_ERROR_UNKNOWN = 0x7ffffffe ///< Unknown error
51+
UMF_RESULT_ERROR_INVALID_CTL_PATH =
52+
9, ///< CTL path is not supported or not found
53+
UMF_RESULT_ERROR_UNKNOWN = 0x7ffffffe ///< Unknown error
5254
} umf_result_t;
5355

5456
/// @brief Handle to the memory properties structure

include/umf/memory_pool_ops.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ typedef struct umf_memory_pool_ops_t {
166166
/// @param args variable arguments for the operation.
167167
///
168168
/// @return umf_result_t result of the control operation.
169+
/// Implementations must return
170+
/// UMF_RESULT_ERROR_INVALID_CTL_PATH if the given path is not
171+
/// supported.
169172
///
170173
umf_result_t (*ext_ctl)(void *hPool, umf_ctl_query_source_t source,
171174
const char *name, void *arg, size_t size,

include/umf/memory_provider_ops.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ typedef struct umf_memory_provider_ops_t {
283283
/// @param args variable arguments for the operation.
284284
///
285285
/// @return umf_result_t result of the control operation.
286+
/// Implementations must return
287+
/// UMF_RESULT_ERROR_INVALID_CTL_PATH if the given path is not
288+
/// supported.
286289
///
287290
umf_result_t (*ext_ctl)(void *provider, umf_ctl_query_source_t source,
288291
const char *name, void *arg, size_t size,

src/ctl/ctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ ctl_find_and_execute_node(const umf_ctl_node_t *nodes, void *ctx,
492492
// if the appropriate node (leaf or subtree) is not found, then return error
493493
if (n == NULL ||
494494
(n->type != CTL_NODE_LEAF && n->type != CTL_NODE_SUBTREE)) {
495-
ret.value = UMF_RESULT_ERROR_INVALID_ARGUMENT;
495+
ret.value = UMF_RESULT_ERROR_INVALID_CTL_PATH;
496496
goto out;
497497
}
498498

@@ -554,7 +554,7 @@ umf_result_t ctl_query(struct ctl *ctl, void *ctx,
554554

555555
va_end(args_copy);
556556

557-
return ret.is_valid ? ret.value : UMF_RESULT_ERROR_INVALID_ARGUMENT;
557+
return ret.is_valid ? ret.value : UMF_RESULT_ERROR_INVALID_CTL_PATH;
558558
}
559559

560560
/*

src/ctl/ctl_defaults.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ umf_result_t ctl_default_subtree(ctl_default_entry_t **list, utils_mutex_t *mtx,
9494
if (!entry) {
9595
LOG_WARN("Wrong path name: %s", extra_name);
9696
utils_mutex_unlock(mtx);
97-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
97+
return UMF_RESULT_ERROR_INVALID_CTL_PATH;
9898
}
9999

100100
if (entry->value_size > size) {

src/memory_pool.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
*/
99

1010
#include <assert.h>
11+
#include <stdarg.h>
1112
#include <stdint.h>
1213
#include <string.h>
13-
#include <stdarg.h>
1414

1515
#include <umf/base.h>
1616
#include <umf/memory_pool.h>
1717
#include <umf/memory_pool_ops.h>
1818

1919
#include "base_alloc_global.h"
20-
#include "ctl/ctl_internal.h"
2120
#include "ctl/ctl_defaults.h"
21+
#include "ctl/ctl_internal.h"
2222
#include "libumf.h"
2323
#include "memory_pool_internal.h"
2424
#include "memory_provider_internal.h"
@@ -167,7 +167,7 @@ static umf_result_t CTL_SUBTREE_HANDLER(CTL_NONAME, by_handle)(
167167
queryType, arg, size, args2);
168168
va_end(args2);
169169

170-
if (ret == UMF_RESULT_ERROR_INVALID_ARGUMENT) {
170+
if (ret == UMF_RESULT_ERROR_INVALID_CTL_PATH) {
171171
// Node was not found in pool_ctl_root, try to query the specific pool
172172
ret = hPool->ops.ext_ctl(hPool->pool_priv, source, extra_name, arg,
173173
size, queryType, args);
@@ -323,7 +323,7 @@ static umf_result_t CTL_SUBTREE_HANDLER(CTL_NONAME, by_name)(
323323
extra_name, queryType, arg, size, args2);
324324
va_end(args2);
325325

326-
if (r == UMF_RESULT_ERROR_INVALID_ARGUMENT) {
326+
if (r == UMF_RESULT_ERROR_INVALID_CTL_PATH) {
327327
va_copy(args2, args);
328328
r = it->pool->ops.ext_ctl(it->pool->pool_priv, source, extra_name,
329329
arg, size, queryType, args2);
@@ -363,7 +363,8 @@ umfDefaultCtlPoolHandle(void *hPool, umf_ctl_query_source_t operationType,
363363
(void)size;
364364
(void)queryType;
365365
(void)args;
366-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
366+
// if given path is not supported implementation should return UMF_RESULT_ERROR_INVALID_CTL_PATH
367+
return UMF_RESULT_ERROR_INVALID_CTL_PATH;
367368
}
368369

369370
static umf_result_t umfDefaultTrimMemory(void *provider,
@@ -377,13 +378,11 @@ static umf_result_t umfPoolPostInitialize(const umf_memory_pool_ops_t *ops,
377378
void *pool_priv, ...) {
378379
va_list args;
379380
va_start(args, pool_priv);
380-
umf_result_t ret = ops->ext_ctl(pool_priv, CTL_QUERY_PROGRAMMATIC,
381-
"post_initialize", NULL, 0,
382-
CTL_QUERY_RUNNABLE, args);
381+
umf_result_t ret =
382+
ops->ext_ctl(pool_priv, CTL_QUERY_PROGRAMMATIC, "post_initialize", NULL,
383+
0, CTL_QUERY_RUNNABLE, args);
383384
va_end(args);
384-
if (ret == UMF_RESULT_ERROR_INVALID_ARGUMENT) {
385-
ret = UMF_RESULT_ERROR_NOT_SUPPORTED;
386-
}
385+
387386
return ret;
388387
}
389388

@@ -481,8 +480,8 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
481480

482481
ctl_default_apply(pool_default_list, pname, ops->ext_ctl, pool->pool_priv);
483482

484-
ret = umfPoolPostInitialize(ops, pool->pool_priv);
485-
if (ret != UMF_RESULT_SUCCESS && ret != UMF_RESULT_ERROR_NOT_SUPPORTED) {
483+
ret = umfPoolPostInitialize(&pool->ops, pool->pool_priv);
484+
if (ret != UMF_RESULT_SUCCESS && ret != UMF_RESULT_ERROR_INVALID_CTL_PATH) {
486485
LOG_ERR("Failed to post-initialize pool");
487486
goto err_pool_init;
488487
}

src/memory_provider.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
*/
99

1010
#include <assert.h>
11+
#include <stdarg.h>
1112
#include <stdbool.h>
1213
#include <stdio.h>
1314
#include <stdlib.h>
1415
#include <string.h>
15-
#include <stdarg.h>
1616

1717
#include <umf/base.h>
1818
#include <umf/memory_provider.h>
1919

2020
#include "base_alloc.h"
2121
#include "base_alloc_global.h"
22-
#include "ctl/ctl_internal.h"
2322
#include "ctl/ctl_defaults.h"
23+
#include "ctl/ctl_internal.h"
2424
#include "libumf.h"
2525
#include "memory_provider_internal.h"
2626
#include "utils_assert.h"
@@ -51,9 +51,7 @@ static ctl_default_entry_t *provider_default_list = NULL;
5151
static utils_mutex_t provider_default_mtx;
5252
static UTIL_ONCE_FLAG mem_provider_ctl_initialized = UTIL_ONCE_FLAG_INIT;
5353

54-
static void provider_ctl_init(void) {
55-
utils_mutex_init(&provider_default_mtx);
56-
}
54+
static void provider_ctl_init(void) { utils_mutex_init(&provider_default_mtx); }
5755

5856
static umf_result_t CTL_SUBTREE_HANDLER(default)(
5957
void *ctx, umf_ctl_query_source_t source, void *arg, size_t size,
@@ -68,8 +66,7 @@ static umf_result_t CTL_SUBTREE_HANDLER(default)(
6866
}
6967

7068
umf_ctl_node_t CTL_NODE(provider)[] = {CTL_CHILD_WITH_ARG(by_handle),
71-
CTL_LEAF_SUBTREE(default),
72-
CTL_NODE_END};
69+
CTL_LEAF_SUBTREE(default), CTL_NODE_END};
7370

7471
static umf_result_t umfDefaultPurgeLazy(void *provider, void *ptr,
7572
size_t size) {
@@ -155,7 +152,8 @@ umfDefaultCtlHandle(void *provider, umf_ctl_query_source_t operationType,
155152
(void)size;
156153
(void)queryType;
157154
(void)args;
158-
return UMF_RESULT_ERROR_NOT_SUPPORTED;
155+
// if given path is not supported implementation should return UMF_RESULT_ERROR_INVALID_CTL_PATH
156+
return UMF_RESULT_ERROR_INVALID_CTL_PATH;
159157
}
160158

161159
static umf_result_t
@@ -206,7 +204,6 @@ void assignOpsExtDefaults(umf_memory_provider_ops_t *ops) {
206204
ops->ext_get_allocation_properties_size =
207205
umfDefaultGetAllocationPropertiesSize;
208206
}
209-
210207
}
211208

212209
void assignOpsIpcDefaults(umf_memory_provider_ops_t *ops) {
@@ -235,13 +232,11 @@ static umf_result_t umfProviderPostInitialize(umf_memory_provider_ops_t *ops,
235232
void *provider_priv, ...) {
236233
va_list args;
237234
va_start(args, provider_priv);
238-
umf_result_t ret = ops->ext_ctl(provider_priv, CTL_QUERY_PROGRAMMATIC,
239-
"post_initialize", NULL, 0,
240-
CTL_QUERY_RUNNABLE, args);
235+
umf_result_t ret =
236+
ops->ext_ctl(provider_priv, CTL_QUERY_PROGRAMMATIC, "post_initialize",
237+
NULL, 0, CTL_QUERY_RUNNABLE, args);
241238
va_end(args);
242-
if (ret == UMF_RESULT_ERROR_INVALID_ARGUMENT) {
243-
ret = UMF_RESULT_ERROR_NOT_SUPPORTED;
244-
}
239+
245240
return ret;
246241
}
247242

@@ -355,7 +350,7 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
355350
provider->provider_priv);
356351
}
357352
ret = umfProviderPostInitialize(&provider->ops, provider_priv);
358-
if (ret != UMF_RESULT_SUCCESS && ret != UMF_RESULT_ERROR_NOT_SUPPORTED) {
353+
if (ret != UMF_RESULT_SUCCESS && ret != UMF_RESULT_ERROR_INVALID_CTL_PATH) {
359354
LOG_ERR("Failed to post-initialize provider");
360355
umf_ba_global_free(provider);
361356
return ret;

src/pool/pool_scalable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,10 @@ static umf_result_t pool_ctl(void *hPool, umf_ctl_query_source_t operationType,
492492
const char *name, void *arg, size_t size,
493493
umf_ctl_query_type_t query_type, va_list args) {
494494
(void)operationType; // unused
495-
umf_memory_pool_handle_t pool_provider = (umf_memory_pool_handle_t)hPool;
495+
496496
utils_init_once(&ctl_initialized, initialize_pool_ctl);
497-
return ctl_query(&pool_scallable_ctl_root, pool_provider->pool_priv,
498-
CTL_QUERY_PROGRAMMATIC, name, query_type, arg, size, args);
497+
return ctl_query(&pool_scallable_ctl_root, hPool, CTL_QUERY_PROGRAMMATIC,
498+
name, query_type, arg, size, args);
499499
}
500500

501501
static umf_result_t scalable_get_name(void *pool, const char **name) {

test/common/pool.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ typedef struct pool_base_t {
156156
}
157157
umf_result_t ext_ctl(umf_ctl_query_source_t, const char *, void *, size_t,
158158
umf_ctl_query_type_t, va_list) noexcept {
159-
return UMF_RESULT_ERROR_UNKNOWN;
159+
return UMF_RESULT_ERROR_INVALID_CTL_PATH;
160160
}
161161
umf_result_t ext_trim_memory(size_t) noexcept {
162162
return UMF_RESULT_ERROR_UNKNOWN;

test/common/provider.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ typedef struct provider_base_t {
137137
[[maybe_unused]] size_t size,
138138
[[maybe_unused]] umf_ctl_query_type_t queryType,
139139
[[maybe_unused]] va_list args) noexcept {
140-
return UMF_RESULT_ERROR_UNKNOWN;
140+
return UMF_RESULT_ERROR_INVALID_CTL_PATH;
141141
}
142142

143143
umf_result_t ext_get_allocation_properties(

0 commit comments

Comments
 (0)