Skip to content

Commit 954d53e

Browse files
committed
Add IPC-consumer-only mode to devdax provider
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 7706431 commit 954d53e

File tree

1 file changed

+74
-22
lines changed

1 file changed

+74
-22
lines changed

src/provider/provider_devdax_memory.c

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <assert.h>
99
#include <errno.h>
1010
#include <limits.h>
11+
#include <stdbool.h>
1112
#include <stddef.h>
1213
#include <stdio.h>
1314
#include <stdlib.h>
@@ -36,12 +37,13 @@ umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) {
3637
#define TLS_MSG_BUF_LEN 1024
3738

3839
typedef struct devdax_memory_provider_t {
39-
char path[PATH_MAX]; // a path to the device DAX
40-
size_t size; // size of the file used for memory mapping
41-
void *base; // base address of memory mapping
42-
size_t offset; // offset in the file used for memory mapping
43-
utils_mutex_t lock; // lock of ptr and offset
44-
unsigned protection; // combination of OS-specific protection flags
40+
char path[PATH_MAX]; // a path to the device DAX
41+
size_t size; // size of the file used for memory mapping
42+
void *base; // base address of memory mapping
43+
size_t offset; // offset in the file used for memory mapping
44+
utils_mutex_t lock; // lock of ptr and offset
45+
unsigned protection; // combination of OS-specific protection flags
46+
bool ipc_consumer_only_mode; // when path==NULL and size==0
4547
} devdax_memory_provider_t;
4648

4749
typedef struct devdax_last_native_error_t {
@@ -104,13 +106,9 @@ static umf_result_t devdax_initialize(void *params, void **provider) {
104106
umf_devdax_memory_provider_params_t *in_params =
105107
(umf_devdax_memory_provider_params_t *)params;
106108

107-
if (in_params->path == NULL) {
108-
LOG_ERR("devdax path is missing");
109-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
110-
}
111-
112-
if (in_params->size == 0) {
113-
LOG_ERR("devdax size is 0");
109+
if (!(!in_params->path == !in_params->size)) {
110+
LOG_ERR(
111+
"both path and size of the devdax have to be provided or both not");
114112
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
115113
}
116114

@@ -122,6 +120,14 @@ static umf_result_t devdax_initialize(void *params, void **provider) {
122120

123121
memset(devdax_provider, 0, sizeof(*devdax_provider));
124122

123+
if (in_params->path == NULL && in_params->size == 0) {
124+
// IPC-consumer-only mode
125+
devdax_provider->ipc_consumer_only_mode = true;
126+
LOG_INFO("devdax provider started in the IPC-consumer-only mode");
127+
*provider = devdax_provider;
128+
return UMF_RESULT_SUCCESS;
129+
}
130+
125131
ret = devdax_translate_params(in_params, devdax_provider);
126132
if (ret != UMF_RESULT_SUCCESS) {
127133
goto err_free_devdax_provider;
@@ -181,8 +187,12 @@ static void devdax_finalize(void *provider) {
181187
}
182188

183189
devdax_memory_provider_t *devdax_provider = provider;
184-
utils_mutex_destroy_not_free(&devdax_provider->lock);
185-
utils_munmap(devdax_provider->base, devdax_provider->size);
190+
191+
if (!devdax_provider->ipc_consumer_only_mode) {
192+
utils_mutex_destroy_not_free(&devdax_provider->lock);
193+
utils_munmap(devdax_provider->base, devdax_provider->size);
194+
}
195+
186196
umf_ba_global_free(devdax_provider);
187197
}
188198

@@ -224,7 +234,19 @@ static umf_result_t devdax_alloc(void *provider, size_t size, size_t alignment,
224234
void **resultPtr) {
225235
int ret;
226236

227-
if (provider == NULL || resultPtr == NULL) {
237+
if (provider == NULL) {
238+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
239+
}
240+
241+
devdax_memory_provider_t *devdax_provider =
242+
(devdax_memory_provider_t *)provider;
243+
244+
if (devdax_provider->ipc_consumer_only_mode) {
245+
LOG_ERR("devdax provider is working in the IPC-consumer-only mode");
246+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
247+
}
248+
249+
if (resultPtr == NULL) {
228250
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
229251
}
230252

@@ -237,9 +259,6 @@ static umf_result_t devdax_alloc(void *provider, size_t size, size_t alignment,
237259
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
238260
}
239261

240-
devdax_memory_provider_t *devdax_provider =
241-
(devdax_memory_provider_t *)provider;
242-
243262
void *addr = NULL;
244263
errno = 0;
245264
ret = devdax_alloc_aligned(size, alignment, devdax_provider->base,
@@ -323,7 +342,19 @@ static umf_result_t devdax_purge_lazy(void *provider, void *ptr, size_t size) {
323342
}
324343

325344
static umf_result_t devdax_purge_force(void *provider, void *ptr, size_t size) {
326-
if (provider == NULL || ptr == NULL) {
345+
if (provider == NULL) {
346+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
347+
}
348+
349+
devdax_memory_provider_t *devdax_provider =
350+
(devdax_memory_provider_t *)provider;
351+
352+
if (devdax_provider->ipc_consumer_only_mode) {
353+
LOG_ERR("devdax provider is working in the IPC-consumer-only mode");
354+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
355+
}
356+
357+
if (ptr == NULL) {
327358
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
328359
}
329360

@@ -345,17 +376,38 @@ static const char *devdax_get_name(void *provider) {
345376
static umf_result_t devdax_allocation_split(void *provider, void *ptr,
346377
size_t totalSize,
347378
size_t firstSize) {
348-
(void)provider;
349379
(void)ptr;
350380
(void)totalSize;
351381
(void)firstSize;
352382

383+
if (provider == NULL) {
384+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
385+
}
386+
387+
devdax_memory_provider_t *devdax_provider =
388+
(devdax_memory_provider_t *)provider;
389+
390+
if (devdax_provider->ipc_consumer_only_mode) {
391+
LOG_ERR("devdax provider is working in the IPC-consumer-only mode");
392+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
393+
}
394+
353395
return UMF_RESULT_SUCCESS;
354396
}
355397

356398
static umf_result_t devdax_allocation_merge(void *provider, void *lowPtr,
357399
void *highPtr, size_t totalSize) {
358-
(void)provider;
400+
if (provider == NULL) {
401+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
402+
}
403+
404+
devdax_memory_provider_t *devdax_provider =
405+
(devdax_memory_provider_t *)provider;
406+
407+
if (devdax_provider->ipc_consumer_only_mode) {
408+
LOG_ERR("devdax provider is working in the IPC-consumer-only mode");
409+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
410+
}
359411

360412
if ((uintptr_t)highPtr <= (uintptr_t)lowPtr) {
361413
return UMF_RESULT_ERROR_INVALID_ARGUMENT;

0 commit comments

Comments
 (0)