From d35951b18d6e12afeb0d5b0539ff2467ab4bfbcf Mon Sep 17 00:00:00 2001 From: Christos Longros <98426896+chrislongros@users.noreply.github.com> Date: Wed, 11 Mar 2026 23:15:45 +0100 Subject: [PATCH] zpool clear: remove undocumented rewind flags Remove the -F, -n, and -X flags from zpool clear. These flags were inherited from OpenSolaris but are not applicable in this context. Unlike zpool import, where the pool is not yet loaded and a specific TXG can be selected, zpool clear operates on an already imported pool whose in-memory state is ahead of what is on disk. Rewinding transactions would require force-exporting the pool first. The rewind policy passed to zpool_clear() is now always ZPOOL_NO_REWIND. Tested on FreeBSD 16.0-CURRENT (amd64). Verified that -F, -n, and -X are properly rejected as invalid options and that the usage output reflects the change. Reviewed-by: Alexander Motin Reviewed-by: Brian Behlendorf Signed-off-by: Christos Longros Closes #13825 Closes #18300 --- cmd/zpool/zpool_main.c | 37 ++++--------------------------------- lib/libzfs/libzfs_pool.c | 3 ++- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index ab0e0fb93..abbdc4896 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -458,7 +458,7 @@ get_usage(zpool_help_t idx) return (gettext("\tattach [-fsw] [-o property=value] " " \n")); case HELP_CLEAR: - return (gettext("\tclear [[--power]|[-nF]] [device]\n")); + return (gettext("\tclear [--power] [device]\n")); case HELP_CREATE: return (gettext("\tcreate [-fnd] [-o property=value] ... \n" "\t [-O file-system-property=value] ... \n" @@ -8251,7 +8251,7 @@ zpool_do_offline(int argc, char **argv) } /* - * zpool clear [-nF]|[--power] [device] + * zpool clear [--power] [device] * * Clear all errors associated with a pool or a particular device. */ @@ -8260,11 +8260,7 @@ zpool_do_clear(int argc, char **argv) { int c; int ret = 0; - boolean_t dryrun = B_FALSE; - boolean_t do_rewind = B_FALSE; - boolean_t xtreme_rewind = B_FALSE; boolean_t is_power_on = B_FALSE; - uint32_t rewind_policy = ZPOOL_NO_REWIND; nvlist_t *policy = NULL; zpool_handle_t *zhp; char *pool, *device; @@ -8275,18 +8271,9 @@ zpool_do_clear(int argc, char **argv) }; /* check options */ - while ((c = getopt_long(argc, argv, "FnX", long_options, + while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { switch (c) { - case 'F': - do_rewind = B_TRUE; - break; - case 'n': - dryrun = B_TRUE; - break; - case 'X': - xtreme_rewind = B_TRUE; - break; case ZPOOL_OPTION_POWER: is_power_on = B_TRUE; break; @@ -8313,24 +8300,8 @@ zpool_do_clear(int argc, char **argv) usage(B_FALSE); } - if ((dryrun || xtreme_rewind) && !do_rewind) { - (void) fprintf(stderr, - gettext("-n or -X only meaningful with -F\n")); - usage(B_FALSE); - } - if (dryrun) - rewind_policy = ZPOOL_TRY_REWIND; - else if (do_rewind) - rewind_policy = ZPOOL_DO_REWIND; - if (xtreme_rewind) - rewind_policy |= ZPOOL_EXTREME_REWIND; - - /* In future, further rewind policy choices can be passed along here */ - if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0 || - nvlist_add_uint32(policy, ZPOOL_LOAD_REWIND_POLICY, - rewind_policy) != 0) { + if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0) return (1); - } pool = argv[0]; device = argc == 2 ? argv[1] : NULL; diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index 3a1a87e85..543c4d340 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -4412,7 +4412,8 @@ zpool_clear(zpool_handle_t *zhp, const char *path, nvlist_t *rewindnvl) zc.zc_cookie = policy.zlp_rewind; zcmd_alloc_dst_nvlist(hdl, &zc, zhp->zpool_config_size * 2); - zcmd_write_src_nvlist(hdl, &zc, rewindnvl); + if (rewindnvl != NULL) + zcmd_write_src_nvlist(hdl, &zc, rewindnvl); while ((error = zfs_ioctl(hdl, ZFS_IOC_CLEAR, &zc)) != 0 && errno == ENOMEM)