]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/zfs_ioctl.c
cstyle: Resolve C style issues
[mirror_zfs.git] / module / zfs / zfs_ioctl.c
index b12205e68e63403ea53a3c0be4b154d0f9bfaaa0..bf212dee82eb94ddc5f9516f704b57bace63e533 100644 (file)
  * Portions Copyright 2012 Pawel Jakub Dawidek <pawel@dawidek.net>
  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
- * Copyright (c) 2012 by Delphix. All rights reserved.
  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
+ * Copyright (c) 201i3 by Delphix. All rights reserved.
  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
- * Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright (c) 2013 Steven Hartland. All rights reserved.
  */
 
 /*
@@ -291,9 +291,7 @@ zfs_is_bootfs(const char *name)
 }
 
 /*
- * zfs_earlier_version
- *
- *     Return non-zero if the spa version is less than requested version.
+ * Return non-zero if the spa version is less than requested version.
  */
 static int
 zfs_earlier_version(const char *name, int version)
@@ -311,8 +309,6 @@ zfs_earlier_version(const char *name, int version)
 }
 
 /*
- * zpl_earlier_version
- *
  * Return TRUE if the ZPL version is less than requested version.
  */
 static boolean_t
@@ -376,7 +372,7 @@ zfs_secpolicy_read(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
            zone_dataset_visible(zc->zc_name, NULL))
                return (0);
 
-       return (ENOENT);
+       return (SET_ERROR(ENOENT));
 }
 
 static int
@@ -390,7 +386,7 @@ zfs_dozonecheck_impl(const char *dataset, uint64_t zoned, cred_t *cr)
         */
        if (!INGLOBALZONE(curproc) &&
            !zone_dataset_visible(dataset, &writable))
-               return (ENOENT);
+               return (SET_ERROR(ENOENT));
 
        if (INGLOBALZONE(curproc)) {
                /*
@@ -398,17 +394,17 @@ zfs_dozonecheck_impl(const char *dataset, uint64_t zoned, cred_t *cr)
                 * global zone.
                 */
                if (secpolicy_zfs(cr) && zoned)
-                       return (EPERM);
+                       return (SET_ERROR(EPERM));
        } else {
                /*
                 * If we are in a local zone, the 'zoned' property must be set.
                 */
                if (!zoned)
-                       return (EPERM);
+                       return (SET_ERROR(EPERM));
 
                /* must be writable by this zone */
                if (!writable)
-                       return (EPERM);
+                       return (SET_ERROR(EPERM));
        }
        return (0);
 }
@@ -419,7 +415,7 @@ zfs_dozonecheck(const char *dataset, cred_t *cr)
        uint64_t zoned;
 
        if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
-               return (ENOENT);
+               return (SET_ERROR(ENOENT));
 
        return (zfs_dozonecheck_impl(dataset, zoned, cr));
 }
@@ -430,7 +426,7 @@ zfs_dozonecheck_ds(const char *dataset, dsl_dataset_t *ds, cred_t *cr)
        uint64_t zoned;
 
        if (dsl_prop_get_int_ds(ds, "zoned", &zoned))
-               return (ENOENT);
+               return (SET_ERROR(ENOENT));
 
        return (zfs_dozonecheck_impl(dataset, zoned, cr));
 }
@@ -494,14 +490,14 @@ zfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
        error = dsl_prop_get(name, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
            1, sizeof (ds_hexsl), &ds_hexsl, NULL);
        if (error != 0)
-               return (EPERM);
+               return (SET_ERROR(EPERM));
 
        if (strcasecmp(strval, ZFS_MLSLABEL_DEFAULT) == 0)
                new_default = TRUE;
 
        /* The label must be translatable */
        if (!new_default && (hexstr_to_label(strval, &new_sl) != 0))
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        /*
         * In a non-global zone, disallow attempts to set a label that
@@ -510,7 +506,7 @@ zfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
         */
        if (!INGLOBALZONE(curproc)) {
                if (new_default || !blequal(&new_sl, CR_SL(CRED())))
-                       return (EPERM);
+                       return (SET_ERROR(EPERM));
                return (0);
        }
 
@@ -521,10 +517,10 @@ zfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
         */
        if (dsl_prop_get_integer(name,
            zfs_prop_to_name(ZFS_PROP_ZONED), &zoned, NULL))
-               return (EPERM);
+               return (SET_ERROR(EPERM));
        if (!zoned) {
                if (zfs_check_global_label(name, strval) != 0)
-                       return (EPERM);
+                       return (SET_ERROR(EPERM));
        }
 
        /*
@@ -544,7 +540,7 @@ zfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
                error = dmu_objset_own(name, DMU_OST_ZFS, B_TRUE,
                    setsl_tag, &os);
                if (error != 0)
-                       return (EPERM);
+                       return (SET_ERROR(EPERM));
 
                dmu_objset_disown(os, setsl_tag);
 
@@ -554,7 +550,7 @@ zfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
                }
 
                if (hexstr_to_label(strval, &new_sl) != 0)
-                       return (EPERM);
+                       return (SET_ERROR(EPERM));
 
                if (blstrictdom(&ds_sl, &new_sl))
                        needed_priv = PRIV_FILE_DOWNGRADE_SL;
@@ -571,7 +567,7 @@ out_check:
                return (PRIV_POLICY(cr, needed_priv, B_FALSE, EPERM, NULL));
        return (0);
 #else
-       return ENOTSUP;
+       return (ENOTSUP);
 #endif /* HAVE_MLSLABEL */
 }
 
@@ -592,7 +588,7 @@ zfs_secpolicy_setprop(const char *dsname, zfs_prop_t prop, nvpair_t *propval,
                 * Disallow setting of 'zoned' from within a local zone.
                 */
                if (!INGLOBALZONE(curproc))
-                       return (EPERM);
+                       return (SET_ERROR(EPERM));
                break;
 
        case ZFS_PROP_QUOTA:
@@ -606,15 +602,15 @@ zfs_secpolicy_setprop(const char *dsname, zfs_prop_t prop, nvpair_t *propval,
                         */
                        if (dsl_prop_get_integer(dsname, "zoned", &zoned,
                            setpoint))
-                               return (EPERM);
+                               return (SET_ERROR(EPERM));
                        if (!zoned || strlen(dsname) <= strlen(setpoint))
-                               return (EPERM);
+                               return (SET_ERROR(EPERM));
                }
                break;
 
        case ZFS_PROP_MLSLABEL:
                if (!is_system_labeled())
-                       return (EPERM);
+                       return (SET_ERROR(EPERM));
 
                if (nvpair_value_string(propval, &strval) == 0) {
                        int err;
@@ -669,7 +665,7 @@ zfs_secpolicy_send(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
         */
        cp = strchr(zc->zc_name, '@');
        if (cp == NULL)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
        if (error != 0)
                return (error);
@@ -716,7 +712,7 @@ zfs_secpolicy_deleg_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
            (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
            zc->zc_name) != 0)) {
                VN_RELE(vp);
-               return (EPERM);
+               return (SET_ERROR(EPERM));
        }
 
        VN_RELE(vp);
@@ -730,7 +726,7 @@ zfs_secpolicy_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
 {
 #ifdef HAVE_SMB_SHARE
        if (!INGLOBALZONE(curproc))
-               return (EPERM);
+               return (SET_ERROR(EPERM));
 
        if (secpolicy_nfs(cr) == 0) {
                return (0);
@@ -738,7 +734,7 @@ zfs_secpolicy_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
                return (zfs_secpolicy_deleg_share(zc, innvl, cr));
        }
 #else
-       return (ENOTSUP);
+       return (SET_ERROR(ENOTSUP));
 #endif /* HAVE_SMB_SHARE */
 }
 
@@ -747,7 +743,7 @@ zfs_secpolicy_smb_acl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
 {
 #ifdef HAVE_SMB_SHARE
        if (!INGLOBALZONE(curproc))
-               return (EPERM);
+               return (SET_ERROR(EPERM));
 
        if (secpolicy_smb(cr) == 0) {
                return (0);
@@ -755,7 +751,7 @@ zfs_secpolicy_smb_acl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
                return (zfs_secpolicy_deleg_share(zc, innvl, cr));
        }
 #else
-       return (ENOTSUP);
+       return (SET_ERROR(ENOTSUP));
 #endif /* HAVE_SMB_SHARE */
 }
 
@@ -774,7 +770,7 @@ zfs_get_parent(const char *datasetname, char *parent, int parentsize)
        } else {
                cp = strrchr(parent, '/');
                if (cp == NULL)
-                       return (ENOENT);
+                       return (SET_ERROR(ENOENT));
                cp[0] = '\0';
        }
 
