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

Implement shared log pool for ZFS #14520

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 115 additions & 2 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2019 by Delphix. All rights reserved.
* Copyright (c) 2011, 2024 by Delphix. All rights reserved.
* Copyright (c) 2014 Integros [integros.com]
* Copyright 2016 Nexenta Systems, Inc.
* Copyright (c) 2017, 2018 Lawrence Livermore National Security, LLC.
Expand Down Expand Up @@ -6011,6 +6011,17 @@ zdb_count_block(zdb_cb_t *zcb, zilog_t *zilog, const blkptr_t *bp,
if (!do_claim)
return;


/*
* Theoretically, we could try to track leaks here, but it would
* require also importing the shared log pool and processing the
* chain map and space maps for it. ZDB currently doesn't have
* much facility to support multiple pools at once, so we leave this
* for future work.
*/
if (zilog && zilog->zl_spa != zilog->zl_io_spa)
return;

VERIFY0(zio_wait(zio_claim(NULL, zcb->zcb_spa,
spa_min_claim_txg(zcb->zcb_spa), bp, NULL, NULL,
ZIO_FLAG_CANFAIL)));
Expand Down Expand Up @@ -6960,6 +6971,48 @@ zdb_brt_entry_compare(const void *zcn1, const void *zcn2)
return (cmp);
}

static int
chain_map_count_blk_cb(spa_t *spa, const blkptr_t *bp, void *arg)
{
(void) spa;
zdb_cb_t *zbc = arg;
zdb_count_block(zbc, NULL, bp, ZDB_OT_OTHER);
return (0);
}

static int
chain_map_count_lr_cb(spa_t *spa, const lr_t *lrc, void *arg)
{
(void) spa;
zdb_cb_t *zbc = arg;
lr_write_t *lr = (lr_write_t *)lrc;
blkptr_t *bp = &lr->lr_blkptr;
if (lrc->lrc_txtype != TX_WRITE || BP_IS_HOLE(bp))
return (0);
zdb_count_block(zbc, NULL, bp, ZDB_OT_OTHER);
return (0);
}

/*
* Count the blocks in the chain maps.
*/
static void
chain_map_count_blocks(spa_t *spa, zdb_cb_t *zbc)
{
avl_tree_t *pool_t = &spa->spa_chain_map;

for (spa_chain_map_pool_t *pool_node = avl_first(pool_t);
pool_node != NULL; pool_node = AVL_NEXT(pool_t, pool_node)) {
avl_tree_t *os_t = &pool_node->scmp_os_tree;
for (spa_chain_map_os_t *os_node = avl_first(os_t);
os_node != NULL; os_node = AVL_NEXT(os_t, os_node)) {
(void) zil_parse_raw(spa, &os_node->scmo_chain_head,
chain_map_count_blk_cb, chain_map_count_lr_cb,
zbc);
}
}
}

static int
dump_block_stats(spa_t *spa)
{
Expand Down Expand Up @@ -7025,6 +7078,10 @@ dump_block_stats(spa_t *spa)

deleted_livelists_count_blocks(spa, zcb);

if (spa_is_shared_log(spa)) {
chain_map_count_blocks(spa, zcb);
}

if (dump_opt['c'] > 1)
flags |= TRAVERSE_PREFETCH_DATA;

Expand Down Expand Up @@ -7378,7 +7435,7 @@ zdb_ddt_add_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
zdb_ddt_entry_t *zdde, zdde_search;

if (zb->zb_level == ZB_DNODE_LEVEL || BP_IS_HOLE(bp) ||
BP_IS_EMBEDDED(bp))
BP_IS_EMBEDDED(bp) || (zilog && zilog->zl_spa != zilog->zl_io_spa))
return (0);

