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

Commit

Permalink
CORTX-33586: ctgdump is crashing after new btree merge (#1974)
Browse files Browse the repository at this point in the history
Issue:
- ctg_open() is responsible for allocating tree pointer and
  opening the btree. This was missing before accessing the
  catalogue tree in the ctgdump().

Fix:
- Added ctg_open() call before accessing tree pointer.
- Added m0_btree_close() to close tree in ctg_fini().
- Fix for ctg_fini() might get called on null tree reference.

Signed-off-by: Kanchan Chaudhari <kanchan.chaudhari@seagate.com>
  • Loading branch information
kanchan-chaudhari authored Jul 15, 2022
1 parent 2730e68 commit 65bcdcb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
7 changes: 3 additions & 4 deletions be/extmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,9 @@ m0_be_emap_init(struct m0_be_emap *map, struct m0_be_seg *db)
{
struct m0_btree_op b_op = {};
int rc;
struct m0_btree_rec_key_op keycmp;
struct m0_btree_rec_key_op keycmp = { .rko_keycmp = be_emap_cmp };
be_emap_init(map, db);

keycmp.rko_keycmp = be_emap_cmp;
M0_ALLOC_PTR(map->em_mapping);
if (map->em_mapping == NULL)
M0_ASSERT(0);
Expand Down Expand Up @@ -388,7 +387,7 @@ M0_INTERNAL void m0_be_emap_create(struct m0_be_emap *map,
struct m0_btree_op b_op = {};
struct m0_fid fid;
int rc;
struct m0_btree_rec_key_op keycmp;
struct m0_btree_rec_key_op keycmp = { .rko_keycmp = be_emap_cmp };
M0_PRE(map->em_seg != NULL);

m0_be_op_active(op);
Expand All @@ -402,7 +401,7 @@ M0_INTERNAL void m0_be_emap_create(struct m0_be_emap *map,
.ksize = sizeof(struct m0_be_emap_key),
.vsize = -1,
};
keycmp.rko_keycmp = be_emap_cmp;

fid = M0_FID_TINIT('b', M0_BT_EMAP_EM_MAPPING, bfid->f_key);
rc = M0_BTREE_OP_SYNC_WITH_RC(&b_op,
m0_btree_create(&map->em_mp_node,
Expand Down
22 changes: 16 additions & 6 deletions cas/ctg_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,18 @@ static void ctg_open(struct m0_cas_ctg *ctg, struct m0_be_seg *seg)

static void ctg_fini(struct m0_cas_ctg *ctg)
{
struct m0_btree_op b_op = {};
int rc;

M0_ENTRY("ctg=%p", ctg);

ctg->cc_inited = false;
m0_free0(&ctg->cc_tree);
if (ctg->cc_tree != NULL) {
rc = M0_BTREE_OP_SYNC_WITH_RC(&b_op,
m0_btree_close(ctg->cc_tree, &b_op));
M0_ASSERT(rc == 0);
m0_free0(&ctg->cc_tree);
}
m0_long_lock_fini(m0_ctg_lock(ctg));
m0_chan_fini_lock(&ctg->cc_chan.bch_chan);
m0_mutex_fini(&ctg->cc_chan_guard.bm_u.mutex);
Expand Down Expand Up @@ -499,6 +507,7 @@ int m0_ctg_create(struct m0_be_seg *seg, struct m0_be_tx *tx,
&b_op, ctg->cc_tree,
seg, fid, tx, &key_cmp));
if (rc != 0) {
m0_free0(&ctg->cc_tree);
ctg_fini(ctg);
M0_BE_FREE_PTR_SYNC(ctg, seg, tx);
}
Expand All @@ -517,6 +526,7 @@ static void ctg_destroy(struct m0_cas_ctg *ctg, struct m0_be_tx *tx)
rc = M0_BTREE_OP_SYNC_WITH_RC(&b_op, m0_btree_destroy(ctg->cc_tree,
&b_op, tx));
M0_ASSERT(rc == 0);
m0_free0(&ctg->cc_tree);
ctg_fini(ctg);
M0_BE_FREE_PTR_SYNC(ctg, cas_seg(tx->t_engine->eng_domain), tx);
}
Expand Down Expand Up @@ -2462,12 +2472,12 @@ M0_INTERNAL int ctg_index_btree_dump(struct m0_motr *motr_ctx,
struct m0_cas_ctg *ctg,
bool dump_in_hex)
{
struct m0_buf key;
struct m0_buf val;
struct m0_btree_cursor cursor;
int rc;
struct m0_buf key;
struct m0_buf val;
struct m0_btree_cursor cursor;
int rc;

ctg_init(ctg, cas_seg(&motr_ctx->cc_reqh_ctx.rc_be.but_dom));
ctg_open(ctg, cas_seg(&motr_ctx->cc_reqh_ctx.rc_be.but_dom));

m0_btree_cursor_init(&cursor, ctg->cc_tree);
for (rc = m0_btree_cursor_first(&cursor); rc == 0;
Expand Down

0 comments on commit 65bcdcb

Please sign in to comment.