@@ -813,7 +809,7 @@ zfs_secpolicy_destroy_snaps(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
        int error = 0;
 
        if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
            pair = nextpair) {
                dsl_pool_t *dp;
@@ -971,14 +967,14 @@ zfs_secpolicy_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
        nvpair_t *pair;
 
        if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
            pair = nvlist_next_nvpair(snaps, pair)) {
                char *name = nvpair_name(pair);
                char *atp = strchr(name, '@');
 
                if (atp == NULL) {
-                       error = EINVAL;
+                       error = SET_ERROR(EINVAL);
                        break;
                }
                *atp = '\0';
@@ -999,7 +995,7 @@ zfs_secpolicy_log_history(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
         * to log to.
         */
        if (tsd_get(zfs_allow_log_key) == NULL)
-               return (EPERM);
+               return (SET_ERROR(EPERM));
        return (0);
 }
 
@@ -1036,7 +1032,7 @@ static int
 zfs_secpolicy_config(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
 {
        if (secpolicy_sys_config(cr, B_FALSE) != 0)
-               return (EPERM);
+               return (SET_ERROR(EPERM));
 
        return (0);
 }
@@ -1075,7 +1071,7 @@ zfs_secpolicy_inherit_prop(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
 
        if (prop == ZPROP_INVAL) {
                if (!zfs_prop_user(zc->zc_value))
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
                return (zfs_secpolicy_write_perms(zc->zc_name,
                    ZFS_DELEG_PERM_USERPROP, cr));
        } else {
@@ -1092,7 +1088,7 @@ zfs_secpolicy_userspace_one(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
                return (err);
 
        if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        if (zc->zc_value[0] == 0) {
                /*
@@ -1121,7 +1117,7 @@ zfs_secpolicy_userspace_many(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
                return (err);
 
        if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        return (zfs_secpolicy_write_perms(zc->zc_name,
            userquota_perms[zc->zc_objset_type], cr));
@@ -1145,7 +1141,7 @@ zfs_secpolicy_hold(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
 
        error = nvlist_lookup_nvlist(innvl, "holds", &holds);
        if (error != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
            pair = nvlist_next_nvpair(holds, pair)) {
@@ -1223,7 +1219,7 @@ get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp)
         * Read in and unpack the user-supplied nvlist.
         */
        if (size == 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        packed = kmem_alloc(size, KM_SLEEP | KM_NODEBUG);
 
@@ -1262,7 +1258,7 @@ nvlist_smush(nvlist_t *errors, size_t max)
                int n = 0;
 
                if (max < 1024)
-                       return (ENOMEM);
+                       return (SET_ERROR(ENOMEM));
 
                fnvlist_add_int32(errors, ZPROP_N_MORE_ERRORS, 0);
                more_errors = nvlist_prev_nvpair(errors, NULL);
@@ -1293,12 +1289,12 @@ put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
        size = fnvlist_size(nvl);
 
        if (size > zc->zc_nvlist_dst_size) {
-               error = ENOMEM;
+               error = SET_ERROR(ENOMEM);
        } else {
                packed = fnvlist_pack(nvl, &size);
                if (ddi_copyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
                    size, zc->zc_iflags) != 0)
-                       error = EFAULT;
+                       error = SET_ERROR(EFAULT);
                fnvlist_pack_free(packed, size);
        }
 
@@ -1318,7 +1314,7 @@ get_zfs_sb(const char *dsname, zfs_sb_t **zsbp)
                return (error);
        if (dmu_objset_type(os) != DMU_OST_ZFS) {
                dmu_objset_rele(os, FTAG);
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        }
 
        mutex_enter(&os->os_user_ptr_lock);
@@ -1326,7 +1322,7 @@ get_zfs_sb(const char *dsname, zfs_sb_t **zsbp)
        if (*zsbp && (*zsbp)->z_sb) {
                atomic_inc(&((*zsbp)->z_sb->s_active));
        } else {
-               error = ESRCH;
+               error = SET_ERROR(ESRCH);
        }
        mutex_exit(&os->os_user_ptr_lock);
        dmu_objset_rele(os, FTAG);
@@ -1353,10 +1349,10 @@ zfs_sb_hold(const char *name, void *tag, zfs_sb_t **zsbp, boolean_t writer)
                        /*
                         * XXX we could probably try again, since the unmounting
                         * thread should be just about to disassociate the
-                        * objset from the zfsvfs.
+                        * objset from the zsb.
                         */
                        rrw_exit(&(*zsbp)->z_teardown_lock, tag);
-                       return (EBUSY);
+                       return (SET_ERROR(EBUSY));
                }
        }
        return (error);
@@ -1401,7 +1397,7 @@ zfs_ioc_pool_create(zfs_cmd_t *zc)
                (void) nvlist_lookup_uint64(props,
                    zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
                if (!SPA_VERSION_IS_SUPPORTED(version)) {
-                       error = EINVAL;
+                       error = SET_ERROR(EINVAL);
                        goto pool_props_bad;
                }
                (void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
@@ -1470,7 +1466,7 @@ zfs_ioc_pool_import(zfs_cmd_t *zc)
 
        if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
            guid != zc->zc_guid)
-               error = EINVAL;
+               error = SET_ERROR(EINVAL);
        else
                error = spa_import(zc->zc_name, config, props, zc->zc_cookie);
 
@@ -1510,7 +1506,7 @@ zfs_ioc_pool_configs(zfs_cmd_t *zc)
        int error;
 
        if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
-               return (EEXIST);
+               return (SET_ERROR(EEXIST));
 
        error = put_nvlist(zc, configs);
 
@@ -1574,7 +1570,7 @@ zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
        nvlist_free(tryconfig);
 
        if (config == NULL)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        error = put_nvlist(zc, config);
        nvlist_free(config);
@@ -1632,7 +1628,7 @@ zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
        if (zc->zc_cookie < spa_version(spa) ||
            !SPA_VERSION_IS_SUPPORTED(zc->zc_cookie)) {
                spa_close(spa, FTAG);
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        }
 
        spa_upgrade(spa, zc->zc_cookie);
@@ -1650,14 +1646,14 @@ zfs_ioc_pool_get_history(zfs_cmd_t *zc)
        int error;
 
        if ((size = zc->zc_history_len) == 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
                return (error);
 
        if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
                spa_close(spa, FTAG);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
 
        hist_buf = vmem_alloc(size, KM_SLEEP);
@@ -1712,7 +1708,7 @@ zfs_ioc_obj_to_path(zfs_cmd_t *zc)
                return (error);
        if (dmu_objset_type(os) != DMU_OST_ZFS) {
                dmu_objset_rele(os, FTAG);
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        }
        error = zfs_obj_to_path(os, zc->zc_obj, zc->zc_value,
            sizeof (zc->zc_value));
@@ -1741,7 +1737,7 @@ zfs_ioc_obj_to_stats(zfs_cmd_t *zc)
                return (error);
        if (dmu_objset_type(os) != DMU_OST_ZFS) {
                dmu_objset_rele(os, FTAG);
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        }
        error = zfs_obj_to_stats(os, zc->zc_obj, &zc->zc_stat, zc->zc_value,
            sizeof (zc->zc_value));
@@ -1755,8 +1751,7 @@ zfs_ioc_vdev_add(zfs_cmd_t *zc)
 {
        spa_t *spa;
        int error;
-       nvlist_t *config, **l2cache, **spares;
-       uint_t nl2cache = 0, nspares = 0;
+       nvlist_t *config;
 
        error = spa_open(zc->zc_name, &spa, FTAG);
        if (error != 0)
@@ -1764,28 +1759,6 @@ zfs_ioc_vdev_add(zfs_cmd_t *zc)
 
        error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
            zc->zc_iflags, &config);
-       (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_L2CACHE,
-           &l2cache, &nl2cache);
-
-       (void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_SPARES,
-           &spares, &nspares);
-
-       /*
-        * A root pool with concatenated devices is not supported.
-        * Thus, can not add a device to a root pool.
-        *
-        * Intent log device can not be added to a rootpool because
-        * during mountroot, zil is replayed, a seperated log device
-        * can not be accessed during the mountroot time.
-        *
-        * l2cache and spare devices are ok to be added to a rootpool.
-        */
-       if (spa_bootfs(spa) != 0 && nl2cache == 0 && nspares == 0) {
-               nvlist_free(config);
-               spa_close(spa, FTAG);
-               return (EDOM);
-       }
-
        if (error == 0) {
                error = spa_vdev_add(spa, config);
                nvlist_free(config);
@@ -1849,7 +1822,7 @@ zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
                break;
 
        default:
-               error = EINVAL;
+               error = SET_ERROR(EINVAL);
        }
        zc->zc_cookie = newstate;
        spa_close(spa, FTAG);
@@ -2044,7 +2017,7 @@ zfs_ioc_objset_recvd_props(zfs_cmd_t *zc)
         * SPA_VERSION_RECVD_PROPS.
         */
        if (!dsl_prop_get_hasrecvd(zc->zc_name))
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
 
        if (zc->zc_nvlist_dst != 0 &&
            (error = dsl_prop_get_received(zc->zc_name, &nv)) == 0) {
@@ -2110,13 +2083,13 @@ zfs_ioc_objset_zplprops(zfs_cmd_t *zc)
                        err = put_nvlist(zc, nv);
                nvlist_free(nv);
        } else {
-               err = ENOENT;
+               err = SET_ERROR(ENOENT);
        }
        dmu_objset_rele(os, FTAG);
        return (err);
 }
 
-static boolean_t
+boolean_t
 dataset_name_hidden(const char *name)
 {
        /*
@@ -2157,7 +2130,7 @@ zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
 top:
        if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os))) {
                if (error == ENOENT)
-                       error = ESRCH;
+                       error = SET_ERROR(ESRCH);
                return (error);
        }
 
@@ -2171,7 +2144,7 @@ top:
                    sizeof (zc->zc_name) - (p - zc->zc_name), p,
                    NULL, &zc->zc_cookie);
                if (error == ENOENT)
-                       error = ESRCH;
+                       error = SET_ERROR(ESRCH);
        } while (error == 0 && dataset_name_hidden(zc->zc_name));
        dmu_objset_rele(os, FTAG);
 
@@ -2219,7 +2192,7 @@ zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
         */
        if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >= MAXNAMELEN) {
                dmu_objset_rele(os, FTAG);
-               return (ESRCH);
+               return (SET_ERROR(ESRCH));
        }
 
        error = dmu_snapshot_list_next(os,
@@ -2241,7 +2214,7 @@ zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
                        dsl_dataset_rele(ds, FTAG);
                }
        } else if (error == ENOENT) {
-               error = ESRCH;
+               error = SET_ERROR(ESRCH);
        }
 
        dmu_objset_rele(os, FTAG);
@@ -2270,7 +2243,7 @@ zfs_prop_set_userquota(const char *dsname, nvpair_t *pair)
                VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
                if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
                    &pair) != 0)
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
        }
 
        /*
@@ -2280,7 +2253,7 @@ zfs_prop_set_userquota(const char *dsname, nvpair_t *pair)
        if ((dash = strchr(propname, '-')) == NULL ||
            nvpair_value_uint64_array(pair, &valary, &vallen) != 0 ||
            vallen != 3)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        domain = dash + 1;
        type = valary[0];
@@ -2446,25 +2419,25 @@ retry:
                        attrs = fnvpair_value_nvlist(pair);
                        if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
                            &propval) != 0)
-                               err = EINVAL;
+                               err = SET_ERROR(EINVAL);
                }
 
                /* Validate value type */
                if (err == 0 && prop == ZPROP_INVAL) {
                        if (zfs_prop_user(propname)) {
                                if (nvpair_type(propval) != DATA_TYPE_STRING)
-                                       err = EINVAL;
+                                       err = SET_ERROR(EINVAL);
                        } else if (zfs_prop_userquota(propname)) {
                                if (nvpair_type(propval) !=
                                    DATA_TYPE_UINT64_ARRAY)
-                                       err = EINVAL;
+                                       err = SET_ERROR(EINVAL);
                        } else {
-                               err = EINVAL;
+                               err = SET_ERROR(EINVAL);
                        }
                } else if (err == 0) {
                        if (nvpair_type(propval) == DATA_TYPE_STRING) {
                                if (zfs_prop_get_type(prop) != PROP_TYPE_STRING)
-                                       err = EINVAL;
+                                       err = SET_ERROR(EINVAL);
                        } else if (nvpair_type(propval) == DATA_TYPE_UINT64) {
                                const char *unused;
 
@@ -2474,19 +2447,19 @@ retry:
                                case PROP_TYPE_NUMBER:
                                        break;
                                case PROP_TYPE_STRING:
-                                       err = EINVAL;
+                                       err = SET_ERROR(EINVAL);
                                        break;
                                case PROP_TYPE_INDEX:
                                        if (zfs_prop_index_to_string(prop,
                                            intval, &unused) != 0)
-                                               err = EINVAL;
+                                               err = SET_ERROR(EINVAL);
                                        break;
                                default:
                                        cmn_err(CE_PANIC,
                                            "unknown property type");
                                }
                        } else {
-                               err = EINVAL;
+                               err = SET_ERROR(EINVAL);
                        }
                }
 
@@ -2583,18 +2556,18 @@ zfs_check_userprops(const char *fsname, nvlist_t *nvl)
 
                if (!zfs_prop_user(propname) ||
                    nvpair_type(pair) != DATA_TYPE_STRING)
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
 
                if ((error = zfs_secpolicy_write_perms(fsname,
                    ZFS_DELEG_PERM_USERPROP, CRED())))
                        return (error);
 
                if (strlen(propname) >= ZAP_MAXNAMELEN)
-                       return (ENAMETOOLONG);
+                       return (SET_ERROR(ENAMETOOLONG));
 
                VERIFY(nvpair_value_string(pair, &valstr) == 0);
                if (strlen(valstr) >= ZAP_MAXVALUELEN)
-                       return (E2BIG);
+                       return (SET_ERROR(E2BIG));
        }
        return (0);
 }
@@ -2714,12 +2687,12 @@ zfs_ioc_inherit_prop(zfs_cmd_t *zc)
                 */
                if (prop == ZPROP_INVAL) {
                        if (!zfs_prop_user(propname))
-                               return (EINVAL);
+                               return (SET_ERROR(EINVAL));
 
                        type = PROP_TYPE_STRING;
                } else if (prop == ZFS_PROP_VOLSIZE ||
                    prop == ZFS_PROP_VERSION) {
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
                } else {
                        type = zfs_prop_get_type(prop);
                }
