Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Dagnelie <[email protected]>
  • Loading branch information
pcd1193182 committed Oct 10, 2024
1 parent 9963866 commit 0ddbdfd
Show file tree
Hide file tree
Showing 39 changed files with 5,089 additions and 10,673 deletions.
57 changes: 56 additions & 1 deletion cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -7007,7 +7007,8 @@ chain_map_count_blocks(spa_t *spa, zdb_cb_t *zbc)
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);
chain_map_count_blk_cb, chain_map_count_lr_cb,
zbc);
}
}
}
Expand Down Expand Up @@ -8380,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 @@ -8461,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
131 changes: 98 additions & 33 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,10 @@ get_usage(zpool_help_t idx)
"\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
"[-R root] [-F [-n]] -a\n"
"\timport [-o mntopts] [-o property=value] ... \n"
"\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m -L pool] "
"[-N] [-R root] [-F [-n]]\n"
"\t [--rewind-to-checkpoint] <pool | id> [newpool]\n"));
"\t [-d dir | -c cachefile] [-D] [-l] [-f] "
"[-m [-L pool]] [-N] [-R root]\n"
"\t [-F [-n]] [--rewind-to-checkpoint] <pool | id> "
"[newpool]\n"));
case HELP_IOSTAT:
return (gettext("\tiostat [[[-c [script1,script2,...]"
"[-lq]]|[-rw]] [-T d | u] [-ghHLpPvy]\n"
Expand Down Expand Up @@ -1536,8 +1537,7 @@ zpool_do_add(int argc, char **argv)

/* pass off to make_root_vdev for processing */
nvroot = make_root_vdev(zhp, props, !check_inuse,
check_replication, B_FALSE, dryrun, has_shared_log, argc,
argv);
check_replication, B_FALSE, dryrun, has_shared_log, argc, argv);
if (nvroot == NULL) {
zpool_close(zhp);
return (1);
Expand Down Expand Up @@ -4037,10 +4037,31 @@ import_pools(nvlist_t *pools, nvlist_t *props, char *mntopts, int flags,
uint_t npools = 0;


int err = 0;
nvpair_t *elem = NULL, *next = NULL;
boolean_t first = B_TRUE;
tpool_t *tp = NULL;
if (import->do_all) {
tp = tpool_create(1, 5 * sysconf(_SC_NPROCESSORS_ONLN),
0, NULL);

elem = nvlist_next_nvpair(pools, NULL);
next = nvlist_next_nvpair(pools, elem);

while (elem != NULL) {
verify(nvpair_value_nvlist(elem, &config) == 0);
if (fnvlist_lookup_boolean(config,
ZPOOL_CONFIG_IS_SHARED_LOG)) {
err = do_import(config, NULL, mntopts, props,
flags, mount_tp_nthr);
first = B_FALSE;
fnvlist_remove_nvpair(pools, elem);
}
elem = next;
next = nvlist_next_nvpair(pools, elem);
}
if (err != 0)
return (err);
}

/*
Expand All @@ -4049,9 +4070,6 @@ import_pools(nvlist_t *pools, nvlist_t *props, char *mntopts, int flags,
* post-process the list to deal with pool state and possible
* duplicate names.
*/
int err = 0;
nvpair_t *elem = NULL;
boolean_t first = B_TRUE;
if (!pool_specified && import->do_all) {
while ((elem = nvlist_next_nvpair(pools, elem)) != NULL)
npools++;
Expand Down Expand Up @@ -7109,7 +7127,7 @@ collect_vdev_prop(zpool_prop_t prop, uint64_t value, const char *str,
static void
collect_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
list_cbdata_t *cb, int depth, boolean_t isspare, boolean_t recurse,
nvlist_t *item)
nvlist_t *item)
{
nvlist_t **child;
vdev_stat_t *vs;
Expand Down Expand Up @@ -7283,8 +7301,8 @@ collect_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,

if (!printed && !cb->cb_json) {
/* LINTED E_SEC_PRINTF_VAR_FMT */
(void) printf(dashes, depth + 2, "", cb->cb_namewidth,
class_name[n]);
(void) printf(dashes, depth + 2, "",
cb->cb_namewidth, class_name[n]);
printed = B_TRUE;
}
vname = zpool_vdev_name(g_zfs, zhp, child[c],
Expand All @@ -7303,12 +7321,13 @@ collect_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
uint64_t shared_log_guid;
if (name == NULL && nvlist_lookup_uint64(zpool_get_config(zhp, NULL),
ZPOOL_CONFIG_SHARED_LOG_POOL, &shared_log_guid) == 0) {
nvlist_t *sl;
nvlist_t *sl = NULL;
if (cb->cb_json) {
sl = fnvlist_alloc();
} else {
/* LINTED E_SEC_PRINTF_VAR_FMT */
(void) printf(dashes, depth + 2, "", cb->cb_namewidth, "shared log");
(void) printf(dashes, depth + 2, "", cb->cb_namewidth,
"shared log");
}
zpool_handle_t *shared_log = find_by_guid(g_zfs,
shared_log_guid);
Expand All @@ -7318,8 +7337,8 @@ collect_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
nvlist_t *nvroot;
VERIFY0(nvlist_lookup_nvlist(shared_log_config,
ZPOOL_CONFIG_VDEV_TREE, &nvroot));
collect_list_stats(shared_log, zpool_get_name(shared_log), nvroot,
cb, depth + 4, B_FALSE, B_FALSE, sl);
collect_list_stats(shared_log, zpool_get_name(shared_log),
nvroot, cb, depth + 4, B_FALSE, B_FALSE, sl);
zpool_close(shared_log);
if (cb->cb_json) {
if (!nvlist_empty(sl))
Expand All @@ -7334,7 +7353,8 @@ collect_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
l2c = fnvlist_alloc();
} else {
/* LINTED E_SEC_PRINTF_VAR_FMT */
(void) printf(dashes, depth + 2, "", cb->cb_namewidth, "cache");
(void) printf(dashes, depth + 2, "", cb->cb_namewidth,
"cache");
}
for (c = 0; c < children; c++) {
vname = zpool_vdev_name(g_zfs, zhp, child[c],
Expand All @@ -7356,7 +7376,8 @@ collect_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
sp = fnvlist_alloc();
} else {
/* LINTED E_SEC_PRINTF_VAR_FMT */
(void) printf(dashes, depth + 2, "", cb->cb_namewidth, "spare");
(void) printf(dashes, depth + 2, "", cb->cb_namewidth,
"spare");
}
for (c = 0; c < children; c++) {
vname = zpool_vdev_name(g_zfs, zhp, child[c],
Expand Down Expand Up @@ -7412,7 +7433,8 @@ list_callback(zpool_handle_t *zhp, void *data)
}
nvdevs = fnvlist_alloc();
}
collect_list_stats(zhp, NULL, nvroot, cbp, 0, B_FALSE, B_TRUE, nvdevs);
collect_list_stats(zhp, NULL, nvroot, cbp, 0, B_FALSE, B_TRUE,
nvdevs);
if (cbp->cb_json) {
fnvlist_add_nvlist(p, "vdevs", nvdevs);
if (cbp->cb_json_pool_key_guid)
Expand Down Expand Up @@ -8690,31 +8712,36 @@ struct recycle_data {
boolean_t verbose;
};

static void
print_recycle_info(nvlist_t *nvl, boolean_t dryrun)
{
printf("Cleaned up%s: [", dryrun ? " (dry run)" : "");
nvpair_t *elem = NULL;
boolean_t first = B_TRUE;
while ((elem = nvlist_next_nvpair(nvl, elem))) {
printf("%s%s", first ? "" : ",\n\t", nvpair_name(elem));
first = B_FALSE;
}
printf("]\n");
}

static int
recycle_callback(zpool_handle_t *zhp, void *data)
{
struct recycle_data *rd = data;
nvlist_t *nvl;

int err = lzc_recycle(zpool_get_name(zhp), rd->dryrun, &nvl);
int err = lzc_recycle(zpool_get_name(zhp), NULL, rd->dryrun, &nvl);
if (err)
return (err);
if (rd->verbose) {
printf("Cleaned up%s: [", rd->dryrun ? " (dry run)" : "");
nvpair_t *elem = NULL;
boolean_t first = B_TRUE;
while ((elem = nvlist_next_nvpair(nvl, elem))) {
printf("%s%s", first ? "" : ",\n\t", nvpair_name(elem));
first = B_FALSE;
}
printf("]\n");
}
if (rd->verbose)
print_recycle_info(nvl, rd->dryrun);
nvlist_free(nvl);
return (0);
}

/*
* zpool recycle <pool> ...
* zpool recycle [-a] [-n] [-v] <pool> [pool]...
*
* Cleans up chain maps for non-attached client pools
*/
Expand All @@ -8723,16 +8750,20 @@ zpool_do_recycle(int argc, char **argv)
{
int c;
struct recycle_data rd = {0};
boolean_t doall = B_FALSE;

/* check options */
while ((c = getopt(argc, argv, "nv")) != -1) {
while ((c = getopt(argc, argv, "nva")) != -1) {
switch (c) {
case 'n':
rd.dryrun = B_TRUE;
zfs_fallthrough;
case 'v':
rd.verbose = B_TRUE;
break;
case 'a':
doall = B_TRUE;
break;
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
Expand All @@ -8746,10 +8777,44 @@ zpool_do_recycle(int argc, char **argv)
if (argc < 1) {
(void) fprintf(stderr, gettext("missing pool name argument\n"));
usage(B_FALSE);
} else if (argc == 1 && !doall) {
(void) fprintf(stderr, gettext("missing client pools\n"));
usage(B_FALSE);
} else if (argc > 1 && doall) {
(void) fprintf(stderr, gettext("specific client pools and "
"do_all\n"));
usage(B_FALSE);
}

return (for_each_pool(argc, argv, B_TRUE, NULL, ZFS_TYPE_POOL,
B_FALSE, recycle_callback, &rd));
if (doall) {
return (for_each_pool(argc, argv, B_TRUE, NULL, ZFS_TYPE_POOL,
B_FALSE, recycle_callback, &rd));
}

const char *pool = argv[0];
argc--;
argv++;

nvlist_t *clients = NULL;
if (argc > 0)
clients = fnvlist_alloc();
while (argc > 0) {
fnvlist_add_boolean(clients, argv[0]);
argc--;
argv++;
}

nvlist_t *nvl;
int err = lzc_recycle(pool, clients, rd.dryrun, &nvl);
if (clients)
nvlist_free(clients);
if (err)
return (err);
if (rd.verbose)
print_recycle_info(nvl, rd.dryrun);
nvlist_free(nvl);

return (0);
}

/*
Expand Down
Loading

0 comments on commit 0ddbdfd

Please sign in to comment.