mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
zpool/zfs: Add '-a|--all' option to scrub, trim, initialize
Add support for the '-a | --all' option to perform trim, scrub, and initialize operations on all pools. Previously, specifying a pool name was mandatory for these operations. With this enhancement, users can now execute these operations across all pools at once, without needing to manually iterate over each pool from the command line. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de> Signed-off-by: Akash B <akash-b@hpe.com> Closes #17524
This commit is contained in:
@@ -1475,6 +1475,11 @@
|
||||
<parameter type-id='80f4b756' name='name'/>
|
||||
<return type-id='a27af98c'/>
|
||||
</function-decl>
|
||||
<function-decl name='zfs_tunable_iter' mangled-name='zfs_tunable_iter' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_tunable_iter'>
|
||||
<parameter type-id='d8d5f4ab' name='cb'/>
|
||||
<parameter type-id='eaa32e2f' name='arg'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<function-decl name='zfs_tunable_set' mangled-name='zfs_tunable_set' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_tunable_set'>
|
||||
<parameter type-id='a27af98c' name='zt'/>
|
||||
<parameter type-id='80f4b756' name='val'/>
|
||||
@@ -1486,11 +1491,6 @@
|
||||
<parameter type-id='b59d7dce' name='valsz'/>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<function-decl name='zfs_tunable_iter' mangled-name='zfs_tunable_iter' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_tunable_iter'>
|
||||
<parameter type-id='d8d5f4ab' name='cb'/>
|
||||
<parameter type-id='eaa32e2f' name='arg'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<function-type size-in-bits='64' id='92f86508'>
|
||||
<parameter type-id='a27af98c'/>
|
||||
<parameter type-id='eaa32e2f'/>
|
||||
|
||||
+24
-5
@@ -483,6 +483,7 @@
|
||||
<elf-symbol name='zpool_clear' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_clear_label' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_close' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_collect_leaves' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_collect_unsup_feat' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_create' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_ddt_prune' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
@@ -532,6 +533,7 @@
|
||||
<elf-symbol name='zpool_import_status' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_in_use' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_initialize' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_initialize_one' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_initialize_wait' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_is_draid_spare' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_iter' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
@@ -581,6 +583,7 @@
|
||||
<elf-symbol name='zpool_state_to_name' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_sync_one' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_trim' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_trim_one' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_upgrade' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_vdev_attach' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
<elf-symbol name='zpool_vdev_clear' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
|
||||
@@ -1655,6 +1658,11 @@
|
||||
<parameter type-id='80f4b756' name='name'/>
|
||||
<return type-id='a27af98c'/>
|
||||
</function-decl>
|
||||
<function-decl name='zfs_tunable_iter' mangled-name='zfs_tunable_iter' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_tunable_iter'>
|
||||
<parameter type-id='d8d5f4ab' name='cb'/>
|
||||
<parameter type-id='eaa32e2f' name='arg'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<function-decl name='zfs_tunable_set' mangled-name='zfs_tunable_set' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_tunable_set'>
|
||||
<parameter type-id='a27af98c' name='zt'/>
|
||||
<parameter type-id='80f4b756' name='val'/>
|
||||
@@ -1666,11 +1674,6 @@
|
||||
<parameter type-id='b59d7dce' name='valsz'/>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<function-decl name='zfs_tunable_iter' mangled-name='zfs_tunable_iter' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_tunable_iter'>
|
||||
<parameter type-id='d8d5f4ab' name='cb'/>
|
||||
<parameter type-id='eaa32e2f' name='arg'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<function-type size-in-bits='64' id='92f86508'>
|
||||
<parameter type-id='a27af98c'/>
|
||||
<parameter type-id='eaa32e2f'/>
|
||||
@@ -6901,6 +6904,11 @@
|
||||
<parameter type-id='95e97e5e' name='flags'/>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<function-decl name='zpool_initialize_one' mangled-name='zpool_initialize_one' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_initialize_one'>
|
||||
<parameter type-id='4c81de99' name='zhp'/>
|
||||
<parameter type-id='eaa32e2f' name='data'/>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<function-decl name='zpool_initialize' mangled-name='zpool_initialize' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_initialize'>
|
||||
<parameter type-id='4c81de99' name='zhp'/>
|
||||
<parameter type-id='7063e1ab' name='cmd_type'/>
|
||||
@@ -6913,6 +6921,17 @@
|
||||
<parameter type-id='5ce45b60' name='vds'/>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<function-decl name='zpool_collect_leaves' mangled-name='zpool_collect_leaves' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_collect_leaves'>
|
||||
<parameter type-id='4c81de99' name='zhp'/>
|
||||
<parameter type-id='5ce45b60' name='nvroot'/>
|
||||
<parameter type-id='5ce45b60' name='res'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<function-decl name='zpool_trim_one' mangled-name='zpool_trim_one' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_trim_one'>
|
||||
<parameter type-id='4c81de99' name='zhp'/>
|
||||
<parameter type-id='eaa32e2f' name='data'/>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<function-decl name='zpool_trim' mangled-name='zpool_trim' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_trim'>
|
||||
<parameter type-id='4c81de99' name='zhp'/>
|
||||
<parameter type-id='b1146b8d' name='cmd_type'/>
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
* Copyright (c) 2018, loli10K <ezomori.nozomu@gmail.com>
|
||||
* Copyright (c) 2021, Colm Buckley <colm@tuatha.org>
|
||||
* Copyright (c) 2021, 2023, Klara Inc.
|
||||
* Copyright (c) 2025 Hewlett Packard Enterprise Development LP.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
@@ -2436,6 +2437,30 @@ xlate_init_err(int err)
|
||||
return (err);
|
||||
}
|
||||
|
||||
int
|
||||
zpool_initialize_one(zpool_handle_t *zhp, void *data)
|
||||
{
|
||||
int error;
|
||||
libzfs_handle_t *hdl = zpool_get_handle(zhp);
|
||||
const char *pool_name = zpool_get_name(zhp);
|
||||
if (zpool_open_silent(hdl, pool_name, &zhp) != 0)
|
||||
return (-1);
|
||||
initialize_cbdata_t *cb = data;
|
||||
nvlist_t *vdevs = fnvlist_alloc();
|
||||
|
||||
nvlist_t *config = zpool_get_config(zhp, NULL);
|
||||
nvlist_t *nvroot = fnvlist_lookup_nvlist(config,
|
||||
ZPOOL_CONFIG_VDEV_TREE);
|
||||
zpool_collect_leaves(zhp, nvroot, vdevs);
|
||||
if (cb->wait)
|
||||
error = zpool_initialize_wait(zhp, cb->cmd_type, vdevs);
|
||||
else
|
||||
error = zpool_initialize(zhp, cb->cmd_type, vdevs);
|
||||
fnvlist_free(vdevs);
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Begin, suspend, cancel, or uninit (clear) the initialization (initializing
|
||||
* of all free blocks) for the given vdevs in the given pool.
|
||||
@@ -2556,6 +2581,58 @@ xlate_trim_err(int err)
|
||||
return (err);
|
||||
}
|
||||
|
||||
void
|
||||
zpool_collect_leaves(zpool_handle_t *zhp, nvlist_t *nvroot, nvlist_t *res)
|
||||
{
|
||||
libzfs_handle_t *hdl = zhp->zpool_hdl;
|
||||
uint_t children = 0;
|
||||
nvlist_t **child;
|
||||
uint_t i;
|
||||
|
||||
(void) nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
|
||||
&child, &children);
|
||||
|
||||
if (children == 0) {
|
||||
char *path = zpool_vdev_name(hdl, zhp, nvroot,
|
||||
VDEV_NAME_PATH);
|
||||
|
||||
if (strcmp(path, VDEV_TYPE_INDIRECT) != 0 &&
|
||||
strcmp(path, VDEV_TYPE_HOLE) != 0)
|
||||
fnvlist_add_boolean(res, path);
|
||||
|
||||
free(path);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < children; i++) {
|
||||
zpool_collect_leaves(zhp, child[i], res);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
zpool_trim_one(zpool_handle_t *zhp, void *data)
|
||||
{
|
||||
int error;
|
||||
libzfs_handle_t *hdl = zpool_get_handle(zhp);
|
||||
const char *pool_name = zpool_get_name(zhp);
|
||||
if (zpool_open_silent(hdl, pool_name, &zhp) != 0)
|
||||
return (-1);
|
||||
|
||||
trim_cbdata_t *cb = data;
|
||||
nvlist_t *vdevs = fnvlist_alloc();
|
||||
|
||||
/* no individual leaf vdevs specified, so add them all */
|
||||
nvlist_t *config = zpool_get_config(zhp, NULL);
|
||||
nvlist_t *nvroot = fnvlist_lookup_nvlist(config,
|
||||
ZPOOL_CONFIG_VDEV_TREE);
|
||||
|
||||
zpool_collect_leaves(zhp, nvroot, vdevs);
|
||||
error = zpool_trim(zhp, cb->cmd_type, vdevs, &cb->trim_flags);
|
||||
fnvlist_free(vdevs);
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
zpool_trim_wait(zpool_handle_t *zhp, nvlist_t *vdev_guids)
|
||||
{
|
||||
|
||||
@@ -1426,6 +1426,11 @@
|
||||
<parameter type-id='80f4b756' name='name'/>
|
||||
<return type-id='a27af98c'/>
|
||||
</function-decl>
|
||||
<function-decl name='zfs_tunable_iter' mangled-name='zfs_tunable_iter' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_tunable_iter'>
|
||||
<parameter type-id='d8d5f4ab' name='cb'/>
|
||||
<parameter type-id='eaa32e2f' name='arg'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<function-decl name='zfs_tunable_set' mangled-name='zfs_tunable_set' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_tunable_set'>
|
||||
<parameter type-id='a27af98c' name='zt'/>
|
||||
<parameter type-id='80f4b756' name='val'/>
|
||||
@@ -1437,11 +1442,6 @@
|
||||
<parameter type-id='b59d7dce' name='valsz'/>
|
||||
<return type-id='95e97e5e'/>
|
||||
</function-decl>
|
||||
<function-decl name='zfs_tunable_iter' mangled-name='zfs_tunable_iter' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zfs_tunable_iter'>
|
||||
<parameter type-id='d8d5f4ab' name='cb'/>
|
||||
<parameter type-id='eaa32e2f' name='arg'/>
|
||||
<return type-id='48b5725f'/>
|
||||
</function-decl>
|
||||
<function-type size-in-bits='64' id='92f86508'>
|
||||
<parameter type-id='a27af98c'/>
|
||||
<parameter type-id='eaa32e2f'/>
|
||||
|
||||
Reference in New Issue
Block a user