@@ -2736,7 +2709,7 @@ zfs_ioc_inherit_prop(zfs_cmd_t *zc)
                        break;
                default:
                        nvlist_free(dummy);
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
                }
 
                pair = nvlist_next_nvpair(dummy, NULL);
@@ -2752,7 +2725,7 @@ zfs_ioc_inherit_prop(zfs_cmd_t *zc)
                 * they are not considered inheritable.
                 */
                if (prop != ZPROP_INVAL && !zfs_prop_inheritable(prop))
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
        }
 
        /* property name has been validated by zfs_secpolicy_inherit_prop() */
@@ -2829,36 +2802,12 @@ zfs_ioc_pool_get_props(zfs_cmd_t *zc)
        if (error == 0 && zc->zc_nvlist_dst != 0)
                error = put_nvlist(zc, nvp);
        else
-               error = EFAULT;
+               error = SET_ERROR(EFAULT);
 
        nvlist_free(nvp);
        return (error);
 }
 
-/*
- * inputs:
- * zc_name              name of volume
- *
- * outputs:             none
- */
-static int
-zfs_ioc_create_minor(zfs_cmd_t *zc)
-{
-       return (zvol_create_minor(zc->zc_name));
-}
-
-/*
- * inputs:
- * zc_name              name of volume
- *
- * outputs:             none
- */
-static int
-zfs_ioc_remove_minor(zfs_cmd_t *zc)
-{
-       return (zvol_remove_minor(zc->zc_name));
-}
-
 /*
  * inputs:
  * zc_name             name of filesystem
@@ -2882,7 +2831,7 @@ zfs_ioc_set_fsacl(zfs_cmd_t *zc)
         */
        if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
                nvlist_free(fsaclnv);
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        }
 
        /*
@@ -2943,10 +2892,10 @@ zfs_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
 
 /*
  * inputs:
- * createprops         list of properties requested by creator
- * default_zplver      zpl version to use if unspecified in createprops
- * fuids_ok            fuids allowed in this version of the spa?
  * os                  parent objset pointer (NULL if root fs)
+ * fuids_ok            fuids allowed in this version of the spa?
+ * sa_ok               SAs allowed in this version of the spa?
+ * createprops         list of properties requested by creator
  *
  * outputs:
  * zplprops    values for the zplprops we attach to the master node object
@@ -3005,7 +2954,7 @@ zfs_fill_zplprops_impl(objset_t *os, uint64_t zplver,
            (zplver < ZPL_VERSION_NORMALIZATION &&
            (norm != ZFS_PROP_UNDEFINED || u8 != ZFS_PROP_UNDEFINED ||
            sense != ZFS_PROP_UNDEFINED)))
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
 
        /*
         * Put the version in the zplprops
@@ -3120,7 +3069,7 @@ zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
        boolean_t is_insensitive = B_FALSE;
 
        if (nvlist_lookup_int32(innvl, "type", &type32) != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        type = type32;
        (void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
 
@@ -3139,26 +3088,26 @@ zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
        }
        if (strchr(fsname, '@') ||
            strchr(fsname, '%'))
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        zct.zct_props = nvprops;
 
        if (cbfunc == NULL)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        if (type == DMU_OST_ZVOL) {
                uint64_t volsize, volblocksize;
 
                if (nvprops == NULL)
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
                if (nvlist_lookup_uint64(nvprops,
                    zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) != 0)
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
 
                if ((error = nvlist_lookup_uint64(nvprops,
                    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
                    &volblocksize)) != 0 && error != ENOENT)
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
 
                if (error != 0)
                        volblocksize = zfs_prop_default_numeric(
@@ -3201,6 +3150,12 @@ zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
                if (error != 0)
                        (void) dsl_destroy_head(fsname);
        }
+
+#ifdef _KERNEL
+       if (error == 0 && type == DMU_OST_ZVOL)
+               zvol_create_minors(fsname);
+#endif
+
        return (error);
 }
 
@@ -3221,15 +3176,15 @@ zfs_ioc_clone(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
        char *origin_name;
 
        if (nvlist_lookup_string(innvl, "origin", &origin_name) != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        (void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
 
        if (strchr(fsname, '@') ||
            strchr(fsname, '%'))
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        if (dataset_namecheck(origin_name, NULL, NULL) != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        error = dmu_objset_clone(fsname, origin_name);
        if (error != 0)
                return (error);
@@ -3243,6 +3198,12 @@ zfs_ioc_clone(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
                if (error != 0)
                        (void) dsl_destroy_head(fsname);
        }
+
+#ifdef _KERNEL
+       if (error == 0)
+               zvol_create_minors(fsname);
+#endif
+
        return (error);
 }
 
@@ -3268,10 +3229,10 @@ zfs_ioc_snapshot(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
 
        if (!nvlist_empty(props) &&
            zfs_earlier_version(poolname, SPA_VERSION_SNAP_PROPS))
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
 
        if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        poollen = strlen(poolname);
        for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
            pair = nvlist_next_nvpair(snaps, pair)) {
@@ -3283,26 +3244,32 @@ zfs_ioc_snapshot(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
                 * contain only valid characters.
                 */
                if (cp == NULL || snapshot_namecheck(cp + 1, NULL, NULL) != 0)
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
 
                /*
                 * The snap must be in the specified pool.
                 */
                if (strncmp(name, poolname, poollen) != 0 ||
                    (name[poollen] != '/' && name[poollen] != '@'))
-                       return (EXDEV);
+                       return (SET_ERROR(EXDEV));
 
                /* This must be the only snap of this fs. */
                for (pair2 = nvlist_next_nvpair(snaps, pair);
                    pair2 != NULL; pair2 = nvlist_next_nvpair(snaps, pair2)) {
                        if (strncmp(name, nvpair_name(pair2), cp - name + 1)
                            == 0) {
-                               return (EXDEV);
+                               return (SET_ERROR(EXDEV));
                        }
                }
        }
 
        error = dsl_dataset_snapshot(snaps, props, outnvl);
+
+#ifdef _KERNEL
+       if (error == 0)
+               zvol_create_minors(poolname);
+#endif
+
        return (error);
 }
 
