Skip to content

Commit

Permalink
Merge pull request #2588 from pbalcer/obj-zero-range
Browse files Browse the repository at this point in the history
obj: fix add_range with size == 0
  • Loading branch information
plebioda authored Feb 6, 2018
2 parents 8b0ca0a + cdf0a28 commit 7e4ab76
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/libpmemobj/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ pmemobj_tx_add_common(struct tx *tx, struct tx_range_def *args)
* snapshot and resume the search from the end of the found
* offset.
*/
do {
while (r.size != 0) {
n = ravl_find(runtime->ranges, &r,
RAVL_PREDICATE_GREATER_EQUAL);
f = n ? ravl_data(n) : NULL;
Expand Down Expand Up @@ -1876,7 +1876,7 @@ pmemobj_tx_add_common(struct tx *tx, struct tx_range_def *args)
* finish...
*/
r.size = offd < args->size ? args->size - offd : 0;
} while (r.size != 0);
}

if (ret != 0) {
ERR("out of memory");
Expand Down
21 changes: 19 additions & 2 deletions src/test/obj_tx_add_range/obj_tx_add_range.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017, Intel Corporation
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -85,7 +85,7 @@ struct overlap_object {
* do_tx_alloc -- do tx allocation with specified type number
*/
static PMEMoid
do_tx_zalloc(PMEMobjpool *pop, int type_num)
do_tx_zalloc(PMEMobjpool *pop, uint64_t type_num)
{
PMEMoid ret = OID_NULL;

Expand Down Expand Up @@ -620,6 +620,21 @@ do_tx_add_range_too_large(PMEMobjpool *pop)
UT_ASSERTne(errno, 0);
}

static void
do_tx_add_range_zero(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));

TX_BEGIN(pop) {
pmemobj_tx_add_range(obj.oid, 0, 0);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END

UT_ASSERTne(errno, 0);
}

int
main(int argc, char *argv[])
{
Expand Down Expand Up @@ -664,6 +679,8 @@ main(int argc, char *argv[])
VALGRIND_WRITE_STATS;
do_tx_add_huge_range_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_zero(pop);
VALGRIND_WRITE_STATS;
do_tx_xadd_range_commit(pop);
pmemobj_close(pop);
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/obj_tx_add_range/pmemcheck1.log.match
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
==$(*)== Number of stores not made persistent: 0
==$(*)== ERROR SUMMARY: 0 errors
==$(*)==
==$(*)== Number of stores not made persistent: 0
==$(*)== ERROR SUMMARY: 0 errors
==$(*)==
==$(*)==
==$(*)== Number of stores not made persistent: 1
==$(*)== Stores not made persistent properly:
Expand Down

0 comments on commit 7e4ab76

Please sign in to comment.