From 1139e170d49a96bd228b0c86035129bc38a89989 Mon Sep 17 00:00:00 2001 From: Rich Ercolani <214141+rincebrain@users.noreply.github.com> Date: Fri, 29 Oct 2021 18:55:22 -0400 Subject: [PATCH] Add explicit error for device_rebuild being disabled Currently, you get back "can only attach to mirrors and top-level disks" unconditionally if zpool attach returns ENOTSUP, but that also happens if, say, feature@device_rebuild=disabled and you tried attach -s. So let's print an error for that case, lest people go down a rabbit hole looking into what they did wrong. Reviewed-by: Brian Behlendorf Signed-off-by: Rich Ercolani Closes #11414 Closes #12680 --- lib/libzfs/libzfs_pool.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index 57dea98cc..8ed96275c 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -3364,9 +3364,20 @@ zpool_vdev_attach(zpool_handle_t *zhp, const char *old_disk, "cannot replace a replacing device")); } } else { - zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, - "can only attach to mirrors and top-level " - "disks")); + char status[64] = {0}; + zpool_prop_get_feature(zhp, + "feature@device_rebuild", status, 63); + if (rebuild && + strncmp(status, ZFS_FEATURE_DISABLED, 64) == 0) { + zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, + "device_rebuild feature must be enabled " + "in order to use sequential " + "reconstruction")); + } else { + zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, + "can only attach to mirrors and top-level " + "disks")); + } } (void) zfs_error(hdl, EZFS_BADTARGET, msg); break;