summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2020-03-04 15:07:11 -0800
committerGitHub <[email protected]>2020-03-04 15:07:11 -0800
commit2288d4196821ae4b5fa375e8e519f6e83f26abad (patch)
tree49c49baf2112da27d14ea2f90e09a333d1ab99da /lib
parentb3212d2fa6ab8d7d8373373e8a6b8acbbf45508e (diff)
Add trim support to zpool wait
Manual trims fall into the category of long-running pool activities which people might want to wait synchronously for. This change adds support to 'zpool wait' for waiting for manual trim operations to complete. It also adds a '-w' flag to 'zpool trim' which can be used to turn 'zpool trim' into a synchronous operation. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Serapheim Dimitropoulos <[email protected]> Signed-off-by: John Gallagher <[email protected]> Closes #10071
Diffstat (limited to 'lib')
-rw-r--r--lib/libzfs/libzfs_pool.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c
index 7f3ec5d0d..e0610a631 100644
--- a/lib/libzfs/libzfs_pool.c
+++ b/lib/libzfs/libzfs_pool.c
@@ -2263,6 +2263,30 @@ xlate_trim_err(int err)
return (err);
}
+static int
+zpool_trim_wait(zpool_handle_t *zhp, nvlist_t *vdev_guids)
+{
+ int err;
+ nvpair_t *elem;
+
+ for (elem = nvlist_next_nvpair(vdev_guids, NULL); elem != NULL;
+ elem = nvlist_next_nvpair(vdev_guids, elem)) {
+
+ uint64_t guid = fnvpair_value_uint64(elem);
+
+ err = lzc_wait_tag(zhp->zpool_name,
+ ZPOOL_WAIT_TRIM, guid, NULL);
+ if (err != 0) {
+ (void) zpool_standard_error_fmt(zhp->zpool_hdl,
+ err, dgettext(TEXT_DOMAIN, "error "
+ "waiting to trim '%s'"), nvpair_name(elem));
+
+ return (err);
+ }
+ }
+ return (0);
+}
+
/*
* Begin, suspend, or cancel the TRIM (discarding of all free blocks) for
* the given vdevs in the given pool.
@@ -2286,9 +2310,12 @@ zpool_trim(zpool_handle_t *zhp, pool_trim_func_t cmd_type, nvlist_t *vds,
err = lzc_trim(zhp->zpool_name, cmd_type, trim_flags->rate,
trim_flags->secure, vdev_guids, &errlist);
if (err == 0) {
+ if (trim_flags->wait)
+ err = zpool_trim_wait(zhp, vdev_guids);
+
fnvlist_free(vdev_guids);
fnvlist_free(guids_to_paths);
- return (0);
+ return (err);
}
if (errlist != NULL) {