mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
OpenZFS 7431 - ZFS Channel Programs
Authored by: Chris Williamson <chris.williamson@delphix.com> Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: John Kennedy <john.kennedy@delphix.com> Reviewed by: Dan Kimmel <dan.kimmel@delphix.com> Approved by: Garrett D'Amore <garrett@damore.org> Ported-by: Don Brady <don.brady@delphix.com> Ported-by: John Kennedy <john.kennedy@delphix.com> OpenZFS-issue: https://www.illumos.org/issues/7431 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/dfc11533 Porting Notes: * The CLI long option arguments for '-t' and '-m' don't parse on linux * Switched from kmem_alloc to vmem_alloc in zcp_lua_alloc * Lua implementation is built as its own module (zlua.ko) * Lua headers consumed directly by zfs code moved to 'include/sys/lua/' * There is no native setjmp/longjump available in stock Linux kernel. Brought over implementations from illumos and FreeBSD * The get_temporary_prop() was adapted due to VFS platform differences * Use of inline functions in lua parser to reduce stack usage per C call * Skip some ZFS Test Suite ZCP tests on sparc64 to avoid stack overflow
This commit is contained in:
committed by
Brian Behlendorf
parent
8824a7f133
commit
d99a015343
@@ -1,5 +1,6 @@
|
||||
src = @abs_top_srcdir@/module/zfs
|
||||
obj = @abs_builddir@
|
||||
target_cpu = @target_cpu@
|
||||
|
||||
MODULE := zfs
|
||||
|
||||
@@ -7,6 +8,11 @@ obj-$(CONFIG_ZFS) := $(MODULE).o
|
||||
|
||||
ccflags-y := $(ZFS_MODULE_CFLAGS) $(ZFS_MODULE_CPPFLAGS)
|
||||
|
||||
# Suppress unused-value warnings in sparc64 architecture headers
|
||||
ifeq ($(target_cpu),sparc64)
|
||||
ccflags-y += -Wno-unused-value
|
||||
endif
|
||||
|
||||
# Suppress unused but set variable warnings often due to ASSERTs
|
||||
ccflags-y += $(NO_UNUSED_BUT_SET_VARIABLE)
|
||||
|
||||
@@ -86,6 +92,11 @@ $(MODULE)-objs += vdev_root.o
|
||||
$(MODULE)-objs += zap.o
|
||||
$(MODULE)-objs += zap_leaf.o
|
||||
$(MODULE)-objs += zap_micro.o
|
||||
$(MODULE)-objs += zcp.o
|
||||
$(MODULE)-objs += zcp_get.o
|
||||
$(MODULE)-objs += zcp_global.o
|
||||
$(MODULE)-objs += zcp_iter.o
|
||||
$(MODULE)-objs += zcp_synctask.o
|
||||
$(MODULE)-objs += zfeature.o
|
||||
$(MODULE)-objs += zfs_acl.o
|
||||
$(MODULE)-objs += zfs_byteswap.o
|
||||
|
||||
+400
-103
@@ -1681,7 +1681,6 @@ dsl_dataset_snapshot_tmp(const char *fsname, const char *snapname,
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dsl_dataset_sync(dsl_dataset_t *ds, zio_t *zio, dmu_tx_t *tx)
|
||||
{
|
||||
@@ -1749,29 +1748,16 @@ dsl_dataset_sync_done(dsl_dataset_t *ds, dmu_tx_t *tx)
|
||||
dmu_buf_rele(ds->ds_dbuf, ds);
|
||||
}
|
||||
|
||||
static void
|
||||
get_clones_stat(dsl_dataset_t *ds, nvlist_t *nv)
|
||||
int
|
||||
get_clones_stat_impl(dsl_dataset_t *ds, nvlist_t *val)
|
||||
{
|
||||
uint64_t count = 0;
|
||||
objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
|
||||
zap_cursor_t zc;
|
||||
zap_attribute_t za;
|
||||
nvlist_t *propval = fnvlist_alloc();
|
||||
nvlist_t *val;
|
||||
|
||||
ASSERT(dsl_pool_config_held(ds->ds_dir->dd_pool));
|
||||
|
||||
/*
|
||||
* We use nvlist_alloc() instead of fnvlist_alloc() because the
|
||||
* latter would allocate the list with NV_UNIQUE_NAME flag.
|
||||
* As a result, every time a clone name is appended to the list
|
||||
* it would be (linearly) searched for for a duplicate name.
|
||||
* We already know that all clone names must be unique and we
|
||||
* want avoid the quadratic complexity of double-checking that
|
||||
* because we can have a large number of clones.
|
||||
*/
|
||||
VERIFY0(nvlist_alloc(&val, 0, KM_SLEEP));
|
||||
|
||||
/*
|
||||
* There may be missing entries in ds_next_clones_obj
|
||||
* due to a bug in a previous version of the code.
|
||||
@@ -1781,8 +1767,9 @@ get_clones_stat(dsl_dataset_t *ds, nvlist_t *nv)
|
||||
VERIFY0(zap_count(mos, dsl_dataset_phys(ds)->ds_next_clones_obj,
|
||||
&count));
|
||||
}
|
||||
if (count != dsl_dataset_phys(ds)->ds_num_children - 1)
|
||||
goto fail;
|
||||
if (count != dsl_dataset_phys(ds)->ds_num_children - 1) {
|
||||
return (ENOENT);
|
||||
}
|
||||
for (zap_cursor_init(&zc, mos,
|
||||
dsl_dataset_phys(ds)->ds_next_clones_obj);
|
||||
zap_cursor_retrieve(&zc, &za) == 0;
|
||||
@@ -1796,15 +1783,42 @@ get_clones_stat(dsl_dataset_t *ds, nvlist_t *nv)
|
||||
dsl_dataset_rele(clone, FTAG);
|
||||
}
|
||||
zap_cursor_fini(&zc);
|
||||
fnvlist_add_nvlist(propval, ZPROP_VALUE, val);
|
||||
fnvlist_add_nvlist(nv, zfs_prop_to_name(ZFS_PROP_CLONES), propval);
|
||||
fail:
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
get_clones_stat(dsl_dataset_t *ds, nvlist_t *nv)
|
||||
{
|
||||
nvlist_t *propval = fnvlist_alloc();
|
||||
nvlist_t *val;
|
||||
|
||||
/*
|
||||
* We use nvlist_alloc() instead of fnvlist_alloc() because the
|
||||
* latter would allocate the list with NV_UNIQUE_NAME flag.
|
||||
* As a result, every time a clone name is appended to the list
|
||||
* it would be (linearly) searched for for a duplicate name.
|
||||
* We already know that all clone names must be unique and we
|
||||
* want avoid the quadratic complexity of double-checking that
|
||||
* because we can have a large number of clones.
|
||||
*/
|
||||
VERIFY0(nvlist_alloc(&val, 0, KM_SLEEP));
|
||||
|
||||
if (get_clones_stat_impl(ds, val) == 0) {
|
||||
fnvlist_add_nvlist(propval, ZPROP_VALUE, val);
|
||||
fnvlist_add_nvlist(nv, zfs_prop_to_name(ZFS_PROP_CLONES),
|
||||
propval);
|
||||
}
|
||||
|
||||
nvlist_free(val);
|
||||
nvlist_free(propval);
|
||||
}
|
||||
|
||||
static void
|
||||
get_receive_resume_stats(dsl_dataset_t *ds, nvlist_t *nv)
|
||||
/*
|
||||
* Returns a string that represents the receive resume stats token. It should
|
||||
* be freed with strfree().
|
||||
*/
|
||||
char *
|
||||
get_receive_resume_stats_impl(dsl_dataset_t *ds)
|
||||
{
|
||||
dsl_pool_t *dp = ds->ds_dir->dd_pool;
|
||||
|
||||
@@ -1876,86 +1890,361 @@ get_receive_resume_stats(dsl_dataset_t *ds, nvlist_t *nv)
|
||||
ZFS_SEND_RESUME_TOKEN_VERSION,
|
||||
(longlong_t)cksum.zc_word[0],
|
||||
(longlong_t)packed_size, str);
|
||||
dsl_prop_nvlist_add_string(nv,
|
||||
ZFS_PROP_RECEIVE_RESUME_TOKEN, propval);
|
||||
kmem_free(packed, packed_size);
|
||||
kmem_free(str, compressed_size * 2 + 1);
|
||||
kmem_free(compressed, packed_size);
|
||||
strfree(propval);
|
||||
return (propval);
|
||||
}
|
||||
return (strdup(""));
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a string that represents the receive resume stats token of the
|
||||
* dataset's child. It should be freed with strfree().
|
||||
*/
|
||||
char *
|
||||
get_child_receive_stats(dsl_dataset_t *ds)
|
||||
{
|
||||
char recvname[ZFS_MAX_DATASET_NAME_LEN + 6];
|
||||
dsl_dataset_t *recv_ds;
|
||||
dsl_dataset_name(ds, recvname);
|
||||
if (strlcat(recvname, "/", sizeof (recvname)) <
|
||||
sizeof (recvname) &&
|
||||
strlcat(recvname, recv_clone_name, sizeof (recvname)) <
|
||||
sizeof (recvname) &&
|
||||
dsl_dataset_hold(ds->ds_dir->dd_pool, recvname, FTAG,
|
||||
&recv_ds) == 0) {
|
||||
char *propval = get_receive_resume_stats_impl(recv_ds);
|
||||
dsl_dataset_rele(recv_ds, FTAG);
|
||||
return (propval);
|
||||
}
|
||||
return (strdup(""));
|
||||
}
|
||||
|
||||
static void
|
||||
get_receive_resume_stats(dsl_dataset_t *ds, nvlist_t *nv)
|
||||
{
|
||||
char *propval = get_receive_resume_stats_impl(ds);
|
||||
if (strcmp(propval, "") != 0) {
|
||||
dsl_prop_nvlist_add_string(nv,
|
||||
ZFS_PROP_RECEIVE_RESUME_TOKEN, propval);
|
||||
} else {
|
||||
char *childval = get_child_receive_stats(ds);
|
||||
if (strcmp(childval, "") != 0) {
|
||||
dsl_prop_nvlist_add_string(nv,
|
||||
ZFS_PROP_RECEIVE_RESUME_TOKEN, childval);
|
||||
}
|
||||
strfree(childval);
|
||||
}
|
||||
strfree(propval);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_refratio(dsl_dataset_t *ds)
|
||||
{
|
||||
uint64_t ratio = dsl_dataset_phys(ds)->ds_compressed_bytes == 0 ? 100 :
|
||||
(dsl_dataset_phys(ds)->ds_uncompressed_bytes * 100 /
|
||||
dsl_dataset_phys(ds)->ds_compressed_bytes);
|
||||
return (ratio);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_logicalreferenced(dsl_dataset_t *ds)
|
||||
{
|
||||
return (dsl_dataset_phys(ds)->ds_uncompressed_bytes);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_compressratio(dsl_dataset_t *ds)
|
||||
{
|
||||
if (ds->ds_is_snapshot) {
|
||||
return (dsl_get_refratio(ds));
|
||||
} else {
|
||||
dsl_dir_t *dd = ds->ds_dir;
|
||||
mutex_enter(&dd->dd_lock);
|
||||
uint64_t val = dsl_dir_get_compressratio(dd);
|
||||
mutex_exit(&dd->dd_lock);
|
||||
return (val);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_used(dsl_dataset_t *ds)
|
||||
{
|
||||
if (ds->ds_is_snapshot) {
|
||||
return (dsl_dataset_phys(ds)->ds_unique_bytes);
|
||||
} else {
|
||||
dsl_dir_t *dd = ds->ds_dir;
|
||||
mutex_enter(&dd->dd_lock);
|
||||
uint64_t val = dsl_dir_get_used(dd);
|
||||
mutex_exit(&dd->dd_lock);
|
||||
return (val);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_creation(dsl_dataset_t *ds)
|
||||
{
|
||||
return (dsl_dataset_phys(ds)->ds_creation_time);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_creationtxg(dsl_dataset_t *ds)
|
||||
{
|
||||
return (dsl_dataset_phys(ds)->ds_creation_txg);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_refquota(dsl_dataset_t *ds)
|
||||
{
|
||||
return (ds->ds_quota);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_refreservation(dsl_dataset_t *ds)
|
||||
{
|
||||
return (ds->ds_reserved);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_guid(dsl_dataset_t *ds)
|
||||
{
|
||||
return (dsl_dataset_phys(ds)->ds_guid);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_unique(dsl_dataset_t *ds)
|
||||
{
|
||||
return (dsl_dataset_phys(ds)->ds_unique_bytes);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_objsetid(dsl_dataset_t *ds)
|
||||
{
|
||||
return (ds->ds_object);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_userrefs(dsl_dataset_t *ds)
|
||||
{
|
||||
return (ds->ds_userrefs);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_defer_destroy(dsl_dataset_t *ds)
|
||||
{
|
||||
return (DS_IS_DEFER_DESTROY(ds) ? 1 : 0);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_referenced(dsl_dataset_t *ds)
|
||||
{
|
||||
return (dsl_dataset_phys(ds)->ds_referenced_bytes);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_numclones(dsl_dataset_t *ds)
|
||||
{
|
||||
ASSERT(ds->ds_is_snapshot);
|
||||
return (dsl_dataset_phys(ds)->ds_num_children - 1);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_inconsistent(dsl_dataset_t *ds)
|
||||
{
|
||||
return ((dsl_dataset_phys(ds)->ds_flags & DS_FLAG_INCONSISTENT) ?
|
||||
1 : 0);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_get_available(dsl_dataset_t *ds)
|
||||
{
|
||||
uint64_t refdbytes = dsl_get_referenced(ds);
|
||||
uint64_t availbytes = dsl_dir_space_available(ds->ds_dir,
|
||||
NULL, 0, TRUE);
|
||||
if (ds->ds_reserved > dsl_dataset_phys(ds)->ds_unique_bytes) {
|
||||
availbytes +=
|
||||
ds->ds_reserved - dsl_dataset_phys(ds)->ds_unique_bytes;
|
||||
}
|
||||
if (ds->ds_quota != 0) {
|
||||
/*
|
||||
* Adjust available bytes according to refquota
|
||||
*/
|
||||
if (refdbytes < ds->ds_quota) {
|
||||
availbytes = MIN(availbytes,
|
||||
ds->ds_quota - refdbytes);
|
||||
} else {
|
||||
availbytes = 0;
|
||||
}
|
||||
}
|
||||
return (availbytes);
|
||||
}
|
||||
|
||||
int
|
||||
dsl_get_written(dsl_dataset_t *ds, uint64_t *written)
|
||||
{
|
||||
dsl_pool_t *dp = ds->ds_dir->dd_pool;
|
||||
dsl_dataset_t *prev;
|
||||
int err = dsl_dataset_hold_obj(dp,
|
||||
dsl_dataset_phys(ds)->ds_prev_snap_obj, FTAG, &prev);
|
||||
if (err == 0) {
|
||||
uint64_t comp, uncomp;
|
||||
err = dsl_dataset_space_written(prev, ds, written,
|
||||
&comp, &uncomp);
|
||||
dsl_dataset_rele(prev, FTAG);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
/*
|
||||
* 'snap' should be a buffer of size ZFS_MAX_DATASET_NAME_LEN.
|
||||
*/
|
||||
int
|
||||
dsl_get_prev_snap(dsl_dataset_t *ds, char *snap)
|
||||
{
|
||||
dsl_pool_t *dp = ds->ds_dir->dd_pool;
|
||||
if (ds->ds_prev != NULL && ds->ds_prev != dp->dp_origin_snap) {
|
||||
dsl_dataset_name(ds->ds_prev, snap);
|
||||
return (0);
|
||||
} else {
|
||||
return (ENOENT);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the mountpoint property and source for the given dataset in the value
|
||||
* and source buffers. The value buffer must be at least as large as MAXPATHLEN
|
||||
* and the source buffer as least as large a ZFS_MAX_DATASET_NAME_LEN.
|
||||
* Returns 0 on success and an error on failure.
|
||||
*/
|
||||
int
|
||||
dsl_get_mountpoint(dsl_dataset_t *ds, const char *dsname, char *value,
|
||||
char *source)
|
||||
{
|
||||
int error;
|
||||
dsl_pool_t *dp = ds->ds_dir->dd_pool;
|
||||
|
||||
/* Retrieve the mountpoint value stored in the zap opbject */
|
||||
error = dsl_prop_get_ds(ds, zfs_prop_to_name(ZFS_PROP_MOUNTPOINT), 1,
|
||||
ZAP_MAXVALUELEN, value, source);
|
||||
if (error != 0) {
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Process the dsname and source to find the full mountpoint string.
|
||||
* Can be skipped for 'legacy' or 'none'.
|
||||
*/
|
||||
if (value[0] == '/') {
|
||||
char *buf = kmem_alloc(ZAP_MAXVALUELEN, KM_SLEEP);
|
||||
char *root = buf;
|
||||
const char *relpath;
|
||||
|
||||
/*
|
||||
* If we inherit the mountpoint, even from a dataset
|
||||
* with a received value, the source will be the path of
|
||||
* the dataset we inherit from. If source is
|
||||
* ZPROP_SOURCE_VAL_RECVD, the received value is not
|
||||
* inherited.
|
||||
*/
|
||||
if (strcmp(source, ZPROP_SOURCE_VAL_RECVD) == 0) {
|
||||
relpath = "";
|
||||
} else {
|
||||
ASSERT0(strncmp(dsname, source, strlen(source)));
|
||||
relpath = dsname + strlen(source);
|
||||
if (relpath[0] == '/')
|
||||
relpath++;
|
||||
}
|
||||
|
||||
spa_altroot(dp->dp_spa, root, ZAP_MAXVALUELEN);
|
||||
|
||||
/*
|
||||
* Special case an alternate root of '/'. This will
|
||||
* avoid having multiple leading slashes in the
|
||||
* mountpoint path.
|
||||
*/
|
||||
if (strcmp(root, "/") == 0)
|
||||
root++;
|
||||
|
||||
/*
|
||||
* If the mountpoint is '/' then skip over this
|
||||
* if we are obtaining either an alternate root or
|
||||
* an inherited mountpoint.
|
||||
*/
|
||||
char *mnt = value;
|
||||
if (value[1] == '\0' && (root[0] != '\0' ||
|
||||
relpath[0] != '\0'))
|
||||
mnt = value + 1;
|
||||
|
||||
if (relpath[0] == '\0') {
|
||||
(void) snprintf(value, ZAP_MAXVALUELEN, "%s%s",
|
||||
root, mnt);
|
||||
} else {
|
||||
(void) snprintf(value, ZAP_MAXVALUELEN, "%s%s%s%s",
|
||||
root, mnt, relpath[0] == '@' ? "" : "/",
|
||||
relpath);
|
||||
}
|
||||
kmem_free(buf, ZAP_MAXVALUELEN);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
dsl_dataset_stats(dsl_dataset_t *ds, nvlist_t *nv)
|
||||
{
|
||||
int err;
|
||||
dsl_pool_t *dp = ds->ds_dir->dd_pool;
|
||||
uint64_t refd, avail, uobjs, aobjs, ratio;
|
||||
|
||||
ASSERT(dsl_pool_config_held(dp));
|
||||
|
||||
ratio = dsl_dataset_phys(ds)->ds_compressed_bytes == 0 ? 100 :
|
||||
(dsl_dataset_phys(ds)->ds_uncompressed_bytes * 100 /
|
||||
dsl_dataset_phys(ds)->ds_compressed_bytes);
|
||||
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFRATIO, ratio);
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFRATIO,
|
||||
dsl_get_refratio(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_LOGICALREFERENCED,
|
||||
dsl_dataset_phys(ds)->ds_uncompressed_bytes);
|
||||
dsl_get_logicalreferenced(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_COMPRESSRATIO,
|
||||
dsl_get_compressratio(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USED,
|
||||
dsl_get_used(ds));
|
||||
|
||||
if (ds->ds_is_snapshot) {
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_COMPRESSRATIO, ratio);
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USED,
|
||||
dsl_dataset_phys(ds)->ds_unique_bytes);
|
||||
get_clones_stat(ds, nv);
|
||||
} else {
|
||||
if (ds->ds_prev != NULL && ds->ds_prev != dp->dp_origin_snap) {
|
||||
char buf[ZFS_MAX_DATASET_NAME_LEN];
|
||||
dsl_dataset_name(ds->ds_prev, buf);
|
||||
dsl_prop_nvlist_add_string(nv, ZFS_PROP_PREV_SNAP, buf);
|
||||
}
|
||||
|
||||
char buf[ZFS_MAX_DATASET_NAME_LEN];
|
||||
if (dsl_get_prev_snap(ds, buf) == 0)
|
||||
dsl_prop_nvlist_add_string(nv, ZFS_PROP_PREV_SNAP,
|
||||
buf);
|
||||
dsl_dir_stats(ds->ds_dir, nv);
|
||||
}
|
||||
|
||||
dsl_dataset_space(ds, &refd, &avail, &uobjs, &aobjs);
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_AVAILABLE, avail);
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFERENCED, refd);
|
||||
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_AVAILABLE,
|
||||
dsl_get_available(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFERENCED,
|
||||
dsl_get_referenced(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATION,
|
||||
dsl_dataset_phys(ds)->ds_creation_time);
|
||||
dsl_get_creation(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATETXG,
|
||||
dsl_dataset_phys(ds)->ds_creation_txg);
|
||||
dsl_get_creationtxg(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFQUOTA,
|
||||
ds->ds_quota);
|
||||
dsl_get_refquota(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFRESERVATION,
|
||||
ds->ds_reserved);
|
||||
dsl_get_refreservation(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_GUID,
|
||||
dsl_dataset_phys(ds)->ds_guid);
|
||||
dsl_get_guid(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_UNIQUE,
|
||||
dsl_dataset_phys(ds)->ds_unique_bytes);
|
||||
dsl_get_unique(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_OBJSETID,
|
||||
ds->ds_object);
|
||||
dsl_get_objsetid(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USERREFS,
|
||||
ds->ds_userrefs);
|
||||
dsl_get_userrefs(ds));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_DEFER_DESTROY,
|
||||
DS_IS_DEFER_DESTROY(ds) ? 1 : 0);
|
||||
dsl_get_defer_destroy(ds));
|
||||
dsl_dataset_crypt_stats(ds, nv);
|
||||
|
||||
if (dsl_dataset_phys(ds)->ds_prev_snap_obj != 0) {
|
||||
uint64_t written, comp, uncomp;
|
||||
dsl_pool_t *dp = ds->ds_dir->dd_pool;
|
||||
dsl_dataset_t *prev;
|
||||
|
||||
err = dsl_dataset_hold_obj(dp,
|
||||
dsl_dataset_phys(ds)->ds_prev_snap_obj, FTAG, &prev);
|
||||
if (err == 0) {
|
||||
err = dsl_dataset_space_written(prev, ds, &written,
|
||||
&comp, &uncomp);
|
||||
dsl_dataset_rele(prev, FTAG);
|
||||
if (err == 0) {
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_WRITTEN,
|
||||
written);
|
||||
}
|
||||
uint64_t written;
|
||||
if (dsl_get_written(ds, &written) == 0) {
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_WRITTEN,
|
||||
written);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1989,30 +2278,22 @@ dsl_dataset_stats(dsl_dataset_t *ds, nvlist_t *nv)
|
||||
void
|
||||
dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat)
|
||||
{
|
||||
dsl_pool_t *dp = ds->ds_dir->dd_pool;
|
||||
ASSERTV(dsl_pool_t *dp = ds->ds_dir->dd_pool);
|
||||
ASSERT(dsl_pool_config_held(dp));
|
||||
|
||||
stat->dds_creation_txg = dsl_dataset_phys(ds)->ds_creation_txg;
|
||||
stat->dds_inconsistent =
|
||||
dsl_dataset_phys(ds)->ds_flags & DS_FLAG_INCONSISTENT;
|
||||
stat->dds_guid = dsl_dataset_phys(ds)->ds_guid;
|
||||
stat->dds_creation_txg = dsl_get_creationtxg(ds);
|
||||
stat->dds_inconsistent = dsl_get_inconsistent(ds);
|
||||
stat->dds_guid = dsl_get_guid(ds);
|
||||
stat->dds_origin[0] = '\0';
|
||||
if (ds->ds_is_snapshot) {
|
||||
stat->dds_is_snapshot = B_TRUE;
|
||||
stat->dds_num_clones =
|
||||
dsl_dataset_phys(ds)->ds_num_children - 1;
|
||||
stat->dds_num_clones = dsl_get_numclones(ds);
|
||||
} else {
|
||||
stat->dds_is_snapshot = B_FALSE;
|
||||
stat->dds_num_clones = 0;
|
||||
|
||||
if (dsl_dir_is_clone(ds->ds_dir)) {
|
||||
dsl_dataset_t *ods;
|
||||
|
||||
VERIFY0(dsl_dataset_hold_obj(dp,
|
||||
dsl_dir_phys(ds->ds_dir)->dd_origin_obj,
|
||||
FTAG, &ods));
|
||||
dsl_dataset_name(ods, stat->dds_origin);
|
||||
dsl_dataset_rele(ods, FTAG);
|
||||
dsl_dir_get_origin(ds->ds_dir, stat->dds_origin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2422,22 +2703,12 @@ struct promotenode {
|
||||
dsl_dataset_t *ds;
|
||||
};
|
||||
|
||||
typedef struct dsl_dataset_promote_arg {
|
||||
const char *ddpa_clonename;
|
||||
dsl_dataset_t *ddpa_clone;
|
||||
list_t shared_snaps, origin_snaps, clone_snaps;
|
||||
dsl_dataset_t *origin_origin; /* origin of the origin */
|
||||
uint64_t used, comp, uncomp, unique, cloneusedsnap, originusedsnap;
|
||||
char *err_ds;
|
||||
cred_t *cr;
|
||||
} dsl_dataset_promote_arg_t;
|
||||
|
||||
static int snaplist_space(list_t *l, uint64_t mintxg, uint64_t *spacep);
|
||||
static int promote_hold(dsl_dataset_promote_arg_t *ddpa, dsl_pool_t *dp,
|
||||
void *tag);
|
||||
static void promote_rele(dsl_dataset_promote_arg_t *ddpa, void *tag);
|
||||
|
||||
static int
|
||||
int
|
||||
dsl_dataset_promote_check(void *arg, dmu_tx_t *tx)
|
||||
{
|
||||
dsl_dataset_promote_arg_t *ddpa = arg;
|
||||
@@ -2449,14 +2720,19 @@ dsl_dataset_promote_check(void *arg, dmu_tx_t *tx)
|
||||
uint64_t unused;
|
||||
uint64_t ss_mv_cnt;
|
||||
size_t max_snap_len;
|
||||
boolean_t conflicting_snaps;
|
||||
|
||||
err = promote_hold(ddpa, dp, FTAG);
|
||||
if (err != 0)
|
||||
return (err);
|
||||
|
||||
hds = ddpa->ddpa_clone;
|
||||
snap = list_head(&ddpa->shared_snaps);
|
||||
origin_ds = snap->ds;
|
||||
max_snap_len = MAXNAMELEN - strlen(ddpa->ddpa_clonename) - 1;
|
||||
|
||||
snap = list_head(&ddpa->origin_snaps);
|
||||
|
||||
if (dsl_dataset_phys(hds)->ds_flags & DS_FLAG_NOPROMOTE) {
|
||||
promote_rele(ddpa, FTAG);
|
||||
return (SET_ERROR(EXDEV));
|
||||
@@ -2511,6 +2787,7 @@ dsl_dataset_promote_check(void *arg, dmu_tx_t *tx)
|
||||
* Note however, if we stop before we reach the ORIGIN we get:
|
||||
* uN + kN + kN-1 + ... + kM - uM-1
|
||||
*/
|
||||
conflicting_snaps = B_FALSE;
|
||||
ss_mv_cnt = 0;
|
||||
ddpa->used = dsl_dataset_phys(origin_ds)->ds_referenced_bytes;
|
||||
ddpa->comp = dsl_dataset_phys(origin_ds)->ds_compressed_bytes;
|
||||
@@ -2539,12 +2816,12 @@ dsl_dataset_promote_check(void *arg, dmu_tx_t *tx)
|
||||
}
|
||||
err = dsl_dataset_snap_lookup(hds, ds->ds_snapname, &val);
|
||||
if (err == 0) {
|
||||
(void) strcpy(ddpa->err_ds, snap->ds->ds_snapname);
|
||||
err = SET_ERROR(EEXIST);
|
||||
fnvlist_add_boolean(ddpa->err_ds,
|
||||
snap->ds->ds_snapname);
|
||||
conflicting_snaps = B_TRUE;
|
||||
} else if (err != ENOENT) {
|
||||
goto out;
|
||||
}
|
||||
if (err != ENOENT)
|
||||
goto out;
|
||||
|
||||
/* The very first snapshot does not have a deadlist */
|
||||
if (dsl_dataset_phys(ds)->ds_prev_snap_obj == 0)
|
||||
@@ -2557,6 +2834,15 @@ dsl_dataset_promote_check(void *arg, dmu_tx_t *tx)
|
||||
ddpa->uncomp += dluncomp;
|
||||
}
|
||||
|
||||
/*
|
||||
* In order to return the full list of conflicting snapshots, we check
|
||||
* whether there was a conflict after traversing all of them.
|
||||
*/
|
||||
if (conflicting_snaps) {
|
||||
err = SET_ERROR(EEXIST);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we are a clone of a clone then we never reached ORIGIN,
|
||||
* so we need to subtract out the clone origin's used space.
|
||||
@@ -2623,7 +2909,7 @@ out:
|
||||
return (err);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
dsl_dataset_promote_sync(void *arg, dmu_tx_t *tx)
|
||||
{
|
||||
dsl_dataset_promote_arg_t *ddpa = arg;
|
||||
@@ -2950,6 +3236,7 @@ dsl_dataset_promote(const char *name, char *conflsnap)
|
||||
dsl_dataset_promote_arg_t ddpa = { 0 };
|
||||
uint64_t numsnaps;
|
||||
int error;
|
||||
nvpair_t *snap_pair;
|
||||
objset_t *os;
|
||||
|
||||
/*
|
||||
@@ -2967,12 +3254,22 @@ dsl_dataset_promote(const char *name, char *conflsnap)
|
||||
return (error);
|
||||
|
||||
ddpa.ddpa_clonename = name;
|
||||
ddpa.err_ds = conflsnap;
|
||||
ddpa.err_ds = fnvlist_alloc();
|
||||
ddpa.cr = CRED();
|
||||
|
||||
return (dsl_sync_task(name, dsl_dataset_promote_check,
|
||||
error = dsl_sync_task(name, dsl_dataset_promote_check,
|
||||
dsl_dataset_promote_sync, &ddpa,
|
||||
2 + numsnaps, ZFS_SPACE_CHECK_RESERVED));
|
||||
2 + numsnaps, ZFS_SPACE_CHECK_RESERVED);
|
||||
|
||||
/*
|
||||
* Return the first conflicting snapshot found.
|
||||
*/
|
||||
snap_pair = nvlist_next_nvpair(ddpa.err_ds, NULL);
|
||||
if (snap_pair != NULL && conflsnap != NULL)
|
||||
(void) strcpy(conflsnap, nvpair_name(snap_pair));
|
||||
|
||||
fnvlist_free(ddpa.err_ds);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
+114
-82
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2015 by Delphix. All rights reserved.
|
||||
* Copyright (c) 2012, 2016 by Delphix. All rights reserved.
|
||||
* Copyright (c) 2013 Steven Hartland. All rights reserved.
|
||||
* Copyright (c) 2013 by Joyent, Inc. All rights reserved.
|
||||
* Copyright (c) 2016 Actifio, Inc. All rights reserved.
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <sys/dsl_userhold.h>
|
||||
#include <sys/dsl_dataset.h>
|
||||
#include <sys/dsl_synctask.h>
|
||||
#include <sys/dsl_destroy.h>
|
||||
#include <sys/dmu_tx.h>
|
||||
#include <sys/dsl_pool.h>
|
||||
#include <sys/dsl_dir.h>
|
||||
@@ -42,13 +43,7 @@
|
||||
#include <sys/dsl_deleg.h>
|
||||
#include <sys/dmu_impl.h>
|
||||
#include <sys/zvol.h>
|
||||
|
||||
typedef struct dmu_snapshots_destroy_arg {
|
||||
nvlist_t *dsda_snaps;
|
||||
nvlist_t *dsda_successful_snaps;
|
||||
boolean_t dsda_defer;
|
||||
nvlist_t *dsda_errlist;
|
||||
} dmu_snapshots_destroy_arg_t;
|
||||
#include <sys/zcp.h>
|
||||
|
||||
int
|
||||
dsl_destroy_snapshot_check_impl(dsl_dataset_t *ds, boolean_t defer)
|
||||
@@ -86,51 +81,33 @@ dsl_destroy_snapshot_check_impl(dsl_dataset_t *ds, boolean_t defer)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
dsl_destroy_snapshot_check(void *arg, dmu_tx_t *tx)
|
||||
{
|
||||
dmu_snapshots_destroy_arg_t *dsda = arg;
|
||||
dsl_pool_t *dp = dmu_tx_pool(tx);
|
||||
nvpair_t *pair;
|
||||
int error = 0;
|
||||
dsl_destroy_snapshot_arg_t *ddsa = arg;
|
||||
const char *dsname = ddsa->ddsa_name;
|
||||
boolean_t defer = ddsa->ddsa_defer;
|
||||
|
||||
if (!dmu_tx_is_syncing(tx))
|
||||
dsl_pool_t *dp = dmu_tx_pool(tx);
|
||||
int error = 0;
|
||||
dsl_dataset_t *ds;
|
||||
|
||||
error = dsl_dataset_hold(dp, dsname, FTAG, &ds);
|
||||
|
||||
/*
|
||||
* If the snapshot does not exist, silently ignore it, and
|
||||
* dsl_destroy_snapshot_sync() will be a no-op
|
||||
* (it's "already destroyed").
|
||||
*/
|
||||
if (error == ENOENT)
|
||||
return (0);
|
||||
|
||||
for (pair = nvlist_next_nvpair(dsda->dsda_snaps, NULL);
|
||||
pair != NULL; pair = nvlist_next_nvpair(dsda->dsda_snaps, pair)) {
|
||||
dsl_dataset_t *ds;
|
||||
|
||||
error = dsl_dataset_hold(dp, nvpair_name(pair),
|
||||
FTAG, &ds);
|
||||
|
||||
/*
|
||||
* If the snapshot does not exist, silently ignore it
|
||||
* (it's "already destroyed").
|
||||
*/
|
||||
if (error == ENOENT)
|
||||
continue;
|
||||
|
||||
if (error == 0) {
|
||||
error = dsl_destroy_snapshot_check_impl(ds,
|
||||
dsda->dsda_defer);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
fnvlist_add_boolean(dsda->dsda_successful_snaps,
|
||||
nvpair_name(pair));
|
||||
} else {
|
||||
fnvlist_add_int32(dsda->dsda_errlist,
|
||||
nvpair_name(pair), error);
|
||||
}
|
||||
if (error == 0) {
|
||||
error = dsl_destroy_snapshot_check_impl(ds, defer);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
}
|
||||
|
||||
pair = nvlist_next_nvpair(dsda->dsda_errlist, NULL);
|
||||
if (pair != NULL)
|
||||
return (fnvpair_value_int32(pair));
|
||||
|
||||
return (0);
|
||||
return (error);
|
||||
}
|
||||
|
||||
struct process_old_arg {
|
||||
@@ -480,24 +457,23 @@ dsl_destroy_snapshot_sync_impl(dsl_dataset_t *ds, boolean_t defer, dmu_tx_t *tx)
|
||||
dmu_object_free_zapified(mos, obj, tx);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
dsl_destroy_snapshot_sync(void *arg, dmu_tx_t *tx)
|
||||
{
|
||||
dmu_snapshots_destroy_arg_t *dsda = arg;
|
||||
dsl_destroy_snapshot_arg_t *ddsa = arg;
|
||||
const char *dsname = ddsa->ddsa_name;
|
||||
boolean_t defer = ddsa->ddsa_defer;
|
||||
|
||||
dsl_pool_t *dp = dmu_tx_pool(tx);
|
||||
nvpair_t *pair;
|
||||
dsl_dataset_t *ds;
|
||||
|
||||
for (pair = nvlist_next_nvpair(dsda->dsda_successful_snaps, NULL);
|
||||
pair != NULL;
|
||||
pair = nvlist_next_nvpair(dsda->dsda_successful_snaps, pair)) {
|
||||
dsl_dataset_t *ds;
|
||||
|
||||
VERIFY0(dsl_dataset_hold(dp, nvpair_name(pair), FTAG, &ds));
|
||||
|
||||
dsl_destroy_snapshot_sync_impl(ds, dsda->dsda_defer, tx);
|
||||
zvol_remove_minors(dp->dp_spa, nvpair_name(pair), B_TRUE);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
}
|
||||
int error = dsl_dataset_hold(dp, dsname, FTAG, &ds);
|
||||
if (error == ENOENT)
|
||||
return;
|
||||
ASSERT0(error);
|
||||
dsl_destroy_snapshot_sync_impl(ds, defer, tx);
|
||||
zvol_remove_minors(dp->dp_spa, dsname, B_TRUE);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -517,26 +493,86 @@ int
|
||||
dsl_destroy_snapshots_nvl(nvlist_t *snaps, boolean_t defer,
|
||||
nvlist_t *errlist)
|
||||
{
|
||||
dmu_snapshots_destroy_arg_t dsda;
|
||||
int error;
|
||||
nvpair_t *pair;
|
||||
|
||||
pair = nvlist_next_nvpair(snaps, NULL);
|
||||
if (pair == NULL)
|
||||
if (nvlist_next_nvpair(snaps, NULL) == NULL)
|
||||
return (0);
|
||||
|
||||
dsda.dsda_snaps = snaps;
|
||||
VERIFY0(nvlist_alloc(&dsda.dsda_successful_snaps,
|
||||
NV_UNIQUE_NAME, KM_SLEEP));
|
||||
dsda.dsda_defer = defer;
|
||||
dsda.dsda_errlist = errlist;
|
||||
nvlist_t *arg = fnvlist_alloc();
|
||||
nvlist_t *snaps_normalized = fnvlist_alloc();
|
||||
/*
|
||||
* lzc_destroy_snaps() is documented to take an nvlist whose
|
||||
* values "don't matter". We need to convert that nvlist to one
|
||||
* that we know can be converted to LUA.
|
||||
*/
|
||||
for (nvpair_t *pair = nvlist_next_nvpair(snaps, NULL);
|
||||
pair != NULL; pair = nvlist_next_nvpair(snaps, pair)) {
|
||||
fnvlist_add_boolean_value(snaps_normalized,
|
||||
nvpair_name(pair), B_TRUE);
|
||||
}
|
||||
fnvlist_add_nvlist(arg, "snaps", snaps_normalized);
|
||||
fnvlist_free(snaps_normalized);
|
||||
fnvlist_add_boolean_value(arg, "defer", defer);
|
||||
|
||||
error = dsl_sync_task(nvpair_name(pair),
|
||||
dsl_destroy_snapshot_check, dsl_destroy_snapshot_sync,
|
||||
&dsda, 0, ZFS_SPACE_CHECK_NONE);
|
||||
fnvlist_free(dsda.dsda_successful_snaps);
|
||||
nvlist_t *wrapper = fnvlist_alloc();
|
||||
fnvlist_add_nvlist(wrapper, ZCP_ARG_ARGLIST, arg);
|
||||
fnvlist_free(arg);
|
||||
|
||||
return (error);
|
||||
const char *program =
|
||||
"arg = ...\n"
|
||||
"snaps = arg['snaps']\n"
|
||||
"defer = arg['defer']\n"
|
||||
"errors = { }\n"
|
||||
"has_errors = false\n"
|
||||
"for snap, v in pairs(snaps) do\n"
|
||||
" errno = zfs.check.destroy{snap, defer=defer}\n"
|
||||
" zfs.debug('snap: ' .. snap .. ' errno: ' .. errno)\n"
|
||||
" if errno == ENOENT then\n"
|
||||
" snaps[snap] = nil\n"
|
||||
" elseif errno ~= 0 then\n"
|
||||
" errors[snap] = errno\n"
|
||||
" has_errors = true\n"
|
||||
" end\n"
|
||||
"end\n"
|
||||
"if has_errors then\n"
|
||||
" return errors\n"
|
||||
"end\n"
|
||||
"for snap, v in pairs(snaps) do\n"
|
||||
" errno = zfs.sync.destroy{snap, defer=defer}\n"
|
||||
" assert(errno == 0)\n"
|
||||
"end\n"
|
||||
"return { }\n";
|
||||
|
||||
nvlist_t *result = fnvlist_alloc();
|
||||
int error = zcp_eval(nvpair_name(nvlist_next_nvpair(snaps, NULL)),
|
||||
program,
|
||||
0,
|
||||
zfs_lua_max_memlimit,
|
||||
fnvlist_lookup_nvpair(wrapper, ZCP_ARG_ARGLIST), result);
|
||||
if (error != 0) {
|
||||
char *errorstr = NULL;
|
||||
(void) nvlist_lookup_string(result, ZCP_RET_ERROR, &errorstr);
|
||||
if (errorstr != NULL) {
|
||||
zfs_dbgmsg(errorstr);
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
fnvlist_free(wrapper);
|
||||
|
||||
/*
|
||||
* lzc_destroy_snaps() is documented to fill the errlist with
|
||||
* int32 values, so we need to covert the int64 values that are
|
||||
* returned from LUA.
|
||||
*/
|
||||
int rv = 0;
|
||||
nvlist_t *errlist_raw = fnvlist_lookup_nvlist(result, ZCP_RET_RETURN);
|
||||
for (nvpair_t *pair = nvlist_next_nvpair(errlist_raw, NULL);
|
||||
pair != NULL; pair = nvlist_next_nvpair(errlist_raw, pair)) {
|
||||
int32_t val = (int32_t)fnvpair_value_int64(pair);
|
||||
if (rv == 0)
|
||||
rv = val;
|
||||
fnvlist_add_int32(errlist, nvpair_name(pair), val);
|
||||
}
|
||||
fnvlist_free(result);
|
||||
return (rv);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -607,10 +643,6 @@ old_synchronous_dataset_destroy(dsl_dataset_t *ds, dmu_tx_t *tx)
|
||||
dsl_dataset_phys(ds)->ds_unique_bytes == 0);
|
||||
}
|
||||
|
||||
typedef struct dsl_destroy_head_arg {
|
||||
const char *ddha_name;
|
||||
} dsl_destroy_head_arg_t;
|
||||
|
||||
int
|
||||
dsl_destroy_head_check_impl(dsl_dataset_t *ds, int expected_holds)
|
||||
{
|
||||
@@ -656,7 +688,7 @@ dsl_destroy_head_check_impl(dsl_dataset_t *ds, int expected_holds)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
dsl_destroy_head_check(void *arg, dmu_tx_t *tx)
|
||||
{
|
||||
dsl_destroy_head_arg_t *ddha = arg;
|
||||
@@ -894,7 +926,7 @@ dsl_destroy_head_sync_impl(dsl_dataset_t *ds, dmu_tx_t *tx)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
dsl_destroy_head_sync(void *arg, dmu_tx_t *tx)
|
||||
{
|
||||
dsl_destroy_head_arg_t *ddha = arg;
|
||||
|
||||
+112
-35
@@ -947,62 +947,139 @@ dsl_dir_is_clone(dsl_dir_t *dd)
|
||||
dd->dd_pool->dp_origin_snap->ds_object));
|
||||
}
|
||||
|
||||
|
||||
uint64_t
|
||||
dsl_dir_get_used(dsl_dir_t *dd)
|
||||
{
|
||||
return (dsl_dir_phys(dd)->dd_used_bytes);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_dir_get_quota(dsl_dir_t *dd)
|
||||
{
|
||||
return (dsl_dir_phys(dd)->dd_quota);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_dir_get_reservation(dsl_dir_t *dd)
|
||||
{
|
||||
return (dsl_dir_phys(dd)->dd_reserved);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_dir_get_compressratio(dsl_dir_t *dd)
|
||||
{
|
||||
/* a fixed point number, 100x the ratio */
|
||||
return (dsl_dir_phys(dd)->dd_compressed_bytes == 0 ? 100 :
|
||||
(dsl_dir_phys(dd)->dd_uncompressed_bytes * 100 /
|
||||
dsl_dir_phys(dd)->dd_compressed_bytes));
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_dir_get_logicalused(dsl_dir_t *dd)
|
||||
{
|
||||
return (dsl_dir_phys(dd)->dd_uncompressed_bytes);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_dir_get_usedsnap(dsl_dir_t *dd)
|
||||
{
|
||||
return (dsl_dir_phys(dd)->dd_used_breakdown[DD_USED_SNAP]);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_dir_get_usedds(dsl_dir_t *dd)
|
||||
{
|
||||
return (dsl_dir_phys(dd)->dd_used_breakdown[DD_USED_HEAD]);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_dir_get_usedrefreserv(dsl_dir_t *dd)
|
||||
{
|
||||
return (dsl_dir_phys(dd)->dd_used_breakdown[DD_USED_REFRSRV]);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
dsl_dir_get_usedchild(dsl_dir_t *dd)
|
||||
{
|
||||
return (dsl_dir_phys(dd)->dd_used_breakdown[DD_USED_CHILD] +
|
||||
dsl_dir_phys(dd)->dd_used_breakdown[DD_USED_CHILD_RSRV]);
|
||||
}
|
||||
|
||||
void
|
||||
dsl_dir_get_origin(dsl_dir_t *dd, char *buf)
|
||||
{
|
||||
dsl_dataset_t *ds;
|
||||
VERIFY0(dsl_dataset_hold_obj(dd->dd_pool,
|
||||
dsl_dir_phys(dd)->dd_origin_obj, FTAG, &ds));
|
||||
|
||||
dsl_dataset_name(ds, buf);
|
||||
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
}
|
||||
|
||||
int
|
||||
dsl_dir_get_filesystem_count(dsl_dir_t *dd, uint64_t *count)
|
||||
{
|
||||
if (dsl_dir_is_zapified(dd)) {
|
||||
objset_t *os = dd->dd_pool->dp_meta_objset;
|
||||
return (zap_lookup(os, dd->dd_object, DD_FIELD_FILESYSTEM_COUNT,
|
||||
sizeof (*count), 1, count));
|
||||
} else {
|
||||
return (ENOENT);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
dsl_dir_get_snapshot_count(dsl_dir_t *dd, uint64_t *count)
|
||||
{
|
||||
if (dsl_dir_is_zapified(dd)) {
|
||||
objset_t *os = dd->dd_pool->dp_meta_objset;
|
||||
return (zap_lookup(os, dd->dd_object, DD_FIELD_SNAPSHOT_COUNT,
|
||||
sizeof (*count), 1, count));
|
||||
} else {
|
||||
return (ENOENT);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv)
|
||||
{
|
||||
uint64_t intval;
|
||||
|
||||
mutex_enter(&dd->dd_lock);
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USED,
|
||||
dsl_dir_phys(dd)->dd_used_bytes);
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_QUOTA,
|
||||
dsl_dir_phys(dd)->dd_quota);
|
||||
dsl_dir_get_quota(dd));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_RESERVATION,
|
||||
dsl_dir_phys(dd)->dd_reserved);
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_COMPRESSRATIO,
|
||||
dsl_dir_phys(dd)->dd_compressed_bytes == 0 ? 100 :
|
||||
(dsl_dir_phys(dd)->dd_uncompressed_bytes * 100 /
|
||||
dsl_dir_phys(dd)->dd_compressed_bytes));
|
||||
dsl_dir_get_reservation(dd));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_LOGICALUSED,
|
||||
dsl_dir_phys(dd)->dd_uncompressed_bytes);
|
||||
dsl_dir_get_logicalused(dd));
|
||||
if (dsl_dir_phys(dd)->dd_flags & DD_FLAG_USED_BREAKDOWN) {
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USEDSNAP,
|
||||
dsl_dir_phys(dd)->dd_used_breakdown[DD_USED_SNAP]);
|
||||
dsl_dir_get_usedsnap(dd));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USEDDS,
|
||||
dsl_dir_phys(dd)->dd_used_breakdown[DD_USED_HEAD]);
|
||||
dsl_dir_get_usedds(dd));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USEDREFRESERV,
|
||||
dsl_dir_phys(dd)->dd_used_breakdown[DD_USED_REFRSRV]);
|
||||
dsl_dir_get_usedrefreserv(dd));
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USEDCHILD,
|
||||
dsl_dir_phys(dd)->dd_used_breakdown[DD_USED_CHILD] +
|
||||
dsl_dir_phys(dd)->dd_used_breakdown[DD_USED_CHILD_RSRV]);
|
||||
dsl_dir_get_usedchild(dd));
|
||||
}
|
||||
mutex_exit(&dd->dd_lock);
|
||||
|
||||
if (dsl_dir_is_zapified(dd)) {
|
||||
objset_t *os = dd->dd_pool->dp_meta_objset;
|
||||
|
||||
if (zap_lookup(os, dd->dd_object, DD_FIELD_FILESYSTEM_COUNT,
|
||||
sizeof (intval), 1, &intval) == 0) {
|
||||
dsl_prop_nvlist_add_uint64(nv,
|
||||
ZFS_PROP_FILESYSTEM_COUNT, intval);
|
||||
}
|
||||
if (zap_lookup(os, dd->dd_object, DD_FIELD_SNAPSHOT_COUNT,
|
||||
sizeof (intval), 1, &intval) == 0) {
|
||||
dsl_prop_nvlist_add_uint64(nv,
|
||||
ZFS_PROP_SNAPSHOT_COUNT, intval);
|
||||
}
|
||||
uint64_t count;
|
||||
if (dsl_dir_get_filesystem_count(dd, &count) == 0) {
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_FILESYSTEM_COUNT,
|
||||
count);
|
||||
}
|
||||
if (dsl_dir_get_snapshot_count(dd, &count) == 0) {
|
||||
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_SNAPSHOT_COUNT,
|
||||
count);
|
||||
}
|
||||
|
||||
if (dsl_dir_is_clone(dd)) {
|
||||
dsl_dataset_t *ds;
|
||||
char buf[ZFS_MAX_DATASET_NAME_LEN];
|
||||
|
||||
VERIFY0(dsl_dataset_hold_obj(dd->dd_pool,
|
||||
dsl_dir_phys(dd)->dd_origin_obj, FTAG, &ds));
|
||||
dsl_dataset_name(ds, buf);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
dsl_dir_get_origin(dd, buf);
|
||||
dsl_prop_nvlist_add_string(nv, ZFS_PROP_ORIGIN, buf);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -132,7 +132,8 @@ vdev_raidz_math_get_ops()
|
||||
default:
|
||||
ASSERT3U(impl, <, raidz_supp_impl_cnt);
|
||||
ASSERT3U(raidz_supp_impl_cnt, >, 0);
|
||||
ops = raidz_supp_impl[impl];
|
||||
if (impl < ARRAY_SIZE(raidz_all_maths))
|
||||
ops = raidz_supp_impl[impl];
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+1357
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,876 @@
|
||||
/*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* This file and its contents are supplied under the terms of the
|
||||
* Common Development and Distribution License ("CDDL"), version 1.0.
|
||||
* You may only use this file in accordance with the terms of version
|
||||
* 1.0 of the CDDL.
|
||||
*
|
||||
* A full copy of the text of the CDDL should have accompanied this
|
||||
* source. A copy of the CDDL is also available via the Internet at
|
||||
* http://www.illumos.org/license/CDDL.
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 by Delphix. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <sys/lua/lua.h>
|
||||
#include <sys/lua/lualib.h>
|
||||
#include <sys/lua/lauxlib.h>
|
||||
|
||||
#include <zfs_prop.h>
|
||||
|
||||
#include <sys/dsl_prop.h>
|
||||
#include <sys/dsl_synctask.h>
|
||||
#include <sys/dsl_dataset.h>
|
||||
#include <sys/dsl_dir.h>
|
||||
#include <sys/dmu_objset.h>
|
||||
#include <sys/mntent.h>
|
||||
#include <sys/sunddi.h>
|
||||
#include <sys/zap.h>
|
||||
#include <sys/zcp.h>
|
||||
#include <sys/zcp_iter.h>
|
||||
#include <sys/zcp_global.h>
|
||||
#include <sys/zfs_ioctl.h>
|
||||
#include <sys/zfs_znode.h>
|
||||
#include <sys/zvol.h>
|
||||
|
||||
#ifdef _KERNEL
|
||||
#include <sys/zfs_vfsops.h>
|
||||
#endif
|
||||
|
||||
static int
|
||||
get_objset_type(dsl_dataset_t *ds, zfs_type_t *type)
|
||||
{
|
||||
int error;
|
||||
objset_t *os;
|
||||
error = dmu_objset_from_ds(ds, &os);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
if (ds->ds_is_snapshot) {
|
||||
*type = ZFS_TYPE_SNAPSHOT;
|
||||
} else {
|
||||
switch (os->os_phys->os_type) {
|
||||
case DMU_OST_ZFS:
|
||||
*type = ZFS_TYPE_FILESYSTEM;
|
||||
break;
|
||||
case DMU_OST_ZVOL:
|
||||
*type = ZFS_TYPE_VOLUME;
|
||||
break;
|
||||
default:
|
||||
return (EINVAL);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the string name of ds's type in str (a buffer which should be
|
||||
* at least 12 bytes long).
|
||||
*/
|
||||
static int
|
||||
get_objset_type_name(dsl_dataset_t *ds, char *str)
|
||||
{
|
||||
int error;
|
||||
zfs_type_t type;
|
||||
error = get_objset_type(ds, &type);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
switch (type) {
|
||||
case ZFS_TYPE_SNAPSHOT:
|
||||
(void) strcpy(str, "snapshot");
|
||||
break;
|
||||
case ZFS_TYPE_FILESYSTEM:
|
||||
(void) strcpy(str, "filesystem");
|
||||
break;
|
||||
case ZFS_TYPE_VOLUME:
|
||||
(void) strcpy(str, "volume");
|
||||
break;
|
||||
default:
|
||||
return (EINVAL);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Determines the source of a property given its setpoint and
|
||||
* property type. It pushes the source to the lua stack.
|
||||
*/
|
||||
static void
|
||||
get_prop_src(lua_State *state, const char *setpoint, zfs_prop_t prop)
|
||||
{
|
||||
if (zfs_prop_readonly(prop) || (prop == ZFS_PROP_VERSION)) {
|
||||
lua_pushnil(state);
|
||||
} else {
|
||||
const char *src;
|
||||
if (strcmp("", setpoint) == 0) {
|
||||
src = "default";
|
||||
} else {
|
||||
src = setpoint;
|
||||
}
|
||||
(void) lua_pushstring(state, src);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Given an error encountered while getting properties, either longjmp's for
|
||||
* a fatal error or pushes nothing to the stack for a non fatal one.
|
||||
*/
|
||||
static int
|
||||
zcp_handle_error(lua_State *state, const char *dataset_name,
|
||||
const char *property_name, int error)
|
||||
{
|
||||
ASSERT3S(error, !=, 0);
|
||||
if (error == ENOENT) {
|
||||
return (0);
|
||||
} else if (error == EINVAL) {
|
||||
return (luaL_error(state,
|
||||
"property '%s' is not a valid property on dataset '%s'",
|
||||
property_name, dataset_name));
|
||||
} else if (error == EIO) {
|
||||
return (luaL_error(state,
|
||||
"I/O error while retrieving property '%s' on dataset '%s'",
|
||||
property_name, dataset_name));
|
||||
} else {
|
||||
return (luaL_error(state, "unexpected error %d while "
|
||||
"retrieving property '%s' on dataset '%s'",
|
||||
error, property_name, dataset_name));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Look up a user defined property in the zap object. If it exists, push it
|
||||
* and the setpoint onto the stack, otherwise don't push anything.
|
||||
*/
|
||||
static int
|
||||
zcp_get_user_prop(lua_State *state, dsl_pool_t *dp, const char *dataset_name,
|
||||
const char *property_name)
|
||||
{
|
||||
int error;
|
||||
char *buf;
|
||||
char setpoint[ZFS_MAX_DATASET_NAME_LEN];
|
||||
/*
|
||||
* zcp_dataset_hold will either successfully return the requested
|
||||
* dataset or throw a lua error and longjmp out of the zfs.get_prop call
|
||||
* without returning.
|
||||
*/
|
||||
dsl_dataset_t *ds = zcp_dataset_hold(state, dp, dataset_name, FTAG);
|
||||
if (ds == NULL)
|
||||
return (1); /* not reached; zcp_dataset_hold() longjmp'd */
|
||||
|
||||
buf = kmem_alloc(ZAP_MAXVALUELEN, KM_SLEEP);
|
||||
error = dsl_prop_get_ds(ds, property_name, 1, ZAP_MAXVALUELEN,
|
||||
buf, setpoint);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
|
||||
if (error != 0) {
|
||||
kmem_free(buf, ZAP_MAXVALUELEN);
|
||||
return (zcp_handle_error(state, dataset_name, property_name,
|
||||
error));
|
||||
}
|
||||
(void) lua_pushstring(state, buf);
|
||||
(void) lua_pushstring(state, setpoint);
|
||||
kmem_free(buf, ZAP_MAXVALUELEN);
|
||||
return (2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the property we're looking for is stored in the ds_dir. If so,
|
||||
* return it in the 'val' argument. Return 0 on success and ENOENT and if
|
||||
* the property is not present.
|
||||
*/
|
||||
static int
|
||||
get_dsl_dir_prop(dsl_dataset_t *ds, zfs_prop_t zfs_prop,
|
||||
uint64_t *val)
|
||||
{
|
||||
dsl_dir_t *dd = ds->ds_dir;
|
||||
mutex_enter(&dd->dd_lock);
|
||||
switch (zfs_prop) {
|
||||
case ZFS_PROP_USEDSNAP:
|
||||
*val = dsl_dir_get_usedsnap(dd);
|
||||
break;
|
||||
case ZFS_PROP_USEDCHILD:
|
||||
*val = dsl_dir_get_usedchild(dd);
|
||||
break;
|
||||
case ZFS_PROP_USEDDS:
|
||||
*val = dsl_dir_get_usedds(dd);
|
||||
break;
|
||||
case ZFS_PROP_USEDREFRESERV:
|
||||
*val = dsl_dir_get_usedrefreserv(dd);
|
||||
break;
|
||||
case ZFS_PROP_LOGICALUSED:
|
||||
*val = dsl_dir_get_logicalused(dd);
|
||||
break;
|
||||
default:
|
||||
mutex_exit(&dd->dd_lock);
|
||||
return (ENOENT);
|
||||
}
|
||||
mutex_exit(&dd->dd_lock);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Takes a dataset, a property, a value and that value's setpoint as
|
||||
* found in the ZAP. Checks if the property has been changed in the vfs.
|
||||
* If so, val and setpoint will be overwritten with updated content.
|
||||
* Otherwise, they are left unchanged.
|
||||
*/
|
||||
static int
|
||||
get_temporary_prop(dsl_dataset_t *ds, zfs_prop_t zfs_prop, uint64_t *val,
|
||||
char *setpoint)
|
||||
{
|
||||
#if !defined(_KERNEL)
|
||||
return (0);
|
||||
#else
|
||||
int error;
|
||||
zfsvfs_t *zfvp;
|
||||
vfs_t *vfsp;
|
||||
objset_t *os;
|
||||
uint64_t tmp = *val;
|
||||
|
||||
error = dmu_objset_from_ds(ds, &os);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
if (dmu_objset_type(os) != DMU_OST_ZFS)
|
||||
return (EINVAL);
|
||||
|
||||
mutex_enter(&os->os_user_ptr_lock);
|
||||
zfvp = dmu_objset_get_user(os);
|
||||
mutex_exit(&os->os_user_ptr_lock);
|
||||
if (zfvp == NULL)
|
||||
return (ESRCH);
|
||||
|
||||
vfsp = zfvp->z_vfs;
|
||||
|
||||
switch (zfs_prop) {
|
||||
case ZFS_PROP_ATIME:
|
||||
if (vfsp->vfs_do_atime)
|
||||
tmp = vfsp->vfs_atime;
|
||||
break;
|
||||
case ZFS_PROP_RELATIME:
|
||||
if (vfsp->vfs_do_relatime)
|
||||
tmp = vfsp->vfs_relatime;
|
||||
break;
|
||||
case ZFS_PROP_DEVICES:
|
||||
if (vfsp->vfs_do_devices)
|
||||
tmp = vfsp->vfs_devices;
|
||||
break;
|
||||
case ZFS_PROP_EXEC:
|
||||
if (vfsp->vfs_do_exec)
|
||||
tmp = vfsp->vfs_exec;
|
||||
break;
|
||||
case ZFS_PROP_SETUID:
|
||||
if (vfsp->vfs_do_setuid)
|
||||
tmp = vfsp->vfs_setuid;
|
||||
break;
|
||||
case ZFS_PROP_READONLY:
|
||||
if (vfsp->vfs_do_readonly)
|
||||
tmp = vfsp->vfs_readonly;
|
||||
break;
|
||||
case ZFS_PROP_XATTR:
|
||||
if (vfsp->vfs_do_xattr)
|
||||
tmp = vfsp->vfs_xattr;
|
||||
break;
|
||||
case ZFS_PROP_NBMAND:
|
||||
if (vfsp->vfs_do_nbmand)
|
||||
tmp = vfsp->vfs_nbmand;
|
||||
break;
|
||||
default:
|
||||
return (ENOENT);
|
||||
}
|
||||
|
||||
if (tmp != *val) {
|
||||
(void) strcpy(setpoint, "temporary");
|
||||
*val = tmp;
|
||||
}
|
||||
return (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the property we're looking for is stored at the dsl_dataset or
|
||||
* dsl_dir level. If so, push the property value and source onto the lua stack
|
||||
* and return 0. If it is not present or a failure occurs in lookup, return a
|
||||
* non-zero error value.
|
||||
*/
|
||||
static int
|
||||
get_special_prop(lua_State *state, dsl_dataset_t *ds, const char *dsname,
|
||||
zfs_prop_t zfs_prop)
|
||||
{
|
||||
int error = 0;
|
||||
objset_t *os;
|
||||
uint64_t numval;
|
||||
char *strval = kmem_alloc(ZAP_MAXVALUELEN, KM_SLEEP);
|
||||
char setpoint[ZFS_MAX_DATASET_NAME_LEN] =
|
||||
"Internal error - setpoint not determined";
|
||||
zfs_type_t ds_type;
|
||||
zprop_type_t prop_type = zfs_prop_get_type(zfs_prop);
|
||||
(void) get_objset_type(ds, &ds_type);
|
||||
|
||||
switch (zfs_prop) {
|
||||
case ZFS_PROP_REFRATIO:
|
||||
numval = dsl_get_refratio(ds);
|
||||
break;
|
||||
case ZFS_PROP_USED:
|
||||
numval = dsl_get_used(ds);
|
||||
break;
|
||||
case ZFS_PROP_CLONES: {
|
||||
nvlist_t *clones = fnvlist_alloc();
|
||||
error = get_clones_stat_impl(ds, clones);
|
||||
if (error == 0) {
|
||||
/* push list to lua stack */
|
||||
VERIFY0(zcp_nvlist_to_lua(state, clones, NULL, 0ULL));
|
||||
/* source */
|
||||
(void) lua_pushnil(state);
|
||||
}
|
||||
nvlist_free(clones);
|
||||
kmem_free(strval, ZAP_MAXVALUELEN);
|
||||
return (error);
|
||||
}
|
||||
case ZFS_PROP_COMPRESSRATIO:
|
||||
numval = dsl_get_compressratio(ds);
|
||||
break;
|
||||
case ZFS_PROP_CREATION:
|
||||
numval = dsl_get_creation(ds);
|
||||
break;
|
||||
case ZFS_PROP_REFERENCED:
|
||||
numval = dsl_get_referenced(ds);
|
||||
break;
|
||||
case ZFS_PROP_AVAILABLE:
|
||||
numval = dsl_get_available(ds);
|
||||
break;
|
||||
case ZFS_PROP_LOGICALREFERENCED:
|
||||
numval = dsl_get_logicalreferenced(ds);
|
||||
break;
|
||||
case ZFS_PROP_CREATETXG:
|
||||
numval = dsl_get_creationtxg(ds);
|
||||
break;
|
||||
case ZFS_PROP_GUID:
|
||||
numval = dsl_get_guid(ds);
|
||||
break;
|
||||
case ZFS_PROP_UNIQUE:
|
||||
numval = dsl_get_unique(ds);
|
||||
break;
|
||||
case ZFS_PROP_OBJSETID:
|
||||
numval = dsl_get_objsetid(ds);
|
||||
break;
|
||||
case ZFS_PROP_ORIGIN:
|
||||
dsl_dir_get_origin(ds->ds_dir, strval);
|
||||
break;
|
||||
case ZFS_PROP_USERACCOUNTING:
|
||||
error = dmu_objset_from_ds(ds, &os);
|
||||
if (error == 0)
|
||||
numval = dmu_objset_userspace_present(os);
|
||||
break;
|
||||
case ZFS_PROP_WRITTEN:
|
||||
error = dsl_get_written(ds, &numval);
|
||||
break;
|
||||
case ZFS_PROP_TYPE:
|
||||
error = get_objset_type_name(ds, strval);
|
||||
break;
|
||||
case ZFS_PROP_PREV_SNAP:
|
||||
error = dsl_get_prev_snap(ds, strval);
|
||||
break;
|
||||
case ZFS_PROP_NAME:
|
||||
dsl_dataset_name(ds, strval);
|
||||
break;
|
||||
case ZFS_PROP_MOUNTPOINT:
|
||||
error = dsl_get_mountpoint(ds, dsname, strval, setpoint);
|
||||
break;
|
||||
case ZFS_PROP_VERSION:
|
||||
/* should be a snapshot or filesystem */
|
||||
ASSERT(ds_type != ZFS_TYPE_VOLUME);
|
||||
error = dmu_objset_from_ds(ds, &os);
|
||||
/* look in the master node for the version */
|
||||
if (error == 0) {
|
||||
error = zap_lookup(os, MASTER_NODE_OBJ, ZPL_VERSION_STR,
|
||||
sizeof (numval), 1, &numval);
|
||||
}
|
||||
break;
|
||||
case ZFS_PROP_DEFER_DESTROY:
|
||||
numval = dsl_get_defer_destroy(ds);
|
||||
break;
|
||||
case ZFS_PROP_USERREFS:
|
||||
numval = dsl_get_userrefs(ds);
|
||||
break;
|
||||
case ZFS_PROP_FILESYSTEM_COUNT:
|
||||
error = dsl_dir_get_filesystem_count(ds->ds_dir, &numval);
|
||||
(void) strcpy(setpoint, "");
|
||||
break;
|
||||
case ZFS_PROP_SNAPSHOT_COUNT:
|
||||
error = dsl_dir_get_snapshot_count(ds->ds_dir, &numval);
|
||||
(void) strcpy(setpoint, "");
|
||||
break;
|
||||
case ZFS_PROP_NUMCLONES:
|
||||
numval = dsl_get_numclones(ds);
|
||||
break;
|
||||
case ZFS_PROP_INCONSISTENT:
|
||||
numval = dsl_get_inconsistent(ds);
|
||||
break;
|
||||
case ZFS_PROP_RECEIVE_RESUME_TOKEN: {
|
||||
char *token = get_receive_resume_stats_impl(ds);
|
||||
|
||||
VERIFY3U(strlcpy(strval, token, ZAP_MAXVALUELEN),
|
||||
<, ZAP_MAXVALUELEN);
|
||||
if (strcmp(strval, "") == 0) {
|
||||
char *childval = get_child_receive_stats(ds);
|
||||
|
||||
VERIFY3U(strlcpy(strval, childval, ZAP_MAXVALUELEN),
|
||||
<, ZAP_MAXVALUELEN);
|
||||
if (strcmp(strval, "") == 0)
|
||||
error = ENOENT;
|
||||
|
||||
strfree(childval);
|
||||
}
|
||||
strfree(token);
|
||||
break;
|
||||
}
|
||||
case ZFS_PROP_VOLSIZE:
|
||||
ASSERT(ds_type == ZFS_TYPE_VOLUME ||
|
||||
ds_type == ZFS_TYPE_SNAPSHOT);
|
||||
error = dmu_objset_from_ds(ds, &os);
|
||||
if (error == 0) {
|
||||
error = zap_lookup(os, ZVOL_ZAP_OBJ, "size",
|
||||
sizeof (numval), 1, &numval);
|
||||
}
|
||||
if (error == 0)
|
||||
(void) strcpy(setpoint, dsname);
|
||||
|
||||
break;
|
||||
case ZFS_PROP_VOLBLOCKSIZE: {
|
||||
ASSERT(ds_type == ZFS_TYPE_VOLUME);
|
||||
dmu_object_info_t doi;
|
||||
error = dmu_objset_from_ds(ds, &os);
|
||||
if (error == 0) {
|
||||
error = dmu_object_info(os, ZVOL_OBJ, &doi);
|
||||
if (error == 0)
|
||||
numval = doi.doi_data_block_size;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ZFS_PROP_KEYSTATUS:
|
||||
case ZFS_PROP_KEYFORMAT: {
|
||||
/* provide defaults in case no crypto obj exists */
|
||||
setpoint[0] = '\0';
|
||||
if (zfs_prop == ZFS_PROP_KEYSTATUS)
|
||||
numval = ZFS_KEYSTATUS_NONE;
|
||||
else
|
||||
numval = ZFS_KEYFORMAT_NONE;
|
||||
|
||||
nvlist_t *nvl, *propval;
|
||||
nvl = fnvlist_alloc();
|
||||
dsl_dataset_crypt_stats(ds, nvl);
|
||||
if (nvlist_lookup_nvlist(nvl, zfs_prop_to_name(zfs_prop),
|
||||
&propval) == 0) {
|
||||
char *source;
|
||||
|
||||
(void) nvlist_lookup_uint64(propval, ZPROP_VALUE,
|
||||
&numval);
|
||||
if (nvlist_lookup_string(propval, ZPROP_SOURCE,
|
||||
&source) == 0)
|
||||
strlcpy(setpoint, source, sizeof (setpoint));
|
||||
}
|
||||
nvlist_free(nvl);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
/* Did not match these props, check in the dsl_dir */
|
||||
error = get_dsl_dir_prop(ds, zfs_prop, &numval);
|
||||
}
|
||||
if (error != 0) {
|
||||
kmem_free(strval, ZAP_MAXVALUELEN);
|
||||
return (error);
|
||||
}
|
||||
|
||||
switch (prop_type) {
|
||||
case PROP_TYPE_NUMBER: {
|
||||
(void) lua_pushnumber(state, numval);
|
||||
break;
|
||||
}
|
||||
case PROP_TYPE_STRING: {
|
||||
(void) lua_pushstring(state, strval);
|
||||
break;
|
||||
}
|
||||
case PROP_TYPE_INDEX: {
|
||||
const char *propval;
|
||||
error = zfs_prop_index_to_string(zfs_prop, numval, &propval);
|
||||
if (error != 0) {
|
||||
kmem_free(strval, ZAP_MAXVALUELEN);
|
||||
return (error);
|
||||
}
|
||||
(void) lua_pushstring(state, propval);
|
||||
break;
|
||||
}
|
||||
}
|
||||
kmem_free(strval, ZAP_MAXVALUELEN);
|
||||
|
||||
/* Push the source to the stack */
|
||||
get_prop_src(state, setpoint, zfs_prop);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Look up a property and its source in the zap object. If the value is
|
||||
* present and successfully retrieved, push the value and source on the
|
||||
* lua stack and return 0. On failure, return a non-zero error value.
|
||||
*/
|
||||
static int
|
||||
get_zap_prop(lua_State *state, dsl_dataset_t *ds, zfs_prop_t zfs_prop)
|
||||
{
|
||||
int error = 0;
|
||||
char setpoint[ZFS_MAX_DATASET_NAME_LEN];
|
||||
char *strval = kmem_alloc(ZAP_MAXVALUELEN, KM_SLEEP);
|
||||
uint64_t numval;
|
||||
const char *prop_name = zfs_prop_to_name(zfs_prop);
|
||||
zprop_type_t prop_type = zfs_prop_get_type(zfs_prop);
|
||||
|
||||
if (prop_type == PROP_TYPE_STRING) {
|
||||
/* Push value to lua stack */
|
||||
error = dsl_prop_get_ds(ds, prop_name, 1,
|
||||
ZAP_MAXVALUELEN, strval, setpoint);
|
||||
if (error == 0)
|
||||
(void) lua_pushstring(state, strval);
|
||||
} else {
|
||||
error = dsl_prop_get_ds(ds, prop_name, sizeof (numval),
|
||||
1, &numval, setpoint);
|
||||
|
||||
/* Fill in temorary value for prop, if applicable */
|
||||
(void) get_temporary_prop(ds, zfs_prop, &numval, setpoint);
|
||||
|
||||
/* Push value to lua stack */
|
||||
if (prop_type == PROP_TYPE_INDEX) {
|
||||
const char *propval;
|
||||
error = zfs_prop_index_to_string(zfs_prop, numval,
|
||||
&propval);
|
||||
if (error == 0)
|
||||
(void) lua_pushstring(state, propval);
|
||||
} else {
|
||||
if (error == 0)
|
||||
(void) lua_pushnumber(state, numval);
|
||||
}
|
||||
}
|
||||
kmem_free(strval, ZAP_MAXVALUELEN);
|
||||
if (error == 0)
|
||||
get_prop_src(state, setpoint, zfs_prop);
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine whether property is valid for a given dataset
|
||||
*/
|
||||
boolean_t
|
||||
prop_valid_for_ds(dsl_dataset_t *ds, zfs_prop_t zfs_prop)
|
||||
{
|
||||
int error;
|
||||
zfs_type_t zfs_type;
|
||||
|
||||
/* properties not supported */
|
||||
if ((zfs_prop == ZFS_PROP_ISCSIOPTIONS) ||
|
||||
(zfs_prop == ZFS_PROP_MOUNTED))
|
||||
return (B_FALSE);
|
||||
|
||||
/* if we want the origin prop, ds must be a clone */
|
||||
if ((zfs_prop == ZFS_PROP_ORIGIN) && (!dsl_dir_is_clone(ds->ds_dir)))
|
||||
return (B_FALSE);
|
||||
|
||||
error = get_objset_type(ds, &zfs_type);
|
||||
if (error != 0)
|
||||
return (B_FALSE);
|
||||
return (zfs_prop_valid_for_type(zfs_prop, zfs_type, B_FALSE));
|
||||
}
|
||||
|
||||
/*
|
||||
* Look up a given dataset property. On success return 2, the number of
|
||||
* values pushed to the lua stack (property value and source). On a fatal
|
||||
* error, longjmp. On a non fatal error push nothing.
|
||||
*/
|
||||
static int
|
||||
zcp_get_system_prop(lua_State *state, dsl_pool_t *dp, const char *dataset_name,
|
||||
zfs_prop_t zfs_prop)
|
||||
{
|
||||
int error;
|
||||
/*
|
||||
* zcp_dataset_hold will either successfully return the requested
|
||||
* dataset or throw a lua error and longjmp out of the zfs.get_prop call
|
||||
* without returning.
|
||||
*/
|
||||
dsl_dataset_t *ds = zcp_dataset_hold(state, dp, dataset_name, FTAG);
|
||||
if (ds == NULL)
|
||||
return (1); /* not reached; zcp_dataset_hold() longjmp'd */
|
||||
|
||||
/* Check that the property is valid for the given dataset */
|
||||
const char *prop_name = zfs_prop_to_name(zfs_prop);
|
||||
if (!prop_valid_for_ds(ds, zfs_prop)) {
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Check if the property can be accessed directly */
|
||||
error = get_special_prop(state, ds, dataset_name, zfs_prop);
|
||||
if (error == 0) {
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
/* The value and source have been pushed by get_special_prop */
|
||||
return (2);
|
||||
}
|
||||
if (error != ENOENT) {
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
return (zcp_handle_error(state, dataset_name,
|
||||
prop_name, error));
|
||||
}
|
||||
|
||||
/* If we were unable to find it, look in the zap object */
|
||||
error = get_zap_prop(state, ds, zfs_prop);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
if (error != 0) {
|
||||
return (zcp_handle_error(state, dataset_name,
|
||||
prop_name, error));
|
||||
}
|
||||
/* The value and source have been pushed by get_zap_prop */
|
||||
return (2);
|
||||
}
|
||||
|
||||
#ifdef _KERNEL
|
||||
static zfs_userquota_prop_t
|
||||
get_userquota_prop(const char *prop_name)
|
||||
{
|
||||
zfs_userquota_prop_t type;
|
||||
/* Figure out the property type ({user|group}{quota|used}) */
|
||||
for (type = 0; type < ZFS_NUM_USERQUOTA_PROPS; type++) {
|
||||
if (strncmp(prop_name, zfs_userquota_prop_prefixes[type],
|
||||
strlen(zfs_userquota_prop_prefixes[type])) == 0)
|
||||
break;
|
||||
}
|
||||
return (type);
|
||||
}
|
||||
|
||||
/*
|
||||
* Given the name of a zfs_userquota_prop, this function determines the
|
||||
* prop type as well as the numeric group/user ids based on the string
|
||||
* following the '@' in the property name. On success, returns 0. On failure,
|
||||
* returns a non-zero error.
|
||||
* 'domain' must be free'd by caller using strfree()
|
||||
*/
|
||||
static int
|
||||
parse_userquota_prop(const char *prop_name, zfs_userquota_prop_t *type,
|
||||
char **domain, uint64_t *rid)
|
||||
{
|
||||
char *cp, *end, *domain_val;
|
||||
|
||||
*type = get_userquota_prop(prop_name);
|
||||
if (*type >= ZFS_NUM_USERQUOTA_PROPS)
|
||||
return (EINVAL);
|
||||
|
||||
*rid = 0;
|
||||
cp = strchr(prop_name, '@') + 1;
|
||||
if (strncmp(cp, "S-1-", 4) == 0) {
|
||||
/*
|
||||
* It's a numeric SID (eg "S-1-234-567-89") and we want to
|
||||
* seperate the domain id and the rid
|
||||
*/
|
||||
int domain_len = strrchr(cp, '-') - cp;
|
||||
domain_val = kmem_alloc(domain_len + 1, KM_SLEEP);
|
||||
(void) strncpy(domain_val, cp, domain_len);
|
||||
domain_val[domain_len] = '\0';
|
||||
cp += domain_len + 1;
|
||||
|
||||
(void) ddi_strtoll(cp, &end, 10, (longlong_t *)rid);
|
||||
if (*end != '\0') {
|
||||
strfree(domain_val);
|
||||
return (EINVAL);
|
||||
}
|
||||
} else {
|
||||
/* It's only a user/group ID (eg "12345"), just get the rid */
|
||||
domain_val = NULL;
|
||||
(void) ddi_strtoll(cp, &end, 10, (longlong_t *)rid);
|
||||
if (*end != '\0')
|
||||
return (EINVAL);
|
||||
}
|
||||
*domain = domain_val;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Look up {user|group}{quota|used} property for given dataset. On success
|
||||
* push the value (quota or used amount) and the setpoint. On failure, push
|
||||
* a lua error.
|
||||
*/
|
||||
static int
|
||||
zcp_get_userquota_prop(lua_State *state, dsl_pool_t *dp,
|
||||
const char *dataset_name, const char *prop_name)
|
||||
{
|
||||
zfsvfs_t *zfvp;
|
||||
zfsvfs_t *zfsvfs;
|
||||
int error;
|
||||
zfs_userquota_prop_t type;
|
||||
char *domain;
|
||||
uint64_t rid, value = 0;
|
||||
objset_t *os;
|
||||
|
||||
dsl_dataset_t *ds = zcp_dataset_hold(state, dp, dataset_name, FTAG);
|
||||
if (ds == NULL)
|
||||
return (1); /* not reached; zcp_dataset_hold() longjmp'd */
|
||||
|
||||
error = parse_userquota_prop(prop_name, &type, &domain, &rid);
|
||||
if (error == 0) {
|
||||
error = dmu_objset_from_ds(ds, &os);
|
||||
if (error == 0) {
|
||||
zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
|
||||
error = zfsvfs_create_impl(&zfvp, zfsvfs, os);
|
||||
if (error == 0) {
|
||||
error = zfs_userspace_one(zfvp, type, domain,
|
||||
rid, &value);
|
||||
zfsvfs_free(zfvp);
|
||||
}
|
||||
}
|
||||
if (domain != NULL)
|
||||
strfree(domain);
|
||||
}
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
|
||||
if ((value == 0) && ((type == ZFS_PROP_USERQUOTA) ||
|
||||
(type == ZFS_PROP_GROUPQUOTA)))
|
||||
error = ENOENT;
|
||||
if (error != 0) {
|
||||
return (zcp_handle_error(state, dataset_name,
|
||||
prop_name, error));
|
||||
}
|
||||
|
||||
(void) lua_pushnumber(state, value);
|
||||
(void) lua_pushstring(state, dataset_name);
|
||||
return (2);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Determines the name of the snapshot referenced in the written property
|
||||
* name. Returns snapshot name in snap_name, a buffer that must be at least
|
||||
* as large as ZFS_MAX_DATASET_NAME_LEN
|
||||
*/
|
||||
static void
|
||||
parse_written_prop(const char *dataset_name, const char *prop_name,
|
||||
char *snap_name)
|
||||
{
|
||||
ASSERT(zfs_prop_written(prop_name));
|
||||
const char *name = prop_name + ZFS_WRITTEN_PROP_PREFIX_LEN;
|
||||
if (strchr(name, '@') == NULL) {
|
||||
(void) sprintf(snap_name, "%s@%s", dataset_name, name);
|
||||
} else {
|
||||
(void) strcpy(snap_name, name);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Look up written@ property for given dataset. On success
|
||||
* push the value and the setpoint. If error is fatal, we will
|
||||
* longjmp, otherwise push nothing.
|
||||
*/
|
||||
static int
|
||||
zcp_get_written_prop(lua_State *state, dsl_pool_t *dp,
|
||||
const char *dataset_name, const char *prop_name)
|
||||
{
|
||||
char snap_name[ZFS_MAX_DATASET_NAME_LEN];
|
||||
uint64_t used, comp, uncomp;
|
||||
dsl_dataset_t *old;
|
||||
int error = 0;
|
||||
|
||||
parse_written_prop(dataset_name, prop_name, snap_name);
|
||||
dsl_dataset_t *new = zcp_dataset_hold(state, dp, dataset_name, FTAG);
|
||||
if (new == NULL)
|
||||
return (1); /* not reached; zcp_dataset_hold() longjmp'd */
|
||||
|
||||
error = dsl_dataset_hold(dp, snap_name, FTAG, &old);
|
||||
if (error != 0) {
|
||||
dsl_dataset_rele(new, FTAG);
|
||||
return (zcp_dataset_hold_error(state, dp, snap_name,
|
||||
error));
|
||||
}
|
||||
error = dsl_dataset_space_written(old, new,
|
||||
&used, &comp, &uncomp);
|
||||
|
||||
dsl_dataset_rele(old, FTAG);
|
||||
dsl_dataset_rele(new, FTAG);
|
||||
|
||||
if (error != 0) {
|
||||
return (zcp_handle_error(state, dataset_name,
|
||||
snap_name, error));
|
||||
}
|
||||
(void) lua_pushnumber(state, used);
|
||||
(void) lua_pushstring(state, dataset_name);
|
||||
return (2);
|
||||
}
|
||||
|
||||
static int zcp_get_prop(lua_State *state);
|
||||
static zcp_lib_info_t zcp_get_prop_info = {
|
||||
.name = "get_prop",
|
||||
.func = zcp_get_prop,
|
||||
.pargs = {
|
||||
{ .za_name = "dataset", .za_lua_type = LUA_TSTRING},
|
||||
{ .za_name = "property", .za_lua_type = LUA_TSTRING},
|
||||
{NULL, 0}
|
||||
},
|
||||
.kwargs = {
|
||||
{NULL, 0}
|
||||
}
|
||||
};
|
||||
|
||||
static int
|
||||
zcp_get_prop(lua_State *state)
|
||||
{
|
||||
const char *dataset_name;
|
||||
const char *property_name;
|
||||
dsl_pool_t *dp = zcp_run_info(state)->zri_pool;
|
||||
zcp_lib_info_t *libinfo = &zcp_get_prop_info;
|
||||
|
||||
zcp_parse_args(state, libinfo->name, libinfo->pargs, libinfo->kwargs);
|
||||
|
||||
dataset_name = lua_tostring(state, 1);
|
||||
property_name = lua_tostring(state, 2);
|
||||
|
||||
/* User defined property */
|
||||
if (zfs_prop_user(property_name)) {
|
||||
return (zcp_get_user_prop(state, dp,
|
||||
dataset_name, property_name));
|
||||
}
|
||||
/* userspace property */
|
||||
if (zfs_prop_userquota(property_name)) {
|
||||
#ifdef _KERNEL
|
||||
return (zcp_get_userquota_prop(state, dp,
|
||||
dataset_name, property_name));
|
||||
#else
|
||||
return (luaL_error(state,
|
||||
"user quota properties only supported in kernel mode",
|
||||
property_name));
|
||||
#endif
|
||||
}
|
||||
/* written@ property */
|
||||
if (zfs_prop_written(property_name)) {
|
||||
return (zcp_get_written_prop(state, dp,
|
||||
dataset_name, property_name));
|
||||
}
|
||||
|
||||
zfs_prop_t zfs_prop = zfs_name_to_prop(property_name);
|
||||
/* Valid system property */
|
||||
if (zfs_prop != ZPROP_INVAL) {
|
||||
return (zcp_get_system_prop(state, dp, dataset_name,
|
||||
zfs_prop));
|
||||
}
|
||||
|
||||
/* Invalid property name */
|
||||
return (luaL_error(state,
|
||||
"'%s' is not a valid property", property_name));
|
||||
}
|
||||
|
||||
int
|
||||
zcp_load_get_lib(lua_State *state)
|
||||
{
|
||||
lua_pushcclosure(state, zcp_get_prop_info.func, 0);
|
||||
lua_setfield(state, -2, zcp_get_prop_info.name);
|
||||
|
||||
return (1);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* This file and its contents are supplied under the terms of the
|
||||
* Common Development and Distribution License ("CDDL"), version 1.0.
|
||||
* You may only use this file in accordance with the terms of version
|
||||
* 1.0 of the CDDL.
|
||||
*
|
||||
* A full copy of the text of the CDDL should have accompanied this
|
||||
* source. A copy of the CDDL is also available via the Internet at
|
||||
* http://www.illumos.org/license/CDDL.
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 by Delphix. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <sys/zcp_global.h>
|
||||
|
||||
#include <sys/lua/lua.h>
|
||||
#include <sys/lua/lauxlib.h>
|
||||
|
||||
typedef struct zcp_errno_global {
|
||||
const char *zeg_name;
|
||||
int zeg_errno;
|
||||
} zcp_errno_global_t;
|
||||
|
||||
static const zcp_errno_global_t errno_globals[] = {
|
||||
{"EPERM", EPERM},
|
||||
{"ENOENT", ENOENT},
|
||||
{"ESRCH", ESRCH},
|
||||
{"EINTR", EINTR},
|
||||
{"EIO", EIO},
|
||||
{"ENXIO", ENXIO},
|
||||
{"E2BIG", E2BIG},
|
||||
{"ENOEXEC", ENOEXEC},
|
||||
{"EBADF", EBADF},
|
||||
{"ECHILD", ECHILD},
|
||||
{"EAGAIN", EAGAIN},
|
||||
{"ENOMEM", ENOMEM},
|
||||
{"EACCES", EACCES},
|
||||
{"EFAULT", EFAULT},
|
||||
{"ENOTBLK", ENOTBLK},
|
||||
{"EBUSY", EBUSY},
|
||||
{"EEXIST", EEXIST},
|
||||
{"EXDEV", EXDEV},
|
||||
{"ENODEV", ENODEV},
|
||||
{"ENOTDIR", ENOTDIR},
|
||||
{"EISDIR", EISDIR},
|
||||
{"EINVAL", EINVAL},
|
||||
{"ENFILE", ENFILE},
|
||||
{"EMFILE", EMFILE},
|
||||
{"ENOTTY", ENOTTY},
|
||||
{"ETXTBSY", ETXTBSY},
|
||||
{"EFBIG", EFBIG},
|
||||
{"ENOSPC", ENOSPC},
|
||||
{"ESPIPE", ESPIPE},
|
||||
{"EROFS", EROFS},
|
||||
{"EMLINK", EMLINK},
|
||||
{"EPIPE", EPIPE},
|
||||
{"EDOM", EDOM},
|
||||
{"ERANGE", ERANGE},
|
||||
{"EDQUOT", EDQUOT},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static void
|
||||
zcp_load_errno_globals(lua_State *state)
|
||||
{
|
||||
const zcp_errno_global_t *global = errno_globals;
|
||||
while (global->zeg_name != NULL) {
|
||||
lua_pushnumber(state, (lua_Number)global->zeg_errno);
|
||||
lua_setglobal(state, global->zeg_name);
|
||||
global++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
zcp_load_globals(lua_State *state)
|
||||
{
|
||||
zcp_load_errno_globals(state);
|
||||
}
|
||||
@@ -0,0 +1,531 @@
|
||||
/*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* This file and its contents are supplied under the terms of the
|
||||
* Common Development and Distribution License ("CDDL"), version 1.0.
|
||||
* You may only use this file in accordance with the terms of version
|
||||
* 1.0 of the CDDL.
|
||||
*
|
||||
* A full copy of the text of the CDDL should have accompanied this
|
||||
* source. A copy of the CDDL is also available via the Internet at
|
||||
* http://www.illumos.org/license/CDDL.
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 by Delphix. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <sys/lua/lua.h>
|
||||
#include <sys/lua/lauxlib.h>
|
||||
|
||||
#include <sys/dmu.h>
|
||||
#include <sys/dsl_prop.h>
|
||||
#include <sys/dsl_synctask.h>
|
||||
#include <sys/dsl_dataset.h>
|
||||
#include <sys/dsl_pool.h>
|
||||
#include <sys/dmu_tx.h>
|
||||
#include <sys/dmu_objset.h>
|
||||
#include <sys/zap.h>
|
||||
#include <sys/dsl_dir.h>
|
||||
#include <sys/zcp_prop.h>
|
||||
|
||||
#include <sys/zcp.h>
|
||||
|
||||
typedef int (zcp_list_func_t)(lua_State *);
|
||||
typedef struct zcp_list_info {
|
||||
const char *name;
|
||||
zcp_list_func_t *func;
|
||||
zcp_list_func_t *gc;
|
||||
const zcp_arg_t pargs[4];
|
||||
const zcp_arg_t kwargs[2];
|
||||
} zcp_list_info_t;
|
||||
|
||||
static int
|
||||
zcp_clones_iter(lua_State *state)
|
||||
{
|
||||
int err;
|
||||
char clonename[ZFS_MAX_DATASET_NAME_LEN];
|
||||
uint64_t dsobj = lua_tonumber(state, lua_upvalueindex(1));
|
||||
uint64_t cursor = lua_tonumber(state, lua_upvalueindex(2));
|
||||
dsl_pool_t *dp = zcp_run_info(state)->zri_pool;
|
||||
dsl_dataset_t *ds, *clone;
|
||||
zap_attribute_t za;
|
||||
zap_cursor_t zc;
|
||||
|
||||
err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds);
|
||||
if (err == ENOENT) {
|
||||
return (0);
|
||||
} else if (err != 0) {
|
||||
return (luaL_error(state,
|
||||
"unexpected error %d from dsl_dataset_hold_obj(dsobj)",
|
||||
err));
|
||||
}
|
||||
|
||||
if (dsl_dataset_phys(ds)->ds_next_clones_obj == 0) {
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
return (0);
|
||||
}
|
||||
|
||||
zap_cursor_init_serialized(&zc, dp->dp_meta_objset,
|
||||
dsl_dataset_phys(ds)->ds_next_clones_obj, cursor);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
|
||||
err = zap_cursor_retrieve(&zc, &za);
|
||||
if (err != 0) {
|
||||
zap_cursor_fini(&zc);
|
||||
if (err != ENOENT) {
|
||||
return (luaL_error(state,
|
||||
"unexpected error %d from zap_cursor_retrieve()",
|
||||
err));
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
zap_cursor_advance(&zc);
|
||||
cursor = zap_cursor_serialize(&zc);
|
||||
zap_cursor_fini(&zc);
|
||||
|
||||
err = dsl_dataset_hold_obj(dp, za.za_first_integer, FTAG, &clone);
|
||||
if (err != 0) {
|
||||
return (luaL_error(state,
|
||||
"unexpected error %d from "
|
||||
"dsl_dataset_hold_obj(za_first_integer)", err));
|
||||
}
|
||||
|
||||
dsl_dir_name(clone->ds_dir, clonename);
|
||||
dsl_dataset_rele(clone, FTAG);
|
||||
|
||||
lua_pushnumber(state, cursor);
|
||||
lua_replace(state, lua_upvalueindex(2));
|
||||
|
||||
(void) lua_pushstring(state, clonename);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int zcp_clones_list(lua_State *);
|
||||
static zcp_list_info_t zcp_clones_list_info = {
|
||||
.name = "clones",
|
||||
.func = zcp_clones_list,
|
||||
.gc = NULL,
|
||||
.pargs = {
|
||||
{ .za_name = "snapshot", .za_lua_type = LUA_TSTRING},
|
||||
{NULL, 0}
|
||||
},
|
||||
.kwargs = {
|
||||
{NULL, 0}
|
||||
}
|
||||
};
|
||||
|
||||
static int
|
||||
zcp_clones_list(lua_State *state)
|
||||
{
|
||||
const char *snapname = lua_tostring(state, 1);
|
||||
dsl_pool_t *dp = zcp_run_info(state)->zri_pool;
|
||||
boolean_t issnap;
|
||||
uint64_t dsobj, cursor;
|
||||
|
||||
/*
|
||||
* zcp_dataset_hold will either successfully return the requested
|
||||
* dataset or throw a lua error and longjmp out of the zfs.list.clones
|
||||
* call without returning.
|
||||
*/
|
||||
dsl_dataset_t *ds = zcp_dataset_hold(state, dp, snapname, FTAG);
|
||||
if (ds == NULL)
|
||||
return (1); /* not reached; zcp_dataset_hold() longjmp'd */
|
||||
cursor = 0;
|
||||
issnap = ds->ds_is_snapshot;
|
||||
dsobj = ds->ds_object;
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
|
||||
if (!issnap) {
|
||||
return (zcp_argerror(state, 1, "%s is not a snapshot",
|
||||
snapname));
|
||||
}
|
||||
|
||||
lua_pushnumber(state, dsobj);
|
||||
lua_pushnumber(state, cursor);
|
||||
lua_pushcclosure(state, &zcp_clones_iter, 2);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
zcp_snapshots_iter(lua_State *state)
|
||||
{
|
||||
int err;
|
||||
char snapname[ZFS_MAX_DATASET_NAME_LEN];
|
||||
uint64_t dsobj = lua_tonumber(state, lua_upvalueindex(1));
|
||||
uint64_t cursor = lua_tonumber(state, lua_upvalueindex(2));
|
||||
dsl_pool_t *dp = zcp_run_info(state)->zri_pool;
|
||||
dsl_dataset_t *ds;
|
||||
objset_t *os;
|
||||
char *p;
|
||||
|
||||
err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds);
|
||||
if (err != 0) {
|
||||
return (luaL_error(state,
|
||||
"unexpected error %d from dsl_dataset_hold_obj(dsobj)",
|
||||
err));
|
||||
}
|
||||
|
||||
dsl_dataset_name(ds, snapname);
|
||||
VERIFY3U(sizeof (snapname), >,
|
||||
strlcat(snapname, "@", sizeof (snapname)));
|
||||
|
||||
p = strchr(snapname, '\0');
|
||||
VERIFY0(dmu_objset_from_ds(ds, &os));
|
||||
err = dmu_snapshot_list_next(os,
|
||||
sizeof (snapname) - (p - snapname), p, NULL, &cursor, NULL);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
|
||||
if (err == ENOENT) {
|
||||
return (0);
|
||||
} else if (err != 0) {
|
||||
return (luaL_error(state,
|
||||
"unexpected error %d from dmu_snapshot_list_next()", err));
|
||||
}
|
||||
|
||||
lua_pushnumber(state, cursor);
|
||||
lua_replace(state, lua_upvalueindex(2));
|
||||
|
||||
(void) lua_pushstring(state, snapname);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int zcp_snapshots_list(lua_State *);
|
||||
static zcp_list_info_t zcp_snapshots_list_info = {
|
||||
.name = "snapshots",
|
||||
.func = zcp_snapshots_list,
|
||||
.gc = NULL,
|
||||
.pargs = {
|
||||
{ .za_name = "filesystem | volume", .za_lua_type = LUA_TSTRING},
|
||||
{NULL, 0}
|
||||
},
|
||||
.kwargs = {
|
||||
{NULL, 0}
|
||||
}
|
||||
};
|
||||
|
||||
static int
|
||||
zcp_snapshots_list(lua_State *state)
|
||||
{
|
||||
const char *fsname = lua_tostring(state, 1);
|
||||
dsl_pool_t *dp = zcp_run_info(state)->zri_pool;
|
||||
boolean_t issnap;
|
||||
uint64_t dsobj;
|
||||
|
||||
dsl_dataset_t *ds = zcp_dataset_hold(state, dp, fsname, FTAG);
|
||||
if (ds == NULL)
|
||||
return (1); /* not reached; zcp_dataset_hold() longjmp'd */
|
||||
issnap = ds->ds_is_snapshot;
|
||||
dsobj = ds->ds_object;
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
|
||||
if (issnap) {
|
||||
return (zcp_argerror(state, 1,
|
||||
"argument %s cannot be a snapshot", fsname));
|
||||
}
|
||||
|
||||
lua_pushnumber(state, dsobj);
|
||||
lua_pushnumber(state, 0);
|
||||
lua_pushcclosure(state, &zcp_snapshots_iter, 2);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Note: channel programs only run in the global zone, so all datasets
|
||||
* are visible to this zone.
|
||||
*/
|
||||
static boolean_t
|
||||
dataset_name_hidden(const char *name)
|
||||
{
|
||||
if (strchr(name, '$') != NULL)
|
||||
return (B_TRUE);
|
||||
if (strchr(name, '%') != NULL)
|
||||
return (B_TRUE);
|
||||
return (B_FALSE);
|
||||
}
|
||||
|
||||
static int
|
||||
zcp_children_iter(lua_State *state)
|
||||
{
|
||||
int err;
|
||||
char childname[ZFS_MAX_DATASET_NAME_LEN];
|
||||
uint64_t dsobj = lua_tonumber(state, lua_upvalueindex(1));
|
||||
uint64_t cursor = lua_tonumber(state, lua_upvalueindex(2));
|
||||
zcp_run_info_t *ri = zcp_run_info(state);
|
||||
dsl_pool_t *dp = ri->zri_pool;
|
||||
dsl_dataset_t *ds;
|
||||
objset_t *os;
|
||||
char *p;
|
||||
|
||||
err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds);
|
||||
if (err != 0) {
|
||||
return (luaL_error(state,
|
||||
"unexpected error %d from dsl_dataset_hold_obj(dsobj)",
|
||||
err));
|
||||
}
|
||||
|
||||
dsl_dataset_name(ds, childname);
|
||||
VERIFY3U(sizeof (childname), >,
|
||||
strlcat(childname, "/", sizeof (childname)));
|
||||
p = strchr(childname, '\0');
|
||||
|
||||
VERIFY0(dmu_objset_from_ds(ds, &os));
|
||||
do {
|
||||
err = dmu_dir_list_next(os,
|
||||
sizeof (childname) - (p - childname), p, NULL, &cursor);
|
||||
} while (err == 0 && dataset_name_hidden(childname));
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
|
||||
if (err == ENOENT) {
|
||||
return (0);
|
||||
} else if (err != 0) {
|
||||
return (luaL_error(state,
|
||||
"unexpected error %d from dmu_dir_list_next()",
|
||||
err));
|
||||
}
|
||||
|
||||
lua_pushnumber(state, cursor);
|
||||
lua_replace(state, lua_upvalueindex(2));
|
||||
|
||||
(void) lua_pushstring(state, childname);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int zcp_children_list(lua_State *);
|
||||
static zcp_list_info_t zcp_children_list_info = {
|
||||
.name = "children",
|
||||
.func = zcp_children_list,
|
||||
.gc = NULL,
|
||||
.pargs = {
|
||||
{ .za_name = "filesystem | volume", .za_lua_type = LUA_TSTRING},
|
||||
{NULL, 0}
|
||||
},
|
||||
.kwargs = {
|
||||
{NULL, 0}
|
||||
}
|
||||
};
|
||||
|
||||
static int
|
||||
zcp_children_list(lua_State *state)
|
||||
{
|
||||
const char *fsname = lua_tostring(state, 1);
|
||||
dsl_pool_t *dp = zcp_run_info(state)->zri_pool;
|
||||
boolean_t issnap;
|
||||
uint64_t dsobj;
|
||||
|
||||
dsl_dataset_t *ds = zcp_dataset_hold(state, dp, fsname, FTAG);
|
||||
if (ds == NULL)
|
||||
return (1); /* not reached; zcp_dataset_hold() longjmp'd */
|
||||
|
||||
issnap = ds->ds_is_snapshot;
|
||||
dsobj = ds->ds_object;
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
|
||||
if (issnap) {
|
||||
return (zcp_argerror(state, 1,
|
||||
"argument %s cannot be a snapshot", fsname));
|
||||
}
|
||||
|
||||
lua_pushnumber(state, dsobj);
|
||||
lua_pushnumber(state, 0);
|
||||
lua_pushcclosure(state, &zcp_children_iter, 2);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
zcp_props_list_gc(lua_State *state)
|
||||
{
|
||||
nvlist_t **props = lua_touserdata(state, 1);
|
||||
if (*props != NULL)
|
||||
fnvlist_free(*props);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
zcp_props_iter(lua_State *state)
|
||||
{
|
||||
char *source, *val;
|
||||
nvlist_t *nvprop;
|
||||
nvlist_t **props = lua_touserdata(state, lua_upvalueindex(1));
|
||||
nvpair_t *pair = lua_touserdata(state, lua_upvalueindex(2));
|
||||
|
||||
do {
|
||||
pair = nvlist_next_nvpair(*props, pair);
|
||||
if (pair == NULL) {
|
||||
fnvlist_free(*props);
|
||||
*props = NULL;
|
||||
return (0);
|
||||
}
|
||||
} while (!zfs_prop_user(nvpair_name(pair)));
|
||||
|
||||
lua_pushlightuserdata(state, pair);
|
||||
lua_replace(state, lua_upvalueindex(2));
|
||||
|
||||
nvprop = fnvpair_value_nvlist(pair);
|
||||
val = fnvlist_lookup_string(nvprop, ZPROP_VALUE);
|
||||
source = fnvlist_lookup_string(nvprop, ZPROP_SOURCE);
|
||||
|
||||
(void) lua_pushstring(state, nvpair_name(pair));
|
||||
(void) lua_pushstring(state, val);
|
||||
(void) lua_pushstring(state, source);
|
||||
return (3);
|
||||
}
|
||||
|
||||
static int zcp_props_list(lua_State *);
|
||||
static zcp_list_info_t zcp_props_list_info = {
|
||||
.name = "properties",
|
||||
.func = zcp_props_list,
|
||||
.gc = zcp_props_list_gc,
|
||||
.pargs = {
|
||||
{ .za_name = "filesystem | snapshot | volume",
|
||||
.za_lua_type = LUA_TSTRING},
|
||||
{NULL, 0}
|
||||
},
|
||||
.kwargs = {
|
||||
{NULL, 0}
|
||||
}
|
||||
};
|
||||
|
||||
static int
|
||||
zcp_props_list(lua_State *state)
|
||||
{
|
||||
const char *dsname = lua_tostring(state, 1);
|
||||
dsl_pool_t *dp = zcp_run_info(state)->zri_pool;
|
||||
objset_t *os;
|
||||
nvlist_t **props = lua_newuserdata(state, sizeof (nvlist_t *));
|
||||
|
||||
dsl_dataset_t *ds = zcp_dataset_hold(state, dp, dsname, FTAG);
|
||||
if (ds == NULL)
|
||||
return (1); /* not reached; zcp_dataset_hold() longjmp'd */
|
||||
VERIFY0(dmu_objset_from_ds(ds, &os));
|
||||
VERIFY0(dsl_prop_get_all(os, props));
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
|
||||
/*
|
||||
* Set the metatable for the properties list to free it on completion.
|
||||
*/
|
||||
luaL_getmetatable(state, zcp_props_list_info.name);
|
||||
(void) lua_setmetatable(state, -2);
|
||||
|
||||
lua_pushlightuserdata(state, NULL);
|
||||
lua_pushcclosure(state, &zcp_props_iter, 2);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Populate nv with all valid properties and their values for the given
|
||||
* dataset.
|
||||
*/
|
||||
static void
|
||||
zcp_dataset_props(dsl_dataset_t *ds, nvlist_t *nv)
|
||||
{
|
||||
for (int prop = ZFS_PROP_TYPE; prop < ZFS_NUM_PROPS; prop++) {
|
||||
/* Do not display hidden props */
|
||||
if (!zfs_prop_visible(prop))
|
||||
continue;
|
||||
/* Do not display props not valid for this dataset */
|
||||
if (!prop_valid_for_ds(ds, prop))
|
||||
continue;
|
||||
fnvlist_add_boolean(nv, zfs_prop_to_name(prop));
|
||||
}
|
||||
}
|
||||
|
||||
static int zcp_system_props_list(lua_State *);
|
||||
static zcp_list_info_t zcp_system_props_list_info = {
|
||||
.name = "system_properties",
|
||||
.func = zcp_system_props_list,
|
||||
.pargs = {
|
||||
{ .za_name = "dataset", .za_lua_type = LUA_TSTRING},
|
||||
{NULL, 0}
|
||||
},
|
||||
.kwargs = {
|
||||
{NULL, 0}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Get a list of all visble properties and their values for a given dataset.
|
||||
* Returned on the stack as a Lua table.
|
||||
*/
|
||||
static int
|
||||
zcp_system_props_list(lua_State *state)
|
||||
{
|
||||
int error;
|
||||
char errbuf[128];
|
||||
const char *dataset_name;
|
||||
dsl_pool_t *dp = zcp_run_info(state)->zri_pool;
|
||||
zcp_list_info_t *libinfo = &zcp_system_props_list_info;
|
||||
zcp_parse_args(state, libinfo->name, libinfo->pargs, libinfo->kwargs);
|
||||
dataset_name = lua_tostring(state, 1);
|
||||
nvlist_t *nv = fnvlist_alloc();
|
||||
|
||||
dsl_dataset_t *ds = zcp_dataset_hold(state, dp, dataset_name, FTAG);
|
||||
if (ds == NULL)
|
||||
return (1); /* not reached; zcp_dataset_hold() longjmp'd */
|
||||
|
||||
/* Get the names of all valid properties for this dataset */
|
||||
zcp_dataset_props(ds, nv);
|
||||
dsl_dataset_rele(ds, FTAG);
|
||||
|
||||
/* push list as lua table */
|
||||
error = zcp_nvlist_to_lua(state, nv, errbuf, sizeof (errbuf));
|
||||
nvlist_free(nv);
|
||||
if (error != 0) {
|
||||
return (luaL_error(state,
|
||||
"Error returning nvlist: %s", errbuf));
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
zcp_list_func(lua_State *state)
|
||||
{
|
||||
zcp_list_info_t *info = lua_touserdata(state, lua_upvalueindex(1));
|
||||
|
||||
zcp_parse_args(state, info->name, info->pargs, info->kwargs);
|
||||
|
||||
return (info->func(state));
|
||||
}
|
||||
|
||||
int
|
||||
zcp_load_list_lib(lua_State *state)
|
||||
{
|
||||
int i;
|
||||
zcp_list_info_t *zcp_list_funcs[] = {
|
||||
&zcp_children_list_info,
|
||||
&zcp_snapshots_list_info,
|
||||
&zcp_props_list_info,
|
||||
&zcp_clones_list_info,
|
||||
&zcp_system_props_list_info,
|
||||
NULL
|
||||
};
|
||||
|
||||
lua_newtable(state);
|
||||
|
||||
for (i = 0; zcp_list_funcs[i] != NULL; i++) {
|
||||
zcp_list_info_t *info = zcp_list_funcs[i];
|
||||
|
||||
if (info->gc != NULL) {
|
||||
/*
|
||||
* If the function requires garbage collection, create
|
||||
* a metatable with its name and register the __gc
|
||||
* function.
|
||||
*/
|
||||
(void) luaL_newmetatable(state, info->name);
|
||||
(void) lua_pushstring(state, "__gc");
|
||||
lua_pushcfunction(state, info->gc);
|
||||
lua_settable(state, -3);
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
|
||||
lua_pushlightuserdata(state, info);
|
||||
lua_pushcclosure(state, &zcp_list_func, 1);
|
||||
lua_setfield(state, -2, info->name);
|
||||
info++;
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* This file and its contents are supplied under the terms of the
|
||||
* Common Development and Distribution License ("CDDL"), version 1.0.
|
||||
* You may only use this file in accordance with the terms of version
|
||||
* 1.0 of the CDDL.
|
||||
*
|
||||
* A full copy of the text of the CDDL should have accompanied this
|
||||
* source. A copy of the CDDL is also available via the Internet at
|
||||
* http://www.illumos.org/license/CDDL.
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 by Delphix. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <sys/lua/lua.h>
|
||||
#include <sys/lua/lauxlib.h>
|
||||
|
||||
#include <sys/zcp.h>
|
||||
#include <sys/dsl_dir.h>
|
||||
#include <sys/dsl_pool.h>
|
||||
#include <sys/dsl_prop.h>
|
||||
#include <sys/dsl_synctask.h>
|
||||
#include <sys/dsl_dataset.h>
|
||||
#include <sys/dsl_bookmark.h>
|
||||
#include <sys/dsl_destroy.h>
|
||||
#include <sys/dmu_objset.h>
|
||||
#include <sys/zfs_znode.h>
|
||||
#include <sys/zfeature.h>
|
||||
#include <sys/metaslab.h>
|
||||
|
||||
#define DST_AVG_BLKSHIFT 14
|
||||
|
||||
typedef int (zcp_synctask_func_t)(lua_State *, boolean_t, nvlist_t *);
|
||||
typedef struct zcp_synctask_info {
|
||||
const char *name;
|
||||
zcp_synctask_func_t *func;
|
||||
zfs_space_check_t space_check;
|
||||
int blocks_modified;
|
||||
const zcp_arg_t pargs[4];
|
||||
const zcp_arg_t kwargs[2];
|
||||
} zcp_synctask_info_t;
|
||||
|
||||
/*
|
||||
* Generic synctask interface for channel program syncfuncs.
|
||||
*
|
||||
* To perform some action in syncing context, we'd generally call
|
||||
* dsl_sync_task(), but since the Lua script is already running inside a
|
||||
* synctask we need to leave out some actions (such as acquiring the config
|
||||
* rwlock and performing space checks).
|
||||
*
|
||||
* If 'sync' is false, executes a dry run and returns the error code.
|
||||
*
|
||||
* This function also handles common fatal error cases for channel program
|
||||
* library functions. If a fatal error occurs, err_dsname will be the dataset
|
||||
* name reported in error messages, if supplied.
|
||||
*/
|
||||
static int
|
||||
zcp_sync_task(lua_State *state, dsl_checkfunc_t *checkfunc,
|
||||
dsl_syncfunc_t *syncfunc, void *arg, boolean_t sync, const char *err_dsname)
|
||||
{
|
||||
int err;
|
||||
zcp_run_info_t *ri = zcp_run_info(state);
|
||||
|
||||
err = checkfunc(arg, ri->zri_tx);
|
||||
if (!sync)
|
||||
return (err);
|
||||
|
||||
if (err == 0) {
|
||||
syncfunc(arg, ri->zri_tx);
|
||||
} else if (err == EIO) {
|
||||
if (err_dsname != NULL) {
|
||||
return (luaL_error(state,
|
||||
"I/O error while accessing dataset '%s'",
|
||||
err_dsname));
|
||||
} else {
|
||||
return (luaL_error(state,
|
||||
"I/O error while accessing dataset."));
|
||||
}
|
||||
}
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
|
||||
static int zcp_synctask_destroy(lua_State *, boolean_t, nvlist_t *);
|
||||
static zcp_synctask_info_t zcp_synctask_destroy_info = {
|
||||
.name = "destroy",
|
||||
.func = zcp_synctask_destroy,
|
||||
.space_check = ZFS_SPACE_CHECK_NONE,
|
||||
.blocks_modified = 0,
|
||||
.pargs = {
|
||||
{.za_name = "filesystem | snapshot", .za_lua_type = LUA_TSTRING},
|
||||
{NULL, 0}
|
||||
},
|
||||
.kwargs = {
|
||||
{.za_name = "defer", .za_lua_type = LUA_TBOOLEAN},
|
||||
{NULL, 0}
|
||||
}
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
zcp_synctask_destroy(lua_State *state, boolean_t sync, nvlist_t *err_details)
|
||||
{
|
||||
int err;
|
||||
const char *dsname = lua_tostring(state, 1);
|
||||
|
||||
boolean_t issnap = (strchr(dsname, '@') != NULL);
|
||||
|
||||
if (!issnap && !lua_isnil(state, 2)) {
|
||||
return (luaL_error(state,
|
||||
"'deferred' kwarg only supported for snapshots: %s",
|
||||
dsname));
|
||||
}
|
||||
|
||||
if (issnap) {
|
||||
dsl_destroy_snapshot_arg_t ddsa = { 0 };
|
||||
ddsa.ddsa_name = dsname;
|
||||
if (!lua_isnil(state, 2)) {
|
||||
ddsa.ddsa_defer = lua_toboolean(state, 2);
|
||||
} else {
|
||||
ddsa.ddsa_defer = B_FALSE;
|
||||
}
|
||||
|
||||
err = zcp_sync_task(state, dsl_destroy_snapshot_check,
|
||||
dsl_destroy_snapshot_sync, &ddsa, sync, dsname);
|
||||
} else {
|
||||
dsl_destroy_head_arg_t ddha = { 0 };
|
||||
ddha.ddha_name = dsname;
|
||||
|
||||
err = zcp_sync_task(state, dsl_destroy_head_check,
|
||||
dsl_destroy_head_sync, &ddha, sync, dsname);
|
||||
}
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
static int zcp_synctask_promote(lua_State *, boolean_t, nvlist_t *err_details);
|
||||
static zcp_synctask_info_t zcp_synctask_promote_info = {
|
||||
.name = "promote",
|
||||
.func = zcp_synctask_promote,
|
||||
.space_check = ZFS_SPACE_CHECK_RESERVED,
|
||||
.blocks_modified = 3,
|
||||
.pargs = {
|
||||
{.za_name = "clone", .za_lua_type = LUA_TSTRING},
|
||||
{NULL, 0}
|
||||
},
|
||||
.kwargs = {
|
||||
{NULL, 0}
|
||||
}
|
||||
};
|
||||
|
||||
static int
|
||||
zcp_synctask_promote(lua_State *state, boolean_t sync, nvlist_t *err_details)
|
||||
{
|
||||
int err;
|
||||
dsl_dataset_promote_arg_t ddpa = { 0 };
|
||||
const char *dsname = lua_tostring(state, 1);
|
||||
zcp_run_info_t *ri = zcp_run_info(state);
|
||||
|
||||
ddpa.ddpa_clonename = dsname;
|
||||
ddpa.err_ds = err_details;
|
||||
ddpa.cr = ri->zri_cred;
|
||||
|
||||
/*
|
||||
* If there was a snapshot name conflict, then err_ds will be filled
|
||||
* with a list of conflicting snapshot names.
|
||||
*/
|
||||
err = zcp_sync_task(state, dsl_dataset_promote_check,
|
||||
dsl_dataset_promote_sync, &ddpa, sync, dsname);
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
void
|
||||
zcp_synctask_wrapper_cleanup(void *arg)
|
||||
{
|
||||
fnvlist_free(arg);
|
||||
}
|
||||
|
||||
static int
|
||||
zcp_synctask_wrapper(lua_State *state)
|
||||
{
|
||||
int err;
|
||||
int num_ret = 1;
|
||||
nvlist_t *err_details = fnvlist_alloc();
|
||||
|
||||
/*
|
||||
* Make sure err_details is properly freed, even if a fatal error is
|
||||
* thrown during the synctask.
|
||||
*/
|
||||
zcp_register_cleanup(state, &zcp_synctask_wrapper_cleanup, err_details);
|
||||
|
||||
zcp_synctask_info_t *info = lua_touserdata(state, lua_upvalueindex(1));
|
||||
boolean_t sync = lua_toboolean(state, lua_upvalueindex(2));
|
||||
|
||||
zcp_run_info_t *ri = zcp_run_info(state);
|
||||
dsl_pool_t *dp = ri->zri_pool;
|
||||
|
||||
/* MOS space is triple-dittoed, so we multiply by 3. */
|
||||
uint64_t funcspace = (info->blocks_modified << DST_AVG_BLKSHIFT) * 3;
|
||||
|
||||
zcp_parse_args(state, info->name, info->pargs, info->kwargs);
|
||||
|
||||
err = 0;
|
||||
if (info->space_check != ZFS_SPACE_CHECK_NONE && funcspace > 0) {
|
||||
uint64_t quota = dsl_pool_adjustedsize(dp,
|
||||
info->space_check == ZFS_SPACE_CHECK_RESERVED) -
|
||||
metaslab_class_get_deferred(spa_normal_class(dp->dp_spa));
|
||||
uint64_t used = dsl_dir_phys(dp->dp_root_dir)->dd_used_bytes +
|
||||
ri->zri_space_used;
|
||||
|
||||
if (used + funcspace > quota) {
|
||||
err = SET_ERROR(ENOSPC);
|
||||
}
|
||||
}
|
||||
|
||||
if (err == 0) {
|
||||
err = info->func(state, sync, err_details);
|
||||
}
|
||||
|
||||
if (err == 0) {
|
||||
ri->zri_space_used += funcspace;
|
||||
}
|
||||
|
||||
lua_pushnumber(state, (lua_Number)err);
|
||||
if (fnvlist_num_pairs(err_details) > 0) {
|
||||
(void) zcp_nvlist_to_lua(state, err_details, NULL, 0);
|
||||
num_ret++;
|
||||
}
|
||||
|
||||
zcp_clear_cleanup(state);
|
||||
fnvlist_free(err_details);
|
||||
|
||||
return (num_ret);
|
||||
}
|
||||
|
||||
int
|
||||
zcp_load_synctask_lib(lua_State *state, boolean_t sync)
|
||||
{
|
||||
int i;
|
||||
zcp_synctask_info_t *zcp_synctask_funcs[] = {
|
||||
&zcp_synctask_destroy_info,
|
||||
&zcp_synctask_promote_info,
|
||||
NULL
|
||||
};
|
||||
|
||||
lua_newtable(state);
|
||||
|
||||
for (i = 0; zcp_synctask_funcs[i] != NULL; i++) {
|
||||
zcp_synctask_info_t *info = zcp_synctask_funcs[i];
|
||||
lua_pushlightuserdata(state, info);
|
||||
lua_pushboolean(state, sync);
|
||||
lua_pushcclosure(state, &zcp_synctask_wrapper, 2);
|
||||
lua_setfield(state, -2, info->name);
|
||||
info++;
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
+69
-11
@@ -27,7 +27,7 @@
|
||||
* 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, 2016 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]
|
||||
@@ -193,6 +193,7 @@
|
||||
#include <sys/dsl_bookmark.h>
|
||||
#include <sys/dsl_userhold.h>
|
||||
#include <sys/zfeature.h>
|
||||
#include <sys/zcp.h>
|
||||
#include <sys/zio_checksum.h>
|
||||
|
||||
#include <linux/miscdevice.h>
|
||||
@@ -203,6 +204,9 @@
|
||||
#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.
|
||||
@@ -1414,17 +1418,11 @@ put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
getzfsvfs(const char *dsname, zfsvfs_t **zfvp)
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -1436,6 +1434,20 @@ getzfsvfs(const char *dsname, zfsvfs_t **zfvp)
|
||||
error = SET_ERROR(ESRCH);
|
||||
}
|
||||
mutex_exit(&os->os_user_ptr_lock);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static 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);
|
||||
}
|
||||
@@ -3660,6 +3672,36 @@ zfs_ioc_destroy_bookmarks(const char *poolname, nvlist_t *innvl,
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
zfs_ioc_channel_program(const char *poolname, nvlist_t *innvl,
|
||||
nvlist_t *outnvl)
|
||||
{
|
||||
char *program;
|
||||
uint64_t instrlimit, memlimit;
|
||||
nvpair_t *nvarg = NULL;
|
||||
|
||||
if (0 != nvlist_lookup_string(innvl, ZCP_ARG_PROGRAM, &program)) {
|
||||
return (EINVAL);
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (0 != nvlist_lookup_nvpair(innvl, ZCP_ARG_ARGLIST, &nvarg)) {
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
if (instrlimit == 0 || instrlimit > zfs_lua_max_instrlimit)
|
||||
return (EINVAL);
|
||||
if (memlimit == 0 || memlimit > ZCP_MAX_MEMLIMIT)
|
||||
return (EINVAL);
|
||||
|
||||
return (zcp_eval(poolname, program, instrlimit, memlimit,
|
||||
nvarg, outnvl));
|
||||
}
|
||||
|
||||
/*
|
||||
* inputs:
|
||||
* zc_name name of dataset to destroy
|
||||
@@ -6333,6 +6375,11 @@ zfs_ioctl_init(void)
|
||||
zfs_secpolicy_config, POOL_NAME, POOL_CHECK_SUSPENDED, B_TRUE,
|
||||
B_TRUE);
|
||||
|
||||
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);
|
||||
|
||||
/* IOCTLS that use the legacy function signature */
|
||||
|
||||
zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE, zfs_ioc_pool_freeze,
|
||||
@@ -6803,12 +6850,23 @@ zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
|
||||
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);
|
||||
}
|
||||
|
||||
+14
-2
@@ -1053,13 +1053,26 @@ zfsvfs_create(const char *osname, zfsvfs_t **zfvp)
|
||||
* We claim to always be readonly so we can open snapshots;
|
||||
* other ZPL code will prevent us from writing to snapshots.
|
||||
*/
|
||||
|
||||
error = dmu_objset_own(osname, DMU_OST_ZFS, B_TRUE, B_TRUE,
|
||||
zfsvfs, &os);
|
||||
if (error) {
|
||||
if (error != 0) {
|
||||
kmem_free(zfsvfs, sizeof (zfsvfs_t));
|
||||
return (error);
|
||||
}
|
||||
|
||||
error = zfsvfs_create_impl(zfvp, zfsvfs, os);
|
||||
if (error != 0) {
|
||||
dmu_objset_disown(os, B_TRUE, zfsvfs);
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os)
|
||||
{
|
||||
int error;
|
||||
|
||||
zfsvfs->z_vfs = NULL;
|
||||
zfsvfs->z_sb = NULL;
|
||||
zfsvfs->z_parent = zfsvfs;
|
||||
@@ -1086,7 +1099,6 @@ zfsvfs_create(const char *osname, zfsvfs_t **zfvp)
|
||||
|
||||
error = zfsvfs_init(zfsvfs, os);
|
||||
if (error != 0) {
|
||||
dmu_objset_disown(os, B_TRUE, zfsvfs);
|
||||
*zfvp = NULL;
|
||||
kmem_free(zfsvfs, sizeof (zfsvfs_t));
|
||||
return (error);
|
||||
|
||||
Reference in New Issue
Block a user