usr/src/uts/common/fs/zfs/dmu_objset.c
author Neil Perrin <Neil.Perrin@Sun.COM>
Fri, 14 Aug 2009 11:18:12 -0600
changeset 10310 ba87b3315737
parent 10298 a0d52501437c
child 10373 bcf97ee54990
permissions -rw-r--r--
PSARC 2009/423 ZFS logbias property 6832481 ZFS separate intent log bypass property
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
    22
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
    26
#include <sys/cred.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/dsl_prop.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/dsl_pool.h>
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
    33
#include <sys/dsl_synctask.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
    34
#include <sys/dsl_deleg.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/dnode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/dbuf.h>
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
    37
#include <sys/zvol.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/dmu_tx.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <sys/zio_checksum.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/zil.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/dmu_impl.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
    43
#include <sys/zfs_ioctl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
spa_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
dmu_objset_spa(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    48
	return (os->os_spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
zilog_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
dmu_objset_zil(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    54
	return (os->os_zil);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
dsl_pool_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
dmu_objset_pool(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
	dsl_dataset_t *ds;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    62
	if ((ds = os->os_dsl_dataset) != NULL && ds->ds_dir)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
		return (ds->ds_dir->dd_pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
	else
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    65
		return (spa_get_dsl(os->os_spa));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
dsl_dataset_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
dmu_objset_ds(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    71
	return (os->os_dsl_dataset);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
dmu_objset_type_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
dmu_objset_type(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    77
	return (os->os_phys->os_type);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
dmu_objset_name(objset_t *os, char *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    83
	dsl_dataset_name(os->os_dsl_dataset, buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
dmu_objset_id(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
    89
	dsl_dataset_t *ds = os->os_dsl_dataset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
	return (ds ? ds->ds_object : 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
    94
uint64_t
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
    95
dmu_objset_logbias(objset_t *os)
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
    96
{
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
    97
	return (os->os_logbias);
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
    98
}
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
    99
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
checksum_changed_cb(void *arg, uint64_t newval)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   103
	objset_t *os = arg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	 * Inheritance should have been done by now.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	ASSERT(newval != ZIO_CHECKSUM_INHERIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   110
	os->os_checksum = zio_checksum_select(newval, ZIO_CHECKSUM_ON_VALUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
compression_changed_cb(void *arg, uint64_t newval)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   116
	objset_t *os = arg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
	 * Inheritance and range checking should have been done by now.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
	ASSERT(newval != ZIO_COMPRESS_INHERIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   123
	os->os_compress = zio_compress_select(newval, ZIO_COMPRESS_ON_VALUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
3835
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   126
static void
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   127
copies_changed_cb(void *arg, uint64_t newval)
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   128
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   129
	objset_t *os = arg;
3835
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   130
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   131
	/*
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   132
	 * Inheritance and range checking should have been done by now.
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   133
	 */
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   134
	ASSERT(newval > 0);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   135
	ASSERT(newval <= spa_max_replication(os->os_spa));
3835
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   136
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   137
	os->os_copies = newval;
3835
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   138
}
063f0749804a PSARC/2007/121 zfs set copies
ahrens
parents: 3689
diff changeset
   139
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   140
static void
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   141
primary_cache_changed_cb(void *arg, uint64_t newval)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   142
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   143
	objset_t *os = arg;
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   144
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   145
	/*
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   146
	 * Inheritance and range checking should have been done by now.
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   147
	 */
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   148
	ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE ||
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   149
	    newval == ZFS_CACHE_METADATA);
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   150
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   151
	os->os_primary_cache = newval;
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   152
}
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   153
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   154
static void
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   155
secondary_cache_changed_cb(void *arg, uint64_t newval)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   156
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   157
	objset_t *os = arg;
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   158
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   159
	/*
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   160
	 * Inheritance and range checking should have been done by now.
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   161
	 */
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   162
	ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE ||
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   163
	    newval == ZFS_CACHE_METADATA);
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   164
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   165
	os->os_secondary_cache = newval;
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   166
}
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   167
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   168
static void
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   169
logbias_changed_cb(void *arg, uint64_t newval)
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   170
{
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   171
	objset_t *os = arg;
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   172
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   173
	ASSERT(newval == ZFS_LOGBIAS_LATENCY ||
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   174
	    newval == ZFS_LOGBIAS_THROUGHPUT);
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   175
	os->os_logbias = newval;
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   176
	if (os->os_zil)
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   177
		zil_set_logbias(os->os_zil, newval);
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   178
}
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   179
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
dmu_objset_byteswap(void *buf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
	objset_phys_t *osp = buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   185
	ASSERT(size == OBJSET_OLD_PHYS_SIZE || size == sizeof (objset_phys_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
	dnode_byteswap(&osp->os_meta_dnode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
	byteswap_uint64_array(&osp->os_zil_header, sizeof (zil_header_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
	osp->os_type = BSWAP_64(osp->os_type);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   189
	osp->os_flags = BSWAP_64(osp->os_flags);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   190
	if (size == sizeof (objset_phys_t)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   191
		dnode_byteswap(&osp->os_userused_dnode);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   192
		dnode_byteswap(&osp->os_groupused_dnode);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   193
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   196
int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   197
dmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   198
    objset_t **osp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   200
	objset_t *os;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   201
	int i, err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   203
	ASSERT(ds == NULL || MUTEX_HELD(&ds->ds_opening_lock));
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   204
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   205
	os = kmem_zalloc(sizeof (objset_t), KM_SLEEP);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   206
	os->os_dsl_dataset = ds;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   207
	os->os_spa = spa;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   208
	os->os_rootbp = bp;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   209
	if (!BP_IS_HOLE(os->os_rootbp)) {
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2199
diff changeset
   210
		uint32_t aflags = ARC_WAIT;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   211
		zbookmark_t zb;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   212
		zb.zb_objset = ds ? ds->ds_object : 0;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   213
		zb.zb_object = 0;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   214
		zb.zb_level = -1;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   215
		zb.zb_blkid = 0;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   216
		if (DMU_OS_IS_L2CACHEABLE(os))
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   217
			aflags |= ARC_L2CACHE;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   218
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   219
		dprintf_bp(os->os_rootbp, "reading %s", "");
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   220
		/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   221
		 * NB: when bprewrite scrub can change the bp,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   222
		 * and this is called from dmu_objset_open_ds_os, the bp
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   223
		 * could change, and we'll need a lock.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   224
		 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   225
		err = arc_read_nolock(NULL, spa, os->os_rootbp,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   226
		    arc_getbuf_func, &os->os_phys_buf,
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2199
diff changeset
   227
		    ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &aflags, &zb);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   228
		if (err) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   229
			kmem_free(os, sizeof (objset_t));
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7237
diff changeset
   230
			/* convert checksum errors into IO errors */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7237
diff changeset
   231
			if (err == ECKSUM)
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7237
diff changeset
   232
				err = EIO;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   233
			return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   234
		}
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   235
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   236
		/* Increase the blocksize if we are permitted. */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   237
		if (spa_version(spa) >= SPA_VERSION_USERSPACE &&
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   238
		    arc_buf_size(os->os_phys_buf) < sizeof (objset_phys_t)) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   239
			arc_buf_t *buf = arc_buf_alloc(spa,
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   240
			    sizeof (objset_phys_t), &os->os_phys_buf,
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   241
			    ARC_BUFC_METADATA);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   242
			bzero(buf->b_data, sizeof (objset_phys_t));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   243
			bcopy(os->os_phys_buf->b_data, buf->b_data,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   244
			    arc_buf_size(os->os_phys_buf));
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   245
			(void) arc_buf_remove_ref(os->os_phys_buf,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   246
			    &os->os_phys_buf);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   247
			os->os_phys_buf = buf;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   248
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   249
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   250
		os->os_phys = os->os_phys_buf->b_data;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   251
		os->os_flags = os->os_phys->os_flags;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
	} else {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   253
		int size = spa_version(spa) >= SPA_VERSION_USERSPACE ?
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   254
		    sizeof (objset_phys_t) : OBJSET_OLD_PHYS_SIZE;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   255
		os->os_phys_buf = arc_buf_alloc(spa, size,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   256
		    &os->os_phys_buf, ARC_BUFC_METADATA);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   257
		os->os_phys = os->os_phys_buf->b_data;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   258
		bzero(os->os_phys, size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
	 * Note: the changed_cb will be called once before the register
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
	 * func returns, thus changing the checksum/compression from the
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   264
	 * default (fletcher2/off).  Snapshots don't need to know about
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   265
	 * checksum/compression/copies.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
	 */
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   267
	if (ds) {
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   268
		err = dsl_prop_register(ds, "primarycache",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   269
		    primary_cache_changed_cb, os);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   270
		if (err == 0)
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   271
			err = dsl_prop_register(ds, "secondarycache",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   272
			    secondary_cache_changed_cb, os);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   273
		if (!dsl_dataset_is_snapshot(ds)) {
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   274
			if (err == 0)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   275
				err = dsl_prop_register(ds, "checksum",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   276
				    checksum_changed_cb, os);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   277
			if (err == 0)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   278
				err = dsl_prop_register(ds, "compression",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   279
				    compression_changed_cb, os);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   280
			if (err == 0)
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   281
				err = dsl_prop_register(ds, "copies",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   282
				    copies_changed_cb, os);
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   283
			if (err == 0)
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   284
				err = dsl_prop_register(ds, "logbias",
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   285
				    logbias_changed_cb, os);
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   286
		}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   287
		if (err) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   288
			VERIFY(arc_buf_remove_ref(os->os_phys_buf,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   289
			    &os->os_phys_buf) == 1);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   290
			kmem_free(os, sizeof (objset_t));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   291
			return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   292
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   293
	} else if (ds == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
		/* It's the meta-objset. */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   295
		os->os_checksum = ZIO_CHECKSUM_FLETCHER_4;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   296
		os->os_compress = ZIO_COMPRESS_LZJB;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   297
		os->os_copies = spa_max_replication(spa);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   298
		os->os_primary_cache = ZFS_CACHE_ALL;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   299
		os->os_secondary_cache = ZFS_CACHE_ALL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   302
	os->os_zil_header = os->os_phys->os_zil_header;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   303
	os->os_zil = zil_alloc(os, &os->os_zil_header);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
	for (i = 0; i < TXG_SIZE; i++) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   306
		list_create(&os->os_dirty_dnodes[i], sizeof (dnode_t),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
		    offsetof(dnode_t, dn_dirty_link[i]));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   308
		list_create(&os->os_free_dnodes[i], sizeof (dnode_t),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
		    offsetof(dnode_t, dn_dirty_link[i]));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
	}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   311
	list_create(&os->os_dnodes, sizeof (dnode_t),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
	    offsetof(dnode_t, dn_link));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   313
	list_create(&os->os_downgraded_dbufs, sizeof (dmu_buf_impl_t),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
	    offsetof(dmu_buf_impl_t, db_link));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   316
	mutex_init(&os->os_lock, NULL, MUTEX_DEFAULT, NULL);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   317
	mutex_init(&os->os_obj_lock, NULL, MUTEX_DEFAULT, NULL);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   318
	mutex_init(&os->os_user_ptr_lock, NULL, MUTEX_DEFAULT, NULL);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   319
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   320
	os->os_meta_dnode = dnode_special_open(os,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   321
	    &os->os_phys->os_meta_dnode, DMU_META_DNODE_OBJECT);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   322
	if (arc_buf_size(os->os_phys_buf) >= sizeof (objset_phys_t)) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   323
		os->os_userused_dnode = dnode_special_open(os,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   324
		    &os->os_phys->os_userused_dnode, DMU_USERUSED_OBJECT);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   325
		os->os_groupused_dnode = dnode_special_open(os,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   326
		    &os->os_phys->os_groupused_dnode, DMU_GROUPUSED_OBJECT);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   327
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   329
	/*
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   330
	 * We should be the only thread trying to do this because we
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   331
	 * have ds_opening_lock
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   332
	 */
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   333
	if (ds) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   334
		mutex_enter(&ds->ds_lock);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   335
		ASSERT(ds->ds_objset == NULL);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   336
		ds->ds_objset = os;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   337
		mutex_exit(&ds->ds_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   340
	*osp = os;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   341
	return (0);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   342
}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   343
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   344
int
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   345
dmu_objset_from_ds(dsl_dataset_t *ds, objset_t **osp)
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   346
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   347
	int err = 0;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   348
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   349
	mutex_enter(&ds->ds_opening_lock);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   350
	*osp = ds->ds_objset;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   351
	if (*osp == NULL) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   352
		err = dmu_objset_open_impl(dsl_dataset_get_spa(ds),
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   353
		    ds, &ds->ds_phys->ds_bp, osp);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   354
	}
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   355
	mutex_exit(&ds->ds_opening_lock);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   356
	return (err);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   357
}
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   358
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   359
/* called from zpl */
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   360
int
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   361
dmu_objset_hold(const char *name, void *tag, objset_t **osp)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   362
{
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   363
	dsl_dataset_t *ds;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   364
	int err;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   365
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   366
	err = dsl_dataset_hold(name, tag, &ds);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   367
	if (err)
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   368
		return (err);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   369
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   370
	err = dmu_objset_from_ds(ds, osp);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   371
	if (err)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   372
		dsl_dataset_rele(ds, tag);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   373
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   374
	return (err);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   375
}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   376
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
/* called from zpl */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
int
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   379
dmu_objset_own(const char *name, dmu_objset_type_t type,
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   380
    boolean_t readonly, void *tag, objset_t **osp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
	dsl_dataset_t *ds;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   385
	err = dsl_dataset_own(name, B_FALSE, tag, &ds);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   386
	if (err)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   387
		return (err);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   388
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   389
	err = dmu_objset_from_ds(ds, osp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   390
	if (err) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   391
		dsl_dataset_disown(ds, tag);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   392
	} else if ((type != DMU_OST_ANY && type != (*osp)->os_phys->os_type) ||
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   393
	    (!readonly && dsl_dataset_is_snapshot(ds))) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   394
		dmu_objset_disown(*osp, tag);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   395
		return (EINVAL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   396
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   398
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   400
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
void
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   402
dmu_objset_rele(objset_t *os, void *tag)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   404
	dsl_dataset_rele(os->os_dsl_dataset, tag);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   405
}
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6492
diff changeset
   406
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   407
void
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   408
dmu_objset_disown(objset_t *os, void *tag)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   409
{
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   410
	dsl_dataset_disown(os->os_dsl_dataset, tag);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   411
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1596
diff changeset
   413
int
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4935
diff changeset
   414
dmu_objset_evict_dbufs(objset_t *os)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   415
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   416
	dnode_t *dn;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   417
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   418
	mutex_enter(&os->os_lock);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   419
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   420
	/* process the mdn last, since the other dnodes have holds on it */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   421
	list_remove(&os->os_dnodes, os->os_meta_dnode);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   422
	list_insert_tail(&os->os_dnodes, os->os_meta_dnode);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   423
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   424
	/*
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   425
	 * Find the first dnode with holds.  We have to do this dance
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   426
	 * because dnode_add_ref() only works if you already have a
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   427
	 * hold.  If there are no holds then it has no dbufs so OK to
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   428
	 * skip.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   429
	 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   430
	for (dn = list_head(&os->os_dnodes);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4935
diff changeset
   431
	    dn && !dnode_add_ref(dn, FTAG);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   432
	    dn = list_next(&os->os_dnodes, dn))
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   433
		continue;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   434
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   435
	while (dn) {
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   436
		dnode_t *next_dn = dn;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   437
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   438
		do {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   439
			next_dn = list_next(&os->os_dnodes, next_dn);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4935
diff changeset
   440
		} while (next_dn && !dnode_add_ref(next_dn, FTAG));
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   441
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   442
		mutex_exit(&os->os_lock);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4935
diff changeset
   443
		dnode_evict_dbufs(dn);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   444
		dnode_rele(dn, FTAG);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   445
		mutex_enter(&os->os_lock);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
   446
		dn = next_dn;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   447
	}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   448
	mutex_exit(&os->os_lock);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   449
	return (list_head(&os->os_dnodes) != os->os_meta_dnode);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   450
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   451
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   452
void
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   453
dmu_objset_evict(objset_t *os)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   455
	dsl_dataset_t *ds = os->os_dsl_dataset;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   456
	int i;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
	for (i = 0; i < TXG_SIZE; i++) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   459
		ASSERT(list_head(&os->os_dirty_dnodes[i]) == NULL);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   460
		ASSERT(list_head(&os->os_free_dnodes[i]) == NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   463
	if (ds) {
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   464
		if (!dsl_dataset_is_snapshot(ds)) {
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   465
			VERIFY(0 == dsl_prop_unregister(ds, "checksum",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   466
			    checksum_changed_cb, os));
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   467
			VERIFY(0 == dsl_prop_unregister(ds, "compression",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   468
			    compression_changed_cb, os));
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   469
			VERIFY(0 == dsl_prop_unregister(ds, "copies",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   470
			    copies_changed_cb, os));
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   471
			VERIFY(0 == dsl_prop_unregister(ds, "logbias",
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
   472
			    logbias_changed_cb, os));
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   473
		}
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   474
		VERIFY(0 == dsl_prop_unregister(ds, "primarycache",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   475
		    primary_cache_changed_cb, os));
7237
f47d41541b14 PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents: 7046
diff changeset
   476
		VERIFY(0 == dsl_prop_unregister(ds, "secondarycache",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   477
		    secondary_cache_changed_cb, os));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   480
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   481
	 * We should need only a single pass over the dnode list, since
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   482
	 * nothing can be added to the list at this point.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   483
	 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   484
	(void) dmu_objset_evict_dbufs(os);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   485
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   486
	dnode_special_close(os->os_meta_dnode);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   487
	if (os->os_userused_dnode) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   488
		dnode_special_close(os->os_userused_dnode);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   489
		dnode_special_close(os->os_groupused_dnode);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   490
	}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   491
	zil_free(os->os_zil);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   493
	ASSERT3P(list_head(&os->os_dnodes), ==, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   495
	VERIFY(arc_buf_remove_ref(os->os_phys_buf, &os->os_phys_buf) == 1);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   496
	mutex_destroy(&os->os_lock);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   497
	mutex_destroy(&os->os_obj_lock);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   498
	mutex_destroy(&os->os_user_ptr_lock);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   499
	kmem_free(os, sizeof (objset_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
/* called from dsl for meta-objset */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   503
objset_t *
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   504
dmu_objset_create_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   505
    dmu_objset_type_t type, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   507
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
	dnode_t *mdn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
	ASSERT(dmu_tx_is_syncing(tx));
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   511
	if (ds)
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   512
		mutex_enter(&ds->ds_opening_lock);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   513
	VERIFY(0 == dmu_objset_open_impl(spa, ds, bp, &os));
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   514
	if (ds)
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   515
		mutex_exit(&ds->ds_opening_lock);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   516
	mdn = os->os_meta_dnode;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   518
	dnode_allocate(mdn, DMU_OT_DNODE, 1 << DNODE_BLOCK_SHIFT,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
	    DN_MAX_INDBLKSHIFT, DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
	 * We don't want to have to increase the meta-dnode's nlevels
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
	 * later, because then we could do it in quescing context while
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
	 * we are also accessing it in open context.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
	 * This precaution is not necessary for the MOS (ds == NULL),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
	 * because the MOS is only updated in syncing context.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
	 * This is most fortunate: the MOS is the only objset that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
	 * needs to be synced multiple times as spa_sync() iterates
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
	 * to convergence, so minimizing its dn_nlevels matters.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   532
	if (ds != NULL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   533
		int levels = 1;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   534
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   535
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   536
		 * Determine the number of levels necessary for the meta-dnode
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   537
		 * to contain DN_MAX_OBJECT dnodes.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   538
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   539
		while ((uint64_t)mdn->dn_nblkptr << (mdn->dn_datablkshift +
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   540
		    (levels - 1) * (mdn->dn_indblkshift - SPA_BLKPTRSHIFT)) <
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   541
		    DN_MAX_OBJECT * sizeof (dnode_phys_t))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   542
			levels++;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   543
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
		mdn->dn_next_nlevels[tx->tx_txg & TXG_MASK] =
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   545
		    mdn->dn_nlevels = levels;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   546
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
	ASSERT(type != DMU_OST_NONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
	ASSERT(type != DMU_OST_ANY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
	ASSERT(type < DMU_OST_NUMTYPES);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   551
	os->os_phys->os_type = type;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   552
	if (dmu_objset_userused_enabled(os)) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   553
		os->os_phys->os_flags |= OBJSET_FLAG_USERACCOUNTING_COMPLETE;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   554
		os->os_flags = os->os_phys->os_flags;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   555
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
	dsl_dataset_dirty(ds, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   559
	return (os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
struct oscarg {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   563
	void (*userfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
	void *userarg;
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   565
	dsl_dataset_t *clone_origin;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
	const char *lastname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
	dmu_objset_type_t type;
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
   568
	uint64_t flags;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   571
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
static int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   573
dmu_objset_create_check(void *arg1, void *arg2, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   574
{
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   575
	dsl_dir_t *dd = arg1;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   576
	struct oscarg *oa = arg2;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   577
	objset_t *mos = dd->dd_pool->dp_meta_objset;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   578
	int err;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   579
	uint64_t ddobj;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   580
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   581
	err = zap_lookup(mos, dd->dd_phys->dd_child_dir_zapobj,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   582
	    oa->lastname, sizeof (uint64_t), 1, &ddobj);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   583
	if (err != ENOENT)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   584
		return (err ? err : EEXIST);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   585
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   586
	if (oa->clone_origin != NULL) {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   587
		/* You can't clone across pools. */
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   588
		if (oa->clone_origin->ds_dir->dd_pool != dd->dd_pool)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   589
			return (EXDEV);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   590
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   591
		/* You can only clone snapshots, not the head datasets. */
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   592
		if (!dsl_dataset_is_snapshot(oa->clone_origin))
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   593
			return (EINVAL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   594
	}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   595
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   596
	return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   597
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   598
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   599
static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   600
dmu_objset_create_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   601
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   602
	dsl_dir_t *dd = arg1;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   603
	struct oscarg *oa = arg2;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   604
	uint64_t dsobj;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   605
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
	ASSERT(dmu_tx_is_syncing(tx));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   608
	dsobj = dsl_dataset_create_sync(dd, oa->lastname,
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   609
	    oa->clone_origin, oa->flags, cr, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   611
	if (oa->clone_origin == NULL) {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   612
		dsl_dataset_t *ds;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   613
		blkptr_t *bp;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   614
		objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   616
		VERIFY(0 == dsl_dataset_hold_obj(dd->dd_pool, dsobj,
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   617
		    FTAG, &ds));
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   618
		bp = dsl_dataset_get_blkptr(ds);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   619
		ASSERT(BP_IS_HOLE(bp));
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   620
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   621
		os = dmu_objset_create_impl(dsl_dataset_get_spa(ds),
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   622
		    ds, bp, oa->type, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   624
		if (oa->userfunc)
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   625
			oa->userfunc(os, oa->userarg, cr, tx);
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   626
		dsl_dataset_rele(ds, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   627
	}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   628
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   629
	spa_history_internal_log(LOG_DS_CREATE, dd->dd_pool->dp_spa,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   630
	    tx, cr, "dataset = %llu", dsobj);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
int
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   634
dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   635
    void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
{
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   637
	dsl_dir_t *pdd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
	const char *tail;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
	int err = 0;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   640
	struct oscarg oa = { 0 };
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   642
	ASSERT(strchr(name, '@') == NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   643
	err = dsl_dir_open(name, FTAG, &pdd, &tail);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   644
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   645
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
	if (tail == NULL) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   647
		dsl_dir_close(pdd, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   648
		return (EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   651
	oa.userfunc = func;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   652
	oa.userarg = arg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   653
	oa.lastname = tail;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   654
	oa.type = type;
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
   655
	oa.flags = flags;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   656
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   657
	err = dsl_sync_task_do(pdd->dd_pool, dmu_objset_create_check,
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   658
	    dmu_objset_create_sync, pdd, &oa, 5);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   659
	dsl_dir_close(pdd, FTAG);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   660
	return (err);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   661
}
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   662
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   663
int
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   664
dmu_objset_clone(const char *name, dsl_dataset_t *clone_origin, uint64_t flags)
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   665
{
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   666
	dsl_dir_t *pdd;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   667
	const char *tail;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   668
	int err = 0;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   669
	struct oscarg oa = { 0 };
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   670
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   671
	ASSERT(strchr(name, '@') == NULL);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   672
	err = dsl_dir_open(name, FTAG, &pdd, &tail);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   673
	if (err)
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   674
		return (err);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   675
	if (tail == NULL) {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   676
		dsl_dir_close(pdd, FTAG);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   677
		return (EEXIST);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
	}
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   679
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   680
	oa.lastname = tail;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   681
	oa.clone_origin = clone_origin;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   682
	oa.flags = flags;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   683
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   684
	err = dsl_sync_task_do(pdd->dd_pool, dmu_objset_create_check,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   685
	    dmu_objset_create_sync, pdd, &oa, 5);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   686
	dsl_dir_close(pdd, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
int
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 9951
diff changeset
   691
dmu_objset_destroy(const char *name, boolean_t defer)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   693
	dsl_dataset_t *ds;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
	/*
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   697
	 * dsl_dataset_destroy() can free any claimed-but-unplayed
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   698
	 * intent log, but if there is an active log, it has blocks that
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   699
	 * are allocated, but may not yet be reflected in the on-disk
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   700
	 * structure.  Only the ZIL knows how to free them, so we have
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   701
	 * to call into it here.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
	 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   703
	error = dsl_dataset_own(name, B_TRUE, FTAG, &ds);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
	if (error == 0) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   705
		objset_t *os;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   706
		if (dmu_objset_from_ds(ds, &os) == 0)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   707
			zil_destroy(dmu_objset_zil(os), B_FALSE);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   708
		error = dsl_dataset_destroy(ds, FTAG, defer);
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   709
		/* dsl_dataset_destroy() closes the ds. */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   712
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   715
struct snaparg {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   716
	dsl_sync_task_group_t *dstg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   717
	char *snapname;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   718
	char failed[MAXPATHLEN];
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   719
	boolean_t checkperms;
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   720
	nvlist_t *props;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   721
};
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   722
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   723
static int
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   724
snapshot_check(void *arg1, void *arg2, dmu_tx_t *tx)
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   725
{
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   726
	objset_t *os = arg1;
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   727
	struct snaparg *sn = arg2;
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   728
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   729
	/* The props have already been checked by zfs_check_userprops(). */
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   730
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   731
	return (dsl_dataset_snapshot_check(os->os_dsl_dataset,
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   732
	    sn->snapname, tx));
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   733
}
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   734
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   735
static void
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   736
snapshot_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx)
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   737
{
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   738
	objset_t *os = arg1;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   739
	dsl_dataset_t *ds = os->os_dsl_dataset;
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   740
	struct snaparg *sn = arg2;
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   741
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   742
	dsl_dataset_snapshot_sync(ds, sn->snapname, cr, tx);
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   743
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   744
	if (sn->props)
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   745
		dsl_props_set_sync(ds->ds_prev, sn->props, cr, tx);
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   746
}
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   747
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   748
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   749
dmu_objset_snapshot_one(char *name, void *arg)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   750
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   751
	struct snaparg *sn = arg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   752
	objset_t *os;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   753
	int err;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   754
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   755
	(void) strcpy(sn->failed, name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   756
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   757
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   758
	 * Check permissions only when requested.  This only applies when
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   759
	 * doing a recursive snapshot.  The permission checks for the starting
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   760
	 * dataset have already been performed in zfs_secpolicy_snapshot()
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   761
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   762
	if (sn->checkperms == B_TRUE &&
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   763
	    (err = zfs_secpolicy_snapshot_perms(name, CRED())))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   764
		return (err);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   765
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   766
	err = dmu_objset_hold(name, sn, &os);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   767
	if (err != 0)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   768
		return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   769
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6492
diff changeset
   770
	/* If the objset is in an inconsistent state, return busy */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   771
	if (os->os_dsl_dataset->ds_phys->ds_flags & DS_FLAG_INCONSISTENT) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   772
		dmu_objset_rele(os, sn);
3637
526d8412c163 6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents: 3547
diff changeset
   773
		return (EBUSY);
526d8412c163 6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents: 3547
diff changeset
   774
	}
526d8412c163 6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents: 3547
diff changeset
   775
526d8412c163 6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents: 3547
diff changeset
   776
	/*
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   777
	 * NB: we need to wait for all in-flight changes to get to disk,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   778
	 * so that we snapshot those changes.  zil_suspend does this as
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   779
	 * a side effect.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   780
	 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   781
	err = zil_suspend(dmu_objset_zil(os));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   782
	if (err == 0) {
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   783
		dsl_sync_task_create(sn->dstg, snapshot_check,
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   784
		    snapshot_sync, os, sn, 3);
3637
526d8412c163 6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents: 3547
diff changeset
   785
	} else {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   786
		dmu_objset_rele(os, sn);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   787
	}
3637
526d8412c163 6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents: 3547
diff changeset
   788
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   789
	return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   790
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   791
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   792
int
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   793
dmu_objset_snapshot(char *fsname, char *snapname,
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   794
    nvlist_t *props, boolean_t recursive)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   795
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   796
	dsl_sync_task_t *dst;
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   797
	struct snaparg sn;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   798
	spa_t *spa;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   799
	int err;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   800
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   801
	(void) strcpy(sn.failed, fsname);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   802
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4543
diff changeset
   803
	err = spa_open(fsname, &spa, FTAG);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   804
	if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   805
		return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   806
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   807
	sn.dstg = dsl_sync_task_group_create(spa_get_dsl(spa));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   808
	sn.snapname = snapname;
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   809
	sn.props = props;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   810
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
   811
	if (recursive) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   812
		sn.checkperms = B_TRUE;
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
   813
		err = dmu_objset_find(fsname,
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
   814
		    dmu_objset_snapshot_one, &sn, DS_FIND_CHILDREN);
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
   815
	} else {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3978
diff changeset
   816
		sn.checkperms = B_FALSE;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   817
		err = dmu_objset_snapshot_one(fsname, &sn);
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
   818
	}
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   819
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   820
	if (err == 0)
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   821
		err = dsl_sync_task_group_wait(sn.dstg);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   822
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   823
	for (dst = list_head(&sn.dstg->dstg_tasks); dst;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   824
	    dst = list_next(&sn.dstg->dstg_tasks, dst)) {
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   825
		objset_t *os = dst->dst_arg1;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   826
		dsl_dataset_t *ds = os->os_dsl_dataset;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   827
		if (dst->dst_err)
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   828
			dsl_dataset_name(ds, sn.failed);
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8415
diff changeset
   829
		zil_resume(dmu_objset_zil(os));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   830
		dmu_objset_rele(os, &sn);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   831
	}
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5329
diff changeset
   832
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   833
	if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   834
		(void) strcpy(fsname, sn.failed);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   835
	dsl_sync_task_group_destroy(sn.dstg);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   836
	spa_close(spa, FTAG);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   837
	return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   838
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
   839
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
static void
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   841
dmu_objset_sync_dnodes(list_t *list, list_t *newlist, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
{
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   843
	dnode_t *dn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   845
	while (dn = list_head(list)) {
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   846
		ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   847
		ASSERT(dn->dn_dbuf->db_data_pending);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   848
		/*
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   849
		 * Initialize dn_zio outside dnode_sync() because the
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   850
		 * meta-dnode needs to set it ouside dnode_sync().
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   851
		 */
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   852
		dn->dn_zio = dn->dn_dbuf->db_data_pending->dr_zio;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   853
		ASSERT(dn->dn_zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   855
		ASSERT3U(dn->dn_nlevels, <=, DN_MAX_LEVELS);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   856
		list_remove(list, dn);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   857
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   858
		if (newlist) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   859
			(void) dnode_add_ref(dn, newlist);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   860
			list_insert_tail(newlist, dn);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   861
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   862
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   863
		dnode_sync(dn, tx);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   864
	}
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   865
}
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   866
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   867
/* ARGSUSED */
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   868
static void
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   869
ready(zio_t *zio, arc_buf_t *abuf, void *arg)
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   870
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   871
	blkptr_t *bp = zio->io_bp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   872
	blkptr_t *bp_orig = &zio->io_bp_orig;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   873
	objset_t *os = arg;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   874
	dnode_phys_t *dnp = &os->os_phys->os_meta_dnode;
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   875
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   876
	ASSERT(bp == os->os_rootbp);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   877
	ASSERT(BP_GET_TYPE(bp) == DMU_OT_OBJSET);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   878
	ASSERT(BP_GET_LEVEL(bp) == 0);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
   879
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   880
	/*
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   881
	 * Update rootbp fill count: it should be the number of objects
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   882
	 * allocated in the object set (not counting the "special"
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   883
	 * objects that are stored in the objset_phys_t -- the meta
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   884
	 * dnode and user/group accounting objects).
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   885
	 */
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   886
	bp->blk_fill = 0;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   887
	for (int i = 0; i < dnp->dn_nblkptr; i++)
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   888
		bp->blk_fill += dnp->dn_blkptr[i].blk_fill;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
   889
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   890
	if (zio->io_flags & ZIO_FLAG_IO_REWRITE) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   891
		ASSERT(DVA_EQUAL(BP_IDENTITY(bp), BP_IDENTITY(bp_orig)));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   892
	} else {
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
   893
		if (zio->io_bp_orig.blk_birth == os->os_synctx->tx_txg)
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6689
diff changeset
   894
			(void) dsl_dataset_block_kill(os->os_dsl_dataset,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   895
			    &zio->io_bp_orig, zio, os->os_synctx);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
   896
		dsl_dataset_block_born(os->os_dsl_dataset, bp, os->os_synctx);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
   897
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
/* called from dsl */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
void
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   902
dmu_objset_sync(objset_t *os, zio_t *pio, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
	int txgoff;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
   905
	zbookmark_t zb;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   906
	writeprops_t wp = { 0 };
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   907
	zio_t *zio;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   908
	list_t *list;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   909
	list_t *newlist = NULL;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   910
	dbuf_dirty_record_t *dr;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   911
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   912
	dprintf_ds(os->os_dsl_dataset, "txg=%llu\n", tx->tx_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   913
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   914
	ASSERT(dmu_tx_is_syncing(tx));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   915
	/* XXX the write_done callback should really give us the tx... */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
	os->os_synctx = tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   917
3882
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
   918
	if (os->os_dsl_dataset == NULL) {
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
   919
		/*
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
   920
		 * This is the MOS.  If we have upgraded,
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
   921
		 * spa_max_replication() could change, so reset
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
   922
		 * os_copies here.
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
   923
		 */
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
   924
		os->os_copies = spa_max_replication(os->os_spa);
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
   925
	}
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3835
diff changeset
   926
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   927
	/*
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   928
	 * Create the root block IO
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   929
	 */
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   930
	zb.zb_objset = os->os_dsl_dataset ? os->os_dsl_dataset->ds_object : 0;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   931
	zb.zb_object = 0;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   932
	zb.zb_level = -1;	/* for block ordering; it's level 0 on disk */
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   933
	zb.zb_blkid = 0;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   934
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   935
	wp.wp_type = DMU_OT_OBJSET;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   936
	wp.wp_level = 0;	/* on-disk BP level; see above */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   937
	wp.wp_copies = os->os_copies;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   938
	wp.wp_oschecksum = os->os_checksum;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   939
	wp.wp_oscompress = os->os_compress;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   940
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   941
	if (BP_IS_OLDER(os->os_rootbp, tx->tx_txg)) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6689
diff changeset
   942
		(void) dsl_dataset_block_kill(os->os_dsl_dataset,
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   943
		    os->os_rootbp, pio, tx);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4634
diff changeset
   944
	}
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   945
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   946
	arc_release(os->os_phys_buf, &os->os_phys_buf);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   947
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   948
	zio = arc_write(pio, os->os_spa, &wp, DMU_OS_IS_L2CACHEABLE(os),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   949
	    tx->tx_txg, os->os_rootbp, os->os_phys_buf, ready, NULL, os,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   950
	    ZIO_PRIORITY_ASYNC_WRITE, ZIO_FLAG_MUSTSUCCEED, &zb);
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   951
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   952
	/*
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   953
	 * Sync special dnodes - the parent IO for the sync is the root block
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   954
	 */
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   955
	os->os_meta_dnode->dn_zio = zio;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   956
	dnode_sync(os->os_meta_dnode, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   958
	os->os_phys->os_flags = os->os_flags;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   959
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   960
	if (os->os_userused_dnode &&
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   961
	    os->os_userused_dnode->dn_type != DMU_OT_NONE) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   962
		os->os_userused_dnode->dn_zio = zio;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   963
		dnode_sync(os->os_userused_dnode, tx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   964
		os->os_groupused_dnode->dn_zio = zio;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   965
		dnode_sync(os->os_groupused_dnode, tx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   966
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   967
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
	txgoff = tx->tx_txg & TXG_MASK;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   970
	if (dmu_objset_userused_enabled(os)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   971
		newlist = &os->os_synced_dnodes;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   972
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   973
		 * We must create the list here because it uses the
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   974
		 * dn_dirty_link[] of this txg.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   975
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   976
		list_create(newlist, sizeof (dnode_t),
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   977
		    offsetof(dnode_t, dn_dirty_link[txgoff]));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   978
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   979
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   980
	dmu_objset_sync_dnodes(&os->os_free_dnodes[txgoff], newlist, tx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   981
	dmu_objset_sync_dnodes(&os->os_dirty_dnodes[txgoff], newlist, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   983
	list = &os->os_meta_dnode->dn_dirty_records[txgoff];
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   984
	while (dr = list_head(list)) {
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   985
		ASSERT(dr->dr_dbuf->db_level == 0);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   986
		list_remove(list, dr);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   987
		if (dr->dr_zio)
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   988
			zio_nowait(dr->dr_zio);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   989
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
	 * Free intent log blocks up to this tx.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
	zil_sync(os->os_zil, tx);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   994
	os->os_phys->os_zil_header = os->os_zil_header;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3290
diff changeset
   995
	zio_nowait(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   998
static objset_used_cb_t *used_cbs[DMU_OST_NUMTYPES];
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   999
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1000
void
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1001
dmu_objset_register_type(dmu_objset_type_t ost, objset_used_cb_t *cb)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1002
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1003
	used_cbs[ost] = cb;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1004
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1005
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1006
boolean_t
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1007
dmu_objset_userused_enabled(objset_t *os)
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1008
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1009
	return (spa_version(os->os_spa) >= SPA_VERSION_USERSPACE &&
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1010
	    used_cbs[os->os_phys->os_type] &&
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1011
	    os->os_userused_dnode);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1012
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1013
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1014
void
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1015
dmu_objset_do_userquota_callbacks(objset_t *os, dmu_tx_t *tx)
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1016
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1017
	dnode_t *dn;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1018
	list_t *list = &os->os_synced_dnodes;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1019
	static const char zerobuf[DN_MAX_BONUSLEN] = {0};
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1020
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1021
	ASSERT(list_head(list) == NULL || dmu_objset_userused_enabled(os));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1022
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1023
	while (dn = list_head(list)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1024
		dmu_object_type_t bonustype;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1025
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1026
		ASSERT(!DMU_OBJECT_IS_SPECIAL(dn->dn_object));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1027
		ASSERT(dn->dn_oldphys);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1028
		ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE ||
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1029
		    dn->dn_phys->dn_flags &
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1030
		    DNODE_FLAG_USERUSED_ACCOUNTED);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1031
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1032
		/* Allocate the user/groupused objects if necessary. */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1033
		if (os->os_userused_dnode->dn_type == DMU_OT_NONE) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1034
			VERIFY(0 == zap_create_claim(os,
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1035
			    DMU_USERUSED_OBJECT,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1036
			    DMU_OT_USERGROUP_USED, DMU_OT_NONE, 0, tx));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1037
			VERIFY(0 == zap_create_claim(os,
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1038
			    DMU_GROUPUSED_OBJECT,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1039
			    DMU_OT_USERGROUP_USED, DMU_OT_NONE, 0, tx));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1040
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1041
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1042
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1043
		 * If the object was not previously
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1044
		 * accounted, pretend that it was free.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1045
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1046
		if (!(dn->dn_oldphys->dn_flags &
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1047
		    DNODE_FLAG_USERUSED_ACCOUNTED)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1048
			bzero(dn->dn_oldphys, sizeof (dnode_phys_t));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1049
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1050
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1051
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1052
		 * If the object was freed, use the previous bonustype.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1053
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1054
		bonustype = dn->dn_phys->dn_bonustype ?
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1055
		    dn->dn_phys->dn_bonustype : dn->dn_oldphys->dn_bonustype;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1056
		ASSERT(dn->dn_phys->dn_type != 0 ||
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1057
		    (bcmp(DN_BONUS(dn->dn_phys), zerobuf,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1058
		    DN_MAX_BONUSLEN) == 0 &&
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1059
		    DN_USED_BYTES(dn->dn_phys) == 0));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1060
		ASSERT(dn->dn_oldphys->dn_type != 0 ||
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1061
		    (bcmp(DN_BONUS(dn->dn_oldphys), zerobuf,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1062
		    DN_MAX_BONUSLEN) == 0 &&
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1063
		    DN_USED_BYTES(dn->dn_oldphys) == 0));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1064
		used_cbs[os->os_phys->os_type](os, bonustype,
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1065
		    DN_BONUS(dn->dn_oldphys), DN_BONUS(dn->dn_phys),
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1066
		    DN_USED_BYTES(dn->dn_oldphys),
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1067
		    DN_USED_BYTES(dn->dn_phys), tx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1068
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1069
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1070
		 * The mutex is needed here for interlock with dnode_allocate.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1071
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1072
		mutex_enter(&dn->dn_mtx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1073
		zio_buf_free(dn->dn_oldphys, sizeof (dnode_phys_t));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1074
		dn->dn_oldphys = NULL;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1075
		mutex_exit(&dn->dn_mtx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1076
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1077
		list_remove(list, dn);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1078
		dnode_rele(dn, list);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1079
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1080
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1081
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1082
boolean_t
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1083
dmu_objset_userspace_present(objset_t *os)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1084
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1085
	return (os->os_phys->os_flags &
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1086
	    OBJSET_FLAG_USERACCOUNTING_COMPLETE);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1087
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1088
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1089
int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1090
dmu_objset_userspace_upgrade(objset_t *os)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1091
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1092
	uint64_t obj;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1093
	int err = 0;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1094
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1095
	if (dmu_objset_userspace_present(os))
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1096
		return (0);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1097
	if (!dmu_objset_userused_enabled(os))
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1098
		return (ENOTSUP);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1099
	if (dmu_objset_is_snapshot(os))
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1100
		return (EINVAL);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1101
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1102
	/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1103
	 * We simply need to mark every object dirty, so that it will be
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1104
	 * synced out and now accounted.  If this is called
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1105
	 * concurrently, or if we already did some work before crashing,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1106
	 * that's fine, since we track each object's accounted state
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1107
	 * independently.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1108
	 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1109
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1110
	for (obj = 0; err == 0; err = dmu_object_next(os, &obj, FALSE, 0)) {
9951
a4895b3dd543 6842815 SUNWzfsu package dependency on SUNWPython is not captured
Lin Ling <Lin.Ling@Sun.COM>
parents: 9554
diff changeset
  1111
		dmu_tx_t *tx;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1112
		dmu_buf_t *db;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1113
		int objerr;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1114
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1115
		if (issig(JUSTLOOKING) && issig(FORREAL))
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1116
			return (EINTR);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1117
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1118
		objerr = dmu_bonus_hold(os, obj, FTAG, &db);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1119
		if (objerr)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1120
			continue;
9951
a4895b3dd543 6842815 SUNWzfsu package dependency on SUNWPython is not captured
Lin Ling <Lin.Ling@Sun.COM>
parents: 9554
diff changeset
  1121
		tx = dmu_tx_create(os);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1122
		dmu_tx_hold_bonus(tx, obj);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1123
		objerr = dmu_tx_assign(tx, TXG_WAIT);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1124
		if (objerr) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1125
			dmu_tx_abort(tx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1126
			continue;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1127
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1128
		dmu_buf_will_dirty(db, tx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1129
		dmu_buf_rele(db, FTAG);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1130
		dmu_tx_commit(tx);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1131
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1132
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1133
	os->os_flags |= OBJSET_FLAG_USERACCOUNTING_COMPLETE;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1134
	txg_wait_synced(dmu_objset_pool(os), 0);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1135
	return (0);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1136
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1137
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
void
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1139
dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp,
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1140
    uint64_t *usedobjsp, uint64_t *availobjsp)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1141
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1142
	dsl_dataset_space(os->os_dsl_dataset, refdbytesp, availbytesp,
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1143
	    usedobjsp, availobjsp);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1144
}
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1145
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1146
uint64_t
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1147
dmu_objset_fsid_guid(objset_t *os)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1148
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1149
	return (dsl_dataset_fsid_guid(os->os_dsl_dataset));
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1150
}
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1151
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1152
void
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1153
dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1155
	stat->dds_type = os->os_phys->os_type;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1156
	if (os->os_dsl_dataset)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1157
		dsl_dataset_fast_stat(os->os_dsl_dataset, stat);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1158
}
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1159
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1160
void
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1161
dmu_objset_stats(objset_t *os, nvlist_t *nv)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1162
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1163
	ASSERT(os->os_dsl_dataset ||
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1164
	    os->os_phys->os_type == DMU_OST_META);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1165
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1166
	if (os->os_dsl_dataset != NULL)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1167
		dsl_dataset_stats(os->os_dsl_dataset, nv);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1168
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1169
	dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_TYPE,
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1170
	    os->os_phys->os_type);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1171
	dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USERACCOUNTING,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1172
	    dmu_objset_userspace_present(os));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1173
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1176
dmu_objset_is_snapshot(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1178
	if (os->os_dsl_dataset != NULL)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1179
		return (dsl_dataset_is_snapshot(os->os_dsl_dataset));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1180
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
		return (B_FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
int
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1185
dmu_snapshot_realname(objset_t *os, char *name, char *real, int maxlen,
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1186
    boolean_t *conflict)
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1187
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1188
	dsl_dataset_t *ds = os->os_dsl_dataset;
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1189
	uint64_t ignored;
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1190
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1191
	if (ds->ds_phys->ds_snapnames_zapobj == 0)
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1192
		return (ENOENT);
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1193
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1194
	return (zap_lookup_norm(ds->ds_dir->dd_pool->dp_meta_objset,
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1195
	    ds->ds_phys->ds_snapnames_zapobj, name, 8, 1, &ignored, MT_FIRST,
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1196
	    real, maxlen, conflict));
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1197
}
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1198
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6174
diff changeset
  1199
int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
dmu_snapshot_list_next(objset_t *os, int namelen, char *name,
5663
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5446
diff changeset
  1201
    uint64_t *idp, uint64_t *offp, boolean_t *case_conflict)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1203
	dsl_dataset_t *ds = os->os_dsl_dataset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
	zap_cursor_t cursor;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
	zap_attribute_t attr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
	if (ds->ds_phys->ds_snapnames_zapobj == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1210
	zap_cursor_init_serialized(&cursor,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
	    ds->ds_dir->dd_pool->dp_meta_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
	    ds->ds_phys->ds_snapnames_zapobj, *offp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1214
	if (zap_cursor_retrieve(&cursor, &attr) != 0) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1215
		zap_cursor_fini(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1216
		return (ENOENT);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1217
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1218
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1219
	if (strlen(attr.za_name) + 1 > namelen) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1220
		zap_cursor_fini(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1221
		return (ENAMETOOLONG);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1222
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1223
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1224
	(void) strcpy(name, attr.za_name);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1225
	if (idp)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1226
		*idp = attr.za_first_integer;
5663
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5446
diff changeset
  1227
	if (case_conflict)
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5446
diff changeset
  1228
		*case_conflict = attr.za_normalization_conflict;
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1229
	zap_cursor_advance(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1230
	*offp = zap_cursor_serialize(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1231
	zap_cursor_fini(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1232
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1233
	return (0);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1234
}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1235
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1236
int
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1237
dmu_dir_list_next(objset_t *os, int namelen, char *name,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1238
    uint64_t *idp, uint64_t *offp)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1239
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1240
	dsl_dir_t *dd = os->os_dsl_dataset->ds_dir;
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1241
	zap_cursor_t cursor;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1242
	zap_attribute_t attr;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1243
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1244
	/* there is no next dir on a snapshot! */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1245
	if (os->os_dsl_dataset->ds_object !=
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1246
	    dd->dd_phys->dd_head_dataset_obj)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1247
		return (ENOENT);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1248
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1249
	zap_cursor_init_serialized(&cursor,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1250
	    dd->dd_pool->dp_meta_objset,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1251
	    dd->dd_phys->dd_child_dir_zapobj, *offp);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1252
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1253
	if (zap_cursor_retrieve(&cursor, &attr) != 0) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1254
		zap_cursor_fini(&cursor);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1255
		return (ENOENT);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1256
	}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1257
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1258
	if (strlen(attr.za_name) + 1 > namelen) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1259
		zap_cursor_fini(&cursor);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1260
		return (ENAMETOOLONG);
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1261
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1262
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1263
	(void) strcpy(name, attr.za_name);
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1264
	if (idp)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1265
		*idp = attr.za_first_integer;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1266
	zap_cursor_advance(&cursor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
	*offp = zap_cursor_serialize(&cursor);
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
  1268
	zap_cursor_fini(&cursor);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1269
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1270
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1271
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1272
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1273
struct findarg {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1274
	int (*func)(char *, void *);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1275
	void *arg;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1276
};
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1277
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1278
/* ARGSUSED */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1279
static int
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1280
findfunc(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1281
{
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1282
	struct findarg *fa = arg;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1283
	return (fa->func((char *)dsname, fa->arg));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1284
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1285
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1286
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1287
 * Find all objsets under name, and for each, call 'func(child_name, arg)'.
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1288
 * Perhaps change all callers to use dmu_objset_find_spa()?
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1289
 */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1290
int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1291
dmu_objset_find(char *name, int func(char *, void *), void *arg, int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1292
{
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1293
	struct findarg fa;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1294
	fa.func = func;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1295
	fa.arg = arg;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1296
	return (dmu_objset_find_spa(NULL, name, findfunc, &fa, flags));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1297
}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1298
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1299
/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1300
 * Find all objsets under name, call func on each
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1301
 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1302
int
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1303
dmu_objset_find_spa(spa_t *spa, const char *name,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1304
    int func(spa_t *, uint64_t, const char *, void *), void *arg, int flags)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1305
{
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1306
	dsl_dir_t *dd;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1307
	dsl_pool_t *dp;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1308
	dsl_dataset_t *ds;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1309
	zap_cursor_t zc;
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1310
	zap_attribute_t *attr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1311
	char *child;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1312
	uint64_t thisobj;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1313
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1314
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1315
	if (name == NULL)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1316
		name = spa_name(spa);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1317
	err = dsl_dir_open_spa(spa, name, FTAG, &dd, NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 982
diff changeset
  1318
	if (err)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1319
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1320
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1321
	/* Don't visit hidden ($MOS & $ORIGIN) objsets. */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1322
	if (dd->dd_myname[0] == '$') {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1323
		dsl_dir_close(dd, FTAG);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1324
		return (0);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1325
	}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1326
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1327
	thisobj = dd->dd_phys->dd_head_dataset_obj;
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1328
	attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1329
	dp = dd->dd_pool;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1331
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1332
	 * Iterate over all children.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1333
	 */
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1334
	if (flags & DS_FIND_CHILDREN) {
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1335
		for (zap_cursor_init(&zc, dp->dp_meta_objset,
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1336
		    dd->dd_phys->dd_child_dir_zapobj);
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1337
		    zap_cursor_retrieve(&zc, attr) == 0;
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1338
		    (void) zap_cursor_advance(&zc)) {
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1339
			ASSERT(attr->za_integer_length == sizeof (uint64_t));
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1340
			ASSERT(attr->za_num_integers == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1341
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1342
			child = kmem_alloc(MAXPATHLEN, KM_SLEEP);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1343
			(void) strcpy(child, name);
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1344
			(void) strcat(child, "/");
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1345
			(void) strcat(child, attr->za_name);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1346
			err = dmu_objset_find_spa(spa, child, func, arg, flags);
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1347
			kmem_free(child, MAXPATHLEN);
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1348
			if (err)
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1349
				break;
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1350
		}
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1351
		zap_cursor_fini(&zc);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1352
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1353
		if (err) {
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1354
			dsl_dir_close(dd, FTAG);
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1355
			kmem_free(attr, sizeof (zap_attribute_t));
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1356
			return (err);
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2391
diff changeset
  1357
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1358
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1359
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1360
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1361
	 * Iterate over all snapshots.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
	 */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1363
	if (flags & DS_FIND_SNAPSHOTS) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1364
		if (!dsl_pool_sync_context(dp))
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1365
			rw_enter(&dp->dp_config_rwlock, RW_READER);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1366
		err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1367
		if (!dsl_pool_sync_context(dp))
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1368
			rw_exit(&dp->dp_config_rwlock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1369
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1370
		if (err == 0) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1371
			uint64_t snapobj = ds->ds_phys->ds_snapnames_zapobj;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1372
			dsl_dataset_rele(ds, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1373
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1374
			for (zap_cursor_init(&zc, dp->dp_meta_objset, snapobj);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1375
			    zap_cursor_retrieve(&zc, attr) == 0;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1376
			    (void) zap_cursor_advance(&zc)) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1377
				ASSERT(attr->za_integer_length ==
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1378
				    sizeof (uint64_t));
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1379
				ASSERT(attr->za_num_integers == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1380
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1381
				child = kmem_alloc(MAXPATHLEN, KM_SLEEP);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1382
				(void) strcpy(child, name);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1383
				(void) strcat(child, "@");
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1384
				(void) strcat(child, attr->za_name);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1385
				err = func(spa, attr->za_first_integer,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1386
				    child, arg);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1387
				kmem_free(child, MAXPATHLEN);
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1388
				if (err)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1389
					break;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1390
			}
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1391
			zap_cursor_fini(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1392
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1393
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1395
	dsl_dir_close(dd, FTAG);
3978
2dd668007b7a 6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents: 3897
diff changeset
  1396
	kmem_free(attr, sizeof (zap_attribute_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1397
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1398
	if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1399
		return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1400
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1401
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1402
	 * Apply to self if appropriate.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1403
	 */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1404
	err = func(spa, thisobj, name, arg);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1405
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
}
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1407
8415
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1408
/* ARGSUSED */
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1409
int
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1410
dmu_objset_prefetch(char *name, void *arg)
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1411
{
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1412
	dsl_dataset_t *ds;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1413
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1414
	if (dsl_dataset_hold(name, FTAG, &ds))
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1415
		return (0);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1416
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1417
	if (!BP_IS_HOLE(&ds->ds_phys->ds_bp)) {
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1418
		mutex_enter(&ds->ds_opening_lock);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1419
		if (ds->ds_objset == NULL) {
8415
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1420
			uint32_t aflags = ARC_NOWAIT | ARC_PREFETCH;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1421
			zbookmark_t zb;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1422
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1423
			zb.zb_objset = ds->ds_object;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1424
			zb.zb_object = 0;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1425
			zb.zb_level = -1;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1426
			zb.zb_blkid = 0;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1427
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1428
			(void) arc_read_nolock(NULL, dsl_dataset_get_spa(ds),
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1429
			    &ds->ds_phys->ds_bp, NULL, NULL,
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1430
			    ZIO_PRIORITY_ASYNC_READ,
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1431
			    ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE,
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1432
			    &aflags, &zb);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1433
		}
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1434
		mutex_exit(&ds->ds_opening_lock);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1435
	}
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1436
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1437
	dsl_dataset_rele(ds, FTAG);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1438
	return (0);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1439
}
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8213
diff changeset
  1440
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1441
void
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1442
dmu_objset_set_user(objset_t *os, void *user_ptr)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1443
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1444
	ASSERT(MUTEX_HELD(&os->os_user_ptr_lock));
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1445
	os->os_user_ptr = user_ptr;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1446
}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1447
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1448
void *
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1449
dmu_objset_get_user(objset_t *os)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1450
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1451
	ASSERT(MUTEX_HELD(&os->os_user_ptr_lock));
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1452
	return (os->os_user_ptr);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1453
}