You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ISSUE: Inconsistency bugs in array example for libpmemobj
Environment Information
PMDK package version(s): 1.9
OS(es) version(s): Ubuntu 16 LTS
ndctl version(s): 58+
kernel version(s): 4.4.0-173-generic
compiler, libraries, packaging and other related tools version(s):
Please provide a reproduction of the bug:
It exists inconsistency bugs if calling following command. ./array /mnt/pmem/testfile alloc test2 100 int
How often bug is revealed: Always:
Actual behavior:
When a crash happens in a specified place, it causes inconsistency.
Expected behavior:
It always keeps consistent.
Details
First, line info->array= alloc_array\[type\](size); in Snippet C calls alloc_int in Snippet B and finally reaches Snippet A's alloc_int .
Then, the crash happens in specified place of Snippet A (right before return).
As a result, data of the array are persistent but previous info in Snippet C doesn't guarantee persistency. So it causes inconsistency
Snippet A
alloc_int(size_t size)
{
TOID(int) array;
/*
* To allocate persistent array of simple type is enough to allocate
* pointer with size equal to number of elements multiplied by size of
* user-defined structure.
*/
POBJ_ALLOC(pop, &array, int, sizeof(int) * size,
NULL, NULL);
if (TOID_IS_NULL(array)) {
fprintf(stderr, "POBJ_ALLOC\n");
return OID_NULL;
}
for (size_t i = 0; i < size; i++)
D_RW(array)[i] = (int)i;
pmemobj_persist(pop, D_RW(array), size * sizeof(*D_RW(array))); CRASH HAPPEN
return array.oid;
}
ISSUE: Inconsistency bugs in array example for libpmemobj
Environment Information
Please provide a reproduction of the bug:
It exists inconsistency bugs if calling following command.
./array /mnt/pmem/testfile alloc test2 100 int
How often bug is revealed: Always:
Actual behavior:
When a crash happens in a specified place, it causes inconsistency.
Expected behavior:
It always keeps consistent.
Details
info->array= alloc_array\[type\](size);
in Snippet C callsalloc_int
in Snippet B and finally reaches Snippet A'salloc_int
.info
in Snippet C doesn't guarantee persistency. So it causes inconsistencySnippet A
alloc_int(size_t size)
{
TOID(int) array;
/*
* To allocate persistent array of simple type is enough to allocate
* pointer with size equal to number of elements multiplied by size of
* user-defined structure.
*/
POBJ_ALLOC(pop, &array, int, sizeof(int) * size,
NULL, NULL);
if (TOID_IS_NULL(array)) {
fprintf(stderr, "POBJ_ALLOC\n");
return OID_NULL;
}
for (size_t i = 0; i < size; i++)
D_RW(array)[i] = (int)i;
pmemobj_persist(pop, D_RW(array), size * sizeof(*D_RW(array)));
CRASH HAPPEN
return array.oid;
}
===============================================
Snippet B
static void
static fn_alloc alloc_array[] = {NULL, alloc_int, alloc_pmemoid, alloc_toid};
=================================================
Snippet C
do_alloc(int argc, char *argv[])
{
if (argc != 3) {
printf("usage: ./array alloc "
" \n");
return;
}
enum array_types type = get_type(argv[2]);
if (type == UNKNOWN_ARRAY_TYPE)
return;
size_t size = atoi(argv[1]);
TOID(struct array_info) array_info = find_array(argv[0]);
if (!TOID_IS_NULL(array_info))
POBJ_FREE(&array_info);
POBJ_ZNEW(pop, &array_info, struct array_info);
struct array_info *info = D_RW(array_info);
strncpy(info->name, argv[0], MAX_BUFFLEN - 1);
info->name[MAX_BUFFLEN - 1] = '\0';
info->size = size;
info->type = type;
info->array = alloc_array[type](size);
if (OID_IS_NULL(info->array))
assert(0);
pmemobj_persist(pop, info, sizeof(*info));
}
Additional information about Priority and Help Requested:
Are you willing to submit a pull request with a proposed change? (Yes, No)
Requested priority: High
The text was updated successfully, but these errors were encountered: