From d9e64a4030d141580af2e8b75e8982637818145a Mon Sep 17 00:00:00 2001 From: Paul Dagnelie Date: Tue, 21 Feb 2023 17:30:05 -0800 Subject: [PATCH] Improve error message of zfs redact We improve the error message of zfs redact by checking if the target snapshot exists, and if all the redaction snapshots exist. As a future improvement we could iterate over every snapshot provided and use that to determine which one specifically doesn't exist. Reviewed-by: Brian Behlendorf Signed-off-by: Paul Dagnelie Closes #11426 Closes #14496 --- cmd/zfs/zfs_main.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 1ffe805aab..437f83c2a8 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -3882,10 +3882,25 @@ zfs_do_redact(int argc, char **argv) switch (err) { case 0: break; - case ENOENT: - (void) fprintf(stderr, - gettext("provided snapshot %s does not exist\n"), snap); + case ENOENT: { + zfs_handle_t *zhp = zfs_open(g_zfs, snap, ZFS_TYPE_SNAPSHOT); + if (zhp == NULL) { + (void) fprintf(stderr, gettext("provided snapshot %s " + "does not exist\n"), snap); + } else { + zfs_close(zhp); + } + for (int i = 0; i < numrsnaps; i++) { + zhp = zfs_open(g_zfs, rsnaps[i], ZFS_TYPE_SNAPSHOT); + if (zhp == NULL) { + (void) fprintf(stderr, gettext("provided " + "snapshot %s does not exist\n"), rsnaps[i]); + } else { + zfs_close(zhp); + } + } break; + } case EEXIST: (void) fprintf(stderr, gettext("specified redaction bookmark " "(%s) provided already exists\n"), bookname);