]> git.proxmox.com Git - mirror_zfs-debian.git/blobdiff - cmd/zpool/zpool_main.c
Merge branch 'master' of git+ssh://git.debian.org/git/pkg-zfsonlinux/zfs
[mirror_zfs-debian.git] / cmd / zpool / zpool_main.c
index ce95bfe01c29d93ddfa9ec631f8580f48f2dab23..aa9b21dadf0c7b7a75c33bc77c917322717caf20 100644 (file)
 
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
+ * Copyright (c) 2011, 2014 by Delphix. All rights reserved.
+ * Copyright (c) 2012 by Frederik Wessels. All rights reserved.
+ * Copyright (c) 2012 by Cyril Plisko. All rights reserved.
+ * Copyright (c) 2013 by Prasad Joshi (sTec). All rights reserved.
  */
 
 #include <assert.h>
 #include <priv.h>
 #include <pwd.h>
 #include <zone.h>
+#include <zfs_prop.h>
 #include <sys/fs/zfs.h>
 #include <sys/stat.h>
 #include <sys/fm/util.h>
 #include <sys/fm/protocol.h>
+#include <sys/zfs_ioctl.h>
 
 #include <libzfs.h>
 
 #include "zpool_util.h"
 #include "zfs_comutil.h"
+#include "zfeature_common.h"
 
 #include "statcommon.h"
 
@@ -57,6 +65,7 @@ static int zpool_do_destroy(int, char **);
 
 static int zpool_do_add(int, char **);
 static int zpool_do_remove(int, char **);
+static int zpool_do_labelclear(int, char **);
 
 static int zpool_do_list(int, char **);
 static int zpool_do_iostat(int, char **);
@@ -65,6 +74,9 @@ static int zpool_do_status(int, char **);
 static int zpool_do_online(int, char **);
 static int zpool_do_offline(int, char **);
 static int zpool_do_clear(int, char **);
+static int zpool_do_reopen(int, char **);
+
+static int zpool_do_reguid(int, char **);
 
 static int zpool_do_attach(int, char **);
 static int zpool_do_detach(int, char **);
