Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency bugs in array example for libpmemobj #4927

Closed
dibang2008 opened this issue Aug 3, 2020 · 1 comment
Closed

Inconsistency bugs in array example for libpmemobj #4927

dibang2008 opened this issue Aug 3, 2020 · 1 comment
Assignees
Labels
libpmemobj src/libpmemobj Type: Bug A previously unknown bug in PMDK
Milestone

Comments

@dibang2008
Copy link

dibang2008 commented Aug 3, 2020

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;
}

===============================================

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

@dibang2008 dibang2008 added the Type: Bug A previously unknown bug in PMDK label Aug 3, 2020
@pbalcer
Copy link
Member

pbalcer commented Aug 18, 2020

You are right, thanks for reporting this.
I looked over that whole example, and I think it should be either rewritten or removed entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libpmemobj src/libpmemobj Type: Bug A previously unknown bug in PMDK
Projects
None yet
Development

No branches or pull requests

4 participants