From 1bf9a552bb52785d5d838108574443e35682c85c Mon Sep 17 00:00:00 2001 From: Tom Caputi Date: Fri, 6 Apr 2018 16:28:15 -0400 Subject: Make encrypted "zfs mount -a" failures consistent Currently, "zfs mount -a" will print a warning and fail to mount any encrypted datasets that do not have a key loaded. This patch makes the behavior of this failure consistent with other failure modes ("zfs mount -a" will silently continue, explict "zfs mount" will print a message and return an error code. Reviewed-by: Brian Behlendorf Signed-off-by: Tom Caputi Closes #7382 --- cmd/zfs/zfs_main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cmd/zfs') diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index d148516f1..31376080b 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -6228,6 +6228,22 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol, return (0); } + /* + * If this filesystem is encrypted and does not have + * a loaded key, we can not mount it. + */ + if ((flags & MS_CRYPT) == 0 && + zfs_prop_get_int(zhp, ZFS_PROP_ENCRYPTION) != ZIO_CRYPT_OFF && + zfs_prop_get_int(zhp, ZFS_PROP_KEYSTATUS) == + ZFS_KEYSTATUS_UNAVAILABLE) { + if (!explicit) + return (0); + + (void) fprintf(stderr, gettext("cannot %s '%s': " + "encryption key not loaded\n"), cmdname, zfs_get_name(zhp)); + return (1); + } + /* * If this filesystem is inconsistent and has a receive resume * token, we can not mount it. -- cgit v1.2.3