]> git.proxmox.com Git - mirror_zfs.git/blobdiff - cmd/zfs/zfs_main.c
OpenZFS 6550 - cmd/zfs: cleanup gcc warnings
[mirror_zfs.git] / cmd / zfs / zfs_main.c
index 4989b3b47272ebd1dcad6846bf1562f95479e703..3b72d60f2284cb66c6425f6d9c287d5990ab7584 100644 (file)
 
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2013 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
+ * Copyright 2012 Milan Jurik. All rights reserved.
  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  * Copyright (c) 2013 Steven Hartland.  All rights reserved.
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
+ * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>.
  */
 
 #include <assert.h>
@@ -101,6 +103,7 @@ static int zfs_do_hold(int argc, char **argv);
 static int zfs_do_holds(int argc, char **argv);
 static int zfs_do_release(int argc, char **argv);
 static int zfs_do_diff(int argc, char **argv);
+static int zfs_do_bookmark(int argc, char **argv);
 
 /*
  * Enable a reasonable set of defaults for libumem debugging on DEBUG builds.
@@ -147,6 +150,7 @@ typedef enum {
        HELP_HOLDS,
        HELP_RELEASE,
        HELP_DIFF,
+       HELP_BOOKMARK,
 } zfs_help_t;
 
 typedef struct zfs_command {
@@ -173,6 +177,7 @@ static zfs_command_t command_table[] = {
        { "clone",      zfs_do_clone,           HELP_CLONE              },
        { "promote",    zfs_do_promote,         HELP_PROMOTE            },
        { "rename",     zfs_do_rename,          HELP_RENAME             },
+       { "bookmark",   zfs_do_bookmark,        HELP_BOOKMARK           },
        { NULL },
        { "list",       zfs_do_list,            HELP_LIST               },
        { NULL },
@@ -220,11 +225,12 @@ get_usage(zfs_help_t idx)
        case HELP_DESTROY:
                return (gettext("\tdestroy [-fnpRrv] <filesystem|volume>\n"
                    "\tdestroy [-dnpRrv] "
-                   "<filesystem|volume>@<snap>[%<snap>][,...]\n"));
+                   "<filesystem|volume>@<snap>[%<snap>][,...]\n"
+                   "\tdestroy <filesystem|volume>#<bookmark>\n"));
        case HELP_GET:
                return (gettext("\tget [-rHp] [-d max] "
-                   "[-o \"all\" | field[,...]] [-t type[,...]] "
-                   "[-s source[,...]]\n"
+                   "[-o \"all\" | field[,...]]\n"
+                   "\t    [-t type[,...]] [-s source[,...]]\n"
                    "\t    <\"all\" | property[,...]> "
                    "[filesystem|volume|snapshot] ...\n"));
        case HELP_INHERIT:
@@ -243,33 +249,38 @@ get_usage(zfs_help_t idx)
        case HELP_PROMOTE:
                return (gettext("\tpromote <clone-filesystem>\n"));
        case HELP_RECEIVE:
-               return (gettext("\treceive [-vnFu] <filesystem|volume|"
-               "snapshot>\n"
-               "\treceive [-vnFu] [-d | -e] <filesystem>\n"));
+               return (gettext("\treceive [-vnsFu] <filesystem|volume|"
+                   "snapshot>\n"
+                   "\treceive [-vnsFu] [-o origin=<snapshot>] [-d | -e] "
+                   "<filesystem>\n"
+                   "\treceive -A <filesystem|volume>\n"));
        case HELP_RENAME:
                return (gettext("\trename [-f] <filesystem|volume|snapshot> "
                    "<filesystem|volume|snapshot>\n"
                    "\trename [-f] -p <filesystem|volume> <filesystem|volume>\n"
-                   "\trename -r <snapshot> <snapshot>"));
+                   "\trename -r <snapshot> <snapshot>\n"));
        case HELP_ROLLBACK:
                return (gettext("\trollback [-rRf] <snapshot>\n"));
        case HELP_SEND:
-               return (gettext("\tsend [-DnPpRrv] [-[iI] snapshot] "
-                   "<snapshot>\n"));
+               return (gettext("\tsend [-DnPpRvLec] [-[iI] snapshot] "
+                   "<snapshot>\n"
+                   "\tsend [-Le] [-i snapshot|bookmark] "
+                   "<filesystem|volume|snapshot>\n"
+                   "\tsend [-nvPe] -t <receive_resume_token>\n"));
        case HELP_SET:
-               return (gettext("\tset <property=value> "
+               return (gettext("\tset <property=value> ... "
                    "<filesystem|volume|snapshot> ...\n"));
        case HELP_SHARE:
-               return (gettext("\tshare <-a | filesystem>\n"));
+               return (gettext("\tshare <-a [nfs|smb] | filesystem>\n"));
        case HELP_SNAPSHOT:
                return (gettext("\tsnapshot|snap [-r] [-o property=value] ... "
-                   "<filesystem@snapname|volume@snapname> ...\n"));
+                   "<filesystem|volume>@<snap> ...\n"));
        case HELP_UNMOUNT:
                return (gettext("\tunmount [-f] "
                    "<-a | filesystem|mountpoint>\n"));
        case HELP_UNSHARE:
                return (gettext("\tunshare "
-                   "<-a | filesystem|mountpoint>\n"));
+                   "<-a [nfs|smb] | filesystem|mountpoint>\n"));
        case HELP_ALLOW:
                return (gettext("\tallow <filesystem|volume>\n"
                    "\tallow [-ldug] "
@@ -292,11 +303,13 @@ get_usage(zfs_help_t idx)
                    "<filesystem|volume>\n"));
        case HELP_USERSPACE:
                return (gettext("\tuserspace [-Hinp] [-o field[,...]] "
-                   "[-s field]...\n\t    [-S field]... [-t type[,...]] "
+                   "[-s field] ...\n"
+                   "\t    [-S field] ... [-t type[,...]] "
                    "<filesystem|snapshot>\n"));
        case HELP_GROUPSPACE:
                return (gettext("\tgroupspace [-Hinp] [-o field[,...]] "
-                   "[-s field]...\n\t    [-S field]... [-t type[,...]] "
+                   "[-s field] ...\n"
+                   "\t    [-S field] ... [-t type[,...]] "
                    "<filesystem|snapshot>\n"));
        case HELP_HOLD:
                return (gettext("\thold [-r] <tag> <snapshot> ...\n"));
@@ -307,6 +320,8 @@ get_usage(zfs_help_t idx)
        case HELP_DIFF:
                return (gettext("\tdiff [-FHt] <snapshot> "
                    "[snapshot|filesystem]\n"));
+       case HELP_BOOKMARK:
+               return (gettext("\tbookmark <snapshot> <bookmark>\n"));
        }
 
        abort();
@@ -468,15 +483,18 @@ usage(boolean_t requested)
        exit(requested ? 0 : 2);
 }
 
+/*
+ * Take a property=value argument string and add it to the given nvlist.
+ * Modifies the argument inplace.
+ */
 static int
-parseprop(nvlist_t *props)
+parseprop(nvlist_t *props, char *propname)
 {
-       char *propname = optarg;
        char *propval, *strval;
 
        if ((propval = strchr(propname, '=')) == NULL) {
                (void) fprintf(stderr, gettext("missing "
-                   "'=' for -o option\n"));
+                   "'=' for property=value argument\n"));
                return (-1);
        }
        *propval = '\0';
@@ -566,6 +584,56 @@ finish_progress(char *done)
        pt_header = NULL;
 }
 
+static int
+zfs_mount_and_share(libzfs_handle_t *hdl, const char *dataset, zfs_type_t type)
+{
+       zfs_handle_t *zhp = NULL;
+       int ret = 0;
+
+       zhp = zfs_open(hdl, dataset, type);
+       if (zhp == NULL)
+               return (1);
+
+       /*
+        * Volumes may neither be mounted or shared.  Potentially in the
+        * future filesystems detected on these volumes could be mounted.
+        */
+       if (zfs_get_type(zhp) == ZFS_TYPE_VOLUME) {
+               zfs_close(zhp);
+               return (0);
+       }
+
+       /*
+        * Mount and/or share the new filesystem as appropriate.  We provide a
+        * verbose error message to let the user know that their filesystem was
+        * in fact created, even if we failed to mount or share it.
+        *
+        * If the user doesn't want the dataset automatically mounted, then
+        * skip the mount/share step
+        */
+       if (zfs_prop_valid_for_type(ZFS_PROP_CANMOUNT, type, B_FALSE) &&
+           zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_ON) {
+               if (geteuid() != 0) {
+                       (void) fprintf(stderr, gettext("filesystem "
+                           "successfully created, but it may only be "
+                           "mounted by root\n"));
+                       ret = 1;
+               } else if (zfs_mount(zhp, NULL, 0) != 0) {
+                       (void) fprintf(stderr, gettext("filesystem "
+                           "successfully created, but not mounted\n"));
+                       ret = 1;
+               } else if (zfs_share(zhp) != 0) {
+                       (void) fprintf(stderr, gettext("filesystem "
+                           "successfully created, but not shared\n"));
+                       ret = 1;
+               }
+       }
+
+       zfs_close(zhp);
+
+       return (ret);
+}
+
 /*
  * zfs clone [-p] [-o prop=value] ... <snap> <fs | vol>
  *
@@ -592,8 +660,10 @@ zfs_do_clone(int argc, char **argv)
        while ((c = getopt(argc, argv, "o:p")) != -1) {
                switch (c) {
                case 'o':
-                       if (parseprop(props))
+                       if (parseprop(props, optarg) != 0) {
+                               nvlist_free(props);
                                return (1);
+                       }
                        break;
                case 'p':
                        parents = B_TRUE;
@@ -625,8 +695,10 @@ zfs_do_clone(int argc, char **argv)
        }
 
        /* open the source dataset */