@@ -3334,12 +3301,12 @@ zfs_ioc_log_history(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
 
        if (nvlist_lookup_string(innvl, "message", &message) != 0)  {
                spa_close(spa, FTAG);
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        }
 
        if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
                spa_close(spa, FTAG);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
 
        error = spa_history_log(spa, message);
@@ -3353,8 +3320,16 @@ zfs_ioc_log_history(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
  *
  * This function is best-effort.  Callers must deal gracefully if it
  * remains mounted (or is remounted after this call).
+ *
+ * XXX: This function should detect a failure to unmount a snapdir of a dataset
+ * and return the appropriate error code when it is mounted. Its Illumos and
+ * FreeBSD counterparts do this. We do not do this on Linux because there is no
+ * clear way to access the mount information that FreeBSD and Illumos use to
+ * distinguish between things with mounted snapshot directories, and things
+ * without mounted snapshot directories, which include zvols. Returning a
+ * failure for the latter causes `zfs destroy` to fail on zvol snapshots.
  */
-void
+int
 zfs_unmount_snap(const char *snapname)
 {
        zfs_sb_t *zsb = NULL;
@@ -3363,7 +3338,7 @@ zfs_unmount_snap(const char *snapname)
        char *ptr;
 
        if ((ptr = strchr(snapname, '@')) == NULL)
-               return;
+               return (0);
 
        dsname = kmem_alloc(ptr - snapname + 1, KM_SLEEP);
        strlcpy(dsname, snapname, ptr - snapname + 1);
@@ -3378,15 +3353,14 @@ zfs_unmount_snap(const char *snapname)
        kmem_free(dsname, ptr - snapname + 1);
        strfree(fullname);
 
-       return;
+       return (0);
 }
 
 /* ARGSUSED */
 static int
 zfs_unmount_snap_cb(const char *snapname, void *arg)
 {
-       zfs_unmount_snap(snapname);
-       return (0);
+       return (zfs_unmount_snap(snapname));
 }
 
 /*
@@ -3409,7 +3383,7 @@ zfs_destroy_unmount_origin(const char *fsname)
                char originname[MAXNAMELEN];
                dsl_dataset_name(ds->ds_prev, originname);
                dmu_objset_rele(os, FTAG);
-               zfs_unmount_snap(originname);
+               (void) zfs_unmount_snap(originname);
        } else {
                dmu_objset_rele(os, FTAG);
        }
@@ -3426,13 +3400,13 @@ zfs_destroy_unmount_origin(const char *fsname)
 static int
 zfs_ioc_destroy_snaps(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
 {
-       int poollen;
+       int error, poollen;
        nvlist_t *snaps;
        nvpair_t *pair;
        boolean_t defer;
 
        if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        defer = nvlist_exists(innvl, "defer");
 
        poollen = strlen(poolname);
@@ -3445,9 +3419,11 @@ zfs_ioc_destroy_snaps(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
                 */
                if (strncmp(name, poolname, poollen) != 0 ||
                    (name[poollen] != '/' && name[poollen] != '@'))
-                       return (EXDEV);
+                       return (SET_ERROR(EXDEV));
 
-               zfs_unmount_snap(name);
+               error = zfs_unmount_snap(name);
+               if (error != 0)
+                       return (error);
                (void) zvol_remove_minor(name);
        }
 
@@ -3466,8 +3442,12 @@ static int
 zfs_ioc_destroy(zfs_cmd_t *zc)
 {
        int err;
-       if (strchr(zc->zc_name, '@') && zc->zc_objset_type == DMU_OST_ZFS)
-               zfs_unmount_snap(zc->zc_name);
+
+       if (zc->zc_objset_type == DMU_OST_ZFS) {
+               err = zfs_unmount_snap(zc->zc_name);
+               if (err != 0)
+                       return (err);
+       }
 
        if (strchr(zc->zc_name, '@'))
                err = dsl_destroy_snapshot(zc->zc_name, zc->zc_defer_destroy);
@@ -3479,29 +3459,32 @@ zfs_ioc_destroy(zfs_cmd_t *zc)
 }
 
 /*
- * inputs:
- * zc_name     name of dataset to rollback (to most recent snapshot)
+ * fsname is name of dataset to rollback (to most recent snapshot)
  *
- * outputs:    none
+ * innvl is not used.
+ *
+ * outnvl: "target" -> name of most recent snapshot
+ * }
  */
+/* ARGSUSED */
 static int
-zfs_ioc_rollback(zfs_cmd_t *zc)
+zfs_ioc_rollback(const char *fsname, nvlist_t *args, nvlist_t *outnvl)
 {
        zfs_sb_t *zsb;
        int error;
 
-       if (get_zfs_sb(zc->zc_name, &zsb) == 0) {
+       if (get_zfs_sb(fsname, &zsb) == 0) {
                error = zfs_suspend_fs(zsb);
                if (error == 0) {
                        int resume_err;
 
-                       error = dsl_dataset_rollback(zc->zc_name);
-                       resume_err = zfs_resume_fs(zsb, zc->zc_name);
+                       error = dsl_dataset_rollback(fsname, zsb, outnvl);
+                       resume_err = zfs_resume_fs(zsb, fsname);
                        error = error ? error : resume_err;
                }
                deactivate_super(zsb->z_sb);
        } else {
-               error = dsl_dataset_rollback(zc->zc_name);
+               error = dsl_dataset_rollback(fsname, NULL, outnvl);
        }
        return (error);
 }
@@ -3515,7 +3498,7 @@ recursive_unmount(const char *fsname, void *arg)
        fullname = kmem_asprintf("%s@%s", fsname, snapname);
        zfs_unmount_snap(fullname);
        strfree(fullname);
-       return (0);
+       return (zfs_unmount_snap(fullname));
 }
 
 /*
@@ -3531,35 +3514,36 @@ zfs_ioc_rename(zfs_cmd_t *zc)
 {
        boolean_t recursive = zc->zc_cookie & 1;
        char *at;
-       int err;
 
        zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
        if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
            strchr(zc->zc_value, '%'))
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        at = strchr(zc->zc_name, '@');
        if (at != NULL) {
                /* snaps must be in same fs */
+               int error;
+
                if (strncmp(zc->zc_name, zc->zc_value, at - zc->zc_name + 1))
-                       return (EXDEV);
+                       return (SET_ERROR(EXDEV));
                *at = '\0';
                if (zc->zc_objset_type == DMU_OST_ZFS) {
-                       int error = dmu_objset_find(zc->zc_name,
+                       error = dmu_objset_find(zc->zc_name,
                            recursive_unmount, at + 1,
                            recursive ? DS_FIND_CHILDREN : 0);
-                       if (error != 0)
+                       if (error != 0) {
+                               *at = '@';
                                return (error);
+                       }
                }
-               return (dsl_dataset_rename_snapshot(zc->zc_name,
-                   at + 1, strchr(zc->zc_value, '@') + 1, recursive));
+               error = dsl_dataset_rename_snapshot(zc->zc_name,
+                   at + 1, strchr(zc->zc_value, '@') + 1, recursive);
+               *at = '@';
+
+               return (error);
        } else {
-               err = dsl_dir_rename(zc->zc_name, zc->zc_value);
-               if (!err && zc->zc_objset_type == DMU_OST_ZVOL) {
-                       (void) zvol_remove_minor(zc->zc_name);
-                       (void) zvol_create_minor(zc->zc_value);
-               }
-               return (err);
+               return (dsl_dir_rename(zc->zc_name, zc->zc_value));
        }
 }
 
@@ -3595,7 +3579,7 @@ zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
                                perm = ZFS_DELEG_PERM_GROUPQUOTA;
                        } else {
                                /* USERUSED and GROUPUSED are read-only */
-                               return (EINVAL);
+                               return (SET_ERROR(EINVAL));
                        }
 
                        if ((err = zfs_secpolicy_write_perms(dsname, perm, cr)))
@@ -3603,11 +3587,11 @@ zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
                        return (0);
                }
 
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        }
 
        if (issnap)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
                /*
@@ -3636,13 +3620,13 @@ zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
                            intval <= ZIO_COMPRESS_GZIP_9 &&
                            zfs_earlier_version(dsname,
                            SPA_VERSION_GZIP_COMPRESSION)) {
-                               return (ENOTSUP);
+                               return (SET_ERROR(ENOTSUP));
                        }
 
                        if (intval == ZIO_COMPRESS_ZLE &&
                            zfs_earlier_version(dsname,
                            SPA_VERSION_ZLE_COMPRESSION))
-                               return (ENOTSUP);
+                               return (SET_ERROR(ENOTSUP));
 
                        if (intval == ZIO_COMPRESS_LZ4) {
                                zfeature_info_t *feature =
@@ -3655,7 +3639,7 @@ zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
 
                                if (!spa_feature_is_enabled(spa, feature)) {
                                        spa_close(spa, FTAG);
-                                       return (ENOTSUP);
+                                       return (SET_ERROR(ENOTSUP));
                                }
                                spa_close(spa, FTAG);
                        }
@@ -3669,24 +3653,24 @@ zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
                         */
                        if (zfs_is_bootfs(dsname) &&
                            !BOOTFS_COMPRESS_VALID(intval)) {
-                               return (ERANGE);
+                               return (SET_ERROR(ERANGE));
                        }
                }
                break;
 
        case ZFS_PROP_COPIES:
                if (zfs_earlier_version(dsname, SPA_VERSION_DITTO_BLOCKS))
