diff options
author | John Gallagher <[email protected]> | 2019-09-13 18:09:06 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2019-09-13 18:09:06 -0700 |
commit | e60e158eff920825311c1e18b3631876eaaacb54 (patch) | |
tree | 03b5f6ff4855ae0fdc233d377d3c1939d1223912 /include/sys | |
parent | 7238cbd4d3ee7eadb3131c890d0692a49ea844af (diff) |
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 <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: John Gallagher <[email protected]>
Closes #9162
Diffstat (limited to 'include/sys')
-rw-r--r-- | include/sys/fs/zfs.h | 19 | ||||
-rw-r--r-- | include/sys/spa.h | 8 | ||||
-rw-r--r-- | include/sys/spa_impl.h | 7 | ||||
-rw-r--r-- | include/sys/vdev.h | 1 |
4 files changed, 35 insertions, 0 deletions
diff --git a/include/sys/fs/zfs.h b/include/sys/fs/zfs.h index eb970b2cd..eeb457903 100644 --- a/include/sys/fs/zfs.h +++ b/include/sys/fs/zfs.h @@ -1277,6 +1277,7 @@ typedef enum zfs_ioc { ZFS_IOC_POOL_TRIM, /* 0x5a50 */ ZFS_IOC_REDACT, /* 0x5a51 */ ZFS_IOC_GET_BOOKMARK_PROPS, /* 0x5a52 */ + ZFS_IOC_WAIT, /* 0x5a53 */ /* * Linux - 3/64 numbers reserved. @@ -1340,6 +1341,17 @@ typedef enum { SPA_LOAD_CREATE /* creation in progress */ } spa_load_state_t; +typedef enum { + ZPOOL_WAIT_CKPT_DISCARD, + ZPOOL_WAIT_FREE, + ZPOOL_WAIT_INITIALIZE, + ZPOOL_WAIT_REPLACE, + ZPOOL_WAIT_REMOVE, + ZPOOL_WAIT_RESILVER, + ZPOOL_WAIT_SCRUB, + ZPOOL_WAIT_NUM_ACTIVITIES +} zpool_wait_activity_t; + /* * Bookmark name values. */ @@ -1391,6 +1403,13 @@ typedef enum { #define ZPOOL_TRIM_SECURE "trim_secure" /* + * The following are names used when invoking ZFS_IOC_POOL_WAIT. + */ +#define ZPOOL_WAIT_ACTIVITY "wait_activity" +#define ZPOOL_WAIT_TAG "wait_tag" +#define ZPOOL_WAIT_WAITED "wait_waited" + +/* * Flags for ZFS_IOC_VDEV_SET_STATE */ #define ZFS_ONLINE_CHECKREMOVE 0x1 diff --git a/include/sys/spa.h b/include/sys/spa.h index 51e4c0f77..caa2157b9 100644 --- a/include/sys/spa.h +++ b/include/sys/spa.h @@ -1204,6 +1204,14 @@ extern void spa_configfile_set(spa_t *, nvlist_t *, boolean_t); extern void spa_event_notify(spa_t *spa, vdev_t *vdev, nvlist_t *hist_nvl, const char *name); +/* waiting for pool activities to complete */ +extern int spa_wait(const char *pool, zpool_wait_activity_t activity, + boolean_t *waited); +extern int spa_wait_tag(const char *name, zpool_wait_activity_t activity, + uint64_t tag, boolean_t *waited); +extern void spa_notify_waiters(spa_t *spa); +extern void spa_wake_waiters(spa_t *spa); + #ifdef ZFS_DEBUG #define dprintf_bp(bp, fmt, ...) do { \ if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ diff --git a/include/sys/spa_impl.h b/include/sys/spa_impl.h index 71b07405c..8dfd46431 100644 --- a/include/sys/spa_impl.h +++ b/include/sys/spa_impl.h @@ -413,6 +413,13 @@ struct spa { uint64_t spa_leaf_list_gen; /* track leaf_list changes */ uint32_t spa_hostid; /* cached system hostid */ + /* synchronization for threads in spa_wait */ + kmutex_t spa_activities_lock; + kcondvar_t spa_activities_cv; + kcondvar_t spa_waiters_cv; + int spa_waiters; /* number of waiting threads */ + boolean_t spa_waiters_cancel; /* waiters should return */ + /* * spa_refcount & spa_config_lock must be the last elements * because zfs_refcount_t changes size based on compilation options. diff --git a/include/sys/vdev.h b/include/sys/vdev.h index 67ca0d116..0d0d0234e 100644 --- a/include/sys/vdev.h +++ b/include/sys/vdev.h @@ -85,6 +85,7 @@ extern void vdev_indirect_mark_obsolete(vdev_t *vd, uint64_t offset, uint64_t size); extern void spa_vdev_indirect_mark_obsolete(spa_t *spa, uint64_t vdev, uint64_t offset, uint64_t size, dmu_tx_t *tx); +extern boolean_t vdev_replace_in_progress(vdev_t *vdev); extern void vdev_hold(vdev_t *); extern void vdev_rele(vdev_t *); |