if (dump_opt['S'] > 1 && zb->zb_level == ZB_ROOT_LEVEL) {
Expand Down Expand Up @@ -8148,6 +8205,8 @@ dump_mos_leaks(spa_t *spa)
scip_next_mapping_object);
mos_obj_refd(spa->spa_condensing_indirect_phys.
scip_prev_obsolete_sm_object);
if (spa_is_shared_log(spa))
mos_obj_refd(spa->spa_dsl_pool->dp_chain_map_obj);
if (spa->spa_condensing_indirect_phys.scip_next_mapping_object != 0) {
vdev_indirect_mapping_t *vim =
vdev_indirect_mapping_open(mos,
Expand Down Expand Up @@ -8322,6 +8381,57 @@ dump_log_spacemap_obsolete_stats(spa_t *spa)
(u_longlong_t)lsos.lsos_total_entries);
}

static void print_blkptr(const blkptr_t *bp)
{
char blkbuf[BP_SPRINTF_LEN];
snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
if (dump_opt['Z'] && BP_GET_COMPRESS(bp) == ZIO_COMPRESS_ZSTD)
snprintf_zstd_header(spa, blkbuf, sizeof (blkbuf), bp);
(void) printf("%s\n", blkbuf);

}

static int
chain_map_dump_blk_cb(spa_t *spa, const blkptr_t *bp, void *arg)
{
(void) spa, (void) arg;
printf("\t\t\tBP: ");
print_blkptr(bp);
return (0);
}

static int
chain_map_dump_lr_cb(spa_t *spa, const lr_t *lrc, void *arg)
{
(void) spa, (void) arg;
lr_write_t *lr = (lr_write_t *)lrc;
blkptr_t *bp = &lr->lr_blkptr;
printf("\t\t\tLR BP: ");
print_blkptr(bp);
return (0);
}

static void
dump_chain_map(spa_t *spa)
{
(void) printf("Chain map contents:\n");
avl_tree_t *pool_t = &spa->spa_chain_map;

for (spa_chain_map_pool_t *pool_node = avl_first(pool_t);
pool_node != NULL; pool_node = AVL_NEXT(pool_t, pool_node)) {
avl_tree_t *os_t = &pool_node->scmp_os_tree;
(void) printf("\tPool entry: %s\n", pool_node->scmp_name);
for (spa_chain_map_os_t *os_node = avl_first(os_t);
os_node != NULL; os_node = AVL_NEXT(os_t, os_node)) {
(void) printf("\t\tObjset entry: %"PRIu64"\n\t\t\t",
os_node->scmo_id);
print_blkptr(&os_node->scmo_chain_head);
(void) zil_parse_raw(spa, &os_node->scmo_chain_head,
chain_map_dump_blk_cb, chain_map_dump_lr_cb, NULL);
}
}
}

static void
dump_zpool(spa_t *spa)
{
Expand Down Expand Up @@ -8403,6 +8513,9 @@ dump_zpool(spa_t *spa)
(void) dmu_objset_find(spa_name(spa), dump_one_objset,
NULL, DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN);

if (spa_is_shared_log(spa))
dump_chain_map(spa);

if (rc == 0 && !dump_opt['L'])
rc = dump_mos_leaks(spa);

Expand Down
5 changes: 3 additions & 2 deletions cmd/zhack.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fatal(spa_t *spa, const void *tag, const char *fmt, ...)

if (spa != NULL) {
spa_close(spa, tag);
(void) spa_export(g_pool, NULL, B_TRUE, B_FALSE);
(void) spa_export(g_pool, NULL, B_TRUE, B_FALSE, NULL);
}

va_start(ap, fmt);
Expand Down Expand Up @@ -1016,7 +1016,8 @@ main(int argc, char **argv)
usage();
}

if (!g_readonly && spa_export(g_pool, NULL, B_TRUE, B_FALSE) != 0) {
if (!g_readonly && spa_export(g_pool, NULL, B_TRUE, B_FALSE,
NULL) != 0) {
fatal(NULL, FTAG, "pool export failed; "
"changes may not be committed to disk\n");
}
Expand Down
Loading
Loading