@@ -114,6 +126,7 @@ typedef enum {
        HELP_HISTORY,
        HELP_IMPORT,
        HELP_IOSTAT,
+       HELP_LABELCLEAR,
        HELP_LIST,
        HELP_OFFLINE,
        HELP_ONLINE,
@@ -125,7 +138,9 @@ typedef enum {
        HELP_EVENTS,
        HELP_GET,
        HELP_SET,
-       HELP_SPLIT
+       HELP_SPLIT,
+       HELP_REGUID,
+       HELP_REOPEN
 } zpool_help_t;
 
 
@@ -151,6 +166,8 @@ static zpool_command_t command_table[] = {
        { "add",        zpool_do_add,           HELP_ADD                },
        { "remove",     zpool_do_remove,        HELP_REMOVE             },
        { NULL },
+       { "labelclear", zpool_do_labelclear,    HELP_LABELCLEAR         },
+       { NULL },
        { "list",       zpool_do_list,          HELP_LIST               },
        { "iostat",     zpool_do_iostat,        HELP_IOSTAT             },
        { "status",     zpool_do_status,        HELP_STATUS             },
@@ -158,6 +175,7 @@ static zpool_command_t command_table[] = {
        { "online",     zpool_do_online,        HELP_ONLINE             },
        { "offline",    zpool_do_offline,       HELP_OFFLINE            },
        { "clear",      zpool_do_clear,         HELP_CLEAR              },
+       { "reopen",     zpool_do_reopen,        HELP_REOPEN             },
        { NULL },
        { "attach",     zpool_do_attach,        HELP_ATTACH             },
        { "detach",     zpool_do_detach,        HELP_DETACH             },
@@ -169,6 +187,7 @@ static zpool_command_t command_table[] = {
        { "import",     zpool_do_import,        HELP_IMPORT             },
        { "export",     zpool_do_export,        HELP_EXPORT             },
        { "upgrade",    zpool_do_upgrade,       HELP_UPGRADE            },
+       { "reguid",     zpool_do_reguid,        HELP_REGUID             },
        { NULL },
        { "history",    zpool_do_history,       HELP_HISTORY            },
        { "events",     zpool_do_events,        HELP_EVENTS             },
@@ -179,23 +198,24 @@ static zpool_command_t command_table[] = {
 
 #define        NCOMMAND        (sizeof (command_table) / sizeof (command_table[0]))
 
-zpool_command_t *current_command;
+static zpool_command_t *current_command;
 static char history_str[HIS_MAX_RECORD_LEN];
-
+static boolean_t log_history = B_TRUE;
 static uint_t timestamp_fmt = NODATE;
 
 static const char *
 get_usage(zpool_help_t idx) {
        switch (idx) {
        case HELP_ADD:
-               return (gettext("\tadd [-fn] <pool> <vdev> ...\n"));
+               return (gettext("\tadd [-fn] [-o property=value] "
+                   "<pool> <vdev> ...\n"));
        case HELP_ATTACH:
-               return (gettext("\tattach [-f] <pool> <device> "
-                   "<new-device>\n"));
+               return (gettext("\tattach [-f] [-o property=value] "
+                   "<pool> <device> <new-device>\n"));
        case HELP_CLEAR:
                return (gettext("\tclear [-nF] <pool> [device]\n"));
        case HELP_CREATE:
-               return (gettext("\tcreate [-fn] [-o property=value] ... \n"
+               return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
                    "\t    [-O file-system-property=value] ... \n"
                    "\t    [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
        case HELP_DESTROY:
@@ -203,7 +223,7 @@ get_usage(zpool_help_t idx) {
        case HELP_DETACH:
                return (gettext("\tdetach <pool> <device>\n"));
        case HELP_EXPORT:
-               return (gettext("\texport [-f] <pool> ...\n"));
+               return (gettext("\texport [-af] <pool> ...\n"));
        case HELP_HISTORY:
                return (gettext("\thistory [-il] [<pool>] ...\n"));
        case HELP_IMPORT:
@@ -217,24 +237,28 @@ get_usage(zpool_help_t idx) {
                    "[-R root] [-F [-n]]\n"
                    "\t    <pool | id> [newpool]\n"));
        case HELP_IOSTAT:
-               return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
-                   "[count]]\n"));
+               return (gettext("\tiostat [-v] [-T d|u] [-y] [pool] ... "
+                   "[interval [count]]\n"));
+       case HELP_LABELCLEAR:
+               return (gettext("\tlabelclear [-f] <vdev>\n"));
        case HELP_LIST:
-               return (gettext("\tlist [-H] [-o property[,...]] "
+               return (gettext("\tlist [-Hv] [-o property[,...]] "
                    "[-T d|u] [pool] ... [interval [count]]\n"));
        case HELP_OFFLINE:
                return (gettext("\toffline [-t] <pool> <device> ...\n"));
        case HELP_ONLINE:
                return (gettext("\tonline <pool> <device> ...\n"));
        case HELP_REPLACE:
-               return (gettext("\treplace [-f] <pool> <device> "
-                   "[new-device]\n"));
+               return (gettext("\treplace [-f] [-o property=value] "
+                   "<pool> <device> [new-device]\n"));
        case HELP_REMOVE:
                return (gettext("\tremove <pool> <device> ...\n"));
+       case HELP_REOPEN:
+               return (gettext("\treopen <pool>\n"));
        case HELP_SCRUB:
                return (gettext("\tscrub [-s] <pool> ...\n"));
        case HELP_STATUS:
-               return (gettext("\tstatus [-vx] [-T d|u] [pool] ... [interval "
+               return (gettext("\tstatus [-vxD] [-T d|u] [pool] ... [interval "
                    "[count]]\n"));
        case HELP_UPGRADE:
                return (gettext("\tupgrade\n"
@@ -243,7 +267,7 @@ get_usage(zpool_help_t idx) {
        case HELP_EVENTS:
                return (gettext("\tevents [-vHfc]\n"));
        case HELP_GET:
-               return (gettext("\tget <\"all\" | property[,...]> "
+               return (gettext("\tget [-pH] <\"all\" | property[,...]> "
                    "<pool> ...\n"));
        case HELP_SET:
                return (gettext("\tset <property=value> <pool> \n"));
@@ -251,6 +275,8 @@ get_usage(zpool_help_t idx) {
                return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n"
                    "\t    [-o property=value] <pool> <newpool> "
                    "[<device> ...]\n"));
+       case HELP_REGUID:
+               return (gettext("\treguid <pool>\n"));
        }
 
        abort();
@@ -324,6 +350,12 @@ usage(boolean_t requested)
                /* Iterate over all properties */
                (void) zprop_iter(print_prop_cb, fp, B_FALSE, B_TRUE,
                    ZFS_TYPE_POOL);
+
+               (void) fprintf(fp, "\t%-15s   ", "feature@...");
+               (void) fprintf(fp, "YES   disabled | enabled | active\n");
+
+               (void) fprintf(fp, gettext("\nThe feature@ properties must be "
+                   "appended with a feature name.\nSee zpool-features(5).\n"));
        }
 
        /*
@@ -367,6 +399,18 @@ print_vdev_tree(zpool_handle_t *zhp, const char *name, nvlist_t *nv, int indent,
        }
 }
 
+static boolean_t
+prop_list_contains_feature(nvlist_t *proplist)
+{
+       nvpair_t *nvp;
+       for (nvp = nvlist_next_nvpair(proplist, NULL); NULL != nvp;
+           nvp = nvlist_next_nvpair(proplist, nvp)) {
+               if (zpool_prop_feature(nvpair_name(nvp)))
+                       return (B_TRUE);
+       }
+       return (B_FALSE);
+}
+
 /*
  * Add a property pair (name, string-value) into a property nvlist.
  */
@@ -390,12 +434,34 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props,
        proplist = *props;
 
        if (poolprop) {
-               if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) {
+               const char *vname = zpool_prop_to_name(ZPOOL_PROP_VERSION);
+
+               if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL &&
+                   !zpool_prop_feature(propname)) {
                        (void) fprintf(stderr, gettext("property '%s' is "
                            "not a valid pool property\n"), propname);
                        return (2);
                }
-               normnm = zpool_prop_to_name(prop);
+
+               /*
+                * feature@ properties and version should not be specified
+                * at the same time.
+                */
+               if ((prop == ZPROP_INVAL && zpool_prop_feature(propname) &&
+                   nvlist_exists(proplist, vname)) ||
+                   (prop == ZPOOL_PROP_VERSION &&
+                   prop_list_contains_feature(proplist))) {
+                       (void) fprintf(stderr, gettext("'feature@' and "
+                           "'version' properties cannot be specified "
+                           "together\n"));
+                       return (2);
+               }
+
+
+               if (zpool_prop_feature(propname))
+                       normnm = propname;
+               else
+                       normnm = zpool_prop_to_name(prop);
        } else {
                if ((fprop = zfs_name_to_prop(propname)) != ZPROP_INVAL) {
                        normnm = zfs_prop_to_name(fprop);
@@ -421,11 +487,27 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props,
 }
 
 /*
- * zpool add [-fn] <pool> <vdev> ...
+ * Set a default property pair (name, string-value) in a property nvlist
+ */
+static int
+add_prop_list_default(const char *propname, char *propval, nvlist_t **props,
+    boolean_t poolprop)
+{
+       char *pval;
+
+       if (nvlist_lookup_string(*props, propname, &pval) == 0)
+               return (0);
+
+       return (add_prop_list(propname, propval, props, B_TRUE));
+}
+
+/*
+ * zpool add [-fn] [-o property=value] <pool> <vdev> ...
  *
  *     -f      Force addition of devices, even if they appear in use
  *     -n      Do not add the devices, but display the resulting layout if
  *             they were to be added.
+ *     -o      Set property=value.
  *
  * Adds the given vdevs to 'pool'.  As with create, the bulk of this work is
  * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
@@ -442,9 +524,11 @@ zpool_do_add(int argc, char **argv)
        int ret;
        zpool_handle_t *zhp;
        nvlist_t *config;
+       nvlist_t *props = NULL;
+       char *propval;
 
        /* check options */
-       while ((c = getopt(argc, argv, "fn")) != -1) {
+       while ((c = getopt(argc, argv, "fno:")) != -1) {
                switch (c) {
                case 'f':
                        force = B_TRUE;
@@ -452,6 +536,19 @@ zpool_do_add(int argc, char **argv)
                case 'n':
                        dryrun = B_TRUE;
                        break;
+               case 'o':
+                       if ((propval = strchr(optarg, '=')) == NULL) {
+                               (void) fprintf(stderr, gettext("missing "
+                                   "'=' for -o option\n"));
+                               usage(B_FALSE);
+                       }
+                       *propval = '\0';
+                       propval++;
+
+                       if ((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) ||
+                           (add_prop_list(optarg, propval, &props, B_TRUE)))
+                               usage(B_FALSE);
+                       break;
                case '?':
                        (void) fprintf(stderr, gettext("invalid option '%c'\n"),
                            optopt);
@@ -488,7 +585,7 @@ zpool_do_add(int argc, char **argv)
        }
 
        /* pass off to get_vdev_spec for processing */
-       nvroot = make_root_vdev(zhp, NULL, force, !force, B_FALSE, dryrun,
+       nvroot = make_root_vdev(zhp, props, force, !force, B_FALSE, dryrun,
            argc, argv);
        if (nvroot == NULL) {
                zpool_close(zhp);
@@ -497,6 +594,10 @@ zpool_do_add(int argc, char **argv)
 
        if (dryrun) {
                nvlist_t *poolnvroot;
+               nvlist_t **l2child;
+               uint_t l2children, c;
+               char *vname;
+               boolean_t hadcache = B_FALSE;
 
                verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
                    &poolnvroot) == 0);
@@ -516,11 +617,36 @@ zpool_do_add(int argc, char **argv)
                        print_vdev_tree(zhp, "logs", nvroot, 0, B_TRUE);
                }
 
+               /* Do the same for the caches */
+               if (nvlist_lookup_nvlist_array(poolnvroot, ZPOOL_CONFIG_L2CACHE,
+                   &l2child, &l2children) == 0 && l2children) {
+                       hadcache = B_TRUE;
+                       (void) printf(gettext("\tcache\n"));
+                       for (c = 0; c < l2children; c++) {
+                               vname = zpool_vdev_name(g_zfs, NULL,
+                                   l2child[c], B_FALSE);
+                               (void) printf("\t  %s\n", vname);
+                               free(vname);
+                       }
+               }
+               if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
+                   &l2child, &l2children) == 0 && l2children) {
+                       if (!hadcache)
+                               (void) printf(gettext("\tcache\n"));
+                       for (c = 0; c < l2children; c++) {
+                               vname = zpool_vdev_name(g_zfs, NULL,
+                                   l2child[c], B_FALSE);
+                               (void) printf("\t  %s\n", vname);
+                               free(vname);
+                       }
+               }
+
                ret = 0;
        } else {
                ret = (zpool_add(zhp, nvroot) != 0);
        }
 
+       nvlist_free(props);
        nvlist_free(nvroot);
        zpool_close(zhp);
 
@@ -567,7 +693,128 @@ zpool_do_remove(int argc, char **argv)
 }
 
 /*
- * zpool create [-fn] [-o property=value] ...
+ * zpool labelclear <vdev>
+ *
+ * Verifies that the vdev is not active and zeros out the label information
+ * on the device.
+ */
+int
+zpool_do_labelclear(int argc, char **argv)
+{
+       char *vdev, *name;
+       int c, fd = -1, ret = 0;
+       pool_state_t state;
+       boolean_t inuse = B_FALSE;
+       boolean_t force = B_FALSE;
+
+       /* check options */
+       while ((c = getopt(argc, argv, "f")) != -1) {
+               switch (c) {
+               case 'f':
+                       force = B_TRUE;
+                       break;
+               default:
+                       (void) fprintf(stderr, gettext("invalid option '%c'\n"),
+                           optopt);
+                       usage(B_FALSE);
+               }
+       }
+
+       argc -= optind;
+       argv += optind;
+
+       /* get vdev name */
+       if (argc < 1) {
+               (void) fprintf(stderr, gettext("missing vdev device name\n"));
+               usage(B_FALSE);
+       }
+
+       vdev = argv[0];
+       if ((fd = open(vdev, O_RDWR)) < 0) {
+               (void) fprintf(stderr, gettext("Unable to open %s\n"), vdev);
+               return (B_FALSE);
+       }
+
+       name = NULL;
+       if (zpool_in_use(g_zfs, fd, &state, &name, &inuse) != 0) {
+               if (force)
+                       goto wipe_label;
+
+               (void) fprintf(stderr,
+                   gettext("Unable to determine pool state for %s\n"
+                   "Use -f to force the clearing any label data\n"), vdev);
+
+               return (1);
+       }
+
+       if (inuse) {
+               switch (state) {
+               default:
+               case POOL_STATE_ACTIVE:
+               case POOL_STATE_SPARE:
+               case POOL_STATE_L2CACHE:
+                       (void) fprintf(stderr,
+                           gettext("labelclear operation failed.\n"
+                           "\tVdev %s is a member (%s), of pool \"%s\".\n"
+                           "\tTo remove label information from this device, "
+                           "export or destroy\n\tthe pool, or remove %s from "
+                           "the configuration of this pool\n\tand retry the "
+                           "labelclear operation.\n"),
+                           vdev, zpool_pool_state_to_name(state), name, vdev);
+                       ret = 1;
+                       goto errout;
+
+               case POOL_STATE_EXPORTED:
+                       if (force)
+                               break;
+
+                       (void) fprintf(stderr,
+                           gettext("labelclear operation failed.\n\tVdev "
+                           "%s is a member of the exported pool \"%s\".\n"
+                           "\tUse \"zpool labelclear -f %s\" to force the "
+                           "removal of label\n\tinformation.\n"),
+                           vdev, name, vdev);
+                       ret = 1;
+                       goto errout;
+
+               case POOL_STATE_POTENTIALLY_ACTIVE:
+                       if (force)
+                               break;
+
+                       (void) fprintf(stderr,
+                           gettext("labelclear operation failed.\n"
+                           "\tVdev %s is a member of the pool \"%s\".\n"
+                           "\tThis pool is unknown to this system, but may "
+                           "be active on\n\tanother system. Use "
+                           "\'zpool labelclear -f %s\' to force the\n"
+                           "\tremoval of label information.\n"),
+                           vdev, name, vdev);
+                       ret = 1;
+                       goto errout;
+
+               case POOL_STATE_DESTROYED:
+                       /* inuse should never be set for a destroyed pool... */
+                       break;
+               }
+       }
+
+wipe_label:
+       if (zpool_clear_label(fd) != 0) {
+               (void) fprintf(stderr,
+                   gettext("Label clear failed on vdev %s\n"), vdev);
+               ret = 1;
+       }
+
+errout:
+       close(fd);
+       if (name != NULL)
+               free(name);
+
+       return (ret);
+}
+
+/*
+ * zpool create [-fnd] [-o property=value] ...
  *             [-O file-system-property=value] ...
  *             [-R root] [-m mountpoint] <pool> <dev> ...
  *
@@ -576,8 +823,10 @@ zpool_do_remove(int argc, char **argv)
  *             were to be created.
  *      -R     Create a pool under an alternate root
  *      -m     Set default mountpoint for the root dataset.  By default it's
- *             '/<pool>'
+ *             '/<pool>'
  *     -o      Set property=value.
+ *     -d      Don't automatically enable all supported pool features
+ *             (individual features can be enabled with -o).
  *     -O      Set fsproperty=value in the pool's root file system
  *
  * Creates the named pool according to the given vdev specification.  The
@@ -590,9 +839,11 @@ zpool_do_create(int argc, char **argv)
 {
        boolean_t force = B_FALSE;
        boolean_t dryrun = B_FALSE;
+       boolean_t enable_all_pool_feat = B_TRUE;
        int c;
        nvlist_t *nvroot = NULL;
        char *poolname;
+       char *tname = NULL;
        int ret = 1;
        char *altroot = NULL;
        char *mountpoint = NULL;
@@ -601,7 +852,7 @@ zpool_do_create(int argc, char **argv)
        char *propval;
 
        /* check options */
-       while ((c = getopt(argc, argv, ":fnR:m:o:O:")) != -1) {
+       while ((c = getopt(argc, argv, ":fndR:m:o:O:t:")) != -1) {
                switch (c) {
                case 'f':
                        force = B_TRUE;
@@ -609,20 +860,20 @@ zpool_do_create(int argc, char **argv)
                case 'n':
                        dryrun = B_TRUE;
                        break;
+               case 'd':
+                       enable_all_pool_feat = B_FALSE;
+                       break;
                case 'R':
                        altroot = optarg;
                        if (add_prop_list(zpool_prop_to_name(
                            ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE))
                                goto errout;
-                       if (nvlist_lookup_string(props,
-                           zpool_prop_to_name(ZPOOL_PROP_CACHEFILE),
-                           &propval) == 0)
-                               break;
-                       if (add_prop_list(zpool_prop_to_name(
+                       if (add_prop_list_default(zpool_prop_to_name(
                            ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
                                goto errout;
                        break;
                case 'm':
+                       /* Equivalent to -O mountpoint=optarg */
                        mountpoint = optarg;
                        break;
                case 'o':
@@ -636,6 +887,21 @@ zpool_do_create(int argc, char **argv)
 
                        if (add_prop_list(optarg, propval, &props, B_TRUE))
                                goto errout;
+
+                       /*
+                        * If the user is creating a pool that doesn't support
+                        * feature flags, don't enable any features.
+                        */
+                       if (zpool_name_to_prop(optarg) == ZPOOL_PROP_VERSION) {
+                               char *end;
+                               u_longlong_t ver;
+
+                               ver = strtoull(propval, &end, 10);
+                               if (*end == '\0' &&
+                                   ver < SPA_VERSION_FEATURES) {
+                                       enable_all_pool_feat = B_FALSE;
+                               }
+                       }
                        break;
                case 'O':
                        if ((propval = strchr(optarg, '=')) == NULL) {
@@ -646,8 +912,39 @@ zpool_do_create(int argc, char **argv)
                        *propval = '\0';
                        propval++;
 
-                       if (add_prop_list(optarg, propval, &fsprops, B_FALSE))
+                       /*
+                        * Mountpoints are checked and then added later.
+                        * Uniquely among properties, they can be specified
+                        * more than once, to avoid conflict with -m.
+                        */
+                       if (0 == strcmp(optarg,
+                           zfs_prop_to_name(ZFS_PROP_MOUNTPOINT))) {
+                               mountpoint = propval;
+                       } else if (add_prop_list(optarg, propval, &fsprops,
+                           B_FALSE)) {
+                               goto errout;
+                       }
+                       break;
+               case 't':
+                       /*
+                        * Sanity check temporary pool name.
+                        */
+                       if (strchr(optarg, '/') != NULL) {
+                               (void) fprintf(stderr, gettext("cannot create "
+                                   "'%s': invalid character '/' in temporary "
+                                   "name\n"), optarg);
+                               (void) fprintf(stderr, gettext("use 'zfs "
+                                   "create' to create a dataset\n"));
+                               goto errout;
+                       }
+
+                       if (add_prop_list(zpool_prop_to_name(
+                           ZPOOL_PROP_TNAME), optarg, &props, B_TRUE))
+                               goto errout;
+                       if (add_prop_list_default(zpool_prop_to_name(
+                           ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
                                goto errout;
+                       tname = optarg;
                        break;
                case ':':
                        (void) fprintf(stderr, gettext("missing argument for "
@@ -701,7 +998,6 @@ zpool_do_create(int argc, char **argv)
                goto errout;
        }
 
-
        if (altroot != NULL && altroot[0] != '/') {
                (void) fprintf(stderr, gettext("invalid alternate root '%s': "
                    "must be an absolute path\n"), altroot);
@@ -765,6 +1061,18 @@ zpool_do_create(int argc, char **argv)
                }
        }
 
+       /*
+        * Now that the mountpoint's validity has been checked, ensure that
+        * the property is set appropriately prior to creating the pool.
+        */
+       if (mountpoint != NULL) {
+               ret = add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT),
+                   mountpoint, &fsprops, B_FALSE);
+               if (ret != 0)
+                       goto errout;
+       }
+
+       ret = 1;
        if (dryrun) {
                /*
                 * For a dry run invocation, print out a basic message and run
@@ -783,16 +1091,35 @@ zpool_do_create(int argc, char **argv)
                /*
                 * Hand off to libzfs.
                 */
+               if (enable_all_pool_feat) {
+                       spa_feature_t i;
+                       for (i = 0; i < SPA_FEATURES; i++) {
+                               char propname[MAXPATHLEN];
+                               zfeature_info_t *feat = &spa_feature_table[i];
+
+                               (void) snprintf(propname, sizeof (propname),
+                                   "feature@%s", feat->fi_uname);
+
+                               /*
+                                * Skip feature if user specified it manually
+                                * on the command line.
+                                */
+                               if (nvlist_exists(props, propname))
+                                       continue;
+
+                               ret = add_prop_list(propname,
+                                   ZFS_FEATURE_ENABLED, &props, B_TRUE);
+                               if (ret != 0)
+                                       goto errout;
+                       }
+               }
+
+               ret = 1;
                if (zpool_create(g_zfs, poolname,
                    nvroot, props, fsprops) == 0) {
-                       zfs_handle_t *pool = zfs_open(g_zfs, poolname,
-                           ZFS_TYPE_FILESYSTEM);
+                       zfs_handle_t *pool = zfs_open(g_zfs,
+                           tname ? tname : poolname, ZFS_TYPE_FILESYSTEM);
                        if (pool != NULL) {
-                               if (mountpoint != NULL)
-                                       verify(zfs_prop_set(pool,
-                                           zfs_prop_to_name(
-                                           ZFS_PROP_MOUNTPOINT),
-                                           mountpoint) == 0);
                                if (zfs_mount(pool, NULL, 0) == 0)
                                        ret = zfs_shareall(pool);
                                zfs_close(pool);
@@ -876,16 +1203,49 @@ zpool_do_destroy(int argc, char **argv)
                return (1);
        }
 
-       ret = (zpool_destroy(zhp) != 0);
+       /* The history must be logged as part of the export */
+       log_history = B_FALSE;
+
+       ret = (zpool_destroy(zhp, history_str) != 0);
 
        zpool_close(zhp);
 
        return (ret);
 }
 
+typedef struct export_cbdata {
+       boolean_t force;
+       boolean_t hardforce;
+} export_cbdata_t;
+
+/*
+ * Export one pool
+ */
+int
+zpool_export_one(zpool_handle_t *zhp, void *data)
+{
+       export_cbdata_t *cb = data;
+
+       if (zpool_disable_datasets(zhp, cb->force) != 0)
+               return (1);
+
+       /* The history must be logged as part of the export */
+       log_history = B_FALSE;
+
+       if (cb->hardforce) {
+               if (zpool_export_force(zhp, history_str) != 0)
+                       return (1);
+       } else if (zpool_export(zhp, cb->force, history_str) != 0) {
+               return (1);
+       }
+
+       return (0);
+}
+
 /*
  * zpool export [-f] <pool> ...
  *
+ *     -a      Export all pools
  *     -f      Forcefully unmount datasets
  *
  * Export the given pools.  By default, the command will attempt to cleanly
@@ -895,16 +1255,18 @@ zpool_do_destroy(int argc, char **argv)
 int
 zpool_do_export(int argc, char **argv)
 {
+       export_cbdata_t cb;
+       boolean_t do_all = B_FALSE;
        boolean_t force = B_FALSE;
        boolean_t hardforce = B_FALSE;
-       int c;
-       zpool_handle_t *zhp;
-       int ret;
-       int i;
+       int c, ret;
 
        /* check options */
-       while ((c = getopt(argc, argv, "fF")) != -1) {
+       while ((c = getopt(argc, argv, "afF")) != -1) {
                switch (c) {
+               case 'a':
+                       do_all = B_TRUE;
+                       break;
                case 'f':
                        force = B_TRUE;
                        break;
@@ -918,37 +1280,28 @@ zpool_do_export(int argc, char **argv)
                }
        }
 
+       cb.force = force;
+       cb.hardforce = hardforce;
        argc -= optind;
        argv += optind;
 
+       if (do_all) {
+               if (argc != 0) {
+                       (void) fprintf(stderr, gettext("too many arguments\n"));
+                       usage(B_FALSE);
+               }
+
+               return (for_each_pool(argc, argv, B_TRUE, NULL,
+                   zpool_export_one, &cb));
+       }
+
        /* check arguments */
        if (argc < 1) {
                (void) fprintf(stderr, gettext("missing pool argument\n"));
                usage(B_FALSE);
        }
 
-       ret = 0;
-       for (i = 0; i < argc; i++) {
-               if ((zhp = zpool_open_canfail(g_zfs, argv[i])) == NULL) {
-                       ret = 1;
-                       continue;
-               }
-
-               if (zpool_disable_datasets(zhp, force) != 0) {
-                       ret = 1;
-                       zpool_close(zhp);
-                       continue;
-               }
-
-               if (hardforce) {
-                       if (zpool_export_force(zhp) != 0)
-                               ret = 1;
-               } else if (zpool_export(zhp, force) != 0) {
-                       ret = 1;
-               }
-
-               zpool_close(zhp);
-       }
+       ret = for_each_pool(argc, argv, B_TRUE, NULL, zpool_export_one, &cb);
 
        return (ret);
 }
@@ -1114,6 +1467,10 @@ print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
                        (void) printf(gettext("newer version"));
                        break;
 
+               case VDEV_AUX_UNSUP_FEAT:
+                       (void) printf(gettext("unsupported feature(s)"));
+                       break;
+
                case VDEV_AUX_SPARED:
                        verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
                            &cb.cb_guid) == 0);
@@ -1231,6 +1588,10 @@ print_import_config(const char *name, nvlist_t *nv, int namewidth, int depth)
                        (void) printf(gettext("newer version"));
                        break;
 
+               case VDEV_AUX_UNSUP_FEAT:
+                       (void) printf(gettext("unsupported feature(s)"));
+                       break;
+
                case VDEV_AUX_ERR_EXCEEDED:
                        (void) printf(gettext("too many errors"));
                        break;
@@ -1330,10 +1691,12 @@ show_import(nvlist_t *config)
        uint64_t guid;
        char *msgid;
        nvlist_t *nvroot;
-       int reason;
+       zpool_status_t reason;
+       zpool_errata_t errata;
        const char *health;
        uint_t vsc;
        int namewidth;
+       char *comment;
 
        verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
            &name) == 0);
@@ -1348,11 +1711,11 @@ show_import(nvlist_t *config)
            (uint64_t **)&vs, &vsc) == 0);
        health = zpool_state_to_name(vs->vs_state, vs->vs_aux);
 
-       reason = zpool_import_status(config, &msgid);
+       reason = zpool_import_status(config, &msgid, &errata);
 
-       (void) printf(gettext("  pool: %s\n"), name);
-       (void) printf(gettext("    id: %llu\n"), (u_longlong_t)guid);
-       (void) printf(gettext(" state: %s"), health);
+       (void) printf(gettext("   pool: %s\n"), name);
+       (void) printf(gettext("     id: %llu\n"), (u_longlong_t)guid);
+       (void) printf(gettext("  state: %s"), health);
        if (pool_state == POOL_STATE_DESTROYED)
                (void) printf(gettext(" (DESTROYED)"));
        (void) printf("\n");
@@ -1361,61 +1724,86 @@ show_import(nvlist_t *config)
        case ZPOOL_STATUS_MISSING_DEV_R:
        case ZPOOL_STATUS_MISSING_DEV_NR:
        case ZPOOL_STATUS_BAD_GUID_SUM:
-               (void) printf(gettext("status: One or more devices are missing "
-                   "from the system.\n"));
+               (void) printf(gettext(" status: One or more devices are "
+                   "missing from the system.\n"));
                break;
 
        case ZPOOL_STATUS_CORRUPT_LABEL_R:
        case ZPOOL_STATUS_CORRUPT_LABEL_NR:
-               (void) printf(gettext("status: One or more devices contains "
+               (void) printf(gettext(" status: One or more devices contains "
                    "corrupted data.\n"));
                break;
 
        case ZPOOL_STATUS_CORRUPT_DATA:
-               (void) printf(gettext("status: The pool data is corrupted.\n"));
+               (void) printf(
+                   gettext(" status: The pool data is corrupted.\n"));
                break;
 
        case ZPOOL_STATUS_OFFLINE_DEV:
-               (void) printf(gettext("status: One or more devices "
+               (void) printf(gettext(" status: One or more devices "
                    "are offlined.\n"));
                break;
 
        case ZPOOL_STATUS_CORRUPT_POOL:
-               (void) printf(gettext("status: The pool metadata is "
+               (void) printf(gettext(" status: The pool metadata is "
                    "corrupted.\n"));
                break;
 
        case ZPOOL_STATUS_VERSION_OLDER:
-               (void) printf(gettext("status: The pool is formatted using an "
-                   "older on-disk version.\n"));
+               (void) printf(gettext(" status: The pool is formatted using a "
+                   "legacy on-disk version.\n"));
                break;
 
        case ZPOOL_STATUS_VERSION_NEWER:
-               (void) printf(gettext("status: The pool is formatted using an "
+               (void) printf(gettext(" status: The pool is formatted using an "
                    "incompatible version.\n"));
                break;
 
+       case ZPOOL_STATUS_FEAT_DISABLED:
+               (void) printf(gettext(" status: Some supported features are "
+                   "not enabled on the pool.\n"));
+               break;
+
+       case ZPOOL_STATUS_UNSUP_FEAT_READ:
+               (void) printf(gettext("status: The pool uses the following "
+                   "feature(s) not supported on this sytem:\n"));
+               zpool_print_unsup_feat(config);
+               break;
+
+       case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
+               (void) printf(gettext("status: The pool can only be accessed "
+                   "in read-only mode on this system. It\n\tcannot be "
+                   "accessed in read-write mode because it uses the "
+                   "following\n\tfeature(s) not supported on this system:\n"));
+               zpool_print_unsup_feat(config);
+               break;
+
        case ZPOOL_STATUS_HOSTID_MISMATCH:
-               (void) printf(gettext("status: The pool was last accessed by "
+               (void) printf(gettext(" status: The pool was last accessed by "
                    "another system.\n"));
                break;
 
        case ZPOOL_STATUS_FAULTED_DEV_R:
        case ZPOOL_STATUS_FAULTED_DEV_NR:
-               (void) printf(gettext("status: One or more devices are "
+               (void) printf(gettext(" status: One or more devices are "
                    "faulted.\n"));
                break;
 
        case ZPOOL_STATUS_BAD_LOG:
-               (void) printf(gettext("status: An intent log record cannot be "
+               (void) printf(gettext(" status: An intent log record cannot be "
                    "read.\n"));
                break;
 
        case ZPOOL_STATUS_RESILVERING:
-               (void) printf(gettext("status: One or more devices were being "
+               (void) printf(gettext(" status: One or more devices were being "
                    "resilvered.\n"));
                break;
 
+       case ZPOOL_STATUS_ERRATA:
+               (void) printf(gettext(" status: Errata #%d detected.\n"),
+                   errata);
+               break;
+
        default:
                /*
                 * No other status can be seen when importing pools.
@@ -1427,44 +1815,92 @@ show_import(nvlist_t *config)
         * Print out an action according to the overall state of the pool.
         */
        if (vs->vs_state == VDEV_STATE_HEALTHY) {
-               if (reason == ZPOOL_STATUS_VERSION_OLDER)
-                       (void) printf(gettext("action: The pool can be "
+               if (reason == ZPOOL_STATUS_VERSION_OLDER ||
+                   reason == ZPOOL_STATUS_FEAT_DISABLED) {
+                       (void) printf(gettext(" action: The pool can be "
                            "imported using its name or numeric identifier, "
                            "though\n\tsome features will not be available "
                            "without an explicit 'zpool upgrade'.\n"));
-               else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH)
-                       (void) printf(gettext("action: The pool can be "
+               } else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH) {
+                       (void) printf(gettext(" action: The pool can be "
                            "imported using its name or numeric "
                            "identifier and\n\tthe '-f' flag.\n"));
-               else
-                       (void) printf(gettext("action: The pool can be "
+               } else if (reason == ZPOOL_STATUS_ERRATA) {
+                       switch (errata) {
+                       case ZPOOL_ERRATA_NONE:
+                               break;
+
+                       case ZPOOL_ERRATA_ZOL_2094_SCRUB:
+                               (void) printf(gettext(" action: The pool can "
+                                   "be imported using its name or numeric "
+                                   "identifier,\n\thowever there is a compat"
+                                   "ibility issue which should be corrected"
+                                   "\n\tby running 'zpool scrub'\n"));
+                               break;
+
+                       case ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY:
+                               (void) printf(gettext(" action: The pool can"
+                                   "not be imported with this version of ZFS "
+                                   "due to\n\tan active asynchronous destroy. "
+                                   "Revert to an earlier version\n\tand "
+                                   "allow the destroy to complete before "
+                                   "updating.\n"));
+                               break;
+
+                       default:
+                               /*
+                                * All errata must contain an action message.
+                                */
+                               assert(0);
+                       }
+               } else {
+                       (void) printf(gettext(" action: The pool can be "
                            "imported using its name or numeric "
                            "identifier.\n"));
+               }
        } else if (vs->vs_state == VDEV_STATE_DEGRADED) {
-               (void) printf(gettext("action: The pool can be imported "
+               (void) printf(gettext(" action: The pool can be imported "
                    "despite missing or damaged devices.  The\n\tfault "
                    "tolerance of the pool may be compromised if imported.\n"));
        } else {
                switch (reason) {
                case ZPOOL_STATUS_VERSION_NEWER:
-                       (void) printf(gettext("action: The pool cannot be "
+                       (void) printf(gettext(" action: The pool cannot be "
                            "imported.  Access the pool on a system running "
                            "newer\n\tsoftware, or recreate the pool from "
                            "backup.\n"));
                        break;
+               case ZPOOL_STATUS_UNSUP_FEAT_READ:
+                       (void) printf(gettext("action: The pool cannot be "
+                           "imported. Access the pool on a system that "
+                           "supports\n\tthe required feature(s), or recreate "
+                           "the pool from backup.\n"));
+                       break;
+               case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
+                       (void) printf(gettext("action: The pool cannot be "
+                           "imported in read-write mode. Import the pool "
+                           "with\n"
+                           "\t\"-o readonly=on\", access the pool on a system "
+                           "that supports the\n\trequired feature(s), or "
+                           "recreate the pool from backup.\n"));
+                       break;
                case ZPOOL_STATUS_MISSING_DEV_R:
                case ZPOOL_STATUS_MISSING_DEV_NR:
                case ZPOOL_STATUS_BAD_GUID_SUM:
-                       (void) printf(gettext("action: The pool cannot be "
+                       (void) printf(gettext(" action: The pool cannot be "
                            "imported. Attach the missing\n\tdevices and try "
                            "again.\n"));
                        break;
                default:
-                       (void) printf(gettext("action: The pool cannot be "
+                       (void) printf(gettext(" action: The pool cannot be "
                            "imported due to damaged devices or data.\n"));
                }
        }
 
+       /* Print the comment attached to the pool. */
+       if (nvlist_lookup_string(config, ZPOOL_CONFIG_COMMENT, &comment) == 0)
+               (void) printf(gettext("comment: %s\n"), comment);
+
        /*
         * If the state is "closed" or "can't open", and the aux state
         * is "corrupt data":
@@ -1482,10 +1918,10 @@ show_import(nvlist_t *config)
        }
 
        if (msgid != NULL)
-               (void) printf(gettext("   see: http://www.sun.com/msg/%s\n"),
+               (void) printf(gettext("   see: http://zfsonlinux.org/msg/%s\n"),
                    msgid);
 
-       (void) printf(gettext("config:\n\n"));
+       (void) printf(gettext(" config:\n\n"));
 
        namewidth = max_width(NULL, nvroot, 0, 0);
        if (namewidth < 10)
@@ -1523,43 +1959,36 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
            ZPOOL_CONFIG_POOL_STATE, &state) == 0);
        verify(nvlist_lookup_uint64(config,
            ZPOOL_CONFIG_VERSION, &version) == 0);
-       if (version > SPA_VERSION) {
+       if (!SPA_VERSION_IS_SUPPORTED(version)) {
                (void) fprintf(stderr, gettext("cannot import '%s': pool "
-                   "is formatted using a newer ZFS version\n"), name);
+                   "is formatted using an unsupported ZFS version\n"), name);
                return (1);
        } else if (state != POOL_STATE_EXPORTED &&
            !(flags & ZFS_IMPORT_ANY_HOST)) {
-               uint64_t hostid;
-
-               if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
-                   &hostid) == 0) {
-                       unsigned long system_hostid = gethostid() & 0xffffffff;
-
-                       if ((unsigned long)hostid != system_hostid) {
-                               char *hostname;
-                               uint64_t timestamp;
-                               time_t t;
-
-                               verify(nvlist_lookup_string(config,
-                                   ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);
-                               verify(nvlist_lookup_uint64(config,
-                                   ZPOOL_CONFIG_TIMESTAMP, &timestamp) == 0);
-                               t = timestamp;
-                               (void) fprintf(stderr, gettext("cannot import "
-                                   "'%s': pool may be in use from other "
-                                   "system, it was last accessed by %s "
-                                   "(hostid: 0x%lx) on %s"), name, hostname,
-                                   (unsigned long)hostid,
-                                   asctime(localtime(&t)));
-                               (void) fprintf(stderr, gettext("use '-f' to "
-                                   "import anyway\n"));
-                               return (1);
-                       }
-               } else {
-                       (void) fprintf(stderr, gettext("cannot import '%s': "
-                           "pool may be in use from other system\n"), name);
-                       (void) fprintf(stderr, gettext("use '-f' to import "
-                           "anyway\n"));
+               uint64_t hostid = 0;
+               unsigned long system_hostid = get_system_hostid();
+
+               (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
+                   &hostid);
+
+               if (hostid != 0 && (unsigned long)hostid != system_hostid) {
+                       char *hostname;
+                       uint64_t timestamp;
+                       time_t t;
+
+                       verify(nvlist_lookup_string(config,
+                           ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);
+                       verify(nvlist_lookup_uint64(config,
+                           ZPOOL_CONFIG_TIMESTAMP, &timestamp) == 0);
+                       t = timestamp;
+                       (void) fprintf(stderr, gettext("cannot import "
+                           "'%s': pool may be in use from other "
+                           "system, it was last accessed by %s "
+                           "(hostid: 0x%lx) on %s"), name, hostname,
+                           (unsigned long)hostid,
+                           asctime(localtime(&t)));
+                       (void) fprintf(stderr, gettext("use '-f' to "
+                           "import anyway\n"));
                        return (1);
                }
        }
@@ -1632,6 +2061,7 @@ int
 zpool_do_import(int argc, char **argv)
 {
        char **searchdirs = NULL;
+       char *env, *envdup = NULL;
        int nsearch = 0;
        int c;
        int err = 0;
@@ -1659,7 +2089,7 @@ zpool_do_import(int argc, char **argv)
        char *endptr;
 
        /* check options */
-       while ((c = getopt(argc, argv, ":aCc:d:DEfFmnNo:rR:T:VX")) != -1) {
+       while ((c = getopt(argc, argv, ":aCc:d:DEfFmnNo:R:tT:VX")) != -1) {
                switch (c) {
                case 'a':
                        do_all = B_TRUE;
@@ -1713,17 +2143,20 @@ zpool_do_import(int argc, char **argv)
                        if (add_prop_list(zpool_prop_to_name(
                            ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE))
                                goto error;
-                       if (nvlist_lookup_string(props,
-                           zpool_prop_to_name(ZPOOL_PROP_CACHEFILE),
-                           &propval) == 0)
-                               break;
-                       if (add_prop_list(zpool_prop_to_name(
+                       if (add_prop_list_default(zpool_prop_to_name(
+                           ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
+                               goto error;
+                       break;
+               case 't':
+                       flags |= ZFS_IMPORT_TEMP_NAME;
+                       if (add_prop_list_default(zpool_prop_to_name(
                            ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
                                goto error;
                        break;
+
                case 'T':
                        errno = 0;
-                       txg = strtoull(optarg, &endptr, 10);
+                       txg = strtoull(optarg, &endptr, 0);
                        if (errno != 0 || *endptr != '\0') {
                                (void) fprintf(stderr,
                                    gettext("invalid txg value\n"));
@@ -1821,8 +2254,10 @@ zpool_do_import(int argc, char **argv)
 
                errno = 0;
                searchguid = strtoull(argv[0], &endptr, 10);
-               if (errno != 0 || *endptr != '\0')
+               if (errno != 0 || *endptr != '\0') {
                        searchname = argv[0];
+                       searchguid = 0;
+               }
                found_config = NULL;
 
                /*
@@ -1831,12 +2266,36 @@ zpool_do_import(int argc, char **argv)
                idata.unique = B_TRUE;
        }
 
+       /*
+        * Check the environment for the preferred search path.
+        */
+       if ((searchdirs == NULL) && (env = getenv("ZPOOL_IMPORT_PATH"))) {
+               char *dir;
 
-       idata.path = searchdirs;
-       idata.paths = nsearch;
-       idata.poolname = searchname;
-       idata.guid = searchguid;
-       idata.cachefile = cachefile;
+               envdup = strdup(env);
+
+               dir = strtok(envdup, ":");
+               while (dir != NULL) {
+                       if (searchdirs == NULL) {
+                               searchdirs = safe_malloc(sizeof (char *));
+                       } else {
+                               char **tmp = safe_malloc((nsearch + 1) *
+                                   sizeof (char *));
+                               bcopy(searchdirs, tmp, nsearch *
+                                   sizeof (char *));
+                               free(searchdirs);
+                               searchdirs = tmp;
+                       }
+                       searchdirs[nsearch++] = dir;
+                       dir = strtok(NULL, ":");
+               }
+       }
+
+       idata.path = searchdirs;
+       idata.paths = nsearch;
+       idata.poolname = searchname;
+       idata.guid = searchguid;
+       idata.cachefile = cachefile;
 
        pools = zpool_search_import(g_zfs, &idata);
 
@@ -1867,6 +2326,8 @@ zpool_do_import(int argc, char **argv)
        if (err == 1) {
                if (searchdirs != NULL)
                        free(searchdirs);
+               if (envdup != NULL)
+                       free(envdup);
                nvlist_free(policy);
                return (1);
        }
@@ -1969,15 +2430,17 @@ error:
        nvlist_free(policy);
        if (searchdirs != NULL)
                free(searchdirs);
+       if (envdup != NULL)
+               free(envdup);
 
        return (err ? 1 : 0);
 }
 
 typedef struct iostat_cbdata {
-       zpool_list_t *cb_list;
-       int cb_verbose;
-       int cb_iteration;
+       boolean_t cb_verbose;
        int cb_namewidth;
+       int cb_iteration;
+       zpool_list_t *cb_list;
 } iostat_cbdata_t;
 
 static void
@@ -2086,10 +2549,15 @@ print_vdev_stats(zpool_handle_t *zhp, const char *name, nvlist_t *oldnv,
                return;
 
        for (c = 0; c < children; c++) {
-               uint64_t ishole = B_FALSE;
+               uint64_t ishole = B_FALSE, islog = B_FALSE;
 
-               if (nvlist_lookup_uint64(newchild[c],
-                   ZPOOL_CONFIG_IS_HOLE, &ishole) == 0 && ishole)
+               (void) nvlist_lookup_uint64(newchild[c], ZPOOL_CONFIG_IS_HOLE,
+                   &ishole);
+
+               (void) nvlist_lookup_uint64(newchild[c], ZPOOL_CONFIG_IS_LOG,
+                   &islog);
+
+               if (ishole || islog)
                        continue;
 
                vname = zpool_vdev_name(g_zfs, zhp, newchild[c], B_FALSE);
@@ -2098,6 +2566,31 @@ print_vdev_stats(zpool_handle_t *zhp, const char *name, nvlist_t *oldnv,
                free(vname);
        }
 
+       /*
+        * Log device section
+        */
+
+       if (num_logs(newnv) > 0) {
+               (void) printf("%-*s      -      -      -      -      -      "
+                   "-\n", cb->cb_namewidth, "logs");
+
+               for (c = 0; c < children; c++) {
+                       uint64_t islog = B_FALSE;
+                       (void) nvlist_lookup_uint64(newchild[c],
+                           ZPOOL_CONFIG_IS_LOG, &islog);
+
+                       if (islog) {
+                               vname = zpool_vdev_name(g_zfs, zhp, newchild[c],
+                                   B_FALSE);
+                               print_vdev_stats(zhp, vname, oldnv ?
+                                   oldchild[c] : NULL, newchild[c],
+                                   cb, depth + 2);
+                               free(vname);
+                       }
+               }
+
+       }
+
        /*
         * Include level 2 ARC devices in iostat output
         */
@@ -2175,11 +2668,30 @@ print_iostat(zpool_handle_t *zhp, void *data)
        return (0);
 }
 
+static int
+get_columns(void)
+{
+       struct winsize ws;
+       int columns = 80;
+       int error;
+
+       if (isatty(STDOUT_FILENO)) {
+               error = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
+               if (error == 0)
+                       columns = ws.ws_col;
+       } else {
+               columns = 999;
+       }
+
+       return (columns);
+}
+
 int
 get_namewidth(zpool_handle_t *zhp, void *data)
 {
        iostat_cbdata_t *cb = data;
        nvlist_t *config, *nvroot;
+       int columns;
 
        if ((config = zpool_get_config(zhp, NULL)) != NULL) {
                verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
@@ -2187,17 +2699,20 @@ get_namewidth(zpool_handle_t *zhp, void *data)
                if (!cb->cb_verbose)
                        cb->cb_namewidth = strlen(zpool_get_name(zhp));
                else
-                       cb->cb_namewidth = max_width(zhp, nvroot, 0, 0);
+                       cb->cb_namewidth = max_width(zhp, nvroot, 0,
+                           cb->cb_namewidth);
        }
 
        /*
-        * The width must fall into the range [10,38].  The upper limit is the
-        * maximum we can have and still fit in 80 columns.
+        * The width must be at least 10, but may be as large as the
+        * column width - 42 so that we can still fit in one line.
         */
+       columns = get_columns();
+
        if (cb->cb_namewidth < 10)
                cb->cb_namewidth = 10;
-       if (cb->cb_namewidth > 38)
-               cb->cb_namewidth = 38;
+       if (cb->cb_namewidth > columns - 42)
+               cb->cb_namewidth = columns - 42;
 
        return (0);
 }
@@ -2305,10 +2820,11 @@ zpool_do_iostat(int argc, char **argv)
        unsigned long interval = 0, count = 0;
        zpool_list_t *list;
        boolean_t verbose = B_FALSE;
+       boolean_t omit_since_boot = B_FALSE;
        iostat_cbdata_t cb;
 
        /* check options */
-       while ((c = getopt(argc, argv, "T:v")) != -1) {
+       while ((c = getopt(argc, argv, "T:vy")) != -1) {
                switch (c) {
                case 'T':
                        get_timestamp_arg(*optarg);
@@ -2316,6 +2832,9 @@ zpool_do_iostat(int argc, char **argv)
                case 'v':
                        verbose = B_TRUE;
                        break;
+               case 'y':
+                       omit_since_boot = B_TRUE;
+                       break;
                case '?':
                        (void) fprintf(stderr, gettext("invalid option '%c'\n"),
                            optopt);
@@ -2355,11 +2874,16 @@ zpool_do_iostat(int argc, char **argv)
        cb.cb_namewidth = 0;
 
        for (;;) {
-               pool_list_update(list);
-
                if ((npools = pool_list_count(list)) == 0)
-                       (void) printf(gettext("no pools available\n"));
+                       (void) fprintf(stderr, gettext("no pools available\n"));
                else {
+                       /*
+                        * If this is the first iteration and -y was supplied
+                        * we skip any printing.
+                        */
+                       boolean_t skip = (omit_since_boot &&
+                               cb.cb_iteration == 0);
+
                        /*
                         * Refresh all statistics.  This is done as an
                         * explicit step before calculating the maximum name
@@ -2381,12 +2905,18 @@ zpool_do_iostat(int argc, char **argv)
                                print_timestamp(timestamp_fmt);
 
                        /*
-                        * If it's the first time, or verbose mode, print the
-                        * header.
+                        * If it's the first time and we're not skipping it,
+                        * or either skip or verbose mode, print the header.
                         */
-                       if (++cb.cb_iteration == 1 || verbose)
+                       if ((++cb.cb_iteration == 1 && !skip) ||
+                               (skip != verbose))
                                print_iostat_header(&cb);
 
+                       if (skip) {
+                               (void) sleep(interval);
+                               continue;
+                       }
+
                        (void) pool_list_iter(list, B_FALSE, print_iostat, &cb);
 
                        /*
@@ -2422,8 +2952,9 @@ zpool_do_iostat(int argc, char **argv)
 }
 
 typedef struct list_cbdata {
+       boolean_t       cb_verbose;
+       int             cb_namewidth;
        boolean_t       cb_scripted;
-       boolean_t       cb_first;
        zprop_list_t    *cb_proplist;
 } list_cbdata_t;
 
@@ -2431,30 +2962,49 @@ typedef struct list_cbdata {
  * Given a list of columns to display, output appropriate headers for each one.
  */
 static void
-print_header(zprop_list_t *pl)
+print_header(list_cbdata_t *cb)
 {
+       zprop_list_t *pl = cb->cb_proplist;
+       char headerbuf[ZPOOL_MAXPROPLEN];
        const char *header;
        boolean_t first = B_TRUE;
        boolean_t right_justify;
+       size_t width = 0;
 
        for (; pl != NULL; pl = pl->pl_next) {
-               if (pl->pl_prop == ZPROP_INVAL)
-                       continue;
+               width = pl->pl_width;
+               if (first && cb->cb_verbose) {
+                       /*
+                        * Reset the width to accommodate the verbose listing
+                        * of devices.
+                        */
+                       width = cb->cb_namewidth;
+               }
 
                if (!first)
                        (void) printf("  ");
                else
                        first = B_FALSE;
 
-               header = zpool_prop_column_name(pl->pl_prop);
-               right_justify = zpool_prop_align_right(pl->pl_prop);
+               right_justify = B_FALSE;
+               if (pl->pl_prop != ZPROP_INVAL) {
+                       header = zpool_prop_column_name(pl->pl_prop);
+                       right_justify = zpool_prop_align_right(pl->pl_prop);
+               } else {
+                       int i;
+
+                       for (i = 0; pl->pl_user_prop[i] != '\0'; i++)
+                               headerbuf[i] = toupper(pl->pl_user_prop[i]);
+                       headerbuf[i] = '\0';
+                       header = headerbuf;
+               }
 
                if (pl->pl_next == NULL && !right_justify)
                        (void) printf("%s", header);
                else if (right_justify)
-                       (void) printf("%*s", (int)pl->pl_width, header);
+                       (void) printf("%*s", (int)width, header);
                else
-                       (void) printf("%-*s", (int)pl->pl_width, header);
+                       (void) printf("%-*s", (int)width, header);
        }
 
        (void) printf("\n");
@@ -2465,17 +3015,28 @@ print_header(zprop_list_t *pl)
  * to the described layout.
  */
 static void
-print_pool(zpool_handle_t *zhp, zprop_list_t *pl, int scripted)
+print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
 {
+       zprop_list_t *pl = cb->cb_proplist;
        boolean_t first = B_TRUE;
        char property[ZPOOL_MAXPROPLEN];
        char *propstr;
        boolean_t right_justify;
-       int width;
+       size_t width;
 
        for (; pl != NULL; pl = pl->pl_next) {
+
+               width = pl->pl_width;
+               if (first && cb->cb_verbose) {
+                       /*
+                        * Reset the width to accommodate the verbose listing
+                        * of devices.
+                        */
+                       width = cb->cb_namewidth;
+               }
+
                if (!first) {
-                       if (scripted)
+                       if (cb->cb_scripted)
                                (void) printf("\t");
                        else
                                (void) printf("  ");
@@ -2492,28 +3053,156 @@ print_pool(zpool_handle_t *zhp, zprop_list_t *pl, int scripted)
                                propstr = property;
 
                        right_justify = zpool_prop_align_right(pl->pl_prop);
+               } else if ((zpool_prop_feature(pl->pl_user_prop) ||
+                   zpool_prop_unsupported(pl->pl_user_prop)) &&
+                   zpool_prop_get_feature(zhp, pl->pl_user_prop, property,
+                   sizeof (property)) == 0) {
+                       propstr = property;
                } else {
                        propstr = "-";
                }
 
-               width = pl->pl_width;
 
                /*
                 * If this is being called in scripted mode, or if this is the
                 * last column and it is left-justified, don't include a width
                 * format specifier.
                 */
-               if (scripted || (pl->pl_next == NULL && !right_justify))
+               if (cb->cb_scripted || (pl->pl_next == NULL && !right_justify))
                        (void) printf("%s", propstr);
                else if (right_justify)
-                       (void) printf("%*s", width, propstr);
+                       (void) printf("%*s", (int)width, propstr);
                else
-                       (void) printf("%-*s", width, propstr);
+                       (void) printf("%-*s", (int)width, propstr);
        }
 
        (void) printf("\n");
 }
 
+static void
+print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted,
+    boolean_t valid)
+{
+       char propval[64];
+       boolean_t fixed;
+       size_t width = zprop_width(prop, &fixed, ZFS_TYPE_POOL);
+
+       switch (prop) {
+       case ZPOOL_PROP_EXPANDSZ:
+               if (value == 0)
+                       (void) strlcpy(propval, "-", sizeof (propval));
+               else
+                       zfs_nicenum(value, propval, sizeof (propval));
+               break;
+       case ZPOOL_PROP_FRAGMENTATION:
+               if (value == ZFS_FRAG_INVALID) {
+                       (void) strlcpy(propval, "-", sizeof (propval));
+               } else {
+                       (void) snprintf(propval, sizeof (propval), "%llu%%",
+                           (unsigned long long)value);
+               }
+               break;
+       case ZPOOL_PROP_CAPACITY:
+               (void) snprintf(propval, sizeof (propval), "%llu%%",
+                   (unsigned long long)value);
+               break;
+       default:
+               zfs_nicenum(value, propval, sizeof (propval));
+       }
+
+       if (!valid)
+               (void) strlcpy(propval, "-", sizeof (propval));
+
+       if (scripted)
+               (void) printf("\t%s", propval);
+       else
+               (void) printf("  %*s", (int)width, propval);
+}
+
+void
+print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
+    list_cbdata_t *cb, int depth)
+{
+       nvlist_t **child;
+       vdev_stat_t *vs;
+       uint_t c, children;
+       char *vname;
+       boolean_t scripted = cb->cb_scripted;
+
+       verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
+           (uint64_t **)&vs, &c) == 0);
+
+       if (name != NULL) {
+               boolean_t toplevel = (vs->vs_space != 0);
+               uint64_t cap;
+
+               if (scripted)
+                       (void) printf("\t%s", name);
+               else if (strlen(name) + depth > cb->cb_namewidth)
+                       (void) printf("%*s%s", depth, "", name);
+               else
+                       (void) printf("%*s%s%*s", depth, "", name,
+                           (int)(cb->cb_namewidth - strlen(name) - depth), "");
+
+               /*
+                * Print the properties for the individual vdevs. Some
+                * properties are only applicable to toplevel vdevs. The
+                * 'toplevel' boolean value is passed to the print_one_column()
+                * to indicate that the value is valid.
+                */
+               print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, scripted,
+                   toplevel);
+               print_one_column(ZPOOL_PROP_ALLOCATED, vs->vs_alloc, scripted,
+                   toplevel);
+               print_one_column(ZPOOL_PROP_FREE, vs->vs_space - vs->vs_alloc,
+                   scripted, toplevel);
+               print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, scripted,
+                   B_TRUE);
+               print_one_column(ZPOOL_PROP_FRAGMENTATION,
+                   vs->vs_fragmentation, scripted,
+                   (vs->vs_fragmentation != ZFS_FRAG_INVALID && toplevel));
+               cap = (vs->vs_space == 0) ? 0 :
+                   (vs->vs_alloc * 100 / vs->vs_space);
+               print_one_column(ZPOOL_PROP_CAPACITY, cap, scripted, toplevel);
+               (void) printf("\n");
+       }
+
+       if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
+           &child, &children) != 0)
+               return;
+
+       for (c = 0; c < children; c++) {
+               uint64_t ishole = B_FALSE;
+
+               if (nvlist_lookup_uint64(child[c],
+                   ZPOOL_CONFIG_IS_HOLE, &ishole) == 0 && ishole)
+                       continue;
+
+               vname = zpool_vdev_name(g_zfs, zhp, child[c], B_FALSE);
+               print_list_stats(zhp, vname, child[c], cb, depth + 2);
+               free(vname);
+       }
+
+       /*
+        * Include level 2 ARC devices in iostat output
+        */
+       if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
+           &child, &children) != 0)
+               return;
+
+       if (children > 0) {
+               (void) printf("%-*s      -      -      -      -      -      "
+                   "-\n", cb->cb_namewidth, "cache");
+               for (c = 0; c < children; c++) {
+                       vname = zpool_vdev_name(g_zfs, zhp, child[c],
+                           B_FALSE);
+                       print_list_stats(zhp, vname, child[c], cb, depth + 2);
+                       free(vname);
+               }
+       }
+}
+
+
 /*
  * Generic callback function to list a pool.
  */
@@ -2521,14 +3210,18 @@ int
 list_callback(zpool_handle_t *zhp, void *data)
 {
        list_cbdata_t *cbp = data;
+       nvlist_t *config;
+       nvlist_t *nvroot;
 
-       if (cbp->cb_first) {
-               if (!cbp->cb_scripted)
-                       print_header(cbp->cb_proplist);
-               cbp->cb_first = B_FALSE;
-       }
+       config = zpool_get_config(zhp, NULL);
 
-       print_pool(zhp, cbp->cb_proplist, cbp->cb_scripted);
+       print_pool(zhp, cbp);
+       if (!cbp->cb_verbose)
+               return (0);
+
+       verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
+           &nvroot) == 0);
+       print_list_stats(zhp, NULL, nvroot, cbp, 0);
 
        return (0);
 }
@@ -2539,7 +3232,8 @@ list_callback(zpool_handle_t *zhp, void *data)
  *     -H      Scripted mode.  Don't display headers, and separate properties
  *             by a single tab.
  *     -o      List of properties to display.  Defaults to
- *             "name,size,allocated,free,capacity,health,altroot"
+ *             "name,size,allocated,free,expandsize,fragmentation,capacity,"
+ *             "dedupratio,health,altroot"
  *     -T      Display a timestamp in date(1) or Unix format
  *
  * List all pools in the system, whether or not they're healthy.  Output space
@@ -2549,15 +3243,18 @@ int
 zpool_do_list(int argc, char **argv)
 {
        int c;
-       int ret;
+       int ret = 0;
        list_cbdata_t cb = { 0 };
        static char default_props[] =
-           "name,size,allocated,free,capacity,dedupratio,health,altroot";
+           "name,size,allocated,free,expandsize,fragmentation,capacity,"
+           "dedupratio,health,altroot";
        char *props = default_props;
        unsigned long interval = 0, count = 0;
+       zpool_list_t *list;
+       boolean_t first = B_TRUE;
 
        /* check options */
-       while ((c = getopt(argc, argv, ":Ho:T:")) != -1) {
+       while ((c = getopt(argc, argv, ":Ho:T:v")) != -1) {
                switch (c) {
                case 'H':
                        cb.cb_scripted = B_TRUE;
@@ -2568,6 +3265,9 @@ zpool_do_list(int argc, char **argv)
                case 'T':
                        get_timestamp_arg(*optarg);
                        break;
+               case 'v':
+                       cb.cb_verbose = B_TRUE;
+                       break;
                case ':':
                        (void) fprintf(stderr, gettext("missing argument for "
                            "'%c' option\n"), optopt);
@@ -2588,23 +3288,22 @@ zpool_do_list(int argc, char **argv)
        if (zprop_get_list(g_zfs, props, &cb.cb_proplist, ZFS_TYPE_POOL) != 0)
                usage(B_FALSE);
 
-       cb.cb_first = B_TRUE;
-
        for (;;) {
+               if ((list = pool_list_get(argc, argv, &cb.cb_proplist,
+                   &ret)) == NULL)
+                       return (1);
+
+               if (pool_list_count(list) == 0)
+                       break;
 
                if (timestamp_fmt != NODATE)
                        print_timestamp(timestamp_fmt);
 
-               ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist,
-                   list_callback, &cb);
-
-               if (argc == 0 && cb.cb_first)
-                       (void) printf(gettext("no pools available\n"));
-               else if (argc && cb.cb_first) {
-                       /* cannot open the given pool */
-                       zprop_free_list(cb.cb_proplist);
-                       return (1);
+               if (!cb.cb_scripted && (first || cb.cb_verbose)) {
+                       print_header(&cb);
+                       first = B_FALSE;
                }
+               ret = pool_list_iter(list, B_TRUE, list_callback, &cb);
 
                if (interval == 0)
                        break;
@@ -2612,9 +3311,16 @@ zpool_do_list(int argc, char **argv)
                if (count != 0 && --count == 0)
                        break;
 
+               pool_list_free(list);
                (void) sleep(interval);
        }
 
+       if (argc == 0 && !cb.cb_scripted && pool_list_count(list) == 0) {
+               (void) printf(gettext("no pools available\n"));
+               ret = 0;
+       }
+
+       pool_list_free(list);
        zprop_free_list(cb.cb_proplist);
        return (ret);
 }
@@ -2627,14 +3333,29 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing)
        nvlist_t *nvroot;
        char *poolname, *old_disk, *new_disk;
        zpool_handle_t *zhp;
+       nvlist_t *props = NULL;
+       char *propval;
        int ret;
 
        /* check options */
-       while ((c = getopt(argc, argv, "f")) != -1) {
+       while ((c = getopt(argc, argv, "fo:")) != -1) {
                switch (c) {
                case 'f':
                        force = B_TRUE;
                        break;
+               case 'o':
+                       if ((propval = strchr(optarg, '=')) == NULL) {
+                               (void) fprintf(stderr, gettext("missing "
+                                   "'=' for -o option\n"));
+                               usage(B_FALSE);
+                       }
+                       *propval = '\0';
+                       propval++;
+
+                       if ((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) ||
+                           (add_prop_list(optarg, propval, &props, B_TRUE)))
+                               usage(B_FALSE);
+                       break;
                case '?':
                        (void) fprintf(stderr, gettext("invalid option '%c'\n"),
                            optopt);
@@ -2691,7 +3412,7 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing)
                return (1);
        }
 
-       nvroot = make_root_vdev(zhp, NULL, force, B_FALSE, replacing, B_FALSE,
+       nvroot = make_root_vdev(zhp, props, force, B_FALSE, replacing, B_FALSE,
            argc, argv);
        if (nvroot == NULL) {
                zpool_close(zhp);
@@ -2721,9 +3442,10 @@ zpool_do_replace(int argc, char **argv)
 }
 
 /*
- * zpool attach [-f] <pool> <device> <new_device>
+ * zpool attach [-f] [-o property=value] <pool> <device> <new_device>
  *
  *     -f      Force attach, even if <new_device> appears to be in use.
+ *     -o      Set property=value.
  *
  * Attach <new_device> to the mirror containing <device>.  If <device> is not
  * part of a mirror, then <device> will be transformed into a mirror of
@@ -2922,7 +3644,7 @@ zpool_do_split(int argc, char **argv)
        if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
            zpool_enable_datasets(zhp, mntopts, 0) != 0) {
                ret = 1;
-               (void) fprintf(stderr, gettext("Split was succssful, but "
+               (void) fprintf(stderr, gettext("Split was successful, but "
                    "the datasets could not all be mounted\n"));
                (void) fprintf(stderr, gettext("Try doing '%s' with a "
                    "different altroot\n"), "zpool import");
@@ -3151,6 +3873,97 @@ zpool_do_clear(int argc, char **argv)
        return (ret);
 }
 
+/*
+ * zpool reguid <pool>
+ */
+int
+zpool_do_reguid(int argc, char **argv)
+{
+       int c;
+       char *poolname;
+       zpool_handle_t *zhp;
+       int ret = 0;
+
+       /* check options */
+       while ((c = getopt(argc, argv, "")) != -1) {
+               switch (c) {
+               case '?':
+                       (void) fprintf(stderr, gettext("invalid option '%c'\n"),
+                           optopt);
+                       usage(B_FALSE);
+               }
+       }
+
+       argc -= optind;
+       argv += optind;
+
+       /* get pool name and check number of arguments */
+       if (argc < 1) {
+               (void) fprintf(stderr, gettext("missing pool name\n"));
+               usage(B_FALSE);
+       }
+
+       if (argc > 1) {
+               (void) fprintf(stderr, gettext("too many arguments\n"));
+               usage(B_FALSE);
+       }
+
+       poolname = argv[0];
+       if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
+               return (1);
+
+       ret = zpool_reguid(zhp);
+
+       zpool_close(zhp);
+       return (ret);
+}
+
+
+/*
+ * zpool reopen <pool>
+ *
+ * Reopen the pool so that the kernel can update the sizes of all vdevs.
+ */
+int
+zpool_do_reopen(int argc, char **argv)
+{
+       int c;
+       int ret = 0;
+       zpool_handle_t *zhp;
+       char *pool;
+
+       /* check options */
+       while ((c = getopt(argc, argv, "")) != -1) {
+               switch (c) {
+               case '?':
+                       (void) fprintf(stderr, gettext("invalid option '%c'\n"),
+                           optopt);
+                       usage(B_FALSE);
+               }
+       }
+
+       argc--;
+       argv++;
+
+       if (argc < 1) {
+               (void) fprintf(stderr, gettext("missing pool name\n"));
+               usage(B_FALSE);
+       }
+
+       if (argc > 1) {
+               (void) fprintf(stderr, gettext("too many arguments\n"));
+               usage(B_FALSE);
+       }
+
+       pool = argv[0];
+       if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL)
+               return (1);
+
+       ret = zpool_reopen(zhp);
+       zpool_close(zhp);
+       return (ret);
+}
+
 typedef struct scrub_cbdata {
        int     cb_type;
        int     cb_argc;
@@ -3238,7 +4051,7 @@ print_scan_status(pool_scan_stat_t *ps)
        double fraction_done;
        char processed_buf[7], examined_buf[7], total_buf[7], rate_buf[7];
 
-       (void) printf(gettext(" scan: "));
+       (void) printf(gettext("  scan: "));
 
        /* If there's never been a scan, there's not much to say. */
        if (ps == NULL || ps->pss_func == POOL_SCAN_NONE ||
@@ -3422,14 +4235,20 @@ print_dedup_stats(nvlist_t *config)
 
        /*
         * If the pool was faulted then we may not have been able to
-        * obtain the config. Otherwise, if have anything in the dedup
+        * obtain the config. Otherwise, if we have anything in the dedup
         * table continue processing the stats.
         */
        if (nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_OBJ_STATS,
-           (uint64_t **)&ddo, &c) != 0 || ddo->ddo_count == 0)
+           (uint64_t **)&ddo, &c) != 0)
                return;
 
        (void) printf("\n");
+       (void) printf(gettext(" dedup: "));
+       if (ddo->ddo_count == 0) {
+               (void) printf(gettext("no DDT entries\n"));
+               return;
+       }
+
        (void) printf("DDT entries %llu, size %llu on disk, %llu in core\n",
            (u_longlong_t)ddo->ddo_count,
            (u_longlong_t)ddo->ddo_dspace,
@@ -3448,7 +4267,7 @@ print_dedup_stats(nvlist_t *config)
  *        pool: tank
  *     status: DEGRADED
  *     reason: One or more devices ...
- *         see: http://www.sun.com/msg/ZFS-xxxx-01
+ *         see: http://zfsonlinux.org/msg/ZFS-xxxx-01
  *     config:
  *             mirror          DEGRADED
  *                c1t0d0       OK
@@ -3463,13 +4282,14 @@ status_callback(zpool_handle_t *zhp, void *data)
        status_cbdata_t *cbp = data;
        nvlist_t *config, *nvroot;
        char *msgid;
-       int reason;
+       zpool_status_t reason;
+       zpool_errata_t errata;
        const char *health;
        uint_t c;
        vdev_stat_t *vs;
 
        config = zpool_get_config(zhp, NULL);
-       reason = zpool_get_status(zhp, &msgid);
+       reason = zpool_get_status(zhp, &msgid, &errata);
 
        cbp->cb_count++;
 
@@ -3477,7 +4297,10 @@ status_callback(zpool_handle_t *zhp, void *data)
         * If we were given 'zpool status -x', only report those pools with
         * problems.
         */
-       if (reason == ZPOOL_STATUS_OK && cbp->cb_explain) {
+       if (cbp->cb_explain &&
+           (reason == ZPOOL_STATUS_OK ||
+           reason == ZPOOL_STATUS_VERSION_OLDER ||
+           reason == ZPOOL_STATUS_FEAT_DISABLED)) {
                if (!cbp->cb_allpools) {
                        (void) printf(gettext("pool '%s' is healthy\n"),
                            zpool_get_name(zhp));
@@ -3592,12 +4415,13 @@ status_callback(zpool_handle_t *zhp, void *data)
                break;
 
        case ZPOOL_STATUS_VERSION_OLDER:
-               (void) printf(gettext("status: The pool is formatted using an "
-                   "older on-disk format.  The pool can\n\tstill be used, but "
-                   "some features are unavailable.\n"));
+               (void) printf(gettext("status: The pool is formatted using a "
+                   "legacy on-disk format.  The pool can\n\tstill be used, "
+                   "but some features are unavailable.\n"));
                (void) printf(gettext("action: Upgrade the pool using 'zpool "
                    "upgrade'.  Once this is done, the\n\tpool will no longer "
-                   "be accessible on older software versions.\n"));
+                   "be accessible on software that does not support\n\t"
+                   "feature flags.\n"));
                break;
 
        case ZPOOL_STATUS_VERSION_NEWER:
@@ -3609,6 +4433,41 @@ status_callback(zpool_handle_t *zhp, void *data)
                    "backup.\n"));
                break;
 
+       case ZPOOL_STATUS_FEAT_DISABLED:
+               (void) printf(gettext("status: Some supported features are not "
+                   "enabled on the pool. The pool can\n\tstill be used, but "
+                   "some features are unavailable.\n"));
+               (void) printf(gettext("action: Enable all features using "
+                   "'zpool upgrade'. Once this is done,\n\tthe pool may no "
+                   "longer be accessible by software that does not support\n\t"
+                   "the features. See zpool-features(5) for details.\n"));
+               break;
+
+       case ZPOOL_STATUS_UNSUP_FEAT_READ:
+               (void) printf(gettext("status: The pool cannot be accessed on "
+                   "this system because it uses the\n\tfollowing feature(s) "
+                   "not supported on this system:\n"));
+               zpool_print_unsup_feat(config);
+               (void) printf("\n");
+               (void) printf(gettext("action: Access the pool from a system "
+                   "that supports the required feature(s),\n\tor restore the "
+                   "pool from backup.\n"));
+               break;
+
+       case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
+               (void) printf(gettext("status: The pool can only be accessed "
+                   "in read-only mode on this system. It\n\tcannot be "
+                   "accessed in read-write mode because it uses the "
+                   "following\n\tfeature(s) not supported on this system:\n"));
+               zpool_print_unsup_feat(config);
+               (void) printf("\n");
+               (void) printf(gettext("action: The pool cannot be accessed in "
+                   "read-write mode. Import the pool with\n"
+                   "\t\"-o readonly=on\", access the pool from a system that "
+                   "supports the\n\trequired feature(s), or restore the "
+                   "pool from backup.\n"));
+               break;
+
        case ZPOOL_STATUS_FAULTED_DEV_R:
                (void) printf(gettext("status: One or more devices are "
                    "faulted in response to persistent errors.\n\tSufficient "
@@ -3648,6 +4507,39 @@ status_callback(zpool_handle_t *zhp, void *data)
                    "'zpool clear'.\n"));
                break;
 
+       case ZPOOL_STATUS_HOSTID_MISMATCH:
+               (void) printf(gettext("status: Mismatch between pool hostid "
+                   "and system hostid on imported pool.\n\tThis pool was "
+                   "previously imported into a system with a different "
+                   "hostid,\n\tand then was verbatim imported into this "
+                   "system.\n"));
+               (void) printf(gettext("action: Export this pool on all systems "
+                   "on which it is imported.\n"
+                   "\tThen import it to correct the mismatch.\n"));
+               break;
+
+       case ZPOOL_STATUS_ERRATA:
+               (void) printf(gettext("status: Errata #%d detected.\n"),
+                   errata);
+
+               switch (errata) {
+               case ZPOOL_ERRATA_NONE:
+                       break;
+
+               case ZPOOL_ERRATA_ZOL_2094_SCRUB:
+                       (void) printf(gettext("action: To correct the issue "
+                           "run 'zpool scrub'.\n"));
+                       break;
+
+               default:
+                       /*
+                        * All errata which allow the pool to be imported
+                        * must contain an action message.
+                        */
+                       assert(0);
+               }
+               break;
+
        default:
                /*
                 * The remaining errors can't actually be generated, yet.
@@ -3656,7 +4548,7 @@ status_callback(zpool_handle_t *zhp, void *data)
        }
 
        if (msgid != NULL)
-               (void) printf(gettext("   see: http://www.sun.com/msg/%s\n"),
+               (void) printf(gettext("   see: http://zfsonlinux.org/msg/%s\n"),
                    msgid);
 
        if (config != NULL) {
@@ -3793,7 +4685,7 @@ zpool_do_status(int argc, char **argv)
                    status_callback, &cb);
 
                if (argc == 0 && cb.cb_count == 0)
-                       (void) printf(gettext("no pools available\n"));
+                       (void) fprintf(stderr, gettext("no pools available\n"));
                else if (cb.cb_explain && cb.cb_first && cb.cb_allpools)
                        (void) printf(gettext("all pools are healthy\n"));
 
@@ -3813,56 +4705,186 @@ zpool_do_status(int argc, char **argv)
 }
 
 typedef struct upgrade_cbdata {
-       int     cb_all;
        int     cb_first;
-       int     cb_newer;
        int     cb_argc;
        uint64_t cb_version;
        char    **cb_argv;
 } upgrade_cbdata_t;
 
+static int
+check_unsupp_fs(zfs_handle_t *zhp, void *unsupp_fs)
+{
+       int zfs_version = (int) zfs_prop_get_int(zhp, ZFS_PROP_VERSION);
+       int *count = (int *)unsupp_fs;
+
+       if (zfs_version > ZPL_VERSION) {
+               (void) printf(gettext("%s (v%d) is not supported by this "
+                   "implementation of ZFS.\n"),
+                   zfs_get_name(zhp), zfs_version);
+               (*count)++;
+       }
+
+       zfs_iter_filesystems(zhp, check_unsupp_fs, unsupp_fs);
+
+       zfs_close(zhp);
+
+       return (0);
+}
+
+static int
+upgrade_version(zpool_handle_t *zhp, uint64_t version)
+{
+       int ret;
+       nvlist_t *config;
+       uint64_t oldversion;
+       int unsupp_fs = 0;
+
+       config = zpool_get_config(zhp, NULL);
+       verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
+           &oldversion) == 0);
+
+       assert(SPA_VERSION_IS_SUPPORTED(oldversion));
+       assert(oldversion < version);
+
+       ret = zfs_iter_root(zpool_get_handle(zhp), check_unsupp_fs, &unsupp_fs);
+       if (ret != 0)
+               return (ret);
+
+       if (unsupp_fs) {
+               (void) fprintf(stderr, gettext("Upgrade not performed due "
+                   "to %d unsupported filesystems (max v%d).\n"),
+                   unsupp_fs, (int) ZPL_VERSION);
+               return (1);
+       }
+
+       ret = zpool_upgrade(zhp, version);
+       if (ret != 0)
+               return (ret);
+
+       if (version >= SPA_VERSION_FEATURES) {
+               (void) printf(gettext("Successfully upgraded "
+                   "'%s' from version %llu to feature flags.\n"),
+                   zpool_get_name(zhp), (u_longlong_t) oldversion);
+       } else {
+               (void) printf(gettext("Successfully upgraded "
+                   "'%s' from version %llu to version %llu.\n"),
+                   zpool_get_name(zhp), (u_longlong_t) oldversion,
+                   (u_longlong_t) version);
+       }
+
+       return (0);
+}
+
+static int
+upgrade_enable_all(zpool_handle_t *zhp, int *countp)
+{
+       int i, ret, count;
+       boolean_t firstff = B_TRUE;
+       nvlist_t *enabled = zpool_get_features(zhp);
+
+       count = 0;
+       for (i = 0; i < SPA_FEATURES; i++) {
+               const char *fname = spa_feature_table[i].fi_uname;
+               const char *fguid = spa_feature_table[i].fi_guid;
+               if (!nvlist_exists(enabled, fguid)) {
+                       char *propname;
+                       verify(-1 != asprintf(&propname, "feature@%s", fname));
+                       ret = zpool_set_prop(zhp, propname,
+                           ZFS_FEATURE_ENABLED);
+                       if (ret != 0) {
+                               free(propname);
+                               return (ret);
+                       }
+                       count++;
+
+                       if (firstff) {
+                               (void) printf(gettext("Enabled the "
+                                   "following features on '%s':\n"),
+                                   zpool_get_name(zhp));
+                               firstff = B_FALSE;
+                       }
+                       (void) printf(gettext("  %s\n"), fname);
+                       free(propname);
+               }
+       }
+
+       if (countp != NULL)
+               *countp = count;
+       return (0);
+}
+
 static int
 upgrade_cb(zpool_handle_t *zhp, void *arg)
 {
        upgrade_cbdata_t *cbp = arg;
        nvlist_t *config;
        uint64_t version;
-       int ret = 0;
+       boolean_t printnl = B_FALSE;
+       int ret;
 
        config = zpool_get_config(zhp, NULL);
        verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
            &version) == 0);
 
-       if (!cbp->cb_newer && version < SPA_VERSION) {
-               if (!cbp->cb_all) {
-                       if (cbp->cb_first) {
-                               (void) printf(gettext("The following pools are "
-                                   "out of date, and can be upgraded.  After "
-                                   "being\nupgraded, these pools will no "
-                                   "longer be accessible by older software "
-                                   "versions.\n\n"));
-                               (void) printf(gettext("VER  POOL\n"));
-                               (void) printf(gettext("---  ------------\n"));
-                               cbp->cb_first = B_FALSE;
-                       }
+       assert(SPA_VERSION_IS_SUPPORTED(version));
 
-                       (void) printf("%2llu   %s\n", (u_longlong_t)version,
-                           zpool_get_name(zhp));
-               } else {
+       if (version < cbp->cb_version) {
+               cbp->cb_first = B_FALSE;
+               ret = upgrade_version(zhp, cbp->cb_version);
+               if (ret != 0)
+                       return (ret);
+               printnl = B_TRUE;
+
+               /*
+                * If they did "zpool upgrade -a", then we could
+                * be doing ioctls to different pools.  We need
+                * to log this history once to each pool, and bypass
+                * the normal history logging that happens in main().
+                */
+               (void) zpool_log_history(g_zfs, history_str);
+               log_history = B_FALSE;
+       }
+
+       if (cbp->cb_version >= SPA_VERSION_FEATURES) {
+               int count;
+               ret = upgrade_enable_all(zhp, &count);
+               if (ret != 0)
+                       return (ret);
+
+               if (count > 0) {
                        cbp->cb_first = B_FALSE;
-                       ret = zpool_upgrade(zhp, cbp->cb_version);
-                       if (!ret) {
-                               (void) printf(gettext("Successfully upgraded "
-                                   "'%s'\n\n"), zpool_get_name(zhp));
-                       }
+                       printnl = B_TRUE;
                }
-       } else if (cbp->cb_newer && version > SPA_VERSION) {
-               assert(!cbp->cb_all);
+       }
+
+       if (printnl) {
+               (void) printf(gettext("\n"));
+       }
+
+       return (0);
+}
+
+static int
+upgrade_list_older_cb(zpool_handle_t *zhp, void *arg)
+{
+       upgrade_cbdata_t *cbp = arg;
+       nvlist_t *config;
+       uint64_t version;
+
+       config = zpool_get_config(zhp, NULL);
+       verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
+           &version) == 0);
+
+       assert(SPA_VERSION_IS_SUPPORTED(version));
 
+       if (version < SPA_VERSION_FEATURES) {
                if (cbp->cb_first) {
                        (void) printf(gettext("The following pools are "
-                           "formatted using a newer software version and\n"
-                           "cannot be accessed on the current system.\n\n"));
+                           "formatted with legacy version numbers and can\n"
+                           "be upgraded to use feature flags.  After "
+                           "being upgraded, these pools\nwill no "
+                           "longer be accessible by software that does not "
+                           "support feature\nflags.\n\n"));
                        (void) printf(gettext("VER  POOL\n"));
                        (void) printf(gettext("---  ------------\n"));
                        cbp->cb_first = B_FALSE;
@@ -3872,20 +4894,79 @@ upgrade_cb(zpool_handle_t *zhp, void *arg)
                    zpool_get_name(zhp));
        }
 
-       zpool_close(zhp);
-       return (ret);
+       return (0);
+}
+
+static int
+upgrade_list_disabled_cb(zpool_handle_t *zhp, void *arg)
+{
+       upgrade_cbdata_t *cbp = arg;
+       nvlist_t *config;
+       uint64_t version;
+
+       config = zpool_get_config(zhp, NULL);
+       verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
+           &version) == 0);
+
+       if (version >= SPA_VERSION_FEATURES) {
+               int i;
+               boolean_t poolfirst = B_TRUE;
+               nvlist_t *enabled = zpool_get_features(zhp);
+
+               for (i = 0; i < SPA_FEATURES; i++) {
+                       const char *fguid = spa_feature_table[i].fi_guid;
+                       const char *fname = spa_feature_table[i].fi_uname;
+                       if (!nvlist_exists(enabled, fguid)) {
+                               if (cbp->cb_first) {
+                                       (void) printf(gettext("\nSome "
+                                           "supported features are not "
+                                           "enabled on the following pools. "
+                                           "Once a\nfeature is enabled the "
+                                           "pool may become incompatible with "
+                                           "software\nthat does not support "
+                                           "the feature. See "
+                                           "zpool-features(5) for "
+                                           "details.\n\n"));
+                                       (void) printf(gettext("POOL  "
+                                           "FEATURE\n"));
+                                       (void) printf(gettext("------"
+                                           "---------\n"));
+                                       cbp->cb_first = B_FALSE;
+                               }
+
+                               if (poolfirst) {
+                                       (void) printf(gettext("%s\n"),
+                                           zpool_get_name(zhp));
+                                       poolfirst = B_FALSE;
+                               }
+
+                               (void) printf(gettext("      %s\n"), fname);
+                       }
+                       /*
+                        * If they did "zpool upgrade -a", then we could
+                        * be doing ioctls to different pools.  We need
+                        * to log this history once to each pool, and bypass
+                        * the normal history logging that happens in main().
+                        */
+                       (void) zpool_log_history(g_zfs, history_str);
+                       log_history = B_FALSE;
+               }
+       }
+
+       return (0);
 }
 
 /* ARGSUSED */
 static int
 upgrade_one(zpool_handle_t *zhp, void *data)
 {
+       boolean_t printnl = B_FALSE;
        upgrade_cbdata_t *cbp = data;
        uint64_t cur_version;
        int ret;
 
        if (strcmp("log", zpool_get_name(zhp)) == 0) {
-               (void) printf(gettext("'log' is now a reserved word\n"
+               (void) fprintf(stderr, gettext("'log' is now a reserved word\n"
                    "Pool 'log' must be renamed using export and import"
                    " to upgrade.\n"));
                return (1);
@@ -3894,26 +4975,45 @@ upgrade_one(zpool_handle_t *zhp, void *data)
        cur_version = zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL);
        if (cur_version > cbp->cb_version) {
                (void) printf(gettext("Pool '%s' is already formatted "
-                   "using more current version '%llu'.\n"),
+                   "using more current version '%llu'.\n\n"),
                    zpool_get_name(zhp), (u_longlong_t) cur_version);
                return (0);
        }
-       if (cur_version == cbp->cb_version) {
+
+       if (cbp->cb_version != SPA_VERSION && cur_version == cbp->cb_version) {
                (void) printf(gettext("Pool '%s' is already formatted "
-                   "using the current version.\n"), zpool_get_name(zhp));
+                   "using version %llu.\n\n"), zpool_get_name(zhp),
+                   (u_longlong_t) cbp->cb_version);
                return (0);
        }
 
-       ret = zpool_upgrade(zhp, cbp->cb_version);
+       if (cur_version != cbp->cb_version) {
+               printnl = B_TRUE;
+               ret = upgrade_version(zhp, cbp->cb_version);
+               if (ret != 0)
+                       return (ret);
+       }
+
+       if (cbp->cb_version >= SPA_VERSION_FEATURES) {
+               int count = 0;
+               ret = upgrade_enable_all(zhp, &count);
+               if (ret != 0)
+                       return (ret);
+
+               if (count != 0) {
+                       printnl = B_TRUE;
+               } else if (cur_version == SPA_VERSION) {
+                       (void) printf(gettext("Pool '%s' already has all "
+                           "supported features enabled.\n"),
+                           zpool_get_name(zhp));
+               }
+       }
 
-       if (!ret) {
-               (void) printf(gettext("Successfully upgraded '%s' "
-                   "from version %llu to version %llu\n\n"),
-                   zpool_get_name(zhp), (u_longlong_t)cur_version,
-                   (u_longlong_t)cbp->cb_version);
+       if (printnl) {
+               (void) printf(gettext("\n"));
        }
 
-       return (ret != 0);
+       return (0);
 }
 
 /*
@@ -3932,6 +5032,7 @@ zpool_do_upgrade(int argc, char **argv)
        upgrade_cbdata_t cb = { 0 };
        int ret = 0;
        boolean_t showversions = B_FALSE;
+       boolean_t upgradeall = B_FALSE;
        char *end;
 
 
@@ -3939,15 +5040,15 @@ zpool_do_upgrade(int argc, char **argv)
        while ((c = getopt(argc, argv, ":avV:")) != -1) {
                switch (c) {
                case 'a':
-                       cb.cb_all = B_TRUE;
+                       upgradeall = B_TRUE;
                        break;
                case 'v':
                        showversions = B_TRUE;
                        break;
                case 'V':
                        cb.cb_version = strtoll(optarg, &end, 10);
-                       if (*end != '\0' || cb.cb_version > SPA_VERSION ||
-                           cb.cb_version < SPA_VERSION_1) {
+                       if (*end != '\0' ||
+                           !SPA_VERSION_IS_SUPPORTED(cb.cb_version)) {
                                (void) fprintf(stderr,
                                    gettext("invalid version '%s'\n"), optarg);
                                usage(B_FALSE);
@@ -3972,19 +5073,19 @@ zpool_do_upgrade(int argc, char **argv)
 
        if (cb.cb_version == 0) {
                cb.cb_version = SPA_VERSION;
-       } else if (!cb.cb_all && argc == 0) {
+       } else if (!upgradeall && argc == 0) {
                (void) fprintf(stderr, gettext("-V option is "
                    "incompatible with other arguments\n"));
                usage(B_FALSE);
        }
 
        if (showversions) {
-               if (cb.cb_all || argc != 0) {
+               if (upgradeall || argc != 0) {
                        (void) fprintf(stderr, gettext("-v option is "
                            "incompatible with other arguments\n"));
                        usage(B_FALSE);
                }
-       } else if (cb.cb_all) {
+       } else if (upgradeall) {
                if (argc != 0) {
                        (void) fprintf(stderr, gettext("-a option should not "
                            "be used along with a pool name\n"));
@@ -3992,11 +5093,27 @@ zpool_do_upgrade(int argc, char **argv)
                }
        }
 
-       (void) printf(gettext("This system is currently running "
-           "ZFS pool version %llu.\n\n"), SPA_VERSION);
-       cb.cb_first = B_TRUE;
+       (void) printf(gettext("This system supports ZFS pool feature "
+           "flags.\n\n"));
        if (showversions) {
-               (void) printf(gettext("The following versions are "
+               int i;
+
+               (void) printf(gettext("The following features are "
+                   "supported:\n\n"));
+               (void) printf(gettext("FEAT DESCRIPTION\n"));
+               (void) printf("----------------------------------------------"
+                   "---------------\n");
+               for (i = 0; i < SPA_FEATURES; i++) {
+                       zfeature_info_t *fi = &spa_feature_table[i];
+                       const char *ro = fi->fi_can_readonly ?
+                           " (read-only compatible)" : "";
+
+                       (void) printf("%-37s%s\n", fi->fi_uname, ro);
+                       (void) printf("     %s\n", fi->fi_desc);
+               }
+               (void) printf("\n");
+
+               (void) printf(gettext("The following legacy versions are also "
                    "supported:\n\n"));
                (void) printf(gettext("VER  DESCRIPTION\n"));
                (void) printf("---  -----------------------------------------"
@@ -4039,32 +5156,44 @@ zpool_do_upgrade(int argc, char **argv)
                (void) printf(gettext("\nFor more information on a particular "
                    "version, including supported releases,\n"));
                (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
-       } else if (argc == 0) {
-               int notfound;
-
+       } else if (argc == 0 && upgradeall) {
+               cb.cb_first = B_TRUE;
                ret = zpool_iter(g_zfs, upgrade_cb, &cb);
-               notfound = cb.cb_first;
-
-               if (!cb.cb_all && ret == 0) {
-                       if (!cb.cb_first)
-                               (void) printf("\n");
-                       cb.cb_first = B_TRUE;
-                       cb.cb_newer = B_TRUE;
-                       ret = zpool_iter(g_zfs, upgrade_cb, &cb);
-                       if (!cb.cb_first) {
-                               notfound = B_FALSE;
-                               (void) printf("\n");
+               if (ret == 0 && cb.cb_first) {
+                       if (cb.cb_version == SPA_VERSION) {
+                               (void) printf(gettext("All pools are already "
+                                   "formatted using feature flags.\n\n"));
+                               (void) printf(gettext("Every feature flags "
+                                   "pool already has all supported features "
+                                   "enabled.\n"));
+                       } else {
+                               (void) printf(gettext("All pools are already "
+                                   "formatted with version %llu or higher.\n"),
+                                   (u_longlong_t) cb.cb_version);
                        }
                }
+       } else if (argc == 0) {
+               cb.cb_first = B_TRUE;
+               ret = zpool_iter(g_zfs, upgrade_list_older_cb, &cb);
+               assert(ret == 0);
 
-               if (ret == 0) {
-                       if (notfound)
-                               (void) printf(gettext("All pools are formatted "
-                                   "using this version.\n"));
-                       else if (!cb.cb_all)
-                               (void) printf(gettext("Use 'zpool upgrade -v' "
-                                   "for a list of available versions and "
-                                   "their associated\nfeatures.\n"));
+               if (cb.cb_first) {
+                       (void) printf(gettext("All pools are formatted "
+                           "using feature flags.\n\n"));
+               } else {
+                       (void) printf(gettext("\nUse 'zpool upgrade -v' "
+                           "for a list of available legacy versions.\n"));
+               }
+
+               cb.cb_first = B_TRUE;
+               ret = zpool_iter(g_zfs, upgrade_list_disabled_cb, &cb);
+               assert(ret == 0);
+
+               if (cb.cb_first) {
+                       (void) printf(gettext("Every feature flags pool has "
+                           "all supported features enabled.\n"));
+               } else {
+                       (void) printf(gettext("\n"));
                }
        } else {
                ret = for_each_pool(argc, argv, B_FALSE, NULL,
@@ -4076,8 +5205,8 @@ zpool_do_upgrade(int argc, char **argv)
 
 typedef struct hist_cbdata {
        boolean_t first;
-       int longfmt;
-       int internal;
+       boolean_t longfmt;
+       boolean_t internal;
 } hist_cbdata_t;
 
 /*
@@ -4089,21 +5218,8 @@ get_history_one(zpool_handle_t *zhp, void *data)
        nvlist_t *nvhis;
        nvlist_t **records;
        uint_t numrecords;
-       char *cmdstr;
-       char *pathstr;
-       uint64_t dst_time;
-       time_t tsec;
-       struct tm t;
-       char tbuf[30];
        int ret, i;
-       uint64_t who;
-       struct passwd *pwd;
-       char *hostname;
-       char *zonename;
-       char internalstr[MAXPATHLEN];
        hist_cbdata_t *cb = (hist_cbdata_t *)data;
-       uint64_t txg;
-       uint64_t ievent;
 
        cb->first = B_FALSE;
 
@@ -4115,62 +5231,95 @@ get_history_one(zpool_handle_t *zhp, void *data)
        verify(nvlist_lookup_nvlist_array(nvhis, ZPOOL_HIST_RECORD,
            &records, &numrecords) == 0);
        for (i = 0; i < numrecords; i++) {
-               if (nvlist_lookup_uint64(records[i], ZPOOL_HIST_TIME,
-                   &dst_time) != 0)
-                       continue;
+               nvlist_t *rec = records[i];
+               char tbuf[30] = "";
 
-               /* is it an internal event or a standard event? */
-               if (nvlist_lookup_string(records[i], ZPOOL_HIST_CMD,
-                   &cmdstr) != 0) {
-                       if (cb->internal == 0)
-                               continue;
+               if (nvlist_exists(rec, ZPOOL_HIST_TIME)) {
+                       time_t tsec;
+                       struct tm t;
+
+                       tsec = fnvlist_lookup_uint64(records[i],
+                           ZPOOL_HIST_TIME);
+                       (void) localtime_r(&tsec, &t);
+                       (void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
+               }
 
-                       if (nvlist_lookup_uint64(records[i],
-                           ZPOOL_HIST_INT_EVENT, &ievent) != 0)
+               if (nvlist_exists(rec, ZPOOL_HIST_CMD)) {
+                       (void) printf("%s %s", tbuf,
+                           fnvlist_lookup_string(rec, ZPOOL_HIST_CMD));
+               } else if (nvlist_exists(rec, ZPOOL_HIST_INT_EVENT)) {
+                       int ievent =
+                           fnvlist_lookup_uint64(rec, ZPOOL_HIST_INT_EVENT);
+                       if (!cb->internal)
+                               continue;
+                       if (ievent >= ZFS_NUM_LEGACY_HISTORY_EVENTS) {
+                               (void) printf("%s unrecognized record:\n",
+                                   tbuf);
+                               dump_nvlist(rec, 4);
+                               continue;
+                       }
+                       (void) printf("%s [internal %s txg:%lld] %s", tbuf,
+                           zfs_history_event_names[ievent],
+                           (longlong_t) fnvlist_lookup_uint64(
+                           rec, ZPOOL_HIST_TXG),
+                           fnvlist_lookup_string(rec, ZPOOL_HIST_INT_STR));
+               } else if (nvlist_exists(rec, ZPOOL_HIST_INT_NAME)) {
+                       if (!cb->internal)
+                               continue;
+                       (void) printf("%s [txg:%lld] %s", tbuf,
+                           (longlong_t) fnvlist_lookup_uint64(
+                           rec, ZPOOL_HIST_TXG),
+                           fnvlist_lookup_string(rec, ZPOOL_HIST_INT_NAME));
+                       if (nvlist_exists(rec, ZPOOL_HIST_DSNAME)) {
+                               (void) printf(" %s (%llu)",
+                                   fnvlist_lookup_string(rec,
+                                   ZPOOL_HIST_DSNAME),
+                                   (u_longlong_t)fnvlist_lookup_uint64(rec,
+                                   ZPOOL_HIST_DSID));
+                       }
+                       (void) printf(" %s", fnvlist_lookup_string(rec,
+                           ZPOOL_HIST_INT_STR));
+               } else if (nvlist_exists(rec, ZPOOL_HIST_IOCTL)) {
+                       if (!cb->internal)
                                continue;
-                       verify(nvlist_lookup_uint64(records[i],
-                           ZPOOL_HIST_TXG, &txg) == 0);
-                       verify(nvlist_lookup_string(records[i],
-                           ZPOOL_HIST_INT_STR, &pathstr) == 0);
-                       if (ievent >= LOG_END)
+                       (void) printf("%s ioctl %s\n", tbuf,
+                           fnvlist_lookup_string(rec, ZPOOL_HIST_IOCTL));
+                       if (nvlist_exists(rec, ZPOOL_HIST_INPUT_NVL)) {
+                               (void) printf("    input:\n");
+                               dump_nvlist(fnvlist_lookup_nvlist(rec,
+                                   ZPOOL_HIST_INPUT_NVL), 8);
+                       }
+                       if (nvlist_exists(rec, ZPOOL_HIST_OUTPUT_NVL)) {
+                               (void) printf("    output:\n");
+                               dump_nvlist(fnvlist_lookup_nvlist(rec,
+                                   ZPOOL_HIST_OUTPUT_NVL), 8);
+                       }
+               } else {
+                       if (!cb->internal)
                                continue;
-                       (void) snprintf(internalstr,
-                           sizeof (internalstr),
-                           "[internal %s txg:%llu] %s",
-                           zfs_history_event_names[ievent], (u_longlong_t)txg,
-                           pathstr);
-                       cmdstr = internalstr;
+                       (void) printf("%s unrecognized record:\n", tbuf);
+                       dump_nvlist(rec, 4);
                }
-               tsec = dst_time;
-               (void) localtime_r(&tsec, &t);
-               (void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
-               (void) printf("%s %s", tbuf, cmdstr);
 
                if (!cb->longfmt) {
                        (void) printf("\n");
                        continue;
                }
                (void) printf(" [");
-               if (nvlist_lookup_uint64(records[i],
-                   ZPOOL_HIST_WHO, &who) == 0) {
-                       pwd = getpwuid((uid_t)who);
-                       if (pwd)
-                               (void) printf("user %s on",
-                                   pwd->pw_name);
-                       else
-                               (void) printf("user %d on",
-                                   (int)who);
-               } else {
-                       (void) printf(gettext("no info]\n"));
-                       continue;
+               if (nvlist_exists(rec, ZPOOL_HIST_WHO)) {
+                       uid_t who = fnvlist_lookup_uint64(rec, ZPOOL_HIST_WHO);
+                       struct passwd *pwd = getpwuid(who);
+                       (void) printf("user %d ", (int)who);
+                       if (pwd != NULL)
+                               (void) printf("(%s) ", pwd->pw_name);
                }
-               if (nvlist_lookup_string(records[i],
-                   ZPOOL_HIST_HOST, &hostname) == 0) {
-                       (void) printf(" %s", hostname);
+               if (nvlist_exists(rec, ZPOOL_HIST_HOST)) {
+                       (void) printf("on %s",
+                           fnvlist_lookup_string(rec, ZPOOL_HIST_HOST));
                }
-               if (nvlist_lookup_string(records[i],
-                   ZPOOL_HIST_ZONE, &zonename) == 0) {
-                       (void) printf(":%s", zonename);
+               if (nvlist_exists(rec, ZPOOL_HIST_ZONE)) {
+                       (void) printf(":%s",
+                           fnvlist_lookup_string(rec, ZPOOL_HIST_ZONE));
                }
 
                (void) printf("]");
@@ -4187,8 +5336,6 @@ get_history_one(zpool_handle_t *zhp, void *data)
  *
  * Displays the history of commands that modified pools.
  */
-
-
 int
 zpool_do_history(int argc, char **argv)
 {
@@ -4201,10 +5348,10 @@ zpool_do_history(int argc, char **argv)
        while ((c = getopt(argc, argv, "li")) != -1) {
                switch (c) {
                case 'l':
-                       cbdata.longfmt = 1;
+                       cbdata.longfmt = B_TRUE;
                        break;
                case 'i':
-                       cbdata.internal = 1;
+                       cbdata.internal = B_TRUE;
                        break;
                case '?':
                        (void) fprintf(stderr, gettext("invalid option '%c'\n"),
@@ -4219,7 +5366,7 @@ zpool_do_history(int argc, char **argv)
            &cbdata);
 
        if (argc == 0 && cbdata.first == B_TRUE) {
-               (void) printf(gettext("no pools available\n"));
+               (void) fprintf(stderr, gettext("no pools available\n"));
                return (0);
        }
 
@@ -4243,10 +5390,10 @@ zpool_do_events_short(nvlist_t *nvl)
        verify(nvlist_lookup_int64_array(nvl, FM_EREPORT_TIME, &tv, &n) == 0);
        memset(str, ' ', 32);
        (void) ctime_r((const time_t *)&tv[0], ctime_str);
-       (void) strncpy(str,    ctime_str+4,  6);             /* 'Jun 30'     */
-       (void) strncpy(str+7,  ctime_str+20, 4);             /* '1993'       */
-       (void) strncpy(str+12, ctime_str+11, 8);             /* '21:49:08'   */
-       (void) sprintf(str+20, ".%09lld", (longlong_t)tv[1]);/* '.123456789' */
+       (void) strncpy(str, ctime_str+4,  6);           /* 'Jun 30' */
+       (void) strncpy(str+7, ctime_str+20, 4);         /* '1993' */
+       (void) strncpy(str+12, ctime_str+11, 8);        /* '21:49:08' */
+       (void) sprintf(str+20, ".%09lld", (longlong_t)tv[1]); /* '.123456789' */
        (void) printf(gettext("%s "), str);
 
        verify(nvlist_lookup_string(nvl, FM_CLASS, &ptr) == 0);
@@ -4354,10 +5501,10 @@ zpool_do_events_nvprint(nvlist_t *nvl, int depth)
                        printf(gettext("(%d embedded nvlists)\n"), nelem);
                        for (i = 0; i < nelem; i++) {
                                printf(gettext("%*s%s[%d] = %s\n"),
-                                      depth, "", name, i, "(embedded nvlist)");
+                                   depth, "", name, i, "(embedded nvlist)");
                                zpool_do_events_nvprint(val[i], depth + 8);
                                printf(gettext("%*s(end %s[%i])\n"),
-                                      depth, "", name, i);
+                                   depth, "", name, i);
                        }
                        printf(gettext("%*s(end %s)\n"), depth, "", name);
                        }
@@ -4435,7 +5582,8 @@ zpool_do_events_nvprint(nvlist_t *nvl, int depth)
 
                        (void) nvpair_value_int64_array(nvp, &val, &nelem);
                        for (i = 0; i < nelem; i++)
-                               printf(gettext("0x%llx "), (u_longlong_t)val[i]);
+                               printf(gettext("0x%llx "),
+                                   (u_longlong_t)val[i]);
 
                        break;
                        }
@@ -4446,12 +5594,24 @@ zpool_do_events_nvprint(nvlist_t *nvl, int depth)
 
                        (void) nvpair_value_uint64_array(nvp, &val, &nelem);
                        for (i = 0; i < nelem; i++)
-                               printf(gettext("0x%llx "), (u_longlong_t)val[i]);
+                               printf(gettext("0x%llx "),
+                                   (u_longlong_t)val[i]);
+
+                       break;
+                       }
+
+               case DATA_TYPE_STRING_ARRAY: {
+                       char **str;
+                       uint_t i, nelem;
+
+                       (void) nvpair_value_string_array(nvp, &str, &nelem);
+                       for (i = 0; i < nelem; i++)
+                               printf(gettext("\"%s\" "),
+                                   str[i] ? str[i] : "<NULL>");
 
                        break;
                        }
 
-               case DATA_TYPE_STRING_ARRAY:
                case DATA_TYPE_BOOLEAN_ARRAY:
                case DATA_TYPE_BYTE_ARRAY:
                case DATA_TYPE_DOUBLE:
@@ -4468,17 +5628,17 @@ static int
 zpool_do_events_next(ev_opts_t *opts)
 {
        nvlist_t *nvl;
-       int cleanup_fd, ret, dropped;
+       int zevent_fd, ret, dropped;
 
-        cleanup_fd = open(ZFS_DEV, O_RDWR);
-        VERIFY(cleanup_fd >= 0);
+       zevent_fd = open(ZFS_DEV, O_RDWR);
+       VERIFY(zevent_fd >= 0);
 
        if (!opts->scripted)
                (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
 
        while (1) {
                ret = zpool_events_next(g_zfs, &nvl, &dropped,
-                   !!opts->follow, cleanup_fd);
+                   (opts->follow ? ZEVENT_NONE : ZEVENT_NONBLOCK), zevent_fd);
                if (ret || nvl == NULL)
                        break;
 
@@ -4491,11 +5651,12 @@ zpool_do_events_next(ev_opts_t *opts)
                        zpool_do_events_nvprint(nvl, 8);
                        printf(gettext("\n"));
                }
+               (void) fflush(stdout);
 
                nvlist_free(nvl);
        }
 
-        VERIFY(0 == close(cleanup_fd));
+       VERIFY(0 == close(zevent_fd));
 
        return (ret);
 }
@@ -4553,7 +5714,7 @@ zpool_do_events(int argc, char **argv)
        else
                ret = zpool_do_events_next(&opts);
 
-       return ret;
+       return (ret);
 }
 
 static int
@@ -4574,13 +5735,26 @@ get_callback(zpool_handle_t *zhp, void *data)
                    pl == cbp->cb_proplist)
                        continue;
 
-               if (zpool_get_prop(zhp, pl->pl_prop,
-                   value, sizeof (value), &srctype) != 0)
-                       continue;
+               if (pl->pl_prop == ZPROP_INVAL &&
+                   (zpool_prop_feature(pl->pl_user_prop) ||
+                   zpool_prop_unsupported(pl->pl_user_prop))) {
+                       srctype = ZPROP_SRC_LOCAL;
+
+                       if (zpool_prop_get_feature(zhp, pl->pl_user_prop,
+                           value, sizeof (value)) == 0) {
+                               zprop_print_one_property(zpool_get_name(zhp),
+                                   cbp, pl->pl_user_prop, value, srctype,
+                                   NULL, NULL);
+                       }
+               } else {
+                       if (zpool_get_prop_literal(zhp, pl->pl_prop, value,
+                           sizeof (value), &srctype, cbp->cb_literal) != 0)
+                               continue;
 
-               zprop_print_one_property(zpool_get_name(zhp), cbp,
-                   zpool_prop_to_name(pl->pl_prop), value, srctype, NULL,
-                   NULL);
+                       zprop_print_one_property(zpool_get_name(zhp), cbp,
+                           zpool_prop_to_name(pl->pl_prop), value, srctype,
+                           NULL, NULL);
+               }
        }
        return (0);
 }
@@ -4590,10 +5764,34 @@ zpool_do_get(int argc, char **argv)
 {
        zprop_get_cbdata_t cb = { 0 };
        zprop_list_t fake_name = { 0 };
-       int ret;
+       int c, ret;
+
+       /* check options */
+       while ((c = getopt(argc, argv, "pH")) != -1) {
+               switch (c) {
+               case 'p':
+                       cb.cb_literal = B_TRUE;
+                       break;
 
-       if (argc < 3)
+               case 'H':
+                       cb.cb_scripted = B_TRUE;
+                       break;
+
+               case '?':
+                       (void) fprintf(stderr, gettext("invalid option '%c'\n"),
+                           optopt);
+                       usage(B_FALSE);
+               }
+       }
+
+       argc -= optind;
+       argv += optind;
+
+       if (argc < 1) {
+               (void) fprintf(stderr, gettext("missing property "
+                   "argument\n"));
                usage(B_FALSE);
+       }
 
        cb.cb_first = B_TRUE;
        cb.cb_sources = ZPROP_SRC_ALL;
@@ -4603,10 +5801,12 @@ zpool_do_get(int argc, char **argv)
        cb.cb_columns[3] = GET_COL_SOURCE;
        cb.cb_type = ZFS_TYPE_POOL;
 
-       if (zprop_get_list(g_zfs, argv[1],  &cb.cb_proplist,
-           ZFS_TYPE_POOL) != 0)
+       if (zprop_get_list(g_zfs, argv[0], &cb.cb_proplist, ZFS_TYPE_POOL) != 0)
                usage(B_FALSE);
 
+       argc--;
+       argv++;
+
        if (cb.cb_proplist != NULL) {
                fake_name.pl_prop = ZPOOL_PROP_NAME;
                fake_name.pl_width = strlen(gettext("NAME"));
@@ -4614,7 +5814,7 @@ zpool_do_get(int argc, char **argv)
                cb.cb_proplist = &fake_name;
        }
 
-       ret = for_each_pool(argc - 2, argv + 2, B_TRUE, &cb.cb_proplist,
+       ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist,
            get_callback, &cb);
 
        if (cb.cb_proplist == &fake_name)
@@ -4717,6 +5917,8 @@ main(int argc, char **argv)
        (void) setlocale(LC_ALL, "");
        (void) textdomain(TEXT_DOMAIN);
 
+       dprintf_setup(&argc, argv);
+
        opterr = 0;
 
        /*
@@ -4732,17 +5934,17 @@ main(int argc, char **argv)
        /*
         * Special case '-?'
         */
-       if ((strcmp(cmdname, "-?") == 0) ||
-            strcmp(cmdname, "--help") == 0)
+       if ((strcmp(cmdname, "-?") == 0) || strcmp(cmdname, "--help") == 0)
                usage(B_TRUE);
 
-       if ((g_zfs = libzfs_init()) == NULL)
+       if ((g_zfs = libzfs_init()) == NULL) {
+               (void) fprintf(stderr, "%s", libzfs_error_init(errno));
                return (1);
+       }
 
        libzfs_print_on_error(g_zfs, B_TRUE);
 
-       zpool_set_history_str("zpool", argc, argv, history_str);
-       verify(zpool_stage_history(g_zfs, history_str) == 0);
+       zfs_save_arguments(argc, argv, history_str, sizeof (history_str));
 
        /*
         * Run the appropriate command.
@@ -4770,6 +5972,9 @@ main(int argc, char **argv)
                ret = 1;
        }
 
+       if (ret == 0 && log_history)
+               (void) zpool_log_history(g_zfs, history_str);
+
        libzfs_fini(g_zfs);
 
        /*