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 <alexander.motin@TrueNAS.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Christos Longros <chris.longros@gmail.com>
Closes #13825
Closes #18300
This commit is contained in:
Christos Longros 2026-03-11 23:15:45 +01:00 committed by GitHub
parent 65165df129
commit d35951b18d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 34 deletions

View File

@ -458,7 +458,7 @@ get_usage(zpool_help_t idx)
return (gettext("\tattach [-fsw] [-o property=value] " return (gettext("\tattach [-fsw] [-o property=value] "
"<pool> <vdev> <new-device>\n")); "<pool> <vdev> <new-device>\n"));
case HELP_CLEAR: case HELP_CLEAR:
return (gettext("\tclear [[--power]|[-nF]] <pool> [device]\n")); return (gettext("\tclear [--power] <pool> [device]\n"));
case HELP_CREATE: case HELP_CREATE:
return (gettext("\tcreate [-fnd] [-o property=value] ... \n" return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
"\t [-O file-system-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] <pool> [device] * zpool clear [--power] <pool> [device]
* *
* Clear all errors associated with a pool or a particular 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 c;
int ret = 0; 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; boolean_t is_power_on = B_FALSE;
uint32_t rewind_policy = ZPOOL_NO_REWIND;
nvlist_t *policy = NULL; nvlist_t *policy = NULL;
zpool_handle_t *zhp; zpool_handle_t *zhp;
char *pool, *device; char *pool, *device;
@ -8275,18 +8271,9 @@ zpool_do_clear(int argc, char **argv)
}; };
/* check options */ /* check options */
while ((c = getopt_long(argc, argv, "FnX", long_options, while ((c = getopt_long(argc, argv, "", long_options,
NULL)) != -1) { NULL)) != -1) {
switch (c) { 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: case ZPOOL_OPTION_POWER:
is_power_on = B_TRUE; is_power_on = B_TRUE;
break; break;
@ -8313,24 +8300,8 @@ zpool_do_clear(int argc, char **argv)
usage(B_FALSE); usage(B_FALSE);
} }
if ((dryrun || xtreme_rewind) && !do_rewind) { if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0)
(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) {
return (1); return (1);
}
pool = argv[0]; pool = argv[0];
device = argc == 2 ? argv[1] : NULL; device = argc == 2 ? argv[1] : NULL;

View File

@ -4412,7 +4412,8 @@ zpool_clear(zpool_handle_t *zhp, const char *path, nvlist_t *rewindnvl)
zc.zc_cookie = policy.zlp_rewind; zc.zc_cookie = policy.zlp_rewind;
zcmd_alloc_dst_nvlist(hdl, &zc, zhp->zpool_config_size * 2); 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 && while ((error = zfs_ioctl(hdl, ZFS_IOC_CLEAR, &zc)) != 0 &&
errno == ENOMEM) errno == ENOMEM)