Search is not available for this dataset
repo
stringlengths 2
152
⌀ | file
stringlengths 15
239
| code
stringlengths 0
58.4M
| file_length
int64 0
58.4M
| avg_line_length
float64 0
1.81M
| max_line_length
int64 0
12.7M
| extension_type
stringclasses 364
values |
---|---|---|---|---|---|---|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/log_pool_lock/log_pool_lock.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* log_pool_lock.c -- unit test which checks whether it's possible to
* simultaneously open the same log pool
*/
#include "unittest.h"
static void
test_reopen(const char *path)
{
PMEMlogpool *log1 = pmemlog_create(path, PMEMLOG_MIN_POOL,
S_IWUSR | S_IRUSR);
if (!log1)
UT_FATAL("!create");
PMEMlogpool *log2 = pmemlog_open(path);
if (log2)
UT_FATAL("pmemlog_open should not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemlog_open failed but for unexpected reason");
pmemlog_close(log1);
log2 = pmemlog_open(path);
if (!log2)
UT_FATAL("pmemlog_open should succeed after close");
pmemlog_close(log2);
UNLINK(path);
}
#ifndef _WIN32
static void
test_open_in_different_process(int argc, char **argv, unsigned sleep)
{
pid_t pid = fork();
PMEMlogpool *log;
char *path = argv[1];
if (pid < 0)
UT_FATAL("fork failed");
if (pid == 0) {
/* child */
if (sleep)
usleep(sleep);
while (os_access(path, R_OK))
usleep(100 * 1000);
log = pmemlog_open(path);
if (log)
UT_FATAL("pmemlog_open after fork should not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemlog_open after fork failed but for "
"unexpected reason");
exit(0);
}
log = pmemlog_create(path, PMEMLOG_MIN_POOL, S_IWUSR | S_IRUSR);
if (!log)
UT_FATAL("!create");
int status;
if (waitpid(pid, &status, 0) < 0)
UT_FATAL("!waitpid failed");
if (!WIFEXITED(status))
UT_FATAL("child process failed");
pmemlog_close(log);
UNLINK(path);
}
#else
static void
test_open_in_different_process(int argc, char **argv, unsigned sleep)
{
PMEMlogpool *log;
if (sleep > 0)
return;
char *path = argv[1];
/* before starting the 2nd process, create a pool */
log = pmemlog_create(path, PMEMLOG_MIN_POOL, S_IWUSR | S_IRUSR);
if (!log)
UT_FATAL("!create");
/*
* "X" is pass as an additional param to the new process
* created by ut_spawnv to distinguish second process on Windows
*/
uintptr_t result = ut_spawnv(argc, argv, "X", NULL);
if (result == -1)
UT_FATAL("Create new process failed error: %d", GetLastError());
pmemlog_close(log);
}
#endif
int
main(int argc, char *argv[])
{
START(argc, argv, "log_pool_lock");
if (argc < 2)
UT_FATAL("usage: %s path", argv[0]);
if (argc == 2) {
test_reopen(argv[1]);
test_open_in_different_process(argc, argv, 0);
for (unsigned i = 1; i < 100000; i *= 2)
test_open_in_different_process(argc, argv, i);
} else if (argc == 3) {
PMEMlogpool *log;
/* 2nd arg used by windows for 2 process test */
log = pmemlog_open(argv[1]);
if (log)
UT_FATAL("pmemlog_open after create process should "
"not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemlog_open after create process failed "
"but for unexpected reason");
}
DONE(NULL);
}
| 4,392 | 25.14881 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_dirty/cto_dirty.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_dirty -- unit test for detecting inconsistent pool
*
* usage: cto_dirty filename [phase]
*/
#include "unittest.h"
#define POOL_SIZE (2 * PMEMCTO_MIN_POOL)
#define EXIT_ON(x, y) do {\
if ((x) == (y)) {\
exit(1);\
}\
} while (0)
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_dirty");
if (argc < 2)
UT_FATAL("usage: %s filename [phase]", argv[0]);
PMEMctopool *pcp;
int phase = 0;
if (argc > 2) {
phase = atoi(argv[2]);
pcp = pmemcto_create(argv[1], "test", POOL_SIZE, 0666);
UT_ASSERTne(pcp, NULL);
} else {
pcp = pmemcto_open(argv[1], "test");
if (pcp == NULL) {
UT_ERR("pmemcto_open: %s", pmemcto_errormsg());
goto end;
}
}
EXIT_ON(phase, 1);
void *ptr = pmemcto_malloc(pcp, 16);
UT_ASSERTne(ptr, NULL);
pmemcto_set_root_pointer(pcp, ptr);
EXIT_ON(phase, 2);
pmemcto_free(pcp, ptr);
pmemcto_set_root_pointer(pcp, NULL);
pmemcto_close(pcp);
end:
DONE(NULL);
}
| 2,535 | 27.494382 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_out_of_memory/vmem_out_of_memory.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_out_of_memory -- unit test for vmem_out_of_memory
*
* usage: vmem_out_of_memory [directory]
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_out_of_memory");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
if (dir == NULL) {
/* allocate memory for function vmem_create_in_region() */
mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
/* allocate all memory */
void *prev = NULL;
for (;;) {
void **next = vmem_malloc(vmp, sizeof(void *));
if (next == NULL) {
/* out of memory */
break;
}
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(next, mem_pool, VMEM_MIN_POOL);
}
*next = prev;
prev = next;
}
UT_ASSERTne(prev, NULL);
/* free all allocations */
while (prev != NULL) {
void **act = prev;
prev = *act;
vmem_free(vmp, act);
}
vmem_delete(vmp);
DONE(NULL);
}
| 2,835 | 27.646465 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/remote_obj_basic/remote_obj_basic.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* remote_obj_basic.c -- unit test for remote tests support
*
* usage: remote_obj_basic <create|open> <poolset-file>
*/
#include "unittest.h"
#define LAYOUT_NAME "remote_obj_basic"
int
main(int argc, char *argv[])
{
PMEMobjpool *pop;
START(argc, argv, "remote_obj_basic");
if (argc != 3)
UT_FATAL("usage: %s <create|open> <poolset-file>", argv[0]);
const char *mode = argv[1];
const char *file = argv[2];
if (strcmp(mode, "create") == 0) {
if ((pop = pmemobj_create(file, LAYOUT_NAME, 0,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", file);
else
UT_OUT("The pool set %s has been created", file);
} else if (strcmp(mode, "open") == 0) {
if ((pop = pmemobj_open(file, LAYOUT_NAME)) == NULL)
UT_FATAL("!pmemobj_open: %s", file);
else
UT_OUT("The pool set %s has been opened", file);
} else {
UT_FATAL("wrong mode: %s\n", argv[1]);
}
pmemobj_close(pop);
DONE(NULL);
}
| 2,534 | 31.922078 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_ctl_debug/obj_ctl_debug.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_ctl_debug.c -- tests for the ctl debug namesapce entry points
*/
#include "unittest.h"
#include "../../libpmemobj/obj.h"
#define LAYOUT "obj_ctl_debug"
#define BUFFER_SIZE 128
#define ALLOC_PATTERN 0xAC
static void
test_alloc_pattern(PMEMobjpool *pop)
{
int ret;
int pattern;
PMEMoid oid;
/* check default pattern */
ret = pmemobj_ctl_get(pop, "debug.heap.alloc_pattern", &pattern);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(pattern, PALLOC_CTL_DEBUG_NO_PATTERN);
/* check set pattern */
pattern = ALLOC_PATTERN;
ret = pmemobj_ctl_set(pop, "debug.heap.alloc_pattern", &pattern);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(pop->heap.alloc_pattern, pattern);
/* check alloc with pattern */
ret = pmemobj_alloc(pop, &oid, BUFFER_SIZE, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
char *buff = pmemobj_direct(oid);
int i;
for (i = 0; i < BUFFER_SIZE; i++)
/* should trigger memcheck error: read uninitialized values */
UT_ASSERTeq(*(buff + i), (char)pattern);
pmemobj_free(&oid);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_ctl_debug");
if (argc < 2)
UT_FATAL("usage: %s filename", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop;
if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_open: %s", path);
test_alloc_pattern(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 2,967 | 29.597938 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_list_macro/obj_list_macro.c
|
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_list_macro.c -- unit tests for list module
*/
#include <stddef.h>
#include "libpmemobj.h"
#include "unittest.h"
TOID_DECLARE(struct item, 0);
TOID_DECLARE(struct list, 1);
struct item {
int id;
POBJ_LIST_ENTRY(struct item) next;
};
struct list {
POBJ_LIST_HEAD(listhead, struct item) head;
};
/* global lists */
static TOID(struct list) List;
static TOID(struct list) List_sec;
#define LAYOUT_NAME "list_macros"
/* usage macros */
#define FATAL_USAGE()\
UT_FATAL("usage: obj_list_macro <file> [PRnifr]")
#define FATAL_USAGE_PRINT()\
UT_FATAL("usage: obj_list_macro <file> P:<list>")
#define FATAL_USAGE_PRINT_REVERSE()\
UT_FATAL("usage: obj_list_macro <file> R:<list>")
#define FATAL_USAGE_INSERT()\
UT_FATAL("usage: obj_list_macro <file> i:<where>:<num>[:<id>]")
#define FATAL_USAGE_INSERT_NEW()\
UT_FATAL("usage: obj_list_macro <file> n:<where>:<num>[:<id>]")
#define FATAL_USAGE_REMOVE_FREE()\
UT_FATAL("usage: obj_list_macro <file> f:<list>:<num>")
#define FATAL_USAGE_REMOVE()\
UT_FATAL("usage: obj_list_macro <file> r:<list>:<num>")
#define FATAL_USAGE_MOVE()\
UT_FATAL("usage: obj_list_macro <file> m:<num>:<where>:<num>")
/*
* get_item_list -- get nth item from list
*/
static TOID(struct item)
get_item_list(TOID(struct list) list, int n)
{
TOID(struct item) item;
if (n >= 0) {
POBJ_LIST_FOREACH(item, &D_RO(list)->head, next) {
if (n == 0)
return item;
n--;
}
} else {
POBJ_LIST_FOREACH_REVERSE(item, &D_RO(list)->head, next) {
n++;
if (n == 0)
return item;
}
}
return TOID_NULL(struct item);
}
/*
* do_print -- print list elements in normal order
*/
static void
do_print(PMEMobjpool *pop, const char *arg)
{
int L; /* which list */
if (sscanf(arg, "P:%d", &L) != 1)
FATAL_USAGE_PRINT();
TOID(struct item) item;
if (L == 1) {
UT_OUT("list:");
POBJ_LIST_FOREACH(item, &D_RW(List)->head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else if (L == 2) {
UT_OUT("list sec:");
POBJ_LIST_FOREACH(item, &D_RW(List_sec)->head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else {
FATAL_USAGE_PRINT();
}
}
/*
* do_print_reverse -- print list elements in reverse order
*/
static void
do_print_reverse(PMEMobjpool *pop, const char *arg)
{
int L; /* which list */
if (sscanf(arg, "R:%d", &L) != 1)
FATAL_USAGE_PRINT_REVERSE();
TOID(struct item) item;
if (L == 1) {
UT_OUT("list reverse:");
POBJ_LIST_FOREACH_REVERSE(item, &D_RW(List)->head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else if (L == 2) {
UT_OUT("list sec reverse:");
POBJ_LIST_FOREACH_REVERSE(item, &D_RW(List_sec)->head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else {
FATAL_USAGE_PRINT_REVERSE();
}
}
/*
* item_constructor -- constructor which sets the item's id to
* new value
*/
static int
item_constructor(PMEMobjpool *pop, void *ptr, void *arg)
{
int id = *(int *)arg;
struct item *item = (struct item *)ptr;
item->id = id;
UT_OUT("constructor(id = %d)", id);
return 0;
}
/*
* do_insert_new -- insert new element to list
*/
static void
do_insert_new(PMEMobjpool *pop, const char *arg)
{
int n; /* which element on List */
int before;
int id;
int ret = sscanf(arg, "n:%d:%d:%d", &before, &n, &id);
if (ret != 3 && ret != 2)
FATAL_USAGE_INSERT_NEW();
int ptr = (ret == 3) ? id : 0;
TOID(struct item) item;
if (POBJ_LIST_EMPTY(&D_RW(List)->head)) {
POBJ_LIST_INSERT_NEW_HEAD(pop, &D_RW(List)->head, next,
sizeof(struct item), item_constructor, &ptr);
if (POBJ_LIST_EMPTY(&D_RW(List)->head))
UT_FATAL("POBJ_LIST_INSERT_NEW_HEAD");
} else {
item = get_item_list(List, n);
UT_ASSERT(!TOID_IS_NULL(item));
if (!before) {
POBJ_LIST_INSERT_NEW_AFTER(pop, &D_RW(List)->head,
item, next, sizeof(struct item),
item_constructor, &ptr);
if (TOID_IS_NULL(POBJ_LIST_NEXT(item, next)))
UT_FATAL("POBJ_LIST_INSERT_NEW_AFTER");
} else {
POBJ_LIST_INSERT_NEW_BEFORE(pop, &D_RW(List)->head,
item, next, sizeof(struct item),
item_constructor, &ptr);
if (TOID_IS_NULL(POBJ_LIST_PREV(item, next)))
UT_FATAL("POBJ_LIST_INSERT_NEW_BEFORE");
}
}
}
/*
* do_insert -- insert element to list
*/
static void
do_insert(PMEMobjpool *pop, const char *arg)
{
int n; /* which element on List */
int before;
int id;
int ret = sscanf(arg, "i:%d:%d:%d", &before, &n, &id);
if (ret != 3 && ret != 2)
FATAL_USAGE_INSERT();
int ptr = (ret == 3) ? id : 0;
TOID(struct item) item;
POBJ_NEW(pop, &item, struct item, item_constructor, &ptr);
UT_ASSERT(!TOID_IS_NULL(item));
errno = 0;
if (POBJ_LIST_EMPTY(&D_RW(List)->head)) {
ret = POBJ_LIST_INSERT_HEAD(pop, &D_RW(List)->head,
item, next);
if (ret) {
UT_ASSERTeq(ret, -1);
UT_ASSERTne(errno, 0);
UT_FATAL("POBJ_LIST_INSERT_HEAD");
}
if (POBJ_LIST_EMPTY(&D_RW(List)->head))
UT_FATAL("POBJ_LIST_INSERT_HEAD");
} else {
TOID(struct item) elm = get_item_list(List, n);
UT_ASSERT(!TOID_IS_NULL(elm));
if (!before) {
ret = POBJ_LIST_INSERT_AFTER(pop, &D_RW(List)->head,
elm, item, next);
if (ret) {
UT_ASSERTeq(ret, -1);
UT_ASSERTne(errno, 0);
UT_FATAL("POBJ_LIST_INSERT_AFTER");
}
if (!TOID_EQUALS(item, POBJ_LIST_NEXT(elm, next)))
UT_FATAL("POBJ_LIST_INSERT_AFTER");
} else {
ret = POBJ_LIST_INSERT_BEFORE(pop, &D_RW(List)->head,
elm, item, next);
if (ret) {
UT_ASSERTeq(ret, -1);
UT_ASSERTne(errno, 0);
UT_FATAL("POBJ_LIST_INSERT_BEFORE");
}
if (!TOID_EQUALS(item, POBJ_LIST_PREV(elm, next)))
UT_FATAL("POBJ_LIST_INSERT_BEFORE");
}
}
}
/*
* do_remove_free -- remove and free element from list
*/
static void
do_remove_free(PMEMobjpool *pop, const char *arg)
{
int L; /* which list */
int n; /* which element */
if (sscanf(arg, "f:%d:%d", &L, &n) != 2)
FATAL_USAGE_REMOVE_FREE();
TOID(struct item) item;
TOID(struct list) tmp_list;
if (L == 1)
tmp_list = List;
else if (L == 2)
tmp_list = List_sec;
else
FATAL_USAGE_REMOVE_FREE();
if (POBJ_LIST_EMPTY(&D_RW(tmp_list)->head))
return;
item = get_item_list(tmp_list, n);
UT_ASSERT(!TOID_IS_NULL(item));
errno = 0;
int ret = POBJ_LIST_REMOVE_FREE(pop, &D_RW(tmp_list)->head,
item, next);
if (ret) {
UT_ASSERTeq(ret, -1);
UT_ASSERTne(errno, 0);
UT_FATAL("POBJ_LIST_REMOVE_FREE");
}
}
/*
* do_remove -- remove element from list
*/
static void
do_remove(PMEMobjpool *pop, const char *arg)
{
int L; /* which list */
int n; /* which element */
if (sscanf(arg, "r:%d:%d", &L, &n) != 2)
FATAL_USAGE_REMOVE();
TOID(struct item) item;
TOID(struct list) tmp_list;
if (L == 1)
tmp_list = List;
else if (L == 2)
tmp_list = List_sec;
else
FATAL_USAGE_REMOVE_FREE();
if (POBJ_LIST_EMPTY(&D_RW(tmp_list)->head))
return;
item = get_item_list(tmp_list, n);
UT_ASSERT(!TOID_IS_NULL(item));
errno = 0;
int ret = POBJ_LIST_REMOVE(pop, &D_RW(tmp_list)->head, item, next);
if (ret) {
UT_ASSERTeq(ret, -1);
UT_ASSERTne(errno, 0);
UT_FATAL("POBJ_LIST_REMOVE");
}
POBJ_FREE(&item);
}
/*
* do_move -- move element from one list to another
*/
static void
do_move(PMEMobjpool *pop, const char *arg)
{
int n;
int d;
int before;
if (sscanf(arg, "m:%d:%d:%d", &n, &before, &d) != 3)
FATAL_USAGE_MOVE();
int ret;
errno = 0;
if (POBJ_LIST_EMPTY(&D_RW(List)->head))
return;
if (POBJ_LIST_EMPTY(&D_RW(List_sec)->head)) {
ret = POBJ_LIST_MOVE_ELEMENT_HEAD(pop, &D_RW(List)->head,
&D_RW(List_sec)->head,
get_item_list(List, n),
next, next);
if (ret) {
UT_ASSERTeq(ret, -1);
UT_ASSERTne(errno, 0);
UT_FATAL("POBJ_LIST_MOVE_ELEMENT_HEAD");
}
} else {
if (before) {
ret = POBJ_LIST_MOVE_ELEMENT_BEFORE(pop,
&D_RW(List)->head,
&D_RW(List_sec)->head,
get_item_list(List_sec, d),
get_item_list(List, n),
next, next);
if (ret) {
UT_ASSERTeq(ret, -1);
UT_ASSERTne(errno, 0);
UT_FATAL("POBJ_LIST_MOVE_ELEMENT_BEFORE");
}
} else {
ret = POBJ_LIST_MOVE_ELEMENT_AFTER(pop,
&D_RW(List)->head,
&D_RW(List_sec)->head,
get_item_list(List_sec, d),
get_item_list(List, n),
next, next);
if (ret) {
UT_ASSERTeq(ret, -1);
UT_ASSERTne(errno, 0);
UT_FATAL("POBJ_LIST_MOVE_ELEMENT_AFTER");
}
}
}
}
/*
* do_cleanup -- de-initialization function
*/
static void
do_cleanup(PMEMobjpool *pop, TOID(struct list) list)
{
int ret;
errno = 0;
while (!POBJ_LIST_EMPTY(&D_RW(list)->head)) {
TOID(struct item) tmp = POBJ_LIST_FIRST(&D_RW(list)->head);
ret = POBJ_LIST_REMOVE_FREE(pop, &D_RW(list)->head, tmp, next);
UT_ASSERTeq(errno, 0);
UT_ASSERTeq(ret, 0);
}
POBJ_FREE(&list);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_list_macro");
if (argc < 2)
FATAL_USAGE();
const char *path = argv[1];
PMEMobjpool *pop;
if ((pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
POBJ_ZNEW(pop, &List, struct list);
POBJ_ZNEW(pop, &List_sec, struct list);
int i;
for (i = 2; i < argc; i++) {
switch (argv[i][0]) {
case 'P':
do_print(pop, argv[i]);
break;
case 'R':
do_print_reverse(pop, argv[i]);
break;
case 'n':
do_insert_new(pop, argv[i]);
break;
case 'i':
do_insert(pop, argv[i]);
break;
case 'f':
do_remove_free(pop, argv[i]);
break;
case 'r':
do_remove(pop, argv[i]);
break;
case 'm':
do_move(pop, argv[i]);
break;
default:
FATAL_USAGE();
}
}
do_cleanup(pop, List);
do_cleanup(pop, List_sec);
pmemobj_close(pop);
DONE(NULL);
}
| 11,141 | 23.596026 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_pool/cto_pool.c
|
/*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_pool.c -- unit test for pmemcto_create() and pmemcto_open()
*
* usage: cto_pool op path layout [poolsize mode]
*
* op can be:
* c - create
* o - open
*
* "poolsize" and "mode" arguments are ignored for "open"
*/
#include "unittest.h"
#define MB ((size_t)1 << 20)
static void
pool_create(const char *path, const char *layout, size_t poolsize,
unsigned mode)
{
PMEMctopool *pcp = pmemcto_create(path, layout, poolsize, mode);
if (pcp == NULL)
UT_OUT("!%s: pmemcto_create", path);
else {
os_stat_t stbuf;
STAT(path, &stbuf);
UT_OUT("%s: file size %zu mode 0%o",
path, stbuf.st_size,
stbuf.st_mode & 0777);
pmemcto_close(pcp);
int result = pmemcto_check(path, layout);
if (result < 0)
UT_OUT("!%s: pmemcto_check", path);
else if (result == 0)
UT_OUT("%s: pmemcto_check: not consistent", path);
}
}
static void
pool_open(const char *path, const char *layout)
{
PMEMctopool *pcp = pmemcto_open(path, layout);
if (pcp == NULL)
UT_OUT("!%s: pmemcto_open", path);
else {
UT_OUT("%s: pmemcto_open: Success", path);
pmemcto_close(pcp);
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_pool");
if (argc < 4)
UT_FATAL("usage: %s op path layout [poolsize mode]", argv[0]);
char *layout = NULL;
size_t poolsize;
unsigned mode;
if (strcmp(argv[3], "EMPTY") == 0)
layout = "";
else if (strcmp(argv[3], "NULL") != 0)
layout = argv[3];
switch (argv[1][0]) {
case 'c':
poolsize = strtoul(argv[4], NULL, 0) * MB; /* in megabytes */
mode = strtoul(argv[5], NULL, 8);
pool_create(argv[2], layout, poolsize, mode);
break;
case 'o':
pool_open(argv[2], layout);
break;
default:
UT_FATAL("unknown operation");
}
DONE(NULL);
}
| 3,327 | 26.278689 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_valgrind_region/vmem_valgrind_region.c
|
/*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_valgrind_region.c -- unit test for vmem_valgrind_region
*/
#include "unittest.h"
#define POOLSIZE (16 << 20)
#define CHUNKSIZE (4 << 20)
#define NOBJS 8
struct foo {
size_t size;
char data[1]; /* dynamically sized */
};
static struct foo *objs[NOBJS];
static void
do_alloc(VMEM *vmp)
{
size_t size = 256;
/* allocate objects */
for (int i = 0; i < NOBJS; i++) {
objs[i] = vmem_malloc(vmp, size + sizeof(size_t));
UT_ASSERTne(objs[i], NULL);
objs[i]->size = size;
memset(objs[i]->data, '0' + i, size - 1);
objs[i]->data[size] = '\0';
size *= 4;
}
}
static void
do_iterate(void)
{
/* dump selected objects */
for (int i = 0; i < NOBJS; i++)
UT_OUT("%p size %zu", objs[i], objs[i]->size);
}
static void
do_free(VMEM *vmp)
{
/* free objects */
for (int i = 0; i < NOBJS; i++)
vmem_free(vmp, objs[i]);
}
int
main(int argc, char *argv[])
{
VMEM *vmp;
START(argc, argv, "vmem_valgrind_region");
if (argc < 2)
UT_FATAL("usage: %s <0..4>", argv[0]);
int test = atoi(argv[1]);
/*
* Allocate memory for vmem_create_in_region().
* Reserve more space for test case #4.
*/
char *addr = MMAP_ANON_ALIGNED(VMEM_MIN_POOL + CHUNKSIZE,
CHUNKSIZE);
vmp = vmem_create_in_region(addr, POOLSIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
do_alloc(vmp);
switch (test) {
case 0:
/* free objects and delete pool */
do_free(vmp);
vmem_delete(vmp);
break;
case 1:
/* delete pool without freeing objects */
vmem_delete(vmp);
break;
case 2:
/*
* delete pool without freeing objects
* try to access objects
* expected: use of uninitialized value
*/
vmem_delete(vmp);
do_iterate();
break;
case 3:
/*
* delete pool without freeing objects
* re-create pool in the same region
* try to access objects
* expected: invalid read
*/
vmem_delete(vmp);
vmp = vmem_create_in_region(addr, POOLSIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
do_iterate();
vmem_delete(vmp);
break;
case 4:
/*
* delete pool without freeing objects
* re-create pool in the overlapping region
* try to access objects
* expected: use of uninitialized value & invalid read
*/
vmem_delete(vmp);
vmp = vmem_create_in_region(addr + CHUNKSIZE, POOLSIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
do_iterate();
vmem_delete(vmp);
break;
default:
UT_FATAL("wrong test case %d", test);
}
MUNMAP(addr, VMEM_MIN_POOL + CHUNKSIZE);
DONE(NULL);
}
| 4,094 | 23.668675 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmempool_transform_remote/config.sh
|
#!/usr/bin/env bash
#
# Copyright 2017, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# pmempool_transform_remote/config.sh -- configuration of unit tests
#
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 1,784 | 41.5 | 73 |
sh
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmempool_transform_remote/common.sh
|
#!/usr/bin/env bash
#
# Copyright 2017-2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# pmempool_transform_remote/common.sh -- commons for pmempool transform tests
# with remote replication
#
set -e
require_nodes 2
require_node_libfabric 0 $RPMEM_PROVIDER
require_node_libfabric 1 $RPMEM_PROVIDER
setup
init_rpmem_on_node 1 0
require_node_log_files 1 pmemobj$UNITTEST_NUM.log
require_node_log_files 1 pmempool$UNITTEST_NUM.log
LOG=out${UNITTEST_NUM}.log
LOG_TEMP=out${UNITTEST_NUM}_part.log
rm -f $LOG && touch $LOG
rm -f $LOG_TEMP && touch $LOG_TEMP
rm_files_from_node 0 ${NODE_TEST_DIR[0]}/$LOG
rm_files_from_node 1 ${NODE_TEST_DIR[1]}/$LOG
LAYOUT=OBJ_LAYOUT
POOLSET_LOCAL_IN=poolset.in
POOLSET_LOCAL_OUT=poolset.out
POOLSET_REMOTE=poolset.remote
POOLSET_REMOTE1=poolset.remote1
POOLSET_REMOTE2=poolset.remote2
# CLI scripts for writing and reading some data hitting all the parts
WRITE_SCRIPT="pmemobjcli.write.script"
READ_SCRIPT="pmemobjcli.read.script"
copy_files_to_node 1 ${NODE_DIR[1]} $WRITE_SCRIPT $READ_SCRIPT
DUMP_INFO_LOG="../pmempool info"
DUMP_INFO_LOG_REMOTE="$DUMP_INFO_LOG -f obj"
DUMP_INFO_SED="sed -e '/^Checksum/d' -e '/^Creation/d' -e '/^Previous replica UUID/d' -e '/^Next replica UUID/d'"
DUMP_INFO_SED_REMOTE="$DUMP_INFO_SED -e '/^Previous part UUID/d' -e '/^Next part UUID/d'"
function dump_info_log() {
local node=$1
local poolset=$2
local name=$3
local ignore=$4
local sed_cmd="$DUMP_INFO_SED"
if [ -n "$ignore" ]; then
sed_cmd="$sed_cmd -e '/^$ignore/d'"
fi
expect_normal_exit run_on_node $node "\"$DUMP_INFO_LOG $poolset | $sed_cmd >> $name\""
}
function dump_info_log_remote() {
local node=$1
local poolset=$2
local name=$3
local ignore=$4
local sed_cmd="$DUMP_INFO_SED_REMOTE"
if [ -n "$ignore" ]; then
sed_cmd="$sed_cmd -e '/^$ignore/d'"
fi
expect_normal_exit run_on_node $node "\"$DUMP_INFO_LOG_REMOTE $poolset | $sed_cmd >> $name\""
}
function diff_log() {
local node=$1
local f1=$2
local f2=$3
expect_normal_exit run_on_node $node "\"[ -s $f1 ] && [ -s $f2 ] && diff $f1 $f2\""
}
exec_pmemobjcli_script() {
local node=$1
local script=$2
local poolset=$3
local out=$4
expect_normal_exit run_on_node $node "\"../pmemobjcli -s $script $poolset > $out \""
}
| 3,784 | 30.541667 | 113 |
sh
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/win_signal/win_signal.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* win_signal.c -- test signal related routines
*/
#include "unittest.h"
extern int sys_siglist_size;
int
main(int argc, char *argv[])
{
int sig;
START(argc, argv, "win_signal");
for (sig = 0; sig < sys_siglist_size; sig++) {
UT_OUT("%d; %s", sig, os_strsignal(sig));
}
for (sig = 33; sig < 66; sig++) {
UT_OUT("%d; %s", sig, os_strsignal(sig));
}
DONE(NULL);
}
| 1,983 | 35.072727 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_extent/util_extent.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_extent.c -- unit test for the linux fs extent query API
*
*/
#include "unittest.h"
#include "extent.h"
/*
* test_size -- test if sum of all file's extents sums up to the file's size
*/
static void
test_size(const char *path, size_t size)
{
size_t total_length = 0;
struct extents *exts = MALLOC(sizeof(struct extents));
UT_ASSERT(os_extents_count(path, exts) >= 0);
UT_OUT("exts->extents_count: %u", exts->extents_count);
if (exts->extents_count > 0) {
exts->extents = MALLOC(exts->extents_count *
sizeof(struct extent));
UT_ASSERTeq(os_extents_get(path, exts), 0);
unsigned e;
for (e = 0; e < exts->extents_count; e++)
total_length += exts->extents[e].length;
FREE(exts->extents);
}
FREE(exts);
UT_ASSERTeq(total_length, size);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_extent");
if (argc != 3)
UT_FATAL("usage: %s file file-size", argv[0]);
long long isize = atoi(argv[2]);
UT_ASSERT(isize > 0);
size_t size = (size_t)isize;
test_size(argv[1], size);
DONE(NULL);
}
| 2,651 | 28.797753 | 76 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/win_poolset_unmap/win_poolset_unmap.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* win_poolset_unmap.c -- test for windows mmap destructor.
*
* It checks whether all mappings are properly unmpapped and memory is properly
* unreserved when auto growing pool is used.
*/
#include "unittest.h"
#include "os.h"
#include "libpmemobj.h"
#define KILOBYTE (1 << 10)
#define MEGABYTE (1 << 20)
#define LAYOUT_NAME "poolset_unmap"
int
main(int argc, char *argv[])
{
START(argc, argv, "win_poolset_unmap");
if (argc != 2)
UT_FATAL("usage: %s path", argv[0]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, 0,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
MEMORY_BASIC_INFORMATION basic_info;
SIZE_T bytes_returned;
SIZE_T offset = 0;
bytes_returned = VirtualQuery(pop, &basic_info,
sizeof(basic_info));
/*
* When opening pool, we try to remove all permissions on header.
* If this action fails VirtualQuery will return one region with
* size 8MB. If it succeeds, RegionSize will be equal to 4KB due
* to different header and rest of the mapping permissions.
*/
if (basic_info.RegionSize == 4 * KILOBYTE) {
/* header */
UT_ASSERTeq(bytes_returned, sizeof(basic_info));
UT_ASSERTeq(basic_info.State, MEM_COMMIT);
offset += basic_info.RegionSize;
/* first part */
bytes_returned = VirtualQuery((char *)pop + offset, &basic_info,
sizeof(basic_info));
UT_ASSERTeq(bytes_returned, sizeof(basic_info));
UT_ASSERTeq(basic_info.RegionSize, 8 * MEGABYTE - 4 * KILOBYTE);
UT_ASSERTeq(basic_info.State, MEM_COMMIT);
} else {
/* first part with header */
UT_ASSERTeq(bytes_returned, sizeof(basic_info));
UT_ASSERTeq(basic_info.RegionSize, 8 * MEGABYTE);
UT_ASSERTeq(basic_info.State, MEM_COMMIT);
}
offset += basic_info.RegionSize;
/* reservation after first part */
bytes_returned = VirtualQuery((char *)pop + offset, &basic_info,
sizeof(basic_info));
UT_ASSERTeq(bytes_returned, sizeof(basic_info));
UT_ASSERTeq(basic_info.RegionSize, (50 - 8) * MEGABYTE);
UT_ASSERTeq(basic_info.State, MEM_RESERVE);
DONE(NULL);
}
| 3,632 | 32.638889 | 79 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/remote_basic/remote_basic.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* remote_basic.c -- unit test for remote tests support
*
* usage: remote_basic <file-to-be-checked>
*/
#include "file.h"
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "remote_basic");
if (argc != 2)
UT_FATAL("usage: %s <file-to-be-checked>", argv[0]);
const char *file = argv[1];
int exists = util_file_exists(file);
if (exists < 0)
UT_FATAL("!util_file_exists");
if (!exists)
UT_FATAL("File '%s' does not exist", file);
else
UT_OUT("File '%s' exists", file);
UT_OUT("An example of OUT message");
UT_ERR("An example of ERR message");
DONE(NULL);
}
| 2,213 | 32.044776 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/win_getopt/win_getopt.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* win_getopt.c -- test for windows getopt() implementation
*/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "unittest.h"
/*
* long_options -- command line arguments
*/
static const struct option long_options[] = {
{ "arg_a", no_argument, NULL, 'a' },
{ "arg_b", no_argument, NULL, 'b' },
{ "arg_c", no_argument, NULL, 'c' },
{ "arg_d", no_argument, NULL, 'd' },
{ "arg_e", no_argument, NULL, 'e' },
{ "arg_f", no_argument, NULL, 'f' },
{ "arg_g", no_argument, NULL, 'g' },
{ "arg_h", no_argument, NULL, 'h' },
{ "arg_A", required_argument, NULL, 'A' },
{ "arg_B", required_argument, NULL, 'B' },
{ "arg_C", required_argument, NULL, 'C' },
{ "arg_D", required_argument, NULL, 'D' },
{ "arg_E", required_argument, NULL, 'E' },
{ "arg_F", required_argument, NULL, 'F' },
{ "arg_G", required_argument, NULL, 'G' },
{ "arg_H", required_argument, NULL, 'H' },
{ "arg_1", optional_argument, NULL, '1' },
{ "arg_2", optional_argument, NULL, '2' },
{ "arg_3", optional_argument, NULL, '3' },
{ "arg_4", optional_argument, NULL, '4' },
{ "arg_5", optional_argument, NULL, '5' },
{ "arg_6", optional_argument, NULL, '6' },
{ "arg_7", optional_argument, NULL, '7' },
{ "arg_8", optional_argument, NULL, '8' },
{ NULL, 0, NULL, 0 },
};
int
main(int argc, char *argv[])
{
int opt;
int option_index;
START(argc, argv, "win_getopt");
while ((opt = getopt_long(argc, argv,
"abcdefghA:B:C:D:E:F:G::H1::2::3::4::5::6::7::8::",
long_options, &option_index)) != -1) {
switch (opt) {
case '?':
UT_OUT("unknown argument");
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
UT_OUT("arg_%c", opt);
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
UT_OUT("arg_%c=%s", opt,
optarg == NULL ? "null": optarg);
break;
}
}
while (optind < argc) {
UT_OUT("%s", argv[optind++]);
}
DONE(NULL);
}
| 3,677 | 28.66129 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_strdup/obj_tx_strdup.c
|
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_strdup.c -- unit test for pmemobj_tx_strdup
*/
#include <sys/param.h>
#include <string.h>
#include <wchar.h>
#include "unittest.h"
#define LAYOUT_NAME "tx_strdup"
TOID_DECLARE(char, 0);
TOID_DECLARE(wchar_t, 1);
enum type_number {
TYPE_NO_TX,
TYPE_WCS_NO_TX,
TYPE_COMMIT,
TYPE_WCS_COMMIT,
TYPE_ABORT,
TYPE_WCS_ABORT,
TYPE_FREE_COMMIT,
TYPE_WCS_FREE_COMMIT,
TYPE_FREE_ABORT,
TYPE_WCS_FREE_ABORT,
TYPE_COMMIT_NESTED1,
TYPE_WCS_COMMIT_NESTED1,
TYPE_COMMIT_NESTED2,
TYPE_WCS_COMMIT_NESTED2,
TYPE_ABORT_NESTED1,
TYPE_WCS_ABORT_NESTED1,
TYPE_ABORT_NESTED2,
TYPE_WCS_ABORT_NESTED2,
TYPE_ABORT_AFTER_NESTED1,
TYPE_WCS_ABORT_AFTER_NESTED1,
TYPE_ABORT_AFTER_NESTED2,
TYPE_WCS_ABORT_AFTER_NESTED2,
};
#define TEST_STR_1 "Test string 1"
#define TEST_STR_2 "Test string 2"
#define TEST_WCS_1 L"Test string 3"
#define TEST_WCS_2 L"Test string 4"
#define MAX_FUNC 2
typedef void (*fn_tx_strdup)(TOID(char) *str, const char *s,
unsigned type_num);
typedef void (*fn_tx_wcsdup)(TOID(wchar_t) *wcs, const wchar_t *s,
unsigned type_num);
static unsigned counter;
/*
* tx_strdup -- duplicate a string using pmemobj_tx_strdup
*/
static void
tx_strdup(TOID(char) *str, const char *s, unsigned type_num)
{
TOID_ASSIGN(*str, pmemobj_tx_strdup(s, type_num));
}
/*
* tx_wcsdup -- duplicate a string using pmemobj_tx_wcsdup
*/
static void
tx_wcsdup(TOID(wchar_t) *wcs, const wchar_t *s, unsigned type_num)
{
TOID_ASSIGN(*wcs, pmemobj_tx_wcsdup(s, type_num));
}
/*
* tx_strdup_macro -- duplicate a string using macro
*/
static void
tx_strdup_macro(TOID(char) *str, const char *s, unsigned type_num)
{
TOID_ASSIGN(*str, TX_STRDUP(s, type_num));
}
/*
* tx_wcsdup_macro -- duplicate a wide character string using macro
*/
static void
tx_wcsdup_macro(TOID(wchar_t) *wcs, const wchar_t *s, unsigned type_num)
{
TOID_ASSIGN(*wcs, TX_WCSDUP(s, type_num));
}
static fn_tx_strdup do_tx_strdup[MAX_FUNC] = {tx_strdup, tx_strdup_macro};
static fn_tx_wcsdup do_tx_wcsdup[MAX_FUNC] = {tx_wcsdup, tx_wcsdup_macro};
/*
* do_tx_strdup_commit -- duplicate a string and commit the transaction
*/
static void
do_tx_strdup_commit(PMEMobjpool *pop)
{
TOID(char) str;
TOID(wchar_t) wcs;
TX_BEGIN(pop) {
do_tx_strdup[counter](&str, TEST_STR_1, TYPE_COMMIT);
do_tx_wcsdup[counter](&wcs, TEST_WCS_1, TYPE_WCS_COMMIT);
UT_ASSERT(!TOID_IS_NULL(str));
UT_ASSERT(!TOID_IS_NULL(wcs));
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(str, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT));
TOID_ASSIGN(wcs, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_COMMIT));
UT_ASSERT(!TOID_IS_NULL(str));
UT_ASSERTeq(strcmp(TEST_STR_1, D_RO(str)), 0);
UT_ASSERTeq(wcscmp(TEST_WCS_1, D_RO(wcs)), 0);
}
/*
* do_tx_strdup_abort -- duplicate a string and abort the transaction
*/
static void
do_tx_strdup_abort(PMEMobjpool *pop)
{
TOID(char) str;
TOID(wchar_t) wcs;
TX_BEGIN(pop) {
do_tx_strdup[counter](&str, TEST_STR_1, TYPE_ABORT);
do_tx_wcsdup[counter](&wcs, TEST_WCS_1, TYPE_WCS_ABORT);
UT_ASSERT(!TOID_IS_NULL(str));
UT_ASSERT(!TOID_IS_NULL(wcs));
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(str, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT));
TOID_ASSIGN(wcs, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_ABORT));
UT_ASSERT(TOID_IS_NULL(str));
UT_ASSERT(TOID_IS_NULL(wcs));
}
/*
* do_tx_strdup_null -- duplicate a NULL string to trigger tx abort
*/
static void
do_tx_strdup_null(PMEMobjpool *pop)
{
TOID(char) str;
TOID(wchar_t) wcs;
TX_BEGIN(pop) {
do_tx_strdup[counter](&str, NULL, TYPE_ABORT);
do_tx_wcsdup[counter](&wcs, NULL, TYPE_WCS_ABORT);
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(str, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT));
TOID_ASSIGN(wcs, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_ABORT));
UT_ASSERT(TOID_IS_NULL(str));
UT_ASSERT(TOID_IS_NULL(wcs));
}
/*
* do_tx_strdup_free_commit -- duplicate a string, free and commit the
* transaction
*/
static void
do_tx_strdup_free_commit(PMEMobjpool *pop)
{
TOID(char) str;
TOID(wchar_t) wcs;
TX_BEGIN(pop) {
do_tx_strdup[counter](&str, TEST_STR_1, TYPE_FREE_COMMIT);
do_tx_wcsdup[counter](&wcs, TEST_WCS_1, TYPE_WCS_FREE_COMMIT);
UT_ASSERT(!TOID_IS_NULL(str));
UT_ASSERT(!TOID_IS_NULL(wcs));
int ret = pmemobj_tx_free(str.oid);
UT_ASSERTeq(ret, 0);
ret = pmemobj_tx_free(wcs.oid);
UT_ASSERTeq(ret, 0);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(str, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_COMMIT));
TOID_ASSIGN(wcs, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_FREE_COMMIT));
UT_ASSERT(TOID_IS_NULL(str));
UT_ASSERT(TOID_IS_NULL(wcs));
}
/*
* do_tx_strdup_free_abort -- duplicate a string, free and abort the
* transaction
*/
static void
do_tx_strdup_free_abort(PMEMobjpool *pop)
{
TOID(char) str;
TOID(wchar_t) wcs;
TX_BEGIN(pop) {
do_tx_strdup[counter](&str, TEST_STR_1, TYPE_FREE_ABORT);
do_tx_wcsdup[counter](&wcs, TEST_WCS_1, TYPE_WCS_FREE_ABORT);
UT_ASSERT(!TOID_IS_NULL(str));
UT_ASSERT(!TOID_IS_NULL(wcs));
int ret = pmemobj_tx_free(str.oid);
UT_ASSERTeq(ret, 0);
ret = pmemobj_tx_free(wcs.oid);
UT_ASSERTeq(ret, 0);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(str, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_ABORT));
TOID_ASSIGN(wcs, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_FREE_ABORT));
UT_ASSERT(TOID_IS_NULL(str));
UT_ASSERT(TOID_IS_NULL(wcs));
}
/*
* do_tx_strdup_commit_nested -- duplicate two string suing nested
* transaction and commit the transaction
*/
static void
do_tx_strdup_commit_nested(PMEMobjpool *pop)
{
TOID(char) str1;
TOID(char) str2;
TOID(wchar_t) wcs1;
TOID(wchar_t) wcs2;
TX_BEGIN(pop) {
do_tx_strdup[counter](&str1, TEST_STR_1, TYPE_COMMIT_NESTED1);
do_tx_wcsdup[counter](&wcs1, TEST_WCS_1,
TYPE_WCS_COMMIT_NESTED1);
UT_ASSERT(!TOID_IS_NULL(str1));
UT_ASSERT(!TOID_IS_NULL(wcs1));
TX_BEGIN(pop) {
do_tx_strdup[counter](&str2, TEST_STR_2,
TYPE_COMMIT_NESTED2);
do_tx_wcsdup[counter](&wcs2, TEST_WCS_2,
TYPE_WCS_COMMIT_NESTED2);
UT_ASSERT(!TOID_IS_NULL(str2));
UT_ASSERT(!TOID_IS_NULL(wcs2));
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(str1, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_NESTED1));
TOID_ASSIGN(wcs1, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_COMMIT_NESTED1));
UT_ASSERT(!TOID_IS_NULL(str1));
UT_ASSERT(!TOID_IS_NULL(wcs1));
UT_ASSERTeq(strcmp(TEST_STR_1, D_RO(str1)), 0);
UT_ASSERTeq(wcscmp(TEST_WCS_1, D_RO(wcs1)), 0);
TOID_ASSIGN(str2, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_NESTED2));
TOID_ASSIGN(wcs2, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_COMMIT_NESTED2));
UT_ASSERT(!TOID_IS_NULL(str2));
UT_ASSERT(!TOID_IS_NULL(wcs2));
UT_ASSERTeq(strcmp(TEST_STR_2, D_RO(str2)), 0);
UT_ASSERTeq(wcscmp(TEST_WCS_2, D_RO(wcs2)), 0);
}
/*
* do_tx_strdup_commit_abort -- duplicate two string suing nested
* transaction and abort the transaction
*/
static void
do_tx_strdup_abort_nested(PMEMobjpool *pop)
{
TOID(char) str1;
TOID(char) str2;
TOID(wchar_t) wcs1;
TOID(wchar_t) wcs2;
TX_BEGIN(pop) {
do_tx_strdup[counter](&str1, TEST_STR_1, TYPE_ABORT_NESTED1);
do_tx_wcsdup[counter](&wcs1, TEST_WCS_1,
TYPE_WCS_ABORT_NESTED1);
UT_ASSERT(!TOID_IS_NULL(str1));
UT_ASSERT(!TOID_IS_NULL(wcs1));
TX_BEGIN(pop) {
do_tx_strdup[counter](&str2, TEST_STR_2,
TYPE_ABORT_NESTED2);
do_tx_wcsdup[counter](&wcs2, TEST_WCS_2,
TYPE_WCS_ABORT_NESTED2);
UT_ASSERT(!TOID_IS_NULL(str2));
UT_ASSERT(!TOID_IS_NULL(wcs2));
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(str1, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_NESTED1));
TOID_ASSIGN(wcs1, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_ABORT_NESTED1));
UT_ASSERT(TOID_IS_NULL(str1));
UT_ASSERT(TOID_IS_NULL(wcs1));
TOID_ASSIGN(str2, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_NESTED2));
TOID_ASSIGN(wcs2, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_ABORT_NESTED2));
UT_ASSERT(TOID_IS_NULL(str2));
UT_ASSERT(TOID_IS_NULL(wcs2));
}
/*
* do_tx_strdup_commit_abort -- duplicate two string suing nested
* transaction and abort after the nested transaction
*/
static void
do_tx_strdup_abort_after_nested(PMEMobjpool *pop)
{
TOID(char) str1;
TOID(char) str2;
TOID(wchar_t) wcs1;
TOID(wchar_t) wcs2;
TX_BEGIN(pop) {
do_tx_strdup[counter](&str1, TEST_STR_1,
TYPE_ABORT_AFTER_NESTED1);
do_tx_wcsdup[counter](&wcs1, TEST_WCS_1,
TYPE_WCS_ABORT_AFTER_NESTED1);
UT_ASSERT(!TOID_IS_NULL(str1));
UT_ASSERT(!TOID_IS_NULL(wcs1));
TX_BEGIN(pop) {
do_tx_strdup[counter](&str2, TEST_STR_2,
TYPE_ABORT_AFTER_NESTED2);
do_tx_wcsdup[counter](&wcs2, TEST_WCS_2,
TYPE_WCS_ABORT_AFTER_NESTED2);
UT_ASSERT(!TOID_IS_NULL(str2));
UT_ASSERT(!TOID_IS_NULL(wcs2));
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(str1, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_AFTER_NESTED1));
TOID_ASSIGN(wcs1, POBJ_FIRST_TYPE_NUM(pop,
TYPE_WCS_ABORT_AFTER_NESTED1));
UT_ASSERT(TOID_IS_NULL(str1));
UT_ASSERT(TOID_IS_NULL(wcs1));
TOID_ASSIGN(str2, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_AFTER_NESTED2));
TOID_ASSIGN(wcs2, POBJ_FIRST_TYPE_NUM(pop,
TYPE_WCS_ABORT_AFTER_NESTED2));
UT_ASSERT(TOID_IS_NULL(str2));
UT_ASSERT(TOID_IS_NULL(wcs2));
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_strdup");
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
for (counter = 0; counter < MAX_FUNC; counter++) {
do_tx_strdup_commit(pop);
do_tx_strdup_abort(pop);
do_tx_strdup_null(pop);
do_tx_strdup_free_commit(pop);
do_tx_strdup_free_abort(pop);
do_tx_strdup_commit_nested(pop);
do_tx_strdup_abort_nested(pop);
do_tx_strdup_abort_after_nested(pop);
}
pmemobj_close(pop);
DONE(NULL);
}
| 11,575 | 26.760192 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_realloc/obj_tx_realloc.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_realloc.c -- unit test for pmemobj_tx_realloc and pmemobj_tx_zrealloc
*/
#include <sys/param.h>
#include <string.h>
#include "unittest.h"
#include "util.h"
#define LAYOUT_NAME "tx_realloc"
#define TEST_VALUE_1 1
#define OBJ_SIZE 1024
enum type_number {
TYPE_NO_TX,
TYPE_COMMIT,
TYPE_ABORT,
TYPE_TYPE,
TYPE_COMMIT_ZERO,
TYPE_COMMIT_ZERO_MACRO,
TYPE_ABORT_ZERO,
TYPE_ABORT_ZERO_MACRO,
TYPE_COMMIT_ALLOC,
TYPE_ABORT_ALLOC,
TYPE_ABORT_HUGE,
TYPE_ABORT_ZERO_HUGE,
TYPE_ABORT_ZERO_HUGE_MACRO,
TYPE_FREE,
};
struct object {
size_t value;
char data[OBJ_SIZE - sizeof(size_t)];
};
TOID_DECLARE(struct object, 0);
struct object_macro {
size_t value;
char data[OBJ_SIZE - sizeof(size_t)];
};
TOID_DECLARE(struct object_macro, TYPE_COMMIT_ZERO_MACRO);
/*
* do_tx_alloc -- do tx allocation with specified type number
*/
static PMEMoid
do_tx_alloc(PMEMobjpool *pop, unsigned type_num, size_t value)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, OID_NULL);
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(
sizeof(struct object), type_num));
if (!TOID_IS_NULL(obj)) {
D_RW(obj)->value = value;
}
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
return obj.oid;
}
/*
* do_tx_realloc_commit -- reallocate an object and commit the transaction
*/
static void
do_tx_realloc_commit(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_COMMIT, TEST_VALUE_1));
size_t new_size = 2 * pmemobj_alloc_usable_size(obj.oid);
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid,
new_size, TYPE_COMMIT));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_realloc_abort -- reallocate an object and commit the transaction
*/
static void
do_tx_realloc_abort(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT, TEST_VALUE_1));
size_t new_size = 2 * pmemobj_alloc_usable_size(obj.oid);
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid,
new_size, TYPE_ABORT));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size);
TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_realloc_huge -- reallocate an object to a huge size to trigger tx abort
*/
static void
do_tx_realloc_huge(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_HUGE, TEST_VALUE_1));
size_t new_size = PMEMOBJ_MAX_ALLOC_SIZE + 1;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid,
new_size, TYPE_ABORT_HUGE));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_HUGE));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size);
TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_zrealloc_commit_macro -- reallocate an object, zero it and commit
* the transaction using macro
*/
static void
do_tx_zrealloc_commit_macro(PMEMobjpool *pop)
{
TOID(struct object_macro) obj;
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_COMMIT_ZERO_MACRO,
TEST_VALUE_1));
size_t old_size = pmemobj_alloc_usable_size(obj.oid);
size_t new_size = 2 * old_size;
TX_BEGIN(pop) {
obj = TX_ZREALLOC(obj, new_size);
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size);
UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size));
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_ZERO_MACRO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size);
UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size));
TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_zrealloc_commit -- reallocate an object, zero it and commit
* the transaction
*/
static void
do_tx_zrealloc_commit(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_COMMIT_ZERO, TEST_VALUE_1));
size_t old_size = pmemobj_alloc_usable_size(obj.oid);
size_t new_size = 2 * old_size;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zrealloc(obj.oid,
new_size, TYPE_COMMIT_ZERO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size);
UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size));
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_ZERO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size);
UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size));
TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_realloc_abort_macro -- reallocate an object, zero it and commit the
* transaction using macro
*/
static void
do_tx_zrealloc_abort_macro(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_ZERO_MACRO, TEST_VALUE_1));
size_t old_size = pmemobj_alloc_usable_size(obj.oid);
size_t new_size = 2 * old_size;
TX_BEGIN(pop) {
obj = TX_ZREALLOC(obj, new_size);
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size);
UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size));
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_ZERO_MACRO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size);
TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_realloc_abort -- reallocate an object and commit the transaction
*/
static void
do_tx_zrealloc_abort(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_ZERO, TEST_VALUE_1));
size_t old_size = pmemobj_alloc_usable_size(obj.oid);
size_t new_size = 2 * old_size;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zrealloc(obj.oid,
new_size, TYPE_ABORT_ZERO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size);
UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size));
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_ZERO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size);
TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_realloc_huge_macro -- reallocate an object to a huge size to trigger
* tx abort and zero it using macro
*/
static void
do_tx_zrealloc_huge_macro(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_ZERO_HUGE_MACRO,
TEST_VALUE_1));
size_t old_size = pmemobj_alloc_usable_size(obj.oid);
size_t new_size = 2 * old_size;
TX_BEGIN(pop) {
obj = TX_ZREALLOC(obj, PMEMOBJ_MAX_ALLOC_SIZE + 1);
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_ZERO_HUGE_MACRO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size);
TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_realloc_huge -- reallocate an object to a huge size to trigger tx abort
*/
static void
do_tx_zrealloc_huge(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_ZERO_HUGE, TEST_VALUE_1));
size_t old_size = pmemobj_alloc_usable_size(obj.oid);
size_t new_size = 2 * old_size;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zrealloc(obj.oid,
PMEMOBJ_MAX_ALLOC_SIZE + 1, TYPE_ABORT_ZERO_HUGE));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_ZERO_HUGE));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size);
TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_realloc_alloc_commit -- reallocate an allocated object
* and commit the transaction
*/
static void
do_tx_realloc_alloc_commit(PMEMobjpool *pop)
{
TOID(struct object) obj;
size_t new_size = 0;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_COMMIT_ALLOC,
TEST_VALUE_1));
UT_ASSERT(!TOID_IS_NULL(obj));
new_size = 2 * pmemobj_alloc_usable_size(obj.oid);
TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid,
new_size, TYPE_COMMIT_ALLOC));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_ALLOC));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_realloc_alloc_abort -- reallocate an allocated object
* and commit the transaction
*/
static void
do_tx_realloc_alloc_abort(PMEMobjpool *pop)
{
TOID(struct object) obj;
size_t new_size = 0;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_ALLOC,
TEST_VALUE_1));
UT_ASSERT(!TOID_IS_NULL(obj));
new_size = 2 * pmemobj_alloc_usable_size(obj.oid);
TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid,
new_size, TYPE_ABORT_ALLOC));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_ALLOC));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_root_realloc -- retrieve root inside of transaction
*/
static void
do_tx_root_realloc(PMEMobjpool *pop)
{
TX_BEGIN(pop) {
PMEMoid root = pmemobj_root(pop, sizeof(struct object));
UT_ASSERT(!OID_IS_NULL(root));
UT_ASSERT(util_is_zeroed(pmemobj_direct(root),
sizeof(struct object)));
UT_ASSERTeq(sizeof(struct object), pmemobj_root_size(pop));
root = pmemobj_root(pop, 2 * sizeof(struct object));
UT_ASSERT(!OID_IS_NULL(root));
UT_ASSERT(util_is_zeroed(pmemobj_direct(root),
2 * sizeof(struct object)));
UT_ASSERTeq(2 * sizeof(struct object), pmemobj_root_size(pop));
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
}
/*
* do_tx_realloc_free -- reallocate an allocated object
* and commit the transaction
*/
static void
do_tx_realloc_free(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_FREE, TEST_VALUE_1));
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid,
0, TYPE_COMMIT));
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE));
UT_ASSERT(TOID_IS_NULL(obj));
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_realloc");
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, 0,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
do_tx_root_realloc(pop);
do_tx_realloc_commit(pop);
do_tx_realloc_abort(pop);
do_tx_realloc_huge(pop);
do_tx_zrealloc_commit(pop);
do_tx_zrealloc_commit_macro(pop);
do_tx_zrealloc_abort(pop);
do_tx_zrealloc_abort_macro(pop);
do_tx_zrealloc_huge(pop);
do_tx_zrealloc_huge_macro(pop);
do_tx_realloc_alloc_commit(pop);
do_tx_realloc_alloc_abort(pop);
do_tx_realloc_free(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 14,391 | 27.109375 | 80 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/log_pool/log_pool.c
|
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* log_pool.c -- unit test for pmemlog_create() and pmemlog_open()
*
* usage: log_pool op path [poolsize mode]
*
* op can be:
* c - create
* o - open
*
* "poolsize" and "mode" arguments are ignored for "open"
*/
#include "unittest.h"
#define MB ((size_t)1 << 20)
static void
pool_create(const char *path, size_t poolsize, unsigned mode)
{
PMEMlogpool *plp = pmemlog_create(path, poolsize, mode);
if (plp == NULL)
UT_OUT("!%s: pmemlog_create", path);
else {
os_stat_t stbuf;
STAT(path, &stbuf);
UT_OUT("%s: file size %zu usable space %zu mode 0%o",
path, stbuf.st_size,
pmemlog_nbyte(plp),
stbuf.st_mode & 0777);
pmemlog_close(plp);
int result = pmemlog_check(path);
if (result < 0)
UT_OUT("!%s: pmemlog_check", path);
else if (result == 0)
UT_OUT("%s: pmemlog_check: not consistent", path);
}
}
static void
pool_open(const char *path)
{
PMEMlogpool *plp = pmemlog_open(path);
if (plp == NULL)
UT_OUT("!%s: pmemlog_open", path);
else {
UT_OUT("%s: pmemlog_open: Success", path);
pmemlog_close(plp);
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "log_pool");
if (argc < 3)
UT_FATAL("usage: %s op path [poolsize mode]", argv[0]);
size_t poolsize;
unsigned mode;
switch (argv[1][0]) {
case 'c':
poolsize = strtoul(argv[3], NULL, 0) * MB; /* in megabytes */
mode = strtoul(argv[4], NULL, 8);
pool_create(argv[2], poolsize, mode);
break;
case 'o':
pool_open(argv[2]);
break;
default:
UT_FATAL("unknown operation");
}
DONE(NULL);
}
| 3,144 | 26.112069 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_lists_atomic_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_lists_atomic_include.c -- include test for libpmemobj
*/
#include <libpmemobj/lists_atomic.h>
| 1,703 | 43.842105 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_lists_atomic_base_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_lists_atomic_base_include.c -- include test for libpmemobj
*/
#include <libpmemobj/lists_atomic_base.h>
| 1,713 | 44.105263 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_tx_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_include.c -- include test for libpmemobj
*/
#include <libpmemobj/tx.h>
| 1,683 | 43.315789 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_base_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_base_include.c -- include test for libpmemobj
*/
#include <libpmemobj/base.h>
int
main(int argc, char *argv[])
{
return 0;
}
| 1,736 | 38.477273 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_atomic_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_atomic_include.c -- include test for libpmemobj
*/
#include <libpmemobj/atomic.h>
| 1,691 | 43.526316 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_iterator_base_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_iterator_base_include.c -- include test for libpmemobj
*/
#include <libpmemobj/iterator_base.h>
| 1,705 | 43.894737 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_thread_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_thread_include.c -- include test for libpmemobj
*/
#include <libpmemobj/thread.h>
| 1,691 | 43.526316 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_iterator_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_iterator_include.c -- include test for libpmemobj
*/
#include <libpmemobj/iterator.h>
| 1,695 | 43.631579 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_types_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_types_include.c -- include test for libpmemobj
*/
#include <libpmemobj/types.h>
| 1,689 | 43.473684 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_tx_base_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_base_include.c -- include test for libpmemobj
*/
#include <libpmemobj/tx_base.h>
| 1,693 | 43.578947 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_pool_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_pool_include.c -- include test for libpmemobj
*/
#include <libpmemobj/pool.h>
| 1,687 | 43.421053 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_pool_base_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_pool_base_include.c -- include test for libpmemobj
*/
#include <libpmemobj/pool_base.h>
| 1,697 | 43.684211 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_include/obj_atomic_base_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_atomic_base_include.c -- include test for libpmemobj
*/
#include <libpmemobj/atomic_base.h>
| 1,701 | 43.789474 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_rm_win/libpmempool_rm_win.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmempool_rm_win -- a unittest for pmempool_rm.
*
*/
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include "unittest.h"
#define FATAL_USAGE(n) UT_FATAL("usage: %s [-f -l -r] path..", (n))
static PMEMobjpool *Pop;
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "libpmempool_rm_win");
if (argc < 2)
FATAL_USAGE(ut_toUTF8(argv[0]));
unsigned flags = 0;
int do_open = 0;
int i = 1;
for (; i < argc - 1; i++) {
wchar_t *optarg = argv[i + 1];
if (wcscmp(L"-f", argv[i]) == 0)
flags |= PMEMPOOL_RM_FORCE;
else if (wcscmp(L"-r", argv[i]) == 0)
flags |= PMEMPOOL_RM_POOLSET_REMOTE;
else if (wcscmp(L"-l", argv[i]) == 0)
flags |= PMEMPOOL_RM_POOLSET_LOCAL;
else if (wcscmp(L"-o", argv[i]) == 0)
do_open = 1;
else if (wcschr(argv[i], L'-') == argv[i])
FATAL_USAGE(argv[0]);
else
break;
}
for (; i < argc; i++) {
const wchar_t *path = argv[i];
if (do_open) {
Pop = pmemobj_openW(path, NULL);
UT_ASSERTne(Pop, NULL);
}
int ret = pmempool_rmW(path, flags);
if (ret) {
UT_OUT("!%s: %s", ut_toUTF8(path),
pmempool_errormsgU());
}
if (do_open) {
UT_ASSERTne(Pop, NULL);
pmemobj_close(Pop);
}
}
DONEW(NULL);
}
| 2,857 | 28.770833 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/blk_rw/blk_rw.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* blk_rw.c -- unit test for pmemblk_read/write/set_zero/set_error
*
* usage: blk_rw bsize file func operation:lba...
*
* func is 'c' or 'o' (create or open)
* operations are 'r' or 'w' or 'z' or 'e'
*
*/
#include "unittest.h"
static size_t Bsize;
/*
* construct -- build a buffer for writing
*/
static void
construct(unsigned char *buf)
{
static int ord = 1;
for (int i = 0; i < Bsize; i++)
buf[i] = ord;
ord++;
if (ord > 255)
ord = 1;
}
/*
* ident -- identify what a buffer holds
*/
static char *
ident(unsigned char *buf)
{
static char descr[100];
unsigned val = *buf;
for (int i = 1; i < Bsize; i++)
if (buf[i] != val) {
sprintf(descr, "{%u} TORN at byte %d", val, i);
return descr;
}
sprintf(descr, "{%u}", val);
return descr;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "blk_rw");
if (argc < 5)
UT_FATAL("usage: %s bsize file func op:lba...", argv[0]);
Bsize = strtoul(argv[1], NULL, 0);
const char *path = argv[2];
PMEMblkpool *handle;
switch (*argv[3]) {
case 'c':
handle = pmemblk_create(path, Bsize, 0,
S_IWUSR | S_IRUSR);
if (handle == NULL)
UT_FATAL("!%s: pmemblk_create", path);
break;
case 'o':
handle = pmemblk_open(path, Bsize);
if (handle == NULL)
UT_FATAL("!%s: pmemblk_open", path);
break;
}
UT_OUT("%s block size %zu usable blocks %zu",
argv[1], Bsize, pmemblk_nblock(handle));
unsigned char *buf = MALLOC(Bsize);
if (buf == NULL)
UT_FATAL("cannot allocate buf");
/* map each file argument with the given map type */
for (int arg = 4; arg < argc; arg++) {
if (strchr("rwze", argv[arg][0]) == NULL || argv[arg][1] != ':')
UT_FATAL("op must be r: or w: or z: or e:");
os_off_t lba = strtol(&argv[arg][2], NULL, 0);
switch (argv[arg][0]) {
case 'r':
if (pmemblk_read(handle, buf, lba) < 0)
UT_OUT("!read lba %jd", lba);
else
UT_OUT("read lba %jd: %s", lba,
ident(buf));
break;
case 'w':
construct(buf);
if (pmemblk_write(handle, buf, lba) < 0)
UT_OUT("!write lba %jd", lba);
else
UT_OUT("write lba %jd: %s", lba,
ident(buf));
break;
case 'z':
if (pmemblk_set_zero(handle, lba) < 0)
UT_OUT("!set_zero lba %jd", lba);
else
UT_OUT("set_zero lba %jd", lba);
break;
case 'e':
if (pmemblk_set_error(handle, lba) < 0)
UT_OUT("!set_error lba %jd", lba);
else
UT_OUT("set_error lba %jd", lba);
break;
}
}
FREE(buf);
pmemblk_close(handle);
int result = pmemblk_check(path, Bsize);
if (result < 0)
UT_OUT("!%s: pmemblk_check", path);
else if (result == 0)
UT_OUT("%s: pmemblk_check: not consistent", path);
DONE(NULL);
}
| 4,288 | 24.529762 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_lock/obj_tx_lock.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_lock.c -- unit test for pmemobj_tx_lock()
*/
#include "unittest.h"
#include "libpmemobj.h"
#define LAYOUT_NAME "obj_tx_lock"
#define NUM_LOCKS 2
struct transaction_data {
PMEMmutex mutexes[NUM_LOCKS];
PMEMrwlock rwlocks[NUM_LOCKS];
};
static PMEMobjpool *Pop;
#define DO_LOCK(mtx, rwlock)\
pmemobj_tx_lock(TX_PARAM_MUTEX, &(mtx)[0]);\
pmemobj_tx_lock(TX_PARAM_MUTEX, &(mtx)[1]);\
pmemobj_tx_lock(TX_PARAM_RWLOCK, &(rwlock)[0]);\
pmemobj_tx_lock(TX_PARAM_RWLOCK, &(rwlock)[1])
#define IS_UNLOCKED(pop, mtx, rwlock)\
ret = 0;\
ret += pmemobj_mutex_trylock((pop), &(mtx)[0]);\
ret += pmemobj_mutex_trylock((pop), &(mtx)[1]);\
ret += pmemobj_rwlock_trywrlock((pop), &(rwlock)[0]);\
ret += pmemobj_rwlock_trywrlock((pop), &(rwlock)[1]);\
UT_ASSERTeq(ret, 0);\
pmemobj_mutex_unlock((pop), &(mtx)[0]);\
pmemobj_mutex_unlock((pop), &(mtx)[1]);\
pmemobj_rwlock_unlock((pop), &(rwlock)[0]);\
pmemobj_rwlock_unlock((pop), &(rwlock)[1])
#define IS_LOCKED(pop, mtx, rwlock)\
ret = pmemobj_mutex_trylock((pop), &(mtx)[0]);\
UT_ASSERT(ret != 0);\
ret = pmemobj_mutex_trylock((pop), &(mtx)[1]);\
UT_ASSERT(ret != 0);\
ret = pmemobj_rwlock_trywrlock((pop), &(rwlock)[0]);\
UT_ASSERT(ret != 0);\
ret = pmemobj_rwlock_trywrlock((pop), &(rwlock)[1]);\
UT_ASSERT(ret != 0)
/*
* do_tx_add_locks -- (internal) transaction where locks are added after
* transaction begins
*/
static void *
do_tx_add_locks(struct transaction_data *data)
{
int ret;
IS_UNLOCKED(Pop, data->mutexes, data->rwlocks);
TX_BEGIN(Pop) {
DO_LOCK(data->mutexes, data->rwlocks);
IS_LOCKED(Pop, data->mutexes, data->rwlocks);
} TX_ONABORT { /* not called */
UT_ASSERT(0);
} TX_END
IS_UNLOCKED(Pop, data->mutexes, data->rwlocks);
return NULL;
}
/*
* do_tx_add_locks_nested -- (internal) transaction where locks
* are added after nested transaction begins
*/
static void *
do_tx_add_locks_nested(struct transaction_data *data)
{
int ret;
TX_BEGIN(Pop) {
IS_UNLOCKED(Pop, data->mutexes, data->rwlocks);
TX_BEGIN(Pop) {
DO_LOCK(data->mutexes, data->rwlocks);
IS_LOCKED(Pop, data->mutexes, data->rwlocks);
} TX_END
IS_LOCKED(Pop, data->mutexes, data->rwlocks);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
IS_UNLOCKED(Pop, data->mutexes, data->rwlocks);
return NULL;
}
/*
* do_tx_add_locks_nested_all -- (internal) transaction where all locks
* are added in both transactions after transaction begins
*/
static void *
do_tx_add_locks_nested_all(struct transaction_data *data)
{
int ret;
TX_BEGIN(Pop) {
IS_UNLOCKED(Pop, data->mutexes, data->rwlocks);
DO_LOCK(data->mutexes, data->rwlocks);
IS_LOCKED(Pop, data->mutexes, data->rwlocks);
TX_BEGIN(Pop) {
IS_LOCKED(Pop, data->mutexes, data->rwlocks);
DO_LOCK(data->mutexes, data->rwlocks);
IS_LOCKED(Pop, data->mutexes, data->rwlocks);
} TX_END
IS_LOCKED(Pop, data->mutexes, data->rwlocks);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
IS_UNLOCKED(Pop, data->mutexes, data->rwlocks);
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_lock");
if (argc != 2)
UT_FATAL("usage: %s <file>", argv[0]);
if ((Pop = pmemobj_create(argv[1], LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
PMEMoid root = pmemobj_root(Pop, sizeof(struct transaction_data));
struct transaction_data *test_obj =
(struct transaction_data *)pmemobj_direct(root);
do_tx_add_locks(test_obj);
do_tx_add_locks_nested(test_obj);
do_tx_add_locks_nested_all(test_obj);
pmemobj_close(Pop);
DONE(NULL);
}
| 5,159 | 29.352941 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_memops/obj_memops.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_memops.c -- basic memory operations tests
*
*/
#include <stddef.h>
#include "obj.h"
#include "memops.h"
#include "ulog.h"
#include "unittest.h"
#define TEST_ENTRIES 256
#define TEST_VALUES 128
enum fail_types {
FAIL_NONE,
FAIL_CHECKSUM,
FAIL_MODIFY_NEXT,
FAIL_MODIFY_VALUE,
};
struct test_object {
uint8_t padding[CACHELINE_SIZE - 16]; /* align to a cacheline */
struct ULOG(TEST_ENTRIES) redo;
struct ULOG(TEST_ENTRIES) undo;
uint64_t values[TEST_VALUES];
};
static void
clear_test_values(struct test_object *object)
{
memset(object->values, 0, sizeof(uint64_t) * TEST_VALUES);
}
static int
redo_log_constructor(void *ctx, void *ptr, size_t usable_size, void *arg)
{
PMEMobjpool *pop = ctx;
const struct pmem_ops *p_ops = &pop->p_ops;
ulog_construct(OBJ_PTR_TO_OFF(ctx, ptr), TEST_ENTRIES, 1, p_ops);
return 0;
}
static int
pmalloc_redo_extend(void *base, uint64_t *redo)
{
size_t s = SIZEOF_ULOG(TEST_ENTRIES);
return pmalloc_construct(base, redo, s, redo_log_constructor, NULL, 0,
OBJ_INTERNAL_OBJECT_MASK, 0);
}
static void
test_set_entries(PMEMobjpool *pop,
struct operation_context *ctx, struct test_object *object,
size_t nentries, enum fail_types fail)
{
operation_start(ctx);
for (size_t i = 0; i < nentries; ++i) {
operation_add_typed_entry(ctx,
&object->values[i], i + 1,
ULOG_OPERATION_SET, LOG_PERSISTENT);
}
operation_reserve(ctx, nentries * 16);
if (fail != FAIL_NONE) {
operation_cancel(ctx);
switch (fail) {
case FAIL_CHECKSUM:
object->redo.checksum += 1;
break;
case FAIL_MODIFY_NEXT:
pmalloc_redo_extend(pop,
&object->redo.next);
break;
case FAIL_MODIFY_VALUE:
object->redo.data[16] += 8;
break;
default:
UT_ASSERT(0);
}
ulog_recover((struct ulog *)&object->redo,
OBJ_OFF_IS_VALID_FROM_CTX, &pop->p_ops);
for (size_t i = 0; i < nentries; ++i)
UT_ASSERTeq(object->values[i], 0);
} else {
operation_finish(ctx);
for (size_t i = 0; i < nentries; ++i)
UT_ASSERTeq(object->values[i], i + 1);
}
}
static void
test_merge_op(struct operation_context *ctx, struct test_object *object)
{
operation_start(ctx);
operation_add_typed_entry(ctx,
&object->values[0], 0b10,
ULOG_OPERATION_OR, LOG_PERSISTENT);
operation_add_typed_entry(ctx,
&object->values[0], 0b01,
ULOG_OPERATION_OR, LOG_PERSISTENT);
operation_add_typed_entry(ctx,
&object->values[0], 0b00,
ULOG_OPERATION_AND, LOG_PERSISTENT);
operation_add_typed_entry(ctx,
&object->values[0], 0b01,
ULOG_OPERATION_OR, LOG_PERSISTENT);
operation_finish(ctx);
UT_ASSERTeq(object->values[0], 0b01);
}
static void
test_same_twice(struct operation_context *ctx, struct test_object *object)
{
operation_start(ctx);
operation_add_typed_entry(ctx,
&object->values[0], 5,
ULOG_OPERATION_SET, LOG_PERSISTENT);
operation_add_typed_entry(ctx,
&object->values[0], 10,
ULOG_OPERATION_SET, LOG_PERSISTENT);
operation_process(ctx);
UT_ASSERTeq(object->values[0], 10);
}
static void
test_redo(PMEMobjpool *pop, struct test_object *object)
{
struct operation_context *ctx = operation_new(
(struct ulog *)&object->redo, TEST_ENTRIES,
pmalloc_redo_extend, NULL, &pop->p_ops, LOG_TYPE_REDO);
test_set_entries(pop, ctx, object, 10, FAIL_NONE);
clear_test_values(object);
test_merge_op(ctx, object);
clear_test_values(object);
test_set_entries(pop, ctx, object, 100, FAIL_NONE);
clear_test_values(object);
test_set_entries(pop, ctx, object, 100, FAIL_CHECKSUM);
clear_test_values(object);
test_set_entries(pop, ctx, object, 10, FAIL_CHECKSUM);
clear_test_values(object);
test_set_entries(pop, ctx, object, 100, FAIL_MODIFY_VALUE);
clear_test_values(object);
test_set_entries(pop, ctx, object, 10, FAIL_MODIFY_VALUE);
clear_test_values(object);
test_same_twice(ctx, object);
clear_test_values(object);
operation_delete(ctx);
/* verify that rebuilding redo_next works */
ctx = operation_new(
(struct ulog *)&object->redo, TEST_ENTRIES,
NULL, NULL, &pop->p_ops, LOG_TYPE_REDO);
test_set_entries(pop, ctx, object, 100, 0);
clear_test_values(object);
/* FAIL_MODIFY_NEXT tests can only happen after redo_next test */
test_set_entries(pop, ctx, object, 100, FAIL_MODIFY_NEXT);
clear_test_values(object);
test_set_entries(pop, ctx, object, 10, FAIL_MODIFY_NEXT);
clear_test_values(object);
operation_delete(ctx);
}
static void
test_undo_small_single_copy(struct operation_context *ctx,
struct test_object *object)
{
operation_start(ctx);
object->values[0] = 1;
object->values[1] = 2;
operation_add_buffer(ctx,
&object->values, &object->values, sizeof(*object->values) * 2,
ULOG_OPERATION_BUF_CPY);
object->values[0] = 2;
object->values[1] = 1;
operation_process(ctx);
operation_finish(ctx);
operation_start(ctx);
UT_ASSERTeq(object->values[0], 1);
UT_ASSERTeq(object->values[1], 2);
object->values[0] = 2;
object->values[1] = 1;
operation_process(ctx);
UT_ASSERTeq(object->values[0], 2);
UT_ASSERTeq(object->values[1], 1);
operation_finish(ctx);
}
static void
test_undo_small_single_set(struct operation_context *ctx,
struct test_object *object)
{
operation_start(ctx);
object->values[0] = 1;
object->values[1] = 2;
int c = 0;
operation_add_buffer(ctx,
&object->values, &c, sizeof(*object->values) * 2,
ULOG_OPERATION_BUF_SET);
operation_process(ctx);
UT_ASSERTeq(object->values[0], 0);
UT_ASSERTeq(object->values[1], 0);
operation_finish(ctx);
}
static void
test_undo_large_single_copy(struct operation_context *ctx,
struct test_object *object)
{
operation_start(ctx);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 1;
operation_add_buffer(ctx,
&object->values, &object->values, sizeof(object->values),
ULOG_OPERATION_BUF_CPY);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 2;
operation_process(ctx);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
UT_ASSERTeq(object->values[i], i + 1);
operation_finish(ctx);
}
static void
test_undo_checksum_mismatch(PMEMobjpool *pop, struct operation_context *ctx,
struct test_object *object, struct ulog *log)
{
operation_start(ctx);
for (uint64_t i = 0; i < 20; ++i)
object->values[i] = i + 1;
operation_add_buffer(ctx,
&object->values, &object->values, sizeof(*object->values) * 20,
ULOG_OPERATION_BUF_CPY);
for (uint64_t i = 0; i < 20; ++i)
object->values[i] = i + 2;
pmemobj_persist(pop, &object->values, sizeof(*object->values) * 20);
log->data[100] += 1; /* corrupt the log somewhere */
operation_process(ctx);
/* the log shouldn't get applied */
for (uint64_t i = 0; i < 20; ++i)
UT_ASSERTeq(object->values[i], i + 2);
operation_finish(ctx);
}
static void
test_undo_large_copy(PMEMobjpool *pop, struct operation_context *ctx,
struct test_object *object)
{
operation_start(ctx);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 1;
operation_add_buffer(ctx,
&object->values, &object->values, sizeof(object->values),
ULOG_OPERATION_BUF_CPY);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 2;
operation_process(ctx);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
UT_ASSERTeq(object->values[i], i + 1);
operation_finish(ctx);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 3;
operation_start(ctx);
operation_add_buffer(ctx,
&object->values, &object->values, sizeof(*object->values) * 26,
ULOG_OPERATION_BUF_CPY);
for (uint64_t i = 0; i < TEST_VALUES; ++i)
object->values[i] = i + 4;
pmemobj_persist(pop, &object->values, sizeof(object->values));
operation_process(ctx);
for (uint64_t i = 0; i < 26; ++i)
UT_ASSERTeq(object->values[i], i + 3);
for (uint64_t i = 26; i < TEST_VALUES; ++i)
UT_ASSERTeq(object->values[i], i + 4);
operation_finish(ctx);
}
static void
test_undo(PMEMobjpool *pop, struct test_object *object)
{
struct operation_context *ctx = operation_new(
(struct ulog *)&object->undo, TEST_ENTRIES,
pmalloc_redo_extend, (ulog_free_fn)pfree,
&pop->p_ops, LOG_TYPE_UNDO);
test_undo_small_single_copy(ctx, object);
test_undo_small_single_set(ctx, object);
test_undo_large_single_copy(ctx, object);
test_undo_large_copy(pop, ctx, object);
test_undo_checksum_mismatch(pop, ctx, object,
(struct ulog *)&object->undo);
/* undo logs are clobbered at the end, which shrinks their size */
size_t capacity = ulog_capacity((struct ulog *)&object->undo,
TEST_ENTRIES, &pop->p_ops);
/* builtin log + one next */
UT_ASSERTeq(capacity, TEST_ENTRIES * 2);
operation_delete(ctx);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_memops");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, "obj_memops",
PMEMOBJ_MIN_POOL * 10, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
struct test_object *object =
pmemobj_direct(pmemobj_root(pop, sizeof(struct test_object)));
UT_ASSERTne(object, NULL);
ulog_construct(OBJ_PTR_TO_OFF(pop, &object->undo),
TEST_ENTRIES, 1, &pop->p_ops);
test_redo(pop, object);
test_undo(pop, object);
pmemobj_close(pop);
DONE(NULL);
}
#ifdef _MSC_VER
/*
* Since libpmemobj is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmemobj_init)
MSVC_DESTR(libpmemobj_fini)
#endif
| 10,934 | 23.908884 | 76 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_include/libpmempool_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmempool_include.c -- include test for libpmempool
*
* this is only a compilation test - do not run this program
*/
#include <libpmempool.h>
int
main(int argc, char *argv[])
{
return 0;
}
| 1,800 | 38.152174 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_strdup/obj_strdup.c
|
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_strdup.c -- unit test for pmemobj_strdup
*/
#include <sys/param.h>
#include <string.h>
#include <wchar.h>
#include "unittest.h"
#include "libpmemobj.h"
#define LAYOUT_NAME "strdup"
TOID_DECLARE(char, 0);
TOID_DECLARE(wchar_t, 1);
enum type_number {
TYPE_SIMPLE,
TYPE_NULL,
TYPE_SIMPLE_ALLOC,
TYPE_SIMPLE_ALLOC_1,
TYPE_SIMPLE_ALLOC_2,
TYPE_NULL_ALLOC,
TYPE_NULL_ALLOC_1,
};
#define TEST_STR_1 "Test string 1"
#define TEST_STR_2 "Test string 2"
#define TEST_WCS_1 L"Test string 3"
#define TEST_WCS_2 L"Test string 4"
/*
* do_strdup -- duplicate a string to not allocated toid using pmemobj_strdup
*/
static void
do_strdup(PMEMobjpool *pop)
{
TOID(char) str = TOID_NULL(char);
TOID(wchar_t) wcs = TOID_NULL(wchar_t);
pmemobj_strdup(pop, &str.oid, TEST_STR_1, TYPE_SIMPLE);
pmemobj_wcsdup(pop, &wcs.oid, TEST_WCS_1, TYPE_SIMPLE);
UT_ASSERT(!TOID_IS_NULL(str));
UT_ASSERT(!TOID_IS_NULL(wcs));
UT_ASSERTeq(strcmp(D_RO(str), TEST_STR_1), 0);
UT_ASSERTeq(wcscmp(D_RO(wcs), TEST_WCS_1), 0);
}
/*
* do_strdup_null -- duplicate a NULL string to not allocated toid
*/
static void
do_strdup_null(PMEMobjpool *pop)
{
TOID(char) str = TOID_NULL(char);
TOID(wchar_t) wcs = TOID_NULL(wchar_t);
pmemobj_strdup(pop, &str.oid, NULL, TYPE_NULL);
pmemobj_wcsdup(pop, &wcs.oid, NULL, TYPE_NULL);
UT_ASSERT(TOID_IS_NULL(str));
UT_ASSERT(TOID_IS_NULL(wcs));
}
/*
* do_alloc -- allocate toid and duplicate a string
*/
static TOID(char)
do_alloc(PMEMobjpool *pop, const char *s, unsigned type_num)
{
TOID(char) str;
POBJ_ZNEW(pop, &str, char);
pmemobj_strdup(pop, &str.oid, s, type_num);
UT_ASSERT(!TOID_IS_NULL(str));
UT_ASSERTeq(strcmp(D_RO(str), s), 0);
return str;
}
/*
* do_wcs_alloc -- allocate toid and duplicate a wide character string
*/
static TOID(wchar_t)
do_wcs_alloc(PMEMobjpool *pop, const wchar_t *s, unsigned type_num)
{
TOID(wchar_t) str;
POBJ_ZNEW(pop, &str, wchar_t);
pmemobj_wcsdup(pop, &str.oid, s, type_num);
UT_ASSERT(!TOID_IS_NULL(str));
UT_ASSERTeq(wcscmp(D_RO(str), s), 0);
return str;
}
/*
* do_strdup_alloc -- duplicate a string to allocated toid
*/
static void
do_strdup_alloc(PMEMobjpool *pop)
{
TOID(char) str1 = do_alloc(pop, TEST_STR_1, TYPE_SIMPLE_ALLOC_1);
TOID(wchar_t) wcs1 = do_wcs_alloc(pop, TEST_WCS_1, TYPE_SIMPLE_ALLOC_1);
TOID(char) str2 = do_alloc(pop, TEST_STR_2, TYPE_SIMPLE_ALLOC_2);
TOID(wchar_t) wcs2 = do_wcs_alloc(pop, TEST_WCS_2, TYPE_SIMPLE_ALLOC_2);
pmemobj_strdup(pop, &str1.oid, D_RO(str2), TYPE_SIMPLE_ALLOC);
pmemobj_wcsdup(pop, &wcs1.oid, D_RO(wcs2), TYPE_SIMPLE_ALLOC);
UT_ASSERTeq(strcmp(D_RO(str1), D_RO(str2)), 0);
UT_ASSERTeq(wcscmp(D_RO(wcs1), D_RO(wcs2)), 0);
}
/*
* do_strdup_null_alloc -- duplicate a NULL string to allocated toid
*/
static void
do_strdup_null_alloc(PMEMobjpool *pop)
{
TOID(char) str1 = do_alloc(pop, TEST_STR_1, TYPE_NULL_ALLOC_1);
TOID(wchar_t) wcs1 = do_wcs_alloc(pop, TEST_WCS_1, TYPE_NULL_ALLOC_1);
TOID(char) str2 = TOID_NULL(char);
TOID(wchar_t) wcs2 = TOID_NULL(wchar_t);
pmemobj_strdup(pop, &str1.oid, D_RO(str2), TYPE_NULL_ALLOC);
pmemobj_wcsdup(pop, &wcs1.oid, D_RO(wcs2), TYPE_NULL_ALLOC);
UT_ASSERT(!TOID_IS_NULL(str1));
UT_ASSERT(!TOID_IS_NULL(wcs1));
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_strdup");
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
do_strdup(pop);
do_strdup_null(pop);
do_strdup_alloc(pop);
do_strdup_null_alloc(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 5,221 | 29.011494 | 77 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_fork/vmmalloc_fork.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_fork.c -- unit test for libvmmalloc fork() support
*
* usage: vmmalloc_fork [c|e] <nfork> <nthread>
*/
#ifdef __FreeBSD__
#include <stdlib.h>
#include <malloc_np.h>
#else
#include <malloc.h>
#endif
#include <sys/wait.h>
#include "unittest.h"
#define NBUFS 16
/*
* get_rand_size -- returns random size of allocation
*/
static size_t
get_rand_size(void)
{
return sizeof(int) + 64 * ((unsigned)rand() % 100);
}
/*
* do_test -- thread callback
*
* This function is called in separate thread and the main thread
* forks a child processes. Please be aware that any locks held in this
* function may potentially cause a deadlock.
*
* For example using rand() in this function may cause a deadlock because
* it grabs an internal lock.
*/
static void *
do_test(void *arg)
{
int **bufs = malloc(NBUFS * sizeof(void *));
UT_ASSERTne(bufs, NULL);
size_t *sizes = (size_t *)arg;
UT_ASSERTne(sizes, NULL);
for (int j = 0; j < NBUFS; j++) {
bufs[j] = malloc(sizes[j]);
UT_ASSERTne(bufs[j], NULL);
}
for (int j = 0; j < NBUFS; j++) {
UT_ASSERT(malloc_usable_size(bufs[j]) >= sizes[j]);
free(bufs[j]);
}
free(bufs);
return NULL;
}
int
main(int argc, char *argv[])
{
if (argc == 4 && argv[3][0] == 't') {
exit(0);
}
START(argc, argv, "vmmalloc_fork");
if (argc < 4)
UT_FATAL("usage: %s [c|e] <nfork> <nthread>", argv[0]);
unsigned nfork = ATOU(argv[2]);
unsigned nthread = ATOU(argv[3]);
os_thread_t thread[nthread];
unsigned first_child = 0;
unsigned **bufs = malloc(nfork * NBUFS * sizeof(void *));
UT_ASSERTne(bufs, NULL);
size_t *sizes = malloc(nfork * NBUFS * sizeof(size_t));
UT_ASSERTne(sizes, NULL);
int *pids1 = malloc(nfork * sizeof(pid_t));
UT_ASSERTne(pids1, NULL);
int *pids2 = malloc(nfork * sizeof(pid_t));
UT_ASSERTne(pids2, NULL);
for (unsigned i = 0; i < nfork; i++) {
for (unsigned j = 0; j < NBUFS; j++) {
unsigned idx = i * NBUFS + j;
sizes[idx] = get_rand_size();
bufs[idx] = malloc(sizes[idx]);
UT_ASSERTne(bufs[idx], NULL);
UT_ASSERT(malloc_usable_size(bufs[idx]) >= sizes[idx]);
}
size_t **thread_sizes = malloc(sizeof(size_t *) * nthread);
UT_ASSERTne(thread_sizes, NULL);
for (int t = 0; t < nthread; ++t) {
thread_sizes[t] = malloc(NBUFS * sizeof(size_t));
UT_ASSERTne(thread_sizes[t], NULL);
for (int j = 0; j < NBUFS; j++)
thread_sizes[t][j] = get_rand_size();
}
for (int t = 0; t < nthread; ++t) {
PTHREAD_CREATE(&thread[t], NULL,
do_test, thread_sizes[t]);
}
pids1[i] = fork();
if (pids1[i] == -1)
UT_OUT("fork failed");
UT_ASSERTne(pids1[i], -1);
if (pids1[i] == 0 && argv[1][0] == 'e' && i == nfork - 1) {
int fd = os_open("/dev/null", O_RDWR, S_IWUSR);
int res = dup2(fd, 1);
UT_ASSERTne(res, -1);
os_close(fd);
execl("/bin/echo", "/bin/echo", "Hello world!", NULL);
}
pids2[i] = getpid();
for (unsigned j = 0; j < NBUFS; j++) {
*bufs[i * NBUFS + j] = ((unsigned)pids2[i] << 16) + j;
}
if (pids1[i]) {
/* parent */
for (int t = 0; t < nthread; ++t) {
PTHREAD_JOIN(&thread[t], NULL);
free(thread_sizes[t]);
}
free(thread_sizes);
} else {
/* child */
first_child = i + 1;
}
for (unsigned ii = 0; ii < i; ii++) {
for (unsigned j = 0; j < NBUFS; j++) {
UT_ASSERTeq(*bufs[ii * NBUFS + j],
((unsigned)pids2[ii] << 16) + j);
}
}
}
for (unsigned i = first_child; i < nfork; i++) {
int status;
waitpid(pids1[i], &status, 0);
UT_ASSERT(WIFEXITED(status));
UT_ASSERTeq(WEXITSTATUS(status), 0);
}
free(pids1);
free(pids2);
for (int i = 0; i < nfork; i++) {
for (int j = 0; j < NBUFS; j++) {
int idx = i * NBUFS + j;
UT_ASSERT(malloc_usable_size(bufs[idx]) >= sizes[idx]);
free(bufs[idx]);
}
}
free(sizes);
free(bufs);
if (first_child == 0) {
DONE(NULL);
}
}
| 5,443 | 24.439252 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_is_pmem/pmem_is_pmem.c
|
/*
* Copyright 2014-2018, Intel Corporation
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_is_pmem.c -- unit test for pmem_is_pmem()
*
* usage: pmem_is_pmem file [env]
*/
#include "unittest.h"
#define NTHREAD 16
static void *Addr;
static size_t Size;
/*
* worker -- the work each thread performs
*/
static void *
worker(void *arg)
{
int *ret = (int *)arg;
*ret = pmem_is_pmem(Addr, Size);
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "pmem_is_pmem");
if (argc < 2 || argc > 3)
UT_FATAL("usage: %s file [env]", argv[0]);
if (argc == 3)
UT_ASSERTeq(os_setenv("PMEM_IS_PMEM_FORCE", argv[2], 1), 0);
Addr = pmem_map_file(argv[1], 0, 0, 0, &Size, NULL);
UT_ASSERTne(Addr, NULL);
os_thread_t threads[NTHREAD];
int ret[NTHREAD];
/* kick off NTHREAD threads */
for (int i = 0; i < NTHREAD; i++)
PTHREAD_CREATE(&threads[i], NULL, worker, &ret[i]);
/* wait for all the threads to complete */
for (int i = 0; i < NTHREAD; i++)
PTHREAD_JOIN(&threads[i], NULL);
/* verify that all the threads return the same value */
for (int i = 1; i < NTHREAD; i++)
UT_ASSERTeq(ret[0], ret[i]);
UT_OUT("threads.is_pmem(Addr, Size): %d", ret[0]);
UT_ASSERTeq(os_unsetenv("PMEM_IS_PMEM_FORCE"), 0);
UT_OUT("is_pmem(Addr, Size): %d", pmem_is_pmem(Addr, Size));
/* zero-sized region is not pmem */
UT_OUT("is_pmem(Addr, 0): %d", pmem_is_pmem(Addr, 0));
UT_OUT("is_pmem(Addr + Size / 2, 0): %d",
pmem_is_pmem((char *)Addr + Size / 2, 0));
UT_OUT("is_pmem(Addr + Size, 0): %d",
pmem_is_pmem((char *)Addr + Size, 0));
DONE(NULL);
}
| 3,174 | 30.127451 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmem_obc_int/rpmem_obc_int.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_obc_int.c -- integration test for rpmem_obc and rpmemd_obc modules
*/
#include "unittest.h"
#include "pmemcommon.h"
#include "librpmem.h"
#include "rpmem.h"
#include "rpmem_proto.h"
#include "rpmem_common.h"
#include "rpmem_util.h"
#include "rpmem_obc.h"
#include "rpmemd_obc.h"
#include "rpmemd_log.h"
#include "os.h"
#define POOL_SIZE 1024
#define NLANES 32
#define NLANES_RESP 16
#define PROVIDER RPMEM_PROV_LIBFABRIC_SOCKETS
#define POOL_DESC "pool_desc"
#define RKEY 0xabababababababab
#define RADDR 0x0101010101010101
#define PORT 1234
#define PERSIST_METHOD RPMEM_PM_GPSPM
#define RESP_ATTR_INIT {\
.port = PORT,\
.rkey = RKEY,\
.raddr = RADDR,\
.persist_method = PERSIST_METHOD,\
.nlanes = NLANES_RESP,\
}
#define REQ_ATTR_INIT {\
.pool_size = POOL_SIZE,\
.nlanes = NLANES,\
.provider = PROVIDER,\
.pool_desc = POOL_DESC,\
}
#define POOL_ATTR_INIT {\
.signature = "<RPMEM>",\
.major = 1,\
.compat_features = 2,\
.incompat_features = 3,\
.ro_compat_features = 4,\
.poolset_uuid = "POOLSET_UUID0123",\
.uuid = "UUID0123456789AB",\
.next_uuid = "NEXT_UUID0123456",\
.prev_uuid = "PREV_UUID0123456",\
.user_flags = "USER_FLAGS012345",\
}
#define POOL_ATTR_ALT {\
.signature = "<ALT>",\
.major = 5,\
.compat_features = 6,\
.incompat_features = 7,\
.ro_compat_features = 8,\
.poolset_uuid = "UUID_POOLSET_ALT",\
.uuid = "ALT_UUIDCDEFFEDC",\
.next_uuid = "456UUID_NEXT_ALT",\
.prev_uuid = "UUID012_ALT_PREV",\
.user_flags = "012345USER_FLAGS",\
}
TEST_CASE_DECLARE(client_create);
TEST_CASE_DECLARE(client_open);
TEST_CASE_DECLARE(client_set_attr);
TEST_CASE_DECLARE(server);
/*
* client_create -- perform create request
*/
int
client_create(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: %s <addr>[:<port>]", tc->name);
char *target = argv[0];
int ret;
struct rpmem_obc *rpc;
struct rpmem_target_info *info;
struct rpmem_req_attr req = REQ_ATTR_INIT;
struct rpmem_pool_attr pool_attr = POOL_ATTR_INIT;
struct rpmem_resp_attr ex_res = RESP_ATTR_INIT;
struct rpmem_resp_attr res;
info = rpmem_target_parse(target);
UT_ASSERTne(info, NULL);
rpc = rpmem_obc_init();
UT_ASSERTne(rpc, NULL);
ret = rpmem_obc_connect(rpc, info);
UT_ASSERTeq(ret, 0);
rpmem_target_free(info);
ret = rpmem_obc_monitor(rpc, 1);
UT_ASSERTeq(ret, 1);
ret = rpmem_obc_create(rpc, &req, &res, &pool_attr);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(ex_res.port, res.port);
UT_ASSERTeq(ex_res.rkey, res.rkey);
UT_ASSERTeq(ex_res.raddr, res.raddr);
UT_ASSERTeq(ex_res.persist_method, res.persist_method);
UT_ASSERTeq(ex_res.nlanes, res.nlanes);
ret = rpmem_obc_monitor(rpc, 1);
UT_ASSERTeq(ret, 1);
ret = rpmem_obc_close(rpc, 0);
UT_ASSERTeq(ret, 0);
ret = rpmem_obc_disconnect(rpc);
UT_ASSERTeq(ret, 0);
rpmem_obc_fini(rpc);
return 1;
}
/*
* client_open -- perform open request
*/
int
client_open(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: %s <addr>[:<port>]", tc->name);
char *target = argv[0];
int ret;
struct rpmem_obc *rpc;
struct rpmem_target_info *info;
struct rpmem_req_attr req = REQ_ATTR_INIT;
struct rpmem_pool_attr ex_pool_attr = POOL_ATTR_INIT;
struct rpmem_pool_attr pool_attr;
struct rpmem_resp_attr ex_res = RESP_ATTR_INIT;
struct rpmem_resp_attr res;
info = rpmem_target_parse(target);
UT_ASSERTne(info, NULL);
rpc = rpmem_obc_init();
UT_ASSERTne(rpc, NULL);
ret = rpmem_obc_connect(rpc, info);
UT_ASSERTeq(ret, 0);
rpmem_target_free(info);
ret = rpmem_obc_monitor(rpc, 1);
UT_ASSERTeq(ret, 1);
ret = rpmem_obc_open(rpc, &req, &res, &pool_attr);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(ex_res.port, res.port);
UT_ASSERTeq(ex_res.rkey, res.rkey);
UT_ASSERTeq(ex_res.raddr, res.raddr);
UT_ASSERTeq(ex_res.persist_method, res.persist_method);
UT_ASSERTeq(ex_res.nlanes, res.nlanes);
UT_ASSERTeq(memcmp(&ex_pool_attr, &pool_attr,
sizeof(ex_pool_attr)), 0);
ret = rpmem_obc_monitor(rpc, 1);
UT_ASSERTeq(ret, 1);
ret = rpmem_obc_close(rpc, 0);
UT_ASSERTeq(ret, 0);
ret = rpmem_obc_disconnect(rpc);
UT_ASSERTeq(ret, 0);
rpmem_obc_fini(rpc);
return 1;
}
/*
* client_set_attr -- perform set attributes request
*/
int
client_set_attr(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: %s <addr>[:<port>]", tc->name);
char *target = argv[0];
int ret;
struct rpmem_obc *rpc;
struct rpmem_target_info *info;
const struct rpmem_pool_attr pool_attr = POOL_ATTR_ALT;
info = rpmem_target_parse(target);
UT_ASSERTne(info, NULL);
rpc = rpmem_obc_init();
UT_ASSERTne(rpc, NULL);
ret = rpmem_obc_connect(rpc, info);
UT_ASSERTeq(ret, 0);
rpmem_target_free(info);
ret = rpmem_obc_monitor(rpc, 1);
UT_ASSERTeq(ret, 1);
ret = rpmem_obc_set_attr(rpc, &pool_attr);
UT_ASSERTeq(ret, 0);
ret = rpmem_obc_monitor(rpc, 1);
UT_ASSERTeq(ret, 1);
ret = rpmem_obc_close(rpc, 0);
UT_ASSERTeq(ret, 0);
ret = rpmem_obc_disconnect(rpc);
UT_ASSERTeq(ret, 0);
rpmem_obc_fini(rpc);
return 1;
}
/*
* req_arg -- request callbacks argument
*/
struct req_arg {
struct rpmem_resp_attr resp;
struct rpmem_pool_attr pool_attr;
int closing;
};
/*
* req_create -- process create request
*/
static int
req_create(struct rpmemd_obc *obc, void *arg,
const struct rpmem_req_attr *req,
const struct rpmem_pool_attr *pool_attr)
{
struct rpmem_req_attr ex_req = REQ_ATTR_INIT;
struct rpmem_pool_attr ex_pool_attr = POOL_ATTR_INIT;
UT_ASSERTne(arg, NULL);
UT_ASSERTeq(ex_req.provider, req->provider);
UT_ASSERTeq(ex_req.pool_size, req->pool_size);
UT_ASSERTeq(ex_req.nlanes, req->nlanes);
UT_ASSERTeq(strcmp(ex_req.pool_desc, req->pool_desc), 0);
UT_ASSERTeq(memcmp(&ex_pool_attr, pool_attr, sizeof(ex_pool_attr)), 0);
struct req_arg *args = arg;
return rpmemd_obc_create_resp(obc, 0, &args->resp);
}
/*
* req_open -- process open request
*/
static int
req_open(struct rpmemd_obc *obc, void *arg,
const struct rpmem_req_attr *req)
{
struct rpmem_req_attr ex_req = REQ_ATTR_INIT;
UT_ASSERTne(arg, NULL);
UT_ASSERTeq(ex_req.provider, req->provider);
UT_ASSERTeq(ex_req.pool_size, req->pool_size);
UT_ASSERTeq(ex_req.nlanes, req->nlanes);
UT_ASSERTeq(strcmp(ex_req.pool_desc, req->pool_desc), 0);
struct req_arg *args = arg;
return rpmemd_obc_open_resp(obc, 0,
&args->resp, &args->pool_attr);
}
/*
* req_set_attr -- process set attributes request
*/
static int
req_set_attr(struct rpmemd_obc *obc, void *arg,
const struct rpmem_pool_attr *pool_attr)
{
struct rpmem_pool_attr ex_pool_attr = POOL_ATTR_ALT;
UT_ASSERTne(arg, NULL);
UT_ASSERTeq(memcmp(&ex_pool_attr, pool_attr, sizeof(ex_pool_attr)), 0);
return rpmemd_obc_set_attr_resp(obc, 0);
}
/*
* req_close -- process close request
*/
static int
req_close(struct rpmemd_obc *obc, void *arg, int flags)
{
UT_ASSERTne(arg, NULL);
struct req_arg *args = arg;
args->closing = 1;
return rpmemd_obc_close_resp(obc, 0);
}
/*
* REQ -- server request callbacks
*/
static struct rpmemd_obc_requests REQ = {
.create = req_create,
.open = req_open,
.close = req_close,
.set_attr = req_set_attr,
};
/*
* server -- run server and process clients requests
*/
int
server(const struct test_case *tc, int argc, char *argv[])
{
int ret;
struct req_arg arg = {
.resp = RESP_ATTR_INIT,
.pool_attr = POOL_ATTR_INIT,
.closing = 0,
};
struct rpmemd_obc *obc;
obc = rpmemd_obc_init(0, 1);
UT_ASSERTne(obc, NULL);
ret = rpmemd_obc_status(obc, 0);
UT_ASSERTeq(ret, 0);
while (1) {
ret = rpmemd_obc_process(obc, &REQ, &arg);
if (arg.closing) {
break;
} else {
UT_ASSERTeq(ret, 0);
}
}
ret = rpmemd_obc_process(obc, &REQ, &arg);
UT_ASSERTeq(ret, 1);
rpmemd_obc_fini(obc);
return 0;
}
/*
* test_cases -- available test cases
*/
static struct test_case test_cases[] = {
TEST_CASE(server),
TEST_CASE(client_create),
TEST_CASE(client_open),
TEST_CASE(client_set_attr),
};
#define NTESTS (sizeof(test_cases) / sizeof(test_cases[0]))
int
main(int argc, char *argv[])
{
START(argc, argv, "rpmem_obc");
common_init("rpmem_fip",
"RPMEM_LOG_LEVEL",
"RPMEM_LOG_FILE", 0, 0);
rpmemd_log_init("rpmemd", os_getenv("RPMEMD_LOG_FILE"), 0);
rpmemd_log_level = rpmemd_log_level_from_str(
os_getenv("RPMEMD_LOG_LEVEL"));
rpmem_util_cmds_init();
TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS);
rpmem_util_cmds_fini();
common_fini();
rpmemd_log_close();
DONE(NULL);
}
| 10,054 | 22.770686 | 75 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmempool_feature_remote/config.sh
|
#!/usr/bin/env bash
#
# Copyright 2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# pmempool_feature_remote/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
# pmempool feature does not support poolsets with remote replicas
# unittest contains only negative scenarios so no point to loop over
# all providers and persistency methods
CONF_GLOBAL_RPMEM_PROVIDER=sockets
CONF_GLOBAL_RPMEM_PMETHOD=GPSPM
| 1,954 | 42.444444 | 73 |
sh
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmem_basic/common_pm_policy.sh
|
#!/usr/bin/env bash
#
# Copyright 2017-2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# src/test/rpmem_basic/common_pm_policy.sh -- common part for TEST[10-11] scripts
#
set -e
LOG=rpmemd$UNITTEST_NUM.log
OUT=out$UNITTEST_NUM.log
rm -f $OUT
# create poolset and upload
run_on_node 0 "rm -rf ${RPMEM_POOLSET_DIR[0]} && mkdir -p ${RPMEM_POOLSET_DIR[0]} && mkdir -p ${NODE_DIR[0]}$POOLS_PART"
create_poolset $DIR/pool.set 8M:$PART_DIR/pool.part0 8M:$PART_DIR/pool.part1
copy_files_to_node 0 ${RPMEM_POOLSET_DIR[0]} $DIR/pool.set
# create pool and close it - local pool from file
SIMPLE_ARGS="test_create 0 pool.set ${NODE_ADDR[0]} pool 8M none test_close 0"
function test_pm_policy()
{
# initialize pmem
PMEM_IS_PMEM_FORCE=$1
export_vars_node 0 PMEM_IS_PMEM_FORCE
init_rpmem_on_node 1 0
# remove rpmemd log and pool parts
run_on_node 0 "rm -rf $PART_DIR && mkdir -p $PART_DIR && rm -f $LOG"
# execute, get log
expect_normal_exit run_on_node 1 ./rpmem_basic$EXESUFFIX $SIMPLE_ARGS
copy_files_from_node 0 . ${NODE_TEST_DIR[0]}/$LOG
# extract persist method and flush function
cat $LOG | $GREP -A2 "persistency policy:" >> $OUT
}
| 2,648 | 37.955882 | 120 |
sh
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmem_basic/config.sh
|
#!/usr/bin/env bash
#
# Copyright 2016-2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# rpmem_basic/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
CONF_RPMEM_PMETHOD[10]=APM
CONF_RPMEM_PMETHOD[11]=GPSPM
# Sockets provider does not detect fi_cq_signal so it does not return
# from fi_cq_sread. It causes this test to hang sporadically.
# https://github.com/ofiwg/libfabric/pull/3645
CONF_RPMEM_PROVIDER[12]=verbs
| 2,033 | 39.68 | 73 |
sh
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmem_basic/setup2to1.sh
|
#!/usr/bin/env bash
#
# Copyright 2016-2017, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# src/test/rpmem_basic/setup2to1.sh -- common part for TEST[7-] scripts
#
POOLS_DIR=pools
POOLS_PART=pool_parts
TEST_LOG_FILE=test$UNITTEST_NUM.log
TEST_LOG_LEVEL=3
#
# This unit test requires 4 nodes, but nodes #0 and #3 should be the same
# physical machine - they should have the same NODE[n] addresses but
# different NODE_ADDR[n] addresses in order to test "2-to-1" configuration.
# Node #1 is being replicated to the node #0 and node #2 is being replicated
# to the node #3.
#
require_nodes 4
REPLICA[1]=0
REPLICA[2]=3
for node in 1 2; do
require_node_libfabric ${node} $RPMEM_PROVIDER
require_node_libfabric ${REPLICA[${node}]} $RPMEM_PROVIDER
export_vars_node ${node} TEST_LOG_FILE
export_vars_node ${node} TEST_LOG_LEVEL
require_node_log_files ${node} $PMEM_LOG_FILE
require_node_log_files ${node} $RPMEM_LOG_FILE
require_node_log_files ${node} $TEST_LOG_FILE
require_node_log_files ${REPLICA[${node}]} $RPMEMD_LOG_FILE
REP_ADDR[${node}]=${NODE_ADDR[${REPLICA[${node}]}]}
PART_DIR[${node}]=${NODE_DIR[${REPLICA[${node}]}]}$POOLS_PART
RPMEM_POOLSET_DIR[${REPLICA[${node}]}]=${NODE_DIR[${REPLICA[${node}]}]}$POOLS_DIR
init_rpmem_on_node ${node} ${REPLICA[${node}]}
PID_FILE[${node}]="pidfile${UNITTEST_NUM}-${node}.pid"
clean_remote_node ${node} ${PID_FILE[${node}]}
done
| 2,972 | 37.115385 | 82 |
sh
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmem_basic/rpmem_basic.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_basic.c -- unit test for rpmem operations
*/
#include "unittest.h"
#include "librpmem.h"
#include "pool_hdr.h"
#include "set.h"
#include "util.h"
#include "out.h"
#include "rpmem_common.h"
#include "rpmem_fip_common.h"
/*
* Use default terminal command for terminating session in user flags field
* in order to make sure this is not interpreted by terminal.
*/
#define POOL_ATTR_INIT {\
.signature = "<RPMEM>",\
.major = 1,\
.compat_features = 2,\
.incompat_features = 2,\
.ro_compat_features = 4,\
.poolset_uuid = "POOLSET_UUID0123",\
.uuid = "UUID0123456789AB",\
.next_uuid = "NEXT_UUID0123456",\
.prev_uuid = "PREV_UUID0123456",\
.user_flags = "USER_FLAGS\0\0\0\n~.",\
}
/* as above but with SINGLEHDR incompat feature */
#define POOL_ATTR_INIT_SINGLEHDR {\
.signature = "<RPMEM>",\
.major = 1,\
.compat_features = 2,\
.incompat_features = 3,\
.ro_compat_features = 4,\
.poolset_uuid = "POOLSET_UUID0123",\
.uuid = "UUID0123456789AB",\
.next_uuid = "NEXT_UUID0123456",\
.prev_uuid = "PREV_UUID0123456",\
.user_flags = "USER_FLAGS\0\0\0\n~.",\
}
#define POOL_ATTR_ALT {\
.signature = "<ALT>",\
.major = 5,\
.compat_features = 6,\
.incompat_features = 2,\
.ro_compat_features = 8,\
.poolset_uuid = "UUID_POOLSET_ALT",\
.uuid = "ALT_UUIDCDEFFEDC",\
.next_uuid = "456UUID_NEXT_ALT",\
.prev_uuid = "UUID012_ALT_PREV",\
.user_flags = "\0\0\0\n~._ALT_FLAGS",\
}
/* as above but with SINGLEHDR incompat feature */
#define POOL_ATTR_ALT_SINGLEHDR {\
.signature = "<ALT>",\
.major = 5,\
.compat_features = 6,\
.incompat_features = 3,\
.ro_compat_features = 8,\
.poolset_uuid = "UUID_POOLSET_ALT",\
.uuid = "ALT_UUIDCDEFFEDC",\
.next_uuid = "456UUID_NEXT_ALT",\
.prev_uuid = "UUID012_ALT_PREV",\
.user_flags = "\0\0\0\n~._ALT_FLAGS",\
}
static const struct rpmem_pool_attr pool_attrs[] = {
POOL_ATTR_INIT,
POOL_ATTR_INIT_SINGLEHDR,
POOL_ATTR_ALT,
POOL_ATTR_ALT_SINGLEHDR
};
static const char *pool_attr_names[] = {
"init",
"init_singlehdr",
"alt",
"alt_singlehdr"
};
#define POOL_ATTR_INIT_INDEX 0
#define NLANES 32
struct pool_entry {
RPMEMpool *rpp;
const char *target;
void *pool;
size_t size;
unsigned nlanes;
int is_mem;
int error_must_occur;
int exp_errno;
};
#define MAX_IDS 1024
static struct pool_entry pools[MAX_IDS];
/*
* init_pool -- map local pool file or allocate memory region
*/
static void
init_pool(struct pool_entry *pool, const char *target, const char *pool_path,
const char *pool_size)
{
pool->target = target;
pool->exp_errno = 0;
pool->nlanes = NLANES;
int ret = util_parse_size(pool_size, &pool->size);
UT_ASSERTeq(ret, 0);
int flags = PMEM_FILE_CREATE;
if (pool->size)
flags |= PMEM_FILE_EXCL;
if (strncmp(pool_path, "mem", strlen("mem")) == 0) {
pool->pool = PAGEALIGNMALLOC(pool->size);
pool->is_mem = 1;
} else {
pool->pool = pmem_map_file(pool_path, pool->size,
flags, 0666, &pool->size, NULL);
UT_ASSERTne(pool->pool, NULL);
/*
* This is a workaround for an issue with using device dax with
* libibverbs. The problem is that libfabric to handle fork()
* function calls correctly use ibv_fork_init(3) which makes
* all registered memory being madvised with MADV_DONTFORK flag.
* In libpmemobj the remote replication is performed without
* pool header (first 4k). In such case the address passed to
* madvise(2) is aligned to 4k, but device dax can require
* different alignment (default is 2MB). This workaround
* madvises the entire memory region before registering
* it by fi_mr_reg(3).
*
* The librpmem client requires fork() support to work
* correctly.
*/
ret = os_madvise(pool->pool, pool->size, MADV_DONTFORK);
UT_ASSERTeq(ret, 0);
pool->is_mem = 0;
os_unlink(pool_path);
}
}
/*
* free_pool -- unmap local pool file or free memory region
*/
static void
free_pool(struct pool_entry *pool)
{
if (pool->is_mem)
FREE(pool->pool);
else
UT_ASSERTeq(pmem_unmap(pool->pool, pool->size), 0);
pool->pool = NULL;
pool->rpp = NULL;
pool->target = NULL;
}
/*
* str_2_pool_attr_index -- convert string to the index of pool attributes
*/
static int
str_2_pool_attr_index(const char *str)
{
COMPILE_ERROR_ON((sizeof(pool_attr_names) / sizeof(pool_attr_names[0]))
!= (sizeof(pool_attrs) / sizeof(pool_attrs[0])));
const unsigned num_of_names = sizeof(pool_attr_names) /
sizeof(pool_attr_names[0]);
for (int i = 0; i < num_of_names; ++i) {
if (strcmp(str, pool_attr_names[i]) == 0) {
return i;
}
}
UT_FATAL("unrecognized name of pool attributes set: %s", str);
}
/*
* cmp_pool_attr -- check pool attributes
*/
static void
cmp_pool_attr(const struct rpmem_pool_attr *attr1,
const struct rpmem_pool_attr *attr2)
{
if (attr2 == NULL) {
UT_ASSERTeq(util_is_zeroed(attr1, sizeof(*attr1)), 1);
} else {
UT_ASSERTeq(memcmp(attr1->signature, attr2->signature,
sizeof(attr1->signature)), 0);
UT_ASSERTeq(attr1->major, attr2->major);
UT_ASSERTeq(attr1->compat_features, attr2->compat_features);
UT_ASSERTeq(attr1->ro_compat_features,
attr2->ro_compat_features);
UT_ASSERTeq(attr1->incompat_features, attr2->incompat_features);
UT_ASSERTeq(memcmp(attr1->uuid, attr2->uuid,
sizeof(attr1->uuid)), 0);
UT_ASSERTeq(memcmp(attr1->poolset_uuid, attr2->poolset_uuid,
sizeof(attr1->poolset_uuid)), 0);
UT_ASSERTeq(memcmp(attr1->prev_uuid, attr2->prev_uuid,
sizeof(attr1->prev_uuid)), 0);
UT_ASSERTeq(memcmp(attr1->next_uuid, attr2->next_uuid,
sizeof(attr1->next_uuid)), 0);
}
}
/*
* check_return_and_errno - validate return value and errno
*/
#define check_return_and_errno(ret, error_must_occur, exp_errno) \
if ((exp_errno) != 0) { \
if (error_must_occur) { \
UT_ASSERTne(ret, 0); \
UT_ASSERTeq(errno, exp_errno); \
} else { \
if ((ret) != 0) { \
UT_ASSERTeq(errno, exp_errno); \
} \
} \
} else { \
UT_ASSERTeq(ret, 0); \
}
/*
* test_create -- test case for creating remote pool
*
* The <option> argument values:
* - "singlehdr" - the incompat feature flag is set to POOL_FEAT_SINGLEHDR,
* - "noattr" - NULL pool attributes are passed to rpmem_create(),
* - "none" or any other string - no options.
*/
static int
test_create(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 6)
UT_FATAL("usage: test_create <id> <pool set> "
"<target> <pool> <size> <option>");
const char *id_str = argv[0];
const char *pool_set = argv[1];
const char *target = argv[2];
const char *pool_path = argv[3];
const char *size_str = argv[4];
const char *option = argv[5];
int id = atoi(id_str);
UT_ASSERT(id >= 0 && id < MAX_IDS);
struct pool_entry *pool = &pools[id];
UT_ASSERTeq(pool->rpp, NULL);
struct rpmem_pool_attr *rattr = NULL;
struct rpmem_pool_attr pool_attr = pool_attrs[POOL_ATTR_INIT_INDEX];
if (strcmp(option, "noattr") == 0) {
/* pass NULL pool attributes */
} else {
if (strcmp(option, "singlehdr") == 0)
pool_attr.incompat_features |= POOL_FEAT_SINGLEHDR;
rattr = &pool_attr;
}
init_pool(pool, target, pool_path, size_str);
pool->rpp = rpmem_create(target, pool_set, pool->pool,
pool->size, &pool->nlanes, rattr);
if (pool->rpp) {
UT_ASSERTne(pool->nlanes, 0);
UT_OUT("%s: created", pool_set);
} else {
UT_OUT("!%s", pool_set);
free_pool(pool);
}
return 6;
}
/*
* test_open -- test case for opening remote pool
*
* The <option> argument values:
* - "singlehdr" - the incompat feature flag is set to POOL_FEAT_SINGLEHDR,
* - "noattr" - NULL pool attributes are passed to rpmem_create(),
* - "none" or any other string - no options.
*/
static int
test_open(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 7)
UT_FATAL("usage: test_open <id> <pool set> "
"<target> <pool> <size> <pool attr name> "
"<option>");
const char *id_str = argv[0];
const char *pool_set = argv[1];
const char *target = argv[2];
const char *pool_path = argv[3];
const char *size_str = argv[4];
const char *pool_attr_name = argv[5];
const char *option = argv[6];
int id = atoi(id_str);
UT_ASSERT(id >= 0 && id < MAX_IDS);
struct pool_entry *pool = &pools[id];
UT_ASSERTeq(pool->rpp, NULL);
const struct rpmem_pool_attr *rattr = NULL;
const int pool_attr_id = str_2_pool_attr_index(pool_attr_name);
struct rpmem_pool_attr pool_attr = pool_attrs[pool_attr_id];
if (strcmp(option, "noattr") == 0) {
/* pass NULL pool attributes */
} else {
/* pass non-NULL pool attributes */
if (strcmp(option, "singlehdr") == 0)
pool_attr.incompat_features |= POOL_FEAT_SINGLEHDR;
rattr = &pool_attr;
}
init_pool(pool, target, pool_path, size_str);
struct rpmem_pool_attr pool_attr_open;
pool->rpp = rpmem_open(target, pool_set, pool->pool,
pool->size, &pool->nlanes, &pool_attr_open);
if (pool->rpp) {
cmp_pool_attr(&pool_attr_open, rattr);
UT_ASSERTne(pool->nlanes, 0);
UT_OUT("%s: opened", pool_set);
} else {
UT_OUT("!%s", pool_set);
free_pool(pool);
}
return 7;
}
/*
* test_close -- test case for closing remote pool
*/
static int
test_close(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: test_close <id>");
const char *id_str = argv[0];
int id = atoi(id_str);
UT_ASSERT(id >= 0 && id < MAX_IDS);
struct pool_entry *pool = &pools[id];
UT_ASSERTne(pool->rpp, NULL);
int ret = rpmem_close(pool->rpp);
check_return_and_errno(ret, pool->error_must_occur, pool->exp_errno);
free_pool(pool);
return 1;
}
typedef int (*flush_func)(RPMEMpool *rpp, size_t off,
size_t size, unsigned lane);
static int
persist_relaxed(RPMEMpool *rpp, size_t off,
size_t size, unsigned lane)
{
return rpmem_persist(rpp, off, size, lane, RPMEM_PERSIST_RELAXED);
}
static int
persist_normal(RPMEMpool *rpp, size_t off,
size_t size, unsigned lane)
{
return rpmem_persist(rpp, off, size, lane, 0);
}
/*
* thread_arg -- persist worker thread arguments
*/
struct thread_arg {
RPMEMpool *rpp;
size_t off;
size_t size;
unsigned nops;
unsigned lane;
int error_must_occur;
int exp_errno;
flush_func flush;
};
/*
* thread_func -- worker thread function
*/
static void *
thread_func(void *arg)
{
struct thread_arg *args = arg;
size_t flush_size = args->size / args->nops;
UT_ASSERTeq(args->size % args->nops, 0);
for (unsigned i = 0; i < args->nops; i++) {
size_t off = args->off + i * flush_size;
size_t left = args->size - i * flush_size;
size_t size = left < flush_size ?
left : flush_size;
int ret = args->flush(args->rpp, off, size, args->lane);
check_return_and_errno(ret, args->error_must_occur,
args->exp_errno);
}
return NULL;
}
static void
test_flush(unsigned id, unsigned seed, unsigned nthreads, unsigned nops,
flush_func func)
{
struct pool_entry *pool = &pools[id];
UT_ASSERTne(pool->nlanes, 0);
nthreads = min(nthreads, pool->nlanes);
size_t buff_size = pool->size - POOL_HDR_SIZE;
if (seed) {
srand(seed);
uint8_t *buff = (uint8_t *)((uintptr_t)pool->pool +
POOL_HDR_SIZE);
for (size_t i = 0; i < buff_size; i++)
buff[i] = rand();
}
os_thread_t *threads = MALLOC(nthreads * sizeof(*threads));
struct thread_arg *args = MALLOC(nthreads * sizeof(*args));
size_t size_per_thread = buff_size / nthreads;
UT_ASSERTeq(buff_size % nthreads, 0);
for (unsigned i = 0; i < nthreads; i++) {
args[i].rpp = pool->rpp;
args[i].nops = nops;
args[i].lane = (unsigned)i;
args[i].off = POOL_HDR_SIZE + i * size_per_thread;
args[i].flush = func;
size_t size_left = buff_size - size_per_thread * i;
args[i].size = size_left < size_per_thread ?
size_left : size_per_thread;
args[i].exp_errno = pool->exp_errno;
args[i].error_must_occur = pool->error_must_occur;
PTHREAD_CREATE(&threads[i], NULL, thread_func, &args[i]);
}
for (int i = 0; i < nthreads; i++)
PTHREAD_JOIN(&threads[i], NULL);
FREE(args);
FREE(threads);
}
/*
* test_persist -- test case for persist operation
*/
static int
test_persist(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 4)
UT_FATAL("usage: test_persist <id> <seed> <nthreads> "
"<nops> <relaxed>");
unsigned id = ATOU(argv[0]);
UT_ASSERT(id >= 0 && id < MAX_IDS);
unsigned seed = ATOU(argv[1]);
unsigned nthreads = ATOU(argv[2]);
unsigned nops = ATOU(argv[3]);
unsigned relaxed = ATOU(argv[4]);
if (relaxed)
test_flush(id, seed, nthreads, nops, persist_relaxed);
else
test_flush(id, seed, nthreads, nops, persist_normal);
return 5;
}
/*
* test_deep_persist -- test case for deep_persist operation
*/
static int
test_deep_persist(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 4)
UT_FATAL("usage: test_deep_persist <id> <seed> <nthreads> "
"<nops>");
unsigned id = ATOU(argv[0]);
UT_ASSERT(id >= 0 && id < MAX_IDS);
unsigned seed = ATOU(argv[1]);
unsigned nthreads = ATOU(argv[2]);
unsigned nops = ATOU(argv[3]);
test_flush(id, seed, nthreads, nops, rpmem_deep_persist);
return 4;
}
/*
* test_read -- test case for read operation
*/
static int
test_read(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 2)
UT_FATAL("usage: test_read <id> <seed>");
int id = atoi(argv[0]);
UT_ASSERT(id >= 0 && id < MAX_IDS);
struct pool_entry *pool = &pools[id];
srand(ATOU(argv[1]));
int ret;
uint8_t *buff = (uint8_t *)((uintptr_t)pool->pool + POOL_HDR_SIZE);
size_t buff_size = pool->size - POOL_HDR_SIZE;
ret = rpmem_read(pool->rpp, buff, POOL_HDR_SIZE, buff_size, 0);
check_return_and_errno(ret, pool->error_must_occur, pool->exp_errno);
if (ret == 0) {
for (size_t i = 0; i < buff_size; i++) {
uint8_t r = rand();
UT_ASSERTeq(buff[i], r);
}
}
return 2;
}
/*
* test_remove -- test case for remove operation
*/
static int
test_remove(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 4)
UT_FATAL("usage: test_remove <target> <pool set> "
"<force> <rm pool set>");
const char *target = argv[0];
const char *pool_set = argv[1];
int force = atoi(argv[2]);
int rm_pool_set = atoi(argv[3]);
int flags = 0;
if (force)
flags |= RPMEM_REMOVE_FORCE;
if (rm_pool_set)
flags |= RPMEM_REMOVE_POOL_SET;
int ret;
ret = rpmem_remove(target, pool_set, flags);
UT_ASSERTeq(ret, 0);
return 4;
}
/*
* test_set_attr -- test case for set attributes operation
*/
static int
test_set_attr(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 3)
UT_FATAL("usage: test_set_attr <id> <pool attr name> <option>");
const char *id_str = argv[0];
const char *pool_attr_name = argv[1];
const char *option = argv[2];
int id = atoi(id_str);
UT_ASSERT(id >= 0 && id < MAX_IDS);
struct pool_entry *pool = &pools[id];
UT_ASSERTne(pool->rpp, NULL);
struct rpmem_pool_attr *rattr = NULL;
const int pool_attr_id = str_2_pool_attr_index(pool_attr_name);
struct rpmem_pool_attr pool_attr = pool_attrs[pool_attr_id];
if (strcmp(option, "noattr") == 0) {
/* pass NULL pool attributes */
} else {
/* pass non-NULL pool attributes */
if (strcmp(option, "singlehdr") == 0)
pool_attr.incompat_features |= POOL_FEAT_SINGLEHDR;
rattr = &pool_attr;
}
int ret = rpmem_set_attr(pool->rpp, rattr);
if (ret)
UT_OUT("set attributes failed (%s)", pool_attr_name);
else
UT_OUT("set attributes succeeded (%s)", pool_attr_name);
return 3;
}
/*
* check_pool -- check if remote pool contains specified random sequence
*/
static int
check_pool(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 3)
UT_FATAL("usage: fill_pool <pool set> <seed> <size>");
char *pool_set = argv[0];
srand(ATOU(argv[1]));
int ret;
size_t size;
ret = util_parse_size(argv[2], &size);
size -= POOL_HDR_SIZE;
struct pool_set *set;
ret = util_poolset_create_set(&set, pool_set, 0, 0, 0);
UT_ASSERTeq(ret, 0);
ret = util_pool_open_nocheck(set, 0);
UT_ASSERTeq(ret, 0);
uint8_t *data = set->replica[0]->part[0].addr;
for (size_t i = 0; i < size; i++) {
uint8_t r = rand();
UT_ASSERTeq(data[POOL_HDR_SIZE + i], r);
}
util_poolset_close(set, DO_NOT_DELETE_PARTS);
return 3;
}
/*
* fill_pool -- fill remote pool with specified random sequence
*/
static int
fill_pool(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 2)
UT_FATAL("usage: fill_pool <pool set> <seed>");
char *pool_set = argv[0];
srand(ATOU(argv[1]));
int ret;
struct pool_set *set;
ret = util_poolset_create_set(&set, pool_set, 0, 0, 0);
UT_ASSERTeq(ret, 0);
ret = util_pool_open_nocheck(set, 0);
UT_ASSERTeq(ret, 0);
uint8_t *data = set->replica[0]->part[0].addr;
for (size_t i = POOL_HDR_SIZE; i < set->poolsize; i++)
data[i] = rand();
util_poolset_close(set, DO_NOT_DELETE_PARTS);
return 2;
}
enum wait_type {
WAIT,
NOWAIT
};
static const char *wait_type_str[2] = {
"wait",
"nowait"
};
static enum wait_type
str2wait(const char *str)
{
for (int i = 0; i < ARRAY_SIZE(wait_type_str); ++i) {
if (strcmp(wait_type_str[i], str) == 0)
return (enum wait_type)i;
}
UT_FATAL("'%s' does not match <wait|nowait>", str);
}
#define SSH_EXE "ssh"
#define RPMEMD_TERMINATE_CMD SSH_EXE " -tt %s kill -9 %d"
#define GET_RPMEMD_PID_CMD SSH_EXE " %s cat %s"
#define COUNT_RPMEMD_CMD SSH_EXE " %s ps -A | grep -c %d"
/*
* rpmemd_kill -- kill target rpmemd
*/
static int
rpmemd_kill(const char *target, int pid)
{
char cmd[100];
snprintf(cmd, sizeof(cmd), RPMEMD_TERMINATE_CMD, target, pid);
return system(cmd);
}
/*
* popen_readi -- popen cmd and read integer
*/
static int
popen_readi(const char *cmd)
{
FILE *stream = popen(cmd, "r");
UT_ASSERT(stream != NULL);
int i;
int ret = fscanf(stream, "%d", &i);
UT_ASSERT(ret == 1);
pclose(stream);
return i;
}
/*
* rpmemd_get_pid -- get target rpmemd pid
*/
static int
rpmemd_get_pid(const char *target, const char *pid_file)
{
char cmd[PATH_MAX];
snprintf(cmd, sizeof(cmd), GET_RPMEMD_PID_CMD, target, pid_file);
return popen_readi(cmd);
}
/*
* rpmemd_is_running -- tell if target rpmemd is running
*/
static int
rpmemd_is_running(const char *target, int pid)
{
char cmd[100];
snprintf(cmd, sizeof(cmd), COUNT_RPMEMD_CMD, target, pid);
return popen_readi(cmd) > 0;
}
/*
* rpmemd_kill_wait -- kill target rpmemd and wait for it to stop
*/
static void
rpmemd_kill_wait(const char *target, const char *pid_file, enum wait_type wait)
{
int pid = rpmemd_get_pid(target, pid_file);
int ret;
do {
ret = rpmemd_kill(target, pid);
if (ret != 0 || wait == NOWAIT) {
break;
}
} while (rpmemd_is_running(target, pid));
}
/*
* rpmemd_terminate -- terminate target rpmemd
*/
static int
rpmemd_terminate(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 3) {
UT_FATAL("usage: rpmemd_terminate <id> <pid file> "
"<wait|nowait>");
}
const char *id_str = argv[0];
const char *pid_file = argv[1];
const char *wait_str = argv[2];
int id = atoi(id_str);
UT_ASSERT(id >= 0 && id < MAX_IDS);
struct pool_entry *pool = &pools[id];
UT_ASSERTne(pool->target, NULL);
pool->exp_errno = ECONNRESET;
enum wait_type wait = str2wait(wait_str);
/*
* if process will wait for rpmemd to terminate it is sure error will
* occur
*/
pool->error_must_occur = wait == WAIT;
rpmemd_kill_wait(pool->target, pid_file, wait);
return 3;
}
/*
* test_persist_header -- test case for persisting data with offset < 4096
*
* if 'hdr' argument is used, test passes if rpmem_persist fails
* if 'nohdr' argument is used, test passes if rpmem_persist passes
*/
static int
test_persist_header(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 2)
UT_FATAL("usage: test_persist_header <id> "
"<hdr|nohdr> <relaxed>");
int id = atoi(argv[0]);
const char *hdr_str = argv[1];
int relaxed = atoi(argv[2]);
unsigned flags = 0;
if (relaxed)
flags |= RPMEM_PERSIST_RELAXED;
UT_ASSERT(id >= 0 && id < MAX_IDS);
struct pool_entry *pool = &pools[id];
int with_hdr;
if (strcmp(hdr_str, "hdr") == 0)
with_hdr = 1;
else if (strcmp(hdr_str, "nohdr") == 0)
with_hdr = 0;
else
UT_ASSERT(0);
for (size_t off = 0; off < POOL_HDR_SIZE; off += 8) {
int ret = rpmem_persist(pool->rpp, off, 8, 0, flags);
UT_ASSERTeq(ret, with_hdr ? -1 : 0);
}
return 3;
}
/*
* test_cases -- available test cases
*/
static struct test_case test_cases[] = {
TEST_CASE(test_create),
TEST_CASE(test_open),
TEST_CASE(test_set_attr),
TEST_CASE(test_close),
TEST_CASE(test_persist),
TEST_CASE(test_deep_persist),
TEST_CASE(test_read),
TEST_CASE(test_remove),
TEST_CASE(check_pool),
TEST_CASE(fill_pool),
TEST_CASE(rpmemd_terminate),
TEST_CASE(test_persist_header),
};
#define NTESTS (sizeof(test_cases) / sizeof(test_cases[0]))
int
main(int argc, char *argv[])
{
util_init();
rpmem_fip_probe_get("localhost", NULL);
START(argc, argv, "rpmem_basic");
out_init("rpmem_basic", "TEST_LOG_LEVEL", "TEST_LOG_FILE", 0, 0);
TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS);
out_fini();
DONE(NULL);
}
| 22,499 | 23.377031 | 79 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmem_basic/setup.sh
|
#!/usr/bin/env bash
#
# Copyright 2016-2017, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# src/test/rpmem_basic/setup.sh -- common part for TEST* scripts
#
set -e
require_nodes 2
require_node_libfabric 0 $RPMEM_PROVIDER $SETUP_LIBFABRIC_VERSION
require_node_libfabric 1 $RPMEM_PROVIDER $SETUP_LIBFABRIC_VERSION
require_node_log_files 0 $RPMEMD_LOG_FILE
require_node_log_files 1 $RPMEM_LOG_FILE
require_node_log_files 1 $PMEM_LOG_FILE
POOLS_DIR=pools
POOLS_PART=pool_parts
PART_DIR=${NODE_DIR[0]}/$POOLS_PART
RPMEM_POOLSET_DIR[0]=${NODE_DIR[0]}$POOLS_DIR
if [ -z "$SETUP_MANUAL_INIT_RPMEM" ]; then
init_rpmem_on_node 1 0
fi
| 2,130 | 38.462963 | 73 |
sh
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_realloc_inplace/vmem_realloc_inplace.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_realloc_inplace -- unit test for vmem_realloc
*
* usage: vmem_realloc_inplace [directory]
*/
#include "unittest.h"
#define POOL_SIZE (16 * 1024 * 1024)
int
main(int argc, char *argv[])
{
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_realloc_inplace");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
if (dir == NULL) {
/* allocate memory for function vmem_create_in_region() */
mem_pool = MMAP_ANON_ALIGNED(POOL_SIZE, 4 << 20);
vmp = vmem_create_in_region(mem_pool, POOL_SIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, POOL_SIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
int *test1 = vmem_malloc(vmp, 12 * 1024 * 1024);
UT_ASSERTne(test1, NULL);
int *test1r = vmem_realloc(vmp, test1, 6 * 1024 * 1024);
UT_ASSERTeq(test1r, test1);
test1r = vmem_realloc(vmp, test1, 12 * 1024 * 1024);
UT_ASSERTeq(test1r, test1);
test1r = vmem_realloc(vmp, test1, 8 * 1024 * 1024);
UT_ASSERTeq(test1r, test1);
int *test2 = vmem_malloc(vmp, 4 * 1024 * 1024);
UT_ASSERTne(test2, NULL);
/* 4MB => 16B */
int *test2r = vmem_realloc(vmp, test2, 16);
UT_ASSERTeq(test2r, NULL);
/* ... but the usable size is still 4MB. */
UT_ASSERTeq(vmem_malloc_usable_size(vmp, test2), 4 * 1024 * 1024);
/* 8MB => 16B */
test1r = vmem_realloc(vmp, test1, 16);
/*
* If the old size of the allocation is larger than
* the chunk size (4MB), we can reallocate it to 4MB first (in place),
* releasing some space, which makes it possible to do the actual
* shrinking...
*/
UT_ASSERTne(test1r, NULL);
UT_ASSERTne(test1r, test1);
UT_ASSERTeq(vmem_malloc_usable_size(vmp, test1r), 16);
/* ... and leaves some memory for new allocations. */
int *test3 = vmem_malloc(vmp, 3 * 1024 * 1024);
UT_ASSERTne(test3, NULL);
vmem_free(vmp, test1r);
vmem_free(vmp, test2r);
vmem_free(vmp, test3);
vmem_delete(vmp);
DONE(NULL);
}
| 3,606 | 30.094828 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_rm/libpmempool_rm.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmempool_rm -- a unittest for pmempool_rm.
*
*/
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include "unittest.h"
#define FATAL_USAGE(n) UT_FATAL("usage: %s [-f -l -r] path..", (n))
static PMEMobjpool *Pop;
int
main(int argc, char *argv[])
{
START(argc, argv, "libpmempool_rm");
if (argc < 2)
FATAL_USAGE(argv[0]);
unsigned flags = 0;
char *optstr = "flro";
int do_open = 0;
int opt;
while ((opt = getopt(argc, argv, optstr)) != -1) {
switch (opt) {
case 'f':
flags |= PMEMPOOL_RM_FORCE;
break;
case 'r':
flags |= PMEMPOOL_RM_POOLSET_REMOTE;
break;
case 'l':
flags |= PMEMPOOL_RM_POOLSET_LOCAL;
break;
case 'o':
do_open = 1;
break;
default:
FATAL_USAGE(argv[0]);
}
}
for (int i = optind; i < argc; i++) {
const char *path = argv[i];
if (do_open) {
Pop = pmemobj_open(path, NULL);
UT_ASSERTne(Pop, NULL);
}
int ret = pmempool_rm(path, flags);
if (ret) {
UT_OUT("!%s: %s", path, pmempool_errormsg());
}
if (do_open) {
UT_ASSERTne(Pop, NULL);
pmemobj_close(Pop);
}
}
DONE(NULL);
}
| 2,741 | 26.42 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_zones/obj_zones.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_zones.c -- allocates from a very large pool (exceeding 1 zone)
*
*/
#include <stddef.h>
#include "unittest.h"
#define LAYOUT_NAME "obj_zones"
#define ALLOC_SIZE ((8191 * (256 * 1024)) - 16) /* must evenly divide a zone */
/*
* test_create -- allocate all possible objects and log the number. It should
* exceed what would be possible on a single zone.
* Additionally, free one object so that we can later check that it can be
* allocated after the next open.
*/
static void
test_create(const char *path)
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, LAYOUT_NAME,
0, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
PMEMoid oid;
int n = 0;
while (1) {
if (pmemobj_alloc(pop, &oid, ALLOC_SIZE, 0, NULL, NULL) != 0)
break;
n++;
}
UT_OUT("allocated: %d", n);
pmemobj_free(&oid);
pmemobj_close(pop);
}
/*
* test_open -- in the open test we should be able to allocate exactly
* one object.
*/
static void
test_open(const char *path)
{
PMEMobjpool *pop;
if ((pop = pmemobj_open(path, LAYOUT_NAME)) == NULL)
UT_FATAL("!pmemobj_open: %s", path);
int ret = pmemobj_alloc(pop, NULL, ALLOC_SIZE, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
ret = pmemobj_alloc(pop, NULL, ALLOC_SIZE, 0, NULL, NULL);
UT_ASSERTne(ret, 0);
pmemobj_close(pop);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_zones");
if (argc != 3)
UT_FATAL("usage: %s file-name [open|create]", argv[0]);
const char *path = argv[1];
char op = argv[2][0];
if (op == 'c')
test_create(path);
else if (op == 'o')
test_open(path);
else
UT_FATAL("invalid operation");
DONE(NULL);
}
| 3,249 | 27.508772 | 79 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_rpmem_heap_interrupt/config.sh
|
#!/usr/bin/env bash
#
# Copyright 2016-2017, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# src/test/obj_rpmem_heap_interrupt/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=pmem
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 1,789 | 41.619048 | 73 |
sh
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_is_poolset/util_is_poolset.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_is_poolset.c -- unit test for util_is_poolset
*
* usage: util_is_poolset file
*/
#include "unittest.h"
#include "set.h"
#include "pmemcommon.h"
#include <errno.h>
#define LOG_PREFIX "ut"
#define LOG_LEVEL_VAR "TEST_LOG_LEVEL"
#define LOG_FILE_VAR "TEST_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
int
main(int argc, char *argv[])
{
START(argc, argv, "util_is_poolset");
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
if (argc < 2)
UT_FATAL("usage: %s file...",
argv[0]);
for (int i = 1; i < argc; i++) {
char *fname = argv[i];
int is_poolset = util_is_poolset_file(fname);
UT_OUT("util_is_poolset(%s): %d", fname, is_poolset);
}
common_fini();
DONE(NULL);
}
| 2,349 | 31.638889 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_ctl_config/obj_ctl_config.c
|
/*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_ctl_config.c -- tests for ctl configuration
*/
#include "unittest.h"
#include "out.h"
#define LAYOUT "obj_ctl_config"
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_ctl_config");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = pmemobj_open(path, LAYOUT);
if (pop == NULL)
UT_FATAL("!pmemobj_open: %s", path);
/* dump all available ctl read entry points */
int result;
pmemobj_ctl_get(pop, "prefault.at_open", &result);
UT_OUT("%d", result);
pmemobj_ctl_get(pop, "prefault.at_create", &result);
UT_OUT("%d", result);
pmemobj_close(pop);
DONE(NULL);
}
| 2,250 | 33.106061 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_locks_abort/obj_tx_locks_abort.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_locks_nested.c -- unit test for transaction locks
*/
#include "unittest.h"
#define LAYOUT_NAME "locks"
TOID_DECLARE_ROOT(struct root_obj);
TOID_DECLARE(struct obj, 1);
struct root_obj {
PMEMmutex lock;
TOID(struct obj) head;
};
struct obj {
int data;
PMEMmutex lock;
TOID(struct obj) next;
};
/*
* do_nested_tx-- (internal) nested transaction
*/
static void
do_nested_tx(PMEMobjpool *pop, TOID(struct obj) o, int value)
{
TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(o)->lock, TX_PARAM_NONE) {
TX_ADD(o);
D_RW(o)->data = value;
if (!TOID_IS_NULL(D_RO(o)->next)) {
/*
* Add the object to undo log, while the mutex
* it contains is not locked.
*/
TX_ADD(D_RO(o)->next);
do_nested_tx(pop, D_RO(o)->next, value);
}
} TX_END;
}
/*
* do_aborted_nested_tx -- (internal) aborted nested transaction
*/
static void
do_aborted_nested_tx(PMEMobjpool *pop, TOID(struct obj) oid, int value)
{
TOID(struct obj) o = oid;
TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(o)->lock, TX_PARAM_NONE) {
TX_ADD(o);
D_RW(o)->data = value;
if (!TOID_IS_NULL(D_RO(o)->next)) {
/*
* Add the object to undo log, while the mutex
* it contains is not locked.
*/
TX_ADD(D_RO(o)->next);
do_nested_tx(pop, D_RO(o)->next, value);
}
pmemobj_tx_abort(EINVAL);
} TX_FINALLY {
o = oid;
while (!TOID_IS_NULL(o)) {
if (pmemobj_mutex_trylock(pop, &D_RW(o)->lock)) {
UT_OUT("trylock failed");
} else {
UT_OUT("trylock succeeded");
pmemobj_mutex_unlock(pop, &D_RW(o)->lock);
}
o = D_RO(o)->next;
}
} TX_END;
}
/*
* do_check -- (internal) print 'data' value of each object on the list
*/
static void
do_check(TOID(struct obj) o)
{
while (!TOID_IS_NULL(o)) {
UT_OUT("data = %d", D_RO(o)->data);
o = D_RO(o)->next;
}
}
int
main(int argc, char *argv[])
{
PMEMobjpool *pop;
START(argc, argv, "obj_tx_locks_abort");
if (argc > 3)
UT_FATAL("usage: %s <file>", argv[0]);
pop = pmemobj_create(argv[1], LAYOUT_NAME,
PMEMOBJ_MIN_POOL * 4, S_IWUSR | S_IRUSR);
if (pop == NULL)
UT_FATAL("!pmemobj_create");
TOID(struct root_obj) root = POBJ_ROOT(pop, struct root_obj);
TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) {
TX_ADD(root);
D_RW(root)->head = TX_ZNEW(struct obj);
TOID(struct obj) o;
o = D_RW(root)->head;
D_RW(o)->data = 100;
pmemobj_mutex_zero(pop, &D_RW(o)->lock);
for (int i = 0; i < 3; i++) {
D_RW(o)->next = TX_ZNEW(struct obj);
o = D_RO(o)->next;
D_RW(o)->data = 101 + i;
pmemobj_mutex_zero(pop, &D_RW(o)->lock);
}
TOID_ASSIGN(D_RW(o)->next, OID_NULL);
} TX_END;
UT_OUT("initial state");
do_check(D_RO(root)->head);
UT_OUT("nested tx");
do_nested_tx(pop, D_RW(root)->head, 200);
do_check(D_RO(root)->head);
UT_OUT("aborted nested tx");
do_aborted_nested_tx(pop, D_RW(root)->head, 300);
do_check(D_RO(root)->head);
pmemobj_close(pop);
DONE(NULL);
}
| 4,509 | 25.686391 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_sync_win/libpmempool_sync_win.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmempool_sync_win -- a unittest for libpmempool sync.
*
*/
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "unittest.h"
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "libpmempool_sync_win");
if (argc != 3)
UT_FATAL("usage: %s poolset_file flags", ut_toUTF8(argv[0]));
int ret = pmempool_syncW(argv[1], (unsigned)wcstoul(argv[2], NULL, 0));
if (ret)
UT_OUT("result: %d, errno: %d", ret, errno);
else
UT_OUT("result: 0");
DONEW(NULL);
}
| 2,117 | 34.3 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_cuckoo/obj_cuckoo.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_cuckoo.c -- unit test for cuckoo hash table
*/
#include <errno.h>
#include "unittest.h"
#include "cuckoo.h"
#include "util.h"
#include "libpmemobj.h"
#define TEST_INSERTS 100
#define TEST_VAL(x) ((void *)((uintptr_t)(x)))
static int Rcounter_malloc;
static void *
__wrap_malloc(size_t size)
{
switch (util_fetch_and_add32(&Rcounter_malloc, 1)) {
case 1: /* internal out_err malloc */
default:
return malloc(size);
case 2: /* tab malloc */
case 0: /* cuckoo malloc */
return NULL;
}
}
static void
test_cuckoo_new_delete(void)
{
struct cuckoo *c = NULL;
/* cuckoo malloc fail */
c = cuckoo_new();
UT_ASSERT(c == NULL);
/* tab malloc fail */
c = cuckoo_new();
UT_ASSERT(c == NULL);
/* all ok */
c = cuckoo_new();
UT_ASSERT(c != NULL);
cuckoo_delete(c);
}
static void
test_insert_get_remove(void)
{
struct cuckoo *c = cuckoo_new();
UT_ASSERT(c != NULL);
for (unsigned i = 0; i < TEST_INSERTS; ++i)
UT_ASSERT(cuckoo_insert(c, i, TEST_VAL(i)) == 0);
for (unsigned i = 0; i < TEST_INSERTS; ++i)
UT_ASSERT(cuckoo_get(c, i) == TEST_VAL(i));
for (unsigned i = 0; i < TEST_INSERTS; ++i)
UT_ASSERT(cuckoo_remove(c, i) == TEST_VAL(i));
for (unsigned i = 0; i < TEST_INSERTS; ++i)
UT_ASSERT(cuckoo_remove(c, i) == NULL);
for (unsigned i = 0; i < TEST_INSERTS; ++i)
UT_ASSERT(cuckoo_get(c, i) == NULL);
cuckoo_delete(c);
}
/*
* rand64 -- (internal) 64-bit random function of doubtful quality, but good
* enough for the test.
*/
static uint64_t
rand64(void)
{
return (((uint64_t)rand()) << 32) | (unsigned)rand();
}
#define NVALUES (100000)
#define TEST_VALUE ((void *)0x1)
#define INITIAL_SEED 54321
/*
* test_load_factor -- calculates the average load factor of the hash table
* when inserting <0, 1M> elements in random order.
*
* The factor itself isn't really that important because the implementation
* is optimized for lookup speed, but it should be reasonable.
*/
static void
test_load_factor(void)
{
struct cuckoo *c = cuckoo_new();
UT_ASSERT(c != NULL);
/*
* The seed is intentionally constant so that the test result is
* consistent (at least on the same platform).
*/
srand(INITIAL_SEED);
float avg_load = 0.f;
int inserted = 0;
for (int i = 0; ; ++i) {
if (cuckoo_insert(c, rand64() % NVALUES, TEST_VALUE) == 0) {
inserted++;
avg_load += (float)inserted / cuckoo_get_size(c);
if (inserted == NVALUES)
break;
}
}
avg_load /= inserted;
UT_ASSERT(avg_load >= 0.4f);
cuckoo_delete(c);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_cuckoo");
Malloc = __wrap_malloc;
test_cuckoo_new_delete();
test_insert_get_remove();
test_load_factor();
DONE(NULL);
}
| 4,294 | 24.414201 | 76 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_ctl_alloc_class/obj_ctl_alloc_class.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_ctl_alloc_class.c -- tests for the ctl entry points: heap.alloc_class
*/
#include <sys/resource.h>
#include "unittest.h"
#define LAYOUT "obj_ctl_alloc_class"
static void
basic(const char *path)
{
PMEMobjpool *pop;
if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL * 20,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
int ret;
PMEMoid oid;
size_t usable_size;
struct pobj_alloc_class_desc alloc_class_128;
alloc_class_128.header_type = POBJ_HEADER_NONE;
alloc_class_128.unit_size = 128;
alloc_class_128.units_per_block = 1000;
alloc_class_128.alignment = 0;
ret = pmemobj_ctl_set(pop, "heap.alloc_class.128.desc",
&alloc_class_128);
UT_ASSERTeq(ret, 0);
struct pobj_alloc_class_desc alloc_class_129;
alloc_class_129.header_type = POBJ_HEADER_COMPACT;
alloc_class_129.unit_size = 1024;
alloc_class_129.units_per_block = 1000;
alloc_class_129.alignment = 0;
ret = pmemobj_ctl_set(pop, "heap.alloc_class.129.desc",
&alloc_class_129);
UT_ASSERTeq(ret, 0);
struct pobj_alloc_class_desc alloc_class_128_r;
ret = pmemobj_ctl_get(pop, "heap.alloc_class.128.desc",
&alloc_class_128_r);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(alloc_class_128.header_type, alloc_class_128_r.header_type);
UT_ASSERTeq(alloc_class_128.unit_size, alloc_class_128_r.unit_size);
UT_ASSERT(alloc_class_128.units_per_block <=
alloc_class_128_r.units_per_block);
/*
* One unit from alloc class 128 - 128 bytes unit size, minimal headers.
*/
ret = pmemobj_xalloc(pop, &oid, 128, 0, POBJ_CLASS_ID(128), NULL, NULL);
UT_ASSERTeq(ret, 0);
usable_size = pmemobj_alloc_usable_size(oid);
UT_ASSERTeq(usable_size, 128);
pmemobj_free(&oid);
/*
* Reserve as above.
*/
struct pobj_action act;
oid = pmemobj_xreserve(pop, &act, 128, 0, POBJ_CLASS_ID(128));
UT_ASSERT(!OID_IS_NULL(oid));
usable_size = pmemobj_alloc_usable_size(oid);
UT_ASSERTeq(usable_size, 128);
pmemobj_cancel(pop, &act, 1);
/*
* One unit from alloc class 128 - 128 bytes unit size, minimal headers,
* but request size 1 byte.
*/
ret = pmemobj_xalloc(pop, &oid, 1, 0, POBJ_CLASS_ID(128), NULL, NULL);
UT_ASSERTeq(ret, 0);
usable_size = pmemobj_alloc_usable_size(oid);
UT_ASSERTeq(usable_size, 128);
pmemobj_free(&oid);
/*
* Two units from alloc class 129 -
* 1024 bytes unit size, compact headers.
*/
ret = pmemobj_xalloc(pop, &oid, 1024 + 1,
0, POBJ_CLASS_ID(129), NULL, NULL);
UT_ASSERTeq(ret, 0);
usable_size = pmemobj_alloc_usable_size(oid);
UT_ASSERTeq(usable_size, (1024 * 2) - 16); /* 2 units minus hdr */
pmemobj_free(&oid);
/*
* 64 units from alloc class 129
* - 1024 bytes unit size, compact headers.
*/
ret = pmemobj_xalloc(pop, &oid, (1024 * 64) - 16,
0, POBJ_CLASS_ID(129), NULL, NULL);
UT_ASSERTeq(ret, 0);
usable_size = pmemobj_alloc_usable_size(oid);
UT_ASSERTeq(usable_size, (1024 * 64) - 16);
pmemobj_free(&oid);
/*
* 65 units from alloc class 129 -
* 1024 bytes unit size, compact headers.
* Should fail, as it would require two bitmap modifications.
*/
ret = pmemobj_xalloc(pop, &oid, 1024 * 64 + 1, 0,
POBJ_CLASS_ID(129), NULL, NULL);
UT_ASSERTeq(ret, -1);
/*
* Nonexistent alloc class.
*/
ret = pmemobj_xalloc(pop, &oid, 1, 0, POBJ_CLASS_ID(130), NULL, NULL);
UT_ASSERTeq(ret, -1);
struct pobj_alloc_class_desc alloc_class_new;
alloc_class_new.header_type = POBJ_HEADER_NONE;
alloc_class_new.unit_size = 777;
alloc_class_new.units_per_block = 200;
alloc_class_new.class_id = 0;
alloc_class_new.alignment = 0;
ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc",
&alloc_class_new);
UT_ASSERTeq(ret, 0);
struct pobj_alloc_class_desc alloc_class_fail;
alloc_class_fail.header_type = POBJ_HEADER_NONE;
alloc_class_fail.unit_size = 777;
alloc_class_fail.units_per_block = 200;
alloc_class_fail.class_id = 0;
alloc_class_fail.alignment = 0;
ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc",
&alloc_class_fail);
UT_ASSERTeq(ret, -1);
ret = pmemobj_ctl_set(pop, "heap.alloc_class.200.desc",
&alloc_class_fail);
UT_ASSERTeq(ret, -1);
ret = pmemobj_xalloc(pop, &oid, 1, 0,
POBJ_CLASS_ID(alloc_class_new.class_id), NULL, NULL);
UT_ASSERTeq(ret, 0);
usable_size = pmemobj_alloc_usable_size(oid);
UT_ASSERTeq(usable_size, 777);
struct pobj_alloc_class_desc alloc_class_new_huge;
alloc_class_new_huge.header_type = POBJ_HEADER_NONE;
alloc_class_new_huge.unit_size = (2 << 23);
alloc_class_new_huge.units_per_block = 1;
alloc_class_new_huge.class_id = 0;
alloc_class_new_huge.alignment = 0;
ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc",
&alloc_class_new_huge);
UT_ASSERTeq(ret, 0);
ret = pmemobj_xalloc(pop, &oid, 1, 0,
POBJ_CLASS_ID(alloc_class_new_huge.class_id), NULL, NULL);
UT_ASSERTeq(ret, 0);
usable_size = pmemobj_alloc_usable_size(oid);
UT_ASSERTeq(usable_size, (2 << 23));
struct pobj_alloc_class_desc alloc_class_new_max;
alloc_class_new_max.header_type = POBJ_HEADER_COMPACT;
alloc_class_new_max.unit_size = PMEMOBJ_MAX_ALLOC_SIZE;
alloc_class_new_max.units_per_block = 1024;
alloc_class_new_max.class_id = 0;
alloc_class_new_max.alignment = 0;
ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc",
&alloc_class_new_max);
UT_ASSERTeq(ret, 0);
ret = pmemobj_xalloc(pop, &oid, 1, 0,
POBJ_CLASS_ID(alloc_class_new_max.class_id), NULL, NULL);
UT_ASSERTne(ret, 0);
struct pobj_alloc_class_desc alloc_class_new_loop;
alloc_class_new_loop.header_type = POBJ_HEADER_COMPACT;
alloc_class_new_loop.unit_size = 16384;
alloc_class_new_loop.units_per_block = 63;
alloc_class_new_loop.class_id = 0;
alloc_class_new_loop.alignment = 0;
ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc",
&alloc_class_new_loop);
UT_ASSERTeq(ret, 0);
size_t s = (63 * 16384) - 16;
ret = pmemobj_xalloc(pop, &oid, s + 1, 0,
POBJ_CLASS_ID(alloc_class_new_loop.class_id), NULL, NULL);
UT_ASSERTne(ret, 0);
struct pobj_alloc_class_desc alloc_class_tiny;
alloc_class_tiny.header_type = POBJ_HEADER_NONE;
alloc_class_tiny.unit_size = 7;
alloc_class_tiny.units_per_block = 1000;
alloc_class_tiny.class_id = 0;
alloc_class_tiny.alignment = 0;
ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc",
&alloc_class_tiny);
UT_ASSERTeq(ret, 0);
for (int i = 0; i < 1000; ++i) {
ret = pmemobj_xalloc(pop, &oid, 7, 0,
POBJ_CLASS_ID(alloc_class_tiny.class_id), NULL, NULL);
UT_ASSERTeq(ret, 0);
}
pmemobj_close(pop);
}
static void
many(const char *path)
{
PMEMobjpool *pop;
if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
unsigned nunits = UINT16_MAX + 1;
struct pobj_alloc_class_desc alloc_class_tiny;
alloc_class_tiny.header_type = POBJ_HEADER_NONE;
alloc_class_tiny.unit_size = 8;
alloc_class_tiny.units_per_block = nunits;
alloc_class_tiny.class_id = 0;
alloc_class_tiny.alignment = 0;
int ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc",
&alloc_class_tiny);
UT_ASSERTeq(ret, 0);
PMEMoid oid;
uint64_t *counterp = NULL;
for (size_t i = 0; i < nunits; ++i) {
pmemobj_xalloc(pop, &oid, 8, 0,
POBJ_CLASS_ID(alloc_class_tiny.class_id), NULL, NULL);
counterp = pmemobj_direct(oid);
(*counterp)++;
/*
* This works only because this is a fresh pool in a new file
* and so the counter must be initially zero.
* This might have to be fixed if that ever changes.
*/
UT_ASSERTeq(*counterp, 1);
}
pmemobj_close(pop);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_ctl_alloc_class");
if (argc != 3)
UT_FATAL("usage: %s file-name b|m", argv[0]);
const char *path = argv[1];
if (argv[2][0] == 'b')
basic(path);
else if (argv[2][0] == 'm')
many(path);
DONE(NULL);
}
| 9,325 | 29.083871 | 76 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/traces_pmem/traces_pmem.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* traces_pmem.c -- unit test traces for libraries pmem
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "traces_pmem");
UT_ASSERT(!pmem_check_version(PMEM_MAJOR_VERSION,
PMEM_MINOR_VERSION));
UT_ASSERT(!pmemblk_check_version(PMEMBLK_MAJOR_VERSION,
PMEMBLK_MINOR_VERSION));
UT_ASSERT(!pmemlog_check_version(PMEMLOG_MAJOR_VERSION,
PMEMLOG_MINOR_VERSION));
UT_ASSERT(!pmemobj_check_version(PMEMOBJ_MAJOR_VERSION,
PMEMOBJ_MINOR_VERSION));
UT_ASSERT(!pmemcto_check_version(PMEMCTO_MAJOR_VERSION,
PMEMCTO_MINOR_VERSION));
DONE(NULL);
}
| 2,197 | 37.561404 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_debug/obj_debug.c
|
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_debug.c -- unit test for debug features
*
* usage: obj_debug file operation [op_index]:...
*
* operations are 'f' or 'l' or 'r' or 'a' or 'n' or 's'
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <sys/param.h>
#include "unittest.h"
#include "libpmemobj.h"
#define LAYOUT_NAME "layout_obj_debug"
TOID_DECLARE_ROOT(struct root);
TOID_DECLARE(struct tobj, 0);
TOID_DECLARE(struct int3_s, 1);
struct root {
POBJ_LIST_HEAD(listhead, struct tobj) lhead, lhead2;
uint32_t val;
};
struct tobj {
POBJ_LIST_ENTRY(struct tobj) next;
};
struct int3_s {
uint32_t i1;
uint32_t i2;
uint32_t i3;
};
typedef void (*func)(PMEMobjpool *pop, void *sync, void *cond);
static void
test_FOREACH(const char *path)
{
PMEMobjpool *pop = NULL;
PMEMoid varoid, nvaroid;
TOID(struct root) root;
TOID(struct tobj) var, nvar;
#define COMMANDS_FOREACH()\
do {\
POBJ_FOREACH(pop, varoid) {}\
POBJ_FOREACH_SAFE(pop, varoid, nvaroid) {}\
POBJ_FOREACH_TYPE(pop, var) {}\
POBJ_FOREACH_SAFE_TYPE(pop, var, nvar) {}\
POBJ_LIST_FOREACH(var, &D_RW(root)->lhead, next) {}\
POBJ_LIST_FOREACH_REVERSE(var, &D_RW(root)->lhead, next) {}\
} while (0)
if ((pop = pmemobj_create(path, LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
TOID_ASSIGN(root, pmemobj_root(pop, sizeof(struct root)));
POBJ_LIST_INSERT_NEW_HEAD(pop, &D_RW(root)->lhead, next,
sizeof(struct tobj), NULL, NULL);
COMMANDS_FOREACH();
TX_BEGIN(pop) {
COMMANDS_FOREACH();
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
COMMANDS_FOREACH();
pmemobj_close(pop);
}
static void
test_lists(const char *path)
{
PMEMobjpool *pop = NULL;
TOID(struct root) root;
TOID(struct tobj) elm;
#define COMMANDS_LISTS()\
do {\
POBJ_LIST_INSERT_NEW_HEAD(pop, &D_RW(root)->lhead, next,\
sizeof(struct tobj), NULL, NULL);\
POBJ_NEW(pop, &elm, struct tobj, NULL, NULL);\
POBJ_LIST_INSERT_AFTER(pop, &D_RW(root)->lhead,\
POBJ_LIST_FIRST(&D_RW(root)->lhead), elm, next);\
POBJ_LIST_MOVE_ELEMENT_HEAD(pop, &D_RW(root)->lhead,\
&D_RW(root)->lhead2, elm, next, next);\
POBJ_LIST_REMOVE(pop, &D_RW(root)->lhead2, elm, next);\
POBJ_FREE(&elm);\
} while (0)
if ((pop = pmemobj_create(path, LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
TOID_ASSIGN(root, pmemobj_root(pop, sizeof(struct root)));
COMMANDS_LISTS();
TX_BEGIN(pop) {
COMMANDS_LISTS();
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
COMMANDS_LISTS();
pmemobj_close(pop);
}
static int
int3_constructor(PMEMobjpool *pop, void *ptr, void *arg)
{
struct int3_s *args = (struct int3_s *)arg;
struct int3_s *val = (struct int3_s *)ptr;
val->i1 = args->i1;
val->i2 = args->i2;
val->i3 = args->i3;
pmemobj_persist(pop, val, sizeof(*val));
return 0;
}
static void
test_alloc_construct(const char *path)
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
TX_BEGIN(pop) {
struct int3_s args = { 1, 2, 3 };
PMEMoid allocation;
pmemobj_alloc(pop, &allocation, sizeof(allocation), 1,
int3_constructor, &args);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
pmemobj_close(pop);
}
static void
test_double_free(const char *path)
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
PMEMoid oid, oid2;
int err = pmemobj_zalloc(pop, &oid, 100, 0);
UT_ASSERTeq(err, 0);
UT_ASSERT(!OID_IS_NULL(oid));
oid2 = oid;
pmemobj_free(&oid);
pmemobj_free(&oid2);
}
static int
test_constr(PMEMobjpool *pop, void *ptr, void *arg)
{
PMEMoid oid;
pmemobj_alloc(pop, &oid, 1, 1, test_constr, NULL);
return 0;
}
static void
test_alloc_in_constructor(const char *path)
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
PMEMoid oid;
pmemobj_alloc(pop, &oid, 1, 1, test_constr, NULL);
}
static void
test_mutex_lock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_mutex_lock(pop, (PMEMmutex *)sync);
}
static void
test_mutex_unlock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_mutex_unlock(pop, (PMEMmutex *)sync);
}
static void
test_mutex_trylock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_mutex_trylock(pop, (PMEMmutex *)sync);
}
static void
test_mutex_timedlock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_mutex_timedlock(pop, (PMEMmutex *)sync, NULL);
}
static void
test_mutex_zero(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_mutex_zero(pop, (PMEMmutex *)sync);
}
static void
test_rwlock_rdlock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_rwlock_rdlock(pop, (PMEMrwlock *)sync);
}
static void
test_rwlock_wrlock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_rwlock_wrlock(pop, (PMEMrwlock *)sync);
}
static void
test_rwlock_timedrdlock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_rwlock_timedrdlock(pop, (PMEMrwlock *)sync, NULL);
}
static void
test_rwlock_timedwrlock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_rwlock_timedwrlock(pop, (PMEMrwlock *)sync, NULL);
}
static void
test_rwlock_tryrdlock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_rwlock_tryrdlock(pop, (PMEMrwlock *)sync);
}
static void
test_rwlock_trywrlock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_rwlock_trywrlock(pop, (PMEMrwlock *)sync);
}
static void
test_rwlock_unlock(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_rwlock_unlock(pop, (PMEMrwlock *)sync);
}
static void
test_rwlock_zero(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_rwlock_zero(pop, (PMEMrwlock *)sync);
}
static void
test_cond_wait(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_cond_wait(pop, (PMEMcond *)cond, (PMEMmutex *)sync);
}
static void
test_cond_signal(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_cond_signal(pop, (PMEMcond *)cond);
}
static void
test_cond_broadcast(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_cond_broadcast(pop, (PMEMcond *)cond);
}
static void
test_cond_timedwait(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_cond_timedwait(pop, (PMEMcond *)cond, (PMEMmutex *)sync, NULL);
}
static void
test_cond_zero(PMEMobjpool *pop, void *sync, void *cond)
{
pmemobj_cond_zero(pop, (PMEMcond *)cond);
}
static void
test_sync_pop_check(unsigned long op_index)
{
PMEMobjpool *pop = (PMEMobjpool *)(uintptr_t)0x1;
func to_test[] = {
test_mutex_lock, test_mutex_unlock, test_mutex_trylock,
test_mutex_timedlock, test_mutex_zero, test_rwlock_rdlock,
test_rwlock_wrlock, test_rwlock_timedrdlock,
test_rwlock_timedwrlock, test_rwlock_tryrdlock,
test_rwlock_trywrlock, test_rwlock_unlock, test_rwlock_zero,
test_cond_wait, test_cond_signal, test_cond_broadcast,
test_cond_timedwait, test_cond_zero
};
if (op_index >= (sizeof(to_test) / sizeof(to_test[0])))
UT_FATAL("Invalid op_index provided");
PMEMmutex stack_sync;
PMEMcond stack_cond;
to_test[op_index](pop, &stack_sync, &stack_cond);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_debug");
if (argc < 3)
UT_FATAL("usage: %s file-name op:f|l|r|a|s [op_index]",
argv[0]);
const char *path = argv[1];
if (strchr("flrapns", argv[2][0]) == NULL || argv[2][1] != '\0')
UT_FATAL("op must be f or l or r or a or p or n or s");
unsigned long op_index;
char *tailptr;
switch (argv[2][0]) {
case 'f':
test_FOREACH(path);
break;
case 'l':
test_lists(path);
break;
case 'a':
test_alloc_construct(path);
break;
case 'p':
test_double_free(path);
break;
case 'n':
test_alloc_in_constructor(path);
break;
case 's':
if (argc != 4)
UT_FATAL("Provide an op_index with option s");
op_index = strtoul(argv[3], &tailptr, 10);
if (tailptr[0] != '\0')
UT_FATAL("Wrong op_index format");
test_sync_pop_check(op_index);
break;
}
DONE(NULL);
}
| 9,613 | 22.975062 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_pmalloc_rand_mt/obj_pmalloc_rand_mt.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_pmalloc_mt.c -- multithreaded test of allocator
*/
#include <stdint.h>
#include "file.h"
#include "unittest.h"
#define RRAND(seed, max, min) (os_rand_r(&(seed)) % ((max) - (min)) + (min))
static size_t object_size;
static unsigned nobjects;
static unsigned iterations = 1000000;
static unsigned seed;
static void *
test_worker(void *arg)
{
PMEMobjpool *pop = arg;
PMEMoid *objects = ZALLOC(sizeof(PMEMoid) * nobjects);
unsigned fill = 0;
int ret;
unsigned myseed = seed;
for (unsigned i = 0; i < iterations; ++i) {
unsigned fill_ratio = (fill * 100) / nobjects;
unsigned pos = RRAND(myseed, nobjects, 0);
size_t size = RRAND(myseed, object_size, 64);
if (RRAND(myseed, 100, 0) < fill_ratio) {
if (!OID_IS_NULL(objects[pos])) {
pmemobj_free(&objects[pos]);
objects[pos] = OID_NULL;
fill--;
}
} else {
if (OID_IS_NULL(objects[pos])) {
ret = pmemobj_alloc(pop, &objects[pos],
size, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
fill++;
}
}
}
FREE(objects);
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_pmalloc_rand_mt");
if (argc < 5 || argc > 7)
UT_FATAL("usage: %s [file] "
"[threads #] [objects #] [object size] "
"[iterations (def: 1000000)] [seed (def: time)]",
argv[0]);
unsigned nthreads = ATOU(argv[2]);
nobjects = ATOU(argv[3]);
object_size = ATOUL(argv[4]);
if (argc > 5)
iterations = ATOU(argv[5]);
if (argc > 6)
seed = ATOU(argv[6]);
else
seed = (unsigned)time(NULL);
PMEMobjpool *pop;
int exists = util_file_exists(argv[1]);
if (exists < 0)
UT_FATAL("!util_file_exists");
if (!exists) {
pop = pmemobj_create(argv[1], "TEST",
(PMEMOBJ_MIN_POOL * 10) + (nthreads * nobjects * object_size),
0666);
if (pop == NULL)
UT_FATAL("!pmemobj_create");
} else {
pop = pmemobj_open(argv[1], "TEST");
if (pop == NULL)
UT_FATAL("!pmemobj_open");
}
os_thread_t *threads = MALLOC(sizeof(os_thread_t) * nthreads);
for (unsigned i = 0; i < nthreads; ++i) {
PTHREAD_CREATE(&threads[i], NULL, test_worker, pop);
}
for (unsigned i = 0; i < nthreads; ++i) {
PTHREAD_JOIN(&threads[i], NULL);
}
FREE(threads);
pmemobj_close(pop);
DONE(NULL);
}
| 3,809 | 26.021277 | 76 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_backup/config.sh
|
#!/usr/bin/env bash
#
# Copyright 2017, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# libpmempool_backup/config.sh -- test configuration
#
# Extend timeout for TEST0, as it may take more than a minute
# when run on a non-pmem file system.
CONF_TIMEOUT[0]='10m'
| 1,766 | 41.071429 | 73 |
sh
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_backup/common.sh
|
#!/usr/bin/env bash
#
# Copyright 2016-2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# libpmempool_backup/common.sh -- functions for libpmempool_backup unittest
#
set -e
POOLSET=$DIR/pool.set
BACKUP=_backup
REPLICA=_replica
POOL_PART=$DIR/pool.part
OUT=out${UNITTEST_NUM}.log
OUT_TEMP=out${UNITTEST_NUM}_temp.log
DIFF=diff${UNITTEST_NUM}.log
rm -f $LOG $DIFF $OUT_TEMP && touch $LOG $DIFF $OUT_TEMP
# params for blk, log and obj pools
POOL_TYPES=( blk log obj )
POOL_CREATE_PARAMS=( "--write-layout 512" "" "--layout test_layout" )
POOL_CHECK_PARAMS=( "-smgB" "-s" "-soOaAbZH -l -C" )
POOL_OBJ=2
# create_poolset_variation -- create one from the tested poolset variation
# usage: create_poolset_variation <variation-id> [<suffix>]
#
function create_poolset_variation() {
local sfx=""
local variation=$1
shift
if [ $# -gt 0 ]; then
sfx=$1
fi
case "$variation"
in
1)
# valid poolset file
create_poolset $POOLSET$sfx \
20M:${POOL_PART}1$sfx:x \
20M:${POOL_PART}2$sfx:x \
20M:${POOL_PART}3$sfx:x \
20M:${POOL_PART}4$sfx:x
;;
2)
# valid poolset file with replica
create_poolset $POOLSET$sfx \
20M:${POOL_PART}1$sfx:x \
20M:${POOL_PART}2$sfx:x \
20M:${POOL_PART}3$sfx:x \
20M:${POOL_PART}4$sfx:x \
r 80M:${POOL_PART}${REPLICA}$sfx:x
;;
3)
# other number of parts
create_poolset $POOLSET$sfx \
20M:${POOL_PART}1$sfx:x \
20M:${POOL_PART}2$sfx:x \
40M:${POOL_PART}3$sfx:x
;;
4)
# no poolset
# return without check_file
return
;;
5)
# empty
create_poolset $POOLSET$sfx
;;
6)
# other size of part
create_poolset $POOLSET$sfx \
20M:${POOL_PART}1$sfx:x \
20M:${POOL_PART}2$sfx:x \
20M:${POOL_PART}3$sfx:x \
21M:${POOL_PART}4$sfx:x
;;
esac
check_file $POOLSET$sfx
}
#
# backup_and_compare -- perform backup and compare backup result with original
# if compare parameters are provided
# usage: backup_and_compare <poolset> <type> [<compare-params>]
#
function backup_and_compare () {
local poolset=$1
local type=$2
shift 2
# backup
expect_normal_exit ../libpmempool_api/libpmempool_test$EXESUFFIX \
-b $poolset$BACKUP -t $type -r 1 $poolset
cat $OUT >> $OUT_TEMP
# compare
if [ $# -gt 0 ]; then
compare_replicas "$1" $poolset $poolset$BACKUP >> $DIFF
fi
}
ALL_POOL_PARTS="${POOL_PART}1 ${POOL_PART}2 ${POOL_PART}3 ${POOL_PART}4 \
${POOL_PART}${REPLICA}"
ALL_POOL_BACKUP_PARTS="${POOL_PART}1$BACKUP ${POOL_PART}2$BACKUP \
${POOL_PART}3$BACKUP ${POOL_PART}4$BACKUP \
${POOL_PART}${BACKUP}${REPLICA}"
#
# backup_cleanup -- perform cleanup between test cases
#
function backup_cleanup() {
rm -f $POOLSET$BACKUP $ALL_POOL_PARTS $ALL_POOL_BACKUP_PARTS
}
| 4,177 | 27.421769 | 78 |
sh
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_check_allocations/cto_check_allocations.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_check_allocations -- unit test for cto_check_allocations
*
* usage: cto_check_allocations filename
*/
#include "unittest.h"
#define MAX_ALLOC_SIZE (4L * 1024L * 1024L)
#define NALLOCS 16
#define POOL_SIZE (2 * PMEMCTO_MIN_POOL)
/* buffer for all allocation pointers */
static char *ptrs[NALLOCS];
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_check_allocations");
if (argc != 2)
UT_FATAL("usage: %s filename", argv[0]);
PMEMctopool *pcp = pmemcto_create(argv[1], "test",
POOL_SIZE, 0666);
UT_ASSERTne(pcp, NULL);
for (size_t size = 8; size <= MAX_ALLOC_SIZE; size *= 2) {
memset(ptrs, 0, sizeof(ptrs));
int i;
for (i = 0; i < NALLOCS; ++i) {
ptrs[i] = pmemcto_malloc(pcp, size);
if (ptrs[i] == NULL) {
/* out of memory in pool */
break;
}
/* check that pointer came from mem_pool */
UT_ASSERTrange(ptrs[i], pcp, POOL_SIZE);
/* fill each allocation with a unique value */
memset(ptrs[i], (char)i, size);
}
UT_OUT("size %zu cnt %d", size, i);
UT_ASSERT((i > 0) && (i + 1 < MAX_ALLOC_SIZE));
/* check for unexpected modifications of the data */
for (i = 0; i < NALLOCS && ptrs[i] != NULL; ++i) {
for (size_t j = 0; j < size; ++j)
UT_ASSERTeq(ptrs[i][j], (char)i);
pmemcto_free(pcp, ptrs[i]);
}
}
pmemcto_close(pcp);
DONE(NULL);
}
| 2,940 | 30.287234 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/blk_include/blk_include.c
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* blk_include.c -- include test for libpmemblk
*
* this is only a compilation test - do not run this program
*/
#include <libpmemblk.h>
int
main(int argc, char *argv[])
{
return 0;
}
| 1,790 | 37.934783 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_aligned_alloc/cto_aligned_alloc.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_aligned_alloc.c -- unit test for pmemcto_aligned_alloc
*
* usage: cto_aligned_alloc filename
*/
#include "unittest.h"
#define MAX_ALIGNMENT (4L * 1024L * 1024L)
#define NALLOCS 16
/* buffer for all allocation pointers */
static int *ptrs[NALLOCS];
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_aligned_alloc");
if (argc != 2)
UT_FATAL("usage: %s filename", argv[0]);
/* test with address alignment from 2B to 4MB */
size_t alignment;
for (alignment = 2; alignment <= MAX_ALIGNMENT; alignment *= 2) {
PMEMctopool *pcp = pmemcto_create(argv[1], "test",
PMEMCTO_MIN_POOL, 0666);
UT_ASSERTne(pcp, NULL);
memset(ptrs, 0, sizeof(ptrs));
int i;
for (i = 0; i < NALLOCS; ++i) {
ptrs[i] = pmemcto_aligned_alloc(pcp, alignment,
sizeof(int));
/* at least one allocation must succeed */
UT_ASSERT(i != 0 || ptrs[i] != NULL);
if (ptrs[i] == NULL) {
/* out of memory in pool */
break;
}
/* check that pointer came from mem_pool */
UT_ASSERTrange(ptrs[i], pcp, PMEMCTO_MIN_POOL);
/* check for correct address alignment */
UT_ASSERTeq((uintptr_t)(ptrs[i]) & (alignment - 1), 0);
/* ptr should be usable */
*ptrs[i] = i;
UT_ASSERTeq(*ptrs[i], i);
}
/* check for unexpected modifications of the data */
for (i = 0; i < NALLOCS && ptrs[i] != NULL; ++i)
pmemcto_free(pcp, ptrs[i]);
pmemcto_close(pcp);
UNLINK(argv[1]);
}
DONE(NULL);
}
| 3,043 | 30.061224 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_sync/mocks_windows.h
|
/*
* Copyright 2016-2017, Intel Corporation
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of pthread functions
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmemobj
* files, when compiled for the purpose of obj_sync test.
* It would replace default implementation with mocked functions defined
* in obj_sync.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define os_mutex_init __wrap_os_mutex_init
#define os_rwlock_init __wrap_os_rwlock_init
#define os_cond_init __wrap_os_cond_init
#endif
| 2,221 | 41.730769 | 74 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_sync/obj_sync.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_sync.c -- unit test for PMEM-resident locks
*/
#include "obj.h"
#include "sync.h"
#include "unittest.h"
#include "util.h"
#include "os.h"
#define MAX_THREAD_NUM 200
#define DATA_SIZE 128
#define LOCKED_MUTEX 1
#define NANO_PER_ONE 1000000000LL
#define TIMEOUT (NANO_PER_ONE / 1000LL)
#define WORKER_RUNS 10
#define MAX_OPENS 5
#define FATAL_USAGE() UT_FATAL("usage: obj_sync [mrc] <num_threads> <runs>\n")
/* posix thread worker typedef */
typedef void *(*worker)(void *);
/* the mock pmemobj pool */
static PMEMobjpool Mock_pop;
/* the tested object containing persistent synchronization primitives */
static struct mock_obj {
PMEMmutex mutex;
PMEMmutex mutex_locked;
PMEMcond cond;
PMEMrwlock rwlock;
int check_data;
uint8_t data[DATA_SIZE];
} *Test_obj;
PMEMobjpool *
pmemobj_pool_by_ptr(const void *arg)
{
return &Mock_pop;
}
/*
* mock_open_pool -- (internal) simulate pool opening
*/
static void
mock_open_pool(PMEMobjpool *pop)
{
util_fetch_and_add64(&pop->run_id, 2);
}
/*
* mutex_write_worker -- (internal) write data with mutex
*/
static void *
mutex_write_worker(void *arg)
{
for (unsigned run = 0; run < WORKER_RUNS; run++) {
if (pmemobj_mutex_lock(&Mock_pop, &Test_obj->mutex)) {
UT_ERR("pmemobj_mutex_lock");
return NULL;
}
memset(Test_obj->data, (int)(uintptr_t)arg, DATA_SIZE);
if (pmemobj_mutex_unlock(&Mock_pop, &Test_obj->mutex))
UT_ERR("pmemobj_mutex_unlock");
}
return NULL;
}
/*
* mutex_check_worker -- (internal) check consistency with mutex
*/
static void *
mutex_check_worker(void *arg)
{
for (unsigned run = 0; run < WORKER_RUNS; run++) {
if (pmemobj_mutex_lock(&Mock_pop, &Test_obj->mutex)) {
UT_ERR("pmemobj_mutex_lock");
return NULL;
}
uint8_t val = Test_obj->data[0];
for (int i = 1; i < DATA_SIZE; i++)
UT_ASSERTeq(Test_obj->data[i], val);
memset(Test_obj->data, 0, DATA_SIZE);
if (pmemobj_mutex_unlock(&Mock_pop, &Test_obj->mutex))
UT_ERR("pmemobj_mutex_unlock");
}
return NULL;
}
/*
* cond_write_worker -- (internal) write data with cond variable
*/
static void *
cond_write_worker(void *arg)
{
for (unsigned run = 0; run < WORKER_RUNS; run++) {
if (pmemobj_mutex_lock(&Mock_pop, &Test_obj->mutex))
return NULL;
memset(Test_obj->data, (int)(uintptr_t)arg, DATA_SIZE);
Test_obj->check_data = 1;
if (pmemobj_cond_signal(&Mock_pop, &Test_obj->cond))
UT_ERR("pmemobj_cond_signal");
pmemobj_mutex_unlock(&Mock_pop, &Test_obj->mutex);
}
return NULL;
}
/*
* cond_check_worker -- (internal) check consistency with cond variable
*/
static void *
cond_check_worker(void *arg)
{
for (unsigned run = 0; run < WORKER_RUNS; run++) {
if (pmemobj_mutex_lock(&Mock_pop, &Test_obj->mutex))
return NULL;
while (Test_obj->check_data != 1) {
if (pmemobj_cond_wait(&Mock_pop, &Test_obj->cond,
&Test_obj->mutex))
UT_ERR("pmemobj_cond_wait");
}
uint8_t val = Test_obj->data[0];
for (int i = 1; i < DATA_SIZE; i++)
UT_ASSERTeq(Test_obj->data[i], val);
memset(Test_obj->data, 0, DATA_SIZE);
pmemobj_mutex_unlock(&Mock_pop, &Test_obj->mutex);
}
return NULL;
}
/*
* rwlock_write_worker -- (internal) write data with rwlock
*/
static void *
rwlock_write_worker(void *arg)
{
for (unsigned run = 0; run < WORKER_RUNS; run++) {
if (pmemobj_rwlock_wrlock(&Mock_pop, &Test_obj->rwlock)) {
UT_ERR("pmemobj_rwlock_wrlock");
return NULL;
}
memset(Test_obj->data, (int)(uintptr_t)arg, DATA_SIZE);
if (pmemobj_rwlock_unlock(&Mock_pop, &Test_obj->rwlock))
UT_ERR("pmemobj_rwlock_unlock");
}
return NULL;
}
/*
* rwlock_check_worker -- (internal) check consistency with rwlock
*/
static void *
rwlock_check_worker(void *arg)
{
for (unsigned run = 0; run < WORKER_RUNS; run++) {
if (pmemobj_rwlock_rdlock(&Mock_pop, &Test_obj->rwlock)) {
UT_ERR("pmemobj_rwlock_rdlock");
return NULL;
}
uint8_t val = Test_obj->data[0];
for (int i = 1; i < DATA_SIZE; i++)
UT_ASSERTeq(Test_obj->data[i], val);
if (pmemobj_rwlock_unlock(&Mock_pop, &Test_obj->rwlock))
UT_ERR("pmemobj_rwlock_unlock");
}
return NULL;
}
/*
* timed_write_worker -- (internal) intentionally doing nothing
*/
static void *
timed_write_worker(void *arg)
{
return NULL;
}
/*
* timed_check_worker -- (internal) check consistency with mutex
*/
static void *
timed_check_worker(void *arg)
{
for (unsigned run = 0; run < WORKER_RUNS; run++) {
int mutex_id = (int)(uintptr_t)arg % 2;
PMEMmutex *mtx = mutex_id == LOCKED_MUTEX ?
&Test_obj->mutex_locked : &Test_obj->mutex;
struct timespec t1, t2, abs_time;
os_clock_gettime(CLOCK_REALTIME, &t1);
abs_time = t1;
abs_time.tv_nsec += TIMEOUT;
if (abs_time.tv_nsec >= NANO_PER_ONE) {
abs_time.tv_sec++;
abs_time.tv_nsec -= NANO_PER_ONE;
}
int ret = pmemobj_mutex_timedlock(&Mock_pop, mtx, &abs_time);
os_clock_gettime(CLOCK_REALTIME, &t2);
if (mutex_id == LOCKED_MUTEX) {
UT_ASSERTeq(ret, ETIMEDOUT);
uint64_t diff = (uint64_t)((t2.tv_sec - t1.tv_sec) *
NANO_PER_ONE + t2.tv_nsec - t1.tv_nsec);
UT_ASSERT(diff >= TIMEOUT);
return NULL;
}
if (ret == 0) {
UT_ASSERTne(mutex_id, LOCKED_MUTEX);
pmemobj_mutex_unlock(&Mock_pop, mtx);
} else if (ret == ETIMEDOUT) {
uint64_t diff = (uint64_t)((t2.tv_sec - t1.tv_sec)
* NANO_PER_ONE + t2.tv_nsec - t1.tv_nsec);
UT_ASSERT(diff >= TIMEOUT);
} else {
errno = ret;
UT_ERR("!pmemobj_mutex_timedlock");
}
}
return NULL;
}
/*
* cleanup -- (internal) clean up after each run
*/
static void
cleanup(char test_type)
{
switch (test_type) {
case 'm':
os_mutex_destroy(&((PMEMmutex_internal *)
&(Test_obj->mutex))->PMEMmutex_lock);
break;
case 'r':
os_rwlock_destroy(&((PMEMrwlock_internal *)
&(Test_obj->rwlock))->PMEMrwlock_lock);
break;
case 'c':
os_mutex_destroy(&((PMEMmutex_internal *)
&(Test_obj->mutex))->PMEMmutex_lock);
os_cond_destroy(&((PMEMcond_internal *)
&(Test_obj->cond))->PMEMcond_cond);
break;
case 't':
os_mutex_destroy(&((PMEMmutex_internal *)
&(Test_obj->mutex))->PMEMmutex_lock);
os_mutex_destroy(&((PMEMmutex_internal *)
&(Test_obj->mutex_locked))->PMEMmutex_lock);
break;
default:
FATAL_USAGE();
}
}
static int
obj_sync_persist(void *ctx, const void *ptr, size_t sz, unsigned flags)
{
/* no-op */
return 0;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_sync");
util_init();
if (argc < 4)
FATAL_USAGE();
worker writer;
worker checker;
char test_type = argv[1][0];
switch (test_type) {
case 'm':
writer = mutex_write_worker;
checker = mutex_check_worker;
break;
case 'r':
writer = rwlock_write_worker;
checker = rwlock_check_worker;
break;
case 'c':
writer = cond_write_worker;
checker = cond_check_worker;
break;
case 't':
writer = timed_write_worker;
checker = timed_check_worker;
break;
default:
FATAL_USAGE();
}
unsigned long num_threads = strtoul(argv[2], NULL, 10);
if (num_threads > MAX_THREAD_NUM)
UT_FATAL("Do not use more than %d threads.\n", MAX_THREAD_NUM);
unsigned long opens = strtoul(argv[3], NULL, 10);
if (opens > MAX_OPENS)
UT_FATAL("Do not use more than %d runs.\n", MAX_OPENS);
os_thread_t *write_threads
= (os_thread_t *)MALLOC(num_threads * sizeof(os_thread_t));
os_thread_t *check_threads
= (os_thread_t *)MALLOC(num_threads * sizeof(os_thread_t));
/* first pool open */
mock_open_pool(&Mock_pop);
Mock_pop.p_ops.persist = obj_sync_persist;
Mock_pop.p_ops.base = &Mock_pop;
Test_obj = (struct mock_obj *)MALLOC(sizeof(struct mock_obj));
/* zero-initialize the test object */
pmemobj_mutex_zero(&Mock_pop, &Test_obj->mutex);
pmemobj_mutex_zero(&Mock_pop, &Test_obj->mutex_locked);
pmemobj_cond_zero(&Mock_pop, &Test_obj->cond);
pmemobj_rwlock_zero(&Mock_pop, &Test_obj->rwlock);
Test_obj->check_data = 0;
memset(&Test_obj->data, 0, DATA_SIZE);
for (unsigned long run = 0; run < opens; run++) {
if (test_type == 't') {
pmemobj_mutex_lock(&Mock_pop,
&Test_obj->mutex_locked);
}
for (unsigned i = 0; i < num_threads; i++) {
PTHREAD_CREATE(&write_threads[i], NULL, writer,
(void *)(uintptr_t)i);
PTHREAD_CREATE(&check_threads[i], NULL, checker,
(void *)(uintptr_t)i);
}
for (unsigned i = 0; i < num_threads; i++) {
PTHREAD_JOIN(&write_threads[i], NULL);
PTHREAD_JOIN(&check_threads[i], NULL);
}
if (test_type == 't') {
pmemobj_mutex_unlock(&Mock_pop,
&Test_obj->mutex_locked);
}
/* up the run_id counter and cleanup */
mock_open_pool(&Mock_pop);
cleanup(test_type);
}
FREE(check_threads);
FREE(write_threads);
FREE(Test_obj);
DONE(NULL);
}
| 10,261 | 24.029268 | 78 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_sync/mocks_windows.c
|
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mock-windows.c -- redefinitions of locks function
*/
#include "os.h"
#include "unittest.h"
FUNC_MOCK(os_mutex_init, int,
os_mutex_t *__restrict mutex)
FUNC_MOCK_RUN_RET_DEFAULT_REAL(os_mutex_init, mutex)
FUNC_MOCK_RUN(1) {
return -1;
}
FUNC_MOCK_END
FUNC_MOCK(os_rwlock_init, int,
os_rwlock_t *__restrict rwlock)
FUNC_MOCK_RUN_RET_DEFAULT_REAL(os_rwlock_init, rwlock)
FUNC_MOCK_RUN(1) {
return -1;
}
FUNC_MOCK_END
FUNC_MOCK(os_cond_init, int,
os_cond_t *__restrict cond)
FUNC_MOCK_RUN_RET_DEFAULT_REAL(os_cond_init, cond)
FUNC_MOCK_RUN(1) {
return -1;
}
FUNC_MOCK_END
| 2,202 | 32.378788 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_sync/mocks_posix.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_posix.c -- redefinitions of lock functions (Posix implementation)
*/
#include <pthread.h>
#include "util.h"
#include "os.h"
#include "unittest.h"
FUNC_MOCK(pthread_mutex_init, int,
pthread_mutex_t *__restrict mutex,
const pthread_mutexattr_t *__restrict attr)
FUNC_MOCK_RUN_RET_DEFAULT_REAL(pthread_mutex_init, mutex, attr)
FUNC_MOCK_RUN(1) {
return -1;
}
FUNC_MOCK_END
FUNC_MOCK(pthread_rwlock_init, int,
pthread_rwlock_t *__restrict rwlock,
const pthread_rwlockattr_t *__restrict attr)
FUNC_MOCK_RUN_RET_DEFAULT_REAL(pthread_rwlock_init, rwlock, attr)
FUNC_MOCK_RUN(1) {
return -1;
}
FUNC_MOCK_END
FUNC_MOCK(pthread_cond_init, int,
pthread_cond_t *__restrict cond,
const pthread_condattr_t *__restrict attr)
FUNC_MOCK_RUN_RET_DEFAULT_REAL(pthread_cond_init, cond, attr)
FUNC_MOCK_RUN(1) {
return -1;
}
FUNC_MOCK_END
| 2,465 | 34.73913 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_check_version/vmem_check_version.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_check_version.c -- unit test for vmem_check_version
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "vmem_check_version");
UT_OUT("compile-time libvmem version is %d.%d",
VMEM_MAJOR_VERSION, VMEM_MINOR_VERSION);
const char *errstr = vmem_check_version(VMEM_MAJOR_VERSION,
VMEM_MINOR_VERSION);
UT_ASSERTinfo(errstr == NULL, errstr);
errstr = vmem_check_version(VMEM_MAJOR_VERSION + 1, VMEM_MINOR_VERSION);
UT_ASSERT(errstr != NULL);
UT_OUT("for major version %d, vmem_check_version returned: %s",
VMEM_MAJOR_VERSION + 1, errstr);
DONE(NULL);
}
| 2,213 | 35.295082 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/out_err_mt_win/out_err_mt_win.c
|
/*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* out_err_mt_win.c -- unit test for error messages
*/
#include <sys/types.h>
#include <stdarg.h>
#include <errno.h>
#include "unittest.h"
#include "valgrind_internal.h"
#include "util.h"
#define NUM_THREADS 16
static void
print_errors(const wchar_t *msg)
{
UT_OUT("%S", msg);
UT_OUT("PMEM: %S", pmem_errormsgW());
UT_OUT("PMEMOBJ: %S", pmemobj_errormsgW());
UT_OUT("PMEMLOG: %S", pmemlog_errormsgW());
UT_OUT("PMEMBLK: %S", pmemblk_errormsgW());
UT_OUT("PMEMCTO: %S", pmemcto_errormsgW());
UT_OUT("VMEM: %S", vmem_errormsgW());
UT_OUT("PMEMPOOL: %S", pmempool_errormsgW());
}
static void
check_errors(int ver)
{
int ret;
int err_need;
int err_found;
ret = swscanf(pmem_errormsgW(),
L"libpmem major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEM_MAJOR_VERSION);
ret = swscanf(pmemobj_errormsgW(),
L"libpmemobj major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEMOBJ_MAJOR_VERSION);
ret = swscanf(pmemlog_errormsgW(),
L"libpmemlog major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEMLOG_MAJOR_VERSION);
ret = swscanf(pmemblk_errormsgW(),
L"libpmemblk major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEMBLK_MAJOR_VERSION);
ret = swscanf(pmemcto_errormsgW(),
L"libpmemcto major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEMCTO_MAJOR_VERSION);
ret = swscanf(vmem_errormsgW(),
L"libvmem major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, VMEM_MAJOR_VERSION);
ret = swscanf(pmempool_errormsgW(),
L"libpmempool major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEMPOOL_MAJOR_VERSION);
}
static void *
do_test(void *arg)
{
int ver = *(int *)arg;
pmem_check_version(ver, 0);
pmemobj_check_version(ver, 0);
pmemlog_check_version(ver, 0);
pmemblk_check_version(ver, 0);
pmemcto_check_version(ver, 0);
vmem_check_version(ver, 0);
pmempool_check_version(ver, 0);
check_errors(ver);
return NULL;
}
static void
run_mt_test(void *(*worker)(void *))
{
os_thread_t thread[NUM_THREADS];
int ver[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; ++i) {
ver[i] = 10000 + i;
PTHREAD_CREATE(&thread[i], NULL, worker, &ver[i]);
}
for (int i = 0; i < NUM_THREADS; ++i) {
PTHREAD_JOIN(&thread[i], NULL);
}
}
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "out_err_mt_win");
if (argc != 6)
UT_FATAL("usage: %S file1 file2 file3 file4 dir",
argv[0]);
print_errors(L"start");
PMEMobjpool *pop = pmemobj_createW(argv[1], L"test",
PMEMOBJ_MIN_POOL, 0666);
PMEMlogpool *plp = pmemlog_createW(argv[2],
PMEMLOG_MIN_POOL, 0666);
PMEMblkpool *pbp = pmemblk_createW(argv[3],
128, PMEMBLK_MIN_POOL, 0666);
PMEMctopool *pcp = pmemcto_createW(argv[4], L"test",
PMEMCTO_MIN_POOL, 0666);
VMEM *vmp = vmem_createW(argv[5], VMEM_MIN_POOL);
util_init();
pmem_check_version(10000, 0);
pmemobj_check_version(10001, 0);
pmemlog_check_version(10002, 0);
pmemblk_check_version(10003, 0);
pmemcto_check_version(10004, 0);
vmem_check_version(10005, 0);
pmempool_check_version(10006, 0);
print_errors(L"version check");
void *ptr = NULL;
/*
* We are testing library error reporting and we don't want this test
* to fail under memcheck.
*/
VALGRIND_DO_DISABLE_ERROR_REPORTING;
pmem_msync(ptr, 1);
VALGRIND_DO_ENABLE_ERROR_REPORTING;
print_errors(L"pmem_msync");
int ret;
PMEMoid oid;
ret = pmemobj_alloc(pop, &oid, 0, 0, NULL, NULL);
UT_ASSERTeq(ret, -1);
print_errors(L"pmemobj_alloc");
pmemlog_append(plp, NULL, PMEMLOG_MIN_POOL);
print_errors(L"pmemlog_append");
size_t nblock = pmemblk_nblock(pbp);
pmemblk_set_error(pbp, nblock + 1);
print_errors(L"pmemblk_set_error");
char dummy[8192 + 64] = { 0 };
pmemcto_close((PMEMctopool *)&dummy);
print_errors(L"pmemcto_check");
VMEM *vmp2 = vmem_create_in_region(NULL, 1);
UT_ASSERTeq(vmp2, NULL);
print_errors(L"vmem_create_in_region");
run_mt_test(do_test);
pmemobj_close(pop);
pmemlog_close(plp);
pmemblk_close(pbp);
pmemcto_close(pcp);
vmem_delete(vmp);
PMEMpoolcheck *ppc;
struct pmempool_check_args args = {0, };
ppc = pmempool_check_init(&args, sizeof(args) / 2);
UT_ASSERTeq(ppc, NULL);
print_errors(L"pmempool_check_init");
DONEW(NULL);
}
| 6,392 | 27.162996 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_oid_thread/obj_oid_thread.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_oid_thread.c -- unit test for the reverse direct operation
*/
#include "unittest.h"
#include "lane.h"
#include "obj.h"
#define MAX_PATH_LEN 255
#define LAYOUT_NAME "direct"
static os_mutex_t lock;
static os_cond_t cond;
static int flag = 1;
static PMEMoid thread_oid;
/*
* test_worker -- (internal) test worker thread
*/
static void *
test_worker(void *arg)
{
os_mutex_lock(&lock);
/* before pool is closed */
void *direct = pmemobj_direct(thread_oid);
UT_ASSERT(OID_EQUALS(thread_oid, pmemobj_oid(direct)));
flag = 0;
os_cond_signal(&cond);
os_mutex_unlock(&lock);
os_mutex_lock(&lock);
while (flag == 0)
os_cond_wait(&cond, &lock);
/* after pool is closed */
UT_ASSERT(OID_IS_NULL(pmemobj_oid(direct)));
os_mutex_unlock(&lock);
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_oid_thread");
if (argc != 3)
UT_FATAL("usage: %s [directory] [# of pools]", argv[0]);
os_mutex_init(&lock);
os_cond_init(&cond);
unsigned npools = ATOU(argv[2]);
const char *dir = argv[1];
int r;
PMEMobjpool **pops = MALLOC(npools * sizeof(PMEMoid *));
size_t length = strlen(dir) + MAX_PATH_LEN;
char *path = MALLOC(length);
for (unsigned i = 0; i < npools; ++i) {
int ret = snprintf(path, length, "%s"OS_DIR_SEP_STR"testfile%d",
dir, i);
if (ret < 0 || ret >= length)
UT_FATAL("snprintf: %d", ret);
pops[i] = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (pops[i] == NULL)
UT_FATAL("!pmemobj_create");
}
/* Address outside the pmemobj pool */
void *allocated_memory = MALLOC(sizeof(int));
UT_ASSERT(OID_IS_NULL(pmemobj_oid(allocated_memory)));
PMEMoid *oids = MALLOC(npools * sizeof(PMEMoid));
PMEMoid *tmpoids = MALLOC(npools * sizeof(PMEMoid));
UT_ASSERT(OID_IS_NULL(pmemobj_oid(NULL)));
oids[0] = OID_NULL;
for (unsigned i = 0; i < npools; ++i) {
uint64_t off = pops[i]->heap_offset;
oids[i] = (PMEMoid) {pops[i]->uuid_lo, off};
UT_ASSERT(OID_EQUALS(oids[i],
pmemobj_oid(pmemobj_direct(oids[i]))));
r = pmemobj_alloc(pops[i], &tmpoids[i], 100, 1, NULL, NULL);
UT_ASSERTeq(r, 0);
UT_ASSERT(OID_EQUALS(tmpoids[i],
pmemobj_oid(pmemobj_direct(tmpoids[i]))));
}
r = pmemobj_alloc(pops[0], &thread_oid, 100, 2, NULL, NULL);
UT_ASSERTeq(r, 0);
UT_ASSERT(!OID_IS_NULL(pmemobj_oid(pmemobj_direct(thread_oid))));
os_mutex_lock(&lock);
os_thread_t t;
PTHREAD_CREATE(&t, NULL, test_worker, NULL);
/* wait for the thread to perform the first direct */
while (flag != 0)
os_cond_wait(&cond, &lock);
for (unsigned i = 0; i < npools; ++i) {
pmemobj_free(&tmpoids[i]);
UT_ASSERT(OID_IS_NULL(pmemobj_oid(
pmemobj_direct(tmpoids[i]))));
pmemobj_close(pops[i]);
UT_ASSERT(OID_IS_NULL(pmemobj_oid(
pmemobj_direct(oids[i]))));
}
/* signal the waiting thread */
flag = 1;
os_cond_signal(&cond);
os_mutex_unlock(&lock);
PTHREAD_JOIN(&t, NULL);
FREE(path);
FREE(tmpoids);
FREE(oids);
FREE(pops);
FREE(allocated_memory);
os_mutex_destroy(&lock);
os_cond_destroy(&cond);
DONE(NULL);
}
| 4,661 | 26.585799 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_file_open/util_file_open.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_file_open.c -- unit test for util_file_open()
*
* usage: util_file_open minlen path [path]...
*/
#include "unittest.h"
#include "file.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "util_file_open");
if (argc < 3)
UT_FATAL("usage: %s minlen path...", argv[0]);
char *fname;
size_t minsize = strtoul(argv[1], &fname, 0);
for (int arg = 2; arg < argc; arg++) {
size_t size = 0;
int fd = util_file_open(argv[arg], &size, minsize, O_RDWR);
if (fd == -1)
UT_OUT("!%s: util_file_open", argv[arg]);
else {
UT_OUT("%s: open, len %zu", argv[arg], size);
os_close(fd);
}
}
DONE(NULL);
}
| 2,237 | 32.402985 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libvmmalloc/libvmmalloc.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libvmmalloc.c -- entry points for libvmmalloc
*
* NOTES:
* 1) Since some standard library functions (fopen, sprintf) use malloc
* internally, then at initialization phase, malloc(3) calls are redirected
* to the standard jemalloc interfaces that operate on a system heap.
* There is no need to track these allocations. For small allocations,
* jemalloc is able to detect the corresponding pool the memory was
* allocated from, and Vmp argument is actually ignored. So, it is safe
* to reclaim this memory using je_vmem_pool_free().
* The problem may occur for huge allocations only (>2MB), but it seems
* like such allocations do not happen at initialization phase.
*
* 2) Debug traces in malloc(3) functions are not available until library
* initialization (vmem pool creation) is completed. This is to avoid
* recursive calls to malloc, leading to stack overflow.
*
* 3) Malloc hooks in glibc are overridden to prevent any references to glibc's
* malloc(3) functions in case the application uses dlopen with
* RTLD_DEEPBIND flag. (Not relevant for FreeBSD since FreeBSD supports
* neither malloc hooks nor RTLD_DEEPBIND.)
*
* 4) If the process forks, there is no separate log file open for a new
* process, even if the configured log file name is terminated with "-".
*
* 5) Fork options 2 and 3 are currently not supported on FreeBSD because
* locks are dynamically allocated on FreeBSD and hence they would be cloned
* as part of the pool. This may be solvable.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <errno.h>
#include <stdint.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#ifndef __FreeBSD__
#include <malloc.h>
#endif
#include "libvmem.h"
#include "libvmmalloc.h"
#include "jemalloc.h"
#include "pmemcommon.h"
#include "file.h"
#include "os.h"
#include "os_thread.h"
#include "vmem.h"
#include "vmmalloc.h"
#include "valgrind_internal.h"
#define HUGE (2 * 1024 * 1024)
/*
* private to this file...
*/
static size_t Header_size;
static VMEM *Vmp;
static char *Dir;
static int Fd;
static int Fd_clone;
static int Private;
static int Forkopt = 1; /* default behavior - remap as private */
static bool Destructed; /* when set - ignore all calls (do not call jemalloc) */
/*
* malloc -- allocate a block of size bytes
*/
__ATTR_MALLOC__
__ATTR_ALLOC_SIZE__(1)
void *
malloc(size_t size)
{
if (unlikely(Destructed))
return NULL;
if (Vmp == NULL) {
ASSERT(size <= HUGE);
return je_vmem_malloc(size);
}
LOG(4, "size %zu", size);
return je_vmem_pool_malloc(
(pool_t *)((uintptr_t)Vmp + Header_size), size);
}
/*
* calloc -- allocate a block of nmemb * size bytes and set its contents to zero
*/
__ATTR_MALLOC__
__ATTR_ALLOC_SIZE__(1, 2)
void *
calloc(size_t nmemb, size_t size)
{
if (unlikely(Destructed))
return NULL;
if (Vmp == NULL) {
ASSERT((nmemb * size) <= HUGE);
return je_vmem_calloc(nmemb, size);
}
LOG(4, "nmemb %zu, size %zu", nmemb, size);
return je_vmem_pool_calloc((pool_t *)((uintptr_t)Vmp + Header_size),
nmemb, size);
}
/*
* realloc -- resize a block previously allocated by malloc
*/
__ATTR_ALLOC_SIZE__(2)
void *
realloc(void *ptr, size_t size)
{
if (unlikely(Destructed))
return NULL;
if (Vmp == NULL) {
ASSERT(size <= HUGE);
return je_vmem_realloc(ptr, size);
}
LOG(4, "ptr %p, size %zu", ptr, size);
return je_vmem_pool_ralloc((pool_t *)((uintptr_t)Vmp + Header_size),
ptr, size);
}
/*
* free -- free a block previously allocated by malloc
*/
void
free(void *ptr)
{
if (unlikely(Destructed))
return;
if (Vmp == NULL) {
je_vmem_free(ptr);
return;
}
LOG(4, "ptr %p", ptr);
je_vmem_pool_free((pool_t *)((uintptr_t)Vmp + Header_size), ptr);
}
/*
* cfree -- free a block previously allocated by calloc
*
* the implementation is identical to free()
*
* XXX Not supported on FreeBSD, but we define it anyway
*/
void
cfree(void *ptr)
{
if (unlikely(Destructed))
return;
if (Vmp == NULL) {
je_vmem_free(ptr);
return;
}
LOG(4, "ptr %p", ptr);
je_vmem_pool_free((pool_t *)((uintptr_t)Vmp + Header_size), ptr);
}
/*
* memalign -- allocate a block of size bytes, starting on an address
* that is a multiple of boundary
*
* XXX Not supported on FreeBSD, but we define it anyway
*/
__ATTR_MALLOC__
__ATTR_ALLOC_ALIGN__(1)
__ATTR_ALLOC_SIZE__(2)
void *
memalign(size_t boundary, size_t size)
{
if (unlikely(Destructed))
return NULL;
if (Vmp == NULL) {
ASSERT(size <= HUGE);
return je_vmem_aligned_alloc(boundary, size);
}
LOG(4, "boundary %zu size %zu", boundary, size);
return je_vmem_pool_aligned_alloc(
(pool_t *)((uintptr_t)Vmp + Header_size),
boundary, size);
}
/*
* aligned_alloc -- allocate a block of size bytes, starting on an address
* that is a multiple of alignment
*
* size must be a multiple of alignment
*/
__ATTR_MALLOC__
__ATTR_ALLOC_ALIGN__(1)
__ATTR_ALLOC_SIZE__(2)
void *
aligned_alloc(size_t alignment, size_t size)
{
if (unlikely(Destructed))
return NULL;
/* XXX - check if size is a multiple of alignment */
if (Vmp == NULL) {
ASSERT(size <= HUGE);
return je_vmem_aligned_alloc(alignment, size);
}
LOG(4, "alignment %zu size %zu", alignment, size);
return je_vmem_pool_aligned_alloc(
(pool_t *)((uintptr_t)Vmp + Header_size),
alignment, size);
}
/*
* posix_memalign -- allocate a block of size bytes, starting on an address
* that is a multiple of alignment
*/
__ATTR_NONNULL__(1)
int
posix_memalign(void **memptr, size_t alignment, size_t size)
{
if (unlikely(Destructed))
return ENOMEM;
int ret = 0;
int oerrno = errno;
if (Vmp == NULL) {
ASSERT(size <= HUGE);
return je_vmem_posix_memalign(memptr, alignment, size);
}
LOG(4, "alignment %zu size %zu", alignment, size);
*memptr = je_vmem_pool_aligned_alloc(
(pool_t *)((uintptr_t)Vmp + Header_size),
alignment, size);
if (*memptr == NULL)
ret = errno;
errno = oerrno;
return ret;
}
/*
* valloc -- allocate a block of size bytes, starting on a page boundary
*/
__ATTR_MALLOC__
__ATTR_ALLOC_SIZE__(1)
void *
valloc(size_t size)
{
if (unlikely(Destructed))
return NULL;
ASSERTne(Pagesize, 0);
if (Vmp == NULL) {
ASSERT(size <= HUGE);
return je_vmem_aligned_alloc(Pagesize, size);
}
LOG(4, "size %zu", size);
return je_vmem_pool_aligned_alloc(
(pool_t *)((uintptr_t)Vmp + Header_size),
Pagesize, size);
}
/*
* pvalloc -- allocate a block of size bytes, starting on a page boundary
*
* Requested size is also aligned to page boundary.
*
* XXX Not supported on FreeBSD, but we define it anyway.
*/
__ATTR_MALLOC__
__ATTR_ALLOC_SIZE__(1)
void *
pvalloc(size_t size)
{
if (unlikely(Destructed))
return NULL;
ASSERTne(Pagesize, 0);
if (Vmp == NULL) {
ASSERT(size <= HUGE);
return je_vmem_aligned_alloc(Pagesize, roundup(size, Pagesize));
}
LOG(4, "size %zu", size);
return je_vmem_pool_aligned_alloc(
(pool_t *)((uintptr_t)Vmp + Header_size),
Pagesize, roundup(size, Pagesize));
}
/*
* malloc_usable_size -- get usable size of allocation
*/
size_t
malloc_usable_size(void *ptr)
{
if (unlikely(Destructed))
return 0;
if (Vmp == NULL) {
return je_vmem_malloc_usable_size(ptr);
}
LOG(4, "ptr %p", ptr);
return je_vmem_pool_malloc_usable_size(
(pool_t *)((uintptr_t)Vmp + Header_size), ptr);
}
#if (defined(__GLIBC__) && !defined(__UCLIBC__))
#ifndef __MALLOC_HOOK_VOLATILE
#define __MALLOC_HOOK_VOLATILE
#endif
/*
* Interpose malloc hooks in glibc. Even if the application uses dlopen
* with RTLD_DEEPBIND flag, all the references to libc's malloc(3) functions
* will be redirected to libvmmalloc.
*/
void *(*__MALLOC_HOOK_VOLATILE __malloc_hook) (size_t size,
const void *caller) = (void *)malloc;
void *(*__MALLOC_HOOK_VOLATILE __realloc_hook) (void *ptr, size_t size,
const void *caller) = (void *)realloc;
void (*__MALLOC_HOOK_VOLATILE __free_hook) (void *ptr, const void *caller) =
(void *)free;
void *(*__MALLOC_HOOK_VOLATILE __memalign_hook) (size_t size, size_t alignment,
const void *caller) = (void *)memalign;
#endif
/*
* print_jemalloc_messages -- (internal) custom print function, for jemalloc
*
* Prints traces from jemalloc. All traces from jemalloc
* are considered as error messages.
*/
static void
print_jemalloc_messages(void *ignore, const char *s)
{
LOG_NONL(1, "%s", s);
}
/*
* print_jemalloc_stats -- (internal) print function for jemalloc statistics
*/
static void
print_jemalloc_stats(void *ignore, const char *s)
{
LOG_NONL(0, "%s", s);
}
/*
* libvmmalloc_create -- (internal) create a memory pool in a temp file
*/
static VMEM *
libvmmalloc_create(const char *dir, size_t size)
{
LOG(3, "dir \"%s\" size %zu", dir, size);
if (size < VMMALLOC_MIN_POOL) {
LOG(1, "size %zu smaller than %zu", size, VMMALLOC_MIN_POOL);
errno = EINVAL;
return NULL;
}
/* silently enforce multiple of page size */
size = roundup(size, Pagesize);
Fd = util_tmpfile(dir, "/vmem.XXXXXX", O_EXCL);
if (Fd == -1)
return NULL;
if ((errno = os_posix_fallocate(Fd, 0, (os_off_t)size)) != 0) {
ERR("!posix_fallocate");
(void) os_close(Fd);
return NULL;
}
void *addr;
if ((addr = util_map(Fd, size, MAP_SHARED, 0, 4 << 20, NULL)) == NULL) {
(void) os_close(Fd);
return NULL;
}
/* store opaque info at beginning of mapped area */
struct vmem *vmp = addr;
memset(&vmp->hdr, '\0', sizeof(vmp->hdr));
memcpy(vmp->hdr.signature, VMEM_HDR_SIG, POOL_HDR_SIG_LEN);
vmp->addr = addr;
vmp->size = size;
vmp->caller_mapped = 0;
/* Prepare pool for jemalloc */
if (je_vmem_pool_create((void *)((uintptr_t)addr + Header_size),
size - Header_size, 1 /* zeroed */,
1 /* empty */) == NULL) {
LOG(1, "vmem pool creation failed");
util_unmap(vmp->addr, vmp->size);
return NULL;
}
/*
* If possible, turn off all permissions on the pool header page.
*
* The prototype PMFS doesn't allow this when large pages are in
* use. It is not considered an error if this fails.
*/
util_range_none(addr, sizeof(struct pool_hdr));
LOG(3, "vmp %p", vmp);
return vmp;
}
/*
* libvmmalloc_clone - (internal) clone the entire pool
*/
static int
libvmmalloc_clone(void)
{
LOG(3, NULL);
int err;
Fd_clone = util_tmpfile(Dir, "/vmem.XXXXXX", O_EXCL);
if (Fd_clone == -1)
return -1;
err = os_posix_fallocate(Fd_clone, 0, (os_off_t)Vmp->size);
if (err != 0) {
errno = err;
ERR("!posix_fallocate");
goto err_close;
}
void *addr = mmap(NULL, Vmp->size, PROT_READ|PROT_WRITE,
MAP_SHARED, Fd_clone, 0);
if (addr == MAP_FAILED) {
LOG(1, "!mmap");
goto err_close;
}
LOG(3, "copy the entire pool file: dst %p src %p size %zu",
addr, Vmp->addr, Vmp->size);
util_range_rw(Vmp->addr, sizeof(struct pool_hdr));
/*
* Part of vmem pool was probably freed at some point, so Valgrind
* marked it as undefined/inaccessible. We need to duplicate the whole
* pool, so as a workaround temporarily disable error reporting.
*/
VALGRIND_DO_DISABLE_ERROR_REPORTING;
memcpy(addr, Vmp->addr, Vmp->size);
VALGRIND_DO_ENABLE_ERROR_REPORTING;
if (munmap(addr, Vmp->size)) {
ERR("!munmap");
goto err_close;
}
util_range_none(Vmp->addr, sizeof(struct pool_hdr));
return 0;
err_close:
(void) os_close(Fd_clone);
return -1;
}
/*
* remap_as_private -- (internal) remap the pool as private
*/
static void
remap_as_private(void)
{
LOG(3, "remap the pool file as private");
void *r = mmap(Vmp->addr, Vmp->size, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, Fd, 0);
if (r == MAP_FAILED) {
out_log(NULL, 0, NULL, 0,
"Error (libvmmalloc): remapping failed\n");
abort();
}
if (r != Vmp->addr) {
out_log(NULL, 0, NULL, 0,
"Error (libvmmalloc): wrong address\n");
abort();
}
Private = 1;
}
/*
* libvmmalloc_prefork -- (internal) prepare for fork()
*
* Clones the entire pool or remaps it with MAP_PRIVATE flag.
*/
static void
libvmmalloc_prefork(void)
{
LOG(3, NULL);
/*
* There's no need to grab any locks here, as jemalloc pre-fork handler
* is executed first, and it does all the synchronization.
*/
ASSERTne(Vmp, NULL);
ASSERTne(Dir, NULL);
if (Private) {
LOG(3, "already mapped as private - do nothing");
return;
}
switch (Forkopt) {
case 3:
/* clone the entire pool; if it fails - remap it as private */
LOG(3, "clone or remap");
case 2:
LOG(3, "clone the entire pool file");
if (libvmmalloc_clone() == 0)
break;
if (Forkopt == 2) {
out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): "
"pool cloning failed\n");
abort();
}
/* cloning failed; fall-thru to remapping */
case 1:
remap_as_private();
break;
case 0:
LOG(3, "do nothing");
break;
default:
FATAL("invalid fork action %d", Forkopt);
}
}
/*
* libvmmalloc_postfork_parent -- (internal) parent post-fork handler
*/
static void
libvmmalloc_postfork_parent(void)
{
LOG(3, NULL);
if (Forkopt == 0) {
/* do nothing */
return;
}
if (Private) {
LOG(3, "pool mapped as private - do nothing");
} else {
LOG(3, "close the cloned pool file");
(void) os_close(Fd_clone);
}
}
/*
* libvmmalloc_postfork_child -- (internal) child post-fork handler
*/
static void
libvmmalloc_postfork_child(void)
{
LOG(3, NULL);
if (Forkopt == 0) {
/* do nothing */
return;
}
if (Private) {
LOG(3, "pool mapped as private - do nothing");
} else {
LOG(3, "close the original pool file");
(void) os_close(Fd);
Fd = Fd_clone;
void *addr = Vmp->addr;
size_t size = Vmp->size;
LOG(3, "mapping cloned pool file at %p", addr);
Vmp = mmap(addr, size, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, Fd, 0);
if (Vmp == MAP_FAILED) {
out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): "
"mapping failed\n");
abort();
}
if (Vmp != addr) {
out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): "
"wrong address\n");
abort();
}
}
/* XXX - open a new log file, with the new PID in the name */
}
/*
* libvmmalloc_init -- load-time initialization for libvmmalloc
*
* Called automatically by the run-time loader.
* The constructor priority guarantees this is executed before
* libjemalloc constructor.
*/
__attribute__((constructor(101)))
static void
libvmmalloc_init(void)
{
char *env_str;
size_t size;
/*
* Register fork handlers before jemalloc initialization.
* This provides the correct order of fork handlers execution.
* Note that the first malloc() will trigger jemalloc init, so we
* have to register fork handlers before the call to out_init(),
* as it may indirectly call malloc() when opening the log file.
*/
if (os_thread_atfork(libvmmalloc_prefork,
libvmmalloc_postfork_parent,
libvmmalloc_postfork_child) != 0) {
perror("Error (libvmmalloc): os_thread_atfork");
abort();
}
common_init(VMMALLOC_LOG_PREFIX, VMMALLOC_LOG_LEVEL_VAR,
VMMALLOC_LOG_FILE_VAR, VMMALLOC_MAJOR_VERSION,
VMMALLOC_MINOR_VERSION);
out_set_vsnprintf_func(je_vmem_navsnprintf);
LOG(3, NULL);
/* set up jemalloc messages to a custom print function */
je_vmem_malloc_message = print_jemalloc_messages;
Header_size = roundup(sizeof(VMEM), Pagesize);
if ((Dir = os_getenv(VMMALLOC_POOL_DIR_VAR)) == NULL) {
out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): "
"environment variable %s not specified",
VMMALLOC_POOL_DIR_VAR);
abort();
}
if ((env_str = os_getenv(VMMALLOC_POOL_SIZE_VAR)) == NULL) {
out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): "
"environment variable %s not specified",
VMMALLOC_POOL_SIZE_VAR);
abort();
} else {
long long v = atoll(env_str);
if (v < 0) {
out_log(NULL, 0, NULL, 0,
"Error (libvmmalloc): negative %s",
VMMALLOC_POOL_SIZE_VAR);
abort();
}
size = (size_t)v;
}
if (size < VMMALLOC_MIN_POOL) {
out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): "
"%s value is less than minimum (%zu < %zu)",
VMMALLOC_POOL_SIZE_VAR, size,
VMMALLOC_MIN_POOL);
abort();
}
if ((env_str = os_getenv(VMMALLOC_FORK_VAR)) != NULL) {
Forkopt = atoi(env_str);
if (Forkopt < 0 || Forkopt > 3) {
out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): "
"incorrect %s value (%d)",
VMMALLOC_FORK_VAR, Forkopt);
abort();
}
#ifdef __FreeBSD__
if (Forkopt > 1) {
out_log(NULL, 0, NULL, 0, "Error (libvmmalloc): "
"%s value %d not supported on FreeBSD",
VMMALLOC_FORK_VAR, Forkopt);
abort();
}
#endif
LOG(4, "Fork action %d", Forkopt);
}
/*
* XXX - vmem_create() could be used here, but then we need to
* link vmem.o, including all the vmem API.
*/
Vmp = libvmmalloc_create(Dir, size);
if (Vmp == NULL) {
out_log(NULL, 0, NULL, 0, "!Error (libvmmalloc): "
"vmem pool creation failed");
abort();
}
LOG(2, "initialization completed");
}
/*
* libvmmalloc_fini -- libvmmalloc cleanup routine
*
* Called automatically when the process terminates and prints
* some basic allocator statistics.
*/
__attribute__((destructor(102)))
static void
libvmmalloc_fini(void)
{
LOG(3, NULL);
char *env_str = os_getenv(VMMALLOC_LOG_STATS_VAR);
if ((env_str != NULL) && strcmp(env_str, "1") == 0) {
LOG_NONL(0, "\n========= system heap ========\n");
je_vmem_malloc_stats_print(
print_jemalloc_stats, NULL, "gba");
LOG_NONL(0, "\n========= vmem pool ========\n");
je_vmem_pool_malloc_stats_print(
(pool_t *)((uintptr_t)Vmp + Header_size),
print_jemalloc_stats, NULL, "gba");
}
common_fini();
Destructed = true;
}
| 19,087 | 23.534704 | 80 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libvmmalloc/vmmalloc.h
|
/*
* Copyright 2014-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc.h -- internal definitions for libvmmalloc
*/
#define VMMALLOC_LOG_PREFIX "libvmmalloc"
#define VMMALLOC_LOG_LEVEL_VAR "VMMALLOC_LOG_LEVEL"
#define VMMALLOC_LOG_FILE_VAR "VMMALLOC_LOG_FILE"
#define VMMALLOC_LOG_STATS_VAR "VMMALLOC_LOG_STATS"
#define VMMALLOC_POOL_DIR_VAR "VMMALLOC_POOL_DIR"
#define VMMALLOC_POOL_SIZE_VAR "VMMALLOC_POOL_SIZE"
#define VMMALLOC_FORK_VAR "VMMALLOC_FORK"
| 2,005 | 43.577778 | 74 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/rpmem_common/rpmem_fip_common.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_fip_common.h -- common definitions for librpmem and rpmemd
*/
#ifndef RPMEM_FIP_COMMON_H
#define RPMEM_FIP_COMMON_H 1
#include <string.h>
#include <netinet/in.h>
#include <rdma/fabric.h>
#include <rdma/fi_cm.h>
#include <rdma/fi_rma.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RPMEM_FIVERSION FI_VERSION(1, 4)
#define RPMEM_FIP_CQ_WAIT_MS 100
#define min(a, b) ((a) < (b) ? (a) : (b))
/*
* rpmem_fip_node -- client or server node type
*/
enum rpmem_fip_node {
RPMEM_FIP_NODE_CLIENT,
RPMEM_FIP_NODE_SERVER,
MAX_RPMEM_FIP_NODE,
};
/*
* rpmem_fip_probe -- list of providers
*/
struct rpmem_fip_probe {
unsigned providers;
};
/*
* rpmem_fip_probe -- returns true if specified provider is available
*/
static inline int
rpmem_fip_probe(struct rpmem_fip_probe probe, enum rpmem_provider provider)
{
return (probe.providers & (1U << provider)) != 0;
}
/*
* rpmem_fip_probe_any -- returns true if any provider is available
*/
static inline int
rpmem_fip_probe_any(struct rpmem_fip_probe probe)
{
return probe.providers != 0;
}
int rpmem_fip_probe_get(const char *target, struct rpmem_fip_probe *probe);
struct fi_info *rpmem_fip_get_hints(enum rpmem_provider provider);
int rpmem_fip_read_eq_check(struct fid_eq *eq, struct fi_eq_cm_entry *entry,
uint32_t exp_event, fid_t exp_fid, int timeout);
int rpmem_fip_read_eq(struct fid_eq *eq, struct fi_eq_cm_entry *entry,
uint32_t *event, int timeout);
size_t rpmem_fip_cq_size(enum rpmem_persist_method pm,
enum rpmem_fip_node node);
size_t rpmem_fip_tx_size(enum rpmem_persist_method pm,
enum rpmem_fip_node node);
size_t rpmem_fip_rx_size(enum rpmem_persist_method pm,
enum rpmem_fip_node node);
size_t rpmem_fip_max_nlanes(struct fi_info *fi);
void rpmem_fip_print_info(struct fi_info *fi);
#ifdef __cplusplus
}
#endif
#endif
| 3,428 | 28.307692 | 76 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/rpmem_common/rpmem_fip_common.c
|
/*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_common.c -- common definitions for librpmem and rpmemd
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <errno.h>
#include "rpmem_common.h"
#include "rpmem_fip_common.h"
#include "rpmem_proto.h"
#include "rpmem_common_log.h"
#include "valgrind_internal.h"
#include <rdma/fi_errno.h>
/*
* rpmem_fip_get_hints -- return fabric interface information hints
*/
struct fi_info *
rpmem_fip_get_hints(enum rpmem_provider provider)
{
RPMEMC_ASSERT(provider < MAX_RPMEM_PROV);
struct fi_info *hints = fi_allocinfo();
if (!hints) {
RPMEMC_LOG(ERR, "!fi_allocinfo");
return NULL;
}
/* connection-oriented endpoint */
hints->ep_attr->type = FI_EP_MSG;
/*
* Basic memory registration mode indicates that MR attributes
* (rkey, lkey) are selected by provider.
*/
hints->domain_attr->mr_mode = FI_MR_BASIC;
/*
* FI_THREAD_SAFE indicates MT applications can access any
* resources through interface without any restrictions
*/
hints->domain_attr->threading = FI_THREAD_SAFE;
/*
* FI_MSG - SEND and RECV
* FI_RMA - WRITE and READ
*/
hints->caps = FI_MSG | FI_RMA;
/* must register locally accessed buffers */
hints->mode = FI_CONTEXT | FI_LOCAL_MR | FI_RX_CQ_DATA;
/* READ-after-WRITE and SEND-after-WRITE message ordering required */
hints->tx_attr->msg_order = FI_ORDER_RAW | FI_ORDER_SAW;
hints->addr_format = FI_SOCKADDR;
if (provider != RPMEM_PROV_UNKNOWN) {
const char *prov_name = rpmem_provider_to_str(provider);
RPMEMC_ASSERT(prov_name != NULL);
hints->fabric_attr->prov_name = strdup(prov_name);
if (!hints->fabric_attr->prov_name) {
RPMEMC_LOG(ERR, "!strdup(provider)");
goto err_strdup;
}
}
return hints;
err_strdup:
fi_freeinfo(hints);
return NULL;
}
/*
* rpmem_fip_probe_get -- return list of available providers
*/
int
rpmem_fip_probe_get(const char *target, struct rpmem_fip_probe *probe)
{
struct fi_info *hints = rpmem_fip_get_hints(RPMEM_PROV_UNKNOWN);
if (!hints)
return -1;
int ret;
struct fi_info *fi;
ret = fi_getinfo(RPMEM_FIVERSION, target, NULL, 0, hints, &fi);
if (ret) {
goto err_getinfo;
}
if (probe) {
memset(probe, 0, sizeof(*probe));
struct fi_info *prov = fi;
while (prov) {
enum rpmem_provider p = rpmem_provider_from_str(
prov->fabric_attr->prov_name);
if (p == RPMEM_PROV_UNKNOWN) {
prov = prov->next;
continue;
}
probe->providers |= (1U << p);
prov = prov->next;
}
}
fi_freeinfo(fi);
err_getinfo:
fi_freeinfo(hints);
return ret;
}
/*
* rpmem_fip_read_eq -- read event queue entry with specified timeout
*/
int
rpmem_fip_read_eq(struct fid_eq *eq, struct fi_eq_cm_entry *entry,
uint32_t *event, int timeout)
{
int ret;
ssize_t sret;
struct fi_eq_err_entry err;
sret = fi_eq_sread(eq, event, entry, sizeof(*entry), timeout, 0);
VALGRIND_DO_MAKE_MEM_DEFINED(&sret, sizeof(sret));
if (timeout != -1 && (sret == -FI_ETIMEDOUT || sret == -FI_EAGAIN)) {
errno = ETIMEDOUT;
return 1;
}
if (sret < 0 || (size_t)sret != sizeof(*entry)) {
if (sret < 0)
ret = (int)sret;
else
ret = -1;
sret = fi_eq_readerr(eq, &err, 0);
if (sret < 0) {
errno = EIO;
RPMEMC_LOG(ERR, "error reading from event queue: "
"cannot read error from event queue: %s",
fi_strerror((int)sret));
} else if (sret > 0) {
RPMEMC_ASSERT(sret == sizeof(err));
errno = -err.prov_errno;
RPMEMC_LOG(ERR, "error reading from event queue: %s",
fi_eq_strerror(eq, err.prov_errno,
NULL, NULL, 0));
}
return ret;
}
return 0;
}
/*
* rpmem_fip_read_eq -- read event queue entry and expect specified event
* and fid
*
* Returns:
* 1 - timeout
* 0 - success
* otherwise - error
*/
int
rpmem_fip_read_eq_check(struct fid_eq *eq, struct fi_eq_cm_entry *entry,
uint32_t exp_event, fid_t exp_fid, int timeout)
{
uint32_t event;
int ret = rpmem_fip_read_eq(eq, entry, &event, timeout);
if (ret)
return ret;
if (event != exp_event || entry->fid != exp_fid) {
errno = EIO;
RPMEMC_LOG(ERR, "unexpected event received (%u) "
"expected (%u)%s", event, exp_event,
entry->fid != exp_fid ?
" invalid endpoint" : "");
return -1;
}
return 0;
}
/*
* rpmem_fip_lane_attr -- lane attributes
*
* This structure describes how many SQ, RQ and CQ entries are
* required for a single lane.
*
* NOTE:
* - WRITE, READ and SEND requests are placed in SQ,
* - RECV requests are placed in RQ.
*/
struct rpmem_fip_lane_attr {
size_t n_per_sq; /* number of entries per lane in send queue */
size_t n_per_rq; /* number of entries per lane in receive queue */
size_t n_per_cq; /* number of entries per lane in completion queue */
};
static struct rpmem_fip_lane_attr
rpmem_fip_lane_attrs[MAX_RPMEM_FIP_NODE][MAX_RPMEM_PM] = {
[RPMEM_FIP_NODE_CLIENT][RPMEM_PM_GPSPM] = {
.n_per_sq = 2, /* WRITE + SEND */
.n_per_rq = 1, /* RECV */
.n_per_cq = 3,
},
[RPMEM_FIP_NODE_CLIENT][RPMEM_PM_APM] = {
/* WRITE + READ for persist, WRITE + SEND for deep persist */
.n_per_sq = 2, /* WRITE + SEND */
.n_per_rq = 1, /* RECV */
.n_per_cq = 3,
},
[RPMEM_FIP_NODE_SERVER][RPMEM_PM_GPSPM] = {
.n_per_sq = 1, /* SEND */
.n_per_rq = 1, /* RECV */
.n_per_cq = 3,
},
[RPMEM_FIP_NODE_SERVER][RPMEM_PM_APM] = {
.n_per_sq = 1, /* SEND */
.n_per_rq = 1, /* RECV */
.n_per_cq = 3,
},
};
/*
* rpmem_fip_cq_size -- returns completion queue size based on
* persist method and node type
*/
size_t
rpmem_fip_cq_size(enum rpmem_persist_method pm, enum rpmem_fip_node node)
{
RPMEMC_ASSERT(pm < MAX_RPMEM_PM);
RPMEMC_ASSERT(node < MAX_RPMEM_FIP_NODE);
struct rpmem_fip_lane_attr *attr = &rpmem_fip_lane_attrs[node][pm];
return attr->n_per_cq ? : 1;
}
/*
* rpmem_fip_tx_size -- returns submission queue (transmit queue) size based
* on persist method and node type
*/
size_t
rpmem_fip_tx_size(enum rpmem_persist_method pm, enum rpmem_fip_node node)
{
RPMEMC_ASSERT(pm < MAX_RPMEM_PM);
RPMEMC_ASSERT(node < MAX_RPMEM_FIP_NODE);
struct rpmem_fip_lane_attr *attr = &rpmem_fip_lane_attrs[node][pm];
return attr->n_per_sq ? : 1;
}
/*
* rpmem_fip_tx_size -- returns receive queue size based
* on persist method and node type
*/
size_t
rpmem_fip_rx_size(enum rpmem_persist_method pm, enum rpmem_fip_node node)
{
RPMEMC_ASSERT(pm < MAX_RPMEM_PM);
RPMEMC_ASSERT(node < MAX_RPMEM_FIP_NODE);
struct rpmem_fip_lane_attr *attr = &rpmem_fip_lane_attrs[node][pm];
return attr->n_per_rq ? : 1;
}
/*
* rpmem_fip_max_nlanes -- returns maximum number of lanes
*/
size_t
rpmem_fip_max_nlanes(struct fi_info *fi)
{
return min(min(fi->domain_attr->tx_ctx_cnt,
fi->domain_attr->rx_ctx_cnt),
fi->domain_attr->cq_cnt);
}
/*
* rpmem_fip_print_info -- print some useful info about fabric interface
*/
void
rpmem_fip_print_info(struct fi_info *fi)
{
RPMEMC_LOG(INFO, "libfabric version: %s",
fi_tostr(fi, FI_TYPE_VERSION));
char *str = fi_tostr(fi, FI_TYPE_INFO);
char *buff = strdup(str);
if (!buff) {
RPMEMC_LOG(ERR, "!allocating string buffer for "
"libfabric interface information");
return;
}
RPMEMC_LOG(INFO, "libfabric interface info:");
char *nl;
char *last = buff;
while (last != NULL) {
nl = strchr(last, '\n');
if (nl) {
*nl = '\0';
nl++;
}
RPMEMC_LOG(INFO, "%s", last);
last = nl;
}
free(buff);
}
| 8,921 | 23.991597 | 76 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/rpmem_common/rpmem_common_log.h
|
/*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_common_log.h -- common log macros for librpmem and rpmemd
*/
#if defined(RPMEMC_LOG_RPMEM) && defined(RPMEMC_LOG_RPMEMD)
#error Both RPMEMC_LOG_RPMEM and RPMEMC_LOG_RPMEMD defined
#elif !defined(RPMEMC_LOG_RPMEM) && !defined(RPMEMC_LOG_RPMEMD)
#define RPMEMC_LOG(level, fmt, args...) do {} while (0)
#define RPMEMC_DBG(level, fmt, args...) do {} while (0)
#define RPMEMC_FATAL(fmt, args...) do {} while (0)
#define RPMEMC_ASSERT(cond) do {} while (0)
#elif defined(RPMEMC_LOG_RPMEM)
#include "out.h"
#include "rpmem_util.h"
#define RPMEMC_LOG(level, fmt, args...) RPMEM_LOG(level, fmt, ## args)
#define RPMEMC_DBG(level, fmt, args...) RPMEM_DBG(fmt, ## args)
#define RPMEMC_FATAL(fmt, args...) RPMEM_FATAL(fmt, ## args)
#define RPMEMC_ASSERT(cond) RPMEM_ASSERT(cond)
#else
#include "rpmemd_log.h"
#define RPMEMC_LOG(level, fmt, args...) RPMEMD_LOG(level, fmt, ## args)
#define RPMEMC_DBG(level, fmt, args...) RPMEMD_DBG(fmt, ## args)
#define RPMEMC_FATAL(fmt, args...) RPMEMD_FATAL(fmt, ## args)
#define RPMEMC_ASSERT(cond) RPMEMD_ASSERT(cond)
#endif
| 2,675 | 38.352941 | 74 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/rpmem_common/rpmem_common.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_common.h -- common definitions for librpmem and rpmemd
*/
#ifndef RPMEM_COMMON_H
#define RPMEM_COMMON_H 1
/*
* Values for SO_KEEPALIVE socket option
*/
#define RPMEM_CMD_ENV "RPMEM_CMD"
#define RPMEM_SSH_ENV "RPMEM_SSH"
#define RPMEM_DEF_CMD "rpmemd"
#define RPMEM_DEF_SSH "ssh"
#define RPMEM_PROV_SOCKET_ENV "RPMEM_ENABLE_SOCKETS"
#define RPMEM_PROV_VERBS_ENV "RPMEM_ENABLE_VERBS"
#define RPMEM_MAX_NLANES_ENV "RPMEM_MAX_NLANES"
#define RPMEM_ACCEPT_TIMEOUT 30000
#define RPMEM_CONNECT_TIMEOUT 30000
#define RPMEM_MONITOR_TIMEOUT 1000
#include <stdint.h>
#include <sys/socket.h>
#include <netdb.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* rpmem_err -- error codes
*/
enum rpmem_err {
RPMEM_SUCCESS = 0,
RPMEM_ERR_BADPROTO = 1,
RPMEM_ERR_BADNAME = 2,
RPMEM_ERR_BADSIZE = 3,
RPMEM_ERR_BADNLANES = 4,
RPMEM_ERR_BADPROVIDER = 5,
RPMEM_ERR_FATAL = 6,
RPMEM_ERR_FATAL_CONN = 7,
RPMEM_ERR_BUSY = 8,
RPMEM_ERR_EXISTS = 9,
RPMEM_ERR_PROVNOSUP = 10,
RPMEM_ERR_NOEXIST = 11,
RPMEM_ERR_NOACCESS = 12,
RPMEM_ERR_POOL_CFG = 13,
MAX_RPMEM_ERR,
};
/*
* rpmem_persist_method -- remote persist operation method
*/
enum rpmem_persist_method {
RPMEM_PM_GPSPM = 1, /* General Purpose Server Persistency Method */
RPMEM_PM_APM = 2, /* Appliance Persistency Method */
MAX_RPMEM_PM,
};
const char *rpmem_persist_method_to_str(enum rpmem_persist_method pm);
/*
* rpmem_provider -- supported providers
*/
enum rpmem_provider {
RPMEM_PROV_UNKNOWN = 0,
RPMEM_PROV_LIBFABRIC_VERBS = 1,
RPMEM_PROV_LIBFABRIC_SOCKETS = 2,
MAX_RPMEM_PROV,
};
enum rpmem_provider rpmem_provider_from_str(const char *str);
const char *rpmem_provider_to_str(enum rpmem_provider provider);
/*
* rpmem_req_attr -- arguments for open/create request
*/
struct rpmem_req_attr {
size_t pool_size;
unsigned nlanes;
size_t buff_size;
enum rpmem_provider provider;
const char *pool_desc;
};
/*
* rpmem_resp_attr -- return arguments from open/create request
*/
struct rpmem_resp_attr {
unsigned short port;
uint64_t rkey;
uint64_t raddr;
unsigned nlanes;
enum rpmem_persist_method persist_method;
};
#define RPMEM_HAS_USER 0x1
#define RPMEM_HAS_SERVICE 0x2
#define RPMEM_FLAGS_USE_IPV4 0x4
#define RPMEM_MAX_USER (32 + 1) /* see useradd(8) + 1 for '\0' */
#define RPMEM_MAX_NODE (255 + 1) /* see gethostname(2) + 1 for '\0' */
#define RPMEM_MAX_SERVICE (NI_MAXSERV + 1) /* + 1 for '\0' */
#define RPMEM_HDR_SIZE 4096
#define RPMEM_CLOSE_FLAGS_REMOVE 0x1
#define RPMEM_DEF_BUFF_SIZE 8192
struct rpmem_target_info {
char user[RPMEM_MAX_USER];
char node[RPMEM_MAX_NODE];
char service[RPMEM_MAX_SERVICE];
unsigned flags;
};
extern unsigned Rpmem_max_nlanes;
extern int Rpmem_fork_unsafe;
int rpmem_b64_write(int sockfd, const void *buf, size_t len, int flags);
int rpmem_b64_read(int sockfd, void *buf, size_t len, int flags);
const char *rpmem_get_ip_str(const struct sockaddr *addr);
struct rpmem_target_info *rpmem_target_parse(const char *target);
void rpmem_target_free(struct rpmem_target_info *info);
int rpmem_xwrite(int fd, const void *buf, size_t len, int flags);
int rpmem_xread(int fd, void *buf, size_t len, int flags);
char *rpmem_get_ssh_conn_addr(void);
#ifdef __cplusplus
}
#endif
#endif
| 4,838 | 27.976048 | 74 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/rpmem_common/rpmem_proto.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_proto.h -- rpmem protocol definitions
*/
#ifndef RPMEM_PROTO_H
#define RPMEM_PROTO_H 1
#include <stdint.h>
#include <endian.h>
#include "librpmem.h"
#ifdef __cplusplus
extern "C" {
#endif
#define PACKED __attribute__((packed))
#define RPMEM_PROTO "tcp"
#define RPMEM_PROTO_MAJOR 0
#define RPMEM_PROTO_MINOR 1
#define RPMEM_SIG_SIZE 8
#define RPMEM_UUID_SIZE 16
#define RPMEM_PROV_SIZE 32
#define RPMEM_USER_SIZE 16
/*
* rpmem_msg_type -- type of messages
*/
enum rpmem_msg_type {
RPMEM_MSG_TYPE_CREATE = 1, /* create request */
RPMEM_MSG_TYPE_CREATE_RESP = 2, /* create request response */
RPMEM_MSG_TYPE_OPEN = 3, /* open request */
RPMEM_MSG_TYPE_OPEN_RESP = 4, /* open request response */
RPMEM_MSG_TYPE_CLOSE = 5, /* close request */
RPMEM_MSG_TYPE_CLOSE_RESP = 6, /* close request response */
RPMEM_MSG_TYPE_SET_ATTR = 7, /* set attributes request */
/* set attributes request response */
RPMEM_MSG_TYPE_SET_ATTR_RESP = 8,
MAX_RPMEM_MSG_TYPE,
};
/*
* rpmem_pool_attr_packed -- a packed version
*/
struct rpmem_pool_attr_packed {
char signature[RPMEM_POOL_HDR_SIG_LEN]; /* pool signature */
uint32_t major; /* format major version number */
uint32_t compat_features; /* mask: compatible "may" features */
uint32_t incompat_features; /* mask: "must support" features */
uint32_t ro_compat_features; /* mask: force RO if unsupported */
unsigned char poolset_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* pool uuid */
unsigned char uuid[RPMEM_POOL_HDR_UUID_LEN]; /* first part uuid */
unsigned char next_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* next pool uuid */
unsigned char prev_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* prev pool uuid */
unsigned char user_flags[RPMEM_POOL_USER_FLAGS_LEN]; /* user flags */
} PACKED;
/*
* rpmem_msg_ibc_attr -- in-band connection attributes
*
* Used by create request response and open request response.
* Contains essential information to proceed with in-band connection
* initialization.
*/
struct rpmem_msg_ibc_attr {
uint32_t port; /* RDMA connection port */
uint32_t persist_method; /* persist method */
uint64_t rkey; /* remote key */
uint64_t raddr; /* remote address */
uint32_t nlanes; /* number of lanes */
} PACKED;
/*
* rpmem_msg_pool_desc -- remote pool descriptor
*/
struct rpmem_msg_pool_desc {
uint32_t size; /* size of pool descriptor */
uint8_t desc[0]; /* pool descriptor, null-terminated string */
} PACKED;
/*
* rpmem_msg_hdr -- message header which consists of type and size of message
*
* The type must be one of the rpmem_msg_type values.
*/
struct rpmem_msg_hdr {
uint32_t type; /* type of message */
uint64_t size; /* size of message */
uint8_t body[0];
} PACKED;
/*
* rpmem_msg_hdr_resp -- message response header which consists of type, size
* and status.
*
* The type must be one of the rpmem_msg_type values.
*/
struct rpmem_msg_hdr_resp {
uint32_t status; /* response status */
uint32_t type; /* type of message */
uint64_t size; /* size of message */
} PACKED;
/*
* rpmem_msg_common -- common fields for open/create messages
*/
struct rpmem_msg_common {
uint16_t major; /* protocol version major number */
uint16_t minor; /* protocol version minor number */
uint64_t pool_size; /* minimum required size of a pool */
uint32_t nlanes; /* number of lanes used by initiator */
uint32_t provider; /* provider */
uint64_t buff_size; /* buffer size for inline persist */
} PACKED;
/*
* rpmem_msg_create -- create request message
*
* The type of message must be set to RPMEM_MSG_TYPE_CREATE.
* The size of message must be set to
* sizeof(struct rpmem_msg_create) + pool_desc_size
*/
struct rpmem_msg_create {
struct rpmem_msg_hdr hdr; /* message header */
struct rpmem_msg_common c;
struct rpmem_pool_attr_packed pool_attr; /* pool attributes */
struct rpmem_msg_pool_desc pool_desc; /* pool descriptor */
} PACKED;
/*
* rpmem_msg_create_resp -- create request response message
*
* The type of message must be set to RPMEM_MSG_TYPE_CREATE_RESP.
* The size of message must be set to sizeof(struct rpmem_msg_create_resp).
*/
struct rpmem_msg_create_resp {
struct rpmem_msg_hdr_resp hdr; /* message header */
struct rpmem_msg_ibc_attr ibc; /* in-band connection attributes */
} PACKED;
/*
* rpmem_msg_open -- open request message
*
* The type of message must be set to RPMEM_MSG_TYPE_OPEN.
* The size of message must be set to
* sizeof(struct rpmem_msg_open) + pool_desc_size
*/
struct rpmem_msg_open {
struct rpmem_msg_hdr hdr; /* message header */
struct rpmem_msg_common c;
struct rpmem_msg_pool_desc pool_desc; /* pool descriptor */
} PACKED;
/*
* rpmem_msg_open_resp -- open request response message
*
* The type of message must be set to RPMEM_MSG_TYPE_OPEN_RESP.
* The size of message must be set to sizeof(struct rpmem_msg_open_resp)
*/
struct rpmem_msg_open_resp {
struct rpmem_msg_hdr_resp hdr; /* message header */
struct rpmem_msg_ibc_attr ibc; /* in-band connection attributes */
struct rpmem_pool_attr_packed pool_attr; /* pool attributes */
} PACKED;
/*
* rpmem_msg_close -- close request message
*
* The type of message must be set to RPMEM_MSG_TYPE_CLOSE
* The size of message must be set to sizeof(struct rpmem_msg_close)
*/
struct rpmem_msg_close {
struct rpmem_msg_hdr hdr; /* message header */
uint32_t flags; /* flags */
} PACKED;
/*
* rpmem_msg_close_resp -- close request response message
*
* The type of message must be set to RPMEM_MSG_TYPE_CLOSE_RESP
* The size of message must be set to sizeof(struct rpmem_msg_close_resp)
*/
struct rpmem_msg_close_resp {
struct rpmem_msg_hdr_resp hdr; /* message header */
/* no more fields */
} PACKED;
#define RPMEM_PERSIST_WRITE 0U /* persist using RDMA WRITE */
#define RPMEM_DEEP_PERSIST 1U /* deep persist operation */
#define RPMEM_PERSIST_SEND 2U /* persist using RDMA SEND */
#define RPMEM_PERSIST_MAX 2U /* maximum valid value */
/*
* the two least significant bits
* are reserved for mode of persist
*/
#define RPMEM_PERSIST_MASK 0x3U
/*
* rpmem_msg_persist -- remote persist message
*/
struct rpmem_msg_persist {
uint32_t flags; /* lane flags */
uint32_t lane; /* lane identifier */
uint64_t addr; /* remote memory address */
uint64_t size; /* remote memory size */
uint8_t data[];
};
/*
* rpmem_msg_persist_resp -- remote persist response message
*/
struct rpmem_msg_persist_resp {
uint32_t flags; /* lane flags */
uint32_t lane; /* lane identifier */
};
/*
* rpmem_msg_set_attr -- set attributes request message
*
* The type of message must be set to RPMEM_MSG_TYPE_SET_ATTR.
* The size of message must be set to sizeof(struct rpmem_msg_set_attr)
*/
struct rpmem_msg_set_attr {
struct rpmem_msg_hdr hdr; /* message header */
struct rpmem_pool_attr_packed pool_attr; /* pool attributes */
} PACKED;
/*
* rpmem_msg_set_attr_resp -- set attributes request response message
*
* The type of message must be set to RPMEM_MSG_TYPE_SET_ATTR_RESP.
* The size of message must be set to sizeof(struct rpmem_msg_set_attr_resp).
*/
struct rpmem_msg_set_attr_resp {
struct rpmem_msg_hdr_resp hdr; /* message header */
} PACKED;
/*
* XXX Begin: Suppress gcc conversion warnings for FreeBSD be*toh macros.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
/*
* rpmem_ntoh_msg_ibc_attr -- convert rpmem_msg_ibc attr to host byte order
*/
static inline void
rpmem_ntoh_msg_ibc_attr(struct rpmem_msg_ibc_attr *ibc)
{
ibc->port = be32toh(ibc->port);
ibc->persist_method = be32toh(ibc->persist_method);
ibc->rkey = be64toh(ibc->rkey);
ibc->raddr = be64toh(ibc->raddr);
}
/*
* rpmem_ntoh_msg_pool_desc -- convert rpmem_msg_pool_desc to host byte order
*/
static inline void
rpmem_ntoh_msg_pool_desc(struct rpmem_msg_pool_desc *pool_desc)
{
pool_desc->size = be32toh(pool_desc->size);
}
/*
* rpmem_ntoh_pool_attr -- convert rpmem_pool_attr to host byte order
*/
static inline void
rpmem_ntoh_pool_attr(struct rpmem_pool_attr_packed *attr)
{
attr->major = be32toh(attr->major);
attr->ro_compat_features = be32toh(attr->ro_compat_features);
attr->incompat_features = be32toh(attr->incompat_features);
attr->compat_features = be32toh(attr->compat_features);
}
/*
* rpmem_ntoh_msg_hdr -- convert rpmem_msg_hdr to host byte order
*/
static inline void
rpmem_ntoh_msg_hdr(struct rpmem_msg_hdr *hdrp)
{
hdrp->type = be32toh(hdrp->type);
hdrp->size = be64toh(hdrp->size);
}
/*
* rpmem_hton_msg_hdr -- convert rpmem_msg_hdr to network byte order
*/
static inline void
rpmem_hton_msg_hdr(struct rpmem_msg_hdr *hdrp)
{
rpmem_ntoh_msg_hdr(hdrp);
}
/*
* rpmem_ntoh_msg_hdr_resp -- convert rpmem_msg_hdr_resp to host byte order
*/
static inline void
rpmem_ntoh_msg_hdr_resp(struct rpmem_msg_hdr_resp *hdrp)
{
hdrp->status = be32toh(hdrp->status);
hdrp->type = be32toh(hdrp->type);
hdrp->size = be64toh(hdrp->size);
}
/*
* rpmem_hton_msg_hdr_resp -- convert rpmem_msg_hdr_resp to network byte order
*/
static inline void
rpmem_hton_msg_hdr_resp(struct rpmem_msg_hdr_resp *hdrp)
{
rpmem_ntoh_msg_hdr_resp(hdrp);
}
/*
* rpmem_ntoh_msg_common -- convert rpmem_msg_common to host byte order
*/
static inline void
rpmem_ntoh_msg_common(struct rpmem_msg_common *msg)
{
msg->major = be16toh(msg->major);
msg->minor = be16toh(msg->minor);
msg->pool_size = be64toh(msg->pool_size);
msg->nlanes = be32toh(msg->nlanes);
msg->provider = be32toh(msg->provider);
msg->buff_size = be64toh(msg->buff_size);
}
/*
* rpmem_hton_msg_common -- convert rpmem_msg_common to network byte order
*/
static inline void
rpmem_hton_msg_common(struct rpmem_msg_common *msg)
{
rpmem_ntoh_msg_common(msg);
}
/*
* rpmem_ntoh_msg_create -- convert rpmem_msg_create to host byte order
*/
static inline void
rpmem_ntoh_msg_create(struct rpmem_msg_create *msg)
{
rpmem_ntoh_msg_hdr(&msg->hdr);
rpmem_ntoh_msg_common(&msg->c);
rpmem_ntoh_pool_attr(&msg->pool_attr);
rpmem_ntoh_msg_pool_desc(&msg->pool_desc);
}
/*
* rpmem_hton_msg_create -- convert rpmem_msg_create to network byte order
*/
static inline void
rpmem_hton_msg_create(struct rpmem_msg_create *msg)
{
rpmem_ntoh_msg_create(msg);
}
/*
* rpmem_ntoh_msg_create_resp -- convert rpmem_msg_create_resp to host byte
* order
*/
static inline void
rpmem_ntoh_msg_create_resp(struct rpmem_msg_create_resp *msg)
{
rpmem_ntoh_msg_hdr_resp(&msg->hdr);
rpmem_ntoh_msg_ibc_attr(&msg->ibc);
}
/*
* rpmem_hton_msg_create_resp -- convert rpmem_msg_create_resp to network byte
* order
*/
static inline void
rpmem_hton_msg_create_resp(struct rpmem_msg_create_resp *msg)
{
rpmem_ntoh_msg_create_resp(msg);
}
/*
* rpmem_ntoh_msg_open -- convert rpmem_msg_open to host byte order
*/
static inline void
rpmem_ntoh_msg_open(struct rpmem_msg_open *msg)
{
rpmem_ntoh_msg_hdr(&msg->hdr);
rpmem_ntoh_msg_common(&msg->c);
rpmem_ntoh_msg_pool_desc(&msg->pool_desc);
}
/*
* XXX End: Suppress gcc conversion warnings for FreeBSD be*toh macros
*/
#pragma GCC diagnostic pop
/*
* rpmem_hton_msg_open -- convert rpmem_msg_open to network byte order
*/
static inline void
rpmem_hton_msg_open(struct rpmem_msg_open *msg)
{
rpmem_ntoh_msg_open(msg);
}
/*
* rpmem_ntoh_msg_open_resp -- convert rpmem_msg_open_resp to host byte order
*/
static inline void
rpmem_ntoh_msg_open_resp(struct rpmem_msg_open_resp *msg)
{
rpmem_ntoh_msg_hdr_resp(&msg->hdr);
rpmem_ntoh_msg_ibc_attr(&msg->ibc);
rpmem_ntoh_pool_attr(&msg->pool_attr);
}
/*
* rpmem_hton_msg_open_resp -- convert rpmem_msg_open_resp to network byte order
*/
static inline void
rpmem_hton_msg_open_resp(struct rpmem_msg_open_resp *msg)
{
rpmem_ntoh_msg_open_resp(msg);
}
/*
* rpmem_ntoh_msg_set_attr -- convert rpmem_msg_set_attr to host byte order
*/
static inline void
rpmem_ntoh_msg_set_attr(struct rpmem_msg_set_attr *msg)
{
rpmem_ntoh_msg_hdr(&msg->hdr);
rpmem_ntoh_pool_attr(&msg->pool_attr);
}
/*
* rpmem_hton_msg_set_attr -- convert rpmem_msg_set_attr to network byte order
*/
static inline void
rpmem_hton_msg_set_attr(struct rpmem_msg_set_attr *msg)
{
rpmem_ntoh_msg_set_attr(msg);
}
/*
* rpmem_ntoh_msg_set_attr_resp -- convert rpmem_msg_set_attr_resp to host byte
* order
*/
static inline void
rpmem_ntoh_msg_set_attr_resp(struct rpmem_msg_set_attr_resp *msg)
{
rpmem_ntoh_msg_hdr_resp(&msg->hdr);
}
/*
* rpmem_hton_msg_set_attr_resp -- convert rpmem_msg_set_attr_resp to network
* byte order
*/
static inline void
rpmem_hton_msg_set_attr_resp(struct rpmem_msg_set_attr_resp *msg)
{
rpmem_hton_msg_hdr_resp(&msg->hdr);
}
/*
* rpmem_ntoh_msg_close -- convert rpmem_msg_close to host byte order
*/
static inline void
rpmem_ntoh_msg_close(struct rpmem_msg_close *msg)
{
rpmem_ntoh_msg_hdr(&msg->hdr);
}
/*
* rpmem_hton_msg_close -- convert rpmem_msg_close to network byte order
*/
static inline void
rpmem_hton_msg_close(struct rpmem_msg_close *msg)
{
rpmem_ntoh_msg_close(msg);
}
/*
* rpmem_ntoh_msg_close_resp -- convert rpmem_msg_close_resp to host byte order
*/
static inline void
rpmem_ntoh_msg_close_resp(struct rpmem_msg_close_resp *msg)
{
rpmem_ntoh_msg_hdr_resp(&msg->hdr);
}
/*
* rpmem_hton_msg_close_resp -- convert rpmem_msg_close_resp to network byte
* order
*/
static inline void
rpmem_hton_msg_close_resp(struct rpmem_msg_close_resp *msg)
{
rpmem_ntoh_msg_close_resp(msg);
}
/*
* pack_rpmem_pool_attr -- copy pool attributes to a packed structure
*/
static inline void
pack_rpmem_pool_attr(const struct rpmem_pool_attr *src,
struct rpmem_pool_attr_packed *dst)
{
memcpy(dst->signature, src->signature, sizeof(src->signature));
dst->major = src->major;
dst->compat_features = src->compat_features;
dst->incompat_features = src->incompat_features;
dst->ro_compat_features = src->ro_compat_features;
memcpy(dst->poolset_uuid, src->poolset_uuid, sizeof(dst->poolset_uuid));
memcpy(dst->uuid, src->uuid, sizeof(dst->uuid));
memcpy(dst->next_uuid, src->next_uuid, sizeof(dst->next_uuid));
memcpy(dst->prev_uuid, src->prev_uuid, sizeof(dst->prev_uuid));
memcpy(dst->user_flags, src->user_flags, sizeof(dst->user_flags));
}
/*
* unpack_rpmem_pool_attr -- copy pool attributes to an unpacked structure
*/
static inline void
unpack_rpmem_pool_attr(const struct rpmem_pool_attr_packed *src,
struct rpmem_pool_attr *dst)
{
memcpy(dst->signature, src->signature, sizeof(src->signature));
dst->major = src->major;
dst->compat_features = src->compat_features;
dst->incompat_features = src->incompat_features;
dst->ro_compat_features = src->ro_compat_features;
memcpy(dst->poolset_uuid, src->poolset_uuid, sizeof(dst->poolset_uuid));
memcpy(dst->uuid, src->uuid, sizeof(dst->uuid));
memcpy(dst->next_uuid, src->next_uuid, sizeof(dst->next_uuid));
memcpy(dst->prev_uuid, src->prev_uuid, sizeof(dst->prev_uuid));
memcpy(dst->user_flags, src->user_flags, sizeof(dst->user_flags));
}
#ifdef __cplusplus
}
#endif
#endif
| 16,448 | 27.507799 | 80 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/rpmem_common/rpmem_common.c
|
/*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_common.c -- common definitions for librpmem and rpmemd
*/
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include "rpmem_common.h"
#include "rpmem_proto.h"
#include "rpmem_common_log.h"
#include "os.h"
unsigned Rpmem_max_nlanes = UINT_MAX;
/*
* If set, indicates libfabric does not support fork() and consecutive calls to
* rpmem_create/rpmem_open must fail.
*/
int Rpmem_fork_unsafe;
/*
* rpmem_xwrite -- send entire buffer or fail
*
* Returns 1 if send returned 0.
*/
int
rpmem_xwrite(int fd, const void *buf, size_t len, int flags)
{
size_t wr = 0;
const uint8_t *cbuf = buf;
while (wr < len) {
ssize_t sret;
if (!flags)
sret = write(fd, &cbuf[wr], len - wr);
else
sret = send(fd, &cbuf[wr], len - wr, flags);
if (sret == 0)
return 1;
if (sret < 0)
return (int)sret;
wr += (size_t)sret;
}
return 0;
}
/*
* rpmem_xread -- read entire buffer or fail
*
* Returns 1 if recv returned 0.
*/
int
rpmem_xread(int fd, void *buf, size_t len, int flags)
{
size_t rd = 0;
uint8_t *cbuf = buf;
while (rd < len) {
ssize_t sret;
if (!flags)
sret = read(fd, &cbuf[rd], len - rd);
else
sret = recv(fd, &cbuf[rd], len - rd, flags);
if (sret == 0) {
RPMEMC_DBG(ERR, "recv/read returned 0");
return 1;
}
if (sret < 0)
return (int)sret;
rd += (size_t)sret;
}
return 0;
}
static const char *pm2str[MAX_RPMEM_PM] = {
[RPMEM_PM_APM] = "Appliance Persistency Method",
[RPMEM_PM_GPSPM] = "General Purpose Server Persistency Method",
};
/*
* rpmem_persist_method_to_str -- convert enum rpmem_persist_method to string
*/
const char *
rpmem_persist_method_to_str(enum rpmem_persist_method pm)
{
if (pm >= MAX_RPMEM_PM)
return NULL;
return pm2str[pm];
}
static const char *provider2str[MAX_RPMEM_PROV] = {
[RPMEM_PROV_LIBFABRIC_VERBS] = "verbs",
[RPMEM_PROV_LIBFABRIC_SOCKETS] = "sockets",
};
/*
* rpmem_provider_from_str -- convert string to enum rpmem_provider
*
* Returns RPMEM_PROV_UNKNOWN if provider is not known.
*/
enum rpmem_provider
rpmem_provider_from_str(const char *str)
{
for (enum rpmem_provider p = 0; p < MAX_RPMEM_PROV; p++) {
if (provider2str[p] && strcmp(str, provider2str[p]) == 0)
return p;
}
return RPMEM_PROV_UNKNOWN;
}
/*
* rpmem_provider_to_str -- convert enum rpmem_provider to string
*/
const char *
rpmem_provider_to_str(enum rpmem_provider provider)
{
if (provider >= MAX_RPMEM_PROV)
return NULL;
return provider2str[provider];
}
/*
* rpmem_get_ip_str -- converts socket address to string
*/
const char *
rpmem_get_ip_str(const struct sockaddr *addr)
{
static char str[INET6_ADDRSTRLEN + NI_MAXSERV + 1];
char ip[INET6_ADDRSTRLEN];
struct sockaddr_in *in4;
struct sockaddr_in6 *in6;
switch (addr->sa_family) {
case AF_INET:
in4 = (struct sockaddr_in *)addr;
if (!inet_ntop(AF_INET, &in4->sin_addr, ip, sizeof(ip)))
return NULL;
if (snprintf(str, sizeof(str), "%s:%u",
ip, ntohs(in4->sin_port)) < 0)
return NULL;
break;
case AF_INET6:
in6 = (struct sockaddr_in6 *)addr;
if (!inet_ntop(AF_INET6, &in6->sin6_addr, ip, sizeof(ip)))
return NULL;
if (snprintf(str, sizeof(str), "%s:%u",
ip, ntohs(in6->sin6_port)) < 0)
return NULL;
break;
default:
return NULL;
}
return str;
}
/*
* rpmem_target_parse -- parse target info
*/
struct rpmem_target_info *
rpmem_target_parse(const char *target)
{
struct rpmem_target_info *info = calloc(1, sizeof(*info));
if (!info)
return NULL;
char *str = strdup(target);
if (!str)
goto err_strdup;
char *tmp = strchr(str, '@');
if (tmp) {
*tmp = '\0';
info->flags |= RPMEM_HAS_USER;
strncpy(info->user, str, sizeof(info->user) - 1);
tmp++;
} else {
tmp = str;
}
if (*tmp == '[') {
tmp++;
/* IPv6 */
char *end = strchr(tmp, ']');
if (!end) {
errno = EINVAL;
goto err_ipv6;
}
*end = '\0';
strncpy(info->node, tmp, sizeof(info->node) - 1);
tmp = end + 1;
end = strchr(tmp, ':');
if (end) {
*end = '\0';
end++;
info->flags |= RPMEM_HAS_SERVICE;
strncpy(info->service, end, sizeof(info->service) - 1);
}
} else {
char *first = strchr(tmp, ':');
char *last = strrchr(tmp, ':');
if (first == last) {
/* IPv4 - one colon */
if (first) {
*first = '\0';
first++;
info->flags |= RPMEM_HAS_SERVICE;
strncpy(info->service, first,
sizeof(info->service) - 1);
}
}
strncpy(info->node, tmp, sizeof(info->node) - 1);
}
if (*info->node == '\0') {
errno = EINVAL;
goto err_node;
}
free(str);
/* make sure that user, node and service are NULL-terminated */
info->user[sizeof(info->user) - 1] = '\0';
info->node[sizeof(info->node) - 1] = '\0';
info->service[sizeof(info->service) - 1] = '\0';
return info;
err_node:
err_ipv6:
free(str);
err_strdup:
free(info);
return NULL;
}
/*
* rpmem_target_free -- free target info
*/
void
rpmem_target_free(struct rpmem_target_info *info)
{
free(info);
}
/*
* rpmem_get_ssh_conn_addr -- returns an address which the ssh connection is
* established on
*
* This function utilizes the SSH_CONNECTION environment variable to retrieve
* the server IP address. See ssh(1) for details.
*/
char *
rpmem_get_ssh_conn_addr(void)
{
char *ssh_conn = os_getenv("SSH_CONNECTION");
if (!ssh_conn) {
RPMEMC_LOG(ERR, "SSH_CONNECTION variable is not set");
return NULL;
}
char *sp = strchr(ssh_conn, ' ');
if (!sp)
goto err_fmt;
char *addr = strchr(sp + 1, ' ');
if (!addr)
goto err_fmt;
addr++;
sp = strchr(addr, ' ');
if (!sp)
goto err_fmt;
*sp = '\0';
return addr;
err_fmt:
RPMEMC_LOG(ERR, "invalid format of SSH_CONNECTION variable");
return NULL;
}
| 7,456 | 21.127596 | 79 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/rpmem_common/rpmem_fip_lane.h
|
/*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_fip_lane.h -- rpmem fabric provider lane definition
*/
#include <sched.h>
#include <stdint.h>
#include "sys_util.h"
/*
* rpmem_fip_lane -- basic lane structure
*
* This structure consist of a synchronization object and a return value.
* It is possible to wait on the lane for specified event. The event can be
* signalled by another thread which can pass the return value if required.
*
* The sync variable can store up to 64 different events, each event on
* separate bit.
*/
struct rpmem_fip_lane {
os_spinlock_t lock;
int ret;
uint64_t sync;
};
/*
* rpmem_fip_lane_init -- initialize basic lane structure
*/
static inline int
rpmem_fip_lane_init(struct rpmem_fip_lane *lanep)
{
lanep->ret = 0;
lanep->sync = 0;
return util_spin_init(&lanep->lock, PTHREAD_PROCESS_PRIVATE);
}
/*
* rpmem_fip_lane_fini -- deinitialize basic lane structure
*/
static inline void
rpmem_fip_lane_fini(struct rpmem_fip_lane *lanep)
{
util_spin_destroy(&lanep->lock);
}
/*
* rpmem_fip_lane_busy -- return true if lane has pending events
*/
static inline int
rpmem_fip_lane_busy(struct rpmem_fip_lane *lanep)
{
util_spin_lock(&lanep->lock);
int ret = lanep->sync != 0;
util_spin_unlock(&lanep->lock);
return ret;
}
/*
* rpmem_fip_lane_begin -- begin waiting for specified event(s)
*/
static inline void
rpmem_fip_lane_begin(struct rpmem_fip_lane *lanep, uint64_t sig)
{
util_spin_lock(&lanep->lock);
lanep->ret = 0;
lanep->sync |= sig;
util_spin_unlock(&lanep->lock);
}
static inline int
rpmem_fip_lane_is_busy(struct rpmem_fip_lane *lanep, uint64_t sig)
{
util_spin_lock(&lanep->lock);
int ret = (lanep->sync & sig) != 0;
util_spin_unlock(&lanep->lock);
return ret;
}
static inline int
rpmem_fip_lane_ret(struct rpmem_fip_lane *lanep)
{
util_spin_lock(&lanep->lock);
int ret = lanep->ret;
util_spin_unlock(&lanep->lock);
return ret;
}
/*
* rpmem_fip_lane_wait -- wait for specified event(s)
*/
static inline int
rpmem_fip_lane_wait(struct rpmem_fip_lane *lanep, uint64_t sig)
{
while (rpmem_fip_lane_is_busy(lanep, sig))
sched_yield();
return rpmem_fip_lane_ret(lanep);
}
/*
* rpmem_fip_lane_signal -- signal lane about specified event
*/
static inline void
rpmem_fip_lane_signal(struct rpmem_fip_lane *lanep, uint64_t sig)
{
util_spin_lock(&lanep->lock);
lanep->sync &= ~sig;
util_spin_unlock(&lanep->lock);
}
/*
* rpmem_fip_lane_signal -- signal lane about specified event and store
* return value
*/
static inline void
rpmem_fip_lane_sigret(struct rpmem_fip_lane *lanep, uint64_t sig, int ret)
{
util_spin_lock(&lanep->lock);
lanep->ret = ret;
lanep->sync &= ~sig;
util_spin_unlock(&lanep->lock);
}
| 4,269 | 26.197452 | 75 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/rpmem_common/rpmem_fip_msg.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_fip_msg.h -- simple wrappers for fi_rma(3) and fi_msg(3) functions
*/
#ifndef RPMEM_FIP_MSG_H
#define RPMEM_FIP_MSG_H 1
#include <rdma/fi_rma.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* rpmem_fip_rma -- helper struct for RMA operation
*/
struct rpmem_fip_rma {
struct fi_msg_rma msg; /* message structure */
struct iovec msg_iov; /* IO vector buffer */
struct fi_rma_iov rma_iov; /* RMA IO vector buffer */
void *desc; /* local memory descriptor */
uint64_t flags; /* RMA operation flags */
};
/*
* rpmem_fip_msg -- helper struct for MSG operation
*/
struct rpmem_fip_msg {
struct fi_msg msg; /* message structure */
struct iovec iov; /* IO vector buffer */
void *desc; /* local memory descriptor */
uint64_t flags; /* MSG operation flags */
};
/*
* rpmem_fip_rma_init -- initialize RMA helper struct
*/
static inline void
rpmem_fip_rma_init(struct rpmem_fip_rma *rma, void *desc,
fi_addr_t addr, uint64_t rkey, void *context, uint64_t flags)
{
memset(rma, 0, sizeof(*rma));
rma->desc = desc;
rma->flags = flags;
rma->rma_iov.key = rkey;
rma->msg.context = context;
rma->msg.addr = addr;
rma->msg.desc = &rma->desc;
rma->msg.rma_iov = &rma->rma_iov;
rma->msg.rma_iov_count = 1;
rma->msg.msg_iov = &rma->msg_iov;
rma->msg.iov_count = 1;
}
/*
* rpmem_fip_msg_init -- initialize MSG helper struct
*/
static inline void
rpmem_fip_msg_init(struct rpmem_fip_msg *msg, void *desc, fi_addr_t addr,
void *context, void *buff, size_t len, uint64_t flags)
{
memset(msg, 0, sizeof(*msg));
msg->desc = desc;
msg->flags = flags;
msg->iov.iov_base = buff;
msg->iov.iov_len = len;
msg->msg.context = context;
msg->msg.addr = addr;
msg->msg.desc = &msg->desc;
msg->msg.msg_iov = &msg->iov;
msg->msg.iov_count = 1;
}
/*
* rpmem_fip_writemsg -- wrapper for fi_writemsg
*/
static inline int
rpmem_fip_writemsg(struct fid_ep *ep, struct rpmem_fip_rma *rma,
const void *buff, size_t len, uint64_t addr)
{
rma->rma_iov.addr = addr;
rma->rma_iov.len = len;
rma->msg_iov.iov_base = (void *)buff;
rma->msg_iov.iov_len = len;
return (int)fi_writemsg(ep, &rma->msg, rma->flags);
}
/*
* rpmem_fip_readmsg -- wrapper for fi_readmsg
*/
static inline int
rpmem_fip_readmsg(struct fid_ep *ep, struct rpmem_fip_rma *rma,
void *buff, size_t len, uint64_t addr)
{
rma->rma_iov.addr = addr;
rma->rma_iov.len = len;
rma->msg_iov.iov_base = buff;
rma->msg_iov.iov_len = len;
return (int)fi_readmsg(ep, &rma->msg, rma->flags);
}
/*
* rpmem_fip_sendmsg -- wrapper for fi_sendmsg
*/
static inline int
rpmem_fip_sendmsg(struct fid_ep *ep, struct rpmem_fip_msg *msg, size_t len)
{
msg->iov.iov_len = len;
return (int)fi_sendmsg(ep, &msg->msg, msg->flags);
}
/*
* rpmem_fip_recvmsg -- wrapper for fi_recvmsg
*/
static inline int
rpmem_fip_recvmsg(struct fid_ep *ep, struct rpmem_fip_msg *msg)
{
return (int)fi_recvmsg(ep, &msg->msg, msg->flags);
}
/*
* rpmem_fip_msg_get_pmsg -- returns message buffer as a persist message
*/
static inline struct rpmem_msg_persist *
rpmem_fip_msg_get_pmsg(struct rpmem_fip_msg *msg)
{
return (struct rpmem_msg_persist *)msg->iov.iov_base;
}
/*
* rpmem_fip_msg_get_pres -- returns message buffer as a persist response
*/
static inline struct rpmem_msg_persist_resp *
rpmem_fip_msg_get_pres(struct rpmem_fip_msg *msg)
{
return (struct rpmem_msg_persist_resp *)msg->iov.iov_base;
}
#ifdef __cplusplus
}
#endif
#endif
| 5,009 | 27.465909 | 75 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/libpmempool.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmempool.c -- entry points for libpmempool
*/
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <sys/param.h>
#include "pmemcommon.h"
#include "libpmempool.h"
#include "pmempool.h"
#include "pool.h"
#include "check.h"
#ifdef USE_RPMEM
#include "rpmem_common.h"
#include "rpmem_util.h"
#endif
#ifdef _WIN32
#define ANSWER_BUFFSIZE 256
#endif
/*
* libpmempool_init -- load-time initialization for libpmempool
*
* Called automatically by the run-time loader.
*/
ATTR_CONSTRUCTOR
void
libpmempool_init(void)
{
common_init(PMEMPOOL_LOG_PREFIX, PMEMPOOL_LOG_LEVEL_VAR,
PMEMPOOL_LOG_FILE_VAR, PMEMPOOL_MAJOR_VERSION,
PMEMPOOL_MINOR_VERSION);
LOG(3, NULL);
#ifdef USE_RPMEM
util_remote_init();
rpmem_util_cmds_init();
#endif
}
/*
* libpmempool_fini -- libpmempool cleanup routine
*
* Called automatically when the process terminates.
*/
ATTR_DESTRUCTOR
void
libpmempool_fini(void)
{
LOG(3, NULL);
#ifdef USE_RPMEM
util_remote_unload();
util_remote_fini();
rpmem_util_cmds_fini();
#endif
common_fini();
}
/*
* pmempool_check_versionU -- see if library meets application version
* requirements
*/
#ifndef _WIN32
static inline
#endif
const char *
pmempool_check_versionU(unsigned major_required, unsigned minor_required)
{
LOG(3, "major_required %u minor_required %u",
major_required, minor_required);
if (major_required != PMEMPOOL_MAJOR_VERSION) {
ERR("libpmempool major version mismatch (need %u, found %u)",
major_required, PMEMPOOL_MAJOR_VERSION);
return out_get_errormsg();
}
if (minor_required > PMEMPOOL_MINOR_VERSION) {
ERR("libpmempool minor version mismatch (need %u, found %u)",
minor_required, PMEMPOOL_MINOR_VERSION);
return out_get_errormsg();
}
return NULL;
}
#ifndef _WIN32
/*
* pmempool_check_version -- see if lib meets application version requirements
*/
const char *
pmempool_check_version(unsigned major_required, unsigned minor_required)
{
return pmempool_check_versionU(major_required, minor_required);
}
#else
/*
* pmempool_check_versionW -- see if library meets application version
* requirements as widechar
*/
const wchar_t *
pmempool_check_versionW(unsigned major_required, unsigned minor_required)
{
if (pmempool_check_versionU(major_required, minor_required) != NULL)
return out_get_errormsgW();
else
return NULL;
}
#endif
/*
* pmempool_errormsgU -- return last error message
*/
#ifndef _WIN32
static inline
#endif
const char *
pmempool_errormsgU(void)
{
return out_get_errormsg();
}
#ifndef _WIN32
/*
* pmempool_errormsg -- return last error message
*/
const char *
pmempool_errormsg(void)
{
return pmempool_errormsgU();
}
#else
/*
* pmempool_errormsgW -- return last error message as widechar
*/
const wchar_t *
pmempool_errormsgW(void)
{
return out_get_errormsgW();
}
#endif
/*
* pmempool_ppc_set_default -- (internal) set default values of check context
*/
static void
pmempool_ppc_set_default(PMEMpoolcheck *ppc)
{
/* all other fields should be zeroed */
const PMEMpoolcheck ppc_default = {
.args = {
.pool_type = PMEMPOOL_POOL_TYPE_DETECT,
},
.result = CHECK_RESULT_CONSISTENT,
};
*ppc = ppc_default;
}
/*
* pmempool_check_initU -- initialize check context
*/
#ifndef _WIN32
static inline
#endif
PMEMpoolcheck *
pmempool_check_initU(struct pmempool_check_argsU *args, size_t args_size)
{
LOG(3, "path %s backup_path %s pool_type %u flags %x", args->path,
args->backup_path, args->pool_type, args->flags);
/*
* Currently one size of args structure is supported. The version of the
* pmempool_check_args structure can be distinguished based on provided
* args_size.
*/
if (args_size < sizeof(struct pmempool_check_args)) {
ERR("provided args_size is not supported");
errno = EINVAL;
return NULL;
}
/*
* Dry run does not allow to made changes possibly performed during
* repair. Advanced allow to perform more complex repairs. Questions
* are ask only if repairs are made. So dry run, advanced and always_yes
* can be set only if repair is set.
*/
if (util_flag_isclr(args->flags, PMEMPOOL_CHECK_REPAIR) &&
util_flag_isset(args->flags, PMEMPOOL_CHECK_DRY_RUN |
PMEMPOOL_CHECK_ADVANCED | PMEMPOOL_CHECK_ALWAYS_YES)) {
ERR("dry_run, advanced and always_yes are applicable only if "
"repair is set");
errno = EINVAL;
return NULL;
}
/*
* dry run does not modify anything so performing backup is redundant
*/
if (util_flag_isset(args->flags, PMEMPOOL_CHECK_DRY_RUN) &&
args->backup_path != NULL) {
ERR("dry run does not allow one to perform backup");
errno = EINVAL;
return NULL;
}
/*
* libpmempool uses str format of communication so it must be set
*/
if (util_flag_isclr(args->flags, PMEMPOOL_CHECK_FORMAT_STR)) {
ERR("PMEMPOOL_CHECK_FORMAT_STR flag must be set");
errno = EINVAL;
return NULL;
}
PMEMpoolcheck *ppc = calloc(1, sizeof(*ppc));
if (ppc == NULL) {
ERR("!calloc");
return NULL;
}
pmempool_ppc_set_default(ppc);
memcpy(&ppc->args, args, sizeof(ppc->args));
ppc->path = strdup(args->path);
if (!ppc->path) {
ERR("!strdup");
goto error_path_malloc;
}
ppc->args.path = ppc->path;
if (args->backup_path != NULL) {
ppc->backup_path = strdup(args->backup_path);
if (!ppc->backup_path) {
ERR("!strdup");
goto error_backup_path_malloc;
}
ppc->args.backup_path = ppc->backup_path;
}
if (check_init(ppc) != 0)
goto error_check_init;
return ppc;
error_check_init:
/* in case errno not set by any of the used functions set its value */
if (errno == 0)
errno = EINVAL;
free(ppc->backup_path);
error_backup_path_malloc:
free(ppc->path);
error_path_malloc:
free(ppc);
return NULL;
}
#ifndef _WIN32
/*
* pmempool_check_init -- initialize check context
*/
PMEMpoolcheck *
pmempool_check_init(struct pmempool_check_args *args, size_t args_size)
{
return pmempool_check_initU(args, args_size);
}
#else
/*
* pmempool_check_initW -- initialize check context as widechar
*/
PMEMpoolcheck *
pmempool_check_initW(struct pmempool_check_argsW *args, size_t args_size)
{
char *upath = util_toUTF8(args->path);
if (upath == NULL)
return NULL;
char *ubackup_path = NULL;
if (args->backup_path != NULL) {
ubackup_path = util_toUTF8(args->backup_path);
if (ubackup_path == NULL) {
util_free_UTF8(upath);
return NULL;
}
}
struct pmempool_check_argsU uargs = {
.path = upath,
.backup_path = ubackup_path,
.pool_type = args->pool_type,
.flags = args->flags
};
PMEMpoolcheck *ret = pmempool_check_initU(&uargs, args_size);
util_free_UTF8(ubackup_path);
util_free_UTF8(upath);
return ret;
}
#endif
/*
* pmempool_checkU -- continue check till produce status to consume for caller
*/
#ifndef _WIN32
static inline
#endif
struct pmempool_check_statusU *
pmempool_checkU(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
ASSERTne(ppc, NULL);
struct check_status *result;
do {
result = check_step(ppc);
if (check_is_end(ppc->data) && result == NULL)
return NULL;
} while (result == NULL);
return check_status_get(result);
}
#ifndef _WIN32
/*
* pmempool_check -- continue check till produce status to consume for caller
*/
struct pmempool_check_status *
pmempool_check(PMEMpoolcheck *ppc)
{
return pmempool_checkU(ppc);
}
#else
/*
* pmempool_checkW -- continue check till produce status to consume for caller
*/
struct pmempool_check_statusW *
pmempool_checkW(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
ASSERTne(ppc, NULL);
/* check the cache and convert msg and answer */
char buf[ANSWER_BUFFSIZE];
memset(buf, 0, ANSWER_BUFFSIZE);
convert_status_cache(ppc, buf, ANSWER_BUFFSIZE);
struct check_status *uresult;
do {
uresult = check_step(ppc);
if (check_is_end(ppc->data) && uresult == NULL)
return NULL;
} while (uresult == NULL);
struct pmempool_check_statusU *uret_res = check_status_get(uresult);
const wchar_t *wmsg = util_toUTF16(uret_res->str.msg);
if (wmsg == NULL)
FATAL("!malloc");
struct pmempool_check_statusW *wret_res =
(struct pmempool_check_statusW *)uret_res;
/* pointer to old message is freed in next check step */
wret_res->str.msg = wmsg;
return wret_res;
}
#endif
/*
* pmempool_check_end -- end check and release check context
*/
enum pmempool_check_result
pmempool_check_end(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
const enum check_result result = ppc->result;
const unsigned sync_required = ppc->sync_required;
check_fini(ppc);
free(ppc->path);
free(ppc->backup_path);
free(ppc);
if (sync_required) {
switch (result) {
case CHECK_RESULT_CONSISTENT:
case CHECK_RESULT_REPAIRED:
return PMEMPOOL_CHECK_RESULT_SYNC_REQ;
default:
/* other results require fixing prior to sync */
;
}
}
switch (result) {
case CHECK_RESULT_CONSISTENT:
return PMEMPOOL_CHECK_RESULT_CONSISTENT;
case CHECK_RESULT_NOT_CONSISTENT:
return PMEMPOOL_CHECK_RESULT_NOT_CONSISTENT;
case CHECK_RESULT_REPAIRED:
return PMEMPOOL_CHECK_RESULT_REPAIRED;
case CHECK_RESULT_CANNOT_REPAIR:
return PMEMPOOL_CHECK_RESULT_CANNOT_REPAIR;
default:
return PMEMPOOL_CHECK_RESULT_ERROR;
}
}
| 10,657 | 22.8434 | 78 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/replica.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* replica.h -- module for synchronizing and transforming poolset
*/
#ifndef REPLICA_H
#define REPLICA_H
#include "libpmempool.h"
#include "pool.h"
#include "os_badblock.h"
#ifdef __cplusplus
extern "C" {
#endif
#define UNDEF_REPLICA UINT_MAX
#define UNDEF_PART UINT_MAX
/*
* A part marked as broken does not exist or is damaged so that
* it cannot be opened and has to be recreated.
*/
#define IS_BROKEN (1U << 0)
/*
* A replica marked as inconsistent exists but has inconsistent metadata
* (e.g. inconsistent parts or replicas linkage)
*/
#define IS_INCONSISTENT (1U << 1)
/*
* A part or replica marked in this way has bad blocks inside.
*/
#define HAS_BAD_BLOCKS (1U << 2)
/*
* A part marked in this way has bad blocks in the header
*/
#define HAS_CORRUPTED_HEADER (1U << 3)
/*
* A flag which can be passed to sync_replica() to indicate that the function is
* called by pmempool_transform
*/
#define IS_TRANSFORMED (1U << 10)
/*
* Number of lanes utilized when working with remote replicas
*/
#define REMOTE_NLANES 1
/*
* Helping structures for storing part's health status
*/
struct part_health_status {
unsigned flags;
struct badblocks bbs; /* structure with bad blocks */
char *recovery_file_name; /* name of bad block recovery file */
int recovery_file_exists; /* bad block recovery file exists */
};
/*
* Helping structures for storing replica and poolset's health status
*/
struct replica_health_status {
unsigned nparts;
unsigned nhdrs;
/* a flag for the replica */
unsigned flags;
/* effective size of a pool, valid only for healthy replica */
size_t pool_size;
/* flags for each part */
struct part_health_status part[];
};
struct poolset_health_status {
unsigned nreplicas;
/* a flag for the poolset */
unsigned flags;
/* health statuses for each replica */
struct replica_health_status *replica[];
};
/* get index of the (r)th replica health status */
static inline unsigned
REP_HEALTHidx(struct poolset_health_status *set, unsigned r)
{
ASSERTne(set->nreplicas, 0);
return (set->nreplicas + r) % set->nreplicas;
}
/* get index of the (r + 1)th replica health status */
static inline unsigned
REPN_HEALTHidx(struct poolset_health_status *set, unsigned r)
{
ASSERTne(set->nreplicas, 0);
return (set->nreplicas + r + 1) % set->nreplicas;
}
/* get (p)th part health status */
static inline unsigned
PART_HEALTHidx(struct replica_health_status *rep, unsigned p)
{
ASSERTne(rep->nparts, 0);
return (rep->nparts + p) % rep->nparts;
}
/* get (r)th replica health status */
static inline struct replica_health_status *
REP_HEALTH(struct poolset_health_status *set, unsigned r)
{
return set->replica[REP_HEALTHidx(set, r)];
}
/* get (p)th part health status */
static inline unsigned
PART_HEALTH(struct replica_health_status *rep, unsigned p)
{
return rep->part[PART_HEALTHidx(rep, p)].flags;
}
uint64_t replica_get_part_offset(struct pool_set *set,
unsigned repn, unsigned partn);
void replica_align_badblock_offset_length(size_t *offset, size_t *length,
struct pool_set *set_in, unsigned repn, unsigned partn);
size_t replica_get_part_data_len(struct pool_set *set_in, unsigned repn,
unsigned partn);
uint64_t replica_get_part_data_offset(struct pool_set *set_in, unsigned repn,
unsigned part);
/*
* is_dry_run -- (internal) check whether only verification mode is enabled
*/
static inline bool
is_dry_run(unsigned flags)
{
/*
* PMEMPOOL_SYNC_DRY_RUN and PMEMPOOL_TRANSFORM_DRY_RUN
* have to have the same value in order to use this common function.
*/
ASSERT_COMPILE_ERROR_ON(PMEMPOOL_SYNC_DRY_RUN !=
PMEMPOOL_TRANSFORM_DRY_RUN);
return flags & PMEMPOOL_SYNC_DRY_RUN;
}
/*
* fix_bad_blocks -- (internal) fix bad blocks - it causes reading or creating
* bad blocks recovery files
* (depending on if they exist or not)
*/
static inline bool
fix_bad_blocks(unsigned flags)
{
return flags & PMEMPOOL_SYNC_FIX_BAD_BLOCKS;
}
int replica_remove_all_recovery_files(struct poolset_health_status *set_hs);
int replica_remove_part(struct pool_set *set, unsigned repn, unsigned partn,
int fix_bad_blocks);
int replica_create_poolset_health_status(struct pool_set *set,
struct poolset_health_status **set_hsp);
void replica_free_poolset_health_status(struct poolset_health_status *set_s);
int replica_check_poolset_health(struct pool_set *set,
struct poolset_health_status **set_hs,
int called_from_sync, unsigned flags);
int replica_is_part_broken(unsigned repn, unsigned partn,
struct poolset_health_status *set_hs);
int replica_has_bad_blocks(unsigned repn, struct poolset_health_status *set_hs);
int replica_part_has_bad_blocks(struct part_health_status *phs);
int replica_part_has_corrupted_header(unsigned repn, unsigned partn,
struct poolset_health_status *set_hs);
unsigned replica_find_unbroken_part(unsigned repn,
struct poolset_health_status *set_hs);
int replica_is_replica_broken(unsigned repn,
struct poolset_health_status *set_hs);
int replica_is_replica_consistent(unsigned repn,
struct poolset_health_status *set_hs);
int replica_is_replica_healthy(unsigned repn,
struct poolset_health_status *set_hs);
unsigned replica_find_healthy_replica(
struct poolset_health_status *set_hs);
unsigned replica_find_replica_healthy_header(
struct poolset_health_status *set_hs);
int replica_is_poolset_healthy(struct poolset_health_status *set_hs);
int replica_is_poolset_transformed(unsigned flags);
ssize_t replica_get_pool_size(struct pool_set *set, unsigned repn);
int replica_check_part_sizes(struct pool_set *set, size_t min_size);
int replica_check_part_dirs(struct pool_set *set);
int replica_check_local_part_dir(struct pool_set *set, unsigned repn,
unsigned partn);
int replica_open_replica_part_files(struct pool_set *set, unsigned repn);
int replica_open_poolset_part_files(struct pool_set *set);
int replica_sync(struct pool_set *set_in, struct poolset_health_status *set_hs,
unsigned flags);
int replica_transform(struct pool_set *set_in, struct pool_set *set_out,
unsigned flags);
#ifdef __cplusplus
}
#endif
#endif
| 7,734 | 30.96281 | 80 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/check.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check.h -- internal definitions for logic performing check
*/
#ifndef CHECK_H
#define CHECK_H
#ifdef __cplusplus
extern "C" {
#endif
int check_init(PMEMpoolcheck *ppc);
struct check_status *check_step(PMEMpoolcheck *ppc);
void check_fini(PMEMpoolcheck *ppc);
int check_is_end(struct check_data *data);
struct pmempool_check_status *check_status_get(struct check_status *status);
#ifdef _WIN32
void convert_status_cache(PMEMpoolcheck *ppc, char *buf, size_t size);
#endif
#ifdef __cplusplus
}
#endif
#endif
| 2,122 | 34.383333 | 76 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/check_blk.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check_blk.c -- check pmemblk
*/
#include <inttypes.h>
#include <sys/param.h>
#include <endian.h>
#include "out.h"
#include "btt.h"
#include "libpmempool.h"
#include "pmempool.h"
#include "pool.h"
#include "check_util.h"
enum question {
Q_BLK_BSIZE,
};
/*
* blk_get_max_bsize -- (internal) return maximum size of block for given file
* size
*/
static inline uint32_t
blk_get_max_bsize(uint64_t fsize)
{
LOG(3, NULL);
if (fsize == 0)
return 0;
/* default nfree */
uint32_t nfree = BTT_DEFAULT_NFREE;
/* number of blocks must be at least 2 * nfree */
uint32_t internal_nlba = 2 * nfree;
/* compute arena size from file size without pmemblk structure */
uint64_t arena_size = fsize - sizeof(struct pmemblk);
if (arena_size > BTT_MAX_ARENA)
arena_size = BTT_MAX_ARENA;
arena_size = btt_arena_datasize(arena_size, nfree);
/* compute maximum internal LBA size */
uint64_t internal_lbasize = (arena_size - BTT_ALIGNMENT) /
internal_nlba - BTT_MAP_ENTRY_SIZE;
ASSERT(internal_lbasize <= UINT32_MAX);
if (internal_lbasize < BTT_MIN_LBA_SIZE)
internal_lbasize = BTT_MIN_LBA_SIZE;
internal_lbasize = roundup(internal_lbasize, BTT_INTERNAL_LBA_ALIGNMENT)
- BTT_INTERNAL_LBA_ALIGNMENT;
return (uint32_t)internal_lbasize;
}
/*
* blk_read -- (internal) read pmemblk header
*/
static int
blk_read(PMEMpoolcheck *ppc)
{
/*
* Here we want to read the pmemblk header without the pool_hdr as we've
* already done it before.
*
* Take the pointer to fields right after pool_hdr, compute the size and
* offset of remaining fields.
*/
uint8_t *ptr = (uint8_t *)&ppc->pool->hdr.blk;
ptr += sizeof(ppc->pool->hdr.blk.hdr);
size_t size = sizeof(ppc->pool->hdr.blk) -
sizeof(ppc->pool->hdr.blk.hdr);
uint64_t offset = sizeof(ppc->pool->hdr.blk.hdr);
if (pool_read(ppc->pool, ptr, size, offset)) {
return CHECK_ERR(ppc, "cannot read pmemblk structure");
}
/* endianness conversion */
ppc->pool->hdr.blk.bsize = le32toh(ppc->pool->hdr.blk.bsize);
return 0;
}
/*
* blk_bsize_valid -- (internal) check if block size is valid for given file
* size
*/
static int
blk_bsize_valid(uint32_t bsize, uint64_t fsize)
{
uint32_t max_bsize = blk_get_max_bsize(fsize);
return (bsize >= max_bsize);
}
/*
* blk_hdr_check -- (internal) check pmemblk header
*/
static int
blk_hdr_check(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
CHECK_INFO(ppc, "checking pmemblk header");
if (blk_read(ppc)) {
ppc->result = CHECK_RESULT_ERROR;
return -1;
}
/* check for valid BTT Info arena as we can take bsize from it */
if (!ppc->pool->bttc.valid)
pool_blk_get_first_valid_arena(ppc->pool, &ppc->pool->bttc);
if (ppc->pool->bttc.valid) {
const uint32_t btt_bsize =
ppc->pool->bttc.btt_info.external_lbasize;
if (ppc->pool->hdr.blk.bsize != btt_bsize) {
CHECK_ASK(ppc, Q_BLK_BSIZE,
"invalid pmemblk.bsize.|Do you want to set "
"pmemblk.bsize to %u from BTT Info?",
btt_bsize);
}
} else if (!ppc->pool->bttc.zeroed) {
if (ppc->pool->hdr.blk.bsize < BTT_MIN_LBA_SIZE ||
blk_bsize_valid(ppc->pool->hdr.blk.bsize,
ppc->pool->set_file->size)) {
ppc->result = CHECK_RESULT_CANNOT_REPAIR;
return CHECK_ERR(ppc, "invalid pmemblk.bsize");
}
}
if (ppc->result == CHECK_RESULT_CONSISTENT ||
ppc->result == CHECK_RESULT_REPAIRED)
CHECK_INFO(ppc, "pmemblk header correct");
return check_questions_sequence_validate(ppc);
}
/*
* blk_hdr_fix -- (internal) fix pmemblk header
*/
static int
blk_hdr_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *ctx)
{
LOG(3, NULL);
uint32_t btt_bsize;
switch (question) {
case Q_BLK_BSIZE:
/*
* check for valid BTT Info arena as we can take bsize from it
*/
if (!ppc->pool->bttc.valid)
pool_blk_get_first_valid_arena(ppc->pool,
&ppc->pool->bttc);
btt_bsize = ppc->pool->bttc.btt_info.external_lbasize;
CHECK_INFO(ppc, "setting pmemblk.b_size to 0x%x", btt_bsize);
ppc->pool->hdr.blk.bsize = btt_bsize;
break;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
struct step {
int (*check)(PMEMpoolcheck *, location *);
int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *);
enum pool_type type;
};
static const struct step steps[] = {
{
.check = blk_hdr_check,
.type = POOL_TYPE_BLK
},
{
.fix = blk_hdr_fix,
.type = POOL_TYPE_BLK
},
{
.check = NULL,
.fix = NULL,
},
};
/*
* step_exe -- (internal) perform single step according to its parameters
*/
static inline int
step_exe(PMEMpoolcheck *ppc, location *loc)
{
ASSERT(loc->step < ARRAY_SIZE(steps));
ASSERTeq(ppc->pool->params.type, POOL_TYPE_BLK);
const struct step *step = &steps[loc->step++];
if (!(step->type & ppc->pool->params.type))
return 0;
if (!step->fix)
return step->check(ppc, loc);
if (blk_read(ppc)) {
ppc->result = CHECK_RESULT_ERROR;
return -1;
}
return check_answer_loop(ppc, loc, NULL, 1, step->fix);
}
/*
* check_blk -- entry point for pmemblk checks
*/
void
check_blk(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
location *loc = check_get_step_data(ppc->data);
/* do all checks */
while (CHECK_NOT_COMPLETE(loc, steps)) {
if (step_exe(ppc, loc))
break;
}
}
| 6,792 | 24.441948 | 78 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/check_sds.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check_shutdown_state.c -- shutdown state check
*/
#include <stdio.h>
#include <inttypes.h>
#include <sys/mman.h>
#include <endian.h>
#include "out.h"
#include "util_pmem.h"
#include "libpmempool.h"
#include "libpmem.h"
#include "pmempool.h"
#include "pool.h"
#include "set.h"
#include "check_util.h"
enum question {
Q_RESET_SDS,
};
#define SDS_CHECK_STR "checking shutdown state"
#define SDS_OK_STR "shutdown state correct"
#define SDS_DIRTY_STR "shutdown state is dirty"
#define ADR_FAILURE_STR \
"an ADR failure was detected - your pool might be corrupted"
#define ZERO_SDS_STR \
"Do you want to zero shutdown state?"
#define RESET_SDS_STR \
"Do you want to reset shutdown state at your own risk? " \
"If you have more then one replica you will have to " \
"synchronize your pool after this operation."
#define SDS_FAIL_MSG(hdrp) \
IGNORE_SDS(hdrp) ? SDS_DIRTY_STR : ADR_FAILURE_STR
#define SDS_REPAIR_MSG(hdrp) \
IGNORE_SDS(hdrp) \
? SDS_DIRTY_STR ".|" ZERO_SDS_STR \
: ADR_FAILURE_STR ".|" RESET_SDS_STR
/*
* sds_check_replica -- (internal) check if replica is healthy
*/
static int
sds_check_replica(location *loc)
{
LOG(3, NULL);
struct pool_replica *rep = REP(loc->set, loc->replica);
if (rep->remote)
return 0;
/* make a copy of sds as we shouldn't modify a pool */
struct shutdown_state old_sds = loc->hdr.sds;
struct shutdown_state curr_sds;
if (IGNORE_SDS(&loc->hdr))
return util_is_zeroed(&old_sds, sizeof(old_sds)) ? 0 : -1;
shutdown_state_init(&curr_sds, NULL);
/* get current shutdown state */
for (unsigned p = 0; p < rep->nparts; ++p) {
if (shutdown_state_add_part(&curr_sds,
PART(rep, p)->path, NULL))
return -1;
}
/* compare current and old shutdown state */
return shutdown_state_check(&curr_sds, &old_sds, NULL);
}
/*
* sds_check -- (internal) check shutdown_state
*/
static int
sds_check(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
CHECK_INFO(ppc, "%s" SDS_CHECK_STR, loc->prefix);
/* shutdown state is valid */
if (!sds_check_replica(loc)) {
CHECK_INFO(ppc, "%s" SDS_OK_STR, loc->prefix);
loc->step = CHECK_STEP_COMPLETE;
return 0;
}
/* shutdown state is NOT valid and can NOT be repaired */
if (CHECK_IS_NOT(ppc, REPAIR)) {
check_end(ppc->data);
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, "%s%s", loc->prefix,
SDS_FAIL_MSG(&loc->hdr));
}
/* shutdown state is NOT valid but can be repaired */
CHECK_ASK(ppc, Q_RESET_SDS, "%s%s", loc->prefix,
SDS_REPAIR_MSG(&loc->hdr));
return check_questions_sequence_validate(ppc);
}
/*
* sds_fix -- (internal) fix shutdown state
*/
static int
sds_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question,
void *context)
{
LOG(3, NULL);
switch (question) {
case Q_RESET_SDS:
CHECK_INFO(ppc, "%sresetting pool_hdr.sds", loc->prefix);
memset(&loc->hdr.sds, 0, sizeof(loc->hdr.sds));
++loc->healthy_replicas;
break;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
struct step {
int (*check)(PMEMpoolcheck *, location *);
int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *);
};
static const struct step steps[] = {
{
.check = sds_check,
},
{
.fix = sds_fix,
},
{
.check = NULL,
.fix = NULL,
},
};
/*
* step_exe -- (internal) perform single step according to its parameters
*/
static int
step_exe(PMEMpoolcheck *ppc, const struct step *steps, location *loc)
{
const struct step *step = &steps[loc->step++];
if (!step->fix)
return step->check(ppc, loc);
if (!check_has_answer(ppc->data))
return 0;
if (check_answer_loop(ppc, loc, NULL, 0 /* fail on no */, step->fix))
return -1;
util_convert2le_hdr(&loc->hdr);
memcpy(loc->hdrp, &loc->hdr, sizeof(loc->hdr));
util_persist_auto(loc->is_dev_dax, loc->hdrp, sizeof(*loc->hdrp));
util_convert2h_hdr_nocheck(&loc->hdr);
loc->pool_hdr_modified = 1;
return 0;
}
/*
* init_prefix -- prepare prefix for messages
*/
static void
init_prefix(location *loc)
{
if (loc->set->nreplicas > 1) {
int ret = snprintf(loc->prefix, PREFIX_MAX_SIZE,
"replica %u: ",
loc->replica);
if (ret < 0 || ret >= PREFIX_MAX_SIZE)
FATAL("snprintf: %d", ret);
} else
loc->prefix[0] = '\0';
loc->step = 0;
}
/*
* init_location_data -- (internal) prepare location information
*/
static void
init_location_data(PMEMpoolcheck *ppc, location *loc)
{
ASSERTeq(loc->part, 0);
loc->set = ppc->pool->set_file->poolset;
if (ppc->result != CHECK_RESULT_PROCESS_ANSWERS)
init_prefix(loc);
struct pool_replica *rep = REP(loc->set, loc->replica);
loc->hdrp = HDR(rep, loc->part);
memcpy(&loc->hdr, loc->hdrp, sizeof(loc->hdr));
util_convert2h_hdr_nocheck(&loc->hdr);
loc->is_dev_dax = PART(rep, 0)->is_dev_dax;
}
/*
* sds_get_healthy_replicas_num -- (internal) get number of healthy replicas
*/
static void
sds_get_healthy_replicas_num(PMEMpoolcheck *ppc, location *loc)
{
const unsigned nreplicas = ppc->pool->set_file->poolset->nreplicas;
loc->healthy_replicas = 0;
loc->part = 0;
for (; loc->replica < nreplicas; loc->replica++) {
init_location_data(ppc, loc);
if (!sds_check_replica(loc)) {
++loc->healthy_replicas; /* healthy replica found */
}
}
loc->replica = 0; /* reset replica index */
}
/*
* check_sds -- entry point for shutdown state checks
*/
void
check_sds(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
const unsigned nreplicas = ppc->pool->set_file->poolset->nreplicas;
location *loc = check_get_step_data(ppc->data);
if (!loc->init_done) {
sds_get_healthy_replicas_num(ppc, loc);
if (loc->healthy_replicas == nreplicas) {
/* all replicas have healthy shutdown state */
/* print summary */
for (; loc->replica < nreplicas; loc->replica++) {
init_prefix(loc);
CHECK_INFO(ppc, "%s" SDS_CHECK_STR,
loc->prefix);
CHECK_INFO(ppc, "%s" SDS_OK_STR, loc->prefix);
}
return;
} else if (loc->healthy_replicas > 0) {
ppc->sync_required = true;
return;
}
loc->init_done = true;
}
/* produce single healthy replica */
loc->part = 0;
for (; loc->replica < nreplicas; loc->replica++) {
init_location_data(ppc, loc);
while (CHECK_NOT_COMPLETE(loc, steps)) {
ASSERT(loc->step < ARRAY_SIZE(steps));
if (step_exe(ppc, steps, loc))
return;
}
if (loc->healthy_replicas)
break;
}
if (loc->healthy_replicas == 0) {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
CHECK_ERR(ppc, "cannot complete repair, reverting changes");
} else if (loc->healthy_replicas < nreplicas) {
ppc->sync_required = true;
}
}
| 8,112 | 24.432602 | 76 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/check_log.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check_log.c -- check pmemlog
*/
#include <inttypes.h>
#include <sys/param.h>
#include <endian.h>
#include "out.h"
#include "libpmempool.h"
#include "pmempool.h"
#include "pool.h"
#include "check_util.h"
enum question {
Q_LOG_START_OFFSET,
Q_LOG_END_OFFSET,
Q_LOG_WRITE_OFFSET,
};
/*
* log_read -- (internal) read pmemlog header
*/
static int
log_read(PMEMpoolcheck *ppc)
{
/*
* Here we want to read the pmemlog header without the pool_hdr as we've
* already done it before.
*
* Take the pointer to fields right after pool_hdr, compute the size and
* offset of remaining fields.
*/
uint8_t *ptr = (uint8_t *)&ppc->pool->hdr.log;
ptr += sizeof(ppc->pool->hdr.log.hdr);
size_t size = sizeof(ppc->pool->hdr.log) -
sizeof(ppc->pool->hdr.log.hdr);
uint64_t offset = sizeof(ppc->pool->hdr.log.hdr);
if (pool_read(ppc->pool, ptr, size, offset))
return CHECK_ERR(ppc, "cannot read pmemlog structure");
/* endianness conversion */
log_convert2h(&ppc->pool->hdr.log);
return 0;
}
/*
* log_hdr_check -- (internal) check pmemlog header
*/
static int
log_hdr_check(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
CHECK_INFO(ppc, "checking pmemlog header");
if (log_read(ppc)) {
ppc->result = CHECK_RESULT_ERROR;
return -1;
}
/* determine constant values for pmemlog */
const uint64_t d_start_offset =
roundup(sizeof(ppc->pool->hdr.log), LOG_FORMAT_DATA_ALIGN);
if (ppc->pool->hdr.log.start_offset != d_start_offset) {
if (CHECK_ASK(ppc, Q_LOG_START_OFFSET,
"invalid pmemlog.start_offset: 0x%jx.|Do you "
"want to set pmemlog.start_offset to default "
"0x%jx?",
ppc->pool->hdr.log.start_offset,
d_start_offset))
goto error;
}
if (ppc->pool->hdr.log.end_offset != ppc->pool->set_file->size) {
if (CHECK_ASK(ppc, Q_LOG_END_OFFSET,
"invalid pmemlog.end_offset: 0x%jx.|Do you "
"want to set pmemlog.end_offset to 0x%jx?",
ppc->pool->hdr.log.end_offset,
ppc->pool->set_file->size))
goto error;
}
if (ppc->pool->hdr.log.write_offset < d_start_offset ||
ppc->pool->hdr.log.write_offset > ppc->pool->set_file->size) {
if (CHECK_ASK(ppc, Q_LOG_WRITE_OFFSET,
"invalid pmemlog.write_offset: 0x%jx.|Do you "
"want to set pmemlog.write_offset to "
"pmemlog.end_offset?",
ppc->pool->hdr.log.write_offset))
goto error;
}
if (ppc->result == CHECK_RESULT_CONSISTENT ||
ppc->result == CHECK_RESULT_REPAIRED)
CHECK_INFO(ppc, "pmemlog header correct");
return check_questions_sequence_validate(ppc);
error:
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
check_end(ppc->data);
return -1;
}
/*
* log_hdr_fix -- (internal) fix pmemlog header
*/
static int
log_hdr_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, void *ctx)
{
LOG(3, NULL);
uint64_t d_start_offset;
switch (question) {
case Q_LOG_START_OFFSET:
/* determine constant values for pmemlog */
d_start_offset = roundup(sizeof(ppc->pool->hdr.log),
LOG_FORMAT_DATA_ALIGN);
CHECK_INFO(ppc, "setting pmemlog.start_offset to 0x%jx",
d_start_offset);
ppc->pool->hdr.log.start_offset = d_start_offset;
break;
case Q_LOG_END_OFFSET:
CHECK_INFO(ppc, "setting pmemlog.end_offset to 0x%jx",
ppc->pool->set_file->size);
ppc->pool->hdr.log.end_offset = ppc->pool->set_file->size;
break;
case Q_LOG_WRITE_OFFSET:
CHECK_INFO(ppc, "setting pmemlog.write_offset to "
"pmemlog.end_offset");
ppc->pool->hdr.log.write_offset = ppc->pool->set_file->size;
break;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
struct step {
int (*check)(PMEMpoolcheck *, location *);
int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *);
enum pool_type type;
};
static const struct step steps[] = {
{
.check = log_hdr_check,
.type = POOL_TYPE_LOG
},
{
.fix = log_hdr_fix,
.type = POOL_TYPE_LOG
},
{
.check = NULL,
.fix = NULL,
},
};
/*
* step_exe -- (internal) perform single step according to its parameters
*/
static inline int
step_exe(PMEMpoolcheck *ppc, location *loc)
{
ASSERT(loc->step < ARRAY_SIZE(steps));
ASSERTeq(ppc->pool->params.type, POOL_TYPE_LOG);
const struct step *step = &steps[loc->step++];
if (!(step->type & ppc->pool->params.type))
return 0;
if (!step->fix)
return step->check(ppc, loc);
if (log_read(ppc)) {
ppc->result = CHECK_RESULT_ERROR;
return -1;
}
return check_answer_loop(ppc, loc, NULL, 1, step->fix);
}
/*
* check_log -- entry point for pmemlog checks
*/
void
check_log(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
location *loc = check_get_step_data(ppc->data);
/* do all checks */
while (CHECK_NOT_COMPLETE(loc, steps)) {
if (step_exe(ppc, loc))
break;
}
}
| 6,275 | 25.259414 | 76 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/replica.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* replica.c -- groups all commands for replica manipulation
*/
#include "replica.h"
#include <errno.h>
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <libgen.h>
#include "obj.h"
#include "palloc.h"
#include "file.h"
#include "os.h"
#include "out.h"
#include "pool_hdr.h"
#include "set.h"
#include "util.h"
#include "uuid.h"
#include "shutdown_state.h"
#include "os_dimm.h"
#include "badblock.h"
/*
* check_flags_sync -- (internal) check if flags are supported for sync
*/
static int
check_flags_sync(unsigned flags)
{
flags &= ~(PMEMPOOL_SYNC_DRY_RUN | PMEMPOOL_SYNC_FIX_BAD_BLOCKS);
return flags > 0;
}
/*
* check_flags_transform -- (internal) check if flags are supported for
* transform
*/
static int
check_flags_transform(unsigned flags)
{
flags &= ~PMEMPOOL_TRANSFORM_DRY_RUN;
return flags > 0;
}
/*
* replica_align_badblock_offset_length -- align offset and length
* of the bad block for the given part
*/
void
replica_align_badblock_offset_length(size_t *offset, size_t *length,
struct pool_set *set_in, unsigned repn, unsigned partn)
{
LOG(3, "offset %zu, length %zu, pool_set %p, replica %u, part %u",
*offset, *length, set_in, repn, partn);
size_t alignment = set_in->replica[repn]->part[partn].alignment;
size_t off = ALIGN_DOWN(*offset, alignment);
size_t len = ALIGN_UP(*length + (*offset - off), alignment);
*offset = off;
*length = len;
}
/*
* replica_get_part_data_len -- get data length for given part
*/
size_t
replica_get_part_data_len(struct pool_set *set_in, unsigned repn,
unsigned partn)
{
size_t alignment = set_in->replica[repn]->part[partn].alignment;
size_t hdrsize = (set_in->options & OPTION_SINGLEHDR) ? 0 : alignment;
return ALIGN_DOWN(set_in->replica[repn]->part[partn].filesize,
alignment) - ((partn == 0) ? POOL_HDR_SIZE : hdrsize);
}
/*
* replica_get_part_offset -- get part's offset from the beginning of replica
*/
uint64_t
replica_get_part_offset(struct pool_set *set, unsigned repn, unsigned partn)
{
return (uint64_t)set->replica[repn]->part[partn].addr -
(uint64_t)set->replica[repn]->part[0].addr;
}
/*
* replica_get_part_data_offset -- get data length before given part
*/
uint64_t
replica_get_part_data_offset(struct pool_set *set, unsigned repn,
unsigned partn)
{
if (partn == 0)
return POOL_HDR_SIZE;
return (uint64_t)set->replica[repn]->part[partn].addr -
(uint64_t)set->replica[repn]->part[0].addr;
}
/*
* replica_remove_part -- unlink part from replica
*/
int
replica_remove_part(struct pool_set *set, unsigned repn, unsigned partn,
int fix_bad_blocks)
{
LOG(3, "set %p repn %u partn %u fix_bad_blocks %i",
set, repn, partn, fix_bad_blocks);
struct pool_set_part *part = PART(REP(set, repn), partn);
if (part->fd != -1) {
os_close(part->fd);
part->fd = -1;
}
int olderrno = errno;
enum file_type type = util_file_get_type(part->path);
if (type == OTHER_ERROR)
return -1;
/* if the part is a device dax, clear its bad blocks */
if (type == TYPE_DEVDAX && fix_bad_blocks &&
os_dimm_devdax_clear_badblocks_all(part->path)) {
ERR("clearing bad blocks in device dax failed -- '%s'",
part->path);
errno = EIO;
return -1;
}
if (type == TYPE_NORMAL && util_unlink(part->path)) {
ERR("!removing part %u from replica %u failed",
partn, repn);
return -1;
}
errno = olderrno;
LOG(4, "Removed part %s number %u from replica %u", part->path, partn,
repn);
return 0;
}
/*
* create_replica_health_status -- (internal) create helping structure for
* storing replica's health status
*/
static struct replica_health_status *
create_replica_health_status(struct pool_set *set, unsigned repn)
{
LOG(3, "set %p, repn %u", set, repn);
unsigned nparts = set->replica[repn]->nparts;
struct replica_health_status *replica_hs;
replica_hs = Zalloc(sizeof(struct replica_health_status)
+ nparts * sizeof(struct part_health_status));
if (replica_hs == NULL) {
ERR("!Zalloc for replica health status");
return NULL;
}
replica_hs->nparts = nparts;
replica_hs->nhdrs = set->replica[repn]->nhdrs;
return replica_hs;
}
/*
* replica_part_remove_recovery_file -- remove bad blocks' recovery file
*/
static int
replica_part_remove_recovery_file(struct part_health_status *phs)
{
LOG(3, "phs %p", phs);
if (phs->recovery_file_name == NULL || phs->recovery_file_exists == 0)
return 0;
if (os_unlink(phs->recovery_file_name) < 0) {
ERR("!removing the bad block recovery file failed -- '%s'",
phs->recovery_file_name);
return -1;
}
LOG(3, "bad block recovery file removed -- '%s'",
phs->recovery_file_name);
phs->recovery_file_exists = 0;
return 0;
}
/*
* replica_remove_all_recovery_files -- remove all recovery files
*/
int
replica_remove_all_recovery_files(struct poolset_health_status *set_hs)
{
LOG(3, "set_hs %p", set_hs);
int ret = 0;
for (unsigned r = 0; r < set_hs->nreplicas; ++r) {
struct replica_health_status *rhs = set_hs->replica[r];
for (unsigned p = 0; p < rhs->nparts; ++p)
ret |= replica_part_remove_recovery_file(&rhs->part[p]);
}
return ret;
}
/*
* replica_free_poolset_health_status -- free memory allocated for helping
* structure
*/
void
replica_free_poolset_health_status(struct poolset_health_status *set_hs)
{
LOG(3, "set_hs %p", set_hs);
for (unsigned r = 0; r < set_hs->nreplicas; ++r) {
struct replica_health_status *rep_hs = set_hs->replica[r];
for (unsigned p = 0; p < rep_hs->nparts; ++p)
Free(rep_hs->part[p].recovery_file_name);
Free(set_hs->replica[r]);
}
Free(set_hs);
}
/*
* replica_create_poolset_health_status -- create helping structure for storing
* poolset's health status
*/
int
replica_create_poolset_health_status(struct pool_set *set,
struct poolset_health_status **set_hsp)
{
LOG(3, "set %p, set_hsp %p", set, set_hsp);
unsigned nreplicas = set->nreplicas;
struct poolset_health_status *set_hs;
set_hs = Zalloc(sizeof(struct poolset_health_status) +
nreplicas * sizeof(struct replica_health_status *));
if (set_hs == NULL) {
ERR("!Zalloc for poolset health state");
return -1;
}
set_hs->nreplicas = nreplicas;
for (unsigned i = 0; i < nreplicas; ++i) {
struct replica_health_status *replica_hs =
create_replica_health_status(set, i);
if (replica_hs == NULL) {
replica_free_poolset_health_status(set_hs);
return -1;
}
set_hs->replica[i] = replica_hs;
}
*set_hsp = set_hs;
return 0;
}
/*
* replica_is_part_broken -- check if part is marked as broken in the helping
* structure
*/
int
replica_is_part_broken(unsigned repn, unsigned partn,
struct poolset_health_status *set_hs)
{
struct replica_health_status *rhs = REP_HEALTH(set_hs, repn);
return (rhs->flags & IS_BROKEN) ||
(PART_HEALTH(rhs, partn) & IS_BROKEN);
}
/*
* is_replica_broken -- check if any part in the replica is marked as broken
*/
int
replica_is_replica_broken(unsigned repn, struct poolset_health_status *set_hs)
{
LOG(3, "repn %u, set_hs %p", repn, set_hs);
struct replica_health_status *r_hs = REP_HEALTH(set_hs, repn);
if (r_hs->flags & IS_BROKEN)
return 1;
for (unsigned p = 0; p < r_hs->nparts; ++p) {
if (replica_is_part_broken(repn, p, set_hs))
return 1;
}
return 0;
}
/*
* replica_is_replica_consistent -- check if replica is not marked as
* inconsistent
*/
int
replica_is_replica_consistent(unsigned repn,
struct poolset_health_status *set_hs)
{
return !(REP_HEALTH(set_hs, repn)->flags & IS_INCONSISTENT);
}
/*
* replica_has_bad_blocks -- check if replica has bad blocks
*/
int
replica_has_bad_blocks(unsigned repn, struct poolset_health_status *set_hs)
{
return REP_HEALTH(set_hs, repn)->flags & HAS_BAD_BLOCKS;
}
/*
* replica_part_has_bad_blocks -- check if replica's part has bad blocks
*/
int
replica_part_has_bad_blocks(struct part_health_status *phs)
{
return phs->flags & HAS_BAD_BLOCKS;
}
/*
* replica_part_has_corrupted_header -- (internal) check if replica's part
* has bad blocks in the header (corrupted header)
*/
int
replica_part_has_corrupted_header(unsigned repn, unsigned partn,
struct poolset_health_status *set_hs)
{
struct replica_health_status *rhs = REP_HEALTH(set_hs, repn);
return PART_HEALTH(rhs, partn) & HAS_CORRUPTED_HEADER;
}
/*
* replica_has_corrupted_header -- (internal) check if replica has bad blocks
* in the header (corrupted header)
*/
static int
replica_has_corrupted_header(unsigned repn,
struct poolset_health_status *set_hs)
{
return REP_HEALTH(set_hs, repn)->flags & HAS_CORRUPTED_HEADER;
}
/*
* replica_is_replica_healthy -- check if replica is unbroken and consistent
*/
int
replica_is_replica_healthy(unsigned repn, struct poolset_health_status *set_hs)
{
LOG(3, "repn %u, set_hs %p", repn, set_hs);
int ret = !replica_is_replica_broken(repn, set_hs) &&
replica_is_replica_consistent(repn, set_hs) &&
!replica_has_bad_blocks(repn, set_hs);
LOG(4, "return %i", ret);
return ret;
}
/*
* replica_has_healthy_header -- (interal) check if replica has healthy headers
*/
static int
replica_has_healthy_header(unsigned repn, struct poolset_health_status *set_hs)
{
LOG(3, "repn %u, set_hs %p", repn, set_hs);
int ret = !replica_is_replica_broken(repn, set_hs) &&
replica_is_replica_consistent(repn, set_hs) &&
!replica_has_corrupted_header(repn, set_hs);
LOG(4, "return %i", ret);
return ret;
}
/*
* replica_is_poolset_healthy -- check if all replicas in a poolset are not
* marked as broken nor inconsistent in the
* helping structure
*/
int
replica_is_poolset_healthy(struct poolset_health_status *set_hs)
{
LOG(3, "set_hs %p", set_hs);
for (unsigned r = 0; r < set_hs->nreplicas; ++r) {
if (!replica_is_replica_healthy(r, set_hs))
return 0;
}
return 1;
}
/*
* replica_is_poolset_transformed -- check if the flag indicating a call from
* pmempool_transform is on
*/
int
replica_is_poolset_transformed(unsigned flags)
{
return flags & IS_TRANSFORMED;
}
/*
* replica_find_unbroken_part_with_header -- find a part number in a given
* replica, which is not marked as broken in the helping structure and contains
* a pool header
*/
unsigned
replica_find_unbroken_part(unsigned repn, struct poolset_health_status *set_hs)
{
LOG(3, "repn %u, set_hs %p", repn, set_hs);
for (unsigned p = 0; p < REP_HEALTH(set_hs, repn)->nhdrs; ++p) {
if (!replica_is_part_broken(repn, p, set_hs))
return p;
}
return UNDEF_PART;
}
/*
* replica_find_healthy_replica -- find a replica which is a good source of data
*/
unsigned
replica_find_healthy_replica(struct poolset_health_status *set_hs)
{
LOG(3, "set_hs %p", set_hs);
for (unsigned r = 0; r < set_hs->nreplicas; ++r) {
if (replica_is_replica_healthy(r, set_hs)) {
LOG(4, "return %i", r);
return r;
}
}
LOG(4, "return %i", UNDEF_REPLICA);
return UNDEF_REPLICA;
}
/*
* replica_find_replica_healthy_header -- find a replica with a healthy header
*/
unsigned
replica_find_replica_healthy_header(struct poolset_health_status *set_hs)
{
LOG(3, "set_hs %p", set_hs);
for (unsigned r = 0; r < set_hs->nreplicas; ++r) {
if (replica_has_healthy_header(r, set_hs)) {
LOG(4, "return %i", r);
return r;
}
}
LOG(4, "return %i", UNDEF_REPLICA);
return UNDEF_REPLICA;
}
/*
* replica_check_store_size -- (internal) store size from pool descriptor for
* replica
*/
static int
replica_check_store_size(struct pool_set *set,
struct poolset_health_status *set_hs, unsigned repn)
{
LOG(3, "set %p, set_hs %p, repn %u", set, set_hs, repn);
struct pool_replica *rep = set->replica[repn];
struct pmemobjpool pop;
if (rep->remote) {
memcpy(&pop.hdr, rep->part[0].hdr, sizeof(pop.hdr));
void *descr = (void *)((uintptr_t)&pop + POOL_HDR_SIZE);
if (Rpmem_read(rep->remote->rpp, descr, POOL_HDR_SIZE,
sizeof(pop) - POOL_HDR_SIZE, 0)) {
return -1;
}
} else {
/* round up map size to Mmap align size */
if (util_map_part(&rep->part[0], NULL,
ALIGN_UP(sizeof(pop), rep->part[0].alignment),
0, MAP_SHARED, 1)) {
return -1;
}
memcpy(&pop, rep->part[0].addr, sizeof(pop));
util_unmap_part(&rep->part[0]);
}
void *dscp = (void *)((uintptr_t)&pop + sizeof(pop.hdr));
if (!util_checksum(dscp, OBJ_DSC_P_SIZE, &pop.checksum, 0,
0)) {
set_hs->replica[repn]->flags |= IS_BROKEN;
return 0;
}
set_hs->replica[repn]->pool_size = pop.heap_offset + pop.heap_size;
return 0;
}
/*
* check_store_all_sizes -- (internal) store sizes from pool descriptor for all
* healthy replicas
*/
static int
check_store_all_sizes(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
for (unsigned r = 0; r < set->nreplicas; ++r) {
if (!replica_has_healthy_header(r, set_hs))
continue;
if (replica_check_store_size(set, set_hs, r))
return -1;
}
return 0;
}
/*
* check_and_open_poolset_part_files -- (internal) for each part in a poolset
* check if the part files are accessible, and if not, mark it as broken
* in a helping structure; then open the part file
*/
static int
check_and_open_poolset_part_files(struct pool_set *set,
struct poolset_health_status *set_hs, unsigned flags)
{
LOG(3, "set %p, set_hs %p, flags %u", set, set_hs, flags);
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
struct replica_health_status *rep_hs = set_hs->replica[r];
if (rep->remote) {
if (util_replica_open_remote(set, r, 0)) {
LOG(1, "cannot open remote replica no %u", r);
return -1;
}
unsigned nlanes = REMOTE_NLANES;
int ret = util_poolset_remote_open(rep, r,
rep->repsize, 0,
rep->part[0].addr,
rep->resvsize, &nlanes);
if (ret) {
rep_hs->flags |= IS_BROKEN;
LOG(1, "remote replica #%u marked as BROKEN",
r);
}
continue;
}
for (unsigned p = 0; p < rep->nparts; ++p) {
const char *path = rep->part[p].path;
enum file_type type = util_file_get_type(path);
if (type < 0 || os_access(path, R_OK|W_OK) != 0) {
LOG(1, "part file %s is not accessible", path);
errno = 0;
rep_hs->part[p].flags |= IS_BROKEN;
if (is_dry_run(flags))
continue;
}
if (util_part_open(&rep->part[p], 0, 0)) {
if (type == TYPE_DEVDAX) {
LOG(1,
"opening part on Device DAX %s failed",
path);
return -1;
}
LOG(1, "opening part %s failed", path);
errno = 0;
rep_hs->part[p].flags |= IS_BROKEN;
}
}
}
return 0;
}
/*
* map_all_unbroken_headers -- (internal) map all headers in a poolset,
* skipping those marked as broken in a helping
* structure
*/
static int
map_all_unbroken_headers(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
struct replica_health_status *rep_hs = set_hs->replica[r];
if (rep->remote)
continue;
for (unsigned p = 0; p < rep->nhdrs; ++p) {
/* skip broken parts */
if (replica_is_part_broken(r, p, set_hs))
continue;
LOG(4, "mapping header for part %u, replica %u", p, r);
if (util_map_hdr(&rep->part[p], MAP_SHARED, 0) != 0) {
LOG(1, "header mapping failed - part #%d", p);
rep_hs->part[p].flags |= IS_BROKEN;
}
}
}
return 0;
}
/*
* unmap_all_headers -- (internal) unmap all headers in a poolset
*/
static int
unmap_all_headers(struct pool_set *set)
{
LOG(3, "set %p", set);
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
util_replica_close(set, r);
if (rep->remote && rep->remote->rpp) {
Rpmem_close(rep->remote->rpp);
rep->remote->rpp = NULL;
}
}
return 0;
}
/*
* check_checksums_and_signatures -- (internal) check if checksums
* and signatures are correct for parts
* in a given replica
*/
static int
check_checksums_and_signatures(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = REP(set, r);
struct replica_health_status *rep_hs = REP_HEALTH(set_hs, r);
if (rep->remote)
continue;
for (unsigned p = 0; p < rep->nhdrs; ++p) {
/* skip broken parts */
if (replica_is_part_broken(r, p, set_hs))
continue;
/* check part's checksum */
LOG(4, "checking checksum for part %u, replica %u",
p, r);
struct pool_hdr *hdr;
if (rep->remote) {
hdr = rep->part[p].remote_hdr;
} else {
hdr = HDR(rep, p);
}
if (!util_checksum(hdr, sizeof(*hdr), &hdr->checksum, 0,
POOL_HDR_CSUM_END_OFF(hdr))) {
ERR("invalid checksum of pool header");
rep_hs->part[p].flags |= IS_BROKEN;
} else if (util_is_zeroed(hdr, sizeof(*hdr))) {
rep_hs->part[p].flags |= IS_BROKEN;
}
enum pool_type type = pool_hdr_get_type(hdr);
if (type == POOL_TYPE_UNKNOWN) {
ERR("invalid signature");
rep_hs->part[p].flags |= IS_BROKEN;
}
}
}
return 0;
}
/*
* replica_badblocks_recovery_file_save -- save bad blocks in the bad blocks
* recovery file before clearing them
*/
static int
replica_badblocks_recovery_file_save(struct part_health_status *part_hs)
{
LOG(3, "part_health_status %p", part_hs);
ASSERTeq(part_hs->recovery_file_exists, 1);
ASSERTne(part_hs->recovery_file_name, NULL);
struct badblocks *bbs = &part_hs->bbs;
char *path = part_hs->recovery_file_name;
int ret = -1;
int fd = os_open(path, O_WRONLY | O_TRUNC);
if (fd < 0) {
ERR("!opening bad block recovery file failed -- '%s'", path);
return -1;
}
FILE *recovery_file_name = os_fdopen(fd, "w");
if (recovery_file_name == NULL) {
ERR(
"!opening a file stream for bad block recovery file failed -- '%s'",
path);
os_close(fd);
return -1;
}
/* save bad blocks */
for (unsigned i = 0; i < bbs->bb_cnt; i++) {
ASSERT(bbs->bbv[i].length != 0);
fprintf(recovery_file_name, "%llu %u\n",
bbs->bbv[i].offset, bbs->bbv[i].length);
}
if (fflush(recovery_file_name) == EOF) {
ERR("!flushing bad block recovery file failed -- '%s'", path);
goto exit_error;
}
if (os_fsync(fd) < 0) {
ERR("!syncing bad block recovery file failed -- '%s'", path);
goto exit_error;
}
/* save the finish flag */
fprintf(recovery_file_name, "0 0\n");
if (fflush(recovery_file_name) == EOF) {
ERR("!flushing bad block recovery file failed -- '%s'", path);
goto exit_error;
}
if (os_fsync(fd) < 0) {
ERR("!syncing bad block recovery file failed -- '%s'", path);
goto exit_error;
}
LOG(3, "bad blocks saved in the recovery file -- '%s'", path);
ret = 0;
exit_error:
os_fclose(recovery_file_name);
return ret;
}
/*
* replica_part_badblocks_recovery_file_read -- read bad blocks
* from the bad block recovery file
* for the current part
*/
static int
replica_part_badblocks_recovery_file_read(struct part_health_status *part_hs)
{
LOG(3, "part_health_status %p", part_hs);
ASSERT(part_hs->recovery_file_exists);
ASSERTne(part_hs->recovery_file_name, NULL);
VEC(bbsvec, struct bad_block) bbv = VEC_INITIALIZER;
char *path = part_hs->recovery_file_name;
struct bad_block bb;
int ret = -1;
FILE *recovery_file = os_fopen(path, "r");
if (!recovery_file) {
ERR("!opening the recovery file for reading failed -- '%s'",
path);
return -1;
}
unsigned long long min_offset = 0; /* minimum possible offset */
do {
if (fscanf(recovery_file, "%llu %u\n",
&bb.offset, &bb.length) < 2) {
LOG(1, "incomplete bad block recovery file -- '%s'",
path);
ret = 1;
goto error_exit;
}
if (bb.offset == 0 && bb.length == 0) {
/* finish_flag */
break;
}
/* check if bad blocks build an increasing sequence */
if (bb.offset < min_offset) {
ERR(
"wrong format of bad block recovery file (bad blocks are not sorted by the offset in ascending order) -- '%s'",
path);
errno = EINVAL;
ret = -1;
goto error_exit;
}
/* update the minimum possible offset */
min_offset = bb.offset + bb.length;
bb.nhealthy = NO_HEALTHY_REPLICA; /* unknown healthy replica */
/* add the new bad block to the vector */
if (VEC_PUSH_BACK(&bbv, bb))
goto error_exit;
} while (1);
part_hs->bbs.bbv = VEC_ARR(&bbv);
part_hs->bbs.bb_cnt = (unsigned)VEC_SIZE(&bbv);
os_fclose(recovery_file);
LOG(1, "bad blocks read from the recovery file -- '%s'", path);
return 0;
error_exit:
VEC_DELETE(&bbv);
os_fclose(recovery_file);
return ret;
}
/* status returned by the replica_badblocks_recovery_files_check() function */
enum badblocks_recovery_files_status {
RECOVERY_FILES_ERROR = -1,
RECOVERY_FILES_DO_NOT_EXIST = 0,
RECOVERY_FILES_EXIST_ALL = 1,
RECOVERY_FILES_NOT_ALL_EXIST = 2
};
/*
* replica_badblocks_recovery_files_check -- (internal) check if bad blocks
* recovery files exist
*/
static enum badblocks_recovery_files_status
replica_badblocks_recovery_files_check(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
int recovery_file_exists = 0;
int recovery_file_does_not_exist = 0;
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
struct replica_health_status *rep_hs = set_hs->replica[r];
if (rep->remote) {
/*
* Bad blocks in remote replicas curently are fixed
* during opening by removing and recreating
* the whole remote replica.
*/
continue;
}
for (unsigned p = 0; p < rep->nparts; ++p) {
const char *path = PART(rep, p)->path;
struct part_health_status *part_hs = &rep_hs->part[p];
int exists = util_file_exists(path);
if (exists < 0)
return -1;
if (!exists) {
/* part file does not exist - skip it */
continue;
}
part_hs->recovery_file_name =
badblocks_recovery_file_alloc(set->path,
r, p);
if (part_hs->recovery_file_name == NULL) {
LOG(1,
"allocating name of bad block recovery file failed");
return RECOVERY_FILES_ERROR;
}
exists = util_file_exists(part_hs->recovery_file_name);
if (exists < 0)
return -1;
part_hs->recovery_file_exists = exists;
if (part_hs->recovery_file_exists) {
LOG(3, "bad block recovery file exists: %s",
part_hs->recovery_file_name);
recovery_file_exists = 1;
} else {
LOG(3,
"bad block recovery file does not exist: %s",
part_hs->recovery_file_name);
recovery_file_does_not_exist = 1;
}
}
}
if (recovery_file_exists) {
if (recovery_file_does_not_exist) {
LOG(4, "return RECOVERY_FILES_NOT_ALL_EXIST");
return RECOVERY_FILES_NOT_ALL_EXIST;
} else {
LOG(4, "return RECOVERY_FILES_EXIST_ALL");
return RECOVERY_FILES_EXIST_ALL;
}
}
LOG(4, "return RECOVERY_FILES_DO_NOT_EXIST");
return RECOVERY_FILES_DO_NOT_EXIST;
}
/*
* replica_badblocks_recovery_files_read -- (internal) read bad blocks from all
* bad block recovery files for all parts
*/
static int
replica_badblocks_recovery_files_read(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
int ret;
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
struct replica_health_status *rep_hs = set_hs->replica[r];
/* XXX: not supported yet */
if (rep->remote)
continue;
for (unsigned p = 0; p < rep->nparts; ++p) {
const char *path = PART(rep, p)->path;
struct part_health_status *part_hs = &rep_hs->part[p];
int exists = util_file_exists(path);
if (exists < 0)
return -1;
if (!exists) {
/* the part does not exist */
continue;
}
LOG(1,
"reading bad blocks from the recovery file -- '%s'",
part_hs->recovery_file_name);
ret = replica_part_badblocks_recovery_file_read(
part_hs);
if (ret < 0) {
LOG(1,
"reading bad blocks from the recovery file failed -- '%s'",
part_hs->recovery_file_name);
return -1;
}
if (ret > 0) {
LOG(1,
"incomplete bad block recovery file detected -- '%s'",
part_hs->recovery_file_name);
return 1;
}
if (part_hs->bbs.bb_cnt) {
LOG(3, "part %u contains %u bad blocks -- '%s'",
p, part_hs->bbs.bb_cnt, path);
}
}
}
return 0;
}
/*
* replica_badblocks_recovery_files_create_empty -- (internal) create one empty
* bad block recovery file
* for each part file
*/
static int
replica_badblocks_recovery_files_create_empty(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
struct part_health_status *part_hs;
const char *path;
int fd;
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
struct replica_health_status *rep_hs = set_hs->replica[r];
/* XXX: not supported yet */
if (rep->remote)
continue;
for (unsigned p = 0; p < rep->nparts; ++p) {
part_hs = &rep_hs->part[p];
path = PART(rep, p)->path;
if (!part_hs->recovery_file_name)
continue;
fd = os_open(part_hs->recovery_file_name,
O_RDWR | O_CREAT | O_EXCL,
0600);
if (fd < 0) {
ERR(
"!creating an empty bad block recovery file failed -- '%s' (part file '%s')",
part_hs->recovery_file_name, path);
return -1;
}
os_close(fd);
char *file_name = Strdup(part_hs->recovery_file_name);
if (file_name == NULL) {
ERR("!Strdup");
return -1;
}
char *dir_name = dirname(file_name);
/* fsync the file's directory */
if (os_fsync_dir(dir_name) < 0) {
ERR(
"!syncing the directory of the bad block recovery file failed -- '%s' (part file '%s')",
dir_name, path);
Free(file_name);
return -1;
}
Free(file_name);
part_hs->recovery_file_exists = 1;
}
}
return 0;
}
/*
* replica_badblocks_recovery_files_save -- (internal) save bad blocks
* in the bad block recovery files
*/
static int
replica_badblocks_recovery_files_save(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
struct replica_health_status *rep_hs = set_hs->replica[r];
/* XXX: not supported yet */
if (rep->remote)
continue;
for (unsigned p = 0; p < rep->nparts; ++p) {
struct part_health_status *part_hs = &rep_hs->part[p];
if (!part_hs->recovery_file_name)
continue;
int ret = replica_badblocks_recovery_file_save(part_hs);
if (ret < 0) {
LOG(1,
"opening bad block recovery file failed -- '%s'",
part_hs->recovery_file_name);
return -1;
}
}
}
return 0;
}
/*
* replica_badblocks_get -- (internal) get all bad blocks and save them
* in part_hs->bbs structures.
* Returns 1 if any bad block was found, 0 otherwise.
*/
static int
replica_badblocks_get(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
int bad_blocks_found = 0;
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
struct replica_health_status *rep_hs = set_hs->replica[r];
/* XXX: not supported yet */
if (rep->remote)
continue;
for (unsigned p = 0; p < rep->nparts; ++p) {
const char *path = PART(rep, p)->path;
struct part_health_status *part_hs = &rep_hs->part[p];
int exists = util_file_exists(path);
if (exists < 0)
return -1;
if (!exists)
continue;
int ret = os_badblocks_get(path, &part_hs->bbs);
if (ret < 0) {
ERR(
"checking the pool part for bad blocks failed -- '%s'",
path);
return -1;
}
if (part_hs->bbs.bb_cnt) {
LOG(3, "part %u contains %u bad blocks -- '%s'",
p, part_hs->bbs.bb_cnt, path);
bad_blocks_found = 1;
}
}
}
return bad_blocks_found;
}
/*
* check_badblocks_in_header -- (internal) check if bad blocks corrupted
* the header
*/
static int
check_badblocks_in_header(struct badblocks *bbs)
{
for (unsigned b = 0; b < bbs->bb_cnt; b++)
if (bbs->bbv[b].offset < POOL_HDR_SIZE)
return 1;
return 0;
}
/*
* replica_badblocks_clear -- (internal) clear all bad blocks
*/
static int
replica_badblocks_clear(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
int ret;
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
struct replica_health_status *rep_hs = set_hs->replica[r];
/* XXX: not supported yet */
if (rep->remote)
continue;
for (unsigned p = 0; p < rep->nparts; ++p) {
const char *path = PART(rep, p)->path;
struct part_health_status *part_hs = &rep_hs->part[p];
int exists = util_file_exists(path);
if (exists < 0)
return -1;
if (!exists) {
/* the part does not exist */
continue;
}
if (part_hs->bbs.bb_cnt == 0) {
/* no bad blocks found */
continue;
}
/* bad blocks were found */
part_hs->flags |= HAS_BAD_BLOCKS;
rep_hs->flags |= HAS_BAD_BLOCKS;
if (check_badblocks_in_header(&part_hs->bbs)) {
part_hs->flags |= HAS_CORRUPTED_HEADER;
if (p == 0)
rep_hs->flags |= HAS_CORRUPTED_HEADER;
}
ret = os_badblocks_clear(path, &part_hs->bbs);
if (ret < 0) {
LOG(1,
"clearing bad blocks in replica failed -- '%s'",
path);
return -1;
}
}
}
return 0;
}
/*
* replica_badblocks_check_or_clear -- (internal) check if replica contains
* bad blocks when in dry run
* or clear them otherwise
*/
static int
replica_badblocks_check_or_clear(struct pool_set *set,
struct poolset_health_status *set_hs,
int dry_run, int called_from_sync,
int check_bad_blocks, int fix_bad_blocks)
{
LOG(3,
"set %p, set_hs %p, dry_run %i, called_from_sync %i, "
"check_bad_blocks %i, fix_bad_blocks %i",
set, set_hs, dry_run, called_from_sync,
check_bad_blocks, fix_bad_blocks);
#define ERR_MSG_BB \
" please read the manual first and use this option\n"\
" ONLY IF you are sure that you know what you are doing"
enum badblocks_recovery_files_status status;
int ret;
/* check all bad block recovery files */
status = replica_badblocks_recovery_files_check(set, set_hs);
/* phase #1 - error handling */
switch (status) {
case RECOVERY_FILES_ERROR:
LOG(1, "checking bad block recovery files failed");
return -1;
case RECOVERY_FILES_EXIST_ALL:
case RECOVERY_FILES_NOT_ALL_EXIST:
if (!called_from_sync) {
ERR(
"error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' to fix bad blocks first");
return -1;
}
if (!fix_bad_blocks) {
ERR(
"error: a bad block recovery file exists, but the '--bad-blocks' option is not set\n"
ERR_MSG_BB);
return -1;
}
break;
default:
break;
};
/*
* The pool is checked for bad blocks only if:
* 1) compat feature POOL_FEAT_CHECK_BAD_BLOCKS is set
* OR:
* 2) the '--bad-blocks' option is set
*
* Bad blocks are cleared and fixed only if:
* - the '--bad-blocks' option is set
*/
if (!fix_bad_blocks && !check_bad_blocks) {
LOG(3, "skipping bad blocks checking");
return 0;
}
/* phase #2 - reading recovery files */
switch (status) {
case RECOVERY_FILES_EXIST_ALL:
/* read all bad block recovery files */
ret = replica_badblocks_recovery_files_read(set, set_hs);
if (ret < 0) {
LOG(1, "checking bad block recovery files failed");
return -1;
}
if (ret > 0) {
/* incomplete bad block recovery file was detected */
LOG(1,
"warning: incomplete bad block recovery file detected\n"
" - all recovery files will be removed");
/* changing status to RECOVERY_FILES_NOT_ALL_EXIST */
status = RECOVERY_FILES_NOT_ALL_EXIST;
}
break;
case RECOVERY_FILES_NOT_ALL_EXIST:
LOG(1,
"warning: one of bad block recovery files does not exist\n"
" - all recovery files will be removed");
break;
default:
break;
};
if (status == RECOVERY_FILES_NOT_ALL_EXIST) {
/*
* At least one of bad block recovery files does not exist,
* or an incomplete bad block recovery file was detected,
* so all recovery files have to be removed.
*/
if (!dry_run) {
LOG(1, "removing all bad block recovery files...");
ret = replica_remove_all_recovery_files(set_hs);
if (ret < 0) {
LOG(1,
"removing bad block recovery files failed");
return -1;
}
} else {
LOG(1, "all bad block recovery files would be removed");
}
/* changing status to RECOVERY_FILES_DO_NOT_EXIST */
status = RECOVERY_FILES_DO_NOT_EXIST;
}
if (status == RECOVERY_FILES_DO_NOT_EXIST) {
/*
* There are no bad block recovery files,
* so let's check bad blocks.
*/
int bad_blocks_found = replica_badblocks_get(set, set_hs);
if (bad_blocks_found < 0) {
LOG(1, "checking bad blocks failed");
return -1;
}
if (!bad_blocks_found) {
LOG(4, "no bad blocks found");
return 0;
}
/* bad blocks were found */
if (!called_from_sync) {
ERR(
"error: bad blocks found, run 'pmempool sync --bad-blocks' to fix bad blocks first");
return -1;
}
if (!fix_bad_blocks) {
ERR(
"error: bad blocks found, but the '--bad-blocks' option is not set\n"
ERR_MSG_BB);
return -1;
}
if (dry_run) {
/* dry-run - do nothing */
LOG(1, "warning: bad blocks were found");
return 0;
}
/* create one empty recovery file for each part file */
ret = replica_badblocks_recovery_files_create_empty(set,
set_hs);
if (ret < 0) {
LOG(1,
"creating empty bad block recovery files failed");
return -1;
}
/* save bad blocks in recovery files */
ret = replica_badblocks_recovery_files_save(set, set_hs);
if (ret < 0) {
LOG(1, "saving bad block recovery files failed");
return -1;
}
}
if (dry_run) {
/* dry-run - do nothing */
LOG(1, "bad blocks would be cleared");
return 0;
}
ret = replica_badblocks_clear(set, set_hs);
if (ret < 0) {
ERR("clearing bad blocks failed");
return -1;
}
return 0;
}
/*
* check_shutdown_state -- (internal) check if replica has
* healthy shutdown_state
*/
static int
check_shutdown_state(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
for (unsigned r = 0; r < set->nreplicas; ++r) {\
struct pool_replica *rep = set->replica[r];
struct replica_health_status *rep_hs = set_hs->replica[r];
struct pool_hdr *hdrp = HDR(rep, 0);
if (rep->remote)
continue;
if (hdrp == NULL) {
/* cannot verify shutdown state */
rep_hs->flags |= IS_BROKEN;
continue;
}
struct shutdown_state curr_sds;
shutdown_state_init(&curr_sds, NULL);
for (unsigned p = 0; p < rep->nparts; ++p) {
const char *path = PART(rep, p)->path;
const int exists = util_file_exists(path);
if (exists < 0)
return -1;
/*
* skip missing parts to avoid false positive shutdown
* state failure detection
*/
if (!exists)
continue;
if (shutdown_state_add_part(&curr_sds, path, NULL)) {
rep_hs->flags |= IS_BROKEN;
break;
}
}
if (rep_hs->flags & IS_BROKEN)
continue;
/* make a copy of sds as we shouldn't modify a pool */
struct shutdown_state pool_sds = hdrp->sds;
if (shutdown_state_check(&curr_sds, &pool_sds, NULL))
rep_hs->flags |= IS_BROKEN;
}
return 0;
}
/*
* check_uuids_between_parts -- (internal) check if uuids between adjacent
* parts are consistent for a given replica
*/
static int
check_uuids_between_parts(struct pool_set *set, unsigned repn,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, repn %u, set_hs %p", set, repn, set_hs);
struct pool_replica *rep = REP(set, repn);
/* check poolset_uuid consistency between replica's parts */
LOG(4, "checking consistency of poolset uuid in replica %u", repn);
uuid_t poolset_uuid;
int uuid_stored = 0;
unsigned part_stored = UNDEF_PART;
for (unsigned p = 0; p < rep->nhdrs; ++p) {
/* skip broken parts */
if (replica_is_part_broken(repn, p, set_hs))
continue;
if (!uuid_stored) {
memcpy(poolset_uuid, HDR(rep, p)->poolset_uuid,
POOL_HDR_UUID_LEN);
uuid_stored = 1;
part_stored = p;
continue;
}
if (uuidcmp(HDR(rep, p)->poolset_uuid, poolset_uuid)) {
ERR(
"different poolset uuids in parts from the same replica (repn %u, parts %u and %u) - cannot synchronize",
repn, part_stored, p);
errno = EINVAL;
return -1;
}
}
/* check if all uuids for adjacent replicas are the same across parts */
LOG(4, "checking consistency of adjacent replicas' uuids in replica %u",
repn);
unsigned unbroken_p = UNDEF_PART;
for (unsigned p = 0; p < rep->nhdrs; ++p) {
/* skip broken parts */
if (replica_is_part_broken(repn, p, set_hs))
continue;
if (unbroken_p == UNDEF_PART) {
unbroken_p = p;
continue;
}
struct pool_hdr *hdrp = HDR(rep, p);
int prev_differ = uuidcmp(HDR(rep, unbroken_p)->prev_repl_uuid,
hdrp->prev_repl_uuid);
int next_differ = uuidcmp(HDR(rep, unbroken_p)->next_repl_uuid,
hdrp->next_repl_uuid);
if (prev_differ || next_differ) {
ERR(
"different adjacent replica UUID between parts (repn %u, parts %u and %u) - cannot synchronize",
repn, unbroken_p, p);
errno = EINVAL;
return -1;
}
}
/* check parts linkage */
LOG(4, "checking parts linkage in replica %u", repn);
for (unsigned p = 0; p < rep->nhdrs; ++p) {
/* skip broken parts */
if (replica_is_part_broken(repn, p, set_hs))
continue;
struct pool_hdr *hdrp = HDR(rep, p);
struct pool_hdr *next_hdrp = HDRN(rep, p);
int next_is_broken = replica_is_part_broken(repn, p + 1,
set_hs);
if (!next_is_broken) {
int next_decoupled =
uuidcmp(next_hdrp->prev_part_uuid,
hdrp->uuid) ||
uuidcmp(hdrp->next_part_uuid, next_hdrp->uuid);
if (next_decoupled) {
ERR(
"two consecutive unbroken parts are not linked to each other (repn %u, parts %u and %u) - cannot synchronize",
repn, p, p + 1);
errno = EINVAL;
return -1;
}
}
}
return 0;
}
/*
* check_replicas_consistency -- (internal) check if all uuids within each
* replica are consistent
*/
static int
check_replicas_consistency(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
for (unsigned r = 0; r < set->nreplicas; ++r) {
if (check_uuids_between_parts(set, r, set_hs))
return -1;
}
return 0;
}
/*
* check_replica_options -- (internal) check if options are consistent in the
* replica
*/
static int
check_replica_options(struct pool_set *set, unsigned repn,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, repn %u, set_hs %p", set, repn, set_hs);
struct pool_replica *rep = REP(set, repn);
struct replica_health_status *rep_hs = REP_HEALTH(set_hs, repn);
for (unsigned p = 0; p < rep->nhdrs; ++p) {
/* skip broken parts */
if (replica_is_part_broken(repn, p, set_hs))
continue;
struct pool_hdr *hdr = HDR(rep, p);
if (((hdr->features.incompat & POOL_FEAT_SINGLEHDR) == 0) !=
((set->options & OPTION_SINGLEHDR) == 0)) {
LOG(1,
"improper options are set in part %u's header in replica %u",
p, repn);
rep_hs->part[p].flags |= IS_BROKEN;
}
}
return 0;
}
/*
* check_options -- (internal) check if options are consistent in all replicas
*/
static int
check_options(struct pool_set *set, struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
for (unsigned r = 0; r < set->nreplicas; ++r) {
if (check_replica_options(set, r, set_hs))
return -1;
}
return 0;
}
/*
* check_replica_poolset_uuids - (internal) check if poolset_uuid fields are
* consistent among all parts of a replica;
* the replica is initially considered as
* consistent
*/
static int
check_replica_poolset_uuids(struct pool_set *set, unsigned repn,
uuid_t poolset_uuid, struct poolset_health_status *set_hs)
{
LOG(3, "set %p, repn %u, poolset_uuid %p, set_hs %p", set, repn,
poolset_uuid, set_hs);
struct pool_replica *rep = REP(set, repn);
for (unsigned p = 0; p < rep->nhdrs; ++p) {
/* skip broken parts */
if (replica_is_part_broken(repn, p, set_hs))
continue;
if (uuidcmp(HDR(rep, p)->poolset_uuid, poolset_uuid)) {
/*
* two internally consistent replicas have
* different poolset_uuid
*/
return -1;
} else {
/*
* it is sufficient to check only one part
* from internally consistent replica
*/
break;
}
}
return 0;
}
/*
* check_poolset_uuids -- (internal) check if poolset_uuid fields are consistent
* among all internally consistent replicas
*/
static int
check_poolset_uuids(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
/* find a replica with healthy header */
unsigned r_h = replica_find_replica_healthy_header(set_hs);
if (r_h == UNDEF_REPLICA) {
ERR("no healthy replica found");
return -1;
}
uuid_t poolset_uuid;
memcpy(poolset_uuid, HDR(REP(set, r_h), 0)->poolset_uuid,
POOL_HDR_UUID_LEN);
for (unsigned r = 0; r < set->nreplicas; ++r) {
/* skip inconsistent replicas */
if (!replica_is_replica_consistent(r, set_hs) || r == r_h)
continue;
if (check_replica_poolset_uuids(set, r, poolset_uuid, set_hs)) {
ERR(
"inconsistent poolset uuids between replicas %u and %u - cannot synchronize",
r_h, r);
return -1;
}
}
return 0;
}
/*
* get_replica_uuid -- (internal) get replica uuid
*/
static int
get_replica_uuid(struct pool_replica *rep, unsigned repn,
struct poolset_health_status *set_hs, uuid_t **uuidpp)
{
unsigned nhdrs = rep->nhdrs;
if (!replica_is_part_broken(repn, 0, set_hs)) {
/* the first part is not broken */
*uuidpp = &HDR(rep, 0)->uuid;
return 0;
} else if (nhdrs > 1 && !replica_is_part_broken(repn, 1, set_hs)) {
/* the second part is not broken */
*uuidpp = &HDR(rep, 1)->prev_part_uuid;
return 0;
} else if (nhdrs > 1 &&
!replica_is_part_broken(repn, nhdrs - 1, set_hs)) {
/* the last part is not broken */
*uuidpp = &HDR(rep, nhdrs - 1)->next_part_uuid;
return 0;
} else {
/* cannot get replica uuid */
return -1;
}
}
/*
* check_uuids_between_replicas -- (internal) check if uuids between internally
* consistent adjacent replicas are consistent
*/
static int
check_uuids_between_replicas(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
for (unsigned r = 0; r < set->nreplicas; ++r) {
/* skip comparing inconsistent pairs of replicas */
if (!replica_is_replica_consistent(r, set_hs) ||
!replica_is_replica_consistent(r + 1, set_hs))
continue;
struct pool_replica *rep = REP(set, r);
struct pool_replica *rep_n = REPN(set, r);
/* get uuids of the two adjacent replicas */
uuid_t *rep_uuidp = NULL;
uuid_t *rep_n_uuidp = NULL;
unsigned r_n = REPN_HEALTHidx(set_hs, r);
if (get_replica_uuid(rep, r, set_hs, &rep_uuidp))
LOG(2, "cannot get replica uuid, replica %u", r);
if (get_replica_uuid(rep_n, r_n, set_hs, &rep_n_uuidp))
LOG(2, "cannot get replica uuid, replica %u", r_n);
/*
* check if replica uuids are consistent between two adjacent
* replicas
*/
unsigned p = replica_find_unbroken_part(r, set_hs);
unsigned p_n = replica_find_unbroken_part(r_n, set_hs);
if (p_n != UNDEF_PART && rep_uuidp != NULL &&
uuidcmp(*rep_uuidp,
HDR(rep_n, p_n)->prev_repl_uuid)) {
ERR(
"inconsistent replica uuids between replicas %u and %u",
r, r_n);
return -1;
}
if (p != UNDEF_PART && rep_n_uuidp != NULL &&
uuidcmp(*rep_n_uuidp,
HDR(rep, p)->next_repl_uuid)) {
ERR(
"inconsistent replica uuids between replicas %u and %u",
r, r_n);
return -1;
}
/*
* check if replica uuids on borders of a broken replica are
* consistent
*/
unsigned r_nn = REPN_HEALTHidx(set_hs, r_n);
if (set->nreplicas > 1 && p != UNDEF_PART &&
replica_is_replica_broken(r_n, set_hs) &&
replica_is_replica_consistent(r_nn, set_hs)) {
unsigned p_nn =
replica_find_unbroken_part(r_nn, set_hs);
if (p_nn == UNDEF_PART) {
LOG(2,
"cannot compare uuids on borders of replica %u",
r);
continue;
}
struct pool_replica *rep_nn = REP(set, r_nn);
if (uuidcmp(HDR(rep, p)->next_repl_uuid,
HDR(rep_nn, p_nn)->prev_repl_uuid)) {
ERR(
"inconsistent replica uuids on borders of replica %u",
r);
return -1;
}
}
}
return 0;
}
/*
* check_replica_cycles -- (internal) check if healthy replicas form cycles
* shorter than the number of all replicas
*/
static int
check_replica_cycles(struct pool_set *set,
struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
unsigned first_healthy;
unsigned count_healthy = 0;
for (unsigned r = 0; r < set->nreplicas; ++r) {
if (!replica_is_replica_healthy(r, set_hs)) {
count_healthy = 0;
continue;
}
if (count_healthy == 0)
first_healthy = r;
++count_healthy;
struct pool_hdr *hdrh =
PART(REP(set, first_healthy), 0)->hdr;
struct pool_hdr *hdr = PART(REP(set, r), 0)->hdr;
if (uuidcmp(hdrh->uuid, hdr->next_repl_uuid) == 0 &&
count_healthy < set->nreplicas) {
/*
* Healthy replicas form a cycle shorter than
* the number of all replicas; for the user it
* means that:
*/
ERR(
"alien replica found (probably coming from a different poolset)");
return -1;
}
}
return 0;
}
/*
* check_replica_sizes -- (internal) check if all replicas are large
* enough to hold data from a healthy replica
*/
static int
check_replica_sizes(struct pool_set *set, struct poolset_health_status *set_hs)
{
LOG(3, "set %p, set_hs %p", set, set_hs);
ssize_t pool_size = -1;
for (unsigned r = 0; r < set->nreplicas; ++r) {
/* skip broken replicas */
if (!replica_is_replica_healthy(r, set_hs))
continue;
/* get the size of a pool in the replica */
ssize_t replica_pool_size;
if (REP(set, r)->remote)
/* XXX: no way to get the size of a remote pool yet */
replica_pool_size = (ssize_t)set->poolsize;
else
replica_pool_size = replica_get_pool_size(set, r);
if (replica_pool_size < 0) {
LOG(1, "getting pool size from replica %u failed", r);
set_hs->replica[r]->flags |= IS_BROKEN;
continue;
}
/* check if the pool is bigger than minimum size */
enum pool_type type = pool_hdr_get_type(HDR(REP(set, r), 0));
if ((size_t)replica_pool_size < pool_get_min_size(type)) {
LOG(1,
"pool size from replica %u is smaller than the minimum size allowed for the pool",
r);
set_hs->replica[r]->flags |= IS_BROKEN;
continue;
}
/* check if each replica is big enough to hold the pool data */
if (set->poolsize < (size_t)replica_pool_size) {
ERR(
"some replicas are too small to hold synchronized data");
return -1;
}
if (pool_size < 0) {
pool_size = replica_pool_size;
continue;
}
/* check if pools in all healthy replicas are of equal size */
if (pool_size != replica_pool_size) {
ERR("pool sizes from different replicas differ");
return -1;
}
}
return 0;
}
/*
* replica_read_compat_features -- (internal) read compat features
* from the header
*/
static int
replica_read_compat_features(struct pool_set *set, uint32_t *compat_features)
{
LOG(3, "set %p compat_features %p", set, compat_features);
*compat_features = 0;
for (unsigned r = 0; r < set->nreplicas; r++) {
struct pool_replica *rep = set->replica[r];
for (unsigned p = 0; p < rep->nparts; p++) {
struct pool_set_part *part = &rep->part[p];
if (part->fd == -1)
continue;
if (util_map_hdr(part, MAP_SHARED, 0) != 0) {
LOG(1, "header mapping failed");
return -1;
}
struct pool_hdr *hdrp = part->hdr;
*compat_features = hdrp->features.compat;
if (util_unmap_hdr(part) != 0) {
LOG(1, "header unmapping failed");
return -1;
}
return 0;
}
}
/* if there is no opened part, compat_features is set to 0 */
return 0;
}
/*
* replica_check_poolset_health -- check if a given poolset can be considered as
* healthy, and store the status in a helping structure
*/
int
replica_check_poolset_health(struct pool_set *set,
struct poolset_health_status **set_hsp,
int called_from_sync, unsigned flags)
{
LOG(3, "set %p, set_hsp %p, called_from_sync %i, flags %u",
set, set_hsp, called_from_sync, flags);
if (replica_create_poolset_health_status(set, set_hsp)) {
LOG(1, "creating poolset health status failed");
return -1;
}
struct poolset_health_status *set_hs = *set_hsp;
/* check if part files exist and are accessible */
if (check_and_open_poolset_part_files(set, set_hs, flags)) {
LOG(1, "poolset part files check failed");
goto err;
}
uint32_t compat_features;
if (replica_read_compat_features(set, &compat_features)) {
LOG(1, "reading compat features failed");
goto err;
}
int check_bad_blocks = compat_features & POOL_FEAT_CHECK_BAD_BLOCKS;
/* check for bad blocks when in dry run or clear them otherwise */
if (replica_badblocks_check_or_clear(set, set_hs, is_dry_run(flags),
called_from_sync, check_bad_blocks,
called_from_sync && fix_bad_blocks(flags))) {
LOG(1, "replica bad_blocks check failed");
goto err;
}
/* map all headers */
map_all_unbroken_headers(set, set_hs);
/*
* Check if checksums and signatures are correct for all parts
* in all replicas.
*/
check_checksums_and_signatures(set, set_hs);
/* check if option flags are consistent */
if (check_options(set, set_hs)) {
LOG(1, "flags check failed");
goto err;
}
if (check_shutdown_state(set, set_hs)) {
LOG(1, "replica shutdown_state check failed");
goto err;
}
/* check if uuids in parts across each replica are consistent */
if (check_replicas_consistency(set, set_hs)) {
LOG(1, "replica consistency check failed");
goto err;
}
/* check poolset_uuid values between replicas */
if (check_poolset_uuids(set, set_hs)) {
LOG(1, "poolset uuids check failed");
goto err;
}
/* check if uuids for adjacent replicas are consistent */
if (check_uuids_between_replicas(set, set_hs)) {
LOG(1, "replica uuids check failed");
goto err;
}
/* check if healthy replicas make up another poolset */
if (check_replica_cycles(set, set_hs)) {
LOG(1, "replica cycles check failed");
goto err;
}
/* check if replicas are large enough */
if (check_replica_sizes(set, set_hs)) {
LOG(1, "replica sizes check failed");
goto err;
}
if (check_store_all_sizes(set, set_hs)) {
LOG(1, "reading pool sizes failed");
goto err;
}
unmap_all_headers(set);
util_poolset_fdclose_always(set);
return 0;
err:
errno = EINVAL;
unmap_all_headers(set);
util_poolset_fdclose_always(set);
replica_free_poolset_health_status(set_hs);
return -1;
}
/*
* replica_get_pool_size -- find the effective size (mapped) of a pool based
* on metadata from given replica
*/
ssize_t
replica_get_pool_size(struct pool_set *set, unsigned repn)
{
LOG(3, "set %p, repn %u", set, repn);
struct pool_set_part *part = PART(REP(set, repn), 0);
int should_close_part = 0;
int should_unmap_part = 0;
if (part->fd == -1) {
if (util_part_open(part, 0, 0))
return -1;
should_close_part = 1;
}
if (part->addr == NULL) {
if (util_map_part(part, NULL,
ALIGN_UP(sizeof(PMEMobjpool), part->alignment), 0,
MAP_SHARED, 1)) {
util_part_fdclose(part);
return -1;
}
should_unmap_part = 1;
}
PMEMobjpool *pop = (PMEMobjpool *)part->addr;
ssize_t ret = (ssize_t)(pop->heap_offset + pop->heap_size);
if (should_unmap_part)
util_unmap_part(part);
if (should_close_part)
util_part_fdclose(part);
return ret;
}
/*
* replica_check_part_sizes -- check if all parts are large enough
*/
int
replica_check_part_sizes(struct pool_set *set, size_t min_size)
{
LOG(3, "set %p, min_size %zu", set, min_size);
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
if (rep->remote != NULL)
/* skip remote replicas */
continue;
for (unsigned p = 0; p < rep->nparts; ++p) {
if (PART(rep, p)->filesize < min_size) {
ERR("replica %u, part %u: file is too small",
r, p);
errno = EINVAL;
return -1;
}
}
}
return 0;
}
/*
* replica_check_local_part_dir -- check if directory for the part file
* exists
*/
int
replica_check_local_part_dir(struct pool_set *set, unsigned repn,
unsigned partn)
{
LOG(3, "set %p, repn %u, partn %u", set, repn, partn);
char *path = Strdup(PART(REP(set, repn), partn)->path);
const char *dir = dirname(path);
os_stat_t sb;
if (os_stat(dir, &sb) != 0 || !(sb.st_mode & S_IFDIR)) {
ERR(
"directory %s for part %u in replica %u does not exist or is not accessible",
path, partn, repn);
Free(path);
return -1;
}
Free(path);
return 0;
}
/*
* replica_check_part_dirs -- (internal) check if directories for part files
* exist
*/
int
replica_check_part_dirs(struct pool_set *set)
{
LOG(3, "set %p", set);
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
if (rep->remote != NULL)
/* skip remote replicas */
continue;
for (unsigned p = 0; p < rep->nparts; ++p) {
if (replica_check_local_part_dir(set, r, p))
return -1;
}
}
return 0;
}
/*
* replica_open_replica_part_files -- open all part files for a replica
*/
int
replica_open_replica_part_files(struct pool_set *set, unsigned repn)
{
LOG(3, "set %p, repn %u", set, repn);
struct pool_replica *rep = set->replica[repn];
for (unsigned p = 0; p < rep->nparts; ++p) {
/* skip already opened files */
if (rep->part[p].fd != -1)
continue;
if (util_part_open(&rep->part[p], 0, 0)) {
LOG(1, "part files open failed for replica %u, part %u",
repn, p);
errno = EINVAL;
goto err;
}
}
return 0;
err:
util_replica_fdclose(set->replica[repn]);
return -1;
}
/*
* replica_open_poolset_part_files -- open all part files for a poolset
*/
int
replica_open_poolset_part_files(struct pool_set *set)
{
LOG(3, "set %p", set);
for (unsigned r = 0; r < set->nreplicas; ++r) {
if (set->replica[r]->remote)
continue;
if (replica_open_replica_part_files(set, r)) {
LOG(1, "opening replica %u, part files failed", r);
goto err;
}
}
return 0;
err:
util_poolset_fdclose_always(set);
return -1;
}
/*
* pmempool_syncU -- synchronize replicas within a poolset
*/
#ifndef _WIN32
static inline
#endif
int
pmempool_syncU(const char *poolset, unsigned flags)
{
LOG(3, "poolset %s, flags %u", poolset, flags);
ASSERTne(poolset, NULL);
/* check if poolset has correct signature */
if (util_is_poolset_file(poolset) != 1) {
ERR("file is not a poolset file");
goto err;
}
/* check if flags are supported */
if (check_flags_sync(flags)) {
ERR("unsupported flags");
errno = EINVAL;
goto err;
}
/* open poolset file */
int fd = util_file_open(poolset, NULL, 0, O_RDONLY);
if (fd < 0) {
ERR("cannot open a poolset file");
goto err;
}
/* fill up pool_set structure */
struct pool_set *set = NULL;
if (util_poolset_parse(&set, poolset, fd)) {
ERR("parsing input poolset failed");
goto err_close_file;
}
if (set->nreplicas == 1) {
ERR("no replica(s) found in the pool set");
errno = EINVAL;
goto err_close_file;
}
if (set->remote && util_remote_load()) {
ERR("remote replication not available");
errno = ENOTSUP;
goto err_close_file;
}
/* sync all replicas */
if (replica_sync(set, NULL, flags)) {
LOG(1, "synchronization failed");
goto err_close_all;
}
util_poolset_close(set, DO_NOT_DELETE_PARTS);
os_close(fd);
return 0;
err_close_all:
util_poolset_close(set, DO_NOT_DELETE_PARTS);
err_close_file:
os_close(fd);
err:
if (errno == 0)
errno = EINVAL;
return -1;
}
#ifndef _WIN32
/*
* pmempool_sync -- synchronize replicas within a poolset
*/
int
pmempool_sync(const char *poolset, unsigned flags)
{
return pmempool_syncU(poolset, flags);
}
#else
/*
* pmempool_syncW -- synchronize replicas within a poolset in widechar
*/
int
pmempool_syncW(const wchar_t *poolset, unsigned flags)
{
char *path = util_toUTF8(poolset);
if (path == NULL) {
ERR("Invalid poolest file path.");
return -1;
}
int ret = pmempool_syncU(path, flags);
util_free_UTF8(path);
return ret;
}
#endif
/*
* pmempool_transformU -- alter poolset structure
*/
#ifndef _WIN32
static inline
#endif
int
pmempool_transformU(const char *poolset_src,
const char *poolset_dst, unsigned flags)
{
LOG(3, "poolset_src %s, poolset_dst %s, flags %u", poolset_src,
poolset_dst, flags);
ASSERTne(poolset_src, NULL);
ASSERTne(poolset_dst, NULL);
/* check if the source poolset has correct signature */
if (util_is_poolset_file(poolset_src) != 1) {
ERR("source file is not a poolset file");
goto err;
}
/* check if the destination poolset has correct signature */
if (util_is_poolset_file(poolset_dst) != 1) {
ERR("destination file is not a poolset file");
goto err;
}
/* check if flags are supported */
if (check_flags_transform(flags)) {
ERR("unsupported flags");
errno = EINVAL;
goto err;
}
/* open the source poolset file */
int fd_in = util_file_open(poolset_src, NULL, 0, O_RDONLY);
if (fd_in < 0) {
ERR("cannot open source poolset file");
goto err;
}
/* parse the source poolset file */
struct pool_set *set_in = NULL;
if (util_poolset_parse(&set_in, poolset_src, fd_in)) {
ERR("parsing source poolset failed");
os_close(fd_in);
goto err;
}
os_close(fd_in);
/* open the destination poolset file */
int fd_out = util_file_open(poolset_dst, NULL, 0, O_RDONLY);
if (fd_out < 0) {
ERR("cannot open destination poolset file");
goto err;
}
enum del_parts_mode del = DO_NOT_DELETE_PARTS;
/* parse the destination poolset file */
struct pool_set *set_out = NULL;
if (util_poolset_parse(&set_out, poolset_dst, fd_out)) {
ERR("parsing destination poolset failed");
os_close(fd_out);
goto err_free_poolin;
}
os_close(fd_out);
/* check if the source poolset is of a correct type */
enum pool_type ptype = pool_set_type(set_in);
if (ptype != POOL_TYPE_OBJ) {
ERR("transform is not supported for given pool type: %s",
pool_get_pool_type_str(ptype));
goto err_free_poolout;
}
/* load remote library if needed */
if (set_in->remote && util_remote_load()) {
ERR("remote replication not available");
goto err_free_poolout;
}
if (set_out->remote && util_remote_load()) {
ERR("remote replication not available");
goto err_free_poolout;
}
del = is_dry_run(flags) ? DO_NOT_DELETE_PARTS : DELETE_CREATED_PARTS;
/* transform poolset */
if (replica_transform(set_in, set_out, flags)) {
LOG(1, "transformation failed");
goto err_free_poolout;
}
util_poolset_close(set_in, DO_NOT_DELETE_PARTS);
util_poolset_close(set_out, DO_NOT_DELETE_PARTS);
return 0;
err_free_poolout:
util_poolset_close(set_out, del);
err_free_poolin:
util_poolset_close(set_in, DO_NOT_DELETE_PARTS);
err:
if (errno == 0)
errno = EINVAL;
return -1;
}
#ifndef _WIN32
/*
* pmempool_transform -- alter poolset structure
*/
int
pmempool_transform(const char *poolset_src,
const char *poolset_dst, unsigned flags)
{
return pmempool_transformU(poolset_src, poolset_dst, flags);
}
#else
/*
* pmempool_transformW -- alter poolset structure in widechar
*/
int
pmempool_transformW(const wchar_t *poolset_src,
const wchar_t *poolset_dst, unsigned flags)
{
char *path_src = util_toUTF8(poolset_src);
if (path_src == NULL) {
ERR("Invalid source poolest file path.");
return -1;
}
char *path_dst = util_toUTF8(poolset_dst);
if (path_dst == NULL) {
ERR("Invalid destination poolest file path.");
Free(path_src);
return -1;
}
int ret = pmempool_transformU(path_src, path_dst, flags);
util_free_UTF8(path_src);
util_free_UTF8(path_dst);
return ret;
}
#endif
| 62,618 | 24.0476 | 115 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/transform.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* transform.c -- a module for poolset transforming
*/
#include <stdio.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <dirent.h>
#include <assert.h>
#include "replica.h"
#include "out.h"
#include "file.h"
#include "os.h"
#include "libpmem.h"
#include "util_pmem.h"
/*
* poolset_compare_status - a helping structure for gathering corresponding
* replica numbers when comparing poolsets
*/
struct poolset_compare_status
{
unsigned nreplicas;
unsigned flags;
unsigned replica[];
};
/*
* type of transform operation to be done
*/
enum transform_op {
NOT_TRANSFORMABLE,
ADD_REPLICAS,
RM_REPLICAS,
ADD_HDRS,
RM_HDRS,
};
/*
* check_if_part_used_once -- (internal) check if the part is used only once in
* the rest of the poolset
*/
static int
check_if_part_used_once(struct pool_set *set, unsigned repn, unsigned partn)
{
LOG(3, "set %p, repn %u, partn %u", set, repn, partn);
struct pool_replica *rep = REP(set, repn);
char *path = util_part_realpath(PART(rep, partn)->path);
if (path == NULL) {
LOG(1, "cannot get absolute path for %s, replica %u, part %u",
PART(rep, partn)->path, repn, partn);
errno = 0;
path = strdup(PART(rep, partn)->path);
if (path == NULL) {
ERR("!strdup");
return -1;
}
}
int ret = 0;
for (unsigned r = repn; r < set->nreplicas; ++r) {
struct pool_replica *repr = set->replica[r];
/* skip remote replicas */
if (repr->remote != NULL)
continue;
/* avoid superfluous comparisons */
unsigned i = (r == repn) ? partn + 1 : 0;
for (unsigned p = i; p < repr->nparts; ++p) {
char *pathp = util_part_realpath(PART(repr, p)->path);
if (pathp == NULL) {
if (errno != ENOENT) {
ERR("realpath failed for %s, errno %d",
PART(repr, p)->path, errno);
ret = -1;
goto out;
}
LOG(1, "cannot get absolute path for %s,"
" replica %u, part %u",
PART(rep, partn)->path, repn,
partn);
pathp = strdup(PART(repr, p)->path);
errno = 0;
}
int result = util_compare_file_inodes(path, pathp);
if (result == 0) {
/* same file used multiple times */
ERR("some part file's path is"
" used multiple times");
ret = -1;
errno = EINVAL;
free(pathp);
goto out;
} else if (result < 0) {
ERR("comparing file inodes failed for %s and"
" %s", path, pathp);
ret = -1;
free(pathp);
goto out;
}
free(pathp);
}
}
out:
free(path);
return ret;
}
/*
* check_if_remote_replica_used_once -- (internal) check if remote replica is
* used only once in the rest of the
* poolset
*/
static int
check_if_remote_replica_used_once(struct pool_set *set, unsigned repn)
{
LOG(3, "set %p, repn %u", set, repn);
struct remote_replica *rep = REP(set, repn)->remote;
ASSERTne(rep, NULL);
for (unsigned r = repn + 1; r < set->nreplicas; ++r) {
/* skip local replicas */
if (REP(set, r)->remote == NULL)
continue;
struct remote_replica *repr = REP(set, r)->remote;
/* XXX: add comparing resolved addresses of the nodes */
if (strcmp(rep->node_addr, repr->node_addr) == 0 &&
strcmp(rep->pool_desc, repr->pool_desc) == 0) {
ERR("remote replica %u is used multiple times", repn);
errno = EINVAL;
return -1;
}
}
return 0;
}
/*
* check_paths -- (internal) check if directories for part files exist
* and if paths for part files do not repeat in the poolset
*/
static int
check_paths(struct pool_set *set)
{
LOG(3, "set %p", set);
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
if (rep->remote != NULL) {
if (check_if_remote_replica_used_once(set, r))
return -1;
} else {
for (unsigned p = 0; p < rep->nparts; ++p) {
if (replica_check_local_part_dir(set, r, p))
return -1;
if (check_if_part_used_once(set, r, p))
return -1;
}
}
}
return 0;
}
/*
* validate_args -- (internal) check whether passed arguments are valid
*/
static int
validate_args(struct pool_set *set_in, struct pool_set *set_out)
{
LOG(3, "set_in %p, set_out %p", set_in, set_out);
if (set_in->directory_based) {
ERR("transform of directory poolsets is not supported");
errno = EINVAL;
return -1;
}
/*
* check if all parts in the target poolset are large enough
* (now replication works only for pmemobj pools)
*/
if (replica_check_part_sizes(set_out, PMEMOBJ_MIN_POOL)) {
ERR("part sizes check failed");
return -1;
}
/*
* check if all directories for part files exist and if part files
* do not reoccur in the poolset
*/
if (check_paths(set_out))
return -1;
/*
* check if set_out has enough size, i.e. if the target poolset
* structure has enough capacity to accommodate the effective size of
* the source poolset
*/
ssize_t master_pool_size = replica_get_pool_size(set_in, 0);
if (master_pool_size < 0) {
ERR("getting pool size from master replica failed");
return -1;
}
if (set_out->poolsize < (size_t)master_pool_size) {
ERR("target poolset is too small");
errno = EINVAL;
return -1;
}
return 0;
}
/*
* create poolset_compare_status -- (internal) create structure for gathering
* status of poolset comparison
*/
static int
create_poolset_compare_status(struct pool_set *set,
struct poolset_compare_status **set_sp)
{
LOG(3, "set %p, set_sp %p", set, set_sp);
struct poolset_compare_status *set_s;
set_s = Zalloc(sizeof(struct poolset_compare_status)
+ set->nreplicas * sizeof(unsigned));
if (set_s == NULL) {
ERR("!Zalloc for poolset status");
return -1;
}
for (unsigned r = 0; r < set->nreplicas; ++r)
set_s->replica[r] = UNDEF_REPLICA;
set_s->nreplicas = set->nreplicas;
*set_sp = set_s;
return 0;
}
/*
* compare_parts -- (internal) check if two parts can be considered the same
*/
static int
compare_parts(struct pool_set_part *p1, struct pool_set_part *p2)
{
LOG(3, "p1 %p, p2 %p", p1, p2);
LOG(4, "p1->path: %s, p1->filesize: %lu", p1->path, p1->filesize);
LOG(4, "p2->path: %s, p2->filesize: %lu", p2->path, p2->filesize);
return strcmp(p1->path, p2->path) || (p1->filesize != p2->filesize);
}
/*
* compare_replicas -- (internal) check if two replicas are different
*/
static int
compare_replicas(struct pool_replica *r1, struct pool_replica *r2)
{
LOG(3, "r1 %p, r2 %p", r1, r2);
LOG(4, "r1->nparts: %u, r2->nparts: %u", r1->nparts, r2->nparts);
/* both replicas are local */
if (r1->remote == NULL && r2->remote == NULL) {
if (r1->nparts != r2->nparts)
return 1;
for (unsigned p = 0; p < r1->nparts; ++p) {
if (compare_parts(&r1->part[p], &r2->part[p]))
return 1;
}
return 0;
}
/* both replicas are remote */
if (r1->remote != NULL && r2->remote != NULL) {
return strcmp(r1->remote->node_addr, r2->remote->node_addr) ||
strcmp(r1->remote->pool_desc, r2->remote->pool_desc);
}
/* a remote and a local replicas */
return 1;
}
/*
* check_compare_poolsets_status -- (internal) find different replicas between
* two poolsets; for each replica which has
* a counterpart in the other poolset store
* the other replica's number in a helping
* structure
*/
static int
check_compare_poolsets_status(struct pool_set *set_in,
struct pool_set *set_out,
struct poolset_compare_status *set_in_s,
struct poolset_compare_status *set_out_s)
{
LOG(3, "set_in %p, set_out %p, set_in_s %p, set_out_s %p", set_in,
set_out, set_in_s, set_out_s);
for (unsigned ri = 0; ri < set_in->nreplicas; ++ri) {
struct pool_replica *rep_in = REP(set_in, ri);
for (unsigned ro = 0; ro < set_out->nreplicas; ++ro) {
struct pool_replica *rep_out = REP(set_out, ro);
LOG(1, "comparing rep_in %u with rep_out %u", ri, ro);
/* skip different replicas */
if (compare_replicas(rep_in, rep_out))
continue;
if (set_in_s->replica[ri] != UNDEF_REPLICA ||
set_out_s->replica[ro]
!= UNDEF_REPLICA) {
/* there are more than one counterparts */
ERR("there are more then one corresponding"
" replicas; cannot transform");
errno = EINVAL;
return -1;
}
set_in_s->replica[ri] = ro;
set_out_s->replica[ro] = ri;
}
}
return 0;
}
/*
* check_compare_poolset_options -- (internal) check poolset options
*/
static int
check_compare_poolsets_options(struct pool_set *set_in,
struct pool_set *set_out,
struct poolset_compare_status *set_in_s,
struct poolset_compare_status *set_out_s)
{
if (set_in->options & OPTION_SINGLEHDR)
set_in_s->flags |= OPTION_SINGLEHDR;
if (set_out->options & OPTION_SINGLEHDR)
set_out_s->flags |= OPTION_SINGLEHDR;
if ((set_in->options & OPTION_NOHDRS) ||
(set_out->options & OPTION_NOHDRS)) {
errno = EINVAL;
ERR(
"the NOHDRS poolset option is not supported in local poolset files");
return -1;
}
return 0;
}
/*
* compare_poolsets -- (internal) compare two poolsets; for each replica which
* has a counterpart in the other poolset store the other
* replica's number in a helping structure
*/
static int
compare_poolsets(struct pool_set *set_in, struct pool_set *set_out,
struct poolset_compare_status **set_in_s,
struct poolset_compare_status **set_out_s)
{
LOG(3, "set_in %p, set_out %p, set_in_s %p, set_out_s %p", set_in,
set_out, set_in_s, set_out_s);
if (create_poolset_compare_status(set_in, set_in_s))
return -1;
if (create_poolset_compare_status(set_out, set_out_s))
goto err_free_in;
if (check_compare_poolsets_status(set_in, set_out, *set_in_s,
*set_out_s))
goto err_free_out;
if (check_compare_poolsets_options(set_in, set_out, *set_in_s,
*set_out_s))
goto err_free_out;
return 0;
err_free_out:
Free(*set_out_s);
err_free_in:
Free(*set_in_s);
return -1;
}
/*
* replica_counterpart -- (internal) returns index of a counterpart replica
*/
static unsigned
replica_counterpart(unsigned repn,
struct poolset_compare_status *set_s)
{
return set_s->replica[repn];
}
/*
* are_poolsets_transformable -- (internal) check if poolsets can be transformed
* one into the other; also gather info about
* replicas's health
*/
static enum transform_op
identify_transform_operation(struct poolset_compare_status *set_in_s,
struct poolset_compare_status *set_out_s,
struct poolset_health_status *set_in_hs,
struct poolset_health_status *set_out_hs)
{
LOG(3, "set_in_s %p, set_out_s %p", set_in_s, set_out_s);
int has_replica_to_keep = 0;
int is_removing_replicas = 0;
int is_adding_replicas = 0;
/* check if there are replicas to be removed */
for (unsigned r = 0; r < set_in_s->nreplicas; ++r) {
unsigned c = replica_counterpart(r, set_in_s);
if (c != UNDEF_REPLICA) {
LOG(2, "replica %u has a counterpart %u", r,
set_in_s->replica[r]);
has_replica_to_keep = 1;
REP_HEALTH(set_out_hs, c)->pool_size =
REP_HEALTH(set_in_hs, r)->pool_size;
} else {
LOG(2, "replica %u has no counterpart", r);
is_removing_replicas = 1;
}
}
/* make sure we have at least one replica to keep */
if (!has_replica_to_keep) {
ERR("there must be at least one replica left");
return NOT_TRANSFORMABLE;
}
/* check if there are replicas to be added */
for (unsigned r = 0; r < set_out_s->nreplicas; ++r) {
if (replica_counterpart(r, set_out_s) == UNDEF_REPLICA) {
LOG(2, "Replica %u from output set has no counterpart",
r);
if (is_removing_replicas) {
ERR(
"adding and removing replicas at the same time is not allowed");
return NOT_TRANSFORMABLE;
}
REP_HEALTH(set_out_hs, r)->flags |= IS_BROKEN;
is_adding_replicas = 1;
}
}
/* check if there is anything to do */
if (!is_removing_replicas && !is_adding_replicas &&
(set_in_s->flags & OPTION_SINGLEHDR) ==
(set_out_s->flags & OPTION_SINGLEHDR)) {
ERR("both poolsets are equal");
return NOT_TRANSFORMABLE;
}
/* allow changing the SINGLEHDR option only as the sole operation */
if ((is_removing_replicas || is_adding_replicas) &&
(set_in_s->flags & OPTION_SINGLEHDR) !=
(set_out_s->flags & OPTION_SINGLEHDR)) {
ERR(
"cannot add/remove replicas and change the SINGLEHDR option at the same time");
return NOT_TRANSFORMABLE;
}
if (is_removing_replicas)
return RM_REPLICAS;
if (is_adding_replicas)
return ADD_REPLICAS;
if (set_out_s->flags & OPTION_SINGLEHDR)
return RM_HDRS;
if (set_in_s->flags & OPTION_SINGLEHDR)
return ADD_HDRS;
ASSERT(0);
return NOT_TRANSFORMABLE;
}
/*
* do_added_parts_exist -- (internal) check if any part of the replicas that are
* to be added (marked as broken) already exists
*/
static int
do_added_parts_exist(struct pool_set *set,
struct poolset_health_status *set_hs)
{
for (unsigned r = 0; r < set->nreplicas; ++r) {
/* skip unbroken (i.e. not being added) replicas */
if (!replica_is_replica_broken(r, set_hs))
continue;
struct pool_replica *rep = REP(set, r);
/* skip remote replicas */
if (rep->remote)
continue;
for (unsigned p = 0; p < rep->nparts; ++p) {
/* check if part file exists */
int oerrno = errno;
int exists = util_file_exists(rep->part[p].path);
if (exists < 0)
return -1;
if (exists && !rep->part[p].is_dev_dax) {
LOG(1, "part file %s exists",
rep->part[p].path);
return 1;
}
errno = oerrno;
}
}
return 0;
}
/*
* delete_replicas -- (internal) delete replicas which do not have their
* counterpart set in the helping status structure
*/
static int
delete_replicas(struct pool_set *set, struct poolset_compare_status *set_s)
{
LOG(3, "set %p, set_s %p", set, set_s);
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = REP(set, r);
if (replica_counterpart(r, set_s) == UNDEF_REPLICA) {
if (!rep->remote) {
if (util_replica_close_local(rep, r,
DELETE_ALL_PARTS))
return -1;
} else {
if (util_replica_close_remote(rep, r,
DELETE_ALL_PARTS))
return -1;
}
}
}
return 0;
}
/*
* copy_replica_data_fw -- (internal) copy data between replicas of two
* poolsets, starting from the beginning of the
* second part
*/
static void
copy_replica_data_fw(struct pool_set *set_dst, struct pool_set *set_src,
unsigned repn)
{
LOG(3, "set_in %p, set_out %p, repn %u", set_src, set_dst, repn);
ssize_t pool_size = replica_get_pool_size(set_src, repn);
if (pool_size < 0) {
LOG(1, "getting pool size from replica %u failed", repn);
pool_size = (ssize_t)set_src->poolsize;
}
size_t len = (size_t)pool_size - POOL_HDR_SIZE -
replica_get_part_data_len(set_src, repn, 0);
void *src = PART(REP(set_src, repn), 1)->addr;
void *dst = PART(REP(set_dst, repn), 1)->addr;
size_t count = len / POOL_HDR_SIZE;
while (count-- > 0) {
pmem_memcpy_persist(dst, src, POOL_HDR_SIZE);
src = ADDR_SUM(src, POOL_HDR_SIZE);
dst = ADDR_SUM(dst, POOL_HDR_SIZE);
}
}
/*
* copy_replica_data_bw -- (internal) copy data between replicas of two
* poolsets, starting from the end of the pool
*/
static void
copy_replica_data_bw(struct pool_set *set_dst, struct pool_set *set_src,
unsigned repn)
{
LOG(3, "set_in %p, set_out %p, repn %u", set_src, set_dst, repn);
ssize_t pool_size = replica_get_pool_size(set_src, repn);
if (pool_size < 0) {
LOG(1, "getting pool size from replica %u failed", repn);
pool_size = (ssize_t)set_src->poolsize;
}
size_t len = (size_t)pool_size - POOL_HDR_SIZE -
replica_get_part_data_len(set_src, repn, 0);
size_t count = len / POOL_HDR_SIZE;
void *src = ADDR_SUM(PART(REP(set_src, repn), 1)->addr, len);
void *dst = ADDR_SUM(PART(REP(set_dst, repn), 1)->addr, len);
while (count-- > 0) {
src = ADDR_SUM(src, -(ssize_t)POOL_HDR_SIZE);
dst = ADDR_SUM(dst, -(ssize_t)POOL_HDR_SIZE);
pmem_memcpy_persist(dst, src, POOL_HDR_SIZE);
}
}
/*
* create_missing_headers -- (internal) create headers for all parts but the
* first one
*/
static int
create_missing_headers(struct pool_set *set, unsigned repn)
{
LOG(3, "set %p, repn %u", set, repn);
struct pool_hdr *src_hdr = HDR(REP(set, repn), 0);
for (unsigned p = 1; p < set->replica[repn]->nhdrs; ++p) {
struct pool_attr attr;
util_pool_hdr2attr(&attr, src_hdr);
attr.features.incompat &= (uint32_t)(~POOL_FEAT_SINGLEHDR);
if (util_header_create(set, repn, p, &attr, 1) != 0) {
LOG(1, "part headers create failed for"
" replica %u part %u", repn, p);
errno = EINVAL;
return -1;
}
}
return 0;
}
/*
* update_replica_header -- (internal) update field values in the first header
* in the replica
*/
static void
update_replica_header(struct pool_set *set, unsigned repn)
{
LOG(3, "set %p, repn %u", set, repn);
struct pool_replica *rep = REP(set, repn);
struct pool_set_part *part = PART(REP(set, repn), 0);
struct pool_hdr *hdr = (struct pool_hdr *)part->hdr;
if (set->options & OPTION_SINGLEHDR) {
hdr->features.incompat |= POOL_FEAT_SINGLEHDR;
memcpy(hdr->next_part_uuid, hdr->uuid, POOL_HDR_UUID_LEN);
memcpy(hdr->prev_part_uuid, hdr->uuid, POOL_HDR_UUID_LEN);
} else {
hdr->features.incompat &= (uint32_t)(~POOL_FEAT_SINGLEHDR);
}
util_checksum(hdr, sizeof(*hdr), &hdr->checksum, 1,
POOL_HDR_CSUM_END_OFF(hdr));
util_persist_auto(rep->is_pmem, hdr, sizeof(*hdr));
}
/*
* fill_replica_struct_uuids -- (internal) gather all uuids required for the
* replica in the helper structure
*/
static int
fill_replica_struct_uuids(struct pool_set *set, unsigned repn)
{
LOG(3, "set %p, repn %u", set, repn);
struct pool_replica *rep = REP(set, repn);
memcpy(PART(rep, 0)->uuid, HDR(rep, 0)->uuid, POOL_HDR_UUID_LEN);
for (unsigned p = 1; p < rep->nhdrs; ++p) {
if (util_uuid_generate(rep->part[p].uuid) < 0) {
ERR("cannot generate part UUID");
errno = EINVAL;
return -1;
}
}
return 0;
}
/*
* update_uuids -- (internal) update uuids in all headers in the replica
*/
static void
update_uuids(struct pool_set *set, unsigned repn)
{
LOG(3, "set %p, repn %u", set, repn);
struct pool_replica *rep = REP(set, repn);
struct pool_hdr *hdr0 = HDR(rep, 0);
for (unsigned p = 0; p < rep->nhdrs; ++p) {
struct pool_hdr *hdrp = HDR(rep, p);
memcpy(hdrp->next_part_uuid, PARTN(rep, p)->uuid,
POOL_HDR_UUID_LEN);
memcpy(hdrp->prev_part_uuid, PARTP(rep, p)->uuid,
POOL_HDR_UUID_LEN);
memcpy(hdrp->next_repl_uuid, hdr0->next_repl_uuid,
POOL_HDR_UUID_LEN);
memcpy(hdrp->prev_repl_uuid, hdr0->prev_repl_uuid,
POOL_HDR_UUID_LEN);
memcpy(hdrp->poolset_uuid, hdr0->poolset_uuid,
POOL_HDR_UUID_LEN);
util_checksum(hdrp, sizeof(*hdrp), &hdrp->checksum, 1,
POOL_HDR_CSUM_END_OFF(hdrp));
util_persist(PART(rep, p)->is_dev_dax, hdrp, sizeof(*hdrp));
}
}
/*
* copy_part_fds -- (internal) copy poolset part file descriptors between
* two poolsets
*/
static void
copy_part_fds(struct pool_set *set_dst, struct pool_set *set_src)
{
ASSERTeq(set_src->nreplicas, set_dst->nreplicas);
for (unsigned r = 0; r < set_dst->nreplicas; ++r) {
ASSERTeq(REP(set_src, r)->nparts, REP(set_dst, r)->nparts);
for (unsigned p = 0; p < REP(set_dst, r)->nparts; ++p) {
PART(REP(set_dst, r), p)->fd =
PART(REP(set_src, r), p)->fd;
}
}
}
/*
* remove_hdrs_replica -- (internal) remove headers from the replica
*/
static int
remove_hdrs_replica(struct pool_set *set_in, struct pool_set *set_out,
unsigned repn)
{
LOG(3, "set %p, repn %u", set_in, repn);
int ret = 0;
/* open all part files of the input replica */
if (replica_open_replica_part_files(set_in, repn)) {
LOG(1, "opening replica %u, part files failed", repn);
ret = -1;
goto out;
}
/* share part file descriptors between poolset structures */
copy_part_fds(set_out, set_in);
/* map the whole input replica */
if (util_replica_open(set_in, repn, MAP_SHARED)) {
LOG(1, "opening input replica failed: replica %u", repn);
ret = -1;
goto out_close;
}
/* map the whole output replica */
if (util_replica_open(set_out, repn, MAP_SHARED)) {
LOG(1, "opening output replica failed: replica %u", repn);
ret = -1;
goto out_unmap_in;
}
/* move data between the two mappings of the replica */
if (REP(set_in, repn)->nparts > 1)
copy_replica_data_fw(set_out, set_in, repn);
/* make changes to the first part's header */
update_replica_header(set_out, repn);
util_replica_close(set_out, repn);
out_unmap_in:
util_replica_close(set_in, repn);
out_close:
util_replica_fdclose(REP(set_in, repn));
out:
return ret;
}
/*
* add_hdrs_replica -- (internal) add lacking headers to the replica
*
* when the operation fails and returns -1, the replica remains untouched
*/
static int
add_hdrs_replica(struct pool_set *set_in, struct pool_set *set_out,
unsigned repn)
{
LOG(3, "set %p, repn %u", set_in, repn);
int ret = 0;
/* open all part files of the input replica */
if (replica_open_replica_part_files(set_in, repn)) {
LOG(1, "opening replica %u, part files failed", repn);
ret = -1;
goto out;
}
/* share part file descriptors between poolset structures */
copy_part_fds(set_out, set_in);
/* map the whole input replica */
if (util_replica_open(set_in, repn, MAP_SHARED)) {
LOG(1, "opening input replica failed: replica %u", repn);
ret = -1;
goto out_close;
}
/* map the whole output replica */
if (util_replica_open(set_out, repn, MAP_SHARED)) {
LOG(1, "opening output replica failed: replica %u", repn);
ret = -1;
goto out_unmap_in;
}
/* generate new uuids for lacking headers */
if (fill_replica_struct_uuids(set_out, repn)) {
LOG(1, "generating lacking uuids for parts failed: replica %u",
repn);
ret = -1;
goto out_unmap_out;
}
/* copy data between the two mappings of the replica */
if (REP(set_in, repn)->nparts > 1)
copy_replica_data_bw(set_out, set_in, repn);
/* create the missing headers */
if (create_missing_headers(set_out, repn)) {
LOG(1, "creating lacking headers failed: replica %u", repn);
/*
* copy the data back, so we could fall back to the original
* state
*/
if (REP(set_in, repn)->nparts > 1)
copy_replica_data_fw(set_in, set_out, repn);
ret = -1;
goto out_unmap_out;
}
/* make changes to the first part's header */
update_replica_header(set_out, repn);
/* store new uuids in all headers and update linkage in the replica */
update_uuids(set_out, repn);
out_unmap_out:
util_replica_close(set_out, repn);
out_unmap_in:
util_replica_close(set_in, repn);
out_close:
util_replica_fdclose(REP(set_in, repn));
out:
return ret;
}
/*
* remove_hdrs -- (internal) transform a poolset without the SINGLEHDR option
* (with headers) into a poolset with the SINGLEHDR option
* (without headers)
*/
static int
remove_hdrs(struct pool_set *set_in, struct pool_set *set_out,
struct poolset_health_status *set_in_hs, unsigned flags)
{
LOG(3, "set_in %p, set_out %p, set_in_hs %p, flags %u",
set_in, set_out, set_in_hs, flags);
for (unsigned r = 0; r < set_in->nreplicas; ++r) {
if (remove_hdrs_replica(set_in, set_out, r)) {
LOG(1, "removing headers from replica %u failed", r);
/* mark all previous replicas as damaged */
while (--r < set_in->nreplicas)
REP_HEALTH(set_in_hs, r)->flags |= IS_BROKEN;
return -1;
}
}
return 0;
}
/*
* add_hdrs -- (internal) transform a poolset with the SINGLEHDR option (without
* headers) into a poolset without the SINGLEHDR option (with
* headers)
*/
static int
add_hdrs(struct pool_set *set_in, struct pool_set *set_out,
struct poolset_health_status *set_in_hs,
unsigned flags)
{
LOG(3, "set_in %p, set_out %p, set_in_hs %p, flags %u",
set_in, set_out, set_in_hs, flags);
for (unsigned r = 0; r < set_in->nreplicas; ++r) {
if (add_hdrs_replica(set_in, set_out, r)) {
LOG(1, "adding headers to replica %u failed", r);
/* mark all previous replicas as damaged */
while (--r < set_in->nreplicas)
REP_HEALTH(set_in_hs, r)->flags |= IS_BROKEN;
return -1;
}
}
return 0;
}
/*
* transform_replica -- transforming one poolset into another
*/
int
replica_transform(struct pool_set *set_in, struct pool_set *set_out,
unsigned flags)
{
LOG(3, "set_in %p, set_out %p", set_in, set_out);
int ret = 0;
/* validate user arguments */
if (validate_args(set_in, set_out))
return -1;
/* check if the source poolset is healthy */
struct poolset_health_status *set_in_hs = NULL;
if (replica_check_poolset_health(set_in, &set_in_hs,
0 /* called from transform */, flags)) {
ERR("source poolset health check failed");
return -1;
}
if (!replica_is_poolset_healthy(set_in_hs)) {
ERR("source poolset is broken");
ret = -1;
errno = EINVAL;
goto free_hs_in;
}
struct poolset_health_status *set_out_hs = NULL;
if (replica_create_poolset_health_status(set_out, &set_out_hs)) {
ERR("creating poolset health status failed");
ret = -1;
goto free_hs_in;
}
/* check if the poolsets are transformable */
struct poolset_compare_status *set_in_cs = NULL;
struct poolset_compare_status *set_out_cs = NULL;
if (compare_poolsets(set_in, set_out, &set_in_cs, &set_out_cs)) {
ERR("comparing poolsets failed");
ret = -1;
goto free_hs_out;
}
enum transform_op operation = identify_transform_operation(set_in_cs,
set_out_cs, set_in_hs, set_out_hs);
if (operation == NOT_TRANSFORMABLE) {
LOG(1, "poolsets are not transformable");
ret = -1;
errno = EINVAL;
goto free_cs;
}
if (operation == RM_HDRS) {
if (!is_dry_run(flags) &&
remove_hdrs(set_in, set_out, set_in_hs,
flags)) {
ERR("removing headers failed; falling back to the "
"input poolset");
if (replica_sync(set_in, set_in_hs,
flags | IS_TRANSFORMED)) {
LOG(1, "falling back to the input poolset "
"failed");
} else {
LOG(1, "falling back to the input poolset "
"succeeded");
}
ret = -1;
}
goto free_cs;
}
if (operation == ADD_HDRS) {
if (!is_dry_run(flags) &&
add_hdrs(set_in, set_out, set_in_hs, flags)) {
ERR("adding headers failed; falling back to the "
"input poolset");
if (replica_sync(set_in, set_in_hs,
flags | IS_TRANSFORMED)) {
LOG(1, "falling back to the input poolset "
"failed");
} else {
LOG(1, "falling back to the input poolset "
"succeeded");
}
ret = -1;
}
goto free_cs;
}
if (operation == ADD_REPLICAS) {
/*
* check if any of the parts that are to be added already exists
*/
if (do_added_parts_exist(set_out, set_out_hs)) {
ERR("some parts being added already exist");
ret = -1;
errno = EINVAL;
goto free_cs;
}
}
/* signal that sync is called by transform */
if (replica_sync(set_out, set_out_hs, flags | IS_TRANSFORMED)) {
ret = -1;
goto free_cs;
}
if (operation == RM_REPLICAS) {
if (!is_dry_run(flags) && delete_replicas(set_in, set_in_cs))
ret = -1;
}
free_cs:
Free(set_in_cs);
Free(set_out_cs);
free_hs_out:
replica_free_poolset_health_status(set_out_hs);
free_hs_in:
replica_free_poolset_health_status(set_in_hs);
return ret;
}
| 29,028 | 26.9125 | 81 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/check_pool_hdr.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check_pool_hdr.c -- pool header check
*/
#include <stdio.h>
#include <inttypes.h>
#include <sys/mman.h>
#include <endian.h>
#include "out.h"
#include "util_pmem.h"
#include "libpmempool.h"
#include "libpmem.h"
#include "pmempool.h"
#include "pool.h"
#include "set.h"
#include "check_util.h"
#define NO_COMMON_POOLSET_UUID "%sno common pool_hdr.poolset_uuid"
#define INVALID_UUID "%sinvalid pool_hdr.uuid"
#define INVALID_CHECKSUM "%sinvalid pool_hdr.checksum"
enum question {
Q_DEFAULT_SIGNATURE,
Q_DEFAULT_MAJOR,
Q_DEFAULT_COMPAT_FEATURES,
Q_DEFAULT_INCOMPAT_FEATURES,
Q_DEFAULT_RO_COMPAT_FEATURES,
Q_ZERO_UNUSED_AREA,
Q_ARCH_FLAGS,
Q_CRTIME,
Q_CHECKSUM,
Q_POOLSET_UUID_SET,
Q_POOLSET_UUID_FROM_BTT_INFO,
Q_POOLSET_UUID_REGENERATE,
Q_UUID_SET,
Q_UUID_REGENERATE,
Q_NEXT_PART_UUID_SET,
Q_PREV_PART_UUID_SET,
Q_NEXT_REPL_UUID_SET,
Q_PREV_REPL_UUID_SET
};
/*
* pool_hdr_possible_type -- (internal) return possible type of pool
*/
static enum pool_type
pool_hdr_possible_type(PMEMpoolcheck *ppc)
{
if (pool_blk_get_first_valid_arena(ppc->pool, &ppc->pool->bttc))
return POOL_TYPE_BLK;
return POOL_TYPE_UNKNOWN;
}
/*
* pool_hdr_valid -- (internal) return true if pool header is valid
*/
static int
pool_hdr_valid(struct pool_hdr *hdrp)
{
return !util_is_zeroed((void *)hdrp, sizeof(*hdrp)) &&
util_checksum(hdrp, sizeof(*hdrp), &hdrp->checksum, 0,
POOL_HDR_CSUM_END_OFF(hdrp));
}
/*
* pool_supported -- (internal) check if pool type is supported
*/
static int
pool_supported(enum pool_type type)
{
switch (type) {
case POOL_TYPE_LOG:
return 1;
case POOL_TYPE_BLK:
return 1;
case POOL_TYPE_CTO:
return 1;
case POOL_TYPE_OBJ:
default:
return 0;
}
}
/*
* pool_hdr_preliminary_check -- (internal) check pool header checksum and pool
* parameters
*/
static int
pool_hdr_preliminary_check(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
CHECK_INFO(ppc, "%schecking pool header", loc->prefix);
if (util_is_zeroed((void *)&loc->hdr, sizeof(loc->hdr))) {
if (CHECK_IS_NOT(ppc, REPAIR)) {
check_end(ppc->data);
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, "%sempty pool hdr", loc->prefix);
}
} else if (loc->hdr_valid) {
enum pool_type type = pool_hdr_get_type(&loc->hdr);
if (type == POOL_TYPE_UNKNOWN) {
if (CHECK_IS_NOT(ppc, REPAIR)) {
check_end(ppc->data);
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, "%sinvalid signature",
loc->prefix);
}
CHECK_INFO(ppc, "%sinvalid signature", loc->prefix);
} else {
/* valid check sum */
CHECK_INFO(ppc, "%spool header correct",
loc->prefix);
loc->step = CHECK_STEP_COMPLETE;
return 0;
}
} else if (CHECK_IS_NOT(ppc, REPAIR)) {
check_end(ppc->data);
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, "%sincorrect pool header", loc->prefix);
} else {
CHECK_INFO(ppc, "%sincorrect pool header", loc->prefix);
}
ASSERT(CHECK_IS(ppc, REPAIR));
if (ppc->pool->params.type == POOL_TYPE_UNKNOWN) {
ppc->pool->params.type = pool_hdr_possible_type(ppc);
if (ppc->pool->params.type == POOL_TYPE_UNKNOWN) {
ppc->result = CHECK_RESULT_CANNOT_REPAIR;
return CHECK_ERR(ppc, "cannot determine pool type");
}
}
if (!pool_supported(ppc->pool->params.type)) {
ppc->result = CHECK_RESULT_CANNOT_REPAIR;
return CHECK_ERR(ppc, "the repair of %s pools is not supported",
pool_get_pool_type_str(ppc->pool->params.type));
}
return 0;
}
/*
* pool_hdr_default_check -- (internal) check some default values in pool header
*/
static int
pool_hdr_default_check(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
ASSERT(CHECK_IS(ppc, REPAIR));
struct pool_hdr def_hdr;
pool_hdr_default(ppc->pool->params.type, &def_hdr);
if (memcmp(loc->hdr.signature, def_hdr.signature, POOL_HDR_SIG_LEN)) {
CHECK_ASK(ppc, Q_DEFAULT_SIGNATURE,
"%spool_hdr.signature is not valid.|Do you want to set "
"it to %.8s?", loc->prefix, def_hdr.signature);
}
if (loc->hdr.major != def_hdr.major) {
CHECK_ASK(ppc, Q_DEFAULT_MAJOR,
"%spool_hdr.major is not valid.|Do you want to set it "
"to default value 0x%x?", loc->prefix, def_hdr.major);
}
features_t unknown = util_get_unknown_features(
loc->hdr.features, def_hdr.features);
if (unknown.compat) {
CHECK_ASK(ppc, Q_DEFAULT_COMPAT_FEATURES,
"%spool_hdr.features.compat is not valid.|Do you want "
"to set it to default value 0x%x?", loc->prefix,
def_hdr.features.compat);
}
if (unknown.incompat) {
CHECK_ASK(ppc, Q_DEFAULT_INCOMPAT_FEATURES,
"%spool_hdr.features.incompat is not valid.|Do you "
"want to set it to default value 0x%x?", loc->prefix,
def_hdr.features.incompat);
}
if (unknown.ro_compat) {
CHECK_ASK(ppc, Q_DEFAULT_RO_COMPAT_FEATURES,
"%spool_hdr.features.ro_compat is not valid.|Do you "
"want to set it to default value 0x%x?", loc->prefix,
def_hdr.features.ro_compat);
}
if (!util_is_zeroed(loc->hdr.unused, sizeof(loc->hdr.unused))) {
CHECK_ASK(ppc, Q_ZERO_UNUSED_AREA,
"%sunused area is not filled by zeros.|Do you want to "
"fill it up?", loc->prefix);
}
return check_questions_sequence_validate(ppc);
}
/*
* pool_hdr_default_fix -- (internal) fix some default values in pool header
*/
static int
pool_hdr_default_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question,
void *context)
{
LOG(3, NULL);
ASSERTne(loc, NULL);
struct pool_hdr def_hdr;
pool_hdr_default(ppc->pool->params.type, &def_hdr);
switch (question) {
case Q_DEFAULT_SIGNATURE:
CHECK_INFO(ppc, "%ssetting pool_hdr.signature to %.8s",
loc->prefix, def_hdr.signature);
memcpy(&loc->hdr.signature, &def_hdr.signature,
POOL_HDR_SIG_LEN);
break;
case Q_DEFAULT_MAJOR:
CHECK_INFO(ppc, "%ssetting pool_hdr.major to 0x%x", loc->prefix,
def_hdr.major);
loc->hdr.major = def_hdr.major;
break;
case Q_DEFAULT_COMPAT_FEATURES:
CHECK_INFO(ppc, "%ssetting pool_hdr.features.compat to 0x%x",
loc->prefix, def_hdr.features.compat);
loc->hdr.features.compat = def_hdr.features.compat;
break;
case Q_DEFAULT_INCOMPAT_FEATURES:
CHECK_INFO(ppc, "%ssetting pool_hdr.features.incompat to 0x%x",
loc->prefix, def_hdr.features.incompat);
loc->hdr.features.incompat = def_hdr.features.incompat;
break;
case Q_DEFAULT_RO_COMPAT_FEATURES:
CHECK_INFO(ppc, "%ssetting pool_hdr.features.ro_compat to 0x%x",
loc->prefix, def_hdr.features.ro_compat);
loc->hdr.features.ro_compat = def_hdr.features.ro_compat;
break;
case Q_ZERO_UNUSED_AREA:
CHECK_INFO(ppc, "%ssetting pool_hdr.unused to zeros",
loc->prefix);
memset(loc->hdr.unused, 0, sizeof(loc->hdr.unused));
break;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
/*
* pool_hdr_quick_check -- (internal) end check if pool header is valid
*/
static int
pool_hdr_quick_check(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
if (pool_hdr_valid(loc->hdrp))
loc->step = CHECK_STEP_COMPLETE;
return 0;
}
/*
* pool_hdr_nondefault -- (internal) validate custom value fields
*/
static int
pool_hdr_nondefault(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
if (loc->hdr.crtime > (uint64_t)ppc->pool->set_file->mtime) {
const char * const error = "%spool_hdr.crtime is not valid";
if (CHECK_IS_NOT(ppc, REPAIR)) {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, error, loc->prefix);
} else if (CHECK_IS_NOT(ppc, ADVANCED)) {
ppc->result = CHECK_RESULT_CANNOT_REPAIR;
CHECK_INFO(ppc, "%s" REQUIRE_ADVANCED, loc->prefix);
return CHECK_ERR(ppc, error, loc->prefix);
}
CHECK_ASK(ppc, Q_CRTIME,
"%spool_hdr.crtime is not valid.|Do you want to set it "
"to file's modtime [%s]?", loc->prefix,
check_get_time_str(ppc->pool->set_file->mtime));
}
if (loc->valid_part_hdrp &&
memcmp(&loc->valid_part_hdrp->arch_flags,
&loc->hdr.arch_flags,
sizeof(struct arch_flags)) != 0) {
const char * const error = "%spool_hdr.arch_flags is not valid";
if (CHECK_IS_NOT(ppc, REPAIR)) {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, error, loc->prefix);
}
CHECK_ASK(ppc, Q_ARCH_FLAGS,
"%spool_hdr.arch_flags is not valid.|Do you want to "
"copy it from a valid part?", loc->prefix);
}
return check_questions_sequence_validate(ppc);
}
/*
* pool_hdr_nondefault_fix -- (internal) fix custom value fields
*/
static int
pool_hdr_nondefault_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question,
void *context)
{
LOG(3, NULL);
ASSERTne(loc, NULL);
uint64_t *flags = NULL;
switch (question) {
case Q_CRTIME:
CHECK_INFO(ppc, "%ssetting pool_hdr.crtime to file's modtime: "
"%s", loc->prefix,
check_get_time_str(ppc->pool->set_file->mtime));
util_convert2h_hdr_nocheck(&loc->hdr);
loc->hdr.crtime = (uint64_t)ppc->pool->set_file->mtime;
util_convert2le_hdr(&loc->hdr);
break;
case Q_ARCH_FLAGS:
flags = (uint64_t *)&loc->valid_part_hdrp->arch_flags;
CHECK_INFO(ppc, "%ssetting pool_hdr.arch_flags to 0x%08" PRIx64
"%08" PRIx64, loc->prefix, flags[0], flags[1]);
util_convert2h_hdr_nocheck(&loc->hdr);
memcpy(&loc->hdr.arch_flags, &loc->valid_part_hdrp->arch_flags,
sizeof(struct arch_flags));
util_convert2le_hdr(&loc->hdr);
break;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
/*
* pool_hdr_poolset_uuid -- (internal) check poolset_uuid field
*/
static int
pool_hdr_poolset_uuid_find(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
/*
* If the pool header is valid and there is not other parts or replicas
* in the poolset its poolset_uuid is also valid.
*/
if (loc->hdr_valid && loc->single_repl && loc->single_part)
return 0;
if (loc->replica != 0 || loc->part != 0)
goto after_lookup;
/* for blk pool we can take the UUID from BTT Info header */
if (ppc->pool->params.type == POOL_TYPE_BLK && ppc->pool->bttc.valid) {
loc->valid_puuid = &ppc->pool->bttc.btt_info.parent_uuid;
if (uuidcmp(loc->hdr.poolset_uuid, *loc->valid_puuid) != 0) {
CHECK_ASK(ppc, Q_POOLSET_UUID_FROM_BTT_INFO,
"%sinvalid pool_hdr.poolset_uuid.|Do you want "
"to set it to %s from BTT Info?", loc->prefix,
check_get_uuid_str(*loc->valid_puuid));
goto exit_question;
}
}
if (loc->single_part && loc->single_repl) {
/*
* If the pool is not blk pool or BTT Info header is invalid
* there is no other way to validate poolset uuid.
*/
return 0;
}
/*
* if all valid poolset part files have the same poolset uuid it is
* the valid poolset uuid
* if all part files have the same poolset uuid it is valid poolset uuid
*/
struct pool_set *poolset = ppc->pool->set_file->poolset;
unsigned nreplicas = poolset->nreplicas;
uuid_t *common_puuid = loc->valid_puuid;
for (unsigned r = 0; r < nreplicas; r++) {
struct pool_replica *rep = REP(poolset, r);
for (unsigned p = 0; p < rep->nhdrs; p++) {
struct pool_hdr *hdr = HDR(rep, p);
/*
* find poolset uuid if it is the same for all part
* files
*/
if (common_puuid == NULL) {
if (r == 0 && p == 0) {
common_puuid = &hdr->poolset_uuid;
}
} else if (uuidcmp(*common_puuid, hdr->poolset_uuid)
!= 0) {
common_puuid = NULL;
}
if (!pool_hdr_valid(hdr))
continue;
/*
* find poolset uuid if it is the same for all valid
* part files
*/
if (loc->valid_puuid == NULL) {
loc->valid_puuid = &hdr->poolset_uuid;
} else if (uuidcmp(*loc->valid_puuid, hdr->poolset_uuid)
!= 0) {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, "the poolset contains "
"part files from various poolsets");
}
}
}
if (!loc->valid_puuid && common_puuid)
loc->valid_puuid = common_puuid;
if (loc->valid_puuid)
goto after_lookup;
if (CHECK_IS_NOT(ppc, REPAIR)) {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, NO_COMMON_POOLSET_UUID, loc->prefix);
} else if (CHECK_IS_NOT(ppc, ADVANCED)) {
ppc->result = CHECK_RESULT_CANNOT_REPAIR;
CHECK_INFO(ppc, "%s" REQUIRE_ADVANCED, loc->prefix);
return CHECK_ERR(ppc, NO_COMMON_POOLSET_UUID, loc->prefix);
} else {
CHECK_ASK(ppc, Q_POOLSET_UUID_REGENERATE, NO_COMMON_POOLSET_UUID
".|Do you want to regenerate pool_hdr.poolset_uuid?",
loc->prefix);
goto exit_question;
}
after_lookup:
if (loc->valid_puuid) {
if (uuidcmp(*loc->valid_puuid, loc->hdr.poolset_uuid) != 0) {
if (CHECK_IS_NOT(ppc, REPAIR)) {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, "%sinvalid "
"pool_hdr.poolset_uuid", loc->prefix);
}
CHECK_ASK(ppc, Q_POOLSET_UUID_SET, "%sinvalid "
"pool_hdr.poolset_uuid.|Do you want to set "
"it to %s from a valid part file?", loc->prefix,
check_get_uuid_str(*loc->valid_puuid));
}
}
exit_question:
return check_questions_sequence_validate(ppc);
}
/*
* pool_hdr_poolset_uuid_fix -- (internal) fix poolset_uuid field
*/
static int
pool_hdr_poolset_uuid_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question,
void *context)
{
LOG(3, NULL);
ASSERTne(loc, NULL);
switch (question) {
case Q_POOLSET_UUID_SET:
case Q_POOLSET_UUID_FROM_BTT_INFO:
CHECK_INFO(ppc, "%ssetting pool_hdr.poolset_uuid to %s",
loc->prefix, check_get_uuid_str(*loc->valid_puuid));
memcpy(loc->hdr.poolset_uuid, loc->valid_puuid,
POOL_HDR_UUID_LEN);
if (question == Q_POOLSET_UUID_SET)
ppc->pool->uuid_op = UUID_NOT_FROM_BTT;
else
ppc->pool->uuid_op = UUID_FROM_BTT;
break;
case Q_POOLSET_UUID_REGENERATE:
if (util_uuid_generate(loc->hdr.poolset_uuid) != 0) {
ppc->result = CHECK_RESULT_INTERNAL_ERROR;
return CHECK_ERR(ppc, "%suuid generation failed",
loc->prefix);
}
CHECK_INFO(ppc, "%ssetting pool_hdr.pooset_uuid to %s",
loc->prefix,
check_get_uuid_str(loc->hdr.poolset_uuid));
ppc->pool->uuid_op = UUID_NOT_FROM_BTT;
break;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
#define COMPARE_TO_FIRST_PART_ONLY 2
/*
* pool_hdr_uuid_find -- (internal) check UUID value
*/
static int
pool_hdr_uuid_find(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
/*
* If the pool header is valid and there is not other parts or replicas
* in the poolset its uuid is also valid.
*/
if (loc->hdr_valid && loc->single_repl && loc->single_part)
return 0;
int hdrs_valid[] = {
loc->next_part_hdr_valid, loc->prev_part_hdr_valid,
loc->next_repl_hdr_valid, loc->prev_repl_hdr_valid};
uuid_t *uuids[] = {
&loc->next_part_hdrp->prev_part_uuid,
&loc->prev_part_hdrp->next_part_uuid,
&loc->next_repl_hdrp->prev_repl_uuid,
&loc->prev_repl_hdrp->next_repl_uuid
};
/*
* if all valid poolset part files have the same uuid links to this part
* file it is valid uuid
* if all links have the same uuid and it is single file pool it is also
* the valid uuid
*/
loc->valid_uuid = NULL;
if (loc->hdr_valid)
loc->valid_uuid = &loc->hdr.uuid;
uuid_t *common_uuid = uuids[0];
COMPILE_ERROR_ON(ARRAY_SIZE(uuids) != ARRAY_SIZE(hdrs_valid));
COMPILE_ERROR_ON(COMPARE_TO_FIRST_PART_ONLY >= ARRAY_SIZE(uuids));
for (unsigned i = 0; i < ARRAY_SIZE(uuids); ++i) {
if (i > 0 && common_uuid != NULL) {
if (uuidcmp(*common_uuid, *uuids[i]) != 0) {
common_uuid = NULL;
}
}
if (i >= COMPARE_TO_FIRST_PART_ONLY && loc->part != 0)
continue;
if (!hdrs_valid[i])
continue;
if (!loc->valid_uuid) {
loc->valid_uuid = uuids[i];
} else if (uuidcmp(*loc->valid_uuid, *uuids[i]) != 0) {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, "%sambiguous pool_hdr.uuid",
loc->prefix);
}
}
if (!loc->valid_uuid && common_uuid)
loc->valid_uuid = common_uuid;
if (loc->valid_uuid != NULL) {
if (uuidcmp(*loc->valid_uuid, loc->hdr.uuid) != 0) {
CHECK_ASK(ppc, Q_UUID_SET, INVALID_UUID ".|Do you want "
"to set it to %s from a valid part file?",
loc->prefix,
check_get_uuid_str(*loc->valid_uuid));
}
} else if (CHECK_IS(ppc, ADVANCED)) {
CHECK_ASK(ppc, Q_UUID_REGENERATE, INVALID_UUID ".|Do you want "
"to regenerate it?", loc->prefix);
} else if (CHECK_IS(ppc, REPAIR)) {
ppc->result = CHECK_RESULT_CANNOT_REPAIR;
CHECK_INFO(ppc, "%s" REQUIRE_ADVANCED, loc->prefix);
return CHECK_ERR(ppc, INVALID_UUID, loc->prefix);
} else {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, INVALID_UUID, loc->prefix);
}
return check_questions_sequence_validate(ppc);
}
/*
* pool_hdr_uuid_fix -- (internal) fix UUID value
*/
static int
pool_hdr_uuid_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question,
void *context)
{
LOG(3, NULL);
ASSERTne(loc, NULL);
switch (question) {
case Q_UUID_SET:
CHECK_INFO(ppc, "%ssetting pool_hdr.uuid to %s", loc->prefix,
check_get_uuid_str(*loc->valid_uuid));
memcpy(loc->hdr.uuid, loc->valid_uuid, POOL_HDR_UUID_LEN);
break;
case Q_UUID_REGENERATE:
if (util_uuid_generate(loc->hdr.uuid) != 0) {
ppc->result = CHECK_RESULT_INTERNAL_ERROR;
return CHECK_ERR(ppc, "%suuid generation failed",
loc->prefix);
}
CHECK_INFO(ppc, "%ssetting pool_hdr.uuid to %s", loc->prefix,
check_get_uuid_str(loc->hdr.uuid));
break;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
/*
* pool_hdr_uuid_links -- (internal) check UUID links values
*/
static int
pool_hdr_uuid_links(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
/*
* If the pool header is valid and there is not other parts or replicas
* in the poolset its uuid links are also valid.
*/
if (loc->hdr_valid && loc->single_repl && loc->single_part)
return 0;
uuid_t *links[] = {
&loc->hdr.next_part_uuid, &loc->hdr.prev_part_uuid,
&loc->hdr.next_repl_uuid, &loc->hdr.prev_repl_uuid};
uuid_t *uuids[] = {
&loc->next_part_hdrp->uuid, &loc->prev_part_hdrp->uuid,
&loc->next_repl_hdrp->uuid, &loc->prev_repl_hdrp->uuid
};
uint32_t questions[] = {
Q_NEXT_PART_UUID_SET, Q_PREV_PART_UUID_SET,
Q_NEXT_REPL_UUID_SET, Q_PREV_REPL_UUID_SET
};
const char *fields[] = {
"pool_hdr.next_part_uuid", "pool_hdr.prev_part_uuid",
"pool_hdr.next_repl_uuid", "pool_hdr.prev_repl_uuid"
};
COMPILE_ERROR_ON(ARRAY_SIZE(links) != ARRAY_SIZE(uuids));
COMPILE_ERROR_ON(ARRAY_SIZE(links) != ARRAY_SIZE(questions));
COMPILE_ERROR_ON(ARRAY_SIZE(links) != ARRAY_SIZE(fields));
for (uint64_t i = 0; i < ARRAY_SIZE(links); ++i) {
if (uuidcmp(*links[i], *uuids[i]) == 0)
continue;
if (CHECK_IS(ppc, REPAIR)) {
CHECK_ASK(ppc, questions[i],
"%sinvalid %s.|Do you want to set it to a "
"valid value?", loc->prefix, fields[i]);
} else {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, "%sinvalid %s", loc->prefix,
fields[i]);
}
}
return check_questions_sequence_validate(ppc);
}
/*
* pool_hdr_uuid_links_fix -- (internal) fix UUID links values
*/
static int
pool_hdr_uuid_links_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question,
void *context)
{
LOG(3, NULL);
ASSERTne(loc, NULL);
switch (question) {
case Q_NEXT_PART_UUID_SET:
CHECK_INFO(ppc, "%ssetting pool_hdr.next_part_uuid to %s",
loc->prefix,
check_get_uuid_str(loc->next_part_hdrp->uuid));
memcpy(loc->hdr.next_part_uuid, loc->next_part_hdrp->uuid,
POOL_HDR_UUID_LEN);
break;
case Q_PREV_PART_UUID_SET:
CHECK_INFO(ppc, "%ssetting pool_hdr.prev_part_uuid to %s",
loc->prefix,
check_get_uuid_str(loc->prev_part_hdrp->uuid));
memcpy(loc->hdr.prev_part_uuid, loc->prev_part_hdrp->uuid,
POOL_HDR_UUID_LEN);
break;
case Q_NEXT_REPL_UUID_SET:
CHECK_INFO(ppc, "%ssetting pool_hdr.next_repl_uuid to %s",
loc->prefix,
check_get_uuid_str(loc->next_repl_hdrp->uuid));
memcpy(loc->hdr.next_repl_uuid, loc->next_repl_hdrp->uuid,
POOL_HDR_UUID_LEN);
break;
case Q_PREV_REPL_UUID_SET:
CHECK_INFO(ppc, "%ssetting pool_hdr.prev_repl_uuid to %s",
loc->prefix,
check_get_uuid_str(loc->prev_repl_hdrp->uuid));
memcpy(loc->hdr.prev_repl_uuid, loc->prev_repl_hdrp->uuid,
POOL_HDR_UUID_LEN);
break;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
/*
* pool_hdr_checksum -- (internal) validate checksum
*/
static int
pool_hdr_checksum(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
if (loc->hdr_valid)
return 0;
if (CHECK_IS_NOT(ppc, REPAIR)) {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
return CHECK_ERR(ppc, INVALID_CHECKSUM, loc->prefix);
} else if (CHECK_IS_NOT(ppc, ADVANCED)) {
ppc->result = CHECK_RESULT_CANNOT_REPAIR;
CHECK_INFO(ppc, "%s" REQUIRE_ADVANCED, loc->prefix);
return CHECK_ERR(ppc, INVALID_CHECKSUM, loc->prefix);
}
CHECK_ASK(ppc, Q_CHECKSUM, INVALID_CHECKSUM ".|Do you want to "
"regenerate checksum?", loc->prefix);
return check_questions_sequence_validate(ppc);
}
/*
* pool_hdr_checksum_fix -- (internal) fix checksum
*/
static int
pool_hdr_checksum_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question,
void *context)
{
LOG(3, NULL);
ASSERTne(loc, NULL);
switch (question) {
case Q_CHECKSUM:
util_checksum(&loc->hdr, sizeof(loc->hdr), &loc->hdr.checksum,
1, POOL_HDR_CSUM_END_OFF(&loc->hdr));
CHECK_INFO(ppc, "%ssetting pool_hdr.checksum to 0x%jx",
loc->prefix, le64toh(loc->hdr.checksum));
break;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
struct step {
int (*check)(PMEMpoolcheck *, location *);
int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *);
};
static const struct step steps_initial[] = {
{
.check = pool_hdr_preliminary_check,
},
{
.check = pool_hdr_default_check,
},
{
.fix = pool_hdr_default_fix,
.check = pool_hdr_quick_check,
},
{
.check = pool_hdr_nondefault,
},
{
.fix = pool_hdr_nondefault_fix,
},
{
.check = NULL,
.fix = NULL,
},
};
static const struct step steps_uuids[] = {
{
.check = pool_hdr_poolset_uuid_find,
},
{
.fix = pool_hdr_poolset_uuid_fix,
},
{
.check = pool_hdr_uuid_find,
},
{
.fix = pool_hdr_uuid_fix,
},
{
.check = pool_hdr_uuid_links,
},
{
.fix = pool_hdr_uuid_links_fix,
},
{
.check = pool_hdr_checksum,
},
{
.fix = pool_hdr_checksum_fix,
},
{
.check = NULL,
.fix = NULL,
},
};
/*
* step_exe -- (internal) perform single step according to its parameters
*/
static int
step_exe(PMEMpoolcheck *ppc, const struct step *steps, location *loc,
struct pool_replica *rep, unsigned nreplicas)
{
const struct step *step = &steps[loc->step++];
if (!step->fix)
return step->check(ppc, loc);
if (!check_has_answer(ppc->data))
return 0;
if (check_answer_loop(ppc, loc, NULL, 1, step->fix))
return -1;
util_convert2le_hdr(&loc->hdr);
memcpy(loc->hdrp, &loc->hdr, sizeof(loc->hdr));
loc->hdr_valid = pool_hdr_valid(loc->hdrp);
util_persist_auto(rep->part[0].is_dev_dax, loc->hdrp,
sizeof(*loc->hdrp));
util_convert2h_hdr_nocheck(&loc->hdr);
loc->pool_hdr_modified = 1;
/* execute check after fix if available */
if (step->check)
return step->check(ppc, loc);
return 0;
}
/*
* init_location_data -- (internal) prepare location information
*/
static void
init_location_data(PMEMpoolcheck *ppc, location *loc)
{
/* prepare prefix for messages */
unsigned nfiles = pool_set_files_count(ppc->pool->set_file);
if (ppc->result != CHECK_RESULT_PROCESS_ANSWERS) {
if (nfiles > 1) {
int ret = snprintf(loc->prefix, PREFIX_MAX_SIZE,
"replica %u part %u: ",
loc->replica, loc->part);
if (ret < 0 || ret >= PREFIX_MAX_SIZE)
FATAL("snprintf: %d", ret);
} else
loc->prefix[0] = '\0';
loc->step = 0;
}
/* get neighboring parts and replicas and briefly validate them */
const struct pool_set *poolset = ppc->pool->set_file->poolset;
loc->single_repl = poolset->nreplicas == 1;
loc->single_part = poolset->replica[loc->replica]->nparts == 1;
struct pool_replica *rep = REP(poolset, loc->replica);
struct pool_replica *next_rep = REPN(poolset, loc->replica);
struct pool_replica *prev_rep = REPP(poolset, loc->replica);
loc->hdrp = HDR(rep, loc->part);
memcpy(&loc->hdr, loc->hdrp, sizeof(loc->hdr));
util_convert2h_hdr_nocheck(&loc->hdr);
loc->hdr_valid = pool_hdr_valid(loc->hdrp);
loc->next_part_hdrp = HDRN(rep, loc->part);
loc->prev_part_hdrp = HDRP(rep, loc->part);
loc->next_repl_hdrp = HDR(next_rep, 0);
loc->prev_repl_hdrp = HDR(prev_rep, 0);
loc->next_part_hdr_valid = pool_hdr_valid(loc->next_part_hdrp);
loc->prev_part_hdr_valid = pool_hdr_valid(loc->prev_part_hdrp);
loc->next_repl_hdr_valid = pool_hdr_valid(loc->next_repl_hdrp);
loc->prev_repl_hdr_valid = pool_hdr_valid(loc->prev_repl_hdrp);
if (!loc->valid_part_done || loc->valid_part_replica != loc->replica) {
loc->valid_part_hdrp = NULL;
for (unsigned p = 0; p < rep->nhdrs; ++p) {
if (pool_hdr_valid(HDR(rep, p))) {
loc->valid_part_hdrp = HDR(rep, p);
break;
}
}
loc->valid_part_done = true;
}
}
/*
* check_pool_hdr -- entry point for pool header checks
*/
void
check_pool_hdr(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
location *loc = check_get_step_data(ppc->data);
unsigned nreplicas = ppc->pool->set_file->poolset->nreplicas;
struct pool_set *poolset = ppc->pool->set_file->poolset;
for (; loc->replica < nreplicas; loc->replica++) {
struct pool_replica *rep = poolset->replica[loc->replica];
for (; loc->part < rep->nhdrs; loc->part++) {
init_location_data(ppc, loc);
/* do all checks */
while (CHECK_NOT_COMPLETE(loc, steps_initial)) {
ASSERT(loc->step < ARRAY_SIZE(steps_initial));
if (step_exe(ppc, steps_initial, loc, rep,
nreplicas))
return;
}
}
loc->part = 0;
}
memcpy(&ppc->pool->hdr.pool, poolset->replica[0]->part[0].hdr,
sizeof(struct pool_hdr));
if (loc->pool_hdr_modified) {
struct pool_hdr hdr;
memcpy(&hdr, &ppc->pool->hdr.pool, sizeof(struct pool_hdr));
util_convert2h_hdr_nocheck(&hdr);
pool_params_from_header(&ppc->pool->params, &hdr);
}
}
/*
* check_pool_hdr_uuids -- entry point for pool header links checks
*/
void
check_pool_hdr_uuids(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
location *loc = check_get_step_data(ppc->data);
unsigned nreplicas = ppc->pool->set_file->poolset->nreplicas;
struct pool_set *poolset = ppc->pool->set_file->poolset;
for (; loc->replica < nreplicas; loc->replica++) {
struct pool_replica *rep = poolset->replica[loc->replica];
for (; loc->part < rep->nparts; loc->part++) {
init_location_data(ppc, loc);
/* do all checks */
while (CHECK_NOT_COMPLETE(loc, steps_uuids)) {
ASSERT(loc->step < ARRAY_SIZE(steps_uuids));
if (step_exe(ppc, steps_uuids, loc, rep,
nreplicas))
return;
}
}
loc->part = 0;
}
memcpy(&ppc->pool->hdr.pool, poolset->replica[0]->part[0].hdr,
sizeof(struct pool_hdr));
if (loc->pool_hdr_modified) {
struct pool_hdr hdr;
memcpy(&hdr, &ppc->pool->hdr.pool, sizeof(struct pool_hdr));
util_convert2h_hdr_nocheck(&hdr);
pool_params_from_header(&ppc->pool->params, &hdr);
}
}
| 28,442 | 26.296545 | 80 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/check_util.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check_util.h -- internal definitions check util
*/
#ifndef CHECK_UTIL_H
#define CHECK_UTIL_H
#include <time.h>
#include <limits.h>
#include <sys/param.h>
#ifdef __cplusplus
extern "C" {
#endif
#define CHECK_STEP_COMPLETE UINT_MAX
#define CHECK_INVALID_QUESTION UINT_MAX
#define REQUIRE_ADVANCED "the following error can be fixed using " \
"PMEMPOOL_CHECK_ADVANCED flag"
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
/* check control context */
struct check_data;
struct arena;
/* queue of check statuses */
struct check_status;
/* container storing state of all check steps */
#define PREFIX_MAX_SIZE 30
typedef struct {
unsigned init_done;
unsigned step;
unsigned replica;
unsigned part;
int single_repl;
int single_part;
struct pool_set *set;
int is_dev_dax;
struct pool_hdr *hdrp;
/* copy of the pool header in host byte order */
struct pool_hdr hdr;
int hdr_valid;
/*
* If pool header has been modified this field indicates that
* the pool parameters structure requires refresh.
*/
int pool_hdr_modified;
unsigned healthy_replicas;
struct pool_hdr *next_part_hdrp;
struct pool_hdr *prev_part_hdrp;
struct pool_hdr *next_repl_hdrp;
struct pool_hdr *prev_repl_hdrp;
int next_part_hdr_valid;
int prev_part_hdr_valid;
int next_repl_hdr_valid;
int prev_repl_hdr_valid;
/* valid poolset uuid */
uuid_t *valid_puuid;
/* valid part uuid */
uuid_t *valid_uuid;
/* valid part pool header */
struct pool_hdr *valid_part_hdrp;
int valid_part_done;
unsigned valid_part_replica;
char prefix[PREFIX_MAX_SIZE];
struct arena *arenap;
uint64_t offset;
uint32_t narena;
uint8_t *bitmap;
uint8_t *dup_bitmap;
uint8_t *fbitmap;
struct list *list_inval;
struct list *list_flog_inval;
struct list *list_unmap;
struct {
int btti_header;
int btti_backup;
} valid;
struct {
struct btt_info btti;
uint64_t btti_offset;
} pool_valid;
} location;
/* check steps */
void check_bad_blocks(PMEMpoolcheck *ppc);
void check_backup(PMEMpoolcheck *ppc);
void check_pool_hdr(PMEMpoolcheck *ppc);
void check_pool_hdr_uuids(PMEMpoolcheck *ppc);
void check_sds(PMEMpoolcheck *ppc);
void check_log(PMEMpoolcheck *ppc);
void check_blk(PMEMpoolcheck *ppc);
void check_cto(PMEMpoolcheck *ppc);
void check_btt_info(PMEMpoolcheck *ppc);
void check_btt_map_flog(PMEMpoolcheck *ppc);
void check_write(PMEMpoolcheck *ppc);
struct check_data *check_data_alloc(void);
void check_data_free(struct check_data *data);
uint32_t check_step_get(struct check_data *data);
void check_step_inc(struct check_data *data);
location *check_get_step_data(struct check_data *data);
void check_end(struct check_data *data);
int check_is_end_util(struct check_data *data);
int check_status_create(PMEMpoolcheck *ppc, enum pmempool_check_msg_type type,
uint32_t arg, const char *fmt, ...) FORMAT_PRINTF(4, 5);
void check_status_release(PMEMpoolcheck *ppc, struct check_status *status);
void check_clear_status_cache(struct check_data *data);
struct check_status *check_pop_question(struct check_data *data);
struct check_status *check_pop_error(struct check_data *data);
struct check_status *check_pop_info(struct check_data *data);
bool check_has_error(struct check_data *data);
bool check_has_answer(struct check_data *data);
int check_push_answer(PMEMpoolcheck *ppc);
struct pmempool_check_status *check_status_get_util(
struct check_status *status);
int check_status_is(struct check_status *status,
enum pmempool_check_msg_type type);
/* create info status */
#define CHECK_INFO(ppc, ...)\
check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_INFO, 0, __VA_ARGS__)
/* create info status and append error message based on errno */
#define CHECK_INFO_ERRNO(ppc, ...)\
check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_INFO,\
(uint32_t)errno, __VA_ARGS__)
/* create error status */
#define CHECK_ERR(ppc, ...)\
check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_ERROR, 0, __VA_ARGS__)
/* create question status */
#define CHECK_ASK(ppc, question, ...)\
check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_QUESTION, question,\
__VA_ARGS__)
#define CHECK_NOT_COMPLETE(loc, steps)\
((loc)->step != CHECK_STEP_COMPLETE &&\
((steps)[(loc)->step].check != NULL ||\
(steps)[(loc)->step].fix != NULL))
int check_answer_loop(PMEMpoolcheck *ppc, location *data,
void *ctx, int fail_on_no,
int (*callback)(PMEMpoolcheck *, location *, uint32_t, void *ctx));
int check_questions_sequence_validate(PMEMpoolcheck *ppc);
const char *check_get_time_str(time_t time);
const char *check_get_uuid_str(uuid_t uuid);
const char *check_get_pool_type_str(enum pool_type type);
void check_insert_arena(PMEMpoolcheck *ppc, struct arena *arenap);
#ifdef _WIN32
void cache_to_utf8(struct check_data *data, char *buf, size_t size);
#endif
#define CHECK_IS(ppc, flag)\
util_flag_isset((ppc)->args.flags, PMEMPOOL_CHECK_ ## flag)
#define CHECK_IS_NOT(ppc, flag)\
util_flag_isclr((ppc)->args.flags, PMEMPOOL_CHECK_ ## flag)
#define CHECK_WITHOUT_FIXING(ppc)\
CHECK_IS_NOT(ppc, REPAIR) || CHECK_IS(ppc, DRY_RUN)
#ifdef __cplusplus
}
#endif
#endif
| 6,694 | 28.493392 | 78 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/pmempool.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmempool.h -- internal definitions for libpmempool
*/
#ifndef PMEMPOOL_H
#define PMEMPOOL_H
#ifdef __cplusplus
extern "C" {
#endif
#define PMEMPOOL_LOG_PREFIX "libpmempool"
#define PMEMPOOL_LOG_LEVEL_VAR "PMEMPOOL_LOG_LEVEL"
#define PMEMPOOL_LOG_FILE_VAR "PMEMPOOL_LOG_FILE"
enum check_result {
CHECK_RESULT_CONSISTENT,
CHECK_RESULT_NOT_CONSISTENT,
CHECK_RESULT_ASK_QUESTIONS,
CHECK_RESULT_PROCESS_ANSWERS,
CHECK_RESULT_REPAIRED,
CHECK_RESULT_CANNOT_REPAIR,
CHECK_RESULT_ERROR,
CHECK_RESULT_INTERNAL_ERROR
};
/*
* pmempool_check_ctx -- context and arguments for check command
*/
struct pmempool_check_ctx {
struct pmempool_check_args args;
char *path;
char *backup_path;
struct check_data *data;
struct pool_data *pool;
enum check_result result;
unsigned sync_required;
};
#ifdef __cplusplus
}
#endif
#endif
| 2,442 | 30.320513 | 74 |
h
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/libpmempool_main.c
|
/*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmempool_main.c -- entry point for libpmempool.dll
*
* XXX - This is a placeholder. All the library initialization/cleanup
* that is done in library ctors/dtors, as well as TLS initialization
* should be moved here.
*/
#include <stdio.h>
void libpmempool_init(void);
void libpmempool_fini(void);
int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
libpmempool_init();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
libpmempool_fini();
break;
}
return TRUE;
}
| 2,210 | 33.546875 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/check_bad_blocks.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check_bad_blocks.c -- pre-check bad_blocks
*/
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#include "out.h"
#include "libpmempool.h"
#include "pmempool.h"
#include "pool.h"
#include "check_util.h"
#include "os_badblock.h"
#include "badblock.h"
/*
* check_bad_blocks -- check poolset for bad_blocks
*/
void
check_bad_blocks(PMEMpoolcheck *ppc)
{
LOG(3, "ppc %p", ppc);
int ret;
if (!(ppc->pool->params.features.compat & POOL_FEAT_CHECK_BAD_BLOCKS)) {
/* skipping checking poolset for bad blocks */
ppc->result = CHECK_RESULT_CONSISTENT;
return;
}
if (ppc->pool->set_file->poolset) {
ret = badblocks_check_poolset(ppc->pool->set_file->poolset, 0);
} else {
ret = os_badblocks_check_file(ppc->pool->set_file->fname);
}
if (ret < 0) {
ppc->result = CHECK_RESULT_ERROR;
CHECK_ERR(ppc, "checking poolset for bad blocks failed -- '%s'",
ppc->path);
return;
}
if (ret > 0) {
ppc->result = CHECK_RESULT_CANNOT_REPAIR;
CHECK_ERR(ppc,
"poolset contains bad blocks, use 'pmempool info -k' to print or 'pmempool sync -b' to clear them");
}
}
| 2,701 | 31.166667 | 103 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/feature.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* feature.c -- implementation of pmempool_feature_(enable|disable|query)()
*/
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include "libpmempool.h"
#include "util_pmem.h"
#include "pool_hdr.h"
#include "pool.h"
#define RW 0
#define RDONLY 1
#define FEATURE_INCOMPAT(X) \
(features_t)FEAT_INCOMPAT(X)
static const features_t f_singlehdr = FEAT_INCOMPAT(SINGLEHDR);
static const features_t f_cksum_2k = FEAT_INCOMPAT(CKSUM_2K);
static const features_t f_sds = FEAT_INCOMPAT(SDS);
static const features_t f_chkbb = FEAT_COMPAT(CHECK_BAD_BLOCKS);
#define FEAT_INVALID \
{UINT32_MAX, UINT32_MAX, UINT32_MAX};
static const features_t f_invalid = FEAT_INVALID;
#define FEATURE_MAXPRINT ((size_t)1024)
/*
* buff_concat -- (internal) concat formatted string to string buffer
*/
static int
buff_concat(char *buff, size_t *pos, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int ret = vsnprintf(buff + *pos, FEATURE_MAXPRINT - *pos - 1, fmt, ap);
va_end(ap);
if (ret < 0) {
ERR("vsprintf");
return ret;
}
*pos += (size_t)ret;
return 0;
}
/*
* buff_concat_features -- (internal) concat features string to string buffer
*/
static int
buff_concat_features(char *buff, size_t *pos, features_t f)
{
return buff_concat(buff, pos,
"{compat 0x%x, incompat 0x%x, ro_compat 0x%x}",
f.compat, f.incompat, f.ro_compat);
}
/*
* poolset_close -- (internal) close pool set
*/
static void
poolset_close(struct pool_set *set)
{
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = REP(set, r);
ASSERT(!rep->remote);
for (unsigned p = 0; p < rep->nparts; ++p) {
util_unmap_hdr(PART(rep, p));
}
}
util_poolset_close(set, DO_NOT_DELETE_PARTS);
}
/*
* features_check -- (internal) check if features are correct
*/
static int
features_check(features_t *features, struct pool_hdr *hdrp)
{
static char msg[FEATURE_MAXPRINT];
struct pool_hdr hdr;
memcpy(&hdr, hdrp, sizeof(hdr));
util_convert2h_hdr_nocheck(&hdr);
if (!util_feature_cmp(*features, f_invalid)) {
if (!util_feature_cmp(*features, hdr.features)) {
size_t pos = 0;
if (!buff_concat_features(msg, &pos, hdr.features))
goto err;
if (!buff_concat(msg, &pos, "%s", " != "))
goto err;
if (!buff_concat_features(msg, &pos, *features))
goto err;
ERR("features mismatch detected: %s", msg);
return -1;
}
}
features_t unknown = util_get_unknown_features(
hdr.features, (features_t)POOL_FEAT_VALID);
/* all features are known */
if (util_feature_is_zero(unknown)) {
memcpy(features, &hdr.features, sizeof(*features));
return 0;
}
/* unknown features detected - print error message */
size_t pos = 0;
if (buff_concat_features(msg, &pos, unknown))
goto err;
ERR("invalid features detected: %s", msg);
err:
return -1;
}
/*
* get_pool_open_flags -- (internal) generate pool open flags
*/
static inline unsigned
get_pool_open_flags(struct pool_set *set, int rdonly)
{
unsigned flags = 0;
if (rdonly == RDONLY && !util_pool_has_device_dax(set))
flags = POOL_OPEN_COW;
flags |= POOL_OPEN_IGNORE_BAD_BLOCKS;
return flags;
}
/*
* get_mmap_flags -- (internal) generate mmap flags
*/
static inline int
get_mmap_flags(struct pool_set_part *part, int rdonly)
{
if (part->is_dev_dax)
return MAP_SHARED;
else
return rdonly ? MAP_PRIVATE : MAP_SHARED;
}
/*
* poolset_open -- (internal) open pool set
*/
static struct pool_set *
poolset_open(const char *path, int rdonly)
{
struct pool_set *set;
features_t features = FEAT_INVALID;
/* read poolset */
int ret = util_poolset_create_set(&set, path, 0, 0, true);
if (ret < 0) {
ERR("cannot open pool set -- '%s'", path);
goto err_poolset;
}
if (set->remote) {
ERR("poolsets with remote replicas are not supported");
errno = EINVAL;
goto err_open;
}
/* open a memory pool */
unsigned flags = get_pool_open_flags(set, rdonly);
if (util_pool_open_nocheck(set, flags))
goto err_open;
/* map all headers and check features */
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = REP(set, r);
ASSERT(!rep->remote);
for (unsigned p = 0; p < rep->nparts; ++p) {
struct pool_set_part *part = PART(rep, p);
int mmap_flags = get_mmap_flags(part, rdonly);
if (util_map_hdr(part, mmap_flags, rdonly)) {
part->hdr = NULL;
goto err_map_hdr;
}
if (features_check(&features, HDR(rep, p))) {
ERR(
"invalid features - replica #%d part #%d",
r, p);
goto err_open;
}
}
}
return set;
err_map_hdr:
/* unmap all headers */
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = REP(set, r);
ASSERT(!rep->remote);
for (unsigned p = 0; p < rep->nparts; ++p) {
util_unmap_hdr(PART(rep, p));
}
}
err_open:
/* close the memory pool and release pool set structure */
util_poolset_close(set, DO_NOT_DELETE_PARTS);
err_poolset:
return NULL;
}
/*
* get_hdr -- (internal) read header in host byte order
*/
static struct pool_hdr *
get_hdr(struct pool_set *set, unsigned rep, unsigned part)
{
static struct pool_hdr hdr;
/* copy header */
struct pool_hdr *hdrp = HDR(REP(set, rep), part);
memcpy(&hdr, hdrp, sizeof(hdr));
/* convert to host byte order and return */
util_convert2h_hdr_nocheck(&hdr);
return &hdr;
}
/*
* set_hdr -- (internal) convert header to little-endian, checksum and write
*/
static void
set_hdr(struct pool_set *set, unsigned rep, unsigned part, struct pool_hdr *src)
{
/* convert to little-endian and set new checksum */
const size_t skip_off = POOL_HDR_CSUM_END_OFF(src);
util_convert2le_hdr(src);
util_checksum(src, sizeof(*src), &src->checksum, 1, skip_off);
/* write header */
struct pool_replica *replica = REP(set, rep);
struct pool_hdr *dst = HDR(replica, part);
memcpy(dst, src, sizeof(*src));
util_persist_auto(PART(replica, part)->is_dev_dax, dst, sizeof(*src));
}
typedef enum {
DISABLED,
ENABLED
} fstate_t;
#define FEATURE_IS_ENABLED_STR "feature already enabled: %s"
#define FEATURE_IS_DISABLED_STR "feature already disabled: %s"
/*
* require_feature_is -- (internal) check if required feature is enabled
* (or disabled)
*/
static int
require_feature_is(struct pool_set *set, features_t feature, fstate_t req_state)
{
struct pool_hdr *hdrp = get_hdr((set), 0, 0);
fstate_t state = util_feature_is_set(hdrp->features, feature)
? ENABLED : DISABLED;
if (state == req_state)
return 1;
const char *msg = (state == ENABLED)
? FEATURE_IS_ENABLED_STR : FEATURE_IS_DISABLED_STR;
LOG(3, msg, util_feature2str(feature, NULL));
return 0;
}
#define FEATURE_IS_NOT_ENABLED_PRIOR_STR "enable %s prior to %s %s"
#define FEATURE_IS_NOT_DISABLED_PRIOR_STR "disable %s prior to %s %s"
/*
* require_other_feature_is -- (internal) check if other feature is enabled
* (or disabled) in case the other feature has to be enabled (or disabled)
* prior to the main one
*/
static int
require_other_feature_is(struct pool_set *set, features_t other,
fstate_t req_state, features_t feature, const char *cause)
{
struct pool_hdr *hdrp = get_hdr((set), 0, 0);
fstate_t state = util_feature_is_set(hdrp->features, other)
? ENABLED : DISABLED;
if (state == req_state)
return 1;
const char *msg = (req_state == ENABLED)
? FEATURE_IS_NOT_ENABLED_PRIOR_STR
: FEATURE_IS_NOT_DISABLED_PRIOR_STR;
ERR(msg, util_feature2str(other, NULL),
cause, util_feature2str(feature, NULL));
return 0;
}
/*
* feature_set -- (internal) enable (or disable) feature
*/
static void
feature_set(struct pool_set *set, features_t feature, int value)
{
for (unsigned r = 0; r < set->nreplicas; ++r) {
for (unsigned p = 0; p < REP(set, r)->nparts; ++p) {
struct pool_hdr *hdrp = get_hdr(set, r, p);
if (value == ENABLED)
util_feature_enable(&hdrp->features, feature);
else
util_feature_disable(&hdrp->features, feature);
set_hdr(set, r, p, hdrp);
}
}
}
/*
* query_feature -- (internal) query feature value
*/
static int
query_feature(const char *path, features_t feature)
{
struct pool_set *set = poolset_open(path, RDONLY);
if (!set)
goto err_open;
struct pool_hdr *hdrp = get_hdr(set, 0, 0);
const int query = util_feature_is_set(hdrp->features, feature);
poolset_close(set);
return query;
err_open:
return -1;
}
/*
* unsupported_feature -- (internal) report unsupported feature
*/
static inline int
unsupported_feature(features_t feature)
{
ERR("unsupported feature: %s", util_feature2str(feature, NULL));
errno = EINVAL;
return -1;
}
/*
* enable_singlehdr -- (internal) enable POOL_FEAT_SINGLEHDR
*/
static int
enable_singlehdr(const char *path)
{
return unsupported_feature(f_singlehdr);
}
/*
* disable_singlehdr -- (internal) disable POOL_FEAT_SINGLEHDR
*/
static int
disable_singlehdr(const char *path)
{
return unsupported_feature(f_singlehdr);
}
/*
* query_singlehdr -- (internal) query POOL_FEAT_SINGLEHDR
*/
static int
query_singlehdr(const char *path)
{
return query_feature(path, f_singlehdr);
}
/*
* enable_checksum_2k -- (internal) enable POOL_FEAT_CKSUM_2K
*/
static int
enable_checksum_2k(const char *path)
{
struct pool_set *set = poolset_open(path, RW);
if (!set)
return -1;
if (require_feature_is(set, f_cksum_2k, DISABLED))
feature_set(set, f_cksum_2k, ENABLED);
poolset_close(set);
return 0;
}
/*
* disable_checksum_2k -- (internal) disable POOL_FEAT_CKSUM_2K
*/
static int
disable_checksum_2k(const char *path)
{
struct pool_set *set = poolset_open(path, RW);
if (!set)
return -1;
int ret = 0;
if (!require_feature_is(set, f_cksum_2k, ENABLED))
goto exit;
/* check if POOL_FEAT_SDS is disabled */
if (!require_other_feature_is(set, f_sds, DISABLED,
f_cksum_2k, "disabling")) {
ret = -1;
goto exit;
}
feature_set(set, f_cksum_2k, DISABLED);
exit:
poolset_close(set);
return ret;
}
/*
* query_checksum_2k -- (internal) query POOL_FEAT_CKSUM_2K
*/
static int
query_checksum_2k(const char *path)
{
return query_feature(path, f_cksum_2k);
}
/*
* enable_shutdown_state -- (internal) enable POOL_FEAT_SDS
*/
static int
enable_shutdown_state(const char *path)
{
struct pool_set *set = poolset_open(path, RW);
if (!set)
return -1;
int ret = 0;
if (!require_feature_is(set, f_sds, DISABLED))
goto exit;
/* check if POOL_FEAT_CKSUM_2K is enabled */
if (!require_other_feature_is(set, f_cksum_2k, ENABLED,
f_sds, "enabling")) {
ret = -1;
goto exit;
}
feature_set(set, f_sds, ENABLED);
exit:
poolset_close(set);
return ret;
}
/*
* reset_shutdown_state -- zero all shutdown structures
*/
static void
reset_shutdown_state(struct pool_set *set)
{
for (unsigned rep = 0; rep < set->nreplicas; ++rep) {
for (unsigned part = 0; part < REP(set, rep)->nparts; ++part) {
struct pool_hdr *hdrp = HDR(REP(set, rep), part);
shutdown_state_init(&hdrp->sds, REP(set, rep));
}
}
}
/*
* disable_shutdown_state -- (internal) disable POOL_FEAT_SDS
*/
static int
disable_shutdown_state(const char *path)
{
struct pool_set *set = poolset_open(path, RW);
if (!set)
return -1;
if (require_feature_is(set, f_sds, ENABLED)) {
feature_set(set, f_sds, DISABLED);
reset_shutdown_state(set);
}
poolset_close(set);
return 0;
}
/*
* query_shutdown_state -- (internal) query POOL_FEAT_SDS
*/
static int
query_shutdown_state(const char *path)
{
return query_feature(path, f_sds);
}
/*
* enable_badblocks_checking -- (internal) enable POOL_FEAT_CHECK_BAD_BLOCKS
*/
static int
enable_badblocks_checking(const char *path)
{
#ifdef _WIN32
ERR("bad blocks checking is not supported on Windows");
return -1;
#else
struct pool_set *set = poolset_open(path, RW);
if (!set)
return -1;
if (require_feature_is(set, f_chkbb, DISABLED))
feature_set(set, f_chkbb, ENABLED);
poolset_close(set);
return 0;
#endif
}
/*
* disable_badblocks_checking -- (internal) disable POOL_FEAT_CHECK_BAD_BLOCKS
*/
static int
disable_badblocks_checking(const char *path)
{
struct pool_set *set = poolset_open(path, RW);
if (!set)
return -1;
int ret = 0;
if (!require_feature_is(set, f_chkbb, ENABLED))
goto exit;
feature_set(set, f_chkbb, DISABLED);
exit:
poolset_close(set);
return ret;
}
/*
* query_badblocks_checking -- (internal) query POOL_FEAT_CHECK_BAD_BLOCKS
*/
static int
query_badblocks_checking(const char *path)
{
return query_feature(path, f_chkbb);
}
struct feature_funcs {
int (*enable)(const char *);
int (*disable)(const char *);
int (*query)(const char *);
};
static struct feature_funcs features[] = {
{
.enable = enable_singlehdr,
.disable = disable_singlehdr,
.query = query_singlehdr
},
{
.enable = enable_checksum_2k,
.disable = disable_checksum_2k,
.query = query_checksum_2k
},
{
.enable = enable_shutdown_state,
.disable = disable_shutdown_state,
.query = query_shutdown_state
},
{
.enable = enable_badblocks_checking,
.disable = disable_badblocks_checking,
.query = query_badblocks_checking
},
};
#define FEATURE_FUNCS_MAX ARRAY_SIZE(features)
/*
* are_flags_valid -- (internal) check if flags are valid
*/
static inline int
are_flags_valid(unsigned flags)
{
if (flags != 0) {
ERR("invalid flags: 0x%x", flags);
errno = EINVAL;
return 0;
}
return 1;
}
/*
* is_feature_valid -- (internal) check if feature is valid
*/
static inline int
is_feature_valid(uint32_t feature)
{
if (feature >= FEATURE_FUNCS_MAX) {
ERR("invalid feature: 0x%x", feature);
errno = EINVAL;
return 0;
}
return 1;
}
/*
* pmempool_feature_enableU -- enable pool set feature
*/
#ifndef _WIN32
static inline
#endif
int
pmempool_feature_enableU(const char *path, enum pmempool_feature feature,
unsigned flags)
{
LOG(3, "path %s feature %x flags %x", path, feature, flags);
if (!is_feature_valid(feature))
return -1;
if (!are_flags_valid(flags))
return -1;
return features[feature].enable(path);
}
/*
* pmempool_feature_disableU -- disable pool set feature
*/
#ifndef _WIN32
static inline
#endif
int
pmempool_feature_disableU(const char *path, enum pmempool_feature feature,
unsigned flags)
{
LOG(3, "path %s feature %x flags %x", path, feature, flags);
if (!is_feature_valid(feature))
return -1;
if (!are_flags_valid(flags))
return -1;
return features[feature].disable(path);
}
/*
* pmempool_feature_queryU -- query pool set feature
*/
#ifndef _WIN32
static inline
#endif
int
pmempool_feature_queryU(const char *path, enum pmempool_feature feature,
unsigned flags)
{
LOG(3, "path %s feature %x flags %x", path, feature, flags);
/*
* XXX: Windows does not allow function call in a constant expressions
*/
#ifndef _WIN32
#define CHECK_INCOMPAT_MAPPING(FEAT, ENUM) \
COMPILE_ERROR_ON( \
util_feature2pmempool_feature(FEATURE_INCOMPAT(FEAT)) != ENUM)
CHECK_INCOMPAT_MAPPING(SINGLEHDR, PMEMPOOL_FEAT_SINGLEHDR);
CHECK_INCOMPAT_MAPPING(CKSUM_2K, PMEMPOOL_FEAT_CKSUM_2K);
CHECK_INCOMPAT_MAPPING(SDS, PMEMPOOL_FEAT_SHUTDOWN_STATE);
#undef CHECK_INCOMPAT_MAPPING
#endif
if (!is_feature_valid(feature))
return -1;
if (!are_flags_valid(flags))
return -1;
return features[feature].query(path);
}
#ifndef _WIN32
/*
* pmempool_feature_enable -- enable pool set feature
*/
int
pmempool_feature_enable(const char *path, enum pmempool_feature feature,
unsigned flags)
{
return pmempool_feature_enableU(path, feature, flags);
}
#else
/*
* pmempool_feature_enableW -- enable pool set feature as widechar
*/
int
pmempool_feature_enableW(const wchar_t *path, enum pmempool_feature feature,
unsigned flags)
{
char *upath = util_toUTF8(path);
if (upath == NULL) {
ERR("Invalid poolest/pool file path.");
return -1;
}
int ret = pmempool_feature_enableU(upath, feature, flags);
util_free_UTF8(upath);
return ret;
}
#endif
#ifndef _WIN32
/*
* pmempool_feature_disable -- disable pool set feature
*/
int
pmempool_feature_disable(const char *path, enum pmempool_feature feature,
unsigned flags)
{
return pmempool_feature_disableU(path, feature, flags);
}
#else
/*
* pmempool_feature_disableW -- disable pool set feature as widechar
*/
int
pmempool_feature_disableW(const wchar_t *path, enum pmempool_feature feature,
unsigned flags)
{
char *upath = util_toUTF8(path);
if (upath == NULL) {
ERR("Invalid poolest/pool file path.");
return -1;
}
int ret = pmempool_feature_disableU(upath, feature, flags);
util_free_UTF8(upath);
return ret;
}
#endif
#ifndef _WIN32
/*
* pmempool_feature_query -- query pool set feature
*/
int
pmempool_feature_query(const char *path, enum pmempool_feature feature,
unsigned flags)
{
return pmempool_feature_queryU(path, feature, flags);
}
#else
/*
* pmempool_feature_queryW -- query pool set feature as widechar
*/
int
pmempool_feature_queryW(const wchar_t *path, enum pmempool_feature feature,
unsigned flags)
{
char *upath = util_toUTF8(path);
if (upath == NULL) {
ERR("Invalid poolest/pool file path.");
return -1;
}
int ret = pmempool_feature_queryU(upath, feature, flags);
util_free_UTF8(upath);
return ret;
}
#endif
| 18,602 | 21.995056 | 80 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/check.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check.c -- functions performing checks in proper order
*/
#include <stdint.h>
#include "out.h"
#include "libpmempool.h"
#include "pmempool.h"
#include "pool.h"
#include "check.h"
#include "check_util.h"
#define CHECK_RESULT_IS_STOP(result)\
((result) == CHECK_RESULT_ERROR ||\
(result) == CHECK_RESULT_INTERNAL_ERROR ||\
((result) == CHECK_RESULT_CANNOT_REPAIR) ||\
((result) == CHECK_RESULT_NOT_CONSISTENT))
struct step {
void (*func)(PMEMpoolcheck *);
enum pool_type type;
bool part;
};
static const struct step steps[] = {
{
.type = POOL_TYPE_ANY,
.func = check_bad_blocks,
.part = true,
},
{
.type = POOL_TYPE_ANY,
.func = check_backup,
.part = true,
},
{
.type = POOL_TYPE_BLK | POOL_TYPE_LOG |
POOL_TYPE_OBJ | POOL_TYPE_CTO,
.func = check_sds,
.part = true,
},
{
.type = POOL_TYPE_BLK | POOL_TYPE_LOG |
POOL_TYPE_OBJ | POOL_TYPE_CTO |
POOL_TYPE_UNKNOWN,
.func = check_pool_hdr,
.part = true,
},
{
.type = POOL_TYPE_BLK | POOL_TYPE_LOG |
POOL_TYPE_OBJ | POOL_TYPE_CTO |
POOL_TYPE_UNKNOWN,
.func = check_pool_hdr_uuids,
.part = true,
},
{
.type = POOL_TYPE_LOG,
.func = check_log,
.part = false,
},
{
.type = POOL_TYPE_BLK,
.func = check_blk,
.part = false,
},
{
.type = POOL_TYPE_CTO,
.func = check_cto,
.part = false,
},
{
.type = POOL_TYPE_BLK | POOL_TYPE_BTT,
.func = check_btt_info,
.part = false,
},
{
.type = POOL_TYPE_BLK | POOL_TYPE_BTT,
.func = check_btt_map_flog,
.part = false,
},
{
.type = POOL_TYPE_BLK | POOL_TYPE_LOG |
POOL_TYPE_BTT | POOL_TYPE_CTO,
.func = check_write,
.part = false,
},
{
.func = NULL,
},
};
/*
* check_init -- initialize check process
*/
int
check_init(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
if (!(ppc->data = check_data_alloc()))
goto error_data_malloc;
if (!(ppc->pool = pool_data_alloc(ppc)))
goto error_pool_malloc;
return 0;
error_pool_malloc:
check_data_free(ppc->data);
error_data_malloc:
return -1;
}
#ifdef _WIN32
void
convert_status_cache(PMEMpoolcheck *ppc, char *buf, size_t size)
{
cache_to_utf8(ppc->data, buf, size);
}
#endif
/*
* status_get -- (internal) get next check_status
*
* The assumed order of check_statuses is: all info messages, error or question.
*/
static struct check_status *
status_get(PMEMpoolcheck *ppc)
{
struct check_status *status = NULL;
/* clear cache if exists */
check_clear_status_cache(ppc->data);
/* return next info if exists */
if ((status = check_pop_info(ppc->data)))
return status;
/* return error if exists */
if ((status = check_pop_error(ppc->data)))
return status;
if (ppc->result == CHECK_RESULT_ASK_QUESTIONS) {
/*
* push answer for previous question and return info if answer
* is not valid
*/
if (check_push_answer(ppc))
if ((status = check_pop_info(ppc->data)))
return status;
/* if has next question ask it */
if ((status = check_pop_question(ppc->data)))
return status;
/* process answers otherwise */
ppc->result = CHECK_RESULT_PROCESS_ANSWERS;
} else if (CHECK_RESULT_IS_STOP(ppc->result))
check_end(ppc->data);
return NULL;
}
/*
* check_step -- perform single check step
*/
struct check_status *
check_step(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
struct check_status *status = NULL;
/* return if we have information or questions to ask or check ended */
if ((status = status_get(ppc)) || check_is_end(ppc->data))
return status;
/* get next step and check if exists */
const struct step *step = &steps[check_step_get(ppc->data)];
if (step->func == NULL) {
check_end(ppc->data);
return status;
}
/*
* step would be performed if pool type is one of the required pool type
* and it is not part if parts are excluded from current step
*/
if (!(step->type & ppc->pool->params.type) ||
(ppc->pool->params.is_part && !step->part)) {
/* skip test */
check_step_inc(ppc->data);
return NULL;
}
/* perform step */
step->func(ppc);
/* move on to next step if no questions were generated */
if (ppc->result != CHECK_RESULT_ASK_QUESTIONS)
check_step_inc(ppc->data);
/* get current status and return */
return status_get(ppc);
}
/*
* check_fini -- stop check process
*/
void
check_fini(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
pool_data_free(ppc->pool);
check_data_free(ppc->data);
}
/*
* check_is_end -- return if check has ended
*/
int
check_is_end(struct check_data *data)
{
return check_is_end_util(data);
}
/*
* check_status_get -- extract pmempool_check_status from check_status
*/
struct pmempool_check_status *
check_status_get(struct check_status *status)
{
return check_status_get_util(status);
}
| 6,303 | 22.610487 | 80 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/check_btt_map_flog.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check_btt_map_flog.c -- check BTT Map and Flog
*/
#include <stdint.h>
#include <sys/param.h>
#include <endian.h>
#include "out.h"
#include "btt.h"
#include "libpmempool.h"
#include "pmempool.h"
#include "pool.h"
#include "check_util.h"
enum questions {
Q_REPAIR_MAP,
Q_REPAIR_FLOG,
};
/*
* flog_read -- (internal) read and convert flog from file
*/
static int
flog_read(PMEMpoolcheck *ppc, struct arena *arenap)
{
uint64_t flogoff = arenap->offset + arenap->btt_info.flogoff;
arenap->flogsize = btt_flog_size(arenap->btt_info.nfree);
arenap->flog = malloc(arenap->flogsize);
if (!arenap->flog) {
ERR("!malloc");
goto error_malloc;
}
if (pool_read(ppc->pool, arenap->flog, arenap->flogsize, flogoff))
goto error_read;
uint8_t *ptr = arenap->flog;
uint32_t i;
for (i = 0; i < arenap->btt_info.nfree; i++) {
struct btt_flog *flog = (struct btt_flog *)ptr;
btt_flog_convert2h(&flog[0]);
btt_flog_convert2h(&flog[1]);
ptr += BTT_FLOG_PAIR_ALIGN;
}
return 0;
error_read:
free(arenap->flog);
arenap->flog = NULL;
error_malloc:
return -1;
}
/*
* map_read -- (internal) read and convert map from file
*/
static int
map_read(PMEMpoolcheck *ppc, struct arena *arenap)
{
uint64_t mapoff = arenap->offset + arenap->btt_info.mapoff;
arenap->mapsize = btt_map_size(arenap->btt_info.external_nlba);
ASSERT(arenap->mapsize != 0);
arenap->map = malloc(arenap->mapsize);
if (!arenap->map) {
ERR("!malloc");
goto error_malloc;
}
if (pool_read(ppc->pool, arenap->map, arenap->mapsize, mapoff)) {
goto error_read;
}
uint32_t i;
for (i = 0; i < arenap->btt_info.external_nlba; i++)
arenap->map[i] = le32toh(arenap->map[i]);
return 0;
error_read:
free(arenap->map);
arenap->map = NULL;
error_malloc:
return -1;
}
/*
* list_item -- item for simple list
*/
struct list_item {
LIST_ENTRY(list_item) next;
uint32_t val;
};
/*
* list -- simple list for storing numbers
*/
struct list {
LIST_HEAD(listhead, list_item) head;
uint32_t count;
};
/*
* list_alloc -- (internal) allocate an empty list
*/
static struct list *
list_alloc(void)
{
struct list *list = malloc(sizeof(struct list));
if (!list) {
ERR("!malloc");
return NULL;
}
LIST_INIT(&list->head);
list->count = 0;
return list;
}
/*
* list_push -- (internal) insert new element to the list
*/
static struct list_item *
list_push(struct list *list, uint32_t val)
{
struct list_item *item = malloc(sizeof(*item));
if (!item) {
ERR("!malloc");
return NULL;
}
item->val = val;
list->count++;
LIST_INSERT_HEAD(&list->head, item, next);
return item;
}
/*
* list_pop -- (internal) pop element from list head
*/
static int
list_pop(struct list *list, uint32_t *valp)
{
if (!LIST_EMPTY(&list->head)) {
struct list_item *i = LIST_FIRST(&list->head);
LIST_REMOVE(i, next);
if (valp)
*valp = i->val;
free(i);
list->count--;
return 1;
}
return 0;
}
/*
* list_free -- (internal) free the list
*/
static void
list_free(struct list *list)
{
while (list_pop(list, NULL))
;
free(list);
}
/*
* cleanup -- (internal) prepare resources for map and flog check
*/
static int
cleanup(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
if (loc->list_unmap)
list_free(loc->list_unmap);
if (loc->list_flog_inval)
list_free(loc->list_flog_inval);
if (loc->list_inval)
list_free(loc->list_inval);
if (loc->fbitmap)
free(loc->fbitmap);
if (loc->bitmap)
free(loc->bitmap);
if (loc->dup_bitmap)
free(loc->dup_bitmap);
return 0;
}
/*
* init -- (internal) initialize map and flog check
*/
static int
init(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
struct arena *arenap = loc->arenap;
/* read flog and map entries */
if (flog_read(ppc, arenap)) {
CHECK_ERR(ppc, "arena %u: cannot read BTT Flog", arenap->id);
goto error;
}
if (map_read(ppc, arenap)) {
CHECK_ERR(ppc, "arena %u: cannot read BTT Map", arenap->id);
goto error;
}
/* create bitmaps for checking duplicated blocks */
uint32_t bitmapsize = howmany(arenap->btt_info.internal_nlba, 8);
loc->bitmap = calloc(bitmapsize, 1);
if (!loc->bitmap) {
ERR("!calloc");
CHECK_ERR(ppc, "arena %u: cannot allocate memory for blocks "
"bitmap", arenap->id);
goto error;
}
loc->dup_bitmap = calloc(bitmapsize, 1);
if (!loc->dup_bitmap) {
ERR("!calloc");
CHECK_ERR(ppc, "arena %u: cannot allocate memory for "
"duplicated blocks bitmap", arenap->id);
goto error;
}
loc->fbitmap = calloc(bitmapsize, 1);
if (!loc->fbitmap) {
ERR("!calloc");
CHECK_ERR(ppc, "arena %u: cannot allocate memory for BTT Flog "
"bitmap", arenap->id);
goto error;
}
/* list of invalid map entries */
loc->list_inval = list_alloc();
if (!loc->list_inval) {
CHECK_ERR(ppc,
"arena %u: cannot allocate memory for invalid BTT map "
"entries list", arenap->id);
goto error;
}
/* list of invalid flog entries */
loc->list_flog_inval = list_alloc();
if (!loc->list_flog_inval) {
CHECK_ERR(ppc,
"arena %u: cannot allocate memory for invalid BTT Flog "
"entries list", arenap->id);
goto error;
}
/* list of unmapped blocks */
loc->list_unmap = list_alloc();
if (!loc->list_unmap) {
CHECK_ERR(ppc,
"arena %u: cannot allocate memory for unmaped blocks "
"list", arenap->id);
goto error;
}
return 0;
error:
ppc->result = CHECK_RESULT_ERROR;
cleanup(ppc, loc);
return -1;
}
/*
* map_get_postmap_lba -- extract postmap LBA from map entry
*/
static inline uint32_t
map_get_postmap_lba(struct arena *arenap, uint32_t i)
{
uint32_t entry = arenap->map[i];
/* if map record is in initial state (flags == 0b00) */
if (map_entry_is_initial(entry))
return i;
/* read postmap LBA otherwise */
return entry & BTT_MAP_ENTRY_LBA_MASK;
}
/*
* map_entry_check -- (internal) check single map entry
*/
static int
map_entry_check(PMEMpoolcheck *ppc, location *loc, uint32_t i)
{
struct arena *arenap = loc->arenap;
uint32_t lba = map_get_postmap_lba(arenap, i);
/* add duplicated and invalid entries to list */
if (lba < arenap->btt_info.internal_nlba) {
if (util_isset(loc->bitmap, lba)) {
CHECK_INFO(ppc, "arena %u: BTT Map entry %u duplicated "
"at %u", arenap->id, lba, i);
util_setbit(loc->dup_bitmap, lba);
if (!list_push(loc->list_inval, i))
return -1;
} else
util_setbit(loc->bitmap, lba);
} else {
CHECK_INFO(ppc, "arena %u: invalid BTT Map entry at %u",
arenap->id, i);
if (!list_push(loc->list_inval, i))
return -1;
}
return 0;
}
/*
* flog_entry_check -- (internal) check single flog entry
*/
static int
flog_entry_check(PMEMpoolcheck *ppc, location *loc, uint32_t i,
uint8_t **ptr)
{
struct arena *arenap = loc->arenap;
/* flog entry consists of two btt_flog structures */
struct btt_flog *flog = (struct btt_flog *)*ptr;
int next;
struct btt_flog *flog_cur = btt_flog_get_valid(flog, &next);
/* insert invalid and duplicated indexes to list */
if (!flog_cur) {
CHECK_INFO(ppc, "arena %u: invalid BTT Flog entry at %u",
arenap->id, i);
if (!list_push(loc->list_flog_inval, i))
return -1;
goto next;
}
uint32_t entry = flog_cur->old_map & BTT_MAP_ENTRY_LBA_MASK;
uint32_t new_entry = flog_cur->new_map & BTT_MAP_ENTRY_LBA_MASK;
/*
* Check if lba is in extranal_nlba range, and check if both old_map and
* new_map are in internal_nlba range.
*/
if (flog_cur->lba >= arenap->btt_info.external_nlba ||
entry >= arenap->btt_info.internal_nlba ||
new_entry >= arenap->btt_info.internal_nlba) {
CHECK_INFO(ppc, "arena %u: invalid BTT Flog entry at %u",
arenap->id, i);
if (!list_push(loc->list_flog_inval, i))
return -1;
goto next;
}
if (util_isset(loc->fbitmap, entry)) {
/*
* here we have two flog entries which holds the same free block
*/
CHECK_INFO(ppc, "arena %u: duplicated BTT Flog entry at %u\n",
arenap->id, i);
if (!list_push(loc->list_flog_inval, i))
return -1;
} else if (util_isset(loc->bitmap, entry)) {
/* here we have probably an unfinished write */
if (util_isset(loc->bitmap, new_entry)) {
/* Both old_map and new_map are already used in map. */
CHECK_INFO(ppc, "arena %u: duplicated BTT Flog entry "
"at %u", arenap->id, i);
util_setbit(loc->dup_bitmap, new_entry);
if (!list_push(loc->list_flog_inval, i))
return -1;
} else {
/*
* Unfinished write. Next time pool is opened, the map
* will be updated to new_map.
*/
util_setbit(loc->bitmap, new_entry);
util_setbit(loc->fbitmap, entry);
}
} else {
int flog_valid = 1;
/*
* Either flog entry is in its initial state:
* - current_btt_flog entry is first one in pair and
* - current_btt_flog.old_map == current_btt_flog.new_map and
* - current_btt_flog.seq == 0b01 and
* - second flog entry in pair is zeroed
* or
* current_btt_flog.old_map != current_btt_flog.new_map
*/
if (entry == new_entry)
flog_valid = (next == 1) && (flog_cur->seq == 1) &&
util_is_zeroed((const void *)&flog[1],
sizeof(flog[1]));
if (flog_valid) {
/* totally fine case */
util_setbit(loc->bitmap, entry);
util_setbit(loc->fbitmap, entry);
} else {
CHECK_INFO(ppc, "arena %u: invalid BTT Flog entry at "
"%u", arenap->id, i);
if (!list_push(loc->list_flog_inval, i))
return -1;
}
}
next:
*ptr += BTT_FLOG_PAIR_ALIGN;
return 0;
}
/*
* arena_map_flog_check -- (internal) check map and flog
*/
static int
arena_map_flog_check(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, NULL);
struct arena *arenap = loc->arenap;
/* check map entries */
uint32_t i;
for (i = 0; i < arenap->btt_info.external_nlba; i++) {
if (map_entry_check(ppc, loc, i))
goto error_push;
}
/* check flog entries */
uint8_t *ptr = arenap->flog;
for (i = 0; i < arenap->btt_info.nfree; i++) {
if (flog_entry_check(ppc, loc, i, &ptr))
goto error_push;
}
/* check unmapped blocks and insert to list */
for (i = 0; i < arenap->btt_info.internal_nlba; i++) {
if (!util_isset(loc->bitmap, i)) {
CHECK_INFO(ppc, "arena %u: unmapped block %u",
arenap->id, i);
if (!list_push(loc->list_unmap, i))
goto error_push;
}
}
if (loc->list_unmap->count)
CHECK_INFO(ppc, "arena %u: number of unmapped blocks: %u",
arenap->id, loc->list_unmap->count);
if (loc->list_inval->count)
CHECK_INFO(ppc, "arena %u: number of invalid BTT Map entries: "
"%u", arenap->id, loc->list_inval->count);
if (loc->list_flog_inval->count)
CHECK_INFO(ppc, "arena %u: number of invalid BTT Flog entries: "
"%u", arenap->id, loc->list_flog_inval->count);
if (CHECK_IS_NOT(ppc, REPAIR) && loc->list_unmap->count > 0) {
ppc->result = CHECK_RESULT_NOT_CONSISTENT;
check_end(ppc->data);
goto cleanup;
}
/*
* We are able to repair if and only if number of unmapped blocks is
* equal to sum of invalid map and flog entries.
*/
if (loc->list_unmap->count != (loc->list_inval->count +
loc->list_flog_inval->count)) {
ppc->result = CHECK_RESULT_CANNOT_REPAIR;
CHECK_ERR(ppc, "arena %u: cannot repair BTT Map and Flog",
arenap->id);
goto cleanup;
}
if (CHECK_IS_NOT(ppc, ADVANCED) && loc->list_inval->count +
loc->list_flog_inval->count > 0) {
ppc->result = CHECK_RESULT_CANNOT_REPAIR;
CHECK_INFO(ppc, REQUIRE_ADVANCED);
CHECK_ERR(ppc, "BTT Map and / or BTT Flog contain invalid "
"entries");
check_end(ppc->data);
goto cleanup;
}
if (loc->list_inval->count > 0) {
CHECK_ASK(ppc, Q_REPAIR_MAP, "Do you want to repair invalid "
"BTT Map entries?");
}
if (loc->list_flog_inval->count > 0) {
CHECK_ASK(ppc, Q_REPAIR_FLOG, "Do you want to repair invalid "
"BTT Flog entries?");
}
return check_questions_sequence_validate(ppc);
error_push:
CHECK_ERR(ppc, "arena %u: cannot allocate momory for list item",
arenap->id);
ppc->result = CHECK_RESULT_ERROR;
cleanup:
cleanup(ppc, loc);
return -1;
}
/*
* arena_map_flog_fix -- (internal) fix map and flog
*/
static int
arena_map_flog_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question,
void *ctx)
{
LOG(3, NULL);
ASSERTeq(ctx, NULL);
ASSERTne(loc, NULL);
struct arena *arenap = loc->arenap;
uint32_t inval;
uint32_t unmap;
switch (question) {
case Q_REPAIR_MAP:
/*
* Cause first of duplicated map entries seems valid till we
* find second of them we must find all first map entries
* pointing to the postmap LBA's we know are duplicated to mark
* them with error flag.
*/
for (uint32_t i = 0; i < arenap->btt_info.external_nlba; i++) {
uint32_t lba = map_get_postmap_lba(arenap, i);
if (lba >= arenap->btt_info.internal_nlba)
continue;
if (!util_isset(loc->dup_bitmap, lba))
continue;
arenap->map[i] = BTT_MAP_ENTRY_ERROR | lba;
util_clrbit(loc->dup_bitmap, lba);
CHECK_INFO(ppc,
"arena %u: storing 0x%x at %u BTT Map entry",
arenap->id, arenap->map[i], i);
}
/*
* repair invalid or duplicated map entries by using unmapped
* blocks
*/
while (list_pop(loc->list_inval, &inval)) {
if (!list_pop(loc->list_unmap, &unmap)) {
ppc->result = CHECK_RESULT_ERROR;
return -1;
}
arenap->map[inval] = unmap | BTT_MAP_ENTRY_ERROR;
CHECK_INFO(ppc, "arena %u: storing 0x%x at %u BTT Map "
"entry", arenap->id, arenap->map[inval], inval);
}
break;
case Q_REPAIR_FLOG:
/* repair invalid flog entries using unmapped blocks */
while (list_pop(loc->list_flog_inval, &inval)) {
if (!list_pop(loc->list_unmap, &unmap)) {
ppc->result = CHECK_RESULT_ERROR;
return -1;
}
struct btt_flog *flog = (struct btt_flog *)
(arenap->flog + inval * BTT_FLOG_PAIR_ALIGN);
memset(&flog[1], 0, sizeof(flog[1]));
uint32_t entry = unmap | BTT_MAP_ENTRY_ERROR;
flog[0].lba = inval;
flog[0].new_map = entry;
flog[0].old_map = entry;
flog[0].seq = 1;
CHECK_INFO(ppc, "arena %u: repairing BTT Flog at %u "
"with free block entry 0x%x", loc->arenap->id,
inval, entry);
}
break;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
struct step {
int (*check)(PMEMpoolcheck *, location *);
int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *);
};
static const struct step steps[] = {
{
.check = init,
},
{
.check = arena_map_flog_check,
},
{
.fix = arena_map_flog_fix,
},
{
.check = cleanup,
},
{
.check = NULL,
.fix = NULL,
},
};
/*
* step_exe -- (internal) perform single step according to its parameters
*/
static inline int
step_exe(PMEMpoolcheck *ppc, location *loc)
{
ASSERT(loc->step < ARRAY_SIZE(steps));
const struct step *step = &steps[loc->step++];
if (!step->fix)
return step->check(ppc, loc);
if (!check_answer_loop(ppc, loc, NULL, 1, step->fix))
return 0;
cleanup(ppc, loc);
return -1;
}
/*
* check_btt_map_flog -- perform check and fixing of map and flog
*/
void
check_btt_map_flog(PMEMpoolcheck *ppc)
{
LOG(3, NULL);
location *loc = check_get_step_data(ppc->data);
if (ppc->pool->blk_no_layout)
return;
/* initialize check */
if (!loc->arenap && loc->narena == 0 &&
ppc->result != CHECK_RESULT_PROCESS_ANSWERS) {
CHECK_INFO(ppc, "checking BTT Map and Flog");
loc->arenap = TAILQ_FIRST(&ppc->pool->arenas);
loc->narena = 0;
}
while (loc->arenap != NULL) {
/* add info about checking next arena */
if (ppc->result != CHECK_RESULT_PROCESS_ANSWERS &&
loc->step == 0) {
CHECK_INFO(ppc, "arena %u: checking BTT Map and Flog",
loc->narena);
}
/* do all checks */
while (CHECK_NOT_COMPLETE(loc, steps)) {
if (step_exe(ppc, loc))
return;
}
/* jump to next arena */
loc->arenap = TAILQ_NEXT(loc->arenap, next);
loc->narena++;
loc->step = 0;
}
}
| 17,204 | 23.062937 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/rm.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rm.c -- implementation of pmempool_rm() function
*/
#include <errno.h>
#include <fcntl.h>
#include "libpmempool.h"
#include "out.h"
#include "os.h"
#include "util.h"
#include "set.h"
#include "file.h"
#define PMEMPOOL_RM_ALL_FLAGS (\
PMEMPOOL_RM_FORCE |\
PMEMPOOL_RM_POOLSET_LOCAL |\
PMEMPOOL_RM_POOLSET_REMOTE)
#define ERR_F(f, ...) do {\
if (CHECK_FLAG((f), FORCE))\
LOG(2, "!(ignored) " __VA_ARGS__);\
else\
ERR(__VA_ARGS__);\
} while (0)
#define CHECK_FLAG(f, i) ((f) & PMEMPOOL_RM_##i)
struct cb_args {
unsigned flags;
int error;
};
/*
* rm_local -- (internal) remove single local file
*/
static int
rm_local(const char *path, unsigned flags, int is_part_file)
{
int ret = util_unlink_flock(path);
if (!ret) {
LOG(3, "%s: removed", path);
return 0;
}
int oerrno = errno;
os_stat_t buff;
ret = os_stat(path, &buff);
if (!ret) {
if (S_ISDIR(buff.st_mode)) {
errno = EISDIR;
if (is_part_file)
ERR("%s: removing file failed", path);
else
ERR("removing file failed");
return -1;
}
}
errno = oerrno;
if (is_part_file)
ERR_F(flags, "%s: removing file failed", path);
else
ERR_F(flags, "removing file failed");
if (CHECK_FLAG(flags, FORCE))
return 0;
return -1;
}
/*
* rm_remote -- (internal) remove remote replica
*/
static int
rm_remote(const char *node, const char *path, unsigned flags)
{
if (!Rpmem_remove) {
ERR_F(flags, "cannot remove remote replica"
" -- missing librpmem");
return -1;
}
int rpmem_flags = 0;
if (CHECK_FLAG(flags, FORCE))
rpmem_flags |= RPMEM_REMOVE_FORCE;
if (CHECK_FLAG(flags, POOLSET_REMOTE))
rpmem_flags |= RPMEM_REMOVE_POOL_SET;
int ret = Rpmem_remove(node, path, rpmem_flags);
if (ret) {
ERR_F(flags, "%s/%s removing failed", node, path);
if (CHECK_FLAG(flags, FORCE))
ret = 0;
} else {
LOG(3, "%s/%s: removed", node, path);
}
return ret;
}
/*
* rm_cb -- (internal) foreach part callback
*/
static int
rm_cb(struct part_file *pf, void *arg)
{
struct cb_args *args = (struct cb_args *)arg;
int ret;
if (pf->is_remote) {
ret = rm_remote(pf->remote->node_addr, pf->remote->pool_desc,
args->flags);
} else {
ret = rm_local(pf->part->path, args->flags, 1);
}
if (ret)
args->error = ret;
return 0;
}
/*
* pmempool_rmU -- remove pool files or poolsets
*/
#ifndef _WIN32
static inline
#endif
int
pmempool_rmU(const char *path, unsigned flags)
{
LOG(3, "path %s flags %x", path, flags);
int ret;
if (flags & ~PMEMPOOL_RM_ALL_FLAGS) {
ERR("invalid flags specified");
errno = EINVAL;
return -1;
}
int is_poolset = util_is_poolset_file(path);
if (is_poolset < 0) {
os_stat_t buff;
ret = os_stat(path, &buff);
if (!ret) {
if (S_ISDIR(buff.st_mode)) {
errno = EISDIR;
ERR("removing file failed");
return -1;
}
}
ERR_F(flags, "removing file failed");
if (CHECK_FLAG(flags, FORCE))
return 0;
return -1;
}
if (!is_poolset) {
LOG(2, "%s: not a poolset file", path);
return rm_local(path, flags, 0);
}
LOG(2, "%s: poolset file", path);
/* fill up pool_set structure */
struct pool_set *set = NULL;
int fd = os_open(path, O_RDONLY);
if (fd == -1 || util_poolset_parse(&set, path, fd)) {
ERR_F(flags, "parsing poolset file failed");
if (fd != -1)
os_close(fd);
if (CHECK_FLAG(flags, FORCE))
return 0;
return -1;
}
os_close(fd);
if (set->remote) {
/* ignore error - it will be handled in rm_remote() */
(void) util_remote_load();
}
util_poolset_free(set);
struct cb_args args;
args.flags = flags;
args.error = 0;
ret = util_poolset_foreach_part(path, rm_cb, &args);
if (ret == -1) {
ERR_F(flags, "parsing poolset file failed");
if (CHECK_FLAG(flags, FORCE))
return 0;
return ret;
}
ASSERTeq(ret, 0);
if (args.error)
return args.error;
if (CHECK_FLAG(flags, POOLSET_LOCAL)) {
ret = rm_local(path, flags, 0);
if (ret) {
ERR_F(flags, "removing pool set file failed");
} else {
LOG(3, "%s: removed", path);
}
if (CHECK_FLAG(flags, FORCE))
return 0;
return ret;
}
return 0;
}
#ifndef _WIN32
/*
* pmempool_rm -- remove pool files or poolsets
*/
int
pmempool_rm(const char *path, unsigned flags)
{
return pmempool_rmU(path, flags);
}
#else
/*
* pmempool_rmW -- remove pool files or poolsets in widechar
*/
int
pmempool_rmW(const wchar_t *path, unsigned flags)
{
char *upath = util_toUTF8(path);
if (upath == NULL) {
ERR("Invalid poolest/pool file path.");
return -1;
}
int ret = pmempool_rmU(upath, flags);
util_free_UTF8(upath);
return ret;
}
#endif
| 6,151 | 20.893238 | 74 |
c
|
null |
NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/libpmempool/check_backup.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check_backup.c -- pre-check backup
*/
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#include "out.h"
#include "file.h"
#include "os.h"
#include "libpmempool.h"
#include "pmempool.h"
#include "pool.h"
#include "check_util.h"
enum question {
Q_OVERWRITE_EXISTING_FILE,
Q_OVERWRITE_EXISTING_PARTS
};
/*
* location_release -- (internal) release poolset structure
*/
static void
location_release(location *loc)
{
if (loc->set) {
util_poolset_free(loc->set);
loc->set = NULL;
}
}
/*
* backup_nonpoolset_requirements -- (internal) check backup requirements
*/
static int
backup_nonpoolset_requirements(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, "backup_path %s", ppc->backup_path);
int exists = util_file_exists(ppc->backup_path);
if (exists < 0) {
return CHECK_ERR(ppc,
"unable to access the backup destination: %s",
ppc->backup_path);
}
if (!exists) {
errno = 0;
return 0;
}
if ((size_t)util_file_get_size(ppc->backup_path) !=
ppc->pool->set_file->size) {
ppc->result = CHECK_RESULT_ERROR;
return CHECK_ERR(ppc,
"destination of the backup does not match the size of the source pool file: %s",
ppc->backup_path);
}
if (CHECK_WITHOUT_FIXING(ppc)) {
location_release(loc);
loc->step = CHECK_STEP_COMPLETE;
return 0;
}
CHECK_ASK(ppc, Q_OVERWRITE_EXISTING_FILE,
"destination of the backup already exists.|Do you want to overwrite it?");
return check_questions_sequence_validate(ppc);
}
/*
* backup_nonpoolset_overwrite -- (internal) overwrite pool
*/
static int
backup_nonpoolset_overwrite(PMEMpoolcheck *ppc, location *loc,
uint32_t question, void *context)
{
LOG(3, NULL);
ASSERTne(loc, NULL);
switch (question) {
case Q_OVERWRITE_EXISTING_FILE:
if (pool_copy(ppc->pool, ppc->backup_path, 1 /* overwrite */)) {
location_release(loc);
ppc->result = CHECK_RESULT_ERROR;
return CHECK_ERR(ppc, "cannot perform backup");
}
location_release(loc);
loc->step = CHECK_STEP_COMPLETE;
return 0;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
/*
* backup_nonpoolset_create -- (internal) create backup
*/
static int
backup_nonpoolset_create(PMEMpoolcheck *ppc, location *loc)
{
CHECK_INFO(ppc, "creating backup file: %s", ppc->backup_path);
if (pool_copy(ppc->pool, ppc->backup_path, 0)) {
location_release(loc);
ppc->result = CHECK_RESULT_ERROR;
return CHECK_ERR(ppc, "cannot perform backup");
}
location_release(loc);
loc->step = CHECK_STEP_COMPLETE;
return 0;
}
/*
* backup_poolset_requirements -- (internal) check backup requirements
*/
static int
backup_poolset_requirements(PMEMpoolcheck *ppc, location *loc)
{
LOG(3, "backup_path %s", ppc->backup_path);
if (ppc->pool->set_file->poolset->nreplicas > 1) {
CHECK_INFO(ppc,
"backup of a poolset with multiple replicas is not supported");
goto err;
}
if (pool_set_parse(&loc->set, ppc->backup_path)) {
CHECK_INFO_ERRNO(ppc, "invalid poolset backup file: %s",
ppc->backup_path);
goto err;
}
if (loc->set->nreplicas > 1) {
CHECK_INFO(ppc,
"backup to a poolset with multiple replicas is not supported");
goto err_poolset;
}
ASSERTeq(loc->set->nreplicas, 1);
struct pool_replica *srep = ppc->pool->set_file->poolset->replica[0];
struct pool_replica *drep = loc->set->replica[0];
if (srep->nparts != drep->nparts) {
CHECK_INFO(ppc,
"number of part files in the backup poolset must match number of part files in the source poolset");
goto err_poolset;
}
int overwrite_required = 0;
for (unsigned p = 0; p < srep->nparts; p++) {
int exists = util_file_exists(drep->part[p].path);
if (exists < 0) {
CHECK_INFO(ppc,
"unable to access the part of the destination poolset: %s",
ppc->backup_path);
goto err_poolset;
}
if (srep->part[p].filesize != drep->part[p].filesize) {
CHECK_INFO(ppc,
"size of the part %u of the backup poolset does not match source poolset",
p);
goto err_poolset;
}
if (!exists) {
errno = 0;
continue;
}
overwrite_required = true;
if ((size_t)util_file_get_size(drep->part[p].path) !=
srep->part[p].filesize) {
CHECK_INFO(ppc,
"destination of the backup part does not match size of the source part file: %s",
drep->part[p].path);
goto err_poolset;
}
}
if (CHECK_WITHOUT_FIXING(ppc)) {
location_release(loc);
loc->step = CHECK_STEP_COMPLETE;
return 0;
}
if (overwrite_required) {
CHECK_ASK(ppc, Q_OVERWRITE_EXISTING_PARTS,
"part files of the destination poolset of the backup already exist.|"
"Do you want to overwrite them?");
}
return check_questions_sequence_validate(ppc);
err_poolset:
location_release(loc);
err:
ppc->result = CHECK_RESULT_ERROR;
return CHECK_ERR(ppc, "unable to backup poolset");
}
/*
* backup_poolset -- (internal) backup the poolset
*/
static int
backup_poolset(PMEMpoolcheck *ppc, location *loc, int overwrite)
{
struct pool_replica *srep = ppc->pool->set_file->poolset->replica[0];
struct pool_replica *drep = loc->set->replica[0];
for (unsigned p = 0; p < srep->nparts; p++) {
if (overwrite == 0) {
CHECK_INFO(ppc, "creating backup file: %s",
drep->part[p].path);
}
if (pool_set_part_copy(&drep->part[p], &srep->part[p],
overwrite)) {
location_release(loc);
ppc->result = CHECK_RESULT_ERROR;
CHECK_INFO(ppc, "unable to create backup file");
return CHECK_ERR(ppc, "unable to backup poolset");
}
}
return 0;
}
/*
* backup_poolset_overwrite -- (internal) backup poolset with overwrite
*/
static int
backup_poolset_overwrite(PMEMpoolcheck *ppc, location *loc,
uint32_t question, void *context)
{
LOG(3, NULL);
ASSERTne(loc, NULL);
switch (question) {
case Q_OVERWRITE_EXISTING_PARTS:
if (backup_poolset(ppc, loc, 1 /* overwrite */)) {
location_release(loc);
ppc->result = CHECK_RESULT_ERROR;
return CHECK_ERR(ppc, "cannot perform backup");
}
location_release(loc);
loc->step = CHECK_STEP_COMPLETE;
return 0;
default:
ERR("not implemented question id: %u", question);
}
return 0;
}
/*
* backup_poolset_create -- (internal) backup poolset
*/
static int
backup_poolset_create(PMEMpoolcheck *ppc, location *loc)
{
if (backup_poolset(ppc, loc, 0)) {
location_release(loc);
ppc->result = CHECK_RESULT_ERROR;
return CHECK_ERR(ppc, "cannot perform backup");
}
location_release(loc);
loc->step = CHECK_STEP_COMPLETE;
return 0;
}
struct step {
int (*check)(PMEMpoolcheck *, location *);
int (*fix)(PMEMpoolcheck *, location *, uint32_t, void *);
int poolset;
};
static const struct step steps[] = {
{
.check = backup_nonpoolset_requirements,
.poolset = false,
},
{
.fix = backup_nonpoolset_overwrite,
.poolset = false,
},
{
.check = backup_nonpoolset_create,
.poolset = false
},
{
.check = backup_poolset_requirements,
.poolset = true,
},
{
.fix = backup_poolset_overwrite,
.poolset = true,
},
{
.check = backup_poolset_create,
.poolset = true
},
{
.check = NULL,
.fix = NULL,
},
};
/*
* step_exe -- (internal) perform single step according to its parameters
*/
static int
step_exe(PMEMpoolcheck *ppc, location *loc)
{
ASSERT(loc->step < ARRAY_SIZE(steps));
const struct step *step = &steps[loc->step++];
if (step->poolset == 0 && ppc->pool->params.is_poolset == 1)
return 0;
if (!step->fix)
return step->check(ppc, loc);
if (!check_has_answer(ppc->data))
return 0;
if (check_answer_loop(ppc, loc, NULL, 1, step->fix))
return -1;
ppc->result = CHECK_RESULT_CONSISTENT;
return 0;
}
/*
* check_backup -- perform backup if requested and needed
*/
void
check_backup(PMEMpoolcheck *ppc)
{
LOG(3, "backup_path %s", ppc->backup_path);
if (ppc->backup_path == NULL)
return;
location *loc = check_get_step_data(ppc->data);
/* do all checks */
while (CHECK_NOT_COMPLETE(loc, steps)) {
if (step_exe(ppc, loc))
break;
}
}
| 9,483 | 22.889169 | 103 |
c
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.