-                       return (ENOTSUP);
+                       return (SET_ERROR(ENOTSUP));
                break;
 
        case ZFS_PROP_DEDUP:
                if (zfs_earlier_version(dsname, SPA_VERSION_DEDUP))
-                       return (ENOTSUP);
+                       return (SET_ERROR(ENOTSUP));
                break;
 
        case ZFS_PROP_SHARESMB:
                if (zpl_earlier_version(dsname, ZPL_VERSION_FUID))
-                       return (ENOTSUP);
+                       return (SET_ERROR(ENOTSUP));
                break;
 
        case ZFS_PROP_ACLINHERIT:
@@ -3695,7 +3679,7 @@ zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
                        if (intval == ZFS_ACL_PASSTHROUGH_X &&
                            zfs_earlier_version(dsname,
                            SPA_VERSION_PASSTHROUGH_X))
-                               return (ENOTSUP);
+                               return (SET_ERROR(ENOTSUP));
                }
                break;
        default:
@@ -3718,7 +3702,7 @@ zfs_prop_activate_feature_check(void *arg, dmu_tx_t *tx)
        if (!spa_feature_is_active(spa, feature))
                return (0);
        else
-               return (EBUSY);
+               return (SET_ERROR(EBUSY));
 }
 
 /*
@@ -3926,7 +3910,7 @@ zfs_ioc_recv(zfs_cmd_t *zc)
        if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
            strchr(zc->zc_value, '@') == NULL ||
            strchr(zc->zc_value, '%'))
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        (void) strcpy(tofs, zc->zc_value);
        tosnap = strchr(tofs, '@');
@@ -3941,7 +3925,7 @@ zfs_ioc_recv(zfs_cmd_t *zc)
        fp = getf(fd);
        if (fp == NULL) {
                nvlist_free(props);
-               return (EBADF);
+               return (SET_ERROR(EBADF));
        }
 
        VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
@@ -4010,7 +3994,7 @@ zfs_ioc_recv(zfs_cmd_t *zc)
                 * Caller made zc->zc_nvlist_dst less than the minimum expected
                 * size or supplied an invalid address.
                 */
-               props_error = EINVAL;
+               props_error = SET_ERROR(EINVAL);
        }
 
        off = fp->f_offset;
@@ -4029,13 +4013,13 @@ zfs_ioc_recv(zfs_cmd_t *zc)
                         * If the suspend fails, then the recv_end will
                         * likely also fail, and clean up after itself.
                         */
-                       end_err = dmu_recv_end(&drc);
+                       end_err = dmu_recv_end(&drc, zsb);
                        if (error == 0)
                                error = zfs_resume_fs(zsb, tofs);
                        error = error ? error : end_err;
                        deactivate_super(zsb->z_sb);
                } else {
-                       error = dmu_recv_end(&drc);
+                       error = dmu_recv_end(&drc, NULL);
                }
        }
 
@@ -4049,6 +4033,12 @@ zfs_ioc_recv(zfs_cmd_t *zc)
                error = 1;
        }
 #endif
+
+#ifdef _KERNEL
+       if (error == 0)
+               zvol_create_minors(tofs);
+#endif
+
        /*
         * On error, restore the original props.
         */
@@ -4172,7 +4162,7 @@ zfs_ioc_send(zfs_cmd_t *zc)
        } else {
                file_t *fp = getf(zc->zc_cookie);
                if (fp == NULL)
-                       return (EBADF);
+                       return (SET_ERROR(EBADF));
 
                off = fp->f_offset;
                error = dmu_send_obj(zc->zc_name, zc->zc_sendobj,
@@ -4230,7 +4220,7 @@ zfs_ioc_send_progress(zfs_cmd_t *zc)
        if (dsp != NULL)
                zc->zc_cookie = *(dsp->dsa_off);
        else
-               error = ENOENT;
+               error = SET_ERROR(ENOENT);
 
        mutex_exit(&ds->ds_sendstream_lock);
        dsl_dataset_rele(ds, FTAG);
@@ -4308,7 +4298,7 @@ zfs_ioc_clear(zfs_cmd_t *zc)
        spa = spa_lookup(zc->zc_name);
        if (spa == NULL) {
                mutex_exit(&spa_namespace_lock);
-               return (EIO);
+               return (SET_ERROR(EIO));
        }
        if (spa_get_log_state(spa) == SPA_LOG_MISSING) {
                /* we need to let spa_open/spa_load clear the chains */
@@ -4324,7 +4314,7 @@ zfs_ioc_clear(zfs_cmd_t *zc)
                nvlist_t *config = NULL;
 
                if (zc->zc_nvlist_src == 0)
-                       return (EINVAL);
+                       return (SET_ERROR(EINVAL));
 
                if ((error = get_nvlist(zc->zc_nvlist_src,
                    zc->zc_nvlist_src_size, zc->zc_iflags, &policy)) == 0) {
@@ -4353,7 +4343,7 @@ zfs_ioc_clear(zfs_cmd_t *zc)
                if (vd == NULL) {
                        (void) spa_vdev_state_exit(spa, NULL, ENODEV);
                        spa_close(spa, FTAG);
-                       return (ENODEV);
+                       return (SET_ERROR(ENODEV));
                }
        }
 
@@ -4365,7 +4355,7 @@ zfs_ioc_clear(zfs_cmd_t *zc)
         * Resume any suspended I/Os.
         */
        if (zio_resume(spa) != 0)
-               error = EIO;
+               error = SET_ERROR(EIO);
 
        spa_close(spa, FTAG);
 
@@ -4442,7 +4432,7 @@ zfs_ioc_userspace_one(zfs_cmd_t *zc)
        int error;
 
        if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        error = zfs_sb_hold(zc->zc_name, FTAG, &zsb, B_FALSE);
        if (error != 0)
@@ -4475,7 +4465,7 @@ zfs_ioc_userspace_many(zfs_cmd_t *zc)
        void *buf;
 
        if (bufsize <= 0)
-               return (ENOMEM);
+               return (SET_ERROR(ENOMEM));
 
        error = zfs_sb_hold(zc->zc_name, FTAG, &zsb, B_FALSE);
        if (error != 0)
@@ -4519,8 +4509,11 @@ zfs_ioc_userspace_upgrade(zfs_cmd_t *zc)
                         * objset_phys_t).  Suspend/resume the fs will do that.
                         */
                        error = zfs_suspend_fs(zsb);
-                       if (error == 0)
+                       if (error == 0) {
+                               dmu_objset_refresh_ownership(zsb->z_os,
+                                   zsb);
                                error = zfs_resume_fs(zsb, zc->zc_name);
+                       }
                }
                if (error == 0)
                        error = dmu_objset_userspace_upgrade(zsb->z_os);
@@ -4541,7 +4534,7 @@ zfs_ioc_userspace_upgrade(zfs_cmd_t *zc)
 static int
 zfs_ioc_share(zfs_cmd_t *zc)
 {
-       return (ENOSYS);
+       return (SET_ERROR(ENOSYS));
 }
 
 ace_t full_access[] = {
@@ -4626,7 +4619,7 @@ zfs_ioc_diff(zfs_cmd_t *zc)
 
        fp = getf(zc->zc_cookie);
        if (fp == NULL)
-               return (EBADF);
+               return (SET_ERROR(EBADF));
 
        off = fp->f_offset;
 
@@ -4688,7 +4681,7 @@ zfs_ioc_smb_acl(zfs_cmd_t *zc)
            (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
            zc->zc_name) != 0)) {
                VN_RELE(vp);
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
        }
 
        dzp = VTOZ(vp);
