#include <sys/fm/util.h>
#include <sys/fm/protocol.h>
#include <sys/zfs_ioctl.h>
-
+#include <sys/mount.h>
#include <math.h>
#include <libzfs.h>
return (gettext("\thistory [-il] [<pool>] ...\n"));
case HELP_IMPORT:
return (gettext("\timport [-d dir] [-D]\n"
- "\timport [-d dir | -c cachefile] [-F [-n]] <pool | id>\n"
+ "\timport [-d dir | -c cachefile] [-F [-n]] [-l] "
+ "<pool | id>\n"
"\timport [-o mntopts] [-o property=value] ... \n"
- "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
+ "\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
"[-R root] [-F [-n]] -a\n"
"\timport [-o mntopts] [-o property=value] ... \n"
- "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
+ "\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
"[-R root] [-F [-n]]\n"
"\t <pool | id> [newpool]\n"));
case HELP_IOSTAT:
case HELP_SET:
return (gettext("\tset <property=value> <pool> \n"));
case HELP_SPLIT:
- return (gettext("\tsplit [-gLnP] [-R altroot] [-o mntopts]\n"
+ return (gettext("\tsplit [-gLnPl] [-R altroot] [-o mntopts]\n"
"\t [-o property=value] <pool> <newpool> "
"[<device> ...]\n"));
case HELP_REGUID:
do_import(nvlist_t *config, const char *newname, const char *mntopts,
nvlist_t *props, int flags)
{
+ int ret = 0;
zpool_handle_t *zhp;
char *name;
uint64_t state;
if ((zhp = zpool_open_canfail(g_zfs, name)) == NULL)
return (1);
+ /*
+ * Loading keys is best effort. We don't want to return immediately
+ * if it fails but we do want to give the error to the caller.
+ */
+ if (flags & ZFS_IMPORT_LOAD_KEYS) {
+ ret = zfs_crypto_attempt_load_keys(g_zfs, name);
+ if (ret != 0)
+ ret = 1;
+ }
+
if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
!(flags & ZFS_IMPORT_ONLY) &&
zpool_enable_datasets(zhp, mntopts, 0) != 0) {
}
zpool_close(zhp);
- return (0);
+ return (ret);
}
/*
* zpool import [-d dir] [-D]
- * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
+ * import [-o mntopts] [-o prop=value] ... [-R root] [-D] [-l]
* [-d dir | -c cachefile] [-f] -a
- * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
+ * import [-o mntopts] [-o prop=value] ... [-R root] [-D] [-l]
* [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
*
* -c Read pool information from a cachefile instead of searching
*
* -a Import all pools found.
*
+ * -l Load encryption keys while importing.
+ *
* -o Set property=value and/or temporary mount options (without '=').
*
* -s Scan using the default search path, the libblkid cache will
char *endptr;
/* check options */
- while ((c = getopt(argc, argv, ":aCc:d:DEfFmnNo:R:stT:VX")) != -1) {
+ while ((c = getopt(argc, argv, ":aCc:d:DEfFlmnNo:R:stT:VX")) != -1) {
switch (c) {
case 'a':
do_all = B_TRUE;
case 'F':
do_rewind = B_TRUE;
break;
+ case 'l':
+ flags |= ZFS_IMPORT_LOAD_KEYS;
+ break;
case 'm':
flags |= ZFS_IMPORT_MISSING_LOG;
break;
usage(B_FALSE);
}
+ if ((flags & ZFS_IMPORT_LOAD_KEYS) && (flags & ZFS_IMPORT_ONLY)) {
+ (void) fprintf(stderr, gettext("-l is incompatible with -N\n"));
+ usage(B_FALSE);
+ }
+
+ if ((flags & ZFS_IMPORT_LOAD_KEYS) && !do_all && argc == 0) {
+ (void) fprintf(stderr, gettext("-l is only meaningful during "
+ "an import\n"));
+ usage(B_FALSE);
+ }
+
if ((dryrun || xtreme_rewind) && !do_rewind) {
(void) fprintf(stderr,
gettext("-n or -X only meaningful with -F\n"));
* -o Set property=value, or set mount options.
* -P Display full path for vdev name.
* -R Mount the split-off pool under an alternate root.
+ * -l Load encryption keys while importing.
*
* Splits the named pool and gives it the new pool name. Devices to be split
* off may be listed, provided that no more than one device is specified
char *mntopts = NULL;
splitflags_t flags;
int c, ret = 0;
+ boolean_t loadkeys = B_FALSE;
zpool_handle_t *zhp;
nvlist_t *config, *props = NULL;
flags.name_flags = 0;
/* check options */
- while ((c = getopt(argc, argv, ":gLR:no:P")) != -1) {
+ while ((c = getopt(argc, argv, ":gLR:lno:P")) != -1) {
switch (c) {
case 'g':
flags.name_flags |= VDEV_NAME_GUID;
usage(B_FALSE);
}
break;
+ case 'l':
+ loadkeys = B_TRUE;
+ break;
case 'n':
flags.dryrun = B_TRUE;
break;
usage(B_FALSE);
}
+ if (!flags.import && loadkeys) {
+ (void) fprintf(stderr, gettext("loading keys is only "
+ "valid when importing the pool\n"));
+ usage(B_FALSE);
+ }
+
argc -= optind;
argv += optind;
nvlist_free(props);
return (1);
}
+
+ if (loadkeys) {
+ ret = zfs_crypto_attempt_load_keys(g_zfs, newpool);
+ if (ret != 0)
+ ret = 1;
+ }
+
if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
zpool_enable_datasets(zhp, mntopts, 0) != 0) {
ret = 1;