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 <behlendorf1@llnl.gov>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #11426 
Closes #14496
This commit is contained in:
Paul Dagnelie 2023-02-21 17:30:05 -08:00 committed by GitHub
parent 28251d81d7
commit d9e64a4030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);