From f658f61c722872753e8899a118e11546f136e85a Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Mon, 25 Nov 2019 20:08:20 +0100 Subject: [PATCH] cmd/zfs: redact: better error message for common usage errors Reviewed-by: Brian Behlendorf Reviewed-by: Matt Ahrens Signed-off-by: Christian Schwarz Closes #9867 --- cmd/zfs/zfs_main.c | 13 +++++++++++-- .../functional/redacted_send/redacted_negative.ksh | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index a6e75e0bac..20ecb30314 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -3746,8 +3746,13 @@ zfs_do_redact(int argc, char **argv) "specified\n")); break; case EINVAL: - (void) fprintf(stderr, gettext("redaction snapshot must be " - "descendent of snapshot being redacted\n")); + if (strchr(bookname, '#') != NULL) + (void) fprintf(stderr, gettext( + "redaction bookmark name must not contain '#'\n")); + else + (void) fprintf(stderr, gettext( + "redaction snapshot must be descendent of " + "snapshot being redacted\n")); break; case EALREADY: (void) fprintf(stderr, gettext("attempted to redact redacted " @@ -3757,6 +3762,10 @@ zfs_do_redact(int argc, char **argv) (void) fprintf(stderr, gettext("redaction bookmarks feature " "not enabled\n")); break; + case EXDEV: + (void) fprintf(stderr, gettext("potentially invalid redaction " + "snapshot; full dataset names required\n")); + break; default: (void) fprintf(stderr, gettext("internal error: %s\n"), strerror(errno)); diff --git a/tests/zfs-tests/tests/functional/redacted_send/redacted_negative.ksh b/tests/zfs-tests/tests/functional/redacted_send/redacted_negative.ksh index e27eb601e2..8eafc47066 100755 --- a/tests/zfs-tests/tests/functional/redacted_send/redacted_negative.ksh +++ b/tests/zfs-tests/tests/functional/redacted_send/redacted_negative.ksh @@ -77,4 +77,12 @@ log_mustnot zfs redact $recvfs@snap book5 $clone3@snap # Nor may a redacted dataset appear in the redaction list. log_mustnot zfs redact testpool2/recvfs@snap2 book7 testpool2/recvfs@snap +# Error messages for common usage errors +log_mustnot_expect "not contain '#'" zfs redact $sendfs@snap1 \#book $sendfs@snap2 +log_mustnot_expect "not contain '#'" zfs redact $sendfs@snap1 $sendfs#book $sendfs@snap2 +log_mustnot_expect "full dataset names" zfs redact $sendfs@snap1 book @snap2 +log_mustnot_expect "full dataset names" zfs redact $sendfs@snap1 book @snap2 +log_mustnot_expect "full dataset names" zfs redact $sendfs@snap1 \#book @snap2 +log_mustnot_expect "descendent of snapshot" zfs redact $sendfs@snap2 book $sendfs@snap1 + log_pass "Verify that redacted send correctly detects invalid arguments."