2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/* Portions Copyright 2010 Robert Milkowski */
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
#include <sys/cred.h>
|
|
|
|
#include <sys/zfs_context.h>
|
|
|
|
#include <sys/dmu_objset.h>
|
|
|
|
#include <sys/dsl_dir.h>
|
|
|
|
#include <sys/dsl_dataset.h>
|
|
|
|
#include <sys/dsl_prop.h>
|
|
|
|
#include <sys/dsl_pool.h>
|
|
|
|
#include <sys/dsl_synctask.h>
|
|
|
|
#include <sys/dsl_deleg.h>
|
|
|
|
#include <sys/dnode.h>
|
|
|
|
#include <sys/dbuf.h>
|
|
|
|
#include <sys/zvol.h>
|
|
|
|
#include <sys/dmu_tx.h>
|
|
|
|
#include <sys/zap.h>
|
|
|
|
#include <sys/zil.h>
|
|
|
|
#include <sys/dmu_impl.h>
|
|
|
|
#include <sys/zfs_ioctl.h>
|
2010-05-28 20:45:14 +00:00
|
|
|
#include <sys/sa.h>
|
2010-08-26 21:24:34 +00:00
|
|
|
#include <sys/zfs_onexit.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Needed to close a window in dnode_move() that allows the objset to be freed
|
|
|
|
* before it can be safely accessed.
|
|
|
|
*/
|
|
|
|
krwlock_t os_lock;
|
|
|
|
|
|
|
|
void
|
|
|
|
dmu_objset_init(void)
|
|
|
|
{
|
|
|
|
rw_init(&os_lock, NULL, RW_DEFAULT, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dmu_objset_fini(void)
|
|
|
|
{
|
|
|
|
rw_destroy(&os_lock);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
spa_t *
|
|
|
|
dmu_objset_spa(objset_t *os)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
return (os->os_spa);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zilog_t *
|
|
|
|
dmu_objset_zil(objset_t *os)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
return (os->os_zil);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dsl_pool_t *
|
|
|
|
dmu_objset_pool(objset_t *os)
|
|
|
|
{
|
|
|
|
dsl_dataset_t *ds;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((ds = os->os_dsl_dataset) != NULL && ds->ds_dir)
|
2008-11-20 20:01:55 +00:00
|
|
|
return (ds->ds_dir->dd_pool);
|
|
|
|
else
|
2010-05-28 20:45:14 +00:00
|
|
|
return (spa_get_dsl(os->os_spa));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dsl_dataset_t *
|
|
|
|
dmu_objset_ds(objset_t *os)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
return (os->os_dsl_dataset);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dmu_objset_type_t
|
|
|
|
dmu_objset_type(objset_t *os)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
return (os->os_phys->os_type);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dmu_objset_name(objset_t *os, char *buf)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_name(os->os_dsl_dataset, buf);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
dmu_objset_id(objset_t *os)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_t *ds = os->os_dsl_dataset;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
return (ds ? ds->ds_object : 0);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t
|
|
|
|
dmu_objset_syncprop(objset_t *os)
|
|
|
|
{
|
|
|
|
return (os->os_sync);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
dmu_objset_logbias(objset_t *os)
|
|
|
|
{
|
|
|
|
return (os->os_logbias);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
static void
|
|
|
|
checksum_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
objset_t *os = arg;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Inheritance should have been done by now.
|
|
|
|
*/
|
|
|
|
ASSERT(newval != ZIO_CHECKSUM_INHERIT);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_checksum = zio_checksum_select(newval, ZIO_CHECKSUM_ON_VALUE);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
compression_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
objset_t *os = arg;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Inheritance and range checking should have been done by now.
|
|
|
|
*/
|
|
|
|
ASSERT(newval != ZIO_COMPRESS_INHERIT);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_compress = zio_compress_select(newval, ZIO_COMPRESS_ON_VALUE);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copies_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
objset_t *os = arg;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Inheritance and range checking should have been done by now.
|
|
|
|
*/
|
|
|
|
ASSERT(newval > 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(newval <= spa_max_replication(os->os_spa));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_copies = newval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dedup_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
|
|
|
objset_t *os = arg;
|
|
|
|
spa_t *spa = os->os_spa;
|
|
|
|
enum zio_checksum checksum;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inheritance should have been done by now.
|
|
|
|
*/
|
|
|
|
ASSERT(newval != ZIO_CHECKSUM_INHERIT);
|
|
|
|
|
|
|
|
checksum = zio_checksum_dedup_select(spa, newval, ZIO_CHECKSUM_OFF);
|
|
|
|
|
|
|
|
os->os_dedup_checksum = checksum & ZIO_CHECKSUM_MASK;
|
|
|
|
os->os_dedup_verify = !!(checksum & ZIO_CHECKSUM_VERIFY);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
static void
|
|
|
|
primary_cache_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
objset_t *os = arg;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Inheritance and range checking should have been done by now.
|
|
|
|
*/
|
|
|
|
ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE ||
|
|
|
|
newval == ZFS_CACHE_METADATA);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_primary_cache = newval;
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
secondary_cache_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
objset_t *os = arg;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Inheritance and range checking should have been done by now.
|
|
|
|
*/
|
|
|
|
ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE ||
|
|
|
|
newval == ZFS_CACHE_METADATA);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_secondary_cache = newval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
|
|
|
objset_t *os = arg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inheritance and range checking should have been done by now.
|
|
|
|
*/
|
|
|
|
ASSERT(newval == ZFS_SYNC_STANDARD || newval == ZFS_SYNC_ALWAYS ||
|
|
|
|
newval == ZFS_SYNC_DISABLED);
|
|
|
|
|
|
|
|
os->os_sync = newval;
|
|
|
|
if (os->os_zil)
|
|
|
|
zil_set_sync(os->os_zil, newval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
logbias_changed_cb(void *arg, uint64_t newval)
|
|
|
|
{
|
|
|
|
objset_t *os = arg;
|
|
|
|
|
|
|
|
ASSERT(newval == ZFS_LOGBIAS_LATENCY ||
|
|
|
|
newval == ZFS_LOGBIAS_THROUGHPUT);
|
|
|
|
os->os_logbias = newval;
|
|
|
|
if (os->os_zil)
|
|
|
|
zil_set_logbias(os->os_zil, newval);
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
void
|
|
|
|
dmu_objset_byteswap(void *buf, size_t size)
|
|
|
|
{
|
|
|
|
objset_phys_t *osp = buf;
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
ASSERT(size == OBJSET_OLD_PHYS_SIZE || size == sizeof (objset_phys_t));
|
2008-11-20 20:01:55 +00:00
|
|
|
dnode_byteswap(&osp->os_meta_dnode);
|
|
|
|
byteswap_uint64_array(&osp->os_zil_header, sizeof (zil_header_t));
|
|
|
|
osp->os_type = BSWAP_64(osp->os_type);
|
2009-07-02 22:44:48 +00:00
|
|
|
osp->os_flags = BSWAP_64(osp->os_flags);
|
|
|
|
if (size == sizeof (objset_phys_t)) {
|
|
|
|
dnode_byteswap(&osp->os_userused_dnode);
|
|
|
|
dnode_byteswap(&osp->os_groupused_dnode);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
|
2010-05-28 20:45:14 +00:00
|
|
|
objset_t **osp)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
objset_t *os;
|
2008-12-03 20:09:06 +00:00
|
|
|
int i, err;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
ASSERT(ds == NULL || MUTEX_HELD(&ds->ds_opening_lock));
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
os = kmem_zalloc(sizeof (objset_t), KM_SLEEP);
|
|
|
|
os->os_dsl_dataset = ds;
|
|
|
|
os->os_spa = spa;
|
|
|
|
os->os_rootbp = bp;
|
|
|
|
if (!BP_IS_HOLE(os->os_rootbp)) {
|
2008-11-20 20:01:55 +00:00
|
|
|
uint32_t aflags = ARC_WAIT;
|
|
|
|
zbookmark_t zb;
|
2010-05-28 20:45:14 +00:00
|
|
|
SET_BOOKMARK(&zb, ds ? ds->ds_object : DMU_META_OBJSET,
|
|
|
|
ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
|
|
|
|
|
|
|
|
if (DMU_OS_IS_L2CACHEABLE(os))
|
2008-12-03 20:09:06 +00:00
|
|
|
aflags |= ARC_L2CACHE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
dprintf_bp(os->os_rootbp, "reading %s", "");
|
2008-12-03 20:09:06 +00:00
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* XXX when bprewrite scrub can change the bp,
|
2008-12-03 20:09:06 +00:00
|
|
|
* and this is called from dmu_objset_open_ds_os, the bp
|
|
|
|
* could change, and we'll need a lock.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
err = dsl_read_nolock(NULL, spa, os->os_rootbp,
|
|
|
|
arc_getbuf_func, &os->os_phys_buf,
|
2008-11-20 20:01:55 +00:00
|
|
|
ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &aflags, &zb);
|
|
|
|
if (err) {
|
2010-05-28 20:45:14 +00:00
|
|
|
kmem_free(os, sizeof (objset_t));
|
2008-12-03 20:09:06 +00:00
|
|
|
/* convert checksum errors into IO errors */
|
|
|
|
if (err == ECKSUM)
|
|
|
|
err = EIO;
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
}
|
2009-07-02 22:44:48 +00:00
|
|
|
|
|
|
|
/* Increase the blocksize if we are permitted. */
|
|
|
|
if (spa_version(spa) >= SPA_VERSION_USERSPACE &&
|
2010-05-28 20:45:14 +00:00
|
|
|
arc_buf_size(os->os_phys_buf) < sizeof (objset_phys_t)) {
|
2009-07-02 22:44:48 +00:00
|
|
|
arc_buf_t *buf = arc_buf_alloc(spa,
|
2010-05-28 20:45:14 +00:00
|
|
|
sizeof (objset_phys_t), &os->os_phys_buf,
|
2009-07-02 22:44:48 +00:00
|
|
|
ARC_BUFC_METADATA);
|
|
|
|
bzero(buf->b_data, sizeof (objset_phys_t));
|
2010-05-28 20:45:14 +00:00
|
|
|
bcopy(os->os_phys_buf->b_data, buf->b_data,
|
|
|
|
arc_buf_size(os->os_phys_buf));
|
|
|
|
(void) arc_buf_remove_ref(os->os_phys_buf,
|
|
|
|
&os->os_phys_buf);
|
|
|
|
os->os_phys_buf = buf;
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_phys = os->os_phys_buf->b_data;
|
|
|
|
os->os_flags = os->os_phys->os_flags;
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
2009-07-02 22:44:48 +00:00
|
|
|
int size = spa_version(spa) >= SPA_VERSION_USERSPACE ?
|
|
|
|
sizeof (objset_phys_t) : OBJSET_OLD_PHYS_SIZE;
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_phys_buf = arc_buf_alloc(spa, size,
|
|
|
|
&os->os_phys_buf, ARC_BUFC_METADATA);
|
|
|
|
os->os_phys = os->os_phys_buf->b_data;
|
|
|
|
bzero(os->os_phys, size);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: the changed_cb will be called once before the register
|
|
|
|
* func returns, thus changing the checksum/compression from the
|
2008-12-03 20:09:06 +00:00
|
|
|
* default (fletcher2/off). Snapshots don't need to know about
|
|
|
|
* checksum/compression/copies.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2008-12-03 20:09:06 +00:00
|
|
|
if (ds) {
|
|
|
|
err = dsl_prop_register(ds, "primarycache",
|
2010-05-28 20:45:14 +00:00
|
|
|
primary_cache_changed_cb, os);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err == 0)
|
2008-12-03 20:09:06 +00:00
|
|
|
err = dsl_prop_register(ds, "secondarycache",
|
2010-05-28 20:45:14 +00:00
|
|
|
secondary_cache_changed_cb, os);
|
2008-12-03 20:09:06 +00:00
|
|
|
if (!dsl_dataset_is_snapshot(ds)) {
|
|
|
|
if (err == 0)
|
|
|
|
err = dsl_prop_register(ds, "checksum",
|
2010-05-28 20:45:14 +00:00
|
|
|
checksum_changed_cb, os);
|
2008-12-03 20:09:06 +00:00
|
|
|
if (err == 0)
|
|
|
|
err = dsl_prop_register(ds, "compression",
|
2010-05-28 20:45:14 +00:00
|
|
|
compression_changed_cb, os);
|
2008-12-03 20:09:06 +00:00
|
|
|
if (err == 0)
|
|
|
|
err = dsl_prop_register(ds, "copies",
|
2010-05-28 20:45:14 +00:00
|
|
|
copies_changed_cb, os);
|
|
|
|
if (err == 0)
|
|
|
|
err = dsl_prop_register(ds, "dedup",
|
|
|
|
dedup_changed_cb, os);
|
|
|
|
if (err == 0)
|
|
|
|
err = dsl_prop_register(ds, "logbias",
|
|
|
|
logbias_changed_cb, os);
|
|
|
|
if (err == 0)
|
|
|
|
err = dsl_prop_register(ds, "sync",
|
|
|
|
sync_changed_cb, os);
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err) {
|
2010-05-28 20:45:14 +00:00
|
|
|
VERIFY(arc_buf_remove_ref(os->os_phys_buf,
|
|
|
|
&os->os_phys_buf) == 1);
|
|
|
|
kmem_free(os, sizeof (objset_t));
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
} else if (ds == NULL) {
|
|
|
|
/* It's the meta-objset. */
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_checksum = ZIO_CHECKSUM_FLETCHER_4;
|
|
|
|
os->os_compress = ZIO_COMPRESS_LZJB;
|
|
|
|
os->os_copies = spa_max_replication(spa);
|
|
|
|
os->os_dedup_checksum = ZIO_CHECKSUM_OFF;
|
|
|
|
os->os_dedup_verify = 0;
|
|
|
|
os->os_logbias = 0;
|
|
|
|
os->os_sync = 0;
|
|
|
|
os->os_primary_cache = ZFS_CACHE_ALL;
|
|
|
|
os->os_secondary_cache = ZFS_CACHE_ALL;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (ds == NULL || !dsl_dataset_is_snapshot(ds))
|
|
|
|
os->os_zil_header = os->os_phys->os_zil_header;
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_zil = zil_alloc(os, &os->os_zil_header);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
for (i = 0; i < TXG_SIZE; i++) {
|
2010-05-28 20:45:14 +00:00
|
|
|
list_create(&os->os_dirty_dnodes[i], sizeof (dnode_t),
|
2008-11-20 20:01:55 +00:00
|
|
|
offsetof(dnode_t, dn_dirty_link[i]));
|
2010-05-28 20:45:14 +00:00
|
|
|
list_create(&os->os_free_dnodes[i], sizeof (dnode_t),
|
2008-11-20 20:01:55 +00:00
|
|
|
offsetof(dnode_t, dn_dirty_link[i]));
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
list_create(&os->os_dnodes, sizeof (dnode_t),
|
2008-11-20 20:01:55 +00:00
|
|
|
offsetof(dnode_t, dn_link));
|
2010-05-28 20:45:14 +00:00
|
|
|
list_create(&os->os_downgraded_dbufs, sizeof (dmu_buf_impl_t),
|
2008-11-20 20:01:55 +00:00
|
|
|
offsetof(dmu_buf_impl_t, db_link));
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_init(&os->os_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
mutex_init(&os->os_obj_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
mutex_init(&os->os_user_ptr_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
DMU_META_DNODE(os) = dnode_special_open(os,
|
|
|
|
&os->os_phys->os_meta_dnode, DMU_META_DNODE_OBJECT,
|
|
|
|
&os->os_meta_dnode);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (arc_buf_size(os->os_phys_buf) >= sizeof (objset_phys_t)) {
|
2010-08-26 21:24:34 +00:00
|
|
|
DMU_USERUSED_DNODE(os) = dnode_special_open(os,
|
|
|
|
&os->os_phys->os_userused_dnode, DMU_USERUSED_OBJECT,
|
|
|
|
&os->os_userused_dnode);
|
|
|
|
DMU_GROUPUSED_DNODE(os) = dnode_special_open(os,
|
|
|
|
&os->os_phys->os_groupused_dnode, DMU_GROUPUSED_OBJECT,
|
|
|
|
&os->os_groupused_dnode);
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We should be the only thread trying to do this because we
|
|
|
|
* have ds_opening_lock
|
|
|
|
*/
|
|
|
|
if (ds) {
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_enter(&ds->ds_lock);
|
|
|
|
ASSERT(ds->ds_objset == NULL);
|
|
|
|
ds->ds_objset = os;
|
|
|
|
mutex_exit(&ds->ds_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
*osp = os;
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
int
|
|
|
|
dmu_objset_from_ds(dsl_dataset_t *ds, objset_t **osp)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
int err = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
mutex_enter(&ds->ds_opening_lock);
|
2010-05-28 20:45:14 +00:00
|
|
|
*osp = ds->ds_objset;
|
|
|
|
if (*osp == NULL) {
|
2008-11-20 20:01:55 +00:00
|
|
|
err = dmu_objset_open_impl(dsl_dataset_get_spa(ds),
|
2010-08-26 21:24:34 +00:00
|
|
|
ds, dsl_dataset_get_blkptr(ds), osp);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
mutex_exit(&ds->ds_opening_lock);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (err);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/* called from zpl */
|
2008-11-20 20:01:55 +00:00
|
|
|
int
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_hold(const char *name, void *tag, objset_t **osp)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_t *ds;
|
2008-11-20 20:01:55 +00:00
|
|
|
int err;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
err = dsl_dataset_hold(name, tag, &ds);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err)
|
2010-05-28 20:45:14 +00:00
|
|
|
return (err);
|
|
|
|
|
|
|
|
err = dmu_objset_from_ds(ds, osp);
|
|
|
|
if (err)
|
|
|
|
dsl_dataset_rele(ds, tag);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called from zpl */
|
|
|
|
int
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_own(const char *name, dmu_objset_type_t type,
|
|
|
|
boolean_t readonly, void *tag, objset_t **osp)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
dsl_dataset_t *ds;
|
|
|
|
int err;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
err = dsl_dataset_own(name, B_FALSE, tag, &ds);
|
|
|
|
if (err)
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
err = dmu_objset_from_ds(ds, osp);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err) {
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_disown(ds, tag);
|
|
|
|
} else if (type != DMU_OST_ANY && type != (*osp)->os_phys->os_type) {
|
|
|
|
dmu_objset_disown(*osp, tag);
|
|
|
|
return (EINVAL);
|
|
|
|
} else if (!readonly && dsl_dataset_is_snapshot(ds)) {
|
|
|
|
dmu_objset_disown(*osp, tag);
|
|
|
|
return (EROFS);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_rele(objset_t *os, void *tag)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_rele(os->os_dsl_dataset, tag);
|
|
|
|
}
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
void
|
|
|
|
dmu_objset_disown(objset_t *os, void *tag)
|
|
|
|
{
|
|
|
|
dsl_dataset_disown(os->os_dsl_dataset, tag);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dmu_objset_evict_dbufs(objset_t *os)
|
|
|
|
{
|
|
|
|
dnode_t *dn;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_enter(&os->os_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* process the mdn last, since the other dnodes have holds on it */
|
2010-08-26 21:24:34 +00:00
|
|
|
list_remove(&os->os_dnodes, DMU_META_DNODE(os));
|
|
|
|
list_insert_tail(&os->os_dnodes, DMU_META_DNODE(os));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the first dnode with holds. We have to do this dance
|
|
|
|
* because dnode_add_ref() only works if you already have a
|
|
|
|
* hold. If there are no holds then it has no dbufs so OK to
|
|
|
|
* skip.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
for (dn = list_head(&os->os_dnodes);
|
2008-11-20 20:01:55 +00:00
|
|
|
dn && !dnode_add_ref(dn, FTAG);
|
2010-05-28 20:45:14 +00:00
|
|
|
dn = list_next(&os->os_dnodes, dn))
|
2008-11-20 20:01:55 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
while (dn) {
|
|
|
|
dnode_t *next_dn = dn;
|
|
|
|
|
|
|
|
do {
|
2010-05-28 20:45:14 +00:00
|
|
|
next_dn = list_next(&os->os_dnodes, next_dn);
|
2008-11-20 20:01:55 +00:00
|
|
|
} while (next_dn && !dnode_add_ref(next_dn, FTAG));
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_exit(&os->os_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
dnode_evict_dbufs(dn);
|
|
|
|
dnode_rele(dn, FTAG);
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_enter(&os->os_lock);
|
2008-11-20 20:01:55 +00:00
|
|
|
dn = next_dn;
|
|
|
|
}
|
2010-08-26 21:24:34 +00:00
|
|
|
dn = list_head(&os->os_dnodes);
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_exit(&os->os_lock);
|
2010-08-26 21:24:34 +00:00
|
|
|
return (dn != DMU_META_DNODE(os));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_evict(objset_t *os)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_t *ds = os->os_dsl_dataset;
|
2010-08-26 16:52:39 +00:00
|
|
|
int t;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 16:52:39 +00:00
|
|
|
for (t = 0; t < TXG_SIZE; t++)
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(!dmu_objset_is_dirty(os, t));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (ds) {
|
|
|
|
if (!dsl_dataset_is_snapshot(ds)) {
|
|
|
|
VERIFY(0 == dsl_prop_unregister(ds, "checksum",
|
2010-05-28 20:45:14 +00:00
|
|
|
checksum_changed_cb, os));
|
2008-12-03 20:09:06 +00:00
|
|
|
VERIFY(0 == dsl_prop_unregister(ds, "compression",
|
2010-05-28 20:45:14 +00:00
|
|
|
compression_changed_cb, os));
|
2008-12-03 20:09:06 +00:00
|
|
|
VERIFY(0 == dsl_prop_unregister(ds, "copies",
|
2010-05-28 20:45:14 +00:00
|
|
|
copies_changed_cb, os));
|
|
|
|
VERIFY(0 == dsl_prop_unregister(ds, "dedup",
|
|
|
|
dedup_changed_cb, os));
|
|
|
|
VERIFY(0 == dsl_prop_unregister(ds, "logbias",
|
|
|
|
logbias_changed_cb, os));
|
|
|
|
VERIFY(0 == dsl_prop_unregister(ds, "sync",
|
|
|
|
sync_changed_cb, os));
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
|
|
|
VERIFY(0 == dsl_prop_unregister(ds, "primarycache",
|
2010-05-28 20:45:14 +00:00
|
|
|
primary_cache_changed_cb, os));
|
2008-12-03 20:09:06 +00:00
|
|
|
VERIFY(0 == dsl_prop_unregister(ds, "secondarycache",
|
2010-05-28 20:45:14 +00:00
|
|
|
secondary_cache_changed_cb, os));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (os->os_sa)
|
|
|
|
sa_tear_down(os);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* We should need only a single pass over the dnode list, since
|
|
|
|
* nothing can be added to the list at this point.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) dmu_objset_evict_dbufs(os);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
dnode_special_close(&os->os_meta_dnode);
|
|
|
|
if (DMU_USERUSED_DNODE(os)) {
|
|
|
|
dnode_special_close(&os->os_userused_dnode);
|
|
|
|
dnode_special_close(&os->os_groupused_dnode);
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
zil_free(os->os_zil);
|
|
|
|
|
|
|
|
ASSERT3P(list_head(&os->os_dnodes), ==, NULL);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
VERIFY(arc_buf_remove_ref(os->os_phys_buf, &os->os_phys_buf) == 1);
|
2010-08-26 21:24:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a barrier to prevent the objset from going away in
|
|
|
|
* dnode_move() until we can safely ensure that the objset is still in
|
|
|
|
* use. We consider the objset valid before the barrier and invalid
|
|
|
|
* after the barrier.
|
|
|
|
*/
|
|
|
|
rw_enter(&os_lock, RW_READER);
|
|
|
|
rw_exit(&os_lock);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
mutex_destroy(&os->os_lock);
|
|
|
|
mutex_destroy(&os->os_obj_lock);
|
|
|
|
mutex_destroy(&os->os_user_ptr_lock);
|
|
|
|
kmem_free(os, sizeof (objset_t));
|
|
|
|
}
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
timestruc_t
|
|
|
|
dmu_objset_snap_cmtime(objset_t *os)
|
|
|
|
{
|
|
|
|
return (dsl_dir_snap_cmtime(os->os_dsl_dataset->ds_dir));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called from dsl for meta-objset */
|
2010-05-28 20:45:14 +00:00
|
|
|
objset_t *
|
2008-11-20 20:01:55 +00:00
|
|
|
dmu_objset_create_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
|
|
|
|
dmu_objset_type_t type, dmu_tx_t *tx)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
objset_t *os;
|
2008-11-20 20:01:55 +00:00
|
|
|
dnode_t *mdn;
|
|
|
|
|
|
|
|
ASSERT(dmu_tx_is_syncing(tx));
|
2010-08-26 21:24:34 +00:00
|
|
|
if (ds != NULL)
|
|
|
|
VERIFY(0 == dmu_objset_from_ds(ds, &os));
|
|
|
|
else
|
|
|
|
VERIFY(0 == dmu_objset_open_impl(spa, NULL, bp, &os));
|
|
|
|
|
|
|
|
mdn = DMU_META_DNODE(os);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
dnode_allocate(mdn, DMU_OT_DNODE, 1 << DNODE_BLOCK_SHIFT,
|
|
|
|
DN_MAX_INDBLKSHIFT, DMU_OT_NONE, 0, tx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't want to have to increase the meta-dnode's nlevels
|
|
|
|
* later, because then we could do it in quescing context while
|
|
|
|
* we are also accessing it in open context.
|
|
|
|
*
|
|
|
|
* This precaution is not necessary for the MOS (ds == NULL),
|
|
|
|
* because the MOS is only updated in syncing context.
|
|
|
|
* This is most fortunate: the MOS is the only objset that
|
|
|
|
* needs to be synced multiple times as spa_sync() iterates
|
|
|
|
* to convergence, so minimizing its dn_nlevels matters.
|
|
|
|
*/
|
|
|
|
if (ds != NULL) {
|
|
|
|
int levels = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the number of levels necessary for the meta-dnode
|
|
|
|
* to contain DN_MAX_OBJECT dnodes.
|
|
|
|
*/
|
|
|
|
while ((uint64_t)mdn->dn_nblkptr << (mdn->dn_datablkshift +
|
|
|
|
(levels - 1) * (mdn->dn_indblkshift - SPA_BLKPTRSHIFT)) <
|
|
|
|
DN_MAX_OBJECT * sizeof (dnode_phys_t))
|
|
|
|
levels++;
|
|
|
|
|
|
|
|
mdn->dn_next_nlevels[tx->tx_txg & TXG_MASK] =
|
|
|
|
mdn->dn_nlevels = levels;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(type != DMU_OST_NONE);
|
|
|
|
ASSERT(type != DMU_OST_ANY);
|
|
|
|
ASSERT(type < DMU_OST_NUMTYPES);
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_phys->os_type = type;
|
|
|
|
if (dmu_objset_userused_enabled(os)) {
|
|
|
|
os->os_phys->os_flags |= OBJSET_FLAG_USERACCOUNTING_COMPLETE;
|
|
|
|
os->os_flags = os->os_phys->os_flags;
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
dsl_dataset_dirty(ds, tx);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
return (os);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct oscarg {
|
|
|
|
void (*userfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
|
|
|
|
void *userarg;
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_t *clone_origin;
|
2008-11-20 20:01:55 +00:00
|
|
|
const char *lastname;
|
|
|
|
dmu_objset_type_t type;
|
|
|
|
uint64_t flags;
|
2010-05-28 20:45:14 +00:00
|
|
|
cred_t *cr;
|
2008-11-20 20:01:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static int
|
|
|
|
dmu_objset_create_check(void *arg1, void *arg2, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
dsl_dir_t *dd = arg1;
|
|
|
|
struct oscarg *oa = arg2;
|
|
|
|
objset_t *mos = dd->dd_pool->dp_meta_objset;
|
|
|
|
int err;
|
|
|
|
uint64_t ddobj;
|
|
|
|
|
|
|
|
err = zap_lookup(mos, dd->dd_phys->dd_child_dir_zapobj,
|
|
|
|
oa->lastname, sizeof (uint64_t), 1, &ddobj);
|
|
|
|
if (err != ENOENT)
|
|
|
|
return (err ? err : EEXIST);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (oa->clone_origin != NULL) {
|
|
|
|
/* You can't clone across pools. */
|
|
|
|
if (oa->clone_origin->ds_dir->dd_pool != dd->dd_pool)
|
2008-11-20 20:01:55 +00:00
|
|
|
return (EXDEV);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/* You can only clone snapshots, not the head datasets. */
|
|
|
|
if (!dsl_dataset_is_snapshot(oa->clone_origin))
|
2008-11-20 20:01:55 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_create_sync(void *arg1, void *arg2, dmu_tx_t *tx)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
dsl_dir_t *dd = arg1;
|
2010-08-26 21:24:34 +00:00
|
|
|
spa_t *spa = dd->dd_pool->dp_spa;
|
2008-11-20 20:01:55 +00:00
|
|
|
struct oscarg *oa = arg2;
|
2010-08-26 21:24:34 +00:00
|
|
|
uint64_t obj;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
ASSERT(dmu_tx_is_syncing(tx));
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
obj = dsl_dataset_create_sync(dd, oa->lastname,
|
2010-05-28 20:45:14 +00:00
|
|
|
oa->clone_origin, oa->flags, oa->cr, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (oa->clone_origin == NULL) {
|
2010-08-26 21:24:34 +00:00
|
|
|
dsl_pool_t *dp = dd->dd_pool;
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_t *ds;
|
|
|
|
blkptr_t *bp;
|
|
|
|
objset_t *os;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
VERIFY3U(0, ==, dsl_dataset_hold_obj(dp, obj, FTAG, &ds));
|
2010-05-28 20:45:14 +00:00
|
|
|
bp = dsl_dataset_get_blkptr(ds);
|
|
|
|
ASSERT(BP_IS_HOLE(bp));
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
os = dmu_objset_create_impl(spa, ds, bp, oa->type, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (oa->userfunc)
|
2010-05-28 20:45:14 +00:00
|
|
|
oa->userfunc(os, oa->userarg, oa->cr, tx);
|
|
|
|
dsl_dataset_rele(ds, FTAG);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
spa_history_log_internal(LOG_DS_CREATE, spa, tx, "dataset = %llu", obj);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
|
2008-11-20 20:01:55 +00:00
|
|
|
void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg)
|
|
|
|
{
|
|
|
|
dsl_dir_t *pdd;
|
|
|
|
const char *tail;
|
|
|
|
int err = 0;
|
|
|
|
struct oscarg oa = { 0 };
|
|
|
|
|
|
|
|
ASSERT(strchr(name, '@') == NULL);
|
|
|
|
err = dsl_dir_open(name, FTAG, &pdd, &tail);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
if (tail == NULL) {
|
|
|
|
dsl_dir_close(pdd, FTAG);
|
|
|
|
return (EEXIST);
|
|
|
|
}
|
|
|
|
|
|
|
|
oa.userfunc = func;
|
|
|
|
oa.userarg = arg;
|
|
|
|
oa.lastname = tail;
|
|
|
|
oa.type = type;
|
|
|
|
oa.flags = flags;
|
2010-05-28 20:45:14 +00:00
|
|
|
oa.cr = CRED();
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
err = dsl_sync_task_do(pdd->dd_pool, dmu_objset_create_check,
|
|
|
|
dmu_objset_create_sync, pdd, &oa, 5);
|
|
|
|
dsl_dir_close(pdd, FTAG);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_clone(const char *name, dsl_dataset_t *clone_origin, uint64_t flags)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dir_t *pdd;
|
|
|
|
const char *tail;
|
|
|
|
int err = 0;
|
|
|
|
struct oscarg oa = { 0 };
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(strchr(name, '@') == NULL);
|
|
|
|
err = dsl_dir_open(name, FTAG, &pdd, &tail);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
if (tail == NULL) {
|
|
|
|
dsl_dir_close(pdd, FTAG);
|
|
|
|
return (EEXIST);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
oa.lastname = tail;
|
|
|
|
oa.clone_origin = clone_origin;
|
|
|
|
oa.flags = flags;
|
|
|
|
oa.cr = CRED();
|
|
|
|
|
|
|
|
err = dsl_sync_task_do(pdd->dd_pool, dmu_objset_create_check,
|
|
|
|
dmu_objset_create_sync, pdd, &oa, 5);
|
|
|
|
dsl_dir_close(pdd, FTAG);
|
|
|
|
return (err);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_destroy(const char *name, boolean_t defer)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
dsl_dataset_t *ds;
|
2010-05-28 20:45:14 +00:00
|
|
|
int error;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
error = dsl_dataset_own(name, B_TRUE, FTAG, &ds);
|
|
|
|
if (error == 0) {
|
|
|
|
error = dsl_dataset_destroy(ds, FTAG, defer);
|
|
|
|
/* dsl_dataset_destroy() closes the ds. */
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct snaparg {
|
|
|
|
dsl_sync_task_group_t *dstg;
|
|
|
|
char *snapname;
|
2010-08-26 21:24:34 +00:00
|
|
|
char *htag;
|
2008-11-20 20:01:55 +00:00
|
|
|
char failed[MAXPATHLEN];
|
2010-05-28 20:45:14 +00:00
|
|
|
boolean_t recursive;
|
2010-08-26 21:24:34 +00:00
|
|
|
boolean_t needsuspend;
|
|
|
|
boolean_t temporary;
|
2009-07-02 22:44:48 +00:00
|
|
|
nvlist_t *props;
|
2010-08-26 21:24:34 +00:00
|
|
|
struct dsl_ds_holdarg *ha; /* only needed in the temporary case */
|
|
|
|
dsl_dataset_t *newds;
|
2008-11-20 20:01:55 +00:00
|
|
|
};
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
static int
|
|
|
|
snapshot_check(void *arg1, void *arg2, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
objset_t *os = arg1;
|
|
|
|
struct snaparg *sn = arg2;
|
2010-08-26 21:24:34 +00:00
|
|
|
int error;
|
2009-07-02 22:44:48 +00:00
|
|
|
|
|
|
|
/* The props have already been checked by zfs_check_userprops(). */
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
error = dsl_dataset_snapshot_check(os->os_dsl_dataset,
|
|
|
|
sn->snapname, tx);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (sn->temporary) {
|
|
|
|
/*
|
|
|
|
* Ideally we would just call
|
|
|
|
* dsl_dataset_user_hold_check() and
|
|
|
|
* dsl_dataset_destroy_check() here. However the
|
|
|
|
* dataset we want to hold and destroy is the snapshot
|
|
|
|
* that we just confirmed we can create, but it won't
|
|
|
|
* exist until after these checks are run. Do any
|
|
|
|
* checks we can here and if more checks are added to
|
|
|
|
* those routines in the future, similar checks may be
|
|
|
|
* necessary here.
|
|
|
|
*/
|
|
|
|
if (spa_version(os->os_spa) < SPA_VERSION_USERREFS)
|
|
|
|
return (ENOTSUP);
|
|
|
|
/*
|
|
|
|
* Not checking number of tags because the tag will be
|
|
|
|
* unique, as it will be the only tag.
|
|
|
|
*/
|
|
|
|
if (strlen(sn->htag) + MAX_TAG_PREFIX_LEN >= MAXNAMELEN)
|
|
|
|
return (E2BIG);
|
|
|
|
|
|
|
|
sn->ha = kmem_alloc(sizeof (struct dsl_ds_holdarg), KM_SLEEP);
|
|
|
|
sn->ha->temphold = B_TRUE;
|
|
|
|
sn->ha->htag = sn->htag;
|
|
|
|
}
|
|
|
|
return (error);
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-28 20:45:14 +00:00
|
|
|
snapshot_sync(void *arg1, void *arg2, dmu_tx_t *tx)
|
2009-07-02 22:44:48 +00:00
|
|
|
{
|
|
|
|
objset_t *os = arg1;
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_t *ds = os->os_dsl_dataset;
|
2009-07-02 22:44:48 +00:00
|
|
|
struct snaparg *sn = arg2;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_snapshot_sync(ds, sn->snapname, tx);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (sn->props) {
|
|
|
|
dsl_props_arg_t pa;
|
|
|
|
pa.pa_props = sn->props;
|
|
|
|
pa.pa_source = ZPROP_SRC_LOCAL;
|
|
|
|
dsl_props_set_sync(ds->ds_prev, &pa, tx);
|
|
|
|
}
|
2010-08-26 21:24:34 +00:00
|
|
|
|
|
|
|
if (sn->temporary) {
|
|
|
|
struct dsl_ds_destroyarg da;
|
|
|
|
|
|
|
|
dsl_dataset_user_hold_sync(ds->ds_prev, sn->ha, tx);
|
|
|
|
kmem_free(sn->ha, sizeof (struct dsl_ds_holdarg));
|
|
|
|
sn->ha = NULL;
|
|
|
|
sn->newds = ds->ds_prev;
|
|
|
|
|
|
|
|
da.ds = ds->ds_prev;
|
|
|
|
da.defer = B_TRUE;
|
|
|
|
dsl_dataset_destroy_sync(&da, FTAG, tx);
|
|
|
|
}
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
static int
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_snapshot_one(const char *name, void *arg)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
struct snaparg *sn = arg;
|
|
|
|
objset_t *os;
|
|
|
|
int err;
|
2010-05-28 20:45:14 +00:00
|
|
|
char *cp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the objset starts with a '%', then ignore it unless it was
|
|
|
|
* explicitly named (ie, not recursive). These hidden datasets
|
|
|
|
* are always inconsistent, and by not opening them here, we can
|
|
|
|
* avoid a race with dsl_dir_destroy_check().
|
|
|
|
*/
|
|
|
|
cp = strrchr(name, '/');
|
|
|
|
if (cp && cp[1] == '%' && sn->recursive)
|
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
(void) strcpy(sn->failed, name);
|
|
|
|
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Check permissions if we are doing a recursive snapshot. The
|
|
|
|
* permission checks for the starting dataset have already been
|
|
|
|
* performed in zfs_secpolicy_snapshot()
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
if (sn->recursive && (err = zfs_secpolicy_snapshot_perms(name, CRED())))
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
err = dmu_objset_hold(name, sn, &os);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* If the objset is in an inconsistent state (eg, in the process
|
|
|
|
* of being destroyed), don't snapshot it. As with %hidden
|
|
|
|
* datasets, we return EBUSY if this name was explicitly
|
|
|
|
* requested (ie, not recursive), and otherwise ignore it.
|
|
|
|
*/
|
|
|
|
if (os->os_dsl_dataset->ds_phys->ds_flags & DS_FLAG_INCONSISTENT) {
|
|
|
|
dmu_objset_rele(os, sn);
|
|
|
|
return (sn->recursive ? 0 : EBUSY);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (sn->needsuspend) {
|
|
|
|
err = zil_suspend(dmu_objset_zil(os));
|
|
|
|
if (err) {
|
|
|
|
dmu_objset_rele(os, sn);
|
|
|
|
return (err);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2010-08-26 21:24:34 +00:00
|
|
|
dsl_sync_task_create(sn->dstg, snapshot_check, snapshot_sync,
|
|
|
|
os, sn, 3);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-08-26 21:24:34 +00:00
|
|
|
dmu_objset_snapshot(char *fsname, char *snapname, char *tag,
|
|
|
|
nvlist_t *props, boolean_t recursive, boolean_t temporary, int cleanup_fd)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
dsl_sync_task_t *dst;
|
2009-07-02 22:44:48 +00:00
|
|
|
struct snaparg sn;
|
2008-11-20 20:01:55 +00:00
|
|
|
spa_t *spa;
|
2010-08-26 21:24:34 +00:00
|
|
|
minor_t minor;
|
2008-11-20 20:01:55 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
(void) strcpy(sn.failed, fsname);
|
|
|
|
|
|
|
|
err = spa_open(fsname, &spa, FTAG);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (temporary) {
|
|
|
|
if (cleanup_fd < 0) {
|
|
|
|
spa_close(spa, FTAG);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if ((err = zfs_onexit_fd_hold(cleanup_fd, &minor)) != 0) {
|
|
|
|
spa_close(spa, FTAG);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
sn.dstg = dsl_sync_task_group_create(spa_get_dsl(spa));
|
|
|
|
sn.snapname = snapname;
|
2010-08-26 21:24:34 +00:00
|
|
|
sn.htag = tag;
|
2009-07-02 22:44:48 +00:00
|
|
|
sn.props = props;
|
2010-05-28 20:45:14 +00:00
|
|
|
sn.recursive = recursive;
|
2010-08-26 21:24:34 +00:00
|
|
|
sn.needsuspend = (spa_version(spa) < SPA_VERSION_FAST_SNAP);
|
|
|
|
sn.temporary = temporary;
|
|
|
|
sn.ha = NULL;
|
|
|
|
sn.newds = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (recursive) {
|
|
|
|
err = dmu_objset_find(fsname,
|
|
|
|
dmu_objset_snapshot_one, &sn, DS_FIND_CHILDREN);
|
|
|
|
} else {
|
|
|
|
err = dmu_objset_snapshot_one(fsname, &sn);
|
|
|
|
}
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
if (err == 0)
|
|
|
|
err = dsl_sync_task_group_wait(sn.dstg);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
for (dst = list_head(&sn.dstg->dstg_tasks); dst;
|
|
|
|
dst = list_next(&sn.dstg->dstg_tasks, dst)) {
|
2009-07-02 22:44:48 +00:00
|
|
|
objset_t *os = dst->dst_arg1;
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_t *ds = os->os_dsl_dataset;
|
2010-08-26 21:24:34 +00:00
|
|
|
if (dst->dst_err) {
|
2008-11-20 20:01:55 +00:00
|
|
|
dsl_dataset_name(ds, sn.failed);
|
2010-08-26 21:24:34 +00:00
|
|
|
} else if (temporary) {
|
|
|
|
dsl_register_onexit_hold_cleanup(sn.newds, tag, minor);
|
|
|
|
}
|
|
|
|
if (sn.needsuspend)
|
|
|
|
zil_resume(dmu_objset_zil(os));
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_rele(os, &sn);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
(void) strcpy(fsname, sn.failed);
|
2010-08-26 21:24:34 +00:00
|
|
|
if (temporary)
|
|
|
|
zfs_onexit_fd_rele(cleanup_fd);
|
2008-11-20 20:01:55 +00:00
|
|
|
dsl_sync_task_group_destroy(sn.dstg);
|
|
|
|
spa_close(spa, FTAG);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-07-02 22:44:48 +00:00
|
|
|
dmu_objset_sync_dnodes(list_t *list, list_t *newlist, dmu_tx_t *tx)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
dnode_t *dn;
|
|
|
|
|
|
|
|
while (dn = list_head(list)) {
|
|
|
|
ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT);
|
|
|
|
ASSERT(dn->dn_dbuf->db_data_pending);
|
|
|
|
/*
|
2009-07-02 22:44:48 +00:00
|
|
|
* Initialize dn_zio outside dnode_sync() because the
|
|
|
|
* meta-dnode needs to set it ouside dnode_sync().
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
dn->dn_zio = dn->dn_dbuf->db_data_pending->dr_zio;
|
|
|
|
ASSERT(dn->dn_zio);
|
|
|
|
|
|
|
|
ASSERT3U(dn->dn_nlevels, <=, DN_MAX_LEVELS);
|
|
|
|
list_remove(list, dn);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
|
|
|
if (newlist) {
|
|
|
|
(void) dnode_add_ref(dn, newlist);
|
|
|
|
list_insert_tail(newlist, dn);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
dnode_sync(dn, tx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static void
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_write_ready(zio_t *zio, arc_buf_t *abuf, void *arg)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-08-26 16:52:39 +00:00
|
|
|
int i;
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
blkptr_t *bp = zio->io_bp;
|
2010-05-28 20:45:14 +00:00
|
|
|
objset_t *os = arg;
|
2008-11-20 20:01:55 +00:00
|
|
|
dnode_phys_t *dnp = &os->os_phys->os_meta_dnode;
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
ASSERT(bp == os->os_rootbp);
|
|
|
|
ASSERT(BP_GET_TYPE(bp) == DMU_OT_OBJSET);
|
|
|
|
ASSERT(BP_GET_LEVEL(bp) == 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
2009-07-02 22:44:48 +00:00
|
|
|
* Update rootbp fill count: it should be the number of objects
|
|
|
|
* allocated in the object set (not counting the "special"
|
|
|
|
* objects that are stored in the objset_phys_t -- the meta
|
|
|
|
* dnode and user/group accounting objects).
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2009-07-02 22:44:48 +00:00
|
|
|
bp->blk_fill = 0;
|
2010-08-26 16:52:39 +00:00
|
|
|
for (i = 0; i < dnp->dn_nblkptr; i++)
|
2008-11-20 20:01:55 +00:00
|
|
|
bp->blk_fill += dnp->dn_blkptr[i].blk_fill;
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static void
|
|
|
|
dmu_objset_write_done(zio_t *zio, arc_buf_t *abuf, void *arg)
|
|
|
|
{
|
|
|
|
blkptr_t *bp = zio->io_bp;
|
|
|
|
blkptr_t *bp_orig = &zio->io_bp_orig;
|
|
|
|
objset_t *os = arg;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (zio->io_flags & ZIO_FLAG_IO_REWRITE) {
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(BP_EQUAL(bp, bp_orig));
|
2008-12-03 20:09:06 +00:00
|
|
|
} else {
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_t *ds = os->os_dsl_dataset;
|
|
|
|
dmu_tx_t *tx = os->os_synctx;
|
|
|
|
|
|
|
|
(void) dsl_dataset_block_kill(ds, bp_orig, tx, B_TRUE);
|
|
|
|
dsl_dataset_block_born(ds, bp, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called from dsl */
|
|
|
|
void
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_sync(objset_t *os, zio_t *pio, dmu_tx_t *tx)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
int txgoff;
|
|
|
|
zbookmark_t zb;
|
2010-05-28 20:45:14 +00:00
|
|
|
zio_prop_t zp;
|
2008-11-20 20:01:55 +00:00
|
|
|
zio_t *zio;
|
|
|
|
list_t *list;
|
2009-07-02 22:44:48 +00:00
|
|
|
list_t *newlist = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
dbuf_dirty_record_t *dr;
|
|
|
|
|
|
|
|
dprintf_ds(os->os_dsl_dataset, "txg=%llu\n", tx->tx_txg);
|
|
|
|
|
|
|
|
ASSERT(dmu_tx_is_syncing(tx));
|
|
|
|
/* XXX the write_done callback should really give us the tx... */
|
|
|
|
os->os_synctx = tx;
|
|
|
|
|
|
|
|
if (os->os_dsl_dataset == NULL) {
|
|
|
|
/*
|
|
|
|
* This is the MOS. If we have upgraded,
|
|
|
|
* spa_max_replication() could change, so reset
|
|
|
|
* os_copies here.
|
|
|
|
*/
|
|
|
|
os->os_copies = spa_max_replication(os->os_spa);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the root block IO
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
SET_BOOKMARK(&zb, os->os_dsl_dataset ?
|
|
|
|
os->os_dsl_dataset->ds_object : DMU_META_OBJSET,
|
|
|
|
ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
|
|
|
|
VERIFY3U(0, ==, arc_release_bp(os->os_phys_buf, &os->os_phys_buf,
|
|
|
|
os->os_rootbp, os->os_spa, &zb));
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_write_policy(os, NULL, 0, 0, &zp);
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
zio = arc_write(pio, os->os_spa, tx->tx_txg,
|
|
|
|
os->os_rootbp, os->os_phys_buf, DMU_OS_IS_L2CACHEABLE(os), &zp,
|
|
|
|
dmu_objset_write_ready, dmu_objset_write_done, os,
|
2008-12-03 20:09:06 +00:00
|
|
|
ZIO_PRIORITY_ASYNC_WRITE, ZIO_FLAG_MUSTSUCCEED, &zb);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
2009-07-02 22:44:48 +00:00
|
|
|
* Sync special dnodes - the parent IO for the sync is the root block
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2010-08-26 21:24:34 +00:00
|
|
|
DMU_META_DNODE(os)->dn_zio = zio;
|
|
|
|
dnode_sync(DMU_META_DNODE(os), tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
os->os_phys->os_flags = os->os_flags;
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (DMU_USERUSED_DNODE(os) &&
|
|
|
|
DMU_USERUSED_DNODE(os)->dn_type != DMU_OT_NONE) {
|
|
|
|
DMU_USERUSED_DNODE(os)->dn_zio = zio;
|
|
|
|
dnode_sync(DMU_USERUSED_DNODE(os), tx);
|
|
|
|
DMU_GROUPUSED_DNODE(os)->dn_zio = zio;
|
|
|
|
dnode_sync(DMU_GROUPUSED_DNODE(os), tx);
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
txgoff = tx->tx_txg & TXG_MASK;
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
if (dmu_objset_userused_enabled(os)) {
|
|
|
|
newlist = &os->os_synced_dnodes;
|
|
|
|
/*
|
|
|
|
* We must create the list here because it uses the
|
|
|
|
* dn_dirty_link[] of this txg.
|
|
|
|
*/
|
|
|
|
list_create(newlist, sizeof (dnode_t),
|
|
|
|
offsetof(dnode_t, dn_dirty_link[txgoff]));
|
|
|
|
}
|
|
|
|
|
|
|
|
dmu_objset_sync_dnodes(&os->os_free_dnodes[txgoff], newlist, tx);
|
|
|
|
dmu_objset_sync_dnodes(&os->os_dirty_dnodes[txgoff], newlist, tx);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
list = &DMU_META_DNODE(os)->dn_dirty_records[txgoff];
|
2008-11-20 20:01:55 +00:00
|
|
|
while (dr = list_head(list)) {
|
|
|
|
ASSERT(dr->dr_dbuf->db_level == 0);
|
|
|
|
list_remove(list, dr);
|
|
|
|
if (dr->dr_zio)
|
|
|
|
zio_nowait(dr->dr_zio);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Free intent log blocks up to this tx.
|
|
|
|
*/
|
|
|
|
zil_sync(os->os_zil, tx);
|
2008-12-03 20:09:06 +00:00
|
|
|
os->os_phys->os_zil_header = os->os_zil_header;
|
2008-11-20 20:01:55 +00:00
|
|
|
zio_nowait(zio);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
boolean_t
|
|
|
|
dmu_objset_is_dirty(objset_t *os, uint64_t txg)
|
|
|
|
{
|
|
|
|
return (!list_is_empty(&os->os_dirty_dnodes[txg & TXG_MASK]) ||
|
|
|
|
!list_is_empty(&os->os_free_dnodes[txg & TXG_MASK]));
|
|
|
|
}
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
boolean_t
|
|
|
|
dmu_objset_is_dirty_anywhere(objset_t *os)
|
|
|
|
{
|
2010-08-26 16:52:39 +00:00
|
|
|
int t;
|
|
|
|
|
|
|
|
for (t = 0; t < TXG_SIZE; t++)
|
2010-08-26 21:24:34 +00:00
|
|
|
if (dmu_objset_is_dirty(os, t))
|
|
|
|
return (B_TRUE);
|
|
|
|
return (B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static objset_used_cb_t *used_cbs[DMU_OST_NUMTYPES];
|
2009-07-02 22:44:48 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
dmu_objset_register_type(dmu_objset_type_t ost, objset_used_cb_t *cb)
|
|
|
|
{
|
|
|
|
used_cbs[ost] = cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean_t
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_userused_enabled(objset_t *os)
|
2009-07-02 22:44:48 +00:00
|
|
|
{
|
|
|
|
return (spa_version(os->os_spa) >= SPA_VERSION_USERSPACE &&
|
2010-08-26 21:24:34 +00:00
|
|
|
used_cbs[os->os_phys->os_type] != NULL &&
|
|
|
|
DMU_USERUSED_DNODE(os) != NULL);
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
static void
|
|
|
|
do_userquota_update(objset_t *os, uint64_t used, uint64_t flags,
|
|
|
|
uint64_t user, uint64_t group, boolean_t subtract, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
if ((flags & DNODE_FLAG_USERUSED_ACCOUNTED)) {
|
|
|
|
int64_t delta = DNODE_SIZE + used;
|
|
|
|
if (subtract)
|
|
|
|
delta = -delta;
|
|
|
|
VERIFY3U(0, ==, zap_increment_int(os, DMU_USERUSED_OBJECT,
|
|
|
|
user, delta, tx));
|
|
|
|
VERIFY3U(0, ==, zap_increment_int(os, DMU_GROUPUSED_OBJECT,
|
|
|
|
group, delta, tx));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
void
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_do_userquota_updates(objset_t *os, dmu_tx_t *tx)
|
2009-07-02 22:44:48 +00:00
|
|
|
{
|
|
|
|
dnode_t *dn;
|
|
|
|
list_t *list = &os->os_synced_dnodes;
|
|
|
|
|
|
|
|
ASSERT(list_head(list) == NULL || dmu_objset_userused_enabled(os));
|
|
|
|
|
|
|
|
while (dn = list_head(list)) {
|
2010-08-26 21:24:34 +00:00
|
|
|
int flags;
|
2009-07-02 22:44:48 +00:00
|
|
|
ASSERT(!DMU_OBJECT_IS_SPECIAL(dn->dn_object));
|
|
|
|
ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE ||
|
|
|
|
dn->dn_phys->dn_flags &
|
|
|
|
DNODE_FLAG_USERUSED_ACCOUNTED);
|
|
|
|
|
|
|
|
/* Allocate the user/groupused objects if necessary. */
|
2010-08-26 21:24:34 +00:00
|
|
|
if (DMU_USERUSED_DNODE(os)->dn_type == DMU_OT_NONE) {
|
2010-05-28 20:45:14 +00:00
|
|
|
VERIFY(0 == zap_create_claim(os,
|
2009-07-02 22:44:48 +00:00
|
|
|
DMU_USERUSED_OBJECT,
|
|
|
|
DMU_OT_USERGROUP_USED, DMU_OT_NONE, 0, tx));
|
2010-05-28 20:45:14 +00:00
|
|
|
VERIFY(0 == zap_create_claim(os,
|
2009-07-02 22:44:48 +00:00
|
|
|
DMU_GROUPUSED_OBJECT,
|
|
|
|
DMU_OT_USERGROUP_USED, DMU_OT_NONE, 0, tx));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* We intentionally modify the zap object even if the
|
|
|
|
* net delta is zero. Otherwise
|
|
|
|
* the block of the zap obj could be shared between
|
|
|
|
* datasets but need to be different between them after
|
|
|
|
* a bprewrite.
|
2009-07-02 22:44:48 +00:00
|
|
|
*/
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
flags = dn->dn_id_flags;
|
|
|
|
ASSERT(flags);
|
|
|
|
if (flags & DN_ID_OLD_EXIST) {
|
2010-05-28 20:45:14 +00:00
|
|
|
do_userquota_update(os, dn->dn_oldused, dn->dn_oldflags,
|
|
|
|
dn->dn_olduid, dn->dn_oldgid, B_TRUE, tx);
|
|
|
|
}
|
2010-08-26 21:24:34 +00:00
|
|
|
if (flags & DN_ID_NEW_EXIST) {
|
2010-05-28 20:45:14 +00:00
|
|
|
do_userquota_update(os, DN_USED_BYTES(dn->dn_phys),
|
|
|
|
dn->dn_phys->dn_flags, dn->dn_newuid,
|
|
|
|
dn->dn_newgid, B_FALSE, tx);
|
|
|
|
}
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
mutex_enter(&dn->dn_mtx);
|
2010-05-28 20:45:14 +00:00
|
|
|
dn->dn_oldused = 0;
|
|
|
|
dn->dn_oldflags = 0;
|
|
|
|
if (dn->dn_id_flags & DN_ID_NEW_EXIST) {
|
|
|
|
dn->dn_olduid = dn->dn_newuid;
|
|
|
|
dn->dn_oldgid = dn->dn_newgid;
|
|
|
|
dn->dn_id_flags |= DN_ID_OLD_EXIST;
|
|
|
|
if (dn->dn_bonuslen == 0)
|
|
|
|
dn->dn_id_flags |= DN_ID_CHKED_SPILL;
|
|
|
|
else
|
|
|
|
dn->dn_id_flags |= DN_ID_CHKED_BONUS;
|
|
|
|
}
|
|
|
|
dn->dn_id_flags &= ~(DN_ID_NEW_EXIST);
|
2009-07-02 22:44:48 +00:00
|
|
|
mutex_exit(&dn->dn_mtx);
|
|
|
|
|
|
|
|
list_remove(list, dn);
|
|
|
|
dnode_rele(dn, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* Returns a pointer to data to find uid/gid from
|
|
|
|
*
|
|
|
|
* If a dirty record for transaction group that is syncing can't
|
|
|
|
* be found then NULL is returned. In the NULL case it is assumed
|
|
|
|
* the uid/gid aren't changing.
|
|
|
|
*/
|
|
|
|
static void *
|
|
|
|
dmu_objset_userquota_find_data(dmu_buf_impl_t *db, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
dbuf_dirty_record_t *dr, **drp;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
if (db->db_dirtycnt == 0)
|
|
|
|
return (db->db.db_data); /* Nothing is changing */
|
|
|
|
|
|
|
|
for (drp = &db->db_last_dirty; (dr = *drp) != NULL; drp = &dr->dr_next)
|
|
|
|
if (dr->dr_txg == tx->tx_txg)
|
|
|
|
break;
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (dr == NULL) {
|
2010-05-28 20:45:14 +00:00
|
|
|
data = NULL;
|
2010-08-26 21:24:34 +00:00
|
|
|
} else {
|
|
|
|
dnode_t *dn;
|
|
|
|
|
|
|
|
DB_DNODE_ENTER(dr->dr_dbuf);
|
|
|
|
dn = DB_DNODE(dr->dr_dbuf);
|
|
|
|
|
|
|
|
if (dn->dn_bonuslen == 0 &&
|
|
|
|
dr->dr_dbuf->db_blkid == DMU_SPILL_BLKID)
|
|
|
|
data = dr->dt.dl.dr_data->b_data;
|
|
|
|
else
|
|
|
|
data = dr->dt.dl.dr_data;
|
|
|
|
|
|
|
|
DB_DNODE_EXIT(dr->dr_dbuf);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
return (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dmu_objset_userquota_get_ids(dnode_t *dn, boolean_t before, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
objset_t *os = dn->dn_objset;
|
|
|
|
void *data = NULL;
|
|
|
|
dmu_buf_impl_t *db = NULL;
|
|
|
|
uint64_t *user, *group;
|
|
|
|
int flags = dn->dn_id_flags;
|
|
|
|
int error;
|
|
|
|
boolean_t have_spill = B_FALSE;
|
|
|
|
|
|
|
|
if (!dmu_objset_userused_enabled(dn->dn_objset))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (before && (flags & (DN_ID_CHKED_BONUS|DN_ID_OLD_EXIST|
|
|
|
|
DN_ID_CHKED_SPILL)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (before && dn->dn_bonuslen != 0)
|
|
|
|
data = DN_BONUS(dn->dn_phys);
|
|
|
|
else if (!before && dn->dn_bonuslen != 0) {
|
|
|
|
if (dn->dn_bonus) {
|
|
|
|
db = dn->dn_bonus;
|
|
|
|
mutex_enter(&db->db_mtx);
|
|
|
|
data = dmu_objset_userquota_find_data(db, tx);
|
|
|
|
} else {
|
|
|
|
data = DN_BONUS(dn->dn_phys);
|
|
|
|
}
|
|
|
|
} else if (dn->dn_bonuslen == 0 && dn->dn_bonustype == DMU_OT_SA) {
|
|
|
|
int rf = 0;
|
|
|
|
|
|
|
|
if (RW_WRITE_HELD(&dn->dn_struct_rwlock))
|
|
|
|
rf |= DB_RF_HAVESTRUCT;
|
2010-08-26 21:24:34 +00:00
|
|
|
error = dmu_spill_hold_by_dnode(dn,
|
|
|
|
rf | DB_RF_MUST_SUCCEED,
|
2010-05-28 20:45:14 +00:00
|
|
|
FTAG, (dmu_buf_t **)&db);
|
|
|
|
ASSERT(error == 0);
|
|
|
|
mutex_enter(&db->db_mtx);
|
|
|
|
data = (before) ? db->db.db_data :
|
|
|
|
dmu_objset_userquota_find_data(db, tx);
|
|
|
|
have_spill = B_TRUE;
|
|
|
|
} else {
|
|
|
|
mutex_enter(&dn->dn_mtx);
|
|
|
|
dn->dn_id_flags |= DN_ID_CHKED_BONUS;
|
|
|
|
mutex_exit(&dn->dn_mtx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (before) {
|
|
|
|
ASSERT(data);
|
|
|
|
user = &dn->dn_olduid;
|
|
|
|
group = &dn->dn_oldgid;
|
|
|
|
} else if (data) {
|
|
|
|
user = &dn->dn_newuid;
|
|
|
|
group = &dn->dn_newgid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must always call the callback in case the object
|
|
|
|
* type has changed and that type isn't an object type to track
|
|
|
|
*/
|
|
|
|
error = used_cbs[os->os_phys->os_type](dn->dn_bonustype, data,
|
|
|
|
user, group);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Preserve existing uid/gid when the callback can't determine
|
|
|
|
* what the new uid/gid are and the callback returned EEXIST.
|
|
|
|
* The EEXIST error tells us to just use the existing uid/gid.
|
|
|
|
* If we don't know what the old values are then just assign
|
|
|
|
* them to 0, since that is a new file being created.
|
|
|
|
*/
|
|
|
|
if (!before && data == NULL && error == EEXIST) {
|
|
|
|
if (flags & DN_ID_OLD_EXIST) {
|
|
|
|
dn->dn_newuid = dn->dn_olduid;
|
|
|
|
dn->dn_newgid = dn->dn_oldgid;
|
|
|
|
} else {
|
|
|
|
dn->dn_newuid = 0;
|
|
|
|
dn->dn_newgid = 0;
|
|
|
|
}
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (db)
|
|
|
|
mutex_exit(&db->db_mtx);
|
|
|
|
|
|
|
|
mutex_enter(&dn->dn_mtx);
|
|
|
|
if (error == 0 && before)
|
|
|
|
dn->dn_id_flags |= DN_ID_OLD_EXIST;
|
|
|
|
if (error == 0 && !before)
|
|
|
|
dn->dn_id_flags |= DN_ID_NEW_EXIST;
|
|
|
|
|
|
|
|
if (have_spill) {
|
|
|
|
dn->dn_id_flags |= DN_ID_CHKED_SPILL;
|
|
|
|
} else {
|
|
|
|
dn->dn_id_flags |= DN_ID_CHKED_BONUS;
|
|
|
|
}
|
|
|
|
mutex_exit(&dn->dn_mtx);
|
|
|
|
if (have_spill)
|
|
|
|
dmu_buf_rele((dmu_buf_t *)db, FTAG);
|
|
|
|
}
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
boolean_t
|
|
|
|
dmu_objset_userspace_present(objset_t *os)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
return (os->os_phys->os_flags &
|
2009-07-02 22:44:48 +00:00
|
|
|
OBJSET_FLAG_USERACCOUNTING_COMPLETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dmu_objset_userspace_upgrade(objset_t *os)
|
|
|
|
{
|
|
|
|
uint64_t obj;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (dmu_objset_userspace_present(os))
|
|
|
|
return (0);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (!dmu_objset_userused_enabled(os))
|
2009-07-02 22:44:48 +00:00
|
|
|
return (ENOTSUP);
|
|
|
|
if (dmu_objset_is_snapshot(os))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We simply need to mark every object dirty, so that it will be
|
|
|
|
* synced out and now accounted. If this is called
|
|
|
|
* concurrently, or if we already did some work before crashing,
|
|
|
|
* that's fine, since we track each object's accounted state
|
|
|
|
* independently.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (obj = 0; err == 0; err = dmu_object_next(os, &obj, FALSE, 0)) {
|
2009-08-18 18:43:27 +00:00
|
|
|
dmu_tx_t *tx;
|
2009-07-02 22:44:48 +00:00
|
|
|
dmu_buf_t *db;
|
|
|
|
int objerr;
|
|
|
|
|
|
|
|
if (issig(JUSTLOOKING) && issig(FORREAL))
|
|
|
|
return (EINTR);
|
|
|
|
|
|
|
|
objerr = dmu_bonus_hold(os, obj, FTAG, &db);
|
|
|
|
if (objerr)
|
|
|
|
continue;
|
2009-08-18 18:43:27 +00:00
|
|
|
tx = dmu_tx_create(os);
|
2009-07-02 22:44:48 +00:00
|
|
|
dmu_tx_hold_bonus(tx, obj);
|
|
|
|
objerr = dmu_tx_assign(tx, TXG_WAIT);
|
|
|
|
if (objerr) {
|
|
|
|
dmu_tx_abort(tx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dmu_buf_will_dirty(db, tx);
|
|
|
|
dmu_buf_rele(db, FTAG);
|
|
|
|
dmu_tx_commit(tx);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_flags |= OBJSET_FLAG_USERACCOUNTING_COMPLETE;
|
2009-07-02 22:44:48 +00:00
|
|
|
txg_wait_synced(dmu_objset_pool(os), 0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
void
|
|
|
|
dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp,
|
|
|
|
uint64_t *usedobjsp, uint64_t *availobjsp)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_space(os->os_dsl_dataset, refdbytesp, availbytesp,
|
2008-11-20 20:01:55 +00:00
|
|
|
usedobjsp, availobjsp);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
dmu_objset_fsid_guid(objset_t *os)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
return (dsl_dataset_fsid_guid(os->os_dsl_dataset));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
stat->dds_type = os->os_phys->os_type;
|
|
|
|
if (os->os_dsl_dataset)
|
|
|
|
dsl_dataset_fast_stat(os->os_dsl_dataset, stat);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dmu_objset_stats(objset_t *os, nvlist_t *nv)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(os->os_dsl_dataset ||
|
|
|
|
os->os_phys->os_type == DMU_OST_META);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (os->os_dsl_dataset != NULL)
|
|
|
|
dsl_dataset_stats(os->os_dsl_dataset, nv);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_TYPE,
|
2010-05-28 20:45:14 +00:00
|
|
|
os->os_phys->os_type);
|
2009-07-02 22:44:48 +00:00
|
|
|
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USERACCOUNTING,
|
|
|
|
dmu_objset_userspace_present(os));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dmu_objset_is_snapshot(objset_t *os)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
if (os->os_dsl_dataset != NULL)
|
|
|
|
return (dsl_dataset_is_snapshot(os->os_dsl_dataset));
|
2008-11-20 20:01:55 +00:00
|
|
|
else
|
|
|
|
return (B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dmu_snapshot_realname(objset_t *os, char *name, char *real, int maxlen,
|
|
|
|
boolean_t *conflict)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_t *ds = os->os_dsl_dataset;
|
2008-11-20 20:01:55 +00:00
|
|
|
uint64_t ignored;
|
|
|
|
|
|
|
|
if (ds->ds_phys->ds_snapnames_zapobj == 0)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
return (zap_lookup_norm(ds->ds_dir->dd_pool->dp_meta_objset,
|
|
|
|
ds->ds_phys->ds_snapnames_zapobj, name, 8, 1, &ignored, MT_FIRST,
|
|
|
|
real, maxlen, conflict));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dmu_snapshot_list_next(objset_t *os, int namelen, char *name,
|
|
|
|
uint64_t *idp, uint64_t *offp, boolean_t *case_conflict)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dataset_t *ds = os->os_dsl_dataset;
|
2008-11-20 20:01:55 +00:00
|
|
|
zap_cursor_t cursor;
|
|
|
|
zap_attribute_t attr;
|
|
|
|
|
|
|
|
if (ds->ds_phys->ds_snapnames_zapobj == 0)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
zap_cursor_init_serialized(&cursor,
|
|
|
|
ds->ds_dir->dd_pool->dp_meta_objset,
|
|
|
|
ds->ds_phys->ds_snapnames_zapobj, *offp);
|
|
|
|
|
|
|
|
if (zap_cursor_retrieve(&cursor, &attr) != 0) {
|
|
|
|
zap_cursor_fini(&cursor);
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(attr.za_name) + 1 > namelen) {
|
|
|
|
zap_cursor_fini(&cursor);
|
|
|
|
return (ENAMETOOLONG);
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) strcpy(name, attr.za_name);
|
|
|
|
if (idp)
|
|
|
|
*idp = attr.za_first_integer;
|
|
|
|
if (case_conflict)
|
|
|
|
*case_conflict = attr.za_normalization_conflict;
|
|
|
|
zap_cursor_advance(&cursor);
|
|
|
|
*offp = zap_cursor_serialize(&cursor);
|
|
|
|
zap_cursor_fini(&cursor);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dmu_dir_list_next(objset_t *os, int namelen, char *name,
|
|
|
|
uint64_t *idp, uint64_t *offp)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
dsl_dir_t *dd = os->os_dsl_dataset->ds_dir;
|
2008-11-20 20:01:55 +00:00
|
|
|
zap_cursor_t cursor;
|
|
|
|
zap_attribute_t attr;
|
|
|
|
|
|
|
|
/* there is no next dir on a snapshot! */
|
2010-05-28 20:45:14 +00:00
|
|
|
if (os->os_dsl_dataset->ds_object !=
|
2008-11-20 20:01:55 +00:00
|
|
|
dd->dd_phys->dd_head_dataset_obj)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
zap_cursor_init_serialized(&cursor,
|
|
|
|
dd->dd_pool->dp_meta_objset,
|
|
|
|
dd->dd_phys->dd_child_dir_zapobj, *offp);
|
|
|
|
|
|
|
|
if (zap_cursor_retrieve(&cursor, &attr) != 0) {
|
|
|
|
zap_cursor_fini(&cursor);
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(attr.za_name) + 1 > namelen) {
|
|
|
|
zap_cursor_fini(&cursor);
|
|
|
|
return (ENAMETOOLONG);
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) strcpy(name, attr.za_name);
|
|
|
|
if (idp)
|
|
|
|
*idp = attr.za_first_integer;
|
|
|
|
zap_cursor_advance(&cursor);
|
|
|
|
*offp = zap_cursor_serialize(&cursor);
|
|
|
|
zap_cursor_fini(&cursor);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
struct findarg {
|
2010-05-28 20:45:14 +00:00
|
|
|
int (*func)(const char *, void *);
|
2008-12-03 20:09:06 +00:00
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
findfunc(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
|
|
|
|
{
|
|
|
|
struct findarg *fa = arg;
|
2010-05-28 20:45:14 +00:00
|
|
|
return (fa->func(dsname, fa->arg));
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Find all objsets under name, and for each, call 'func(child_name, arg)'.
|
2008-12-03 20:09:06 +00:00
|
|
|
* Perhaps change all callers to use dmu_objset_find_spa()?
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
int
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_find(char *name, int func(const char *, void *), void *arg,
|
|
|
|
int flags)
|
2008-12-03 20:09:06 +00:00
|
|
|
{
|
|
|
|
struct findarg fa;
|
|
|
|
fa.func = func;
|
|
|
|
fa.arg = arg;
|
|
|
|
return (dmu_objset_find_spa(NULL, name, findfunc, &fa, flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find all objsets under name, call func on each
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
dmu_objset_find_spa(spa_t *spa, const char *name,
|
|
|
|
int func(spa_t *, uint64_t, const char *, void *), void *arg, int flags)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
dsl_dir_t *dd;
|
2008-12-03 20:09:06 +00:00
|
|
|
dsl_pool_t *dp;
|
|
|
|
dsl_dataset_t *ds;
|
2008-11-20 20:01:55 +00:00
|
|
|
zap_cursor_t zc;
|
|
|
|
zap_attribute_t *attr;
|
|
|
|
char *child;
|
2008-12-03 20:09:06 +00:00
|
|
|
uint64_t thisobj;
|
|
|
|
int err;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (name == NULL)
|
|
|
|
name = spa_name(spa);
|
|
|
|
err = dsl_dir_open_spa(spa, name, FTAG, &dd, NULL);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/* Don't visit hidden ($MOS & $ORIGIN) objsets. */
|
|
|
|
if (dd->dd_myname[0] == '$') {
|
|
|
|
dsl_dir_close(dd, FTAG);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
thisobj = dd->dd_phys->dd_head_dataset_obj;
|
2008-11-20 20:01:55 +00:00
|
|
|
attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
|
2008-12-03 20:09:06 +00:00
|
|
|
dp = dd->dd_pool;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over all children.
|
|
|
|
*/
|
|
|
|
if (flags & DS_FIND_CHILDREN) {
|
2008-12-03 20:09:06 +00:00
|
|
|
for (zap_cursor_init(&zc, dp->dp_meta_objset,
|
2008-11-20 20:01:55 +00:00
|
|
|
dd->dd_phys->dd_child_dir_zapobj);
|
|
|
|
zap_cursor_retrieve(&zc, attr) == 0;
|
|
|
|
(void) zap_cursor_advance(&zc)) {
|
|
|
|
ASSERT(attr->za_integer_length == sizeof (uint64_t));
|
|
|
|
ASSERT(attr->za_num_integers == 1);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
child = kmem_asprintf("%s/%s", name, attr->za_name);
|
2008-12-03 20:09:06 +00:00
|
|
|
err = dmu_objset_find_spa(spa, child, func, arg, flags);
|
2010-05-28 20:45:14 +00:00
|
|
|
strfree(child);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
zap_cursor_fini(&zc);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
dsl_dir_close(dd, FTAG);
|
|
|
|
kmem_free(attr, sizeof (zap_attribute_t));
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over all snapshots.
|
|
|
|
*/
|
2008-12-03 20:09:06 +00:00
|
|
|
if (flags & DS_FIND_SNAPSHOTS) {
|
|
|
|
if (!dsl_pool_sync_context(dp))
|
|
|
|
rw_enter(&dp->dp_config_rwlock, RW_READER);
|
|
|
|
err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds);
|
|
|
|
if (!dsl_pool_sync_context(dp))
|
|
|
|
rw_exit(&dp->dp_config_rwlock);
|
|
|
|
|
|
|
|
if (err == 0) {
|
|
|
|
uint64_t snapobj = ds->ds_phys->ds_snapnames_zapobj;
|
|
|
|
dsl_dataset_rele(ds, FTAG);
|
|
|
|
|
|
|
|
for (zap_cursor_init(&zc, dp->dp_meta_objset, snapobj);
|
|
|
|
zap_cursor_retrieve(&zc, attr) == 0;
|
|
|
|
(void) zap_cursor_advance(&zc)) {
|
|
|
|
ASSERT(attr->za_integer_length ==
|
|
|
|
sizeof (uint64_t));
|
|
|
|
ASSERT(attr->za_num_integers == 1);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
child = kmem_asprintf("%s@%s",
|
|
|
|
name, attr->za_name);
|
2008-12-03 20:09:06 +00:00
|
|
|
err = func(spa, attr->za_first_integer,
|
|
|
|
child, arg);
|
2010-05-28 20:45:14 +00:00
|
|
|
strfree(child);
|
2008-12-03 20:09:06 +00:00
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
zap_cursor_fini(&zc);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dsl_dir_close(dd, FTAG);
|
|
|
|
kmem_free(attr, sizeof (zap_attribute_t));
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply to self if appropriate.
|
|
|
|
*/
|
2008-12-03 20:09:06 +00:00
|
|
|
err = func(spa, thisobj, name, arg);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2009-02-18 20:51:31 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2010-05-28 20:45:14 +00:00
|
|
|
dmu_objset_prefetch(const char *name, void *arg)
|
2009-02-18 20:51:31 +00:00
|
|
|
{
|
|
|
|
dsl_dataset_t *ds;
|
|
|
|
|
|
|
|
if (dsl_dataset_hold(name, FTAG, &ds))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (!BP_IS_HOLE(&ds->ds_phys->ds_bp)) {
|
|
|
|
mutex_enter(&ds->ds_opening_lock);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (ds->ds_objset == NULL) {
|
2009-02-18 20:51:31 +00:00
|
|
|
uint32_t aflags = ARC_NOWAIT | ARC_PREFETCH;
|
|
|
|
zbookmark_t zb;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
SET_BOOKMARK(&zb, ds->ds_object, ZB_ROOT_OBJECT,
|
|
|
|
ZB_ROOT_LEVEL, ZB_ROOT_BLKID);
|
2009-02-18 20:51:31 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) dsl_read_nolock(NULL, dsl_dataset_get_spa(ds),
|
2009-02-18 20:51:31 +00:00
|
|
|
&ds->ds_phys->ds_bp, NULL, NULL,
|
|
|
|
ZIO_PRIORITY_ASYNC_READ,
|
|
|
|
ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE,
|
|
|
|
&aflags, &zb);
|
|
|
|
}
|
|
|
|
mutex_exit(&ds->ds_opening_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
dsl_dataset_rele(ds, FTAG);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
void
|
|
|
|
dmu_objset_set_user(objset_t *os, void *user_ptr)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(MUTEX_HELD(&os->os_user_ptr_lock));
|
|
|
|
os->os_user_ptr = user_ptr;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
dmu_objset_get_user(objset_t *os)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
ASSERT(MUTEX_HELD(&os->os_user_ptr_lock));
|
|
|
|
return (os->os_user_ptr);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|