Inconsistency bugs in array example for libpmemobj
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 callsalloc_intin Snippet B and finally reaches Snippet A'salloc_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
infoin 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;
}
===============================================
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
Additional information about Priority and Help Requested:
Are you willing to submit a pull request with a proposed change? (Yes, No)
Requested priority: High
You are right, thanks for reporting this. I looked over that whole example, and I think it should be either rewritten or removed entirely.