-       if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_SNAPSHOT)) == NULL)
+       if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_SNAPSHOT)) == NULL) {
+               nvlist_free(props);
                return (1);
+       }
 
        if (parents && zfs_name_valid(argv[1], ZFS_TYPE_FILESYSTEM |
            ZFS_TYPE_VOLUME)) {
@@ -636,10 +708,16 @@ zfs_do_clone(int argc, char **argv)
                 * complain.
                 */
                if (zfs_dataset_exists(g_zfs, argv[1], ZFS_TYPE_FILESYSTEM |
-                   ZFS_TYPE_VOLUME))
+                   ZFS_TYPE_VOLUME)) {
+                       zfs_close(zhp);
+                       nvlist_free(props);
                        return (0);
-               if (zfs_create_ancestors(g_zfs, argv[1]) != 0)
+               }
+               if (zfs_create_ancestors(g_zfs, argv[1]) != 0) {
+                       zfs_close(zhp);
+                       nvlist_free(props);
                        return (1);
+               }
        }
 
        /* pass to libzfs */
@@ -647,31 +725,12 @@ zfs_do_clone(int argc, char **argv)
 
        /* create the mountpoint if necessary */
        if (ret == 0) {
-               zfs_handle_t *clone;
-               int canmount = ZFS_CANMOUNT_OFF;
-
                if (log_history) {
                        (void) zpool_log_history(g_zfs, history_str);
                        log_history = B_FALSE;
                }
 
-               clone = zfs_open(g_zfs, argv[1], ZFS_TYPE_DATASET);
-               if (clone != NULL) {
-                       /*
-                        * if the user doesn't want the dataset automatically
-                        * mounted, then skip the mount/share step.
-                        */
-                       if (zfs_prop_valid_for_type(ZFS_PROP_CANMOUNT,
-                           zfs_get_type(clone), B_FALSE))
-                               canmount = zfs_prop_get_int(clone,
-                                   ZFS_PROP_CANMOUNT);
-
-                       if (zfs_get_type(clone) != ZFS_TYPE_VOLUME &&
-                           canmount == ZFS_CANMOUNT_ON)
-                               if ((ret = zfs_mount(clone, NULL, 0)) == 0)
-                                       ret = zfs_share(clone);
-                       zfs_close(clone);
-               }
+               ret = zfs_mount_and_share(g_zfs, argv[1], ZFS_TYPE_DATASET);
        }
 
        zfs_close(zhp);
@@ -706,7 +765,6 @@ static int
 zfs_do_create(int argc, char **argv)
 {
        zfs_type_t type = ZFS_TYPE_FILESYSTEM;
-       zfs_handle_t *zhp = NULL;
        uint64_t volsize = 0;
        int c;
        boolean_t noreserve = B_FALSE;
@@ -715,7 +773,6 @@ zfs_do_create(int argc, char **argv)
        int ret = 1;
        nvlist_t *props;
        uint64_t intval;
-       int canmount = ZFS_CANMOUNT_OFF;
 
        if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0)
                nomem();
@@ -755,7 +812,7 @@ zfs_do_create(int argc, char **argv)
                                nomem();
                        break;
                case 'o':
-                       if (parseprop(props))
+                       if (parseprop(props, optarg) != 0)
                                goto error;
                        break;
                case 's':
@@ -765,7 +822,6 @@ zfs_do_create(int argc, char **argv)
                        (void) fprintf(stderr, gettext("missing size "
                            "argument\n"));
                        goto badusage;
-                       break;
                case '?':
                        (void) fprintf(stderr, gettext("invalid option '%c'\n"),
                            optopt);
@@ -795,12 +851,14 @@ zfs_do_create(int argc, char **argv)
 
        if (type == ZFS_TYPE_VOLUME && !noreserve) {
                zpool_handle_t *zpool_handle;
+               nvlist_t *real_props = NULL;
                uint64_t spa_version;
                char *p;
                zfs_prop_t resv_prop;
                char *strval;
+               char msg[1024];
 
-               if ((p = strchr(argv[0], '/')))
+               if ((p = strchr(argv[0], '/')) != NULL)
                        *p = '\0';
                zpool_handle = zpool_open(g_zfs, argv[0]);
                if (p != NULL)
@@ -809,12 +867,22 @@ zfs_do_create(int argc, char **argv)
                        goto error;
                spa_version = zpool_get_prop_int(zpool_handle,
                    ZPOOL_PROP_VERSION, NULL);
-               zpool_close(zpool_handle);
                if (spa_version >= SPA_VERSION_REFRESERVATION)
                        resv_prop = ZFS_PROP_REFRESERVATION;
                else
                        resv_prop = ZFS_PROP_RESERVATION;
-               volsize = zvol_volsize_to_reservation(volsize, props);
+
+               (void) snprintf(msg, sizeof (msg),
+                   gettext("cannot create '%s'"), argv[0]);
+               if (props && (real_props = zfs_valid_proplist(g_zfs, type,
+                   props, 0, NULL, zpool_handle, msg)) == NULL) {
+                       zpool_close(zpool_handle);
+                       goto error;
+               }
+               zpool_close(zpool_handle);
+
+               volsize = zvol_volsize_to_reservation(volsize, real_props);
+               nvlist_free(real_props);
 
                if (nvlist_lookup_string(props, zfs_prop_to_name(resv_prop),
                    &strval) != 0) {
@@ -849,37 +917,8 @@ zfs_do_create(int argc, char **argv)
                log_history = B_FALSE;
        }
 
-       if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET)) == NULL)
-               goto error;
-
-       ret = 0;
-       /*
-        * if the user doesn't want the dataset automatically mounted,
-        * then skip the mount/share step
-        */
-       if (zfs_prop_valid_for_type(ZFS_PROP_CANMOUNT, type, B_FALSE))
-               canmount = zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT);
-
-       /*
-        * Mount and/or share the new filesystem as appropriate.  We provide a
-        * verbose error message to let the user know that their filesystem was
-        * in fact created, even if we failed to mount or share it.
-        */
-       if (canmount == ZFS_CANMOUNT_ON) {
-               if (zfs_mount(zhp, NULL, 0) != 0) {
-                       (void) fprintf(stderr, gettext("filesystem "
-                           "successfully created, but not mounted\n"));
-                       ret = 1;
-               } else if (zfs_share(zhp) != 0) {
-                       (void) fprintf(stderr, gettext("filesystem "
-                           "successfully created, but not shared\n"));
-                       ret = 1;
-               }
-       }
-
+       ret = zfs_mount_and_share(g_zfs, argv[0], ZFS_TYPE_DATASET);
 error:
-       if (zhp)
-               zfs_close(zhp);
        nvlist_free(props);
        return (ret);
 badusage:
@@ -921,6 +960,7 @@ typedef struct destroy_cbdata {
        char            *cb_prevsnap;
        int64_t         cb_snapused;
        char            *cb_snapspec;
+       char            *cb_bookmark;
 } destroy_cbdata_t;
 
 /*
@@ -1190,7 +1230,7 @@ zfs_do_destroy(int argc, char **argv)
        int err = 0;
        int c;
        zfs_handle_t *zhp = NULL;
-       char *at;
+       char *at, *pound;
        zfs_type_t type = ZFS_TYPE_DATASET;
 
        /* check options */
@@ -1242,6 +1282,7 @@ zfs_do_destroy(int argc, char **argv)
        }
 
        at = strchr(argv[0], '@');
