* Portions Copyright 2011 Martin Matuska
* Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
* Portions Copyright 2012 Pawel Jakub Dawidek <pawel@dawidek.net>
- * Copyright (c) 2012, Joyent, Inc. All rights reserved.
+ * Copyright (c) 2014, 2016 Joyent, Inc. All rights reserved.
* Copyright 2016 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2014, Joyent, Inc. All rights reserved.
- * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
* Copyright (c) 2013 Steven Hartland. All rights reserved.
+ * Copyright (c) 2014 Integros [integros.com]
+ * Copyright 2016 Toomas Soome <tsoome@me.com>
* Copyright (c) 2016 Actifio, Inc. All rights reserved.
+ * Copyright (c) 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
+ * Copyright 2017 RackTop Systems.
+ * Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
+ * Copyright (c) 2019 Datto Inc.
*/
/*
*
* zfs_ioc_t ioc
* The ioctl request number, which userland will pass to ioctl(2).
- * The ioctl numbers can change from release to release, because
- * the caller (libzfs) must be matched to the kernel.
+ * We want newer versions of libzfs and libzfs_core to run against
+ * existing zfs kernel modules (i.e. a deferred reboot after an update).
+ * Therefore the ioctl numbers cannot change from release to release.
*
* zfs_secpolicy_func_t *secpolicy
* This function will be called before the zfs_ioc_func_t, to
* Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
* POOL_CHECK_READONLY).
*
+ * zfs_ioc_key_t *nvl_keys
+ * The list of expected/allowable innvl input keys. This list is used
+ * to validate the nvlist input to the ioctl.
+ *
* boolean_t smush_outnvlist
* If smush_outnvlist is true, then the output is presumed to be a
* list of errors, and it will be "smushed" down to fit into the
* use the outnvl if they succeed, because the caller can not
* distinguish between the operation failing, and
* deserialization failing.
+ *
+ * IOCTL Interface Errors
+ *
+ * The following ioctl input errors can be returned:
+ * ZFS_ERR_IOC_CMD_UNAVAIL the ioctl number is not supported by kernel
+ * ZFS_ERR_IOC_ARG_UNAVAIL an input argument is not supported by kernel
+ * ZFS_ERR_IOC_ARG_REQUIRED a required input argument is missing
+ * ZFS_ERR_IOC_ARG_BADTYPE an input argument has an invalid type
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/errno.h>
#include <sys/uio.h>
-#include <sys/buf.h>
-#include <sys/modctl.h>
-#include <sys/open.h>
#include <sys/file.h>
#include <sys/kmem.h>
-#include <sys/conf.h>
#include <sys/cmn_err.h>
#include <sys/stat.h>
#include <sys/zfs_ioctl.h>
#include <sys/spa.h>
#include <sys/spa_impl.h>
#include <sys/vdev.h>
-#include <sys/priv_impl.h>
+#include <sys/vdev_impl.h>
#include <sys/dmu.h>
#include <sys/dsl_dir.h>
#include <sys/dsl_dataset.h>
#include <sys/dmu_objset.h>
#include <sys/dmu_impl.h>
#include <sys/dmu_tx.h>
-#include <sys/ddi.h>
#include <sys/sunddi.h>
-#include <sys/sunldi.h>
#include <sys/policy.h>
#include <sys/zone.h>
#include <sys/nvpair.h>
#include <sys/pathname.h>
-#include <sys/mount.h>
#include <sys/sdt.h>
#include <sys/fs/zfs.h>
#include <sys/zfs_ctldir.h>
#include <sys/zfs_onexit.h>
#include <sys/zvol.h>
#include <sys/dsl_scan.h>
-#include <sharefs/share.h>
#include <sys/fm/util.h>
+#include <sys/dsl_crypt.h>
+#include <sys/dmu_recv.h>
#include <sys/dmu_send.h>
#include <sys/dsl_destroy.h>
#include <sys/dsl_bookmark.h>
#include <sys/dsl_userhold.h>
#include <sys/zfeature.h>
+#include <sys/zcp.h>
#include <sys/zio_checksum.h>
+#include <sys/vdev_removal.h>
+#include <sys/zfs_sysfs.h>
+#include <sys/vdev_impl.h>
+#include <sys/vdev_initialize.h>
+#include <sys/vdev_trim.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include "zfs_deleg.h"
#include "zfs_comutil.h"
+#include <sys/lua/lua.h>
+#include <sys/lua/lauxlib.h>
+
/*
* Limit maximum nvlist size. We don't want users passing in insane values
* for zc->zc_nvlist_src_size, since we will need to allocate that much memory.
typedef int zfs_ioc_func_t(const char *, nvlist_t *, nvlist_t *);
typedef int zfs_secpolicy_func_t(zfs_cmd_t *, nvlist_t *, cred_t *);
+/*
+ * IOC Keys are used to document and validate user->kernel interface inputs.
+ * See zfs_keys_recv_new for an example declaration. Any key name that is not
+ * listed will be rejected as input.
+ *
+ * The keyname 'optional' is always allowed, and must be an nvlist if present.
+ * Arguments which older kernels can safely ignore can be placed under the
+ * "optional" key.
+ *
+ * When adding new keys to an existing ioc for new functionality, consider:
+ * - adding an entry into zfs_sysfs.c zfs_features[] list
+ * - updating the libzfs_input_check.c test utility
+ *
+ * Note: in the ZK_WILDCARDLIST case, the name serves as documentation
+ * for the expected name (bookmark, snapshot, property, etc) but there
+ * is no validation in the preflight zfs_check_input_nvpairs() check.
+ */
+typedef enum {
+ ZK_OPTIONAL = 1 << 0, /* pair is optional */
+ ZK_WILDCARDLIST = 1 << 1, /* one or more unspecified key names */
+} ioc_key_flag_t;
+
+/* DATA_TYPE_ANY is used when zkey_type can vary. */
+#define DATA_TYPE_ANY DATA_TYPE_UNKNOWN
+
+typedef struct zfs_ioc_key {
+ const char *zkey_name;
+ data_type_t zkey_type;
+ ioc_key_flag_t zkey_flags;
+} zfs_ioc_key_t;
+
typedef enum {
NO_NAME,
POOL_NAME,
zfs_ioc_poolcheck_t zvec_pool_check;
boolean_t zvec_smush_outnvlist;
const char *zvec_name;
+ const zfs_ioc_key_t *zvec_nvl_keys;
+ size_t zvec_nvl_key_count;
} zfs_ioc_vec_t;
/* This array is indexed by zfs_userquota_prop_t */
ZFS_DELEG_PERM_USEROBJQUOTA,
ZFS_DELEG_PERM_GROUPOBJUSED,
ZFS_DELEG_PERM_GROUPOBJQUOTA,
+ ZFS_DELEG_PERM_PROJECTUSED,
+ ZFS_DELEG_PERM_PROJECTQUOTA,
+ ZFS_DELEG_PERM_PROJECTOBJUSED,
+ ZFS_DELEG_PERM_PROJECTOBJQUOTA,
};
static int zfs_ioc_userspace_upgrade(zfs_cmd_t *zc);
-static int zfs_ioc_userobjspace_upgrade(zfs_cmd_t *zc);
+static int zfs_ioc_id_quota_upgrade(zfs_cmd_t *zc);
static int zfs_check_settable(const char *name, nvpair_t *property,
cred_t *cr);
static int zfs_check_clearable(char *dataset, nvlist_t *props,
dsl_dataset_t *ds;
dsl_pool_t *dp;
+ /*
+ * First do a quick check for root in the global zone, which
+ * is allowed to do all write_perms. This ensures that zfs_ioc_*
+ * will get to handle nonexistent datasets.
+ */
+ if (INGLOBALZONE(curproc) && secpolicy_zfs(cr) == 0)
+ return (0);
+
error = dsl_pool_hold(name, FTAG, &dp);
if (error != 0)
return (error);
/*
* If the existing dataset label is nondefault, check if the
* dataset is mounted (label cannot be changed while mounted).
- * Get the zfs_sb_t; if there isn't one, then the dataset isn't
+ * Get the zfsvfs_t; if there isn't one, then the dataset isn't
* mounted (or isn't a dataset, doesn't exist, ...).
*/
if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) != 0) {
* Try to own the dataset; abort if there is any error,
* (e.g., already mounted, in use, or other error).
*/
- error = dmu_objset_own(name, DMU_OST_ZFS, B_TRUE,
+ error = dmu_objset_own(name, DMU_OST_ZFS, B_TRUE, B_TRUE,
setsl_tag, &os);
if (error != 0)
return (SET_ERROR(EPERM));
- dmu_objset_disown(os, setsl_tag);
+ dmu_objset_disown(os, B_TRUE, setsl_tag);
if (new_default) {
needed_priv = PRIV_FILE_DOWNGRADE_SL;
return (PRIV_POLICY(cr, needed_priv, B_FALSE, EPERM, NULL));
return (0);
#else
- return (ENOTSUP);
+ return (SET_ERROR(ENOTSUP));
#endif /* HAVE_MLSLABEL */
}
ZFS_DELEG_PERM_SEND, cr));
}
-#ifdef HAVE_SMB_SHARE
-/* ARGSUSED */
-static int
-zfs_secpolicy_deleg_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
-{
- vnode_t *vp;
- int error;
-
- if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
- NO_FOLLOW, NULL, &vp)) != 0)
- return (error);
-
- /* Now make sure mntpnt and dataset are ZFS */
-
- if (vp->v_vfsp->vfs_fstype != zfsfstype ||
- (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
- zc->zc_name) != 0)) {
- VN_RELE(vp);
- return (SET_ERROR(EPERM));
- }
-
- VN_RELE(vp);
- return (dsl_deleg_access(zc->zc_name,
- ZFS_DELEG_PERM_SHARE, cr));
-}
-#endif /* HAVE_SMB_SHARE */
-
int
zfs_secpolicy_share(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
{
-#ifdef HAVE_SMB_SHARE
- if (!INGLOBALZONE(curproc))
- return (SET_ERROR(EPERM));
-
- if (secpolicy_nfs(cr) == 0) {
- return (0);
- } else {
- return (zfs_secpolicy_deleg_share(zc, innvl, cr));
- }
-#else
return (SET_ERROR(ENOTSUP));
-#endif /* HAVE_SMB_SHARE */
}
int
zfs_secpolicy_smb_acl(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
{
-#ifdef HAVE_SMB_SHARE
- if (!INGLOBALZONE(curproc))
- return (SET_ERROR(EPERM));
-
- if (secpolicy_smb(cr) == 0) {
- return (0);
- } else {
- return (zfs_secpolicy_deleg_share(zc, innvl, cr));
- }
-#else
return (SET_ERROR(ENOTSUP));
-#endif /* HAVE_SMB_SHARE */
}
static int
nvpair_t *pair, *nextpair;
int error = 0;
- if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
- return (SET_ERROR(EINVAL));
+ snaps = fnvlist_lookup_nvlist(innvl, "snaps");
+
for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
pair = nextpair) {
nextpair = nvlist_next_nvpair(snaps, pair);
int error = 0;
nvpair_t *pair;
- if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
- return (SET_ERROR(EINVAL));
+ snaps = fnvlist_lookup_nvlist(innvl, "snaps");
+
for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
pair = nvlist_next_nvpair(snaps, pair)) {
char *name = nvpair_name(pair);
}
/*
- * Check for permission to create each snapshot in the nvlist.
+ * Check for permission to create each bookmark in the nvlist.
*/
/* ARGSUSED */
static int
zfs_secpolicy_bookmark(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
{
int error = 0;
- nvpair_t *pair;
- for (pair = nvlist_next_nvpair(innvl, NULL);
+ for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
char *name = nvpair_name(pair);
char *hashp = strchr(name, '#');
return (error);
}
+/* ARGSUSED */
+static int
+zfs_secpolicy_remap(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
+{
+ return (zfs_secpolicy_write_perms(zc->zc_name,
+ ZFS_DELEG_PERM_REMAP, cr));
+}
+
/* ARGSUSED */
static int
zfs_secpolicy_destroy_bookmarks(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
zc->zc_objset_type == ZFS_PROP_USEROBJQUOTA) {
if (zc->zc_guid == crgetuid(cr))
return (0);
- } else {
+ } else if (zc->zc_objset_type == ZFS_PROP_GROUPUSED ||
+ zc->zc_objset_type == ZFS_PROP_GROUPQUOTA ||
+ zc->zc_objset_type == ZFS_PROP_GROUPOBJUSED ||
+ zc->zc_objset_type == ZFS_PROP_GROUPOBJQUOTA) {
if (groupmember(zc->zc_guid, cr))
return (0);
}
+ /* else is for project quota/used */
}
return (zfs_secpolicy_write_perms(zc->zc_name,
nvlist_t *holds;
int error;
- error = nvlist_lookup_nvlist(innvl, "holds", &holds);
- if (error != 0)
- return (SET_ERROR(EINVAL));
+ holds = fnvlist_lookup_nvlist(innvl, "holds");
for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
pair = nvlist_next_nvpair(holds, pair)) {
return (0);
error = zfs_secpolicy_snapshot_perms(zc->zc_name, cr);
- if (error == 0)
- error = zfs_secpolicy_hold(zc, innvl, cr);
- if (error == 0)
- error = zfs_secpolicy_release(zc, innvl, cr);
- if (error == 0)
- error = zfs_secpolicy_destroy(zc, innvl, cr);
+
+ if (innvl != NULL) {
+ if (error == 0)
+ error = zfs_secpolicy_hold(zc, innvl, cr);
+ if (error == 0)
+ error = zfs_secpolicy_release(zc, innvl, cr);
+ if (error == 0)
+ error = zfs_secpolicy_destroy(zc, innvl, cr);
+ }
return (error);
}
+static int
+zfs_secpolicy_load_key(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
+{
+ return (zfs_secpolicy_write_perms(zc->zc_name,
+ ZFS_DELEG_PERM_LOAD_KEY, cr));
+}
+
+static int
+zfs_secpolicy_change_key(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
+{
+ return (zfs_secpolicy_write_perms(zc->zc_name,
+ ZFS_DELEG_PERM_CHANGE_KEY, cr));
+}
+
/*
* Returns the nvlist as specified by the user in the zfs_cmd_t.
*/
return (error);
}
-static int
-get_zfs_sb(const char *dsname, zfs_sb_t **zsbp)
+int
+getzfsvfs_impl(objset_t *os, zfsvfs_t **zfvp)
{
- objset_t *os;
- int error;
-
- error = dmu_objset_hold(dsname, FTAG, &os);
- if (error != 0)
- return (error);
+ int error = 0;
if (dmu_objset_type(os) != DMU_OST_ZFS) {
- dmu_objset_rele(os, FTAG);
return (SET_ERROR(EINVAL));
}
mutex_enter(&os->os_user_ptr_lock);
- *zsbp = dmu_objset_get_user(os);
+ *zfvp = dmu_objset_get_user(os);
/* bump s_active only when non-zero to prevent umount race */
- if (*zsbp == NULL || (*zsbp)->z_sb == NULL ||
- !atomic_inc_not_zero(&((*zsbp)->z_sb->s_active))) {
+ if (*zfvp == NULL || (*zfvp)->z_sb == NULL ||
+ !atomic_inc_not_zero(&((*zfvp)->z_sb->s_active))) {
error = SET_ERROR(ESRCH);
}
mutex_exit(&os->os_user_ptr_lock);
+ return (error);
+}
+
+int
+getzfsvfs(const char *dsname, zfsvfs_t **zfvp)
+{
+ objset_t *os;
+ int error;
+
+ error = dmu_objset_hold(dsname, FTAG, &os);
+ if (error != 0)
+ return (error);
+
+ error = getzfsvfs_impl(os, zfvp);
dmu_objset_rele(os, FTAG);
return (error);
}
/*
- * Find a zfs_sb_t for a mounted filesystem, or create our own, in which
+ * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
* case its z_sb will be NULL, and it will be opened as the owner.
* If 'writer' is set, the z_teardown_lock will be held for RW_WRITER,
* which prevents all inode ops from running.
*/
static int
-zfs_sb_hold(const char *name, void *tag, zfs_sb_t **zsbp, boolean_t writer)
+zfsvfs_hold(const char *name, void *tag, zfsvfs_t **zfvp, boolean_t writer)
{
int error = 0;
- if (get_zfs_sb(name, zsbp) != 0)
- error = zfs_sb_create(name, NULL, zsbp);
+ if (getzfsvfs(name, zfvp) != 0)
+ error = zfsvfs_create(name, B_FALSE, zfvp);
if (error == 0) {
- rrm_enter(&(*zsbp)->z_teardown_lock, (writer) ? RW_WRITER :
+ rrm_enter(&(*zfvp)->z_teardown_lock, (writer) ? RW_WRITER :
RW_READER, tag);
- if ((*zsbp)->z_unmounted) {
+ if ((*zfvp)->z_unmounted) {
/*
* XXX we could probably try again, since the unmounting
* thread should be just about to disassociate the
- * objset from the zsb.
+ * objset from the zfsvfs.
*/
- rrm_exit(&(*zsbp)->z_teardown_lock, tag);
+ rrm_exit(&(*zfvp)->z_teardown_lock, tag);
return (SET_ERROR(EBUSY));
}
}
}
static void
-zfs_sb_rele(zfs_sb_t *zsb, void *tag)
+zfsvfs_rele(zfsvfs_t *zfsvfs, void *tag)
{
- rrm_exit(&zsb->z_teardown_lock, tag);
+ rrm_exit(&zfsvfs->z_teardown_lock, tag);
- if (zsb->z_sb) {
- deactivate_super(zsb->z_sb);
+ if (zfsvfs->z_sb) {
+ deactivate_super(zfsvfs->z_sb);
} else {
- dmu_objset_disown(zsb->z_os, zsb);
- zfs_sb_free(zsb);
+ dmu_objset_disown(zfsvfs->z_os, B_TRUE, zfsvfs);
+ zfsvfs_free(zfsvfs);
}
}
nvlist_t *config, *props = NULL;
nvlist_t *rootprops = NULL;
nvlist_t *zplprops = NULL;
+ dsl_crypto_params_t *dcp = NULL;
+ char *spa_name = zc->zc_name;
if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
zc->zc_iflags, &config)))
if (props) {
nvlist_t *nvl = NULL;
+ nvlist_t *hidden_args = NULL;
uint64_t version = SPA_VERSION;
+ char *tname;
(void) nvlist_lookup_uint64(props,
zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
}
(void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
}
+
+ (void) nvlist_lookup_nvlist(props, ZPOOL_HIDDEN_ARGS,
+ &hidden_args);
+ error = dsl_crypto_params_create_nvlist(DCP_CMD_NONE,
+ rootprops, hidden_args, &dcp);
+ if (error != 0) {
+ nvlist_free(config);
+ nvlist_free(props);
+ return (error);
+ }
+ (void) nvlist_remove_all(props, ZPOOL_HIDDEN_ARGS);
+
VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
error = zfs_fill_zplprops_root(version, rootprops,
zplprops, NULL);
if (error != 0)
goto pool_props_bad;
+
+ if (nvlist_lookup_string(props,
+ zpool_prop_to_name(ZPOOL_PROP_TNAME), &tname) == 0)
+ spa_name = tname;
}
- error = spa_create(zc->zc_name, config, props, zplprops);
+ error = spa_create(zc->zc_name, config, props, zplprops, dcp);
/*
* Set the remaining root properties
*/
- if (!error && (error = zfs_set_prop_nvlist(zc->zc_name,
+ if (!error && (error = zfs_set_prop_nvlist(spa_name,
ZPROP_SRC_LOCAL, rootprops, NULL)) != 0)
- (void) spa_destroy(zc->zc_name);
+ (void) spa_destroy(spa_name);
pool_props_bad:
nvlist_free(rootprops);
nvlist_free(zplprops);
nvlist_free(config);
nvlist_free(props);
+ dsl_crypto_params_free(dcp, !!error);
return (error);
}
static int
zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
{
- nvlist_t *tryconfig, *config;
+ nvlist_t *tryconfig, *config = NULL;
int error;
if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
* inputs:
* zc_name name of the pool
* zc_cookie scan func (pool_scan_func_t)
+ * zc_flags scrub pause/resume flag (pool_scrub_cmd_t)
*/
static int
zfs_ioc_pool_scan(zfs_cmd_t *zc)
spa_t *spa;
int error;
+ if (zc->zc_flags >= POOL_SCRUB_FLAGS_END)
+ return (SET_ERROR(EINVAL));
+
if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
return (error);
- if (zc->zc_cookie == POOL_SCAN_NONE)
+ if (zc->zc_flags == POOL_SCRUB_PAUSE)
+ error = spa_scrub_pause_resume(spa, POOL_SCRUB_PAUSE);
+ else if (zc->zc_cookie == POOL_SCAN_NONE)
error = spa_scan_stop(spa);
else
error = spa_scan(spa, zc->zc_cookie);
int error;
/* XXX reading from objset not owned */
- if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
+ if ((error = dmu_objset_hold_flags(zc->zc_name, B_TRUE,
+ FTAG, &os)) != 0)
return (error);
if (dmu_objset_type(os) != DMU_OST_ZFS) {
- dmu_objset_rele(os, FTAG);
+ dmu_objset_rele_flags(os, B_TRUE, FTAG);
return (SET_ERROR(EINVAL));
}
error = zfs_obj_to_path(os, zc->zc_obj, zc->zc_value,
sizeof (zc->zc_value));
- dmu_objset_rele(os, FTAG);
+ dmu_objset_rele_flags(os, B_TRUE, FTAG);
return (error);
}
int error;
/* XXX reading from objset not owned */
- if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
+ if ((error = dmu_objset_hold_flags(zc->zc_name, B_TRUE,
+ FTAG, &os)) != 0)
return (error);
if (dmu_objset_type(os) != DMU_OST_ZFS) {
- dmu_objset_rele(os, FTAG);
+ dmu_objset_rele_flags(os, B_TRUE, FTAG);
return (SET_ERROR(EINVAL));
}
error = zfs_obj_to_stats(os, zc->zc_obj, &zc->zc_stat, zc->zc_value,
sizeof (zc->zc_value));
- dmu_objset_rele(os, FTAG);
+ dmu_objset_rele_flags(os, B_TRUE, FTAG);
return (error);
}
/*
* inputs:
* zc_name name of the pool
- * zc_nvlist_conf nvlist of devices to remove
- * zc_cookie to stop the remove?
+ * zc_guid guid of vdev to remove
+ * zc_cookie cancel removal
*/
static int
zfs_ioc_vdev_remove(zfs_cmd_t *zc)
error = spa_open(zc->zc_name, &spa, FTAG);
if (error != 0)
return (error);
- error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
+ if (zc->zc_cookie != 0) {
+ error = spa_vdev_remove_cancel(spa);
+ } else {
+ error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
+ }
spa_close(spa, FTAG);
return (error);
}
case VDEV_STATE_FAULTED:
if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
- zc->zc_obj != VDEV_AUX_EXTERNAL)
+ zc->zc_obj != VDEV_AUX_EXTERNAL &&
+ zc->zc_obj != VDEV_AUX_EXTERNAL_PERSIST)
zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
error = vdev_fault(spa, zc->zc_guid, zc->zc_obj);
return (err);
}
-boolean_t
-dataset_name_hidden(const char *name)
-{
- /*
- * Skip over datasets that are not visible in this zone,
- * internal datasets (which have a $ in their name), and
- * temporary datasets (which have a % in their name).
- */
- if (strchr(name, '$') != NULL)
- return (B_TRUE);
- if (strchr(name, '%') != NULL)
- return (B_TRUE);
- if (!INGLOBALZONE(curproc) && !zone_dataset_visible(name, NULL))
- return (B_TRUE);
- return (B_FALSE);
-}
-
/*
* inputs:
* zc_name name of filesystem
NULL, &zc->zc_cookie);
if (error == ENOENT)
error = SET_ERROR(ESRCH);
- } while (error == 0 && dataset_name_hidden(zc->zc_name));
+ } while (error == 0 && zfs_dataset_name_hidden(zc->zc_name));
dmu_objset_rele(os, FTAG);
/*
* inputs:
* zc_name name of filesystem
* zc_cookie zap cursor
- * zc_nvlist_dst_size size of buffer for property nvlist
+ * zc_nvlist_src iteration range nvlist
+ * zc_nvlist_src_size size of iteration range nvlist
*
* outputs:
* zc_name name of next snapshot
static int
zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
{
- objset_t *os;
int error;
+ objset_t *os, *ossnap;
+ dsl_dataset_t *ds;
+ uint64_t min_txg = 0, max_txg = 0;
+
+ if (zc->zc_nvlist_src_size != 0) {
+ nvlist_t *props = NULL;
+ error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
+ zc->zc_iflags, &props);
+ if (error != 0)
+ return (error);
+ (void) nvlist_lookup_uint64(props, SNAP_ITER_MIN_TXG,
+ &min_txg);
+ (void) nvlist_lookup_uint64(props, SNAP_ITER_MAX_TXG,
+ &max_txg);
+ nvlist_free(props);
+ }
error = dmu_objset_hold(zc->zc_name, FTAG, &os);
if (error != 0) {
return (SET_ERROR(ESRCH));
}
- error = dmu_snapshot_list_next(os,
- sizeof (zc->zc_name) - strlen(zc->zc_name),
- zc->zc_name + strlen(zc->zc_name), &zc->zc_obj, &zc->zc_cookie,
- NULL);
+ while (error == 0) {
+ if (issig(JUSTLOOKING) && issig(FORREAL)) {
+ error = SET_ERROR(EINTR);
+ break;
+ }
- if (error == 0 && !zc->zc_simple) {
- dsl_dataset_t *ds;
- dsl_pool_t *dp = os->os_dsl_dataset->ds_dir->dd_pool;
+ error = dmu_snapshot_list_next(os,
+ sizeof (zc->zc_name) - strlen(zc->zc_name),
+ zc->zc_name + strlen(zc->zc_name), &zc->zc_obj,
+ &zc->zc_cookie, NULL);
+ if (error == ENOENT) {
+ error = SET_ERROR(ESRCH);
+ break;
+ } else if (error != 0) {
+ break;
+ }
- error = dsl_dataset_hold_obj(dp, zc->zc_obj, FTAG, &ds);
- if (error == 0) {
- objset_t *ossnap;
+ error = dsl_dataset_hold_obj(dmu_objset_pool(os), zc->zc_obj,
+ FTAG, &ds);
+ if (error != 0)
+ break;
- error = dmu_objset_from_ds(ds, &ossnap);
- if (error == 0)
- error = zfs_ioc_objset_stats_impl(zc, ossnap);
+ if ((min_txg != 0 && dsl_get_creationtxg(ds) < min_txg) ||
+ (max_txg != 0 && dsl_get_creationtxg(ds) > max_txg)) {
dsl_dataset_rele(ds, FTAG);
+ /* undo snapshot name append */
+ *(strchr(zc->zc_name, '@') + 1) = '\0';
+ /* skip snapshot */
+ continue;
}
- } else if (error == ENOENT) {
- error = SET_ERROR(ESRCH);
+
+ if (zc->zc_simple) {
+ dsl_dataset_rele(ds, FTAG);
+ break;
+ }
+
+ if ((error = dmu_objset_from_ds(ds, &ossnap)) != 0) {
+ dsl_dataset_rele(ds, FTAG);
+ break;
+ }
+ if ((error = zfs_ioc_objset_stats_impl(zc, ossnap)) != 0) {
+ dsl_dataset_rele(ds, FTAG);
+ break;
+ }
+ dsl_dataset_rele(ds, FTAG);
+ break;
}
dmu_objset_rele(os, FTAG);
zfs_userquota_prop_t type;
uint64_t rid;
uint64_t quota;
- zfs_sb_t *zsb;
+ zfsvfs_t *zfsvfs;
int err;
if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
rid = valary[1];
quota = valary[2];
- err = zfs_sb_hold(dsname, FTAG, &zsb, B_FALSE);
+ err = zfsvfs_hold(dsname, FTAG, &zfsvfs, B_FALSE);
if (err == 0) {
- err = zfs_set_userquota(zsb, type, domain, rid, quota);
- zfs_sb_rele(zsb, FTAG);
+ err = zfs_set_userquota(zfsvfs, type, domain, rid, quota);
+ zfsvfs_rele(zfsvfs, FTAG);
}
return (err);
{
const char *propname = nvpair_name(pair);
zfs_prop_t prop = zfs_name_to_prop(propname);
- uint64_t intval;
+ uint64_t intval = 0;
+ char *strval = NULL;
int err = -1;
if (prop == ZPROP_INVAL) {
&pair) == 0);
}
- if (zfs_prop_get_type(prop) == PROP_TYPE_STRING)
- return (-1);
-
- VERIFY(0 == nvpair_value_uint64(pair, &intval));
+ /* all special properties are numeric except for keylocation */
+ if (zfs_prop_get_type(prop) == PROP_TYPE_STRING) {
+ strval = fnvpair_value_string(pair);
+ } else {
+ intval = fnvpair_value_uint64(pair);
+ }
switch (prop) {
case ZFS_PROP_QUOTA:
} else {
err = dsl_dir_activate_fs_ss_limit(dsname);
}
+ /*
+ * Set err to -1 to force the zfs_set_prop_nvlist code down the
+ * default path to set the value in the nvlist.
+ */
+ if (err == 0)
+ err = -1;
+ break;
+ case ZFS_PROP_KEYLOCATION:
+ err = dsl_crypto_can_set_keylocation(dsname, strval);
+
/*
* Set err to -1 to force the zfs_set_prop_nvlist code down the
* default path to set the value in the nvlist.
case ZFS_PROP_SNAPDEV:
err = zvol_set_snapdev(dsname, source, intval);
break;
+ case ZFS_PROP_VOLMODE:
+ err = zvol_set_volmode(dsname, source, intval);
+ break;
case ZFS_PROP_VERSION:
{
- zfs_sb_t *zsb;
+ zfsvfs_t *zfsvfs;
- if ((err = zfs_sb_hold(dsname, FTAG, &zsb, B_TRUE)) != 0)
+ if ((err = zfsvfs_hold(dsname, FTAG, &zfsvfs, B_TRUE)) != 0)
break;
- err = zfs_set_version(zsb, intval);
- zfs_sb_rele(zsb, FTAG);
+ err = zfs_set_version(zfsvfs, intval);
+ zfsvfs_rele(zfsvfs, FTAG);
if (err == 0 && intval >= ZPL_VERSION_USERSPACE) {
zfs_cmd_t *zc;
zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
(void) strcpy(zc->zc_name, dsname);
(void) zfs_ioc_userspace_upgrade(zc);
- (void) zfs_ioc_userobjspace_upgrade(zc);
+ (void) zfs_ioc_id_quota_upgrade(zc);
kmem_free(zc, sizeof (zfs_cmd_t));
}
break;
}
/* Validate value type */
- if (err == 0 && prop == ZPROP_INVAL) {
+ if (err == 0 && source == ZPROP_SRC_INHERITED) {
+ /* inherited properties are expected to be booleans */
+ if (nvpair_type(propval) != DATA_TYPE_BOOLEAN)
+ err = SET_ERROR(EINVAL);
+ } else if (err == 0 && prop == ZPROP_INVAL) {
if (zfs_prop_user(propname)) {
if (nvpair_type(propval) != DATA_TYPE_STRING)
err = SET_ERROR(EINVAL);
err = zfs_check_settable(dsname, pair, CRED());
if (err == 0) {
- err = zfs_prop_set_special(dsname, source, pair);
+ if (source == ZPROP_SRC_INHERITED)
+ err = -1; /* does not need special handling */
+ else
+ err = zfs_prop_set_special(dsname, source,
+ pair);
if (err == -1) {
/*
* For better performance we build up a list of
strval = fnvpair_value_string(propval);
err = dsl_prop_set_string(dsname, propname,
source, strval);
+ } else if (nvpair_type(propval) == DATA_TYPE_BOOLEAN) {
+ err = dsl_prop_inherit(dsname, propname,
+ source);
} else {
intval = fnvpair_value_uint64(propval);
err = dsl_prop_set_int(dsname, propname, source,
zprop_source_t source = (received
? ZPROP_SRC_NONE /* revert to received value, if any */
: ZPROP_SRC_INHERITED); /* explicitly inherit */
+ nvlist_t *dummy;
+ nvpair_t *pair;
+ zprop_type_t type;
+ int err;
- if (received) {
- nvlist_t *dummy;
- nvpair_t *pair;
- zprop_type_t type;
- int err;
-
- /*
- * zfs_prop_set_special() expects properties in the form of an
- * nvpair with type info.
- */
- if (prop == ZPROP_INVAL) {
- if (!zfs_prop_user(propname))
- return (SET_ERROR(EINVAL));
-
- type = PROP_TYPE_STRING;
- } else if (prop == ZFS_PROP_VOLSIZE ||
- prop == ZFS_PROP_VERSION) {
- return (SET_ERROR(EINVAL));
- } else {
- type = zfs_prop_get_type(prop);
- }
-
- VERIFY(nvlist_alloc(&dummy, NV_UNIQUE_NAME, KM_SLEEP) == 0);
-
- switch (type) {
- case PROP_TYPE_STRING:
- VERIFY(0 == nvlist_add_string(dummy, propname, ""));
- break;
- case PROP_TYPE_NUMBER:
- case PROP_TYPE_INDEX:
- VERIFY(0 == nvlist_add_uint64(dummy, propname, 0));
- break;
- default:
- nvlist_free(dummy);
- return (SET_ERROR(EINVAL));
- }
-
- pair = nvlist_next_nvpair(dummy, NULL);
- if (pair == NULL) {
- nvlist_free(dummy);
- return (SET_ERROR(EINVAL));
- }
- err = zfs_prop_set_special(zc->zc_name, source, pair);
- nvlist_free(dummy);
- if (err != -1)
- return (err); /* special property already handled */
- } else {
+ if (!received) {
/*
* Only check this in the non-received case. We want to allow
* 'inherit -S' to revert non-inheritable properties like quota
return (SET_ERROR(EINVAL));
}
- /* property name has been validated by zfs_secpolicy_inherit_prop() */
- return (dsl_prop_inherit(zc->zc_name, zc->zc_value, source));
+ if (prop == ZPROP_INVAL) {
+ if (!zfs_prop_user(propname))
+ return (SET_ERROR(EINVAL));
+
+ type = PROP_TYPE_STRING;
+ } else if (prop == ZFS_PROP_VOLSIZE || prop == ZFS_PROP_VERSION) {
+ return (SET_ERROR(EINVAL));
+ } else {
+ type = zfs_prop_get_type(prop);
+ }
+
+ /*
+ * zfs_prop_set_special() expects properties in the form of an
+ * nvpair with type info.
+ */
+ dummy = fnvlist_alloc();
+
+ switch (type) {
+ case PROP_TYPE_STRING:
+ VERIFY(0 == nvlist_add_string(dummy, propname, ""));
+ break;
+ case PROP_TYPE_NUMBER:
+ case PROP_TYPE_INDEX:
+ VERIFY(0 == nvlist_add_uint64(dummy, propname, 0));
+ break;
+ default:
+ err = SET_ERROR(EINVAL);
+ goto errout;
+ }
+
+ pair = nvlist_next_nvpair(dummy, NULL);
+ if (pair == NULL) {
+ err = SET_ERROR(EINVAL);
+ } else {
+ err = zfs_prop_set_special(zc->zc_name, source, pair);
+ if (err == -1) /* property is not "special", needs handling */
+ err = dsl_prop_inherit(zc->zc_name, zc->zc_value,
+ source);
+ }
+
+errout:
+ nvlist_free(dummy);
+ return (err);
}
static int
mutex_enter(&spa_namespace_lock);
if ((spa = spa_lookup(zc->zc_name)) != NULL) {
spa_configfile_set(spa, props, B_FALSE);
- spa_config_sync(spa, B_FALSE, B_TRUE);
+ spa_write_cachefile(spa, B_FALSE, B_TRUE);
}
mutex_exit(&spa_namespace_lock);
if (spa != NULL) {
ASSERT(zplprops != NULL);
+ /* parent dataset must be a filesystem */
+ if (os != NULL && os->os_phys->os_type != DMU_OST_ZFS)
+ return (SET_ERROR(ZFS_ERR_WRONG_PARENT));
+
/*
* Pull out creator prop choices, if any.
*/
uint64_t zplver = ZPL_VERSION;
objset_t *os = NULL;
char parentname[ZFS_MAX_DATASET_NAME_LEN];
- char *cp;
spa_t *spa;
uint64_t spa_vers;
int error;
- (void) strlcpy(parentname, dataset, sizeof (parentname));
- cp = strrchr(parentname, '/');
- ASSERT(cp != NULL);
- cp[0] = '\0';
+ zfs_get_parent(dataset, parentname, sizeof (parentname));
if ((error = spa_open(dataset, &spa, FTAG)) != 0)
return (error);
* innvl: {
* "type" -> dmu_objset_type_t (int32)
* (optional) "props" -> { prop -> value }
+ * (optional) "hidden_args" -> { "wkeydata" -> value }
+ * raw uint8_t array of encryption wrapping key data (32 bytes)
* }
*
* outnvl: propname -> error code (int32)
*/
+
+static const zfs_ioc_key_t zfs_keys_create[] = {
+ {"type", DATA_TYPE_INT32, 0},
+ {"props", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+ {"hidden_args", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+};
+
static int
zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
{
int error = 0;
zfs_creat_t zct = { 0 };
nvlist_t *nvprops = NULL;
+ nvlist_t *hidden_args = NULL;
void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
- int32_t type32;
dmu_objset_type_t type;
boolean_t is_insensitive = B_FALSE;
+ dsl_crypto_params_t *dcp = NULL;
- if (nvlist_lookup_int32(innvl, "type", &type32) != 0)
- return (SET_ERROR(EINVAL));
- type = type32;
+ type = (dmu_objset_type_t)fnvlist_lookup_int32(innvl, "type");
(void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
+ (void) nvlist_lookup_nvlist(innvl, ZPOOL_HIDDEN_ARGS, &hidden_args);
switch (type) {
case DMU_OST_ZFS:
}
}
+ error = dsl_crypto_params_create_nvlist(DCP_CMD_NONE, nvprops,
+ hidden_args, &dcp);
+ if (error != 0) {
+ nvlist_free(zct.zct_zplprops);
+ return (error);
+ }
+
error = dmu_objset_create(fsname, type,
- is_insensitive ? DS_FLAG_CI_DATASET : 0, cbfunc, &zct);
+ is_insensitive ? DS_FLAG_CI_DATASET : 0, dcp, cbfunc, &zct);
+
nvlist_free(zct.zct_zplprops);
+ dsl_crypto_params_free(dcp, !!error);
/*
* It would be nice to do this atomically.
* innvl: {
* "origin" -> name of origin snapshot
* (optional) "props" -> { prop -> value }
+ * (optional) "hidden_args" -> { "wkeydata" -> value }
+ * raw uint8_t array of encryption wrapping key data (32 bytes)
* }
*
* outputs:
* outnvl: propname -> error code (int32)
*/
+static const zfs_ioc_key_t zfs_keys_clone[] = {
+ {"origin", DATA_TYPE_STRING, 0},
+ {"props", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+ {"hidden_args", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+};
+
static int
zfs_ioc_clone(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
{
nvlist_t *nvprops = NULL;
char *origin_name;
- if (nvlist_lookup_string(innvl, "origin", &origin_name) != 0)
- return (SET_ERROR(EINVAL));
+ origin_name = fnvlist_lookup_string(innvl, "origin");
(void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
if (strchr(fsname, '@') ||
if (dataset_namecheck(origin_name, NULL, NULL) != 0)
return (SET_ERROR(EINVAL));
+
error = dmu_objset_clone(fsname, origin_name);
- if (error != 0)
- return (error);
/*
* It would be nice to do this atomically.
return (error);
}
+static const zfs_ioc_key_t zfs_keys_remap[] = {
+ /* no nvl keys */
+};
+
+/* ARGSUSED */
+static int
+zfs_ioc_remap(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
+{
+ if (strchr(fsname, '@') ||
+ strchr(fsname, '%'))
+ return (SET_ERROR(EINVAL));
+
+ return (dmu_objset_remap_indirects(fsname));
+}
+
/*
* innvl: {
* "snaps" -> { snapshot1, snapshot2 }
*
* outnvl: snapshot -> error code (int32)
*/
+static const zfs_ioc_key_t zfs_keys_snapshot[] = {
+ {"snaps", DATA_TYPE_NVLIST, 0},
+ {"props", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+};
+
static int
zfs_ioc_snapshot(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
{
nvlist_t *snaps;
nvlist_t *props = NULL;
int error, poollen;
- nvpair_t *pair, *pair2;
+ nvpair_t *pair;
(void) nvlist_lookup_nvlist(innvl, "props", &props);
if ((error = zfs_check_userprops(poolname, props)) != 0)
zfs_earlier_version(poolname, SPA_VERSION_SNAP_PROPS))
return (SET_ERROR(ENOTSUP));
- if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
- return (SET_ERROR(EINVAL));
+ snaps = fnvlist_lookup_nvlist(innvl, "snaps");
poollen = strlen(poolname);
for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
pair = nvlist_next_nvpair(snaps, pair)) {
return (SET_ERROR(EXDEV));
/* This must be the only snap of this fs. */
- for (pair2 = nvlist_next_nvpair(snaps, pair);
+ for (nvpair_t *pair2 = nvlist_next_nvpair(snaps, pair);
pair2 != NULL; pair2 = nvlist_next_nvpair(snaps, pair2)) {
if (strncmp(name, nvpair_name(pair2), cp - name + 1)
== 0) {
/*
* innvl: "message" -> string
*/
+static const zfs_ioc_key_t zfs_keys_log_history[] = {
+ {"message", DATA_TYPE_STRING, 0},
+};
+
/* ARGSUSED */
static int
zfs_ioc_log_history(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
if (error != 0)
return (error);
- if (nvlist_lookup_string(innvl, "message", &message) != 0) {
- spa_close(spa, FTAG);
- return (SET_ERROR(EINVAL));
- }
+ message = fnvlist_lookup_string(innvl, "message");
if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
spa_close(spa, FTAG);
* Returns 0 if the argument is not a snapshot, or it is not currently a
* filesystem, or we were able to unmount it. Returns error code otherwise.
*/
-int
+void
zfs_unmount_snap(const char *snapname)
{
- int err;
-
if (strchr(snapname, '@') == NULL)
- return (0);
-
- err = zfsctl_snapshot_unmount((char *)snapname, MNT_FORCE);
- if (err != 0 && err != ENOENT)
- return (SET_ERROR(err));
+ return;
- return (0);
+ (void) zfsctl_snapshot_unmount((char *)snapname, MNT_FORCE);
}
/* ARGSUSED */
static int
zfs_unmount_snap_cb(const char *snapname, void *arg)
{
- return (zfs_unmount_snap(snapname));
+ zfs_unmount_snap(snapname);
+ return (0);
}
/*
char originname[ZFS_MAX_DATASET_NAME_LEN];
dsl_dataset_name(ds->ds_prev, originname);
dmu_objset_rele(os, FTAG);
- (void) zfs_unmount_snap(originname);
+ zfs_unmount_snap(originname);
} else {
dmu_objset_rele(os, FTAG);
}
*
* outnvl: snapshot -> error code (int32)
*/
+static const zfs_ioc_key_t zfs_keys_destroy_snaps[] = {
+ {"snaps", DATA_TYPE_NVLIST, 0},
+ {"defer", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+};
+
/* ARGSUSED */
static int
zfs_ioc_destroy_snaps(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
nvpair_t *pair;
boolean_t defer;
- if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
- return (SET_ERROR(EINVAL));
+ snaps = fnvlist_lookup_nvlist(innvl, "snaps");
defer = nvlist_exists(innvl, "defer");
for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
pair = nvlist_next_nvpair(snaps, pair)) {
- (void) zfs_unmount_snap(nvpair_name(pair));
+ zfs_unmount_snap(nvpair_name(pair));
}
return (dsl_destroy_snapshots_nvl(snaps, defer, outnvl));
* outnvl: bookmark -> error code (int32)
*
*/
+static const zfs_ioc_key_t zfs_keys_bookmark[] = {
+ {"<bookmark>...", DATA_TYPE_STRING, ZK_WILDCARDLIST},
+};
+
/* ARGSUSED */
static int
zfs_ioc_bookmark(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
{
- nvpair_t *pair, *pair2;
-
- for (pair = nvlist_next_nvpair(innvl, NULL);
+ for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
char *snap_name;
/* Verify that the keys (bookmarks) are unique */
- for (pair2 = nvlist_next_nvpair(innvl, pair);
+ for (nvpair_t *pair2 = nvlist_next_nvpair(innvl, pair);
pair2 != NULL; pair2 = nvlist_next_nvpair(innvl, pair2)) {
if (strcmp(nvpair_name(pair), nvpair_name(pair2)) == 0)
return (SET_ERROR(EINVAL));
* }
*
*/
+static const zfs_ioc_key_t zfs_keys_get_bookmarks[] = {
+ {"<property>...", DATA_TYPE_BOOLEAN, ZK_WILDCARDLIST | ZK_OPTIONAL},
+};
+
static int
zfs_ioc_get_bookmarks(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
{
* outnvl: bookmark -> error code (int32)
*
*/
+static const zfs_ioc_key_t zfs_keys_destroy_bookmarks[] = {
+ {"<bookmark>...", DATA_TYPE_BOOLEAN, ZK_WILDCARDLIST},
+};
+
static int
zfs_ioc_destroy_bookmarks(const char *poolname, nvlist_t *innvl,
nvlist_t *outnvl)
{
int error, poollen;
- nvpair_t *pair;
poollen = strlen(poolname);
- for (pair = nvlist_next_nvpair(innvl, NULL);
+ for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
const char *name = nvpair_name(pair);
const char *cp = strchr(name, '#');
return (error);
}
+static const zfs_ioc_key_t zfs_keys_channel_program[] = {
+ {"program", DATA_TYPE_STRING, 0},
+ {"arg", DATA_TYPE_ANY, 0},
+ {"sync", DATA_TYPE_BOOLEAN_VALUE, ZK_OPTIONAL},
+ {"instrlimit", DATA_TYPE_UINT64, ZK_OPTIONAL},
+ {"memlimit", DATA_TYPE_UINT64, ZK_OPTIONAL},
+};
+
+static int
+zfs_ioc_channel_program(const char *poolname, nvlist_t *innvl,
+ nvlist_t *outnvl)
+{
+ char *program;
+ uint64_t instrlimit, memlimit;
+ boolean_t sync_flag;
+ nvpair_t *nvarg = NULL;
+
+ program = fnvlist_lookup_string(innvl, ZCP_ARG_PROGRAM);
+ if (0 != nvlist_lookup_boolean_value(innvl, ZCP_ARG_SYNC, &sync_flag)) {
+ sync_flag = B_TRUE;
+ }
+ if (0 != nvlist_lookup_uint64(innvl, ZCP_ARG_INSTRLIMIT, &instrlimit)) {
+ instrlimit = ZCP_DEFAULT_INSTRLIMIT;
+ }
+ if (0 != nvlist_lookup_uint64(innvl, ZCP_ARG_MEMLIMIT, &memlimit)) {
+ memlimit = ZCP_DEFAULT_MEMLIMIT;
+ }
+ nvarg = fnvlist_lookup_nvpair(innvl, ZCP_ARG_ARGLIST);
+
+ if (instrlimit == 0 || instrlimit > zfs_lua_max_instrlimit)
+ return (EINVAL);
+ if (memlimit == 0 || memlimit > zfs_lua_max_memlimit)
+ return (EINVAL);
+
+ return (zcp_eval(poolname, program, sync_flag, instrlimit, memlimit,
+ nvarg, outnvl));
+}
+
+/*
+ * innvl: unused
+ * outnvl: empty
+ */
+static const zfs_ioc_key_t zfs_keys_pool_checkpoint[] = {
+ /* no nvl keys */
+};
+
+/* ARGSUSED */
+static int
+zfs_ioc_pool_checkpoint(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
+{
+ return (spa_checkpoint(poolname));
+}
+
+/*
+ * innvl: unused
+ * outnvl: empty
+ */
+static const zfs_ioc_key_t zfs_keys_pool_discard_checkpoint[] = {
+ /* no nvl keys */
+};
+
+/* ARGSUSED */
+static int
+zfs_ioc_pool_discard_checkpoint(const char *poolname, nvlist_t *innvl,
+ nvlist_t *outnvl)
+{
+ return (spa_checkpoint_discard(poolname));
+}
+
/*
* inputs:
* zc_name name of dataset to destroy
- * zc_objset_type type of objset
* zc_defer_destroy mark for deferred destroy
*
* outputs: none
static int
zfs_ioc_destroy(zfs_cmd_t *zc)
{
+ objset_t *os;
+ dmu_objset_type_t ost;
int err;
- if (zc->zc_objset_type == DMU_OST_ZFS) {
- err = zfs_unmount_snap(zc->zc_name);
- if (err != 0)
- return (err);
- }
+ err = dmu_objset_hold(zc->zc_name, FTAG, &os);
+ if (err != 0)
+ return (err);
+ ost = dmu_objset_type(os);
+ dmu_objset_rele(os, FTAG);
+
+ if (ost == DMU_OST_ZFS)
+ zfs_unmount_snap(zc->zc_name);
if (strchr(zc->zc_name, '@')) {
err = dsl_destroy_snapshot(zc->zc_name, zc->zc_defer_destroy);
*/
char namebuf[ZFS_MAX_DATASET_NAME_LEN + 6];
- (void) snprintf(namebuf, sizeof (namebuf),
- "%s/%s", zc->zc_name, recv_clone_name);
+ if (snprintf(namebuf, sizeof (namebuf), "%s/%s",
+ zc->zc_name, recv_clone_name) >=
+ sizeof (namebuf))
+ return (SET_ERROR(EINVAL));
/*
* Try to remove the hidden child (%recv) and after
if (err == 0)
err = dsl_destroy_head(zc->zc_name);
else if (err == ENOENT)
- err = EEXIST;
+ err = SET_ERROR(EEXIST);
}
}
return (err);
}
+/*
+ * innvl: {
+ * "initialize_command" -> POOL_INITIALIZE_{CANCEL|START|SUSPEND} (uint64)
+ * "initialize_vdevs": { -> guids to initialize (nvlist)
+ * "vdev_path_1": vdev_guid_1, (uint64),
+ * "vdev_path_2": vdev_guid_2, (uint64),
+ * ...
+ * },
+ * }
+ *
+ * outnvl: {
+ * "initialize_vdevs": { -> initialization errors (nvlist)
+ * "vdev_path_1": errno, see function body for possible errnos (uint64)
+ * "vdev_path_2": errno, ... (uint64)
+ * ...
+ * }
+ * }
+ *
+ * EINVAL is returned for an unknown commands or if any of the provided vdev
+ * guids have be specified with a type other than uint64.
+ */
+static const zfs_ioc_key_t zfs_keys_pool_initialize[] = {
+ {ZPOOL_INITIALIZE_COMMAND, DATA_TYPE_UINT64, 0},
+ {ZPOOL_INITIALIZE_VDEVS, DATA_TYPE_NVLIST, 0}
+};
+
+static int
+zfs_ioc_pool_initialize(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
+{
+ uint64_t cmd_type;
+ if (nvlist_lookup_uint64(innvl, ZPOOL_INITIALIZE_COMMAND,
+ &cmd_type) != 0) {
+ return (SET_ERROR(EINVAL));
+ }
+
+ if (!(cmd_type == POOL_INITIALIZE_CANCEL ||
+ cmd_type == POOL_INITIALIZE_START ||
+ cmd_type == POOL_INITIALIZE_SUSPEND)) {
+ return (SET_ERROR(EINVAL));
+ }
+
+ nvlist_t *vdev_guids;
+ if (nvlist_lookup_nvlist(innvl, ZPOOL_INITIALIZE_VDEVS,
+ &vdev_guids) != 0) {
+ return (SET_ERROR(EINVAL));
+ }
+
+ for (nvpair_t *pair = nvlist_next_nvpair(vdev_guids, NULL);
+ pair != NULL; pair = nvlist_next_nvpair(vdev_guids, pair)) {
+ uint64_t vdev_guid;
+ if (nvpair_value_uint64(pair, &vdev_guid) != 0) {
+ return (SET_ERROR(EINVAL));
+ }
+ }
+
+ spa_t *spa;
+ int error = spa_open(poolname, &spa, FTAG);
+ if (error != 0)
+ return (error);
+
+ nvlist_t *vdev_errlist = fnvlist_alloc();
+ int total_errors = spa_vdev_initialize(spa, vdev_guids, cmd_type,
+ vdev_errlist);
+
+ if (fnvlist_size(vdev_errlist) > 0) {
+ fnvlist_add_nvlist(outnvl, ZPOOL_INITIALIZE_VDEVS,
+ vdev_errlist);
+ }
+ fnvlist_free(vdev_errlist);
+
+ spa_close(spa, FTAG);
+ return (total_errors > 0 ? EINVAL : 0);
+}
+
+/*
+ * innvl: {
+ * "trim_command" -> POOL_TRIM_{CANCEL|START|SUSPEND} (uint64)
+ * "trim_vdevs": { -> guids to TRIM (nvlist)
+ * "vdev_path_1": vdev_guid_1, (uint64),
+ * "vdev_path_2": vdev_guid_2, (uint64),
+ * ...
+ * },
+ * "trim_rate" -> Target TRIM rate in bytes/sec.
+ * "trim_secure" -> Set to request a secure TRIM.
+ * }
+ *
+ * outnvl: {
+ * "trim_vdevs": { -> TRIM errors (nvlist)
+ * "vdev_path_1": errno, see function body for possible errnos (uint64)
+ * "vdev_path_2": errno, ... (uint64)
+ * ...
+ * }
+ * }
+ *
+ * EINVAL is returned for an unknown commands or if any of the provided vdev
+ * guids have be specified with a type other than uint64.
+ */
+static const zfs_ioc_key_t zfs_keys_pool_trim[] = {
+ {ZPOOL_TRIM_COMMAND, DATA_TYPE_UINT64, 0},
+ {ZPOOL_TRIM_VDEVS, DATA_TYPE_NVLIST, 0},
+ {ZPOOL_TRIM_RATE, DATA_TYPE_UINT64, ZK_OPTIONAL},
+ {ZPOOL_TRIM_SECURE, DATA_TYPE_BOOLEAN_VALUE, ZK_OPTIONAL},
+};
+
+static int
+zfs_ioc_pool_trim(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
+{
+ uint64_t cmd_type;
+ if (nvlist_lookup_uint64(innvl, ZPOOL_TRIM_COMMAND, &cmd_type) != 0)
+ return (SET_ERROR(EINVAL));
+
+ if (!(cmd_type == POOL_TRIM_CANCEL ||
+ cmd_type == POOL_TRIM_START ||
+ cmd_type == POOL_TRIM_SUSPEND)) {
+ return (SET_ERROR(EINVAL));
+ }
+
+ nvlist_t *vdev_guids;
+ if (nvlist_lookup_nvlist(innvl, ZPOOL_TRIM_VDEVS, &vdev_guids) != 0)
+ return (SET_ERROR(EINVAL));
+
+ for (nvpair_t *pair = nvlist_next_nvpair(vdev_guids, NULL);
+ pair != NULL; pair = nvlist_next_nvpair(vdev_guids, pair)) {
+ uint64_t vdev_guid;
+ if (nvpair_value_uint64(pair, &vdev_guid) != 0) {
+ return (SET_ERROR(EINVAL));
+ }
+ }
+
+ /* Optional, defaults to maximum rate when not provided */
+ uint64_t rate;
+ if (nvlist_lookup_uint64(innvl, ZPOOL_TRIM_RATE, &rate) != 0)
+ rate = 0;
+
+ /* Optional, defaults to standard TRIM when not provided */
+ boolean_t secure;
+ if (nvlist_lookup_boolean_value(innvl, ZPOOL_TRIM_SECURE,
+ &secure) != 0) {
+ secure = B_FALSE;
+ }
+
+ spa_t *spa;
+ int error = spa_open(poolname, &spa, FTAG);
+ if (error != 0)
+ return (error);
+
+ nvlist_t *vdev_errlist = fnvlist_alloc();
+ int total_errors = spa_vdev_trim(spa, vdev_guids, cmd_type,
+ rate, !!zfs_trim_metaslab_skip, secure, vdev_errlist);
+
+ if (fnvlist_size(vdev_errlist) > 0)
+ fnvlist_add_nvlist(outnvl, ZPOOL_TRIM_VDEVS, vdev_errlist);
+
+ fnvlist_free(vdev_errlist);
+
+ spa_close(spa, FTAG);
+ return (total_errors > 0 ? EINVAL : 0);
+}
+
/*
* fsname is name of dataset to rollback (to most recent snapshot)
*
- * innvl is not used.
+ * innvl may contain name of expected target snapshot
*
* outnvl: "target" -> name of most recent snapshot
* }
*/
+static const zfs_ioc_key_t zfs_keys_rollback[] = {
+ {"target", DATA_TYPE_STRING, ZK_OPTIONAL},
+};
+
/* ARGSUSED */
static int
-zfs_ioc_rollback(const char *fsname, nvlist_t *args, nvlist_t *outnvl)
+zfs_ioc_rollback(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
{
- zfs_sb_t *zsb;
+ zfsvfs_t *zfsvfs;
+ zvol_state_t *zv;
+ char *target = NULL;
int error;
- if (get_zfs_sb(fsname, &zsb) == 0) {
- error = zfs_suspend_fs(zsb);
+ (void) nvlist_lookup_string(innvl, "target", &target);
+ if (target != NULL) {
+ const char *cp = strchr(target, '@');
+
+ /*
+ * The snap name must contain an @, and the part after it must
+ * contain only valid characters.
+ */
+ if (cp == NULL ||
+ zfs_component_namecheck(cp + 1, NULL, NULL) != 0)
+ return (SET_ERROR(EINVAL));
+ }
+
+ if (getzfsvfs(fsname, &zfsvfs) == 0) {
+ dsl_dataset_t *ds;
+
+ ds = dmu_objset_ds(zfsvfs->z_os);
+ error = zfs_suspend_fs(zfsvfs);
if (error == 0) {
int resume_err;
- error = dsl_dataset_rollback(fsname, zsb, outnvl);
- resume_err = zfs_resume_fs(zsb, fsname);
+ error = dsl_dataset_rollback(fsname, target, zfsvfs,
+ outnvl);
+ resume_err = zfs_resume_fs(zfsvfs, ds);
error = error ? error : resume_err;
}
- deactivate_super(zsb->z_sb);
+ deactivate_super(zfsvfs->z_sb);
+ } else if ((zv = zvol_suspend(fsname)) != NULL) {
+ error = dsl_dataset_rollback(fsname, target, zvol_tag(zv),
+ outnvl);
+ zvol_resume(zv);
} else {
- error = dsl_dataset_rollback(fsname, NULL, outnvl);
+ error = dsl_dataset_rollback(fsname, target, NULL, outnvl);
}
return (error);
}
{
const char *snapname = arg;
char *fullname;
- int error;
fullname = kmem_asprintf("%s@%s", fsname, snapname);
- error = zfs_unmount_snap(fullname);
+ zfs_unmount_snap(fullname);
strfree(fullname);
- return (error);
+ return (0);
}
/*
static int
zfs_ioc_rename(zfs_cmd_t *zc)
{
+ objset_t *os;
+ dmu_objset_type_t ost;
boolean_t recursive = zc->zc_cookie & 1;
char *at;
+ int err;
+ /* "zfs rename" from and to ...%recv datasets should both fail */
+ zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
- if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
- strchr(zc->zc_value, '%'))
+ if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0 ||
+ dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
+ strchr(zc->zc_name, '%') || strchr(zc->zc_value, '%'))
return (SET_ERROR(EINVAL));
+ err = dmu_objset_hold(zc->zc_name, FTAG, &os);
+ if (err != 0)
+ return (err);
+ ost = dmu_objset_type(os);
+ dmu_objset_rele(os, FTAG);
+
at = strchr(zc->zc_name, '@');
if (at != NULL) {
/* snaps must be in same fs */
if (strncmp(zc->zc_name, zc->zc_value, at - zc->zc_name + 1))
return (SET_ERROR(EXDEV));
*at = '\0';
- if (zc->zc_objset_type == DMU_OST_ZFS) {
+ if (ost == DMU_OST_ZFS) {
error = dmu_objset_find(zc->zc_name,
recursive_unmount, at + 1,
recursive ? DS_FIND_CHILDREN : 0);
zfs_userquota_prop_prefixes[ZFS_PROP_USEROBJQUOTA];
const char *giq_prefix =
zfs_userquota_prop_prefixes[ZFS_PROP_GROUPOBJQUOTA];
+ const char *pq_prefix =
+ zfs_userquota_prop_prefixes[ZFS_PROP_PROJECTQUOTA];
+ const char *piq_prefix = zfs_userquota_prop_prefixes[\
+ ZFS_PROP_PROJECTOBJQUOTA];
if (strncmp(propname, uq_prefix,
strlen(uq_prefix)) == 0) {
} else if (strncmp(propname, giq_prefix,
strlen(giq_prefix)) == 0) {
perm = ZFS_DELEG_PERM_GROUPOBJQUOTA;
+ } else if (strncmp(propname, pq_prefix,
+ strlen(pq_prefix)) == 0) {
+ perm = ZFS_DELEG_PERM_PROJECTQUOTA;
+ } else if (strncmp(propname, piq_prefix,
+ strlen(piq_prefix)) == 0) {
+ perm = ZFS_DELEG_PERM_PROJECTOBJQUOTA;
} else {
- /* USERUSED and GROUPUSED are read-only */
+ /* {USER|GROUP|PROJECT}USED are read-only */
return (SET_ERROR(EINVAL));
}
intval > SPA_OLD_MAXBLOCKSIZE) {
spa_t *spa;
- /*
- * If this is a bootable dataset then
- * we don't allow large (>128K) blocks,
- * because GRUB doesn't support them.
- */
- if (zfs_is_bootfs(dsname) &&
- intval > SPA_OLD_MAXBLOCKSIZE) {
- return (SET_ERROR(ERANGE));
- }
-
/*
* We don't allow setting the property above 1MB,
* unless the tunable has been changed.
}
break;
+ case ZFS_PROP_SPECIAL_SMALL_BLOCKS:
+ /*
+ * This property could require the allocation classes
+ * feature to be active for setting, however we allow
+ * it so that tests of settable properties succeed.
+ * The CLI will issue a warning in this case.
+ */
+ break;
+
case ZFS_PROP_SHARESMB:
if (zpl_earlier_version(dsname, ZPL_VERSION_FUID))
return (SET_ERROR(ENOTSUP));
{
spa_feature_t feature;
spa_t *spa;
- uint64_t intval;
int err;
/* dedup feature version checks */
zfs_earlier_version(dsname, SPA_VERSION_DEDUP))
return (SET_ERROR(ENOTSUP));
- if (nvpair_value_uint64(pair, &intval) != 0)
- return (SET_ERROR(EINVAL));
+ if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
+ nvpair_value_uint64(pair, &intval) == 0) {
+ /* check prop value is enabled in features */
+ feature = zio_checksum_to_feature(
+ intval & ZIO_CHECKSUM_MASK);
+ if (feature == SPA_FEATURE_NONE)
+ break;
- /* check prop value is enabled in features */
- feature = zio_checksum_to_feature(intval & ZIO_CHECKSUM_MASK);
- if (feature == SPA_FEATURE_NONE)
- break;
+ if ((err = spa_open(dsname, &spa, FTAG)) != 0)
+ return (err);
- if ((err = spa_open(dsname, &spa, FTAG)) != 0)
- return (err);
- /*
- * Salted checksums are not supported on root pools.
- */
- if (spa_bootfs(spa) != 0 &&
- intval < ZIO_CHECKSUM_FUNCTIONS &&
- (zio_checksum_table[intval].ci_flags &
- ZCHECKSUM_FLAG_SALTED)) {
- spa_close(spa, FTAG);
- return (SET_ERROR(ERANGE));
- }
- if (!spa_feature_is_enabled(spa, feature)) {
+ if (!spa_feature_is_enabled(spa, feature)) {
+ spa_close(spa, FTAG);
+ return (SET_ERROR(ENOTSUP));
+ }
spa_close(spa, FTAG);
- return (SET_ERROR(ENOTSUP));
}
- spa_close(spa, FTAG);
break;
}
{
nvlist_t *delayprops;
nvpair_t *nvp, *tmp;
- static const zfs_prop_t delayable[] = { ZFS_PROP_REFQUOTA, 0 };
+ static const zfs_prop_t delayable[] = {
+ ZFS_PROP_REFQUOTA,
+ ZFS_PROP_KEYLOCATION,
+ 0
+ };
int i;
VERIFY(nvlist_alloc(&delayprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
* encountered errors, if any. It's the callers responsibility to free.
*/
static int
-zfs_ioc_recv_impl(char *tofs, char *tosnap, char *origin,
- nvlist_t *props, boolean_t force, boolean_t resumable, int input_fd,
- dmu_replay_record_t *begin_record, int cleanup_fd, uint64_t *read_bytes,
- uint64_t *errflags, uint64_t *action_handle, nvlist_t **errors)
+zfs_ioc_recv_impl(char *tofs, char *tosnap, char *origin, nvlist_t *recvprops,
+ nvlist_t *localprops, nvlist_t *hidden_args, boolean_t force,
+ boolean_t resumable, int input_fd, dmu_replay_record_t *begin_record,
+ int cleanup_fd, uint64_t *read_bytes, uint64_t *errflags,
+ uint64_t *action_handle, nvlist_t **errors)
{
dmu_recv_cookie_t drc;
int error = 0;
int props_error = 0;
offset_t off;
- nvlist_t *delayprops = NULL; /* sent properties applied post-receive */
+ nvlist_t *local_delayprops = NULL;
+ nvlist_t *recv_delayprops = NULL;
nvlist_t *origprops = NULL; /* existing properties */
+ nvlist_t *origrecvd = NULL; /* existing received properties */
boolean_t first_recvd_props = B_FALSE;
file_t *input_fp;
if (input_fp == NULL)
return (SET_ERROR(EBADF));
- error = dmu_recv_begin(tofs, tosnap,
- begin_record, force, resumable, origin, &drc);
+ error = dmu_recv_begin(tofs, tosnap, begin_record, force,
+ resumable, localprops, hidden_args, origin, &drc);
if (error != 0)
goto out;
* to the new data. Note that we must call dmu_recv_stream() if
* dmu_recv_begin() succeeds.
*/
- if (props != NULL && !drc.drc_newfs) {
+ if (recvprops != NULL && !drc.drc_newfs) {
if (spa_version(dsl_dataset_get_spa(drc.drc_ds)) >=
SPA_VERSION_RECVD_PROPS &&
!dsl_prop_get_hasrecvd(tofs))
/*
* If new received properties are supplied, they are to
- * completely replace the existing received properties, so stash
- * away the existing ones.
+ * completely replace the existing received properties,
+ * so stash away the existing ones.
*/
- if (dsl_prop_get_received(tofs, &origprops) == 0) {
+ if (dsl_prop_get_received(tofs, &origrecvd) == 0) {
nvlist_t *errlist = NULL;
/*
* Don't bother writing a property if its value won't
* regardless.
*/
if (!first_recvd_props)
- props_reduce(props, origprops);
- if (zfs_check_clearable(tofs, origprops, &errlist) != 0)
+ props_reduce(recvprops, origrecvd);
+ if (zfs_check_clearable(tofs, origrecvd, &errlist) != 0)
(void) nvlist_merge(*errors, errlist, 0);
nvlist_free(errlist);
- if (clear_received_props(tofs, origprops,
- first_recvd_props ? NULL : props) != 0)
+ if (clear_received_props(tofs, origrecvd,
+ first_recvd_props ? NULL : recvprops) != 0)
*errflags |= ZPROP_ERR_NOCLEAR;
} else {
*errflags |= ZPROP_ERR_NOCLEAR;
}
}
- if (props != NULL) {
+ /*
+ * Stash away existing properties so we can restore them on error unless
+ * we're doing the first receive after SPA_VERSION_RECVD_PROPS, in which
+ * case "origrecvd" will take care of that.
+ */
+ if (localprops != NULL && !drc.drc_newfs && !first_recvd_props) {
+ objset_t *os;
+ if (dmu_objset_hold(tofs, FTAG, &os) == 0) {
+ if (dsl_prop_get_all(os, &origprops) != 0) {
+ *errflags |= ZPROP_ERR_NOCLEAR;
+ }
+ dmu_objset_rele(os, FTAG);
+ } else {
+ *errflags |= ZPROP_ERR_NOCLEAR;
+ }
+ }
+
+ if (recvprops != NULL) {
props_error = dsl_prop_set_hasrecvd(tofs);
if (props_error == 0) {
- delayprops = extract_delay_props(props);
+ recv_delayprops = extract_delay_props(recvprops);
(void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_RECEIVED,
- props, *errors);
+ recvprops, *errors);
}
}
+ if (localprops != NULL) {
+ nvlist_t *oprops = fnvlist_alloc();
+ nvlist_t *xprops = fnvlist_alloc();
+ nvpair_t *nvp = NULL;
+
+ while ((nvp = nvlist_next_nvpair(localprops, nvp)) != NULL) {
+ if (nvpair_type(nvp) == DATA_TYPE_BOOLEAN) {
+ /* -x property */
+ const char *name = nvpair_name(nvp);
+ zfs_prop_t prop = zfs_name_to_prop(name);
+ if (prop != ZPROP_INVAL) {
+ if (!zfs_prop_inheritable(prop))
+ continue;
+ } else if (!zfs_prop_user(name))
+ continue;
+ fnvlist_add_boolean(xprops, name);
+ } else {
+ /* -o property=value */
+ fnvlist_add_nvpair(oprops, nvp);
+ }
+ }
+
+ local_delayprops = extract_delay_props(oprops);
+ (void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_LOCAL,
+ oprops, *errors);
+ (void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_INHERITED,
+ xprops, *errors);
+
+ nvlist_free(oprops);
+ nvlist_free(xprops);
+ }
+
off = input_fp->f_offset;
error = dmu_recv_stream(&drc, input_fp->f_vnode, &off, cleanup_fd,
action_handle);
if (error == 0) {
- zfs_sb_t *zsb = NULL;
+ zfsvfs_t *zfsvfs = NULL;
+ zvol_state_t *zv = NULL;
- if (get_zfs_sb(tofs, &zsb) == 0) {
+ if (getzfsvfs(tofs, &zfsvfs) == 0) {
/* online recv */
+ dsl_dataset_t *ds;
int end_err;
- error = zfs_suspend_fs(zsb);
+ ds = dmu_objset_ds(zfsvfs->z_os);
+ error = zfs_suspend_fs(zfsvfs);
/*
* If the suspend fails, then the recv_end will
* likely also fail, and clean up after itself.
*/
- end_err = dmu_recv_end(&drc, zsb);
+ end_err = dmu_recv_end(&drc, zfsvfs);
if (error == 0)
- error = zfs_resume_fs(zsb, tofs);
+ error = zfs_resume_fs(zfsvfs, ds);
error = error ? error : end_err;
- deactivate_super(zsb->z_sb);
+ deactivate_super(zfsvfs->z_sb);
+ } else if ((zv = zvol_suspend(tofs)) != NULL) {
+ error = dmu_recv_end(&drc, zvol_tag(zv));
+ zvol_resume(zv);
} else {
error = dmu_recv_end(&drc, NULL);
}
/* Set delayed properties now, after we're done receiving. */
- if (delayprops != NULL && error == 0) {
+ if (recv_delayprops != NULL && error == 0) {
(void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_RECEIVED,
- delayprops, *errors);
+ recv_delayprops, *errors);
+ }
+ if (local_delayprops != NULL && error == 0) {
+ (void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_LOCAL,
+ local_delayprops, *errors);
}
}
- if (delayprops != NULL) {
- /*
- * Merge delayed props back in with initial props, in case
- * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
- * we have to make sure clear_received_props() includes
- * the delayed properties).
- *
- * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
- * using ASSERT() will be just like a VERIFY.
- */
- ASSERT(nvlist_merge(props, delayprops, 0) == 0);
- nvlist_free(delayprops);
+ /*
+ * Merge delayed props back in with initial props, in case
+ * we're DEBUG and zfs_ioc_recv_inject_err is set (which means
+ * we have to make sure clear_received_props() includes
+ * the delayed properties).
+ *
+ * Since zfs_ioc_recv_inject_err is only in DEBUG kernels,
+ * using ASSERT() will be just like a VERIFY.
+ */
+ if (recv_delayprops != NULL) {
+ ASSERT(nvlist_merge(recvprops, recv_delayprops, 0) == 0);
+ nvlist_free(recv_delayprops);
+ }
+ if (local_delayprops != NULL) {
+ ASSERT(nvlist_merge(localprops, local_delayprops, 0) == 0);
+ nvlist_free(local_delayprops);
}
-
*read_bytes = off - input_fp->f_offset;
if (VOP_SEEK(input_fp->f_vnode, input_fp->f_offset, &off, NULL) == 0)
/*
* On error, restore the original props.
*/
- if (error != 0 && props != NULL && !drc.drc_newfs) {
- if (clear_received_props(tofs, props, NULL) != 0) {
+ if (error != 0 && recvprops != NULL && !drc.drc_newfs) {
+ if (clear_received_props(tofs, recvprops, NULL) != 0) {
/*
* We failed to clear the received properties.
* Since we may have left a $recvd value on the
dsl_prop_unset_hasrecvd(tofs);
}
- if (origprops == NULL && !drc.drc_newfs) {
+ if (origrecvd == NULL && !drc.drc_newfs) {
/* We failed to stash the original properties. */
*errflags |= ZPROP_ERR_NORESTORE;
}
* explicitly if we're restoring local properties cleared in the
* first new-style receive.
*/
- if (origprops != NULL &&
+ if (origrecvd != NULL &&
zfs_set_prop_nvlist(tofs, (first_recvd_props ?
ZPROP_SRC_LOCAL : ZPROP_SRC_RECEIVED),
- origprops, NULL) != 0) {
+ origrecvd, NULL) != 0) {
/*
* We stashed the original properties but failed to
* restore them.
*errflags |= ZPROP_ERR_NORESTORE;
}
}
+ if (error != 0 && localprops != NULL && !drc.drc_newfs &&
+ !first_recvd_props) {
+ nvlist_t *setprops;
+ nvlist_t *inheritprops;
+ nvpair_t *nvp;
+
+ if (origprops == NULL) {
+ /* We failed to stash the original properties. */
+ *errflags |= ZPROP_ERR_NORESTORE;
+ goto out;
+ }
+
+ /* Restore original props */
+ setprops = fnvlist_alloc();
+ inheritprops = fnvlist_alloc();
+ nvp = NULL;
+ while ((nvp = nvlist_next_nvpair(localprops, nvp)) != NULL) {
+ const char *name = nvpair_name(nvp);
+ const char *source;
+ nvlist_t *attrs;
+
+ if (!nvlist_exists(origprops, name)) {
+ /*
+ * Property was not present or was explicitly
+ * inherited before the receive, restore this.
+ */
+ fnvlist_add_boolean(inheritprops, name);
+ continue;
+ }
+ attrs = fnvlist_lookup_nvlist(origprops, name);
+ source = fnvlist_lookup_string(attrs, ZPROP_SOURCE);
+
+ /* Skip received properties */
+ if (strcmp(source, ZPROP_SOURCE_VAL_RECVD) == 0)
+ continue;
+
+ if (strcmp(source, tofs) == 0) {
+ /* Property was locally set */
+ fnvlist_add_nvlist(setprops, name, attrs);
+ } else {
+ /* Property was implicitly inherited */
+ fnvlist_add_boolean(inheritprops, name);
+ }
+ }
+
+ if (zfs_set_prop_nvlist(tofs, ZPROP_SRC_LOCAL, setprops,
+ NULL) != 0)
+ *errflags |= ZPROP_ERR_NORESTORE;
+ if (zfs_set_prop_nvlist(tofs, ZPROP_SRC_INHERITED, inheritprops,
+ NULL) != 0)
+ *errflags |= ZPROP_ERR_NORESTORE;
+
+ nvlist_free(setprops);
+ nvlist_free(inheritprops);
+ }
out:
releasef(input_fd);
+ nvlist_free(origrecvd);
nvlist_free(origprops);
if (error == 0)
* inputs:
* zc_name name of containing filesystem (unused)
* zc_nvlist_src{_size} nvlist of properties to apply
+ * zc_nvlist_conf{_size} nvlist of properties to exclude
+ * (DATA_TYPE_BOOLEAN) and override (everything else)
* zc_value name of snapshot to create
* zc_string name of clone origin (if DRR_FLAG_CLONE)
* zc_cookie file descriptor to recv from
{
dmu_replay_record_t begin_record;
nvlist_t *errors = NULL;
- nvlist_t *props = NULL;
+ nvlist_t *recvdprops = NULL;
+ nvlist_t *localprops = NULL;
char *origin = NULL;
char *tosnap;
char tofs[ZFS_MAX_DATASET_NAME_LEN];
if (zc->zc_nvlist_src != 0 &&
(error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
- zc->zc_iflags, &props)) != 0)
+ zc->zc_iflags, &recvdprops)) != 0)
+ return (error);
+
+ if (zc->zc_nvlist_conf != 0 &&
+ (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
+ zc->zc_iflags, &localprops)) != 0)
return (error);
if (zc->zc_string[0])
begin_record.drr_payloadlen = 0;
begin_record.drr_u.drr_begin = zc->zc_begin_record;
- error = zfs_ioc_recv_impl(tofs, tosnap, origin, props, zc->zc_guid,
- B_FALSE, zc->zc_cookie, &begin_record, zc->zc_cleanup_fd,
- &zc->zc_cookie, &zc->zc_obj, &zc->zc_action_handle, &errors);
- nvlist_free(props);
+ error = zfs_ioc_recv_impl(tofs, tosnap, origin, recvdprops, localprops,
+ NULL, zc->zc_guid, B_FALSE, zc->zc_cookie, &begin_record,
+ zc->zc_cleanup_fd, &zc->zc_cookie, &zc->zc_obj,
+ &zc->zc_action_handle, &errors);
+ nvlist_free(recvdprops);
+ nvlist_free(localprops);
/*
* Now that all props, initial and delayed, are set, report the prop
/*
* innvl: {
* "snapname" -> full name of the snapshot to create
- * (optional) "props" -> properties to set (nvlist)
+ * (optional) "props" -> received properties to set (nvlist)
+ * (optional) "localprops" -> override and exclude properties (nvlist)
* (optional) "origin" -> name of clone origin (DRR_FLAG_CLONE)
* "begin_record" -> non-byteswapped dmu_replay_record_t
* "input_fd" -> file descriptor to read stream from (int32)
* (optional) "resumable" -> resumable flag (value ignored)
* (optional) "cleanup_fd" -> cleanup-on-exit file descriptor
* (optional) "action_handle" -> handle for this guid/ds mapping
+ * (optional) "hidden_args" -> { "wkeydata" -> value }
* }
*
* outnvl: {
* "errors" -> error for each unapplied received property (nvlist)
* }
*/
+static const zfs_ioc_key_t zfs_keys_recv_new[] = {
+ {"snapname", DATA_TYPE_STRING, 0},
+ {"props", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+ {"localprops", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+ {"origin", DATA_TYPE_STRING, ZK_OPTIONAL},
+ {"begin_record", DATA_TYPE_BYTE_ARRAY, 0},
+ {"input_fd", DATA_TYPE_INT32, 0},
+ {"force", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"resumable", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"cleanup_fd", DATA_TYPE_INT32, ZK_OPTIONAL},
+ {"action_handle", DATA_TYPE_UINT64, ZK_OPTIONAL},
+ {"hidden_args", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+};
+
static int
zfs_ioc_recv_new(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
{
dmu_replay_record_t *begin_record;
uint_t begin_record_size;
nvlist_t *errors = NULL;
- nvlist_t *props = NULL;
- char *snapname = NULL;
+ nvlist_t *recvprops = NULL;
+ nvlist_t *localprops = NULL;
+ nvlist_t *hidden_args = NULL;
+ char *snapname;
char *origin = NULL;
char *tosnap;
char tofs[ZFS_MAX_DATASET_NAME_LEN];
int cleanup_fd = -1;
int error;
- error = nvlist_lookup_string(innvl, "snapname", &snapname);
- if (error != 0)
- return (SET_ERROR(EINVAL));
+ snapname = fnvlist_lookup_string(innvl, "snapname");
if (dataset_namecheck(snapname, NULL, NULL) != 0 ||
strchr(snapname, '@') == NULL ||
if (error != 0 || begin_record_size != sizeof (*begin_record))
return (SET_ERROR(EINVAL));
- error = nvlist_lookup_int32(innvl, "input_fd", &input_fd);
- if (error != 0)
- return (SET_ERROR(EINVAL));
+ input_fd = fnvlist_lookup_int32(innvl, "input_fd");
force = nvlist_exists(innvl, "force");
resumable = nvlist_exists(innvl, "resumable");
if (error && error != ENOENT)
return (error);
- error = nvlist_lookup_nvlist(innvl, "props", &props);
+ /* we still use "props" here for backwards compatibility */
+ error = nvlist_lookup_nvlist(innvl, "props", &recvprops);
if (error && error != ENOENT)
return (error);
- error = zfs_ioc_recv_impl(tofs, tosnap, origin, props, force,
- resumable, input_fd, begin_record, cleanup_fd, &read_bytes,
- &errflags, &action_handle, &errors);
+ error = nvlist_lookup_nvlist(innvl, "localprops", &localprops);
+ if (error && error != ENOENT)
+ return (error);
+
+ error = nvlist_lookup_nvlist(innvl, ZPOOL_HIDDEN_ARGS, &hidden_args);
+ if (error && error != ENOENT)
+ return (error);
+
+ error = zfs_ioc_recv_impl(tofs, tosnap, origin, recvprops, localprops,
+ hidden_args, force, resumable, input_fd, begin_record, cleanup_fd,
+ &read_bytes, &errflags, &action_handle, &errors);
fnvlist_add_uint64(outnvl, "read_bytes", read_bytes);
fnvlist_add_uint64(outnvl, "error_flags", errflags);
fnvlist_add_nvlist(outnvl, "errors", errors);
nvlist_free(errors);
- nvlist_free(props);
+ nvlist_free(recvprops);
+ nvlist_free(localprops);
return (error);
}
*
* outputs:
* zc_objset_type estimated size, if zc_guid is set
+ *
+ * NOTE: This is no longer the preferred interface, any new functionality
+ * should be added to zfs_ioc_send_new() instead.
*/
static int
zfs_ioc_send(zfs_cmd_t *zc)
boolean_t embedok = (zc->zc_flags & 0x1);
boolean_t large_block_ok = (zc->zc_flags & 0x2);
boolean_t compressok = (zc->zc_flags & 0x4);
+ boolean_t rawok = (zc->zc_flags & 0x8);
if (zc->zc_obj != 0) {
dsl_pool_t *dp;
if (error != 0)
return (error);
- error = dsl_dataset_hold_obj(dp, zc->zc_sendobj, FTAG, &tosnap);
+ error = dsl_dataset_hold_obj(dp, zc->zc_sendobj,
+ FTAG, &tosnap);
if (error != 0) {
dsl_pool_rele(dp, FTAG);
return (error);
}
}
- error = dmu_send_estimate(tosnap, fromsnap, compressok,
+ error = dmu_send_estimate(tosnap, fromsnap, compressok || rawok,
&zc->zc_objset_type);
if (fromsnap != NULL)
off = fp->f_offset;
error = dmu_send_obj(zc->zc_name, zc->zc_sendobj,
- zc->zc_fromobj, embedok, large_block_ok, compressok,
+ zc->zc_fromobj, embedok, large_block_ok, compressok, rawok,
zc->zc_cookie, fp->f_vnode, &off);
if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
if (error != 0)
return (error);
+ /*
+ * If multihost is enabled, resuming I/O is unsafe as another
+ * host may have imported the pool.
+ */
+ if (spa_multihost(spa) && spa_suspended(spa))
+ return (SET_ERROR(EINVAL));
+
spa_vdev_state_enter(spa, SCL_NONE);
if (zc->zc_guid == 0) {
vdev_clear(spa, vd);
- (void) spa_vdev_state_exit(spa, NULL, 0);
+ (void) spa_vdev_state_exit(spa, spa_suspended(spa) ?
+ NULL : spa->spa_root_vdev, 0);
/*
* Resume any suspended I/Os.
return (error);
}
+/*
+ * Reopen all the vdevs associated with the pool.
+ *
+ * innvl: {
+ * "scrub_restart" -> when true and scrub is running, allow to restart
+ * scrub as the side effect of the reopen (boolean).
+ * }
+ *
+ * outnvl is unused
+ */
+static const zfs_ioc_key_t zfs_keys_pool_reopen[] = {
+ {"scrub_restart", DATA_TYPE_BOOLEAN_VALUE, 0},
+};
+
+/* ARGSUSED */
static int
-zfs_ioc_pool_reopen(zfs_cmd_t *zc)
+zfs_ioc_pool_reopen(const char *pool, nvlist_t *innvl, nvlist_t *outnvl)
{
spa_t *spa;
int error;
+ boolean_t scrub_restart = B_TRUE;
- error = spa_open(zc->zc_name, &spa, FTAG);
+ if (innvl) {
+ scrub_restart = fnvlist_lookup_boolean_value(innvl,
+ "scrub_restart");
+ }
+
+ error = spa_open(pool, &spa, FTAG);
if (error != 0)
return (error);
spa_vdev_state_enter(spa, SCL_NONE);
/*
- * If a resilver is already in progress then set the
- * spa_scrub_reopen flag to B_TRUE so that we don't restart
- * the scan as a side effect of the reopen. Otherwise, let
- * vdev_open() decided if a resilver is required.
+ * If the scrub_restart flag is B_FALSE and a scrub is already
+ * in progress then set spa_scrub_reopen flag to B_TRUE so that
+ * we don't restart the scrub as a side effect of the reopen.
+ * Otherwise, let vdev_open() decided if a resilver is required.
*/
- spa->spa_scrub_reopen = dsl_scan_resilvering(spa->spa_dsl_pool);
+
+ spa->spa_scrub_reopen = (!scrub_restart &&
+ dsl_scan_scrubbing(spa->spa_dsl_pool));
vdev_reopen(spa->spa_root_vdev);
spa->spa_scrub_reopen = B_FALSE;
- (void) spa_vdev_state_exit(spa, NULL, 0);
- spa_close(spa, FTAG);
- return (0);
-}
-/*
- * inputs:
- * zc_name name of filesystem
- * zc_value name of origin snapshot
- *
- * outputs:
- * zc_string name of conflicting snapshot, if there is one
- */
-static int
-zfs_ioc_promote(zfs_cmd_t *zc)
-{
- char *cp;
+ (void) spa_vdev_state_exit(spa, NULL, 0);
+ spa_close(spa, FTAG);
+ return (0);
+}
+
+/*
+ * inputs:
+ * zc_name name of filesystem
+ *
+ * outputs:
+ * zc_string name of conflicting snapshot, if there is one
+ */
+static int
+zfs_ioc_promote(zfs_cmd_t *zc)
+{
+ dsl_pool_t *dp;
+ dsl_dataset_t *ds, *ods;
+ char origin[ZFS_MAX_DATASET_NAME_LEN];
+ char *cp;
+ int error;
+
+ zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
+ if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0 ||
+ strchr(zc->zc_name, '%'))
+ return (SET_ERROR(EINVAL));
+
+ error = dsl_pool_hold(zc->zc_name, FTAG, &dp);
+ if (error != 0)
+ return (error);
+
+ error = dsl_dataset_hold(dp, zc->zc_name, FTAG, &ds);
+ if (error != 0) {
+ dsl_pool_rele(dp, FTAG);
+ return (error);
+ }
+
+ if (!dsl_dir_is_clone(ds->ds_dir)) {
+ dsl_dataset_rele(ds, FTAG);
+ dsl_pool_rele(dp, FTAG);
+ return (SET_ERROR(EINVAL));
+ }
+
+ error = dsl_dataset_hold_obj(dp,
+ dsl_dir_phys(ds->ds_dir)->dd_origin_obj, FTAG, &ods);
+ if (error != 0) {
+ dsl_dataset_rele(ds, FTAG);
+ dsl_pool_rele(dp, FTAG);
+ return (error);
+ }
+
+ dsl_dataset_name(ods, origin);
+ dsl_dataset_rele(ods, FTAG);
+ dsl_dataset_rele(ds, FTAG);
+ dsl_pool_rele(dp, FTAG);
/*
* We don't need to unmount *all* the origin fs's snapshots, but
* it's easier.
*/
- cp = strchr(zc->zc_value, '@');
+ cp = strchr(origin, '@');
if (cp)
*cp = '\0';
- (void) dmu_objset_find(zc->zc_value,
+ (void) dmu_objset_find(origin,
zfs_unmount_snap_cb, NULL, DS_FIND_SNAPSHOTS);
return (dsl_dataset_promote(zc->zc_name, zc->zc_string));
}
/*
- * Retrieve a single {user|group}{used|quota}@... property.
+ * Retrieve a single {user|group|project}{used|quota}@... property.
*
* inputs:
* zc_name name of filesystem
static int
zfs_ioc_userspace_one(zfs_cmd_t *zc)
{
- zfs_sb_t *zsb;
+ zfsvfs_t *zfsvfs;
int error;
if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
return (SET_ERROR(EINVAL));
- error = zfs_sb_hold(zc->zc_name, FTAG, &zsb, B_FALSE);
+ error = zfsvfs_hold(zc->zc_name, FTAG, &zfsvfs, B_FALSE);
if (error != 0)
return (error);
- error = zfs_userspace_one(zsb,
+ error = zfs_userspace_one(zfsvfs,
zc->zc_objset_type, zc->zc_value, zc->zc_guid, &zc->zc_cookie);
- zfs_sb_rele(zsb, FTAG);
+ zfsvfs_rele(zfsvfs, FTAG);
return (error);
}
static int
zfs_ioc_userspace_many(zfs_cmd_t *zc)
{
- zfs_sb_t *zsb;
+ zfsvfs_t *zfsvfs;
int bufsize = zc->zc_nvlist_dst_size;
- int error;
- void *buf;
if (bufsize <= 0)
return (SET_ERROR(ENOMEM));
- error = zfs_sb_hold(zc->zc_name, FTAG, &zsb, B_FALSE);
+ int error = zfsvfs_hold(zc->zc_name, FTAG, &zfsvfs, B_FALSE);
if (error != 0)
return (error);
- buf = vmem_alloc(bufsize, KM_SLEEP);
+ void *buf = vmem_alloc(bufsize, KM_SLEEP);
- error = zfs_userspace_many(zsb, zc->zc_objset_type, &zc->zc_cookie,
+ error = zfs_userspace_many(zfsvfs, zc->zc_objset_type, &zc->zc_cookie,
buf, &zc->zc_nvlist_dst_size);
if (error == 0) {
zc->zc_nvlist_dst_size);
}
vmem_free(buf, bufsize);
- zfs_sb_rele(zsb, FTAG);
+ zfsvfs_rele(zfsvfs, FTAG);
return (error);
}
{
objset_t *os;
int error = 0;
- zfs_sb_t *zsb;
+ zfsvfs_t *zfsvfs;
- if (get_zfs_sb(zc->zc_name, &zsb) == 0) {
- if (!dmu_objset_userused_enabled(zsb->z_os)) {
+ if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
+ if (!dmu_objset_userused_enabled(zfsvfs->z_os)) {
/*
* If userused is not enabled, it may be because the
* objset needs to be closed & reopened (to grow the
* objset_phys_t). Suspend/resume the fs will do that.
*/
- error = zfs_suspend_fs(zsb);
+ dsl_dataset_t *ds, *newds;
+
+ ds = dmu_objset_ds(zfsvfs->z_os);
+ error = zfs_suspend_fs(zfsvfs);
if (error == 0) {
- dmu_objset_refresh_ownership(zsb->z_os,
- zsb);
- error = zfs_resume_fs(zsb, zc->zc_name);
+ dmu_objset_refresh_ownership(ds, &newds,
+ B_TRUE, zfsvfs);
+ error = zfs_resume_fs(zfsvfs, newds);
}
}
if (error == 0)
- error = dmu_objset_userspace_upgrade(zsb->z_os);
- deactivate_super(zsb->z_sb);
+ error = dmu_objset_userspace_upgrade(zfsvfs->z_os);
+ deactivate_super(zfsvfs->z_sb);
} else {
/* XXX kind of reading contents without owning */
- error = dmu_objset_hold(zc->zc_name, FTAG, &os);
+ error = dmu_objset_hold_flags(zc->zc_name, B_TRUE, FTAG, &os);
if (error != 0)
return (error);
error = dmu_objset_userspace_upgrade(os);
- dmu_objset_rele(os, FTAG);
+ dmu_objset_rele_flags(os, B_TRUE, FTAG);
}
return (error);
* none
*/
static int
-zfs_ioc_userobjspace_upgrade(zfs_cmd_t *zc)
+zfs_ioc_id_quota_upgrade(zfs_cmd_t *zc)
{
objset_t *os;
int error;
- error = dmu_objset_hold(zc->zc_name, FTAG, &os);
+ error = dmu_objset_hold_flags(zc->zc_name, B_TRUE, FTAG, &os);
if (error != 0)
return (error);
- dsl_dataset_long_hold(dmu_objset_ds(os), FTAG);
- dsl_pool_rele(dmu_objset_pool(os), FTAG);
-
- if (dmu_objset_userobjspace_upgradable(os)) {
+ if (dmu_objset_userobjspace_upgradable(os) ||
+ dmu_objset_projectquota_upgradable(os)) {
mutex_enter(&os->os_upgrade_lock);
if (os->os_upgrade_id == 0) {
/* clear potential error code and retry */
os->os_upgrade_status = 0;
mutex_exit(&os->os_upgrade_lock);
- dmu_objset_userobjspace_upgrade(os);
+ dmu_objset_id_quota_upgrade(os);
} else {
mutex_exit(&os->os_upgrade_lock);
}
+ dsl_pool_rele(dmu_objset_pool(os), FTAG);
+
taskq_wait_id(os->os_spa->spa_upgrade_taskq, os->os_upgrade_id);
error = os->os_upgrade_status;
+ } else {
+ dsl_pool_rele(dmu_objset_pool(os), FTAG);
}
- dsl_dataset_long_rele(dmu_objset_ds(os), FTAG);
- dsl_dataset_rele(dmu_objset_ds(os), FTAG);
+ dsl_dataset_rele_flags(dmu_objset_ds(os), DS_HOLD_FLAG_DECRYPT, FTAG);
return (error);
}
return (error);
}
-/*
- * Remove all ACL files in shares dir
- */
-#ifdef HAVE_SMB_SHARE
-static int
-zfs_smb_acl_purge(znode_t *dzp)
-{
- zap_cursor_t zc;
- zap_attribute_t zap;
- zfs_sb_t *zsb = ZTOZSB(dzp);
- int error;
-
- for (zap_cursor_init(&zc, zsb->z_os, dzp->z_id);
- (error = zap_cursor_retrieve(&zc, &zap)) == 0;
- zap_cursor_advance(&zc)) {
- if ((error = VOP_REMOVE(ZTOV(dzp), zap.za_name, kcred,
- NULL, 0)) != 0)
- break;
- }
- zap_cursor_fini(&zc);
- return (error);
-}
-#endif /* HAVE_SMB_SHARE */
-
static int
zfs_ioc_smb_acl(zfs_cmd_t *zc)
{
-#ifdef HAVE_SMB_SHARE
- vnode_t *vp;
- znode_t *dzp;
- vnode_t *resourcevp = NULL;
- znode_t *sharedir;
- zfs_sb_t *zsb;
- nvlist_t *nvlist;
- char *src, *target;
- vattr_t vattr;
- vsecattr_t vsec;
- int error = 0;
-
- if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
- NO_FOLLOW, NULL, &vp)) != 0)
- return (error);
-
- /* Now make sure mntpnt and dataset are ZFS */
-
- if (vp->v_vfsp->vfs_fstype != zfsfstype ||
- (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
- zc->zc_name) != 0)) {
- VN_RELE(vp);
- return (SET_ERROR(EINVAL));
- }
-
- dzp = VTOZ(vp);
- zsb = ZTOZSB(dzp);
- ZFS_ENTER(zsb);
-
- /*
- * Create share dir if its missing.
- */
- mutex_enter(&zsb->z_lock);
- if (zsb->z_shares_dir == 0) {
- dmu_tx_t *tx;
-
- tx = dmu_tx_create(zsb->z_os);
- dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, TRUE,
- ZFS_SHARES_DIR);
- dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
- error = dmu_tx_assign(tx, TXG_WAIT);
- if (error != 0) {
- dmu_tx_abort(tx);
- } else {
- error = zfs_create_share_dir(zsb, tx);
- dmu_tx_commit(tx);
- }
- if (error != 0) {
- mutex_exit(&zsb->z_lock);
- VN_RELE(vp);
- ZFS_EXIT(zsb);
- return (error);
- }
- }
- mutex_exit(&zsb->z_lock);
-
- ASSERT(zsb->z_shares_dir);
- if ((error = zfs_zget(zsb, zsb->z_shares_dir, &sharedir)) != 0) {
- VN_RELE(vp);
- ZFS_EXIT(zsb);
- return (error);
- }
-
- switch (zc->zc_cookie) {
- case ZFS_SMB_ACL_ADD:
- vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
- vattr.va_mode = S_IFREG|0777;
- vattr.va_uid = 0;
- vattr.va_gid = 0;
-
- vsec.vsa_mask = VSA_ACE;
- vsec.vsa_aclentp = &full_access;
- vsec.vsa_aclentsz = sizeof (full_access);
- vsec.vsa_aclcnt = 1;
-
- error = VOP_CREATE(ZTOV(sharedir), zc->zc_string,
- &vattr, EXCL, 0, &resourcevp, kcred, 0, NULL, &vsec);
- if (resourcevp)
- VN_RELE(resourcevp);
- break;
-
- case ZFS_SMB_ACL_REMOVE:
- error = VOP_REMOVE(ZTOV(sharedir), zc->zc_string, kcred,
- NULL, 0);
- break;
-
- case ZFS_SMB_ACL_RENAME:
- if ((error = get_nvlist(zc->zc_nvlist_src,
- zc->zc_nvlist_src_size, zc->zc_iflags, &nvlist)) != 0) {
- VN_RELE(vp);
- VN_RELE(ZTOV(sharedir));
- ZFS_EXIT(zsb);
- return (error);
- }
- if (nvlist_lookup_string(nvlist, ZFS_SMB_ACL_SRC, &src) ||
- nvlist_lookup_string(nvlist, ZFS_SMB_ACL_TARGET,
- &target)) {
- VN_RELE(vp);
- VN_RELE(ZTOV(sharedir));
- ZFS_EXIT(zsb);
- nvlist_free(nvlist);
- return (error);
- }
- error = VOP_RENAME(ZTOV(sharedir), src, ZTOV(sharedir), target,
- kcred, NULL, 0);
- nvlist_free(nvlist);
- break;
-
- case ZFS_SMB_ACL_PURGE:
- error = zfs_smb_acl_purge(sharedir);
- break;
-
- default:
- error = SET_ERROR(EINVAL);
- break;
- }
-
- VN_RELE(vp);
- VN_RELE(ZTOV(sharedir));
-
- ZFS_EXIT(zsb);
-
- return (error);
-#else
return (SET_ERROR(ENOTSUP));
-#endif /* HAVE_SMB_SHARE */
}
/*
* ...
* }
*/
+static const zfs_ioc_key_t zfs_keys_hold[] = {
+ {"holds", DATA_TYPE_NVLIST, 0},
+ {"cleanup_fd", DATA_TYPE_INT32, ZK_OPTIONAL},
+};
+
/* ARGSUSED */
static int
zfs_ioc_hold(const char *pool, nvlist_t *args, nvlist_t *errlist)
int error;
minor_t minor = 0;
- error = nvlist_lookup_nvlist(args, "holds", &holds);
- if (error != 0)
- return (SET_ERROR(EINVAL));
+ holds = fnvlist_lookup_nvlist(args, "holds");
/* make sure the user didn't pass us any invalid (empty) tags */
for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
* ...
* }
*/
+static const zfs_ioc_key_t zfs_keys_get_holds[] = {
+ /* no nvl keys */
+};
+
/* ARGSUSED */
static int
zfs_ioc_get_holds(const char *snapname, nvlist_t *args, nvlist_t *outnvl)
* ...
* }
*/
+static const zfs_ioc_key_t zfs_keys_release[] = {
+ {"<snapname>...", DATA_TYPE_NVLIST, ZK_WILDCARDLIST},
+};
+
/* ARGSUSED */
static int
zfs_ioc_release(const char *pool, nvlist_t *holds, nvlist_t *errlist)
* "uncompressed" -> uncompressed space in bytes
* }
*/
+static const zfs_ioc_key_t zfs_keys_space_snaps[] = {
+ {"firstsnap", DATA_TYPE_STRING, 0},
+};
+
static int
zfs_ioc_space_snaps(const char *lastsnap, nvlist_t *innvl, nvlist_t *outnvl)
{
char *firstsnap;
uint64_t used, comp, uncomp;
- if (nvlist_lookup_string(innvl, "firstsnap", &firstsnap) != 0)
- return (SET_ERROR(EINVAL));
+ firstsnap = fnvlist_lookup_string(innvl, "firstsnap");
error = dsl_pool_hold(lastsnap, FTAG, &dp);
if (error != 0)
* presence indicates DRR_WRITE_EMBEDDED records are permitted
* (optional) "compressok" -> (value ignored)
* presence indicates compressed DRR_WRITE records are permitted
+ * (optional) "rawok" -> (value ignored)
+ * presence indicates raw encrypted records should be used.
* (optional) "resume_object" and "resume_offset" -> (uint64)
* if present, resume send stream from specified object and offset.
* }
*
* outnvl is unused
*/
+static const zfs_ioc_key_t zfs_keys_send_new[] = {
+ {"fd", DATA_TYPE_INT32, 0},
+ {"fromsnap", DATA_TYPE_STRING, ZK_OPTIONAL},
+ {"largeblockok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"embedok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"compressok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"rawok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"resume_object", DATA_TYPE_UINT64, ZK_OPTIONAL},
+ {"resume_offset", DATA_TYPE_UINT64, ZK_OPTIONAL},
+};
+
/* ARGSUSED */
static int
zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
boolean_t largeblockok;
boolean_t embedok;
boolean_t compressok;
+ boolean_t rawok;
uint64_t resumeobj = 0;
uint64_t resumeoff = 0;
- error = nvlist_lookup_int32(innvl, "fd", &fd);
- if (error != 0)
- return (SET_ERROR(EINVAL));
+ fd = fnvlist_lookup_int32(innvl, "fd");
(void) nvlist_lookup_string(innvl, "fromsnap", &fromname);
largeblockok = nvlist_exists(innvl, "largeblockok");
embedok = nvlist_exists(innvl, "embedok");
compressok = nvlist_exists(innvl, "compressok");
+ rawok = nvlist_exists(innvl, "rawok");
(void) nvlist_lookup_uint64(innvl, "resume_object", &resumeobj);
(void) nvlist_lookup_uint64(innvl, "resume_offset", &resumeoff);
off = fp->f_offset;
error = dmu_send(snapname, fromname, embedok, largeblockok, compressok,
- fd, resumeobj, resumeoff, fp->f_vnode, &off);
+ rawok, fd, resumeobj, resumeoff, fp->f_vnode, &off);
if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
fp->f_offset = off;
* presence indicates DRR_WRITE_EMBEDDED records are permitted
* (optional) "compressok" -> (value ignored)
* presence indicates compressed DRR_WRITE records are permitted
+ * (optional) "rawok" -> (value ignored)
+ * presence indicates raw encrypted records should be used.
* }
*
* outnvl: {
* "space" -> bytes of space (uint64)
* }
*/
+static const zfs_ioc_key_t zfs_keys_send_space[] = {
+ {"from", DATA_TYPE_STRING, ZK_OPTIONAL},
+ {"fromsnap", DATA_TYPE_STRING, ZK_OPTIONAL},
+ {"largeblockok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"embedok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"compressok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"rawok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+};
+
static int
zfs_ioc_send_space(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
{
dsl_dataset_t *tosnap;
int error;
char *fromname;
- /* LINTED E_FUNC_SET_NOT_USED */
- boolean_t largeblockok;
- /* LINTED E_FUNC_SET_NOT_USED */
- boolean_t embedok;
boolean_t compressok;
+ boolean_t rawok;
uint64_t space;
error = dsl_pool_hold(snapname, FTAG, &dp);
return (error);
}
- largeblockok = nvlist_exists(innvl, "largeblockok");
- embedok = nvlist_exists(innvl, "embedok");
compressok = nvlist_exists(innvl, "compressok");
+ rawok = nvlist_exists(innvl, "rawok");
error = nvlist_lookup_string(innvl, "from", &fromname);
if (error == 0) {
error = dsl_dataset_hold(dp, fromname, FTAG, &fromsnap);
if (error != 0)
goto out;
- error = dmu_send_estimate(tosnap, fromsnap, compressok,
- &space);
+ error = dmu_send_estimate(tosnap, fromsnap,
+ compressok || rawok, &space);
dsl_dataset_rele(fromsnap, FTAG);
} else if (strchr(fromname, '#') != NULL) {
/*
if (error != 0)
goto out;
error = dmu_send_estimate_from_txg(tosnap,
- frombm.zbm_creation_txg, compressok, &space);
+ frombm.zbm_creation_txg, compressok || rawok,
+ &space);
} else {
/*
* from is not properly formatted as a snapshot or
goto out;
}
} else {
- // If estimating the size of a full send, use dmu_send_estimate
- error = dmu_send_estimate(tosnap, NULL, compressok, &space);
+ /*
+ * If estimating the size of a full send, use dmu_send_estimate.
+ */
+ error = dmu_send_estimate(tosnap, NULL, compressok || rawok,
+ &space);
}
fnvlist_add_uint64(outnvl, "space", space);
return (error);
}
+/*
+ * Sync the currently open TXG to disk for the specified pool.
+ * This is somewhat similar to 'zfs_sync()'.
+ * For cases that do not result in error this ioctl will wait for
+ * the currently open TXG to commit before returning back to the caller.
+ *
+ * innvl: {
+ * "force" -> when true, force uberblock update even if there is no dirty data.
+ * In addition this will cause the vdev configuration to be written
+ * out including updating the zpool cache file. (boolean_t)
+ * }
+ *
+ * onvl is unused
+ */
+static const zfs_ioc_key_t zfs_keys_pool_sync[] = {
+ {"force", DATA_TYPE_BOOLEAN_VALUE, 0},
+};
+
+/* ARGSUSED */
+static int
+zfs_ioc_pool_sync(const char *pool, nvlist_t *innvl, nvlist_t *onvl)
+{
+ int err;
+ boolean_t force = B_FALSE;
+ spa_t *spa;
+
+ if ((err = spa_open(pool, &spa, FTAG)) != 0)
+ return (err);
+
+ if (innvl)
+ force = fnvlist_lookup_boolean_value(innvl, "force");
+
+ if (force) {
+ spa_config_enter(spa, SCL_CONFIG, FTAG, RW_WRITER);
+ vdev_config_dirty(spa->spa_root_vdev);
+ spa_config_exit(spa, SCL_CONFIG, FTAG);
+ }
+ txg_wait_synced(spa_get_dsl(spa), 0);
+
+ spa_close(spa, FTAG);
+
+ return (err);
+}
+
+/*
+ * Load a user's wrapping key into the kernel.
+ * innvl: {
+ * "hidden_args" -> { "wkeydata" -> value }
+ * raw uint8_t array of encryption wrapping key data (32 bytes)
+ * (optional) "noop" -> (value ignored)
+ * presence indicated key should only be verified, not loaded
+ * }
+ */
+static const zfs_ioc_key_t zfs_keys_load_key[] = {
+ {"hidden_args", DATA_TYPE_NVLIST, 0},
+ {"noop", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+};
+
+/* ARGSUSED */
+static int
+zfs_ioc_load_key(const char *dsname, nvlist_t *innvl, nvlist_t *outnvl)
+{
+ int ret;
+ dsl_crypto_params_t *dcp = NULL;
+ nvlist_t *hidden_args;
+ boolean_t noop = nvlist_exists(innvl, "noop");
+
+ if (strchr(dsname, '@') != NULL || strchr(dsname, '%') != NULL) {
+ ret = SET_ERROR(EINVAL);
+ goto error;
+ }
+
+ hidden_args = fnvlist_lookup_nvlist(innvl, ZPOOL_HIDDEN_ARGS);
+
+ ret = dsl_crypto_params_create_nvlist(DCP_CMD_NONE, NULL,
+ hidden_args, &dcp);
+ if (ret != 0)
+ goto error;
+
+ ret = spa_keystore_load_wkey(dsname, dcp, noop);
+ if (ret != 0)
+ goto error;
+
+ dsl_crypto_params_free(dcp, noop);
+
+ return (0);
+
+error:
+ dsl_crypto_params_free(dcp, B_TRUE);
+ return (ret);
+}
+
+/*
+ * Unload a user's wrapping key from the kernel.
+ * Both innvl and outnvl are unused.
+ */
+static const zfs_ioc_key_t zfs_keys_unload_key[] = {
+ /* no nvl keys */
+};
+
+/* ARGSUSED */
+static int
+zfs_ioc_unload_key(const char *dsname, nvlist_t *innvl, nvlist_t *outnvl)
+{
+ int ret = 0;
+
+ if (strchr(dsname, '@') != NULL || strchr(dsname, '%') != NULL) {
+ ret = (SET_ERROR(EINVAL));
+ goto out;
+ }
+
+ ret = spa_keystore_unload_wkey(dsname);
+ if (ret != 0)
+ goto out;
+
+out:
+ return (ret);
+}
+
+/*
+ * Changes a user's wrapping key used to decrypt a dataset. The keyformat,
+ * keylocation, pbkdf2salt, and pbkdf2iters properties can also be specified
+ * here to change how the key is derived in userspace.
+ *
+ * innvl: {
+ * "hidden_args" (optional) -> { "wkeydata" -> value }
+ * raw uint8_t array of new encryption wrapping key data (32 bytes)
+ * "props" (optional) -> { prop -> value }
+ * }
+ *
+ * outnvl is unused
+ */
+static const zfs_ioc_key_t zfs_keys_change_key[] = {
+ {"crypt_cmd", DATA_TYPE_UINT64, ZK_OPTIONAL},
+ {"hidden_args", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+ {"props", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+};
+
+/* ARGSUSED */
+static int
+zfs_ioc_change_key(const char *dsname, nvlist_t *innvl, nvlist_t *outnvl)
+{
+ int ret;
+ uint64_t cmd = DCP_CMD_NONE;
+ dsl_crypto_params_t *dcp = NULL;
+ nvlist_t *args = NULL, *hidden_args = NULL;
+
+ if (strchr(dsname, '@') != NULL || strchr(dsname, '%') != NULL) {
+ ret = (SET_ERROR(EINVAL));
+ goto error;
+ }
+
+ (void) nvlist_lookup_uint64(innvl, "crypt_cmd", &cmd);
+ (void) nvlist_lookup_nvlist(innvl, "props", &args);
+ (void) nvlist_lookup_nvlist(innvl, ZPOOL_HIDDEN_ARGS, &hidden_args);
+
+ ret = dsl_crypto_params_create_nvlist(cmd, args, hidden_args, &dcp);
+ if (ret != 0)
+ goto error;
+
+ ret = spa_keystore_change_key(dsname, dcp);
+ if (ret != 0)
+ goto error;
+
+ dsl_crypto_params_free(dcp, B_FALSE);
+
+ return (0);
+
+error:
+ dsl_crypto_params_free(dcp, B_TRUE);
+ return (ret);
+}
+
static zfs_ioc_vec_t zfs_ioc_vec[ZFS_IOC_LAST - ZFS_IOC_FIRST];
static void
zfs_ioctl_register(const char *name, zfs_ioc_t ioc, zfs_ioc_func_t *func,
zfs_secpolicy_func_t *secpolicy, zfs_ioc_namecheck_t namecheck,
zfs_ioc_poolcheck_t pool_check, boolean_t smush_outnvlist,
- boolean_t allow_log)
+ boolean_t allow_log, const zfs_ioc_key_t *nvl_keys, size_t num_keys)
{
zfs_ioc_vec_t *vec = &zfs_ioc_vec[ioc - ZFS_IOC_FIRST];
vec->zvec_pool_check = pool_check;
vec->zvec_smush_outnvlist = smush_outnvlist;
vec->zvec_allow_log = allow_log;
+ vec->zvec_nvl_keys = nvl_keys;
+ vec->zvec_nvl_key_count = num_keys;
}
static void
static void
zfs_ioctl_register_dataset_modify(zfs_ioc_t ioc, zfs_ioc_legacy_func_t *func,
- zfs_secpolicy_func_t *secpolicy)
+ zfs_secpolicy_func_t *secpolicy)
{
zfs_ioctl_register_legacy(ioc, func, secpolicy,
DATASET_NAME, B_TRUE, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
{
zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT,
zfs_ioc_snapshot, zfs_secpolicy_snapshot, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_snapshot, ARRAY_SIZE(zfs_keys_snapshot));
zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY,
zfs_ioc_log_history, zfs_secpolicy_log_history, NO_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE,
+ zfs_keys_log_history, ARRAY_SIZE(zfs_keys_log_history));
zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS,
zfs_ioc_space_snaps, zfs_secpolicy_read, DATASET_NAME,
- POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE,
+ zfs_keys_space_snaps, ARRAY_SIZE(zfs_keys_space_snaps));
zfs_ioctl_register("send", ZFS_IOC_SEND_NEW,
zfs_ioc_send_new, zfs_secpolicy_send_new, DATASET_NAME,
- POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE,
+ zfs_keys_send_new, ARRAY_SIZE(zfs_keys_send_new));
zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE,
zfs_ioc_send_space, zfs_secpolicy_read, DATASET_NAME,
- POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE,
+ zfs_keys_send_space, ARRAY_SIZE(zfs_keys_send_space));
zfs_ioctl_register("create", ZFS_IOC_CREATE,
zfs_ioc_create, zfs_secpolicy_create_clone, DATASET_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_create, ARRAY_SIZE(zfs_keys_create));
zfs_ioctl_register("clone", ZFS_IOC_CLONE,
zfs_ioc_clone, zfs_secpolicy_create_clone, DATASET_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_clone, ARRAY_SIZE(zfs_keys_clone));
+
+ zfs_ioctl_register("remap", ZFS_IOC_REMAP,
+ zfs_ioc_remap, zfs_secpolicy_remap, DATASET_NAME,
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE,
+ zfs_keys_remap, ARRAY_SIZE(zfs_keys_remap));
zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS,
zfs_ioc_destroy_snaps, zfs_secpolicy_destroy_snaps, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_destroy_snaps, ARRAY_SIZE(zfs_keys_destroy_snaps));
zfs_ioctl_register("hold", ZFS_IOC_HOLD,
zfs_ioc_hold, zfs_secpolicy_hold, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_hold, ARRAY_SIZE(zfs_keys_hold));
zfs_ioctl_register("release", ZFS_IOC_RELEASE,
zfs_ioc_release, zfs_secpolicy_release, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_release, ARRAY_SIZE(zfs_keys_release));
zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS,
zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME,
- POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE,
+ zfs_keys_get_holds, ARRAY_SIZE(zfs_keys_get_holds));
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);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE,
+ zfs_keys_rollback, ARRAY_SIZE(zfs_keys_rollback));
zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK,
zfs_ioc_bookmark, zfs_secpolicy_bookmark, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_bookmark, ARRAY_SIZE(zfs_keys_bookmark));
zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS,
zfs_ioc_get_bookmarks, zfs_secpolicy_read, DATASET_NAME,
- POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE,
+ zfs_keys_get_bookmarks, ARRAY_SIZE(zfs_keys_get_bookmarks));
zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS,
zfs_ioc_destroy_bookmarks, zfs_secpolicy_destroy_bookmarks,
POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_destroy_bookmarks,
+ ARRAY_SIZE(zfs_keys_destroy_bookmarks));
zfs_ioctl_register("receive", ZFS_IOC_RECV_NEW,
zfs_ioc_recv_new, zfs_secpolicy_recv_new, DATASET_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_recv_new, ARRAY_SIZE(zfs_keys_recv_new));
+ zfs_ioctl_register("load-key", ZFS_IOC_LOAD_KEY,
+ zfs_ioc_load_key, zfs_secpolicy_load_key,
+ DATASET_NAME, POOL_CHECK_SUSPENDED, B_TRUE, B_TRUE,
+ zfs_keys_load_key, ARRAY_SIZE(zfs_keys_load_key));
+ zfs_ioctl_register("unload-key", ZFS_IOC_UNLOAD_KEY,
+ zfs_ioc_unload_key, zfs_secpolicy_load_key,
+ DATASET_NAME, POOL_CHECK_SUSPENDED, B_TRUE, B_TRUE,
+ zfs_keys_unload_key, ARRAY_SIZE(zfs_keys_unload_key));
+ zfs_ioctl_register("change-key", ZFS_IOC_CHANGE_KEY,
+ zfs_ioc_change_key, zfs_secpolicy_change_key,
+ DATASET_NAME, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY,
+ B_TRUE, B_TRUE, zfs_keys_change_key,
+ ARRAY_SIZE(zfs_keys_change_key));
+
+ zfs_ioctl_register("sync", ZFS_IOC_POOL_SYNC,
+ zfs_ioc_pool_sync, zfs_secpolicy_none, POOL_NAME,
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE,
+ zfs_keys_pool_sync, ARRAY_SIZE(zfs_keys_pool_sync));
+ zfs_ioctl_register("reopen", ZFS_IOC_POOL_REOPEN, zfs_ioc_pool_reopen,
+ zfs_secpolicy_config, POOL_NAME, POOL_CHECK_SUSPENDED, B_TRUE,
+ B_TRUE, zfs_keys_pool_reopen, ARRAY_SIZE(zfs_keys_pool_reopen));
+
+ zfs_ioctl_register("channel_program", ZFS_IOC_CHANNEL_PROGRAM,
+ zfs_ioc_channel_program, zfs_secpolicy_config,
+ POOL_NAME, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE,
+ B_TRUE, zfs_keys_channel_program,
+ ARRAY_SIZE(zfs_keys_channel_program));
+
+ zfs_ioctl_register("zpool_checkpoint", ZFS_IOC_POOL_CHECKPOINT,
+ zfs_ioc_pool_checkpoint, zfs_secpolicy_config, POOL_NAME,
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_pool_checkpoint, ARRAY_SIZE(zfs_keys_pool_checkpoint));
+
+ zfs_ioctl_register("zpool_discard_checkpoint",
+ ZFS_IOC_POOL_DISCARD_CHECKPOINT, zfs_ioc_pool_discard_checkpoint,
+ zfs_secpolicy_config, POOL_NAME,
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_pool_discard_checkpoint,
+ ARRAY_SIZE(zfs_keys_pool_discard_checkpoint));
+
+ zfs_ioctl_register("initialize", ZFS_IOC_POOL_INITIALIZE,
+ zfs_ioc_pool_initialize, zfs_secpolicy_config, POOL_NAME,
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_pool_initialize, ARRAY_SIZE(zfs_keys_pool_initialize));
+
+ zfs_ioctl_register("trim", ZFS_IOC_POOL_TRIM,
+ zfs_ioc_pool_trim, zfs_secpolicy_config, POOL_NAME,
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_pool_trim, ARRAY_SIZE(zfs_keys_pool_trim));
/* IOCTLS that use the legacy function signature */
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_NONE);
- zfs_ioctl_register_pool(ZFS_IOC_POOL_REOPEN, zfs_ioc_pool_reopen,
- zfs_secpolicy_config, B_TRUE, POOL_CHECK_SUSPENDED);
+ zfs_secpolicy_config, B_TRUE, POOL_CHECK_READONLY);
zfs_ioctl_register_dataset_read(ZFS_IOC_SPACE_WRITTEN,
zfs_ioc_space_written);
zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_NONE);
}
+/*
+ * Verify that for non-legacy ioctls the input nvlist
+ * pairs match against the expected input.
+ *
+ * Possible errors are:
+ * ZFS_ERR_IOC_ARG_UNAVAIL An unrecognized nvpair was encountered
+ * ZFS_ERR_IOC_ARG_REQUIRED A required nvpair is missing
+ * ZFS_ERR_IOC_ARG_BADTYPE Invalid type for nvpair
+ */
+static int
+zfs_check_input_nvpairs(nvlist_t *innvl, const zfs_ioc_vec_t *vec)
+{
+ const zfs_ioc_key_t *nvl_keys = vec->zvec_nvl_keys;
+ boolean_t required_keys_found = B_FALSE;
+
+ /*
+ * examine each input pair
+ */
+ for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
+ pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
+ char *name = nvpair_name(pair);
+ data_type_t type = nvpair_type(pair);
+ boolean_t identified = B_FALSE;
+
+ /*
+ * check pair against the documented names and type
+ */
+ for (int k = 0; k < vec->zvec_nvl_key_count; k++) {
+ /* if not a wild card name, check for an exact match */
+ if ((nvl_keys[k].zkey_flags & ZK_WILDCARDLIST) == 0 &&
+ strcmp(nvl_keys[k].zkey_name, name) != 0)
+ continue;
+
+ identified = B_TRUE;
+
+ if (nvl_keys[k].zkey_type != DATA_TYPE_ANY &&
+ nvl_keys[k].zkey_type != type) {
+ return (SET_ERROR(ZFS_ERR_IOC_ARG_BADTYPE));
+ }
+
+ if (nvl_keys[k].zkey_flags & ZK_OPTIONAL)
+ continue;
+
+ required_keys_found = B_TRUE;
+ break;
+ }
+
+ /* allow an 'optional' key, everything else is invalid */
+ if (!identified &&
+ (strcmp(name, "optional") != 0 ||
+ type != DATA_TYPE_NVLIST)) {
+ return (SET_ERROR(ZFS_ERR_IOC_ARG_UNAVAIL));
+ }
+ }
+
+ /* verify that all required keys were found */
+ for (int k = 0; k < vec->zvec_nvl_key_count; k++) {
+ if (nvl_keys[k].zkey_flags & ZK_OPTIONAL)
+ continue;
+
+ if (nvl_keys[k].zkey_flags & ZK_WILDCARDLIST) {
+ /* at least one non-optionial key is expected here */
+ if (!required_keys_found)
+ return (SET_ERROR(ZFS_ERR_IOC_ARG_REQUIRED));
+ continue;
+ }
+
+ if (!nvlist_exists(innvl, nvl_keys[k].zkey_name))
+ return (SET_ERROR(ZFS_ERR_IOC_ARG_REQUIRED));
+ }
+
+ return (0);
+}
+
int
pool_status_check(const char *name, zfs_ioc_namecheck_t type,
zfs_ioc_poolcheck_t check)
fpd = filp->private_data;
if (fpd == NULL)
- return (EBADF);
+ return (SET_ERROR(EBADF));
mutex_enter(&zfsdev_state_lock);
mutex_exit(&zfsdev_state_lock);
- return (EBADF);
+ return (SET_ERROR(EBADF));
}
/*
vecnum = cmd - ZFS_IOC_FIRST;
if (vecnum >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
- return (-SET_ERROR(EINVAL));
+ return (-SET_ERROR(ZFS_ERR_IOC_CMD_UNAVAIL));
vec = &zfs_ioc_vec[vecnum];
/*
* a normal or legacy handler are registered.
*/
if (vec->zvec_func == NULL && vec->zvec_legacy_func == NULL)
- return (-SET_ERROR(EINVAL));
+ return (-SET_ERROR(ZFS_ERR_IOC_CMD_UNAVAIL));
zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
break;
}
+ /*
+ * Ensure that all input pairs are valid before we pass them down
+ * to the lower layers.
+ *
+ * The vectored functions can use fnvlist_lookup_{type} for any
+ * required pairs since zfs_check_input_nvpairs() confirmed that
+ * they exist and are of the correct type.
+ */
+ if (error == 0 && vec->zvec_func != NULL) {
+ error = zfs_check_input_nvpairs(innvl, vec);
+ if (error != 0)
+ goto out;
+ }
- if (error == 0 && !(flag & FKIOCTL)) {
+ if (error == 0) {
cookie = spl_fstrans_mark();
error = vec->zvec_secpolicy(zc, innvl, CRED());
spl_fstrans_unmark(cookie);
error = vec->zvec_func(zc->zc_name, innvl, outnvl);
spl_fstrans_unmark(cookie);
- if (error == 0 && vec->zvec_allow_log &&
+ /*
+ * Some commands can partially execute, modify state, and still
+ * return an error. In these cases, attempt to record what
+ * was modified.
+ */
+ if ((error == 0 ||
+ (cmd == ZFS_IOC_CHANNEL_PROGRAM && error != EINVAL)) &&
+ vec->zvec_allow_log &&
spa_open(zc->zc_name, &spa, FTAG) == 0) {
if (!nvlist_empty(outnvl)) {
fnvlist_add_nvlist(lognv, ZPOOL_HIST_OUTPUT_NVL,
outnvl);
}
+ if (error != 0) {
+ fnvlist_add_int64(lognv, ZPOOL_HIST_ERRNO,
+ error);
+ }
(void) spa_history_log_nvl(spa, lognv);
spa_close(spa, FTAG);
}
};
static struct miscdevice zfs_misc = {
- .minor = MISC_DYNAMIC_MINOR,
+ .minor = ZFS_DEVICE_MINOR,
.name = ZFS_DRIVER,
.fops = &zfsdev_fops,
};
+MODULE_ALIAS_MISCDEV(ZFS_DEVICE_MINOR);
+MODULE_ALIAS("devname:zfs");
+
static int
zfs_attach(void)
{
zfsdev_state_list->zs_minor = -1;
error = misc_register(&zfs_misc);
- if (error != 0) {
- printk(KERN_INFO "ZFS: misc_register() failed %d\n", error);
- return (error);
+ if (error == -EBUSY) {
+ /*
+ * Fallback to dynamic minor allocation in the event of a
+ * collision with a reserved minor in linux/miscdevice.h.
+ * In this case the kernel modules must be manually loaded.
+ */
+ printk(KERN_INFO "ZFS: misc_register() with static minor %d "
+ "failed %d, retrying with MISC_DYNAMIC_MINOR\n",
+ ZFS_DEVICE_MINOR, error);
+
+ zfs_misc.minor = MISC_DYNAMIC_MINOR;
+ error = misc_register(&zfs_misc);
}
- return (0);
+ if (error)
+ printk(KERN_INFO "ZFS: misc_register() failed %d\n", error);
+
+ return (error);
}
static void
zfs_init();
zfs_ioctl_init();
+ zfs_sysfs_init();
if ((error = zfs_attach()) != 0)
goto out;
return (0);
out:
+ zfs_sysfs_fini();
zfs_fini();
spa_fini();
(void) zvol_fini();
_fini(void)
{
zfs_detach();
+ zfs_sysfs_fini();
zfs_fini();
spa_fini();
zvol_fini();
ZFS_META_VERSION, ZFS_META_RELEASE, ZFS_DEBUG_STR);
}
-#ifdef HAVE_SPL
+#if defined(_KERNEL)
module_init(_init);
module_exit(_fini);
MODULE_AUTHOR(ZFS_META_AUTHOR);
MODULE_LICENSE(ZFS_META_LICENSE);
MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
-#endif /* HAVE_SPL */
+#endif