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

Commit 65bcdcb

Browse files
CORTX-33586: ctgdump is crashing after new btree merge (#1974)
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 <[email protected]>
1 parent 2730e68 commit 65bcdcb

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

be/extmap.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,9 @@ m0_be_emap_init(struct m0_be_emap *map, struct m0_be_seg *db)
349349
{
350350
struct m0_btree_op b_op = {};
351351
int rc;
352-
struct m0_btree_rec_key_op keycmp;
352+
struct m0_btree_rec_key_op keycmp = { .rko_keycmp = be_emap_cmp };
353353
be_emap_init(map, db);
354354

355-
keycmp.rko_keycmp = be_emap_cmp;
356355
M0_ALLOC_PTR(map->em_mapping);
357356
if (map->em_mapping == NULL)
358357
M0_ASSERT(0);
@@ -388,7 +387,7 @@ M0_INTERNAL void m0_be_emap_create(struct m0_be_emap *map,
388387
struct m0_btree_op b_op = {};
389388
struct m0_fid fid;
390389
int rc;
391-
struct m0_btree_rec_key_op keycmp;
390+
struct m0_btree_rec_key_op keycmp = { .rko_keycmp = be_emap_cmp };
392391
M0_PRE(map->em_seg != NULL);
393392

394393
m0_be_op_active(op);
@@ -402,7 +401,7 @@ M0_INTERNAL void m0_be_emap_create(struct m0_be_emap *map,
402401
.ksize = sizeof(struct m0_be_emap_key),
403402
.vsize = -1,
404403
};
405-
keycmp.rko_keycmp = be_emap_cmp;
404+
406405
fid = M0_FID_TINIT('b', M0_BT_EMAP_EM_MAPPING, bfid->f_key);
407406
rc = M0_BTREE_OP_SYNC_WITH_RC(&b_op,
408407
m0_btree_create(&map->em_mp_node,

cas/ctg_store.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,18 @@ static void ctg_open(struct m0_cas_ctg *ctg, struct m0_be_seg *seg)
435435

436436
static void ctg_fini(struct m0_cas_ctg *ctg)
437437
{
438+
struct m0_btree_op b_op = {};
439+
int rc;
440+
438441
M0_ENTRY("ctg=%p", ctg);
439442

440443
ctg->cc_inited = false;
441-
m0_free0(&ctg->cc_tree);
444+
if (ctg->cc_tree != NULL) {
445+
rc = M0_BTREE_OP_SYNC_WITH_RC(&b_op,
446+
m0_btree_close(ctg->cc_tree, &b_op));
447+
M0_ASSERT(rc == 0);
448+
m0_free0(&ctg->cc_tree);
449+
}
442450
m0_long_lock_fini(m0_ctg_lock(ctg));
443451
m0_chan_fini_lock(&ctg->cc_chan.bch_chan);
444452
m0_mutex_fini(&ctg->cc_chan_guard.bm_u.mutex);
@@ -499,6 +507,7 @@ int m0_ctg_create(struct m0_be_seg *seg, struct m0_be_tx *tx,
499507
&b_op, ctg->cc_tree,
500508
seg, fid, tx, &key_cmp));
501509
if (rc != 0) {
510+
m0_free0(&ctg->cc_tree);
502511
ctg_fini(ctg);
503512
M0_BE_FREE_PTR_SYNC(ctg, seg, tx);
504513
}
@@ -517,6 +526,7 @@ static void ctg_destroy(struct m0_cas_ctg *ctg, struct m0_be_tx *tx)
517526
rc = M0_BTREE_OP_SYNC_WITH_RC(&b_op, m0_btree_destroy(ctg->cc_tree,
518527
&b_op, tx));
519528
M0_ASSERT(rc == 0);
529+
m0_free0(&ctg->cc_tree);
520530
ctg_fini(ctg);
521531
M0_BE_FREE_PTR_SYNC(ctg, cas_seg(tx->t_engine->eng_domain), tx);
522532
}
@@ -2462,12 +2472,12 @@ M0_INTERNAL int ctg_index_btree_dump(struct m0_motr *motr_ctx,
24622472
struct m0_cas_ctg *ctg,
24632473
bool dump_in_hex)
24642474
{
2465-
struct m0_buf key;
2466-
struct m0_buf val;
2467-
struct m0_btree_cursor cursor;
2468-
int rc;
2475+
struct m0_buf key;
2476+
struct m0_buf val;
2477+
struct m0_btree_cursor cursor;
2478+
int rc;
24692479

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

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

0 commit comments

Comments
 (0)