@@ -4778,7 +4771,7 @@ zfs_ioc_smb_acl(zfs_cmd_t *zc)
                break;
 
        default:
-               error = EINVAL;
+               error = SET_ERROR(EINVAL);
                break;
        }
 
@@ -4789,7 +4782,7 @@ zfs_ioc_smb_acl(zfs_cmd_t *zc)
 
        return (error);
 #else
-       return (ENOTSUP);
+       return (SET_ERROR(ENOTSUP));
 #endif /* HAVE_SMB_SHARE */
 }
 
@@ -4815,7 +4808,7 @@ zfs_ioc_hold(const char *pool, nvlist_t *args, nvlist_t *errlist)
 
        error = nvlist_lookup_nvlist(args, "holds", &holds);
        if (error != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        if (nvlist_lookup_int32(args, "cleanup_fd", &cleanup_fd) == 0) {
                error = zfs_onexit_fd_hold(cleanup_fd, &minor);
@@ -4859,16 +4852,6 @@ zfs_ioc_get_holds(const char *snapname, nvlist_t *args, nvlist_t *outnvl)
 static int
 zfs_ioc_release(const char *pool, nvlist_t *holds, nvlist_t *errlist)
 {
-       nvpair_t *pair;
-
-       /*
-        * The release may cause the snapshot to be destroyed; make sure it
-        * is not mounted.
-        */
-       for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
-           pair = nvlist_next_nvpair(holds, pair))
-               zfs_unmount_snap(nvpair_name(pair));
-
        return (dsl_dataset_user_release(holds, errlist));
 }
 
@@ -4931,7 +4914,7 @@ zfs_ioc_events_clear(zfs_cmd_t *zc)
        zfs_zevent_drain_all(&count);
        zc->zc_cookie = count;
 
-       return 0;
+       return (0);
 }
 
 /*
@@ -4995,7 +4978,7 @@ zfs_ioc_space_snaps(const char *lastsnap, nvlist_t *innvl, nvlist_t *outnvl)
        uint64_t used, comp, uncomp;
 
        if (nvlist_lookup_string(innvl, "firstsnap", &firstsnap) != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        error = dsl_pool_hold(lastsnap, FTAG, &dp);
        if (error != 0)
@@ -5043,12 +5026,12 @@ zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
 
        error = nvlist_lookup_int32(innvl, "fd", &fd);
        if (error != 0)
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        (void) nvlist_lookup_string(innvl, "fromsnap", &fromname);
 
        if ((fp = getf(fd)) == NULL)
-               return (EBADF);
+               return (SET_ERROR(EBADF));
 
        off = fp->f_offset;
        error = dmu_send(snapname, fromname, fd, fp->f_vnode, &off);
@@ -5264,6 +5247,10 @@ zfs_ioctl_init(void)
            zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME,
            POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
 
+       zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK,
+           zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME,
+           POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE);
+
        /* IOCTLS that use the legacy function signature */
 
        zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE, zfs_ioc_pool_freeze,
@@ -5335,7 +5322,7 @@ zfs_ioctl_init(void)
            zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
 
        zfs_ioctl_register_pool(ZFS_IOC_CLEAR, zfs_ioc_clear,
-           zfs_secpolicy_config, B_TRUE, POOL_CHECK_SUSPENDED);
+           zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
        zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN, zfs_ioc_pool_reopen,
            zfs_secpolicy_config, B_TRUE, POOL_CHECK_SUSPENDED);
 
@@ -5375,8 +5362,6 @@ zfs_ioctl_init(void)
            zfs_secpolicy_none);
        zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY, zfs_ioc_destroy,
            zfs_secpolicy_destroy);
-       zfs_ioctl_register_dataset_modify(ZFS_IOC_ROLLBACK, zfs_ioc_rollback,
-           zfs_secpolicy_rollback);
        zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME, zfs_ioc_rename,
            zfs_secpolicy_rename);
        zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV, zfs_ioc_recv,
@@ -5400,12 +5385,8 @@ zfs_ioctl_init(void)
            POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
 
        /*
-        * ZoL functions
+        * ZoL functions
         */
-       zfs_ioctl_register_legacy(ZFS_IOC_CREATE_MINOR, zfs_ioc_create_minor,
-           zfs_secpolicy_config, DATASET_NAME, B_FALSE, POOL_CHECK_NONE);
-       zfs_ioctl_register_legacy(ZFS_IOC_REMOVE_MINOR, zfs_ioc_remove_minor,
-           zfs_secpolicy_config, DATASET_NAME, B_FALSE, POOL_CHECK_NONE);
        zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_NEXT, zfs_ioc_events_next,
            zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_NONE);
        zfs_ioctl_register_legacy(ZFS_IOC_EVENTS_CLEAR, zfs_ioc_events_clear,
@@ -5427,9 +5408,9 @@ pool_status_check(const char *name, zfs_ioc_namecheck_t type,
        error = spa_open(name, &spa, FTAG);
        if (error == 0) {
                if ((check & POOL_CHECK_SUSPENDED) && spa_suspended(spa))
-                       error = EAGAIN;
+                       error = SET_ERROR(EAGAIN);
                else if ((check & POOL_CHECK_READONLY) && !spa_writeable(spa))
-                       error = EROFS;
+                       error = SET_ERROR(EROFS);
                spa_close(spa, FTAG);
        }
        return (error);
@@ -5443,17 +5424,20 @@ zfsdev_get_state_impl(minor_t minor, enum zfsdev_state_type which)
        ASSERT(MUTEX_HELD(&zfsdev_state_lock));
 
        for (zs = list_head(&zfsdev_state_list); zs != NULL;
-            zs = list_next(&zfsdev_state_list, zs)) {
+           zs = list_next(&zfsdev_state_list, zs)) {
                if (zs->zs_minor == minor) {
                        switch (which) {
-                               case ZST_ONEXIT:  return (zs->zs_onexit);
-                               case ZST_ZEVENT:  return (zs->zs_zevent);
-                               case ZST_ALL:     return (zs);
+                       case ZST_ONEXIT:
+                               return (zs->zs_onexit);
+                       case ZST_ZEVENT:
+                               return (zs->zs_zevent);
+                       case ZST_ALL:
+                               return (zs);
                        }
                }
        }
 
-       return NULL;
+       return (NULL);
 }
 
 void *
@@ -5465,7 +5449,7 @@ zfsdev_get_state(minor_t minor, enum zfsdev_state_type which)
        ptr = zfsdev_get_state_impl(minor, which);
        mutex_exit(&zfsdev_state_lock);
 
-       return ptr;
+       return (ptr);
 }
 
 minor_t
@@ -5509,11 +5493,11 @@ zfsdev_state_init(struct file *filp)
 
        ASSERT(MUTEX_HELD(&zfsdev_state_lock));
 
-        minor = zfsdev_minor_alloc();
-        if (minor == 0)
-                return (ENXIO);
+       minor = zfsdev_minor_alloc();
+       if (minor == 0)
+               return (SET_ERROR(ENXIO));
 