+       pound = strchr(argv[0], '#');
        if (at != NULL) {
 
                /* Build the list of snaps to destroy in cb_nvl. */
@@ -1250,8 +1291,10 @@ zfs_do_destroy(int argc, char **argv)
                *at = '\0';
                zhp = zfs_open(g_zfs, argv[0],
                    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME);
-               if (zhp == NULL)
+               if (zhp == NULL) {
+                       nvlist_free(cb.cb_nvl);
                        return (1);
+               }
 
                cb.cb_snapspec = at + 1;
                if (gather_snapshots(zfs_handle_dup(zhp), &cb) != 0 ||
@@ -1303,6 +1346,46 @@ zfs_do_destroy(int argc, char **argv)
 
                if (err != 0)
                        rv = 1;
+       } else if (pound != NULL) {
+               int err;
+               nvlist_t *nvl;
+
+               if (cb.cb_dryrun) {
+                       (void) fprintf(stderr,
+                           "dryrun is not supported with bookmark\n");
+                       return (-1);
+               }
+
+               if (cb.cb_defer_destroy) {
+                       (void) fprintf(stderr,
+                           "defer destroy is not supported with bookmark\n");
+                       return (-1);
+               }
+
+               if (cb.cb_recurse) {
+                       (void) fprintf(stderr,
+                           "recursive is not supported with bookmark\n");
+                       return (-1);
+               }
+
+               if (!zfs_bookmark_exists(argv[0])) {
+                       (void) fprintf(stderr, gettext("bookmark '%s' "
+                           "does not exist.\n"), argv[0]);
+                       return (1);
+               }
+
+               nvl = fnvlist_alloc();
+               fnvlist_add_boolean(nvl, argv[0]);
+
+               err = lzc_destroy_bookmarks(nvl, NULL);
+               if (err != 0) {
+                       (void) zfs_standard_error(g_zfs, err,
+                           "cannot destroy bookmark");
+               }
+
+               nvlist_free(nvl);
+
+               return (err);
        } else {
                /* Open the given dataset */
                if ((zhp = zfs_open(g_zfs, argv[0], type)) == NULL)
@@ -1413,7 +1496,7 @@ get_callback(zfs_handle_t *zhp, void *data)
        char buf[ZFS_MAXPROPLEN];
        char rbuf[ZFS_MAXPROPLEN];
        zprop_source_t sourcetype;
-       char source[ZFS_MAXNAMELEN];
+       char source[ZFS_MAX_DATASET_NAME_LEN];
        zprop_get_cbdata_t *cbp = data;
        nvlist_t *user_props = zfs_get_user_props(zhp);
        zprop_list_t *pl = cbp->cb_proplist;
@@ -1665,7 +1748,8 @@ zfs_do_get(int argc, char **argv)
                        flags &= ~ZFS_ITER_PROP_LISTSNAPS;
                        while (*optarg != '\0') {
                                static char *type_subopts[] = { "filesystem",
-                                   "volume", "snapshot", "all", NULL };
+                                   "volume", "snapshot", "bookmark",
+                                   "all", NULL };
 
                                switch (getsubopt(&optarg, type_subopts,
                                    &value)) {
@@ -1679,7 +1763,11 @@ zfs_do_get(int argc, char **argv)
                                        types |= ZFS_TYPE_SNAPSHOT;
                                        break;
                                case 3:
-                                       types = ZFS_TYPE_DATASET;
+                                       types |= ZFS_TYPE_BOOKMARK;
+                                       break;
+                               case 4:
+                                       types = ZFS_TYPE_DATASET |
+                                           ZFS_TYPE_BOOKMARK;
                                        break;
 
                                default:
@@ -1846,9 +1934,13 @@ zfs_do_inherit(int argc, char **argv)
                        if (prop == ZFS_PROP_QUOTA ||
                            prop == ZFS_PROP_RESERVATION ||
                            prop == ZFS_PROP_REFQUOTA ||
-                           prop == ZFS_PROP_REFRESERVATION)
+                           prop == ZFS_PROP_REFRESERVATION) {
                                (void) fprintf(stderr, gettext("use 'zfs set "
                                    "%s=none' to clear\n"), propname);
+                               (void) fprintf(stderr, gettext("use 'zfs "
+                                   "inherit -S %s' to revert to received "
+                                   "value\n"), propname);
+                       }
                        return (1);
                }
                if (received && (prop == ZFS_PROP_VOLSIZE ||
@@ -1884,7 +1976,7 @@ typedef struct upgrade_cbdata {
        uint64_t cb_version;
        boolean_t cb_newer;
        boolean_t cb_foundone;
-       char cb_lastfs[ZFS_MAXNAMELEN];
+       char cb_lastfs[ZFS_MAX_DATASET_NAME_LEN];
 } upgrade_cbdata_t;
 
 static int
@@ -2083,7 +2175,7 @@ zfs_do_upgrade(int argc, char **argv)
                if (cb.cb_numfailed != 0)
                        ret = 1;
        } else {
-               /* List old-version filesytems */
+               /* List old-version filesystems */
                boolean_t found;
                (void) printf(gettext("This system is currently running "
                    "ZFS filesystem version %llu.\n\n"), ZPL_VERSION);
@@ -2132,10 +2224,14 @@ enum us_field_types {
        USFIELD_TYPE,
        USFIELD_NAME,
        USFIELD_USED,
-       USFIELD_QUOTA
+       USFIELD_QUOTA,
+       USFIELD_OBJUSED,
+       USFIELD_OBJQUOTA
 };
-static char *us_field_hdr[] = { "TYPE", "NAME", "USED", "QUOTA" };
-static char *us_field_names[] = { "type", "name", "used", "quota" };
+static char *us_field_hdr[] = { "TYPE", "NAME", "USED", "QUOTA",
+                                   "OBJUSED", "OBJQUOTA" };
+static char *us_field_names[] = { "type", "name", "used", "quota",
+                                   "objused", "objquota" };
 #define        USFIELD_LAST    (sizeof (us_field_names) / sizeof (char *))
 
 #define        USTYPE_PSX_GRP  (1 << 0)
@@ -2228,6 +2324,7 @@ us_compare(const void *larg, const void *rarg, void *unused)
                case ZFS_PROP_NAME:
                        propname = "name";
                        if (numname) {
+compare_nums:
                                (void) nvlist_lookup_uint64(lnvl, propname,
                                    &lv64);
                                (void) nvlist_lookup_uint64(rnvl, propname,
@@ -2235,10 +2332,12 @@ us_compare(const void *larg, const void *rarg, void *unused)
                                if (rv64 != lv64)
                                        rc = (rv64 < lv64) ? 1 : -1;
                        } else {
-                               (void) nvlist_lookup_string(lnvl, propname,
-                                   &lvstr);
-                               (void) nvlist_lookup_string(rnvl, propname,
-                                   &rvstr);
+                               if ((nvlist_lookup_string(lnvl, propname,
+                                   &lvstr) == ENOENT) ||
+                                   (nvlist_lookup_string(rnvl, propname,
+                                   &rvstr) == ENOENT)) {
+                                       goto compare_nums;
+                               }
                                rc = strcmp(lvstr, rvstr);
                        }
                        break;
@@ -2255,6 +2354,7 @@ us_compare(const void *larg, const void *rarg, void *unused)
                        if (rv64 != lv64)
                                rc = (rv64 < lv64) ? 1 : -1;
                        break;
+
                default:
                        break;
                }
@@ -2280,6 +2380,20 @@ us_compare(const void *larg, const void *rarg, void *unused)
        return (0);
 }
 
+static boolean_t
+zfs_prop_is_user(unsigned p)
+{
+       return (p == ZFS_PROP_USERUSED || p == ZFS_PROP_USERQUOTA ||
+           p == ZFS_PROP_USEROBJUSED || p == ZFS_PROP_USEROBJQUOTA);
+}
+
+static boolean_t
+zfs_prop_is_group(unsigned p)
+{
+       return (p == ZFS_PROP_GROUPUSED || p == ZFS_PROP_GROUPQUOTA ||
+           p == ZFS_PROP_GROUPOBJUSED || p == ZFS_PROP_GROUPOBJQUOTA);
+}
+
 static inline const char *
 us_type2str(unsigned field_type)
 {
@@ -2330,7 +2444,7 @@ userspace_cb(void *arg, const char *domain, uid_t rid, uint64_t space)
        if (domain != NULL && domain[0] != '\0') {
 #ifdef HAVE_IDMAP
                /* SMB */
-               char sid[ZFS_MAXNAMELEN + 32];
+               char sid[MAXNAMELEN + 32];
                uid_t id;
                uint64_t classes;
                int err;
@@ -2369,7 +2483,7 @@ userspace_cb(void *arg, const char *domain, uid_t rid, uint64_t space)
 
        if (cb->cb_sid2posix || domain == NULL || domain[0] == '\0') {
                /* POSIX or -i */
-               if (prop == ZFS_PROP_GROUPUSED || prop == ZFS_PROP_GROUPQUOTA) {
+               if (zfs_prop_is_group(prop)) {
                        type = USTYPE_PSX_GRP;
                        if (!cb->cb_numname) {
                                struct group *g;
@@ -2417,7 +2531,7 @@ userspace_cb(void *arg, const char *domain, uid_t rid, uint64_t space)
                namelen = strlen(name);
        }
        nameidx = us_field_index("name");
-       if (namelen > cb->cb_width[nameidx])
+       if (nameidx >= 0 && namelen > cb->cb_width[nameidx])
                cb->cb_width[nameidx] = namelen;
 
        /*
@@ -2444,13 +2558,25 @@ userspace_cb(void *arg, const char *domain, uid_t rid, uint64_t space)
                propname = "used";
                if (!nvlist_exists(props, "quota"))
                        (void) nvlist_add_uint64(props, "quota", 0);
-       } else {
+       } else if (prop == ZFS_PROP_USERQUOTA || prop == ZFS_PROP_GROUPQUOTA) {
                propname = "quota";
                if (!nvlist_exists(props, "used"))
                        (void) nvlist_add_uint64(props, "used", 0);
+       } else if (prop == ZFS_PROP_USEROBJUSED ||
+           prop == ZFS_PROP_GROUPOBJUSED) {
+               propname = "objused";
+               if (!nvlist_exists(props, "objquota"))
+                       (void) nvlist_add_uint64(props, "objquota", 0);
+       } else if (prop == ZFS_PROP_USEROBJQUOTA ||
+           prop == ZFS_PROP_GROUPOBJQUOTA) {
+               propname = "objquota";
+               if (!nvlist_exists(props, "objused"))
+                       (void) nvlist_add_uint64(props, "objused", 0);
+       } else {
+               return (-1);
        }
        sizeidx = us_field_index(propname);
-       if (sizelen > cb->cb_width[sizeidx])
+       if (sizeidx >= 0 && sizelen > cb->cb_width[sizeidx])
                cb->cb_width[sizeidx] = sizelen;
 
        if (nvlist_add_uint64(props, propname, space) != 0)
@@ -2464,7 +2590,7 @@ print_us_node(boolean_t scripted, boolean_t parsable, int *fields, int types,
     size_t *width, us_node_t *node)
 {
        nvlist_t *nvl = node->usn_nvl;
-       char valstr[ZFS_MAXNAMELEN];
+       char valstr[MAXNAMELEN];
        boolean_t first = B_TRUE;
        int cfield = 0;
        int field;
@@ -2480,7 +2606,7 @@ print_us_node(boolean_t scripted, boolean_t parsable, int *fields, int types,
                data_type_t type;
                uint32_t val32;
                uint64_t val64;
-               char *strval = NULL;
+               char *strval = "-";
 
                while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
                        if (strcmp(nvpair_name(nvp),
@@ -2488,7 +2614,7 @@ print_us_node(boolean_t scripted, boolean_t parsable, int *fields, int types,
                                break;
                }
 
-               type = nvpair_type(nvp);
+               type = nvp == NULL ? DATA_TYPE_UNKNOWN : nvpair_type(nvp);
                switch (type) {
                case DATA_TYPE_UINT32:
                        (void) nvpair_value_uint32(nvp, &val32);
@@ -2499,32 +2625,38 @@ print_us_node(boolean_t scripted, boolean_t parsable, int *fields, int types,
                case DATA_TYPE_STRING:
                        (void) nvpair_value_string(nvp, &strval);
                        break;
+               case DATA_TYPE_UNKNOWN:
+                       break;
                default:
                        (void) fprintf(stderr, "invalid data type\n");
                }
 
                switch (field) {
                case USFIELD_TYPE:
-                       strval = (char *)us_type2str(val32);
+                       if (type == DATA_TYPE_UINT32)
+                               strval = (char *)us_type2str(val32);
                        break;
                case USFIELD_NAME:
                        if (type == DATA_TYPE_UINT64) {
                                (void) sprintf(valstr, "%llu",
-                                   (u_longlong_t) val64);
+                                   (u_longlong_t)val64);
                                strval = valstr;
                        }
                        break;
                case USFIELD_USED:
                case USFIELD_QUOTA:
+               case USFIELD_OBJUSED:
+               case USFIELD_OBJQUOTA:
                        if (type == DATA_TYPE_UINT64) {
                                if (parsable) {
                                        (void) sprintf(valstr, "%llu",
-                                           (u_longlong_t) val64);
+                                           (u_longlong_t)val64);
                                } else {
                                        zfs_nicenum(val64, valstr,
                                            sizeof (valstr));
                                }
-                               if (field == USFIELD_QUOTA &&
+                               if ((field == USFIELD_QUOTA ||
+                                   field == USFIELD_OBJQUOTA) &&
                                    strcmp(valstr, "0") == 0)
                                        strval = "none";
                                else
@@ -2542,9 +2674,9 @@ print_us_node(boolean_t scripted, boolean_t parsable, int *fields, int types,
                if (scripted)
                        (void) printf("%s", strval);
                else if (field == USFIELD_TYPE || field == USFIELD_NAME)
-                       (void) printf("%-*s", (int) width[field], strval);
+                       (void) printf("%-*s", (int)width[field], strval);
                else
-                       (void) printf("%*s", (int) width[field], strval);
+                       (void) printf("%*s", (int)width[field], strval);
 
                first = B_FALSE;
                cfield++;
@@ -2569,10 +2701,10 @@ print_us(boolean_t scripted, boolean_t parsable, int *fields, int types,
                        col = gettext(us_field_hdr[field]);
                        if (field == USFIELD_TYPE || field == USFIELD_NAME) {
                                (void) printf(first ? "%-*s" : "  %-*s",
-                                   (int) width[field], col);
+                                   (int)width[field], col);
                        } else {
                                (void) printf(first ? "%*s" : "  %*s",
-                                   (int) width[field], col);
+                                   (int)width[field], col);
                        }
                        first = B_FALSE;
                        cfield++;
@@ -2596,7 +2728,7 @@ zfs_do_userspace(int argc, char **argv)
        uu_avl_t *avl_tree;
        uu_avl_walk_t *walk;
        char *delim;
-       char deffields[] = "type,name,used,quota";
+       char deffields[] = "type,name,used,quota,objused,objquota";
        char *ofield = NULL;
        char *tfield = NULL;
        int cfield = 0;
@@ -2745,11 +2877,12 @@ zfs_do_userspace(int argc, char **argv)
                cb.cb_width[i] = strlen(gettext(us_field_hdr[i]));
 
        for (p = 0; p < ZFS_NUM_USERQUOTA_PROPS; p++) {
-               if (((p == ZFS_PROP_USERUSED || p == ZFS_PROP_USERQUOTA) &&
+               if ((zfs_prop_is_user(p) &&
                    !(types & (USTYPE_PSX_USR | USTYPE_SMB_USR))) ||
-                   ((p == ZFS_PROP_GROUPUSED || p == ZFS_PROP_GROUPQUOTA) &&
+                   (zfs_prop_is_group(p) &&
                    !(types & (USTYPE_PSX_GRP | USTYPE_SMB_GRP))))
                        continue;
+
                cb.cb_prop = p;
                if ((ret = zfs_userspace(zhp, p, userspace_cb, &cb)) != 0)
                        return (ret);
@@ -3027,7 +3160,8 @@ zfs_do_list(int argc, char **argv)
                        flags &= ~ZFS_ITER_PROP_LISTSNAPS;
                        while (*optarg != '\0') {
                                static char *type_subopts[] = { "filesystem",
-                                   "volume", "snapshot", "snap", "all", NULL };
+                                   "volume", "snapshot", "snap", "bookmark",
+                                   "all", NULL };
 
                                switch (getsubopt(&optarg, type_subopts,
                                    &value)) {
@@ -3042,9 +3176,12 @@ zfs_do_list(int argc, char **argv)
                                        types |= ZFS_TYPE_SNAPSHOT;
                                        break;
                                case 4:
-                                       types = ZFS_TYPE_DATASET;
+                                       types |= ZFS_TYPE_BOOKMARK;
+                                       break;
+                               case 5:
+                                       types = ZFS_TYPE_DATASET |
+                                           ZFS_TYPE_BOOKMARK;
                                        break;
-
                                default:
                                        (void) fprintf(stderr,
                                            gettext("invalid type '%s'\n"),
@@ -3241,7 +3378,7 @@ zfs_do_promote(int argc, char **argv)
  *
  *     -r      Delete any intervening snapshots before doing rollback
  *     -R      Delete any snapshots and their clones
- *     -f      ignored for backwards compatability
+ *     -f      ignored for backwards compatibility
  *
  * Given a filesystem, rollback to a specific snapshot, discarding any changes
  * since then and making it the active dataset.  If more recent snapshots exist,
@@ -3254,9 +3391,31 @@ typedef struct rollback_cbdata {
        char            *cb_target;
        int             cb_error;
        boolean_t       cb_recurse;
-       boolean_t       cb_dependent;
 } rollback_cbdata_t;
 
+static int
+rollback_check_dependent(zfs_handle_t *zhp, void *data)
+{
+       rollback_cbdata_t *cbp = data;
+
+       if (cbp->cb_first && cbp->cb_recurse) {
+               (void) fprintf(stderr, gettext("cannot rollback to "
+                   "'%s': clones of previous snapshots exist\n"),
+                   cbp->cb_target);
+               (void) fprintf(stderr, gettext("use '-R' to "
+                   "force deletion of the following clones and "
+                   "dependents:\n"));
+               cbp->cb_first = 0;
+               cbp->cb_error = 1;
+       }
+
+       (void) fprintf(stderr, "%s\n", zfs_get_name(zhp));
+
+       zfs_close(zhp);
+       return (0);
+}
+
+
 /*
  * Report any snapshots more recent than the one specified.  Used when '-r' is
  * not specified.  We reuse this same callback for the snapshot dependents - if
@@ -3273,52 +3432,30 @@ rollback_check(zfs_handle_t *zhp, void *data)
                return (0);
        }
 
-       if (!cbp->cb_dependent) {
-               if (strcmp(zfs_get_name(zhp), cbp->cb_target) != 0 &&
-                   zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT &&
-                   zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) >
-                   cbp->cb_create) {
-
-                       if (cbp->cb_first && !cbp->cb_recurse) {
-                               (void) fprintf(stderr, gettext("cannot "
-                                   "rollback to '%s': more recent snapshots "
-                                   "exist\n"),
-                                   cbp->cb_target);
-                               (void) fprintf(stderr, gettext("use '-r' to "
-                                   "force deletion of the following "
-                                   "snapshots:\n"));
-                               cbp->cb_first = 0;
-                               cbp->cb_error = 1;
-                       }
-
-                       if (cbp->cb_recurse) {
-                               cbp->cb_dependent = B_TRUE;
-                               if (zfs_iter_dependents(zhp, B_TRUE,
-                                   rollback_check, cbp) != 0) {
-                                       zfs_close(zhp);
-                                       return (-1);
-                               }
-                               cbp->cb_dependent = B_FALSE;
-                       } else {
-                               (void) fprintf(stderr, "%s\n",
-                                   zfs_get_name(zhp));
-                       }
-               }
-       } else {
-               if (cbp->cb_first && cbp->cb_recurse) {
-                       (void) fprintf(stderr, gettext("cannot rollback to "
-                           "'%s': clones of previous snapshots exist\n"),
+       if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > cbp->cb_create) {
+               if (cbp->cb_first && !cbp->cb_recurse) {
+                       (void) fprintf(stderr, gettext("cannot "
+                           "rollback to '%s': more recent snapshots "
+                           "or bookmarks exist\n"),
                            cbp->cb_target);
-                       (void) fprintf(stderr, gettext("use '-R' to "
-                           "force deletion of the following clones and "
-                           "dependents:\n"));
+                       (void) fprintf(stderr, gettext("use '-r' to "
+                           "force deletion of the following "
+                           "snapshots and bookmarks:\n"));
                        cbp->cb_first = 0;
                        cbp->cb_error = 1;
                }
 
-               (void) fprintf(stderr, "%s\n", zfs_get_name(zhp));
+               if (cbp->cb_recurse) {
+                       if (zfs_iter_dependents(zhp, B_TRUE,
+                           rollback_check_dependent, cbp) != 0) {
+                               zfs_close(zhp);
+                               return (-1);
+                       }
+               } else {
+                       (void) fprintf(stderr, "%s\n",
+                           zfs_get_name(zhp));
+               }
        }
-
        zfs_close(zhp);
        return (0);
 }
@@ -3331,7 +3468,7 @@ zfs_do_rollback(int argc, char **argv)
        boolean_t force = B_FALSE;
        rollback_cbdata_t cb = { 0 };
        zfs_handle_t *zhp, *snap;
-       char parentname[ZFS_MAXNAMELEN];
+       char parentname[ZFS_MAX_DATASET_NAME_LEN];
        char *delim;
 
        /* check options */
@@ -3388,7 +3525,9 @@ zfs_do_rollback(int argc, char **argv)
        cb.cb_create = zfs_prop_get_int(snap, ZFS_PROP_CREATETXG);
        cb.cb_first = B_TRUE;
        cb.cb_error = 0;
-       if ((ret = zfs_iter_children(zhp, rollback_check, &cb)) != 0)
+       if ((ret = zfs_iter_snapshots(zhp, B_FALSE, rollback_check, &cb)) != 0)
+               goto out;
+       if ((ret = zfs_iter_bookmarks(zhp, rollback_check, &cb)) != 0)
                goto out;
 
        if ((ret = cb.cb_error) != 0)
@@ -3410,21 +3549,17 @@ out:
 }
 
 /*
- * zfs set property=value { fs | snap | vol } ...
+ * zfs set property=value ... { fs | snap | vol } ...
  *
- * Sets the given property for all datasets specified on the command line.
+ * Sets the given properties for all datasets specified on the command line.
  */
-typedef struct set_cbdata {
-       char            *cb_propname;
-       char            *cb_value;
-} set_cbdata_t;
 
 static int
 set_callback(zfs_handle_t *zhp, void *data)
 {
-       set_cbdata_t *cbp = data;
+       nvlist_t *props = data;
 
-       if (zfs_prop_set(zhp, cbp->cb_propname, cbp->cb_value) != 0) {
+       if (zfs_prop_set_list(zhp, props) != 0) {
                switch (libzfs_errno(g_zfs)) {
                case EZFS_MOUNTFAILED:
                        (void) fprintf(stderr, gettext("property may be set "
@@ -3443,8 +3578,10 @@ set_callback(zfs_handle_t *zhp, void *data)
 static int
 zfs_do_set(int argc, char **argv)
 {
-       set_cbdata_t cb;
+       nvlist_t *props = NULL;
+       int ds_start = -1; /* argv idx of first dataset arg */
        int ret = 0;
+       int i;
 
        /* check for options */
        if (argc > 1 && argv[1][0] == '-') {
@@ -3455,36 +3592,51 @@ zfs_do_set(int argc, char **argv)
 
        /* check number of arguments */
        if (argc < 2) {
-               (void) fprintf(stderr, gettext("missing property=value "
-                   "argument\n"));
+               (void) fprintf(stderr, gettext("missing arguments\n"));
                usage(B_FALSE);
        }
        if (argc < 3) {
-               (void) fprintf(stderr, gettext("missing dataset name\n"));
+               if (strchr(argv[1], '=') == NULL) {
+                       (void) fprintf(stderr, gettext("missing property=value "
+                           "argument(s)\n"));
+               } else {
+                       (void) fprintf(stderr, gettext("missing dataset "
+                           "name(s)\n"));
+               }
                usage(B_FALSE);
        }
 
-       /* validate property=value argument */
-       cb.cb_propname = argv[1];
-       if (((cb.cb_value = strchr(cb.cb_propname, '=')) == NULL) ||
-           (cb.cb_value[1] == '\0')) {
-               (void) fprintf(stderr, gettext("missing value in "
-                   "property=value argument\n"));
+       /* validate argument order:  prop=val args followed by dataset args */
+       for (i = 1; i < argc; i++) {
+               if (strchr(argv[i], '=') != NULL) {
+                       if (ds_start > 0) {
+                               /* out-of-order prop=val argument */
+                               (void) fprintf(stderr, gettext("invalid "
+                                   "argument order\n"));
+                               usage(B_FALSE);
+                       }
+               } else if (ds_start < 0) {
+                       ds_start = i;
+               }
+       }
+       if (ds_start < 0) {
+               (void) fprintf(stderr, gettext("missing dataset name(s)\n"));
                usage(B_FALSE);
        }
 
-       *cb.cb_value = '\0';
-       cb.cb_value++;
-
-       if (*cb.cb_propname == '\0') {
-               (void) fprintf(stderr,
-                   gettext("missing property in property=value argument\n"));
-               usage(B_FALSE);
+       /* Populate a list of property settings */
+       if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0)
+               nomem();
+       for (i = 1; i < ds_start; i++) {
+               if ((ret = parseprop(props, argv[i])) != 0)
+                       goto error;
        }
 
-       ret = zfs_for_each(argc - 2, argv + 2, 0,
-           ZFS_TYPE_DATASET, NULL, NULL, 0, set_callback, &cb);
+       ret = zfs_for_each(argc - ds_start, argv + ds_start, 0,
+           ZFS_TYPE_DATASET, NULL, NULL, 0, set_callback, props);
 
+error:
+       nvlist_free(props);
        return (ret);
 }
 
@@ -3544,8 +3696,11 @@ zfs_do_snapshot(int argc, char **argv)
        while ((c = getopt(argc, argv, "ro:")) != -1) {
                switch (c) {
                case 'o':
-                       if (parseprop(props))
+                       if (parseprop(props, optarg) != 0) {
+                               nvlist_free(sd.sd_nvl);
+                               nvlist_free(props);
                                return (1);
+                       }
                        break;
                case 'r':
                        sd.sd_recursive = B_TRUE;
@@ -3608,6 +3763,7 @@ zfs_do_send(int argc, char **argv)
 {
        char *fromname = NULL;
        char *toname = NULL;
+       char *resume_token = NULL;
        char *cp;
        zfs_handle_t *zhp;
        sendflags_t flags = { 0 };
@@ -3616,7 +3772,7 @@ zfs_do_send(int argc, char **argv)
        boolean_t extraverbose = B_FALSE;
 
        /* check options */
-       while ((c = getopt(argc, argv, ":i:I:RDpvnP")) != -1) {
+       while ((c = getopt(argc, argv, ":i:I:RDpvnPLet:c")) != -1) {
                switch (c) {
                case 'i':
                        if (fromname)
@@ -3651,6 +3807,18 @@ zfs_do_send(int argc, char **argv)
                case 'n':
                        flags.dryrun = B_TRUE;
                        break;
+               case 'L':
+                       flags.largeblock = B_TRUE;
+                       break;
+               case 'e':
+                       flags.embed_data = B_TRUE;
+                       break;
+               case 't':
+                       resume_token = optarg;
+                       break;
+               case 'c':
+                       flags.compress = B_TRUE;
+                       break;
                case ':':
                        (void) fprintf(stderr, gettext("missing argument for "
                            "'%c' option\n"), optopt);
@@ -3666,14 +3834,28 @@ zfs_do_send(int argc, char **argv)
        argc -= optind;
        argv += optind;
 
-       /* check number of arguments */
-       if (argc < 1) {
-               (void) fprintf(stderr, gettext("missing snapshot argument\n"));
-               usage(B_FALSE);
-       }
-       if (argc > 1) {
-               (void) fprintf(stderr, gettext("too many arguments\n"));
-               usage(B_FALSE);
+       if (resume_token != NULL) {
+               if (fromname != NULL || flags.replicate || flags.props ||
+                   flags.dedup) {
+                       (void) fprintf(stderr,
+                           gettext("invalid flags combined with -t\n"));
+                       usage(B_FALSE);
+               }
+               if (argc != 0) {
+                       (void) fprintf(stderr, gettext("no additional "
+                           "arguments are permitted with -t\n"));
+                       usage(B_FALSE);
+               }
+       } else {
+               if (argc < 1) {
+                       (void) fprintf(stderr,
+                           gettext("missing snapshot argument\n"));
+                       usage(B_FALSE);
+               }
+               if (argc > 1) {
+                       (void) fprintf(stderr, gettext("too many arguments\n"));
+                       usage(B_FALSE);
+               }
        }
 
        if (!flags.dryrun && isatty(STDOUT_FILENO)) {
@@ -3683,12 +3865,58 @@ zfs_do_send(int argc, char **argv)
                return (1);
        }
 
-       cp = strchr(argv[0], '@');
-       if (cp == NULL) {
-               (void) fprintf(stderr,
-                   gettext("argument must be a snapshot\n"));
-               usage(B_FALSE);
+       if (resume_token != NULL) {
+               return (zfs_send_resume(g_zfs, &flags, STDOUT_FILENO,
+                   resume_token));
        }
+
+       /*
+        * Special case sending a filesystem, or from a bookmark.
+        */
+       if (strchr(argv[0], '@') == NULL ||
+           (fromname && strchr(fromname, '#') != NULL)) {
+               char frombuf[ZFS_MAX_DATASET_NAME_LEN];
+               enum lzc_send_flags lzc_flags = 0;
+
+               if (flags.replicate || flags.doall || flags.props ||
+                   flags.dedup || flags.dryrun || flags.verbose ||
+                   flags.progress) {
+                       (void) fprintf(stderr,
+                           gettext("Error: "
+                           "Unsupported flag with filesystem or bookmark.\n"));
+                       return (1);
+               }
+
+               zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET);
+               if (zhp == NULL)
+                       return (1);
+
+               if (flags.largeblock)
+                       lzc_flags |= LZC_SEND_FLAG_LARGE_BLOCK;
+               if (flags.embed_data)
+                       lzc_flags |= LZC_SEND_FLAG_EMBED_DATA;
+               if (flags.compress)
+                       lzc_flags |= LZC_SEND_FLAG_COMPRESS;
+
+               if (fromname != NULL &&
+                   (fromname[0] == '#' || fromname[0] == '@')) {
+                       /*
+                        * Incremental source name begins with # or @.
+                        * Default to same fs as target.
+                        */
+                       (void) strlcpy(frombuf, argv[0], sizeof (frombuf));
+                       cp = strchr(frombuf, '@');
+                       if (cp != NULL)
+                               *cp = '\0';
+                       (void) strlcat(frombuf, fromname, sizeof (frombuf));
+                       fromname = frombuf;
+               }
+               err = zfs_send_one(zhp, fromname, STDOUT_FILENO, lzc_flags);
+               zfs_close(zhp);
+               return (err != 0);
+       }
+
+       cp = strchr(argv[0], '@');
        *cp = '\0';
        toname = cp + 1;
        zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME);
@@ -3701,7 +3929,7 @@ zfs_do_send(int argc, char **argv)
         * case if they specify the origin.
         */
        if (fromname && (cp = strchr(fromname, '@')) != NULL) {
-               char origin[ZFS_MAXNAMELEN];
+               char origin[ZFS_MAX_DATASET_NAME_LEN];
                zprop_source_t src;
 
                (void) zfs_prop_get(zhp, ZFS_PROP_ORIGIN,
@@ -3749,19 +3977,30 @@ zfs_do_send(int argc, char **argv)
 }
 
 /*
- * zfs receive [-vnFu] [-d | -e] <fs@snap>
- *
  * Restore a backup stream from stdin.
  */
 static int
 zfs_do_receive(int argc, char **argv)
 {
-       int c, err;
+       int c, err = 0;
        recvflags_t flags = { 0 };
+       boolean_t abort_resumable = B_FALSE;
+
+       nvlist_t *props;
+       nvpair_t *nvp = NULL;
+
+       if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0)
+               nomem();
 
        /* check options */
-       while ((c = getopt(argc, argv, ":denuvF")) != -1) {
+       while ((c = getopt(argc, argv, ":o:denuvFsA")) != -1) {
                switch (c) {
+               case 'o':
+                       if (parseprop(props, optarg) != 0) {
+                               nvlist_free(props);
+                               return (1);
+                       }
+                       break;
                case 'd':
                        flags.isprefix = B_TRUE;
                        break;
@@ -3778,9 +4017,15 @@ zfs_do_receive(int argc, char **argv)
                case 'v':
                        flags.verbose = B_TRUE;
                        break;
+               case 's':
+                       flags.resumable = B_TRUE;
+                       break;
                case 'F':
                        flags.force = B_TRUE;
                        break;
+               case 'A':
+                       abort_resumable = B_TRUE;
+                       break;
                case ':':
                        (void) fprintf(stderr, gettext("missing argument for "
                            "'%c' option\n"), optopt);
@@ -3806,15 +4051,67 @@ zfs_do_receive(int argc, char **argv)
                usage(B_FALSE);
        }
 
+       while ((nvp = nvlist_next_nvpair(props, nvp))) {
+               if (strcmp(nvpair_name(nvp), "origin") != 0) {
+                       (void) fprintf(stderr, gettext("invalid option"));
+                       usage(B_FALSE);
+               }
+       }
+
+       if (abort_resumable) {
+               if (flags.isprefix || flags.istail || flags.dryrun ||
+                   flags.resumable || flags.nomount) {
+                       (void) fprintf(stderr, gettext("invalid option"));
+                       usage(B_FALSE);
+               }
+
+               char namebuf[ZFS_MAX_DATASET_NAME_LEN];
+               (void) snprintf(namebuf, sizeof (namebuf),
+                   "%s/%%recv", argv[0]);
+
+               if (zfs_dataset_exists(g_zfs, namebuf,
+                   ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME)) {
+                       zfs_handle_t *zhp = zfs_open(g_zfs,
+                           namebuf, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME);
+                       if (zhp == NULL) {
+                               nvlist_free(props);
+                               return (1);
+                       }
+                       err = zfs_destroy(zhp, B_FALSE);
+                       zfs_close(zhp);
+               } else {
+                       zfs_handle_t *zhp = zfs_open(g_zfs,
+                           argv[0], ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME);
+                       if (zhp == NULL)
+                               usage(B_FALSE);
+                       if (!zfs_prop_get_int(zhp, ZFS_PROP_INCONSISTENT) ||
+                           zfs_prop_get(zhp, ZFS_PROP_RECEIVE_RESUME_TOKEN,
+                           NULL, 0, NULL, NULL, 0, B_TRUE) == -1) {
+                               (void) fprintf(stderr,
+                                   gettext("'%s' does not have any "
+                                   "resumable receive state to abort\n"),
+                                   argv[0]);
+                               nvlist_free(props);
+                               zfs_close(zhp);
+                               return (1);
+                       }
+                       err = zfs_destroy(zhp, B_FALSE);
+                       zfs_close(zhp);
+               }
+               nvlist_free(props);
+               return (err != 0);
+       }
+
        if (isatty(STDIN_FILENO)) {
                (void) fprintf(stderr,
                    gettext("Error: Backup stream can not be read "
                    "from a terminal.\n"
                    "You must redirect standard input.\n"));
+               nvlist_free(props);
                return (1);
        }
-
-       err = zfs_receive(g_zfs, argv[0], &flags, STDIN_FILENO, NULL);
+       err = zfs_receive(g_zfs, argv[0], props, &flags, STDIN_FILENO, NULL);
+       nvlist_free(props);
 
        return (err != 0);
 }
@@ -3841,9 +4138,15 @@ zfs_do_receive(int argc, char **argv)
 #define        ZFS_DELEG_PERM_GROUPQUOTA       "groupquota"
 #define        ZFS_DELEG_PERM_USERUSED         "userused"
 #define        ZFS_DELEG_PERM_GROUPUSED        "groupused"
+#define        ZFS_DELEG_PERM_USEROBJQUOTA     "userobjquota"
+#define        ZFS_DELEG_PERM_GROUPOBJQUOTA    "groupobjquota"
+#define        ZFS_DELEG_PERM_USEROBJUSED      "userobjused"
+#define        ZFS_DELEG_PERM_GROUPOBJUSED     "groupobjused"
+
 #define        ZFS_DELEG_PERM_HOLD             "hold"
 #define        ZFS_DELEG_PERM_RELEASE          "release"
 #define        ZFS_DELEG_PERM_DIFF             "diff"
+#define        ZFS_DELEG_PERM_BOOKMARK         "bookmark"
 
 #define        ZFS_NUM_DELEG_NOTES ZFS_DELEG_NOTE_NONE
 
@@ -3863,12 +4166,17 @@ static zfs_deleg_perm_tab_t zfs_deleg_perm_tbl[] = {
        { ZFS_DELEG_PERM_SEND, ZFS_DELEG_NOTE_SEND },
        { ZFS_DELEG_PERM_SHARE, ZFS_DELEG_NOTE_SHARE },
        { ZFS_DELEG_PERM_SNAPSHOT, ZFS_DELEG_NOTE_SNAPSHOT },
+       { ZFS_DELEG_PERM_BOOKMARK, ZFS_DELEG_NOTE_BOOKMARK },
 
        { ZFS_DELEG_PERM_GROUPQUOTA, ZFS_DELEG_NOTE_GROUPQUOTA },
        { ZFS_DELEG_PERM_GROUPUSED, ZFS_DELEG_NOTE_GROUPUSED },
        { ZFS_DELEG_PERM_USERPROP, ZFS_DELEG_NOTE_USERPROP },
        { ZFS_DELEG_PERM_USERQUOTA, ZFS_DELEG_NOTE_USERQUOTA },
        { ZFS_DELEG_PERM_USERUSED, ZFS_DELEG_NOTE_USERUSED },
+       { ZFS_DELEG_PERM_USEROBJQUOTA, ZFS_DELEG_NOTE_USEROBJQUOTA },
+       { ZFS_DELEG_PERM_USEROBJUSED, ZFS_DELEG_NOTE_USEROBJUSED },
+       { ZFS_DELEG_PERM_GROUPOBJQUOTA, ZFS_DELEG_NOTE_GROUPOBJQUOTA },
+       { ZFS_DELEG_PERM_GROUPOBJUSED, ZFS_DELEG_NOTE_GROUPOBJUSED },
        { NULL, ZFS_DELEG_NOTE_NONE }
 };
 
@@ -3946,6 +4254,10 @@ deleg_perm_type(zfs_deleg_note_t note)
        case ZFS_DELEG_NOTE_USERPROP:
        case ZFS_DELEG_NOTE_USERQUOTA:
        case ZFS_DELEG_NOTE_USERUSED:
+       case ZFS_DELEG_NOTE_USEROBJQUOTA:
+       case ZFS_DELEG_NOTE_USEROBJUSED:
+       case ZFS_DELEG_NOTE_GROUPOBJQUOTA:
+       case ZFS_DELEG_NOTE_GROUPOBJUSED:
                /* other */
                return (gettext("other"));
        default:
@@ -3953,7 +4265,7 @@ deleg_perm_type(zfs_deleg_note_t note)
        }
 }
 
-static int inline
+static int
 who_type2weight(zfs_deleg_who_type_t who_type)
 {
        int res;
@@ -4173,7 +4485,7 @@ fs_perm_fini(fs_perm_t *fsperm)
        uu_avl_destroy(fsperm->fsp_uge_avl);
 }
 
-static void inline
+static void
 set_deleg_perm_node(uu_avl_t *avl, deleg_perm_node_t *node,
     zfs_deleg_who_type_t who_type, const char *name, char locality)
 {
@@ -4270,8 +4582,9 @@ parse_fs_perm(fs_perm_t *fsperm, nvlist_t *nvl)
                        avl_pool = fspset->fsps_who_perm_avl_pool;
                        avl = fsperm->fsp_uge_avl;
                        break;
+
                default:
-                       break;
+                       assert(!"unhandled zfs_deleg_who_type_t");
                }
 
                if (is_set) {
@@ -4307,6 +4620,7 @@ parse_fs_perm(fs_perm_t *fsperm, nvlist_t *nvl)
                                                if (g)
                                                        nice_name = g->gr_name;
                                                break;
+
                                        default:
                                                break;
                                        }
@@ -4323,7 +4637,7 @@ parse_fs_perm(fs_perm_t *fsperm, nvlist_t *nvl)
                                who_perm = &node->who_perm;
                        }
                }
-
+               VERIFY3P(who_perm, !=, NULL);
                (void) parse_who_perm(who_perm, nvl2, perm_locality);
        }
 
@@ -4449,6 +4763,19 @@ deleg_perm_comment(zfs_deleg_note_t note)
        case ZFS_DELEG_NOTE_USERUSED:
                str = gettext("Allows reading any userused@... property");
                break;
+       case ZFS_DELEG_NOTE_USEROBJQUOTA:
+               str = gettext("Allows accessing any userobjquota@... property");
+               break;
+       case ZFS_DELEG_NOTE_GROUPOBJQUOTA:
+               str = gettext("Allows accessing any \n\t\t\t\t"
+                   "groupobjquota@... property");
+               break;
+       case ZFS_DELEG_NOTE_GROUPOBJUSED:
+               str = gettext("Allows reading any groupobjused@... property");
+               break;
+       case ZFS_DELEG_NOTE_USEROBJUSED:
+               str = gettext("Allows reading any userobjused@... property");
+               break;
                /* other */
        default:
                str = "";
@@ -4509,9 +4836,9 @@ allow_usage(boolean_t un, boolean_t requested, const char *msg)
        (void) fprintf(fp, gettext("Usage: %s\n"), get_usage(un ? HELP_UNALLOW :
            HELP_ALLOW));
        (void) fprintf(fp, gettext("Options:\n"));
-       for (i = 0; i < (un ? unallow_size : allow_size); i++) {
-               const char *opt = opt_desc[i++];
-               const char *optdsc = opt_desc[i];
+       for (i = 0; i < (un ? unallow_size : allow_size); i += 2) {
+               const char *opt = opt_desc[i];
+               const char *optdsc = opt_desc[i + 1];
                (void) fprintf(fp, gettext("  %-10s  %s\n"), opt, optdsc);
        }
 
@@ -4630,9 +4957,9 @@ store_allow_perm(zfs_deleg_who_type_t type, boolean_t local, boolean_t descend,
 {
        int i;
        char ld[2] = { '\0', '\0' };
-       char who_buf[ZFS_MAXNAMELEN+32];
-       char base_type = ZFS_DELEG_WHO_UNKNOWN;
-       char set_type = ZFS_DELEG_WHO_UNKNOWN;
+       char who_buf[MAXNAMELEN + 32];
+       char base_type = '\0';
+       char set_type = '\0';
        nvlist_t *base_nvl = NULL;
        nvlist_t *set_nvl = NULL;
        nvlist_t *nvl;
@@ -4681,8 +5008,10 @@ store_allow_perm(zfs_deleg_who_type_t type, boolean_t local, boolean_t descend,
                        ld[0] = ZFS_DELEG_LOCAL;
                if (descend)
                        ld[1] = ZFS_DELEG_DESCENDENT;
-       default:
                break;
+
+       default:
+               assert(set_type != '\0' && base_type != '\0');
        }
 
        if (perms != NULL) {
@@ -4916,7 +5245,7 @@ print_set_creat_perms(uu_avl_t *who_avl)
        }
 }
 
-static void inline
+static void
 print_uge_deleg_perms(uu_avl_t *who_avl, boolean_t local, boolean_t descend,
     const char *title)
 {
@@ -4967,8 +5296,10 @@ print_uge_deleg_perms(uu_avl_t *who_avl, boolean_t local, boolean_t descend,
                                case ZFS_DELEG_EVERYONE:
                                        who = gettext("everyone");
                                        who_name = NULL;
-                               default:
                                        break;
+
+                               default:
+                                       assert(who != NULL);
                                }
 
                                prt_who = B_FALSE;
@@ -4994,7 +5325,7 @@ static void
 print_fs_perms(fs_perm_set_t *fspset)
 {
        fs_perm_node_t *node = NULL;
-       char buf[ZFS_MAXNAMELEN+32];
+       char buf[MAXNAMELEN + 32];
        const char *dsname = buf;
 
        for (node = uu_list_first(fspset->fsps_list); node != NULL;
@@ -5003,7 +5334,7 @@ print_fs_perms(fs_perm_set_t *fspset)
                uu_avl_t *uge_avl = node->fspn_fsperm.fsp_uge_avl;
                int left = 0;
 
-               (void) snprintf(buf, ZFS_MAXNAMELEN+32,
+               (void) snprintf(buf, sizeof (buf),
                    gettext("---- Permissions on %s "),
                    node->fspn_fsperm.fsp_name);
                (void) printf("%s", dsname);
@@ -5137,8 +5468,7 @@ zfs_do_allow_unallow_impl(int argc, char **argv, boolean_t un)
 
 cleanup0:
        nvlist_free(perm_nvl);
-       if (update_perm_nvl != NULL)
-               nvlist_free(update_perm_nvl);
+       nvlist_free(update_perm_nvl);
 cleanup1:
        fs_perm_set_fini(&fs_perm_set);
 cleanup2:
@@ -5201,7 +5531,7 @@ zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding)
 
        for (i = 0; i < argc; ++i) {
                zfs_handle_t *zhp;
-               char parent[ZFS_MAXNAMELEN];
+               char parent[ZFS_MAX_DATASET_NAME_LEN];
                const char *delim;
                char *path = argv[i];
 
@@ -5329,7 +5659,7 @@ holds_callback(zfs_handle_t *zhp, void *data)
        nvlist_t *nvl = NULL;
        nvpair_t *nvp = NULL;
        const char *zname = zfs_get_name(zhp);
-       size_t znamelen = strnlen(zname, ZFS_MAXNAMELEN);
+       size_t znamelen = strlen(zname);
 
        if (cbp->cb_recursive) {
                const char *snapname;
@@ -5350,7 +5680,7 @@ holds_callback(zfs_handle_t *zhp, void *data)
 
        while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
                const char *tag = nvpair_name(nvp);
-               size_t taglen = strnlen(tag, MAXNAMELEN);
+               size_t taglen = strlen(tag);
                if (taglen > cbp->cb_max_taglen)
                        cbp->cb_max_taglen  = taglen;
        }
@@ -5642,6 +5972,24 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol,
                return (0);
        }
 
+       /*
+        * If this filesystem is inconsistent and has a receive resume
+        * token, we can not mount it.
+        */
+       if (zfs_prop_get_int(zhp, ZFS_PROP_INCONSISTENT) &&
+           zfs_prop_get(zhp, ZFS_PROP_RECEIVE_RESUME_TOKEN,
+           NULL, 0, NULL, NULL, 0, B_TRUE) == 0) {
+               if (!explicit)
+                       return (0);
+
+               (void) fprintf(stderr, gettext("cannot %s '%s': "
+                   "Contains partially-completed state from "
+                   "\"zfs receive -r\", which can be resumed with "
+                   "\"zfs send -t\"\n"),
+                   cmdname, zfs_get_name(zhp));
+               return (1);
+       }
+
        /*
         * At this point, we have verified that the mountpoint and/or
         * shareopts are appropriate for auto management. If the
@@ -5656,10 +6004,10 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol,
                shared_smb = zfs_is_shared_smb(zhp, NULL);
 
                if ((shared_nfs && shared_smb) ||
-                   ((shared_nfs && strcmp(shareopts, "on") == 0) &&
-                   (strcmp(smbshareopts, "off") == 0)) ||
-                   ((shared_smb && strcmp(smbshareopts, "on") == 0) &&
-                   (strcmp(shareopts, "off") == 0))) {
+                   (shared_nfs && strcmp(shareopts, "on") == 0 &&
+                   strcmp(smbshareopts, "off") == 0) ||
+                   (shared_smb && strcmp(smbshareopts, "on") == 0 &&
+                   strcmp(shareopts, "off") == 0)) {
                        if (!explicit)
                                return (0);
 
@@ -5843,8 +6191,11 @@ share_mount(int op, int argc, char **argv)
                start_progress_timer();
                get_all_datasets(&dslist, &count, verbose);
 
-               if (count == 0)
+               if (count == 0) {
+                       if (options != NULL)
+                               free(options);
                        return (0);
+               }
 
                qsort(dslist, count, sizeof (void *), libzfs_dataset_cmp);
 
@@ -5869,14 +6220,18 @@ share_mount(int op, int argc, char **argv)
                }
 
                /*
-                * When mount is given no arguments, go through /etc/mtab and
-                * display any active ZFS mounts.  We hide any snapshots, since
-                * they are controlled automatically.
+                * When mount is given no arguments, go through
+                * /proc/self/mounts and display any active ZFS mounts.
+                * We hide any snapshots, since they are controlled
+                * automatically.
                 */
 
                /* Reopen MNTTAB to prevent reading stale data from open file */
-               if (freopen(MNTTAB, "r", mnttab_file) == NULL)
+               if (freopen(MNTTAB, "r", mnttab_file) == NULL) {
+                       if (options != NULL)
+                               free(options);
                        return (ENOENT);
+               }
 
                while (getmntent(mnttab_file, &entry) == 0) {
                        if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0 ||
@@ -5906,6 +6261,9 @@ share_mount(int op, int argc, char **argv)
                }
        }
 
+       if (options != NULL)
+               free(options);
+
        return (ret);
 }
 
@@ -5951,8 +6309,8 @@ unshare_unmount_compare(const void *larg, const void *rarg, void *unused)
 
 /*
  * Convenience routine used by zfs_do_umount() and manual_unmount().  Given an
- * absolute path, find the entry /etc/mtab, verify that its a ZFS filesystem,
- * and unmount it appropriately.
+ * absolute path, find the entry /proc/self/mounts, verify that its a
+ * ZFS filesystems, and unmount it appropriately.
  */
 static int
 unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual)
@@ -5965,7 +6323,7 @@ unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual)
        ino_t path_inode;
 
        /*
-        * Search for the path in /etc/mtab.  Rather than looking for the
+        * Search for the path in /proc/self/mounts. Rather than looking for the
         * specific path, which can be fooled by non-standard paths (i.e. ".."
         * or "//"), we stat() the path and search for the corresponding
         * (major,minor) device pair.
@@ -5996,8 +6354,8 @@ unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual)
                            "currently mounted\n"), cmdname, path);
                        return (1);
                }
-               (void) fprintf(stderr, gettext("warning: %s not in mtab\n"),
-                   path);
+               (void) fprintf(stderr, gettext("warning: %s not in"
+                   "/proc/self/mounts\n"), path);
                if ((ret = umount2(path, flags)) != 0)
                        (void) fprintf(stderr, gettext("%s: %s\n"), path,
                            strerror(errno));
@@ -6086,7 +6444,7 @@ unshare_unmount(int op, int argc, char **argv)
        char sharesmb[ZFS_MAXPROPLEN];
 
        /* check options */
-       while ((c = getopt(argc, argv, op == OP_SHARE ? "a" : "af")) != -1) {
+       while ((c = getopt(argc, argv, op == OP_SHARE ? ":a" : "af")) != -1) {
                switch (c) {
                case 'a':
                        do_all = 1;
@@ -6094,6 +6452,11 @@ unshare_unmount(int op, int argc, char **argv)
                case 'f':
                        flags = MS_FORCE;
                        break;
+               case ':':
+                       (void) fprintf(stderr, gettext("missing argument for "
+                           "'%c' option\n"), optopt);
+                       usage(B_FALSE);
+                       break;
                case '?':
                        (void) fprintf(stderr, gettext("invalid option '%c'\n"),
                            optopt);
@@ -6108,9 +6471,9 @@ unshare_unmount(int op, int argc, char **argv)
                /*
                 * We could make use of zfs_for_each() to walk all datasets in
                 * the system, but this would be very inefficient, especially
-                * since we would have to linearly search /etc/mtab for each
-                * one.  Instead, do one pass through /etc/mtab looking for
-                * zfs entries and call zfs_unmount() for each one.
+                * since we would have to linearly search /proc/self/mounts for
+                * each one. Instead, do one pass through /proc/self/mounts
+                * looking for zfs entries and call zfs_unmount() for each one.
                 *
                 * Things get a little tricky if the administrator has created
                 * mountpoints beneath other ZFS filesystems.  In this case, we
@@ -6125,6 +6488,19 @@ unshare_unmount(int op, int argc, char **argv)
                unshare_unmount_node_t *node;
                uu_avl_index_t idx;
                uu_avl_walk_t *walk;
+               char *protocol = NULL;
+
+               if (op == OP_SHARE && argc > 0) {
+                       if (strcmp(argv[0], "nfs") != 0 &&
+                           strcmp(argv[0], "smb") != 0) {
+                               (void) fprintf(stderr, gettext("share type "
+                                   "must be 'nfs' or 'smb'\n"));
+                               usage(B_FALSE);
+                       }
+                       protocol = argv[0];
+                       argc--;
+                       argv++;
+               }
 
                if (argc != 0) {
                        (void) fprintf(stderr, gettext("too many arguments\n"));
@@ -6217,8 +6593,8 @@ unshare_unmount(int op, int argc, char **argv)
 
                        switch (op) {
                        case OP_SHARE:
-                               if (zfs_unshareall_bypath(node->un_zhp,
-                                   node->un_mountp) != 0)
+                               if (zfs_unshareall_bytype(node->un_zhp,
+                                   node->un_mountp, protocol) != 0)
                                        ret = 1;
                                break;
 
@@ -6419,12 +6795,13 @@ zfs_do_diff(int argc, char **argv)
        if (copy == NULL)
                usage(B_FALSE);
 
-       if ((atp = strchr(copy, '@')))
+       if ((atp = strchr(copy, '@')) != NULL)
                *atp = '\0';
 
-       if ((zhp = zfs_open(g_zfs, copy, ZFS_TYPE_FILESYSTEM)) == NULL)
+       if ((zhp = zfs_open(g_zfs, copy, ZFS_TYPE_FILESYSTEM)) == NULL) {
+               free(copy);
                return (1);
-
+       }
        free(copy);
 
        /*
@@ -6440,6 +6817,111 @@ zfs_do_diff(int argc, char **argv)
        return (err != 0);
 }
 
+/*
+ * zfs bookmark <fs@snap> <fs#bmark>
+ *
+ * Creates a bookmark with the given name from the given snapshot.
+ */
+static int
+zfs_do_bookmark(int argc, char **argv)
+{
+       char snapname[ZFS_MAX_DATASET_NAME_LEN];
+       zfs_handle_t *zhp;
+       nvlist_t *nvl;
+       int ret = 0;
+       int c;
+
+       /* check options */
+       while ((c = getopt(argc, argv, "")) != -1) {
+               switch (c) {
+               case '?':
+                       (void) fprintf(stderr,
+                           gettext("invalid option '%c'\n"), optopt);
+                       goto usage;
+               }
+       }
+
+       argc -= optind;
+       argv += optind;
+
+       /* check number of arguments */
+       if (argc < 1) {
+               (void) fprintf(stderr, gettext("missing snapshot argument\n"));
+               goto usage;
+       }
+       if (argc < 2) {
+               (void) fprintf(stderr, gettext("missing bookmark argument\n"));
+               goto usage;
+       }
+
+       if (strchr(argv[1], '#') == NULL) {
+               (void) fprintf(stderr,
+                   gettext("invalid bookmark name '%s' -- "
+                   "must contain a '#'\n"), argv[1]);
+               goto usage;
+       }
+
+       if (argv[0][0] == '@') {
+               /*
+                * Snapshot name begins with @.
+                * Default to same fs as bookmark.
+                */
+               (void) strlcpy(snapname, argv[1], sizeof (snapname));
+               *strchr(snapname, '#') = '\0';
+               (void) strlcat(snapname, argv[0], sizeof (snapname));
+       } else {
+               (void) strlcpy(snapname, argv[0], sizeof (snapname));
+       }
+       zhp = zfs_open(g_zfs, snapname, ZFS_TYPE_SNAPSHOT);
+       if (zhp == NULL)
+               goto usage;
+       zfs_close(zhp);
+
+
+       nvl = fnvlist_alloc();
+       fnvlist_add_string(nvl, argv[1], snapname);
+       ret = lzc_bookmark(nvl, NULL);
+       fnvlist_free(nvl);
+
+       if (ret != 0) {
+               const char *err_msg;
+               char errbuf[1024];
+
+               (void) snprintf(errbuf, sizeof (errbuf),
+                   dgettext(TEXT_DOMAIN,
+                   "cannot create bookmark '%s'"), argv[1]);
+
+               switch (ret) {
+               case EXDEV:
+                       err_msg = "bookmark is in a different pool";
+                       break;
+               case EEXIST:
+                       err_msg = "bookmark exists";
+                       break;
+               case EINVAL:
+                       err_msg = "invalid argument";
+                       break;
+               case ENOTSUP:
+                       err_msg = "bookmark feature not enabled";
+                       break;
+               case ENOSPC:
+                       err_msg = "out of space";
+                       break;
+               default:
+                       err_msg = "unknown error";
+                       break;
+               }
+               (void) fprintf(stderr, "%s: %s\n", errbuf,
+                   dgettext(TEXT_DOMAIN, err_msg));
+       }
+
+       return (ret != 0);
+
+usage:
+       usage(B_FALSE);
+       return (-1);
+}
+
 int
 main(int argc, char **argv)
 {
@@ -6450,6 +6932,8 @@ main(int argc, char **argv)
        (void) setlocale(LC_ALL, "");
        (void) textdomain(TEXT_DOMAIN);
 
+       dprintf_setup(&argc, argv);
+
        opterr = 0;
 
        /*
@@ -6487,8 +6971,10 @@ main(int argc, char **argv)
            (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);
+       }
 
        mnttab_file = g_zfs->libzfs_mnttab;