]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Add subcommand to wait for background zfs activity to complete
authorJohn Gallagher <john.gallagher@delphix.com>
Sat, 14 Sep 2019 01:09:06 +0000 (18:09 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Sat, 14 Sep 2019 01:09:06 +0000 (18:09 -0700)
commite60e158eff920825311c1e18b3631876eaaacb54
tree03b5f6ff4855ae0fdc233d377d3c1939d1223912
parent7238cbd4d3ee7eadb3131c890d0692a49ea844af
Add subcommand to wait for background zfs activity to complete

Currently the best way to wait for the completion of a long-running
operation in a pool, like a scrub or device removal, is to poll 'zpool
status' and parse its output, which is neither efficient nor convenient.

This change adds a 'wait' subcommand to the zpool command. When invoked,
'zpool wait' will block until a specified type of background activity
completes. Currently, this subcommand can wait for any of the following:

 - Scrubs or resilvers to complete
 - Devices to initialized
 - Devices to be replaced
 - Devices to be removed
 - Checkpoints to be discarded
 - Background freeing to complete

For example, a scrub that is in progress could be waited for by running

    zpool wait -t scrub <pool>

This also adds a -w flag to the attach, checkpoint, initialize, replace,
remove, and scrub subcommands. When used, this flag makes the operations
kicked off by these subcommands synchronous instead of asynchronous.

This functionality is implemented using a new ioctl. The type of
activity to wait for is provided as input to the ioctl, and the ioctl
blocks until all activity of that type has completed. An ioctl was used
over other methods of kernel-userspace communiction primarily for the
sake of portability.

Porting Notes:
This is ported from Delphix OS change DLPX-44432. The following changes
were made while porting:

 - Added ZoL-style ioctl input declaration.
 - Reorganized error handling in zpool_initialize in libzfs to integrate
   better with changes made for TRIM support.
 - Fixed check for whether a checkpoint discard is in progress.
   Previously it also waited if the pool had a checkpoint, instead of
   just if a checkpoint was being discarded.
 - Exposed zfs_initialize_chunk_size as a ZoL-style tunable.
 - Updated more existing tests to make use of new 'zpool wait'
   functionality, tests that don't exist in Delphix OS.
 - Used existing ZoL tunable zfs_scan_suspend_progress, together with
   zinject, in place of a new tunable zfs_scan_max_blks_per_txg.
 - Added support for a non-integral interval argument to zpool wait.

Future work:
ZoL has support for trimming devices, which Delphix OS does not. In the
future, 'zpool wait' could be extended to add the ability to wait for
trim operations to complete.

Reviewed-by: Matt Ahrens <matt@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: John Gallagher <john.gallagher@delphix.com>
Closes #9162
61 files changed:
cmd/zpool/zpool_main.c
configure.ac
include/libzfs.h
include/libzfs_core.h
include/sys/fs/zfs.h
include/sys/spa.h
include/sys/spa_impl.h
include/sys/vdev.h
lib/libzfs/libzfs_pool.c
lib/libzfs_core/libzfs_core.c
man/man5/zfs-module-parameters.5
man/man8/zpool.8
module/zfs/bpobj.c
module/zfs/dsl_scan.c
module/zfs/spa.c
module/zfs/spa_checkpoint.c
module/zfs/spa_misc.c
module/zfs/vdev.c
module/zfs/vdev_initialize.c
module/zfs/vdev_removal.c
module/zfs/zfs_ioctl.c
tests/runfiles/linux.run
tests/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c
tests/zfs-tests/include/libtest.shlib
tests/zfs-tests/tests/functional/cli_root/Makefile.am
tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib
tests/zfs-tests/tests/functional/cli_root/zpool_clear/zpool_clear_001_pos.ksh
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_004_pos.ksh
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_005_pos.ksh
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_encrypted_unloaded.ksh
tests/zfs-tests/tests/functional/cli_root/zpool_wait/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/scan/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/scan/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/scan/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/scan/zpool_wait_replace.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/scan/zpool_wait_replace_cancel.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/scan/zpool_wait_resilver.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/scan/zpool_wait_scrub_basic.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/scan/zpool_wait_scrub_cancel.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/scan/zpool_wait_scrub_flag.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait.kshlib [new file with mode: 0644]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_discard.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_freeing.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_initialize_basic.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_initialize_cancel.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_initialize_flag.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_multiple.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_no_activity.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_remove.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_remove_cancel.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_usage.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/cli_user/misc/Makefile.am
tests/zfs-tests/tests/functional/cli_user/misc/zpool_wait_privilege.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/events/events_002_pos.ksh
tests/zfs-tests/tests/functional/online_offline/online_offline_002_neg.ksh
tests/zfs-tests/tests/functional/redundancy/redundancy.kshlib
tests/zfs-tests/tests/functional/redundancy/redundancy_004_neg.ksh
tests/zfs-tests/tests/functional/removal/removal.kshlib
tests/zfs-tests/tests/functional/removal/removal_with_errors.ksh