-       zs = kmem_zalloc( sizeof(zfsdev_state_t), KM_SLEEP);
+       zs = kmem_zalloc(sizeof (zfsdev_state_t), KM_SLEEP);
 
        zs->zs_file = filp;
        zs->zs_minor = minor;
@@ -5540,9 +5524,9 @@ zfsdev_state_destroy(struct file *filp)
        zfs_zevent_destroy(zs->zs_zevent);
 
        list_remove(&zfsdev_state_list, zs);
-       kmem_free(zs, sizeof(zfsdev_state_t));
+       kmem_free(zs, sizeof (zfsdev_state_t));
 
-       return 0;
+       return (0);
 }
 
 static int
@@ -5576,19 +5560,27 @@ zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
        uint_t vecnum;
        int error, rc, len, flag = 0;
        const zfs_ioc_vec_t *vec;
-       char saved_poolname[MAXNAMELEN];
+       char *saved_poolname;
        nvlist_t *innvl = NULL;
 
        vecnum = cmd - ZFS_IOC_FIRST;
        if (vecnum >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
-               return (-EINVAL);
+               return (-SET_ERROR(EINVAL));
        vec = &zfs_ioc_vec[vecnum];
 
+       /*
+        * The registered ioctl list may be sparse, verify that either
+        * a normal or legacy handler are registered.
+        */
+       if (vec->zvec_func == NULL && vec->zvec_legacy_func == NULL)
+               return (-SET_ERROR(EINVAL));
+
        zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP | KM_NODEBUG);
+       saved_poolname = kmem_alloc(MAXNAMELEN, KM_SLEEP);
 
        error = ddi_copyin((void *)arg, zc, sizeof (zfs_cmd_t), flag);
        if (error != 0) {
-               error = EFAULT;
+               error = SET_ERROR(EFAULT);
                goto out;
        }
 
@@ -5608,7 +5600,7 @@ zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
        switch (vec->zvec_namecheck) {
        case POOL_NAME:
                if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
-                       error = EINVAL;
+                       error = SET_ERROR(EINVAL);
                else
                        error = pool_status_check(zc->zc_name,
                            vec->zvec_namecheck, vec->zvec_pool_check);
@@ -5616,7 +5608,7 @@ zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
 
        case DATASET_NAME:
                if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
-                       error = EINVAL;
+                       error = SET_ERROR(EINVAL);
                else
                        error = pool_status_check(zc->zc_name,
                            vec->zvec_namecheck, vec->zvec_pool_check);
@@ -5634,7 +5626,7 @@ zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
                goto out;
 
        /* legacy ioctls can modify zc_name */
-       (void) strlcpy(saved_poolname, zc->zc_name, sizeof(saved_poolname));
+       (void) strlcpy(saved_poolname, zc->zc_name, sizeof (saved_poolname));
        len = strcspn(saved_poolname, "/@") + 1;
        saved_poolname[len] = '\0';
 
@@ -5696,7 +5688,7 @@ out:
        nvlist_free(innvl);
        rc = ddi_copyout(zc, (void *)arg, sizeof (zfs_cmd_t), flag);
        if (error == 0 && rc != 0)
-               error = EFAULT;
+               error = SET_ERROR(EFAULT);
        if (error == 0 && vec->zvec_allow_log) {
                char *s = tsd_get(zfs_allow_log_key);
                if (s != NULL)
@@ -5704,6 +5696,7 @@ out:
                (void) tsd_set(zfs_allow_log_key, strdup(saved_poolname));
        }
 
+       kmem_free(saved_poolname, MAXNAMELEN);
        kmem_free(zc, sizeof (zfs_cmd_t));
        return (-error);
 }
@@ -5712,24 +5705,24 @@ out:
 static long
 zfsdev_compat_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
 {
-        return zfsdev_ioctl(filp, cmd, arg);
+       return (zfsdev_ioctl(filp, cmd, arg));
 }
 #else
-#define zfsdev_compat_ioctl   NULL
+#define        zfsdev_compat_ioctl     NULL
 #endif
 
 static const struct file_operations zfsdev_fops = {
-       .open            = zfsdev_open,
-       .release         = zfsdev_release,
-       .unlocked_ioctl  = zfsdev_ioctl,
-       .compat_ioctl    = zfsdev_compat_ioctl,
-       .owner           = THIS_MODULE,
+       .open           = zfsdev_open,
+       .release        = zfsdev_release,
+       .unlocked_ioctl = zfsdev_ioctl,
+       .compat_ioctl   = zfsdev_compat_ioctl,
+       .owner          = THIS_MODULE,
 };
 
 static struct miscdevice zfs_misc = {
-       .minor          = MISC_DYNAMIC_MINOR,
-       .name           = ZFS_DRIVER,
-       .fops           = &zfsdev_fops,
+       .minor          = MISC_DYNAMIC_MINOR,
+       .name           = ZFS_DRIVER,
+       .fops           = &zfsdev_fops,
 };
 
 static int
@@ -5742,7 +5735,7 @@ zfs_attach(void)
            offsetof(zfsdev_state_t, zs_next));
 
        error = misc_register(&zfs_misc);
-        if (error != 0) {
+       if (error != 0) {
                printk(KERN_INFO "ZFS: misc_register() failed %d\n", error);
                return (error);
        }
@@ -5771,9 +5764,9 @@ zfs_allow_log_destroy(void *arg)
 }
 
 #ifdef DEBUG
-#define ZFS_DEBUG_STR  " (DEBUG mode)"
+#define        ZFS_DEBUG_STR   " (DEBUG mode)"
 #else
-#define ZFS_DEBUG_STR  ""
+#define        ZFS_DEBUG_STR   ""
 #endif
 
 int
@@ -5797,9 +5790,12 @@ _init(void)
        tsd_create(&zfs_allow_log_key, zfs_allow_log_destroy);
 
        printk(KERN_NOTICE "ZFS: Loaded module v%s-%s%s, "
-              "ZFS pool version %s, ZFS filesystem version %s\n",
-              ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR,
-              SPA_VERSION_STRING, ZPL_VERSION_STRING);
+           "ZFS pool version %s, ZFS filesystem version %s\n",
+           ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR,
+           SPA_VERSION_STRING, ZPL_VERSION_STRING);
+#ifndef CONFIG_FS_POSIX_ACL
+       printk(KERN_NOTICE "ZFS: Posix ACLs disabled by kernel\n");
+#endif /* CONFIG_FS_POSIX_ACL */
 
        return (0);
 
@@ -5809,8 +5805,8 @@ out1:
        zfs_fini();
        spa_fini();
        printk(KERN_NOTICE "ZFS: Failed to Load ZFS Filesystem v%s-%s%s"
-              ", rc = %d\n", ZFS_META_VERSION, ZFS_META_RELEASE,
-              ZFS_DEBUG_STR, error);
+           ", rc = %d\n", ZFS_META_VERSION, ZFS_META_RELEASE,
+           ZFS_DEBUG_STR, error);
 
        return (error);
 }
@@ -5828,7 +5824,7 @@ _fini(void)
        tsd_destroy(&zfs_allow_log_key);
 
        printk(KERN_NOTICE "ZFS: Unloaded module v%s-%s%s\n",
-              ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR);
+           ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR);
 
        return (0);
 }
@@ -5840,4 +5836,5 @@ spl_module_exit(_fini);
 MODULE_DESCRIPTION("ZFS");
 MODULE_AUTHOR(ZFS_META_AUTHOR);
 MODULE_LICENSE(ZFS_META_LICENSE);
+MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
 #endif /* HAVE_SPL */