Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
CORTX-31907- panic at m0_balloc_load_extents() (#2064)
Browse files Browse the repository at this point in the history
Custom build to debug balloc assert due to corrupt btree.

1. Added assert in balloc code in case any btree operation fails.
2. Added debug print in btree code to print error messages specific balloc btrees.
3. Updated assert added in balloc code in when btree operation fails in sync with new btree code.
4. Added assert in case ext creation fails due low memory also if alloc/free db update returns error.

Signed-off-by: Mukund Kanekar <mukund.kanekar@seagate.com>
  • Loading branch information
mukundkanekar authored Aug 9, 2022
1 parent 5423084 commit 705e891
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion balloc/balloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,7 @@ static int balloc_alloc_db_update(struct m0_balloc *motr, struct m0_be_tx *tx,
key = (struct m0_buf)M0_BUF_INIT_PTR(&cur->e_end);

rc = btree_delete_sync(db, tx, &key);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);

Expand All @@ -1721,6 +1722,7 @@ static int balloc_alloc_db_update(struct m0_balloc *motr, struct m0_be_tx *tx,
/* +------+-------+--------------------+ */
cur->e_end = tgt->e_start;
rc = balloc_ext_insert(db, tx, *cur);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);
maxchunk = max_check(maxchunk, m0_ext_length(cur));
Expand All @@ -1742,6 +1744,7 @@ static int balloc_alloc_db_update(struct m0_balloc *motr, struct m0_be_tx *tx,
/* +------------+----------------------+ */
cur->e_start = tgt->e_end;
rc = balloc_ext_update(db, tx, *cur);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);

Expand All @@ -1754,9 +1757,11 @@ static int balloc_alloc_db_update(struct m0_balloc *motr, struct m0_be_tx *tx,
/* +-------+---------+-----------------+ */
new.e_end = tgt->e_start;
le = lext_create(&new);
M0_ASSERT(le != NULL);
if (le == NULL)
return M0_RC(-ENOMEM);
rc = balloc_ext_insert(db, tx, new);
M0_ASSERT(rc == 0);
if (rc != 0) {
m0_free(le);
return M0_RC(rc);
Expand Down Expand Up @@ -1854,9 +1859,11 @@ static int balloc_free_db_update(struct m0_balloc *motr,
/* | | tgt free | | */
/* +-------+------------------+--------+ */
le = lext_create(tgt);
M0_ASSERT(le != NULL);
if (le == NULL)
return M0_RC(-ENOMEM);
rc = balloc_ext_insert(db, tx, *tgt);
M0_ASSERT(rc == 0);
if (rc != 0) {
m0_free(le);
return M0_RC(rc);
Expand All @@ -1873,9 +1880,11 @@ static int balloc_free_db_update(struct m0_balloc *motr,
/* | | | tgt free | */
/* +-----------+--+--------------------+ */
le = lext_create(tgt);
M0_ASSERT(le != NULL);
if (le == NULL)
return M0_RC(-ENOMEM);
rc = balloc_ext_insert(db, tx, *tgt);
M0_ASSERT(rc == 0);
if (rc != 0) {
m0_free(le);
return M0_RC(rc);
Expand All @@ -1891,10 +1900,12 @@ static int balloc_free_db_update(struct m0_balloc *motr,
M0_ASSERT(cur->e_end == tgt->e_start);
key = (struct m0_buf)M0_BUF_INIT_PTR(&cur->e_end);
rc = btree_delete_sync(db, tx, &key);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);
cur->e_end = tgt->e_end;
rc = balloc_ext_insert(db, tx, *cur);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);
maxchunk = max_check(maxchunk, m0_ext_length(cur));
Expand All @@ -1909,9 +1920,11 @@ static int balloc_free_db_update(struct m0_balloc *motr,
/* | | tgt | | | */
/* +-+---------+---+-------------------+ */
le = lext_create(tgt);
M0_ASSERT(le != NULL);
if (le == NULL)
return M0_RC(-ENOMEM);
rc = balloc_ext_insert(db, tx, *tgt);
M0_ASSERT(rc == 0);
if (rc != 0) {
m0_free(le);
return M0_RC(rc);
Expand All @@ -1928,6 +1941,7 @@ static int balloc_free_db_update(struct m0_balloc *motr,
M0_ASSERT(tgt->e_end == cur->e_start);
cur->e_start = tgt->e_start;
rc = balloc_ext_update(db, tx, *cur);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);
maxchunk = max_check(maxchunk, m0_ext_length(cur));
Expand All @@ -1943,10 +1957,12 @@ static int balloc_free_db_update(struct m0_balloc *motr,
/* +-------+-------+-------------------+ */
key = (struct m0_buf)M0_BUF_INIT_PTR(&pre->e_end);
rc = btree_delete_sync(db, tx, &key);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);
cur->e_start = pre->e_start;
rc = balloc_ext_update(db, tx, *cur);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);
le = container_of(pre, struct m0_lext, le_ext);
Expand All @@ -1961,10 +1977,12 @@ static int balloc_free_db_update(struct m0_balloc *motr,
/* +-------+-------+-------------------+ */
key = (struct m0_buf)M0_BUF_INIT_PTR(&pre->e_end);
rc = btree_delete_sync(db, tx, &key);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);
pre->e_end = tgt->e_end;
rc = balloc_ext_insert(db, tx, *pre);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);
maxchunk = max_check(maxchunk, m0_ext_length(pre));
Expand All @@ -1976,6 +1994,7 @@ static int balloc_free_db_update(struct m0_balloc *motr,
/* +----------+-------+----------------+ */
cur->e_start = tgt->e_start;
rc = balloc_ext_update(db, tx, *cur);
M0_ASSERT(rc == 0);
if (rc != 0)
return M0_RC(rc);
maxchunk = max_check(maxchunk, m0_ext_length(cur));
Expand All @@ -1986,9 +2005,11 @@ static int balloc_free_db_update(struct m0_balloc *motr,
/* | | tgt | | */
/* +----------+-------+----------------+ */
le = lext_create(tgt);
M0_ASSERT(le != NULL);
if (le == NULL)
return M0_RC(-ENOMEM);
rc = balloc_ext_insert(db, tx, *tgt);
M0_ASSERT(rc == 0);
if (rc != 0) {
m0_free(le);
return M0_RC(rc);
Expand Down Expand Up @@ -2078,6 +2099,7 @@ static int balloc_find_by_goal(struct m0_balloc_allocation_context *bac)

ret = balloc_alloc_db_update(bac->bac_ctxt, tx, grp,
&bac->bac_final);
M0_ASSERT(ret == 0);
}

m0_balloc_release_extents(grp);
Expand Down Expand Up @@ -2445,6 +2467,7 @@ static int balloc_try_best_found(struct balloc_allocation_context *bac,
&cur));
rc = balloc_alloc_db_update(bac->bac_ctxt, bac->bac_tx, grp,
&bac->bac_final, alloc_flag, cur);
M0_ASSERT(rc == 0);
}
out:
m0_balloc_unlock_group(grp);
Expand Down Expand Up @@ -2646,6 +2669,7 @@ static int allocate_blocks(int cr, struct balloc_allocation_context *bac,
&cur));
rc = balloc_alloc_db_update(bac->bac_ctxt, bac->bac_tx, grp,
&bac->bac_final, alloc_type, cur);
M0_ASSERT(rc == 0);
}
return rc;
}
Expand Down Expand Up @@ -2790,16 +2814,19 @@ static int balloc_free_internal(struct m0_balloc *ctx,
fex.e_end = grp->bgi_spare.bzp_range.e_start;
rc = balloc_free_db_update(ctx, tx, grp, &fex,
M0_BALLOC_NORMAL_ZONE);
M0_ASSERT(rc == 0);
if (rc != 0)
break;
fex.e_start = zone_start_get(grp,
M0_BALLOC_SPARE_ZONE);
fex.e_end = start + step;
alloc_flag = M0_BALLOC_SPARE_ZONE;
}
if (rc == 0)
if (rc == 0) {
rc = balloc_free_db_update(ctx, tx, grp, &fex,
alloc_flag);
M0_ASSERT(rc == 0);
}
m0_balloc_unlock_group(grp);
start += step;
len -= step;
Expand Down Expand Up @@ -2936,6 +2963,7 @@ static int balloc_reserve_extent(struct m0_ad_balloc *ballroom,
}

rc = balloc_alloc_db_update(ctx, tx, grp, ext, alloc_zone, cur);
M0_ASSERT(rc == 0);

out_unlock:
m0_balloc_unlock_group(grp);
Expand Down

0 comments on commit 705e891

Please sign in to comment.