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 8, 2024
1 parent 9963866 commit ef89c9a
Show file tree
Hide file tree
Showing 38 changed files with 5,078 additions and 10,665 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
116 changes: 89 additions & 27 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 @@ -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 Down Expand Up @@ -8690,31 +8709,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 +8747,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 +8774,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
12 changes: 6 additions & 6 deletions cmd/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -3070,7 +3070,7 @@ ztest_spa_create_destroy(ztest_ds_t *zd, uint64_t id)
* an export concurrently.
*/
VERIFY0(spa_open(zo->zo_pool, &spa, FTAG));
int error = spa_destroy(zo->zo_pool);
int error = spa_destroy(zo->zo_pool, NULL);
if (error != EBUSY && error != ZFS_ERR_EXPORT_IN_PROGRESS) {
fatal(B_FALSE, "spa_destroy(%s) returned unexpected value %d",
spa->spa_name, error);
Expand Down Expand Up @@ -3172,7 +3172,7 @@ ztest_spa_upgrade(ztest_ds_t *zd, uint64_t id)
/*
* Clean up from previous runs.
*/
(void) spa_destroy(name);
(void) spa_destroy(name, NULL);

raidz_children = ztest_get_raidz_children(ztest_spa);

Expand Down Expand Up @@ -3626,7 +3626,7 @@ ztest_split_pool(ztest_ds_t *zd, uint64_t id)
}

/* clean up the old pool, if any */
(void) spa_destroy("splitp");
(void) spa_destroy("splitp", NULL);

spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);

Expand Down Expand Up @@ -7432,7 +7432,7 @@ ztest_spa_import_export(char *oldname, char *newname)
/*
* Clean up from previous runs.
*/
(void) spa_destroy(newname);
(void) spa_destroy(newname, NULL);

/*
* Get the pool's configuration and guid.
Expand All @@ -7453,7 +7453,7 @@ ztest_spa_import_export(char *oldname, char *newname)
/*
* Export it.
*/
VERIFY0(spa_export(oldname, &config, B_FALSE, B_FALSE));
VERIFY0(spa_export(oldname, &config, B_FALSE, B_FALSE, NULL));

ztest_walk_pool_directory("pools after export");

Expand Down Expand Up @@ -8611,7 +8611,7 @@ ztest_init(ztest_shared_t *zs)
/*
* Create the storage pool.
*/
(void) spa_destroy(ztest_opts.zo_pool);
(void) spa_destroy(ztest_opts.zo_pool, NULL);
ztest_shared->zs_vdev_next_leaf = 0;
zs->zs_splits = 0;
zs->zs_mirrors = ztest_opts.zo_mirrors;
Expand Down
1 change: 1 addition & 0 deletions include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ _LIBZFS_H uint64_t zpool_vdev_path_to_guid(zpool_handle_t *zhp,
const char *path);

_LIBZFS_H const char *zpool_get_state_str(zpool_handle_t *);
_LIBZFS_H zpool_handle_t *zpool_get_shared_log(zpool_handle_t *);

/*
* Functions to manage pool properties
Expand Down
7 changes: 6 additions & 1 deletion include/libzfs_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ _LIBZFS_CORE_H int lzc_wait_fs(const char *, zfs_wait_activity_t, boolean_t *);
_LIBZFS_CORE_H int lzc_set_bootenv(const char *, const nvlist_t *);
_LIBZFS_CORE_H int lzc_get_bootenv(const char *, nvlist_t **);

_LIBZFS_CORE_H int lzc_recycle(const char *, boolean_t, nvlist_t **);
_LIBZFS_CORE_H int lzc_recycle(const char *, nvlist_t *, boolean_t,
nvlist_t **);

_LIBZFS_CORE_H int lzc_get_vdev_prop(const char *, nvlist_t *, nvlist_t **);
_LIBZFS_CORE_H int lzc_set_vdev_prop(const char *, nvlist_t *, nvlist_t **);
Expand All @@ -166,6 +167,10 @@ _LIBZFS_CORE_H int lzc_scrub(zfs_ioc_t, const char *, nvlist_t *, nvlist_t **);
_LIBZFS_CORE_H int lzc_ddt_prune(const char *, zpool_ddt_prune_unit_t,
uint64_t);

_LIBZFS_CORE_H int lzc_pool_destroy(const char *, const char *, nvlist_t **);
_LIBZFS_CORE_H int lzc_pool_export(const char *, const char *, boolean_t,
boolean_t, nvlist_t **);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit ef89c9a

Please sign in to comment.