Skip to content

Commit

Permalink
Implement shared log pool for ZFS
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Dagnelie <[email protected]>
  • Loading branch information
pcd1193182 committed Jun 16, 2023
1 parent 10e36e1 commit d09d9d2
Show file tree
Hide file tree
Showing 68 changed files with 2,700 additions and 554 deletions.
71 changes: 67 additions & 4 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, 2023 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 All @@ -47,6 +47,7 @@
#include <sys/spa_impl.h>
#include <sys/dmu.h>
#include <sys/zap.h>
#include <sys/zap_impl.h>
#include <sys/fs/zfs.h>
#include <sys/zfs_znode.h>
#include <sys/zfs_sa.h>
Expand Down Expand Up @@ -1185,6 +1186,10 @@ dump_zap(objset_t *os, uint64_t object, void *data, size_t size)
for (zap_cursor_init(&zc, os, object);
zap_cursor_retrieve(&zc, &attr) == 0;
zap_cursor_advance(&zc)) {
if (zap_getflags(zc.zc_zap) & ZAP_FLAG_UINT64_KEY) {
// We can't dump the contents of a UINT64-keyed ZAP.
break;
}
(void) printf("\t\t%s = ", attr.za_name);
if (attr.za_num_integers == 0) {
(void) printf("\n");
Expand Down Expand Up @@ -5668,6 +5673,7 @@ zdb_count_block(zdb_cb_t *zcb, zilog_t *zilog, const blkptr_t *bp,
if (BP_GET_DEDUP(bp)) {
ddt_t *ddt;
ddt_entry_t *dde;
ASSERT3P(zilog, ==, NULL);

ddt = ddt_select(zcb->zcb_spa, bp);
ddt_enter(ddt);
Expand All @@ -5685,9 +5691,19 @@ zdb_count_block(zdb_cb_t *zcb, zilog_t *zilog, const blkptr_t *bp,
ddt_exit(ddt);
}

VERIFY3U(zio_wait(zio_claim(NULL, zcb->zcb_spa,
/*
* 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. The ZIL 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,
refcnt ? 0 : spa_min_claim_txg(zcb->zcb_spa),
bp, NULL, NULL, ZIO_FLAG_CANFAIL)), ==, 0);
bp, NULL, NULL, ZIO_FLAG_CANFAIL)));
}

static void
Expand Down Expand Up @@ -6664,6 +6680,47 @@ deleted_livelists_dump_mos(spa_t *spa)
iterate_deleted_livelists(spa, dump_livelist_cb, NULL);
}

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 @@ -6720,6 +6777,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 @@ -7069,7 +7130,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 @@ -7840,6 +7901,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
Loading

0 comments on commit d09d9d2

Please sign in to comment.